1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd
12 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
14 #pragma GCC diagnostic ignored "-Wpedantic"
16 #include <infiniband/verbs.h>
18 #pragma GCC diagnostic error "-Wpedantic"
21 #include <rte_common.h>
22 #include <rte_ether.h>
23 #include <rte_ethdev_driver.h>
25 #include <rte_flow_driver.h>
26 #include <rte_malloc.h>
27 #include <rte_cycles.h>
30 #include <rte_vxlan.h>
33 #include <mlx5_glue.h>
34 #include <mlx5_devx_cmds.h>
37 #include "mlx5_defs.h"
39 #include "mlx5_common_os.h"
40 #include "mlx5_flow.h"
41 #include "mlx5_rxtx.h"
43 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
45 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
46 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
49 #ifndef HAVE_MLX5DV_DR_ESWITCH
50 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
51 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
55 #ifndef HAVE_MLX5DV_DR
56 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
59 /* VLAN header definitions */
60 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
61 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
62 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
63 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
64 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
79 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
80 struct mlx5_flow_tbl_resource *tbl);
83 * Initialize flow attributes structure according to flow items' types.
85 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
86 * mode. For tunnel mode, the items to be modified are the outermost ones.
89 * Pointer to item specification.
91 * Pointer to flow attributes structure.
93 * Pointer to the sub flow.
94 * @param[in] tunnel_decap
95 * Whether action is after tunnel decapsulation.
98 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
99 struct mlx5_flow *dev_flow, bool tunnel_decap)
101 uint64_t layers = dev_flow->handle->layers;
104 * If layers is already initialized, it means this dev_flow is the
105 * suffix flow, the layers flags is set by the prefix flow. Need to
106 * use the layer flags from prefix flow as the suffix flow may not
107 * have the user defined items as the flow is split.
110 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
112 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
114 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
116 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
121 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
122 uint8_t next_protocol = 0xff;
123 switch (item->type) {
124 case RTE_FLOW_ITEM_TYPE_GRE:
125 case RTE_FLOW_ITEM_TYPE_NVGRE:
126 case RTE_FLOW_ITEM_TYPE_VXLAN:
127 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
128 case RTE_FLOW_ITEM_TYPE_GENEVE:
129 case RTE_FLOW_ITEM_TYPE_MPLS:
133 case RTE_FLOW_ITEM_TYPE_IPV4:
136 if (item->mask != NULL &&
137 ((const struct rte_flow_item_ipv4 *)
138 item->mask)->hdr.next_proto_id)
140 ((const struct rte_flow_item_ipv4 *)
141 (item->spec))->hdr.next_proto_id &
142 ((const struct rte_flow_item_ipv4 *)
143 (item->mask))->hdr.next_proto_id;
144 if ((next_protocol == IPPROTO_IPIP ||
145 next_protocol == IPPROTO_IPV6) && tunnel_decap)
148 case RTE_FLOW_ITEM_TYPE_IPV6:
151 if (item->mask != NULL &&
152 ((const struct rte_flow_item_ipv6 *)
153 item->mask)->hdr.proto)
155 ((const struct rte_flow_item_ipv6 *)
156 (item->spec))->hdr.proto &
157 ((const struct rte_flow_item_ipv6 *)
158 (item->mask))->hdr.proto;
159 if ((next_protocol == IPPROTO_IPIP ||
160 next_protocol == IPPROTO_IPV6) && tunnel_decap)
163 case RTE_FLOW_ITEM_TYPE_UDP:
167 case RTE_FLOW_ITEM_TYPE_TCP:
179 * Convert rte_mtr_color to mlx5 color.
188 rte_col_2_mlx5_col(enum rte_color rcol)
191 case RTE_COLOR_GREEN:
192 return MLX5_FLOW_COLOR_GREEN;
193 case RTE_COLOR_YELLOW:
194 return MLX5_FLOW_COLOR_YELLOW;
196 return MLX5_FLOW_COLOR_RED;
200 return MLX5_FLOW_COLOR_UNDEFINED;
203 struct field_modify_info {
204 uint32_t size; /* Size of field in protocol header, in bytes. */
205 uint32_t offset; /* Offset of field in protocol header, in bytes. */
206 enum mlx5_modification_field id;
209 struct field_modify_info modify_eth[] = {
210 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
211 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
212 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
213 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
217 struct field_modify_info modify_vlan_out_first_vid[] = {
218 /* Size in bits !!! */
219 {12, 0, MLX5_MODI_OUT_FIRST_VID},
223 struct field_modify_info modify_ipv4[] = {
224 {1, 1, MLX5_MODI_OUT_IP_DSCP},
225 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
226 {4, 12, MLX5_MODI_OUT_SIPV4},
227 {4, 16, MLX5_MODI_OUT_DIPV4},
231 struct field_modify_info modify_ipv6[] = {
232 {1, 0, MLX5_MODI_OUT_IP_DSCP},
233 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
234 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
235 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
236 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
237 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
238 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
239 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
240 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
241 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
245 struct field_modify_info modify_udp[] = {
246 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
247 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
251 struct field_modify_info modify_tcp[] = {
252 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
253 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
254 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
255 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
260 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
261 uint8_t next_protocol, uint64_t *item_flags,
264 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
265 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
266 if (next_protocol == IPPROTO_IPIP) {
267 *item_flags |= MLX5_FLOW_LAYER_IPIP;
270 if (next_protocol == IPPROTO_IPV6) {
271 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
277 * Acquire the synchronizing object to protect multithreaded access
278 * to shared dv context. Lock occurs only if context is actually
279 * shared, i.e. we have multiport IB device and representors are
283 * Pointer to the rte_eth_dev structure.
286 flow_dv_shared_lock(struct rte_eth_dev *dev)
288 struct mlx5_priv *priv = dev->data->dev_private;
289 struct mlx5_dev_ctx_shared *sh = priv->sh;
291 if (sh->dv_refcnt > 1) {
294 ret = pthread_mutex_lock(&sh->dv_mutex);
301 flow_dv_shared_unlock(struct rte_eth_dev *dev)
303 struct mlx5_priv *priv = dev->data->dev_private;
304 struct mlx5_dev_ctx_shared *sh = priv->sh;
306 if (sh->dv_refcnt > 1) {
309 ret = pthread_mutex_unlock(&sh->dv_mutex);
315 /* Update VLAN's VID/PCP based on input rte_flow_action.
318 * Pointer to struct rte_flow_action.
320 * Pointer to struct rte_vlan_hdr.
323 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
324 struct rte_vlan_hdr *vlan)
327 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
329 ((const struct rte_flow_action_of_set_vlan_pcp *)
330 action->conf)->vlan_pcp;
331 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
332 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
333 vlan->vlan_tci |= vlan_tci;
334 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
335 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
336 vlan->vlan_tci |= rte_be_to_cpu_16
337 (((const struct rte_flow_action_of_set_vlan_vid *)
338 action->conf)->vlan_vid);
343 * Fetch 1, 2, 3 or 4 byte field from the byte array
344 * and return as unsigned integer in host-endian format.
347 * Pointer to data array.
349 * Size of field to extract.
352 * converted field in host endian format.
354 static inline uint32_t
355 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
364 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
367 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
368 ret = (ret << 8) | *(data + sizeof(uint16_t));
371 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
382 * Convert modify-header action to DV specification.
384 * Data length of each action is determined by provided field description
385 * and the item mask. Data bit offset and width of each action is determined
386 * by provided item mask.
389 * Pointer to item specification.
391 * Pointer to field modification information.
392 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
393 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
394 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
396 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
397 * Negative offset value sets the same offset as source offset.
398 * size field is ignored, value is taken from source field.
399 * @param[in,out] resource
400 * Pointer to the modify-header resource.
402 * Type of modification.
404 * Pointer to the error structure.
407 * 0 on success, a negative errno value otherwise and rte_errno is set.
410 flow_dv_convert_modify_action(struct rte_flow_item *item,
411 struct field_modify_info *field,
412 struct field_modify_info *dcopy,
413 struct mlx5_flow_dv_modify_hdr_resource *resource,
414 uint32_t type, struct rte_flow_error *error)
416 uint32_t i = resource->actions_num;
417 struct mlx5_modification_cmd *actions = resource->actions;
420 * The item and mask are provided in big-endian format.
421 * The fields should be presented as in big-endian format either.
422 * Mask must be always present, it defines the actual field width.
424 MLX5_ASSERT(item->mask);
425 MLX5_ASSERT(field->size);
432 if (i >= MLX5_MAX_MODIFY_NUM)
433 return rte_flow_error_set(error, EINVAL,
434 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
435 "too many items to modify");
436 /* Fetch variable byte size mask from the array. */
437 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
438 field->offset, field->size);
443 /* Deduce actual data width in bits from mask value. */
444 off_b = rte_bsf32(mask);
445 size_b = sizeof(uint32_t) * CHAR_BIT -
446 off_b - __builtin_clz(mask);
448 size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
449 actions[i] = (struct mlx5_modification_cmd) {
455 /* Convert entire record to expected big-endian format. */
456 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
457 if (type == MLX5_MODIFICATION_TYPE_COPY) {
459 actions[i].dst_field = dcopy->id;
460 actions[i].dst_offset =
461 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
462 /* Convert entire record to big-endian format. */
463 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
465 MLX5_ASSERT(item->spec);
466 data = flow_dv_fetch_field((const uint8_t *)item->spec +
467 field->offset, field->size);
468 /* Shift out the trailing masked bits from data. */
469 data = (data & mask) >> off_b;
470 actions[i].data1 = rte_cpu_to_be_32(data);
474 } while (field->size);
475 if (resource->actions_num == i)
476 return rte_flow_error_set(error, EINVAL,
477 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
478 "invalid modification flow item");
479 resource->actions_num = i;
484 * Convert modify-header set IPv4 address action to DV specification.
486 * @param[in,out] resource
487 * Pointer to the modify-header resource.
489 * Pointer to action specification.
491 * Pointer to the error structure.
494 * 0 on success, a negative errno value otherwise and rte_errno is set.
497 flow_dv_convert_action_modify_ipv4
498 (struct mlx5_flow_dv_modify_hdr_resource *resource,
499 const struct rte_flow_action *action,
500 struct rte_flow_error *error)
502 const struct rte_flow_action_set_ipv4 *conf =
503 (const struct rte_flow_action_set_ipv4 *)(action->conf);
504 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
505 struct rte_flow_item_ipv4 ipv4;
506 struct rte_flow_item_ipv4 ipv4_mask;
508 memset(&ipv4, 0, sizeof(ipv4));
509 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
510 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
511 ipv4.hdr.src_addr = conf->ipv4_addr;
512 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
514 ipv4.hdr.dst_addr = conf->ipv4_addr;
515 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
518 item.mask = &ipv4_mask;
519 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
520 MLX5_MODIFICATION_TYPE_SET, error);
524 * Convert modify-header set IPv6 address action to DV specification.
526 * @param[in,out] resource
527 * Pointer to the modify-header resource.
529 * Pointer to action specification.
531 * Pointer to the error structure.
534 * 0 on success, a negative errno value otherwise and rte_errno is set.
537 flow_dv_convert_action_modify_ipv6
538 (struct mlx5_flow_dv_modify_hdr_resource *resource,
539 const struct rte_flow_action *action,
540 struct rte_flow_error *error)
542 const struct rte_flow_action_set_ipv6 *conf =
543 (const struct rte_flow_action_set_ipv6 *)(action->conf);
544 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
545 struct rte_flow_item_ipv6 ipv6;
546 struct rte_flow_item_ipv6 ipv6_mask;
548 memset(&ipv6, 0, sizeof(ipv6));
549 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
550 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
551 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
552 sizeof(ipv6.hdr.src_addr));
553 memcpy(&ipv6_mask.hdr.src_addr,
554 &rte_flow_item_ipv6_mask.hdr.src_addr,
555 sizeof(ipv6.hdr.src_addr));
557 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
558 sizeof(ipv6.hdr.dst_addr));
559 memcpy(&ipv6_mask.hdr.dst_addr,
560 &rte_flow_item_ipv6_mask.hdr.dst_addr,
561 sizeof(ipv6.hdr.dst_addr));
564 item.mask = &ipv6_mask;
565 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
566 MLX5_MODIFICATION_TYPE_SET, error);
570 * Convert modify-header set MAC address action to DV specification.
572 * @param[in,out] resource
573 * Pointer to the modify-header resource.
575 * Pointer to action specification.
577 * Pointer to the error structure.
580 * 0 on success, a negative errno value otherwise and rte_errno is set.
583 flow_dv_convert_action_modify_mac
584 (struct mlx5_flow_dv_modify_hdr_resource *resource,
585 const struct rte_flow_action *action,
586 struct rte_flow_error *error)
588 const struct rte_flow_action_set_mac *conf =
589 (const struct rte_flow_action_set_mac *)(action->conf);
590 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
591 struct rte_flow_item_eth eth;
592 struct rte_flow_item_eth eth_mask;
594 memset(ð, 0, sizeof(eth));
595 memset(ð_mask, 0, sizeof(eth_mask));
596 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
597 memcpy(ð.src.addr_bytes, &conf->mac_addr,
598 sizeof(eth.src.addr_bytes));
599 memcpy(ð_mask.src.addr_bytes,
600 &rte_flow_item_eth_mask.src.addr_bytes,
601 sizeof(eth_mask.src.addr_bytes));
603 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
604 sizeof(eth.dst.addr_bytes));
605 memcpy(ð_mask.dst.addr_bytes,
606 &rte_flow_item_eth_mask.dst.addr_bytes,
607 sizeof(eth_mask.dst.addr_bytes));
610 item.mask = ð_mask;
611 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
612 MLX5_MODIFICATION_TYPE_SET, error);
616 * Convert modify-header set VLAN VID action to DV specification.
618 * @param[in,out] resource
619 * Pointer to the modify-header resource.
621 * Pointer to action specification.
623 * Pointer to the error structure.
626 * 0 on success, a negative errno value otherwise and rte_errno is set.
629 flow_dv_convert_action_modify_vlan_vid
630 (struct mlx5_flow_dv_modify_hdr_resource *resource,
631 const struct rte_flow_action *action,
632 struct rte_flow_error *error)
634 const struct rte_flow_action_of_set_vlan_vid *conf =
635 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
636 int i = resource->actions_num;
637 struct mlx5_modification_cmd *actions = resource->actions;
638 struct field_modify_info *field = modify_vlan_out_first_vid;
640 if (i >= MLX5_MAX_MODIFY_NUM)
641 return rte_flow_error_set(error, EINVAL,
642 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
643 "too many items to modify");
644 actions[i] = (struct mlx5_modification_cmd) {
645 .action_type = MLX5_MODIFICATION_TYPE_SET,
647 .length = field->size,
648 .offset = field->offset,
650 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
651 actions[i].data1 = conf->vlan_vid;
652 actions[i].data1 = actions[i].data1 << 16;
653 resource->actions_num = ++i;
658 * Convert modify-header set TP action to DV specification.
660 * @param[in,out] resource
661 * Pointer to the modify-header resource.
663 * Pointer to action specification.
665 * Pointer to rte_flow_item objects list.
667 * Pointer to flow attributes structure.
668 * @param[in] dev_flow
669 * Pointer to the sub flow.
670 * @param[in] tunnel_decap
671 * Whether action is after tunnel decapsulation.
673 * Pointer to the error structure.
676 * 0 on success, a negative errno value otherwise and rte_errno is set.
679 flow_dv_convert_action_modify_tp
680 (struct mlx5_flow_dv_modify_hdr_resource *resource,
681 const struct rte_flow_action *action,
682 const struct rte_flow_item *items,
683 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
684 bool tunnel_decap, struct rte_flow_error *error)
686 const struct rte_flow_action_set_tp *conf =
687 (const struct rte_flow_action_set_tp *)(action->conf);
688 struct rte_flow_item item;
689 struct rte_flow_item_udp udp;
690 struct rte_flow_item_udp udp_mask;
691 struct rte_flow_item_tcp tcp;
692 struct rte_flow_item_tcp tcp_mask;
693 struct field_modify_info *field;
696 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
698 memset(&udp, 0, sizeof(udp));
699 memset(&udp_mask, 0, sizeof(udp_mask));
700 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
701 udp.hdr.src_port = conf->port;
702 udp_mask.hdr.src_port =
703 rte_flow_item_udp_mask.hdr.src_port;
705 udp.hdr.dst_port = conf->port;
706 udp_mask.hdr.dst_port =
707 rte_flow_item_udp_mask.hdr.dst_port;
709 item.type = RTE_FLOW_ITEM_TYPE_UDP;
711 item.mask = &udp_mask;
714 MLX5_ASSERT(attr->tcp);
715 memset(&tcp, 0, sizeof(tcp));
716 memset(&tcp_mask, 0, sizeof(tcp_mask));
717 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
718 tcp.hdr.src_port = conf->port;
719 tcp_mask.hdr.src_port =
720 rte_flow_item_tcp_mask.hdr.src_port;
722 tcp.hdr.dst_port = conf->port;
723 tcp_mask.hdr.dst_port =
724 rte_flow_item_tcp_mask.hdr.dst_port;
726 item.type = RTE_FLOW_ITEM_TYPE_TCP;
728 item.mask = &tcp_mask;
731 return flow_dv_convert_modify_action(&item, field, NULL, resource,
732 MLX5_MODIFICATION_TYPE_SET, error);
736 * Convert modify-header set TTL action to DV specification.
738 * @param[in,out] resource
739 * Pointer to the modify-header resource.
741 * Pointer to action specification.
743 * Pointer to rte_flow_item objects list.
745 * Pointer to flow attributes structure.
746 * @param[in] dev_flow
747 * Pointer to the sub flow.
748 * @param[in] tunnel_decap
749 * Whether action is after tunnel decapsulation.
751 * Pointer to the error structure.
754 * 0 on success, a negative errno value otherwise and rte_errno is set.
757 flow_dv_convert_action_modify_ttl
758 (struct mlx5_flow_dv_modify_hdr_resource *resource,
759 const struct rte_flow_action *action,
760 const struct rte_flow_item *items,
761 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
762 bool tunnel_decap, struct rte_flow_error *error)
764 const struct rte_flow_action_set_ttl *conf =
765 (const struct rte_flow_action_set_ttl *)(action->conf);
766 struct rte_flow_item item;
767 struct rte_flow_item_ipv4 ipv4;
768 struct rte_flow_item_ipv4 ipv4_mask;
769 struct rte_flow_item_ipv6 ipv6;
770 struct rte_flow_item_ipv6 ipv6_mask;
771 struct field_modify_info *field;
774 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
776 memset(&ipv4, 0, sizeof(ipv4));
777 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
778 ipv4.hdr.time_to_live = conf->ttl_value;
779 ipv4_mask.hdr.time_to_live = 0xFF;
780 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
782 item.mask = &ipv4_mask;
785 MLX5_ASSERT(attr->ipv6);
786 memset(&ipv6, 0, sizeof(ipv6));
787 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
788 ipv6.hdr.hop_limits = conf->ttl_value;
789 ipv6_mask.hdr.hop_limits = 0xFF;
790 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
792 item.mask = &ipv6_mask;
795 return flow_dv_convert_modify_action(&item, field, NULL, resource,
796 MLX5_MODIFICATION_TYPE_SET, error);
800 * Convert modify-header decrement TTL action to DV specification.
802 * @param[in,out] resource
803 * Pointer to the modify-header resource.
805 * Pointer to action specification.
807 * Pointer to rte_flow_item objects list.
809 * Pointer to flow attributes structure.
810 * @param[in] dev_flow
811 * Pointer to the sub flow.
812 * @param[in] tunnel_decap
813 * Whether action is after tunnel decapsulation.
815 * Pointer to the error structure.
818 * 0 on success, a negative errno value otherwise and rte_errno is set.
821 flow_dv_convert_action_modify_dec_ttl
822 (struct mlx5_flow_dv_modify_hdr_resource *resource,
823 const struct rte_flow_item *items,
824 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
825 bool tunnel_decap, struct rte_flow_error *error)
827 struct rte_flow_item item;
828 struct rte_flow_item_ipv4 ipv4;
829 struct rte_flow_item_ipv4 ipv4_mask;
830 struct rte_flow_item_ipv6 ipv6;
831 struct rte_flow_item_ipv6 ipv6_mask;
832 struct field_modify_info *field;
835 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
837 memset(&ipv4, 0, sizeof(ipv4));
838 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
839 ipv4.hdr.time_to_live = 0xFF;
840 ipv4_mask.hdr.time_to_live = 0xFF;
841 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
843 item.mask = &ipv4_mask;
846 MLX5_ASSERT(attr->ipv6);
847 memset(&ipv6, 0, sizeof(ipv6));
848 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
849 ipv6.hdr.hop_limits = 0xFF;
850 ipv6_mask.hdr.hop_limits = 0xFF;
851 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
853 item.mask = &ipv6_mask;
856 return flow_dv_convert_modify_action(&item, field, NULL, resource,
857 MLX5_MODIFICATION_TYPE_ADD, error);
861 * Convert modify-header increment/decrement TCP Sequence number
862 * to DV specification.
864 * @param[in,out] resource
865 * Pointer to the modify-header resource.
867 * Pointer to action specification.
869 * Pointer to the error structure.
872 * 0 on success, a negative errno value otherwise and rte_errno is set.
875 flow_dv_convert_action_modify_tcp_seq
876 (struct mlx5_flow_dv_modify_hdr_resource *resource,
877 const struct rte_flow_action *action,
878 struct rte_flow_error *error)
880 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
881 uint64_t value = rte_be_to_cpu_32(*conf);
882 struct rte_flow_item item;
883 struct rte_flow_item_tcp tcp;
884 struct rte_flow_item_tcp tcp_mask;
886 memset(&tcp, 0, sizeof(tcp));
887 memset(&tcp_mask, 0, sizeof(tcp_mask));
888 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
890 * The HW has no decrement operation, only increment operation.
891 * To simulate decrement X from Y using increment operation
892 * we need to add UINT32_MAX X times to Y.
893 * Each adding of UINT32_MAX decrements Y by 1.
896 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
897 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
898 item.type = RTE_FLOW_ITEM_TYPE_TCP;
900 item.mask = &tcp_mask;
901 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
902 MLX5_MODIFICATION_TYPE_ADD, error);
906 * Convert modify-header increment/decrement TCP Acknowledgment number
907 * to DV specification.
909 * @param[in,out] resource
910 * Pointer to the modify-header resource.
912 * Pointer to action specification.
914 * Pointer to the error structure.
917 * 0 on success, a negative errno value otherwise and rte_errno is set.
920 flow_dv_convert_action_modify_tcp_ack
921 (struct mlx5_flow_dv_modify_hdr_resource *resource,
922 const struct rte_flow_action *action,
923 struct rte_flow_error *error)
925 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
926 uint64_t value = rte_be_to_cpu_32(*conf);
927 struct rte_flow_item item;
928 struct rte_flow_item_tcp tcp;
929 struct rte_flow_item_tcp tcp_mask;
931 memset(&tcp, 0, sizeof(tcp));
932 memset(&tcp_mask, 0, sizeof(tcp_mask));
933 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
935 * The HW has no decrement operation, only increment operation.
936 * To simulate decrement X from Y using increment operation
937 * we need to add UINT32_MAX X times to Y.
938 * Each adding of UINT32_MAX decrements Y by 1.
941 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
942 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
943 item.type = RTE_FLOW_ITEM_TYPE_TCP;
945 item.mask = &tcp_mask;
946 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
947 MLX5_MODIFICATION_TYPE_ADD, error);
950 static enum mlx5_modification_field reg_to_field[] = {
951 [REG_NONE] = MLX5_MODI_OUT_NONE,
952 [REG_A] = MLX5_MODI_META_DATA_REG_A,
953 [REG_B] = MLX5_MODI_META_DATA_REG_B,
954 [REG_C_0] = MLX5_MODI_META_REG_C_0,
955 [REG_C_1] = MLX5_MODI_META_REG_C_1,
956 [REG_C_2] = MLX5_MODI_META_REG_C_2,
957 [REG_C_3] = MLX5_MODI_META_REG_C_3,
958 [REG_C_4] = MLX5_MODI_META_REG_C_4,
959 [REG_C_5] = MLX5_MODI_META_REG_C_5,
960 [REG_C_6] = MLX5_MODI_META_REG_C_6,
961 [REG_C_7] = MLX5_MODI_META_REG_C_7,
965 * Convert register set to DV specification.
967 * @param[in,out] resource
968 * Pointer to the modify-header resource.
970 * Pointer to action specification.
972 * Pointer to the error structure.
975 * 0 on success, a negative errno value otherwise and rte_errno is set.
978 flow_dv_convert_action_set_reg
979 (struct mlx5_flow_dv_modify_hdr_resource *resource,
980 const struct rte_flow_action *action,
981 struct rte_flow_error *error)
983 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
984 struct mlx5_modification_cmd *actions = resource->actions;
985 uint32_t i = resource->actions_num;
987 if (i >= MLX5_MAX_MODIFY_NUM)
988 return rte_flow_error_set(error, EINVAL,
989 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
990 "too many items to modify");
991 MLX5_ASSERT(conf->id != REG_NONE);
992 MLX5_ASSERT(conf->id < RTE_DIM(reg_to_field));
993 actions[i] = (struct mlx5_modification_cmd) {
994 .action_type = MLX5_MODIFICATION_TYPE_SET,
995 .field = reg_to_field[conf->id],
997 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
998 actions[i].data1 = rte_cpu_to_be_32(conf->data);
1000 resource->actions_num = i;
1005 * Convert SET_TAG action to DV specification.
1008 * Pointer to the rte_eth_dev structure.
1009 * @param[in,out] resource
1010 * Pointer to the modify-header resource.
1012 * Pointer to action specification.
1014 * Pointer to the error structure.
1017 * 0 on success, a negative errno value otherwise and rte_errno is set.
1020 flow_dv_convert_action_set_tag
1021 (struct rte_eth_dev *dev,
1022 struct mlx5_flow_dv_modify_hdr_resource *resource,
1023 const struct rte_flow_action_set_tag *conf,
1024 struct rte_flow_error *error)
1026 rte_be32_t data = rte_cpu_to_be_32(conf->data);
1027 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1028 struct rte_flow_item item = {
1032 struct field_modify_info reg_c_x[] = {
1035 enum mlx5_modification_field reg_type;
1038 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1041 MLX5_ASSERT(ret != REG_NONE);
1042 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1043 reg_type = reg_to_field[ret];
1044 MLX5_ASSERT(reg_type > 0);
1045 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1046 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1047 MLX5_MODIFICATION_TYPE_SET, error);
1051 * Convert internal COPY_REG action to DV specification.
1054 * Pointer to the rte_eth_dev structure.
1055 * @param[in,out] res
1056 * Pointer to the modify-header resource.
1058 * Pointer to action specification.
1060 * Pointer to the error structure.
1063 * 0 on success, a negative errno value otherwise and rte_errno is set.
1066 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1067 struct mlx5_flow_dv_modify_hdr_resource *res,
1068 const struct rte_flow_action *action,
1069 struct rte_flow_error *error)
1071 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1072 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1073 struct rte_flow_item item = {
1077 struct field_modify_info reg_src[] = {
1078 {4, 0, reg_to_field[conf->src]},
1081 struct field_modify_info reg_dst = {
1083 .id = reg_to_field[conf->dst],
1085 /* Adjust reg_c[0] usage according to reported mask. */
1086 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1087 struct mlx5_priv *priv = dev->data->dev_private;
1088 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1090 MLX5_ASSERT(reg_c0);
1091 MLX5_ASSERT(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1092 if (conf->dst == REG_C_0) {
1093 /* Copy to reg_c[0], within mask only. */
1094 reg_dst.offset = rte_bsf32(reg_c0);
1096 * Mask is ignoring the enianness, because
1097 * there is no conversion in datapath.
1099 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1100 /* Copy from destination lower bits to reg_c[0]. */
1101 mask = reg_c0 >> reg_dst.offset;
1103 /* Copy from destination upper bits to reg_c[0]. */
1104 mask = reg_c0 << (sizeof(reg_c0) * CHAR_BIT -
1105 rte_fls_u32(reg_c0));
1108 mask = rte_cpu_to_be_32(reg_c0);
1109 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1110 /* Copy from reg_c[0] to destination lower bits. */
1113 /* Copy from reg_c[0] to destination upper bits. */
1114 reg_dst.offset = sizeof(reg_c0) * CHAR_BIT -
1115 (rte_fls_u32(reg_c0) -
1120 return flow_dv_convert_modify_action(&item,
1121 reg_src, ®_dst, res,
1122 MLX5_MODIFICATION_TYPE_COPY,
1127 * Convert MARK action to DV specification. This routine is used
1128 * in extensive metadata only and requires metadata register to be
1129 * handled. In legacy mode hardware tag resource is engaged.
1132 * Pointer to the rte_eth_dev structure.
1134 * Pointer to MARK action specification.
1135 * @param[in,out] resource
1136 * Pointer to the modify-header resource.
1138 * Pointer to the error structure.
1141 * 0 on success, a negative errno value otherwise and rte_errno is set.
1144 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1145 const struct rte_flow_action_mark *conf,
1146 struct mlx5_flow_dv_modify_hdr_resource *resource,
1147 struct rte_flow_error *error)
1149 struct mlx5_priv *priv = dev->data->dev_private;
1150 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1151 priv->sh->dv_mark_mask);
1152 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1153 struct rte_flow_item item = {
1157 struct field_modify_info reg_c_x[] = {
1158 {4, 0, 0}, /* dynamic instead of MLX5_MODI_META_REG_C_1. */
1164 return rte_flow_error_set(error, EINVAL,
1165 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1166 NULL, "zero mark action mask");
1167 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1170 MLX5_ASSERT(reg > 0);
1171 if (reg == REG_C_0) {
1172 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1173 uint32_t shl_c0 = rte_bsf32(msk_c0);
1175 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1176 mask = rte_cpu_to_be_32(mask) & msk_c0;
1177 mask = rte_cpu_to_be_32(mask << shl_c0);
1179 reg_c_x[0].id = reg_to_field[reg];
1180 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1181 MLX5_MODIFICATION_TYPE_SET, error);
1185 * Get metadata register index for specified steering domain.
1188 * Pointer to the rte_eth_dev structure.
1190 * Attributes of flow to determine steering domain.
1192 * Pointer to the error structure.
1195 * positive index on success, a negative errno value otherwise
1196 * and rte_errno is set.
1198 static enum modify_reg
1199 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1200 const struct rte_flow_attr *attr,
1201 struct rte_flow_error *error)
1204 mlx5_flow_get_reg_id(dev, attr->transfer ?
1208 MLX5_METADATA_RX, 0, error);
1210 return rte_flow_error_set(error,
1211 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1212 NULL, "unavailable "
1213 "metadata register");
1218 * Convert SET_META action to DV specification.
1221 * Pointer to the rte_eth_dev structure.
1222 * @param[in,out] resource
1223 * Pointer to the modify-header resource.
1225 * Attributes of flow that includes this item.
1227 * Pointer to action specification.
1229 * Pointer to the error structure.
1232 * 0 on success, a negative errno value otherwise and rte_errno is set.
1235 flow_dv_convert_action_set_meta
1236 (struct rte_eth_dev *dev,
1237 struct mlx5_flow_dv_modify_hdr_resource *resource,
1238 const struct rte_flow_attr *attr,
1239 const struct rte_flow_action_set_meta *conf,
1240 struct rte_flow_error *error)
1242 uint32_t data = conf->data;
1243 uint32_t mask = conf->mask;
1244 struct rte_flow_item item = {
1248 struct field_modify_info reg_c_x[] = {
1251 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1256 * In datapath code there is no endianness
1257 * coversions for perfromance reasons, all
1258 * pattern conversions are done in rte_flow.
1260 if (reg == REG_C_0) {
1261 struct mlx5_priv *priv = dev->data->dev_private;
1262 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1265 MLX5_ASSERT(msk_c0);
1266 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1267 shl_c0 = rte_bsf32(msk_c0);
1269 shl_c0 = sizeof(msk_c0) * CHAR_BIT - rte_fls_u32(msk_c0);
1273 MLX5_ASSERT(!(~msk_c0 & rte_cpu_to_be_32(mask)));
1275 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1276 /* The routine expects parameters in memory as big-endian ones. */
1277 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1278 MLX5_MODIFICATION_TYPE_SET, error);
1282 * Convert modify-header set IPv4 DSCP action to DV specification.
1284 * @param[in,out] resource
1285 * Pointer to the modify-header resource.
1287 * Pointer to action specification.
1289 * Pointer to the error structure.
1292 * 0 on success, a negative errno value otherwise and rte_errno is set.
1295 flow_dv_convert_action_modify_ipv4_dscp
1296 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1297 const struct rte_flow_action *action,
1298 struct rte_flow_error *error)
1300 const struct rte_flow_action_set_dscp *conf =
1301 (const struct rte_flow_action_set_dscp *)(action->conf);
1302 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1303 struct rte_flow_item_ipv4 ipv4;
1304 struct rte_flow_item_ipv4 ipv4_mask;
1306 memset(&ipv4, 0, sizeof(ipv4));
1307 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1308 ipv4.hdr.type_of_service = conf->dscp;
1309 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1311 item.mask = &ipv4_mask;
1312 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1313 MLX5_MODIFICATION_TYPE_SET, error);
1317 * Convert modify-header set IPv6 DSCP action to DV specification.
1319 * @param[in,out] resource
1320 * Pointer to the modify-header resource.
1322 * Pointer to action specification.
1324 * Pointer to the error structure.
1327 * 0 on success, a negative errno value otherwise and rte_errno is set.
1330 flow_dv_convert_action_modify_ipv6_dscp
1331 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1332 const struct rte_flow_action *action,
1333 struct rte_flow_error *error)
1335 const struct rte_flow_action_set_dscp *conf =
1336 (const struct rte_flow_action_set_dscp *)(action->conf);
1337 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1338 struct rte_flow_item_ipv6 ipv6;
1339 struct rte_flow_item_ipv6 ipv6_mask;
1341 memset(&ipv6, 0, sizeof(ipv6));
1342 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1344 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1345 * rdma-core only accept the DSCP bits byte aligned start from
1346 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1347 * bits in IPv6 case as rdma-core requires byte aligned value.
1349 ipv6.hdr.vtc_flow = conf->dscp;
1350 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1352 item.mask = &ipv6_mask;
1353 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1354 MLX5_MODIFICATION_TYPE_SET, error);
1358 * Validate MARK item.
1361 * Pointer to the rte_eth_dev structure.
1363 * Item specification.
1365 * Attributes of flow that includes this item.
1367 * Pointer to error structure.
1370 * 0 on success, a negative errno value otherwise and rte_errno is set.
1373 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1374 const struct rte_flow_item *item,
1375 const struct rte_flow_attr *attr __rte_unused,
1376 struct rte_flow_error *error)
1378 struct mlx5_priv *priv = dev->data->dev_private;
1379 struct mlx5_dev_config *config = &priv->config;
1380 const struct rte_flow_item_mark *spec = item->spec;
1381 const struct rte_flow_item_mark *mask = item->mask;
1382 const struct rte_flow_item_mark nic_mask = {
1383 .id = priv->sh->dv_mark_mask,
1387 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1388 return rte_flow_error_set(error, ENOTSUP,
1389 RTE_FLOW_ERROR_TYPE_ITEM, item,
1390 "extended metadata feature"
1392 if (!mlx5_flow_ext_mreg_supported(dev))
1393 return rte_flow_error_set(error, ENOTSUP,
1394 RTE_FLOW_ERROR_TYPE_ITEM, item,
1395 "extended metadata register"
1396 " isn't supported");
1398 return rte_flow_error_set(error, ENOTSUP,
1399 RTE_FLOW_ERROR_TYPE_ITEM, item,
1400 "extended metadata register"
1401 " isn't available");
1402 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1406 return rte_flow_error_set(error, EINVAL,
1407 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1409 "data cannot be empty");
1410 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1411 return rte_flow_error_set(error, EINVAL,
1412 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1414 "mark id exceeds the limit");
1418 return rte_flow_error_set(error, EINVAL,
1419 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1420 "mask cannot be zero");
1422 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1423 (const uint8_t *)&nic_mask,
1424 sizeof(struct rte_flow_item_mark),
1432 * Validate META item.
1435 * Pointer to the rte_eth_dev structure.
1437 * Item specification.
1439 * Attributes of flow that includes this item.
1441 * Pointer to error structure.
1444 * 0 on success, a negative errno value otherwise and rte_errno is set.
1447 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1448 const struct rte_flow_item *item,
1449 const struct rte_flow_attr *attr,
1450 struct rte_flow_error *error)
1452 struct mlx5_priv *priv = dev->data->dev_private;
1453 struct mlx5_dev_config *config = &priv->config;
1454 const struct rte_flow_item_meta *spec = item->spec;
1455 const struct rte_flow_item_meta *mask = item->mask;
1456 struct rte_flow_item_meta nic_mask = {
1463 return rte_flow_error_set(error, EINVAL,
1464 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1466 "data cannot be empty");
1467 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1468 if (!mlx5_flow_ext_mreg_supported(dev))
1469 return rte_flow_error_set(error, ENOTSUP,
1470 RTE_FLOW_ERROR_TYPE_ITEM, item,
1471 "extended metadata register"
1472 " isn't supported");
1473 reg = flow_dv_get_metadata_reg(dev, attr, error);
1477 return rte_flow_error_set(error, ENOTSUP,
1478 RTE_FLOW_ERROR_TYPE_ITEM, item,
1482 nic_mask.data = priv->sh->dv_meta_mask;
1485 mask = &rte_flow_item_meta_mask;
1487 return rte_flow_error_set(error, EINVAL,
1488 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1489 "mask cannot be zero");
1491 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1492 (const uint8_t *)&nic_mask,
1493 sizeof(struct rte_flow_item_meta),
1499 * Validate TAG item.
1502 * Pointer to the rte_eth_dev structure.
1504 * Item specification.
1506 * Attributes of flow that includes this item.
1508 * Pointer to error structure.
1511 * 0 on success, a negative errno value otherwise and rte_errno is set.
1514 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
1515 const struct rte_flow_item *item,
1516 const struct rte_flow_attr *attr __rte_unused,
1517 struct rte_flow_error *error)
1519 const struct rte_flow_item_tag *spec = item->spec;
1520 const struct rte_flow_item_tag *mask = item->mask;
1521 const struct rte_flow_item_tag nic_mask = {
1522 .data = RTE_BE32(UINT32_MAX),
1527 if (!mlx5_flow_ext_mreg_supported(dev))
1528 return rte_flow_error_set(error, ENOTSUP,
1529 RTE_FLOW_ERROR_TYPE_ITEM, item,
1530 "extensive metadata register"
1531 " isn't supported");
1533 return rte_flow_error_set(error, EINVAL,
1534 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1536 "data cannot be empty");
1538 mask = &rte_flow_item_tag_mask;
1540 return rte_flow_error_set(error, EINVAL,
1541 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1542 "mask cannot be zero");
1544 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1545 (const uint8_t *)&nic_mask,
1546 sizeof(struct rte_flow_item_tag),
1550 if (mask->index != 0xff)
1551 return rte_flow_error_set(error, EINVAL,
1552 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1553 "partial mask for tag index"
1554 " is not supported");
1555 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
1558 MLX5_ASSERT(ret != REG_NONE);
1563 * Validate vport item.
1566 * Pointer to the rte_eth_dev structure.
1568 * Item specification.
1570 * Attributes of flow that includes this item.
1571 * @param[in] item_flags
1572 * Bit-fields that holds the items detected until now.
1574 * Pointer to error structure.
1577 * 0 on success, a negative errno value otherwise and rte_errno is set.
1580 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
1581 const struct rte_flow_item *item,
1582 const struct rte_flow_attr *attr,
1583 uint64_t item_flags,
1584 struct rte_flow_error *error)
1586 const struct rte_flow_item_port_id *spec = item->spec;
1587 const struct rte_flow_item_port_id *mask = item->mask;
1588 const struct rte_flow_item_port_id switch_mask = {
1591 struct mlx5_priv *esw_priv;
1592 struct mlx5_priv *dev_priv;
1595 if (!attr->transfer)
1596 return rte_flow_error_set(error, EINVAL,
1597 RTE_FLOW_ERROR_TYPE_ITEM,
1599 "match on port id is valid only"
1600 " when transfer flag is enabled");
1601 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
1602 return rte_flow_error_set(error, ENOTSUP,
1603 RTE_FLOW_ERROR_TYPE_ITEM, item,
1604 "multiple source ports are not"
1607 mask = &switch_mask;
1608 if (mask->id != 0xffffffff)
1609 return rte_flow_error_set(error, ENOTSUP,
1610 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
1612 "no support for partial mask on"
1614 ret = mlx5_flow_item_acceptable
1615 (item, (const uint8_t *)mask,
1616 (const uint8_t *)&rte_flow_item_port_id_mask,
1617 sizeof(struct rte_flow_item_port_id),
1623 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
1625 return rte_flow_error_set(error, rte_errno,
1626 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1627 "failed to obtain E-Switch info for"
1629 dev_priv = mlx5_dev_to_eswitch_info(dev);
1631 return rte_flow_error_set(error, rte_errno,
1632 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1634 "failed to obtain E-Switch info");
1635 if (esw_priv->domain_id != dev_priv->domain_id)
1636 return rte_flow_error_set(error, EINVAL,
1637 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1638 "cannot match on a port from a"
1639 " different E-Switch");
1644 * Validate VLAN item.
1647 * Item specification.
1648 * @param[in] item_flags
1649 * Bit-fields that holds the items detected until now.
1651 * Ethernet device flow is being created on.
1653 * Pointer to error structure.
1656 * 0 on success, a negative errno value otherwise and rte_errno is set.
1659 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
1660 uint64_t item_flags,
1661 struct rte_eth_dev *dev,
1662 struct rte_flow_error *error)
1664 const struct rte_flow_item_vlan *mask = item->mask;
1665 const struct rte_flow_item_vlan nic_mask = {
1666 .tci = RTE_BE16(UINT16_MAX),
1667 .inner_type = RTE_BE16(UINT16_MAX),
1669 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1671 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1672 MLX5_FLOW_LAYER_INNER_L4) :
1673 (MLX5_FLOW_LAYER_OUTER_L3 |
1674 MLX5_FLOW_LAYER_OUTER_L4);
1675 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1676 MLX5_FLOW_LAYER_OUTER_VLAN;
1678 if (item_flags & vlanm)
1679 return rte_flow_error_set(error, EINVAL,
1680 RTE_FLOW_ERROR_TYPE_ITEM, item,
1681 "multiple VLAN layers not supported");
1682 else if ((item_flags & l34m) != 0)
1683 return rte_flow_error_set(error, EINVAL,
1684 RTE_FLOW_ERROR_TYPE_ITEM, item,
1685 "VLAN cannot follow L3/L4 layer");
1687 mask = &rte_flow_item_vlan_mask;
1688 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1689 (const uint8_t *)&nic_mask,
1690 sizeof(struct rte_flow_item_vlan),
1694 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1695 struct mlx5_priv *priv = dev->data->dev_private;
1697 if (priv->vmwa_context) {
1699 * Non-NULL context means we have a virtual machine
1700 * and SR-IOV enabled, we have to create VLAN interface
1701 * to make hypervisor to setup E-Switch vport
1702 * context correctly. We avoid creating the multiple
1703 * VLAN interfaces, so we cannot support VLAN tag mask.
1705 return rte_flow_error_set(error, EINVAL,
1706 RTE_FLOW_ERROR_TYPE_ITEM,
1708 "VLAN tag mask is not"
1709 " supported in virtual"
1717 * GTP flags are contained in 1 byte of the format:
1718 * -------------------------------------------
1719 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
1720 * |-----------------------------------------|
1721 * | value | Version | PT | Res | E | S | PN |
1722 * -------------------------------------------
1724 * Matching is supported only for GTP flags E, S, PN.
1726 #define MLX5_GTP_FLAGS_MASK 0x07
1729 * Validate GTP item.
1732 * Pointer to the rte_eth_dev structure.
1734 * Item specification.
1735 * @param[in] item_flags
1736 * Bit-fields that holds the items detected until now.
1738 * Pointer to error structure.
1741 * 0 on success, a negative errno value otherwise and rte_errno is set.
1744 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
1745 const struct rte_flow_item *item,
1746 uint64_t item_flags,
1747 struct rte_flow_error *error)
1749 struct mlx5_priv *priv = dev->data->dev_private;
1750 const struct rte_flow_item_gtp *spec = item->spec;
1751 const struct rte_flow_item_gtp *mask = item->mask;
1752 const struct rte_flow_item_gtp nic_mask = {
1753 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
1755 .teid = RTE_BE32(0xffffffff),
1758 if (!priv->config.hca_attr.tunnel_stateless_gtp)
1759 return rte_flow_error_set(error, ENOTSUP,
1760 RTE_FLOW_ERROR_TYPE_ITEM, item,
1761 "GTP support is not enabled");
1762 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1763 return rte_flow_error_set(error, ENOTSUP,
1764 RTE_FLOW_ERROR_TYPE_ITEM, item,
1765 "multiple tunnel layers not"
1767 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1768 return rte_flow_error_set(error, EINVAL,
1769 RTE_FLOW_ERROR_TYPE_ITEM, item,
1770 "no outer UDP layer found");
1772 mask = &rte_flow_item_gtp_mask;
1773 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
1774 return rte_flow_error_set(error, ENOTSUP,
1775 RTE_FLOW_ERROR_TYPE_ITEM, item,
1776 "Match is supported for GTP"
1778 return mlx5_flow_item_acceptable
1779 (item, (const uint8_t *)mask,
1780 (const uint8_t *)&nic_mask,
1781 sizeof(struct rte_flow_item_gtp),
1786 * Validate the pop VLAN action.
1789 * Pointer to the rte_eth_dev structure.
1790 * @param[in] action_flags
1791 * Holds the actions detected until now.
1793 * Pointer to the pop vlan action.
1794 * @param[in] item_flags
1795 * The items found in this flow rule.
1797 * Pointer to flow attributes.
1799 * Pointer to error structure.
1802 * 0 on success, a negative errno value otherwise and rte_errno is set.
1805 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
1806 uint64_t action_flags,
1807 const struct rte_flow_action *action,
1808 uint64_t item_flags,
1809 const struct rte_flow_attr *attr,
1810 struct rte_flow_error *error)
1812 const struct mlx5_priv *priv = dev->data->dev_private;
1816 if (!priv->sh->pop_vlan_action)
1817 return rte_flow_error_set(error, ENOTSUP,
1818 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1820 "pop vlan action is not supported");
1822 return rte_flow_error_set(error, ENOTSUP,
1823 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1825 "pop vlan action not supported for "
1827 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
1828 return rte_flow_error_set(error, ENOTSUP,
1829 RTE_FLOW_ERROR_TYPE_ACTION, action,
1830 "no support for multiple VLAN "
1832 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1833 return rte_flow_error_set(error, ENOTSUP,
1834 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1836 "cannot pop vlan without a "
1837 "match on (outer) vlan in the flow");
1838 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1839 return rte_flow_error_set(error, EINVAL,
1840 RTE_FLOW_ERROR_TYPE_ACTION, action,
1841 "wrong action order, port_id should "
1842 "be after pop VLAN action");
1843 if (!attr->transfer && priv->representor)
1844 return rte_flow_error_set(error, ENOTSUP,
1845 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1846 "pop vlan action for VF representor "
1847 "not supported on NIC table");
1852 * Get VLAN default info from vlan match info.
1855 * the list of item specifications.
1857 * pointer VLAN info to fill to.
1860 * 0 on success, a negative errno value otherwise and rte_errno is set.
1863 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
1864 struct rte_vlan_hdr *vlan)
1866 const struct rte_flow_item_vlan nic_mask = {
1867 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
1868 MLX5DV_FLOW_VLAN_VID_MASK),
1869 .inner_type = RTE_BE16(0xffff),
1874 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
1875 int type = items->type;
1877 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
1878 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
1881 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
1882 const struct rte_flow_item_vlan *vlan_m = items->mask;
1883 const struct rte_flow_item_vlan *vlan_v = items->spec;
1885 /* If VLAN item in pattern doesn't contain data, return here. */
1890 /* Only full match values are accepted */
1891 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
1892 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
1893 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
1895 rte_be_to_cpu_16(vlan_v->tci &
1896 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
1898 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
1899 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
1900 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
1902 rte_be_to_cpu_16(vlan_v->tci &
1903 MLX5DV_FLOW_VLAN_VID_MASK_BE);
1905 if (vlan_m->inner_type == nic_mask.inner_type)
1906 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
1907 vlan_m->inner_type);
1912 * Validate the push VLAN action.
1915 * Pointer to the rte_eth_dev structure.
1916 * @param[in] action_flags
1917 * Holds the actions detected until now.
1918 * @param[in] item_flags
1919 * The items found in this flow rule.
1921 * Pointer to the action structure.
1923 * Pointer to flow attributes
1925 * Pointer to error structure.
1928 * 0 on success, a negative errno value otherwise and rte_errno is set.
1931 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
1932 uint64_t action_flags,
1933 const struct rte_flow_item_vlan *vlan_m,
1934 const struct rte_flow_action *action,
1935 const struct rte_flow_attr *attr,
1936 struct rte_flow_error *error)
1938 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
1939 const struct mlx5_priv *priv = dev->data->dev_private;
1941 if (!attr->transfer && attr->ingress)
1942 return rte_flow_error_set(error, ENOTSUP,
1943 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1945 "push VLAN action not supported for "
1947 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
1948 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
1949 return rte_flow_error_set(error, EINVAL,
1950 RTE_FLOW_ERROR_TYPE_ACTION, action,
1951 "invalid vlan ethertype");
1952 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
1953 return rte_flow_error_set(error, ENOTSUP,
1954 RTE_FLOW_ERROR_TYPE_ACTION, action,
1955 "no support for multiple VLAN "
1957 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1958 return rte_flow_error_set(error, EINVAL,
1959 RTE_FLOW_ERROR_TYPE_ACTION, action,
1960 "wrong action order, port_id should "
1961 "be after push VLAN");
1962 if (!attr->transfer && priv->representor)
1963 return rte_flow_error_set(error, ENOTSUP,
1964 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1965 "push vlan action for VF representor "
1966 "not supported on NIC table");
1968 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
1969 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
1970 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
1971 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
1972 !(mlx5_flow_find_action
1973 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
1974 return rte_flow_error_set(error, EINVAL,
1975 RTE_FLOW_ERROR_TYPE_ACTION, action,
1976 "not full match mask on VLAN PCP and "
1977 "there is no of_set_vlan_pcp action, "
1978 "push VLAN action cannot figure out "
1981 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
1982 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
1983 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
1984 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
1985 !(mlx5_flow_find_action
1986 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
1987 return rte_flow_error_set(error, EINVAL,
1988 RTE_FLOW_ERROR_TYPE_ACTION, action,
1989 "not full match mask on VLAN VID and "
1990 "there is no of_set_vlan_vid action, "
1991 "push VLAN action cannot figure out "
1998 * Validate the set VLAN PCP.
2000 * @param[in] action_flags
2001 * Holds the actions detected until now.
2002 * @param[in] actions
2003 * Pointer to the list of actions remaining in the flow rule.
2005 * Pointer to error structure.
2008 * 0 on success, a negative errno value otherwise and rte_errno is set.
2011 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2012 const struct rte_flow_action actions[],
2013 struct rte_flow_error *error)
2015 const struct rte_flow_action *action = actions;
2016 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2018 if (conf->vlan_pcp > 7)
2019 return rte_flow_error_set(error, EINVAL,
2020 RTE_FLOW_ERROR_TYPE_ACTION, action,
2021 "VLAN PCP value is too big");
2022 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2023 return rte_flow_error_set(error, ENOTSUP,
2024 RTE_FLOW_ERROR_TYPE_ACTION, action,
2025 "set VLAN PCP action must follow "
2026 "the push VLAN action");
2027 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2028 return rte_flow_error_set(error, ENOTSUP,
2029 RTE_FLOW_ERROR_TYPE_ACTION, action,
2030 "Multiple VLAN PCP modification are "
2032 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2033 return rte_flow_error_set(error, EINVAL,
2034 RTE_FLOW_ERROR_TYPE_ACTION, action,
2035 "wrong action order, port_id should "
2036 "be after set VLAN PCP");
2041 * Validate the set VLAN VID.
2043 * @param[in] item_flags
2044 * Holds the items detected in this rule.
2045 * @param[in] action_flags
2046 * Holds the actions detected until now.
2047 * @param[in] actions
2048 * Pointer to the list of actions remaining in the flow rule.
2050 * Pointer to error structure.
2053 * 0 on success, a negative errno value otherwise and rte_errno is set.
2056 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2057 uint64_t action_flags,
2058 const struct rte_flow_action actions[],
2059 struct rte_flow_error *error)
2061 const struct rte_flow_action *action = actions;
2062 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
2064 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
2065 return rte_flow_error_set(error, EINVAL,
2066 RTE_FLOW_ERROR_TYPE_ACTION, action,
2067 "VLAN VID value is too big");
2068 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
2069 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2070 return rte_flow_error_set(error, ENOTSUP,
2071 RTE_FLOW_ERROR_TYPE_ACTION, action,
2072 "set VLAN VID action must follow push"
2073 " VLAN action or match on VLAN item");
2074 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
2075 return rte_flow_error_set(error, ENOTSUP,
2076 RTE_FLOW_ERROR_TYPE_ACTION, action,
2077 "Multiple VLAN VID modifications are "
2079 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2080 return rte_flow_error_set(error, EINVAL,
2081 RTE_FLOW_ERROR_TYPE_ACTION, action,
2082 "wrong action order, port_id should "
2083 "be after set VLAN VID");
2088 * Validate the FLAG action.
2091 * Pointer to the rte_eth_dev structure.
2092 * @param[in] action_flags
2093 * Holds the actions detected until now.
2095 * Pointer to flow attributes
2097 * Pointer to error structure.
2100 * 0 on success, a negative errno value otherwise and rte_errno is set.
2103 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
2104 uint64_t action_flags,
2105 const struct rte_flow_attr *attr,
2106 struct rte_flow_error *error)
2108 struct mlx5_priv *priv = dev->data->dev_private;
2109 struct mlx5_dev_config *config = &priv->config;
2112 /* Fall back if no extended metadata register support. */
2113 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2114 return mlx5_flow_validate_action_flag(action_flags, attr,
2116 /* Extensive metadata mode requires registers. */
2117 if (!mlx5_flow_ext_mreg_supported(dev))
2118 return rte_flow_error_set(error, ENOTSUP,
2119 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2120 "no metadata registers "
2121 "to support flag action");
2122 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
2123 return rte_flow_error_set(error, ENOTSUP,
2124 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2125 "extended metadata register"
2126 " isn't available");
2127 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2130 MLX5_ASSERT(ret > 0);
2131 if (action_flags & MLX5_FLOW_ACTION_MARK)
2132 return rte_flow_error_set(error, EINVAL,
2133 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2134 "can't mark and flag in same flow");
2135 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2136 return rte_flow_error_set(error, EINVAL,
2137 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2139 " actions in same flow");
2144 * Validate MARK action.
2147 * Pointer to the rte_eth_dev structure.
2149 * Pointer to action.
2150 * @param[in] action_flags
2151 * Holds the actions detected until now.
2153 * Pointer to flow attributes
2155 * Pointer to error structure.
2158 * 0 on success, a negative errno value otherwise and rte_errno is set.
2161 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
2162 const struct rte_flow_action *action,
2163 uint64_t action_flags,
2164 const struct rte_flow_attr *attr,
2165 struct rte_flow_error *error)
2167 struct mlx5_priv *priv = dev->data->dev_private;
2168 struct mlx5_dev_config *config = &priv->config;
2169 const struct rte_flow_action_mark *mark = action->conf;
2172 /* Fall back if no extended metadata register support. */
2173 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2174 return mlx5_flow_validate_action_mark(action, action_flags,
2176 /* Extensive metadata mode requires registers. */
2177 if (!mlx5_flow_ext_mreg_supported(dev))
2178 return rte_flow_error_set(error, ENOTSUP,
2179 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2180 "no metadata registers "
2181 "to support mark action");
2182 if (!priv->sh->dv_mark_mask)
2183 return rte_flow_error_set(error, ENOTSUP,
2184 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2185 "extended metadata register"
2186 " isn't available");
2187 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2190 MLX5_ASSERT(ret > 0);
2192 return rte_flow_error_set(error, EINVAL,
2193 RTE_FLOW_ERROR_TYPE_ACTION, action,
2194 "configuration cannot be null");
2195 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
2196 return rte_flow_error_set(error, EINVAL,
2197 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2199 "mark id exceeds the limit");
2200 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2201 return rte_flow_error_set(error, EINVAL,
2202 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2203 "can't flag and mark in same flow");
2204 if (action_flags & MLX5_FLOW_ACTION_MARK)
2205 return rte_flow_error_set(error, EINVAL,
2206 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2207 "can't have 2 mark actions in same"
2213 * Validate SET_META action.
2216 * Pointer to the rte_eth_dev structure.
2218 * Pointer to the action structure.
2219 * @param[in] action_flags
2220 * Holds the actions detected until now.
2222 * Pointer to flow attributes
2224 * Pointer to error structure.
2227 * 0 on success, a negative errno value otherwise and rte_errno is set.
2230 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
2231 const struct rte_flow_action *action,
2232 uint64_t action_flags __rte_unused,
2233 const struct rte_flow_attr *attr,
2234 struct rte_flow_error *error)
2236 const struct rte_flow_action_set_meta *conf;
2237 uint32_t nic_mask = UINT32_MAX;
2240 if (!mlx5_flow_ext_mreg_supported(dev))
2241 return rte_flow_error_set(error, ENOTSUP,
2242 RTE_FLOW_ERROR_TYPE_ACTION, action,
2243 "extended metadata register"
2244 " isn't supported");
2245 reg = flow_dv_get_metadata_reg(dev, attr, error);
2248 if (reg != REG_A && reg != REG_B) {
2249 struct mlx5_priv *priv = dev->data->dev_private;
2251 nic_mask = priv->sh->dv_meta_mask;
2253 if (!(action->conf))
2254 return rte_flow_error_set(error, EINVAL,
2255 RTE_FLOW_ERROR_TYPE_ACTION, action,
2256 "configuration cannot be null");
2257 conf = (const struct rte_flow_action_set_meta *)action->conf;
2259 return rte_flow_error_set(error, EINVAL,
2260 RTE_FLOW_ERROR_TYPE_ACTION, action,
2261 "zero mask doesn't have any effect");
2262 if (conf->mask & ~nic_mask)
2263 return rte_flow_error_set(error, EINVAL,
2264 RTE_FLOW_ERROR_TYPE_ACTION, action,
2265 "meta data must be within reg C0");
2270 * Validate SET_TAG action.
2273 * Pointer to the rte_eth_dev structure.
2275 * Pointer to the action structure.
2276 * @param[in] action_flags
2277 * Holds the actions detected until now.
2279 * Pointer to flow attributes
2281 * Pointer to error structure.
2284 * 0 on success, a negative errno value otherwise and rte_errno is set.
2287 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
2288 const struct rte_flow_action *action,
2289 uint64_t action_flags,
2290 const struct rte_flow_attr *attr,
2291 struct rte_flow_error *error)
2293 const struct rte_flow_action_set_tag *conf;
2294 const uint64_t terminal_action_flags =
2295 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
2296 MLX5_FLOW_ACTION_RSS;
2299 if (!mlx5_flow_ext_mreg_supported(dev))
2300 return rte_flow_error_set(error, ENOTSUP,
2301 RTE_FLOW_ERROR_TYPE_ACTION, action,
2302 "extensive metadata register"
2303 " isn't supported");
2304 if (!(action->conf))
2305 return rte_flow_error_set(error, EINVAL,
2306 RTE_FLOW_ERROR_TYPE_ACTION, action,
2307 "configuration cannot be null");
2308 conf = (const struct rte_flow_action_set_tag *)action->conf;
2310 return rte_flow_error_set(error, EINVAL,
2311 RTE_FLOW_ERROR_TYPE_ACTION, action,
2312 "zero mask doesn't have any effect");
2313 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
2316 if (!attr->transfer && attr->ingress &&
2317 (action_flags & terminal_action_flags))
2318 return rte_flow_error_set(error, EINVAL,
2319 RTE_FLOW_ERROR_TYPE_ACTION, action,
2320 "set_tag has no effect"
2321 " with terminal actions");
2326 * Validate count action.
2329 * Pointer to rte_eth_dev structure.
2331 * Pointer to error structure.
2334 * 0 on success, a negative errno value otherwise and rte_errno is set.
2337 flow_dv_validate_action_count(struct rte_eth_dev *dev,
2338 struct rte_flow_error *error)
2340 struct mlx5_priv *priv = dev->data->dev_private;
2342 if (!priv->config.devx)
2344 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
2348 return rte_flow_error_set
2350 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2352 "count action not supported");
2356 * Validate the L2 encap action.
2359 * Pointer to the rte_eth_dev structure.
2360 * @param[in] action_flags
2361 * Holds the actions detected until now.
2363 * Pointer to the action structure.
2365 * Pointer to flow attributes.
2367 * Pointer to error structure.
2370 * 0 on success, a negative errno value otherwise and rte_errno is set.
2373 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
2374 uint64_t action_flags,
2375 const struct rte_flow_action *action,
2376 const struct rte_flow_attr *attr,
2377 struct rte_flow_error *error)
2379 const struct mlx5_priv *priv = dev->data->dev_private;
2381 if (!(action->conf))
2382 return rte_flow_error_set(error, EINVAL,
2383 RTE_FLOW_ERROR_TYPE_ACTION, action,
2384 "configuration cannot be null");
2385 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
2386 return rte_flow_error_set(error, EINVAL,
2387 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2388 "can only have a single encap action "
2390 if (!attr->transfer && priv->representor)
2391 return rte_flow_error_set(error, ENOTSUP,
2392 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2393 "encap action for VF representor "
2394 "not supported on NIC table");
2399 * Validate a decap action.
2402 * Pointer to the rte_eth_dev structure.
2403 * @param[in] action_flags
2404 * Holds the actions detected until now.
2406 * Pointer to flow attributes
2408 * Pointer to error structure.
2411 * 0 on success, a negative errno value otherwise and rte_errno is set.
2414 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
2415 uint64_t action_flags,
2416 const struct rte_flow_attr *attr,
2417 struct rte_flow_error *error)
2419 const struct mlx5_priv *priv = dev->data->dev_private;
2421 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
2422 return rte_flow_error_set(error, ENOTSUP,
2423 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2425 MLX5_FLOW_ACTION_DECAP ? "can only "
2426 "have a single decap action" : "decap "
2427 "after encap is not supported");
2428 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
2429 return rte_flow_error_set(error, EINVAL,
2430 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2431 "can't have decap action after"
2434 return rte_flow_error_set(error, ENOTSUP,
2435 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2437 "decap action not supported for "
2439 if (!attr->transfer && priv->representor)
2440 return rte_flow_error_set(error, ENOTSUP,
2441 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2442 "decap action for VF representor "
2443 "not supported on NIC table");
2447 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
2450 * Validate the raw encap and decap actions.
2453 * Pointer to the rte_eth_dev structure.
2455 * Pointer to the decap action.
2457 * Pointer to the encap action.
2459 * Pointer to flow attributes
2460 * @param[in/out] action_flags
2461 * Holds the actions detected until now.
2462 * @param[out] actions_n
2463 * pointer to the number of actions counter.
2465 * Pointer to error structure.
2468 * 0 on success, a negative errno value otherwise and rte_errno is set.
2471 flow_dv_validate_action_raw_encap_decap
2472 (struct rte_eth_dev *dev,
2473 const struct rte_flow_action_raw_decap *decap,
2474 const struct rte_flow_action_raw_encap *encap,
2475 const struct rte_flow_attr *attr, uint64_t *action_flags,
2476 int *actions_n, struct rte_flow_error *error)
2478 const struct mlx5_priv *priv = dev->data->dev_private;
2481 if (encap && (!encap->size || !encap->data))
2482 return rte_flow_error_set(error, EINVAL,
2483 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2484 "raw encap data cannot be empty");
2485 if (decap && encap) {
2486 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
2487 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
2490 else if (encap->size <=
2491 MLX5_ENCAPSULATION_DECISION_SIZE &&
2493 MLX5_ENCAPSULATION_DECISION_SIZE)
2496 else if (encap->size >
2497 MLX5_ENCAPSULATION_DECISION_SIZE &&
2499 MLX5_ENCAPSULATION_DECISION_SIZE)
2500 /* 2 L2 actions: encap and decap. */
2503 return rte_flow_error_set(error,
2505 RTE_FLOW_ERROR_TYPE_ACTION,
2506 NULL, "unsupported too small "
2507 "raw decap and too small raw "
2508 "encap combination");
2511 ret = flow_dv_validate_action_decap(dev, *action_flags, attr,
2515 *action_flags |= MLX5_FLOW_ACTION_DECAP;
2519 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
2520 return rte_flow_error_set(error, ENOTSUP,
2521 RTE_FLOW_ERROR_TYPE_ACTION,
2523 "small raw encap size");
2524 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
2525 return rte_flow_error_set(error, EINVAL,
2526 RTE_FLOW_ERROR_TYPE_ACTION,
2528 "more than one encap action");
2529 if (!attr->transfer && priv->representor)
2530 return rte_flow_error_set
2532 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2533 "encap action for VF representor "
2534 "not supported on NIC table");
2535 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
2542 * Find existing encap/decap resource or create and register a new one.
2544 * @param[in, out] dev
2545 * Pointer to rte_eth_dev structure.
2546 * @param[in, out] resource
2547 * Pointer to encap/decap resource.
2548 * @parm[in, out] dev_flow
2549 * Pointer to the dev_flow.
2551 * pointer to error structure.
2554 * 0 on success otherwise -errno and errno is set.
2557 flow_dv_encap_decap_resource_register
2558 (struct rte_eth_dev *dev,
2559 struct mlx5_flow_dv_encap_decap_resource *resource,
2560 struct mlx5_flow *dev_flow,
2561 struct rte_flow_error *error)
2563 struct mlx5_priv *priv = dev->data->dev_private;
2564 struct mlx5_dev_ctx_shared *sh = priv->sh;
2565 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2566 struct mlx5dv_dr_domain *domain;
2569 resource->flags = dev_flow->dv.group ? 0 : 1;
2570 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2571 domain = sh->fdb_domain;
2572 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2573 domain = sh->rx_domain;
2575 domain = sh->tx_domain;
2576 /* Lookup a matching resource from cache. */
2577 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], sh->encaps_decaps, idx,
2578 cache_resource, next) {
2579 if (resource->reformat_type == cache_resource->reformat_type &&
2580 resource->ft_type == cache_resource->ft_type &&
2581 resource->flags == cache_resource->flags &&
2582 resource->size == cache_resource->size &&
2583 !memcmp((const void *)resource->buf,
2584 (const void *)cache_resource->buf,
2586 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d++",
2587 (void *)cache_resource,
2588 rte_atomic32_read(&cache_resource->refcnt));
2589 rte_atomic32_inc(&cache_resource->refcnt);
2590 dev_flow->handle->dvh.rix_encap_decap = idx;
2591 dev_flow->dv.encap_decap = cache_resource;
2595 /* Register new encap/decap resource. */
2596 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
2597 &dev_flow->handle->dvh.rix_encap_decap);
2598 if (!cache_resource)
2599 return rte_flow_error_set(error, ENOMEM,
2600 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2601 "cannot allocate resource memory");
2602 *cache_resource = *resource;
2603 cache_resource->verbs_action =
2604 mlx5_glue->dv_create_flow_action_packet_reformat
2605 (sh->ctx, cache_resource->reformat_type,
2606 cache_resource->ft_type, domain, cache_resource->flags,
2607 cache_resource->size,
2608 (cache_resource->size ? cache_resource->buf : NULL));
2609 if (!cache_resource->verbs_action) {
2610 rte_free(cache_resource);
2611 return rte_flow_error_set(error, ENOMEM,
2612 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2613 NULL, "cannot create action");
2615 rte_atomic32_init(&cache_resource->refcnt);
2616 rte_atomic32_inc(&cache_resource->refcnt);
2617 ILIST_INSERT(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &sh->encaps_decaps,
2618 dev_flow->handle->dvh.rix_encap_decap, cache_resource,
2620 dev_flow->dv.encap_decap = cache_resource;
2621 DRV_LOG(DEBUG, "new encap/decap resource %p: refcnt %d++",
2622 (void *)cache_resource,
2623 rte_atomic32_read(&cache_resource->refcnt));
2628 * Find existing table jump resource or create and register a new one.
2630 * @param[in, out] dev
2631 * Pointer to rte_eth_dev structure.
2632 * @param[in, out] tbl
2633 * Pointer to flow table resource.
2634 * @parm[in, out] dev_flow
2635 * Pointer to the dev_flow.
2637 * pointer to error structure.
2640 * 0 on success otherwise -errno and errno is set.
2643 flow_dv_jump_tbl_resource_register
2644 (struct rte_eth_dev *dev __rte_unused,
2645 struct mlx5_flow_tbl_resource *tbl,
2646 struct mlx5_flow *dev_flow,
2647 struct rte_flow_error *error)
2649 struct mlx5_flow_tbl_data_entry *tbl_data =
2650 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
2654 cnt = rte_atomic32_read(&tbl_data->jump.refcnt);
2656 tbl_data->jump.action =
2657 mlx5_glue->dr_create_flow_action_dest_flow_tbl
2659 if (!tbl_data->jump.action)
2660 return rte_flow_error_set(error, ENOMEM,
2661 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2662 NULL, "cannot create jump action");
2663 DRV_LOG(DEBUG, "new jump table resource %p: refcnt %d++",
2664 (void *)&tbl_data->jump, cnt);
2666 /* old jump should not make the table ref++. */
2667 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
2668 MLX5_ASSERT(tbl_data->jump.action);
2669 DRV_LOG(DEBUG, "existed jump table resource %p: refcnt %d++",
2670 (void *)&tbl_data->jump, cnt);
2672 rte_atomic32_inc(&tbl_data->jump.refcnt);
2673 dev_flow->handle->rix_jump = tbl_data->idx;
2674 dev_flow->dv.jump = &tbl_data->jump;
2679 * Find existing table port ID resource or create and register a new one.
2681 * @param[in, out] dev
2682 * Pointer to rte_eth_dev structure.
2683 * @param[in, out] resource
2684 * Pointer to port ID action resource.
2685 * @parm[in, out] dev_flow
2686 * Pointer to the dev_flow.
2688 * pointer to error structure.
2691 * 0 on success otherwise -errno and errno is set.
2694 flow_dv_port_id_action_resource_register
2695 (struct rte_eth_dev *dev,
2696 struct mlx5_flow_dv_port_id_action_resource *resource,
2697 struct mlx5_flow *dev_flow,
2698 struct rte_flow_error *error)
2700 struct mlx5_priv *priv = dev->data->dev_private;
2701 struct mlx5_dev_ctx_shared *sh = priv->sh;
2702 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
2705 /* Lookup a matching resource from cache. */
2706 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_PORT_ID], sh->port_id_action_list,
2707 idx, cache_resource, next) {
2708 if (resource->port_id == cache_resource->port_id) {
2709 DRV_LOG(DEBUG, "port id action resource resource %p: "
2711 (void *)cache_resource,
2712 rte_atomic32_read(&cache_resource->refcnt));
2713 rte_atomic32_inc(&cache_resource->refcnt);
2714 dev_flow->handle->rix_port_id_action = idx;
2715 dev_flow->dv.port_id_action = cache_resource;
2719 /* Register new port id action resource. */
2720 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID],
2721 &dev_flow->handle->rix_port_id_action);
2722 if (!cache_resource)
2723 return rte_flow_error_set(error, ENOMEM,
2724 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2725 "cannot allocate resource memory");
2726 *cache_resource = *resource;
2728 * Depending on rdma_core version the glue routine calls
2729 * either mlx5dv_dr_action_create_dest_ib_port(domain, dev_port)
2730 * or mlx5dv_dr_action_create_dest_vport(domain, vport_id).
2732 cache_resource->action =
2733 mlx5_glue->dr_create_flow_action_dest_port
2734 (priv->sh->fdb_domain, resource->port_id);
2735 if (!cache_resource->action) {
2736 rte_free(cache_resource);
2737 return rte_flow_error_set(error, ENOMEM,
2738 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2739 NULL, "cannot create action");
2741 rte_atomic32_init(&cache_resource->refcnt);
2742 rte_atomic32_inc(&cache_resource->refcnt);
2743 ILIST_INSERT(sh->ipool[MLX5_IPOOL_PORT_ID], &sh->port_id_action_list,
2744 dev_flow->handle->rix_port_id_action, cache_resource,
2746 dev_flow->dv.port_id_action = cache_resource;
2747 DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++",
2748 (void *)cache_resource,
2749 rte_atomic32_read(&cache_resource->refcnt));
2754 * Find existing push vlan resource or create and register a new one.
2756 * @param [in, out] dev
2757 * Pointer to rte_eth_dev structure.
2758 * @param[in, out] resource
2759 * Pointer to port ID action resource.
2760 * @parm[in, out] dev_flow
2761 * Pointer to the dev_flow.
2763 * pointer to error structure.
2766 * 0 on success otherwise -errno and errno is set.
2769 flow_dv_push_vlan_action_resource_register
2770 (struct rte_eth_dev *dev,
2771 struct mlx5_flow_dv_push_vlan_action_resource *resource,
2772 struct mlx5_flow *dev_flow,
2773 struct rte_flow_error *error)
2775 struct mlx5_priv *priv = dev->data->dev_private;
2776 struct mlx5_dev_ctx_shared *sh = priv->sh;
2777 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
2778 struct mlx5dv_dr_domain *domain;
2781 /* Lookup a matching resource from cache. */
2782 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2783 sh->push_vlan_action_list, idx, cache_resource, next) {
2784 if (resource->vlan_tag == cache_resource->vlan_tag &&
2785 resource->ft_type == cache_resource->ft_type) {
2786 DRV_LOG(DEBUG, "push-VLAN action resource resource %p: "
2788 (void *)cache_resource,
2789 rte_atomic32_read(&cache_resource->refcnt));
2790 rte_atomic32_inc(&cache_resource->refcnt);
2791 dev_flow->handle->dvh.rix_push_vlan = idx;
2792 dev_flow->dv.push_vlan_res = cache_resource;
2796 /* Register new push_vlan action resource. */
2797 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2798 &dev_flow->handle->dvh.rix_push_vlan);
2799 if (!cache_resource)
2800 return rte_flow_error_set(error, ENOMEM,
2801 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2802 "cannot allocate resource memory");
2803 *cache_resource = *resource;
2804 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2805 domain = sh->fdb_domain;
2806 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2807 domain = sh->rx_domain;
2809 domain = sh->tx_domain;
2810 cache_resource->action =
2811 mlx5_glue->dr_create_flow_action_push_vlan(domain,
2812 resource->vlan_tag);
2813 if (!cache_resource->action) {
2814 rte_free(cache_resource);
2815 return rte_flow_error_set(error, ENOMEM,
2816 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2817 NULL, "cannot create action");
2819 rte_atomic32_init(&cache_resource->refcnt);
2820 rte_atomic32_inc(&cache_resource->refcnt);
2821 ILIST_INSERT(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2822 &sh->push_vlan_action_list,
2823 dev_flow->handle->dvh.rix_push_vlan,
2824 cache_resource, next);
2825 dev_flow->dv.push_vlan_res = cache_resource;
2826 DRV_LOG(DEBUG, "new push vlan action resource %p: refcnt %d++",
2827 (void *)cache_resource,
2828 rte_atomic32_read(&cache_resource->refcnt));
2832 * Get the size of specific rte_flow_item_type
2834 * @param[in] item_type
2835 * Tested rte_flow_item_type.
2838 * sizeof struct item_type, 0 if void or irrelevant.
2841 flow_dv_get_item_len(const enum rte_flow_item_type item_type)
2845 switch (item_type) {
2846 case RTE_FLOW_ITEM_TYPE_ETH:
2847 retval = sizeof(struct rte_flow_item_eth);
2849 case RTE_FLOW_ITEM_TYPE_VLAN:
2850 retval = sizeof(struct rte_flow_item_vlan);
2852 case RTE_FLOW_ITEM_TYPE_IPV4:
2853 retval = sizeof(struct rte_flow_item_ipv4);
2855 case RTE_FLOW_ITEM_TYPE_IPV6:
2856 retval = sizeof(struct rte_flow_item_ipv6);
2858 case RTE_FLOW_ITEM_TYPE_UDP:
2859 retval = sizeof(struct rte_flow_item_udp);
2861 case RTE_FLOW_ITEM_TYPE_TCP:
2862 retval = sizeof(struct rte_flow_item_tcp);
2864 case RTE_FLOW_ITEM_TYPE_VXLAN:
2865 retval = sizeof(struct rte_flow_item_vxlan);
2867 case RTE_FLOW_ITEM_TYPE_GRE:
2868 retval = sizeof(struct rte_flow_item_gre);
2870 case RTE_FLOW_ITEM_TYPE_NVGRE:
2871 retval = sizeof(struct rte_flow_item_nvgre);
2873 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2874 retval = sizeof(struct rte_flow_item_vxlan_gpe);
2876 case RTE_FLOW_ITEM_TYPE_MPLS:
2877 retval = sizeof(struct rte_flow_item_mpls);
2879 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
2887 #define MLX5_ENCAP_IPV4_VERSION 0x40
2888 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
2889 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
2890 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
2891 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
2892 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
2893 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
2896 * Convert the encap action data from list of rte_flow_item to raw buffer
2899 * Pointer to rte_flow_item objects list.
2901 * Pointer to the output buffer.
2903 * Pointer to the output buffer size.
2905 * Pointer to the error structure.
2908 * 0 on success, a negative errno value otherwise and rte_errno is set.
2911 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
2912 size_t *size, struct rte_flow_error *error)
2914 struct rte_ether_hdr *eth = NULL;
2915 struct rte_vlan_hdr *vlan = NULL;
2916 struct rte_ipv4_hdr *ipv4 = NULL;
2917 struct rte_ipv6_hdr *ipv6 = NULL;
2918 struct rte_udp_hdr *udp = NULL;
2919 struct rte_vxlan_hdr *vxlan = NULL;
2920 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
2921 struct rte_gre_hdr *gre = NULL;
2923 size_t temp_size = 0;
2926 return rte_flow_error_set(error, EINVAL,
2927 RTE_FLOW_ERROR_TYPE_ACTION,
2928 NULL, "invalid empty data");
2929 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2930 len = flow_dv_get_item_len(items->type);
2931 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
2932 return rte_flow_error_set(error, EINVAL,
2933 RTE_FLOW_ERROR_TYPE_ACTION,
2934 (void *)items->type,
2935 "items total size is too big"
2936 " for encap action");
2937 rte_memcpy((void *)&buf[temp_size], items->spec, len);
2938 switch (items->type) {
2939 case RTE_FLOW_ITEM_TYPE_ETH:
2940 eth = (struct rte_ether_hdr *)&buf[temp_size];
2942 case RTE_FLOW_ITEM_TYPE_VLAN:
2943 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
2945 return rte_flow_error_set(error, EINVAL,
2946 RTE_FLOW_ERROR_TYPE_ACTION,
2947 (void *)items->type,
2948 "eth header not found");
2949 if (!eth->ether_type)
2950 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
2952 case RTE_FLOW_ITEM_TYPE_IPV4:
2953 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
2955 return rte_flow_error_set(error, EINVAL,
2956 RTE_FLOW_ERROR_TYPE_ACTION,
2957 (void *)items->type,
2958 "neither eth nor vlan"
2960 if (vlan && !vlan->eth_proto)
2961 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2962 else if (eth && !eth->ether_type)
2963 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2964 if (!ipv4->version_ihl)
2965 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
2966 MLX5_ENCAP_IPV4_IHL_MIN;
2967 if (!ipv4->time_to_live)
2968 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
2970 case RTE_FLOW_ITEM_TYPE_IPV6:
2971 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
2973 return rte_flow_error_set(error, EINVAL,
2974 RTE_FLOW_ERROR_TYPE_ACTION,
2975 (void *)items->type,
2976 "neither eth nor vlan"
2978 if (vlan && !vlan->eth_proto)
2979 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2980 else if (eth && !eth->ether_type)
2981 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2982 if (!ipv6->vtc_flow)
2984 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
2985 if (!ipv6->hop_limits)
2986 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
2988 case RTE_FLOW_ITEM_TYPE_UDP:
2989 udp = (struct rte_udp_hdr *)&buf[temp_size];
2991 return rte_flow_error_set(error, EINVAL,
2992 RTE_FLOW_ERROR_TYPE_ACTION,
2993 (void *)items->type,
2994 "ip header not found");
2995 if (ipv4 && !ipv4->next_proto_id)
2996 ipv4->next_proto_id = IPPROTO_UDP;
2997 else if (ipv6 && !ipv6->proto)
2998 ipv6->proto = IPPROTO_UDP;
3000 case RTE_FLOW_ITEM_TYPE_VXLAN:
3001 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
3003 return rte_flow_error_set(error, EINVAL,
3004 RTE_FLOW_ERROR_TYPE_ACTION,
3005 (void *)items->type,
3006 "udp header not found");
3008 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
3009 if (!vxlan->vx_flags)
3011 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
3013 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3014 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
3016 return rte_flow_error_set(error, EINVAL,
3017 RTE_FLOW_ERROR_TYPE_ACTION,
3018 (void *)items->type,
3019 "udp header not found");
3020 if (!vxlan_gpe->proto)
3021 return rte_flow_error_set(error, EINVAL,
3022 RTE_FLOW_ERROR_TYPE_ACTION,
3023 (void *)items->type,
3024 "next protocol not found");
3027 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
3028 if (!vxlan_gpe->vx_flags)
3029 vxlan_gpe->vx_flags =
3030 MLX5_ENCAP_VXLAN_GPE_FLAGS;
3032 case RTE_FLOW_ITEM_TYPE_GRE:
3033 case RTE_FLOW_ITEM_TYPE_NVGRE:
3034 gre = (struct rte_gre_hdr *)&buf[temp_size];
3036 return rte_flow_error_set(error, EINVAL,
3037 RTE_FLOW_ERROR_TYPE_ACTION,
3038 (void *)items->type,
3039 "next protocol not found");
3041 return rte_flow_error_set(error, EINVAL,
3042 RTE_FLOW_ERROR_TYPE_ACTION,
3043 (void *)items->type,
3044 "ip header not found");
3045 if (ipv4 && !ipv4->next_proto_id)
3046 ipv4->next_proto_id = IPPROTO_GRE;
3047 else if (ipv6 && !ipv6->proto)
3048 ipv6->proto = IPPROTO_GRE;
3050 case RTE_FLOW_ITEM_TYPE_VOID:
3053 return rte_flow_error_set(error, EINVAL,
3054 RTE_FLOW_ERROR_TYPE_ACTION,
3055 (void *)items->type,
3056 "unsupported item type");
3066 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
3068 struct rte_ether_hdr *eth = NULL;
3069 struct rte_vlan_hdr *vlan = NULL;
3070 struct rte_ipv6_hdr *ipv6 = NULL;
3071 struct rte_udp_hdr *udp = NULL;
3075 eth = (struct rte_ether_hdr *)data;
3076 next_hdr = (char *)(eth + 1);
3077 proto = RTE_BE16(eth->ether_type);
3080 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
3081 vlan = (struct rte_vlan_hdr *)next_hdr;
3082 proto = RTE_BE16(vlan->eth_proto);
3083 next_hdr += sizeof(struct rte_vlan_hdr);
3086 /* HW calculates IPv4 csum. no need to proceed */
3087 if (proto == RTE_ETHER_TYPE_IPV4)
3090 /* non IPv4/IPv6 header. not supported */
3091 if (proto != RTE_ETHER_TYPE_IPV6) {
3092 return rte_flow_error_set(error, ENOTSUP,
3093 RTE_FLOW_ERROR_TYPE_ACTION,
3094 NULL, "Cannot offload non IPv4/IPv6");
3097 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
3099 /* ignore non UDP */
3100 if (ipv6->proto != IPPROTO_UDP)
3103 udp = (struct rte_udp_hdr *)(ipv6 + 1);
3104 udp->dgram_cksum = 0;
3110 * Convert L2 encap action to DV specification.
3113 * Pointer to rte_eth_dev structure.
3115 * Pointer to action structure.
3116 * @param[in, out] dev_flow
3117 * Pointer to the mlx5_flow.
3118 * @param[in] transfer
3119 * Mark if the flow is E-Switch flow.
3121 * Pointer to the error structure.
3124 * 0 on success, a negative errno value otherwise and rte_errno is set.
3127 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
3128 const struct rte_flow_action *action,
3129 struct mlx5_flow *dev_flow,
3131 struct rte_flow_error *error)
3133 const struct rte_flow_item *encap_data;
3134 const struct rte_flow_action_raw_encap *raw_encap_data;
3135 struct mlx5_flow_dv_encap_decap_resource res = {
3137 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
3138 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3139 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
3142 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
3144 (const struct rte_flow_action_raw_encap *)action->conf;
3145 res.size = raw_encap_data->size;
3146 memcpy(res.buf, raw_encap_data->data, res.size);
3148 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
3150 ((const struct rte_flow_action_vxlan_encap *)
3151 action->conf)->definition;
3154 ((const struct rte_flow_action_nvgre_encap *)
3155 action->conf)->definition;
3156 if (flow_dv_convert_encap_data(encap_data, res.buf,
3160 if (flow_dv_zero_encap_udp_csum(res.buf, error))
3162 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3163 return rte_flow_error_set(error, EINVAL,
3164 RTE_FLOW_ERROR_TYPE_ACTION,
3165 NULL, "can't create L2 encap action");
3170 * Convert L2 decap action to DV specification.
3173 * Pointer to rte_eth_dev structure.
3174 * @param[in, out] dev_flow
3175 * Pointer to the mlx5_flow.
3176 * @param[in] transfer
3177 * Mark if the flow is E-Switch flow.
3179 * Pointer to the error structure.
3182 * 0 on success, a negative errno value otherwise and rte_errno is set.
3185 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
3186 struct mlx5_flow *dev_flow,
3188 struct rte_flow_error *error)
3190 struct mlx5_flow_dv_encap_decap_resource res = {
3193 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
3194 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3195 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
3198 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3199 return rte_flow_error_set(error, EINVAL,
3200 RTE_FLOW_ERROR_TYPE_ACTION,
3201 NULL, "can't create L2 decap action");
3206 * Convert raw decap/encap (L3 tunnel) action to DV specification.
3209 * Pointer to rte_eth_dev structure.
3211 * Pointer to action structure.
3212 * @param[in, out] dev_flow
3213 * Pointer to the mlx5_flow.
3215 * Pointer to the flow attributes.
3217 * Pointer to the error structure.
3220 * 0 on success, a negative errno value otherwise and rte_errno is set.
3223 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
3224 const struct rte_flow_action *action,
3225 struct mlx5_flow *dev_flow,
3226 const struct rte_flow_attr *attr,
3227 struct rte_flow_error *error)
3229 const struct rte_flow_action_raw_encap *encap_data;
3230 struct mlx5_flow_dv_encap_decap_resource res;
3232 memset(&res, 0, sizeof(res));
3233 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
3234 res.size = encap_data->size;
3235 memcpy(res.buf, encap_data->data, res.size);
3236 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
3237 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
3238 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
3240 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3242 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3243 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3244 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3245 return rte_flow_error_set(error, EINVAL,
3246 RTE_FLOW_ERROR_TYPE_ACTION,
3247 NULL, "can't create encap action");
3252 * Create action push VLAN.
3255 * Pointer to rte_eth_dev structure.
3257 * Pointer to the flow attributes.
3259 * Pointer to the vlan to push to the Ethernet header.
3260 * @param[in, out] dev_flow
3261 * Pointer to the mlx5_flow.
3263 * Pointer to the error structure.
3266 * 0 on success, a negative errno value otherwise and rte_errno is set.
3269 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
3270 const struct rte_flow_attr *attr,
3271 const struct rte_vlan_hdr *vlan,
3272 struct mlx5_flow *dev_flow,
3273 struct rte_flow_error *error)
3275 struct mlx5_flow_dv_push_vlan_action_resource res;
3277 memset(&res, 0, sizeof(res));
3279 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
3282 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3284 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3285 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3286 return flow_dv_push_vlan_action_resource_register
3287 (dev, &res, dev_flow, error);
3291 * Validate the modify-header actions.
3293 * @param[in] action_flags
3294 * Holds the actions detected until now.
3296 * Pointer to the modify action.
3298 * Pointer to error structure.
3301 * 0 on success, a negative errno value otherwise and rte_errno is set.
3304 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
3305 const struct rte_flow_action *action,
3306 struct rte_flow_error *error)
3308 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
3309 return rte_flow_error_set(error, EINVAL,
3310 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3311 NULL, "action configuration not set");
3312 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3313 return rte_flow_error_set(error, EINVAL,
3314 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3315 "can't have encap action before"
3321 * Validate the modify-header MAC address actions.
3323 * @param[in] action_flags
3324 * Holds the actions detected until now.
3326 * Pointer to the modify action.
3327 * @param[in] item_flags
3328 * Holds the items detected.
3330 * Pointer to error structure.
3333 * 0 on success, a negative errno value otherwise and rte_errno is set.
3336 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
3337 const struct rte_flow_action *action,
3338 const uint64_t item_flags,
3339 struct rte_flow_error *error)
3343 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3345 if (!(item_flags & MLX5_FLOW_LAYER_L2))
3346 return rte_flow_error_set(error, EINVAL,
3347 RTE_FLOW_ERROR_TYPE_ACTION,
3349 "no L2 item in pattern");
3355 * Validate the modify-header IPv4 address actions.
3357 * @param[in] action_flags
3358 * Holds the actions detected until now.
3360 * Pointer to the modify action.
3361 * @param[in] item_flags
3362 * Holds the items detected.
3364 * Pointer to error structure.
3367 * 0 on success, a negative errno value otherwise and rte_errno is set.
3370 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
3371 const struct rte_flow_action *action,
3372 const uint64_t item_flags,
3373 struct rte_flow_error *error)
3378 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3380 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3381 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
3382 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3383 if (!(item_flags & layer))
3384 return rte_flow_error_set(error, EINVAL,
3385 RTE_FLOW_ERROR_TYPE_ACTION,
3387 "no ipv4 item in pattern");
3393 * Validate the modify-header IPv6 address actions.
3395 * @param[in] action_flags
3396 * Holds the actions detected until now.
3398 * Pointer to the modify action.
3399 * @param[in] item_flags
3400 * Holds the items detected.
3402 * Pointer to error structure.
3405 * 0 on success, a negative errno value otherwise and rte_errno is set.
3408 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
3409 const struct rte_flow_action *action,
3410 const uint64_t item_flags,
3411 struct rte_flow_error *error)
3416 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3418 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3419 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
3420 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3421 if (!(item_flags & layer))
3422 return rte_flow_error_set(error, EINVAL,
3423 RTE_FLOW_ERROR_TYPE_ACTION,
3425 "no ipv6 item in pattern");
3431 * Validate the modify-header TP actions.
3433 * @param[in] action_flags
3434 * Holds the actions detected until now.
3436 * Pointer to the modify action.
3437 * @param[in] item_flags
3438 * Holds the items detected.
3440 * Pointer to error structure.
3443 * 0 on success, a negative errno value otherwise and rte_errno is set.
3446 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
3447 const struct rte_flow_action *action,
3448 const uint64_t item_flags,
3449 struct rte_flow_error *error)
3454 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3456 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3457 MLX5_FLOW_LAYER_INNER_L4 :
3458 MLX5_FLOW_LAYER_OUTER_L4;
3459 if (!(item_flags & layer))
3460 return rte_flow_error_set(error, EINVAL,
3461 RTE_FLOW_ERROR_TYPE_ACTION,
3462 NULL, "no transport layer "
3469 * Validate the modify-header actions of increment/decrement
3470 * TCP Sequence-number.
3472 * @param[in] action_flags
3473 * Holds the actions detected until now.
3475 * Pointer to the modify action.
3476 * @param[in] item_flags
3477 * Holds the items detected.
3479 * Pointer to error structure.
3482 * 0 on success, a negative errno value otherwise and rte_errno is set.
3485 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
3486 const struct rte_flow_action *action,
3487 const uint64_t item_flags,
3488 struct rte_flow_error *error)
3493 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3495 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3496 MLX5_FLOW_LAYER_INNER_L4_TCP :
3497 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3498 if (!(item_flags & layer))
3499 return rte_flow_error_set(error, EINVAL,
3500 RTE_FLOW_ERROR_TYPE_ACTION,
3501 NULL, "no TCP item in"
3503 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
3504 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
3505 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
3506 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
3507 return rte_flow_error_set(error, EINVAL,
3508 RTE_FLOW_ERROR_TYPE_ACTION,
3510 "cannot decrease and increase"
3511 " TCP sequence number"
3512 " at the same time");
3518 * Validate the modify-header actions of increment/decrement
3519 * TCP Acknowledgment number.
3521 * @param[in] action_flags
3522 * Holds the actions detected until now.
3524 * Pointer to the modify action.
3525 * @param[in] item_flags
3526 * Holds the items detected.
3528 * Pointer to error structure.
3531 * 0 on success, a negative errno value otherwise and rte_errno is set.
3534 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
3535 const struct rte_flow_action *action,
3536 const uint64_t item_flags,
3537 struct rte_flow_error *error)
3542 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3544 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3545 MLX5_FLOW_LAYER_INNER_L4_TCP :
3546 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3547 if (!(item_flags & layer))
3548 return rte_flow_error_set(error, EINVAL,
3549 RTE_FLOW_ERROR_TYPE_ACTION,
3550 NULL, "no TCP item in"
3552 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
3553 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
3554 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
3555 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
3556 return rte_flow_error_set(error, EINVAL,
3557 RTE_FLOW_ERROR_TYPE_ACTION,
3559 "cannot decrease and increase"
3560 " TCP acknowledgment number"
3561 " at the same time");
3567 * Validate the modify-header TTL actions.
3569 * @param[in] action_flags
3570 * Holds the actions detected until now.
3572 * Pointer to the modify action.
3573 * @param[in] item_flags
3574 * Holds the items detected.
3576 * Pointer to error structure.
3579 * 0 on success, a negative errno value otherwise and rte_errno is set.
3582 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
3583 const struct rte_flow_action *action,
3584 const uint64_t item_flags,
3585 struct rte_flow_error *error)
3590 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3592 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3593 MLX5_FLOW_LAYER_INNER_L3 :
3594 MLX5_FLOW_LAYER_OUTER_L3;
3595 if (!(item_flags & layer))
3596 return rte_flow_error_set(error, EINVAL,
3597 RTE_FLOW_ERROR_TYPE_ACTION,
3599 "no IP protocol in pattern");
3605 * Validate jump action.
3608 * Pointer to the jump action.
3609 * @param[in] action_flags
3610 * Holds the actions detected until now.
3611 * @param[in] attributes
3612 * Pointer to flow attributes
3613 * @param[in] external
3614 * Action belongs to flow rule created by request external to PMD.
3616 * Pointer to error structure.
3619 * 0 on success, a negative errno value otherwise and rte_errno is set.
3622 flow_dv_validate_action_jump(const struct rte_flow_action *action,
3623 uint64_t action_flags,
3624 const struct rte_flow_attr *attributes,
3625 bool external, struct rte_flow_error *error)
3627 uint32_t target_group, table;
3630 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3631 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3632 return rte_flow_error_set(error, EINVAL,
3633 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3634 "can't have 2 fate actions in"
3636 if (action_flags & MLX5_FLOW_ACTION_METER)
3637 return rte_flow_error_set(error, ENOTSUP,
3638 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3639 "jump with meter not support");
3641 return rte_flow_error_set(error, EINVAL,
3642 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3643 NULL, "action configuration not set");
3645 ((const struct rte_flow_action_jump *)action->conf)->group;
3646 ret = mlx5_flow_group_to_table(attributes, external, target_group,
3647 true, &table, error);
3650 if (attributes->group == target_group)
3651 return rte_flow_error_set(error, EINVAL,
3652 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3653 "target group must be other than"
3654 " the current flow group");
3659 * Validate the port_id action.
3662 * Pointer to rte_eth_dev structure.
3663 * @param[in] action_flags
3664 * Bit-fields that holds the actions detected until now.
3666 * Port_id RTE action structure.
3668 * Attributes of flow that includes this action.
3670 * Pointer to error structure.
3673 * 0 on success, a negative errno value otherwise and rte_errno is set.
3676 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
3677 uint64_t action_flags,
3678 const struct rte_flow_action *action,
3679 const struct rte_flow_attr *attr,
3680 struct rte_flow_error *error)
3682 const struct rte_flow_action_port_id *port_id;
3683 struct mlx5_priv *act_priv;
3684 struct mlx5_priv *dev_priv;
3687 if (!attr->transfer)
3688 return rte_flow_error_set(error, ENOTSUP,
3689 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3691 "port id action is valid in transfer"
3693 if (!action || !action->conf)
3694 return rte_flow_error_set(error, ENOTSUP,
3695 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3697 "port id action parameters must be"
3699 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3700 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3701 return rte_flow_error_set(error, EINVAL,
3702 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3703 "can have only one fate actions in"
3705 dev_priv = mlx5_dev_to_eswitch_info(dev);
3707 return rte_flow_error_set(error, rte_errno,
3708 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3710 "failed to obtain E-Switch info");
3711 port_id = action->conf;
3712 port = port_id->original ? dev->data->port_id : port_id->id;
3713 act_priv = mlx5_port_to_eswitch_info(port, false);
3715 return rte_flow_error_set
3717 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
3718 "failed to obtain E-Switch port id for port");
3719 if (act_priv->domain_id != dev_priv->domain_id)
3720 return rte_flow_error_set
3722 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3723 "port does not belong to"
3724 " E-Switch being configured");
3729 * Get the maximum number of modify header actions.
3732 * Pointer to rte_eth_dev structure.
3734 * Flags bits to check if root level.
3737 * Max number of modify header actions device can support.
3739 static inline unsigned int
3740 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
3744 * There's no way to directly query the max capacity from FW.
3745 * The maximal value on root table should be assumed to be supported.
3747 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
3748 return MLX5_MAX_MODIFY_NUM;
3750 return MLX5_ROOT_TBL_MODIFY_NUM;
3754 * Validate the meter action.
3757 * Pointer to rte_eth_dev structure.
3758 * @param[in] action_flags
3759 * Bit-fields that holds the actions detected until now.
3761 * Pointer to the meter action.
3763 * Attributes of flow that includes this action.
3765 * Pointer to error structure.
3768 * 0 on success, a negative errno value otherwise and rte_ernno is set.
3771 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
3772 uint64_t action_flags,
3773 const struct rte_flow_action *action,
3774 const struct rte_flow_attr *attr,
3775 struct rte_flow_error *error)
3777 struct mlx5_priv *priv = dev->data->dev_private;
3778 const struct rte_flow_action_meter *am = action->conf;
3779 struct mlx5_flow_meter *fm;
3782 return rte_flow_error_set(error, EINVAL,
3783 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3784 "meter action conf is NULL");
3786 if (action_flags & MLX5_FLOW_ACTION_METER)
3787 return rte_flow_error_set(error, ENOTSUP,
3788 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3789 "meter chaining not support");
3790 if (action_flags & MLX5_FLOW_ACTION_JUMP)
3791 return rte_flow_error_set(error, ENOTSUP,
3792 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3793 "meter with jump not support");
3795 return rte_flow_error_set(error, ENOTSUP,
3796 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3798 "meter action not supported");
3799 fm = mlx5_flow_meter_find(priv, am->mtr_id);
3801 return rte_flow_error_set(error, EINVAL,
3802 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3804 if (fm->ref_cnt && (!(fm->transfer == attr->transfer ||
3805 (!fm->ingress && !attr->ingress && attr->egress) ||
3806 (!fm->egress && !attr->egress && attr->ingress))))
3807 return rte_flow_error_set(error, EINVAL,
3808 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3809 "Flow attributes are either invalid "
3810 "or have a conflict with current "
3811 "meter attributes");
3816 * Validate the age action.
3818 * @param[in] action_flags
3819 * Holds the actions detected until now.
3821 * Pointer to the age action.
3823 * Pointer to the Ethernet device structure.
3825 * Pointer to error structure.
3828 * 0 on success, a negative errno value otherwise and rte_errno is set.
3831 flow_dv_validate_action_age(uint64_t action_flags,
3832 const struct rte_flow_action *action,
3833 struct rte_eth_dev *dev,
3834 struct rte_flow_error *error)
3836 struct mlx5_priv *priv = dev->data->dev_private;
3837 const struct rte_flow_action_age *age = action->conf;
3839 if (!priv->config.devx || priv->counter_fallback)
3840 return rte_flow_error_set(error, ENOTSUP,
3841 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3843 "age action not supported");
3844 if (!(action->conf))
3845 return rte_flow_error_set(error, EINVAL,
3846 RTE_FLOW_ERROR_TYPE_ACTION, action,
3847 "configuration cannot be null");
3848 if (age->timeout >= UINT16_MAX / 2 / 10)
3849 return rte_flow_error_set(error, ENOTSUP,
3850 RTE_FLOW_ERROR_TYPE_ACTION, action,
3851 "Max age time: 3275 seconds");
3852 if (action_flags & MLX5_FLOW_ACTION_AGE)
3853 return rte_flow_error_set(error, EINVAL,
3854 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3855 "Duplicate age ctions set");
3860 * Validate the modify-header IPv4 DSCP actions.
3862 * @param[in] action_flags
3863 * Holds the actions detected until now.
3865 * Pointer to the modify action.
3866 * @param[in] item_flags
3867 * Holds the items detected.
3869 * Pointer to error structure.
3872 * 0 on success, a negative errno value otherwise and rte_errno is set.
3875 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
3876 const struct rte_flow_action *action,
3877 const uint64_t item_flags,
3878 struct rte_flow_error *error)
3882 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3884 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
3885 return rte_flow_error_set(error, EINVAL,
3886 RTE_FLOW_ERROR_TYPE_ACTION,
3888 "no ipv4 item in pattern");
3894 * Validate the modify-header IPv6 DSCP actions.
3896 * @param[in] action_flags
3897 * Holds the actions detected until now.
3899 * Pointer to the modify action.
3900 * @param[in] item_flags
3901 * Holds the items detected.
3903 * Pointer to error structure.
3906 * 0 on success, a negative errno value otherwise and rte_errno is set.
3909 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
3910 const struct rte_flow_action *action,
3911 const uint64_t item_flags,
3912 struct rte_flow_error *error)
3916 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3918 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
3919 return rte_flow_error_set(error, EINVAL,
3920 RTE_FLOW_ERROR_TYPE_ACTION,
3922 "no ipv6 item in pattern");
3928 * Find existing modify-header resource or create and register a new one.
3930 * @param dev[in, out]
3931 * Pointer to rte_eth_dev structure.
3932 * @param[in, out] resource
3933 * Pointer to modify-header resource.
3934 * @parm[in, out] dev_flow
3935 * Pointer to the dev_flow.
3937 * pointer to error structure.
3940 * 0 on success otherwise -errno and errno is set.
3943 flow_dv_modify_hdr_resource_register
3944 (struct rte_eth_dev *dev,
3945 struct mlx5_flow_dv_modify_hdr_resource *resource,
3946 struct mlx5_flow *dev_flow,
3947 struct rte_flow_error *error)
3949 struct mlx5_priv *priv = dev->data->dev_private;
3950 struct mlx5_dev_ctx_shared *sh = priv->sh;
3951 struct mlx5_flow_dv_modify_hdr_resource *cache_resource;
3952 struct mlx5dv_dr_domain *ns;
3953 uint32_t actions_len;
3955 resource->flags = dev_flow->dv.group ? 0 :
3956 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
3957 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
3959 return rte_flow_error_set(error, EOVERFLOW,
3960 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3961 "too many modify header items");
3962 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3963 ns = sh->fdb_domain;
3964 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
3968 /* Lookup a matching resource from cache. */
3969 actions_len = resource->actions_num * sizeof(resource->actions[0]);
3970 LIST_FOREACH(cache_resource, &sh->modify_cmds, next) {
3971 if (resource->ft_type == cache_resource->ft_type &&
3972 resource->actions_num == cache_resource->actions_num &&
3973 resource->flags == cache_resource->flags &&
3974 !memcmp((const void *)resource->actions,
3975 (const void *)cache_resource->actions,
3977 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d++",
3978 (void *)cache_resource,
3979 rte_atomic32_read(&cache_resource->refcnt));
3980 rte_atomic32_inc(&cache_resource->refcnt);
3981 dev_flow->handle->dvh.modify_hdr = cache_resource;
3985 /* Register new modify-header resource. */
3986 cache_resource = rte_calloc(__func__, 1,
3987 sizeof(*cache_resource) + actions_len, 0);
3988 if (!cache_resource)
3989 return rte_flow_error_set(error, ENOMEM,
3990 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3991 "cannot allocate resource memory");
3992 *cache_resource = *resource;
3993 rte_memcpy(cache_resource->actions, resource->actions, actions_len);
3994 cache_resource->verbs_action =
3995 mlx5_glue->dv_create_flow_action_modify_header
3996 (sh->ctx, cache_resource->ft_type, ns,
3997 cache_resource->flags, actions_len,
3998 (uint64_t *)cache_resource->actions);
3999 if (!cache_resource->verbs_action) {
4000 rte_free(cache_resource);
4001 return rte_flow_error_set(error, ENOMEM,
4002 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4003 NULL, "cannot create action");
4005 rte_atomic32_init(&cache_resource->refcnt);
4006 rte_atomic32_inc(&cache_resource->refcnt);
4007 LIST_INSERT_HEAD(&sh->modify_cmds, cache_resource, next);
4008 dev_flow->handle->dvh.modify_hdr = cache_resource;
4009 DRV_LOG(DEBUG, "new modify-header resource %p: refcnt %d++",
4010 (void *)cache_resource,
4011 rte_atomic32_read(&cache_resource->refcnt));
4016 * Get DV flow counter by index.
4019 * Pointer to the Ethernet device structure.
4021 * mlx5 flow counter index in the container.
4023 * mlx5 flow counter pool in the container,
4026 * Pointer to the counter, NULL otherwise.
4028 static struct mlx5_flow_counter *
4029 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
4031 struct mlx5_flow_counter_pool **ppool)
4033 struct mlx5_priv *priv = dev->data->dev_private;
4034 struct mlx5_pools_container *cont;
4035 struct mlx5_flow_counter_pool *pool;
4036 uint32_t batch = 0, age = 0;
4039 age = MLX_CNT_IS_AGE(idx);
4040 idx = age ? idx - MLX5_CNT_AGE_OFFSET : idx;
4041 if (idx >= MLX5_CNT_BATCH_OFFSET) {
4042 idx -= MLX5_CNT_BATCH_OFFSET;
4045 cont = MLX5_CNT_CONTAINER(priv->sh, batch, age);
4046 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cont->n);
4047 pool = cont->pools[idx / MLX5_COUNTERS_PER_POOL];
4051 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
4055 * Check the devx counter belongs to the pool.
4058 * Pointer to the counter pool.
4060 * The counter devx ID.
4063 * True if counter belongs to the pool, false otherwise.
4066 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
4068 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
4069 MLX5_COUNTERS_PER_POOL;
4071 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
4077 * Get a pool by devx counter ID.
4080 * Pointer to the counter container.
4082 * The counter devx ID.
4085 * The counter pool pointer if exists, NULL otherwise,
4087 static struct mlx5_flow_counter_pool *
4088 flow_dv_find_pool_by_id(struct mlx5_pools_container *cont, int id)
4092 /* Check last used pool. */
4093 if (cont->last_pool_idx != POOL_IDX_INVALID &&
4094 flow_dv_is_counter_in_pool(cont->pools[cont->last_pool_idx], id))
4095 return cont->pools[cont->last_pool_idx];
4096 /* ID out of range means no suitable pool in the container. */
4097 if (id > cont->max_id || id < cont->min_id)
4100 * Find the pool from the end of the container, since mostly counter
4101 * ID is sequence increasing, and the last pool should be the needed
4104 i = rte_atomic16_read(&cont->n_valid);
4106 struct mlx5_flow_counter_pool *pool = cont->pools[i];
4108 if (flow_dv_is_counter_in_pool(pool, id))
4115 * Allocate a new memory for the counter values wrapped by all the needed
4119 * Pointer to the Ethernet device structure.
4121 * The raw memory areas - each one for MLX5_COUNTERS_PER_POOL counters.
4124 * The new memory management pointer on success, otherwise NULL and rte_errno
4127 static struct mlx5_counter_stats_mem_mng *
4128 flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
4130 struct mlx5_priv *priv = dev->data->dev_private;
4131 struct mlx5_dev_ctx_shared *sh = priv->sh;
4132 struct mlx5_devx_mkey_attr mkey_attr;
4133 struct mlx5_counter_stats_mem_mng *mem_mng;
4134 volatile struct flow_counter_stats *raw_data;
4135 int size = (sizeof(struct flow_counter_stats) *
4136 MLX5_COUNTERS_PER_POOL +
4137 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
4138 sizeof(struct mlx5_counter_stats_mem_mng);
4139 uint8_t *mem = rte_calloc(__func__, 1, size, sysconf(_SC_PAGESIZE));
4146 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
4147 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
4148 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
4149 IBV_ACCESS_LOCAL_WRITE);
4150 if (!mem_mng->umem) {
4155 mkey_attr.addr = (uintptr_t)mem;
4156 mkey_attr.size = size;
4157 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
4158 mkey_attr.pd = sh->pdn;
4159 mkey_attr.log_entity_size = 0;
4160 mkey_attr.pg_access = 0;
4161 mkey_attr.klm_array = NULL;
4162 mkey_attr.klm_num = 0;
4163 if (priv->config.hca_attr.relaxed_ordering_write &&
4164 priv->config.hca_attr.relaxed_ordering_read &&
4165 !haswell_broadwell_cpu)
4166 mkey_attr.relaxed_ordering = 1;
4167 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
4169 mlx5_glue->devx_umem_dereg(mem_mng->umem);
4174 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
4175 raw_data = (volatile struct flow_counter_stats *)mem;
4176 for (i = 0; i < raws_n; ++i) {
4177 mem_mng->raws[i].mem_mng = mem_mng;
4178 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
4180 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
4185 * Resize a counter container.
4188 * Pointer to the Ethernet device structure.
4190 * Whether the pool is for counter that was allocated by batch command.
4192 * Whether the pool is for Aging counter.
4195 * 0 on success, otherwise negative errno value and rte_errno is set.
4198 flow_dv_container_resize(struct rte_eth_dev *dev,
4199 uint32_t batch, uint32_t age)
4201 struct mlx5_priv *priv = dev->data->dev_private;
4202 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4204 struct mlx5_counter_stats_mem_mng *mem_mng = NULL;
4205 void *old_pools = cont->pools;
4206 uint32_t resize = cont->n + MLX5_CNT_CONTAINER_RESIZE;
4207 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
4208 void *pools = rte_calloc(__func__, 1, mem_size, 0);
4215 memcpy(pools, old_pools, cont->n *
4216 sizeof(struct mlx5_flow_counter_pool *));
4218 * Fallback mode query the counter directly, no background query
4219 * resources are needed.
4221 if (!priv->counter_fallback) {
4224 mem_mng = flow_dv_create_counter_stat_mem_mng(dev,
4225 MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES);
4230 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
4231 LIST_INSERT_HEAD(&priv->sh->cmng.free_stat_raws,
4233 MLX5_CNT_CONTAINER_RESIZE +
4236 rte_spinlock_lock(&cont->resize_sl);
4238 cont->mem_mng = mem_mng;
4239 cont->pools = pools;
4240 rte_spinlock_unlock(&cont->resize_sl);
4242 rte_free(old_pools);
4247 * Query a devx flow counter.
4250 * Pointer to the Ethernet device structure.
4252 * Index to the flow counter.
4254 * The statistics value of packets.
4256 * The statistics value of bytes.
4259 * 0 on success, otherwise a negative errno value and rte_errno is set.
4262 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
4265 struct mlx5_priv *priv = dev->data->dev_private;
4266 struct mlx5_flow_counter_pool *pool = NULL;
4267 struct mlx5_flow_counter *cnt;
4268 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4271 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
4273 if (counter < MLX5_CNT_BATCH_OFFSET) {
4274 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt);
4275 if (priv->counter_fallback)
4276 return mlx5_devx_cmd_flow_counter_query(cnt_ext->dcs, 0,
4277 0, pkts, bytes, 0, NULL, NULL, 0);
4280 rte_spinlock_lock(&pool->sl);
4282 * The single counters allocation may allocate smaller ID than the
4283 * current allocated in parallel to the host reading.
4284 * In this case the new counter values must be reported as 0.
4286 if (unlikely(cnt_ext && cnt_ext->dcs->id < pool->raw->min_dcs_id)) {
4290 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
4291 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
4292 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
4294 rte_spinlock_unlock(&pool->sl);
4299 * Create and initialize a new counter pool.
4302 * Pointer to the Ethernet device structure.
4304 * The devX counter handle.
4306 * Whether the pool is for counter that was allocated by batch command.
4308 * Whether the pool is for counter that was allocated for aging.
4309 * @param[in/out] cont_cur
4310 * Pointer to the container pointer, it will be update in pool resize.
4313 * The pool container pointer on success, NULL otherwise and rte_errno is set.
4315 static struct mlx5_flow_counter_pool *
4316 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
4317 uint32_t batch, uint32_t age)
4319 struct mlx5_priv *priv = dev->data->dev_private;
4320 struct mlx5_flow_counter_pool *pool;
4321 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4323 int16_t n_valid = rte_atomic16_read(&cont->n_valid);
4324 uint32_t size = sizeof(*pool);
4326 if (cont->n == n_valid && flow_dv_container_resize(dev, batch, age))
4328 size += MLX5_COUNTERS_PER_POOL * CNT_SIZE;
4329 size += (batch ? 0 : MLX5_COUNTERS_PER_POOL * CNTEXT_SIZE);
4330 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * AGE_SIZE);
4331 pool = rte_calloc(__func__, 1, size, 0);
4336 pool->min_dcs = dcs;
4337 if (!priv->counter_fallback)
4338 pool->raw = cont->mem_mng->raws + n_valid %
4339 MLX5_CNT_CONTAINER_RESIZE;
4340 pool->raw_hw = NULL;
4342 pool->type |= (batch ? 0 : CNT_POOL_TYPE_EXT);
4343 pool->type |= (!age ? 0 : CNT_POOL_TYPE_AGE);
4344 pool->query_gen = 0;
4345 rte_spinlock_init(&pool->sl);
4346 TAILQ_INIT(&pool->counters[0]);
4347 TAILQ_INIT(&pool->counters[1]);
4348 TAILQ_INSERT_HEAD(&cont->pool_list, pool, next);
4349 pool->index = n_valid;
4350 cont->pools[n_valid] = pool;
4352 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
4354 if (base < cont->min_id)
4355 cont->min_id = base;
4356 if (base > cont->max_id)
4357 cont->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
4358 cont->last_pool_idx = pool->index;
4360 /* Pool initialization must be updated before host thread access. */
4362 rte_atomic16_add(&cont->n_valid, 1);
4367 * Update the minimum dcs-id for aged or no-aged counter pool.
4370 * Pointer to the Ethernet device structure.
4372 * Current counter pool.
4374 * Whether the pool is for counter that was allocated by batch command.
4376 * Whether the counter is for aging.
4379 flow_dv_counter_update_min_dcs(struct rte_eth_dev *dev,
4380 struct mlx5_flow_counter_pool *pool,
4381 uint32_t batch, uint32_t age)
4383 struct mlx5_priv *priv = dev->data->dev_private;
4384 struct mlx5_flow_counter_pool *other;
4385 struct mlx5_pools_container *cont;
4387 cont = MLX5_CNT_CONTAINER(priv->sh, batch, (age ^ 0x1));
4388 other = flow_dv_find_pool_by_id(cont, pool->min_dcs->id);
4391 if (pool->min_dcs->id < other->min_dcs->id) {
4392 rte_atomic64_set(&other->a64_dcs,
4393 rte_atomic64_read(&pool->a64_dcs));
4395 rte_atomic64_set(&pool->a64_dcs,
4396 rte_atomic64_read(&other->a64_dcs));
4400 * Prepare a new counter and/or a new counter pool.
4403 * Pointer to the Ethernet device structure.
4404 * @param[out] cnt_free
4405 * Where to put the pointer of a new counter.
4407 * Whether the pool is for counter that was allocated by batch command.
4409 * Whether the pool is for counter that was allocated for aging.
4412 * The counter pool pointer and @p cnt_free is set on success,
4413 * NULL otherwise and rte_errno is set.
4415 static struct mlx5_flow_counter_pool *
4416 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
4417 struct mlx5_flow_counter **cnt_free,
4418 uint32_t batch, uint32_t age)
4420 struct mlx5_priv *priv = dev->data->dev_private;
4421 struct mlx5_pools_container *cont;
4422 struct mlx5_flow_counter_pool *pool;
4423 struct mlx5_counters tmp_tq;
4424 struct mlx5_devx_obj *dcs = NULL;
4425 struct mlx5_flow_counter *cnt;
4428 cont = MLX5_CNT_CONTAINER(priv->sh, batch, age);
4430 /* bulk_bitmap must be 0 for single counter allocation. */
4431 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
4434 pool = flow_dv_find_pool_by_id(cont, dcs->id);
4436 pool = flow_dv_pool_create(dev, dcs, batch, age);
4438 mlx5_devx_cmd_destroy(dcs);
4441 } else if (dcs->id < pool->min_dcs->id) {
4442 rte_atomic64_set(&pool->a64_dcs,
4443 (int64_t)(uintptr_t)dcs);
4445 flow_dv_counter_update_min_dcs(dev,
4447 i = dcs->id % MLX5_COUNTERS_PER_POOL;
4448 cnt = MLX5_POOL_GET_CNT(pool, i);
4450 MLX5_GET_POOL_CNT_EXT(pool, i)->dcs = dcs;
4454 /* bulk_bitmap is in 128 counters units. */
4455 if (priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4)
4456 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
4458 rte_errno = ENODATA;
4461 pool = flow_dv_pool_create(dev, dcs, batch, age);
4463 mlx5_devx_cmd_destroy(dcs);
4466 TAILQ_INIT(&tmp_tq);
4467 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
4468 cnt = MLX5_POOL_GET_CNT(pool, i);
4470 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
4472 rte_spinlock_lock(&cont->csl);
4473 TAILQ_CONCAT(&cont->counters, &tmp_tq, next);
4474 rte_spinlock_unlock(&cont->csl);
4475 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
4476 (*cnt_free)->pool = pool;
4481 * Search for existed shared counter.
4484 * Pointer to the Ethernet device structure.
4486 * The shared counter ID to search.
4488 * mlx5 flow counter pool in the container,
4491 * NULL if not existed, otherwise pointer to the shared extend counter.
4493 static struct mlx5_flow_counter_ext *
4494 flow_dv_counter_shared_search(struct rte_eth_dev *dev, uint32_t id,
4495 struct mlx5_flow_counter_pool **ppool)
4497 struct mlx5_priv *priv = dev->data->dev_private;
4498 union mlx5_l3t_data data;
4501 if (mlx5_l3t_get_entry(priv->sh->cnt_id_tbl, id, &data) || !data.dword)
4503 cnt_idx = data.dword;
4505 * Shared counters don't have age info. The counter extend is after
4506 * the counter datat structure.
4508 return (struct mlx5_flow_counter_ext *)
4509 ((flow_dv_counter_get_by_idx(dev, cnt_idx, ppool)) + 1);
4513 * Allocate a flow counter.
4516 * Pointer to the Ethernet device structure.
4518 * Indicate if this counter is shared with other flows.
4520 * Counter identifier.
4522 * Counter flow group.
4524 * Whether the counter was allocated for aging.
4527 * Index to flow counter on success, 0 otherwise and rte_errno is set.
4530 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
4531 uint16_t group, uint32_t age)
4533 struct mlx5_priv *priv = dev->data->dev_private;
4534 struct mlx5_flow_counter_pool *pool = NULL;
4535 struct mlx5_flow_counter *cnt_free = NULL;
4536 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4538 * Currently group 0 flow counter cannot be assigned to a flow if it is
4539 * not the first one in the batch counter allocation, so it is better
4540 * to allocate counters one by one for these flows in a separate
4542 * A counter can be shared between different groups so need to take
4543 * shared counters from the single container.
4545 uint32_t batch = (group && !shared && !priv->counter_fallback) ? 1 : 0;
4546 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4550 if (!priv->config.devx) {
4551 rte_errno = ENOTSUP;
4555 cnt_ext = flow_dv_counter_shared_search(dev, id, &pool);
4557 if (cnt_ext->ref_cnt + 1 == 0) {
4562 cnt_idx = pool->index * MLX5_COUNTERS_PER_POOL +
4563 (cnt_ext->dcs->id % MLX5_COUNTERS_PER_POOL)
4568 /* Get free counters from container. */
4569 rte_spinlock_lock(&cont->csl);
4570 cnt_free = TAILQ_FIRST(&cont->counters);
4572 TAILQ_REMOVE(&cont->counters, cnt_free, next);
4573 rte_spinlock_unlock(&cont->csl);
4574 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free,
4577 pool = cnt_free->pool;
4579 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt_free);
4580 /* Create a DV counter action only in the first time usage. */
4581 if (!cnt_free->action) {
4583 struct mlx5_devx_obj *dcs;
4586 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
4587 dcs = pool->min_dcs;
4592 cnt_free->action = mlx5_glue->dv_create_flow_action_counter
4594 if (!cnt_free->action) {
4599 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
4600 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
4601 cnt_idx += batch * MLX5_CNT_BATCH_OFFSET;
4602 cnt_idx += age * MLX5_CNT_AGE_OFFSET;
4603 /* Update the counter reset values. */
4604 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
4608 cnt_ext->shared = shared;
4609 cnt_ext->ref_cnt = 1;
4612 union mlx5_l3t_data data;
4614 data.dword = cnt_idx;
4615 if (mlx5_l3t_set_entry(priv->sh->cnt_id_tbl, id, &data))
4619 if (!priv->counter_fallback && !priv->sh->cmng.query_thread_on)
4620 /* Start the asynchronous batch query by the host thread. */
4621 mlx5_set_query_alarm(priv->sh);
4625 cnt_free->pool = pool;
4626 rte_spinlock_lock(&cont->csl);
4627 TAILQ_INSERT_TAIL(&cont->counters, cnt_free, next);
4628 rte_spinlock_unlock(&cont->csl);
4634 * Get age param from counter index.
4637 * Pointer to the Ethernet device structure.
4638 * @param[in] counter
4639 * Index to the counter handler.
4642 * The aging parameter specified for the counter index.
4644 static struct mlx5_age_param*
4645 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
4648 struct mlx5_flow_counter *cnt;
4649 struct mlx5_flow_counter_pool *pool = NULL;
4651 flow_dv_counter_get_by_idx(dev, counter, &pool);
4652 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
4653 cnt = MLX5_POOL_GET_CNT(pool, counter);
4654 return MLX5_CNT_TO_AGE(cnt);
4658 * Remove a flow counter from aged counter list.
4661 * Pointer to the Ethernet device structure.
4662 * @param[in] counter
4663 * Index to the counter handler.
4665 * Pointer to the counter handler.
4668 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
4669 uint32_t counter, struct mlx5_flow_counter *cnt)
4671 struct mlx5_age_info *age_info;
4672 struct mlx5_age_param *age_param;
4673 struct mlx5_priv *priv = dev->data->dev_private;
4675 age_info = GET_PORT_AGE_INFO(priv);
4676 age_param = flow_dv_counter_idx_get_age(dev, counter);
4677 if (rte_atomic16_cmpset((volatile uint16_t *)
4679 AGE_CANDIDATE, AGE_FREE)
4682 * We need the lock even it is age timeout,
4683 * since counter may still in process.
4685 rte_spinlock_lock(&age_info->aged_sl);
4686 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
4687 rte_spinlock_unlock(&age_info->aged_sl);
4689 rte_atomic16_set(&age_param->state, AGE_FREE);
4692 * Release a flow counter.
4695 * Pointer to the Ethernet device structure.
4696 * @param[in] counter
4697 * Index to the counter handler.
4700 flow_dv_counter_release(struct rte_eth_dev *dev, uint32_t counter)
4702 struct mlx5_priv *priv = dev->data->dev_private;
4703 struct mlx5_flow_counter_pool *pool = NULL;
4704 struct mlx5_flow_counter *cnt;
4705 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4709 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
4711 if (counter < MLX5_CNT_BATCH_OFFSET) {
4712 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt);
4714 if (--cnt_ext->ref_cnt)
4716 if (cnt_ext->shared)
4717 mlx5_l3t_clear_entry(priv->sh->cnt_id_tbl,
4721 if (IS_AGE_POOL(pool))
4722 flow_dv_counter_remove_from_age(dev, counter, cnt);
4725 * Put the counter back to list to be updated in none fallback mode.
4726 * Currently, we are using two list alternately, while one is in query,
4727 * add the freed counter to the other list based on the pool query_gen
4728 * value. After query finishes, add counter the list to the global
4729 * container counter list. The list changes while query starts. In
4730 * this case, lock will not be needed as query callback and release
4731 * function both operate with the different list.
4734 if (!priv->counter_fallback)
4735 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
4737 TAILQ_INSERT_TAIL(&((MLX5_CNT_CONTAINER
4738 (priv->sh, 0, 0))->counters),
4743 * Verify the @p attributes will be correctly understood by the NIC and store
4744 * them in the @p flow if everything is correct.
4747 * Pointer to dev struct.
4748 * @param[in] attributes
4749 * Pointer to flow attributes
4750 * @param[in] external
4751 * This flow rule is created by request external to PMD.
4753 * Pointer to error structure.
4756 * - 0 on success and non root table.
4757 * - 1 on success and root table.
4758 * - a negative errno value otherwise and rte_errno is set.
4761 flow_dv_validate_attributes(struct rte_eth_dev *dev,
4762 const struct rte_flow_attr *attributes,
4763 bool external __rte_unused,
4764 struct rte_flow_error *error)
4766 struct mlx5_priv *priv = dev->data->dev_private;
4767 uint32_t priority_max = priv->config.flow_prio - 1;
4770 #ifndef HAVE_MLX5DV_DR
4771 if (attributes->group)
4772 return rte_flow_error_set(error, ENOTSUP,
4773 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
4775 "groups are not supported");
4779 ret = mlx5_flow_group_to_table(attributes, external,
4780 attributes->group, !!priv->fdb_def_rule,
4785 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
4787 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
4788 attributes->priority >= priority_max)
4789 return rte_flow_error_set(error, ENOTSUP,
4790 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
4792 "priority out of range");
4793 if (attributes->transfer) {
4794 if (!priv->config.dv_esw_en)
4795 return rte_flow_error_set
4797 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4798 "E-Switch dr is not supported");
4799 if (!(priv->representor || priv->master))
4800 return rte_flow_error_set
4801 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4802 NULL, "E-Switch configuration can only be"
4803 " done by a master or a representor device");
4804 if (attributes->egress)
4805 return rte_flow_error_set
4807 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
4808 "egress is not supported");
4810 if (!(attributes->egress ^ attributes->ingress))
4811 return rte_flow_error_set(error, ENOTSUP,
4812 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
4813 "must specify exactly one of "
4814 "ingress or egress");
4819 * Internal validation function. For validating both actions and items.
4822 * Pointer to the rte_eth_dev structure.
4824 * Pointer to the flow attributes.
4826 * Pointer to the list of items.
4827 * @param[in] actions
4828 * Pointer to the list of actions.
4829 * @param[in] external
4830 * This flow rule is created by request external to PMD.
4831 * @param[in] hairpin
4832 * Number of hairpin TX actions, 0 means classic flow.
4834 * Pointer to the error structure.
4837 * 0 on success, a negative errno value otherwise and rte_errno is set.
4840 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
4841 const struct rte_flow_item items[],
4842 const struct rte_flow_action actions[],
4843 bool external, int hairpin, struct rte_flow_error *error)
4846 uint64_t action_flags = 0;
4847 uint64_t item_flags = 0;
4848 uint64_t last_item = 0;
4849 uint8_t next_protocol = 0xff;
4850 uint16_t ether_type = 0;
4852 uint8_t item_ipv6_proto = 0;
4853 const struct rte_flow_item *gre_item = NULL;
4854 const struct rte_flow_action_raw_decap *decap;
4855 const struct rte_flow_action_raw_encap *encap;
4856 const struct rte_flow_action_rss *rss;
4857 const struct rte_flow_item_tcp nic_tcp_mask = {
4860 .src_port = RTE_BE16(UINT16_MAX),
4861 .dst_port = RTE_BE16(UINT16_MAX),
4864 const struct rte_flow_item_ipv4 nic_ipv4_mask = {
4866 .src_addr = RTE_BE32(0xffffffff),
4867 .dst_addr = RTE_BE32(0xffffffff),
4868 .type_of_service = 0xff,
4869 .next_proto_id = 0xff,
4870 .time_to_live = 0xff,
4873 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
4876 "\xff\xff\xff\xff\xff\xff\xff\xff"
4877 "\xff\xff\xff\xff\xff\xff\xff\xff",
4879 "\xff\xff\xff\xff\xff\xff\xff\xff"
4880 "\xff\xff\xff\xff\xff\xff\xff\xff",
4881 .vtc_flow = RTE_BE32(0xffffffff),
4886 struct mlx5_priv *priv = dev->data->dev_private;
4887 struct mlx5_dev_config *dev_conf = &priv->config;
4888 uint16_t queue_index = 0xFFFF;
4889 const struct rte_flow_item_vlan *vlan_m = NULL;
4890 int16_t rw_act_num = 0;
4895 ret = flow_dv_validate_attributes(dev, attr, external, error);
4898 is_root = (uint64_t)ret;
4899 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4900 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
4901 int type = items->type;
4904 case RTE_FLOW_ITEM_TYPE_VOID:
4906 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4907 ret = flow_dv_validate_item_port_id
4908 (dev, items, attr, item_flags, error);
4911 last_item = MLX5_FLOW_ITEM_PORT_ID;
4913 case RTE_FLOW_ITEM_TYPE_ETH:
4914 ret = mlx5_flow_validate_item_eth(items, item_flags,
4918 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
4919 MLX5_FLOW_LAYER_OUTER_L2;
4920 if (items->mask != NULL && items->spec != NULL) {
4922 ((const struct rte_flow_item_eth *)
4925 ((const struct rte_flow_item_eth *)
4927 ether_type = rte_be_to_cpu_16(ether_type);
4932 case RTE_FLOW_ITEM_TYPE_VLAN:
4933 ret = flow_dv_validate_item_vlan(items, item_flags,
4937 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
4938 MLX5_FLOW_LAYER_OUTER_VLAN;
4939 if (items->mask != NULL && items->spec != NULL) {
4941 ((const struct rte_flow_item_vlan *)
4942 items->spec)->inner_type;
4944 ((const struct rte_flow_item_vlan *)
4945 items->mask)->inner_type;
4946 ether_type = rte_be_to_cpu_16(ether_type);
4950 /* Store outer VLAN mask for of_push_vlan action. */
4952 vlan_m = items->mask;
4954 case RTE_FLOW_ITEM_TYPE_IPV4:
4955 mlx5_flow_tunnel_ip_check(items, next_protocol,
4956 &item_flags, &tunnel);
4957 ret = mlx5_flow_validate_item_ipv4(items, item_flags,
4964 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4965 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4966 if (items->mask != NULL &&
4967 ((const struct rte_flow_item_ipv4 *)
4968 items->mask)->hdr.next_proto_id) {
4970 ((const struct rte_flow_item_ipv4 *)
4971 (items->spec))->hdr.next_proto_id;
4973 ((const struct rte_flow_item_ipv4 *)
4974 (items->mask))->hdr.next_proto_id;
4976 /* Reset for inner layer. */
4977 next_protocol = 0xff;
4980 case RTE_FLOW_ITEM_TYPE_IPV6:
4981 mlx5_flow_tunnel_ip_check(items, next_protocol,
4982 &item_flags, &tunnel);
4983 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
4990 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4991 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4992 if (items->mask != NULL &&
4993 ((const struct rte_flow_item_ipv6 *)
4994 items->mask)->hdr.proto) {
4996 ((const struct rte_flow_item_ipv6 *)
4997 items->spec)->hdr.proto;
4999 ((const struct rte_flow_item_ipv6 *)
5000 items->spec)->hdr.proto;
5002 ((const struct rte_flow_item_ipv6 *)
5003 items->mask)->hdr.proto;
5005 /* Reset for inner layer. */
5006 next_protocol = 0xff;
5009 case RTE_FLOW_ITEM_TYPE_TCP:
5010 ret = mlx5_flow_validate_item_tcp
5017 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
5018 MLX5_FLOW_LAYER_OUTER_L4_TCP;
5020 case RTE_FLOW_ITEM_TYPE_UDP:
5021 ret = mlx5_flow_validate_item_udp(items, item_flags,
5026 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
5027 MLX5_FLOW_LAYER_OUTER_L4_UDP;
5029 case RTE_FLOW_ITEM_TYPE_GRE:
5030 ret = mlx5_flow_validate_item_gre(items, item_flags,
5031 next_protocol, error);
5035 last_item = MLX5_FLOW_LAYER_GRE;
5037 case RTE_FLOW_ITEM_TYPE_NVGRE:
5038 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
5043 last_item = MLX5_FLOW_LAYER_NVGRE;
5045 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
5046 ret = mlx5_flow_validate_item_gre_key
5047 (items, item_flags, gre_item, error);
5050 last_item = MLX5_FLOW_LAYER_GRE_KEY;
5052 case RTE_FLOW_ITEM_TYPE_VXLAN:
5053 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
5057 last_item = MLX5_FLOW_LAYER_VXLAN;
5059 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
5060 ret = mlx5_flow_validate_item_vxlan_gpe(items,
5065 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
5067 case RTE_FLOW_ITEM_TYPE_GENEVE:
5068 ret = mlx5_flow_validate_item_geneve(items,
5073 last_item = MLX5_FLOW_LAYER_GENEVE;
5075 case RTE_FLOW_ITEM_TYPE_MPLS:
5076 ret = mlx5_flow_validate_item_mpls(dev, items,
5081 last_item = MLX5_FLOW_LAYER_MPLS;
5084 case RTE_FLOW_ITEM_TYPE_MARK:
5085 ret = flow_dv_validate_item_mark(dev, items, attr,
5089 last_item = MLX5_FLOW_ITEM_MARK;
5091 case RTE_FLOW_ITEM_TYPE_META:
5092 ret = flow_dv_validate_item_meta(dev, items, attr,
5096 last_item = MLX5_FLOW_ITEM_METADATA;
5098 case RTE_FLOW_ITEM_TYPE_ICMP:
5099 ret = mlx5_flow_validate_item_icmp(items, item_flags,
5104 last_item = MLX5_FLOW_LAYER_ICMP;
5106 case RTE_FLOW_ITEM_TYPE_ICMP6:
5107 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
5112 item_ipv6_proto = IPPROTO_ICMPV6;
5113 last_item = MLX5_FLOW_LAYER_ICMP6;
5115 case RTE_FLOW_ITEM_TYPE_TAG:
5116 ret = flow_dv_validate_item_tag(dev, items,
5120 last_item = MLX5_FLOW_ITEM_TAG;
5122 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
5123 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
5125 case RTE_FLOW_ITEM_TYPE_GTP:
5126 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
5130 last_item = MLX5_FLOW_LAYER_GTP;
5133 return rte_flow_error_set(error, ENOTSUP,
5134 RTE_FLOW_ERROR_TYPE_ITEM,
5135 NULL, "item not supported");
5137 item_flags |= last_item;
5139 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5140 int type = actions->type;
5141 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5142 return rte_flow_error_set(error, ENOTSUP,
5143 RTE_FLOW_ERROR_TYPE_ACTION,
5144 actions, "too many actions");
5146 case RTE_FLOW_ACTION_TYPE_VOID:
5148 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5149 ret = flow_dv_validate_action_port_id(dev,
5156 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5159 case RTE_FLOW_ACTION_TYPE_FLAG:
5160 ret = flow_dv_validate_action_flag(dev, action_flags,
5164 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
5165 /* Count all modify-header actions as one. */
5166 if (!(action_flags &
5167 MLX5_FLOW_MODIFY_HDR_ACTIONS))
5169 action_flags |= MLX5_FLOW_ACTION_FLAG |
5170 MLX5_FLOW_ACTION_MARK_EXT;
5172 action_flags |= MLX5_FLOW_ACTION_FLAG;
5175 rw_act_num += MLX5_ACT_NUM_SET_MARK;
5177 case RTE_FLOW_ACTION_TYPE_MARK:
5178 ret = flow_dv_validate_action_mark(dev, actions,
5183 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
5184 /* Count all modify-header actions as one. */
5185 if (!(action_flags &
5186 MLX5_FLOW_MODIFY_HDR_ACTIONS))
5188 action_flags |= MLX5_FLOW_ACTION_MARK |
5189 MLX5_FLOW_ACTION_MARK_EXT;
5191 action_flags |= MLX5_FLOW_ACTION_MARK;
5194 rw_act_num += MLX5_ACT_NUM_SET_MARK;
5196 case RTE_FLOW_ACTION_TYPE_SET_META:
5197 ret = flow_dv_validate_action_set_meta(dev, actions,
5202 /* Count all modify-header actions as one action. */
5203 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5205 action_flags |= MLX5_FLOW_ACTION_SET_META;
5206 rw_act_num += MLX5_ACT_NUM_SET_META;
5208 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5209 ret = flow_dv_validate_action_set_tag(dev, actions,
5214 /* Count all modify-header actions as one action. */
5215 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5217 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
5218 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5220 case RTE_FLOW_ACTION_TYPE_DROP:
5221 ret = mlx5_flow_validate_action_drop(action_flags,
5225 action_flags |= MLX5_FLOW_ACTION_DROP;
5228 case RTE_FLOW_ACTION_TYPE_QUEUE:
5229 ret = mlx5_flow_validate_action_queue(actions,
5234 queue_index = ((const struct rte_flow_action_queue *)
5235 (actions->conf))->index;
5236 action_flags |= MLX5_FLOW_ACTION_QUEUE;
5239 case RTE_FLOW_ACTION_TYPE_RSS:
5240 rss = actions->conf;
5241 ret = mlx5_flow_validate_action_rss(actions,
5247 if (rss != NULL && rss->queue_num)
5248 queue_index = rss->queue[0];
5249 action_flags |= MLX5_FLOW_ACTION_RSS;
5252 case RTE_FLOW_ACTION_TYPE_COUNT:
5253 ret = flow_dv_validate_action_count(dev, error);
5256 action_flags |= MLX5_FLOW_ACTION_COUNT;
5259 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5260 if (flow_dv_validate_action_pop_vlan(dev,
5266 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
5269 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5270 ret = flow_dv_validate_action_push_vlan(dev,
5277 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
5280 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5281 ret = flow_dv_validate_action_set_vlan_pcp
5282 (action_flags, actions, error);
5285 /* Count PCP with push_vlan command. */
5286 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
5288 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5289 ret = flow_dv_validate_action_set_vlan_vid
5290 (item_flags, action_flags,
5294 /* Count VID with push_vlan command. */
5295 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
5296 rw_act_num += MLX5_ACT_NUM_MDF_VID;
5298 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5299 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5300 ret = flow_dv_validate_action_l2_encap(dev,
5306 action_flags |= MLX5_FLOW_ACTION_ENCAP;
5309 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5310 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5311 ret = flow_dv_validate_action_decap(dev, action_flags,
5315 action_flags |= MLX5_FLOW_ACTION_DECAP;
5318 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5319 ret = flow_dv_validate_action_raw_encap_decap
5320 (dev, NULL, actions->conf, attr, &action_flags,
5325 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5326 decap = actions->conf;
5327 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5329 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5333 encap = actions->conf;
5335 ret = flow_dv_validate_action_raw_encap_decap
5337 decap ? decap : &empty_decap, encap,
5338 attr, &action_flags, &actions_n,
5343 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5344 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5345 ret = flow_dv_validate_action_modify_mac(action_flags,
5351 /* Count all modify-header actions as one action. */
5352 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5354 action_flags |= actions->type ==
5355 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
5356 MLX5_FLOW_ACTION_SET_MAC_SRC :
5357 MLX5_FLOW_ACTION_SET_MAC_DST;
5359 * Even if the source and destination MAC addresses have
5360 * overlap in the header with 4B alignment, the convert
5361 * function will handle them separately and 4 SW actions
5362 * will be created. And 2 actions will be added each
5363 * time no matter how many bytes of address will be set.
5365 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
5367 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5368 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5369 ret = flow_dv_validate_action_modify_ipv4(action_flags,
5375 /* Count all modify-header actions as one action. */
5376 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5378 action_flags |= actions->type ==
5379 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
5380 MLX5_FLOW_ACTION_SET_IPV4_SRC :
5381 MLX5_FLOW_ACTION_SET_IPV4_DST;
5382 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
5384 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5385 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5386 ret = flow_dv_validate_action_modify_ipv6(action_flags,
5392 if (item_ipv6_proto == IPPROTO_ICMPV6)
5393 return rte_flow_error_set(error, ENOTSUP,
5394 RTE_FLOW_ERROR_TYPE_ACTION,
5396 "Can't change header "
5397 "with ICMPv6 proto");
5398 /* Count all modify-header actions as one action. */
5399 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5401 action_flags |= actions->type ==
5402 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
5403 MLX5_FLOW_ACTION_SET_IPV6_SRC :
5404 MLX5_FLOW_ACTION_SET_IPV6_DST;
5405 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
5407 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5408 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5409 ret = flow_dv_validate_action_modify_tp(action_flags,
5415 /* Count all modify-header actions as one action. */
5416 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5418 action_flags |= actions->type ==
5419 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
5420 MLX5_FLOW_ACTION_SET_TP_SRC :
5421 MLX5_FLOW_ACTION_SET_TP_DST;
5422 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
5424 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5425 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5426 ret = flow_dv_validate_action_modify_ttl(action_flags,
5432 /* Count all modify-header actions as one action. */
5433 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5435 action_flags |= actions->type ==
5436 RTE_FLOW_ACTION_TYPE_SET_TTL ?
5437 MLX5_FLOW_ACTION_SET_TTL :
5438 MLX5_FLOW_ACTION_DEC_TTL;
5439 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
5441 case RTE_FLOW_ACTION_TYPE_JUMP:
5442 ret = flow_dv_validate_action_jump(actions,
5449 action_flags |= MLX5_FLOW_ACTION_JUMP;
5451 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5452 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5453 ret = flow_dv_validate_action_modify_tcp_seq
5460 /* Count all modify-header actions as one action. */
5461 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5463 action_flags |= actions->type ==
5464 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
5465 MLX5_FLOW_ACTION_INC_TCP_SEQ :
5466 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
5467 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
5469 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5470 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5471 ret = flow_dv_validate_action_modify_tcp_ack
5478 /* Count all modify-header actions as one action. */
5479 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5481 action_flags |= actions->type ==
5482 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
5483 MLX5_FLOW_ACTION_INC_TCP_ACK :
5484 MLX5_FLOW_ACTION_DEC_TCP_ACK;
5485 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
5487 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
5489 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
5490 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
5491 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5493 case RTE_FLOW_ACTION_TYPE_METER:
5494 ret = mlx5_flow_validate_action_meter(dev,
5500 action_flags |= MLX5_FLOW_ACTION_METER;
5502 /* Meter action will add one more TAG action. */
5503 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5505 case RTE_FLOW_ACTION_TYPE_AGE:
5506 ret = flow_dv_validate_action_age(action_flags,
5511 action_flags |= MLX5_FLOW_ACTION_AGE;
5514 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5515 ret = flow_dv_validate_action_modify_ipv4_dscp
5522 /* Count all modify-header actions as one action. */
5523 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5525 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
5526 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
5528 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5529 ret = flow_dv_validate_action_modify_ipv6_dscp
5536 /* Count all modify-header actions as one action. */
5537 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5539 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
5540 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
5543 return rte_flow_error_set(error, ENOTSUP,
5544 RTE_FLOW_ERROR_TYPE_ACTION,
5546 "action not supported");
5550 * Validate the drop action mutual exclusion with other actions.
5551 * Drop action is mutually-exclusive with any other action, except for
5554 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
5555 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
5556 return rte_flow_error_set(error, EINVAL,
5557 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5558 "Drop action is mutually-exclusive "
5559 "with any other action, except for "
5561 /* Eswitch has few restrictions on using items and actions */
5562 if (attr->transfer) {
5563 if (!mlx5_flow_ext_mreg_supported(dev) &&
5564 action_flags & MLX5_FLOW_ACTION_FLAG)
5565 return rte_flow_error_set(error, ENOTSUP,
5566 RTE_FLOW_ERROR_TYPE_ACTION,
5568 "unsupported action FLAG");
5569 if (!mlx5_flow_ext_mreg_supported(dev) &&
5570 action_flags & MLX5_FLOW_ACTION_MARK)
5571 return rte_flow_error_set(error, ENOTSUP,
5572 RTE_FLOW_ERROR_TYPE_ACTION,
5574 "unsupported action MARK");
5575 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
5576 return rte_flow_error_set(error, ENOTSUP,
5577 RTE_FLOW_ERROR_TYPE_ACTION,
5579 "unsupported action QUEUE");
5580 if (action_flags & MLX5_FLOW_ACTION_RSS)
5581 return rte_flow_error_set(error, ENOTSUP,
5582 RTE_FLOW_ERROR_TYPE_ACTION,
5584 "unsupported action RSS");
5585 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5586 return rte_flow_error_set(error, EINVAL,
5587 RTE_FLOW_ERROR_TYPE_ACTION,
5589 "no fate action is found");
5591 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
5592 return rte_flow_error_set(error, EINVAL,
5593 RTE_FLOW_ERROR_TYPE_ACTION,
5595 "no fate action is found");
5597 /* Continue validation for Xcap actions.*/
5598 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) && (queue_index == 0xFFFF ||
5599 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5600 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5601 MLX5_FLOW_XCAP_ACTIONS)
5602 return rte_flow_error_set(error, ENOTSUP,
5603 RTE_FLOW_ERROR_TYPE_ACTION,
5604 NULL, "encap and decap "
5605 "combination aren't supported");
5606 if (!attr->transfer && attr->ingress && (action_flags &
5607 MLX5_FLOW_ACTION_ENCAP))
5608 return rte_flow_error_set(error, ENOTSUP,
5609 RTE_FLOW_ERROR_TYPE_ACTION,
5610 NULL, "encap is not supported"
5611 " for ingress traffic");
5613 /* Hairpin flow will add one more TAG action. */
5615 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5616 /* extra metadata enabled: one more TAG action will be add. */
5617 if (dev_conf->dv_flow_en &&
5618 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5619 mlx5_flow_ext_mreg_supported(dev))
5620 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5621 if ((uint32_t)rw_act_num >
5622 flow_dv_modify_hdr_action_max(dev, is_root)) {
5623 return rte_flow_error_set(error, ENOTSUP,
5624 RTE_FLOW_ERROR_TYPE_ACTION,
5625 NULL, "too many header modify"
5626 " actions to support");
5632 * Internal preparation function. Allocates the DV flow size,
5633 * this size is constant.
5636 * Pointer to the rte_eth_dev structure.
5638 * Pointer to the flow attributes.
5640 * Pointer to the list of items.
5641 * @param[in] actions
5642 * Pointer to the list of actions.
5644 * Pointer to the error structure.
5647 * Pointer to mlx5_flow object on success,
5648 * otherwise NULL and rte_errno is set.
5650 static struct mlx5_flow *
5651 flow_dv_prepare(struct rte_eth_dev *dev,
5652 const struct rte_flow_attr *attr __rte_unused,
5653 const struct rte_flow_item items[] __rte_unused,
5654 const struct rte_flow_action actions[] __rte_unused,
5655 struct rte_flow_error *error)
5657 uint32_t handle_idx = 0;
5658 struct mlx5_flow *dev_flow;
5659 struct mlx5_flow_handle *dev_handle;
5660 struct mlx5_priv *priv = dev->data->dev_private;
5662 /* In case of corrupting the memory. */
5663 if (priv->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
5664 rte_flow_error_set(error, ENOSPC,
5665 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5666 "not free temporary device flow");
5669 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
5672 rte_flow_error_set(error, ENOMEM,
5673 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5674 "not enough memory to create flow handle");
5677 /* No multi-thread supporting. */
5678 dev_flow = &((struct mlx5_flow *)priv->inter_flows)[priv->flow_idx++];
5679 dev_flow->handle = dev_handle;
5680 dev_flow->handle_idx = handle_idx;
5681 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
5683 * The matching value needs to be cleared to 0 before using. In the
5684 * past, it will be automatically cleared when using rte_*alloc
5685 * API. The time consumption will be almost the same as before.
5687 memset(dev_flow->dv.value.buf, 0, MLX5_ST_SZ_BYTES(fte_match_param));
5688 dev_flow->ingress = attr->ingress;
5689 dev_flow->dv.transfer = attr->transfer;
5693 #ifdef RTE_LIBRTE_MLX5_DEBUG
5695 * Sanity check for match mask and value. Similar to check_valid_spec() in
5696 * kernel driver. If unmasked bit is present in value, it returns failure.
5699 * pointer to match mask buffer.
5700 * @param match_value
5701 * pointer to match value buffer.
5704 * 0 if valid, -EINVAL otherwise.
5707 flow_dv_check_valid_spec(void *match_mask, void *match_value)
5709 uint8_t *m = match_mask;
5710 uint8_t *v = match_value;
5713 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
5716 "match_value differs from match_criteria"
5717 " %p[%u] != %p[%u]",
5718 match_value, i, match_mask, i);
5727 * Add match of ip_version.
5731 * @param[in] headers_v
5732 * Values header pointer.
5733 * @param[in] headers_m
5734 * Masks header pointer.
5735 * @param[in] ip_version
5736 * The IP version to set.
5739 flow_dv_set_match_ip_version(uint32_t group,
5745 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
5747 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
5749 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
5750 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
5751 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
5755 * Add Ethernet item to matcher and to the value.
5757 * @param[in, out] matcher
5759 * @param[in, out] key
5760 * Flow matcher value.
5762 * Flow pattern to translate.
5764 * Item is inner pattern.
5767 flow_dv_translate_item_eth(void *matcher, void *key,
5768 const struct rte_flow_item *item, int inner,
5771 const struct rte_flow_item_eth *eth_m = item->mask;
5772 const struct rte_flow_item_eth *eth_v = item->spec;
5773 const struct rte_flow_item_eth nic_mask = {
5774 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
5775 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
5776 .type = RTE_BE16(0xffff),
5788 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5790 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5792 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5794 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5796 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, dmac_47_16),
5797 ð_m->dst, sizeof(eth_m->dst));
5798 /* The value must be in the range of the mask. */
5799 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, dmac_47_16);
5800 for (i = 0; i < sizeof(eth_m->dst); ++i)
5801 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
5802 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, smac_47_16),
5803 ð_m->src, sizeof(eth_m->src));
5804 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, smac_47_16);
5805 /* The value must be in the range of the mask. */
5806 for (i = 0; i < sizeof(eth_m->dst); ++i)
5807 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
5809 /* When ethertype is present set mask for tagged VLAN. */
5810 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5811 /* Set value for tagged VLAN if ethertype is 802.1Q. */
5812 if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_VLAN) ||
5813 eth_v->type == RTE_BE16(RTE_ETHER_TYPE_QINQ)) {
5814 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag,
5816 /* Return here to avoid setting match on ethertype. */
5821 * HW supports match on one Ethertype, the Ethertype following the last
5822 * VLAN tag of the packet (see PRM).
5823 * Set match on ethertype only if ETH header is not followed by VLAN.
5824 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
5825 * ethertype, and use ip_version field instead.
5827 if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_IPV4) &&
5828 eth_m->type == 0xFFFF) {
5829 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
5830 } else if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_IPV6) &&
5831 eth_m->type == 0xFFFF) {
5832 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
5834 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
5835 rte_be_to_cpu_16(eth_m->type));
5836 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5838 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
5843 * Add VLAN item to matcher and to the value.
5845 * @param[in, out] dev_flow
5847 * @param[in, out] matcher
5849 * @param[in, out] key
5850 * Flow matcher value.
5852 * Flow pattern to translate.
5854 * Item is inner pattern.
5857 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
5858 void *matcher, void *key,
5859 const struct rte_flow_item *item,
5860 int inner, uint32_t group)
5862 const struct rte_flow_item_vlan *vlan_m = item->mask;
5863 const struct rte_flow_item_vlan *vlan_v = item->spec;
5870 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5872 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5874 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5876 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5878 * This is workaround, masks are not supported,
5879 * and pre-validated.
5882 dev_flow->handle->vf_vlan.tag =
5883 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
5886 * When VLAN item exists in flow, mark packet as tagged,
5887 * even if TCI is not specified.
5889 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5890 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
5894 vlan_m = &rte_flow_item_vlan_mask;
5895 tci_m = rte_be_to_cpu_16(vlan_m->tci);
5896 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
5897 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_vid, tci_m);
5898 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, tci_v);
5899 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_cfi, tci_m >> 12);
5900 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_cfi, tci_v >> 12);
5901 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_prio, tci_m >> 13);
5902 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, tci_v >> 13);
5904 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
5905 * ethertype, and use ip_version field instead.
5907 if (vlan_v->inner_type == RTE_BE16(RTE_ETHER_TYPE_IPV4) &&
5908 vlan_m->inner_type == 0xFFFF) {
5909 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
5910 } else if (vlan_v->inner_type == RTE_BE16(RTE_ETHER_TYPE_IPV6) &&
5911 vlan_m->inner_type == 0xFFFF) {
5912 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
5914 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
5915 rte_be_to_cpu_16(vlan_m->inner_type));
5916 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
5917 rte_be_to_cpu_16(vlan_m->inner_type &
5918 vlan_v->inner_type));
5923 * Add IPV4 item to matcher and to the value.
5925 * @param[in, out] matcher
5927 * @param[in, out] key
5928 * Flow matcher value.
5930 * Flow pattern to translate.
5931 * @param[in] item_flags
5932 * Bit-fields that holds the items detected until now.
5934 * Item is inner pattern.
5936 * The group to insert the rule.
5939 flow_dv_translate_item_ipv4(void *matcher, void *key,
5940 const struct rte_flow_item *item,
5941 const uint64_t item_flags,
5942 int inner, uint32_t group)
5944 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
5945 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
5946 const struct rte_flow_item_ipv4 nic_mask = {
5948 .src_addr = RTE_BE32(0xffffffff),
5949 .dst_addr = RTE_BE32(0xffffffff),
5950 .type_of_service = 0xff,
5951 .next_proto_id = 0xff,
5952 .time_to_live = 0xff,
5962 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5964 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5966 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5968 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5970 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
5972 * On outer header (which must contains L2), or inner header with L2,
5973 * set cvlan_tag mask bit to mark this packet as untagged.
5974 * This should be done even if item->spec is empty.
5976 if (!inner || item_flags & MLX5_FLOW_LAYER_INNER_L2)
5977 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5982 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5983 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
5984 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5985 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
5986 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
5987 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
5988 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5989 src_ipv4_src_ipv6.ipv4_layout.ipv4);
5990 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5991 src_ipv4_src_ipv6.ipv4_layout.ipv4);
5992 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
5993 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
5994 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
5995 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
5996 ipv4_m->hdr.type_of_service);
5997 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
5998 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
5999 ipv4_m->hdr.type_of_service >> 2);
6000 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
6001 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
6002 ipv4_m->hdr.next_proto_id);
6003 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6004 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
6005 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
6006 ipv4_m->hdr.time_to_live);
6007 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
6008 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
6012 * Add IPV6 item to matcher and to the value.
6014 * @param[in, out] matcher
6016 * @param[in, out] key
6017 * Flow matcher value.
6019 * Flow pattern to translate.
6020 * @param[in] item_flags
6021 * Bit-fields that holds the items detected until now.
6023 * Item is inner pattern.
6025 * The group to insert the rule.
6028 flow_dv_translate_item_ipv6(void *matcher, void *key,
6029 const struct rte_flow_item *item,
6030 const uint64_t item_flags,
6031 int inner, uint32_t group)
6033 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
6034 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
6035 const struct rte_flow_item_ipv6 nic_mask = {
6038 "\xff\xff\xff\xff\xff\xff\xff\xff"
6039 "\xff\xff\xff\xff\xff\xff\xff\xff",
6041 "\xff\xff\xff\xff\xff\xff\xff\xff"
6042 "\xff\xff\xff\xff\xff\xff\xff\xff",
6043 .vtc_flow = RTE_BE32(0xffffffff),
6050 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6051 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6060 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6062 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6064 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6066 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6068 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
6070 * On outer header (which must contains L2), or inner header with L2,
6071 * set cvlan_tag mask bit to mark this packet as untagged.
6072 * This should be done even if item->spec is empty.
6074 if (!inner || item_flags & MLX5_FLOW_LAYER_INNER_L2)
6075 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
6080 size = sizeof(ipv6_m->hdr.dst_addr);
6081 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6082 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
6083 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6084 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
6085 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
6086 for (i = 0; i < size; ++i)
6087 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
6088 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6089 src_ipv4_src_ipv6.ipv6_layout.ipv6);
6090 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6091 src_ipv4_src_ipv6.ipv6_layout.ipv6);
6092 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
6093 for (i = 0; i < size; ++i)
6094 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
6096 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
6097 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
6098 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
6099 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
6100 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
6101 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
6104 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
6106 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
6109 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
6111 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
6115 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
6117 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6118 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
6120 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
6121 ipv6_m->hdr.hop_limits);
6122 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
6123 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
6127 * Add TCP item to matcher and to the value.
6129 * @param[in, out] matcher
6131 * @param[in, out] key
6132 * Flow matcher value.
6134 * Flow pattern to translate.
6136 * Item is inner pattern.
6139 flow_dv_translate_item_tcp(void *matcher, void *key,
6140 const struct rte_flow_item *item,
6143 const struct rte_flow_item_tcp *tcp_m = item->mask;
6144 const struct rte_flow_item_tcp *tcp_v = item->spec;
6149 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6151 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6153 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6155 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6157 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6158 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
6162 tcp_m = &rte_flow_item_tcp_mask;
6163 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
6164 rte_be_to_cpu_16(tcp_m->hdr.src_port));
6165 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
6166 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
6167 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
6168 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
6169 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
6170 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
6171 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
6172 tcp_m->hdr.tcp_flags);
6173 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
6174 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
6178 * Add UDP item to matcher and to the value.
6180 * @param[in, out] matcher
6182 * @param[in, out] key
6183 * Flow matcher value.
6185 * Flow pattern to translate.
6187 * Item is inner pattern.
6190 flow_dv_translate_item_udp(void *matcher, void *key,
6191 const struct rte_flow_item *item,
6194 const struct rte_flow_item_udp *udp_m = item->mask;
6195 const struct rte_flow_item_udp *udp_v = item->spec;
6200 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6202 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6204 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6206 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6208 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6209 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
6213 udp_m = &rte_flow_item_udp_mask;
6214 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
6215 rte_be_to_cpu_16(udp_m->hdr.src_port));
6216 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
6217 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
6218 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
6219 rte_be_to_cpu_16(udp_m->hdr.dst_port));
6220 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
6221 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
6225 * Add GRE optional Key item to matcher and to the value.
6227 * @param[in, out] matcher
6229 * @param[in, out] key
6230 * Flow matcher value.
6232 * Flow pattern to translate.
6234 * Item is inner pattern.
6237 flow_dv_translate_item_gre_key(void *matcher, void *key,
6238 const struct rte_flow_item *item)
6240 const rte_be32_t *key_m = item->mask;
6241 const rte_be32_t *key_v = item->spec;
6242 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6243 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6244 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6246 /* GRE K bit must be on and should already be validated */
6247 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
6248 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
6252 key_m = &gre_key_default_mask;
6253 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
6254 rte_be_to_cpu_32(*key_m) >> 8);
6255 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
6256 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
6257 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
6258 rte_be_to_cpu_32(*key_m) & 0xFF);
6259 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
6260 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
6264 * Add GRE item to matcher and to the value.
6266 * @param[in, out] matcher
6268 * @param[in, out] key
6269 * Flow matcher value.
6271 * Flow pattern to translate.
6273 * Item is inner pattern.
6276 flow_dv_translate_item_gre(void *matcher, void *key,
6277 const struct rte_flow_item *item,
6280 const struct rte_flow_item_gre *gre_m = item->mask;
6281 const struct rte_flow_item_gre *gre_v = item->spec;
6284 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6285 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6292 uint16_t s_present:1;
6293 uint16_t k_present:1;
6294 uint16_t rsvd_bit1:1;
6295 uint16_t c_present:1;
6299 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
6302 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6304 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6306 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6308 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6310 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6311 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
6315 gre_m = &rte_flow_item_gre_mask;
6316 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
6317 rte_be_to_cpu_16(gre_m->protocol));
6318 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
6319 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
6320 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
6321 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
6322 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
6323 gre_crks_rsvd0_ver_m.c_present);
6324 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
6325 gre_crks_rsvd0_ver_v.c_present &
6326 gre_crks_rsvd0_ver_m.c_present);
6327 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
6328 gre_crks_rsvd0_ver_m.k_present);
6329 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
6330 gre_crks_rsvd0_ver_v.k_present &
6331 gre_crks_rsvd0_ver_m.k_present);
6332 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
6333 gre_crks_rsvd0_ver_m.s_present);
6334 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
6335 gre_crks_rsvd0_ver_v.s_present &
6336 gre_crks_rsvd0_ver_m.s_present);
6340 * Add NVGRE item to matcher and to the value.
6342 * @param[in, out] matcher
6344 * @param[in, out] key
6345 * Flow matcher value.
6347 * Flow pattern to translate.
6349 * Item is inner pattern.
6352 flow_dv_translate_item_nvgre(void *matcher, void *key,
6353 const struct rte_flow_item *item,
6356 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
6357 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
6358 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6359 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6360 const char *tni_flow_id_m = (const char *)nvgre_m->tni;
6361 const char *tni_flow_id_v = (const char *)nvgre_v->tni;
6367 /* For NVGRE, GRE header fields must be set with defined values. */
6368 const struct rte_flow_item_gre gre_spec = {
6369 .c_rsvd0_ver = RTE_BE16(0x2000),
6370 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
6372 const struct rte_flow_item_gre gre_mask = {
6373 .c_rsvd0_ver = RTE_BE16(0xB000),
6374 .protocol = RTE_BE16(UINT16_MAX),
6376 const struct rte_flow_item gre_item = {
6381 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
6385 nvgre_m = &rte_flow_item_nvgre_mask;
6386 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
6387 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
6388 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
6389 memcpy(gre_key_m, tni_flow_id_m, size);
6390 for (i = 0; i < size; ++i)
6391 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
6395 * Add VXLAN item to matcher and to the value.
6397 * @param[in, out] matcher
6399 * @param[in, out] key
6400 * Flow matcher value.
6402 * Flow pattern to translate.
6404 * Item is inner pattern.
6407 flow_dv_translate_item_vxlan(void *matcher, void *key,
6408 const struct rte_flow_item *item,
6411 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
6412 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
6415 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6416 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6424 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6426 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6428 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6430 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6432 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
6433 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
6434 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6435 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6436 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6441 vxlan_m = &rte_flow_item_vxlan_mask;
6442 size = sizeof(vxlan_m->vni);
6443 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
6444 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
6445 memcpy(vni_m, vxlan_m->vni, size);
6446 for (i = 0; i < size; ++i)
6447 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
6451 * Add VXLAN-GPE item to matcher and to the value.
6453 * @param[in, out] matcher
6455 * @param[in, out] key
6456 * Flow matcher value.
6458 * Flow pattern to translate.
6460 * Item is inner pattern.
6464 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
6465 const struct rte_flow_item *item, int inner)
6467 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
6468 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
6472 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
6474 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6480 uint8_t flags_m = 0xff;
6481 uint8_t flags_v = 0xc;
6484 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6486 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6488 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6490 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6492 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
6493 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
6494 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6495 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6496 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6501 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
6502 size = sizeof(vxlan_m->vni);
6503 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
6504 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
6505 memcpy(vni_m, vxlan_m->vni, size);
6506 for (i = 0; i < size; ++i)
6507 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
6508 if (vxlan_m->flags) {
6509 flags_m = vxlan_m->flags;
6510 flags_v = vxlan_v->flags;
6512 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
6513 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
6514 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
6516 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
6521 * Add Geneve item to matcher and to the value.
6523 * @param[in, out] matcher
6525 * @param[in, out] key
6526 * Flow matcher value.
6528 * Flow pattern to translate.
6530 * Item is inner pattern.
6534 flow_dv_translate_item_geneve(void *matcher, void *key,
6535 const struct rte_flow_item *item, int inner)
6537 const struct rte_flow_item_geneve *geneve_m = item->mask;
6538 const struct rte_flow_item_geneve *geneve_v = item->spec;
6541 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6542 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6551 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6553 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6555 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6557 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6559 dport = MLX5_UDP_PORT_GENEVE;
6560 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6561 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6562 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6567 geneve_m = &rte_flow_item_geneve_mask;
6568 size = sizeof(geneve_m->vni);
6569 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
6570 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
6571 memcpy(vni_m, geneve_m->vni, size);
6572 for (i = 0; i < size; ++i)
6573 vni_v[i] = vni_m[i] & geneve_v->vni[i];
6574 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
6575 rte_be_to_cpu_16(geneve_m->protocol));
6576 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
6577 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
6578 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
6579 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
6580 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
6581 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
6582 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
6583 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
6584 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
6585 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
6586 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
6587 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
6588 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
6592 * Add MPLS item to matcher and to the value.
6594 * @param[in, out] matcher
6596 * @param[in, out] key
6597 * Flow matcher value.
6599 * Flow pattern to translate.
6600 * @param[in] prev_layer
6601 * The protocol layer indicated in previous item.
6603 * Item is inner pattern.
6606 flow_dv_translate_item_mpls(void *matcher, void *key,
6607 const struct rte_flow_item *item,
6608 uint64_t prev_layer,
6611 const uint32_t *in_mpls_m = item->mask;
6612 const uint32_t *in_mpls_v = item->spec;
6613 uint32_t *out_mpls_m = 0;
6614 uint32_t *out_mpls_v = 0;
6615 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6616 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6617 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
6619 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
6620 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
6621 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6623 switch (prev_layer) {
6624 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
6625 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
6626 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
6627 MLX5_UDP_PORT_MPLS);
6629 case MLX5_FLOW_LAYER_GRE:
6630 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
6631 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
6632 RTE_ETHER_TYPE_MPLS);
6635 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6636 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6643 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
6644 switch (prev_layer) {
6645 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
6647 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
6648 outer_first_mpls_over_udp);
6650 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
6651 outer_first_mpls_over_udp);
6653 case MLX5_FLOW_LAYER_GRE:
6655 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
6656 outer_first_mpls_over_gre);
6658 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
6659 outer_first_mpls_over_gre);
6662 /* Inner MPLS not over GRE is not supported. */
6665 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
6669 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
6675 if (out_mpls_m && out_mpls_v) {
6676 *out_mpls_m = *in_mpls_m;
6677 *out_mpls_v = *in_mpls_v & *in_mpls_m;
6682 * Add metadata register item to matcher
6684 * @param[in, out] matcher
6686 * @param[in, out] key
6687 * Flow matcher value.
6688 * @param[in] reg_type
6689 * Type of device metadata register
6696 flow_dv_match_meta_reg(void *matcher, void *key,
6697 enum modify_reg reg_type,
6698 uint32_t data, uint32_t mask)
6701 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
6703 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
6709 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
6710 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
6713 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
6714 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
6718 * The metadata register C0 field might be divided into
6719 * source vport index and META item value, we should set
6720 * this field according to specified mask, not as whole one.
6722 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
6724 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
6725 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
6728 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
6731 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
6732 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
6735 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
6736 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
6739 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
6740 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
6743 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
6744 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
6747 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
6748 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
6751 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
6752 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
6755 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
6756 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
6765 * Add MARK item to matcher
6768 * The device to configure through.
6769 * @param[in, out] matcher
6771 * @param[in, out] key
6772 * Flow matcher value.
6774 * Flow pattern to translate.
6777 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
6778 void *matcher, void *key,
6779 const struct rte_flow_item *item)
6781 struct mlx5_priv *priv = dev->data->dev_private;
6782 const struct rte_flow_item_mark *mark;
6786 mark = item->mask ? (const void *)item->mask :
6787 &rte_flow_item_mark_mask;
6788 mask = mark->id & priv->sh->dv_mark_mask;
6789 mark = (const void *)item->spec;
6791 value = mark->id & priv->sh->dv_mark_mask & mask;
6793 enum modify_reg reg;
6795 /* Get the metadata register index for the mark. */
6796 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
6797 MLX5_ASSERT(reg > 0);
6798 if (reg == REG_C_0) {
6799 struct mlx5_priv *priv = dev->data->dev_private;
6800 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6801 uint32_t shl_c0 = rte_bsf32(msk_c0);
6807 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6812 * Add META item to matcher
6815 * The devich to configure through.
6816 * @param[in, out] matcher
6818 * @param[in, out] key
6819 * Flow matcher value.
6821 * Attributes of flow that includes this item.
6823 * Flow pattern to translate.
6826 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
6827 void *matcher, void *key,
6828 const struct rte_flow_attr *attr,
6829 const struct rte_flow_item *item)
6831 const struct rte_flow_item_meta *meta_m;
6832 const struct rte_flow_item_meta *meta_v;
6834 meta_m = (const void *)item->mask;
6836 meta_m = &rte_flow_item_meta_mask;
6837 meta_v = (const void *)item->spec;
6840 uint32_t value = meta_v->data;
6841 uint32_t mask = meta_m->data;
6843 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
6847 * In datapath code there is no endianness
6848 * coversions for perfromance reasons, all
6849 * pattern conversions are done in rte_flow.
6851 value = rte_cpu_to_be_32(value);
6852 mask = rte_cpu_to_be_32(mask);
6853 if (reg == REG_C_0) {
6854 struct mlx5_priv *priv = dev->data->dev_private;
6855 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6856 uint32_t shl_c0 = rte_bsf32(msk_c0);
6857 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
6858 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
6865 MLX5_ASSERT(msk_c0);
6866 MLX5_ASSERT(!(~msk_c0 & mask));
6868 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6873 * Add vport metadata Reg C0 item to matcher
6875 * @param[in, out] matcher
6877 * @param[in, out] key
6878 * Flow matcher value.
6880 * Flow pattern to translate.
6883 flow_dv_translate_item_meta_vport(void *matcher, void *key,
6884 uint32_t value, uint32_t mask)
6886 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
6890 * Add tag item to matcher
6893 * The devich to configure through.
6894 * @param[in, out] matcher
6896 * @param[in, out] key
6897 * Flow matcher value.
6899 * Flow pattern to translate.
6902 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
6903 void *matcher, void *key,
6904 const struct rte_flow_item *item)
6906 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
6907 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
6908 uint32_t mask, value;
6911 value = tag_v->data;
6912 mask = tag_m ? tag_m->data : UINT32_MAX;
6913 if (tag_v->id == REG_C_0) {
6914 struct mlx5_priv *priv = dev->data->dev_private;
6915 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6916 uint32_t shl_c0 = rte_bsf32(msk_c0);
6922 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
6926 * Add TAG item to matcher
6929 * The devich to configure through.
6930 * @param[in, out] matcher
6932 * @param[in, out] key
6933 * Flow matcher value.
6935 * Flow pattern to translate.
6938 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
6939 void *matcher, void *key,
6940 const struct rte_flow_item *item)
6942 const struct rte_flow_item_tag *tag_v = item->spec;
6943 const struct rte_flow_item_tag *tag_m = item->mask;
6944 enum modify_reg reg;
6947 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
6948 /* Get the metadata register index for the tag. */
6949 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
6950 MLX5_ASSERT(reg > 0);
6951 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
6955 * Add source vport match to the specified matcher.
6957 * @param[in, out] matcher
6959 * @param[in, out] key
6960 * Flow matcher value.
6962 * Source vport value to match
6967 flow_dv_translate_item_source_vport(void *matcher, void *key,
6968 int16_t port, uint16_t mask)
6970 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6971 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6973 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
6974 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
6978 * Translate port-id item to eswitch match on port-id.
6981 * The devich to configure through.
6982 * @param[in, out] matcher
6984 * @param[in, out] key
6985 * Flow matcher value.
6987 * Flow pattern to translate.
6990 * 0 on success, a negative errno value otherwise.
6993 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
6994 void *key, const struct rte_flow_item *item)
6996 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
6997 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
6998 struct mlx5_priv *priv;
7001 mask = pid_m ? pid_m->id : 0xffff;
7002 id = pid_v ? pid_v->id : dev->data->port_id;
7003 priv = mlx5_port_to_eswitch_info(id, item == NULL);
7006 /* Translate to vport field or to metadata, depending on mode. */
7007 if (priv->vport_meta_mask)
7008 flow_dv_translate_item_meta_vport(matcher, key,
7009 priv->vport_meta_tag,
7010 priv->vport_meta_mask);
7012 flow_dv_translate_item_source_vport(matcher, key,
7013 priv->vport_id, mask);
7018 * Add ICMP6 item to matcher and to the value.
7020 * @param[in, out] matcher
7022 * @param[in, out] key
7023 * Flow matcher value.
7025 * Flow pattern to translate.
7027 * Item is inner pattern.
7030 flow_dv_translate_item_icmp6(void *matcher, void *key,
7031 const struct rte_flow_item *item,
7034 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
7035 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
7038 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7040 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7042 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7044 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7046 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7048 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7050 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
7051 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
7055 icmp6_m = &rte_flow_item_icmp6_mask;
7057 * Force flow only to match the non-fragmented IPv6 ICMPv6 packets.
7058 * If only the protocol is specified, no need to match the frag.
7060 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
7061 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
7062 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
7063 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
7064 icmp6_v->type & icmp6_m->type);
7065 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
7066 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
7067 icmp6_v->code & icmp6_m->code);
7071 * Add ICMP item to matcher and to the value.
7073 * @param[in, out] matcher
7075 * @param[in, out] key
7076 * Flow matcher value.
7078 * Flow pattern to translate.
7080 * Item is inner pattern.
7083 flow_dv_translate_item_icmp(void *matcher, void *key,
7084 const struct rte_flow_item *item,
7087 const struct rte_flow_item_icmp *icmp_m = item->mask;
7088 const struct rte_flow_item_icmp *icmp_v = item->spec;
7091 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7093 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7095 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7097 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7099 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7101 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7103 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
7104 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
7108 icmp_m = &rte_flow_item_icmp_mask;
7110 * Force flow only to match the non-fragmented IPv4 ICMP packets.
7111 * If only the protocol is specified, no need to match the frag.
7113 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
7114 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
7115 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
7116 icmp_m->hdr.icmp_type);
7117 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
7118 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
7119 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
7120 icmp_m->hdr.icmp_code);
7121 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
7122 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
7126 * Add GTP item to matcher and to the value.
7128 * @param[in, out] matcher
7130 * @param[in, out] key
7131 * Flow matcher value.
7133 * Flow pattern to translate.
7135 * Item is inner pattern.
7138 flow_dv_translate_item_gtp(void *matcher, void *key,
7139 const struct rte_flow_item *item, int inner)
7141 const struct rte_flow_item_gtp *gtp_m = item->mask;
7142 const struct rte_flow_item_gtp *gtp_v = item->spec;
7145 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7147 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7148 uint16_t dport = RTE_GTPU_UDP_PORT;
7151 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7153 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7155 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7157 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7159 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
7160 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
7161 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
7166 gtp_m = &rte_flow_item_gtp_mask;
7167 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
7168 gtp_m->v_pt_rsv_flags);
7169 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
7170 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
7171 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
7172 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
7173 gtp_v->msg_type & gtp_m->msg_type);
7174 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
7175 rte_be_to_cpu_32(gtp_m->teid));
7176 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
7177 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
7180 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
7182 #define HEADER_IS_ZERO(match_criteria, headers) \
7183 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
7184 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
7187 * Calculate flow matcher enable bitmap.
7189 * @param match_criteria
7190 * Pointer to flow matcher criteria.
7193 * Bitmap of enabled fields.
7196 flow_dv_matcher_enable(uint32_t *match_criteria)
7198 uint8_t match_criteria_enable;
7200 match_criteria_enable =
7201 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
7202 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
7203 match_criteria_enable |=
7204 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
7205 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
7206 match_criteria_enable |=
7207 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
7208 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
7209 match_criteria_enable |=
7210 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
7211 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
7212 match_criteria_enable |=
7213 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
7214 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
7215 return match_criteria_enable;
7222 * @param[in, out] dev
7223 * Pointer to rte_eth_dev structure.
7224 * @param[in] table_id
7227 * Direction of the table.
7228 * @param[in] transfer
7229 * E-Switch or NIC flow.
7231 * pointer to error structure.
7234 * Returns tables resource based on the index, NULL in case of failed.
7236 static struct mlx5_flow_tbl_resource *
7237 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
7238 uint32_t table_id, uint8_t egress,
7240 struct rte_flow_error *error)
7242 struct mlx5_priv *priv = dev->data->dev_private;
7243 struct mlx5_dev_ctx_shared *sh = priv->sh;
7244 struct mlx5_flow_tbl_resource *tbl;
7245 union mlx5_flow_tbl_key table_key = {
7247 .table_id = table_id,
7249 .domain = !!transfer,
7250 .direction = !!egress,
7253 struct mlx5_hlist_entry *pos = mlx5_hlist_lookup(sh->flow_tbls,
7255 struct mlx5_flow_tbl_data_entry *tbl_data;
7261 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
7263 tbl = &tbl_data->tbl;
7264 rte_atomic32_inc(&tbl->refcnt);
7267 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
7269 rte_flow_error_set(error, ENOMEM,
7270 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7272 "cannot allocate flow table data entry");
7275 tbl_data->idx = idx;
7276 tbl = &tbl_data->tbl;
7277 pos = &tbl_data->entry;
7279 domain = sh->fdb_domain;
7281 domain = sh->tx_domain;
7283 domain = sh->rx_domain;
7284 tbl->obj = mlx5_glue->dr_create_flow_tbl(domain, table_id);
7286 rte_flow_error_set(error, ENOMEM,
7287 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7288 NULL, "cannot create flow table object");
7289 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
7293 * No multi-threads now, but still better to initialize the reference
7294 * count before insert it into the hash list.
7296 rte_atomic32_init(&tbl->refcnt);
7297 /* Jump action reference count is initialized here. */
7298 rte_atomic32_init(&tbl_data->jump.refcnt);
7299 pos->key = table_key.v64;
7300 ret = mlx5_hlist_insert(sh->flow_tbls, pos);
7302 rte_flow_error_set(error, -ret,
7303 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7304 "cannot insert flow table data entry");
7305 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
7306 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
7308 rte_atomic32_inc(&tbl->refcnt);
7313 * Release a flow table.
7316 * Pointer to rte_eth_dev structure.
7318 * Table resource to be released.
7321 * Returns 0 if table was released, else return 1;
7324 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
7325 struct mlx5_flow_tbl_resource *tbl)
7327 struct mlx5_priv *priv = dev->data->dev_private;
7328 struct mlx5_dev_ctx_shared *sh = priv->sh;
7329 struct mlx5_flow_tbl_data_entry *tbl_data =
7330 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
7334 if (rte_atomic32_dec_and_test(&tbl->refcnt)) {
7335 struct mlx5_hlist_entry *pos = &tbl_data->entry;
7337 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
7339 /* remove the entry from the hash list and free memory. */
7340 mlx5_hlist_remove(sh->flow_tbls, pos);
7341 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_JUMP],
7349 * Register the flow matcher.
7351 * @param[in, out] dev
7352 * Pointer to rte_eth_dev structure.
7353 * @param[in, out] matcher
7354 * Pointer to flow matcher.
7355 * @param[in, out] key
7356 * Pointer to flow table key.
7357 * @parm[in, out] dev_flow
7358 * Pointer to the dev_flow.
7360 * pointer to error structure.
7363 * 0 on success otherwise -errno and errno is set.
7366 flow_dv_matcher_register(struct rte_eth_dev *dev,
7367 struct mlx5_flow_dv_matcher *matcher,
7368 union mlx5_flow_tbl_key *key,
7369 struct mlx5_flow *dev_flow,
7370 struct rte_flow_error *error)
7372 struct mlx5_priv *priv = dev->data->dev_private;
7373 struct mlx5_dev_ctx_shared *sh = priv->sh;
7374 struct mlx5_flow_dv_matcher *cache_matcher;
7375 struct mlx5dv_flow_matcher_attr dv_attr = {
7376 .type = IBV_FLOW_ATTR_NORMAL,
7377 .match_mask = (void *)&matcher->mask,
7379 struct mlx5_flow_tbl_resource *tbl;
7380 struct mlx5_flow_tbl_data_entry *tbl_data;
7382 tbl = flow_dv_tbl_resource_get(dev, key->table_id, key->direction,
7383 key->domain, error);
7385 return -rte_errno; /* No need to refill the error info */
7386 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
7387 /* Lookup from cache. */
7388 LIST_FOREACH(cache_matcher, &tbl_data->matchers, next) {
7389 if (matcher->crc == cache_matcher->crc &&
7390 matcher->priority == cache_matcher->priority &&
7391 !memcmp((const void *)matcher->mask.buf,
7392 (const void *)cache_matcher->mask.buf,
7393 cache_matcher->mask.size)) {
7395 "%s group %u priority %hd use %s "
7396 "matcher %p: refcnt %d++",
7397 key->domain ? "FDB" : "NIC", key->table_id,
7398 cache_matcher->priority,
7399 key->direction ? "tx" : "rx",
7400 (void *)cache_matcher,
7401 rte_atomic32_read(&cache_matcher->refcnt));
7402 rte_atomic32_inc(&cache_matcher->refcnt);
7403 dev_flow->handle->dvh.matcher = cache_matcher;
7404 /* old matcher should not make the table ref++. */
7405 flow_dv_tbl_resource_release(dev, tbl);
7409 /* Register new matcher. */
7410 cache_matcher = rte_calloc(__func__, 1, sizeof(*cache_matcher), 0);
7411 if (!cache_matcher) {
7412 flow_dv_tbl_resource_release(dev, tbl);
7413 return rte_flow_error_set(error, ENOMEM,
7414 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7415 "cannot allocate matcher memory");
7417 *cache_matcher = *matcher;
7418 dv_attr.match_criteria_enable =
7419 flow_dv_matcher_enable(cache_matcher->mask.buf);
7420 dv_attr.priority = matcher->priority;
7422 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
7423 cache_matcher->matcher_object =
7424 mlx5_glue->dv_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj);
7425 if (!cache_matcher->matcher_object) {
7426 rte_free(cache_matcher);
7427 #ifdef HAVE_MLX5DV_DR
7428 flow_dv_tbl_resource_release(dev, tbl);
7430 return rte_flow_error_set(error, ENOMEM,
7431 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7432 NULL, "cannot create matcher");
7434 /* Save the table information */
7435 cache_matcher->tbl = tbl;
7436 rte_atomic32_init(&cache_matcher->refcnt);
7437 /* only matcher ref++, table ref++ already done above in get API. */
7438 rte_atomic32_inc(&cache_matcher->refcnt);
7439 LIST_INSERT_HEAD(&tbl_data->matchers, cache_matcher, next);
7440 dev_flow->handle->dvh.matcher = cache_matcher;
7441 DRV_LOG(DEBUG, "%s group %u priority %hd new %s matcher %p: refcnt %d",
7442 key->domain ? "FDB" : "NIC", key->table_id,
7443 cache_matcher->priority,
7444 key->direction ? "tx" : "rx", (void *)cache_matcher,
7445 rte_atomic32_read(&cache_matcher->refcnt));
7450 * Find existing tag resource or create and register a new one.
7452 * @param dev[in, out]
7453 * Pointer to rte_eth_dev structure.
7454 * @param[in, out] tag_be24
7455 * Tag value in big endian then R-shift 8.
7456 * @parm[in, out] dev_flow
7457 * Pointer to the dev_flow.
7459 * pointer to error structure.
7462 * 0 on success otherwise -errno and errno is set.
7465 flow_dv_tag_resource_register
7466 (struct rte_eth_dev *dev,
7468 struct mlx5_flow *dev_flow,
7469 struct rte_flow_error *error)
7471 struct mlx5_priv *priv = dev->data->dev_private;
7472 struct mlx5_dev_ctx_shared *sh = priv->sh;
7473 struct mlx5_flow_dv_tag_resource *cache_resource;
7474 struct mlx5_hlist_entry *entry;
7476 /* Lookup a matching resource from cache. */
7477 entry = mlx5_hlist_lookup(sh->tag_table, (uint64_t)tag_be24);
7479 cache_resource = container_of
7480 (entry, struct mlx5_flow_dv_tag_resource, entry);
7481 rte_atomic32_inc(&cache_resource->refcnt);
7482 dev_flow->handle->dvh.rix_tag = cache_resource->idx;
7483 dev_flow->dv.tag_resource = cache_resource;
7484 DRV_LOG(DEBUG, "cached tag resource %p: refcnt now %d++",
7485 (void *)cache_resource,
7486 rte_atomic32_read(&cache_resource->refcnt));
7489 /* Register new resource. */
7490 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG],
7491 &dev_flow->handle->dvh.rix_tag);
7492 if (!cache_resource)
7493 return rte_flow_error_set(error, ENOMEM,
7494 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7495 "cannot allocate resource memory");
7496 cache_resource->entry.key = (uint64_t)tag_be24;
7497 cache_resource->action = mlx5_glue->dv_create_flow_action_tag(tag_be24);
7498 if (!cache_resource->action) {
7499 rte_free(cache_resource);
7500 return rte_flow_error_set(error, ENOMEM,
7501 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7502 NULL, "cannot create action");
7504 rte_atomic32_init(&cache_resource->refcnt);
7505 rte_atomic32_inc(&cache_resource->refcnt);
7506 if (mlx5_hlist_insert(sh->tag_table, &cache_resource->entry)) {
7507 mlx5_glue->destroy_flow_action(cache_resource->action);
7508 rte_free(cache_resource);
7509 return rte_flow_error_set(error, EEXIST,
7510 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7511 NULL, "cannot insert tag");
7513 dev_flow->dv.tag_resource = cache_resource;
7514 DRV_LOG(DEBUG, "new tag resource %p: refcnt now %d++",
7515 (void *)cache_resource,
7516 rte_atomic32_read(&cache_resource->refcnt));
7524 * Pointer to Ethernet device.
7529 * 1 while a reference on it exists, 0 when freed.
7532 flow_dv_tag_release(struct rte_eth_dev *dev,
7535 struct mlx5_priv *priv = dev->data->dev_private;
7536 struct mlx5_dev_ctx_shared *sh = priv->sh;
7537 struct mlx5_flow_dv_tag_resource *tag;
7539 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
7542 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
7543 dev->data->port_id, (void *)tag,
7544 rte_atomic32_read(&tag->refcnt));
7545 if (rte_atomic32_dec_and_test(&tag->refcnt)) {
7546 claim_zero(mlx5_glue->destroy_flow_action(tag->action));
7547 mlx5_hlist_remove(sh->tag_table, &tag->entry);
7548 DRV_LOG(DEBUG, "port %u tag %p: removed",
7549 dev->data->port_id, (void *)tag);
7550 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
7557 * Translate port ID action to vport.
7560 * Pointer to rte_eth_dev structure.
7562 * Pointer to the port ID action.
7563 * @param[out] dst_port_id
7564 * The target port ID.
7566 * Pointer to the error structure.
7569 * 0 on success, a negative errno value otherwise and rte_errno is set.
7572 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
7573 const struct rte_flow_action *action,
7574 uint32_t *dst_port_id,
7575 struct rte_flow_error *error)
7578 struct mlx5_priv *priv;
7579 const struct rte_flow_action_port_id *conf =
7580 (const struct rte_flow_action_port_id *)action->conf;
7582 port = conf->original ? dev->data->port_id : conf->id;
7583 priv = mlx5_port_to_eswitch_info(port, false);
7585 return rte_flow_error_set(error, -rte_errno,
7586 RTE_FLOW_ERROR_TYPE_ACTION,
7588 "No eswitch info was found for port");
7589 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
7591 * This parameter is transferred to
7592 * mlx5dv_dr_action_create_dest_ib_port().
7594 *dst_port_id = priv->dev_port;
7597 * Legacy mode, no LAG configurations is supported.
7598 * This parameter is transferred to
7599 * mlx5dv_dr_action_create_dest_vport().
7601 *dst_port_id = priv->vport_id;
7607 * Create a counter with aging configuration.
7610 * Pointer to rte_eth_dev structure.
7612 * Pointer to the counter action configuration.
7614 * Pointer to the aging action configuration.
7617 * Index to flow counter on success, 0 otherwise.
7620 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
7621 struct mlx5_flow *dev_flow,
7622 const struct rte_flow_action_count *count,
7623 const struct rte_flow_action_age *age)
7626 struct mlx5_age_param *age_param;
7628 counter = flow_dv_counter_alloc(dev,
7629 count ? count->shared : 0,
7630 count ? count->id : 0,
7631 dev_flow->dv.group, !!age);
7632 if (!counter || age == NULL)
7634 age_param = flow_dv_counter_idx_get_age(dev, counter);
7636 * The counter age accuracy may have a bit delay. Have 3/4
7637 * second bias on the timeount in order to let it age in time.
7639 age_param->context = age->context ? age->context :
7640 (void *)(uintptr_t)(dev_flow->flow_idx);
7642 * The counter age accuracy may have a bit delay. Have 3/4
7643 * second bias on the timeount in order to let it age in time.
7645 age_param->timeout = age->timeout * 10 - MLX5_AGING_TIME_DELAY;
7646 /* Set expire time in unit of 0.1 sec. */
7647 age_param->port_id = dev->data->port_id;
7648 age_param->expire = age_param->timeout +
7649 rte_rdtsc() / (rte_get_tsc_hz() / 10);
7650 rte_atomic16_set(&age_param->state, AGE_CANDIDATE);
7654 * Add Tx queue matcher
7657 * Pointer to the dev struct.
7658 * @param[in, out] matcher
7660 * @param[in, out] key
7661 * Flow matcher value.
7663 * Flow pattern to translate.
7665 * Item is inner pattern.
7668 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
7669 void *matcher, void *key,
7670 const struct rte_flow_item *item)
7672 const struct mlx5_rte_flow_item_tx_queue *queue_m;
7673 const struct mlx5_rte_flow_item_tx_queue *queue_v;
7675 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7677 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7678 struct mlx5_txq_ctrl *txq;
7682 queue_m = (const void *)item->mask;
7685 queue_v = (const void *)item->spec;
7688 txq = mlx5_txq_get(dev, queue_v->queue);
7691 queue = txq->obj->sq->id;
7692 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
7693 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
7694 queue & queue_m->queue);
7695 mlx5_txq_release(dev, queue_v->queue);
7699 * Set the hash fields according to the @p flow information.
7701 * @param[in] dev_flow
7702 * Pointer to the mlx5_flow.
7703 * @param[in] rss_desc
7704 * Pointer to the mlx5_flow_rss_desc.
7707 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
7708 struct mlx5_flow_rss_desc *rss_desc)
7710 uint64_t items = dev_flow->handle->layers;
7712 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
7714 dev_flow->hash_fields = 0;
7715 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
7716 if (rss_desc->level >= 2) {
7717 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
7721 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
7722 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
7723 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
7724 if (rss_types & ETH_RSS_L3_SRC_ONLY)
7725 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
7726 else if (rss_types & ETH_RSS_L3_DST_ONLY)
7727 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
7729 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
7731 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
7732 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
7733 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
7734 if (rss_types & ETH_RSS_L3_SRC_ONLY)
7735 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
7736 else if (rss_types & ETH_RSS_L3_DST_ONLY)
7737 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
7739 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
7742 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
7743 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
7744 if (rss_types & ETH_RSS_UDP) {
7745 if (rss_types & ETH_RSS_L4_SRC_ONLY)
7746 dev_flow->hash_fields |=
7747 IBV_RX_HASH_SRC_PORT_UDP;
7748 else if (rss_types & ETH_RSS_L4_DST_ONLY)
7749 dev_flow->hash_fields |=
7750 IBV_RX_HASH_DST_PORT_UDP;
7752 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
7754 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
7755 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
7756 if (rss_types & ETH_RSS_TCP) {
7757 if (rss_types & ETH_RSS_L4_SRC_ONLY)
7758 dev_flow->hash_fields |=
7759 IBV_RX_HASH_SRC_PORT_TCP;
7760 else if (rss_types & ETH_RSS_L4_DST_ONLY)
7761 dev_flow->hash_fields |=
7762 IBV_RX_HASH_DST_PORT_TCP;
7764 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
7770 * Fill the flow with DV spec, lock free
7771 * (mutex should be acquired by caller).
7774 * Pointer to rte_eth_dev structure.
7775 * @param[in, out] dev_flow
7776 * Pointer to the sub flow.
7778 * Pointer to the flow attributes.
7780 * Pointer to the list of items.
7781 * @param[in] actions
7782 * Pointer to the list of actions.
7784 * Pointer to the error structure.
7787 * 0 on success, a negative errno value otherwise and rte_errno is set.
7790 __flow_dv_translate(struct rte_eth_dev *dev,
7791 struct mlx5_flow *dev_flow,
7792 const struct rte_flow_attr *attr,
7793 const struct rte_flow_item items[],
7794 const struct rte_flow_action actions[],
7795 struct rte_flow_error *error)
7797 struct mlx5_priv *priv = dev->data->dev_private;
7798 struct mlx5_dev_config *dev_conf = &priv->config;
7799 struct rte_flow *flow = dev_flow->flow;
7800 struct mlx5_flow_handle *handle = dev_flow->handle;
7801 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
7803 [!!priv->flow_nested_idx];
7804 uint64_t item_flags = 0;
7805 uint64_t last_item = 0;
7806 uint64_t action_flags = 0;
7807 uint64_t priority = attr->priority;
7808 struct mlx5_flow_dv_matcher matcher = {
7810 .size = sizeof(matcher.mask.buf),
7814 bool actions_end = false;
7816 struct mlx5_flow_dv_modify_hdr_resource res;
7817 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
7818 sizeof(struct mlx5_modification_cmd) *
7819 (MLX5_MAX_MODIFY_NUM + 1)];
7821 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
7822 const struct rte_flow_action_count *count = NULL;
7823 const struct rte_flow_action_age *age = NULL;
7824 union flow_dv_attr flow_attr = { .attr = 0 };
7826 union mlx5_flow_tbl_key tbl_key;
7827 uint32_t modify_action_position = UINT32_MAX;
7828 void *match_mask = matcher.mask.buf;
7829 void *match_value = dev_flow->dv.value.buf;
7830 uint8_t next_protocol = 0xff;
7831 struct rte_vlan_hdr vlan = { 0 };
7835 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
7836 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
7837 ret = mlx5_flow_group_to_table(attr, dev_flow->external, attr->group,
7838 !!priv->fdb_def_rule, &table, error);
7841 dev_flow->dv.group = table;
7843 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
7844 if (priority == MLX5_FLOW_PRIO_RSVD)
7845 priority = dev_conf->flow_prio - 1;
7846 /* number of actions must be set to 0 in case of dirty stack. */
7847 mhdr_res->actions_num = 0;
7848 for (; !actions_end ; actions++) {
7849 const struct rte_flow_action_queue *queue;
7850 const struct rte_flow_action_rss *rss;
7851 const struct rte_flow_action *action = actions;
7852 const uint8_t *rss_key;
7853 const struct rte_flow_action_jump *jump_data;
7854 const struct rte_flow_action_meter *mtr;
7855 struct mlx5_flow_tbl_resource *tbl;
7856 uint32_t port_id = 0;
7857 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
7858 int action_type = actions->type;
7859 const struct rte_flow_action *found_action = NULL;
7860 struct mlx5_flow_meter *fm = NULL;
7862 switch (action_type) {
7863 case RTE_FLOW_ACTION_TYPE_VOID:
7865 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7866 if (flow_dv_translate_action_port_id(dev, action,
7869 port_id_resource.port_id = port_id;
7870 MLX5_ASSERT(!handle->rix_port_id_action);
7871 if (flow_dv_port_id_action_resource_register
7872 (dev, &port_id_resource, dev_flow, error))
7874 dev_flow->dv.actions[actions_n++] =
7875 dev_flow->dv.port_id_action->action;
7876 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7877 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
7879 case RTE_FLOW_ACTION_TYPE_FLAG:
7880 action_flags |= MLX5_FLOW_ACTION_FLAG;
7881 dev_flow->handle->mark = 1;
7882 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7883 struct rte_flow_action_mark mark = {
7884 .id = MLX5_FLOW_MARK_DEFAULT,
7887 if (flow_dv_convert_action_mark(dev, &mark,
7891 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
7894 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
7896 * Only one FLAG or MARK is supported per device flow
7897 * right now. So the pointer to the tag resource must be
7898 * zero before the register process.
7900 MLX5_ASSERT(!handle->dvh.rix_tag);
7901 if (flow_dv_tag_resource_register(dev, tag_be,
7904 MLX5_ASSERT(dev_flow->dv.tag_resource);
7905 dev_flow->dv.actions[actions_n++] =
7906 dev_flow->dv.tag_resource->action;
7908 case RTE_FLOW_ACTION_TYPE_MARK:
7909 action_flags |= MLX5_FLOW_ACTION_MARK;
7910 dev_flow->handle->mark = 1;
7911 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7912 const struct rte_flow_action_mark *mark =
7913 (const struct rte_flow_action_mark *)
7916 if (flow_dv_convert_action_mark(dev, mark,
7920 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
7924 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7925 /* Legacy (non-extensive) MARK action. */
7926 tag_be = mlx5_flow_mark_set
7927 (((const struct rte_flow_action_mark *)
7928 (actions->conf))->id);
7929 MLX5_ASSERT(!handle->dvh.rix_tag);
7930 if (flow_dv_tag_resource_register(dev, tag_be,
7933 MLX5_ASSERT(dev_flow->dv.tag_resource);
7934 dev_flow->dv.actions[actions_n++] =
7935 dev_flow->dv.tag_resource->action;
7937 case RTE_FLOW_ACTION_TYPE_SET_META:
7938 if (flow_dv_convert_action_set_meta
7939 (dev, mhdr_res, attr,
7940 (const struct rte_flow_action_set_meta *)
7941 actions->conf, error))
7943 action_flags |= MLX5_FLOW_ACTION_SET_META;
7945 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7946 if (flow_dv_convert_action_set_tag
7948 (const struct rte_flow_action_set_tag *)
7949 actions->conf, error))
7951 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7953 case RTE_FLOW_ACTION_TYPE_DROP:
7954 action_flags |= MLX5_FLOW_ACTION_DROP;
7955 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
7957 case RTE_FLOW_ACTION_TYPE_QUEUE:
7958 queue = actions->conf;
7959 rss_desc->queue_num = 1;
7960 rss_desc->queue[0] = queue->index;
7961 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7962 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
7964 case RTE_FLOW_ACTION_TYPE_RSS:
7965 rss = actions->conf;
7966 memcpy(rss_desc->queue, rss->queue,
7967 rss->queue_num * sizeof(uint16_t));
7968 rss_desc->queue_num = rss->queue_num;
7969 /* NULL RSS key indicates default RSS key. */
7970 rss_key = !rss->key ? rss_hash_default_key : rss->key;
7971 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
7973 * rss->level and rss.types should be set in advance
7974 * when expanding items for RSS.
7976 action_flags |= MLX5_FLOW_ACTION_RSS;
7977 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
7979 case RTE_FLOW_ACTION_TYPE_AGE:
7980 case RTE_FLOW_ACTION_TYPE_COUNT:
7981 if (!dev_conf->devx) {
7982 return rte_flow_error_set
7984 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7986 "count action not supported");
7988 /* Save information first, will apply later. */
7989 if (actions->type == RTE_FLOW_ACTION_TYPE_COUNT)
7990 count = action->conf;
7993 action_flags |= MLX5_FLOW_ACTION_COUNT;
7995 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7996 dev_flow->dv.actions[actions_n++] =
7997 priv->sh->pop_vlan_action;
7998 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8000 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8001 if (!(action_flags &
8002 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
8003 flow_dev_get_vlan_info_from_items(items, &vlan);
8004 vlan.eth_proto = rte_be_to_cpu_16
8005 ((((const struct rte_flow_action_of_push_vlan *)
8006 actions->conf)->ethertype));
8007 found_action = mlx5_flow_find_action
8009 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
8011 mlx5_update_vlan_vid_pcp(found_action, &vlan);
8012 found_action = mlx5_flow_find_action
8014 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
8016 mlx5_update_vlan_vid_pcp(found_action, &vlan);
8017 if (flow_dv_create_action_push_vlan
8018 (dev, attr, &vlan, dev_flow, error))
8020 dev_flow->dv.actions[actions_n++] =
8021 dev_flow->dv.push_vlan_res->action;
8022 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8024 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8025 /* of_vlan_push action handled this action */
8026 MLX5_ASSERT(action_flags &
8027 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
8029 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8030 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
8032 flow_dev_get_vlan_info_from_items(items, &vlan);
8033 mlx5_update_vlan_vid_pcp(actions, &vlan);
8034 /* If no VLAN push - this is a modify header action */
8035 if (flow_dv_convert_action_modify_vlan_vid
8036 (mhdr_res, actions, error))
8038 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8040 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8041 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8042 if (flow_dv_create_action_l2_encap(dev, actions,
8047 dev_flow->dv.actions[actions_n++] =
8048 dev_flow->dv.encap_decap->verbs_action;
8049 action_flags |= MLX5_FLOW_ACTION_ENCAP;
8051 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8052 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8053 if (flow_dv_create_action_l2_decap(dev, dev_flow,
8057 dev_flow->dv.actions[actions_n++] =
8058 dev_flow->dv.encap_decap->verbs_action;
8059 action_flags |= MLX5_FLOW_ACTION_DECAP;
8061 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8062 /* Handle encap with preceding decap. */
8063 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
8064 if (flow_dv_create_action_raw_encap
8065 (dev, actions, dev_flow, attr, error))
8067 dev_flow->dv.actions[actions_n++] =
8068 dev_flow->dv.encap_decap->verbs_action;
8070 /* Handle encap without preceding decap. */
8071 if (flow_dv_create_action_l2_encap
8072 (dev, actions, dev_flow, attr->transfer,
8075 dev_flow->dv.actions[actions_n++] =
8076 dev_flow->dv.encap_decap->verbs_action;
8078 action_flags |= MLX5_FLOW_ACTION_ENCAP;
8080 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8081 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
8083 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8084 if (flow_dv_create_action_l2_decap
8085 (dev, dev_flow, attr->transfer, error))
8087 dev_flow->dv.actions[actions_n++] =
8088 dev_flow->dv.encap_decap->verbs_action;
8090 /* If decap is followed by encap, handle it at encap. */
8091 action_flags |= MLX5_FLOW_ACTION_DECAP;
8093 case RTE_FLOW_ACTION_TYPE_JUMP:
8094 jump_data = action->conf;
8095 ret = mlx5_flow_group_to_table(attr, dev_flow->external,
8097 !!priv->fdb_def_rule,
8101 tbl = flow_dv_tbl_resource_get(dev, table,
8103 attr->transfer, error);
8105 return rte_flow_error_set
8107 RTE_FLOW_ERROR_TYPE_ACTION,
8109 "cannot create jump action.");
8110 if (flow_dv_jump_tbl_resource_register
8111 (dev, tbl, dev_flow, error)) {
8112 flow_dv_tbl_resource_release(dev, tbl);
8113 return rte_flow_error_set
8115 RTE_FLOW_ERROR_TYPE_ACTION,
8117 "cannot create jump action.");
8119 dev_flow->dv.actions[actions_n++] =
8120 dev_flow->dv.jump->action;
8121 action_flags |= MLX5_FLOW_ACTION_JUMP;
8122 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
8124 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8125 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8126 if (flow_dv_convert_action_modify_mac
8127 (mhdr_res, actions, error))
8129 action_flags |= actions->type ==
8130 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8131 MLX5_FLOW_ACTION_SET_MAC_SRC :
8132 MLX5_FLOW_ACTION_SET_MAC_DST;
8134 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8135 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8136 if (flow_dv_convert_action_modify_ipv4
8137 (mhdr_res, actions, error))
8139 action_flags |= actions->type ==
8140 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8141 MLX5_FLOW_ACTION_SET_IPV4_SRC :
8142 MLX5_FLOW_ACTION_SET_IPV4_DST;
8144 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8145 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8146 if (flow_dv_convert_action_modify_ipv6
8147 (mhdr_res, actions, error))
8149 action_flags |= actions->type ==
8150 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8151 MLX5_FLOW_ACTION_SET_IPV6_SRC :
8152 MLX5_FLOW_ACTION_SET_IPV6_DST;
8154 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8155 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8156 if (flow_dv_convert_action_modify_tp
8157 (mhdr_res, actions, items,
8158 &flow_attr, dev_flow, !!(action_flags &
8159 MLX5_FLOW_ACTION_DECAP), error))
8161 action_flags |= actions->type ==
8162 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8163 MLX5_FLOW_ACTION_SET_TP_SRC :
8164 MLX5_FLOW_ACTION_SET_TP_DST;
8166 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8167 if (flow_dv_convert_action_modify_dec_ttl
8168 (mhdr_res, items, &flow_attr, dev_flow,
8170 MLX5_FLOW_ACTION_DECAP), error))
8172 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
8174 case RTE_FLOW_ACTION_TYPE_SET_TTL:
8175 if (flow_dv_convert_action_modify_ttl
8176 (mhdr_res, actions, items, &flow_attr,
8177 dev_flow, !!(action_flags &
8178 MLX5_FLOW_ACTION_DECAP), error))
8180 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
8182 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8183 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8184 if (flow_dv_convert_action_modify_tcp_seq
8185 (mhdr_res, actions, error))
8187 action_flags |= actions->type ==
8188 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8189 MLX5_FLOW_ACTION_INC_TCP_SEQ :
8190 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8193 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8194 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8195 if (flow_dv_convert_action_modify_tcp_ack
8196 (mhdr_res, actions, error))
8198 action_flags |= actions->type ==
8199 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8200 MLX5_FLOW_ACTION_INC_TCP_ACK :
8201 MLX5_FLOW_ACTION_DEC_TCP_ACK;
8203 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8204 if (flow_dv_convert_action_set_reg
8205 (mhdr_res, actions, error))
8207 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8209 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8210 if (flow_dv_convert_action_copy_mreg
8211 (dev, mhdr_res, actions, error))
8213 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8215 case RTE_FLOW_ACTION_TYPE_METER:
8216 mtr = actions->conf;
8218 fm = mlx5_flow_meter_attach(priv, mtr->mtr_id,
8221 return rte_flow_error_set(error,
8223 RTE_FLOW_ERROR_TYPE_ACTION,
8226 "or invalid parameters");
8227 flow->meter = fm->idx;
8229 /* Set the meter action. */
8231 fm = mlx5_ipool_get(priv->sh->ipool
8232 [MLX5_IPOOL_MTR], flow->meter);
8234 return rte_flow_error_set(error,
8236 RTE_FLOW_ERROR_TYPE_ACTION,
8239 "or invalid parameters");
8241 dev_flow->dv.actions[actions_n++] =
8242 fm->mfts->meter_action;
8243 action_flags |= MLX5_FLOW_ACTION_METER;
8245 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8246 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
8249 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8251 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8252 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
8255 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8257 case RTE_FLOW_ACTION_TYPE_END:
8259 if (mhdr_res->actions_num) {
8260 /* create modify action if needed. */
8261 if (flow_dv_modify_hdr_resource_register
8262 (dev, mhdr_res, dev_flow, error))
8264 dev_flow->dv.actions[modify_action_position] =
8265 handle->dvh.modify_hdr->verbs_action;
8267 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
8269 flow_dv_translate_create_counter(dev,
8270 dev_flow, count, age);
8273 return rte_flow_error_set
8275 RTE_FLOW_ERROR_TYPE_ACTION,
8277 "cannot create counter"
8279 dev_flow->dv.actions[actions_n++] =
8280 (flow_dv_counter_get_by_idx(dev,
8281 flow->counter, NULL))->action;
8287 if (mhdr_res->actions_num &&
8288 modify_action_position == UINT32_MAX)
8289 modify_action_position = actions_n++;
8291 dev_flow->dv.actions_n = actions_n;
8292 dev_flow->act_flags = action_flags;
8293 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
8294 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
8295 int item_type = items->type;
8297 switch (item_type) {
8298 case RTE_FLOW_ITEM_TYPE_PORT_ID:
8299 flow_dv_translate_item_port_id(dev, match_mask,
8300 match_value, items);
8301 last_item = MLX5_FLOW_ITEM_PORT_ID;
8303 case RTE_FLOW_ITEM_TYPE_ETH:
8304 flow_dv_translate_item_eth(match_mask, match_value,
8306 dev_flow->dv.group);
8307 matcher.priority = MLX5_PRIORITY_MAP_L2;
8308 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
8309 MLX5_FLOW_LAYER_OUTER_L2;
8311 case RTE_FLOW_ITEM_TYPE_VLAN:
8312 flow_dv_translate_item_vlan(dev_flow,
8313 match_mask, match_value,
8315 dev_flow->dv.group);
8316 matcher.priority = MLX5_PRIORITY_MAP_L2;
8317 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
8318 MLX5_FLOW_LAYER_INNER_VLAN) :
8319 (MLX5_FLOW_LAYER_OUTER_L2 |
8320 MLX5_FLOW_LAYER_OUTER_VLAN);
8322 case RTE_FLOW_ITEM_TYPE_IPV4:
8323 mlx5_flow_tunnel_ip_check(items, next_protocol,
8324 &item_flags, &tunnel);
8325 flow_dv_translate_item_ipv4(match_mask, match_value,
8326 items, item_flags, tunnel,
8327 dev_flow->dv.group);
8328 matcher.priority = MLX5_PRIORITY_MAP_L3;
8329 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
8330 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
8331 if (items->mask != NULL &&
8332 ((const struct rte_flow_item_ipv4 *)
8333 items->mask)->hdr.next_proto_id) {
8335 ((const struct rte_flow_item_ipv4 *)
8336 (items->spec))->hdr.next_proto_id;
8338 ((const struct rte_flow_item_ipv4 *)
8339 (items->mask))->hdr.next_proto_id;
8341 /* Reset for inner layer. */
8342 next_protocol = 0xff;
8345 case RTE_FLOW_ITEM_TYPE_IPV6:
8346 mlx5_flow_tunnel_ip_check(items, next_protocol,
8347 &item_flags, &tunnel);
8348 flow_dv_translate_item_ipv6(match_mask, match_value,
8349 items, item_flags, tunnel,
8350 dev_flow->dv.group);
8351 matcher.priority = MLX5_PRIORITY_MAP_L3;
8352 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
8353 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
8354 if (items->mask != NULL &&
8355 ((const struct rte_flow_item_ipv6 *)
8356 items->mask)->hdr.proto) {
8358 ((const struct rte_flow_item_ipv6 *)
8359 items->spec)->hdr.proto;
8361 ((const struct rte_flow_item_ipv6 *)
8362 items->mask)->hdr.proto;
8364 /* Reset for inner layer. */
8365 next_protocol = 0xff;
8368 case RTE_FLOW_ITEM_TYPE_TCP:
8369 flow_dv_translate_item_tcp(match_mask, match_value,
8371 matcher.priority = MLX5_PRIORITY_MAP_L4;
8372 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
8373 MLX5_FLOW_LAYER_OUTER_L4_TCP;
8375 case RTE_FLOW_ITEM_TYPE_UDP:
8376 flow_dv_translate_item_udp(match_mask, match_value,
8378 matcher.priority = MLX5_PRIORITY_MAP_L4;
8379 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
8380 MLX5_FLOW_LAYER_OUTER_L4_UDP;
8382 case RTE_FLOW_ITEM_TYPE_GRE:
8383 flow_dv_translate_item_gre(match_mask, match_value,
8385 matcher.priority = rss_desc->level >= 2 ?
8386 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8387 last_item = MLX5_FLOW_LAYER_GRE;
8389 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
8390 flow_dv_translate_item_gre_key(match_mask,
8391 match_value, items);
8392 last_item = MLX5_FLOW_LAYER_GRE_KEY;
8394 case RTE_FLOW_ITEM_TYPE_NVGRE:
8395 flow_dv_translate_item_nvgre(match_mask, match_value,
8397 matcher.priority = rss_desc->level >= 2 ?
8398 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8399 last_item = MLX5_FLOW_LAYER_GRE;
8401 case RTE_FLOW_ITEM_TYPE_VXLAN:
8402 flow_dv_translate_item_vxlan(match_mask, match_value,
8404 matcher.priority = rss_desc->level >= 2 ?
8405 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8406 last_item = MLX5_FLOW_LAYER_VXLAN;
8408 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
8409 flow_dv_translate_item_vxlan_gpe(match_mask,
8412 matcher.priority = rss_desc->level >= 2 ?
8413 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8414 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8416 case RTE_FLOW_ITEM_TYPE_GENEVE:
8417 flow_dv_translate_item_geneve(match_mask, match_value,
8419 matcher.priority = rss_desc->level >= 2 ?
8420 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8421 last_item = MLX5_FLOW_LAYER_GENEVE;
8423 case RTE_FLOW_ITEM_TYPE_MPLS:
8424 flow_dv_translate_item_mpls(match_mask, match_value,
8425 items, last_item, tunnel);
8426 matcher.priority = rss_desc->level >= 2 ?
8427 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8428 last_item = MLX5_FLOW_LAYER_MPLS;
8430 case RTE_FLOW_ITEM_TYPE_MARK:
8431 flow_dv_translate_item_mark(dev, match_mask,
8432 match_value, items);
8433 last_item = MLX5_FLOW_ITEM_MARK;
8435 case RTE_FLOW_ITEM_TYPE_META:
8436 flow_dv_translate_item_meta(dev, match_mask,
8437 match_value, attr, items);
8438 last_item = MLX5_FLOW_ITEM_METADATA;
8440 case RTE_FLOW_ITEM_TYPE_ICMP:
8441 flow_dv_translate_item_icmp(match_mask, match_value,
8443 last_item = MLX5_FLOW_LAYER_ICMP;
8445 case RTE_FLOW_ITEM_TYPE_ICMP6:
8446 flow_dv_translate_item_icmp6(match_mask, match_value,
8448 last_item = MLX5_FLOW_LAYER_ICMP6;
8450 case RTE_FLOW_ITEM_TYPE_TAG:
8451 flow_dv_translate_item_tag(dev, match_mask,
8452 match_value, items);
8453 last_item = MLX5_FLOW_ITEM_TAG;
8455 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8456 flow_dv_translate_mlx5_item_tag(dev, match_mask,
8457 match_value, items);
8458 last_item = MLX5_FLOW_ITEM_TAG;
8460 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8461 flow_dv_translate_item_tx_queue(dev, match_mask,
8464 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
8466 case RTE_FLOW_ITEM_TYPE_GTP:
8467 flow_dv_translate_item_gtp(match_mask, match_value,
8469 matcher.priority = rss_desc->level >= 2 ?
8470 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8471 last_item = MLX5_FLOW_LAYER_GTP;
8476 item_flags |= last_item;
8479 * When E-Switch mode is enabled, we have two cases where we need to
8480 * set the source port manually.
8481 * The first one, is in case of Nic steering rule, and the second is
8482 * E-Switch rule where no port_id item was found. In both cases
8483 * the source port is set according the current port in use.
8485 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
8486 (priv->representor || priv->master)) {
8487 if (flow_dv_translate_item_port_id(dev, match_mask,
8491 #ifdef RTE_LIBRTE_MLX5_DEBUG
8492 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
8493 dev_flow->dv.value.buf));
8496 * Layers may be already initialized from prefix flow if this dev_flow
8497 * is the suffix flow.
8499 handle->layers |= item_flags;
8500 if (action_flags & MLX5_FLOW_ACTION_RSS)
8501 flow_dv_hashfields_set(dev_flow, rss_desc);
8502 /* Register matcher. */
8503 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
8505 matcher.priority = mlx5_flow_adjust_priority(dev, priority,
8507 /* reserved field no needs to be set to 0 here. */
8508 tbl_key.domain = attr->transfer;
8509 tbl_key.direction = attr->egress;
8510 tbl_key.table_id = dev_flow->dv.group;
8511 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow, error))
8517 * Apply the flow to the NIC, lock free,
8518 * (mutex should be acquired by caller).
8521 * Pointer to the Ethernet device structure.
8522 * @param[in, out] flow
8523 * Pointer to flow structure.
8525 * Pointer to error structure.
8528 * 0 on success, a negative errno value otherwise and rte_errno is set.
8531 __flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
8532 struct rte_flow_error *error)
8534 struct mlx5_flow_dv_workspace *dv;
8535 struct mlx5_flow_handle *dh;
8536 struct mlx5_flow_handle_dv *dv_h;
8537 struct mlx5_flow *dev_flow;
8538 struct mlx5_priv *priv = dev->data->dev_private;
8539 uint32_t handle_idx;
8544 for (idx = priv->flow_idx - 1; idx >= priv->flow_nested_idx; idx--) {
8545 dev_flow = &((struct mlx5_flow *)priv->inter_flows)[idx];
8547 dh = dev_flow->handle;
8550 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
8552 dv->actions[n++] = priv->sh->esw_drop_action;
8554 struct mlx5_hrxq *drop_hrxq;
8555 drop_hrxq = mlx5_hrxq_drop_new(dev);
8559 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8561 "cannot get drop hash queue");
8565 * Drop queues will be released by the specify
8566 * mlx5_hrxq_drop_release() function. Assign
8567 * the special index to hrxq to mark the queue
8568 * has been allocated.
8570 dh->rix_hrxq = UINT32_MAX;
8571 dv->actions[n++] = drop_hrxq->action;
8573 } else if (dh->fate_action == MLX5_FLOW_FATE_QUEUE) {
8574 struct mlx5_hrxq *hrxq;
8576 struct mlx5_flow_rss_desc *rss_desc =
8577 &((struct mlx5_flow_rss_desc *)priv->rss_desc)
8578 [!!priv->flow_nested_idx];
8580 MLX5_ASSERT(rss_desc->queue_num);
8581 hrxq_idx = mlx5_hrxq_get(dev, rss_desc->key,
8582 MLX5_RSS_HASH_KEY_LEN,
8583 dev_flow->hash_fields,
8585 rss_desc->queue_num);
8587 hrxq_idx = mlx5_hrxq_new
8588 (dev, rss_desc->key,
8589 MLX5_RSS_HASH_KEY_LEN,
8590 dev_flow->hash_fields,
8592 rss_desc->queue_num,
8594 MLX5_FLOW_LAYER_TUNNEL));
8596 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
8601 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8602 "cannot get hash queue");
8605 dh->rix_hrxq = hrxq_idx;
8606 dv->actions[n++] = hrxq->action;
8609 mlx5_glue->dv_create_flow(dv_h->matcher->matcher_object,
8610 (void *)&dv->value, n,
8613 rte_flow_error_set(error, errno,
8614 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8616 "hardware refuses to create flow");
8619 if (priv->vmwa_context &&
8620 dh->vf_vlan.tag && !dh->vf_vlan.created) {
8622 * The rule contains the VLAN pattern.
8623 * For VF we are going to create VLAN
8624 * interface to make hypervisor set correct
8625 * e-Switch vport context.
8627 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
8632 err = rte_errno; /* Save rte_errno before cleanup. */
8633 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
8634 handle_idx, dh, next) {
8635 /* hrxq is union, don't clear it if the flag is not set. */
8637 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
8638 mlx5_hrxq_drop_release(dev);
8640 } else if (dh->fate_action == MLX5_FLOW_FATE_QUEUE) {
8641 mlx5_hrxq_release(dev, dh->rix_hrxq);
8645 if (dh->vf_vlan.tag && dh->vf_vlan.created)
8646 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
8648 rte_errno = err; /* Restore rte_errno. */
8653 * Release the flow matcher.
8656 * Pointer to Ethernet device.
8658 * Pointer to mlx5_flow_handle.
8661 * 1 while a reference on it exists, 0 when freed.
8664 flow_dv_matcher_release(struct rte_eth_dev *dev,
8665 struct mlx5_flow_handle *handle)
8667 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
8669 MLX5_ASSERT(matcher->matcher_object);
8670 DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
8671 dev->data->port_id, (void *)matcher,
8672 rte_atomic32_read(&matcher->refcnt));
8673 if (rte_atomic32_dec_and_test(&matcher->refcnt)) {
8674 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8675 (matcher->matcher_object));
8676 LIST_REMOVE(matcher, next);
8677 /* table ref-- in release interface. */
8678 flow_dv_tbl_resource_release(dev, matcher->tbl);
8680 DRV_LOG(DEBUG, "port %u matcher %p: removed",
8681 dev->data->port_id, (void *)matcher);
8688 * Release an encap/decap resource.
8691 * Pointer to Ethernet device.
8693 * Pointer to mlx5_flow_handle.
8696 * 1 while a reference on it exists, 0 when freed.
8699 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
8700 struct mlx5_flow_handle *handle)
8702 struct mlx5_priv *priv = dev->data->dev_private;
8703 uint32_t idx = handle->dvh.rix_encap_decap;
8704 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
8706 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
8708 if (!cache_resource)
8710 MLX5_ASSERT(cache_resource->verbs_action);
8711 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d--",
8712 (void *)cache_resource,
8713 rte_atomic32_read(&cache_resource->refcnt));
8714 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8715 claim_zero(mlx5_glue->destroy_flow_action
8716 (cache_resource->verbs_action));
8717 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
8718 &priv->sh->encaps_decaps, idx,
8719 cache_resource, next);
8720 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
8721 DRV_LOG(DEBUG, "encap/decap resource %p: removed",
8722 (void *)cache_resource);
8729 * Release an jump to table action resource.
8732 * Pointer to Ethernet device.
8734 * Pointer to mlx5_flow_handle.
8737 * 1 while a reference on it exists, 0 when freed.
8740 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
8741 struct mlx5_flow_handle *handle)
8743 struct mlx5_priv *priv = dev->data->dev_private;
8744 struct mlx5_flow_dv_jump_tbl_resource *cache_resource;
8745 struct mlx5_flow_tbl_data_entry *tbl_data;
8747 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
8751 cache_resource = &tbl_data->jump;
8752 MLX5_ASSERT(cache_resource->action);
8753 DRV_LOG(DEBUG, "jump table resource %p: refcnt %d--",
8754 (void *)cache_resource,
8755 rte_atomic32_read(&cache_resource->refcnt));
8756 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8757 claim_zero(mlx5_glue->destroy_flow_action
8758 (cache_resource->action));
8759 /* jump action memory free is inside the table release. */
8760 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
8761 DRV_LOG(DEBUG, "jump table resource %p: removed",
8762 (void *)cache_resource);
8769 * Release a modify-header resource.
8772 * Pointer to mlx5_flow_handle.
8775 * 1 while a reference on it exists, 0 when freed.
8778 flow_dv_modify_hdr_resource_release(struct mlx5_flow_handle *handle)
8780 struct mlx5_flow_dv_modify_hdr_resource *cache_resource =
8781 handle->dvh.modify_hdr;
8783 MLX5_ASSERT(cache_resource->verbs_action);
8784 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d--",
8785 (void *)cache_resource,
8786 rte_atomic32_read(&cache_resource->refcnt));
8787 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8788 claim_zero(mlx5_glue->destroy_flow_action
8789 (cache_resource->verbs_action));
8790 LIST_REMOVE(cache_resource, next);
8791 rte_free(cache_resource);
8792 DRV_LOG(DEBUG, "modify-header resource %p: removed",
8793 (void *)cache_resource);
8800 * Release port ID action resource.
8803 * Pointer to Ethernet device.
8805 * Pointer to mlx5_flow_handle.
8808 * 1 while a reference on it exists, 0 when freed.
8811 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
8812 struct mlx5_flow_handle *handle)
8814 struct mlx5_priv *priv = dev->data->dev_private;
8815 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
8816 uint32_t idx = handle->rix_port_id_action;
8818 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
8820 if (!cache_resource)
8822 MLX5_ASSERT(cache_resource->action);
8823 DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--",
8824 (void *)cache_resource,
8825 rte_atomic32_read(&cache_resource->refcnt));
8826 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8827 claim_zero(mlx5_glue->destroy_flow_action
8828 (cache_resource->action));
8829 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
8830 &priv->sh->port_id_action_list, idx,
8831 cache_resource, next);
8832 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_PORT_ID], idx);
8833 DRV_LOG(DEBUG, "port id action resource %p: removed",
8834 (void *)cache_resource);
8841 * Release push vlan action resource.
8844 * Pointer to Ethernet device.
8846 * Pointer to mlx5_flow_handle.
8849 * 1 while a reference on it exists, 0 when freed.
8852 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
8853 struct mlx5_flow_handle *handle)
8855 struct mlx5_priv *priv = dev->data->dev_private;
8856 uint32_t idx = handle->dvh.rix_push_vlan;
8857 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
8859 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN],
8861 if (!cache_resource)
8863 MLX5_ASSERT(cache_resource->action);
8864 DRV_LOG(DEBUG, "push VLAN action resource %p: refcnt %d--",
8865 (void *)cache_resource,
8866 rte_atomic32_read(&cache_resource->refcnt));
8867 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8868 claim_zero(mlx5_glue->destroy_flow_action
8869 (cache_resource->action));
8870 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN],
8871 &priv->sh->push_vlan_action_list, idx,
8872 cache_resource, next);
8873 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
8874 DRV_LOG(DEBUG, "push vlan action resource %p: removed",
8875 (void *)cache_resource);
8882 * Release the fate resource.
8885 * Pointer to Ethernet device.
8887 * Pointer to mlx5_flow_handle.
8890 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
8891 struct mlx5_flow_handle *handle)
8893 if (!handle->rix_fate)
8895 if (handle->fate_action == MLX5_FLOW_FATE_DROP)
8896 mlx5_hrxq_drop_release(dev);
8897 else if (handle->fate_action == MLX5_FLOW_FATE_QUEUE)
8898 mlx5_hrxq_release(dev, handle->rix_hrxq);
8899 else if (handle->fate_action == MLX5_FLOW_FATE_JUMP)
8900 flow_dv_jump_tbl_resource_release(dev, handle);
8901 else if (handle->fate_action == MLX5_FLOW_FATE_PORT_ID)
8902 flow_dv_port_id_action_resource_release(dev, handle);
8904 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
8905 handle->rix_fate = 0;
8909 * Remove the flow from the NIC but keeps it in memory.
8910 * Lock free, (mutex should be acquired by caller).
8913 * Pointer to Ethernet device.
8914 * @param[in, out] flow
8915 * Pointer to flow structure.
8918 __flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
8920 struct mlx5_flow_handle *dh;
8921 uint32_t handle_idx;
8922 struct mlx5_priv *priv = dev->data->dev_private;
8926 handle_idx = flow->dev_handles;
8927 while (handle_idx) {
8928 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8933 claim_zero(mlx5_glue->dv_destroy_flow(dh->ib_flow));
8936 if (dh->fate_action == MLX5_FLOW_FATE_DROP ||
8937 dh->fate_action == MLX5_FLOW_FATE_QUEUE)
8938 flow_dv_fate_resource_release(dev, dh);
8939 if (dh->vf_vlan.tag && dh->vf_vlan.created)
8940 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
8941 handle_idx = dh->next.next;
8946 * Remove the flow from the NIC and the memory.
8947 * Lock free, (mutex should be acquired by caller).
8950 * Pointer to the Ethernet device structure.
8951 * @param[in, out] flow
8952 * Pointer to flow structure.
8955 __flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
8957 struct mlx5_flow_handle *dev_handle;
8958 struct mlx5_priv *priv = dev->data->dev_private;
8962 __flow_dv_remove(dev, flow);
8963 if (flow->counter) {
8964 flow_dv_counter_release(dev, flow->counter);
8968 struct mlx5_flow_meter *fm;
8970 fm = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MTR],
8973 mlx5_flow_meter_detach(fm);
8976 while (flow->dev_handles) {
8977 uint32_t tmp_idx = flow->dev_handles;
8979 dev_handle = mlx5_ipool_get(priv->sh->ipool
8980 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
8983 flow->dev_handles = dev_handle->next.next;
8984 if (dev_handle->dvh.matcher)
8985 flow_dv_matcher_release(dev, dev_handle);
8986 if (dev_handle->dvh.rix_encap_decap)
8987 flow_dv_encap_decap_resource_release(dev, dev_handle);
8988 if (dev_handle->dvh.modify_hdr)
8989 flow_dv_modify_hdr_resource_release(dev_handle);
8990 if (dev_handle->dvh.rix_push_vlan)
8991 flow_dv_push_vlan_action_resource_release(dev,
8993 if (dev_handle->dvh.rix_tag)
8994 flow_dv_tag_release(dev,
8995 dev_handle->dvh.rix_tag);
8996 flow_dv_fate_resource_release(dev, dev_handle);
8997 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9003 * Query a dv flow rule for its statistics via devx.
9006 * Pointer to Ethernet device.
9008 * Pointer to the sub flow.
9010 * data retrieved by the query.
9012 * Perform verbose error reporting if not NULL.
9015 * 0 on success, a negative errno value otherwise and rte_errno is set.
9018 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
9019 void *data, struct rte_flow_error *error)
9021 struct mlx5_priv *priv = dev->data->dev_private;
9022 struct rte_flow_query_count *qc = data;
9024 if (!priv->config.devx)
9025 return rte_flow_error_set(error, ENOTSUP,
9026 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9028 "counters are not supported");
9029 if (flow->counter) {
9030 uint64_t pkts, bytes;
9031 struct mlx5_flow_counter *cnt;
9033 cnt = flow_dv_counter_get_by_idx(dev, flow->counter,
9035 int err = _flow_dv_query_count(dev, flow->counter, &pkts,
9039 return rte_flow_error_set(error, -err,
9040 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9041 NULL, "cannot read counters");
9044 qc->hits = pkts - cnt->hits;
9045 qc->bytes = bytes - cnt->bytes;
9052 return rte_flow_error_set(error, EINVAL,
9053 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9055 "counters are not available");
9061 * @see rte_flow_query()
9065 flow_dv_query(struct rte_eth_dev *dev,
9066 struct rte_flow *flow __rte_unused,
9067 const struct rte_flow_action *actions __rte_unused,
9068 void *data __rte_unused,
9069 struct rte_flow_error *error __rte_unused)
9073 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
9074 switch (actions->type) {
9075 case RTE_FLOW_ACTION_TYPE_VOID:
9077 case RTE_FLOW_ACTION_TYPE_COUNT:
9078 ret = flow_dv_query_count(dev, flow, data, error);
9081 return rte_flow_error_set(error, ENOTSUP,
9082 RTE_FLOW_ERROR_TYPE_ACTION,
9084 "action not supported");
9091 * Destroy the meter table set.
9092 * Lock free, (mutex should be acquired by caller).
9095 * Pointer to Ethernet device.
9097 * Pointer to the meter table set.
9103 flow_dv_destroy_mtr_tbl(struct rte_eth_dev *dev,
9104 struct mlx5_meter_domains_infos *tbl)
9106 struct mlx5_priv *priv = dev->data->dev_private;
9107 struct mlx5_meter_domains_infos *mtd =
9108 (struct mlx5_meter_domains_infos *)tbl;
9110 if (!mtd || !priv->config.dv_flow_en)
9112 if (mtd->ingress.policer_rules[RTE_MTR_DROPPED])
9113 claim_zero(mlx5_glue->dv_destroy_flow
9114 (mtd->ingress.policer_rules[RTE_MTR_DROPPED]));
9115 if (mtd->egress.policer_rules[RTE_MTR_DROPPED])
9116 claim_zero(mlx5_glue->dv_destroy_flow
9117 (mtd->egress.policer_rules[RTE_MTR_DROPPED]));
9118 if (mtd->transfer.policer_rules[RTE_MTR_DROPPED])
9119 claim_zero(mlx5_glue->dv_destroy_flow
9120 (mtd->transfer.policer_rules[RTE_MTR_DROPPED]));
9121 if (mtd->egress.color_matcher)
9122 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9123 (mtd->egress.color_matcher));
9124 if (mtd->egress.any_matcher)
9125 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9126 (mtd->egress.any_matcher));
9127 if (mtd->egress.tbl)
9128 flow_dv_tbl_resource_release(dev, mtd->egress.tbl);
9129 if (mtd->egress.sfx_tbl)
9130 flow_dv_tbl_resource_release(dev, mtd->egress.sfx_tbl);
9131 if (mtd->ingress.color_matcher)
9132 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9133 (mtd->ingress.color_matcher));
9134 if (mtd->ingress.any_matcher)
9135 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9136 (mtd->ingress.any_matcher));
9137 if (mtd->ingress.tbl)
9138 flow_dv_tbl_resource_release(dev, mtd->ingress.tbl);
9139 if (mtd->ingress.sfx_tbl)
9140 flow_dv_tbl_resource_release(dev, mtd->ingress.sfx_tbl);
9141 if (mtd->transfer.color_matcher)
9142 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9143 (mtd->transfer.color_matcher));
9144 if (mtd->transfer.any_matcher)
9145 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9146 (mtd->transfer.any_matcher));
9147 if (mtd->transfer.tbl)
9148 flow_dv_tbl_resource_release(dev, mtd->transfer.tbl);
9149 if (mtd->transfer.sfx_tbl)
9150 flow_dv_tbl_resource_release(dev, mtd->transfer.sfx_tbl);
9152 claim_zero(mlx5_glue->destroy_flow_action(mtd->drop_actn));
9157 /* Number of meter flow actions, count and jump or count and drop. */
9158 #define METER_ACTIONS 2
9161 * Create specify domain meter table and suffix table.
9164 * Pointer to Ethernet device.
9165 * @param[in,out] mtb
9166 * Pointer to DV meter table set.
9169 * @param[in] transfer
9171 * @param[in] color_reg_c_idx
9172 * Reg C index for color match.
9175 * 0 on success, -1 otherwise and rte_errno is set.
9178 flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
9179 struct mlx5_meter_domains_infos *mtb,
9180 uint8_t egress, uint8_t transfer,
9181 uint32_t color_reg_c_idx)
9183 struct mlx5_priv *priv = dev->data->dev_private;
9184 struct mlx5_dev_ctx_shared *sh = priv->sh;
9185 struct mlx5_flow_dv_match_params mask = {
9186 .size = sizeof(mask.buf),
9188 struct mlx5_flow_dv_match_params value = {
9189 .size = sizeof(value.buf),
9191 struct mlx5dv_flow_matcher_attr dv_attr = {
9192 .type = IBV_FLOW_ATTR_NORMAL,
9194 .match_criteria_enable = 0,
9195 .match_mask = (void *)&mask,
9197 void *actions[METER_ACTIONS];
9198 struct mlx5_meter_domain_info *dtb;
9199 struct rte_flow_error error;
9203 dtb = &mtb->transfer;
9207 dtb = &mtb->ingress;
9208 /* Create the meter table with METER level. */
9209 dtb->tbl = flow_dv_tbl_resource_get(dev, MLX5_FLOW_TABLE_LEVEL_METER,
9210 egress, transfer, &error);
9212 DRV_LOG(ERR, "Failed to create meter policer table.");
9215 /* Create the meter suffix table with SUFFIX level. */
9216 dtb->sfx_tbl = flow_dv_tbl_resource_get(dev,
9217 MLX5_FLOW_TABLE_LEVEL_SUFFIX,
9218 egress, transfer, &error);
9219 if (!dtb->sfx_tbl) {
9220 DRV_LOG(ERR, "Failed to create meter suffix table.");
9223 /* Create matchers, Any and Color. */
9224 dv_attr.priority = 3;
9225 dv_attr.match_criteria_enable = 0;
9226 dtb->any_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
9229 if (!dtb->any_matcher) {
9230 DRV_LOG(ERR, "Failed to create meter"
9231 " policer default matcher.");
9234 dv_attr.priority = 0;
9235 dv_attr.match_criteria_enable =
9236 1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
9237 flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
9238 rte_col_2_mlx5_col(RTE_COLORS), UINT8_MAX);
9239 dtb->color_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
9242 if (!dtb->color_matcher) {
9243 DRV_LOG(ERR, "Failed to create meter policer color matcher.");
9246 if (mtb->count_actns[RTE_MTR_DROPPED])
9247 actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
9248 actions[i++] = mtb->drop_actn;
9249 /* Default rule: lowest priority, match any, actions: drop. */
9250 dtb->policer_rules[RTE_MTR_DROPPED] =
9251 mlx5_glue->dv_create_flow(dtb->any_matcher,
9252 (void *)&value, i, actions);
9253 if (!dtb->policer_rules[RTE_MTR_DROPPED]) {
9254 DRV_LOG(ERR, "Failed to create meter policer drop rule.");
9263 * Create the needed meter and suffix tables.
9264 * Lock free, (mutex should be acquired by caller).
9267 * Pointer to Ethernet device.
9269 * Pointer to the flow meter.
9272 * Pointer to table set on success, NULL otherwise and rte_errno is set.
9274 static struct mlx5_meter_domains_infos *
9275 flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
9276 const struct mlx5_flow_meter *fm)
9278 struct mlx5_priv *priv = dev->data->dev_private;
9279 struct mlx5_meter_domains_infos *mtb;
9283 if (!priv->mtr_en) {
9284 rte_errno = ENOTSUP;
9287 mtb = rte_calloc(__func__, 1, sizeof(*mtb), 0);
9289 DRV_LOG(ERR, "Failed to allocate memory for meter.");
9292 /* Create meter count actions */
9293 for (i = 0; i <= RTE_MTR_DROPPED; i++) {
9294 struct mlx5_flow_counter *cnt;
9295 if (!fm->policer_stats.cnt[i])
9297 cnt = flow_dv_counter_get_by_idx(dev,
9298 fm->policer_stats.cnt[i], NULL);
9299 mtb->count_actns[i] = cnt->action;
9301 /* Create drop action. */
9302 mtb->drop_actn = mlx5_glue->dr_create_flow_action_drop();
9303 if (!mtb->drop_actn) {
9304 DRV_LOG(ERR, "Failed to create drop action.");
9307 /* Egress meter table. */
9308 ret = flow_dv_prepare_mtr_tables(dev, mtb, 1, 0, priv->mtr_color_reg);
9310 DRV_LOG(ERR, "Failed to prepare egress meter table.");
9313 /* Ingress meter table. */
9314 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 0, priv->mtr_color_reg);
9316 DRV_LOG(ERR, "Failed to prepare ingress meter table.");
9319 /* FDB meter table. */
9320 if (priv->config.dv_esw_en) {
9321 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 1,
9322 priv->mtr_color_reg);
9324 DRV_LOG(ERR, "Failed to prepare fdb meter table.");
9330 flow_dv_destroy_mtr_tbl(dev, mtb);
9335 * Destroy domain policer rule.
9338 * Pointer to domain table.
9341 flow_dv_destroy_domain_policer_rule(struct mlx5_meter_domain_info *dt)
9345 for (i = 0; i < RTE_MTR_DROPPED; i++) {
9346 if (dt->policer_rules[i]) {
9347 claim_zero(mlx5_glue->dv_destroy_flow
9348 (dt->policer_rules[i]));
9349 dt->policer_rules[i] = NULL;
9352 if (dt->jump_actn) {
9353 claim_zero(mlx5_glue->destroy_flow_action(dt->jump_actn));
9354 dt->jump_actn = NULL;
9359 * Destroy policer rules.
9362 * Pointer to Ethernet device.
9364 * Pointer to flow meter structure.
9366 * Pointer to flow attributes.
9372 flow_dv_destroy_policer_rules(struct rte_eth_dev *dev __rte_unused,
9373 const struct mlx5_flow_meter *fm,
9374 const struct rte_flow_attr *attr)
9376 struct mlx5_meter_domains_infos *mtb = fm ? fm->mfts : NULL;
9381 flow_dv_destroy_domain_policer_rule(&mtb->egress);
9383 flow_dv_destroy_domain_policer_rule(&mtb->ingress);
9385 flow_dv_destroy_domain_policer_rule(&mtb->transfer);
9390 * Create specify domain meter policer rule.
9393 * Pointer to flow meter structure.
9395 * Pointer to DV meter table set.
9396 * @param[in] mtr_reg_c
9397 * Color match REG_C.
9400 * 0 on success, -1 otherwise.
9403 flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
9404 struct mlx5_meter_domain_info *dtb,
9407 struct mlx5_flow_dv_match_params matcher = {
9408 .size = sizeof(matcher.buf),
9410 struct mlx5_flow_dv_match_params value = {
9411 .size = sizeof(value.buf),
9413 struct mlx5_meter_domains_infos *mtb = fm->mfts;
9414 void *actions[METER_ACTIONS];
9417 /* Create jump action. */
9418 if (!dtb->jump_actn)
9420 mlx5_glue->dr_create_flow_action_dest_flow_tbl
9421 (dtb->sfx_tbl->obj);
9422 if (!dtb->jump_actn) {
9423 DRV_LOG(ERR, "Failed to create policer jump action.");
9426 for (i = 0; i < RTE_MTR_DROPPED; i++) {
9429 flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
9430 rte_col_2_mlx5_col(i), UINT8_MAX);
9431 if (mtb->count_actns[i])
9432 actions[j++] = mtb->count_actns[i];
9433 if (fm->action[i] == MTR_POLICER_ACTION_DROP)
9434 actions[j++] = mtb->drop_actn;
9436 actions[j++] = dtb->jump_actn;
9437 dtb->policer_rules[i] =
9438 mlx5_glue->dv_create_flow(dtb->color_matcher,
9441 if (!dtb->policer_rules[i]) {
9442 DRV_LOG(ERR, "Failed to create policer rule.");
9453 * Create policer rules.
9456 * Pointer to Ethernet device.
9458 * Pointer to flow meter structure.
9460 * Pointer to flow attributes.
9463 * 0 on success, -1 otherwise.
9466 flow_dv_create_policer_rules(struct rte_eth_dev *dev,
9467 struct mlx5_flow_meter *fm,
9468 const struct rte_flow_attr *attr)
9470 struct mlx5_priv *priv = dev->data->dev_private;
9471 struct mlx5_meter_domains_infos *mtb = fm->mfts;
9475 ret = flow_dv_create_policer_forward_rule(fm, &mtb->egress,
9476 priv->mtr_color_reg);
9478 DRV_LOG(ERR, "Failed to create egress policer.");
9482 if (attr->ingress) {
9483 ret = flow_dv_create_policer_forward_rule(fm, &mtb->ingress,
9484 priv->mtr_color_reg);
9486 DRV_LOG(ERR, "Failed to create ingress policer.");
9490 if (attr->transfer) {
9491 ret = flow_dv_create_policer_forward_rule(fm, &mtb->transfer,
9492 priv->mtr_color_reg);
9494 DRV_LOG(ERR, "Failed to create transfer policer.");
9500 flow_dv_destroy_policer_rules(dev, fm, attr);
9505 * Query a devx counter.
9508 * Pointer to the Ethernet device structure.
9510 * Index to the flow counter.
9512 * Set to clear the counter statistics.
9514 * The statistics value of packets.
9516 * The statistics value of bytes.
9519 * 0 on success, otherwise return -1.
9522 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
9523 uint64_t *pkts, uint64_t *bytes)
9525 struct mlx5_priv *priv = dev->data->dev_private;
9526 struct mlx5_flow_counter *cnt;
9527 uint64_t inn_pkts, inn_bytes;
9530 if (!priv->config.devx)
9533 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
9536 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
9537 *pkts = inn_pkts - cnt->hits;
9538 *bytes = inn_bytes - cnt->bytes;
9540 cnt->hits = inn_pkts;
9541 cnt->bytes = inn_bytes;
9547 * Get aged-out flows.
9550 * Pointer to the Ethernet device structure.
9551 * @param[in] context
9552 * The address of an array of pointers to the aged-out flows contexts.
9553 * @param[in] nb_contexts
9554 * The length of context array pointers.
9556 * Perform verbose error reporting if not NULL. Initialized in case of
9560 * how many contexts get in success, otherwise negative errno value.
9561 * if nb_contexts is 0, return the amount of all aged contexts.
9562 * if nb_contexts is not 0 , return the amount of aged flows reported
9563 * in the context array.
9564 * @note: only stub for now
9567 flow_get_aged_flows(struct rte_eth_dev *dev,
9569 uint32_t nb_contexts,
9570 struct rte_flow_error *error)
9572 struct mlx5_priv *priv = dev->data->dev_private;
9573 struct mlx5_age_info *age_info;
9574 struct mlx5_age_param *age_param;
9575 struct mlx5_flow_counter *counter;
9578 if (nb_contexts && !context)
9579 return rte_flow_error_set(error, EINVAL,
9580 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9582 "Should assign at least one flow or"
9583 " context to get if nb_contexts != 0");
9584 age_info = GET_PORT_AGE_INFO(priv);
9585 rte_spinlock_lock(&age_info->aged_sl);
9586 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
9589 age_param = MLX5_CNT_TO_AGE(counter);
9590 context[nb_flows - 1] = age_param->context;
9591 if (!(--nb_contexts))
9595 rte_spinlock_unlock(&age_info->aged_sl);
9596 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
9601 * Mutex-protected thunk to lock-free __flow_dv_translate().
9604 flow_dv_translate(struct rte_eth_dev *dev,
9605 struct mlx5_flow *dev_flow,
9606 const struct rte_flow_attr *attr,
9607 const struct rte_flow_item items[],
9608 const struct rte_flow_action actions[],
9609 struct rte_flow_error *error)
9613 flow_dv_shared_lock(dev);
9614 ret = __flow_dv_translate(dev, dev_flow, attr, items, actions, error);
9615 flow_dv_shared_unlock(dev);
9620 * Mutex-protected thunk to lock-free __flow_dv_apply().
9623 flow_dv_apply(struct rte_eth_dev *dev,
9624 struct rte_flow *flow,
9625 struct rte_flow_error *error)
9629 flow_dv_shared_lock(dev);
9630 ret = __flow_dv_apply(dev, flow, error);
9631 flow_dv_shared_unlock(dev);
9636 * Mutex-protected thunk to lock-free __flow_dv_remove().
9639 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
9641 flow_dv_shared_lock(dev);
9642 __flow_dv_remove(dev, flow);
9643 flow_dv_shared_unlock(dev);
9647 * Mutex-protected thunk to lock-free __flow_dv_destroy().
9650 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
9652 flow_dv_shared_lock(dev);
9653 __flow_dv_destroy(dev, flow);
9654 flow_dv_shared_unlock(dev);
9658 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
9661 flow_dv_counter_allocate(struct rte_eth_dev *dev)
9665 flow_dv_shared_lock(dev);
9666 cnt = flow_dv_counter_alloc(dev, 0, 0, 1, 0);
9667 flow_dv_shared_unlock(dev);
9672 * Mutex-protected thunk to lock-free flow_dv_counter_release().
9675 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
9677 flow_dv_shared_lock(dev);
9678 flow_dv_counter_release(dev, cnt);
9679 flow_dv_shared_unlock(dev);
9682 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
9683 .validate = flow_dv_validate,
9684 .prepare = flow_dv_prepare,
9685 .translate = flow_dv_translate,
9686 .apply = flow_dv_apply,
9687 .remove = flow_dv_remove,
9688 .destroy = flow_dv_destroy,
9689 .query = flow_dv_query,
9690 .create_mtr_tbls = flow_dv_create_mtr_tbl,
9691 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbl,
9692 .create_policer_rules = flow_dv_create_policer_rules,
9693 .destroy_policer_rules = flow_dv_destroy_policer_rules,
9694 .counter_alloc = flow_dv_counter_allocate,
9695 .counter_free = flow_dv_counter_free,
9696 .counter_query = flow_dv_counter_query,
9697 .get_aged_flows = flow_get_aged_flows,
9700 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */