1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd
11 #include <rte_common.h>
12 #include <rte_ether.h>
13 #include <ethdev_driver.h>
15 #include <rte_flow_driver.h>
16 #include <rte_malloc.h>
17 #include <rte_cycles.h>
20 #include <rte_vxlan.h>
22 #include <rte_eal_paging.h>
25 #include <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"
37 #include "rte_pmd_mlx5.h"
39 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
41 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
42 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
45 #ifndef HAVE_MLX5DV_DR_ESWITCH
46 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
47 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
51 #ifndef HAVE_MLX5DV_DR
52 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
55 /* VLAN header definitions */
56 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
57 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
58 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
59 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
60 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
75 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
76 struct mlx5_flow_tbl_resource *tbl);
79 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
80 uint32_t encap_decap_idx);
83 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
86 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
89 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
93 * Initialize flow attributes structure according to flow items' types.
95 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
96 * mode. For tunnel mode, the items to be modified are the outermost ones.
99 * Pointer to item specification.
101 * Pointer to flow attributes structure.
102 * @param[in] dev_flow
103 * Pointer to the sub flow.
104 * @param[in] tunnel_decap
105 * Whether action is after tunnel decapsulation.
108 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
109 struct mlx5_flow *dev_flow, bool tunnel_decap)
111 uint64_t layers = dev_flow->handle->layers;
114 * If layers is already initialized, it means this dev_flow is the
115 * suffix flow, the layers flags is set by the prefix flow. Need to
116 * use the layer flags from prefix flow as the suffix flow may not
117 * have the user defined items as the flow is split.
120 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
122 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
124 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
126 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
131 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
132 uint8_t next_protocol = 0xff;
133 switch (item->type) {
134 case RTE_FLOW_ITEM_TYPE_GRE:
135 case RTE_FLOW_ITEM_TYPE_NVGRE:
136 case RTE_FLOW_ITEM_TYPE_VXLAN:
137 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
138 case RTE_FLOW_ITEM_TYPE_GENEVE:
139 case RTE_FLOW_ITEM_TYPE_MPLS:
143 case RTE_FLOW_ITEM_TYPE_IPV4:
146 if (item->mask != NULL &&
147 ((const struct rte_flow_item_ipv4 *)
148 item->mask)->hdr.next_proto_id)
150 ((const struct rte_flow_item_ipv4 *)
151 (item->spec))->hdr.next_proto_id &
152 ((const struct rte_flow_item_ipv4 *)
153 (item->mask))->hdr.next_proto_id;
154 if ((next_protocol == IPPROTO_IPIP ||
155 next_protocol == IPPROTO_IPV6) && tunnel_decap)
158 case RTE_FLOW_ITEM_TYPE_IPV6:
161 if (item->mask != NULL &&
162 ((const struct rte_flow_item_ipv6 *)
163 item->mask)->hdr.proto)
165 ((const struct rte_flow_item_ipv6 *)
166 (item->spec))->hdr.proto &
167 ((const struct rte_flow_item_ipv6 *)
168 (item->mask))->hdr.proto;
169 if ((next_protocol == IPPROTO_IPIP ||
170 next_protocol == IPPROTO_IPV6) && tunnel_decap)
173 case RTE_FLOW_ITEM_TYPE_UDP:
177 case RTE_FLOW_ITEM_TYPE_TCP:
189 * Convert rte_mtr_color to mlx5 color.
198 rte_col_2_mlx5_col(enum rte_color rcol)
201 case RTE_COLOR_GREEN:
202 return MLX5_FLOW_COLOR_GREEN;
203 case RTE_COLOR_YELLOW:
204 return MLX5_FLOW_COLOR_YELLOW;
206 return MLX5_FLOW_COLOR_RED;
210 return MLX5_FLOW_COLOR_UNDEFINED;
213 struct field_modify_info {
214 uint32_t size; /* Size of field in protocol header, in bytes. */
215 uint32_t offset; /* Offset of field in protocol header, in bytes. */
216 enum mlx5_modification_field id;
219 struct field_modify_info modify_eth[] = {
220 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
221 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
222 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
223 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
227 struct field_modify_info modify_vlan_out_first_vid[] = {
228 /* Size in bits !!! */
229 {12, 0, MLX5_MODI_OUT_FIRST_VID},
233 struct field_modify_info modify_ipv4[] = {
234 {1, 1, MLX5_MODI_OUT_IP_DSCP},
235 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
236 {4, 12, MLX5_MODI_OUT_SIPV4},
237 {4, 16, MLX5_MODI_OUT_DIPV4},
241 struct field_modify_info modify_ipv6[] = {
242 {1, 0, MLX5_MODI_OUT_IP_DSCP},
243 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
244 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
245 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
246 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
247 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
248 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
249 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
250 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
251 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
255 struct field_modify_info modify_udp[] = {
256 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
257 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
261 struct field_modify_info modify_tcp[] = {
262 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
263 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
264 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
265 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
270 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
271 uint8_t next_protocol, uint64_t *item_flags,
274 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
275 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
276 if (next_protocol == IPPROTO_IPIP) {
277 *item_flags |= MLX5_FLOW_LAYER_IPIP;
280 if (next_protocol == IPPROTO_IPV6) {
281 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
286 /* Update VLAN's VID/PCP based on input rte_flow_action.
289 * Pointer to struct rte_flow_action.
291 * Pointer to struct rte_vlan_hdr.
294 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
295 struct rte_vlan_hdr *vlan)
298 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
300 ((const struct rte_flow_action_of_set_vlan_pcp *)
301 action->conf)->vlan_pcp;
302 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
303 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
304 vlan->vlan_tci |= vlan_tci;
305 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
306 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
307 vlan->vlan_tci |= rte_be_to_cpu_16
308 (((const struct rte_flow_action_of_set_vlan_vid *)
309 action->conf)->vlan_vid);
314 * Fetch 1, 2, 3 or 4 byte field from the byte array
315 * and return as unsigned integer in host-endian format.
318 * Pointer to data array.
320 * Size of field to extract.
323 * converted field in host endian format.
325 static inline uint32_t
326 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
335 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
338 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
339 ret = (ret << 8) | *(data + sizeof(uint16_t));
342 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
353 * Convert modify-header action to DV specification.
355 * Data length of each action is determined by provided field description
356 * and the item mask. Data bit offset and width of each action is determined
357 * by provided item mask.
360 * Pointer to item specification.
362 * Pointer to field modification information.
363 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
364 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
365 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
367 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
368 * Negative offset value sets the same offset as source offset.
369 * size field is ignored, value is taken from source field.
370 * @param[in,out] resource
371 * Pointer to the modify-header resource.
373 * Type of modification.
375 * Pointer to the error structure.
378 * 0 on success, a negative errno value otherwise and rte_errno is set.
381 flow_dv_convert_modify_action(struct rte_flow_item *item,
382 struct field_modify_info *field,
383 struct field_modify_info *dcopy,
384 struct mlx5_flow_dv_modify_hdr_resource *resource,
385 uint32_t type, struct rte_flow_error *error)
387 uint32_t i = resource->actions_num;
388 struct mlx5_modification_cmd *actions = resource->actions;
391 * The item and mask are provided in big-endian format.
392 * The fields should be presented as in big-endian format either.
393 * Mask must be always present, it defines the actual field width.
395 MLX5_ASSERT(item->mask);
396 MLX5_ASSERT(field->size);
403 if (i >= MLX5_MAX_MODIFY_NUM)
404 return rte_flow_error_set(error, EINVAL,
405 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
406 "too many items to modify");
407 /* Fetch variable byte size mask from the array. */
408 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
409 field->offset, field->size);
414 /* Deduce actual data width in bits from mask value. */
415 off_b = rte_bsf32(mask);
416 size_b = sizeof(uint32_t) * CHAR_BIT -
417 off_b - __builtin_clz(mask);
419 size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
420 actions[i] = (struct mlx5_modification_cmd) {
426 /* Convert entire record to expected big-endian format. */
427 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
428 if (type == MLX5_MODIFICATION_TYPE_COPY) {
430 actions[i].dst_field = dcopy->id;
431 actions[i].dst_offset =
432 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
433 /* Convert entire record to big-endian format. */
434 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
437 MLX5_ASSERT(item->spec);
438 data = flow_dv_fetch_field((const uint8_t *)item->spec +
439 field->offset, field->size);
440 /* Shift out the trailing masked bits from data. */
441 data = (data & mask) >> off_b;
442 actions[i].data1 = rte_cpu_to_be_32(data);
446 } while (field->size);
447 if (resource->actions_num == i)
448 return rte_flow_error_set(error, EINVAL,
449 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
450 "invalid modification flow item");
451 resource->actions_num = i;
456 * Convert modify-header set IPv4 address action to DV specification.
458 * @param[in,out] resource
459 * Pointer to the modify-header resource.
461 * Pointer to action specification.
463 * Pointer to the error structure.
466 * 0 on success, a negative errno value otherwise and rte_errno is set.
469 flow_dv_convert_action_modify_ipv4
470 (struct mlx5_flow_dv_modify_hdr_resource *resource,
471 const struct rte_flow_action *action,
472 struct rte_flow_error *error)
474 const struct rte_flow_action_set_ipv4 *conf =
475 (const struct rte_flow_action_set_ipv4 *)(action->conf);
476 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
477 struct rte_flow_item_ipv4 ipv4;
478 struct rte_flow_item_ipv4 ipv4_mask;
480 memset(&ipv4, 0, sizeof(ipv4));
481 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
482 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
483 ipv4.hdr.src_addr = conf->ipv4_addr;
484 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
486 ipv4.hdr.dst_addr = conf->ipv4_addr;
487 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
490 item.mask = &ipv4_mask;
491 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
492 MLX5_MODIFICATION_TYPE_SET, error);
496 * Convert modify-header set IPv6 address action to DV specification.
498 * @param[in,out] resource
499 * Pointer to the modify-header resource.
501 * Pointer to action specification.
503 * Pointer to the error structure.
506 * 0 on success, a negative errno value otherwise and rte_errno is set.
509 flow_dv_convert_action_modify_ipv6
510 (struct mlx5_flow_dv_modify_hdr_resource *resource,
511 const struct rte_flow_action *action,
512 struct rte_flow_error *error)
514 const struct rte_flow_action_set_ipv6 *conf =
515 (const struct rte_flow_action_set_ipv6 *)(action->conf);
516 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
517 struct rte_flow_item_ipv6 ipv6;
518 struct rte_flow_item_ipv6 ipv6_mask;
520 memset(&ipv6, 0, sizeof(ipv6));
521 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
522 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
523 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
524 sizeof(ipv6.hdr.src_addr));
525 memcpy(&ipv6_mask.hdr.src_addr,
526 &rte_flow_item_ipv6_mask.hdr.src_addr,
527 sizeof(ipv6.hdr.src_addr));
529 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
530 sizeof(ipv6.hdr.dst_addr));
531 memcpy(&ipv6_mask.hdr.dst_addr,
532 &rte_flow_item_ipv6_mask.hdr.dst_addr,
533 sizeof(ipv6.hdr.dst_addr));
536 item.mask = &ipv6_mask;
537 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
538 MLX5_MODIFICATION_TYPE_SET, error);
542 * Convert modify-header set MAC address action to DV specification.
544 * @param[in,out] resource
545 * Pointer to the modify-header resource.
547 * Pointer to action specification.
549 * Pointer to the error structure.
552 * 0 on success, a negative errno value otherwise and rte_errno is set.
555 flow_dv_convert_action_modify_mac
556 (struct mlx5_flow_dv_modify_hdr_resource *resource,
557 const struct rte_flow_action *action,
558 struct rte_flow_error *error)
560 const struct rte_flow_action_set_mac *conf =
561 (const struct rte_flow_action_set_mac *)(action->conf);
562 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
563 struct rte_flow_item_eth eth;
564 struct rte_flow_item_eth eth_mask;
566 memset(ð, 0, sizeof(eth));
567 memset(ð_mask, 0, sizeof(eth_mask));
568 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
569 memcpy(ð.src.addr_bytes, &conf->mac_addr,
570 sizeof(eth.src.addr_bytes));
571 memcpy(ð_mask.src.addr_bytes,
572 &rte_flow_item_eth_mask.src.addr_bytes,
573 sizeof(eth_mask.src.addr_bytes));
575 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
576 sizeof(eth.dst.addr_bytes));
577 memcpy(ð_mask.dst.addr_bytes,
578 &rte_flow_item_eth_mask.dst.addr_bytes,
579 sizeof(eth_mask.dst.addr_bytes));
582 item.mask = ð_mask;
583 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
584 MLX5_MODIFICATION_TYPE_SET, error);
588 * Convert modify-header set VLAN VID action to DV specification.
590 * @param[in,out] resource
591 * Pointer to the modify-header resource.
593 * Pointer to action specification.
595 * Pointer to the error structure.
598 * 0 on success, a negative errno value otherwise and rte_errno is set.
601 flow_dv_convert_action_modify_vlan_vid
602 (struct mlx5_flow_dv_modify_hdr_resource *resource,
603 const struct rte_flow_action *action,
604 struct rte_flow_error *error)
606 const struct rte_flow_action_of_set_vlan_vid *conf =
607 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
608 int i = resource->actions_num;
609 struct mlx5_modification_cmd *actions = resource->actions;
610 struct field_modify_info *field = modify_vlan_out_first_vid;
612 if (i >= MLX5_MAX_MODIFY_NUM)
613 return rte_flow_error_set(error, EINVAL,
614 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
615 "too many items to modify");
616 actions[i] = (struct mlx5_modification_cmd) {
617 .action_type = MLX5_MODIFICATION_TYPE_SET,
619 .length = field->size,
620 .offset = field->offset,
622 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
623 actions[i].data1 = conf->vlan_vid;
624 actions[i].data1 = actions[i].data1 << 16;
625 resource->actions_num = ++i;
630 * Convert modify-header set TP action to DV specification.
632 * @param[in,out] resource
633 * Pointer to the modify-header resource.
635 * Pointer to action specification.
637 * Pointer to rte_flow_item objects list.
639 * Pointer to flow attributes structure.
640 * @param[in] dev_flow
641 * Pointer to the sub flow.
642 * @param[in] tunnel_decap
643 * Whether action is after tunnel decapsulation.
645 * Pointer to the error structure.
648 * 0 on success, a negative errno value otherwise and rte_errno is set.
651 flow_dv_convert_action_modify_tp
652 (struct mlx5_flow_dv_modify_hdr_resource *resource,
653 const struct rte_flow_action *action,
654 const struct rte_flow_item *items,
655 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
656 bool tunnel_decap, struct rte_flow_error *error)
658 const struct rte_flow_action_set_tp *conf =
659 (const struct rte_flow_action_set_tp *)(action->conf);
660 struct rte_flow_item item;
661 struct rte_flow_item_udp udp;
662 struct rte_flow_item_udp udp_mask;
663 struct rte_flow_item_tcp tcp;
664 struct rte_flow_item_tcp tcp_mask;
665 struct field_modify_info *field;
668 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
670 memset(&udp, 0, sizeof(udp));
671 memset(&udp_mask, 0, sizeof(udp_mask));
672 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
673 udp.hdr.src_port = conf->port;
674 udp_mask.hdr.src_port =
675 rte_flow_item_udp_mask.hdr.src_port;
677 udp.hdr.dst_port = conf->port;
678 udp_mask.hdr.dst_port =
679 rte_flow_item_udp_mask.hdr.dst_port;
681 item.type = RTE_FLOW_ITEM_TYPE_UDP;
683 item.mask = &udp_mask;
686 MLX5_ASSERT(attr->tcp);
687 memset(&tcp, 0, sizeof(tcp));
688 memset(&tcp_mask, 0, sizeof(tcp_mask));
689 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
690 tcp.hdr.src_port = conf->port;
691 tcp_mask.hdr.src_port =
692 rte_flow_item_tcp_mask.hdr.src_port;
694 tcp.hdr.dst_port = conf->port;
695 tcp_mask.hdr.dst_port =
696 rte_flow_item_tcp_mask.hdr.dst_port;
698 item.type = RTE_FLOW_ITEM_TYPE_TCP;
700 item.mask = &tcp_mask;
703 return flow_dv_convert_modify_action(&item, field, NULL, resource,
704 MLX5_MODIFICATION_TYPE_SET, error);
708 * Convert modify-header set TTL action to DV specification.
710 * @param[in,out] resource
711 * Pointer to the modify-header resource.
713 * Pointer to action specification.
715 * Pointer to rte_flow_item objects list.
717 * Pointer to flow attributes structure.
718 * @param[in] dev_flow
719 * Pointer to the sub flow.
720 * @param[in] tunnel_decap
721 * Whether action is after tunnel decapsulation.
723 * Pointer to the error structure.
726 * 0 on success, a negative errno value otherwise and rte_errno is set.
729 flow_dv_convert_action_modify_ttl
730 (struct mlx5_flow_dv_modify_hdr_resource *resource,
731 const struct rte_flow_action *action,
732 const struct rte_flow_item *items,
733 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
734 bool tunnel_decap, struct rte_flow_error *error)
736 const struct rte_flow_action_set_ttl *conf =
737 (const struct rte_flow_action_set_ttl *)(action->conf);
738 struct rte_flow_item item;
739 struct rte_flow_item_ipv4 ipv4;
740 struct rte_flow_item_ipv4 ipv4_mask;
741 struct rte_flow_item_ipv6 ipv6;
742 struct rte_flow_item_ipv6 ipv6_mask;
743 struct field_modify_info *field;
746 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
748 memset(&ipv4, 0, sizeof(ipv4));
749 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
750 ipv4.hdr.time_to_live = conf->ttl_value;
751 ipv4_mask.hdr.time_to_live = 0xFF;
752 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
754 item.mask = &ipv4_mask;
757 MLX5_ASSERT(attr->ipv6);
758 memset(&ipv6, 0, sizeof(ipv6));
759 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
760 ipv6.hdr.hop_limits = conf->ttl_value;
761 ipv6_mask.hdr.hop_limits = 0xFF;
762 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
764 item.mask = &ipv6_mask;
767 return flow_dv_convert_modify_action(&item, field, NULL, resource,
768 MLX5_MODIFICATION_TYPE_SET, error);
772 * Convert modify-header decrement TTL action to DV specification.
774 * @param[in,out] resource
775 * Pointer to the modify-header resource.
777 * Pointer to action specification.
779 * Pointer to rte_flow_item objects list.
781 * Pointer to flow attributes structure.
782 * @param[in] dev_flow
783 * Pointer to the sub flow.
784 * @param[in] tunnel_decap
785 * Whether action is after tunnel decapsulation.
787 * Pointer to the error structure.
790 * 0 on success, a negative errno value otherwise and rte_errno is set.
793 flow_dv_convert_action_modify_dec_ttl
794 (struct mlx5_flow_dv_modify_hdr_resource *resource,
795 const struct rte_flow_item *items,
796 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
797 bool tunnel_decap, struct rte_flow_error *error)
799 struct rte_flow_item item;
800 struct rte_flow_item_ipv4 ipv4;
801 struct rte_flow_item_ipv4 ipv4_mask;
802 struct rte_flow_item_ipv6 ipv6;
803 struct rte_flow_item_ipv6 ipv6_mask;
804 struct field_modify_info *field;
807 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
809 memset(&ipv4, 0, sizeof(ipv4));
810 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
811 ipv4.hdr.time_to_live = 0xFF;
812 ipv4_mask.hdr.time_to_live = 0xFF;
813 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
815 item.mask = &ipv4_mask;
818 MLX5_ASSERT(attr->ipv6);
819 memset(&ipv6, 0, sizeof(ipv6));
820 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
821 ipv6.hdr.hop_limits = 0xFF;
822 ipv6_mask.hdr.hop_limits = 0xFF;
823 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
825 item.mask = &ipv6_mask;
828 return flow_dv_convert_modify_action(&item, field, NULL, resource,
829 MLX5_MODIFICATION_TYPE_ADD, error);
833 * Convert modify-header increment/decrement TCP Sequence number
834 * to DV specification.
836 * @param[in,out] resource
837 * Pointer to the modify-header resource.
839 * Pointer to action specification.
841 * Pointer to the error structure.
844 * 0 on success, a negative errno value otherwise and rte_errno is set.
847 flow_dv_convert_action_modify_tcp_seq
848 (struct mlx5_flow_dv_modify_hdr_resource *resource,
849 const struct rte_flow_action *action,
850 struct rte_flow_error *error)
852 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
853 uint64_t value = rte_be_to_cpu_32(*conf);
854 struct rte_flow_item item;
855 struct rte_flow_item_tcp tcp;
856 struct rte_flow_item_tcp tcp_mask;
858 memset(&tcp, 0, sizeof(tcp));
859 memset(&tcp_mask, 0, sizeof(tcp_mask));
860 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
862 * The HW has no decrement operation, only increment operation.
863 * To simulate decrement X from Y using increment operation
864 * we need to add UINT32_MAX X times to Y.
865 * Each adding of UINT32_MAX decrements Y by 1.
868 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
869 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
870 item.type = RTE_FLOW_ITEM_TYPE_TCP;
872 item.mask = &tcp_mask;
873 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
874 MLX5_MODIFICATION_TYPE_ADD, error);
878 * Convert modify-header increment/decrement TCP Acknowledgment number
879 * to DV specification.
881 * @param[in,out] resource
882 * Pointer to the modify-header resource.
884 * Pointer to action specification.
886 * Pointer to the error structure.
889 * 0 on success, a negative errno value otherwise and rte_errno is set.
892 flow_dv_convert_action_modify_tcp_ack
893 (struct mlx5_flow_dv_modify_hdr_resource *resource,
894 const struct rte_flow_action *action,
895 struct rte_flow_error *error)
897 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
898 uint64_t value = rte_be_to_cpu_32(*conf);
899 struct rte_flow_item item;
900 struct rte_flow_item_tcp tcp;
901 struct rte_flow_item_tcp tcp_mask;
903 memset(&tcp, 0, sizeof(tcp));
904 memset(&tcp_mask, 0, sizeof(tcp_mask));
905 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
907 * The HW has no decrement operation, only increment operation.
908 * To simulate decrement X from Y using increment operation
909 * we need to add UINT32_MAX X times to Y.
910 * Each adding of UINT32_MAX decrements Y by 1.
913 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
914 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
915 item.type = RTE_FLOW_ITEM_TYPE_TCP;
917 item.mask = &tcp_mask;
918 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
919 MLX5_MODIFICATION_TYPE_ADD, error);
922 static enum mlx5_modification_field reg_to_field[] = {
923 [REG_NON] = MLX5_MODI_OUT_NONE,
924 [REG_A] = MLX5_MODI_META_DATA_REG_A,
925 [REG_B] = MLX5_MODI_META_DATA_REG_B,
926 [REG_C_0] = MLX5_MODI_META_REG_C_0,
927 [REG_C_1] = MLX5_MODI_META_REG_C_1,
928 [REG_C_2] = MLX5_MODI_META_REG_C_2,
929 [REG_C_3] = MLX5_MODI_META_REG_C_3,
930 [REG_C_4] = MLX5_MODI_META_REG_C_4,
931 [REG_C_5] = MLX5_MODI_META_REG_C_5,
932 [REG_C_6] = MLX5_MODI_META_REG_C_6,
933 [REG_C_7] = MLX5_MODI_META_REG_C_7,
937 * Convert register set to DV specification.
939 * @param[in,out] resource
940 * Pointer to the modify-header resource.
942 * Pointer to action specification.
944 * Pointer to the error structure.
947 * 0 on success, a negative errno value otherwise and rte_errno is set.
950 flow_dv_convert_action_set_reg
951 (struct mlx5_flow_dv_modify_hdr_resource *resource,
952 const struct rte_flow_action *action,
953 struct rte_flow_error *error)
955 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
956 struct mlx5_modification_cmd *actions = resource->actions;
957 uint32_t i = resource->actions_num;
959 if (i >= MLX5_MAX_MODIFY_NUM)
960 return rte_flow_error_set(error, EINVAL,
961 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
962 "too many items to modify");
963 MLX5_ASSERT(conf->id != REG_NON);
964 MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
965 actions[i] = (struct mlx5_modification_cmd) {
966 .action_type = MLX5_MODIFICATION_TYPE_SET,
967 .field = reg_to_field[conf->id],
969 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
970 actions[i].data1 = rte_cpu_to_be_32(conf->data);
972 resource->actions_num = i;
977 * Convert SET_TAG action to DV specification.
980 * Pointer to the rte_eth_dev structure.
981 * @param[in,out] resource
982 * Pointer to the modify-header resource.
984 * Pointer to action specification.
986 * Pointer to the error structure.
989 * 0 on success, a negative errno value otherwise and rte_errno is set.
992 flow_dv_convert_action_set_tag
993 (struct rte_eth_dev *dev,
994 struct mlx5_flow_dv_modify_hdr_resource *resource,
995 const struct rte_flow_action_set_tag *conf,
996 struct rte_flow_error *error)
998 rte_be32_t data = rte_cpu_to_be_32(conf->data);
999 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1000 struct rte_flow_item item = {
1004 struct field_modify_info reg_c_x[] = {
1007 enum mlx5_modification_field reg_type;
1010 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1013 MLX5_ASSERT(ret != REG_NON);
1014 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1015 reg_type = reg_to_field[ret];
1016 MLX5_ASSERT(reg_type > 0);
1017 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1018 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1019 MLX5_MODIFICATION_TYPE_SET, error);
1023 * Convert internal COPY_REG action to DV specification.
1026 * Pointer to the rte_eth_dev structure.
1027 * @param[in,out] res
1028 * Pointer to the modify-header resource.
1030 * Pointer to action specification.
1032 * Pointer to the error structure.
1035 * 0 on success, a negative errno value otherwise and rte_errno is set.
1038 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1039 struct mlx5_flow_dv_modify_hdr_resource *res,
1040 const struct rte_flow_action *action,
1041 struct rte_flow_error *error)
1043 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1044 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1045 struct rte_flow_item item = {
1049 struct field_modify_info reg_src[] = {
1050 {4, 0, reg_to_field[conf->src]},
1053 struct field_modify_info reg_dst = {
1055 .id = reg_to_field[conf->dst],
1057 /* Adjust reg_c[0] usage according to reported mask. */
1058 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1059 struct mlx5_priv *priv = dev->data->dev_private;
1060 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1062 MLX5_ASSERT(reg_c0);
1063 MLX5_ASSERT(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1064 if (conf->dst == REG_C_0) {
1065 /* Copy to reg_c[0], within mask only. */
1066 reg_dst.offset = rte_bsf32(reg_c0);
1068 * Mask is ignoring the enianness, because
1069 * there is no conversion in datapath.
1071 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1072 /* Copy from destination lower bits to reg_c[0]. */
1073 mask = reg_c0 >> reg_dst.offset;
1075 /* Copy from destination upper bits to reg_c[0]. */
1076 mask = reg_c0 << (sizeof(reg_c0) * CHAR_BIT -
1077 rte_fls_u32(reg_c0));
1080 mask = rte_cpu_to_be_32(reg_c0);
1081 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1082 /* Copy from reg_c[0] to destination lower bits. */
1085 /* Copy from reg_c[0] to destination upper bits. */
1086 reg_dst.offset = sizeof(reg_c0) * CHAR_BIT -
1087 (rte_fls_u32(reg_c0) -
1092 return flow_dv_convert_modify_action(&item,
1093 reg_src, ®_dst, res,
1094 MLX5_MODIFICATION_TYPE_COPY,
1099 * Convert MARK action to DV specification. This routine is used
1100 * in extensive metadata only and requires metadata register to be
1101 * handled. In legacy mode hardware tag resource is engaged.
1104 * Pointer to the rte_eth_dev structure.
1106 * Pointer to MARK action specification.
1107 * @param[in,out] resource
1108 * Pointer to the modify-header resource.
1110 * Pointer to the error structure.
1113 * 0 on success, a negative errno value otherwise and rte_errno is set.
1116 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1117 const struct rte_flow_action_mark *conf,
1118 struct mlx5_flow_dv_modify_hdr_resource *resource,
1119 struct rte_flow_error *error)
1121 struct mlx5_priv *priv = dev->data->dev_private;
1122 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1123 priv->sh->dv_mark_mask);
1124 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1125 struct rte_flow_item item = {
1129 struct field_modify_info reg_c_x[] = {
1135 return rte_flow_error_set(error, EINVAL,
1136 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1137 NULL, "zero mark action mask");
1138 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1141 MLX5_ASSERT(reg > 0);
1142 if (reg == REG_C_0) {
1143 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1144 uint32_t shl_c0 = rte_bsf32(msk_c0);
1146 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1147 mask = rte_cpu_to_be_32(mask) & msk_c0;
1148 mask = rte_cpu_to_be_32(mask << shl_c0);
1150 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1151 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1152 MLX5_MODIFICATION_TYPE_SET, error);
1156 * Get metadata register index for specified steering domain.
1159 * Pointer to the rte_eth_dev structure.
1161 * Attributes of flow to determine steering domain.
1163 * Pointer to the error structure.
1166 * positive index on success, a negative errno value otherwise
1167 * and rte_errno is set.
1169 static enum modify_reg
1170 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1171 const struct rte_flow_attr *attr,
1172 struct rte_flow_error *error)
1175 mlx5_flow_get_reg_id(dev, attr->transfer ?
1179 MLX5_METADATA_RX, 0, error);
1181 return rte_flow_error_set(error,
1182 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1183 NULL, "unavailable "
1184 "metadata register");
1189 * Convert SET_META action to DV specification.
1192 * Pointer to the rte_eth_dev structure.
1193 * @param[in,out] resource
1194 * Pointer to the modify-header resource.
1196 * Attributes of flow that includes this item.
1198 * Pointer to action specification.
1200 * Pointer to the error structure.
1203 * 0 on success, a negative errno value otherwise and rte_errno is set.
1206 flow_dv_convert_action_set_meta
1207 (struct rte_eth_dev *dev,
1208 struct mlx5_flow_dv_modify_hdr_resource *resource,
1209 const struct rte_flow_attr *attr,
1210 const struct rte_flow_action_set_meta *conf,
1211 struct rte_flow_error *error)
1213 uint32_t data = conf->data;
1214 uint32_t mask = conf->mask;
1215 struct rte_flow_item item = {
1219 struct field_modify_info reg_c_x[] = {
1222 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1226 MLX5_ASSERT(reg != REG_NON);
1228 * In datapath code there is no endianness
1229 * coversions for perfromance reasons, all
1230 * pattern conversions are done in rte_flow.
1232 if (reg == REG_C_0) {
1233 struct mlx5_priv *priv = dev->data->dev_private;
1234 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1237 MLX5_ASSERT(msk_c0);
1238 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1239 shl_c0 = rte_bsf32(msk_c0);
1241 shl_c0 = sizeof(msk_c0) * CHAR_BIT - rte_fls_u32(msk_c0);
1245 MLX5_ASSERT(!(~msk_c0 & rte_cpu_to_be_32(mask)));
1247 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1248 /* The routine expects parameters in memory as big-endian ones. */
1249 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1250 MLX5_MODIFICATION_TYPE_SET, error);
1254 * Convert modify-header set IPv4 DSCP action to DV specification.
1256 * @param[in,out] resource
1257 * Pointer to the modify-header resource.
1259 * Pointer to action specification.
1261 * Pointer to the error structure.
1264 * 0 on success, a negative errno value otherwise and rte_errno is set.
1267 flow_dv_convert_action_modify_ipv4_dscp
1268 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1269 const struct rte_flow_action *action,
1270 struct rte_flow_error *error)
1272 const struct rte_flow_action_set_dscp *conf =
1273 (const struct rte_flow_action_set_dscp *)(action->conf);
1274 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1275 struct rte_flow_item_ipv4 ipv4;
1276 struct rte_flow_item_ipv4 ipv4_mask;
1278 memset(&ipv4, 0, sizeof(ipv4));
1279 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1280 ipv4.hdr.type_of_service = conf->dscp;
1281 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1283 item.mask = &ipv4_mask;
1284 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1285 MLX5_MODIFICATION_TYPE_SET, error);
1289 * Convert modify-header set IPv6 DSCP action to DV specification.
1291 * @param[in,out] resource
1292 * Pointer to the modify-header resource.
1294 * Pointer to action specification.
1296 * Pointer to the error structure.
1299 * 0 on success, a negative errno value otherwise and rte_errno is set.
1302 flow_dv_convert_action_modify_ipv6_dscp
1303 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1304 const struct rte_flow_action *action,
1305 struct rte_flow_error *error)
1307 const struct rte_flow_action_set_dscp *conf =
1308 (const struct rte_flow_action_set_dscp *)(action->conf);
1309 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1310 struct rte_flow_item_ipv6 ipv6;
1311 struct rte_flow_item_ipv6 ipv6_mask;
1313 memset(&ipv6, 0, sizeof(ipv6));
1314 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1316 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1317 * rdma-core only accept the DSCP bits byte aligned start from
1318 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1319 * bits in IPv6 case as rdma-core requires byte aligned value.
1321 ipv6.hdr.vtc_flow = conf->dscp;
1322 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1324 item.mask = &ipv6_mask;
1325 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1326 MLX5_MODIFICATION_TYPE_SET, error);
1330 mlx5_flow_item_field_width(enum rte_flow_field_id field)
1333 case RTE_FLOW_FIELD_START:
1335 case RTE_FLOW_FIELD_MAC_DST:
1336 case RTE_FLOW_FIELD_MAC_SRC:
1338 case RTE_FLOW_FIELD_VLAN_TYPE:
1340 case RTE_FLOW_FIELD_VLAN_ID:
1342 case RTE_FLOW_FIELD_MAC_TYPE:
1344 case RTE_FLOW_FIELD_IPV4_DSCP:
1346 case RTE_FLOW_FIELD_IPV4_TTL:
1348 case RTE_FLOW_FIELD_IPV4_SRC:
1349 case RTE_FLOW_FIELD_IPV4_DST:
1351 case RTE_FLOW_FIELD_IPV6_DSCP:
1353 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1355 case RTE_FLOW_FIELD_IPV6_SRC:
1356 case RTE_FLOW_FIELD_IPV6_DST:
1358 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1359 case RTE_FLOW_FIELD_TCP_PORT_DST:
1361 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1362 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1364 case RTE_FLOW_FIELD_TCP_FLAGS:
1366 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1367 case RTE_FLOW_FIELD_UDP_PORT_DST:
1369 case RTE_FLOW_FIELD_VXLAN_VNI:
1370 case RTE_FLOW_FIELD_GENEVE_VNI:
1372 case RTE_FLOW_FIELD_GTP_TEID:
1373 case RTE_FLOW_FIELD_TAG:
1375 case RTE_FLOW_FIELD_MARK:
1377 case RTE_FLOW_FIELD_META:
1379 case RTE_FLOW_FIELD_POINTER:
1380 case RTE_FLOW_FIELD_VALUE:
1389 mlx5_flow_field_id_to_modify_info
1390 (const struct rte_flow_action_modify_data *data,
1391 struct field_modify_info *info,
1392 uint32_t *mask, uint32_t *value,
1393 uint32_t width, uint32_t dst_width,
1394 struct rte_eth_dev *dev,
1395 const struct rte_flow_attr *attr,
1396 struct rte_flow_error *error)
1400 switch (data->field) {
1401 case RTE_FLOW_FIELD_START:
1402 /* not supported yet */
1405 case RTE_FLOW_FIELD_MAC_DST:
1407 if (data->offset < 32) {
1408 info[idx] = (struct field_modify_info){4, 0,
1409 MLX5_MODI_OUT_DMAC_47_16};
1412 rte_cpu_to_be_32(0xffffffff >>
1416 mask[idx] = RTE_BE32(0xffffffff);
1423 info[idx] = (struct field_modify_info){2, 4 * idx,
1424 MLX5_MODI_OUT_DMAC_15_0};
1425 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1427 if (data->offset < 32)
1428 info[idx++] = (struct field_modify_info){4, 0,
1429 MLX5_MODI_OUT_DMAC_47_16};
1430 info[idx] = (struct field_modify_info){2, 0,
1431 MLX5_MODI_OUT_DMAC_15_0};
1434 case RTE_FLOW_FIELD_MAC_SRC:
1436 if (data->offset < 32) {
1437 info[idx] = (struct field_modify_info){4, 0,
1438 MLX5_MODI_OUT_SMAC_47_16};
1441 rte_cpu_to_be_32(0xffffffff >>
1445 mask[idx] = RTE_BE32(0xffffffff);
1452 info[idx] = (struct field_modify_info){2, 4 * idx,
1453 MLX5_MODI_OUT_SMAC_15_0};
1454 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1456 if (data->offset < 32)
1457 info[idx++] = (struct field_modify_info){4, 0,
1458 MLX5_MODI_OUT_SMAC_47_16};
1459 info[idx] = (struct field_modify_info){2, 0,
1460 MLX5_MODI_OUT_SMAC_15_0};
1463 case RTE_FLOW_FIELD_VLAN_TYPE:
1464 /* not supported yet */
1466 case RTE_FLOW_FIELD_VLAN_ID:
1467 info[idx] = (struct field_modify_info){2, 0,
1468 MLX5_MODI_OUT_FIRST_VID};
1470 mask[idx] = rte_cpu_to_be_16(0x0fff >> (12 - width));
1472 case RTE_FLOW_FIELD_MAC_TYPE:
1473 info[idx] = (struct field_modify_info){2, 0,
1474 MLX5_MODI_OUT_ETHERTYPE};
1476 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1478 case RTE_FLOW_FIELD_IPV4_DSCP:
1479 info[idx] = (struct field_modify_info){1, 0,
1480 MLX5_MODI_OUT_IP_DSCP};
1482 mask[idx] = 0x3f >> (6 - width);
1484 case RTE_FLOW_FIELD_IPV4_TTL:
1485 info[idx] = (struct field_modify_info){1, 0,
1486 MLX5_MODI_OUT_IPV4_TTL};
1488 mask[idx] = 0xff >> (8 - width);
1490 case RTE_FLOW_FIELD_IPV4_SRC:
1491 info[idx] = (struct field_modify_info){4, 0,
1492 MLX5_MODI_OUT_SIPV4};
1494 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1497 case RTE_FLOW_FIELD_IPV4_DST:
1498 info[idx] = (struct field_modify_info){4, 0,
1499 MLX5_MODI_OUT_DIPV4};
1501 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1504 case RTE_FLOW_FIELD_IPV6_DSCP:
1505 info[idx] = (struct field_modify_info){1, 0,
1506 MLX5_MODI_OUT_IP_DSCP};
1508 mask[idx] = 0x3f >> (6 - width);
1510 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1511 info[idx] = (struct field_modify_info){1, 0,
1512 MLX5_MODI_OUT_IPV6_HOPLIMIT};
1514 mask[idx] = 0xff >> (8 - width);
1516 case RTE_FLOW_FIELD_IPV6_SRC:
1518 if (data->offset < 32) {
1519 info[idx] = (struct field_modify_info){4,
1521 MLX5_MODI_OUT_SIPV6_31_0};
1524 rte_cpu_to_be_32(0xffffffff >>
1528 mask[idx] = RTE_BE32(0xffffffff);
1535 if (data->offset < 64) {
1536 info[idx] = (struct field_modify_info){4,
1538 MLX5_MODI_OUT_SIPV6_63_32};
1541 rte_cpu_to_be_32(0xffffffff >>
1545 mask[idx] = RTE_BE32(0xffffffff);
1552 if (data->offset < 96) {
1553 info[idx] = (struct field_modify_info){4,
1555 MLX5_MODI_OUT_SIPV6_95_64};
1558 rte_cpu_to_be_32(0xffffffff >>
1562 mask[idx] = RTE_BE32(0xffffffff);
1569 info[idx] = (struct field_modify_info){4, 4 * idx,
1570 MLX5_MODI_OUT_SIPV6_127_96};
1571 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1574 if (data->offset < 32)
1575 info[idx++] = (struct field_modify_info){4, 0,
1576 MLX5_MODI_OUT_SIPV6_31_0};
1577 if (data->offset < 64)
1578 info[idx++] = (struct field_modify_info){4, 0,
1579 MLX5_MODI_OUT_SIPV6_63_32};
1580 if (data->offset < 96)
1581 info[idx++] = (struct field_modify_info){4, 0,
1582 MLX5_MODI_OUT_SIPV6_95_64};
1583 if (data->offset < 128)
1584 info[idx++] = (struct field_modify_info){4, 0,
1585 MLX5_MODI_OUT_SIPV6_127_96};
1588 case RTE_FLOW_FIELD_IPV6_DST:
1590 if (data->offset < 32) {
1591 info[idx] = (struct field_modify_info){4,
1593 MLX5_MODI_OUT_DIPV6_31_0};
1596 rte_cpu_to_be_32(0xffffffff >>
1600 mask[idx] = RTE_BE32(0xffffffff);
1607 if (data->offset < 64) {
1608 info[idx] = (struct field_modify_info){4,
1610 MLX5_MODI_OUT_DIPV6_63_32};
1613 rte_cpu_to_be_32(0xffffffff >>
1617 mask[idx] = RTE_BE32(0xffffffff);
1624 if (data->offset < 96) {
1625 info[idx] = (struct field_modify_info){4,
1627 MLX5_MODI_OUT_DIPV6_95_64};
1630 rte_cpu_to_be_32(0xffffffff >>
1634 mask[idx] = RTE_BE32(0xffffffff);
1641 info[idx] = (struct field_modify_info){4, 4 * idx,
1642 MLX5_MODI_OUT_DIPV6_127_96};
1643 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1646 if (data->offset < 32)
1647 info[idx++] = (struct field_modify_info){4, 0,
1648 MLX5_MODI_OUT_DIPV6_31_0};
1649 if (data->offset < 64)
1650 info[idx++] = (struct field_modify_info){4, 0,
1651 MLX5_MODI_OUT_DIPV6_63_32};
1652 if (data->offset < 96)
1653 info[idx++] = (struct field_modify_info){4, 0,
1654 MLX5_MODI_OUT_DIPV6_95_64};
1655 if (data->offset < 128)
1656 info[idx++] = (struct field_modify_info){4, 0,
1657 MLX5_MODI_OUT_DIPV6_127_96};
1660 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1661 info[idx] = (struct field_modify_info){2, 0,
1662 MLX5_MODI_OUT_TCP_SPORT};
1664 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1666 case RTE_FLOW_FIELD_TCP_PORT_DST:
1667 info[idx] = (struct field_modify_info){2, 0,
1668 MLX5_MODI_OUT_TCP_DPORT};
1670 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1672 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1673 info[idx] = (struct field_modify_info){4, 0,
1674 MLX5_MODI_OUT_TCP_SEQ_NUM};
1676 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1679 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1680 info[idx] = (struct field_modify_info){4, 0,
1681 MLX5_MODI_OUT_TCP_ACK_NUM};
1683 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1686 case RTE_FLOW_FIELD_TCP_FLAGS:
1687 info[idx] = (struct field_modify_info){1, 0,
1688 MLX5_MODI_OUT_TCP_FLAGS};
1690 mask[idx] = 0x3f >> (6 - width);
1692 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1693 info[idx] = (struct field_modify_info){2, 0,
1694 MLX5_MODI_OUT_UDP_SPORT};
1696 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1698 case RTE_FLOW_FIELD_UDP_PORT_DST:
1699 info[idx] = (struct field_modify_info){2, 0,
1700 MLX5_MODI_OUT_UDP_DPORT};
1702 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1704 case RTE_FLOW_FIELD_VXLAN_VNI:
1705 /* not supported yet */
1707 case RTE_FLOW_FIELD_GENEVE_VNI:
1708 /* not supported yet*/
1710 case RTE_FLOW_FIELD_GTP_TEID:
1711 info[idx] = (struct field_modify_info){4, 0,
1712 MLX5_MODI_GTP_TEID};
1714 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1717 case RTE_FLOW_FIELD_TAG:
1719 int reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1720 data->level, error);
1723 MLX5_ASSERT(reg != REG_NON);
1724 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1725 info[idx] = (struct field_modify_info){4, 0,
1729 rte_cpu_to_be_32(0xffffffff >>
1733 case RTE_FLOW_FIELD_MARK:
1735 int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1739 MLX5_ASSERT(reg != REG_NON);
1740 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1741 info[idx] = (struct field_modify_info){4, 0,
1745 rte_cpu_to_be_32(0xffffffff >>
1749 case RTE_FLOW_FIELD_META:
1751 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1754 MLX5_ASSERT(reg != REG_NON);
1755 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1756 info[idx] = (struct field_modify_info){4, 0,
1760 rte_cpu_to_be_32(0xffffffff >>
1764 case RTE_FLOW_FIELD_POINTER:
1765 case RTE_FLOW_FIELD_VALUE:
1766 if (data->field == RTE_FLOW_FIELD_POINTER)
1767 memcpy(&val, (void *)(uintptr_t)data->value,
1771 for (idx = 0; idx < MLX5_ACT_MAX_MOD_FIELDS; idx++) {
1773 if (dst_width > 16) {
1774 value[idx] = rte_cpu_to_be_32(val);
1776 } else if (dst_width > 8) {
1777 value[idx] = rte_cpu_to_be_16(val);
1780 value[idx] = (uint8_t)val;
1795 * Convert modify_field action to DV specification.
1798 * Pointer to the rte_eth_dev structure.
1799 * @param[in,out] resource
1800 * Pointer to the modify-header resource.
1802 * Pointer to action specification.
1804 * Attributes of flow that includes this item.
1806 * Pointer to the error structure.
1809 * 0 on success, a negative errno value otherwise and rte_errno is set.
1812 flow_dv_convert_action_modify_field
1813 (struct rte_eth_dev *dev,
1814 struct mlx5_flow_dv_modify_hdr_resource *resource,
1815 const struct rte_flow_action *action,
1816 const struct rte_flow_attr *attr,
1817 struct rte_flow_error *error)
1819 const struct rte_flow_action_modify_field *conf =
1820 (const struct rte_flow_action_modify_field *)(action->conf);
1821 struct rte_flow_item item;
1822 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1824 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1826 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1827 uint32_t value[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1829 uint32_t dst_width = mlx5_flow_item_field_width(conf->dst.field);
1831 if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1832 conf->src.field == RTE_FLOW_FIELD_VALUE) {
1833 type = MLX5_MODIFICATION_TYPE_SET;
1834 /** For SET fill the destination field (field) first. */
1835 mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1836 value, conf->width, dst_width, dev, attr, error);
1837 /** Then copy immediate value from source as per mask. */
1838 mlx5_flow_field_id_to_modify_info(&conf->src, dcopy, mask,
1839 value, conf->width, dst_width, dev, attr, error);
1842 type = MLX5_MODIFICATION_TYPE_COPY;
1843 /** For COPY fill the destination field (dcopy) without mask. */
1844 mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1845 value, conf->width, dst_width, dev, attr, error);
1846 /** Then construct the source field (field) with mask. */
1847 mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1848 value, conf->width, dst_width, dev, attr, error);
1851 return flow_dv_convert_modify_action(&item,
1852 field, dcopy, resource, type, error);
1856 * Validate MARK item.
1859 * Pointer to the rte_eth_dev structure.
1861 * Item specification.
1863 * Attributes of flow that includes this item.
1865 * Pointer to error structure.
1868 * 0 on success, a negative errno value otherwise and rte_errno is set.
1871 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1872 const struct rte_flow_item *item,
1873 const struct rte_flow_attr *attr __rte_unused,
1874 struct rte_flow_error *error)
1876 struct mlx5_priv *priv = dev->data->dev_private;
1877 struct mlx5_dev_config *config = &priv->config;
1878 const struct rte_flow_item_mark *spec = item->spec;
1879 const struct rte_flow_item_mark *mask = item->mask;
1880 const struct rte_flow_item_mark nic_mask = {
1881 .id = priv->sh->dv_mark_mask,
1885 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1886 return rte_flow_error_set(error, ENOTSUP,
1887 RTE_FLOW_ERROR_TYPE_ITEM, item,
1888 "extended metadata feature"
1890 if (!mlx5_flow_ext_mreg_supported(dev))
1891 return rte_flow_error_set(error, ENOTSUP,
1892 RTE_FLOW_ERROR_TYPE_ITEM, item,
1893 "extended metadata register"
1894 " isn't supported");
1896 return rte_flow_error_set(error, ENOTSUP,
1897 RTE_FLOW_ERROR_TYPE_ITEM, item,
1898 "extended metadata register"
1899 " isn't available");
1900 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1904 return rte_flow_error_set(error, EINVAL,
1905 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1907 "data cannot be empty");
1908 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1909 return rte_flow_error_set(error, EINVAL,
1910 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1912 "mark id exceeds the limit");
1916 return rte_flow_error_set(error, EINVAL,
1917 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1918 "mask cannot be zero");
1920 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1921 (const uint8_t *)&nic_mask,
1922 sizeof(struct rte_flow_item_mark),
1923 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1930 * Validate META item.
1933 * Pointer to the rte_eth_dev structure.
1935 * Item specification.
1937 * Attributes of flow that includes this item.
1939 * Pointer to error structure.
1942 * 0 on success, a negative errno value otherwise and rte_errno is set.
1945 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1946 const struct rte_flow_item *item,
1947 const struct rte_flow_attr *attr,
1948 struct rte_flow_error *error)
1950 struct mlx5_priv *priv = dev->data->dev_private;
1951 struct mlx5_dev_config *config = &priv->config;
1952 const struct rte_flow_item_meta *spec = item->spec;
1953 const struct rte_flow_item_meta *mask = item->mask;
1954 struct rte_flow_item_meta nic_mask = {
1961 return rte_flow_error_set(error, EINVAL,
1962 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1964 "data cannot be empty");
1965 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1966 if (!mlx5_flow_ext_mreg_supported(dev))
1967 return rte_flow_error_set(error, ENOTSUP,
1968 RTE_FLOW_ERROR_TYPE_ITEM, item,
1969 "extended metadata register"
1970 " isn't supported");
1971 reg = flow_dv_get_metadata_reg(dev, attr, error);
1975 return rte_flow_error_set(error, ENOTSUP,
1976 RTE_FLOW_ERROR_TYPE_ITEM, item,
1977 "unavalable extended metadata register");
1979 return rte_flow_error_set(error, ENOTSUP,
1980 RTE_FLOW_ERROR_TYPE_ITEM, item,
1984 nic_mask.data = priv->sh->dv_meta_mask;
1987 return rte_flow_error_set(error, ENOTSUP,
1988 RTE_FLOW_ERROR_TYPE_ITEM, item,
1989 "extended metadata feature "
1990 "should be enabled when "
1991 "meta item is requested "
1992 "with e-switch mode ");
1994 return rte_flow_error_set(error, ENOTSUP,
1995 RTE_FLOW_ERROR_TYPE_ITEM, item,
1996 "match on metadata for ingress "
1997 "is not supported in legacy "
2001 mask = &rte_flow_item_meta_mask;
2003 return rte_flow_error_set(error, EINVAL,
2004 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2005 "mask cannot be zero");
2007 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2008 (const uint8_t *)&nic_mask,
2009 sizeof(struct rte_flow_item_meta),
2010 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2015 * Validate TAG item.
2018 * Pointer to the rte_eth_dev structure.
2020 * Item specification.
2022 * Attributes of flow that includes this item.
2024 * Pointer to error structure.
2027 * 0 on success, a negative errno value otherwise and rte_errno is set.
2030 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2031 const struct rte_flow_item *item,
2032 const struct rte_flow_attr *attr __rte_unused,
2033 struct rte_flow_error *error)
2035 const struct rte_flow_item_tag *spec = item->spec;
2036 const struct rte_flow_item_tag *mask = item->mask;
2037 const struct rte_flow_item_tag nic_mask = {
2038 .data = RTE_BE32(UINT32_MAX),
2043 if (!mlx5_flow_ext_mreg_supported(dev))
2044 return rte_flow_error_set(error, ENOTSUP,
2045 RTE_FLOW_ERROR_TYPE_ITEM, item,
2046 "extensive metadata register"
2047 " isn't supported");
2049 return rte_flow_error_set(error, EINVAL,
2050 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2052 "data cannot be empty");
2054 mask = &rte_flow_item_tag_mask;
2056 return rte_flow_error_set(error, EINVAL,
2057 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2058 "mask cannot be zero");
2060 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2061 (const uint8_t *)&nic_mask,
2062 sizeof(struct rte_flow_item_tag),
2063 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2066 if (mask->index != 0xff)
2067 return rte_flow_error_set(error, EINVAL,
2068 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2069 "partial mask for tag index"
2070 " is not supported");
2071 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2074 MLX5_ASSERT(ret != REG_NON);
2079 * Validate vport item.
2082 * Pointer to the rte_eth_dev structure.
2084 * Item specification.
2086 * Attributes of flow that includes this item.
2087 * @param[in] item_flags
2088 * Bit-fields that holds the items detected until now.
2090 * Pointer to error structure.
2093 * 0 on success, a negative errno value otherwise and rte_errno is set.
2096 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2097 const struct rte_flow_item *item,
2098 const struct rte_flow_attr *attr,
2099 uint64_t item_flags,
2100 struct rte_flow_error *error)
2102 const struct rte_flow_item_port_id *spec = item->spec;
2103 const struct rte_flow_item_port_id *mask = item->mask;
2104 const struct rte_flow_item_port_id switch_mask = {
2107 struct mlx5_priv *esw_priv;
2108 struct mlx5_priv *dev_priv;
2111 if (!attr->transfer)
2112 return rte_flow_error_set(error, EINVAL,
2113 RTE_FLOW_ERROR_TYPE_ITEM,
2115 "match on port id is valid only"
2116 " when transfer flag is enabled");
2117 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2118 return rte_flow_error_set(error, ENOTSUP,
2119 RTE_FLOW_ERROR_TYPE_ITEM, item,
2120 "multiple source ports are not"
2123 mask = &switch_mask;
2124 if (mask->id != 0xffffffff)
2125 return rte_flow_error_set(error, ENOTSUP,
2126 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2128 "no support for partial mask on"
2130 ret = mlx5_flow_item_acceptable
2131 (item, (const uint8_t *)mask,
2132 (const uint8_t *)&rte_flow_item_port_id_mask,
2133 sizeof(struct rte_flow_item_port_id),
2134 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2139 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2141 return rte_flow_error_set(error, rte_errno,
2142 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2143 "failed to obtain E-Switch info for"
2145 dev_priv = mlx5_dev_to_eswitch_info(dev);
2147 return rte_flow_error_set(error, rte_errno,
2148 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2150 "failed to obtain E-Switch info");
2151 if (esw_priv->domain_id != dev_priv->domain_id)
2152 return rte_flow_error_set(error, EINVAL,
2153 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2154 "cannot match on a port from a"
2155 " different E-Switch");
2160 * Validate VLAN item.
2163 * Item specification.
2164 * @param[in] item_flags
2165 * Bit-fields that holds the items detected until now.
2167 * Ethernet device flow is being created on.
2169 * Pointer to error structure.
2172 * 0 on success, a negative errno value otherwise and rte_errno is set.
2175 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2176 uint64_t item_flags,
2177 struct rte_eth_dev *dev,
2178 struct rte_flow_error *error)
2180 const struct rte_flow_item_vlan *mask = item->mask;
2181 const struct rte_flow_item_vlan nic_mask = {
2182 .tci = RTE_BE16(UINT16_MAX),
2183 .inner_type = RTE_BE16(UINT16_MAX),
2186 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2188 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2189 MLX5_FLOW_LAYER_INNER_L4) :
2190 (MLX5_FLOW_LAYER_OUTER_L3 |
2191 MLX5_FLOW_LAYER_OUTER_L4);
2192 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2193 MLX5_FLOW_LAYER_OUTER_VLAN;
2195 if (item_flags & vlanm)
2196 return rte_flow_error_set(error, EINVAL,
2197 RTE_FLOW_ERROR_TYPE_ITEM, item,
2198 "multiple VLAN layers not supported");
2199 else if ((item_flags & l34m) != 0)
2200 return rte_flow_error_set(error, EINVAL,
2201 RTE_FLOW_ERROR_TYPE_ITEM, item,
2202 "VLAN cannot follow L3/L4 layer");
2204 mask = &rte_flow_item_vlan_mask;
2205 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2206 (const uint8_t *)&nic_mask,
2207 sizeof(struct rte_flow_item_vlan),
2208 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2211 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2212 struct mlx5_priv *priv = dev->data->dev_private;
2214 if (priv->vmwa_context) {
2216 * Non-NULL context means we have a virtual machine
2217 * and SR-IOV enabled, we have to create VLAN interface
2218 * to make hypervisor to setup E-Switch vport
2219 * context correctly. We avoid creating the multiple
2220 * VLAN interfaces, so we cannot support VLAN tag mask.
2222 return rte_flow_error_set(error, EINVAL,
2223 RTE_FLOW_ERROR_TYPE_ITEM,
2225 "VLAN tag mask is not"
2226 " supported in virtual"
2234 * GTP flags are contained in 1 byte of the format:
2235 * -------------------------------------------
2236 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2237 * |-----------------------------------------|
2238 * | value | Version | PT | Res | E | S | PN |
2239 * -------------------------------------------
2241 * Matching is supported only for GTP flags E, S, PN.
2243 #define MLX5_GTP_FLAGS_MASK 0x07
2246 * Validate GTP item.
2249 * Pointer to the rte_eth_dev structure.
2251 * Item specification.
2252 * @param[in] item_flags
2253 * Bit-fields that holds the items detected until now.
2255 * Pointer to error structure.
2258 * 0 on success, a negative errno value otherwise and rte_errno is set.
2261 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2262 const struct rte_flow_item *item,
2263 uint64_t item_flags,
2264 struct rte_flow_error *error)
2266 struct mlx5_priv *priv = dev->data->dev_private;
2267 const struct rte_flow_item_gtp *spec = item->spec;
2268 const struct rte_flow_item_gtp *mask = item->mask;
2269 const struct rte_flow_item_gtp nic_mask = {
2270 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
2272 .teid = RTE_BE32(0xffffffff),
2275 if (!priv->config.hca_attr.tunnel_stateless_gtp)
2276 return rte_flow_error_set(error, ENOTSUP,
2277 RTE_FLOW_ERROR_TYPE_ITEM, item,
2278 "GTP support is not enabled");
2279 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2280 return rte_flow_error_set(error, ENOTSUP,
2281 RTE_FLOW_ERROR_TYPE_ITEM, item,
2282 "multiple tunnel layers not"
2284 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2285 return rte_flow_error_set(error, EINVAL,
2286 RTE_FLOW_ERROR_TYPE_ITEM, item,
2287 "no outer UDP layer found");
2289 mask = &rte_flow_item_gtp_mask;
2290 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
2291 return rte_flow_error_set(error, ENOTSUP,
2292 RTE_FLOW_ERROR_TYPE_ITEM, item,
2293 "Match is supported for GTP"
2295 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2296 (const uint8_t *)&nic_mask,
2297 sizeof(struct rte_flow_item_gtp),
2298 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2302 * Validate GTP PSC item.
2305 * Item specification.
2306 * @param[in] last_item
2307 * Previous validated item in the pattern items.
2308 * @param[in] gtp_item
2309 * Previous GTP item specification.
2311 * Pointer to flow attributes.
2313 * Pointer to error structure.
2316 * 0 on success, a negative errno value otherwise and rte_errno is set.
2319 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2321 const struct rte_flow_item *gtp_item,
2322 const struct rte_flow_attr *attr,
2323 struct rte_flow_error *error)
2325 const struct rte_flow_item_gtp *gtp_spec;
2326 const struct rte_flow_item_gtp *gtp_mask;
2327 const struct rte_flow_item_gtp_psc *spec;
2328 const struct rte_flow_item_gtp_psc *mask;
2329 const struct rte_flow_item_gtp_psc nic_mask = {
2334 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2335 return rte_flow_error_set
2336 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2337 "GTP PSC item must be preceded with GTP item");
2338 gtp_spec = gtp_item->spec;
2339 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2340 /* GTP spec and E flag is requested to match zero. */
2342 (gtp_mask->v_pt_rsv_flags &
2343 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
2344 return rte_flow_error_set
2345 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2346 "GTP E flag must be 1 to match GTP PSC");
2347 /* Check the flow is not created in group zero. */
2348 if (!attr->transfer && !attr->group)
2349 return rte_flow_error_set
2350 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2351 "GTP PSC is not supported for group 0");
2352 /* GTP spec is here and E flag is requested to match zero. */
2356 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2357 if (spec->pdu_type > MLX5_GTP_EXT_MAX_PDU_TYPE)
2358 return rte_flow_error_set
2359 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2360 "PDU type should be smaller than 16");
2361 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2362 (const uint8_t *)&nic_mask,
2363 sizeof(struct rte_flow_item_gtp_psc),
2364 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2368 * Validate IPV4 item.
2369 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2370 * add specific validation of fragment_offset field,
2373 * Item specification.
2374 * @param[in] item_flags
2375 * Bit-fields that holds the items detected until now.
2377 * Pointer to error structure.
2380 * 0 on success, a negative errno value otherwise and rte_errno is set.
2383 flow_dv_validate_item_ipv4(const struct rte_flow_item *item,
2384 uint64_t item_flags,
2386 uint16_t ether_type,
2387 struct rte_flow_error *error)
2390 const struct rte_flow_item_ipv4 *spec = item->spec;
2391 const struct rte_flow_item_ipv4 *last = item->last;
2392 const struct rte_flow_item_ipv4 *mask = item->mask;
2393 rte_be16_t fragment_offset_spec = 0;
2394 rte_be16_t fragment_offset_last = 0;
2395 const struct rte_flow_item_ipv4 nic_ipv4_mask = {
2397 .src_addr = RTE_BE32(0xffffffff),
2398 .dst_addr = RTE_BE32(0xffffffff),
2399 .type_of_service = 0xff,
2400 .fragment_offset = RTE_BE16(0xffff),
2401 .next_proto_id = 0xff,
2402 .time_to_live = 0xff,
2406 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2407 ether_type, &nic_ipv4_mask,
2408 MLX5_ITEM_RANGE_ACCEPTED, error);
2412 fragment_offset_spec = spec->hdr.fragment_offset &
2413 mask->hdr.fragment_offset;
2414 if (!fragment_offset_spec)
2417 * spec and mask are valid, enforce using full mask to make sure the
2418 * complete value is used correctly.
2420 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2421 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2422 return rte_flow_error_set(error, EINVAL,
2423 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2424 item, "must use full mask for"
2425 " fragment_offset");
2427 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2428 * indicating this is 1st fragment of fragmented packet.
2429 * This is not yet supported in MLX5, return appropriate error message.
2431 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2432 return rte_flow_error_set(error, ENOTSUP,
2433 RTE_FLOW_ERROR_TYPE_ITEM, item,
2434 "match on first fragment not "
2436 if (fragment_offset_spec && !last)
2437 return rte_flow_error_set(error, ENOTSUP,
2438 RTE_FLOW_ERROR_TYPE_ITEM, item,
2439 "specified value not supported");
2440 /* spec and last are valid, validate the specified range. */
2441 fragment_offset_last = last->hdr.fragment_offset &
2442 mask->hdr.fragment_offset;
2444 * Match on fragment_offset spec 0x2001 and last 0x3fff
2445 * means MF is 1 and frag-offset is > 0.
2446 * This packet is fragment 2nd and onward, excluding last.
2447 * This is not yet supported in MLX5, return appropriate
2450 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2451 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2452 return rte_flow_error_set(error, ENOTSUP,
2453 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2454 last, "match on following "
2455 "fragments not supported");
2457 * Match on fragment_offset spec 0x0001 and last 0x1fff
2458 * means MF is 0 and frag-offset is > 0.
2459 * This packet is last fragment of fragmented packet.
2460 * This is not yet supported in MLX5, return appropriate
2463 if (fragment_offset_spec == RTE_BE16(1) &&
2464 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2465 return rte_flow_error_set(error, ENOTSUP,
2466 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2467 last, "match on last "
2468 "fragment not supported");
2470 * Match on fragment_offset spec 0x0001 and last 0x3fff
2471 * means MF and/or frag-offset is not 0.
2472 * This is a fragmented packet.
2473 * Other range values are invalid and rejected.
2475 if (!(fragment_offset_spec == RTE_BE16(1) &&
2476 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2477 return rte_flow_error_set(error, ENOTSUP,
2478 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2479 "specified range not supported");
2484 * Validate IPV6 fragment extension item.
2487 * Item specification.
2488 * @param[in] item_flags
2489 * Bit-fields that holds the items detected until now.
2491 * Pointer to error structure.
2494 * 0 on success, a negative errno value otherwise and rte_errno is set.
2497 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2498 uint64_t item_flags,
2499 struct rte_flow_error *error)
2501 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2502 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2503 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2504 rte_be16_t frag_data_spec = 0;
2505 rte_be16_t frag_data_last = 0;
2506 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2507 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2508 MLX5_FLOW_LAYER_OUTER_L4;
2510 struct rte_flow_item_ipv6_frag_ext nic_mask = {
2512 .next_header = 0xff,
2513 .frag_data = RTE_BE16(0xffff),
2517 if (item_flags & l4m)
2518 return rte_flow_error_set(error, EINVAL,
2519 RTE_FLOW_ERROR_TYPE_ITEM, item,
2520 "ipv6 fragment extension item cannot "
2522 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
2523 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2524 return rte_flow_error_set(error, EINVAL,
2525 RTE_FLOW_ERROR_TYPE_ITEM, item,
2526 "ipv6 fragment extension item must "
2527 "follow ipv6 item");
2529 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2530 if (!frag_data_spec)
2533 * spec and mask are valid, enforce using full mask to make sure the
2534 * complete value is used correctly.
2536 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2537 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2538 return rte_flow_error_set(error, EINVAL,
2539 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2540 item, "must use full mask for"
2543 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2544 * This is 1st fragment of fragmented packet.
2546 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2547 return rte_flow_error_set(error, ENOTSUP,
2548 RTE_FLOW_ERROR_TYPE_ITEM, item,
2549 "match on first fragment not "
2551 if (frag_data_spec && !last)
2552 return rte_flow_error_set(error, EINVAL,
2553 RTE_FLOW_ERROR_TYPE_ITEM, item,
2554 "specified value not supported");
2555 ret = mlx5_flow_item_acceptable
2556 (item, (const uint8_t *)mask,
2557 (const uint8_t *)&nic_mask,
2558 sizeof(struct rte_flow_item_ipv6_frag_ext),
2559 MLX5_ITEM_RANGE_ACCEPTED, error);
2562 /* spec and last are valid, validate the specified range. */
2563 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2565 * Match on frag_data spec 0x0009 and last 0xfff9
2566 * means M is 1 and frag-offset is > 0.
2567 * This packet is fragment 2nd and onward, excluding last.
2568 * This is not yet supported in MLX5, return appropriate
2571 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2572 RTE_IPV6_EHDR_MF_MASK) &&
2573 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2574 return rte_flow_error_set(error, ENOTSUP,
2575 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2576 last, "match on following "
2577 "fragments not supported");
2579 * Match on frag_data spec 0x0008 and last 0xfff8
2580 * means M is 0 and frag-offset is > 0.
2581 * This packet is last fragment of fragmented packet.
2582 * This is not yet supported in MLX5, return appropriate
2585 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2586 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2587 return rte_flow_error_set(error, ENOTSUP,
2588 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2589 last, "match on last "
2590 "fragment not supported");
2591 /* Other range values are invalid and rejected. */
2592 return rte_flow_error_set(error, EINVAL,
2593 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2594 "specified range not supported");
2598 * Validate the pop VLAN action.
2601 * Pointer to the rte_eth_dev structure.
2602 * @param[in] action_flags
2603 * Holds the actions detected until now.
2605 * Pointer to the pop vlan action.
2606 * @param[in] item_flags
2607 * The items found in this flow rule.
2609 * Pointer to flow attributes.
2611 * Pointer to error structure.
2614 * 0 on success, a negative errno value otherwise and rte_errno is set.
2617 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2618 uint64_t action_flags,
2619 const struct rte_flow_action *action,
2620 uint64_t item_flags,
2621 const struct rte_flow_attr *attr,
2622 struct rte_flow_error *error)
2624 const struct mlx5_priv *priv = dev->data->dev_private;
2628 if (!priv->sh->pop_vlan_action)
2629 return rte_flow_error_set(error, ENOTSUP,
2630 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2632 "pop vlan action is not supported");
2634 return rte_flow_error_set(error, ENOTSUP,
2635 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2637 "pop vlan action not supported for "
2639 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2640 return rte_flow_error_set(error, ENOTSUP,
2641 RTE_FLOW_ERROR_TYPE_ACTION, action,
2642 "no support for multiple VLAN "
2644 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2645 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2646 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2647 return rte_flow_error_set(error, ENOTSUP,
2648 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2650 "cannot pop vlan after decap without "
2651 "match on inner vlan in the flow");
2652 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2653 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2654 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2655 return rte_flow_error_set(error, ENOTSUP,
2656 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2658 "cannot pop vlan without a "
2659 "match on (outer) vlan in the flow");
2660 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2661 return rte_flow_error_set(error, EINVAL,
2662 RTE_FLOW_ERROR_TYPE_ACTION, action,
2663 "wrong action order, port_id should "
2664 "be after pop VLAN action");
2665 if (!attr->transfer && priv->representor)
2666 return rte_flow_error_set(error, ENOTSUP,
2667 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2668 "pop vlan action for VF representor "
2669 "not supported on NIC table");
2674 * Get VLAN default info from vlan match info.
2677 * the list of item specifications.
2679 * pointer VLAN info to fill to.
2682 * 0 on success, a negative errno value otherwise and rte_errno is set.
2685 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2686 struct rte_vlan_hdr *vlan)
2688 const struct rte_flow_item_vlan nic_mask = {
2689 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2690 MLX5DV_FLOW_VLAN_VID_MASK),
2691 .inner_type = RTE_BE16(0xffff),
2696 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2697 int type = items->type;
2699 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2700 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2703 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2704 const struct rte_flow_item_vlan *vlan_m = items->mask;
2705 const struct rte_flow_item_vlan *vlan_v = items->spec;
2707 /* If VLAN item in pattern doesn't contain data, return here. */
2712 /* Only full match values are accepted */
2713 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2714 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2715 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2717 rte_be_to_cpu_16(vlan_v->tci &
2718 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2720 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2721 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2722 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2724 rte_be_to_cpu_16(vlan_v->tci &
2725 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2727 if (vlan_m->inner_type == nic_mask.inner_type)
2728 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2729 vlan_m->inner_type);
2734 * Validate the push VLAN action.
2737 * Pointer to the rte_eth_dev structure.
2738 * @param[in] action_flags
2739 * Holds the actions detected until now.
2740 * @param[in] item_flags
2741 * The items found in this flow rule.
2743 * Pointer to the action structure.
2745 * Pointer to flow attributes
2747 * Pointer to error structure.
2750 * 0 on success, a negative errno value otherwise and rte_errno is set.
2753 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2754 uint64_t action_flags,
2755 const struct rte_flow_item_vlan *vlan_m,
2756 const struct rte_flow_action *action,
2757 const struct rte_flow_attr *attr,
2758 struct rte_flow_error *error)
2760 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2761 const struct mlx5_priv *priv = dev->data->dev_private;
2763 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2764 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2765 return rte_flow_error_set(error, EINVAL,
2766 RTE_FLOW_ERROR_TYPE_ACTION, action,
2767 "invalid vlan ethertype");
2768 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2769 return rte_flow_error_set(error, EINVAL,
2770 RTE_FLOW_ERROR_TYPE_ACTION, action,
2771 "wrong action order, port_id should "
2772 "be after push VLAN");
2773 if (!attr->transfer && priv->representor)
2774 return rte_flow_error_set(error, ENOTSUP,
2775 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2776 "push vlan action for VF representor "
2777 "not supported on NIC table");
2779 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2780 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2781 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2782 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2783 !(mlx5_flow_find_action
2784 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2785 return rte_flow_error_set(error, EINVAL,
2786 RTE_FLOW_ERROR_TYPE_ACTION, action,
2787 "not full match mask on VLAN PCP and "
2788 "there is no of_set_vlan_pcp action, "
2789 "push VLAN action cannot figure out "
2792 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2793 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2794 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2795 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2796 !(mlx5_flow_find_action
2797 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2798 return rte_flow_error_set(error, EINVAL,
2799 RTE_FLOW_ERROR_TYPE_ACTION, action,
2800 "not full match mask on VLAN VID and "
2801 "there is no of_set_vlan_vid action, "
2802 "push VLAN action cannot figure out "
2809 * Validate the set VLAN PCP.
2811 * @param[in] action_flags
2812 * Holds the actions detected until now.
2813 * @param[in] actions
2814 * Pointer to the list of actions remaining in the flow rule.
2816 * Pointer to error structure.
2819 * 0 on success, a negative errno value otherwise and rte_errno is set.
2822 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2823 const struct rte_flow_action actions[],
2824 struct rte_flow_error *error)
2826 const struct rte_flow_action *action = actions;
2827 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2829 if (conf->vlan_pcp > 7)
2830 return rte_flow_error_set(error, EINVAL,
2831 RTE_FLOW_ERROR_TYPE_ACTION, action,
2832 "VLAN PCP value is too big");
2833 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2834 return rte_flow_error_set(error, ENOTSUP,
2835 RTE_FLOW_ERROR_TYPE_ACTION, action,
2836 "set VLAN PCP action must follow "
2837 "the push VLAN action");
2838 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2839 return rte_flow_error_set(error, ENOTSUP,
2840 RTE_FLOW_ERROR_TYPE_ACTION, action,
2841 "Multiple VLAN PCP modification are "
2843 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2844 return rte_flow_error_set(error, EINVAL,
2845 RTE_FLOW_ERROR_TYPE_ACTION, action,
2846 "wrong action order, port_id should "
2847 "be after set VLAN PCP");
2852 * Validate the set VLAN VID.
2854 * @param[in] item_flags
2855 * Holds the items detected in this rule.
2856 * @param[in] action_flags
2857 * Holds the actions detected until now.
2858 * @param[in] actions
2859 * Pointer to the list of actions remaining in the flow rule.
2861 * Pointer to error structure.
2864 * 0 on success, a negative errno value otherwise and rte_errno is set.
2867 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2868 uint64_t action_flags,
2869 const struct rte_flow_action actions[],
2870 struct rte_flow_error *error)
2872 const struct rte_flow_action *action = actions;
2873 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
2875 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
2876 return rte_flow_error_set(error, EINVAL,
2877 RTE_FLOW_ERROR_TYPE_ACTION, action,
2878 "VLAN VID value is too big");
2879 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
2880 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2881 return rte_flow_error_set(error, ENOTSUP,
2882 RTE_FLOW_ERROR_TYPE_ACTION, action,
2883 "set VLAN VID action must follow push"
2884 " VLAN action or match on VLAN item");
2885 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
2886 return rte_flow_error_set(error, ENOTSUP,
2887 RTE_FLOW_ERROR_TYPE_ACTION, action,
2888 "Multiple VLAN VID modifications are "
2890 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2891 return rte_flow_error_set(error, EINVAL,
2892 RTE_FLOW_ERROR_TYPE_ACTION, action,
2893 "wrong action order, port_id should "
2894 "be after set VLAN VID");
2899 * Validate the FLAG action.
2902 * Pointer to the rte_eth_dev structure.
2903 * @param[in] action_flags
2904 * Holds the actions detected until now.
2906 * Pointer to flow attributes
2908 * Pointer to error structure.
2911 * 0 on success, a negative errno value otherwise and rte_errno is set.
2914 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
2915 uint64_t action_flags,
2916 const struct rte_flow_attr *attr,
2917 struct rte_flow_error *error)
2919 struct mlx5_priv *priv = dev->data->dev_private;
2920 struct mlx5_dev_config *config = &priv->config;
2923 /* Fall back if no extended metadata register support. */
2924 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2925 return mlx5_flow_validate_action_flag(action_flags, attr,
2927 /* Extensive metadata mode requires registers. */
2928 if (!mlx5_flow_ext_mreg_supported(dev))
2929 return rte_flow_error_set(error, ENOTSUP,
2930 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2931 "no metadata registers "
2932 "to support flag action");
2933 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
2934 return rte_flow_error_set(error, ENOTSUP,
2935 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2936 "extended metadata register"
2937 " isn't available");
2938 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2941 MLX5_ASSERT(ret > 0);
2942 if (action_flags & MLX5_FLOW_ACTION_MARK)
2943 return rte_flow_error_set(error, EINVAL,
2944 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2945 "can't mark and flag in same flow");
2946 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2947 return rte_flow_error_set(error, EINVAL,
2948 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2950 " actions in same flow");
2955 * Validate MARK action.
2958 * Pointer to the rte_eth_dev structure.
2960 * Pointer to action.
2961 * @param[in] action_flags
2962 * Holds the actions detected until now.
2964 * Pointer to flow attributes
2966 * Pointer to error structure.
2969 * 0 on success, a negative errno value otherwise and rte_errno is set.
2972 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
2973 const struct rte_flow_action *action,
2974 uint64_t action_flags,
2975 const struct rte_flow_attr *attr,
2976 struct rte_flow_error *error)
2978 struct mlx5_priv *priv = dev->data->dev_private;
2979 struct mlx5_dev_config *config = &priv->config;
2980 const struct rte_flow_action_mark *mark = action->conf;
2983 if (is_tunnel_offload_active(dev))
2984 return rte_flow_error_set(error, ENOTSUP,
2985 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2987 "if tunnel offload active");
2988 /* Fall back if no extended metadata register support. */
2989 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2990 return mlx5_flow_validate_action_mark(action, action_flags,
2992 /* Extensive metadata mode requires registers. */
2993 if (!mlx5_flow_ext_mreg_supported(dev))
2994 return rte_flow_error_set(error, ENOTSUP,
2995 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2996 "no metadata registers "
2997 "to support mark action");
2998 if (!priv->sh->dv_mark_mask)
2999 return rte_flow_error_set(error, ENOTSUP,
3000 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3001 "extended metadata register"
3002 " isn't available");
3003 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3006 MLX5_ASSERT(ret > 0);
3008 return rte_flow_error_set(error, EINVAL,
3009 RTE_FLOW_ERROR_TYPE_ACTION, action,
3010 "configuration cannot be null");
3011 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3012 return rte_flow_error_set(error, EINVAL,
3013 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3015 "mark id exceeds the limit");
3016 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3017 return rte_flow_error_set(error, EINVAL,
3018 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3019 "can't flag and mark in same flow");
3020 if (action_flags & MLX5_FLOW_ACTION_MARK)
3021 return rte_flow_error_set(error, EINVAL,
3022 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3023 "can't have 2 mark actions in same"
3029 * Validate SET_META action.
3032 * Pointer to the rte_eth_dev structure.
3034 * Pointer to the action structure.
3035 * @param[in] action_flags
3036 * Holds the actions detected until now.
3038 * Pointer to flow attributes
3040 * Pointer to error structure.
3043 * 0 on success, a negative errno value otherwise and rte_errno is set.
3046 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3047 const struct rte_flow_action *action,
3048 uint64_t action_flags __rte_unused,
3049 const struct rte_flow_attr *attr,
3050 struct rte_flow_error *error)
3052 const struct rte_flow_action_set_meta *conf;
3053 uint32_t nic_mask = UINT32_MAX;
3056 if (!mlx5_flow_ext_mreg_supported(dev))
3057 return rte_flow_error_set(error, ENOTSUP,
3058 RTE_FLOW_ERROR_TYPE_ACTION, action,
3059 "extended metadata register"
3060 " isn't supported");
3061 reg = flow_dv_get_metadata_reg(dev, attr, error);
3065 return rte_flow_error_set(error, ENOTSUP,
3066 RTE_FLOW_ERROR_TYPE_ACTION, action,
3067 "unavalable extended metadata register");
3068 if (reg != REG_A && reg != REG_B) {
3069 struct mlx5_priv *priv = dev->data->dev_private;
3071 nic_mask = priv->sh->dv_meta_mask;
3073 if (!(action->conf))
3074 return rte_flow_error_set(error, EINVAL,
3075 RTE_FLOW_ERROR_TYPE_ACTION, action,
3076 "configuration cannot be null");
3077 conf = (const struct rte_flow_action_set_meta *)action->conf;
3079 return rte_flow_error_set(error, EINVAL,
3080 RTE_FLOW_ERROR_TYPE_ACTION, action,
3081 "zero mask doesn't have any effect");
3082 if (conf->mask & ~nic_mask)
3083 return rte_flow_error_set(error, EINVAL,
3084 RTE_FLOW_ERROR_TYPE_ACTION, action,
3085 "meta data must be within reg C0");
3090 * Validate SET_TAG action.
3093 * Pointer to the rte_eth_dev structure.
3095 * Pointer to the action structure.
3096 * @param[in] action_flags
3097 * Holds the actions detected until now.
3099 * Pointer to flow attributes
3101 * Pointer to error structure.
3104 * 0 on success, a negative errno value otherwise and rte_errno is set.
3107 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3108 const struct rte_flow_action *action,
3109 uint64_t action_flags,
3110 const struct rte_flow_attr *attr,
3111 struct rte_flow_error *error)
3113 const struct rte_flow_action_set_tag *conf;
3114 const uint64_t terminal_action_flags =
3115 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3116 MLX5_FLOW_ACTION_RSS;
3119 if (!mlx5_flow_ext_mreg_supported(dev))
3120 return rte_flow_error_set(error, ENOTSUP,
3121 RTE_FLOW_ERROR_TYPE_ACTION, action,
3122 "extensive metadata register"
3123 " isn't supported");
3124 if (!(action->conf))
3125 return rte_flow_error_set(error, EINVAL,
3126 RTE_FLOW_ERROR_TYPE_ACTION, action,
3127 "configuration cannot be null");
3128 conf = (const struct rte_flow_action_set_tag *)action->conf;
3130 return rte_flow_error_set(error, EINVAL,
3131 RTE_FLOW_ERROR_TYPE_ACTION, action,
3132 "zero mask doesn't have any effect");
3133 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3136 if (!attr->transfer && attr->ingress &&
3137 (action_flags & terminal_action_flags))
3138 return rte_flow_error_set(error, EINVAL,
3139 RTE_FLOW_ERROR_TYPE_ACTION, action,
3140 "set_tag has no effect"
3141 " with terminal actions");
3146 * Validate count action.
3149 * Pointer to rte_eth_dev structure.
3151 * Pointer to the action structure.
3152 * @param[in] action_flags
3153 * Holds the actions detected until now.
3155 * Pointer to error structure.
3158 * 0 on success, a negative errno value otherwise and rte_errno is set.
3161 flow_dv_validate_action_count(struct rte_eth_dev *dev,
3162 const struct rte_flow_action *action,
3163 uint64_t action_flags,
3164 struct rte_flow_error *error)
3166 struct mlx5_priv *priv = dev->data->dev_private;
3167 const struct rte_flow_action_count *count;
3169 if (!priv->config.devx)
3171 if (action_flags & MLX5_FLOW_ACTION_COUNT)
3172 return rte_flow_error_set(error, EINVAL,
3173 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3174 "duplicate count actions set");
3175 count = (const struct rte_flow_action_count *)action->conf;
3176 if (count && count->shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
3177 !priv->sh->flow_hit_aso_en)
3178 return rte_flow_error_set(error, EINVAL,
3179 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3180 "old age and shared count combination is not supported");
3181 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3185 return rte_flow_error_set
3187 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3189 "count action not supported");
3193 * Validate the L2 encap action.
3196 * Pointer to the rte_eth_dev structure.
3197 * @param[in] action_flags
3198 * Holds the actions detected until now.
3200 * Pointer to the action structure.
3202 * Pointer to flow attributes.
3204 * Pointer to error structure.
3207 * 0 on success, a negative errno value otherwise and rte_errno is set.
3210 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3211 uint64_t action_flags,
3212 const struct rte_flow_action *action,
3213 const struct rte_flow_attr *attr,
3214 struct rte_flow_error *error)
3216 const struct mlx5_priv *priv = dev->data->dev_private;
3218 if (!(action->conf))
3219 return rte_flow_error_set(error, EINVAL,
3220 RTE_FLOW_ERROR_TYPE_ACTION, action,
3221 "configuration cannot be null");
3222 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3223 return rte_flow_error_set(error, EINVAL,
3224 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3225 "can only have a single encap action "
3227 if (!attr->transfer && priv->representor)
3228 return rte_flow_error_set(error, ENOTSUP,
3229 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3230 "encap action for VF representor "
3231 "not supported on NIC table");
3236 * Validate a decap action.
3239 * Pointer to the rte_eth_dev structure.
3240 * @param[in] action_flags
3241 * Holds the actions detected until now.
3243 * Pointer to the action structure.
3244 * @param[in] item_flags
3245 * Holds the items detected.
3247 * Pointer to flow attributes
3249 * Pointer to error structure.
3252 * 0 on success, a negative errno value otherwise and rte_errno is set.
3255 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3256 uint64_t action_flags,
3257 const struct rte_flow_action *action,
3258 const uint64_t item_flags,
3259 const struct rte_flow_attr *attr,
3260 struct rte_flow_error *error)
3262 const struct mlx5_priv *priv = dev->data->dev_private;
3264 if (priv->config.hca_attr.scatter_fcs_w_decap_disable &&
3265 !priv->config.decap_en)
3266 return rte_flow_error_set(error, ENOTSUP,
3267 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3268 "decap is not enabled");
3269 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3270 return rte_flow_error_set(error, ENOTSUP,
3271 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3273 MLX5_FLOW_ACTION_DECAP ? "can only "
3274 "have a single decap action" : "decap "
3275 "after encap is not supported");
3276 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3277 return rte_flow_error_set(error, EINVAL,
3278 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3279 "can't have decap action after"
3282 return rte_flow_error_set(error, ENOTSUP,
3283 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3285 "decap action not supported for "
3287 if (!attr->transfer && priv->representor)
3288 return rte_flow_error_set(error, ENOTSUP,
3289 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3290 "decap action for VF representor "
3291 "not supported on NIC table");
3292 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3293 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3294 return rte_flow_error_set(error, ENOTSUP,
3295 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3296 "VXLAN item should be present for VXLAN decap");
3300 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3303 * Validate the raw encap and decap actions.
3306 * Pointer to the rte_eth_dev structure.
3308 * Pointer to the decap action.
3310 * Pointer to the encap action.
3312 * Pointer to flow attributes
3313 * @param[in/out] action_flags
3314 * Holds the actions detected until now.
3315 * @param[out] actions_n
3316 * pointer to the number of actions counter.
3318 * Pointer to the action structure.
3319 * @param[in] item_flags
3320 * Holds the items detected.
3322 * Pointer to error structure.
3325 * 0 on success, a negative errno value otherwise and rte_errno is set.
3328 flow_dv_validate_action_raw_encap_decap
3329 (struct rte_eth_dev *dev,
3330 const struct rte_flow_action_raw_decap *decap,
3331 const struct rte_flow_action_raw_encap *encap,
3332 const struct rte_flow_attr *attr, uint64_t *action_flags,
3333 int *actions_n, const struct rte_flow_action *action,
3334 uint64_t item_flags, struct rte_flow_error *error)
3336 const struct mlx5_priv *priv = dev->data->dev_private;
3339 if (encap && (!encap->size || !encap->data))
3340 return rte_flow_error_set(error, EINVAL,
3341 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3342 "raw encap data cannot be empty");
3343 if (decap && encap) {
3344 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3345 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3348 else if (encap->size <=
3349 MLX5_ENCAPSULATION_DECISION_SIZE &&
3351 MLX5_ENCAPSULATION_DECISION_SIZE)
3354 else if (encap->size >
3355 MLX5_ENCAPSULATION_DECISION_SIZE &&
3357 MLX5_ENCAPSULATION_DECISION_SIZE)
3358 /* 2 L2 actions: encap and decap. */
3361 return rte_flow_error_set(error,
3363 RTE_FLOW_ERROR_TYPE_ACTION,
3364 NULL, "unsupported too small "
3365 "raw decap and too small raw "
3366 "encap combination");
3369 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3370 item_flags, attr, error);
3373 *action_flags |= MLX5_FLOW_ACTION_DECAP;
3377 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3378 return rte_flow_error_set(error, ENOTSUP,
3379 RTE_FLOW_ERROR_TYPE_ACTION,
3381 "small raw encap size");
3382 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3383 return rte_flow_error_set(error, EINVAL,
3384 RTE_FLOW_ERROR_TYPE_ACTION,
3386 "more than one encap action");
3387 if (!attr->transfer && priv->representor)
3388 return rte_flow_error_set
3390 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3391 "encap action for VF representor "
3392 "not supported on NIC table");
3393 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3400 * Match encap_decap resource.
3403 * Pointer to the hash list.
3405 * Pointer to exist resource entry object.
3407 * Key of the new entry.
3409 * Pointer to new encap_decap resource.
3412 * 0 on matching, none-zero otherwise.
3415 flow_dv_encap_decap_match_cb(struct mlx5_hlist *list __rte_unused,
3416 struct mlx5_hlist_entry *entry,
3417 uint64_t key __rte_unused, void *cb_ctx)
3419 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3420 struct mlx5_flow_dv_encap_decap_resource *resource = ctx->data;
3421 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3423 cache_resource = container_of(entry,
3424 struct mlx5_flow_dv_encap_decap_resource,
3426 if (resource->reformat_type == cache_resource->reformat_type &&
3427 resource->ft_type == cache_resource->ft_type &&
3428 resource->flags == cache_resource->flags &&
3429 resource->size == cache_resource->size &&
3430 !memcmp((const void *)resource->buf,
3431 (const void *)cache_resource->buf,
3438 * Allocate encap_decap resource.
3441 * Pointer to the hash list.
3443 * Pointer to exist resource entry object.
3445 * Pointer to new encap_decap resource.
3448 * 0 on matching, none-zero otherwise.
3450 struct mlx5_hlist_entry *
3451 flow_dv_encap_decap_create_cb(struct mlx5_hlist *list,
3452 uint64_t key __rte_unused,
3455 struct mlx5_dev_ctx_shared *sh = list->ctx;
3456 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3457 struct mlx5dv_dr_domain *domain;
3458 struct mlx5_flow_dv_encap_decap_resource *resource = ctx->data;
3459 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3463 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3464 domain = sh->fdb_domain;
3465 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3466 domain = sh->rx_domain;
3468 domain = sh->tx_domain;
3469 /* Register new encap/decap resource. */
3470 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
3472 if (!cache_resource) {
3473 rte_flow_error_set(ctx->error, ENOMEM,
3474 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3475 "cannot allocate resource memory");
3478 *cache_resource = *resource;
3479 cache_resource->idx = idx;
3480 ret = mlx5_flow_os_create_flow_action_packet_reformat
3481 (sh->ctx, domain, cache_resource,
3482 &cache_resource->action);
3484 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
3485 rte_flow_error_set(ctx->error, ENOMEM,
3486 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3487 NULL, "cannot create action");
3491 return &cache_resource->entry;
3495 * Find existing encap/decap resource or create and register a new one.
3497 * @param[in, out] dev
3498 * Pointer to rte_eth_dev structure.
3499 * @param[in, out] resource
3500 * Pointer to encap/decap resource.
3501 * @parm[in, out] dev_flow
3502 * Pointer to the dev_flow.
3504 * pointer to error structure.
3507 * 0 on success otherwise -errno and errno is set.
3510 flow_dv_encap_decap_resource_register
3511 (struct rte_eth_dev *dev,
3512 struct mlx5_flow_dv_encap_decap_resource *resource,
3513 struct mlx5_flow *dev_flow,
3514 struct rte_flow_error *error)
3516 struct mlx5_priv *priv = dev->data->dev_private;
3517 struct mlx5_dev_ctx_shared *sh = priv->sh;
3518 struct mlx5_hlist_entry *entry;
3522 uint32_t refmt_type:8;
3524 * Header reformat actions can be shared between
3525 * non-root tables. One bit to indicate non-root
3529 uint32_t reserve:15;
3532 } encap_decap_key = {
3534 .ft_type = resource->ft_type,
3535 .refmt_type = resource->reformat_type,
3536 .is_root = !!dev_flow->dv.group,
3540 struct mlx5_flow_cb_ctx ctx = {
3546 resource->flags = dev_flow->dv.group ? 0 : 1;
3547 key64 = __rte_raw_cksum(&encap_decap_key.v32,
3548 sizeof(encap_decap_key.v32), 0);
3549 if (resource->reformat_type !=
3550 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
3552 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
3553 entry = mlx5_hlist_register(sh->encaps_decaps, key64, &ctx);
3556 resource = container_of(entry, typeof(*resource), entry);
3557 dev_flow->dv.encap_decap = resource;
3558 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3563 * Find existing table jump resource or create and register a new one.
3565 * @param[in, out] dev
3566 * Pointer to rte_eth_dev structure.
3567 * @param[in, out] tbl
3568 * Pointer to flow table resource.
3569 * @parm[in, out] dev_flow
3570 * Pointer to the dev_flow.
3572 * pointer to error structure.
3575 * 0 on success otherwise -errno and errno is set.
3578 flow_dv_jump_tbl_resource_register
3579 (struct rte_eth_dev *dev __rte_unused,
3580 struct mlx5_flow_tbl_resource *tbl,
3581 struct mlx5_flow *dev_flow,
3582 struct rte_flow_error *error __rte_unused)
3584 struct mlx5_flow_tbl_data_entry *tbl_data =
3585 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3588 MLX5_ASSERT(tbl_data->jump.action);
3589 dev_flow->handle->rix_jump = tbl_data->idx;
3590 dev_flow->dv.jump = &tbl_data->jump;
3595 flow_dv_port_id_match_cb(struct mlx5_cache_list *list __rte_unused,
3596 struct mlx5_cache_entry *entry, void *cb_ctx)
3598 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3599 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3600 struct mlx5_flow_dv_port_id_action_resource *res =
3601 container_of(entry, typeof(*res), entry);
3603 return ref->port_id != res->port_id;
3606 struct mlx5_cache_entry *
3607 flow_dv_port_id_create_cb(struct mlx5_cache_list *list,
3608 struct mlx5_cache_entry *entry __rte_unused,
3611 struct mlx5_dev_ctx_shared *sh = list->ctx;
3612 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3613 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3614 struct mlx5_flow_dv_port_id_action_resource *cache;
3618 /* Register new port id action resource. */
3619 cache = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3621 rte_flow_error_set(ctx->error, ENOMEM,
3622 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3623 "cannot allocate port_id action cache memory");
3627 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3631 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3632 rte_flow_error_set(ctx->error, ENOMEM,
3633 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3634 "cannot create action");
3638 return &cache->entry;
3642 * Find existing table port ID resource or create and register a new one.
3644 * @param[in, out] dev
3645 * Pointer to rte_eth_dev structure.
3646 * @param[in, out] resource
3647 * Pointer to port ID action resource.
3648 * @parm[in, out] dev_flow
3649 * Pointer to the dev_flow.
3651 * pointer to error structure.
3654 * 0 on success otherwise -errno and errno is set.
3657 flow_dv_port_id_action_resource_register
3658 (struct rte_eth_dev *dev,
3659 struct mlx5_flow_dv_port_id_action_resource *resource,
3660 struct mlx5_flow *dev_flow,
3661 struct rte_flow_error *error)
3663 struct mlx5_priv *priv = dev->data->dev_private;
3664 struct mlx5_cache_entry *entry;
3665 struct mlx5_flow_dv_port_id_action_resource *cache;
3666 struct mlx5_flow_cb_ctx ctx = {
3671 entry = mlx5_cache_register(&priv->sh->port_id_action_list, &ctx);
3674 cache = container_of(entry, typeof(*cache), entry);
3675 dev_flow->dv.port_id_action = cache;
3676 dev_flow->handle->rix_port_id_action = cache->idx;
3681 flow_dv_push_vlan_match_cb(struct mlx5_cache_list *list __rte_unused,
3682 struct mlx5_cache_entry *entry, void *cb_ctx)
3684 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3685 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3686 struct mlx5_flow_dv_push_vlan_action_resource *res =
3687 container_of(entry, typeof(*res), entry);
3689 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
3692 struct mlx5_cache_entry *
3693 flow_dv_push_vlan_create_cb(struct mlx5_cache_list *list,
3694 struct mlx5_cache_entry *entry __rte_unused,
3697 struct mlx5_dev_ctx_shared *sh = list->ctx;
3698 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3699 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3700 struct mlx5_flow_dv_push_vlan_action_resource *cache;
3701 struct mlx5dv_dr_domain *domain;
3705 /* Register new port id action resource. */
3706 cache = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3708 rte_flow_error_set(ctx->error, ENOMEM,
3709 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3710 "cannot allocate push_vlan action cache memory");
3714 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3715 domain = sh->fdb_domain;
3716 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3717 domain = sh->rx_domain;
3719 domain = sh->tx_domain;
3720 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
3723 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
3724 rte_flow_error_set(ctx->error, ENOMEM,
3725 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3726 "cannot create push vlan action");
3730 return &cache->entry;
3734 * Find existing push vlan resource or create and register a new one.
3736 * @param [in, out] dev
3737 * Pointer to rte_eth_dev structure.
3738 * @param[in, out] resource
3739 * Pointer to port ID action resource.
3740 * @parm[in, out] dev_flow
3741 * Pointer to the dev_flow.
3743 * pointer to error structure.
3746 * 0 on success otherwise -errno and errno is set.
3749 flow_dv_push_vlan_action_resource_register
3750 (struct rte_eth_dev *dev,
3751 struct mlx5_flow_dv_push_vlan_action_resource *resource,
3752 struct mlx5_flow *dev_flow,
3753 struct rte_flow_error *error)
3755 struct mlx5_priv *priv = dev->data->dev_private;
3756 struct mlx5_flow_dv_push_vlan_action_resource *cache;
3757 struct mlx5_cache_entry *entry;
3758 struct mlx5_flow_cb_ctx ctx = {
3763 entry = mlx5_cache_register(&priv->sh->push_vlan_action_list, &ctx);
3766 cache = container_of(entry, typeof(*cache), entry);
3768 dev_flow->handle->dvh.rix_push_vlan = cache->idx;
3769 dev_flow->dv.push_vlan_res = cache;
3774 * Get the size of specific rte_flow_item_type hdr size
3776 * @param[in] item_type
3777 * Tested rte_flow_item_type.
3780 * sizeof struct item_type, 0 if void or irrelevant.
3783 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
3787 switch (item_type) {
3788 case RTE_FLOW_ITEM_TYPE_ETH:
3789 retval = sizeof(struct rte_ether_hdr);
3791 case RTE_FLOW_ITEM_TYPE_VLAN:
3792 retval = sizeof(struct rte_vlan_hdr);
3794 case RTE_FLOW_ITEM_TYPE_IPV4:
3795 retval = sizeof(struct rte_ipv4_hdr);
3797 case RTE_FLOW_ITEM_TYPE_IPV6:
3798 retval = sizeof(struct rte_ipv6_hdr);
3800 case RTE_FLOW_ITEM_TYPE_UDP:
3801 retval = sizeof(struct rte_udp_hdr);
3803 case RTE_FLOW_ITEM_TYPE_TCP:
3804 retval = sizeof(struct rte_tcp_hdr);
3806 case RTE_FLOW_ITEM_TYPE_VXLAN:
3807 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3808 retval = sizeof(struct rte_vxlan_hdr);
3810 case RTE_FLOW_ITEM_TYPE_GRE:
3811 case RTE_FLOW_ITEM_TYPE_NVGRE:
3812 retval = sizeof(struct rte_gre_hdr);
3814 case RTE_FLOW_ITEM_TYPE_MPLS:
3815 retval = sizeof(struct rte_mpls_hdr);
3817 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
3825 #define MLX5_ENCAP_IPV4_VERSION 0x40
3826 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
3827 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
3828 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
3829 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
3830 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
3831 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
3834 * Convert the encap action data from list of rte_flow_item to raw buffer
3837 * Pointer to rte_flow_item objects list.
3839 * Pointer to the output buffer.
3841 * Pointer to the output buffer size.
3843 * Pointer to the error structure.
3846 * 0 on success, a negative errno value otherwise and rte_errno is set.
3849 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
3850 size_t *size, struct rte_flow_error *error)
3852 struct rte_ether_hdr *eth = NULL;
3853 struct rte_vlan_hdr *vlan = NULL;
3854 struct rte_ipv4_hdr *ipv4 = NULL;
3855 struct rte_ipv6_hdr *ipv6 = NULL;
3856 struct rte_udp_hdr *udp = NULL;
3857 struct rte_vxlan_hdr *vxlan = NULL;
3858 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
3859 struct rte_gre_hdr *gre = NULL;
3861 size_t temp_size = 0;
3864 return rte_flow_error_set(error, EINVAL,
3865 RTE_FLOW_ERROR_TYPE_ACTION,
3866 NULL, "invalid empty data");
3867 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3868 len = flow_dv_get_item_hdr_len(items->type);
3869 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
3870 return rte_flow_error_set(error, EINVAL,
3871 RTE_FLOW_ERROR_TYPE_ACTION,
3872 (void *)items->type,
3873 "items total size is too big"
3874 " for encap action");
3875 rte_memcpy((void *)&buf[temp_size], items->spec, len);
3876 switch (items->type) {
3877 case RTE_FLOW_ITEM_TYPE_ETH:
3878 eth = (struct rte_ether_hdr *)&buf[temp_size];
3880 case RTE_FLOW_ITEM_TYPE_VLAN:
3881 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
3883 return rte_flow_error_set(error, EINVAL,
3884 RTE_FLOW_ERROR_TYPE_ACTION,
3885 (void *)items->type,
3886 "eth header not found");
3887 if (!eth->ether_type)
3888 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
3890 case RTE_FLOW_ITEM_TYPE_IPV4:
3891 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
3893 return rte_flow_error_set(error, EINVAL,
3894 RTE_FLOW_ERROR_TYPE_ACTION,
3895 (void *)items->type,
3896 "neither eth nor vlan"
3898 if (vlan && !vlan->eth_proto)
3899 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3900 else if (eth && !eth->ether_type)
3901 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3902 if (!ipv4->version_ihl)
3903 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
3904 MLX5_ENCAP_IPV4_IHL_MIN;
3905 if (!ipv4->time_to_live)
3906 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
3908 case RTE_FLOW_ITEM_TYPE_IPV6:
3909 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
3911 return rte_flow_error_set(error, EINVAL,
3912 RTE_FLOW_ERROR_TYPE_ACTION,
3913 (void *)items->type,
3914 "neither eth nor vlan"
3916 if (vlan && !vlan->eth_proto)
3917 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3918 else if (eth && !eth->ether_type)
3919 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3920 if (!ipv6->vtc_flow)
3922 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
3923 if (!ipv6->hop_limits)
3924 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
3926 case RTE_FLOW_ITEM_TYPE_UDP:
3927 udp = (struct rte_udp_hdr *)&buf[temp_size];
3929 return rte_flow_error_set(error, EINVAL,
3930 RTE_FLOW_ERROR_TYPE_ACTION,
3931 (void *)items->type,
3932 "ip header not found");
3933 if (ipv4 && !ipv4->next_proto_id)
3934 ipv4->next_proto_id = IPPROTO_UDP;
3935 else if (ipv6 && !ipv6->proto)
3936 ipv6->proto = IPPROTO_UDP;
3938 case RTE_FLOW_ITEM_TYPE_VXLAN:
3939 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
3941 return rte_flow_error_set(error, EINVAL,
3942 RTE_FLOW_ERROR_TYPE_ACTION,
3943 (void *)items->type,
3944 "udp header not found");
3946 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
3947 if (!vxlan->vx_flags)
3949 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
3951 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3952 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
3954 return rte_flow_error_set(error, EINVAL,
3955 RTE_FLOW_ERROR_TYPE_ACTION,
3956 (void *)items->type,
3957 "udp header not found");
3958 if (!vxlan_gpe->proto)
3959 return rte_flow_error_set(error, EINVAL,
3960 RTE_FLOW_ERROR_TYPE_ACTION,
3961 (void *)items->type,
3962 "next protocol not found");
3965 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
3966 if (!vxlan_gpe->vx_flags)
3967 vxlan_gpe->vx_flags =
3968 MLX5_ENCAP_VXLAN_GPE_FLAGS;
3970 case RTE_FLOW_ITEM_TYPE_GRE:
3971 case RTE_FLOW_ITEM_TYPE_NVGRE:
3972 gre = (struct rte_gre_hdr *)&buf[temp_size];
3974 return rte_flow_error_set(error, EINVAL,
3975 RTE_FLOW_ERROR_TYPE_ACTION,
3976 (void *)items->type,
3977 "next protocol not found");
3979 return rte_flow_error_set(error, EINVAL,
3980 RTE_FLOW_ERROR_TYPE_ACTION,
3981 (void *)items->type,
3982 "ip header not found");
3983 if (ipv4 && !ipv4->next_proto_id)
3984 ipv4->next_proto_id = IPPROTO_GRE;
3985 else if (ipv6 && !ipv6->proto)
3986 ipv6->proto = IPPROTO_GRE;
3988 case RTE_FLOW_ITEM_TYPE_VOID:
3991 return rte_flow_error_set(error, EINVAL,
3992 RTE_FLOW_ERROR_TYPE_ACTION,
3993 (void *)items->type,
3994 "unsupported item type");
4004 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4006 struct rte_ether_hdr *eth = NULL;
4007 struct rte_vlan_hdr *vlan = NULL;
4008 struct rte_ipv6_hdr *ipv6 = NULL;
4009 struct rte_udp_hdr *udp = NULL;
4013 eth = (struct rte_ether_hdr *)data;
4014 next_hdr = (char *)(eth + 1);
4015 proto = RTE_BE16(eth->ether_type);
4018 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4019 vlan = (struct rte_vlan_hdr *)next_hdr;
4020 proto = RTE_BE16(vlan->eth_proto);
4021 next_hdr += sizeof(struct rte_vlan_hdr);
4024 /* HW calculates IPv4 csum. no need to proceed */
4025 if (proto == RTE_ETHER_TYPE_IPV4)
4028 /* non IPv4/IPv6 header. not supported */
4029 if (proto != RTE_ETHER_TYPE_IPV6) {
4030 return rte_flow_error_set(error, ENOTSUP,
4031 RTE_FLOW_ERROR_TYPE_ACTION,
4032 NULL, "Cannot offload non IPv4/IPv6");
4035 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4037 /* ignore non UDP */
4038 if (ipv6->proto != IPPROTO_UDP)
4041 udp = (struct rte_udp_hdr *)(ipv6 + 1);
4042 udp->dgram_cksum = 0;
4048 * Convert L2 encap action to DV specification.
4051 * Pointer to rte_eth_dev structure.
4053 * Pointer to action structure.
4054 * @param[in, out] dev_flow
4055 * Pointer to the mlx5_flow.
4056 * @param[in] transfer
4057 * Mark if the flow is E-Switch flow.
4059 * Pointer to the error structure.
4062 * 0 on success, a negative errno value otherwise and rte_errno is set.
4065 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4066 const struct rte_flow_action *action,
4067 struct mlx5_flow *dev_flow,
4069 struct rte_flow_error *error)
4071 const struct rte_flow_item *encap_data;
4072 const struct rte_flow_action_raw_encap *raw_encap_data;
4073 struct mlx5_flow_dv_encap_decap_resource res = {
4075 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4076 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4077 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4080 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4082 (const struct rte_flow_action_raw_encap *)action->conf;
4083 res.size = raw_encap_data->size;
4084 memcpy(res.buf, raw_encap_data->data, res.size);
4086 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4088 ((const struct rte_flow_action_vxlan_encap *)
4089 action->conf)->definition;
4092 ((const struct rte_flow_action_nvgre_encap *)
4093 action->conf)->definition;
4094 if (flow_dv_convert_encap_data(encap_data, res.buf,
4098 if (flow_dv_zero_encap_udp_csum(res.buf, error))
4100 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4101 return rte_flow_error_set(error, EINVAL,
4102 RTE_FLOW_ERROR_TYPE_ACTION,
4103 NULL, "can't create L2 encap action");
4108 * Convert L2 decap action to DV specification.
4111 * Pointer to rte_eth_dev structure.
4112 * @param[in, out] dev_flow
4113 * Pointer to the mlx5_flow.
4114 * @param[in] transfer
4115 * Mark if the flow is E-Switch flow.
4117 * Pointer to the error structure.
4120 * 0 on success, a negative errno value otherwise and rte_errno is set.
4123 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4124 struct mlx5_flow *dev_flow,
4126 struct rte_flow_error *error)
4128 struct mlx5_flow_dv_encap_decap_resource res = {
4131 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4132 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4133 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4136 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4137 return rte_flow_error_set(error, EINVAL,
4138 RTE_FLOW_ERROR_TYPE_ACTION,
4139 NULL, "can't create L2 decap action");
4144 * Convert raw decap/encap (L3 tunnel) action to DV specification.
4147 * Pointer to rte_eth_dev structure.
4149 * Pointer to action structure.
4150 * @param[in, out] dev_flow
4151 * Pointer to the mlx5_flow.
4153 * Pointer to the flow attributes.
4155 * Pointer to the error structure.
4158 * 0 on success, a negative errno value otherwise and rte_errno is set.
4161 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4162 const struct rte_flow_action *action,
4163 struct mlx5_flow *dev_flow,
4164 const struct rte_flow_attr *attr,
4165 struct rte_flow_error *error)
4167 const struct rte_flow_action_raw_encap *encap_data;
4168 struct mlx5_flow_dv_encap_decap_resource res;
4170 memset(&res, 0, sizeof(res));
4171 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4172 res.size = encap_data->size;
4173 memcpy(res.buf, encap_data->data, res.size);
4174 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4175 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4176 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4178 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4180 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4181 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4182 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4183 return rte_flow_error_set(error, EINVAL,
4184 RTE_FLOW_ERROR_TYPE_ACTION,
4185 NULL, "can't create encap action");
4190 * Create action push VLAN.
4193 * Pointer to rte_eth_dev structure.
4195 * Pointer to the flow attributes.
4197 * Pointer to the vlan to push to the Ethernet header.
4198 * @param[in, out] dev_flow
4199 * Pointer to the mlx5_flow.
4201 * Pointer to the error structure.
4204 * 0 on success, a negative errno value otherwise and rte_errno is set.
4207 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4208 const struct rte_flow_attr *attr,
4209 const struct rte_vlan_hdr *vlan,
4210 struct mlx5_flow *dev_flow,
4211 struct rte_flow_error *error)
4213 struct mlx5_flow_dv_push_vlan_action_resource res;
4215 memset(&res, 0, sizeof(res));
4217 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4220 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4222 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4223 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4224 return flow_dv_push_vlan_action_resource_register
4225 (dev, &res, dev_flow, error);
4229 * Validate the modify-header actions.
4231 * @param[in] action_flags
4232 * Holds the actions detected until now.
4234 * Pointer to the modify action.
4236 * Pointer to error structure.
4239 * 0 on success, a negative errno value otherwise and rte_errno is set.
4242 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4243 const struct rte_flow_action *action,
4244 struct rte_flow_error *error)
4246 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4247 return rte_flow_error_set(error, EINVAL,
4248 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4249 NULL, "action configuration not set");
4250 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4251 return rte_flow_error_set(error, EINVAL,
4252 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4253 "can't have encap action before"
4259 * Validate the modify-header MAC address 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_mac(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_L2))
4284 return rte_flow_error_set(error, EINVAL,
4285 RTE_FLOW_ERROR_TYPE_ACTION,
4287 "no L2 item in pattern");
4293 * Validate the modify-header IPv4 address 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_ipv4(const uint64_t action_flags,
4309 const struct rte_flow_action *action,
4310 const uint64_t item_flags,
4311 struct rte_flow_error *error)
4316 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4318 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4319 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4320 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4321 if (!(item_flags & layer))
4322 return rte_flow_error_set(error, EINVAL,
4323 RTE_FLOW_ERROR_TYPE_ACTION,
4325 "no ipv4 item in pattern");
4331 * Validate the modify-header IPv6 address actions.
4333 * @param[in] action_flags
4334 * Holds the actions detected until now.
4336 * Pointer to the modify action.
4337 * @param[in] item_flags
4338 * Holds the items detected.
4340 * Pointer to error structure.
4343 * 0 on success, a negative errno value otherwise and rte_errno is set.
4346 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
4347 const struct rte_flow_action *action,
4348 const uint64_t item_flags,
4349 struct rte_flow_error *error)
4354 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4356 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4357 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4358 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4359 if (!(item_flags & layer))
4360 return rte_flow_error_set(error, EINVAL,
4361 RTE_FLOW_ERROR_TYPE_ACTION,
4363 "no ipv6 item in pattern");
4369 * Validate the modify-header TP actions.
4371 * @param[in] action_flags
4372 * Holds the actions detected until now.
4374 * Pointer to the modify action.
4375 * @param[in] item_flags
4376 * Holds the items detected.
4378 * Pointer to error structure.
4381 * 0 on success, a negative errno value otherwise and rte_errno is set.
4384 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
4385 const struct rte_flow_action *action,
4386 const uint64_t item_flags,
4387 struct rte_flow_error *error)
4392 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4394 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4395 MLX5_FLOW_LAYER_INNER_L4 :
4396 MLX5_FLOW_LAYER_OUTER_L4;
4397 if (!(item_flags & layer))
4398 return rte_flow_error_set(error, EINVAL,
4399 RTE_FLOW_ERROR_TYPE_ACTION,
4400 NULL, "no transport layer "
4407 * Validate the modify-header actions of increment/decrement
4408 * TCP Sequence-number.
4410 * @param[in] action_flags
4411 * Holds the actions detected until now.
4413 * Pointer to the modify action.
4414 * @param[in] item_flags
4415 * Holds the items detected.
4417 * Pointer to error structure.
4420 * 0 on success, a negative errno value otherwise and rte_errno is set.
4423 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
4424 const struct rte_flow_action *action,
4425 const uint64_t item_flags,
4426 struct rte_flow_error *error)
4431 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4433 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4434 MLX5_FLOW_LAYER_INNER_L4_TCP :
4435 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4436 if (!(item_flags & layer))
4437 return rte_flow_error_set(error, EINVAL,
4438 RTE_FLOW_ERROR_TYPE_ACTION,
4439 NULL, "no TCP item in"
4441 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
4442 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
4443 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
4444 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
4445 return rte_flow_error_set(error, EINVAL,
4446 RTE_FLOW_ERROR_TYPE_ACTION,
4448 "cannot decrease and increase"
4449 " TCP sequence number"
4450 " at the same time");
4456 * Validate the modify-header actions of increment/decrement
4457 * TCP Acknowledgment number.
4459 * @param[in] action_flags
4460 * Holds the actions detected until now.
4462 * Pointer to the modify action.
4463 * @param[in] item_flags
4464 * Holds the items detected.
4466 * Pointer to error structure.
4469 * 0 on success, a negative errno value otherwise and rte_errno is set.
4472 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
4473 const struct rte_flow_action *action,
4474 const uint64_t item_flags,
4475 struct rte_flow_error *error)
4480 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4482 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4483 MLX5_FLOW_LAYER_INNER_L4_TCP :
4484 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4485 if (!(item_flags & layer))
4486 return rte_flow_error_set(error, EINVAL,
4487 RTE_FLOW_ERROR_TYPE_ACTION,
4488 NULL, "no TCP item in"
4490 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
4491 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
4492 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
4493 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
4494 return rte_flow_error_set(error, EINVAL,
4495 RTE_FLOW_ERROR_TYPE_ACTION,
4497 "cannot decrease and increase"
4498 " TCP acknowledgment number"
4499 " at the same time");
4505 * Validate the modify-header TTL actions.
4507 * @param[in] action_flags
4508 * Holds the actions detected until now.
4510 * Pointer to the modify action.
4511 * @param[in] item_flags
4512 * Holds the items detected.
4514 * Pointer to error structure.
4517 * 0 on success, a negative errno value otherwise and rte_errno is set.
4520 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
4521 const struct rte_flow_action *action,
4522 const uint64_t item_flags,
4523 struct rte_flow_error *error)
4528 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4530 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4531 MLX5_FLOW_LAYER_INNER_L3 :
4532 MLX5_FLOW_LAYER_OUTER_L3;
4533 if (!(item_flags & layer))
4534 return rte_flow_error_set(error, EINVAL,
4535 RTE_FLOW_ERROR_TYPE_ACTION,
4537 "no IP protocol in pattern");
4543 * Validate the generic modify field actions.
4545 * Pointer to the rte_eth_dev structure.
4546 * @param[in] action_flags
4547 * Holds the actions detected until now.
4549 * Pointer to the modify action.
4551 * Pointer to the flow attributes.
4553 * Pointer to error structure.
4556 * Number of header fields to modify (0 or more) on success,
4557 * a negative errno value otherwise and rte_errno is set.
4560 flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
4561 const uint64_t action_flags,
4562 const struct rte_flow_action *action,
4563 const struct rte_flow_attr *attr,
4564 struct rte_flow_error *error)
4567 struct mlx5_priv *priv = dev->data->dev_private;
4568 struct mlx5_dev_config *config = &priv->config;
4569 const struct rte_flow_action_modify_field *action_modify_field =
4571 uint32_t dst_width =
4572 mlx5_flow_item_field_width(action_modify_field->dst.field);
4573 uint32_t src_width =
4574 mlx5_flow_item_field_width(action_modify_field->src.field);
4576 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4580 if (action_modify_field->width == 0)
4581 return rte_flow_error_set(error, EINVAL,
4582 RTE_FLOW_ERROR_TYPE_ACTION, action,
4583 "no bits are requested to be modified");
4584 else if (action_modify_field->width > dst_width ||
4585 action_modify_field->width > src_width)
4586 return rte_flow_error_set(error, EINVAL,
4587 RTE_FLOW_ERROR_TYPE_ACTION, action,
4588 "cannot modify more bits than"
4589 " the width of a field");
4590 if (action_modify_field->dst.field != RTE_FLOW_FIELD_VALUE &&
4591 action_modify_field->dst.field != RTE_FLOW_FIELD_POINTER) {
4592 if ((action_modify_field->dst.offset +
4593 action_modify_field->width > dst_width) ||
4594 (action_modify_field->dst.offset % 32))
4595 return rte_flow_error_set(error, EINVAL,
4596 RTE_FLOW_ERROR_TYPE_ACTION, action,
4597 "destination offset is too big"
4598 " or not aligned to 4 bytes");
4599 if (action_modify_field->dst.level &&
4600 action_modify_field->dst.field != RTE_FLOW_FIELD_TAG)
4601 return rte_flow_error_set(error, ENOTSUP,
4602 RTE_FLOW_ERROR_TYPE_ACTION, action,
4603 "inner header fields modification"
4604 " is not supported");
4606 if (action_modify_field->src.field != RTE_FLOW_FIELD_VALUE &&
4607 action_modify_field->src.field != RTE_FLOW_FIELD_POINTER) {
4608 if (!attr->transfer && !attr->group)
4609 return rte_flow_error_set(error, ENOTSUP,
4610 RTE_FLOW_ERROR_TYPE_ACTION, action,
4611 "modify field action is not"
4612 " supported for group 0");
4613 if ((action_modify_field->src.offset +
4614 action_modify_field->width > src_width) ||
4615 (action_modify_field->src.offset % 32))
4616 return rte_flow_error_set(error, EINVAL,
4617 RTE_FLOW_ERROR_TYPE_ACTION, action,
4618 "source offset is too big"
4619 " or not aligned to 4 bytes");
4620 if (action_modify_field->src.level &&
4621 action_modify_field->src.field != RTE_FLOW_FIELD_TAG)
4622 return rte_flow_error_set(error, ENOTSUP,
4623 RTE_FLOW_ERROR_TYPE_ACTION, action,
4624 "inner header fields modification"
4625 " is not supported");
4627 if (action_modify_field->dst.field ==
4628 action_modify_field->src.field)
4629 return rte_flow_error_set(error, EINVAL,
4630 RTE_FLOW_ERROR_TYPE_ACTION, action,
4631 "source and destination fields"
4632 " cannot be the same");
4633 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VALUE ||
4634 action_modify_field->dst.field == RTE_FLOW_FIELD_POINTER)
4635 return rte_flow_error_set(error, EINVAL,
4636 RTE_FLOW_ERROR_TYPE_ACTION, action,
4637 "immediate value or a pointer to it"
4638 " cannot be used as a destination");
4639 if (action_modify_field->dst.field == RTE_FLOW_FIELD_START ||
4640 action_modify_field->src.field == RTE_FLOW_FIELD_START)
4641 return rte_flow_error_set(error, ENOTSUP,
4642 RTE_FLOW_ERROR_TYPE_ACTION, action,
4643 "modifications of an arbitrary"
4644 " place in a packet is not supported");
4645 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VLAN_TYPE ||
4646 action_modify_field->src.field == RTE_FLOW_FIELD_VLAN_TYPE)
4647 return rte_flow_error_set(error, ENOTSUP,
4648 RTE_FLOW_ERROR_TYPE_ACTION, action,
4649 "modifications of the 802.1Q Tag"
4650 " Identifier is not supported");
4651 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VXLAN_VNI ||
4652 action_modify_field->src.field == RTE_FLOW_FIELD_VXLAN_VNI)
4653 return rte_flow_error_set(error, ENOTSUP,
4654 RTE_FLOW_ERROR_TYPE_ACTION, action,
4655 "modifications of the VXLAN Network"
4656 " Identifier is not supported");
4657 if (action_modify_field->dst.field == RTE_FLOW_FIELD_GENEVE_VNI ||
4658 action_modify_field->src.field == RTE_FLOW_FIELD_GENEVE_VNI)
4659 return rte_flow_error_set(error, ENOTSUP,
4660 RTE_FLOW_ERROR_TYPE_ACTION, action,
4661 "modifications of the GENEVE Network"
4662 " Identifier is not supported");
4663 if (action_modify_field->dst.field == RTE_FLOW_FIELD_MARK ||
4664 action_modify_field->src.field == RTE_FLOW_FIELD_MARK ||
4665 action_modify_field->dst.field == RTE_FLOW_FIELD_META ||
4666 action_modify_field->src.field == RTE_FLOW_FIELD_META) {
4667 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4668 !mlx5_flow_ext_mreg_supported(dev))
4669 return rte_flow_error_set(error, ENOTSUP,
4670 RTE_FLOW_ERROR_TYPE_ACTION, action,
4671 "cannot modify mark or metadata without"
4672 " extended metadata register support");
4674 if (action_modify_field->operation != RTE_FLOW_MODIFY_SET)
4675 return rte_flow_error_set(error, ENOTSUP,
4676 RTE_FLOW_ERROR_TYPE_ACTION, action,
4677 "add and sub operations"
4678 " are not supported");
4679 return (action_modify_field->width / 32) +
4680 !!(action_modify_field->width % 32);
4684 * Validate jump action.
4687 * Pointer to the jump action.
4688 * @param[in] action_flags
4689 * Holds the actions detected until now.
4690 * @param[in] attributes
4691 * Pointer to flow attributes
4692 * @param[in] external
4693 * Action belongs to flow rule created by request external to PMD.
4695 * Pointer to error structure.
4698 * 0 on success, a negative errno value otherwise and rte_errno is set.
4701 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
4702 const struct mlx5_flow_tunnel *tunnel,
4703 const struct rte_flow_action *action,
4704 uint64_t action_flags,
4705 const struct rte_flow_attr *attributes,
4706 bool external, struct rte_flow_error *error)
4708 uint32_t target_group, table;
4710 struct flow_grp_info grp_info = {
4711 .external = !!external,
4712 .transfer = !!attributes->transfer,
4716 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4717 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4718 return rte_flow_error_set(error, EINVAL,
4719 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4720 "can't have 2 fate actions in"
4722 if (action_flags & MLX5_FLOW_ACTION_METER)
4723 return rte_flow_error_set(error, ENOTSUP,
4724 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4725 "jump with meter not support");
4727 return rte_flow_error_set(error, EINVAL,
4728 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4729 NULL, "action configuration not set");
4731 ((const struct rte_flow_action_jump *)action->conf)->group;
4732 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
4736 if (attributes->group == target_group &&
4737 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
4738 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
4739 return rte_flow_error_set(error, EINVAL,
4740 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4741 "target group must be other than"
4742 " the current flow group");
4747 * Validate the port_id action.
4750 * Pointer to rte_eth_dev structure.
4751 * @param[in] action_flags
4752 * Bit-fields that holds the actions detected until now.
4754 * Port_id RTE action structure.
4756 * Attributes of flow that includes this action.
4758 * Pointer to error structure.
4761 * 0 on success, a negative errno value otherwise and rte_errno is set.
4764 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
4765 uint64_t action_flags,
4766 const struct rte_flow_action *action,
4767 const struct rte_flow_attr *attr,
4768 struct rte_flow_error *error)
4770 const struct rte_flow_action_port_id *port_id;
4771 struct mlx5_priv *act_priv;
4772 struct mlx5_priv *dev_priv;
4775 if (!attr->transfer)
4776 return rte_flow_error_set(error, ENOTSUP,
4777 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4779 "port id action is valid in transfer"
4781 if (!action || !action->conf)
4782 return rte_flow_error_set(error, ENOTSUP,
4783 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4785 "port id action parameters must be"
4787 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4788 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4789 return rte_flow_error_set(error, EINVAL,
4790 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4791 "can have only one fate actions in"
4793 dev_priv = mlx5_dev_to_eswitch_info(dev);
4795 return rte_flow_error_set(error, rte_errno,
4796 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4798 "failed to obtain E-Switch info");
4799 port_id = action->conf;
4800 port = port_id->original ? dev->data->port_id : port_id->id;
4801 act_priv = mlx5_port_to_eswitch_info(port, false);
4803 return rte_flow_error_set
4805 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
4806 "failed to obtain E-Switch port id for port");
4807 if (act_priv->domain_id != dev_priv->domain_id)
4808 return rte_flow_error_set
4810 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4811 "port does not belong to"
4812 " E-Switch being configured");
4817 * Get the maximum number of modify header actions.
4820 * Pointer to rte_eth_dev structure.
4822 * Flags bits to check if root level.
4825 * Max number of modify header actions device can support.
4827 static inline unsigned int
4828 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
4832 * There's no way to directly query the max capacity from FW.
4833 * The maximal value on root table should be assumed to be supported.
4835 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
4836 return MLX5_MAX_MODIFY_NUM;
4838 return MLX5_ROOT_TBL_MODIFY_NUM;
4842 * Validate the meter action.
4845 * Pointer to rte_eth_dev structure.
4846 * @param[in] action_flags
4847 * Bit-fields that holds the actions detected until now.
4849 * Pointer to the meter action.
4851 * Attributes of flow that includes this action.
4853 * Pointer to error structure.
4856 * 0 on success, a negative errno value otherwise and rte_ernno is set.
4859 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
4860 uint64_t action_flags,
4861 const struct rte_flow_action *action,
4862 const struct rte_flow_attr *attr,
4863 struct rte_flow_error *error)
4865 struct mlx5_priv *priv = dev->data->dev_private;
4866 const struct rte_flow_action_meter *am = action->conf;
4867 struct mlx5_flow_meter *fm;
4870 return rte_flow_error_set(error, EINVAL,
4871 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4872 "meter action conf is NULL");
4874 if (action_flags & MLX5_FLOW_ACTION_METER)
4875 return rte_flow_error_set(error, ENOTSUP,
4876 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4877 "meter chaining not support");
4878 if (action_flags & MLX5_FLOW_ACTION_JUMP)
4879 return rte_flow_error_set(error, ENOTSUP,
4880 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4881 "meter with jump not support");
4883 return rte_flow_error_set(error, ENOTSUP,
4884 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4886 "meter action not supported");
4887 fm = mlx5_flow_meter_find(priv, am->mtr_id);
4889 return rte_flow_error_set(error, EINVAL,
4890 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4892 if (fm->ref_cnt && (!(fm->transfer == attr->transfer ||
4893 (!fm->ingress && !attr->ingress && attr->egress) ||
4894 (!fm->egress && !attr->egress && attr->ingress))))
4895 return rte_flow_error_set(error, EINVAL,
4896 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4897 "Flow attributes are either invalid "
4898 "or have a conflict with current "
4899 "meter attributes");
4904 * Validate the age action.
4906 * @param[in] action_flags
4907 * Holds the actions detected until now.
4909 * Pointer to the age action.
4911 * Pointer to the Ethernet device structure.
4913 * Pointer to error structure.
4916 * 0 on success, a negative errno value otherwise and rte_errno is set.
4919 flow_dv_validate_action_age(uint64_t action_flags,
4920 const struct rte_flow_action *action,
4921 struct rte_eth_dev *dev,
4922 struct rte_flow_error *error)
4924 struct mlx5_priv *priv = dev->data->dev_private;
4925 const struct rte_flow_action_age *age = action->conf;
4927 if (!priv->config.devx || (priv->sh->cmng.counter_fallback &&
4928 !priv->sh->aso_age_mng))
4929 return rte_flow_error_set(error, ENOTSUP,
4930 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4932 "age action not supported");
4933 if (!(action->conf))
4934 return rte_flow_error_set(error, EINVAL,
4935 RTE_FLOW_ERROR_TYPE_ACTION, action,
4936 "configuration cannot be null");
4937 if (!(age->timeout))
4938 return rte_flow_error_set(error, EINVAL,
4939 RTE_FLOW_ERROR_TYPE_ACTION, action,
4940 "invalid timeout value 0");
4941 if (action_flags & MLX5_FLOW_ACTION_AGE)
4942 return rte_flow_error_set(error, EINVAL,
4943 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4944 "duplicate age actions set");
4949 * Validate the modify-header IPv4 DSCP actions.
4951 * @param[in] action_flags
4952 * Holds the actions detected until now.
4954 * Pointer to the modify action.
4955 * @param[in] item_flags
4956 * Holds the items detected.
4958 * Pointer to error structure.
4961 * 0 on success, a negative errno value otherwise and rte_errno is set.
4964 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
4965 const struct rte_flow_action *action,
4966 const uint64_t item_flags,
4967 struct rte_flow_error *error)
4971 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4973 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
4974 return rte_flow_error_set(error, EINVAL,
4975 RTE_FLOW_ERROR_TYPE_ACTION,
4977 "no ipv4 item in pattern");
4983 * Validate the modify-header IPv6 DSCP actions.
4985 * @param[in] action_flags
4986 * Holds the actions detected until now.
4988 * Pointer to the modify action.
4989 * @param[in] item_flags
4990 * Holds the items detected.
4992 * Pointer to error structure.
4995 * 0 on success, a negative errno value otherwise and rte_errno is set.
4998 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
4999 const struct rte_flow_action *action,
5000 const uint64_t item_flags,
5001 struct rte_flow_error *error)
5005 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5007 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5008 return rte_flow_error_set(error, EINVAL,
5009 RTE_FLOW_ERROR_TYPE_ACTION,
5011 "no ipv6 item in pattern");
5017 * Match modify-header resource.
5020 * Pointer to the hash list.
5022 * Pointer to exist resource entry object.
5024 * Key of the new entry.
5026 * Pointer to new modify-header resource.
5029 * 0 on matching, non-zero otherwise.
5032 flow_dv_modify_match_cb(struct mlx5_hlist *list __rte_unused,
5033 struct mlx5_hlist_entry *entry,
5034 uint64_t key __rte_unused, void *cb_ctx)
5036 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5037 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5038 struct mlx5_flow_dv_modify_hdr_resource *resource =
5039 container_of(entry, typeof(*resource), entry);
5040 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5042 key_len += ref->actions_num * sizeof(ref->actions[0]);
5043 return ref->actions_num != resource->actions_num ||
5044 memcmp(&ref->ft_type, &resource->ft_type, key_len);
5047 struct mlx5_hlist_entry *
5048 flow_dv_modify_create_cb(struct mlx5_hlist *list, uint64_t key __rte_unused,
5051 struct mlx5_dev_ctx_shared *sh = list->ctx;
5052 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5053 struct mlx5dv_dr_domain *ns;
5054 struct mlx5_flow_dv_modify_hdr_resource *entry;
5055 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5057 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5058 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5060 entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry) + data_len, 0,
5063 rte_flow_error_set(ctx->error, ENOMEM,
5064 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5065 "cannot allocate resource memory");
5068 rte_memcpy(&entry->ft_type,
5069 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5070 key_len + data_len);
5071 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5072 ns = sh->fdb_domain;
5073 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5077 ret = mlx5_flow_os_create_flow_action_modify_header
5078 (sh->ctx, ns, entry,
5079 data_len, &entry->action);
5082 rte_flow_error_set(ctx->error, ENOMEM,
5083 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5084 NULL, "cannot create modification action");
5087 return &entry->entry;
5091 * Validate the sample action.
5093 * @param[in, out] action_flags
5094 * Holds the actions detected until now.
5096 * Pointer to the sample action.
5098 * Pointer to the Ethernet device structure.
5100 * Attributes of flow that includes this action.
5101 * @param[in] item_flags
5102 * Holds the items detected.
5104 * Pointer to the RSS action.
5105 * @param[out] sample_rss
5106 * Pointer to the RSS action in sample action list.
5108 * Pointer to the COUNT action in sample action list.
5109 * @param[out] fdb_mirror_limit
5110 * Pointer to the FDB mirror limitation flag.
5112 * Pointer to error structure.
5115 * 0 on success, a negative errno value otherwise and rte_errno is set.
5118 flow_dv_validate_action_sample(uint64_t *action_flags,
5119 const struct rte_flow_action *action,
5120 struct rte_eth_dev *dev,
5121 const struct rte_flow_attr *attr,
5122 uint64_t item_flags,
5123 const struct rte_flow_action_rss *rss,
5124 const struct rte_flow_action_rss **sample_rss,
5125 const struct rte_flow_action_count **count,
5126 int *fdb_mirror_limit,
5127 struct rte_flow_error *error)
5129 struct mlx5_priv *priv = dev->data->dev_private;
5130 struct mlx5_dev_config *dev_conf = &priv->config;
5131 const struct rte_flow_action_sample *sample = action->conf;
5132 const struct rte_flow_action *act;
5133 uint64_t sub_action_flags = 0;
5134 uint16_t queue_index = 0xFFFF;
5139 return rte_flow_error_set(error, EINVAL,
5140 RTE_FLOW_ERROR_TYPE_ACTION, action,
5141 "configuration cannot be NULL");
5142 if (sample->ratio == 0)
5143 return rte_flow_error_set(error, EINVAL,
5144 RTE_FLOW_ERROR_TYPE_ACTION, action,
5145 "ratio value starts from 1");
5146 if (!priv->config.devx || (sample->ratio > 0 && !priv->sampler_en))
5147 return rte_flow_error_set(error, ENOTSUP,
5148 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5150 "sample action not supported");
5151 if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
5152 return rte_flow_error_set(error, EINVAL,
5153 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5154 "Multiple sample actions not "
5156 if (*action_flags & MLX5_FLOW_ACTION_METER)
5157 return rte_flow_error_set(error, EINVAL,
5158 RTE_FLOW_ERROR_TYPE_ACTION, action,
5159 "wrong action order, meter should "
5160 "be after sample action");
5161 if (*action_flags & MLX5_FLOW_ACTION_JUMP)
5162 return rte_flow_error_set(error, EINVAL,
5163 RTE_FLOW_ERROR_TYPE_ACTION, action,
5164 "wrong action order, jump should "
5165 "be after sample action");
5166 act = sample->actions;
5167 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
5168 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5169 return rte_flow_error_set(error, ENOTSUP,
5170 RTE_FLOW_ERROR_TYPE_ACTION,
5171 act, "too many actions");
5172 switch (act->type) {
5173 case RTE_FLOW_ACTION_TYPE_QUEUE:
5174 ret = mlx5_flow_validate_action_queue(act,
5180 queue_index = ((const struct rte_flow_action_queue *)
5181 (act->conf))->index;
5182 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
5185 case RTE_FLOW_ACTION_TYPE_RSS:
5186 *sample_rss = act->conf;
5187 ret = mlx5_flow_validate_action_rss(act,
5194 if (rss && *sample_rss &&
5195 ((*sample_rss)->level != rss->level ||
5196 (*sample_rss)->types != rss->types))
5197 return rte_flow_error_set(error, ENOTSUP,
5198 RTE_FLOW_ERROR_TYPE_ACTION,
5200 "Can't use the different RSS types "
5201 "or level in the same flow");
5202 if (*sample_rss != NULL && (*sample_rss)->queue_num)
5203 queue_index = (*sample_rss)->queue[0];
5204 sub_action_flags |= MLX5_FLOW_ACTION_RSS;
5207 case RTE_FLOW_ACTION_TYPE_MARK:
5208 ret = flow_dv_validate_action_mark(dev, act,
5213 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
5214 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
5215 MLX5_FLOW_ACTION_MARK_EXT;
5217 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
5220 case RTE_FLOW_ACTION_TYPE_COUNT:
5221 ret = flow_dv_validate_action_count
5223 *action_flags | sub_action_flags,
5228 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
5229 *action_flags |= MLX5_FLOW_ACTION_COUNT;
5232 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5233 ret = flow_dv_validate_action_port_id(dev,
5240 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5243 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5244 ret = flow_dv_validate_action_raw_encap_decap
5245 (dev, NULL, act->conf, attr, &sub_action_flags,
5246 &actions_n, action, item_flags, error);
5251 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5252 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5253 ret = flow_dv_validate_action_l2_encap(dev,
5259 sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
5263 return rte_flow_error_set(error, ENOTSUP,
5264 RTE_FLOW_ERROR_TYPE_ACTION,
5266 "Doesn't support optional "
5270 if (attr->ingress && !attr->transfer) {
5271 if (!(sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
5272 MLX5_FLOW_ACTION_RSS)))
5273 return rte_flow_error_set(error, EINVAL,
5274 RTE_FLOW_ERROR_TYPE_ACTION,
5276 "Ingress must has a dest "
5277 "QUEUE for Sample");
5278 } else if (attr->egress && !attr->transfer) {
5279 return rte_flow_error_set(error, ENOTSUP,
5280 RTE_FLOW_ERROR_TYPE_ACTION,
5282 "Sample Only support Ingress "
5284 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
5285 MLX5_ASSERT(attr->transfer);
5286 if (sample->ratio > 1)
5287 return rte_flow_error_set(error, ENOTSUP,
5288 RTE_FLOW_ERROR_TYPE_ACTION,
5290 "E-Switch doesn't support "
5291 "any optional action "
5293 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
5294 return rte_flow_error_set(error, ENOTSUP,
5295 RTE_FLOW_ERROR_TYPE_ACTION,
5297 "unsupported action QUEUE");
5298 if (sub_action_flags & MLX5_FLOW_ACTION_RSS)
5299 return rte_flow_error_set(error, ENOTSUP,
5300 RTE_FLOW_ERROR_TYPE_ACTION,
5302 "unsupported action QUEUE");
5303 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
5304 return rte_flow_error_set(error, EINVAL,
5305 RTE_FLOW_ERROR_TYPE_ACTION,
5307 "E-Switch must has a dest "
5308 "port for mirroring");
5309 if (!priv->config.hca_attr.reg_c_preserve &&
5310 priv->representor_id != -1)
5311 *fdb_mirror_limit = 1;
5313 /* Continue validation for Xcap actions.*/
5314 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
5315 (queue_index == 0xFFFF ||
5316 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5317 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5318 MLX5_FLOW_XCAP_ACTIONS)
5319 return rte_flow_error_set(error, ENOTSUP,
5320 RTE_FLOW_ERROR_TYPE_ACTION,
5321 NULL, "encap and decap "
5322 "combination aren't "
5324 if (!attr->transfer && attr->ingress && (sub_action_flags &
5325 MLX5_FLOW_ACTION_ENCAP))
5326 return rte_flow_error_set(error, ENOTSUP,
5327 RTE_FLOW_ERROR_TYPE_ACTION,
5328 NULL, "encap is not supported"
5329 " for ingress traffic");
5335 * Find existing modify-header resource or create and register a new one.
5337 * @param dev[in, out]
5338 * Pointer to rte_eth_dev structure.
5339 * @param[in, out] resource
5340 * Pointer to modify-header resource.
5341 * @parm[in, out] dev_flow
5342 * Pointer to the dev_flow.
5344 * pointer to error structure.
5347 * 0 on success otherwise -errno and errno is set.
5350 flow_dv_modify_hdr_resource_register
5351 (struct rte_eth_dev *dev,
5352 struct mlx5_flow_dv_modify_hdr_resource *resource,
5353 struct mlx5_flow *dev_flow,
5354 struct rte_flow_error *error)
5356 struct mlx5_priv *priv = dev->data->dev_private;
5357 struct mlx5_dev_ctx_shared *sh = priv->sh;
5358 uint32_t key_len = sizeof(*resource) -
5359 offsetof(typeof(*resource), ft_type) +
5360 resource->actions_num * sizeof(resource->actions[0]);
5361 struct mlx5_hlist_entry *entry;
5362 struct mlx5_flow_cb_ctx ctx = {
5368 resource->flags = dev_flow->dv.group ? 0 :
5369 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
5370 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
5372 return rte_flow_error_set(error, EOVERFLOW,
5373 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5374 "too many modify header items");
5375 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
5376 entry = mlx5_hlist_register(sh->modify_cmds, key64, &ctx);
5379 resource = container_of(entry, typeof(*resource), entry);
5380 dev_flow->handle->dvh.modify_hdr = resource;
5385 * Get DV flow counter by index.
5388 * Pointer to the Ethernet device structure.
5390 * mlx5 flow counter index in the container.
5392 * mlx5 flow counter pool in the container,
5395 * Pointer to the counter, NULL otherwise.
5397 static struct mlx5_flow_counter *
5398 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
5400 struct mlx5_flow_counter_pool **ppool)
5402 struct mlx5_priv *priv = dev->data->dev_private;
5403 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5404 struct mlx5_flow_counter_pool *pool;
5406 /* Decrease to original index and clear shared bit. */
5407 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
5408 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
5409 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
5413 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
5417 * Check the devx counter belongs to the pool.
5420 * Pointer to the counter pool.
5422 * The counter devx ID.
5425 * True if counter belongs to the pool, false otherwise.
5428 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
5430 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
5431 MLX5_COUNTERS_PER_POOL;
5433 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
5439 * Get a pool by devx counter ID.
5442 * Pointer to the counter management.
5444 * The counter devx ID.
5447 * The counter pool pointer if exists, NULL otherwise,
5449 static struct mlx5_flow_counter_pool *
5450 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
5453 struct mlx5_flow_counter_pool *pool = NULL;
5455 rte_spinlock_lock(&cmng->pool_update_sl);
5456 /* Check last used pool. */
5457 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
5458 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
5459 pool = cmng->pools[cmng->last_pool_idx];
5462 /* ID out of range means no suitable pool in the container. */
5463 if (id > cmng->max_id || id < cmng->min_id)
5466 * Find the pool from the end of the container, since mostly counter
5467 * ID is sequence increasing, and the last pool should be the needed
5472 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
5474 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
5480 rte_spinlock_unlock(&cmng->pool_update_sl);
5485 * Resize a counter container.
5488 * Pointer to the Ethernet device structure.
5491 * 0 on success, otherwise negative errno value and rte_errno is set.
5494 flow_dv_container_resize(struct rte_eth_dev *dev)
5496 struct mlx5_priv *priv = dev->data->dev_private;
5497 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5498 void *old_pools = cmng->pools;
5499 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
5500 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
5501 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
5508 memcpy(pools, old_pools, cmng->n *
5509 sizeof(struct mlx5_flow_counter_pool *));
5511 cmng->pools = pools;
5513 mlx5_free(old_pools);
5518 * Query a devx flow counter.
5521 * Pointer to the Ethernet device structure.
5523 * Index to the flow counter.
5525 * The statistics value of packets.
5527 * The statistics value of bytes.
5530 * 0 on success, otherwise a negative errno value and rte_errno is set.
5533 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
5536 struct mlx5_priv *priv = dev->data->dev_private;
5537 struct mlx5_flow_counter_pool *pool = NULL;
5538 struct mlx5_flow_counter *cnt;
5541 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
5543 if (priv->sh->cmng.counter_fallback)
5544 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
5545 0, pkts, bytes, 0, NULL, NULL, 0);
5546 rte_spinlock_lock(&pool->sl);
5551 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
5552 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
5553 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
5555 rte_spinlock_unlock(&pool->sl);
5560 * Create and initialize a new counter pool.
5563 * Pointer to the Ethernet device structure.
5565 * The devX counter handle.
5567 * Whether the pool is for counter that was allocated for aging.
5568 * @param[in/out] cont_cur
5569 * Pointer to the container pointer, it will be update in pool resize.
5572 * The pool container pointer on success, NULL otherwise and rte_errno is set.
5574 static struct mlx5_flow_counter_pool *
5575 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
5578 struct mlx5_priv *priv = dev->data->dev_private;
5579 struct mlx5_flow_counter_pool *pool;
5580 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5581 bool fallback = priv->sh->cmng.counter_fallback;
5582 uint32_t size = sizeof(*pool);
5584 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
5585 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
5586 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
5592 pool->is_aged = !!age;
5593 pool->query_gen = 0;
5594 pool->min_dcs = dcs;
5595 rte_spinlock_init(&pool->sl);
5596 rte_spinlock_init(&pool->csl);
5597 TAILQ_INIT(&pool->counters[0]);
5598 TAILQ_INIT(&pool->counters[1]);
5599 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
5600 rte_spinlock_lock(&cmng->pool_update_sl);
5601 pool->index = cmng->n_valid;
5602 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
5604 rte_spinlock_unlock(&cmng->pool_update_sl);
5607 cmng->pools[pool->index] = pool;
5609 if (unlikely(fallback)) {
5610 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
5612 if (base < cmng->min_id)
5613 cmng->min_id = base;
5614 if (base > cmng->max_id)
5615 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
5616 cmng->last_pool_idx = pool->index;
5618 rte_spinlock_unlock(&cmng->pool_update_sl);
5623 * Prepare a new counter and/or a new counter pool.
5626 * Pointer to the Ethernet device structure.
5627 * @param[out] cnt_free
5628 * Where to put the pointer of a new counter.
5630 * Whether the pool is for counter that was allocated for aging.
5633 * The counter pool pointer and @p cnt_free is set on success,
5634 * NULL otherwise and rte_errno is set.
5636 static struct mlx5_flow_counter_pool *
5637 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
5638 struct mlx5_flow_counter **cnt_free,
5641 struct mlx5_priv *priv = dev->data->dev_private;
5642 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5643 struct mlx5_flow_counter_pool *pool;
5644 struct mlx5_counters tmp_tq;
5645 struct mlx5_devx_obj *dcs = NULL;
5646 struct mlx5_flow_counter *cnt;
5647 enum mlx5_counter_type cnt_type =
5648 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
5649 bool fallback = priv->sh->cmng.counter_fallback;
5653 /* bulk_bitmap must be 0 for single counter allocation. */
5654 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
5657 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
5659 pool = flow_dv_pool_create(dev, dcs, age);
5661 mlx5_devx_cmd_destroy(dcs);
5665 i = dcs->id % MLX5_COUNTERS_PER_POOL;
5666 cnt = MLX5_POOL_GET_CNT(pool, i);
5668 cnt->dcs_when_free = dcs;
5672 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
5674 rte_errno = ENODATA;
5677 pool = flow_dv_pool_create(dev, dcs, age);
5679 mlx5_devx_cmd_destroy(dcs);
5682 TAILQ_INIT(&tmp_tq);
5683 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
5684 cnt = MLX5_POOL_GET_CNT(pool, i);
5686 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
5688 rte_spinlock_lock(&cmng->csl[cnt_type]);
5689 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
5690 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5691 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
5692 (*cnt_free)->pool = pool;
5697 * Allocate a flow counter.
5700 * Pointer to the Ethernet device structure.
5702 * Whether the counter was allocated for aging.
5705 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5708 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
5710 struct mlx5_priv *priv = dev->data->dev_private;
5711 struct mlx5_flow_counter_pool *pool = NULL;
5712 struct mlx5_flow_counter *cnt_free = NULL;
5713 bool fallback = priv->sh->cmng.counter_fallback;
5714 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5715 enum mlx5_counter_type cnt_type =
5716 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
5719 if (!priv->config.devx) {
5720 rte_errno = ENOTSUP;
5723 /* Get free counters from container. */
5724 rte_spinlock_lock(&cmng->csl[cnt_type]);
5725 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
5727 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
5728 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5729 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
5731 pool = cnt_free->pool;
5733 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
5734 /* Create a DV counter action only in the first time usage. */
5735 if (!cnt_free->action) {
5737 struct mlx5_devx_obj *dcs;
5741 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
5742 dcs = pool->min_dcs;
5745 dcs = cnt_free->dcs_when_free;
5747 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
5754 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
5755 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
5756 /* Update the counter reset values. */
5757 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
5760 if (!fallback && !priv->sh->cmng.query_thread_on)
5761 /* Start the asynchronous batch query by the host thread. */
5762 mlx5_set_query_alarm(priv->sh);
5766 cnt_free->pool = pool;
5768 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
5769 rte_spinlock_lock(&cmng->csl[cnt_type]);
5770 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
5771 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5777 * Allocate a shared flow counter.
5780 * Pointer to the shared counter configuration.
5782 * Pointer to save the allocated counter index.
5785 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5789 flow_dv_counter_alloc_shared_cb(void *ctx, union mlx5_l3t_data *data)
5791 struct mlx5_shared_counter_conf *conf = ctx;
5792 struct rte_eth_dev *dev = conf->dev;
5793 struct mlx5_flow_counter *cnt;
5795 data->dword = flow_dv_counter_alloc(dev, 0);
5796 data->dword |= MLX5_CNT_SHARED_OFFSET;
5797 cnt = flow_dv_counter_get_by_idx(dev, data->dword, NULL);
5798 cnt->shared_info.id = conf->id;
5803 * Get a shared flow counter.
5806 * Pointer to the Ethernet device structure.
5808 * Counter identifier.
5811 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5814 flow_dv_counter_get_shared(struct rte_eth_dev *dev, uint32_t id)
5816 struct mlx5_priv *priv = dev->data->dev_private;
5817 struct mlx5_shared_counter_conf conf = {
5821 union mlx5_l3t_data data = {
5825 mlx5_l3t_prepare_entry(priv->sh->cnt_id_tbl, id, &data,
5826 flow_dv_counter_alloc_shared_cb, &conf);
5831 * Get age param from counter index.
5834 * Pointer to the Ethernet device structure.
5835 * @param[in] counter
5836 * Index to the counter handler.
5839 * The aging parameter specified for the counter index.
5841 static struct mlx5_age_param*
5842 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
5845 struct mlx5_flow_counter *cnt;
5846 struct mlx5_flow_counter_pool *pool = NULL;
5848 flow_dv_counter_get_by_idx(dev, counter, &pool);
5849 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
5850 cnt = MLX5_POOL_GET_CNT(pool, counter);
5851 return MLX5_CNT_TO_AGE(cnt);
5855 * Remove a flow counter from aged counter list.
5858 * Pointer to the Ethernet device structure.
5859 * @param[in] counter
5860 * Index to the counter handler.
5862 * Pointer to the counter handler.
5865 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
5866 uint32_t counter, struct mlx5_flow_counter *cnt)
5868 struct mlx5_age_info *age_info;
5869 struct mlx5_age_param *age_param;
5870 struct mlx5_priv *priv = dev->data->dev_private;
5871 uint16_t expected = AGE_CANDIDATE;
5873 age_info = GET_PORT_AGE_INFO(priv);
5874 age_param = flow_dv_counter_idx_get_age(dev, counter);
5875 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
5876 AGE_FREE, false, __ATOMIC_RELAXED,
5877 __ATOMIC_RELAXED)) {
5879 * We need the lock even it is age timeout,
5880 * since counter may still in process.
5882 rte_spinlock_lock(&age_info->aged_sl);
5883 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
5884 rte_spinlock_unlock(&age_info->aged_sl);
5885 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
5890 * Release a flow counter.
5893 * Pointer to the Ethernet device structure.
5894 * @param[in] counter
5895 * Index to the counter handler.
5898 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
5900 struct mlx5_priv *priv = dev->data->dev_private;
5901 struct mlx5_flow_counter_pool *pool = NULL;
5902 struct mlx5_flow_counter *cnt;
5903 enum mlx5_counter_type cnt_type;
5907 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
5909 if (IS_SHARED_CNT(counter) &&
5910 mlx5_l3t_clear_entry(priv->sh->cnt_id_tbl, cnt->shared_info.id))
5913 flow_dv_counter_remove_from_age(dev, counter, cnt);
5916 * Put the counter back to list to be updated in none fallback mode.
5917 * Currently, we are using two list alternately, while one is in query,
5918 * add the freed counter to the other list based on the pool query_gen
5919 * value. After query finishes, add counter the list to the global
5920 * container counter list. The list changes while query starts. In
5921 * this case, lock will not be needed as query callback and release
5922 * function both operate with the different list.
5925 if (!priv->sh->cmng.counter_fallback) {
5926 rte_spinlock_lock(&pool->csl);
5927 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
5928 rte_spinlock_unlock(&pool->csl);
5930 cnt->dcs_when_free = cnt->dcs_when_active;
5931 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
5932 MLX5_COUNTER_TYPE_ORIGIN;
5933 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
5934 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
5936 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
5941 * Verify the @p attributes will be correctly understood by the NIC and store
5942 * them in the @p flow if everything is correct.
5945 * Pointer to dev struct.
5946 * @param[in] attributes
5947 * Pointer to flow attributes
5948 * @param[in] external
5949 * This flow rule is created by request external to PMD.
5951 * Pointer to error structure.
5954 * - 0 on success and non root table.
5955 * - 1 on success and root table.
5956 * - a negative errno value otherwise and rte_errno is set.
5959 flow_dv_validate_attributes(struct rte_eth_dev *dev,
5960 const struct mlx5_flow_tunnel *tunnel,
5961 const struct rte_flow_attr *attributes,
5962 const struct flow_grp_info *grp_info,
5963 struct rte_flow_error *error)
5965 struct mlx5_priv *priv = dev->data->dev_private;
5966 uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
5969 #ifndef HAVE_MLX5DV_DR
5970 RTE_SET_USED(tunnel);
5971 RTE_SET_USED(grp_info);
5972 if (attributes->group)
5973 return rte_flow_error_set(error, ENOTSUP,
5974 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5976 "groups are not supported");
5980 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
5985 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
5987 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
5988 attributes->priority > lowest_priority)
5989 return rte_flow_error_set(error, ENOTSUP,
5990 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
5992 "priority out of range");
5993 if (attributes->transfer) {
5994 if (!priv->config.dv_esw_en)
5995 return rte_flow_error_set
5997 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5998 "E-Switch dr is not supported");
5999 if (!(priv->representor || priv->master))
6000 return rte_flow_error_set
6001 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6002 NULL, "E-Switch configuration can only be"
6003 " done by a master or a representor device");
6004 if (attributes->egress)
6005 return rte_flow_error_set
6007 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
6008 "egress is not supported");
6010 if (!(attributes->egress ^ attributes->ingress))
6011 return rte_flow_error_set(error, ENOTSUP,
6012 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6013 "must specify exactly one of "
6014 "ingress or egress");
6019 * Internal validation function. For validating both actions and items.
6022 * Pointer to the rte_eth_dev structure.
6024 * Pointer to the flow attributes.
6026 * Pointer to the list of items.
6027 * @param[in] actions
6028 * Pointer to the list of actions.
6029 * @param[in] external
6030 * This flow rule is created by request external to PMD.
6031 * @param[in] hairpin
6032 * Number of hairpin TX actions, 0 means classic flow.
6034 * Pointer to the error structure.
6037 * 0 on success, a negative errno value otherwise and rte_errno is set.
6040 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
6041 const struct rte_flow_item items[],
6042 const struct rte_flow_action actions[],
6043 bool external, int hairpin, struct rte_flow_error *error)
6046 uint64_t action_flags = 0;
6047 uint64_t item_flags = 0;
6048 uint64_t last_item = 0;
6049 uint8_t next_protocol = 0xff;
6050 uint16_t ether_type = 0;
6052 uint8_t item_ipv6_proto = 0;
6053 int fdb_mirror_limit = 0;
6054 int modify_after_mirror = 0;
6055 const struct rte_flow_item *geneve_item = NULL;
6056 const struct rte_flow_item *gre_item = NULL;
6057 const struct rte_flow_item *gtp_item = NULL;
6058 const struct rte_flow_action_raw_decap *decap;
6059 const struct rte_flow_action_raw_encap *encap;
6060 const struct rte_flow_action_rss *rss = NULL;
6061 const struct rte_flow_action_rss *sample_rss = NULL;
6062 const struct rte_flow_action_count *count = NULL;
6063 const struct rte_flow_action_count *sample_count = NULL;
6064 const struct rte_flow_item_tcp nic_tcp_mask = {
6067 .src_port = RTE_BE16(UINT16_MAX),
6068 .dst_port = RTE_BE16(UINT16_MAX),
6071 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
6074 "\xff\xff\xff\xff\xff\xff\xff\xff"
6075 "\xff\xff\xff\xff\xff\xff\xff\xff",
6077 "\xff\xff\xff\xff\xff\xff\xff\xff"
6078 "\xff\xff\xff\xff\xff\xff\xff\xff",
6079 .vtc_flow = RTE_BE32(0xffffffff),
6085 const struct rte_flow_item_ecpri nic_ecpri_mask = {
6089 RTE_BE32(((const struct rte_ecpri_common_hdr) {
6093 .dummy[0] = 0xffffffff,
6096 struct mlx5_priv *priv = dev->data->dev_private;
6097 struct mlx5_dev_config *dev_conf = &priv->config;
6098 uint16_t queue_index = 0xFFFF;
6099 const struct rte_flow_item_vlan *vlan_m = NULL;
6100 uint32_t rw_act_num = 0;
6102 const struct mlx5_flow_tunnel *tunnel;
6103 struct flow_grp_info grp_info = {
6104 .external = !!external,
6105 .transfer = !!attr->transfer,
6106 .fdb_def_rule = !!priv->fdb_def_rule,
6108 const struct rte_eth_hairpin_conf *conf;
6112 if (is_flow_tunnel_match_rule(dev, attr, items, actions)) {
6113 tunnel = flow_items_to_tunnel(items);
6114 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
6115 MLX5_FLOW_ACTION_DECAP;
6116 } else if (is_flow_tunnel_steer_rule(dev, attr, items, actions)) {
6117 tunnel = flow_actions_to_tunnel(actions);
6118 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6122 if (tunnel && priv->representor)
6123 return rte_flow_error_set(error, ENOTSUP,
6124 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6125 "decap not supported "
6126 "for VF representor");
6127 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
6128 (dev, tunnel, attr, items, actions);
6129 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
6132 is_root = (uint64_t)ret;
6133 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6134 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
6135 int type = items->type;
6137 if (!mlx5_flow_os_item_supported(type))
6138 return rte_flow_error_set(error, ENOTSUP,
6139 RTE_FLOW_ERROR_TYPE_ITEM,
6140 NULL, "item not supported");
6142 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
6143 if (items[0].type != (typeof(items[0].type))
6144 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL)
6145 return rte_flow_error_set
6147 RTE_FLOW_ERROR_TYPE_ITEM,
6148 NULL, "MLX5 private items "
6149 "must be the first");
6151 case RTE_FLOW_ITEM_TYPE_VOID:
6153 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6154 ret = flow_dv_validate_item_port_id
6155 (dev, items, attr, item_flags, error);
6158 last_item = MLX5_FLOW_ITEM_PORT_ID;
6160 case RTE_FLOW_ITEM_TYPE_ETH:
6161 ret = mlx5_flow_validate_item_eth(items, item_flags,
6165 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
6166 MLX5_FLOW_LAYER_OUTER_L2;
6167 if (items->mask != NULL && items->spec != NULL) {
6169 ((const struct rte_flow_item_eth *)
6172 ((const struct rte_flow_item_eth *)
6174 ether_type = rte_be_to_cpu_16(ether_type);
6179 case RTE_FLOW_ITEM_TYPE_VLAN:
6180 ret = flow_dv_validate_item_vlan(items, item_flags,
6184 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
6185 MLX5_FLOW_LAYER_OUTER_VLAN;
6186 if (items->mask != NULL && items->spec != NULL) {
6188 ((const struct rte_flow_item_vlan *)
6189 items->spec)->inner_type;
6191 ((const struct rte_flow_item_vlan *)
6192 items->mask)->inner_type;
6193 ether_type = rte_be_to_cpu_16(ether_type);
6197 /* Store outer VLAN mask for of_push_vlan action. */
6199 vlan_m = items->mask;
6201 case RTE_FLOW_ITEM_TYPE_IPV4:
6202 mlx5_flow_tunnel_ip_check(items, next_protocol,
6203 &item_flags, &tunnel);
6204 ret = flow_dv_validate_item_ipv4(items, item_flags,
6205 last_item, ether_type,
6209 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
6210 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
6211 if (items->mask != NULL &&
6212 ((const struct rte_flow_item_ipv4 *)
6213 items->mask)->hdr.next_proto_id) {
6215 ((const struct rte_flow_item_ipv4 *)
6216 (items->spec))->hdr.next_proto_id;
6218 ((const struct rte_flow_item_ipv4 *)
6219 (items->mask))->hdr.next_proto_id;
6221 /* Reset for inner layer. */
6222 next_protocol = 0xff;
6225 case RTE_FLOW_ITEM_TYPE_IPV6:
6226 mlx5_flow_tunnel_ip_check(items, next_protocol,
6227 &item_flags, &tunnel);
6228 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
6235 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
6236 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
6237 if (items->mask != NULL &&
6238 ((const struct rte_flow_item_ipv6 *)
6239 items->mask)->hdr.proto) {
6241 ((const struct rte_flow_item_ipv6 *)
6242 items->spec)->hdr.proto;
6244 ((const struct rte_flow_item_ipv6 *)
6245 items->spec)->hdr.proto;
6247 ((const struct rte_flow_item_ipv6 *)
6248 items->mask)->hdr.proto;
6250 /* Reset for inner layer. */
6251 next_protocol = 0xff;
6254 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
6255 ret = flow_dv_validate_item_ipv6_frag_ext(items,
6260 last_item = tunnel ?
6261 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
6262 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
6263 if (items->mask != NULL &&
6264 ((const struct rte_flow_item_ipv6_frag_ext *)
6265 items->mask)->hdr.next_header) {
6267 ((const struct rte_flow_item_ipv6_frag_ext *)
6268 items->spec)->hdr.next_header;
6270 ((const struct rte_flow_item_ipv6_frag_ext *)
6271 items->mask)->hdr.next_header;
6273 /* Reset for inner layer. */
6274 next_protocol = 0xff;
6277 case RTE_FLOW_ITEM_TYPE_TCP:
6278 ret = mlx5_flow_validate_item_tcp
6285 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
6286 MLX5_FLOW_LAYER_OUTER_L4_TCP;
6288 case RTE_FLOW_ITEM_TYPE_UDP:
6289 ret = mlx5_flow_validate_item_udp(items, item_flags,
6294 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
6295 MLX5_FLOW_LAYER_OUTER_L4_UDP;
6297 case RTE_FLOW_ITEM_TYPE_GRE:
6298 ret = mlx5_flow_validate_item_gre(items, item_flags,
6299 next_protocol, error);
6303 last_item = MLX5_FLOW_LAYER_GRE;
6305 case RTE_FLOW_ITEM_TYPE_NVGRE:
6306 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
6311 last_item = MLX5_FLOW_LAYER_NVGRE;
6313 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6314 ret = mlx5_flow_validate_item_gre_key
6315 (items, item_flags, gre_item, error);
6318 last_item = MLX5_FLOW_LAYER_GRE_KEY;
6320 case RTE_FLOW_ITEM_TYPE_VXLAN:
6321 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
6325 last_item = MLX5_FLOW_LAYER_VXLAN;
6327 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6328 ret = mlx5_flow_validate_item_vxlan_gpe(items,
6333 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
6335 case RTE_FLOW_ITEM_TYPE_GENEVE:
6336 ret = mlx5_flow_validate_item_geneve(items,
6341 geneve_item = items;
6342 last_item = MLX5_FLOW_LAYER_GENEVE;
6344 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
6345 ret = mlx5_flow_validate_item_geneve_opt(items,
6352 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
6354 case RTE_FLOW_ITEM_TYPE_MPLS:
6355 ret = mlx5_flow_validate_item_mpls(dev, items,
6360 last_item = MLX5_FLOW_LAYER_MPLS;
6363 case RTE_FLOW_ITEM_TYPE_MARK:
6364 ret = flow_dv_validate_item_mark(dev, items, attr,
6368 last_item = MLX5_FLOW_ITEM_MARK;
6370 case RTE_FLOW_ITEM_TYPE_META:
6371 ret = flow_dv_validate_item_meta(dev, items, attr,
6375 last_item = MLX5_FLOW_ITEM_METADATA;
6377 case RTE_FLOW_ITEM_TYPE_ICMP:
6378 ret = mlx5_flow_validate_item_icmp(items, item_flags,
6383 last_item = MLX5_FLOW_LAYER_ICMP;
6385 case RTE_FLOW_ITEM_TYPE_ICMP6:
6386 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
6391 item_ipv6_proto = IPPROTO_ICMPV6;
6392 last_item = MLX5_FLOW_LAYER_ICMP6;
6394 case RTE_FLOW_ITEM_TYPE_TAG:
6395 ret = flow_dv_validate_item_tag(dev, items,
6399 last_item = MLX5_FLOW_ITEM_TAG;
6401 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
6402 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
6404 case RTE_FLOW_ITEM_TYPE_GTP:
6405 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
6410 last_item = MLX5_FLOW_LAYER_GTP;
6412 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6413 ret = flow_dv_validate_item_gtp_psc(items, last_item,
6418 last_item = MLX5_FLOW_LAYER_GTP_PSC;
6420 case RTE_FLOW_ITEM_TYPE_ECPRI:
6421 /* Capacity will be checked in the translate stage. */
6422 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
6429 last_item = MLX5_FLOW_LAYER_ECPRI;
6432 return rte_flow_error_set(error, ENOTSUP,
6433 RTE_FLOW_ERROR_TYPE_ITEM,
6434 NULL, "item not supported");
6436 item_flags |= last_item;
6438 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
6439 int type = actions->type;
6441 if (!mlx5_flow_os_action_supported(type))
6442 return rte_flow_error_set(error, ENOTSUP,
6443 RTE_FLOW_ERROR_TYPE_ACTION,
6445 "action not supported");
6446 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6447 return rte_flow_error_set(error, ENOTSUP,
6448 RTE_FLOW_ERROR_TYPE_ACTION,
6449 actions, "too many actions");
6451 case RTE_FLOW_ACTION_TYPE_VOID:
6453 case RTE_FLOW_ACTION_TYPE_PORT_ID:
6454 ret = flow_dv_validate_action_port_id(dev,
6461 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6464 case RTE_FLOW_ACTION_TYPE_FLAG:
6465 ret = flow_dv_validate_action_flag(dev, action_flags,
6469 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
6470 /* Count all modify-header actions as one. */
6471 if (!(action_flags &
6472 MLX5_FLOW_MODIFY_HDR_ACTIONS))
6474 action_flags |= MLX5_FLOW_ACTION_FLAG |
6475 MLX5_FLOW_ACTION_MARK_EXT;
6476 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6477 modify_after_mirror = 1;
6480 action_flags |= MLX5_FLOW_ACTION_FLAG;
6483 rw_act_num += MLX5_ACT_NUM_SET_MARK;
6485 case RTE_FLOW_ACTION_TYPE_MARK:
6486 ret = flow_dv_validate_action_mark(dev, actions,
6491 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
6492 /* Count all modify-header actions as one. */
6493 if (!(action_flags &
6494 MLX5_FLOW_MODIFY_HDR_ACTIONS))
6496 action_flags |= MLX5_FLOW_ACTION_MARK |
6497 MLX5_FLOW_ACTION_MARK_EXT;
6498 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6499 modify_after_mirror = 1;
6501 action_flags |= MLX5_FLOW_ACTION_MARK;
6504 rw_act_num += MLX5_ACT_NUM_SET_MARK;
6506 case RTE_FLOW_ACTION_TYPE_SET_META:
6507 ret = flow_dv_validate_action_set_meta(dev, actions,
6512 /* Count all modify-header actions as one action. */
6513 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6515 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6516 modify_after_mirror = 1;
6517 action_flags |= MLX5_FLOW_ACTION_SET_META;
6518 rw_act_num += MLX5_ACT_NUM_SET_META;
6520 case RTE_FLOW_ACTION_TYPE_SET_TAG:
6521 ret = flow_dv_validate_action_set_tag(dev, actions,
6526 /* Count all modify-header actions as one action. */
6527 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6529 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6530 modify_after_mirror = 1;
6531 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
6532 rw_act_num += MLX5_ACT_NUM_SET_TAG;
6534 case RTE_FLOW_ACTION_TYPE_DROP:
6535 ret = mlx5_flow_validate_action_drop(action_flags,
6539 action_flags |= MLX5_FLOW_ACTION_DROP;
6542 case RTE_FLOW_ACTION_TYPE_QUEUE:
6543 ret = mlx5_flow_validate_action_queue(actions,
6548 queue_index = ((const struct rte_flow_action_queue *)
6549 (actions->conf))->index;
6550 action_flags |= MLX5_FLOW_ACTION_QUEUE;
6553 case RTE_FLOW_ACTION_TYPE_RSS:
6554 rss = actions->conf;
6555 ret = mlx5_flow_validate_action_rss(actions,
6561 if (rss && sample_rss &&
6562 (sample_rss->level != rss->level ||
6563 sample_rss->types != rss->types))
6564 return rte_flow_error_set(error, ENOTSUP,
6565 RTE_FLOW_ERROR_TYPE_ACTION,
6567 "Can't use the different RSS types "
6568 "or level in the same flow");
6569 if (rss != NULL && rss->queue_num)
6570 queue_index = rss->queue[0];
6571 action_flags |= MLX5_FLOW_ACTION_RSS;
6574 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
6576 mlx5_flow_validate_action_default_miss(action_flags,
6580 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
6583 case RTE_FLOW_ACTION_TYPE_COUNT:
6584 ret = flow_dv_validate_action_count(dev, actions,
6589 count = actions->conf;
6590 action_flags |= MLX5_FLOW_ACTION_COUNT;
6593 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
6594 if (flow_dv_validate_action_pop_vlan(dev,
6600 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6601 modify_after_mirror = 1;
6602 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
6605 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6606 ret = flow_dv_validate_action_push_vlan(dev,
6613 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6614 modify_after_mirror = 1;
6615 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
6618 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
6619 ret = flow_dv_validate_action_set_vlan_pcp
6620 (action_flags, actions, error);
6623 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6624 modify_after_mirror = 1;
6625 /* Count PCP with push_vlan command. */
6626 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
6628 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6629 ret = flow_dv_validate_action_set_vlan_vid
6630 (item_flags, action_flags,
6634 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6635 modify_after_mirror = 1;
6636 /* Count VID with push_vlan command. */
6637 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
6638 rw_act_num += MLX5_ACT_NUM_MDF_VID;
6640 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6641 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6642 ret = flow_dv_validate_action_l2_encap(dev,
6648 action_flags |= MLX5_FLOW_ACTION_ENCAP;
6651 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
6652 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
6653 ret = flow_dv_validate_action_decap(dev, action_flags,
6654 actions, item_flags,
6658 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6659 modify_after_mirror = 1;
6660 action_flags |= MLX5_FLOW_ACTION_DECAP;
6663 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6664 ret = flow_dv_validate_action_raw_encap_decap
6665 (dev, NULL, actions->conf, attr, &action_flags,
6666 &actions_n, actions, item_flags, error);
6670 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6671 decap = actions->conf;
6672 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
6674 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
6678 encap = actions->conf;
6680 ret = flow_dv_validate_action_raw_encap_decap
6682 decap ? decap : &empty_decap, encap,
6683 attr, &action_flags, &actions_n,
6684 actions, item_flags, error);
6687 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
6688 (action_flags & MLX5_FLOW_ACTION_DECAP))
6689 modify_after_mirror = 1;
6691 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
6692 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
6693 ret = flow_dv_validate_action_modify_mac(action_flags,
6699 /* Count all modify-header actions as one action. */
6700 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6702 action_flags |= actions->type ==
6703 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
6704 MLX5_FLOW_ACTION_SET_MAC_SRC :
6705 MLX5_FLOW_ACTION_SET_MAC_DST;
6706 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6707 modify_after_mirror = 1;
6709 * Even if the source and destination MAC addresses have
6710 * overlap in the header with 4B alignment, the convert
6711 * function will handle them separately and 4 SW actions
6712 * will be created. And 2 actions will be added each
6713 * time no matter how many bytes of address will be set.
6715 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
6717 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
6718 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
6719 ret = flow_dv_validate_action_modify_ipv4(action_flags,
6725 /* Count all modify-header actions as one action. */
6726 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6728 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6729 modify_after_mirror = 1;
6730 action_flags |= actions->type ==
6731 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
6732 MLX5_FLOW_ACTION_SET_IPV4_SRC :
6733 MLX5_FLOW_ACTION_SET_IPV4_DST;
6734 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
6736 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
6737 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
6738 ret = flow_dv_validate_action_modify_ipv6(action_flags,
6744 if (item_ipv6_proto == IPPROTO_ICMPV6)
6745 return rte_flow_error_set(error, ENOTSUP,
6746 RTE_FLOW_ERROR_TYPE_ACTION,
6748 "Can't change header "
6749 "with ICMPv6 proto");
6750 /* Count all modify-header actions as one action. */
6751 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6753 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6754 modify_after_mirror = 1;
6755 action_flags |= actions->type ==
6756 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
6757 MLX5_FLOW_ACTION_SET_IPV6_SRC :
6758 MLX5_FLOW_ACTION_SET_IPV6_DST;
6759 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
6761 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
6762 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
6763 ret = flow_dv_validate_action_modify_tp(action_flags,
6769 /* Count all modify-header actions as one action. */
6770 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6772 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6773 modify_after_mirror = 1;
6774 action_flags |= actions->type ==
6775 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
6776 MLX5_FLOW_ACTION_SET_TP_SRC :
6777 MLX5_FLOW_ACTION_SET_TP_DST;
6778 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
6780 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
6781 case RTE_FLOW_ACTION_TYPE_SET_TTL:
6782 ret = flow_dv_validate_action_modify_ttl(action_flags,
6788 /* Count all modify-header actions as one action. */
6789 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6791 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6792 modify_after_mirror = 1;
6793 action_flags |= actions->type ==
6794 RTE_FLOW_ACTION_TYPE_SET_TTL ?
6795 MLX5_FLOW_ACTION_SET_TTL :
6796 MLX5_FLOW_ACTION_DEC_TTL;
6797 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
6799 case RTE_FLOW_ACTION_TYPE_JUMP:
6800 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
6806 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
6808 return rte_flow_error_set(error, EINVAL,
6809 RTE_FLOW_ERROR_TYPE_ACTION,
6811 "sample and jump action combination is not supported");
6813 action_flags |= MLX5_FLOW_ACTION_JUMP;
6815 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
6816 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
6817 ret = flow_dv_validate_action_modify_tcp_seq
6824 /* Count all modify-header actions as one action. */
6825 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6827 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6828 modify_after_mirror = 1;
6829 action_flags |= actions->type ==
6830 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
6831 MLX5_FLOW_ACTION_INC_TCP_SEQ :
6832 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
6833 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
6835 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
6836 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
6837 ret = flow_dv_validate_action_modify_tcp_ack
6844 /* Count all modify-header actions as one action. */
6845 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6847 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6848 modify_after_mirror = 1;
6849 action_flags |= actions->type ==
6850 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
6851 MLX5_FLOW_ACTION_INC_TCP_ACK :
6852 MLX5_FLOW_ACTION_DEC_TCP_ACK;
6853 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
6855 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
6857 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
6858 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
6859 rw_act_num += MLX5_ACT_NUM_SET_TAG;
6861 case RTE_FLOW_ACTION_TYPE_METER:
6862 ret = mlx5_flow_validate_action_meter(dev,
6868 action_flags |= MLX5_FLOW_ACTION_METER;
6870 /* Meter action will add one more TAG action. */
6871 rw_act_num += MLX5_ACT_NUM_SET_TAG;
6873 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
6874 if (!attr->transfer && !attr->group)
6875 return rte_flow_error_set(error, ENOTSUP,
6876 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6878 "Shared ASO age action is not supported for group 0");
6879 action_flags |= MLX5_FLOW_ACTION_AGE;
6882 case RTE_FLOW_ACTION_TYPE_AGE:
6883 ret = flow_dv_validate_action_age(action_flags,
6889 * Validate the regular AGE action (using counter)
6890 * mutual exclusion with share counter actions.
6892 if (!priv->sh->flow_hit_aso_en) {
6893 if (count && count->shared)
6894 return rte_flow_error_set
6896 RTE_FLOW_ERROR_TYPE_ACTION,
6898 "old age and shared count combination is not supported");
6900 return rte_flow_error_set
6902 RTE_FLOW_ERROR_TYPE_ACTION,
6904 "old age action and count must be in the same sub flow");
6906 action_flags |= MLX5_FLOW_ACTION_AGE;
6909 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
6910 ret = flow_dv_validate_action_modify_ipv4_dscp
6917 /* Count all modify-header actions as one action. */
6918 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6920 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6921 modify_after_mirror = 1;
6922 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
6923 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
6925 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
6926 ret = flow_dv_validate_action_modify_ipv6_dscp
6933 /* Count all modify-header actions as one action. */
6934 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6936 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6937 modify_after_mirror = 1;
6938 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
6939 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
6941 case RTE_FLOW_ACTION_TYPE_SAMPLE:
6942 ret = flow_dv_validate_action_sample(&action_flags,
6951 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
6954 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
6955 if (actions[0].type != (typeof(actions[0].type))
6956 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET)
6957 return rte_flow_error_set
6959 RTE_FLOW_ERROR_TYPE_ACTION,
6960 NULL, "MLX5 private action "
6961 "must be the first");
6963 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6965 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
6966 ret = flow_dv_validate_action_modify_field(dev,
6973 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
6974 modify_after_mirror = 1;
6975 /* Count all modify-header actions as one action. */
6976 if (!(action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD))
6978 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
6982 return rte_flow_error_set(error, ENOTSUP,
6983 RTE_FLOW_ERROR_TYPE_ACTION,
6985 "action not supported");
6989 * Validate actions in flow rules
6990 * - Explicit decap action is prohibited by the tunnel offload API.
6991 * - Drop action in tunnel steer rule is prohibited by the API.
6992 * - Application cannot use MARK action because it's value can mask
6993 * tunnel default miss nitification.
6994 * - JUMP in tunnel match rule has no support in current PMD
6996 * - TAG & META are reserved for future uses.
6998 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
6999 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7000 MLX5_FLOW_ACTION_MARK |
7001 MLX5_FLOW_ACTION_SET_TAG |
7002 MLX5_FLOW_ACTION_SET_META |
7003 MLX5_FLOW_ACTION_DROP;
7005 if (action_flags & bad_actions_mask)
7006 return rte_flow_error_set
7008 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7009 "Invalid RTE action in tunnel "
7011 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
7012 return rte_flow_error_set
7014 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7015 "tunnel set decap rule must terminate "
7018 return rte_flow_error_set
7020 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7021 "tunnel flows for ingress traffic only");
7023 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
7024 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
7025 MLX5_FLOW_ACTION_MARK |
7026 MLX5_FLOW_ACTION_SET_TAG |
7027 MLX5_FLOW_ACTION_SET_META;
7029 if (action_flags & bad_actions_mask)
7030 return rte_flow_error_set
7032 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7033 "Invalid RTE action in tunnel "
7037 * Validate the drop action mutual exclusion with other actions.
7038 * Drop action is mutually-exclusive with any other action, except for
7040 * Drop action compatibility with tunnel offload was already validated.
7042 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
7043 MLX5_FLOW_ACTION_TUNNEL_MATCH));
7044 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
7045 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
7046 return rte_flow_error_set(error, EINVAL,
7047 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7048 "Drop action is mutually-exclusive "
7049 "with any other action, except for "
7051 /* Eswitch has few restrictions on using items and actions */
7052 if (attr->transfer) {
7053 if (!mlx5_flow_ext_mreg_supported(dev) &&
7054 action_flags & MLX5_FLOW_ACTION_FLAG)
7055 return rte_flow_error_set(error, ENOTSUP,
7056 RTE_FLOW_ERROR_TYPE_ACTION,
7058 "unsupported action FLAG");
7059 if (!mlx5_flow_ext_mreg_supported(dev) &&
7060 action_flags & MLX5_FLOW_ACTION_MARK)
7061 return rte_flow_error_set(error, ENOTSUP,
7062 RTE_FLOW_ERROR_TYPE_ACTION,
7064 "unsupported action MARK");
7065 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
7066 return rte_flow_error_set(error, ENOTSUP,
7067 RTE_FLOW_ERROR_TYPE_ACTION,
7069 "unsupported action QUEUE");
7070 if (action_flags & MLX5_FLOW_ACTION_RSS)
7071 return rte_flow_error_set(error, ENOTSUP,
7072 RTE_FLOW_ERROR_TYPE_ACTION,
7074 "unsupported action RSS");
7075 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
7076 return rte_flow_error_set(error, EINVAL,
7077 RTE_FLOW_ERROR_TYPE_ACTION,
7079 "no fate action is found");
7081 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
7082 return rte_flow_error_set(error, EINVAL,
7083 RTE_FLOW_ERROR_TYPE_ACTION,
7085 "no fate action is found");
7088 * Continue validation for Xcap and VLAN actions.
7089 * If hairpin is working in explicit TX rule mode, there is no actions
7090 * splitting and the validation of hairpin ingress flow should be the
7091 * same as other standard flows.
7093 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
7094 MLX5_FLOW_VLAN_ACTIONS)) &&
7095 (queue_index == 0xFFFF ||
7096 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN ||
7097 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
7098 conf->tx_explicit != 0))) {
7099 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
7100 MLX5_FLOW_XCAP_ACTIONS)
7101 return rte_flow_error_set(error, ENOTSUP,
7102 RTE_FLOW_ERROR_TYPE_ACTION,
7103 NULL, "encap and decap "
7104 "combination aren't supported");
7105 if (!attr->transfer && attr->ingress) {
7106 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7107 return rte_flow_error_set
7109 RTE_FLOW_ERROR_TYPE_ACTION,
7110 NULL, "encap is not supported"
7111 " for ingress traffic");
7112 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7113 return rte_flow_error_set
7115 RTE_FLOW_ERROR_TYPE_ACTION,
7116 NULL, "push VLAN action not "
7117 "supported for ingress");
7118 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
7119 MLX5_FLOW_VLAN_ACTIONS)
7120 return rte_flow_error_set
7122 RTE_FLOW_ERROR_TYPE_ACTION,
7123 NULL, "no support for "
7124 "multiple VLAN actions");
7128 * Hairpin flow will add one more TAG action in TX implicit mode.
7129 * In TX explicit mode, there will be no hairpin flow ID.
7132 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7133 /* extra metadata enabled: one more TAG action will be add. */
7134 if (dev_conf->dv_flow_en &&
7135 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
7136 mlx5_flow_ext_mreg_supported(dev))
7137 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7139 flow_dv_modify_hdr_action_max(dev, is_root)) {
7140 return rte_flow_error_set(error, ENOTSUP,
7141 RTE_FLOW_ERROR_TYPE_ACTION,
7142 NULL, "too many header modify"
7143 " actions to support");
7145 /* Eswitch egress mirror and modify flow has limitation on CX5 */
7146 if (fdb_mirror_limit && modify_after_mirror)
7147 return rte_flow_error_set(error, EINVAL,
7148 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7149 "sample before modify action is not supported");
7154 * Internal preparation function. Allocates the DV flow size,
7155 * this size is constant.
7158 * Pointer to the rte_eth_dev structure.
7160 * Pointer to the flow attributes.
7162 * Pointer to the list of items.
7163 * @param[in] actions
7164 * Pointer to the list of actions.
7166 * Pointer to the error structure.
7169 * Pointer to mlx5_flow object on success,
7170 * otherwise NULL and rte_errno is set.
7172 static struct mlx5_flow *
7173 flow_dv_prepare(struct rte_eth_dev *dev,
7174 const struct rte_flow_attr *attr __rte_unused,
7175 const struct rte_flow_item items[] __rte_unused,
7176 const struct rte_flow_action actions[] __rte_unused,
7177 struct rte_flow_error *error)
7179 uint32_t handle_idx = 0;
7180 struct mlx5_flow *dev_flow;
7181 struct mlx5_flow_handle *dev_handle;
7182 struct mlx5_priv *priv = dev->data->dev_private;
7183 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7186 /* In case of corrupting the memory. */
7187 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
7188 rte_flow_error_set(error, ENOSPC,
7189 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7190 "not free temporary device flow");
7193 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
7196 rte_flow_error_set(error, ENOMEM,
7197 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7198 "not enough memory to create flow handle");
7201 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
7202 dev_flow = &wks->flows[wks->flow_idx++];
7203 memset(dev_flow, 0, sizeof(*dev_flow));
7204 dev_flow->handle = dev_handle;
7205 dev_flow->handle_idx = handle_idx;
7207 * In some old rdma-core releases, before continuing, a check of the
7208 * length of matching parameter will be done at first. It needs to use
7209 * the length without misc4 param. If the flow has misc4 support, then
7210 * the length needs to be adjusted accordingly. Each param member is
7211 * aligned with a 64B boundary naturally.
7213 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param) -
7214 MLX5_ST_SZ_BYTES(fte_match_set_misc4);
7215 dev_flow->ingress = attr->ingress;
7216 dev_flow->dv.transfer = attr->transfer;
7220 #ifdef RTE_LIBRTE_MLX5_DEBUG
7222 * Sanity check for match mask and value. Similar to check_valid_spec() in
7223 * kernel driver. If unmasked bit is present in value, it returns failure.
7226 * pointer to match mask buffer.
7227 * @param match_value
7228 * pointer to match value buffer.
7231 * 0 if valid, -EINVAL otherwise.
7234 flow_dv_check_valid_spec(void *match_mask, void *match_value)
7236 uint8_t *m = match_mask;
7237 uint8_t *v = match_value;
7240 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
7243 "match_value differs from match_criteria"
7244 " %p[%u] != %p[%u]",
7245 match_value, i, match_mask, i);
7254 * Add match of ip_version.
7258 * @param[in] headers_v
7259 * Values header pointer.
7260 * @param[in] headers_m
7261 * Masks header pointer.
7262 * @param[in] ip_version
7263 * The IP version to set.
7266 flow_dv_set_match_ip_version(uint32_t group,
7272 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
7274 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
7276 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
7277 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
7278 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
7282 * Add Ethernet item to matcher and to the value.
7284 * @param[in, out] matcher
7286 * @param[in, out] key
7287 * Flow matcher value.
7289 * Flow pattern to translate.
7291 * Item is inner pattern.
7294 flow_dv_translate_item_eth(void *matcher, void *key,
7295 const struct rte_flow_item *item, int inner,
7298 const struct rte_flow_item_eth *eth_m = item->mask;
7299 const struct rte_flow_item_eth *eth_v = item->spec;
7300 const struct rte_flow_item_eth nic_mask = {
7301 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
7302 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
7303 .type = RTE_BE16(0xffff),
7316 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
7318 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7320 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
7322 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7324 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
7325 ð_m->dst, sizeof(eth_m->dst));
7326 /* The value must be in the range of the mask. */
7327 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
7328 for (i = 0; i < sizeof(eth_m->dst); ++i)
7329 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
7330 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
7331 ð_m->src, sizeof(eth_m->src));
7332 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
7333 /* The value must be in the range of the mask. */
7334 for (i = 0; i < sizeof(eth_m->dst); ++i)
7335 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
7337 * HW supports match on one Ethertype, the Ethertype following the last
7338 * VLAN tag of the packet (see PRM).
7339 * Set match on ethertype only if ETH header is not followed by VLAN.
7340 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
7341 * ethertype, and use ip_version field instead.
7342 * eCPRI over Ether layer will use type value 0xAEFE.
7344 if (eth_m->type == 0xFFFF) {
7345 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
7346 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
7347 switch (eth_v->type) {
7348 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
7349 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
7351 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
7352 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
7353 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
7355 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
7356 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
7358 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
7359 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
7365 if (eth_m->has_vlan) {
7366 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
7367 if (eth_v->has_vlan) {
7369 * Here, when also has_more_vlan field in VLAN item is
7370 * not set, only single-tagged packets will be matched.
7372 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
7376 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
7377 rte_be_to_cpu_16(eth_m->type));
7378 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
7379 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
7383 * Add VLAN item to matcher and to the value.
7385 * @param[in, out] dev_flow
7387 * @param[in, out] matcher
7389 * @param[in, out] key
7390 * Flow matcher value.
7392 * Flow pattern to translate.
7394 * Item is inner pattern.
7397 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
7398 void *matcher, void *key,
7399 const struct rte_flow_item *item,
7400 int inner, uint32_t group)
7402 const struct rte_flow_item_vlan *vlan_m = item->mask;
7403 const struct rte_flow_item_vlan *vlan_v = item->spec;
7410 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
7412 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7414 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
7416 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7418 * This is workaround, masks are not supported,
7419 * and pre-validated.
7422 dev_flow->handle->vf_vlan.tag =
7423 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
7426 * When VLAN item exists in flow, mark packet as tagged,
7427 * even if TCI is not specified.
7429 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
7430 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
7431 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
7436 vlan_m = &rte_flow_item_vlan_mask;
7437 tci_m = rte_be_to_cpu_16(vlan_m->tci);
7438 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
7439 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
7440 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
7441 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
7442 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
7443 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
7444 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
7446 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
7447 * ethertype, and use ip_version field instead.
7449 if (vlan_m->inner_type == 0xFFFF) {
7450 switch (vlan_v->inner_type) {
7451 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
7452 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
7453 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
7454 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
7456 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
7457 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
7459 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
7460 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
7466 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
7467 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
7468 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
7469 /* Only one vlan_tag bit can be set. */
7470 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
7473 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
7474 rte_be_to_cpu_16(vlan_m->inner_type));
7475 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
7476 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
7480 * Add IPV4 item to matcher and to the value.
7482 * @param[in, out] matcher
7484 * @param[in, out] key
7485 * Flow matcher value.
7487 * Flow pattern to translate.
7489 * Item is inner pattern.
7491 * The group to insert the rule.
7494 flow_dv_translate_item_ipv4(void *matcher, void *key,
7495 const struct rte_flow_item *item,
7496 int inner, uint32_t group)
7498 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
7499 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
7500 const struct rte_flow_item_ipv4 nic_mask = {
7502 .src_addr = RTE_BE32(0xffffffff),
7503 .dst_addr = RTE_BE32(0xffffffff),
7504 .type_of_service = 0xff,
7505 .next_proto_id = 0xff,
7506 .time_to_live = 0xff,
7516 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7518 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7520 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7522 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7524 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
7529 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
7530 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
7531 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
7532 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
7533 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
7534 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
7535 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
7536 src_ipv4_src_ipv6.ipv4_layout.ipv4);
7537 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
7538 src_ipv4_src_ipv6.ipv4_layout.ipv4);
7539 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
7540 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
7541 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
7542 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
7543 ipv4_m->hdr.type_of_service);
7544 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
7545 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
7546 ipv4_m->hdr.type_of_service >> 2);
7547 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
7548 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
7549 ipv4_m->hdr.next_proto_id);
7550 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
7551 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
7552 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
7553 ipv4_m->hdr.time_to_live);
7554 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
7555 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
7556 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
7557 !!(ipv4_m->hdr.fragment_offset));
7558 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
7559 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
7563 * Add IPV6 item to matcher and to the value.
7565 * @param[in, out] matcher
7567 * @param[in, out] key
7568 * Flow matcher value.
7570 * Flow pattern to translate.
7572 * Item is inner pattern.
7574 * The group to insert the rule.
7577 flow_dv_translate_item_ipv6(void *matcher, void *key,
7578 const struct rte_flow_item *item,
7579 int inner, uint32_t group)
7581 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
7582 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
7583 const struct rte_flow_item_ipv6 nic_mask = {
7586 "\xff\xff\xff\xff\xff\xff\xff\xff"
7587 "\xff\xff\xff\xff\xff\xff\xff\xff",
7589 "\xff\xff\xff\xff\xff\xff\xff\xff"
7590 "\xff\xff\xff\xff\xff\xff\xff\xff",
7591 .vtc_flow = RTE_BE32(0xffffffff),
7598 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7599 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7608 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7610 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7612 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7614 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7616 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
7621 size = sizeof(ipv6_m->hdr.dst_addr);
7622 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
7623 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
7624 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
7625 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
7626 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
7627 for (i = 0; i < size; ++i)
7628 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
7629 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
7630 src_ipv4_src_ipv6.ipv6_layout.ipv6);
7631 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
7632 src_ipv4_src_ipv6.ipv6_layout.ipv6);
7633 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
7634 for (i = 0; i < size; ++i)
7635 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
7637 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
7638 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
7639 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
7640 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
7641 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
7642 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
7645 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
7647 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
7650 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
7652 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
7656 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
7658 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
7659 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
7661 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
7662 ipv6_m->hdr.hop_limits);
7663 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
7664 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
7665 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
7666 !!(ipv6_m->has_frag_ext));
7667 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
7668 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
7672 * Add IPV6 fragment extension item to matcher and to the value.
7674 * @param[in, out] matcher
7676 * @param[in, out] key
7677 * Flow matcher value.
7679 * Flow pattern to translate.
7681 * Item is inner pattern.
7684 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
7685 const struct rte_flow_item *item,
7688 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
7689 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
7690 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
7692 .next_header = 0xff,
7693 .frag_data = RTE_BE16(0xffff),
7700 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7702 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7704 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7706 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7708 /* IPv6 fragment extension item exists, so packet is IP fragment. */
7709 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
7710 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
7711 if (!ipv6_frag_ext_v)
7713 if (!ipv6_frag_ext_m)
7714 ipv6_frag_ext_m = &nic_mask;
7715 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
7716 ipv6_frag_ext_m->hdr.next_header);
7717 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
7718 ipv6_frag_ext_v->hdr.next_header &
7719 ipv6_frag_ext_m->hdr.next_header);
7723 * Add TCP item to matcher and to the value.
7725 * @param[in, out] matcher
7727 * @param[in, out] key
7728 * Flow matcher value.
7730 * Flow pattern to translate.
7732 * Item is inner pattern.
7735 flow_dv_translate_item_tcp(void *matcher, void *key,
7736 const struct rte_flow_item *item,
7739 const struct rte_flow_item_tcp *tcp_m = item->mask;
7740 const struct rte_flow_item_tcp *tcp_v = item->spec;
7745 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7747 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7749 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7751 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7753 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
7754 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
7758 tcp_m = &rte_flow_item_tcp_mask;
7759 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
7760 rte_be_to_cpu_16(tcp_m->hdr.src_port));
7761 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
7762 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
7763 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
7764 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
7765 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
7766 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
7767 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
7768 tcp_m->hdr.tcp_flags);
7769 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
7770 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
7774 * Add UDP item to matcher and to the value.
7776 * @param[in, out] matcher
7778 * @param[in, out] key
7779 * Flow matcher value.
7781 * Flow pattern to translate.
7783 * Item is inner pattern.
7786 flow_dv_translate_item_udp(void *matcher, void *key,
7787 const struct rte_flow_item *item,
7790 const struct rte_flow_item_udp *udp_m = item->mask;
7791 const struct rte_flow_item_udp *udp_v = item->spec;
7796 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7798 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7800 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7802 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7804 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
7805 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
7809 udp_m = &rte_flow_item_udp_mask;
7810 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
7811 rte_be_to_cpu_16(udp_m->hdr.src_port));
7812 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
7813 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
7814 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
7815 rte_be_to_cpu_16(udp_m->hdr.dst_port));
7816 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
7817 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
7821 * Add GRE optional Key item to matcher and to the value.
7823 * @param[in, out] matcher
7825 * @param[in, out] key
7826 * Flow matcher value.
7828 * Flow pattern to translate.
7830 * Item is inner pattern.
7833 flow_dv_translate_item_gre_key(void *matcher, void *key,
7834 const struct rte_flow_item *item)
7836 const rte_be32_t *key_m = item->mask;
7837 const rte_be32_t *key_v = item->spec;
7838 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7839 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7840 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
7842 /* GRE K bit must be on and should already be validated */
7843 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
7844 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
7848 key_m = &gre_key_default_mask;
7849 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
7850 rte_be_to_cpu_32(*key_m) >> 8);
7851 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
7852 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
7853 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
7854 rte_be_to_cpu_32(*key_m) & 0xFF);
7855 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
7856 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
7860 * Add GRE item to matcher and to the value.
7862 * @param[in, out] matcher
7864 * @param[in, out] key
7865 * Flow matcher value.
7867 * Flow pattern to translate.
7869 * Item is inner pattern.
7872 flow_dv_translate_item_gre(void *matcher, void *key,
7873 const struct rte_flow_item *item,
7876 const struct rte_flow_item_gre *gre_m = item->mask;
7877 const struct rte_flow_item_gre *gre_v = item->spec;
7880 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7881 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7888 uint16_t s_present:1;
7889 uint16_t k_present:1;
7890 uint16_t rsvd_bit1:1;
7891 uint16_t c_present:1;
7895 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
7898 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7900 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7902 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7904 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7906 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
7907 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
7911 gre_m = &rte_flow_item_gre_mask;
7912 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
7913 rte_be_to_cpu_16(gre_m->protocol));
7914 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
7915 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
7916 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
7917 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
7918 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
7919 gre_crks_rsvd0_ver_m.c_present);
7920 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
7921 gre_crks_rsvd0_ver_v.c_present &
7922 gre_crks_rsvd0_ver_m.c_present);
7923 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
7924 gre_crks_rsvd0_ver_m.k_present);
7925 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
7926 gre_crks_rsvd0_ver_v.k_present &
7927 gre_crks_rsvd0_ver_m.k_present);
7928 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
7929 gre_crks_rsvd0_ver_m.s_present);
7930 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
7931 gre_crks_rsvd0_ver_v.s_present &
7932 gre_crks_rsvd0_ver_m.s_present);
7936 * Add NVGRE item to matcher and to the value.
7938 * @param[in, out] matcher
7940 * @param[in, out] key
7941 * Flow matcher value.
7943 * Flow pattern to translate.
7945 * Item is inner pattern.
7948 flow_dv_translate_item_nvgre(void *matcher, void *key,
7949 const struct rte_flow_item *item,
7952 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
7953 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
7954 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7955 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7956 const char *tni_flow_id_m;
7957 const char *tni_flow_id_v;
7963 /* For NVGRE, GRE header fields must be set with defined values. */
7964 const struct rte_flow_item_gre gre_spec = {
7965 .c_rsvd0_ver = RTE_BE16(0x2000),
7966 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
7968 const struct rte_flow_item_gre gre_mask = {
7969 .c_rsvd0_ver = RTE_BE16(0xB000),
7970 .protocol = RTE_BE16(UINT16_MAX),
7972 const struct rte_flow_item gre_item = {
7977 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
7981 nvgre_m = &rte_flow_item_nvgre_mask;
7982 tni_flow_id_m = (const char *)nvgre_m->tni;
7983 tni_flow_id_v = (const char *)nvgre_v->tni;
7984 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
7985 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
7986 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
7987 memcpy(gre_key_m, tni_flow_id_m, size);
7988 for (i = 0; i < size; ++i)
7989 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
7993 * Add VXLAN item to matcher and to the value.
7995 * @param[in, out] matcher
7997 * @param[in, out] key
7998 * Flow matcher value.
8000 * Flow pattern to translate.
8002 * Item is inner pattern.
8005 flow_dv_translate_item_vxlan(void *matcher, void *key,
8006 const struct rte_flow_item *item,
8009 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
8010 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
8013 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8014 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8022 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8024 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8026 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8028 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8030 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8031 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8032 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8033 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8034 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8039 vxlan_m = &rte_flow_item_vxlan_mask;
8040 size = sizeof(vxlan_m->vni);
8041 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
8042 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
8043 memcpy(vni_m, vxlan_m->vni, size);
8044 for (i = 0; i < size; ++i)
8045 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8049 * Add VXLAN-GPE item to matcher and to the value.
8051 * @param[in, out] matcher
8053 * @param[in, out] key
8054 * Flow matcher value.
8056 * Flow pattern to translate.
8058 * Item is inner pattern.
8062 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
8063 const struct rte_flow_item *item, int inner)
8065 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
8066 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
8070 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
8072 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8078 uint8_t flags_m = 0xff;
8079 uint8_t flags_v = 0xc;
8082 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8084 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8086 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8088 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8090 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8091 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8092 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8093 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8094 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8099 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
8100 size = sizeof(vxlan_m->vni);
8101 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
8102 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
8103 memcpy(vni_m, vxlan_m->vni, size);
8104 for (i = 0; i < size; ++i)
8105 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8106 if (vxlan_m->flags) {
8107 flags_m = vxlan_m->flags;
8108 flags_v = vxlan_v->flags;
8110 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
8111 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
8112 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
8114 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
8119 * Add Geneve item to matcher and to the value.
8121 * @param[in, out] matcher
8123 * @param[in, out] key
8124 * Flow matcher value.
8126 * Flow pattern to translate.
8128 * Item is inner pattern.
8132 flow_dv_translate_item_geneve(void *matcher, void *key,
8133 const struct rte_flow_item *item, int inner)
8135 const struct rte_flow_item_geneve *geneve_m = item->mask;
8136 const struct rte_flow_item_geneve *geneve_v = item->spec;
8139 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8140 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8149 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8151 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8153 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8155 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8157 dport = MLX5_UDP_PORT_GENEVE;
8158 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8159 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8160 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8165 geneve_m = &rte_flow_item_geneve_mask;
8166 size = sizeof(geneve_m->vni);
8167 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
8168 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
8169 memcpy(vni_m, geneve_m->vni, size);
8170 for (i = 0; i < size; ++i)
8171 vni_v[i] = vni_m[i] & geneve_v->vni[i];
8172 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
8173 rte_be_to_cpu_16(geneve_m->protocol));
8174 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
8175 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
8176 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
8177 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
8178 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
8179 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
8180 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
8181 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
8182 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
8183 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
8184 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
8185 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
8186 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
8190 * Create Geneve TLV option resource.
8192 * @param dev[in, out]
8193 * Pointer to rte_eth_dev structure.
8194 * @param[in, out] tag_be24
8195 * Tag value in big endian then R-shift 8.
8196 * @parm[in, out] dev_flow
8197 * Pointer to the dev_flow.
8199 * pointer to error structure.
8202 * 0 on success otherwise -errno and errno is set.
8206 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
8207 const struct rte_flow_item *item,
8208 struct rte_flow_error *error)
8210 struct mlx5_priv *priv = dev->data->dev_private;
8211 struct mlx5_dev_ctx_shared *sh = priv->sh;
8212 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
8213 sh->geneve_tlv_option_resource;
8214 struct mlx5_devx_obj *obj;
8215 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
8220 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
8221 if (geneve_opt_resource != NULL) {
8222 if (geneve_opt_resource->option_class ==
8223 geneve_opt_v->option_class &&
8224 geneve_opt_resource->option_type ==
8225 geneve_opt_v->option_type &&
8226 geneve_opt_resource->length ==
8227 geneve_opt_v->option_len) {
8228 /* We already have GENVE TLV option obj allocated. */
8229 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
8232 ret = rte_flow_error_set(error, ENOMEM,
8233 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8234 "Only one GENEVE TLV option supported");
8238 /* Create a GENEVE TLV object and resource. */
8239 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->ctx,
8240 geneve_opt_v->option_class,
8241 geneve_opt_v->option_type,
8242 geneve_opt_v->option_len);
8244 ret = rte_flow_error_set(error, ENODATA,
8245 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8246 "Failed to create GENEVE TLV Devx object");
8249 sh->geneve_tlv_option_resource =
8250 mlx5_malloc(MLX5_MEM_ZERO,
8251 sizeof(*geneve_opt_resource),
8253 if (!sh->geneve_tlv_option_resource) {
8254 claim_zero(mlx5_devx_cmd_destroy(obj));
8255 ret = rte_flow_error_set(error, ENOMEM,
8256 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8257 "GENEVE TLV object memory allocation failed");
8260 geneve_opt_resource = sh->geneve_tlv_option_resource;
8261 geneve_opt_resource->obj = obj;
8262 geneve_opt_resource->option_class = geneve_opt_v->option_class;
8263 geneve_opt_resource->option_type = geneve_opt_v->option_type;
8264 geneve_opt_resource->length = geneve_opt_v->option_len;
8265 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
8269 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
8274 * Add Geneve TLV option item to matcher.
8276 * @param[in, out] dev
8277 * Pointer to rte_eth_dev structure.
8278 * @param[in, out] matcher
8280 * @param[in, out] key
8281 * Flow matcher value.
8283 * Flow pattern to translate.
8285 * Pointer to error structure.
8288 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
8289 void *key, const struct rte_flow_item *item,
8290 struct rte_flow_error *error)
8292 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
8293 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
8294 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8295 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8296 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
8298 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8299 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
8305 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
8306 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
8309 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
8313 * Set the option length in GENEVE header if not requested.
8314 * The GENEVE TLV option length is expressed by the option length field
8315 * in the GENEVE header.
8316 * If the option length was not requested but the GENEVE TLV option item
8317 * is present we set the option length field implicitly.
8319 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
8320 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
8321 MLX5_GENEVE_OPTLEN_MASK);
8322 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
8323 geneve_opt_v->option_len + 1);
8326 if (geneve_opt_v->data) {
8327 memcpy(&opt_data_key, geneve_opt_v->data,
8328 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
8329 sizeof(opt_data_key)));
8330 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
8331 sizeof(opt_data_key));
8332 memcpy(&opt_data_mask, geneve_opt_m->data,
8333 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
8334 sizeof(opt_data_mask)));
8335 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
8336 sizeof(opt_data_mask));
8337 MLX5_SET(fte_match_set_misc3, misc3_m,
8338 geneve_tlv_option_0_data,
8339 rte_be_to_cpu_32(opt_data_mask));
8340 MLX5_SET(fte_match_set_misc3, misc3_v,
8341 geneve_tlv_option_0_data,
8342 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
8348 * Add MPLS item to matcher and to the value.
8350 * @param[in, out] matcher
8352 * @param[in, out] key
8353 * Flow matcher value.
8355 * Flow pattern to translate.
8356 * @param[in] prev_layer
8357 * The protocol layer indicated in previous item.
8359 * Item is inner pattern.
8362 flow_dv_translate_item_mpls(void *matcher, void *key,
8363 const struct rte_flow_item *item,
8364 uint64_t prev_layer,
8367 const uint32_t *in_mpls_m = item->mask;
8368 const uint32_t *in_mpls_v = item->spec;
8369 uint32_t *out_mpls_m = 0;
8370 uint32_t *out_mpls_v = 0;
8371 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8372 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8373 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
8375 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
8376 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
8377 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8379 switch (prev_layer) {
8380 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
8381 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
8382 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8383 MLX5_UDP_PORT_MPLS);
8385 case MLX5_FLOW_LAYER_GRE:
8386 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
8387 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8388 RTE_ETHER_TYPE_MPLS);
8391 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8392 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8399 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
8400 switch (prev_layer) {
8401 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
8403 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
8404 outer_first_mpls_over_udp);
8406 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
8407 outer_first_mpls_over_udp);
8409 case MLX5_FLOW_LAYER_GRE:
8411 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
8412 outer_first_mpls_over_gre);
8414 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
8415 outer_first_mpls_over_gre);
8418 /* Inner MPLS not over GRE is not supported. */
8421 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
8425 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
8431 if (out_mpls_m && out_mpls_v) {
8432 *out_mpls_m = *in_mpls_m;
8433 *out_mpls_v = *in_mpls_v & *in_mpls_m;
8438 * Add metadata register item to matcher
8440 * @param[in, out] matcher
8442 * @param[in, out] key
8443 * Flow matcher value.
8444 * @param[in] reg_type
8445 * Type of device metadata register
8452 flow_dv_match_meta_reg(void *matcher, void *key,
8453 enum modify_reg reg_type,
8454 uint32_t data, uint32_t mask)
8457 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
8459 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
8465 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
8466 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
8469 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
8470 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
8474 * The metadata register C0 field might be divided into
8475 * source vport index and META item value, we should set
8476 * this field according to specified mask, not as whole one.
8478 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
8480 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
8481 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
8484 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
8487 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
8488 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
8491 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
8492 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
8495 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
8496 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
8499 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
8500 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
8503 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
8504 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
8507 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
8508 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
8511 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
8512 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
8521 * Add MARK item to matcher
8524 * The device to configure through.
8525 * @param[in, out] matcher
8527 * @param[in, out] key
8528 * Flow matcher value.
8530 * Flow pattern to translate.
8533 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
8534 void *matcher, void *key,
8535 const struct rte_flow_item *item)
8537 struct mlx5_priv *priv = dev->data->dev_private;
8538 const struct rte_flow_item_mark *mark;
8542 mark = item->mask ? (const void *)item->mask :
8543 &rte_flow_item_mark_mask;
8544 mask = mark->id & priv->sh->dv_mark_mask;
8545 mark = (const void *)item->spec;
8547 value = mark->id & priv->sh->dv_mark_mask & mask;
8549 enum modify_reg reg;
8551 /* Get the metadata register index for the mark. */
8552 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
8553 MLX5_ASSERT(reg > 0);
8554 if (reg == REG_C_0) {
8555 struct mlx5_priv *priv = dev->data->dev_private;
8556 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
8557 uint32_t shl_c0 = rte_bsf32(msk_c0);
8563 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
8568 * Add META item to matcher
8571 * The devich to configure through.
8572 * @param[in, out] matcher
8574 * @param[in, out] key
8575 * Flow matcher value.
8577 * Attributes of flow that includes this item.
8579 * Flow pattern to translate.
8582 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
8583 void *matcher, void *key,
8584 const struct rte_flow_attr *attr,
8585 const struct rte_flow_item *item)
8587 const struct rte_flow_item_meta *meta_m;
8588 const struct rte_flow_item_meta *meta_v;
8590 meta_m = (const void *)item->mask;
8592 meta_m = &rte_flow_item_meta_mask;
8593 meta_v = (const void *)item->spec;
8596 uint32_t value = meta_v->data;
8597 uint32_t mask = meta_m->data;
8599 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
8602 MLX5_ASSERT(reg != REG_NON);
8604 * In datapath code there is no endianness
8605 * coversions for perfromance reasons, all
8606 * pattern conversions are done in rte_flow.
8608 value = rte_cpu_to_be_32(value);
8609 mask = rte_cpu_to_be_32(mask);
8610 if (reg == REG_C_0) {
8611 struct mlx5_priv *priv = dev->data->dev_private;
8612 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
8613 uint32_t shl_c0 = rte_bsf32(msk_c0);
8614 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
8615 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
8622 MLX5_ASSERT(msk_c0);
8623 MLX5_ASSERT(!(~msk_c0 & mask));
8625 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
8630 * Add vport metadata Reg C0 item to matcher
8632 * @param[in, out] matcher
8634 * @param[in, out] key
8635 * Flow matcher value.
8637 * Flow pattern to translate.
8640 flow_dv_translate_item_meta_vport(void *matcher, void *key,
8641 uint32_t value, uint32_t mask)
8643 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
8647 * Add tag item to matcher
8650 * The devich to configure through.
8651 * @param[in, out] matcher
8653 * @param[in, out] key
8654 * Flow matcher value.
8656 * Flow pattern to translate.
8659 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
8660 void *matcher, void *key,
8661 const struct rte_flow_item *item)
8663 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
8664 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
8665 uint32_t mask, value;
8668 value = tag_v->data;
8669 mask = tag_m ? tag_m->data : UINT32_MAX;
8670 if (tag_v->id == REG_C_0) {
8671 struct mlx5_priv *priv = dev->data->dev_private;
8672 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
8673 uint32_t shl_c0 = rte_bsf32(msk_c0);
8679 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
8683 * Add TAG item to matcher
8686 * The devich to configure through.
8687 * @param[in, out] matcher
8689 * @param[in, out] key
8690 * Flow matcher value.
8692 * Flow pattern to translate.
8695 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
8696 void *matcher, void *key,
8697 const struct rte_flow_item *item)
8699 const struct rte_flow_item_tag *tag_v = item->spec;
8700 const struct rte_flow_item_tag *tag_m = item->mask;
8701 enum modify_reg reg;
8704 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
8705 /* Get the metadata register index for the tag. */
8706 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
8707 MLX5_ASSERT(reg > 0);
8708 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
8712 * Add source vport match to the specified matcher.
8714 * @param[in, out] matcher
8716 * @param[in, out] key
8717 * Flow matcher value.
8719 * Source vport value to match
8724 flow_dv_translate_item_source_vport(void *matcher, void *key,
8725 int16_t port, uint16_t mask)
8727 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8728 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8730 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
8731 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
8735 * Translate port-id item to eswitch match on port-id.
8738 * The devich to configure through.
8739 * @param[in, out] matcher
8741 * @param[in, out] key
8742 * Flow matcher value.
8744 * Flow pattern to translate.
8749 * 0 on success, a negative errno value otherwise.
8752 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
8753 void *key, const struct rte_flow_item *item,
8754 const struct rte_flow_attr *attr)
8756 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
8757 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
8758 struct mlx5_priv *priv;
8761 mask = pid_m ? pid_m->id : 0xffff;
8762 id = pid_v ? pid_v->id : dev->data->port_id;
8763 priv = mlx5_port_to_eswitch_info(id, item == NULL);
8767 * Translate to vport field or to metadata, depending on mode.
8768 * Kernel can use either misc.source_port or half of C0 metadata
8771 if (priv->vport_meta_mask) {
8773 * Provide the hint for SW steering library
8774 * to insert the flow into ingress domain and
8775 * save the extra vport match.
8777 if (mask == 0xffff && priv->vport_id == 0xffff &&
8778 priv->pf_bond < 0 && attr->transfer)
8779 flow_dv_translate_item_source_vport
8780 (matcher, key, priv->vport_id, mask);
8782 * We should always set the vport metadata register,
8783 * otherwise the SW steering library can drop
8784 * the rule if wire vport metadata value is not zero,
8785 * it depends on kernel configuration.
8787 flow_dv_translate_item_meta_vport(matcher, key,
8788 priv->vport_meta_tag,
8789 priv->vport_meta_mask);
8791 flow_dv_translate_item_source_vport(matcher, key,
8792 priv->vport_id, mask);
8798 * Add ICMP6 item to matcher and to the value.
8800 * @param[in, out] matcher
8802 * @param[in, out] key
8803 * Flow matcher value.
8805 * Flow pattern to translate.
8807 * Item is inner pattern.
8810 flow_dv_translate_item_icmp6(void *matcher, void *key,
8811 const struct rte_flow_item *item,
8814 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
8815 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
8818 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
8820 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8822 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8824 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8826 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8828 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8830 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
8831 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
8835 icmp6_m = &rte_flow_item_icmp6_mask;
8836 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
8837 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
8838 icmp6_v->type & icmp6_m->type);
8839 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
8840 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
8841 icmp6_v->code & icmp6_m->code);
8845 * Add ICMP item to matcher and to the value.
8847 * @param[in, out] matcher
8849 * @param[in, out] key
8850 * Flow matcher value.
8852 * Flow pattern to translate.
8854 * Item is inner pattern.
8857 flow_dv_translate_item_icmp(void *matcher, void *key,
8858 const struct rte_flow_item *item,
8861 const struct rte_flow_item_icmp *icmp_m = item->mask;
8862 const struct rte_flow_item_icmp *icmp_v = item->spec;
8863 uint32_t icmp_header_data_m = 0;
8864 uint32_t icmp_header_data_v = 0;
8867 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
8869 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8871 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8873 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8875 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8877 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8879 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
8880 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
8884 icmp_m = &rte_flow_item_icmp_mask;
8885 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
8886 icmp_m->hdr.icmp_type);
8887 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
8888 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
8889 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
8890 icmp_m->hdr.icmp_code);
8891 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
8892 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
8893 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
8894 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
8895 if (icmp_header_data_m) {
8896 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
8897 icmp_header_data_v |=
8898 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
8899 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
8900 icmp_header_data_m);
8901 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
8902 icmp_header_data_v & icmp_header_data_m);
8907 * Add GTP item to matcher and to the value.
8909 * @param[in, out] matcher
8911 * @param[in, out] key
8912 * Flow matcher value.
8914 * Flow pattern to translate.
8916 * Item is inner pattern.
8919 flow_dv_translate_item_gtp(void *matcher, void *key,
8920 const struct rte_flow_item *item, int inner)
8922 const struct rte_flow_item_gtp *gtp_m = item->mask;
8923 const struct rte_flow_item_gtp *gtp_v = item->spec;
8926 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
8928 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8929 uint16_t dport = RTE_GTPU_UDP_PORT;
8932 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8934 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8936 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8938 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8940 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8941 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8942 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8947 gtp_m = &rte_flow_item_gtp_mask;
8948 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
8949 gtp_m->v_pt_rsv_flags);
8950 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
8951 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
8952 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
8953 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
8954 gtp_v->msg_type & gtp_m->msg_type);
8955 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
8956 rte_be_to_cpu_32(gtp_m->teid));
8957 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
8958 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
8962 * Add GTP PSC item to matcher.
8964 * @param[in, out] matcher
8966 * @param[in, out] key
8967 * Flow matcher value.
8969 * Flow pattern to translate.
8972 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
8973 const struct rte_flow_item *item)
8975 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
8976 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
8977 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
8979 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8985 uint8_t next_ext_header_type;
8990 /* Always set E-flag match on one, regardless of GTP item settings. */
8991 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
8992 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
8993 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
8994 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
8995 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
8996 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
8997 /*Set next extension header type. */
9000 dw_2.next_ext_header_type = 0xff;
9001 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
9002 rte_cpu_to_be_32(dw_2.w32));
9005 dw_2.next_ext_header_type = 0x85;
9006 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
9007 rte_cpu_to_be_32(dw_2.w32));
9019 /*Set extension header PDU type and Qos. */
9021 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
9023 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->pdu_type);
9024 dw_0.qfi = gtp_psc_m->qfi;
9025 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
9026 rte_cpu_to_be_32(dw_0.w32));
9028 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->pdu_type &
9029 gtp_psc_m->pdu_type);
9030 dw_0.qfi = gtp_psc_v->qfi & gtp_psc_m->qfi;
9031 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
9032 rte_cpu_to_be_32(dw_0.w32));
9038 * Add eCPRI item to matcher and to the value.
9041 * The devich to configure through.
9042 * @param[in, out] matcher
9044 * @param[in, out] key
9045 * Flow matcher value.
9047 * Flow pattern to translate.
9048 * @param[in] samples
9049 * Sample IDs to be used in the matching.
9052 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
9053 void *key, const struct rte_flow_item *item)
9055 struct mlx5_priv *priv = dev->data->dev_private;
9056 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
9057 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
9058 struct rte_ecpri_common_hdr common;
9059 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
9061 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
9069 ecpri_m = &rte_flow_item_ecpri_mask;
9071 * Maximal four DW samples are supported in a single matching now.
9072 * Two are used now for a eCPRI matching:
9073 * 1. Type: one byte, mask should be 0x00ff0000 in network order
9074 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
9077 if (!ecpri_m->hdr.common.u32)
9079 samples = priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0].ids;
9080 /* Need to take the whole DW as the mask to fill the entry. */
9081 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9082 prog_sample_field_value_0);
9083 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9084 prog_sample_field_value_0);
9085 /* Already big endian (network order) in the header. */
9086 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
9087 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
9088 /* Sample#0, used for matching type, offset 0. */
9089 MLX5_SET(fte_match_set_misc4, misc4_m,
9090 prog_sample_field_id_0, samples[0]);
9091 /* It makes no sense to set the sample ID in the mask field. */
9092 MLX5_SET(fte_match_set_misc4, misc4_v,
9093 prog_sample_field_id_0, samples[0]);
9095 * Checking if message body part needs to be matched.
9096 * Some wildcard rules only matching type field should be supported.
9098 if (ecpri_m->hdr.dummy[0]) {
9099 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
9100 switch (common.type) {
9101 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
9102 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
9103 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
9104 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9105 prog_sample_field_value_1);
9106 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9107 prog_sample_field_value_1);
9108 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
9109 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
9110 ecpri_m->hdr.dummy[0];
9111 /* Sample#1, to match message body, offset 4. */
9112 MLX5_SET(fte_match_set_misc4, misc4_m,
9113 prog_sample_field_id_1, samples[1]);
9114 MLX5_SET(fte_match_set_misc4, misc4_v,
9115 prog_sample_field_id_1, samples[1]);
9118 /* Others, do not match any sample ID. */
9124 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
9126 #define HEADER_IS_ZERO(match_criteria, headers) \
9127 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
9128 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
9131 * Calculate flow matcher enable bitmap.
9133 * @param match_criteria
9134 * Pointer to flow matcher criteria.
9137 * Bitmap of enabled fields.
9140 flow_dv_matcher_enable(uint32_t *match_criteria)
9142 uint8_t match_criteria_enable;
9144 match_criteria_enable =
9145 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
9146 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
9147 match_criteria_enable |=
9148 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
9149 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
9150 match_criteria_enable |=
9151 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
9152 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
9153 match_criteria_enable |=
9154 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
9155 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
9156 match_criteria_enable |=
9157 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
9158 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
9159 match_criteria_enable |=
9160 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
9161 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
9162 return match_criteria_enable;
9165 struct mlx5_hlist_entry *
9166 flow_dv_tbl_create_cb(struct mlx5_hlist *list, uint64_t key64, void *cb_ctx)
9168 struct mlx5_dev_ctx_shared *sh = list->ctx;
9169 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9170 struct rte_eth_dev *dev = ctx->dev;
9171 struct mlx5_flow_tbl_data_entry *tbl_data;
9172 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data;
9173 struct rte_flow_error *error = ctx->error;
9174 union mlx5_flow_tbl_key key = { .v64 = key64 };
9175 struct mlx5_flow_tbl_resource *tbl;
9180 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
9182 rte_flow_error_set(error, ENOMEM,
9183 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9185 "cannot allocate flow table data entry");
9188 tbl_data->idx = idx;
9189 tbl_data->tunnel = tt_prm->tunnel;
9190 tbl_data->group_id = tt_prm->group_id;
9191 tbl_data->external = !!tt_prm->external;
9192 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
9193 tbl_data->is_egress = !!key.direction;
9194 tbl_data->is_transfer = !!key.domain;
9195 tbl_data->dummy = !!key.dummy;
9196 tbl_data->table_id = key.table_id;
9197 tbl = &tbl_data->tbl;
9199 return &tbl_data->entry;
9201 domain = sh->fdb_domain;
9202 else if (key.direction)
9203 domain = sh->tx_domain;
9205 domain = sh->rx_domain;
9206 ret = mlx5_flow_os_create_flow_tbl(domain, key.table_id, &tbl->obj);
9208 rte_flow_error_set(error, ENOMEM,
9209 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9210 NULL, "cannot create flow table object");
9211 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
9215 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
9216 (tbl->obj, &tbl_data->jump.action);
9218 rte_flow_error_set(error, ENOMEM,
9219 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9221 "cannot create flow jump action");
9222 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
9223 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
9227 MKSTR(matcher_name, "%s_%s_%u_matcher_cache",
9228 key.domain ? "FDB" : "NIC", key.direction ? "egress" : "ingress",
9230 mlx5_cache_list_init(&tbl_data->matchers, matcher_name, 0, sh,
9231 flow_dv_matcher_create_cb,
9232 flow_dv_matcher_match_cb,
9233 flow_dv_matcher_remove_cb);
9234 return &tbl_data->entry;
9238 flow_dv_tbl_match_cb(struct mlx5_hlist *list __rte_unused,
9239 struct mlx5_hlist_entry *entry, uint64_t key64,
9240 void *cb_ctx __rte_unused)
9242 struct mlx5_flow_tbl_data_entry *tbl_data =
9243 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
9244 union mlx5_flow_tbl_key key = { .v64 = key64 };
9246 return tbl_data->table_id != key.table_id ||
9247 tbl_data->dummy != key.dummy ||
9248 tbl_data->is_transfer != key.domain ||
9249 tbl_data->is_egress != key.direction;
9255 * @param[in, out] dev
9256 * Pointer to rte_eth_dev structure.
9257 * @param[in] table_id
9260 * Direction of the table.
9261 * @param[in] transfer
9262 * E-Switch or NIC flow.
9264 * Dummy entry for dv API.
9266 * pointer to error structure.
9269 * Returns tables resource based on the index, NULL in case of failed.
9271 struct mlx5_flow_tbl_resource *
9272 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
9273 uint32_t table_id, uint8_t egress,
9276 const struct mlx5_flow_tunnel *tunnel,
9277 uint32_t group_id, uint8_t dummy,
9278 struct rte_flow_error *error)
9280 struct mlx5_priv *priv = dev->data->dev_private;
9281 union mlx5_flow_tbl_key table_key = {
9283 .table_id = table_id,
9285 .domain = !!transfer,
9286 .direction = !!egress,
9289 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
9291 .group_id = group_id,
9292 .external = external,
9294 struct mlx5_flow_cb_ctx ctx = {
9299 struct mlx5_hlist_entry *entry;
9300 struct mlx5_flow_tbl_data_entry *tbl_data;
9302 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
9304 rte_flow_error_set(error, ENOMEM,
9305 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9306 "cannot get table");
9309 DRV_LOG(DEBUG, "Table_id %u tunnel %u group %u registered.",
9310 table_id, tunnel ? tunnel->tunnel_id : 0, group_id);
9311 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
9312 return &tbl_data->tbl;
9316 flow_dv_tbl_remove_cb(struct mlx5_hlist *list,
9317 struct mlx5_hlist_entry *entry)
9319 struct mlx5_dev_ctx_shared *sh = list->ctx;
9320 struct mlx5_flow_tbl_data_entry *tbl_data =
9321 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
9323 MLX5_ASSERT(entry && sh);
9324 if (tbl_data->jump.action)
9325 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
9326 if (tbl_data->tbl.obj)
9327 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
9328 if (tbl_data->tunnel_offload && tbl_data->external) {
9329 struct mlx5_hlist_entry *he;
9330 struct mlx5_hlist *tunnel_grp_hash;
9331 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
9332 union tunnel_tbl_key tunnel_key = {
9333 .tunnel_id = tbl_data->tunnel ?
9334 tbl_data->tunnel->tunnel_id : 0,
9335 .group = tbl_data->group_id
9337 uint32_t table_id = tbl_data->table_id;
9339 tunnel_grp_hash = tbl_data->tunnel ?
9340 tbl_data->tunnel->groups :
9342 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, NULL);
9344 mlx5_hlist_unregister(tunnel_grp_hash, he);
9346 "Table_id %u tunnel %u group %u released.",
9349 tbl_data->tunnel->tunnel_id : 0,
9350 tbl_data->group_id);
9352 mlx5_cache_list_destroy(&tbl_data->matchers);
9353 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
9357 * Release a flow table.
9360 * Pointer to device shared structure.
9362 * Table resource to be released.
9365 * Returns 0 if table was released, else return 1;
9368 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
9369 struct mlx5_flow_tbl_resource *tbl)
9371 struct mlx5_flow_tbl_data_entry *tbl_data =
9372 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
9376 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
9380 flow_dv_matcher_match_cb(struct mlx5_cache_list *list __rte_unused,
9381 struct mlx5_cache_entry *entry, void *cb_ctx)
9383 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9384 struct mlx5_flow_dv_matcher *ref = ctx->data;
9385 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
9388 return cur->crc != ref->crc ||
9389 cur->priority != ref->priority ||
9390 memcmp((const void *)cur->mask.buf,
9391 (const void *)ref->mask.buf, ref->mask.size);
9394 struct mlx5_cache_entry *
9395 flow_dv_matcher_create_cb(struct mlx5_cache_list *list,
9396 struct mlx5_cache_entry *entry __rte_unused,
9399 struct mlx5_dev_ctx_shared *sh = list->ctx;
9400 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9401 struct mlx5_flow_dv_matcher *ref = ctx->data;
9402 struct mlx5_flow_dv_matcher *cache;
9403 struct mlx5dv_flow_matcher_attr dv_attr = {
9404 .type = IBV_FLOW_ATTR_NORMAL,
9405 .match_mask = (void *)&ref->mask,
9407 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
9411 cache = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*cache), 0, SOCKET_ID_ANY);
9413 rte_flow_error_set(ctx->error, ENOMEM,
9414 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9415 "cannot create matcher");
9419 dv_attr.match_criteria_enable =
9420 flow_dv_matcher_enable(cache->mask.buf);
9421 dv_attr.priority = ref->priority;
9423 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
9424 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->tbl.obj,
9425 &cache->matcher_object);
9428 rte_flow_error_set(ctx->error, ENOMEM,
9429 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9430 "cannot create matcher");
9433 return &cache->entry;
9437 * Register the flow matcher.
9439 * @param[in, out] dev
9440 * Pointer to rte_eth_dev structure.
9441 * @param[in, out] matcher
9442 * Pointer to flow matcher.
9443 * @param[in, out] key
9444 * Pointer to flow table key.
9445 * @parm[in, out] dev_flow
9446 * Pointer to the dev_flow.
9448 * pointer to error structure.
9451 * 0 on success otherwise -errno and errno is set.
9454 flow_dv_matcher_register(struct rte_eth_dev *dev,
9455 struct mlx5_flow_dv_matcher *ref,
9456 union mlx5_flow_tbl_key *key,
9457 struct mlx5_flow *dev_flow,
9458 const struct mlx5_flow_tunnel *tunnel,
9460 struct rte_flow_error *error)
9462 struct mlx5_cache_entry *entry;
9463 struct mlx5_flow_dv_matcher *cache;
9464 struct mlx5_flow_tbl_resource *tbl;
9465 struct mlx5_flow_tbl_data_entry *tbl_data;
9466 struct mlx5_flow_cb_ctx ctx = {
9472 * tunnel offload API requires this registration for cases when
9473 * tunnel match rule was inserted before tunnel set rule.
9475 tbl = flow_dv_tbl_resource_get(dev, key->table_id,
9476 key->direction, key->domain,
9477 dev_flow->external, tunnel,
9478 group_id, 0, error);
9480 return -rte_errno; /* No need to refill the error info */
9481 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
9483 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
9485 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
9486 return rte_flow_error_set(error, ENOMEM,
9487 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9488 "cannot allocate ref memory");
9490 cache = container_of(entry, typeof(*cache), entry);
9491 dev_flow->handle->dvh.matcher = cache;
9495 struct mlx5_hlist_entry *
9496 flow_dv_tag_create_cb(struct mlx5_hlist *list, uint64_t key, void *ctx)
9498 struct mlx5_dev_ctx_shared *sh = list->ctx;
9499 struct rte_flow_error *error = ctx;
9500 struct mlx5_flow_dv_tag_resource *entry;
9504 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
9506 rte_flow_error_set(error, ENOMEM,
9507 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9508 "cannot allocate resource memory");
9512 entry->tag_id = key;
9513 ret = mlx5_flow_os_create_flow_action_tag(key,
9516 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
9517 rte_flow_error_set(error, ENOMEM,
9518 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9519 NULL, "cannot create action");
9522 return &entry->entry;
9526 flow_dv_tag_match_cb(struct mlx5_hlist *list __rte_unused,
9527 struct mlx5_hlist_entry *entry, uint64_t key,
9528 void *cb_ctx __rte_unused)
9530 struct mlx5_flow_dv_tag_resource *tag =
9531 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
9533 return key != tag->tag_id;
9537 * Find existing tag resource or create and register a new one.
9539 * @param dev[in, out]
9540 * Pointer to rte_eth_dev structure.
9541 * @param[in, out] tag_be24
9542 * Tag value in big endian then R-shift 8.
9543 * @parm[in, out] dev_flow
9544 * Pointer to the dev_flow.
9546 * pointer to error structure.
9549 * 0 on success otherwise -errno and errno is set.
9552 flow_dv_tag_resource_register
9553 (struct rte_eth_dev *dev,
9555 struct mlx5_flow *dev_flow,
9556 struct rte_flow_error *error)
9558 struct mlx5_priv *priv = dev->data->dev_private;
9559 struct mlx5_flow_dv_tag_resource *cache_resource;
9560 struct mlx5_hlist_entry *entry;
9562 entry = mlx5_hlist_register(priv->sh->tag_table, tag_be24, error);
9564 cache_resource = container_of
9565 (entry, struct mlx5_flow_dv_tag_resource, entry);
9566 dev_flow->handle->dvh.rix_tag = cache_resource->idx;
9567 dev_flow->dv.tag_resource = cache_resource;
9574 flow_dv_tag_remove_cb(struct mlx5_hlist *list,
9575 struct mlx5_hlist_entry *entry)
9577 struct mlx5_dev_ctx_shared *sh = list->ctx;
9578 struct mlx5_flow_dv_tag_resource *tag =
9579 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
9581 MLX5_ASSERT(tag && sh && tag->action);
9582 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
9583 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
9584 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
9591 * Pointer to Ethernet device.
9596 * 1 while a reference on it exists, 0 when freed.
9599 flow_dv_tag_release(struct rte_eth_dev *dev,
9602 struct mlx5_priv *priv = dev->data->dev_private;
9603 struct mlx5_flow_dv_tag_resource *tag;
9605 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
9608 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
9609 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
9610 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
9614 * Translate port ID action to vport.
9617 * Pointer to rte_eth_dev structure.
9619 * Pointer to the port ID action.
9620 * @param[out] dst_port_id
9621 * The target port ID.
9623 * Pointer to the error structure.
9626 * 0 on success, a negative errno value otherwise and rte_errno is set.
9629 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
9630 const struct rte_flow_action *action,
9631 uint32_t *dst_port_id,
9632 struct rte_flow_error *error)
9635 struct mlx5_priv *priv;
9636 const struct rte_flow_action_port_id *conf =
9637 (const struct rte_flow_action_port_id *)action->conf;
9639 port = conf->original ? dev->data->port_id : conf->id;
9640 priv = mlx5_port_to_eswitch_info(port, false);
9642 return rte_flow_error_set(error, -rte_errno,
9643 RTE_FLOW_ERROR_TYPE_ACTION,
9645 "No eswitch info was found for port");
9646 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
9648 * This parameter is transferred to
9649 * mlx5dv_dr_action_create_dest_ib_port().
9651 *dst_port_id = priv->dev_port;
9654 * Legacy mode, no LAG configurations is supported.
9655 * This parameter is transferred to
9656 * mlx5dv_dr_action_create_dest_vport().
9658 *dst_port_id = priv->vport_id;
9664 * Create a counter with aging configuration.
9667 * Pointer to rte_eth_dev structure.
9669 * Pointer to the counter action configuration.
9671 * Pointer to the aging action configuration.
9674 * Index to flow counter on success, 0 otherwise.
9677 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
9678 struct mlx5_flow *dev_flow,
9679 const struct rte_flow_action_count *count,
9680 const struct rte_flow_action_age *age)
9683 struct mlx5_age_param *age_param;
9685 if (count && count->shared)
9686 counter = flow_dv_counter_get_shared(dev, count->id);
9688 counter = flow_dv_counter_alloc(dev, !!age);
9689 if (!counter || age == NULL)
9691 age_param = flow_dv_counter_idx_get_age(dev, counter);
9692 age_param->context = age->context ? age->context :
9693 (void *)(uintptr_t)(dev_flow->flow_idx);
9694 age_param->timeout = age->timeout;
9695 age_param->port_id = dev->data->port_id;
9696 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
9697 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
9702 * Add Tx queue matcher
9705 * Pointer to the dev struct.
9706 * @param[in, out] matcher
9708 * @param[in, out] key
9709 * Flow matcher value.
9711 * Flow pattern to translate.
9713 * Item is inner pattern.
9716 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
9717 void *matcher, void *key,
9718 const struct rte_flow_item *item)
9720 const struct mlx5_rte_flow_item_tx_queue *queue_m;
9721 const struct mlx5_rte_flow_item_tx_queue *queue_v;
9723 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9725 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9726 struct mlx5_txq_ctrl *txq;
9730 queue_m = (const void *)item->mask;
9733 queue_v = (const void *)item->spec;
9736 txq = mlx5_txq_get(dev, queue_v->queue);
9739 queue = txq->obj->sq->id;
9740 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
9741 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
9742 queue & queue_m->queue);
9743 mlx5_txq_release(dev, queue_v->queue);
9747 * Set the hash fields according to the @p flow information.
9749 * @param[in] dev_flow
9750 * Pointer to the mlx5_flow.
9751 * @param[in] rss_desc
9752 * Pointer to the mlx5_flow_rss_desc.
9755 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
9756 struct mlx5_flow_rss_desc *rss_desc)
9758 uint64_t items = dev_flow->handle->layers;
9760 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
9762 dev_flow->hash_fields = 0;
9763 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
9764 if (rss_desc->level >= 2) {
9765 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
9769 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
9770 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
9771 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
9772 if (rss_types & ETH_RSS_L3_SRC_ONLY)
9773 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
9774 else if (rss_types & ETH_RSS_L3_DST_ONLY)
9775 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
9777 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
9779 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
9780 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
9781 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
9782 if (rss_types & ETH_RSS_L3_SRC_ONLY)
9783 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
9784 else if (rss_types & ETH_RSS_L3_DST_ONLY)
9785 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
9787 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
9790 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
9791 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
9792 if (rss_types & ETH_RSS_UDP) {
9793 if (rss_types & ETH_RSS_L4_SRC_ONLY)
9794 dev_flow->hash_fields |=
9795 IBV_RX_HASH_SRC_PORT_UDP;
9796 else if (rss_types & ETH_RSS_L4_DST_ONLY)
9797 dev_flow->hash_fields |=
9798 IBV_RX_HASH_DST_PORT_UDP;
9800 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
9802 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
9803 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
9804 if (rss_types & ETH_RSS_TCP) {
9805 if (rss_types & ETH_RSS_L4_SRC_ONLY)
9806 dev_flow->hash_fields |=
9807 IBV_RX_HASH_SRC_PORT_TCP;
9808 else if (rss_types & ETH_RSS_L4_DST_ONLY)
9809 dev_flow->hash_fields |=
9810 IBV_RX_HASH_DST_PORT_TCP;
9812 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
9818 * Prepare an Rx Hash queue.
9821 * Pointer to Ethernet device.
9822 * @param[in] dev_flow
9823 * Pointer to the mlx5_flow.
9824 * @param[in] rss_desc
9825 * Pointer to the mlx5_flow_rss_desc.
9826 * @param[out] hrxq_idx
9827 * Hash Rx queue index.
9830 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
9832 static struct mlx5_hrxq *
9833 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
9834 struct mlx5_flow *dev_flow,
9835 struct mlx5_flow_rss_desc *rss_desc,
9838 struct mlx5_priv *priv = dev->data->dev_private;
9839 struct mlx5_flow_handle *dh = dev_flow->handle;
9840 struct mlx5_hrxq *hrxq;
9842 MLX5_ASSERT(rss_desc->queue_num);
9843 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
9844 rss_desc->hash_fields = dev_flow->hash_fields;
9845 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
9846 rss_desc->shared_rss = 0;
9847 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc);
9850 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
9856 * Release sample sub action resource.
9858 * @param[in, out] dev
9859 * Pointer to rte_eth_dev structure.
9860 * @param[in] act_res
9861 * Pointer to sample sub action resource.
9864 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
9865 struct mlx5_flow_sub_actions_idx *act_res)
9867 if (act_res->rix_hrxq) {
9868 mlx5_hrxq_release(dev, act_res->rix_hrxq);
9869 act_res->rix_hrxq = 0;
9871 if (act_res->rix_encap_decap) {
9872 flow_dv_encap_decap_resource_release(dev,
9873 act_res->rix_encap_decap);
9874 act_res->rix_encap_decap = 0;
9876 if (act_res->rix_port_id_action) {
9877 flow_dv_port_id_action_resource_release(dev,
9878 act_res->rix_port_id_action);
9879 act_res->rix_port_id_action = 0;
9881 if (act_res->rix_tag) {
9882 flow_dv_tag_release(dev, act_res->rix_tag);
9883 act_res->rix_tag = 0;
9885 if (act_res->rix_jump) {
9886 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
9887 act_res->rix_jump = 0;
9892 flow_dv_sample_match_cb(struct mlx5_cache_list *list __rte_unused,
9893 struct mlx5_cache_entry *entry, void *cb_ctx)
9895 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9896 struct rte_eth_dev *dev = ctx->dev;
9897 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
9898 struct mlx5_flow_dv_sample_resource *cache_resource =
9899 container_of(entry, typeof(*cache_resource), entry);
9901 if (resource->ratio == cache_resource->ratio &&
9902 resource->ft_type == cache_resource->ft_type &&
9903 resource->ft_id == cache_resource->ft_id &&
9904 resource->set_action == cache_resource->set_action &&
9905 !memcmp((void *)&resource->sample_act,
9906 (void *)&cache_resource->sample_act,
9907 sizeof(struct mlx5_flow_sub_actions_list))) {
9909 * Existing sample action should release the prepared
9910 * sub-actions reference counter.
9912 flow_dv_sample_sub_actions_release(dev,
9913 &resource->sample_idx);
9919 struct mlx5_cache_entry *
9920 flow_dv_sample_create_cb(struct mlx5_cache_list *list __rte_unused,
9921 struct mlx5_cache_entry *entry __rte_unused,
9924 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9925 struct rte_eth_dev *dev = ctx->dev;
9926 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
9927 void **sample_dv_actions = resource->sub_actions;
9928 struct mlx5_flow_dv_sample_resource *cache_resource;
9929 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
9930 struct mlx5_priv *priv = dev->data->dev_private;
9931 struct mlx5_dev_ctx_shared *sh = priv->sh;
9932 struct mlx5_flow_tbl_resource *tbl;
9934 const uint32_t next_ft_step = 1;
9935 uint32_t next_ft_id = resource->ft_id + next_ft_step;
9936 uint8_t is_egress = 0;
9937 uint8_t is_transfer = 0;
9938 struct rte_flow_error *error = ctx->error;
9940 /* Register new sample resource. */
9941 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
9942 if (!cache_resource) {
9943 rte_flow_error_set(error, ENOMEM,
9944 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9946 "cannot allocate resource memory");
9949 *cache_resource = *resource;
9950 /* Create normal path table level */
9951 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
9953 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
9955 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
9956 is_egress, is_transfer,
9957 true, NULL, 0, 0, error);
9959 rte_flow_error_set(error, ENOMEM,
9960 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9962 "fail to create normal path table "
9966 cache_resource->normal_path_tbl = tbl;
9967 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
9968 if (!sh->default_miss_action) {
9969 rte_flow_error_set(error, ENOMEM,
9970 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9972 "default miss action was not "
9976 sample_dv_actions[resource->sample_act.actions_num++] =
9977 sh->default_miss_action;
9979 /* Create a DR sample action */
9980 sampler_attr.sample_ratio = cache_resource->ratio;
9981 sampler_attr.default_next_table = tbl->obj;
9982 sampler_attr.num_sample_actions = resource->sample_act.actions_num;
9983 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
9984 &sample_dv_actions[0];
9985 sampler_attr.action = cache_resource->set_action;
9986 if (mlx5_os_flow_dr_create_flow_action_sampler
9987 (&sampler_attr, &cache_resource->verbs_action)) {
9988 rte_flow_error_set(error, ENOMEM,
9989 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9990 NULL, "cannot create sample action");
9993 cache_resource->idx = idx;
9994 cache_resource->dev = dev;
9995 return &cache_resource->entry;
9997 if (cache_resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
9998 flow_dv_sample_sub_actions_release(dev,
9999 &cache_resource->sample_idx);
10000 if (cache_resource->normal_path_tbl)
10001 flow_dv_tbl_resource_release(MLX5_SH(dev),
10002 cache_resource->normal_path_tbl);
10003 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
10009 * Find existing sample resource or create and register a new one.
10011 * @param[in, out] dev
10012 * Pointer to rte_eth_dev structure.
10013 * @param[in] resource
10014 * Pointer to sample resource.
10015 * @parm[in, out] dev_flow
10016 * Pointer to the dev_flow.
10017 * @param[out] error
10018 * pointer to error structure.
10021 * 0 on success otherwise -errno and errno is set.
10024 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
10025 struct mlx5_flow_dv_sample_resource *resource,
10026 struct mlx5_flow *dev_flow,
10027 struct rte_flow_error *error)
10029 struct mlx5_flow_dv_sample_resource *cache_resource;
10030 struct mlx5_cache_entry *entry;
10031 struct mlx5_priv *priv = dev->data->dev_private;
10032 struct mlx5_flow_cb_ctx ctx = {
10038 entry = mlx5_cache_register(&priv->sh->sample_action_list, &ctx);
10041 cache_resource = container_of(entry, typeof(*cache_resource), entry);
10042 dev_flow->handle->dvh.rix_sample = cache_resource->idx;
10043 dev_flow->dv.sample_res = cache_resource;
10048 flow_dv_dest_array_match_cb(struct mlx5_cache_list *list __rte_unused,
10049 struct mlx5_cache_entry *entry, void *cb_ctx)
10051 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10052 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
10053 struct rte_eth_dev *dev = ctx->dev;
10054 struct mlx5_flow_dv_dest_array_resource *cache_resource =
10055 container_of(entry, typeof(*cache_resource), entry);
10058 if (resource->num_of_dest == cache_resource->num_of_dest &&
10059 resource->ft_type == cache_resource->ft_type &&
10060 !memcmp((void *)cache_resource->sample_act,
10061 (void *)resource->sample_act,
10062 (resource->num_of_dest *
10063 sizeof(struct mlx5_flow_sub_actions_list)))) {
10065 * Existing sample action should release the prepared
10066 * sub-actions reference counter.
10068 for (idx = 0; idx < resource->num_of_dest; idx++)
10069 flow_dv_sample_sub_actions_release(dev,
10070 &resource->sample_idx[idx]);
10076 struct mlx5_cache_entry *
10077 flow_dv_dest_array_create_cb(struct mlx5_cache_list *list __rte_unused,
10078 struct mlx5_cache_entry *entry __rte_unused,
10081 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10082 struct rte_eth_dev *dev = ctx->dev;
10083 struct mlx5_flow_dv_dest_array_resource *cache_resource;
10084 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
10085 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
10086 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
10087 struct mlx5_priv *priv = dev->data->dev_private;
10088 struct mlx5_dev_ctx_shared *sh = priv->sh;
10089 struct mlx5_flow_sub_actions_list *sample_act;
10090 struct mlx5dv_dr_domain *domain;
10091 uint32_t idx = 0, res_idx = 0;
10092 struct rte_flow_error *error = ctx->error;
10093 uint64_t action_flags;
10096 /* Register new destination array resource. */
10097 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
10099 if (!cache_resource) {
10100 rte_flow_error_set(error, ENOMEM,
10101 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10103 "cannot allocate resource memory");
10106 *cache_resource = *resource;
10107 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
10108 domain = sh->fdb_domain;
10109 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
10110 domain = sh->rx_domain;
10112 domain = sh->tx_domain;
10113 for (idx = 0; idx < resource->num_of_dest; idx++) {
10114 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
10115 mlx5_malloc(MLX5_MEM_ZERO,
10116 sizeof(struct mlx5dv_dr_action_dest_attr),
10118 if (!dest_attr[idx]) {
10119 rte_flow_error_set(error, ENOMEM,
10120 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10122 "cannot allocate resource memory");
10125 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
10126 sample_act = &resource->sample_act[idx];
10127 action_flags = sample_act->action_flags;
10128 switch (action_flags) {
10129 case MLX5_FLOW_ACTION_QUEUE:
10130 dest_attr[idx]->dest = sample_act->dr_queue_action;
10132 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
10133 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
10134 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
10135 dest_attr[idx]->dest_reformat->reformat =
10136 sample_act->dr_encap_action;
10137 dest_attr[idx]->dest_reformat->dest =
10138 sample_act->dr_port_id_action;
10140 case MLX5_FLOW_ACTION_PORT_ID:
10141 dest_attr[idx]->dest = sample_act->dr_port_id_action;
10143 case MLX5_FLOW_ACTION_JUMP:
10144 dest_attr[idx]->dest = sample_act->dr_jump_action;
10147 rte_flow_error_set(error, EINVAL,
10148 RTE_FLOW_ERROR_TYPE_ACTION,
10150 "unsupported actions type");
10154 /* create a dest array actioin */
10155 ret = mlx5_os_flow_dr_create_flow_action_dest_array
10157 cache_resource->num_of_dest,
10159 &cache_resource->action);
10161 rte_flow_error_set(error, ENOMEM,
10162 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10164 "cannot create destination array action");
10167 cache_resource->idx = res_idx;
10168 cache_resource->dev = dev;
10169 for (idx = 0; idx < resource->num_of_dest; idx++)
10170 mlx5_free(dest_attr[idx]);
10171 return &cache_resource->entry;
10173 for (idx = 0; idx < resource->num_of_dest; idx++) {
10174 flow_dv_sample_sub_actions_release(dev,
10175 &cache_resource->sample_idx[idx]);
10176 if (dest_attr[idx])
10177 mlx5_free(dest_attr[idx]);
10180 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
10185 * Find existing destination array resource or create and register a new one.
10187 * @param[in, out] dev
10188 * Pointer to rte_eth_dev structure.
10189 * @param[in] resource
10190 * Pointer to destination array resource.
10191 * @parm[in, out] dev_flow
10192 * Pointer to the dev_flow.
10193 * @param[out] error
10194 * pointer to error structure.
10197 * 0 on success otherwise -errno and errno is set.
10200 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
10201 struct mlx5_flow_dv_dest_array_resource *resource,
10202 struct mlx5_flow *dev_flow,
10203 struct rte_flow_error *error)
10205 struct mlx5_flow_dv_dest_array_resource *cache_resource;
10206 struct mlx5_priv *priv = dev->data->dev_private;
10207 struct mlx5_cache_entry *entry;
10208 struct mlx5_flow_cb_ctx ctx = {
10214 entry = mlx5_cache_register(&priv->sh->dest_array_list, &ctx);
10217 cache_resource = container_of(entry, typeof(*cache_resource), entry);
10218 dev_flow->handle->dvh.rix_dest_array = cache_resource->idx;
10219 dev_flow->dv.dest_array_res = cache_resource;
10224 * Convert Sample action to DV specification.
10227 * Pointer to rte_eth_dev structure.
10228 * @param[in] action
10229 * Pointer to sample action structure.
10230 * @param[in, out] dev_flow
10231 * Pointer to the mlx5_flow.
10233 * Pointer to the flow attributes.
10234 * @param[in, out] num_of_dest
10235 * Pointer to the num of destination.
10236 * @param[in, out] sample_actions
10237 * Pointer to sample actions list.
10238 * @param[in, out] res
10239 * Pointer to sample resource.
10240 * @param[out] error
10241 * Pointer to the error structure.
10244 * 0 on success, a negative errno value otherwise and rte_errno is set.
10247 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
10248 const struct rte_flow_action_sample *action,
10249 struct mlx5_flow *dev_flow,
10250 const struct rte_flow_attr *attr,
10251 uint32_t *num_of_dest,
10252 void **sample_actions,
10253 struct mlx5_flow_dv_sample_resource *res,
10254 struct rte_flow_error *error)
10256 struct mlx5_priv *priv = dev->data->dev_private;
10257 const struct rte_flow_action *sub_actions;
10258 struct mlx5_flow_sub_actions_list *sample_act;
10259 struct mlx5_flow_sub_actions_idx *sample_idx;
10260 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10261 struct rte_flow *flow = dev_flow->flow;
10262 struct mlx5_flow_rss_desc *rss_desc;
10263 uint64_t action_flags = 0;
10266 rss_desc = &wks->rss_desc;
10267 sample_act = &res->sample_act;
10268 sample_idx = &res->sample_idx;
10269 res->ratio = action->ratio;
10270 sub_actions = action->actions;
10271 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
10272 int type = sub_actions->type;
10273 uint32_t pre_rix = 0;
10276 case RTE_FLOW_ACTION_TYPE_QUEUE:
10278 const struct rte_flow_action_queue *queue;
10279 struct mlx5_hrxq *hrxq;
10282 queue = sub_actions->conf;
10283 rss_desc->queue_num = 1;
10284 rss_desc->queue[0] = queue->index;
10285 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
10286 rss_desc, &hrxq_idx);
10288 return rte_flow_error_set
10290 RTE_FLOW_ERROR_TYPE_ACTION,
10292 "cannot create fate queue");
10293 sample_act->dr_queue_action = hrxq->action;
10294 sample_idx->rix_hrxq = hrxq_idx;
10295 sample_actions[sample_act->actions_num++] =
10298 action_flags |= MLX5_FLOW_ACTION_QUEUE;
10299 if (action_flags & MLX5_FLOW_ACTION_MARK)
10300 dev_flow->handle->rix_hrxq = hrxq_idx;
10301 dev_flow->handle->fate_action =
10302 MLX5_FLOW_FATE_QUEUE;
10305 case RTE_FLOW_ACTION_TYPE_RSS:
10307 struct mlx5_hrxq *hrxq;
10309 const struct rte_flow_action_rss *rss;
10310 const uint8_t *rss_key;
10312 rss = sub_actions->conf;
10313 memcpy(rss_desc->queue, rss->queue,
10314 rss->queue_num * sizeof(uint16_t));
10315 rss_desc->queue_num = rss->queue_num;
10316 /* NULL RSS key indicates default RSS key. */
10317 rss_key = !rss->key ? rss_hash_default_key : rss->key;
10318 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
10320 * rss->level and rss.types should be set in advance
10321 * when expanding items for RSS.
10323 flow_dv_hashfields_set(dev_flow, rss_desc);
10324 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
10325 rss_desc, &hrxq_idx);
10327 return rte_flow_error_set
10329 RTE_FLOW_ERROR_TYPE_ACTION,
10331 "cannot create fate queue");
10332 sample_act->dr_queue_action = hrxq->action;
10333 sample_idx->rix_hrxq = hrxq_idx;
10334 sample_actions[sample_act->actions_num++] =
10337 action_flags |= MLX5_FLOW_ACTION_RSS;
10338 if (action_flags & MLX5_FLOW_ACTION_MARK)
10339 dev_flow->handle->rix_hrxq = hrxq_idx;
10340 dev_flow->handle->fate_action =
10341 MLX5_FLOW_FATE_QUEUE;
10344 case RTE_FLOW_ACTION_TYPE_MARK:
10346 uint32_t tag_be = mlx5_flow_mark_set
10347 (((const struct rte_flow_action_mark *)
10348 (sub_actions->conf))->id);
10350 dev_flow->handle->mark = 1;
10351 pre_rix = dev_flow->handle->dvh.rix_tag;
10352 /* Save the mark resource before sample */
10353 pre_r = dev_flow->dv.tag_resource;
10354 if (flow_dv_tag_resource_register(dev, tag_be,
10357 MLX5_ASSERT(dev_flow->dv.tag_resource);
10358 sample_act->dr_tag_action =
10359 dev_flow->dv.tag_resource->action;
10360 sample_idx->rix_tag =
10361 dev_flow->handle->dvh.rix_tag;
10362 sample_actions[sample_act->actions_num++] =
10363 sample_act->dr_tag_action;
10364 /* Recover the mark resource after sample */
10365 dev_flow->dv.tag_resource = pre_r;
10366 dev_flow->handle->dvh.rix_tag = pre_rix;
10367 action_flags |= MLX5_FLOW_ACTION_MARK;
10370 case RTE_FLOW_ACTION_TYPE_COUNT:
10372 if (!flow->counter) {
10374 flow_dv_translate_create_counter(dev,
10375 dev_flow, sub_actions->conf,
10377 if (!flow->counter)
10378 return rte_flow_error_set
10380 RTE_FLOW_ERROR_TYPE_ACTION,
10382 "cannot create counter"
10385 sample_act->dr_cnt_action =
10386 (flow_dv_counter_get_by_idx(dev,
10387 flow->counter, NULL))->action;
10388 sample_actions[sample_act->actions_num++] =
10389 sample_act->dr_cnt_action;
10390 action_flags |= MLX5_FLOW_ACTION_COUNT;
10393 case RTE_FLOW_ACTION_TYPE_PORT_ID:
10395 struct mlx5_flow_dv_port_id_action_resource
10397 uint32_t port_id = 0;
10399 memset(&port_id_resource, 0, sizeof(port_id_resource));
10400 /* Save the port id resource before sample */
10401 pre_rix = dev_flow->handle->rix_port_id_action;
10402 pre_r = dev_flow->dv.port_id_action;
10403 if (flow_dv_translate_action_port_id(dev, sub_actions,
10406 port_id_resource.port_id = port_id;
10407 if (flow_dv_port_id_action_resource_register
10408 (dev, &port_id_resource, dev_flow, error))
10410 sample_act->dr_port_id_action =
10411 dev_flow->dv.port_id_action->action;
10412 sample_idx->rix_port_id_action =
10413 dev_flow->handle->rix_port_id_action;
10414 sample_actions[sample_act->actions_num++] =
10415 sample_act->dr_port_id_action;
10416 /* Recover the port id resource after sample */
10417 dev_flow->dv.port_id_action = pre_r;
10418 dev_flow->handle->rix_port_id_action = pre_rix;
10420 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
10423 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
10424 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
10425 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
10426 /* Save the encap resource before sample */
10427 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
10428 pre_r = dev_flow->dv.encap_decap;
10429 if (flow_dv_create_action_l2_encap(dev, sub_actions,
10434 sample_act->dr_encap_action =
10435 dev_flow->dv.encap_decap->action;
10436 sample_idx->rix_encap_decap =
10437 dev_flow->handle->dvh.rix_encap_decap;
10438 sample_actions[sample_act->actions_num++] =
10439 sample_act->dr_encap_action;
10440 /* Recover the encap resource after sample */
10441 dev_flow->dv.encap_decap = pre_r;
10442 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
10443 action_flags |= MLX5_FLOW_ACTION_ENCAP;
10446 return rte_flow_error_set(error, EINVAL,
10447 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10449 "Not support for sampler action");
10452 sample_act->action_flags = action_flags;
10453 res->ft_id = dev_flow->dv.group;
10454 if (attr->transfer) {
10456 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
10457 uint64_t set_action;
10458 } action_ctx = { .set_action = 0 };
10460 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
10461 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
10462 MLX5_MODIFICATION_TYPE_SET);
10463 MLX5_SET(set_action_in, action_ctx.action_in, field,
10464 MLX5_MODI_META_REG_C_0);
10465 MLX5_SET(set_action_in, action_ctx.action_in, data,
10466 priv->vport_meta_tag);
10467 res->set_action = action_ctx.set_action;
10468 } else if (attr->ingress) {
10469 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
10471 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
10477 * Convert Sample action to DV specification.
10480 * Pointer to rte_eth_dev structure.
10481 * @param[in, out] dev_flow
10482 * Pointer to the mlx5_flow.
10483 * @param[in] num_of_dest
10484 * The num of destination.
10485 * @param[in, out] res
10486 * Pointer to sample resource.
10487 * @param[in, out] mdest_res
10488 * Pointer to destination array resource.
10489 * @param[in] sample_actions
10490 * Pointer to sample path actions list.
10491 * @param[in] action_flags
10492 * Holds the actions detected until now.
10493 * @param[out] error
10494 * Pointer to the error structure.
10497 * 0 on success, a negative errno value otherwise and rte_errno is set.
10500 flow_dv_create_action_sample(struct rte_eth_dev *dev,
10501 struct mlx5_flow *dev_flow,
10502 uint32_t num_of_dest,
10503 struct mlx5_flow_dv_sample_resource *res,
10504 struct mlx5_flow_dv_dest_array_resource *mdest_res,
10505 void **sample_actions,
10506 uint64_t action_flags,
10507 struct rte_flow_error *error)
10509 /* update normal path action resource into last index of array */
10510 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
10511 struct mlx5_flow_sub_actions_list *sample_act =
10512 &mdest_res->sample_act[dest_index];
10513 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10514 struct mlx5_flow_rss_desc *rss_desc;
10515 uint32_t normal_idx = 0;
10516 struct mlx5_hrxq *hrxq;
10520 rss_desc = &wks->rss_desc;
10521 if (num_of_dest > 1) {
10522 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
10523 /* Handle QP action for mirroring */
10524 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
10525 rss_desc, &hrxq_idx);
10527 return rte_flow_error_set
10529 RTE_FLOW_ERROR_TYPE_ACTION,
10531 "cannot create rx queue");
10533 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
10534 sample_act->dr_queue_action = hrxq->action;
10535 if (action_flags & MLX5_FLOW_ACTION_MARK)
10536 dev_flow->handle->rix_hrxq = hrxq_idx;
10537 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
10539 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
10541 mdest_res->sample_idx[dest_index].rix_encap_decap =
10542 dev_flow->handle->dvh.rix_encap_decap;
10543 sample_act->dr_encap_action =
10544 dev_flow->dv.encap_decap->action;
10545 dev_flow->handle->dvh.rix_encap_decap = 0;
10547 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
10549 mdest_res->sample_idx[dest_index].rix_port_id_action =
10550 dev_flow->handle->rix_port_id_action;
10551 sample_act->dr_port_id_action =
10552 dev_flow->dv.port_id_action->action;
10553 dev_flow->handle->rix_port_id_action = 0;
10555 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
10557 mdest_res->sample_idx[dest_index].rix_jump =
10558 dev_flow->handle->rix_jump;
10559 sample_act->dr_jump_action =
10560 dev_flow->dv.jump->action;
10561 dev_flow->handle->rix_jump = 0;
10563 sample_act->actions_num = normal_idx;
10564 /* update sample action resource into first index of array */
10565 mdest_res->ft_type = res->ft_type;
10566 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
10567 sizeof(struct mlx5_flow_sub_actions_idx));
10568 memcpy(&mdest_res->sample_act[0], &res->sample_act,
10569 sizeof(struct mlx5_flow_sub_actions_list));
10570 mdest_res->num_of_dest = num_of_dest;
10571 if (flow_dv_dest_array_resource_register(dev, mdest_res,
10573 return rte_flow_error_set(error, EINVAL,
10574 RTE_FLOW_ERROR_TYPE_ACTION,
10575 NULL, "can't create sample "
10578 res->sub_actions = sample_actions;
10579 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
10580 return rte_flow_error_set(error, EINVAL,
10581 RTE_FLOW_ERROR_TYPE_ACTION,
10583 "can't create sample action");
10589 * Remove an ASO age action from age actions list.
10592 * Pointer to the Ethernet device structure.
10594 * Pointer to the aso age action handler.
10597 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
10598 struct mlx5_aso_age_action *age)
10600 struct mlx5_age_info *age_info;
10601 struct mlx5_age_param *age_param = &age->age_params;
10602 struct mlx5_priv *priv = dev->data->dev_private;
10603 uint16_t expected = AGE_CANDIDATE;
10605 age_info = GET_PORT_AGE_INFO(priv);
10606 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
10607 AGE_FREE, false, __ATOMIC_RELAXED,
10608 __ATOMIC_RELAXED)) {
10610 * We need the lock even it is age timeout,
10611 * since age action may still in process.
10613 rte_spinlock_lock(&age_info->aged_sl);
10614 LIST_REMOVE(age, next);
10615 rte_spinlock_unlock(&age_info->aged_sl);
10616 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
10621 * Release an ASO age action.
10624 * Pointer to the Ethernet device structure.
10625 * @param[in] age_idx
10626 * Index of ASO age action to release.
10628 * True if the release operation is during flow destroy operation.
10629 * False if the release operation is during action destroy operation.
10632 * 0 when age action was removed, otherwise the number of references.
10635 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
10637 struct mlx5_priv *priv = dev->data->dev_private;
10638 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
10639 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
10640 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
10643 flow_dv_aso_age_remove_from_age(dev, age);
10644 rte_spinlock_lock(&mng->free_sl);
10645 LIST_INSERT_HEAD(&mng->free, age, next);
10646 rte_spinlock_unlock(&mng->free_sl);
10652 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
10655 * Pointer to the Ethernet device structure.
10658 * 0 on success, otherwise negative errno value and rte_errno is set.
10661 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
10663 struct mlx5_priv *priv = dev->data->dev_private;
10664 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
10665 void *old_pools = mng->pools;
10666 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
10667 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
10668 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
10671 rte_errno = ENOMEM;
10675 memcpy(pools, old_pools,
10676 mng->n * sizeof(struct mlx5_flow_counter_pool *));
10677 mlx5_free(old_pools);
10679 /* First ASO flow hit allocation - starting ASO data-path. */
10680 int ret = mlx5_aso_queue_start(priv->sh);
10688 mng->pools = pools;
10693 * Create and initialize a new ASO aging pool.
10696 * Pointer to the Ethernet device structure.
10697 * @param[out] age_free
10698 * Where to put the pointer of a new age action.
10701 * The age actions pool pointer and @p age_free is set on success,
10702 * NULL otherwise and rte_errno is set.
10704 static struct mlx5_aso_age_pool *
10705 flow_dv_age_pool_create(struct rte_eth_dev *dev,
10706 struct mlx5_aso_age_action **age_free)
10708 struct mlx5_priv *priv = dev->data->dev_private;
10709 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
10710 struct mlx5_aso_age_pool *pool = NULL;
10711 struct mlx5_devx_obj *obj = NULL;
10714 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->ctx,
10717 rte_errno = ENODATA;
10718 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
10721 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
10723 claim_zero(mlx5_devx_cmd_destroy(obj));
10724 rte_errno = ENOMEM;
10727 pool->flow_hit_aso_obj = obj;
10728 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
10729 rte_spinlock_lock(&mng->resize_sl);
10730 pool->index = mng->next;
10731 /* Resize pools array if there is no room for the new pool in it. */
10732 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
10733 claim_zero(mlx5_devx_cmd_destroy(obj));
10735 rte_spinlock_unlock(&mng->resize_sl);
10738 mng->pools[pool->index] = pool;
10740 rte_spinlock_unlock(&mng->resize_sl);
10741 /* Assign the first action in the new pool, the rest go to free list. */
10742 *age_free = &pool->actions[0];
10743 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
10744 pool->actions[i].offset = i;
10745 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
10751 * Allocate a ASO aging bit.
10754 * Pointer to the Ethernet device structure.
10755 * @param[out] error
10756 * Pointer to the error structure.
10759 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
10762 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
10764 struct mlx5_priv *priv = dev->data->dev_private;
10765 const struct mlx5_aso_age_pool *pool;
10766 struct mlx5_aso_age_action *age_free = NULL;
10767 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
10770 /* Try to get the next free age action bit. */
10771 rte_spinlock_lock(&mng->free_sl);
10772 age_free = LIST_FIRST(&mng->free);
10774 LIST_REMOVE(age_free, next);
10775 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
10776 rte_spinlock_unlock(&mng->free_sl);
10777 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
10778 NULL, "failed to create ASO age pool");
10779 return 0; /* 0 is an error. */
10781 rte_spinlock_unlock(&mng->free_sl);
10782 pool = container_of
10783 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
10784 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
10786 if (!age_free->dr_action) {
10787 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
10791 rte_flow_error_set(error, rte_errno,
10792 RTE_FLOW_ERROR_TYPE_ACTION,
10793 NULL, "failed to get reg_c "
10794 "for ASO flow hit");
10795 return 0; /* 0 is an error. */
10797 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
10798 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
10799 (priv->sh->rx_domain,
10800 pool->flow_hit_aso_obj->obj, age_free->offset,
10801 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
10802 (reg_c - REG_C_0));
10803 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
10804 if (!age_free->dr_action) {
10806 rte_spinlock_lock(&mng->free_sl);
10807 LIST_INSERT_HEAD(&mng->free, age_free, next);
10808 rte_spinlock_unlock(&mng->free_sl);
10809 rte_flow_error_set(error, rte_errno,
10810 RTE_FLOW_ERROR_TYPE_ACTION,
10811 NULL, "failed to create ASO "
10812 "flow hit action");
10813 return 0; /* 0 is an error. */
10816 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
10817 return pool->index | ((age_free->offset + 1) << 16);
10821 * Create a age action using ASO mechanism.
10824 * Pointer to rte_eth_dev structure.
10826 * Pointer to the aging action configuration.
10827 * @param[out] error
10828 * Pointer to the error structure.
10831 * Index to flow counter on success, 0 otherwise.
10834 flow_dv_translate_create_aso_age(struct rte_eth_dev *dev,
10835 const struct rte_flow_action_age *age,
10836 struct rte_flow_error *error)
10838 uint32_t age_idx = 0;
10839 struct mlx5_aso_age_action *aso_age;
10841 age_idx = flow_dv_aso_age_alloc(dev, error);
10844 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
10845 aso_age->age_params.context = age->context;
10846 aso_age->age_params.timeout = age->timeout;
10847 aso_age->age_params.port_id = dev->data->port_id;
10848 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
10850 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
10856 * Fill the flow with DV spec, lock free
10857 * (mutex should be acquired by caller).
10860 * Pointer to rte_eth_dev structure.
10861 * @param[in, out] dev_flow
10862 * Pointer to the sub flow.
10864 * Pointer to the flow attributes.
10866 * Pointer to the list of items.
10867 * @param[in] actions
10868 * Pointer to the list of actions.
10869 * @param[out] error
10870 * Pointer to the error structure.
10873 * 0 on success, a negative errno value otherwise and rte_errno is set.
10876 flow_dv_translate(struct rte_eth_dev *dev,
10877 struct mlx5_flow *dev_flow,
10878 const struct rte_flow_attr *attr,
10879 const struct rte_flow_item items[],
10880 const struct rte_flow_action actions[],
10881 struct rte_flow_error *error)
10883 struct mlx5_priv *priv = dev->data->dev_private;
10884 struct mlx5_dev_config *dev_conf = &priv->config;
10885 struct rte_flow *flow = dev_flow->flow;
10886 struct mlx5_flow_handle *handle = dev_flow->handle;
10887 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10888 struct mlx5_flow_rss_desc *rss_desc;
10889 uint64_t item_flags = 0;
10890 uint64_t last_item = 0;
10891 uint64_t action_flags = 0;
10892 struct mlx5_flow_dv_matcher matcher = {
10894 .size = sizeof(matcher.mask.buf) -
10895 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
10899 bool actions_end = false;
10901 struct mlx5_flow_dv_modify_hdr_resource res;
10902 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
10903 sizeof(struct mlx5_modification_cmd) *
10904 (MLX5_MAX_MODIFY_NUM + 1)];
10906 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
10907 const struct rte_flow_action_count *count = NULL;
10908 const struct rte_flow_action_age *age = NULL;
10909 union flow_dv_attr flow_attr = { .attr = 0 };
10911 union mlx5_flow_tbl_key tbl_key;
10912 uint32_t modify_action_position = UINT32_MAX;
10913 void *match_mask = matcher.mask.buf;
10914 void *match_value = dev_flow->dv.value.buf;
10915 uint8_t next_protocol = 0xff;
10916 struct rte_vlan_hdr vlan = { 0 };
10917 struct mlx5_flow_dv_dest_array_resource mdest_res;
10918 struct mlx5_flow_dv_sample_resource sample_res;
10919 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
10920 const struct rte_flow_action_sample *sample = NULL;
10921 struct mlx5_flow_sub_actions_list *sample_act;
10922 uint32_t sample_act_pos = UINT32_MAX;
10923 uint32_t num_of_dest = 0;
10924 int tmp_actions_n = 0;
10927 const struct mlx5_flow_tunnel *tunnel;
10928 struct flow_grp_info grp_info = {
10929 .external = !!dev_flow->external,
10930 .transfer = !!attr->transfer,
10931 .fdb_def_rule = !!priv->fdb_def_rule,
10932 .skip_scale = dev_flow->skip_scale &
10933 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
10937 return rte_flow_error_set(error, ENOMEM,
10938 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10940 "failed to push flow workspace");
10941 rss_desc = &wks->rss_desc;
10942 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
10943 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
10944 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
10945 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
10946 /* update normal path action resource into last index of array */
10947 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
10948 tunnel = is_flow_tunnel_match_rule(dev, attr, items, actions) ?
10949 flow_items_to_tunnel(items) :
10950 is_flow_tunnel_steer_rule(dev, attr, items, actions) ?
10951 flow_actions_to_tunnel(actions) :
10952 dev_flow->tunnel ? dev_flow->tunnel : NULL;
10953 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
10954 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
10955 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
10956 (dev, tunnel, attr, items, actions);
10957 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
10961 dev_flow->dv.group = table;
10962 if (attr->transfer)
10963 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
10964 /* number of actions must be set to 0 in case of dirty stack. */
10965 mhdr_res->actions_num = 0;
10966 if (is_flow_tunnel_match_rule(dev, attr, items, actions)) {
10968 * do not add decap action if match rule drops packet
10969 * HW rejects rules with decap & drop
10971 * if tunnel match rule was inserted before matching tunnel set
10972 * rule flow table used in the match rule must be registered.
10973 * current implementation handles that in the
10974 * flow_dv_match_register() at the function end.
10976 bool add_decap = true;
10977 const struct rte_flow_action *ptr = actions;
10979 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
10980 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
10986 if (flow_dv_create_action_l2_decap(dev, dev_flow,
10990 dev_flow->dv.actions[actions_n++] =
10991 dev_flow->dv.encap_decap->action;
10992 action_flags |= MLX5_FLOW_ACTION_DECAP;
10995 for (; !actions_end ; actions++) {
10996 const struct rte_flow_action_queue *queue;
10997 const struct rte_flow_action_rss *rss;
10998 const struct rte_flow_action *action = actions;
10999 const uint8_t *rss_key;
11000 const struct rte_flow_action_meter *mtr;
11001 struct mlx5_flow_tbl_resource *tbl;
11002 struct mlx5_aso_age_action *age_act;
11003 uint32_t port_id = 0;
11004 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
11005 int action_type = actions->type;
11006 const struct rte_flow_action *found_action = NULL;
11007 struct mlx5_flow_meter *fm = NULL;
11008 uint32_t jump_group = 0;
11010 if (!mlx5_flow_os_action_supported(action_type))
11011 return rte_flow_error_set(error, ENOTSUP,
11012 RTE_FLOW_ERROR_TYPE_ACTION,
11014 "action not supported");
11015 switch (action_type) {
11016 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
11017 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
11019 case RTE_FLOW_ACTION_TYPE_VOID:
11021 case RTE_FLOW_ACTION_TYPE_PORT_ID:
11022 if (flow_dv_translate_action_port_id(dev, action,
11025 port_id_resource.port_id = port_id;
11026 MLX5_ASSERT(!handle->rix_port_id_action);
11027 if (flow_dv_port_id_action_resource_register
11028 (dev, &port_id_resource, dev_flow, error))
11030 dev_flow->dv.actions[actions_n++] =
11031 dev_flow->dv.port_id_action->action;
11032 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11033 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
11034 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11037 case RTE_FLOW_ACTION_TYPE_FLAG:
11038 action_flags |= MLX5_FLOW_ACTION_FLAG;
11039 dev_flow->handle->mark = 1;
11040 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
11041 struct rte_flow_action_mark mark = {
11042 .id = MLX5_FLOW_MARK_DEFAULT,
11045 if (flow_dv_convert_action_mark(dev, &mark,
11049 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
11052 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
11054 * Only one FLAG or MARK is supported per device flow
11055 * right now. So the pointer to the tag resource must be
11056 * zero before the register process.
11058 MLX5_ASSERT(!handle->dvh.rix_tag);
11059 if (flow_dv_tag_resource_register(dev, tag_be,
11062 MLX5_ASSERT(dev_flow->dv.tag_resource);
11063 dev_flow->dv.actions[actions_n++] =
11064 dev_flow->dv.tag_resource->action;
11066 case RTE_FLOW_ACTION_TYPE_MARK:
11067 action_flags |= MLX5_FLOW_ACTION_MARK;
11068 dev_flow->handle->mark = 1;
11069 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
11070 const struct rte_flow_action_mark *mark =
11071 (const struct rte_flow_action_mark *)
11074 if (flow_dv_convert_action_mark(dev, mark,
11078 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
11082 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
11083 /* Legacy (non-extensive) MARK action. */
11084 tag_be = mlx5_flow_mark_set
11085 (((const struct rte_flow_action_mark *)
11086 (actions->conf))->id);
11087 MLX5_ASSERT(!handle->dvh.rix_tag);
11088 if (flow_dv_tag_resource_register(dev, tag_be,
11091 MLX5_ASSERT(dev_flow->dv.tag_resource);
11092 dev_flow->dv.actions[actions_n++] =
11093 dev_flow->dv.tag_resource->action;
11095 case RTE_FLOW_ACTION_TYPE_SET_META:
11096 if (flow_dv_convert_action_set_meta
11097 (dev, mhdr_res, attr,
11098 (const struct rte_flow_action_set_meta *)
11099 actions->conf, error))
11101 action_flags |= MLX5_FLOW_ACTION_SET_META;
11103 case RTE_FLOW_ACTION_TYPE_SET_TAG:
11104 if (flow_dv_convert_action_set_tag
11106 (const struct rte_flow_action_set_tag *)
11107 actions->conf, error))
11109 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
11111 case RTE_FLOW_ACTION_TYPE_DROP:
11112 action_flags |= MLX5_FLOW_ACTION_DROP;
11113 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
11115 case RTE_FLOW_ACTION_TYPE_QUEUE:
11116 queue = actions->conf;
11117 rss_desc->queue_num = 1;
11118 rss_desc->queue[0] = queue->index;
11119 action_flags |= MLX5_FLOW_ACTION_QUEUE;
11120 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
11121 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
11124 case RTE_FLOW_ACTION_TYPE_RSS:
11125 rss = actions->conf;
11126 memcpy(rss_desc->queue, rss->queue,
11127 rss->queue_num * sizeof(uint16_t));
11128 rss_desc->queue_num = rss->queue_num;
11129 /* NULL RSS key indicates default RSS key. */
11130 rss_key = !rss->key ? rss_hash_default_key : rss->key;
11131 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
11133 * rss->level and rss.types should be set in advance
11134 * when expanding items for RSS.
11136 action_flags |= MLX5_FLOW_ACTION_RSS;
11137 dev_flow->handle->fate_action = rss_desc->shared_rss ?
11138 MLX5_FLOW_FATE_SHARED_RSS :
11139 MLX5_FLOW_FATE_QUEUE;
11141 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
11142 flow->age = (uint32_t)(uintptr_t)(action->conf);
11143 age_act = flow_aso_age_get_by_idx(dev, flow->age);
11144 __atomic_fetch_add(&age_act->refcnt, 1,
11146 dev_flow->dv.actions[actions_n++] = age_act->dr_action;
11147 action_flags |= MLX5_FLOW_ACTION_AGE;
11149 case RTE_FLOW_ACTION_TYPE_AGE:
11150 if (priv->sh->flow_hit_aso_en && attr->group) {
11152 * Create one shared age action, to be used
11153 * by all sub-flows.
11157 flow_dv_translate_create_aso_age
11158 (dev, action->conf,
11161 return rte_flow_error_set
11163 RTE_FLOW_ERROR_TYPE_ACTION,
11165 "can't create ASO age action");
11167 dev_flow->dv.actions[actions_n++] =
11168 (flow_aso_age_get_by_idx
11169 (dev, flow->age))->dr_action;
11170 action_flags |= MLX5_FLOW_ACTION_AGE;
11174 case RTE_FLOW_ACTION_TYPE_COUNT:
11175 if (!dev_conf->devx) {
11176 return rte_flow_error_set
11178 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11180 "count action not supported");
11182 /* Save information first, will apply later. */
11183 if (actions->type == RTE_FLOW_ACTION_TYPE_COUNT)
11184 count = action->conf;
11186 age = action->conf;
11187 action_flags |= MLX5_FLOW_ACTION_COUNT;
11189 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
11190 dev_flow->dv.actions[actions_n++] =
11191 priv->sh->pop_vlan_action;
11192 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
11194 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
11195 if (!(action_flags &
11196 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
11197 flow_dev_get_vlan_info_from_items(items, &vlan);
11198 vlan.eth_proto = rte_be_to_cpu_16
11199 ((((const struct rte_flow_action_of_push_vlan *)
11200 actions->conf)->ethertype));
11201 found_action = mlx5_flow_find_action
11203 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
11205 mlx5_update_vlan_vid_pcp(found_action, &vlan);
11206 found_action = mlx5_flow_find_action
11208 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
11210 mlx5_update_vlan_vid_pcp(found_action, &vlan);
11211 if (flow_dv_create_action_push_vlan
11212 (dev, attr, &vlan, dev_flow, error))
11214 dev_flow->dv.actions[actions_n++] =
11215 dev_flow->dv.push_vlan_res->action;
11216 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
11218 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
11219 /* of_vlan_push action handled this action */
11220 MLX5_ASSERT(action_flags &
11221 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
11223 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
11224 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
11226 flow_dev_get_vlan_info_from_items(items, &vlan);
11227 mlx5_update_vlan_vid_pcp(actions, &vlan);
11228 /* If no VLAN push - this is a modify header action */
11229 if (flow_dv_convert_action_modify_vlan_vid
11230 (mhdr_res, actions, error))
11232 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
11234 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11235 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11236 if (flow_dv_create_action_l2_encap(dev, actions,
11241 dev_flow->dv.actions[actions_n++] =
11242 dev_flow->dv.encap_decap->action;
11243 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11244 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
11245 sample_act->action_flags |=
11246 MLX5_FLOW_ACTION_ENCAP;
11248 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
11249 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
11250 if (flow_dv_create_action_l2_decap(dev, dev_flow,
11254 dev_flow->dv.actions[actions_n++] =
11255 dev_flow->dv.encap_decap->action;
11256 action_flags |= MLX5_FLOW_ACTION_DECAP;
11258 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11259 /* Handle encap with preceding decap. */
11260 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
11261 if (flow_dv_create_action_raw_encap
11262 (dev, actions, dev_flow, attr, error))
11264 dev_flow->dv.actions[actions_n++] =
11265 dev_flow->dv.encap_decap->action;
11267 /* Handle encap without preceding decap. */
11268 if (flow_dv_create_action_l2_encap
11269 (dev, actions, dev_flow, attr->transfer,
11272 dev_flow->dv.actions[actions_n++] =
11273 dev_flow->dv.encap_decap->action;
11275 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11276 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
11277 sample_act->action_flags |=
11278 MLX5_FLOW_ACTION_ENCAP;
11280 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
11281 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
11283 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
11284 if (flow_dv_create_action_l2_decap
11285 (dev, dev_flow, attr->transfer, error))
11287 dev_flow->dv.actions[actions_n++] =
11288 dev_flow->dv.encap_decap->action;
11290 /* If decap is followed by encap, handle it at encap. */
11291 action_flags |= MLX5_FLOW_ACTION_DECAP;
11293 case RTE_FLOW_ACTION_TYPE_JUMP:
11294 jump_group = ((const struct rte_flow_action_jump *)
11295 action->conf)->group;
11296 grp_info.std_tbl_fix = 0;
11297 if (dev_flow->skip_scale &
11298 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
11299 grp_info.skip_scale = 1;
11301 grp_info.skip_scale = 0;
11302 ret = mlx5_flow_group_to_table(dev, tunnel,
11308 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
11310 !!dev_flow->external,
11311 tunnel, jump_group, 0,
11314 return rte_flow_error_set
11316 RTE_FLOW_ERROR_TYPE_ACTION,
11318 "cannot create jump action.");
11319 if (flow_dv_jump_tbl_resource_register
11320 (dev, tbl, dev_flow, error)) {
11321 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
11322 return rte_flow_error_set
11324 RTE_FLOW_ERROR_TYPE_ACTION,
11326 "cannot create jump action.");
11328 dev_flow->dv.actions[actions_n++] =
11329 dev_flow->dv.jump->action;
11330 action_flags |= MLX5_FLOW_ACTION_JUMP;
11331 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
11332 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
11335 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
11336 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
11337 if (flow_dv_convert_action_modify_mac
11338 (mhdr_res, actions, error))
11340 action_flags |= actions->type ==
11341 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
11342 MLX5_FLOW_ACTION_SET_MAC_SRC :
11343 MLX5_FLOW_ACTION_SET_MAC_DST;
11345 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
11346 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
11347 if (flow_dv_convert_action_modify_ipv4
11348 (mhdr_res, actions, error))
11350 action_flags |= actions->type ==
11351 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
11352 MLX5_FLOW_ACTION_SET_IPV4_SRC :
11353 MLX5_FLOW_ACTION_SET_IPV4_DST;
11355 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
11356 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
11357 if (flow_dv_convert_action_modify_ipv6
11358 (mhdr_res, actions, error))
11360 action_flags |= actions->type ==
11361 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
11362 MLX5_FLOW_ACTION_SET_IPV6_SRC :
11363 MLX5_FLOW_ACTION_SET_IPV6_DST;
11365 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
11366 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
11367 if (flow_dv_convert_action_modify_tp
11368 (mhdr_res, actions, items,
11369 &flow_attr, dev_flow, !!(action_flags &
11370 MLX5_FLOW_ACTION_DECAP), error))
11372 action_flags |= actions->type ==
11373 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
11374 MLX5_FLOW_ACTION_SET_TP_SRC :
11375 MLX5_FLOW_ACTION_SET_TP_DST;
11377 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
11378 if (flow_dv_convert_action_modify_dec_ttl
11379 (mhdr_res, items, &flow_attr, dev_flow,
11381 MLX5_FLOW_ACTION_DECAP), error))
11383 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
11385 case RTE_FLOW_ACTION_TYPE_SET_TTL:
11386 if (flow_dv_convert_action_modify_ttl
11387 (mhdr_res, actions, items, &flow_attr,
11388 dev_flow, !!(action_flags &
11389 MLX5_FLOW_ACTION_DECAP), error))
11391 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
11393 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
11394 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
11395 if (flow_dv_convert_action_modify_tcp_seq
11396 (mhdr_res, actions, error))
11398 action_flags |= actions->type ==
11399 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
11400 MLX5_FLOW_ACTION_INC_TCP_SEQ :
11401 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
11404 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
11405 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
11406 if (flow_dv_convert_action_modify_tcp_ack
11407 (mhdr_res, actions, error))
11409 action_flags |= actions->type ==
11410 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
11411 MLX5_FLOW_ACTION_INC_TCP_ACK :
11412 MLX5_FLOW_ACTION_DEC_TCP_ACK;
11414 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
11415 if (flow_dv_convert_action_set_reg
11416 (mhdr_res, actions, error))
11418 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
11420 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
11421 if (flow_dv_convert_action_copy_mreg
11422 (dev, mhdr_res, actions, error))
11424 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
11426 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
11427 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
11428 dev_flow->handle->fate_action =
11429 MLX5_FLOW_FATE_DEFAULT_MISS;
11431 case RTE_FLOW_ACTION_TYPE_METER:
11432 mtr = actions->conf;
11433 if (!flow->meter) {
11434 fm = mlx5_flow_meter_attach(priv, mtr->mtr_id,
11437 return rte_flow_error_set(error,
11439 RTE_FLOW_ERROR_TYPE_ACTION,
11442 "or invalid parameters");
11443 flow->meter = fm->idx;
11445 /* Set the meter action. */
11447 fm = mlx5_ipool_get(priv->sh->ipool
11448 [MLX5_IPOOL_MTR], flow->meter);
11450 return rte_flow_error_set(error,
11452 RTE_FLOW_ERROR_TYPE_ACTION,
11455 "or invalid parameters");
11457 dev_flow->dv.actions[actions_n++] =
11458 fm->mfts->meter_action;
11459 action_flags |= MLX5_FLOW_ACTION_METER;
11461 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
11462 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
11465 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
11467 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
11468 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
11471 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
11473 case RTE_FLOW_ACTION_TYPE_SAMPLE:
11474 sample_act_pos = actions_n;
11475 sample = (const struct rte_flow_action_sample *)
11478 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
11479 /* put encap action into group if work with port id */
11480 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
11481 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
11482 sample_act->action_flags |=
11483 MLX5_FLOW_ACTION_ENCAP;
11485 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
11486 if (flow_dv_convert_action_modify_field
11487 (dev, mhdr_res, actions, attr, error))
11489 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
11491 case RTE_FLOW_ACTION_TYPE_END:
11492 actions_end = true;
11493 if (mhdr_res->actions_num) {
11494 /* create modify action if needed. */
11495 if (flow_dv_modify_hdr_resource_register
11496 (dev, mhdr_res, dev_flow, error))
11498 dev_flow->dv.actions[modify_action_position] =
11499 handle->dvh.modify_hdr->action;
11501 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
11503 * Create one count action, to be used
11504 * by all sub-flows.
11506 if (!flow->counter) {
11508 flow_dv_translate_create_counter
11509 (dev, dev_flow, count,
11511 if (!flow->counter)
11512 return rte_flow_error_set
11514 RTE_FLOW_ERROR_TYPE_ACTION,
11515 NULL, "cannot create counter"
11518 dev_flow->dv.actions[actions_n] =
11519 (flow_dv_counter_get_by_idx(dev,
11520 flow->counter, NULL))->action;
11526 if (mhdr_res->actions_num &&
11527 modify_action_position == UINT32_MAX)
11528 modify_action_position = actions_n++;
11530 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
11531 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
11532 int item_type = items->type;
11534 if (!mlx5_flow_os_item_supported(item_type))
11535 return rte_flow_error_set(error, ENOTSUP,
11536 RTE_FLOW_ERROR_TYPE_ITEM,
11537 NULL, "item not supported");
11538 switch (item_type) {
11539 case RTE_FLOW_ITEM_TYPE_PORT_ID:
11540 flow_dv_translate_item_port_id
11541 (dev, match_mask, match_value, items, attr);
11542 last_item = MLX5_FLOW_ITEM_PORT_ID;
11544 case RTE_FLOW_ITEM_TYPE_ETH:
11545 flow_dv_translate_item_eth(match_mask, match_value,
11547 dev_flow->dv.group);
11548 matcher.priority = action_flags &
11549 MLX5_FLOW_ACTION_DEFAULT_MISS &&
11550 !dev_flow->external ?
11551 MLX5_PRIORITY_MAP_L3 :
11552 MLX5_PRIORITY_MAP_L2;
11553 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
11554 MLX5_FLOW_LAYER_OUTER_L2;
11556 case RTE_FLOW_ITEM_TYPE_VLAN:
11557 flow_dv_translate_item_vlan(dev_flow,
11558 match_mask, match_value,
11560 dev_flow->dv.group);
11561 matcher.priority = MLX5_PRIORITY_MAP_L2;
11562 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
11563 MLX5_FLOW_LAYER_INNER_VLAN) :
11564 (MLX5_FLOW_LAYER_OUTER_L2 |
11565 MLX5_FLOW_LAYER_OUTER_VLAN);
11567 case RTE_FLOW_ITEM_TYPE_IPV4:
11568 mlx5_flow_tunnel_ip_check(items, next_protocol,
11569 &item_flags, &tunnel);
11570 flow_dv_translate_item_ipv4(match_mask, match_value,
11572 dev_flow->dv.group);
11573 matcher.priority = MLX5_PRIORITY_MAP_L3;
11574 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
11575 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
11576 if (items->mask != NULL &&
11577 ((const struct rte_flow_item_ipv4 *)
11578 items->mask)->hdr.next_proto_id) {
11580 ((const struct rte_flow_item_ipv4 *)
11581 (items->spec))->hdr.next_proto_id;
11583 ((const struct rte_flow_item_ipv4 *)
11584 (items->mask))->hdr.next_proto_id;
11586 /* Reset for inner layer. */
11587 next_protocol = 0xff;
11590 case RTE_FLOW_ITEM_TYPE_IPV6:
11591 mlx5_flow_tunnel_ip_check(items, next_protocol,
11592 &item_flags, &tunnel);
11593 flow_dv_translate_item_ipv6(match_mask, match_value,
11595 dev_flow->dv.group);
11596 matcher.priority = MLX5_PRIORITY_MAP_L3;
11597 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
11598 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
11599 if (items->mask != NULL &&
11600 ((const struct rte_flow_item_ipv6 *)
11601 items->mask)->hdr.proto) {
11603 ((const struct rte_flow_item_ipv6 *)
11604 items->spec)->hdr.proto;
11606 ((const struct rte_flow_item_ipv6 *)
11607 items->mask)->hdr.proto;
11609 /* Reset for inner layer. */
11610 next_protocol = 0xff;
11613 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
11614 flow_dv_translate_item_ipv6_frag_ext(match_mask,
11617 last_item = tunnel ?
11618 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
11619 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
11620 if (items->mask != NULL &&
11621 ((const struct rte_flow_item_ipv6_frag_ext *)
11622 items->mask)->hdr.next_header) {
11624 ((const struct rte_flow_item_ipv6_frag_ext *)
11625 items->spec)->hdr.next_header;
11627 ((const struct rte_flow_item_ipv6_frag_ext *)
11628 items->mask)->hdr.next_header;
11630 /* Reset for inner layer. */
11631 next_protocol = 0xff;
11634 case RTE_FLOW_ITEM_TYPE_TCP:
11635 flow_dv_translate_item_tcp(match_mask, match_value,
11637 matcher.priority = MLX5_PRIORITY_MAP_L4;
11638 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
11639 MLX5_FLOW_LAYER_OUTER_L4_TCP;
11641 case RTE_FLOW_ITEM_TYPE_UDP:
11642 flow_dv_translate_item_udp(match_mask, match_value,
11644 matcher.priority = MLX5_PRIORITY_MAP_L4;
11645 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
11646 MLX5_FLOW_LAYER_OUTER_L4_UDP;
11648 case RTE_FLOW_ITEM_TYPE_GRE:
11649 flow_dv_translate_item_gre(match_mask, match_value,
11651 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
11652 last_item = MLX5_FLOW_LAYER_GRE;
11654 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
11655 flow_dv_translate_item_gre_key(match_mask,
11656 match_value, items);
11657 last_item = MLX5_FLOW_LAYER_GRE_KEY;
11659 case RTE_FLOW_ITEM_TYPE_NVGRE:
11660 flow_dv_translate_item_nvgre(match_mask, match_value,
11662 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
11663 last_item = MLX5_FLOW_LAYER_GRE;
11665 case RTE_FLOW_ITEM_TYPE_VXLAN:
11666 flow_dv_translate_item_vxlan(match_mask, match_value,
11668 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
11669 last_item = MLX5_FLOW_LAYER_VXLAN;
11671 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
11672 flow_dv_translate_item_vxlan_gpe(match_mask,
11673 match_value, items,
11675 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
11676 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
11678 case RTE_FLOW_ITEM_TYPE_GENEVE:
11679 flow_dv_translate_item_geneve(match_mask, match_value,
11681 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
11682 last_item = MLX5_FLOW_LAYER_GENEVE;
11684 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
11685 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
11689 return rte_flow_error_set(error, -ret,
11690 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
11691 "cannot create GENEVE TLV option");
11692 flow->geneve_tlv_option = 1;
11693 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
11695 case RTE_FLOW_ITEM_TYPE_MPLS:
11696 flow_dv_translate_item_mpls(match_mask, match_value,
11697 items, last_item, tunnel);
11698 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
11699 last_item = MLX5_FLOW_LAYER_MPLS;
11701 case RTE_FLOW_ITEM_TYPE_MARK:
11702 flow_dv_translate_item_mark(dev, match_mask,
11703 match_value, items);
11704 last_item = MLX5_FLOW_ITEM_MARK;
11706 case RTE_FLOW_ITEM_TYPE_META:
11707 flow_dv_translate_item_meta(dev, match_mask,
11708 match_value, attr, items);
11709 last_item = MLX5_FLOW_ITEM_METADATA;
11711 case RTE_FLOW_ITEM_TYPE_ICMP:
11712 flow_dv_translate_item_icmp(match_mask, match_value,
11714 last_item = MLX5_FLOW_LAYER_ICMP;
11716 case RTE_FLOW_ITEM_TYPE_ICMP6:
11717 flow_dv_translate_item_icmp6(match_mask, match_value,
11719 last_item = MLX5_FLOW_LAYER_ICMP6;
11721 case RTE_FLOW_ITEM_TYPE_TAG:
11722 flow_dv_translate_item_tag(dev, match_mask,
11723 match_value, items);
11724 last_item = MLX5_FLOW_ITEM_TAG;
11726 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
11727 flow_dv_translate_mlx5_item_tag(dev, match_mask,
11728 match_value, items);
11729 last_item = MLX5_FLOW_ITEM_TAG;
11731 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
11732 flow_dv_translate_item_tx_queue(dev, match_mask,
11735 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
11737 case RTE_FLOW_ITEM_TYPE_GTP:
11738 flow_dv_translate_item_gtp(match_mask, match_value,
11740 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
11741 last_item = MLX5_FLOW_LAYER_GTP;
11743 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
11744 ret = flow_dv_translate_item_gtp_psc(match_mask,
11748 return rte_flow_error_set(error, -ret,
11749 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
11750 "cannot create GTP PSC item");
11751 last_item = MLX5_FLOW_LAYER_GTP_PSC;
11753 case RTE_FLOW_ITEM_TYPE_ECPRI:
11754 if (!mlx5_flex_parser_ecpri_exist(dev)) {
11755 /* Create it only the first time to be used. */
11756 ret = mlx5_flex_parser_ecpri_alloc(dev);
11758 return rte_flow_error_set
11760 RTE_FLOW_ERROR_TYPE_ITEM,
11762 "cannot create eCPRI parser");
11764 /* Adjust the length matcher and device flow value. */
11765 matcher.mask.size = MLX5_ST_SZ_BYTES(fte_match_param);
11766 dev_flow->dv.value.size =
11767 MLX5_ST_SZ_BYTES(fte_match_param);
11768 flow_dv_translate_item_ecpri(dev, match_mask,
11769 match_value, items);
11770 /* No other protocol should follow eCPRI layer. */
11771 last_item = MLX5_FLOW_LAYER_ECPRI;
11776 item_flags |= last_item;
11779 * When E-Switch mode is enabled, we have two cases where we need to
11780 * set the source port manually.
11781 * The first one, is in case of Nic steering rule, and the second is
11782 * E-Switch rule where no port_id item was found. In both cases
11783 * the source port is set according the current port in use.
11785 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
11786 (priv->representor || priv->master)) {
11787 if (flow_dv_translate_item_port_id(dev, match_mask,
11788 match_value, NULL, attr))
11791 #ifdef RTE_LIBRTE_MLX5_DEBUG
11792 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
11793 dev_flow->dv.value.buf));
11796 * Layers may be already initialized from prefix flow if this dev_flow
11797 * is the suffix flow.
11799 handle->layers |= item_flags;
11800 if (action_flags & MLX5_FLOW_ACTION_RSS)
11801 flow_dv_hashfields_set(dev_flow, rss_desc);
11802 /* If has RSS action in the sample action, the Sample/Mirror resource
11803 * should be registered after the hash filed be update.
11805 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
11806 ret = flow_dv_translate_action_sample(dev,
11815 ret = flow_dv_create_action_sample(dev,
11824 return rte_flow_error_set
11826 RTE_FLOW_ERROR_TYPE_ACTION,
11828 "cannot create sample action");
11829 if (num_of_dest > 1) {
11830 dev_flow->dv.actions[sample_act_pos] =
11831 dev_flow->dv.dest_array_res->action;
11833 dev_flow->dv.actions[sample_act_pos] =
11834 dev_flow->dv.sample_res->verbs_action;
11838 * For multiple destination (sample action with ratio=1), the encap
11839 * action and port id action will be combined into group action.
11840 * So need remove the original these actions in the flow and only
11841 * use the sample action instead of.
11843 if (num_of_dest > 1 &&
11844 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
11846 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
11848 for (i = 0; i < actions_n; i++) {
11849 if ((sample_act->dr_encap_action &&
11850 sample_act->dr_encap_action ==
11851 dev_flow->dv.actions[i]) ||
11852 (sample_act->dr_port_id_action &&
11853 sample_act->dr_port_id_action ==
11854 dev_flow->dv.actions[i]) ||
11855 (sample_act->dr_jump_action &&
11856 sample_act->dr_jump_action ==
11857 dev_flow->dv.actions[i]))
11859 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
11861 memcpy((void *)dev_flow->dv.actions,
11862 (void *)temp_actions,
11863 tmp_actions_n * sizeof(void *));
11864 actions_n = tmp_actions_n;
11866 dev_flow->dv.actions_n = actions_n;
11867 dev_flow->act_flags = action_flags;
11868 /* Register matcher. */
11869 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
11870 matcher.mask.size);
11871 matcher.priority = mlx5_get_matcher_priority(dev, attr,
11873 /* reserved field no needs to be set to 0 here. */
11874 tbl_key.domain = attr->transfer;
11875 tbl_key.direction = attr->egress;
11876 tbl_key.table_id = dev_flow->dv.group;
11877 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
11878 tunnel, attr->group, error))
11884 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
11887 * @param[in, out] action
11888 * Shred RSS action holding hash RX queue objects.
11889 * @param[in] hash_fields
11890 * Defines combination of packet fields to participate in RX hash.
11891 * @param[in] tunnel
11893 * @param[in] hrxq_idx
11894 * Hash RX queue index to set.
11897 * 0 on success, otherwise negative errno value.
11900 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
11901 const uint64_t hash_fields,
11904 uint32_t *hrxqs = action->hrxq;
11906 switch (hash_fields & ~IBV_RX_HASH_INNER) {
11907 case MLX5_RSS_HASH_IPV4:
11908 /* fall-through. */
11909 case MLX5_RSS_HASH_IPV4_DST_ONLY:
11910 /* fall-through. */
11911 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
11912 hrxqs[0] = hrxq_idx;
11914 case MLX5_RSS_HASH_IPV4_TCP:
11915 /* fall-through. */
11916 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
11917 /* fall-through. */
11918 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
11919 hrxqs[1] = hrxq_idx;
11921 case MLX5_RSS_HASH_IPV4_UDP:
11922 /* fall-through. */
11923 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
11924 /* fall-through. */
11925 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
11926 hrxqs[2] = hrxq_idx;
11928 case MLX5_RSS_HASH_IPV6:
11929 /* fall-through. */
11930 case MLX5_RSS_HASH_IPV6_DST_ONLY:
11931 /* fall-through. */
11932 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
11933 hrxqs[3] = hrxq_idx;
11935 case MLX5_RSS_HASH_IPV6_TCP:
11936 /* fall-through. */
11937 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
11938 /* fall-through. */
11939 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
11940 hrxqs[4] = hrxq_idx;
11942 case MLX5_RSS_HASH_IPV6_UDP:
11943 /* fall-through. */
11944 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
11945 /* fall-through. */
11946 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
11947 hrxqs[5] = hrxq_idx;
11949 case MLX5_RSS_HASH_NONE:
11950 hrxqs[6] = hrxq_idx;
11958 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
11962 * Pointer to the Ethernet device structure.
11964 * Shared RSS action ID holding hash RX queue objects.
11965 * @param[in] hash_fields
11966 * Defines combination of packet fields to participate in RX hash.
11967 * @param[in] tunnel
11971 * Valid hash RX queue index, otherwise 0.
11974 __flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
11975 const uint64_t hash_fields)
11977 struct mlx5_priv *priv = dev->data->dev_private;
11978 struct mlx5_shared_action_rss *shared_rss =
11979 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
11980 const uint32_t *hrxqs = shared_rss->hrxq;
11982 switch (hash_fields & ~IBV_RX_HASH_INNER) {
11983 case MLX5_RSS_HASH_IPV4:
11984 /* fall-through. */
11985 case MLX5_RSS_HASH_IPV4_DST_ONLY:
11986 /* fall-through. */
11987 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
11989 case MLX5_RSS_HASH_IPV4_TCP:
11990 /* fall-through. */
11991 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
11992 /* fall-through. */
11993 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
11995 case MLX5_RSS_HASH_IPV4_UDP:
11996 /* fall-through. */
11997 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
11998 /* fall-through. */
11999 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
12001 case MLX5_RSS_HASH_IPV6:
12002 /* fall-through. */
12003 case MLX5_RSS_HASH_IPV6_DST_ONLY:
12004 /* fall-through. */
12005 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
12007 case MLX5_RSS_HASH_IPV6_TCP:
12008 /* fall-through. */
12009 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
12010 /* fall-through. */
12011 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
12013 case MLX5_RSS_HASH_IPV6_UDP:
12014 /* fall-through. */
12015 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
12016 /* fall-through. */
12017 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
12019 case MLX5_RSS_HASH_NONE:
12028 * Apply the flow to the NIC, lock free,
12029 * (mutex should be acquired by caller).
12032 * Pointer to the Ethernet device structure.
12033 * @param[in, out] flow
12034 * Pointer to flow structure.
12035 * @param[out] error
12036 * Pointer to error structure.
12039 * 0 on success, a negative errno value otherwise and rte_errno is set.
12042 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
12043 struct rte_flow_error *error)
12045 struct mlx5_flow_dv_workspace *dv;
12046 struct mlx5_flow_handle *dh;
12047 struct mlx5_flow_handle_dv *dv_h;
12048 struct mlx5_flow *dev_flow;
12049 struct mlx5_priv *priv = dev->data->dev_private;
12050 uint32_t handle_idx;
12054 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12055 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
12058 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
12059 dev_flow = &wks->flows[idx];
12060 dv = &dev_flow->dv;
12061 dh = dev_flow->handle;
12064 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
12065 if (dv->transfer) {
12066 MLX5_ASSERT(priv->sh->dr_drop_action);
12067 dv->actions[n++] = priv->sh->dr_drop_action;
12069 #ifdef HAVE_MLX5DV_DR
12070 /* DR supports drop action placeholder. */
12071 MLX5_ASSERT(priv->sh->dr_drop_action);
12072 dv->actions[n++] = priv->sh->dr_drop_action;
12074 /* For DV we use the explicit drop queue. */
12075 MLX5_ASSERT(priv->drop_queue.hrxq);
12077 priv->drop_queue.hrxq->action;
12080 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
12081 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
12082 struct mlx5_hrxq *hrxq;
12085 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
12090 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12091 "cannot get hash queue");
12094 dh->rix_hrxq = hrxq_idx;
12095 dv->actions[n++] = hrxq->action;
12096 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
12097 struct mlx5_hrxq *hrxq = NULL;
12100 hrxq_idx = __flow_dv_action_rss_hrxq_lookup(dev,
12101 rss_desc->shared_rss,
12102 dev_flow->hash_fields);
12104 hrxq = mlx5_ipool_get
12105 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
12110 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12111 "cannot get hash queue");
12114 dh->rix_srss = rss_desc->shared_rss;
12115 dv->actions[n++] = hrxq->action;
12116 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
12117 if (!priv->sh->default_miss_action) {
12120 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12121 "default miss action not be created.");
12124 dv->actions[n++] = priv->sh->default_miss_action;
12126 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
12127 (void *)&dv->value, n,
12128 dv->actions, &dh->drv_flow);
12130 rte_flow_error_set(error, errno,
12131 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12133 "hardware refuses to create flow");
12136 if (priv->vmwa_context &&
12137 dh->vf_vlan.tag && !dh->vf_vlan.created) {
12139 * The rule contains the VLAN pattern.
12140 * For VF we are going to create VLAN
12141 * interface to make hypervisor set correct
12142 * e-Switch vport context.
12144 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
12149 err = rte_errno; /* Save rte_errno before cleanup. */
12150 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
12151 handle_idx, dh, next) {
12152 /* hrxq is union, don't clear it if the flag is not set. */
12153 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
12154 mlx5_hrxq_release(dev, dh->rix_hrxq);
12156 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
12159 if (dh->vf_vlan.tag && dh->vf_vlan.created)
12160 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
12162 rte_errno = err; /* Restore rte_errno. */
12167 flow_dv_matcher_remove_cb(struct mlx5_cache_list *list __rte_unused,
12168 struct mlx5_cache_entry *entry)
12170 struct mlx5_flow_dv_matcher *cache = container_of(entry, typeof(*cache),
12173 claim_zero(mlx5_flow_os_destroy_flow_matcher(cache->matcher_object));
12178 * Release the flow matcher.
12181 * Pointer to Ethernet device.
12183 * Index to port ID action resource.
12186 * 1 while a reference on it exists, 0 when freed.
12189 flow_dv_matcher_release(struct rte_eth_dev *dev,
12190 struct mlx5_flow_handle *handle)
12192 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
12193 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
12194 typeof(*tbl), tbl);
12197 MLX5_ASSERT(matcher->matcher_object);
12198 ret = mlx5_cache_unregister(&tbl->matchers, &matcher->entry);
12199 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
12204 * Release encap_decap resource.
12207 * Pointer to the hash list.
12209 * Pointer to exist resource entry object.
12212 flow_dv_encap_decap_remove_cb(struct mlx5_hlist *list,
12213 struct mlx5_hlist_entry *entry)
12215 struct mlx5_dev_ctx_shared *sh = list->ctx;
12216 struct mlx5_flow_dv_encap_decap_resource *res =
12217 container_of(entry, typeof(*res), entry);
12219 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
12220 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
12224 * Release an encap/decap resource.
12227 * Pointer to Ethernet device.
12228 * @param encap_decap_idx
12229 * Index of encap decap resource.
12232 * 1 while a reference on it exists, 0 when freed.
12235 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
12236 uint32_t encap_decap_idx)
12238 struct mlx5_priv *priv = dev->data->dev_private;
12239 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
12241 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
12243 if (!cache_resource)
12245 MLX5_ASSERT(cache_resource->action);
12246 return mlx5_hlist_unregister(priv->sh->encaps_decaps,
12247 &cache_resource->entry);
12251 * Release an jump to table action resource.
12254 * Pointer to Ethernet device.
12256 * Index to the jump action resource.
12259 * 1 while a reference on it exists, 0 when freed.
12262 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
12265 struct mlx5_priv *priv = dev->data->dev_private;
12266 struct mlx5_flow_tbl_data_entry *tbl_data;
12268 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
12272 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
12276 flow_dv_modify_remove_cb(struct mlx5_hlist *list __rte_unused,
12277 struct mlx5_hlist_entry *entry)
12279 struct mlx5_flow_dv_modify_hdr_resource *res =
12280 container_of(entry, typeof(*res), entry);
12282 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
12287 * Release a modify-header resource.
12290 * Pointer to Ethernet device.
12292 * Pointer to mlx5_flow_handle.
12295 * 1 while a reference on it exists, 0 when freed.
12298 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
12299 struct mlx5_flow_handle *handle)
12301 struct mlx5_priv *priv = dev->data->dev_private;
12302 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
12304 MLX5_ASSERT(entry->action);
12305 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
12309 flow_dv_port_id_remove_cb(struct mlx5_cache_list *list,
12310 struct mlx5_cache_entry *entry)
12312 struct mlx5_dev_ctx_shared *sh = list->ctx;
12313 struct mlx5_flow_dv_port_id_action_resource *cache =
12314 container_of(entry, typeof(*cache), entry);
12316 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
12317 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], cache->idx);
12321 * Release port ID action resource.
12324 * Pointer to Ethernet device.
12326 * Pointer to mlx5_flow_handle.
12329 * 1 while a reference on it exists, 0 when freed.
12332 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
12335 struct mlx5_priv *priv = dev->data->dev_private;
12336 struct mlx5_flow_dv_port_id_action_resource *cache;
12338 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
12341 MLX5_ASSERT(cache->action);
12342 return mlx5_cache_unregister(&priv->sh->port_id_action_list,
12347 * Release shared RSS action resource.
12350 * Pointer to Ethernet device.
12352 * Shared RSS action index.
12355 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
12357 struct mlx5_priv *priv = dev->data->dev_private;
12358 struct mlx5_shared_action_rss *shared_rss;
12360 shared_rss = mlx5_ipool_get
12361 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
12362 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
12366 flow_dv_push_vlan_remove_cb(struct mlx5_cache_list *list,
12367 struct mlx5_cache_entry *entry)
12369 struct mlx5_dev_ctx_shared *sh = list->ctx;
12370 struct mlx5_flow_dv_push_vlan_action_resource *cache =
12371 container_of(entry, typeof(*cache), entry);
12373 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
12374 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], cache->idx);
12378 * Release push vlan action resource.
12381 * Pointer to Ethernet device.
12383 * Pointer to mlx5_flow_handle.
12386 * 1 while a reference on it exists, 0 when freed.
12389 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
12390 struct mlx5_flow_handle *handle)
12392 struct mlx5_priv *priv = dev->data->dev_private;
12393 struct mlx5_flow_dv_push_vlan_action_resource *cache;
12394 uint32_t idx = handle->dvh.rix_push_vlan;
12396 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
12399 MLX5_ASSERT(cache->action);
12400 return mlx5_cache_unregister(&priv->sh->push_vlan_action_list,
12405 * Release the fate resource.
12408 * Pointer to Ethernet device.
12410 * Pointer to mlx5_flow_handle.
12413 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
12414 struct mlx5_flow_handle *handle)
12416 if (!handle->rix_fate)
12418 switch (handle->fate_action) {
12419 case MLX5_FLOW_FATE_QUEUE:
12420 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
12421 mlx5_hrxq_release(dev, handle->rix_hrxq);
12423 case MLX5_FLOW_FATE_JUMP:
12424 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
12426 case MLX5_FLOW_FATE_PORT_ID:
12427 flow_dv_port_id_action_resource_release(dev,
12428 handle->rix_port_id_action);
12431 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
12434 handle->rix_fate = 0;
12438 flow_dv_sample_remove_cb(struct mlx5_cache_list *list __rte_unused,
12439 struct mlx5_cache_entry *entry)
12441 struct mlx5_flow_dv_sample_resource *cache_resource =
12442 container_of(entry, typeof(*cache_resource), entry);
12443 struct rte_eth_dev *dev = cache_resource->dev;
12444 struct mlx5_priv *priv = dev->data->dev_private;
12446 if (cache_resource->verbs_action)
12447 claim_zero(mlx5_flow_os_destroy_flow_action
12448 (cache_resource->verbs_action));
12449 if (cache_resource->normal_path_tbl)
12450 flow_dv_tbl_resource_release(MLX5_SH(dev),
12451 cache_resource->normal_path_tbl);
12452 flow_dv_sample_sub_actions_release(dev,
12453 &cache_resource->sample_idx);
12454 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
12455 cache_resource->idx);
12456 DRV_LOG(DEBUG, "sample resource %p: removed",
12457 (void *)cache_resource);
12461 * Release an sample resource.
12464 * Pointer to Ethernet device.
12466 * Pointer to mlx5_flow_handle.
12469 * 1 while a reference on it exists, 0 when freed.
12472 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
12473 struct mlx5_flow_handle *handle)
12475 struct mlx5_priv *priv = dev->data->dev_private;
12476 struct mlx5_flow_dv_sample_resource *cache_resource;
12478 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
12479 handle->dvh.rix_sample);
12480 if (!cache_resource)
12482 MLX5_ASSERT(cache_resource->verbs_action);
12483 return mlx5_cache_unregister(&priv->sh->sample_action_list,
12484 &cache_resource->entry);
12488 flow_dv_dest_array_remove_cb(struct mlx5_cache_list *list __rte_unused,
12489 struct mlx5_cache_entry *entry)
12491 struct mlx5_flow_dv_dest_array_resource *cache_resource =
12492 container_of(entry, typeof(*cache_resource), entry);
12493 struct rte_eth_dev *dev = cache_resource->dev;
12494 struct mlx5_priv *priv = dev->data->dev_private;
12497 MLX5_ASSERT(cache_resource->action);
12498 if (cache_resource->action)
12499 claim_zero(mlx5_flow_os_destroy_flow_action
12500 (cache_resource->action));
12501 for (; i < cache_resource->num_of_dest; i++)
12502 flow_dv_sample_sub_actions_release(dev,
12503 &cache_resource->sample_idx[i]);
12504 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12505 cache_resource->idx);
12506 DRV_LOG(DEBUG, "destination array resource %p: removed",
12507 (void *)cache_resource);
12511 * Release an destination array resource.
12514 * Pointer to Ethernet device.
12516 * Pointer to mlx5_flow_handle.
12519 * 1 while a reference on it exists, 0 when freed.
12522 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
12523 struct mlx5_flow_handle *handle)
12525 struct mlx5_priv *priv = dev->data->dev_private;
12526 struct mlx5_flow_dv_dest_array_resource *cache;
12528 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12529 handle->dvh.rix_dest_array);
12532 MLX5_ASSERT(cache->action);
12533 return mlx5_cache_unregister(&priv->sh->dest_array_list,
12538 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
12540 struct mlx5_priv *priv = dev->data->dev_private;
12541 struct mlx5_dev_ctx_shared *sh = priv->sh;
12542 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
12543 sh->geneve_tlv_option_resource;
12544 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
12545 if (geneve_opt_resource) {
12546 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
12547 __ATOMIC_RELAXED))) {
12548 claim_zero(mlx5_devx_cmd_destroy
12549 (geneve_opt_resource->obj));
12550 mlx5_free(sh->geneve_tlv_option_resource);
12551 sh->geneve_tlv_option_resource = NULL;
12554 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
12558 * Remove the flow from the NIC but keeps it in memory.
12559 * Lock free, (mutex should be acquired by caller).
12562 * Pointer to Ethernet device.
12563 * @param[in, out] flow
12564 * Pointer to flow structure.
12567 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
12569 struct mlx5_flow_handle *dh;
12570 uint32_t handle_idx;
12571 struct mlx5_priv *priv = dev->data->dev_private;
12575 handle_idx = flow->dev_handles;
12576 while (handle_idx) {
12577 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
12581 if (dh->drv_flow) {
12582 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
12583 dh->drv_flow = NULL;
12585 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
12586 flow_dv_fate_resource_release(dev, dh);
12587 if (dh->vf_vlan.tag && dh->vf_vlan.created)
12588 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
12589 handle_idx = dh->next.next;
12594 * Remove the flow from the NIC and the memory.
12595 * Lock free, (mutex should be acquired by caller).
12598 * Pointer to the Ethernet device structure.
12599 * @param[in, out] flow
12600 * Pointer to flow structure.
12603 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
12605 struct mlx5_flow_handle *dev_handle;
12606 struct mlx5_priv *priv = dev->data->dev_private;
12611 flow_dv_remove(dev, flow);
12612 if (flow->counter) {
12613 flow_dv_counter_free(dev, flow->counter);
12617 struct mlx5_flow_meter *fm;
12619 fm = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MTR],
12622 mlx5_flow_meter_detach(fm);
12626 flow_dv_aso_age_release(dev, flow->age);
12627 if (flow->geneve_tlv_option) {
12628 flow_dv_geneve_tlv_option_resource_release(dev);
12629 flow->geneve_tlv_option = 0;
12631 while (flow->dev_handles) {
12632 uint32_t tmp_idx = flow->dev_handles;
12634 dev_handle = mlx5_ipool_get(priv->sh->ipool
12635 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
12638 flow->dev_handles = dev_handle->next.next;
12639 if (dev_handle->dvh.matcher)
12640 flow_dv_matcher_release(dev, dev_handle);
12641 if (dev_handle->dvh.rix_sample)
12642 flow_dv_sample_resource_release(dev, dev_handle);
12643 if (dev_handle->dvh.rix_dest_array)
12644 flow_dv_dest_array_resource_release(dev, dev_handle);
12645 if (dev_handle->dvh.rix_encap_decap)
12646 flow_dv_encap_decap_resource_release(dev,
12647 dev_handle->dvh.rix_encap_decap);
12648 if (dev_handle->dvh.modify_hdr)
12649 flow_dv_modify_hdr_resource_release(dev, dev_handle);
12650 if (dev_handle->dvh.rix_push_vlan)
12651 flow_dv_push_vlan_action_resource_release(dev,
12653 if (dev_handle->dvh.rix_tag)
12654 flow_dv_tag_release(dev,
12655 dev_handle->dvh.rix_tag);
12656 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
12657 flow_dv_fate_resource_release(dev, dev_handle);
12659 srss = dev_handle->rix_srss;
12660 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
12664 flow_dv_shared_rss_action_release(dev, srss);
12668 * Release array of hash RX queue objects.
12672 * Pointer to the Ethernet device structure.
12673 * @param[in, out] hrxqs
12674 * Array of hash RX queue objects.
12677 * Total number of references to hash RX queue objects in *hrxqs* array
12678 * after this operation.
12681 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
12682 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
12687 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
12688 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
12698 * Release all hash RX queue objects representing shared RSS action.
12701 * Pointer to the Ethernet device structure.
12702 * @param[in, out] action
12703 * Shared RSS action to remove hash RX queue objects from.
12706 * Total number of references to hash RX queue objects stored in *action*
12707 * after this operation.
12708 * Expected to be 0 if no external references held.
12711 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
12712 struct mlx5_shared_action_rss *shared_rss)
12714 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
12718 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
12721 * Only one hash value is available for one L3+L4 combination:
12723 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
12724 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
12725 * same slot in mlx5_rss_hash_fields.
12728 * Pointer to the shared action RSS conf.
12729 * @param[in, out] hash_field
12730 * hash_field variable needed to be adjusted.
12736 __flow_dv_action_rss_l34_hash_adjust(struct mlx5_shared_action_rss *rss,
12737 uint64_t *hash_field)
12739 uint64_t rss_types = rss->origin.types;
12741 switch (*hash_field & ~IBV_RX_HASH_INNER) {
12742 case MLX5_RSS_HASH_IPV4:
12743 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
12744 *hash_field &= ~MLX5_RSS_HASH_IPV4;
12745 if (rss_types & ETH_RSS_L3_DST_ONLY)
12746 *hash_field |= IBV_RX_HASH_DST_IPV4;
12747 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
12748 *hash_field |= IBV_RX_HASH_SRC_IPV4;
12750 *hash_field |= MLX5_RSS_HASH_IPV4;
12753 case MLX5_RSS_HASH_IPV6:
12754 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
12755 *hash_field &= ~MLX5_RSS_HASH_IPV6;
12756 if (rss_types & ETH_RSS_L3_DST_ONLY)
12757 *hash_field |= IBV_RX_HASH_DST_IPV6;
12758 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
12759 *hash_field |= IBV_RX_HASH_SRC_IPV6;
12761 *hash_field |= MLX5_RSS_HASH_IPV6;
12764 case MLX5_RSS_HASH_IPV4_UDP:
12765 /* fall-through. */
12766 case MLX5_RSS_HASH_IPV6_UDP:
12767 if (rss_types & ETH_RSS_UDP) {
12768 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
12769 if (rss_types & ETH_RSS_L4_DST_ONLY)
12770 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
12771 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
12772 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
12774 *hash_field |= MLX5_UDP_IBV_RX_HASH;
12777 case MLX5_RSS_HASH_IPV4_TCP:
12778 /* fall-through. */
12779 case MLX5_RSS_HASH_IPV6_TCP:
12780 if (rss_types & ETH_RSS_TCP) {
12781 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
12782 if (rss_types & ETH_RSS_L4_DST_ONLY)
12783 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
12784 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
12785 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
12787 *hash_field |= MLX5_TCP_IBV_RX_HASH;
12796 * Setup shared RSS action.
12797 * Prepare set of hash RX queue objects sufficient to handle all valid
12798 * hash_fields combinations (see enum ibv_rx_hash_fields).
12801 * Pointer to the Ethernet device structure.
12802 * @param[in] action_idx
12803 * Shared RSS action ipool index.
12804 * @param[in, out] action
12805 * Partially initialized shared RSS action.
12806 * @param[out] error
12807 * Perform verbose error reporting if not NULL. Initialized in case of
12811 * 0 on success, otherwise negative errno value.
12814 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
12815 uint32_t action_idx,
12816 struct mlx5_shared_action_rss *shared_rss,
12817 struct rte_flow_error *error)
12819 struct mlx5_flow_rss_desc rss_desc = { 0 };
12823 if (mlx5_ind_table_obj_setup(dev, shared_rss->ind_tbl)) {
12824 return rte_flow_error_set(error, rte_errno,
12825 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12826 "cannot setup indirection table");
12828 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
12829 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
12830 rss_desc.const_q = shared_rss->origin.queue;
12831 rss_desc.queue_num = shared_rss->origin.queue_num;
12832 /* Set non-zero value to indicate a shared RSS. */
12833 rss_desc.shared_rss = action_idx;
12834 rss_desc.ind_tbl = shared_rss->ind_tbl;
12835 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
12837 uint64_t hash_fields = mlx5_rss_hash_fields[i];
12840 __flow_dv_action_rss_l34_hash_adjust(shared_rss, &hash_fields);
12841 if (shared_rss->origin.level > 1) {
12842 hash_fields |= IBV_RX_HASH_INNER;
12845 rss_desc.tunnel = tunnel;
12846 rss_desc.hash_fields = hash_fields;
12847 hrxq_idx = mlx5_hrxq_get(dev, &rss_desc);
12851 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12852 "cannot get hash queue");
12853 goto error_hrxq_new;
12855 err = __flow_dv_action_rss_hrxq_set
12856 (shared_rss, hash_fields, hrxq_idx);
12862 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
12863 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
12864 shared_rss->ind_tbl = NULL;
12870 * Create shared RSS action.
12873 * Pointer to the Ethernet device structure.
12875 * Shared action configuration.
12877 * RSS action specification used to create shared action.
12878 * @param[out] error
12879 * Perform verbose error reporting if not NULL. Initialized in case of
12883 * A valid shared action ID in case of success, 0 otherwise and
12884 * rte_errno is set.
12887 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
12888 const struct rte_flow_indir_action_conf *conf,
12889 const struct rte_flow_action_rss *rss,
12890 struct rte_flow_error *error)
12892 struct mlx5_priv *priv = dev->data->dev_private;
12893 struct mlx5_shared_action_rss *shared_rss = NULL;
12894 void *queue = NULL;
12895 struct rte_flow_action_rss *origin;
12896 const uint8_t *rss_key;
12897 uint32_t queue_size = rss->queue_num * sizeof(uint16_t);
12900 RTE_SET_USED(conf);
12901 queue = mlx5_malloc(0, RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
12903 shared_rss = mlx5_ipool_zmalloc
12904 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
12905 if (!shared_rss || !queue) {
12906 rte_flow_error_set(error, ENOMEM,
12907 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12908 "cannot allocate resource memory");
12909 goto error_rss_init;
12911 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
12912 rte_flow_error_set(error, E2BIG,
12913 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12914 "rss action number out of range");
12915 goto error_rss_init;
12917 shared_rss->ind_tbl = mlx5_malloc(MLX5_MEM_ZERO,
12918 sizeof(*shared_rss->ind_tbl),
12920 if (!shared_rss->ind_tbl) {
12921 rte_flow_error_set(error, ENOMEM,
12922 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12923 "cannot allocate resource memory");
12924 goto error_rss_init;
12926 memcpy(queue, rss->queue, queue_size);
12927 shared_rss->ind_tbl->queues = queue;
12928 shared_rss->ind_tbl->queues_n = rss->queue_num;
12929 origin = &shared_rss->origin;
12930 origin->func = rss->func;
12931 origin->level = rss->level;
12932 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
12933 origin->types = !rss->types ? ETH_RSS_IP : rss->types;
12934 /* NULL RSS key indicates default RSS key. */
12935 rss_key = !rss->key ? rss_hash_default_key : rss->key;
12936 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12937 origin->key = &shared_rss->key[0];
12938 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
12939 origin->queue = queue;
12940 origin->queue_num = rss->queue_num;
12941 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
12942 goto error_rss_init;
12943 rte_spinlock_init(&shared_rss->action_rss_sl);
12944 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
12945 rte_spinlock_lock(&priv->shared_act_sl);
12946 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
12947 &priv->rss_shared_actions, idx, shared_rss, next);
12948 rte_spinlock_unlock(&priv->shared_act_sl);
12952 if (shared_rss->ind_tbl)
12953 mlx5_free(shared_rss->ind_tbl);
12954 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
12963 * Destroy the shared RSS action.
12964 * Release related hash RX queue objects.
12967 * Pointer to the Ethernet device structure.
12969 * The shared RSS action object ID to be removed.
12970 * @param[out] error
12971 * Perform verbose error reporting if not NULL. Initialized in case of
12975 * 0 on success, otherwise negative errno value.
12978 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
12979 struct rte_flow_error *error)
12981 struct mlx5_priv *priv = dev->data->dev_private;
12982 struct mlx5_shared_action_rss *shared_rss =
12983 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
12984 uint32_t old_refcnt = 1;
12986 uint16_t *queue = NULL;
12989 return rte_flow_error_set(error, EINVAL,
12990 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12991 "invalid shared action");
12992 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
12994 return rte_flow_error_set(error, EBUSY,
12995 RTE_FLOW_ERROR_TYPE_ACTION,
12997 "shared rss hrxq has references");
12998 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
12999 0, 0, __ATOMIC_ACQUIRE,
13001 return rte_flow_error_set(error, EBUSY,
13002 RTE_FLOW_ERROR_TYPE_ACTION,
13004 "shared rss has references");
13005 queue = shared_rss->ind_tbl->queues;
13006 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true);
13008 return rte_flow_error_set(error, EBUSY,
13009 RTE_FLOW_ERROR_TYPE_ACTION,
13011 "shared rss indirection table has"
13014 rte_spinlock_lock(&priv->shared_act_sl);
13015 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
13016 &priv->rss_shared_actions, idx, shared_rss, next);
13017 rte_spinlock_unlock(&priv->shared_act_sl);
13018 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
13024 * Create indirect action, lock free,
13025 * (mutex should be acquired by caller).
13026 * Dispatcher for action type specific call.
13029 * Pointer to the Ethernet device structure.
13031 * Shared action configuration.
13032 * @param[in] action
13033 * Action specification used to create indirect action.
13034 * @param[out] error
13035 * Perform verbose error reporting if not NULL. Initialized in case of
13039 * A valid shared action handle in case of success, NULL otherwise and
13040 * rte_errno is set.
13042 static struct rte_flow_action_handle *
13043 flow_dv_action_create(struct rte_eth_dev *dev,
13044 const struct rte_flow_indir_action_conf *conf,
13045 const struct rte_flow_action *action,
13046 struct rte_flow_error *err)
13051 switch (action->type) {
13052 case RTE_FLOW_ACTION_TYPE_RSS:
13053 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
13054 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
13055 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
13057 case RTE_FLOW_ACTION_TYPE_AGE:
13058 ret = flow_dv_translate_create_aso_age(dev, action->conf, err);
13059 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
13060 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
13062 struct mlx5_aso_age_action *aso_age =
13063 flow_aso_age_get_by_idx(dev, ret);
13065 if (!aso_age->age_params.context)
13066 aso_age->age_params.context =
13067 (void *)(uintptr_t)idx;
13071 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
13072 NULL, "action type not supported");
13075 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
13079 * Destroy the indirect action.
13080 * Release action related resources on the NIC and the memory.
13081 * Lock free, (mutex should be acquired by caller).
13082 * Dispatcher for action type specific call.
13085 * Pointer to the Ethernet device structure.
13086 * @param[in] handle
13087 * The indirect action object handle to be removed.
13088 * @param[out] error
13089 * Perform verbose error reporting if not NULL. Initialized in case of
13093 * 0 on success, otherwise negative errno value.
13096 flow_dv_action_destroy(struct rte_eth_dev *dev,
13097 struct rte_flow_action_handle *handle,
13098 struct rte_flow_error *error)
13100 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
13101 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
13102 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
13106 case MLX5_INDIRECT_ACTION_TYPE_RSS:
13107 return __flow_dv_action_rss_release(dev, idx, error);
13108 case MLX5_INDIRECT_ACTION_TYPE_AGE:
13109 ret = flow_dv_aso_age_release(dev, idx);
13112 * In this case, the last flow has a reference will
13113 * actually release the age action.
13115 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
13116 " released with references %d.", idx, ret);
13119 return rte_flow_error_set(error, ENOTSUP,
13120 RTE_FLOW_ERROR_TYPE_ACTION,
13122 "action type not supported");
13127 * Updates in place shared RSS action configuration.
13130 * Pointer to the Ethernet device structure.
13132 * The shared RSS action object ID to be updated.
13133 * @param[in] action_conf
13134 * RSS action specification used to modify *shared_rss*.
13135 * @param[out] error
13136 * Perform verbose error reporting if not NULL. Initialized in case of
13140 * 0 on success, otherwise negative errno value.
13141 * @note: currently only support update of RSS queues.
13144 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
13145 const struct rte_flow_action_rss *action_conf,
13146 struct rte_flow_error *error)
13148 struct mlx5_priv *priv = dev->data->dev_private;
13149 struct mlx5_shared_action_rss *shared_rss =
13150 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
13152 void *queue = NULL;
13153 uint16_t *queue_old = NULL;
13154 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
13157 return rte_flow_error_set(error, EINVAL,
13158 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13159 "invalid shared action to update");
13160 if (priv->obj_ops.ind_table_modify == NULL)
13161 return rte_flow_error_set(error, ENOTSUP,
13162 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13163 "cannot modify indirection table");
13164 queue = mlx5_malloc(MLX5_MEM_ZERO,
13165 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
13168 return rte_flow_error_set(error, ENOMEM,
13169 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13171 "cannot allocate resource memory");
13172 memcpy(queue, action_conf->queue, queue_size);
13173 MLX5_ASSERT(shared_rss->ind_tbl);
13174 rte_spinlock_lock(&shared_rss->action_rss_sl);
13175 queue_old = shared_rss->ind_tbl->queues;
13176 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
13177 queue, action_conf->queue_num, true);
13180 ret = rte_flow_error_set(error, rte_errno,
13181 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13182 "cannot update indirection table");
13184 mlx5_free(queue_old);
13185 shared_rss->origin.queue = queue;
13186 shared_rss->origin.queue_num = action_conf->queue_num;
13188 rte_spinlock_unlock(&shared_rss->action_rss_sl);
13193 * Updates in place shared action configuration, lock free,
13194 * (mutex should be acquired by caller).
13197 * Pointer to the Ethernet device structure.
13198 * @param[in] handle
13199 * The indirect action object handle to be updated.
13200 * @param[in] update
13201 * Action specification used to modify the action pointed by *handle*.
13202 * *update* could be of same type with the action pointed by the *handle*
13203 * handle argument, or some other structures like a wrapper, depending on
13204 * the indirect action type.
13205 * @param[out] error
13206 * Perform verbose error reporting if not NULL. Initialized in case of
13210 * 0 on success, otherwise negative errno value.
13213 flow_dv_action_update(struct rte_eth_dev *dev,
13214 struct rte_flow_action_handle *handle,
13215 const void *update,
13216 struct rte_flow_error *err)
13218 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
13219 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
13220 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
13221 const void *action_conf;
13224 case MLX5_INDIRECT_ACTION_TYPE_RSS:
13225 action_conf = ((const struct rte_flow_action *)update)->conf;
13226 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
13228 return rte_flow_error_set(err, ENOTSUP,
13229 RTE_FLOW_ERROR_TYPE_ACTION,
13231 "action type update not supported");
13236 flow_dv_action_query(struct rte_eth_dev *dev,
13237 const struct rte_flow_action_handle *handle, void *data,
13238 struct rte_flow_error *error)
13240 struct mlx5_age_param *age_param;
13241 struct rte_flow_query_age *resp;
13242 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
13243 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
13244 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
13247 case MLX5_INDIRECT_ACTION_TYPE_AGE:
13248 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
13250 resp->aged = __atomic_load_n(&age_param->state,
13251 __ATOMIC_RELAXED) == AGE_TMOUT ?
13253 resp->sec_since_last_hit_valid = !resp->aged;
13254 if (resp->sec_since_last_hit_valid)
13255 resp->sec_since_last_hit = __atomic_load_n
13256 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
13259 return rte_flow_error_set(error, ENOTSUP,
13260 RTE_FLOW_ERROR_TYPE_ACTION,
13262 "action type query not supported");
13267 * Query a dv flow rule for its statistics via devx.
13270 * Pointer to Ethernet device.
13272 * Pointer to the sub flow.
13274 * data retrieved by the query.
13275 * @param[out] error
13276 * Perform verbose error reporting if not NULL.
13279 * 0 on success, a negative errno value otherwise and rte_errno is set.
13282 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
13283 void *data, struct rte_flow_error *error)
13285 struct mlx5_priv *priv = dev->data->dev_private;
13286 struct rte_flow_query_count *qc = data;
13288 if (!priv->config.devx)
13289 return rte_flow_error_set(error, ENOTSUP,
13290 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13292 "counters are not supported");
13293 if (flow->counter) {
13294 uint64_t pkts, bytes;
13295 struct mlx5_flow_counter *cnt;
13297 cnt = flow_dv_counter_get_by_idx(dev, flow->counter,
13299 int err = _flow_dv_query_count(dev, flow->counter, &pkts,
13303 return rte_flow_error_set(error, -err,
13304 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13305 NULL, "cannot read counters");
13308 qc->hits = pkts - cnt->hits;
13309 qc->bytes = bytes - cnt->bytes;
13312 cnt->bytes = bytes;
13316 return rte_flow_error_set(error, EINVAL,
13317 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13319 "counters are not available");
13323 * Query a flow rule AGE action for aging information.
13326 * Pointer to Ethernet device.
13328 * Pointer to the sub flow.
13330 * data retrieved by the query.
13331 * @param[out] error
13332 * Perform verbose error reporting if not NULL.
13335 * 0 on success, a negative errno value otherwise and rte_errno is set.
13338 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
13339 void *data, struct rte_flow_error *error)
13341 struct rte_flow_query_age *resp = data;
13342 struct mlx5_age_param *age_param;
13345 struct mlx5_aso_age_action *act =
13346 flow_aso_age_get_by_idx(dev, flow->age);
13348 age_param = &act->age_params;
13349 } else if (flow->counter) {
13350 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
13352 if (!age_param || !age_param->timeout)
13353 return rte_flow_error_set
13355 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13356 NULL, "cannot read age data");
13358 return rte_flow_error_set(error, EINVAL,
13359 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13360 NULL, "age data not available");
13362 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
13364 resp->sec_since_last_hit_valid = !resp->aged;
13365 if (resp->sec_since_last_hit_valid)
13366 resp->sec_since_last_hit = __atomic_load_n
13367 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
13374 * @see rte_flow_query()
13375 * @see rte_flow_ops
13378 flow_dv_query(struct rte_eth_dev *dev,
13379 struct rte_flow *flow __rte_unused,
13380 const struct rte_flow_action *actions __rte_unused,
13381 void *data __rte_unused,
13382 struct rte_flow_error *error __rte_unused)
13386 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
13387 switch (actions->type) {
13388 case RTE_FLOW_ACTION_TYPE_VOID:
13390 case RTE_FLOW_ACTION_TYPE_COUNT:
13391 ret = flow_dv_query_count(dev, flow, data, error);
13393 case RTE_FLOW_ACTION_TYPE_AGE:
13394 ret = flow_dv_query_age(dev, flow, data, error);
13397 return rte_flow_error_set(error, ENOTSUP,
13398 RTE_FLOW_ERROR_TYPE_ACTION,
13400 "action not supported");
13407 * Destroy the meter table set.
13408 * Lock free, (mutex should be acquired by caller).
13411 * Pointer to Ethernet device.
13413 * Pointer to the meter table set.
13419 flow_dv_destroy_mtr_tbl(struct rte_eth_dev *dev,
13420 struct mlx5_meter_domains_infos *tbl)
13422 struct mlx5_priv *priv = dev->data->dev_private;
13423 struct mlx5_meter_domains_infos *mtd =
13424 (struct mlx5_meter_domains_infos *)tbl;
13426 if (!mtd || !priv->config.dv_flow_en)
13428 if (mtd->ingress.policer_rules[RTE_MTR_DROPPED])
13429 claim_zero(mlx5_flow_os_destroy_flow
13430 (mtd->ingress.policer_rules[RTE_MTR_DROPPED]));
13431 if (mtd->egress.policer_rules[RTE_MTR_DROPPED])
13432 claim_zero(mlx5_flow_os_destroy_flow
13433 (mtd->egress.policer_rules[RTE_MTR_DROPPED]));
13434 if (mtd->transfer.policer_rules[RTE_MTR_DROPPED])
13435 claim_zero(mlx5_flow_os_destroy_flow
13436 (mtd->transfer.policer_rules[RTE_MTR_DROPPED]));
13437 if (mtd->egress.color_matcher)
13438 claim_zero(mlx5_flow_os_destroy_flow_matcher
13439 (mtd->egress.color_matcher));
13440 if (mtd->egress.any_matcher)
13441 claim_zero(mlx5_flow_os_destroy_flow_matcher
13442 (mtd->egress.any_matcher));
13443 if (mtd->egress.tbl)
13444 flow_dv_tbl_resource_release(MLX5_SH(dev), mtd->egress.tbl);
13445 if (mtd->egress.sfx_tbl)
13446 flow_dv_tbl_resource_release(MLX5_SH(dev), mtd->egress.sfx_tbl);
13447 if (mtd->ingress.color_matcher)
13448 claim_zero(mlx5_flow_os_destroy_flow_matcher
13449 (mtd->ingress.color_matcher));
13450 if (mtd->ingress.any_matcher)
13451 claim_zero(mlx5_flow_os_destroy_flow_matcher
13452 (mtd->ingress.any_matcher));
13453 if (mtd->ingress.tbl)
13454 flow_dv_tbl_resource_release(MLX5_SH(dev), mtd->ingress.tbl);
13455 if (mtd->ingress.sfx_tbl)
13456 flow_dv_tbl_resource_release(MLX5_SH(dev),
13457 mtd->ingress.sfx_tbl);
13458 if (mtd->transfer.color_matcher)
13459 claim_zero(mlx5_flow_os_destroy_flow_matcher
13460 (mtd->transfer.color_matcher));
13461 if (mtd->transfer.any_matcher)
13462 claim_zero(mlx5_flow_os_destroy_flow_matcher
13463 (mtd->transfer.any_matcher));
13464 if (mtd->transfer.tbl)
13465 flow_dv_tbl_resource_release(MLX5_SH(dev), mtd->transfer.tbl);
13466 if (mtd->transfer.sfx_tbl)
13467 flow_dv_tbl_resource_release(MLX5_SH(dev),
13468 mtd->transfer.sfx_tbl);
13469 if (mtd->drop_actn)
13470 claim_zero(mlx5_flow_os_destroy_flow_action(mtd->drop_actn));
13475 /* Number of meter flow actions, count and jump or count and drop. */
13476 #define METER_ACTIONS 2
13479 * Create specify domain meter table and suffix table.
13482 * Pointer to Ethernet device.
13483 * @param[in,out] mtb
13484 * Pointer to DV meter table set.
13485 * @param[in] egress
13487 * @param[in] transfer
13489 * @param[in] color_reg_c_idx
13490 * Reg C index for color match.
13493 * 0 on success, -1 otherwise and rte_errno is set.
13496 flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
13497 struct mlx5_meter_domains_infos *mtb,
13498 uint8_t egress, uint8_t transfer,
13499 uint32_t color_reg_c_idx)
13501 struct mlx5_priv *priv = dev->data->dev_private;
13502 struct mlx5_dev_ctx_shared *sh = priv->sh;
13503 struct mlx5_flow_dv_match_params mask = {
13504 .size = sizeof(mask.buf),
13506 struct mlx5_flow_dv_match_params value = {
13507 .size = sizeof(value.buf),
13509 struct mlx5dv_flow_matcher_attr dv_attr = {
13510 .type = IBV_FLOW_ATTR_NORMAL,
13512 .match_criteria_enable = 0,
13513 .match_mask = (void *)&mask,
13515 void *actions[METER_ACTIONS];
13516 struct mlx5_meter_domain_info *dtb;
13517 struct rte_flow_error error;
13522 dtb = &mtb->transfer;
13524 dtb = &mtb->egress;
13526 dtb = &mtb->ingress;
13527 /* Create the meter table with METER level. */
13528 dtb->tbl = flow_dv_tbl_resource_get(dev, MLX5_FLOW_TABLE_LEVEL_METER,
13529 egress, transfer, false, NULL, 0,
13532 DRV_LOG(ERR, "Failed to create meter policer table.");
13535 /* Create the meter suffix table with SUFFIX level. */
13536 dtb->sfx_tbl = flow_dv_tbl_resource_get(dev,
13537 MLX5_FLOW_TABLE_LEVEL_SUFFIX,
13538 egress, transfer, false, NULL, 0,
13540 if (!dtb->sfx_tbl) {
13541 DRV_LOG(ERR, "Failed to create meter suffix table.");
13544 /* Create matchers, Any and Color. */
13545 dv_attr.priority = 3;
13546 dv_attr.match_criteria_enable = 0;
13547 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, dtb->tbl->obj,
13548 &dtb->any_matcher);
13550 DRV_LOG(ERR, "Failed to create meter"
13551 " policer default matcher.");
13554 dv_attr.priority = 0;
13555 dv_attr.match_criteria_enable =
13556 1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
13557 flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
13558 rte_col_2_mlx5_col(RTE_COLORS), UINT8_MAX);
13559 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, dtb->tbl->obj,
13560 &dtb->color_matcher);
13562 DRV_LOG(ERR, "Failed to create meter policer color matcher.");
13565 if (mtb->count_actns[RTE_MTR_DROPPED])
13566 actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
13567 actions[i++] = mtb->drop_actn;
13568 /* Default rule: lowest priority, match any, actions: drop. */
13569 ret = mlx5_flow_os_create_flow(dtb->any_matcher, (void *)&value, i,
13571 &dtb->policer_rules[RTE_MTR_DROPPED]);
13573 DRV_LOG(ERR, "Failed to create meter policer drop rule.");
13582 * Create the needed meter and suffix tables.
13583 * Lock free, (mutex should be acquired by caller).
13586 * Pointer to Ethernet device.
13588 * Pointer to the flow meter.
13591 * Pointer to table set on success, NULL otherwise and rte_errno is set.
13593 static struct mlx5_meter_domains_infos *
13594 flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
13595 const struct mlx5_flow_meter *fm)
13597 struct mlx5_priv *priv = dev->data->dev_private;
13598 struct mlx5_meter_domains_infos *mtb;
13602 if (!priv->mtr_en) {
13603 rte_errno = ENOTSUP;
13606 mtb = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*mtb), 0, SOCKET_ID_ANY);
13608 DRV_LOG(ERR, "Failed to allocate memory for meter.");
13611 /* Create meter count actions */
13612 for (i = 0; i <= RTE_MTR_DROPPED; i++) {
13613 struct mlx5_flow_counter *cnt;
13614 if (!fm->policer_stats.cnt[i])
13616 cnt = flow_dv_counter_get_by_idx(dev,
13617 fm->policer_stats.cnt[i], NULL);
13618 mtb->count_actns[i] = cnt->action;
13620 /* Create drop action. */
13621 ret = mlx5_flow_os_create_flow_action_drop(&mtb->drop_actn);
13623 DRV_LOG(ERR, "Failed to create drop action.");
13626 /* Egress meter table. */
13627 ret = flow_dv_prepare_mtr_tables(dev, mtb, 1, 0, priv->mtr_color_reg);
13629 DRV_LOG(ERR, "Failed to prepare egress meter table.");
13632 /* Ingress meter table. */
13633 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 0, priv->mtr_color_reg);
13635 DRV_LOG(ERR, "Failed to prepare ingress meter table.");
13638 /* FDB meter table. */
13639 if (priv->config.dv_esw_en) {
13640 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 1,
13641 priv->mtr_color_reg);
13643 DRV_LOG(ERR, "Failed to prepare fdb meter table.");
13649 flow_dv_destroy_mtr_tbl(dev, mtb);
13654 * Destroy domain policer rule.
13657 * Pointer to domain table.
13660 flow_dv_destroy_domain_policer_rule(struct mlx5_meter_domain_info *dt)
13664 for (i = 0; i < RTE_MTR_DROPPED; i++) {
13665 if (dt->policer_rules[i]) {
13666 claim_zero(mlx5_flow_os_destroy_flow
13667 (dt->policer_rules[i]));
13668 dt->policer_rules[i] = NULL;
13671 if (dt->jump_actn) {
13672 claim_zero(mlx5_flow_os_destroy_flow_action(dt->jump_actn));
13673 dt->jump_actn = NULL;
13678 * Destroy policer rules.
13681 * Pointer to Ethernet device.
13683 * Pointer to flow meter structure.
13685 * Pointer to flow attributes.
13691 flow_dv_destroy_policer_rules(struct rte_eth_dev *dev __rte_unused,
13692 const struct mlx5_flow_meter *fm,
13693 const struct rte_flow_attr *attr)
13695 struct mlx5_meter_domains_infos *mtb = fm ? fm->mfts : NULL;
13700 flow_dv_destroy_domain_policer_rule(&mtb->egress);
13702 flow_dv_destroy_domain_policer_rule(&mtb->ingress);
13703 if (attr->transfer)
13704 flow_dv_destroy_domain_policer_rule(&mtb->transfer);
13709 * Create specify domain meter policer rule.
13712 * Pointer to flow meter structure.
13714 * Pointer to DV meter table set.
13715 * @param[in] mtr_reg_c
13716 * Color match REG_C.
13719 * 0 on success, -1 otherwise.
13722 flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
13723 struct mlx5_meter_domain_info *dtb,
13726 struct mlx5_flow_dv_match_params matcher = {
13727 .size = sizeof(matcher.buf),
13729 struct mlx5_flow_dv_match_params value = {
13730 .size = sizeof(value.buf),
13732 struct mlx5_meter_domains_infos *mtb = fm->mfts;
13733 void *actions[METER_ACTIONS];
13737 /* Create jump action. */
13738 if (!dtb->jump_actn)
13739 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
13740 (dtb->sfx_tbl->obj, &dtb->jump_actn);
13742 DRV_LOG(ERR, "Failed to create policer jump action.");
13745 for (i = 0; i < RTE_MTR_DROPPED; i++) {
13748 flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
13749 rte_col_2_mlx5_col(i), UINT8_MAX);
13750 if (mtb->count_actns[i])
13751 actions[j++] = mtb->count_actns[i];
13752 if (fm->action[i] == MTR_POLICER_ACTION_DROP)
13753 actions[j++] = mtb->drop_actn;
13755 actions[j++] = dtb->jump_actn;
13756 ret = mlx5_flow_os_create_flow(dtb->color_matcher,
13757 (void *)&value, j, actions,
13758 &dtb->policer_rules[i]);
13760 DRV_LOG(ERR, "Failed to create policer rule.");
13771 * Create policer rules.
13774 * Pointer to Ethernet device.
13776 * Pointer to flow meter structure.
13778 * Pointer to flow attributes.
13781 * 0 on success, -1 otherwise.
13784 flow_dv_create_policer_rules(struct rte_eth_dev *dev,
13785 struct mlx5_flow_meter *fm,
13786 const struct rte_flow_attr *attr)
13788 struct mlx5_priv *priv = dev->data->dev_private;
13789 struct mlx5_meter_domains_infos *mtb = fm->mfts;
13792 if (attr->egress) {
13793 ret = flow_dv_create_policer_forward_rule(fm, &mtb->egress,
13794 priv->mtr_color_reg);
13796 DRV_LOG(ERR, "Failed to create egress policer.");
13800 if (attr->ingress) {
13801 ret = flow_dv_create_policer_forward_rule(fm, &mtb->ingress,
13802 priv->mtr_color_reg);
13804 DRV_LOG(ERR, "Failed to create ingress policer.");
13808 if (attr->transfer) {
13809 ret = flow_dv_create_policer_forward_rule(fm, &mtb->transfer,
13810 priv->mtr_color_reg);
13812 DRV_LOG(ERR, "Failed to create transfer policer.");
13818 flow_dv_destroy_policer_rules(dev, fm, attr);
13823 * Validate the batch counter support in root table.
13825 * Create a simple flow with invalid counter and drop action on root table to
13826 * validate if batch counter with offset on root table is supported or not.
13829 * Pointer to rte_eth_dev structure.
13832 * 0 on success, a negative errno value otherwise and rte_errno is set.
13835 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
13837 struct mlx5_priv *priv = dev->data->dev_private;
13838 struct mlx5_dev_ctx_shared *sh = priv->sh;
13839 struct mlx5_flow_dv_match_params mask = {
13840 .size = sizeof(mask.buf),
13842 struct mlx5_flow_dv_match_params value = {
13843 .size = sizeof(value.buf),
13845 struct mlx5dv_flow_matcher_attr dv_attr = {
13846 .type = IBV_FLOW_ATTR_NORMAL,
13848 .match_criteria_enable = 0,
13849 .match_mask = (void *)&mask,
13851 void *actions[2] = { 0 };
13852 struct mlx5_flow_tbl_resource *tbl = NULL;
13853 struct mlx5_devx_obj *dcs = NULL;
13854 void *matcher = NULL;
13858 tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL, 0, 0, NULL);
13861 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
13864 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
13868 actions[1] = sh->dr_drop_action ? sh->dr_drop_action :
13869 priv->drop_queue.hrxq->action;
13870 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
13871 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
13875 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 2,
13879 * If batch counter with offset is not supported, the driver will not
13880 * validate the invalid offset value, flow create should success.
13881 * In this case, it means batch counter is not supported in root table.
13883 * Otherwise, if flow create is failed, counter offset is supported.
13886 DRV_LOG(INFO, "Batch counter is not supported in root "
13887 "table. Switch to fallback mode.");
13888 rte_errno = ENOTSUP;
13890 claim_zero(mlx5_flow_os_destroy_flow(flow));
13892 /* Check matcher to make sure validate fail at flow create. */
13893 if (!matcher || (matcher && errno != EINVAL))
13894 DRV_LOG(ERR, "Unexpected error in counter offset "
13895 "support detection");
13899 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
13901 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
13903 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
13905 claim_zero(mlx5_devx_cmd_destroy(dcs));
13910 * Query a devx counter.
13913 * Pointer to the Ethernet device structure.
13915 * Index to the flow counter.
13917 * Set to clear the counter statistics.
13919 * The statistics value of packets.
13920 * @param[out] bytes
13921 * The statistics value of bytes.
13924 * 0 on success, otherwise return -1.
13927 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
13928 uint64_t *pkts, uint64_t *bytes)
13930 struct mlx5_priv *priv = dev->data->dev_private;
13931 struct mlx5_flow_counter *cnt;
13932 uint64_t inn_pkts, inn_bytes;
13935 if (!priv->config.devx)
13938 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
13941 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
13942 *pkts = inn_pkts - cnt->hits;
13943 *bytes = inn_bytes - cnt->bytes;
13945 cnt->hits = inn_pkts;
13946 cnt->bytes = inn_bytes;
13952 * Get aged-out flows.
13955 * Pointer to the Ethernet device structure.
13956 * @param[in] context
13957 * The address of an array of pointers to the aged-out flows contexts.
13958 * @param[in] nb_contexts
13959 * The length of context array pointers.
13960 * @param[out] error
13961 * Perform verbose error reporting if not NULL. Initialized in case of
13965 * how many contexts get in success, otherwise negative errno value.
13966 * if nb_contexts is 0, return the amount of all aged contexts.
13967 * if nb_contexts is not 0 , return the amount of aged flows reported
13968 * in the context array.
13969 * @note: only stub for now
13972 flow_get_aged_flows(struct rte_eth_dev *dev,
13974 uint32_t nb_contexts,
13975 struct rte_flow_error *error)
13977 struct mlx5_priv *priv = dev->data->dev_private;
13978 struct mlx5_age_info *age_info;
13979 struct mlx5_age_param *age_param;
13980 struct mlx5_flow_counter *counter;
13981 struct mlx5_aso_age_action *act;
13984 if (nb_contexts && !context)
13985 return rte_flow_error_set(error, EINVAL,
13986 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13987 NULL, "empty context");
13988 age_info = GET_PORT_AGE_INFO(priv);
13989 rte_spinlock_lock(&age_info->aged_sl);
13990 LIST_FOREACH(act, &age_info->aged_aso, next) {
13993 context[nb_flows - 1] =
13994 act->age_params.context;
13995 if (!(--nb_contexts))
13999 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
14002 age_param = MLX5_CNT_TO_AGE(counter);
14003 context[nb_flows - 1] = age_param->context;
14004 if (!(--nb_contexts))
14008 rte_spinlock_unlock(&age_info->aged_sl);
14009 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
14014 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
14017 flow_dv_counter_allocate(struct rte_eth_dev *dev)
14019 return flow_dv_counter_alloc(dev, 0);
14023 * Validate indirect action.
14024 * Dispatcher for action type specific validation.
14027 * Pointer to the Ethernet device structure.
14029 * Shared action configuration.
14030 * @param[in] action
14031 * The indirect action object to validate.
14032 * @param[out] error
14033 * Perform verbose error reporting if not NULL. Initialized in case of
14037 * 0 on success, otherwise negative errno value.
14040 flow_dv_action_validate(struct rte_eth_dev *dev,
14041 const struct rte_flow_indir_action_conf *conf,
14042 const struct rte_flow_action *action,
14043 struct rte_flow_error *err)
14045 struct mlx5_priv *priv = dev->data->dev_private;
14047 RTE_SET_USED(conf);
14048 switch (action->type) {
14049 case RTE_FLOW_ACTION_TYPE_RSS:
14051 * priv->obj_ops is set according to driver capabilities.
14052 * When DevX capabilities are
14053 * sufficient, it is set to devx_obj_ops.
14054 * Otherwise, it is set to ibv_obj_ops.
14055 * ibv_obj_ops doesn't support ind_table_modify operation.
14056 * In this case the shared RSS action can't be used.
14058 if (priv->obj_ops.ind_table_modify == NULL)
14059 return rte_flow_error_set
14061 RTE_FLOW_ERROR_TYPE_ACTION,
14063 "shared RSS action not supported");
14064 return mlx5_validate_action_rss(dev, action, err);
14065 case RTE_FLOW_ACTION_TYPE_AGE:
14066 if (!priv->sh->aso_age_mng)
14067 return rte_flow_error_set(err, ENOTSUP,
14068 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14070 "shared age action not supported");
14071 return flow_dv_validate_action_age(0, action, dev, err);
14073 return rte_flow_error_set(err, ENOTSUP,
14074 RTE_FLOW_ERROR_TYPE_ACTION,
14076 "action type not supported");
14081 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
14083 struct mlx5_priv *priv = dev->data->dev_private;
14086 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
14087 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
14092 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
14093 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
14097 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
14098 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
14105 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
14106 .validate = flow_dv_validate,
14107 .prepare = flow_dv_prepare,
14108 .translate = flow_dv_translate,
14109 .apply = flow_dv_apply,
14110 .remove = flow_dv_remove,
14111 .destroy = flow_dv_destroy,
14112 .query = flow_dv_query,
14113 .create_mtr_tbls = flow_dv_create_mtr_tbl,
14114 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbl,
14115 .create_policer_rules = flow_dv_create_policer_rules,
14116 .destroy_policer_rules = flow_dv_destroy_policer_rules,
14117 .counter_alloc = flow_dv_counter_allocate,
14118 .counter_free = flow_dv_counter_free,
14119 .counter_query = flow_dv_counter_query,
14120 .get_aged_flows = flow_get_aged_flows,
14121 .action_validate = flow_dv_action_validate,
14122 .action_create = flow_dv_action_create,
14123 .action_destroy = flow_dv_action_destroy,
14124 .action_update = flow_dv_action_update,
14125 .action_query = flow_dv_action_query,
14126 .sync_domain = flow_dv_sync_domain,
14129 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */