1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd
11 #include <rte_common.h>
12 #include <rte_ether.h>
13 #include <rte_ethdev_driver.h>
15 #include <rte_flow_driver.h>
16 #include <rte_malloc.h>
17 #include <rte_cycles.h>
20 #include <rte_vxlan.h>
22 #include <rte_eal_paging.h>
25 #include <mlx5_glue.h>
26 #include <mlx5_devx_cmds.h>
28 #include <mlx5_malloc.h>
30 #include "mlx5_defs.h"
32 #include "mlx5_common_os.h"
33 #include "mlx5_flow.h"
34 #include "mlx5_flow_os.h"
35 #include "mlx5_rxtx.h"
37 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
39 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
40 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
43 #ifndef HAVE_MLX5DV_DR_ESWITCH
44 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
45 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
49 #ifndef HAVE_MLX5DV_DR
50 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
53 /* VLAN header definitions */
54 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
55 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
56 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
57 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
58 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
73 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
74 struct mlx5_flow_tbl_resource *tbl);
77 flow_dv_default_miss_resource_release(struct rte_eth_dev *dev);
80 * Initialize flow attributes structure according to flow items' types.
82 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
83 * mode. For tunnel mode, the items to be modified are the outermost ones.
86 * Pointer to item specification.
88 * Pointer to flow attributes structure.
90 * Pointer to the sub flow.
91 * @param[in] tunnel_decap
92 * Whether action is after tunnel decapsulation.
95 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
96 struct mlx5_flow *dev_flow, bool tunnel_decap)
98 uint64_t layers = dev_flow->handle->layers;
101 * If layers is already initialized, it means this dev_flow is the
102 * suffix flow, the layers flags is set by the prefix flow. Need to
103 * use the layer flags from prefix flow as the suffix flow may not
104 * have the user defined items as the flow is split.
107 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
109 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
111 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
113 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
118 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
119 uint8_t next_protocol = 0xff;
120 switch (item->type) {
121 case RTE_FLOW_ITEM_TYPE_GRE:
122 case RTE_FLOW_ITEM_TYPE_NVGRE:
123 case RTE_FLOW_ITEM_TYPE_VXLAN:
124 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
125 case RTE_FLOW_ITEM_TYPE_GENEVE:
126 case RTE_FLOW_ITEM_TYPE_MPLS:
130 case RTE_FLOW_ITEM_TYPE_IPV4:
133 if (item->mask != NULL &&
134 ((const struct rte_flow_item_ipv4 *)
135 item->mask)->hdr.next_proto_id)
137 ((const struct rte_flow_item_ipv4 *)
138 (item->spec))->hdr.next_proto_id &
139 ((const struct rte_flow_item_ipv4 *)
140 (item->mask))->hdr.next_proto_id;
141 if ((next_protocol == IPPROTO_IPIP ||
142 next_protocol == IPPROTO_IPV6) && tunnel_decap)
145 case RTE_FLOW_ITEM_TYPE_IPV6:
148 if (item->mask != NULL &&
149 ((const struct rte_flow_item_ipv6 *)
150 item->mask)->hdr.proto)
152 ((const struct rte_flow_item_ipv6 *)
153 (item->spec))->hdr.proto &
154 ((const struct rte_flow_item_ipv6 *)
155 (item->mask))->hdr.proto;
156 if ((next_protocol == IPPROTO_IPIP ||
157 next_protocol == IPPROTO_IPV6) && tunnel_decap)
160 case RTE_FLOW_ITEM_TYPE_UDP:
164 case RTE_FLOW_ITEM_TYPE_TCP:
176 * Convert rte_mtr_color to mlx5 color.
185 rte_col_2_mlx5_col(enum rte_color rcol)
188 case RTE_COLOR_GREEN:
189 return MLX5_FLOW_COLOR_GREEN;
190 case RTE_COLOR_YELLOW:
191 return MLX5_FLOW_COLOR_YELLOW;
193 return MLX5_FLOW_COLOR_RED;
197 return MLX5_FLOW_COLOR_UNDEFINED;
200 struct field_modify_info {
201 uint32_t size; /* Size of field in protocol header, in bytes. */
202 uint32_t offset; /* Offset of field in protocol header, in bytes. */
203 enum mlx5_modification_field id;
206 struct field_modify_info modify_eth[] = {
207 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
208 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
209 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
210 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
214 struct field_modify_info modify_vlan_out_first_vid[] = {
215 /* Size in bits !!! */
216 {12, 0, MLX5_MODI_OUT_FIRST_VID},
220 struct field_modify_info modify_ipv4[] = {
221 {1, 1, MLX5_MODI_OUT_IP_DSCP},
222 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
223 {4, 12, MLX5_MODI_OUT_SIPV4},
224 {4, 16, MLX5_MODI_OUT_DIPV4},
228 struct field_modify_info modify_ipv6[] = {
229 {1, 0, MLX5_MODI_OUT_IP_DSCP},
230 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
231 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
232 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
233 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
234 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
235 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
236 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
237 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
238 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
242 struct field_modify_info modify_udp[] = {
243 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
244 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
248 struct field_modify_info modify_tcp[] = {
249 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
250 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
251 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
252 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
257 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
258 uint8_t next_protocol, uint64_t *item_flags,
261 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
262 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
263 if (next_protocol == IPPROTO_IPIP) {
264 *item_flags |= MLX5_FLOW_LAYER_IPIP;
267 if (next_protocol == IPPROTO_IPV6) {
268 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
274 * Acquire the synchronizing object to protect multithreaded access
275 * to shared dv context. Lock occurs only if context is actually
276 * shared, i.e. we have multiport IB device and representors are
280 * Pointer to the rte_eth_dev structure.
283 flow_dv_shared_lock(struct rte_eth_dev *dev)
285 struct mlx5_priv *priv = dev->data->dev_private;
286 struct mlx5_dev_ctx_shared *sh = priv->sh;
288 if (sh->dv_refcnt > 1) {
291 ret = pthread_mutex_lock(&sh->dv_mutex);
298 flow_dv_shared_unlock(struct rte_eth_dev *dev)
300 struct mlx5_priv *priv = dev->data->dev_private;
301 struct mlx5_dev_ctx_shared *sh = priv->sh;
303 if (sh->dv_refcnt > 1) {
306 ret = pthread_mutex_unlock(&sh->dv_mutex);
312 /* Update VLAN's VID/PCP based on input rte_flow_action.
315 * Pointer to struct rte_flow_action.
317 * Pointer to struct rte_vlan_hdr.
320 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
321 struct rte_vlan_hdr *vlan)
324 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
326 ((const struct rte_flow_action_of_set_vlan_pcp *)
327 action->conf)->vlan_pcp;
328 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
329 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
330 vlan->vlan_tci |= vlan_tci;
331 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
332 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
333 vlan->vlan_tci |= rte_be_to_cpu_16
334 (((const struct rte_flow_action_of_set_vlan_vid *)
335 action->conf)->vlan_vid);
340 * Fetch 1, 2, 3 or 4 byte field from the byte array
341 * and return as unsigned integer in host-endian format.
344 * Pointer to data array.
346 * Size of field to extract.
349 * converted field in host endian format.
351 static inline uint32_t
352 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
361 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
364 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
365 ret = (ret << 8) | *(data + sizeof(uint16_t));
368 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
379 * Convert modify-header action to DV specification.
381 * Data length of each action is determined by provided field description
382 * and the item mask. Data bit offset and width of each action is determined
383 * by provided item mask.
386 * Pointer to item specification.
388 * Pointer to field modification information.
389 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
390 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
391 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
393 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
394 * Negative offset value sets the same offset as source offset.
395 * size field is ignored, value is taken from source field.
396 * @param[in,out] resource
397 * Pointer to the modify-header resource.
399 * Type of modification.
401 * Pointer to the error structure.
404 * 0 on success, a negative errno value otherwise and rte_errno is set.
407 flow_dv_convert_modify_action(struct rte_flow_item *item,
408 struct field_modify_info *field,
409 struct field_modify_info *dcopy,
410 struct mlx5_flow_dv_modify_hdr_resource *resource,
411 uint32_t type, struct rte_flow_error *error)
413 uint32_t i = resource->actions_num;
414 struct mlx5_modification_cmd *actions = resource->actions;
417 * The item and mask are provided in big-endian format.
418 * The fields should be presented as in big-endian format either.
419 * Mask must be always present, it defines the actual field width.
421 MLX5_ASSERT(item->mask);
422 MLX5_ASSERT(field->size);
429 if (i >= MLX5_MAX_MODIFY_NUM)
430 return rte_flow_error_set(error, EINVAL,
431 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
432 "too many items to modify");
433 /* Fetch variable byte size mask from the array. */
434 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
435 field->offset, field->size);
440 /* Deduce actual data width in bits from mask value. */
441 off_b = rte_bsf32(mask);
442 size_b = sizeof(uint32_t) * CHAR_BIT -
443 off_b - __builtin_clz(mask);
445 size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
446 actions[i] = (struct mlx5_modification_cmd) {
452 /* Convert entire record to expected big-endian format. */
453 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
454 if (type == MLX5_MODIFICATION_TYPE_COPY) {
456 actions[i].dst_field = dcopy->id;
457 actions[i].dst_offset =
458 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
459 /* Convert entire record to big-endian format. */
460 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
462 MLX5_ASSERT(item->spec);
463 data = flow_dv_fetch_field((const uint8_t *)item->spec +
464 field->offset, field->size);
465 /* Shift out the trailing masked bits from data. */
466 data = (data & mask) >> off_b;
467 actions[i].data1 = rte_cpu_to_be_32(data);
471 } while (field->size);
472 if (resource->actions_num == i)
473 return rte_flow_error_set(error, EINVAL,
474 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
475 "invalid modification flow item");
476 resource->actions_num = i;
481 * Convert modify-header set IPv4 address action to DV specification.
483 * @param[in,out] resource
484 * Pointer to the modify-header resource.
486 * Pointer to action specification.
488 * Pointer to the error structure.
491 * 0 on success, a negative errno value otherwise and rte_errno is set.
494 flow_dv_convert_action_modify_ipv4
495 (struct mlx5_flow_dv_modify_hdr_resource *resource,
496 const struct rte_flow_action *action,
497 struct rte_flow_error *error)
499 const struct rte_flow_action_set_ipv4 *conf =
500 (const struct rte_flow_action_set_ipv4 *)(action->conf);
501 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
502 struct rte_flow_item_ipv4 ipv4;
503 struct rte_flow_item_ipv4 ipv4_mask;
505 memset(&ipv4, 0, sizeof(ipv4));
506 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
507 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
508 ipv4.hdr.src_addr = conf->ipv4_addr;
509 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
511 ipv4.hdr.dst_addr = conf->ipv4_addr;
512 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
515 item.mask = &ipv4_mask;
516 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
517 MLX5_MODIFICATION_TYPE_SET, error);
521 * Convert modify-header set IPv6 address action to DV specification.
523 * @param[in,out] resource
524 * Pointer to the modify-header resource.
526 * Pointer to action specification.
528 * Pointer to the error structure.
531 * 0 on success, a negative errno value otherwise and rte_errno is set.
534 flow_dv_convert_action_modify_ipv6
535 (struct mlx5_flow_dv_modify_hdr_resource *resource,
536 const struct rte_flow_action *action,
537 struct rte_flow_error *error)
539 const struct rte_flow_action_set_ipv6 *conf =
540 (const struct rte_flow_action_set_ipv6 *)(action->conf);
541 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
542 struct rte_flow_item_ipv6 ipv6;
543 struct rte_flow_item_ipv6 ipv6_mask;
545 memset(&ipv6, 0, sizeof(ipv6));
546 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
547 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
548 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
549 sizeof(ipv6.hdr.src_addr));
550 memcpy(&ipv6_mask.hdr.src_addr,
551 &rte_flow_item_ipv6_mask.hdr.src_addr,
552 sizeof(ipv6.hdr.src_addr));
554 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
555 sizeof(ipv6.hdr.dst_addr));
556 memcpy(&ipv6_mask.hdr.dst_addr,
557 &rte_flow_item_ipv6_mask.hdr.dst_addr,
558 sizeof(ipv6.hdr.dst_addr));
561 item.mask = &ipv6_mask;
562 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
563 MLX5_MODIFICATION_TYPE_SET, error);
567 * Convert modify-header set MAC address action to DV specification.
569 * @param[in,out] resource
570 * Pointer to the modify-header resource.
572 * Pointer to action specification.
574 * Pointer to the error structure.
577 * 0 on success, a negative errno value otherwise and rte_errno is set.
580 flow_dv_convert_action_modify_mac
581 (struct mlx5_flow_dv_modify_hdr_resource *resource,
582 const struct rte_flow_action *action,
583 struct rte_flow_error *error)
585 const struct rte_flow_action_set_mac *conf =
586 (const struct rte_flow_action_set_mac *)(action->conf);
587 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
588 struct rte_flow_item_eth eth;
589 struct rte_flow_item_eth eth_mask;
591 memset(ð, 0, sizeof(eth));
592 memset(ð_mask, 0, sizeof(eth_mask));
593 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
594 memcpy(ð.src.addr_bytes, &conf->mac_addr,
595 sizeof(eth.src.addr_bytes));
596 memcpy(ð_mask.src.addr_bytes,
597 &rte_flow_item_eth_mask.src.addr_bytes,
598 sizeof(eth_mask.src.addr_bytes));
600 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
601 sizeof(eth.dst.addr_bytes));
602 memcpy(ð_mask.dst.addr_bytes,
603 &rte_flow_item_eth_mask.dst.addr_bytes,
604 sizeof(eth_mask.dst.addr_bytes));
607 item.mask = ð_mask;
608 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
609 MLX5_MODIFICATION_TYPE_SET, error);
613 * Convert modify-header set VLAN VID action to DV specification.
615 * @param[in,out] resource
616 * Pointer to the modify-header resource.
618 * Pointer to action specification.
620 * Pointer to the error structure.
623 * 0 on success, a negative errno value otherwise and rte_errno is set.
626 flow_dv_convert_action_modify_vlan_vid
627 (struct mlx5_flow_dv_modify_hdr_resource *resource,
628 const struct rte_flow_action *action,
629 struct rte_flow_error *error)
631 const struct rte_flow_action_of_set_vlan_vid *conf =
632 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
633 int i = resource->actions_num;
634 struct mlx5_modification_cmd *actions = resource->actions;
635 struct field_modify_info *field = modify_vlan_out_first_vid;
637 if (i >= MLX5_MAX_MODIFY_NUM)
638 return rte_flow_error_set(error, EINVAL,
639 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
640 "too many items to modify");
641 actions[i] = (struct mlx5_modification_cmd) {
642 .action_type = MLX5_MODIFICATION_TYPE_SET,
644 .length = field->size,
645 .offset = field->offset,
647 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
648 actions[i].data1 = conf->vlan_vid;
649 actions[i].data1 = actions[i].data1 << 16;
650 resource->actions_num = ++i;
655 * Convert modify-header set TP action to DV specification.
657 * @param[in,out] resource
658 * Pointer to the modify-header resource.
660 * Pointer to action specification.
662 * Pointer to rte_flow_item objects list.
664 * Pointer to flow attributes structure.
665 * @param[in] dev_flow
666 * Pointer to the sub flow.
667 * @param[in] tunnel_decap
668 * Whether action is after tunnel decapsulation.
670 * Pointer to the error structure.
673 * 0 on success, a negative errno value otherwise and rte_errno is set.
676 flow_dv_convert_action_modify_tp
677 (struct mlx5_flow_dv_modify_hdr_resource *resource,
678 const struct rte_flow_action *action,
679 const struct rte_flow_item *items,
680 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
681 bool tunnel_decap, struct rte_flow_error *error)
683 const struct rte_flow_action_set_tp *conf =
684 (const struct rte_flow_action_set_tp *)(action->conf);
685 struct rte_flow_item item;
686 struct rte_flow_item_udp udp;
687 struct rte_flow_item_udp udp_mask;
688 struct rte_flow_item_tcp tcp;
689 struct rte_flow_item_tcp tcp_mask;
690 struct field_modify_info *field;
693 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
695 memset(&udp, 0, sizeof(udp));
696 memset(&udp_mask, 0, sizeof(udp_mask));
697 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
698 udp.hdr.src_port = conf->port;
699 udp_mask.hdr.src_port =
700 rte_flow_item_udp_mask.hdr.src_port;
702 udp.hdr.dst_port = conf->port;
703 udp_mask.hdr.dst_port =
704 rte_flow_item_udp_mask.hdr.dst_port;
706 item.type = RTE_FLOW_ITEM_TYPE_UDP;
708 item.mask = &udp_mask;
711 MLX5_ASSERT(attr->tcp);
712 memset(&tcp, 0, sizeof(tcp));
713 memset(&tcp_mask, 0, sizeof(tcp_mask));
714 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
715 tcp.hdr.src_port = conf->port;
716 tcp_mask.hdr.src_port =
717 rte_flow_item_tcp_mask.hdr.src_port;
719 tcp.hdr.dst_port = conf->port;
720 tcp_mask.hdr.dst_port =
721 rte_flow_item_tcp_mask.hdr.dst_port;
723 item.type = RTE_FLOW_ITEM_TYPE_TCP;
725 item.mask = &tcp_mask;
728 return flow_dv_convert_modify_action(&item, field, NULL, resource,
729 MLX5_MODIFICATION_TYPE_SET, error);
733 * Convert modify-header set TTL action to DV specification.
735 * @param[in,out] resource
736 * Pointer to the modify-header resource.
738 * Pointer to action specification.
740 * Pointer to rte_flow_item objects list.
742 * Pointer to flow attributes structure.
743 * @param[in] dev_flow
744 * Pointer to the sub flow.
745 * @param[in] tunnel_decap
746 * Whether action is after tunnel decapsulation.
748 * Pointer to the error structure.
751 * 0 on success, a negative errno value otherwise and rte_errno is set.
754 flow_dv_convert_action_modify_ttl
755 (struct mlx5_flow_dv_modify_hdr_resource *resource,
756 const struct rte_flow_action *action,
757 const struct rte_flow_item *items,
758 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
759 bool tunnel_decap, struct rte_flow_error *error)
761 const struct rte_flow_action_set_ttl *conf =
762 (const struct rte_flow_action_set_ttl *)(action->conf);
763 struct rte_flow_item item;
764 struct rte_flow_item_ipv4 ipv4;
765 struct rte_flow_item_ipv4 ipv4_mask;
766 struct rte_flow_item_ipv6 ipv6;
767 struct rte_flow_item_ipv6 ipv6_mask;
768 struct field_modify_info *field;
771 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
773 memset(&ipv4, 0, sizeof(ipv4));
774 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
775 ipv4.hdr.time_to_live = conf->ttl_value;
776 ipv4_mask.hdr.time_to_live = 0xFF;
777 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
779 item.mask = &ipv4_mask;
782 MLX5_ASSERT(attr->ipv6);
783 memset(&ipv6, 0, sizeof(ipv6));
784 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
785 ipv6.hdr.hop_limits = conf->ttl_value;
786 ipv6_mask.hdr.hop_limits = 0xFF;
787 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
789 item.mask = &ipv6_mask;
792 return flow_dv_convert_modify_action(&item, field, NULL, resource,
793 MLX5_MODIFICATION_TYPE_SET, error);
797 * Convert modify-header decrement TTL action to DV specification.
799 * @param[in,out] resource
800 * Pointer to the modify-header resource.
802 * Pointer to action specification.
804 * Pointer to rte_flow_item objects list.
806 * Pointer to flow attributes structure.
807 * @param[in] dev_flow
808 * Pointer to the sub flow.
809 * @param[in] tunnel_decap
810 * Whether action is after tunnel decapsulation.
812 * Pointer to the error structure.
815 * 0 on success, a negative errno value otherwise and rte_errno is set.
818 flow_dv_convert_action_modify_dec_ttl
819 (struct mlx5_flow_dv_modify_hdr_resource *resource,
820 const struct rte_flow_item *items,
821 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
822 bool tunnel_decap, struct rte_flow_error *error)
824 struct rte_flow_item item;
825 struct rte_flow_item_ipv4 ipv4;
826 struct rte_flow_item_ipv4 ipv4_mask;
827 struct rte_flow_item_ipv6 ipv6;
828 struct rte_flow_item_ipv6 ipv6_mask;
829 struct field_modify_info *field;
832 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
834 memset(&ipv4, 0, sizeof(ipv4));
835 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
836 ipv4.hdr.time_to_live = 0xFF;
837 ipv4_mask.hdr.time_to_live = 0xFF;
838 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
840 item.mask = &ipv4_mask;
843 MLX5_ASSERT(attr->ipv6);
844 memset(&ipv6, 0, sizeof(ipv6));
845 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
846 ipv6.hdr.hop_limits = 0xFF;
847 ipv6_mask.hdr.hop_limits = 0xFF;
848 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
850 item.mask = &ipv6_mask;
853 return flow_dv_convert_modify_action(&item, field, NULL, resource,
854 MLX5_MODIFICATION_TYPE_ADD, error);
858 * Convert modify-header increment/decrement TCP Sequence number
859 * to DV specification.
861 * @param[in,out] resource
862 * Pointer to the modify-header resource.
864 * Pointer to action specification.
866 * Pointer to the error structure.
869 * 0 on success, a negative errno value otherwise and rte_errno is set.
872 flow_dv_convert_action_modify_tcp_seq
873 (struct mlx5_flow_dv_modify_hdr_resource *resource,
874 const struct rte_flow_action *action,
875 struct rte_flow_error *error)
877 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
878 uint64_t value = rte_be_to_cpu_32(*conf);
879 struct rte_flow_item item;
880 struct rte_flow_item_tcp tcp;
881 struct rte_flow_item_tcp tcp_mask;
883 memset(&tcp, 0, sizeof(tcp));
884 memset(&tcp_mask, 0, sizeof(tcp_mask));
885 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
887 * The HW has no decrement operation, only increment operation.
888 * To simulate decrement X from Y using increment operation
889 * we need to add UINT32_MAX X times to Y.
890 * Each adding of UINT32_MAX decrements Y by 1.
893 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
894 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
895 item.type = RTE_FLOW_ITEM_TYPE_TCP;
897 item.mask = &tcp_mask;
898 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
899 MLX5_MODIFICATION_TYPE_ADD, error);
903 * Convert modify-header increment/decrement TCP Acknowledgment number
904 * to DV specification.
906 * @param[in,out] resource
907 * Pointer to the modify-header resource.
909 * Pointer to action specification.
911 * Pointer to the error structure.
914 * 0 on success, a negative errno value otherwise and rte_errno is set.
917 flow_dv_convert_action_modify_tcp_ack
918 (struct mlx5_flow_dv_modify_hdr_resource *resource,
919 const struct rte_flow_action *action,
920 struct rte_flow_error *error)
922 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
923 uint64_t value = rte_be_to_cpu_32(*conf);
924 struct rte_flow_item item;
925 struct rte_flow_item_tcp tcp;
926 struct rte_flow_item_tcp tcp_mask;
928 memset(&tcp, 0, sizeof(tcp));
929 memset(&tcp_mask, 0, sizeof(tcp_mask));
930 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
932 * The HW has no decrement operation, only increment operation.
933 * To simulate decrement X from Y using increment operation
934 * we need to add UINT32_MAX X times to Y.
935 * Each adding of UINT32_MAX decrements Y by 1.
938 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
939 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
940 item.type = RTE_FLOW_ITEM_TYPE_TCP;
942 item.mask = &tcp_mask;
943 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
944 MLX5_MODIFICATION_TYPE_ADD, error);
947 static enum mlx5_modification_field reg_to_field[] = {
948 [REG_NON] = MLX5_MODI_OUT_NONE,
949 [REG_A] = MLX5_MODI_META_DATA_REG_A,
950 [REG_B] = MLX5_MODI_META_DATA_REG_B,
951 [REG_C_0] = MLX5_MODI_META_REG_C_0,
952 [REG_C_1] = MLX5_MODI_META_REG_C_1,
953 [REG_C_2] = MLX5_MODI_META_REG_C_2,
954 [REG_C_3] = MLX5_MODI_META_REG_C_3,
955 [REG_C_4] = MLX5_MODI_META_REG_C_4,
956 [REG_C_5] = MLX5_MODI_META_REG_C_5,
957 [REG_C_6] = MLX5_MODI_META_REG_C_6,
958 [REG_C_7] = MLX5_MODI_META_REG_C_7,
962 * Convert register set to DV specification.
964 * @param[in,out] resource
965 * Pointer to the modify-header resource.
967 * Pointer to action specification.
969 * Pointer to the error structure.
972 * 0 on success, a negative errno value otherwise and rte_errno is set.
975 flow_dv_convert_action_set_reg
976 (struct mlx5_flow_dv_modify_hdr_resource *resource,
977 const struct rte_flow_action *action,
978 struct rte_flow_error *error)
980 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
981 struct mlx5_modification_cmd *actions = resource->actions;
982 uint32_t i = resource->actions_num;
984 if (i >= MLX5_MAX_MODIFY_NUM)
985 return rte_flow_error_set(error, EINVAL,
986 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
987 "too many items to modify");
988 MLX5_ASSERT(conf->id != REG_NON);
989 MLX5_ASSERT(conf->id < RTE_DIM(reg_to_field));
990 actions[i] = (struct mlx5_modification_cmd) {
991 .action_type = MLX5_MODIFICATION_TYPE_SET,
992 .field = reg_to_field[conf->id],
994 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
995 actions[i].data1 = rte_cpu_to_be_32(conf->data);
997 resource->actions_num = i;
1002 * Convert SET_TAG action to DV specification.
1005 * Pointer to the rte_eth_dev structure.
1006 * @param[in,out] resource
1007 * Pointer to the modify-header resource.
1009 * Pointer to action specification.
1011 * Pointer to the error structure.
1014 * 0 on success, a negative errno value otherwise and rte_errno is set.
1017 flow_dv_convert_action_set_tag
1018 (struct rte_eth_dev *dev,
1019 struct mlx5_flow_dv_modify_hdr_resource *resource,
1020 const struct rte_flow_action_set_tag *conf,
1021 struct rte_flow_error *error)
1023 rte_be32_t data = rte_cpu_to_be_32(conf->data);
1024 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1025 struct rte_flow_item item = {
1029 struct field_modify_info reg_c_x[] = {
1032 enum mlx5_modification_field reg_type;
1035 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1038 MLX5_ASSERT(ret != REG_NON);
1039 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1040 reg_type = reg_to_field[ret];
1041 MLX5_ASSERT(reg_type > 0);
1042 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1043 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1044 MLX5_MODIFICATION_TYPE_SET, error);
1048 * Convert internal COPY_REG action to DV specification.
1051 * Pointer to the rte_eth_dev structure.
1052 * @param[in,out] res
1053 * Pointer to the modify-header resource.
1055 * Pointer to action specification.
1057 * Pointer to the error structure.
1060 * 0 on success, a negative errno value otherwise and rte_errno is set.
1063 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1064 struct mlx5_flow_dv_modify_hdr_resource *res,
1065 const struct rte_flow_action *action,
1066 struct rte_flow_error *error)
1068 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1069 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1070 struct rte_flow_item item = {
1074 struct field_modify_info reg_src[] = {
1075 {4, 0, reg_to_field[conf->src]},
1078 struct field_modify_info reg_dst = {
1080 .id = reg_to_field[conf->dst],
1082 /* Adjust reg_c[0] usage according to reported mask. */
1083 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1084 struct mlx5_priv *priv = dev->data->dev_private;
1085 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1087 MLX5_ASSERT(reg_c0);
1088 MLX5_ASSERT(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1089 if (conf->dst == REG_C_0) {
1090 /* Copy to reg_c[0], within mask only. */
1091 reg_dst.offset = rte_bsf32(reg_c0);
1093 * Mask is ignoring the enianness, because
1094 * there is no conversion in datapath.
1096 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1097 /* Copy from destination lower bits to reg_c[0]. */
1098 mask = reg_c0 >> reg_dst.offset;
1100 /* Copy from destination upper bits to reg_c[0]. */
1101 mask = reg_c0 << (sizeof(reg_c0) * CHAR_BIT -
1102 rte_fls_u32(reg_c0));
1105 mask = rte_cpu_to_be_32(reg_c0);
1106 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1107 /* Copy from reg_c[0] to destination lower bits. */
1110 /* Copy from reg_c[0] to destination upper bits. */
1111 reg_dst.offset = sizeof(reg_c0) * CHAR_BIT -
1112 (rte_fls_u32(reg_c0) -
1117 return flow_dv_convert_modify_action(&item,
1118 reg_src, ®_dst, res,
1119 MLX5_MODIFICATION_TYPE_COPY,
1124 * Convert MARK action to DV specification. This routine is used
1125 * in extensive metadata only and requires metadata register to be
1126 * handled. In legacy mode hardware tag resource is engaged.
1129 * Pointer to the rte_eth_dev structure.
1131 * Pointer to MARK action specification.
1132 * @param[in,out] resource
1133 * Pointer to the modify-header resource.
1135 * Pointer to the error structure.
1138 * 0 on success, a negative errno value otherwise and rte_errno is set.
1141 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1142 const struct rte_flow_action_mark *conf,
1143 struct mlx5_flow_dv_modify_hdr_resource *resource,
1144 struct rte_flow_error *error)
1146 struct mlx5_priv *priv = dev->data->dev_private;
1147 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1148 priv->sh->dv_mark_mask);
1149 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1150 struct rte_flow_item item = {
1154 struct field_modify_info reg_c_x[] = {
1160 return rte_flow_error_set(error, EINVAL,
1161 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1162 NULL, "zero mark action mask");
1163 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1166 MLX5_ASSERT(reg > 0);
1167 if (reg == REG_C_0) {
1168 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1169 uint32_t shl_c0 = rte_bsf32(msk_c0);
1171 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1172 mask = rte_cpu_to_be_32(mask) & msk_c0;
1173 mask = rte_cpu_to_be_32(mask << shl_c0);
1175 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1176 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1177 MLX5_MODIFICATION_TYPE_SET, error);
1181 * Get metadata register index for specified steering domain.
1184 * Pointer to the rte_eth_dev structure.
1186 * Attributes of flow to determine steering domain.
1188 * Pointer to the error structure.
1191 * positive index on success, a negative errno value otherwise
1192 * and rte_errno is set.
1194 static enum modify_reg
1195 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1196 const struct rte_flow_attr *attr,
1197 struct rte_flow_error *error)
1200 mlx5_flow_get_reg_id(dev, attr->transfer ?
1204 MLX5_METADATA_RX, 0, error);
1206 return rte_flow_error_set(error,
1207 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1208 NULL, "unavailable "
1209 "metadata register");
1214 * Convert SET_META action to DV specification.
1217 * Pointer to the rte_eth_dev structure.
1218 * @param[in,out] resource
1219 * Pointer to the modify-header resource.
1221 * Attributes of flow that includes this item.
1223 * Pointer to action specification.
1225 * Pointer to the error structure.
1228 * 0 on success, a negative errno value otherwise and rte_errno is set.
1231 flow_dv_convert_action_set_meta
1232 (struct rte_eth_dev *dev,
1233 struct mlx5_flow_dv_modify_hdr_resource *resource,
1234 const struct rte_flow_attr *attr,
1235 const struct rte_flow_action_set_meta *conf,
1236 struct rte_flow_error *error)
1238 uint32_t data = conf->data;
1239 uint32_t mask = conf->mask;
1240 struct rte_flow_item item = {
1244 struct field_modify_info reg_c_x[] = {
1247 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1252 * In datapath code there is no endianness
1253 * coversions for perfromance reasons, all
1254 * pattern conversions are done in rte_flow.
1256 if (reg == REG_C_0) {
1257 struct mlx5_priv *priv = dev->data->dev_private;
1258 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1261 MLX5_ASSERT(msk_c0);
1262 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1263 shl_c0 = rte_bsf32(msk_c0);
1265 shl_c0 = sizeof(msk_c0) * CHAR_BIT - rte_fls_u32(msk_c0);
1269 MLX5_ASSERT(!(~msk_c0 & rte_cpu_to_be_32(mask)));
1271 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1272 /* The routine expects parameters in memory as big-endian ones. */
1273 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1274 MLX5_MODIFICATION_TYPE_SET, error);
1278 * Convert modify-header set IPv4 DSCP action to DV specification.
1280 * @param[in,out] resource
1281 * Pointer to the modify-header resource.
1283 * Pointer to action specification.
1285 * Pointer to the error structure.
1288 * 0 on success, a negative errno value otherwise and rte_errno is set.
1291 flow_dv_convert_action_modify_ipv4_dscp
1292 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1293 const struct rte_flow_action *action,
1294 struct rte_flow_error *error)
1296 const struct rte_flow_action_set_dscp *conf =
1297 (const struct rte_flow_action_set_dscp *)(action->conf);
1298 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1299 struct rte_flow_item_ipv4 ipv4;
1300 struct rte_flow_item_ipv4 ipv4_mask;
1302 memset(&ipv4, 0, sizeof(ipv4));
1303 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1304 ipv4.hdr.type_of_service = conf->dscp;
1305 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1307 item.mask = &ipv4_mask;
1308 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1309 MLX5_MODIFICATION_TYPE_SET, error);
1313 * Convert modify-header set IPv6 DSCP action to DV specification.
1315 * @param[in,out] resource
1316 * Pointer to the modify-header resource.
1318 * Pointer to action specification.
1320 * Pointer to the error structure.
1323 * 0 on success, a negative errno value otherwise and rte_errno is set.
1326 flow_dv_convert_action_modify_ipv6_dscp
1327 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1328 const struct rte_flow_action *action,
1329 struct rte_flow_error *error)
1331 const struct rte_flow_action_set_dscp *conf =
1332 (const struct rte_flow_action_set_dscp *)(action->conf);
1333 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1334 struct rte_flow_item_ipv6 ipv6;
1335 struct rte_flow_item_ipv6 ipv6_mask;
1337 memset(&ipv6, 0, sizeof(ipv6));
1338 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1340 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1341 * rdma-core only accept the DSCP bits byte aligned start from
1342 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1343 * bits in IPv6 case as rdma-core requires byte aligned value.
1345 ipv6.hdr.vtc_flow = conf->dscp;
1346 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1348 item.mask = &ipv6_mask;
1349 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1350 MLX5_MODIFICATION_TYPE_SET, error);
1354 * Validate MARK item.
1357 * Pointer to the rte_eth_dev structure.
1359 * Item specification.
1361 * Attributes of flow that includes this item.
1363 * Pointer to error structure.
1366 * 0 on success, a negative errno value otherwise and rte_errno is set.
1369 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1370 const struct rte_flow_item *item,
1371 const struct rte_flow_attr *attr __rte_unused,
1372 struct rte_flow_error *error)
1374 struct mlx5_priv *priv = dev->data->dev_private;
1375 struct mlx5_dev_config *config = &priv->config;
1376 const struct rte_flow_item_mark *spec = item->spec;
1377 const struct rte_flow_item_mark *mask = item->mask;
1378 const struct rte_flow_item_mark nic_mask = {
1379 .id = priv->sh->dv_mark_mask,
1383 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1384 return rte_flow_error_set(error, ENOTSUP,
1385 RTE_FLOW_ERROR_TYPE_ITEM, item,
1386 "extended metadata feature"
1388 if (!mlx5_flow_ext_mreg_supported(dev))
1389 return rte_flow_error_set(error, ENOTSUP,
1390 RTE_FLOW_ERROR_TYPE_ITEM, item,
1391 "extended metadata register"
1392 " isn't supported");
1394 return rte_flow_error_set(error, ENOTSUP,
1395 RTE_FLOW_ERROR_TYPE_ITEM, item,
1396 "extended metadata register"
1397 " isn't available");
1398 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1402 return rte_flow_error_set(error, EINVAL,
1403 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1405 "data cannot be empty");
1406 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1407 return rte_flow_error_set(error, EINVAL,
1408 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1410 "mark id exceeds the limit");
1414 return rte_flow_error_set(error, EINVAL,
1415 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1416 "mask cannot be zero");
1418 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1419 (const uint8_t *)&nic_mask,
1420 sizeof(struct rte_flow_item_mark),
1428 * Validate META item.
1431 * Pointer to the rte_eth_dev structure.
1433 * Item specification.
1435 * Attributes of flow that includes this item.
1437 * Pointer to error structure.
1440 * 0 on success, a negative errno value otherwise and rte_errno is set.
1443 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1444 const struct rte_flow_item *item,
1445 const struct rte_flow_attr *attr,
1446 struct rte_flow_error *error)
1448 struct mlx5_priv *priv = dev->data->dev_private;
1449 struct mlx5_dev_config *config = &priv->config;
1450 const struct rte_flow_item_meta *spec = item->spec;
1451 const struct rte_flow_item_meta *mask = item->mask;
1452 struct rte_flow_item_meta nic_mask = {
1459 return rte_flow_error_set(error, EINVAL,
1460 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1462 "data cannot be empty");
1463 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1464 if (!mlx5_flow_ext_mreg_supported(dev))
1465 return rte_flow_error_set(error, ENOTSUP,
1466 RTE_FLOW_ERROR_TYPE_ITEM, item,
1467 "extended metadata register"
1468 " isn't supported");
1469 reg = flow_dv_get_metadata_reg(dev, attr, error);
1473 return rte_flow_error_set(error, ENOTSUP,
1474 RTE_FLOW_ERROR_TYPE_ITEM, item,
1478 nic_mask.data = priv->sh->dv_meta_mask;
1479 } else if (attr->transfer) {
1480 return rte_flow_error_set(error, ENOTSUP,
1481 RTE_FLOW_ERROR_TYPE_ITEM, item,
1482 "extended metadata feature "
1483 "should be enabled when "
1484 "meta item is requested "
1485 "with e-switch mode ");
1488 mask = &rte_flow_item_meta_mask;
1490 return rte_flow_error_set(error, EINVAL,
1491 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1492 "mask cannot be zero");
1494 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1495 (const uint8_t *)&nic_mask,
1496 sizeof(struct rte_flow_item_meta),
1502 * Validate TAG item.
1505 * Pointer to the rte_eth_dev structure.
1507 * Item specification.
1509 * Attributes of flow that includes this item.
1511 * Pointer to error structure.
1514 * 0 on success, a negative errno value otherwise and rte_errno is set.
1517 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
1518 const struct rte_flow_item *item,
1519 const struct rte_flow_attr *attr __rte_unused,
1520 struct rte_flow_error *error)
1522 const struct rte_flow_item_tag *spec = item->spec;
1523 const struct rte_flow_item_tag *mask = item->mask;
1524 const struct rte_flow_item_tag nic_mask = {
1525 .data = RTE_BE32(UINT32_MAX),
1530 if (!mlx5_flow_ext_mreg_supported(dev))
1531 return rte_flow_error_set(error, ENOTSUP,
1532 RTE_FLOW_ERROR_TYPE_ITEM, item,
1533 "extensive metadata register"
1534 " isn't supported");
1536 return rte_flow_error_set(error, EINVAL,
1537 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1539 "data cannot be empty");
1541 mask = &rte_flow_item_tag_mask;
1543 return rte_flow_error_set(error, EINVAL,
1544 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1545 "mask cannot be zero");
1547 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1548 (const uint8_t *)&nic_mask,
1549 sizeof(struct rte_flow_item_tag),
1553 if (mask->index != 0xff)
1554 return rte_flow_error_set(error, EINVAL,
1555 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1556 "partial mask for tag index"
1557 " is not supported");
1558 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
1561 MLX5_ASSERT(ret != REG_NON);
1566 * Validate vport item.
1569 * Pointer to the rte_eth_dev structure.
1571 * Item specification.
1573 * Attributes of flow that includes this item.
1574 * @param[in] item_flags
1575 * Bit-fields that holds the items detected until now.
1577 * Pointer to error structure.
1580 * 0 on success, a negative errno value otherwise and rte_errno is set.
1583 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
1584 const struct rte_flow_item *item,
1585 const struct rte_flow_attr *attr,
1586 uint64_t item_flags,
1587 struct rte_flow_error *error)
1589 const struct rte_flow_item_port_id *spec = item->spec;
1590 const struct rte_flow_item_port_id *mask = item->mask;
1591 const struct rte_flow_item_port_id switch_mask = {
1594 struct mlx5_priv *esw_priv;
1595 struct mlx5_priv *dev_priv;
1598 if (!attr->transfer)
1599 return rte_flow_error_set(error, EINVAL,
1600 RTE_FLOW_ERROR_TYPE_ITEM,
1602 "match on port id is valid only"
1603 " when transfer flag is enabled");
1604 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
1605 return rte_flow_error_set(error, ENOTSUP,
1606 RTE_FLOW_ERROR_TYPE_ITEM, item,
1607 "multiple source ports are not"
1610 mask = &switch_mask;
1611 if (mask->id != 0xffffffff)
1612 return rte_flow_error_set(error, ENOTSUP,
1613 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
1615 "no support for partial mask on"
1617 ret = mlx5_flow_item_acceptable
1618 (item, (const uint8_t *)mask,
1619 (const uint8_t *)&rte_flow_item_port_id_mask,
1620 sizeof(struct rte_flow_item_port_id),
1626 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
1628 return rte_flow_error_set(error, rte_errno,
1629 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1630 "failed to obtain E-Switch info for"
1632 dev_priv = mlx5_dev_to_eswitch_info(dev);
1634 return rte_flow_error_set(error, rte_errno,
1635 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1637 "failed to obtain E-Switch info");
1638 if (esw_priv->domain_id != dev_priv->domain_id)
1639 return rte_flow_error_set(error, EINVAL,
1640 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1641 "cannot match on a port from a"
1642 " different E-Switch");
1647 * Validate VLAN item.
1650 * Item specification.
1651 * @param[in] item_flags
1652 * Bit-fields that holds the items detected until now.
1654 * Ethernet device flow is being created on.
1656 * Pointer to error structure.
1659 * 0 on success, a negative errno value otherwise and rte_errno is set.
1662 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
1663 uint64_t item_flags,
1664 struct rte_eth_dev *dev,
1665 struct rte_flow_error *error)
1667 const struct rte_flow_item_vlan *mask = item->mask;
1668 const struct rte_flow_item_vlan nic_mask = {
1669 .tci = RTE_BE16(UINT16_MAX),
1670 .inner_type = RTE_BE16(UINT16_MAX),
1672 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1674 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1675 MLX5_FLOW_LAYER_INNER_L4) :
1676 (MLX5_FLOW_LAYER_OUTER_L3 |
1677 MLX5_FLOW_LAYER_OUTER_L4);
1678 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1679 MLX5_FLOW_LAYER_OUTER_VLAN;
1681 if (item_flags & vlanm)
1682 return rte_flow_error_set(error, EINVAL,
1683 RTE_FLOW_ERROR_TYPE_ITEM, item,
1684 "multiple VLAN layers not supported");
1685 else if ((item_flags & l34m) != 0)
1686 return rte_flow_error_set(error, EINVAL,
1687 RTE_FLOW_ERROR_TYPE_ITEM, item,
1688 "VLAN cannot follow L3/L4 layer");
1690 mask = &rte_flow_item_vlan_mask;
1691 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1692 (const uint8_t *)&nic_mask,
1693 sizeof(struct rte_flow_item_vlan),
1697 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1698 struct mlx5_priv *priv = dev->data->dev_private;
1700 if (priv->vmwa_context) {
1702 * Non-NULL context means we have a virtual machine
1703 * and SR-IOV enabled, we have to create VLAN interface
1704 * to make hypervisor to setup E-Switch vport
1705 * context correctly. We avoid creating the multiple
1706 * VLAN interfaces, so we cannot support VLAN tag mask.
1708 return rte_flow_error_set(error, EINVAL,
1709 RTE_FLOW_ERROR_TYPE_ITEM,
1711 "VLAN tag mask is not"
1712 " supported in virtual"
1720 * GTP flags are contained in 1 byte of the format:
1721 * -------------------------------------------
1722 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
1723 * |-----------------------------------------|
1724 * | value | Version | PT | Res | E | S | PN |
1725 * -------------------------------------------
1727 * Matching is supported only for GTP flags E, S, PN.
1729 #define MLX5_GTP_FLAGS_MASK 0x07
1732 * Validate GTP item.
1735 * Pointer to the rte_eth_dev structure.
1737 * Item specification.
1738 * @param[in] item_flags
1739 * Bit-fields that holds the items detected until now.
1741 * Pointer to error structure.
1744 * 0 on success, a negative errno value otherwise and rte_errno is set.
1747 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
1748 const struct rte_flow_item *item,
1749 uint64_t item_flags,
1750 struct rte_flow_error *error)
1752 struct mlx5_priv *priv = dev->data->dev_private;
1753 const struct rte_flow_item_gtp *spec = item->spec;
1754 const struct rte_flow_item_gtp *mask = item->mask;
1755 const struct rte_flow_item_gtp nic_mask = {
1756 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
1758 .teid = RTE_BE32(0xffffffff),
1761 if (!priv->config.hca_attr.tunnel_stateless_gtp)
1762 return rte_flow_error_set(error, ENOTSUP,
1763 RTE_FLOW_ERROR_TYPE_ITEM, item,
1764 "GTP support is not enabled");
1765 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1766 return rte_flow_error_set(error, ENOTSUP,
1767 RTE_FLOW_ERROR_TYPE_ITEM, item,
1768 "multiple tunnel layers not"
1770 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1771 return rte_flow_error_set(error, EINVAL,
1772 RTE_FLOW_ERROR_TYPE_ITEM, item,
1773 "no outer UDP layer found");
1775 mask = &rte_flow_item_gtp_mask;
1776 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
1777 return rte_flow_error_set(error, ENOTSUP,
1778 RTE_FLOW_ERROR_TYPE_ITEM, item,
1779 "Match is supported for GTP"
1781 return mlx5_flow_item_acceptable
1782 (item, (const uint8_t *)mask,
1783 (const uint8_t *)&nic_mask,
1784 sizeof(struct rte_flow_item_gtp),
1789 * Validate the pop VLAN action.
1792 * Pointer to the rte_eth_dev structure.
1793 * @param[in] action_flags
1794 * Holds the actions detected until now.
1796 * Pointer to the pop vlan action.
1797 * @param[in] item_flags
1798 * The items found in this flow rule.
1800 * Pointer to flow attributes.
1802 * Pointer to error structure.
1805 * 0 on success, a negative errno value otherwise and rte_errno is set.
1808 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
1809 uint64_t action_flags,
1810 const struct rte_flow_action *action,
1811 uint64_t item_flags,
1812 const struct rte_flow_attr *attr,
1813 struct rte_flow_error *error)
1815 const struct mlx5_priv *priv = dev->data->dev_private;
1819 if (!priv->sh->pop_vlan_action)
1820 return rte_flow_error_set(error, ENOTSUP,
1821 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1823 "pop vlan action is not supported");
1825 return rte_flow_error_set(error, ENOTSUP,
1826 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1828 "pop vlan action not supported for "
1830 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
1831 return rte_flow_error_set(error, ENOTSUP,
1832 RTE_FLOW_ERROR_TYPE_ACTION, action,
1833 "no support for multiple VLAN "
1835 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
1836 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
1837 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
1838 return rte_flow_error_set(error, ENOTSUP,
1839 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1841 "cannot pop vlan after decap without "
1842 "match on inner vlan in the flow");
1843 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
1844 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
1845 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1846 return rte_flow_error_set(error, ENOTSUP,
1847 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1849 "cannot pop vlan without a "
1850 "match on (outer) vlan in the flow");
1851 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1852 return rte_flow_error_set(error, EINVAL,
1853 RTE_FLOW_ERROR_TYPE_ACTION, action,
1854 "wrong action order, port_id should "
1855 "be after pop VLAN action");
1856 if (!attr->transfer && priv->representor)
1857 return rte_flow_error_set(error, ENOTSUP,
1858 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1859 "pop vlan action for VF representor "
1860 "not supported on NIC table");
1865 * Get VLAN default info from vlan match info.
1868 * the list of item specifications.
1870 * pointer VLAN info to fill to.
1873 * 0 on success, a negative errno value otherwise and rte_errno is set.
1876 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
1877 struct rte_vlan_hdr *vlan)
1879 const struct rte_flow_item_vlan nic_mask = {
1880 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
1881 MLX5DV_FLOW_VLAN_VID_MASK),
1882 .inner_type = RTE_BE16(0xffff),
1887 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
1888 int type = items->type;
1890 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
1891 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
1894 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
1895 const struct rte_flow_item_vlan *vlan_m = items->mask;
1896 const struct rte_flow_item_vlan *vlan_v = items->spec;
1898 /* If VLAN item in pattern doesn't contain data, return here. */
1903 /* Only full match values are accepted */
1904 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
1905 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
1906 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
1908 rte_be_to_cpu_16(vlan_v->tci &
1909 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
1911 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
1912 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
1913 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
1915 rte_be_to_cpu_16(vlan_v->tci &
1916 MLX5DV_FLOW_VLAN_VID_MASK_BE);
1918 if (vlan_m->inner_type == nic_mask.inner_type)
1919 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
1920 vlan_m->inner_type);
1925 * Validate the push VLAN action.
1928 * Pointer to the rte_eth_dev structure.
1929 * @param[in] action_flags
1930 * Holds the actions detected until now.
1931 * @param[in] item_flags
1932 * The items found in this flow rule.
1934 * Pointer to the action structure.
1936 * Pointer to flow attributes
1938 * Pointer to error structure.
1941 * 0 on success, a negative errno value otherwise and rte_errno is set.
1944 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
1945 uint64_t action_flags,
1946 const struct rte_flow_item_vlan *vlan_m,
1947 const struct rte_flow_action *action,
1948 const struct rte_flow_attr *attr,
1949 struct rte_flow_error *error)
1951 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
1952 const struct mlx5_priv *priv = dev->data->dev_private;
1954 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
1955 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
1956 return rte_flow_error_set(error, EINVAL,
1957 RTE_FLOW_ERROR_TYPE_ACTION, action,
1958 "invalid vlan ethertype");
1959 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1960 return rte_flow_error_set(error, EINVAL,
1961 RTE_FLOW_ERROR_TYPE_ACTION, action,
1962 "wrong action order, port_id should "
1963 "be after push VLAN");
1964 if (!attr->transfer && priv->representor)
1965 return rte_flow_error_set(error, ENOTSUP,
1966 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1967 "push vlan action for VF representor "
1968 "not supported on NIC table");
1970 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
1971 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
1972 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
1973 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
1974 !(mlx5_flow_find_action
1975 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
1976 return rte_flow_error_set(error, EINVAL,
1977 RTE_FLOW_ERROR_TYPE_ACTION, action,
1978 "not full match mask on VLAN PCP and "
1979 "there is no of_set_vlan_pcp action, "
1980 "push VLAN action cannot figure out "
1983 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
1984 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
1985 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
1986 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
1987 !(mlx5_flow_find_action
1988 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
1989 return rte_flow_error_set(error, EINVAL,
1990 RTE_FLOW_ERROR_TYPE_ACTION, action,
1991 "not full match mask on VLAN VID and "
1992 "there is no of_set_vlan_vid action, "
1993 "push VLAN action cannot figure out "
2000 * Validate the set VLAN PCP.
2002 * @param[in] action_flags
2003 * Holds the actions detected until now.
2004 * @param[in] actions
2005 * Pointer to the list of actions remaining in the flow rule.
2007 * Pointer to error structure.
2010 * 0 on success, a negative errno value otherwise and rte_errno is set.
2013 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2014 const struct rte_flow_action actions[],
2015 struct rte_flow_error *error)
2017 const struct rte_flow_action *action = actions;
2018 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2020 if (conf->vlan_pcp > 7)
2021 return rte_flow_error_set(error, EINVAL,
2022 RTE_FLOW_ERROR_TYPE_ACTION, action,
2023 "VLAN PCP value is too big");
2024 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2025 return rte_flow_error_set(error, ENOTSUP,
2026 RTE_FLOW_ERROR_TYPE_ACTION, action,
2027 "set VLAN PCP action must follow "
2028 "the push VLAN action");
2029 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2030 return rte_flow_error_set(error, ENOTSUP,
2031 RTE_FLOW_ERROR_TYPE_ACTION, action,
2032 "Multiple VLAN PCP modification are "
2034 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2035 return rte_flow_error_set(error, EINVAL,
2036 RTE_FLOW_ERROR_TYPE_ACTION, action,
2037 "wrong action order, port_id should "
2038 "be after set VLAN PCP");
2043 * Validate the set VLAN VID.
2045 * @param[in] item_flags
2046 * Holds the items detected in this rule.
2047 * @param[in] action_flags
2048 * Holds the actions detected until now.
2049 * @param[in] actions
2050 * Pointer to the list of actions remaining in the flow rule.
2052 * Pointer to error structure.
2055 * 0 on success, a negative errno value otherwise and rte_errno is set.
2058 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2059 uint64_t action_flags,
2060 const struct rte_flow_action actions[],
2061 struct rte_flow_error *error)
2063 const struct rte_flow_action *action = actions;
2064 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
2066 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
2067 return rte_flow_error_set(error, EINVAL,
2068 RTE_FLOW_ERROR_TYPE_ACTION, action,
2069 "VLAN VID value is too big");
2070 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
2071 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2072 return rte_flow_error_set(error, ENOTSUP,
2073 RTE_FLOW_ERROR_TYPE_ACTION, action,
2074 "set VLAN VID action must follow push"
2075 " VLAN action or match on VLAN item");
2076 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
2077 return rte_flow_error_set(error, ENOTSUP,
2078 RTE_FLOW_ERROR_TYPE_ACTION, action,
2079 "Multiple VLAN VID modifications are "
2081 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2082 return rte_flow_error_set(error, EINVAL,
2083 RTE_FLOW_ERROR_TYPE_ACTION, action,
2084 "wrong action order, port_id should "
2085 "be after set VLAN VID");
2090 * Validate the FLAG action.
2093 * Pointer to the rte_eth_dev structure.
2094 * @param[in] action_flags
2095 * Holds the actions detected until now.
2097 * Pointer to flow attributes
2099 * Pointer to error structure.
2102 * 0 on success, a negative errno value otherwise and rte_errno is set.
2105 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
2106 uint64_t action_flags,
2107 const struct rte_flow_attr *attr,
2108 struct rte_flow_error *error)
2110 struct mlx5_priv *priv = dev->data->dev_private;
2111 struct mlx5_dev_config *config = &priv->config;
2114 /* Fall back if no extended metadata register support. */
2115 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2116 return mlx5_flow_validate_action_flag(action_flags, attr,
2118 /* Extensive metadata mode requires registers. */
2119 if (!mlx5_flow_ext_mreg_supported(dev))
2120 return rte_flow_error_set(error, ENOTSUP,
2121 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2122 "no metadata registers "
2123 "to support flag action");
2124 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
2125 return rte_flow_error_set(error, ENOTSUP,
2126 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2127 "extended metadata register"
2128 " isn't available");
2129 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2132 MLX5_ASSERT(ret > 0);
2133 if (action_flags & MLX5_FLOW_ACTION_MARK)
2134 return rte_flow_error_set(error, EINVAL,
2135 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2136 "can't mark and flag in same flow");
2137 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2138 return rte_flow_error_set(error, EINVAL,
2139 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2141 " actions in same flow");
2146 * Validate MARK action.
2149 * Pointer to the rte_eth_dev structure.
2151 * Pointer to action.
2152 * @param[in] action_flags
2153 * Holds the actions detected until now.
2155 * Pointer to flow attributes
2157 * Pointer to error structure.
2160 * 0 on success, a negative errno value otherwise and rte_errno is set.
2163 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
2164 const struct rte_flow_action *action,
2165 uint64_t action_flags,
2166 const struct rte_flow_attr *attr,
2167 struct rte_flow_error *error)
2169 struct mlx5_priv *priv = dev->data->dev_private;
2170 struct mlx5_dev_config *config = &priv->config;
2171 const struct rte_flow_action_mark *mark = action->conf;
2174 /* Fall back if no extended metadata register support. */
2175 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2176 return mlx5_flow_validate_action_mark(action, action_flags,
2178 /* Extensive metadata mode requires registers. */
2179 if (!mlx5_flow_ext_mreg_supported(dev))
2180 return rte_flow_error_set(error, ENOTSUP,
2181 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2182 "no metadata registers "
2183 "to support mark action");
2184 if (!priv->sh->dv_mark_mask)
2185 return rte_flow_error_set(error, ENOTSUP,
2186 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2187 "extended metadata register"
2188 " isn't available");
2189 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2192 MLX5_ASSERT(ret > 0);
2194 return rte_flow_error_set(error, EINVAL,
2195 RTE_FLOW_ERROR_TYPE_ACTION, action,
2196 "configuration cannot be null");
2197 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
2198 return rte_flow_error_set(error, EINVAL,
2199 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2201 "mark id exceeds the limit");
2202 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2203 return rte_flow_error_set(error, EINVAL,
2204 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2205 "can't flag and mark in same flow");
2206 if (action_flags & MLX5_FLOW_ACTION_MARK)
2207 return rte_flow_error_set(error, EINVAL,
2208 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2209 "can't have 2 mark actions in same"
2215 * Validate SET_META action.
2218 * Pointer to the rte_eth_dev structure.
2220 * Pointer to the action structure.
2221 * @param[in] action_flags
2222 * Holds the actions detected until now.
2224 * Pointer to flow attributes
2226 * Pointer to error structure.
2229 * 0 on success, a negative errno value otherwise and rte_errno is set.
2232 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
2233 const struct rte_flow_action *action,
2234 uint64_t action_flags __rte_unused,
2235 const struct rte_flow_attr *attr,
2236 struct rte_flow_error *error)
2238 const struct rte_flow_action_set_meta *conf;
2239 uint32_t nic_mask = UINT32_MAX;
2242 if (!mlx5_flow_ext_mreg_supported(dev))
2243 return rte_flow_error_set(error, ENOTSUP,
2244 RTE_FLOW_ERROR_TYPE_ACTION, action,
2245 "extended metadata register"
2246 " isn't supported");
2247 reg = flow_dv_get_metadata_reg(dev, attr, error);
2250 if (reg != REG_A && reg != REG_B) {
2251 struct mlx5_priv *priv = dev->data->dev_private;
2253 nic_mask = priv->sh->dv_meta_mask;
2255 if (!(action->conf))
2256 return rte_flow_error_set(error, EINVAL,
2257 RTE_FLOW_ERROR_TYPE_ACTION, action,
2258 "configuration cannot be null");
2259 conf = (const struct rte_flow_action_set_meta *)action->conf;
2261 return rte_flow_error_set(error, EINVAL,
2262 RTE_FLOW_ERROR_TYPE_ACTION, action,
2263 "zero mask doesn't have any effect");
2264 if (conf->mask & ~nic_mask)
2265 return rte_flow_error_set(error, EINVAL,
2266 RTE_FLOW_ERROR_TYPE_ACTION, action,
2267 "meta data must be within reg C0");
2272 * Validate SET_TAG action.
2275 * Pointer to the rte_eth_dev structure.
2277 * Pointer to the action structure.
2278 * @param[in] action_flags
2279 * Holds the actions detected until now.
2281 * Pointer to flow attributes
2283 * Pointer to error structure.
2286 * 0 on success, a negative errno value otherwise and rte_errno is set.
2289 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
2290 const struct rte_flow_action *action,
2291 uint64_t action_flags,
2292 const struct rte_flow_attr *attr,
2293 struct rte_flow_error *error)
2295 const struct rte_flow_action_set_tag *conf;
2296 const uint64_t terminal_action_flags =
2297 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
2298 MLX5_FLOW_ACTION_RSS;
2301 if (!mlx5_flow_ext_mreg_supported(dev))
2302 return rte_flow_error_set(error, ENOTSUP,
2303 RTE_FLOW_ERROR_TYPE_ACTION, action,
2304 "extensive metadata register"
2305 " isn't supported");
2306 if (!(action->conf))
2307 return rte_flow_error_set(error, EINVAL,
2308 RTE_FLOW_ERROR_TYPE_ACTION, action,
2309 "configuration cannot be null");
2310 conf = (const struct rte_flow_action_set_tag *)action->conf;
2312 return rte_flow_error_set(error, EINVAL,
2313 RTE_FLOW_ERROR_TYPE_ACTION, action,
2314 "zero mask doesn't have any effect");
2315 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
2318 if (!attr->transfer && attr->ingress &&
2319 (action_flags & terminal_action_flags))
2320 return rte_flow_error_set(error, EINVAL,
2321 RTE_FLOW_ERROR_TYPE_ACTION, action,
2322 "set_tag has no effect"
2323 " with terminal actions");
2328 * Validate count action.
2331 * Pointer to rte_eth_dev structure.
2333 * Pointer to error structure.
2336 * 0 on success, a negative errno value otherwise and rte_errno is set.
2339 flow_dv_validate_action_count(struct rte_eth_dev *dev,
2340 struct rte_flow_error *error)
2342 struct mlx5_priv *priv = dev->data->dev_private;
2344 if (!priv->config.devx)
2346 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
2350 return rte_flow_error_set
2352 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2354 "count action not supported");
2358 * Validate the L2 encap action.
2361 * Pointer to the rte_eth_dev structure.
2362 * @param[in] action_flags
2363 * Holds the actions detected until now.
2365 * Pointer to the action structure.
2367 * Pointer to flow attributes.
2369 * Pointer to error structure.
2372 * 0 on success, a negative errno value otherwise and rte_errno is set.
2375 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
2376 uint64_t action_flags,
2377 const struct rte_flow_action *action,
2378 const struct rte_flow_attr *attr,
2379 struct rte_flow_error *error)
2381 const struct mlx5_priv *priv = dev->data->dev_private;
2383 if (!(action->conf))
2384 return rte_flow_error_set(error, EINVAL,
2385 RTE_FLOW_ERROR_TYPE_ACTION, action,
2386 "configuration cannot be null");
2387 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
2388 return rte_flow_error_set(error, EINVAL,
2389 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2390 "can only have a single encap action "
2392 if (!attr->transfer && priv->representor)
2393 return rte_flow_error_set(error, ENOTSUP,
2394 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2395 "encap action for VF representor "
2396 "not supported on NIC table");
2401 * Validate a decap action.
2404 * Pointer to the rte_eth_dev structure.
2405 * @param[in] action_flags
2406 * Holds the actions detected until now.
2408 * Pointer to flow attributes
2410 * Pointer to error structure.
2413 * 0 on success, a negative errno value otherwise and rte_errno is set.
2416 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
2417 uint64_t action_flags,
2418 const struct rte_flow_attr *attr,
2419 struct rte_flow_error *error)
2421 const struct mlx5_priv *priv = dev->data->dev_private;
2423 if (priv->config.hca_attr.scatter_fcs_w_decap_disable &&
2424 !priv->config.decap_en)
2425 return rte_flow_error_set(error, ENOTSUP,
2426 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2427 "decap is not enabled");
2428 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
2429 return rte_flow_error_set(error, ENOTSUP,
2430 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2432 MLX5_FLOW_ACTION_DECAP ? "can only "
2433 "have a single decap action" : "decap "
2434 "after encap is not supported");
2435 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
2436 return rte_flow_error_set(error, EINVAL,
2437 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2438 "can't have decap action after"
2441 return rte_flow_error_set(error, ENOTSUP,
2442 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2444 "decap action not supported for "
2446 if (!attr->transfer && priv->representor)
2447 return rte_flow_error_set(error, ENOTSUP,
2448 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2449 "decap action for VF representor "
2450 "not supported on NIC table");
2454 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
2457 * Validate the raw encap and decap actions.
2460 * Pointer to the rte_eth_dev structure.
2462 * Pointer to the decap action.
2464 * Pointer to the encap action.
2466 * Pointer to flow attributes
2467 * @param[in/out] action_flags
2468 * Holds the actions detected until now.
2469 * @param[out] actions_n
2470 * pointer to the number of actions counter.
2472 * Pointer to error structure.
2475 * 0 on success, a negative errno value otherwise and rte_errno is set.
2478 flow_dv_validate_action_raw_encap_decap
2479 (struct rte_eth_dev *dev,
2480 const struct rte_flow_action_raw_decap *decap,
2481 const struct rte_flow_action_raw_encap *encap,
2482 const struct rte_flow_attr *attr, uint64_t *action_flags,
2483 int *actions_n, struct rte_flow_error *error)
2485 const struct mlx5_priv *priv = dev->data->dev_private;
2488 if (encap && (!encap->size || !encap->data))
2489 return rte_flow_error_set(error, EINVAL,
2490 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2491 "raw encap data cannot be empty");
2492 if (decap && encap) {
2493 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
2494 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
2497 else if (encap->size <=
2498 MLX5_ENCAPSULATION_DECISION_SIZE &&
2500 MLX5_ENCAPSULATION_DECISION_SIZE)
2503 else if (encap->size >
2504 MLX5_ENCAPSULATION_DECISION_SIZE &&
2506 MLX5_ENCAPSULATION_DECISION_SIZE)
2507 /* 2 L2 actions: encap and decap. */
2510 return rte_flow_error_set(error,
2512 RTE_FLOW_ERROR_TYPE_ACTION,
2513 NULL, "unsupported too small "
2514 "raw decap and too small raw "
2515 "encap combination");
2518 ret = flow_dv_validate_action_decap(dev, *action_flags, attr,
2522 *action_flags |= MLX5_FLOW_ACTION_DECAP;
2526 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
2527 return rte_flow_error_set(error, ENOTSUP,
2528 RTE_FLOW_ERROR_TYPE_ACTION,
2530 "small raw encap size");
2531 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
2532 return rte_flow_error_set(error, EINVAL,
2533 RTE_FLOW_ERROR_TYPE_ACTION,
2535 "more than one encap action");
2536 if (!attr->transfer && priv->representor)
2537 return rte_flow_error_set
2539 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2540 "encap action for VF representor "
2541 "not supported on NIC table");
2542 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
2549 * Match encap_decap resource.
2552 * Pointer to exist resource entry object.
2554 * Pointer to new encap_decap resource.
2557 * 0 on matching, -1 otherwise.
2560 flow_dv_encap_decap_resource_match(struct mlx5_hlist_entry *entry, void *ctx)
2562 struct mlx5_flow_dv_encap_decap_resource *resource;
2563 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2565 resource = (struct mlx5_flow_dv_encap_decap_resource *)ctx;
2566 cache_resource = container_of(entry,
2567 struct mlx5_flow_dv_encap_decap_resource,
2569 if (resource->entry.key == cache_resource->entry.key &&
2570 resource->reformat_type == cache_resource->reformat_type &&
2571 resource->ft_type == cache_resource->ft_type &&
2572 resource->flags == cache_resource->flags &&
2573 resource->size == cache_resource->size &&
2574 !memcmp((const void *)resource->buf,
2575 (const void *)cache_resource->buf,
2582 * Find existing encap/decap resource or create and register a new one.
2584 * @param[in, out] dev
2585 * Pointer to rte_eth_dev structure.
2586 * @param[in, out] resource
2587 * Pointer to encap/decap resource.
2588 * @parm[in, out] dev_flow
2589 * Pointer to the dev_flow.
2591 * pointer to error structure.
2594 * 0 on success otherwise -errno and errno is set.
2597 flow_dv_encap_decap_resource_register
2598 (struct rte_eth_dev *dev,
2599 struct mlx5_flow_dv_encap_decap_resource *resource,
2600 struct mlx5_flow *dev_flow,
2601 struct rte_flow_error *error)
2603 struct mlx5_priv *priv = dev->data->dev_private;
2604 struct mlx5_dev_ctx_shared *sh = priv->sh;
2605 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2606 struct mlx5dv_dr_domain *domain;
2607 struct mlx5_hlist_entry *entry;
2608 union mlx5_flow_encap_decap_key encap_decap_key = {
2610 .ft_type = resource->ft_type,
2611 .refmt_type = resource->reformat_type,
2612 .buf_size = resource->size,
2613 .table_level = !!dev_flow->dv.group,
2619 resource->flags = dev_flow->dv.group ? 0 : 1;
2620 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2621 domain = sh->fdb_domain;
2622 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2623 domain = sh->rx_domain;
2625 domain = sh->tx_domain;
2626 encap_decap_key.cksum = __rte_raw_cksum(resource->buf,
2628 resource->entry.key = encap_decap_key.v64;
2629 /* Lookup a matching resource from cache. */
2630 entry = mlx5_hlist_lookup_ex(sh->encaps_decaps, resource->entry.key,
2631 flow_dv_encap_decap_resource_match,
2634 cache_resource = container_of(entry,
2635 struct mlx5_flow_dv_encap_decap_resource, entry);
2636 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d++",
2637 (void *)cache_resource,
2638 rte_atomic32_read(&cache_resource->refcnt));
2639 rte_atomic32_inc(&cache_resource->refcnt);
2640 dev_flow->handle->dvh.rix_encap_decap = cache_resource->idx;
2641 dev_flow->dv.encap_decap = cache_resource;
2644 /* Register new encap/decap resource. */
2645 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
2646 &dev_flow->handle->dvh.rix_encap_decap);
2647 if (!cache_resource)
2648 return rte_flow_error_set(error, ENOMEM,
2649 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2650 "cannot allocate resource memory");
2651 *cache_resource = *resource;
2652 cache_resource->idx = dev_flow->handle->dvh.rix_encap_decap;
2653 ret = mlx5_flow_os_create_flow_action_packet_reformat
2654 (sh->ctx, domain, cache_resource,
2655 &cache_resource->action);
2657 mlx5_free(cache_resource);
2658 return rte_flow_error_set(error, ENOMEM,
2659 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2660 NULL, "cannot create action");
2662 rte_atomic32_init(&cache_resource->refcnt);
2663 rte_atomic32_inc(&cache_resource->refcnt);
2664 if (mlx5_hlist_insert_ex(sh->encaps_decaps, &cache_resource->entry,
2665 flow_dv_encap_decap_resource_match,
2666 (void *)cache_resource)) {
2667 claim_zero(mlx5_flow_os_destroy_flow_action
2668 (cache_resource->action));
2669 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
2670 cache_resource->idx);
2671 return rte_flow_error_set(error, EEXIST,
2672 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2673 NULL, "action exist");
2675 dev_flow->dv.encap_decap = cache_resource;
2676 DRV_LOG(DEBUG, "new encap/decap resource %p: refcnt %d++",
2677 (void *)cache_resource,
2678 rte_atomic32_read(&cache_resource->refcnt));
2683 * Find existing table jump resource or create and register a new one.
2685 * @param[in, out] dev
2686 * Pointer to rte_eth_dev structure.
2687 * @param[in, out] tbl
2688 * Pointer to flow table resource.
2689 * @parm[in, out] dev_flow
2690 * Pointer to the dev_flow.
2692 * pointer to error structure.
2695 * 0 on success otherwise -errno and errno is set.
2698 flow_dv_jump_tbl_resource_register
2699 (struct rte_eth_dev *dev __rte_unused,
2700 struct mlx5_flow_tbl_resource *tbl,
2701 struct mlx5_flow *dev_flow,
2702 struct rte_flow_error *error)
2704 struct mlx5_flow_tbl_data_entry *tbl_data =
2705 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
2709 cnt = rte_atomic32_read(&tbl_data->jump.refcnt);
2711 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
2712 (tbl->obj, &tbl_data->jump.action);
2714 return rte_flow_error_set(error, ENOMEM,
2715 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2716 NULL, "cannot create jump action");
2717 DRV_LOG(DEBUG, "new jump table resource %p: refcnt %d++",
2718 (void *)&tbl_data->jump, cnt);
2720 /* old jump should not make the table ref++. */
2721 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
2722 MLX5_ASSERT(tbl_data->jump.action);
2723 DRV_LOG(DEBUG, "existed jump table resource %p: refcnt %d++",
2724 (void *)&tbl_data->jump, cnt);
2726 rte_atomic32_inc(&tbl_data->jump.refcnt);
2727 dev_flow->handle->rix_jump = tbl_data->idx;
2728 dev_flow->dv.jump = &tbl_data->jump;
2733 * Find existing default miss resource or create and register a new one.
2735 * @param[in, out] dev
2736 * Pointer to rte_eth_dev structure.
2738 * pointer to error structure.
2741 * 0 on success otherwise -errno and errno is set.
2744 flow_dv_default_miss_resource_register(struct rte_eth_dev *dev,
2745 struct rte_flow_error *error)
2747 struct mlx5_priv *priv = dev->data->dev_private;
2748 struct mlx5_dev_ctx_shared *sh = priv->sh;
2749 struct mlx5_flow_default_miss_resource *cache_resource =
2751 int cnt = rte_atomic32_read(&cache_resource->refcnt);
2754 MLX5_ASSERT(cache_resource->action);
2755 cache_resource->action =
2756 mlx5_glue->dr_create_flow_action_default_miss();
2757 if (!cache_resource->action)
2758 return rte_flow_error_set(error, ENOMEM,
2759 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2760 "cannot create default miss action");
2761 DRV_LOG(DEBUG, "new default miss resource %p: refcnt %d++",
2762 (void *)cache_resource->action, cnt);
2764 rte_atomic32_inc(&cache_resource->refcnt);
2769 * Find existing table port ID resource or create and register a new one.
2771 * @param[in, out] dev
2772 * Pointer to rte_eth_dev structure.
2773 * @param[in, out] resource
2774 * Pointer to port ID action resource.
2775 * @parm[in, out] dev_flow
2776 * Pointer to the dev_flow.
2778 * pointer to error structure.
2781 * 0 on success otherwise -errno and errno is set.
2784 flow_dv_port_id_action_resource_register
2785 (struct rte_eth_dev *dev,
2786 struct mlx5_flow_dv_port_id_action_resource *resource,
2787 struct mlx5_flow *dev_flow,
2788 struct rte_flow_error *error)
2790 struct mlx5_priv *priv = dev->data->dev_private;
2791 struct mlx5_dev_ctx_shared *sh = priv->sh;
2792 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
2796 /* Lookup a matching resource from cache. */
2797 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_PORT_ID], sh->port_id_action_list,
2798 idx, cache_resource, next) {
2799 if (resource->port_id == cache_resource->port_id) {
2800 DRV_LOG(DEBUG, "port id action resource resource %p: "
2802 (void *)cache_resource,
2803 rte_atomic32_read(&cache_resource->refcnt));
2804 rte_atomic32_inc(&cache_resource->refcnt);
2805 dev_flow->handle->rix_port_id_action = idx;
2806 dev_flow->dv.port_id_action = cache_resource;
2810 /* Register new port id action resource. */
2811 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID],
2812 &dev_flow->handle->rix_port_id_action);
2813 if (!cache_resource)
2814 return rte_flow_error_set(error, ENOMEM,
2815 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2816 "cannot allocate resource memory");
2817 *cache_resource = *resource;
2818 ret = mlx5_flow_os_create_flow_action_dest_port
2819 (priv->sh->fdb_domain, resource->port_id,
2820 &cache_resource->action);
2822 mlx5_free(cache_resource);
2823 return rte_flow_error_set(error, ENOMEM,
2824 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2825 NULL, "cannot create action");
2827 rte_atomic32_init(&cache_resource->refcnt);
2828 rte_atomic32_inc(&cache_resource->refcnt);
2829 ILIST_INSERT(sh->ipool[MLX5_IPOOL_PORT_ID], &sh->port_id_action_list,
2830 dev_flow->handle->rix_port_id_action, cache_resource,
2832 dev_flow->dv.port_id_action = cache_resource;
2833 DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++",
2834 (void *)cache_resource,
2835 rte_atomic32_read(&cache_resource->refcnt));
2840 * Find existing push vlan resource or create and register a new one.
2842 * @param [in, out] dev
2843 * Pointer to rte_eth_dev structure.
2844 * @param[in, out] resource
2845 * Pointer to port ID action resource.
2846 * @parm[in, out] dev_flow
2847 * Pointer to the dev_flow.
2849 * pointer to error structure.
2852 * 0 on success otherwise -errno and errno is set.
2855 flow_dv_push_vlan_action_resource_register
2856 (struct rte_eth_dev *dev,
2857 struct mlx5_flow_dv_push_vlan_action_resource *resource,
2858 struct mlx5_flow *dev_flow,
2859 struct rte_flow_error *error)
2861 struct mlx5_priv *priv = dev->data->dev_private;
2862 struct mlx5_dev_ctx_shared *sh = priv->sh;
2863 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
2864 struct mlx5dv_dr_domain *domain;
2868 /* Lookup a matching resource from cache. */
2869 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2870 sh->push_vlan_action_list, idx, cache_resource, next) {
2871 if (resource->vlan_tag == cache_resource->vlan_tag &&
2872 resource->ft_type == cache_resource->ft_type) {
2873 DRV_LOG(DEBUG, "push-VLAN action resource resource %p: "
2875 (void *)cache_resource,
2876 rte_atomic32_read(&cache_resource->refcnt));
2877 rte_atomic32_inc(&cache_resource->refcnt);
2878 dev_flow->handle->dvh.rix_push_vlan = idx;
2879 dev_flow->dv.push_vlan_res = cache_resource;
2883 /* Register new push_vlan action resource. */
2884 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2885 &dev_flow->handle->dvh.rix_push_vlan);
2886 if (!cache_resource)
2887 return rte_flow_error_set(error, ENOMEM,
2888 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2889 "cannot allocate resource memory");
2890 *cache_resource = *resource;
2891 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2892 domain = sh->fdb_domain;
2893 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2894 domain = sh->rx_domain;
2896 domain = sh->tx_domain;
2897 ret = mlx5_flow_os_create_flow_action_push_vlan
2898 (domain, resource->vlan_tag,
2899 &cache_resource->action);
2901 mlx5_free(cache_resource);
2902 return rte_flow_error_set(error, ENOMEM,
2903 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2904 NULL, "cannot create action");
2906 rte_atomic32_init(&cache_resource->refcnt);
2907 rte_atomic32_inc(&cache_resource->refcnt);
2908 ILIST_INSERT(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2909 &sh->push_vlan_action_list,
2910 dev_flow->handle->dvh.rix_push_vlan,
2911 cache_resource, next);
2912 dev_flow->dv.push_vlan_res = cache_resource;
2913 DRV_LOG(DEBUG, "new push vlan action resource %p: refcnt %d++",
2914 (void *)cache_resource,
2915 rte_atomic32_read(&cache_resource->refcnt));
2919 * Get the size of specific rte_flow_item_type hdr size
2921 * @param[in] item_type
2922 * Tested rte_flow_item_type.
2925 * sizeof struct item_type, 0 if void or irrelevant.
2928 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
2932 switch (item_type) {
2933 case RTE_FLOW_ITEM_TYPE_ETH:
2934 retval = sizeof(struct rte_ether_hdr);
2936 case RTE_FLOW_ITEM_TYPE_VLAN:
2937 retval = sizeof(struct rte_vlan_hdr);
2939 case RTE_FLOW_ITEM_TYPE_IPV4:
2940 retval = sizeof(struct rte_ipv4_hdr);
2942 case RTE_FLOW_ITEM_TYPE_IPV6:
2943 retval = sizeof(struct rte_ipv6_hdr);
2945 case RTE_FLOW_ITEM_TYPE_UDP:
2946 retval = sizeof(struct rte_udp_hdr);
2948 case RTE_FLOW_ITEM_TYPE_TCP:
2949 retval = sizeof(struct rte_tcp_hdr);
2951 case RTE_FLOW_ITEM_TYPE_VXLAN:
2952 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2953 retval = sizeof(struct rte_vxlan_hdr);
2955 case RTE_FLOW_ITEM_TYPE_GRE:
2956 case RTE_FLOW_ITEM_TYPE_NVGRE:
2957 retval = sizeof(struct rte_gre_hdr);
2959 case RTE_FLOW_ITEM_TYPE_MPLS:
2960 retval = sizeof(struct rte_mpls_hdr);
2962 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
2970 #define MLX5_ENCAP_IPV4_VERSION 0x40
2971 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
2972 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
2973 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
2974 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
2975 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
2976 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
2979 * Convert the encap action data from list of rte_flow_item to raw buffer
2982 * Pointer to rte_flow_item objects list.
2984 * Pointer to the output buffer.
2986 * Pointer to the output buffer size.
2988 * Pointer to the error structure.
2991 * 0 on success, a negative errno value otherwise and rte_errno is set.
2994 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
2995 size_t *size, struct rte_flow_error *error)
2997 struct rte_ether_hdr *eth = NULL;
2998 struct rte_vlan_hdr *vlan = NULL;
2999 struct rte_ipv4_hdr *ipv4 = NULL;
3000 struct rte_ipv6_hdr *ipv6 = NULL;
3001 struct rte_udp_hdr *udp = NULL;
3002 struct rte_vxlan_hdr *vxlan = NULL;
3003 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
3004 struct rte_gre_hdr *gre = NULL;
3006 size_t temp_size = 0;
3009 return rte_flow_error_set(error, EINVAL,
3010 RTE_FLOW_ERROR_TYPE_ACTION,
3011 NULL, "invalid empty data");
3012 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3013 len = flow_dv_get_item_hdr_len(items->type);
3014 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
3015 return rte_flow_error_set(error, EINVAL,
3016 RTE_FLOW_ERROR_TYPE_ACTION,
3017 (void *)items->type,
3018 "items total size is too big"
3019 " for encap action");
3020 rte_memcpy((void *)&buf[temp_size], items->spec, len);
3021 switch (items->type) {
3022 case RTE_FLOW_ITEM_TYPE_ETH:
3023 eth = (struct rte_ether_hdr *)&buf[temp_size];
3025 case RTE_FLOW_ITEM_TYPE_VLAN:
3026 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
3028 return rte_flow_error_set(error, EINVAL,
3029 RTE_FLOW_ERROR_TYPE_ACTION,
3030 (void *)items->type,
3031 "eth header not found");
3032 if (!eth->ether_type)
3033 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
3035 case RTE_FLOW_ITEM_TYPE_IPV4:
3036 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
3038 return rte_flow_error_set(error, EINVAL,
3039 RTE_FLOW_ERROR_TYPE_ACTION,
3040 (void *)items->type,
3041 "neither eth nor vlan"
3043 if (vlan && !vlan->eth_proto)
3044 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3045 else if (eth && !eth->ether_type)
3046 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3047 if (!ipv4->version_ihl)
3048 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
3049 MLX5_ENCAP_IPV4_IHL_MIN;
3050 if (!ipv4->time_to_live)
3051 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
3053 case RTE_FLOW_ITEM_TYPE_IPV6:
3054 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
3056 return rte_flow_error_set(error, EINVAL,
3057 RTE_FLOW_ERROR_TYPE_ACTION,
3058 (void *)items->type,
3059 "neither eth nor vlan"
3061 if (vlan && !vlan->eth_proto)
3062 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3063 else if (eth && !eth->ether_type)
3064 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3065 if (!ipv6->vtc_flow)
3067 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
3068 if (!ipv6->hop_limits)
3069 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
3071 case RTE_FLOW_ITEM_TYPE_UDP:
3072 udp = (struct rte_udp_hdr *)&buf[temp_size];
3074 return rte_flow_error_set(error, EINVAL,
3075 RTE_FLOW_ERROR_TYPE_ACTION,
3076 (void *)items->type,
3077 "ip header not found");
3078 if (ipv4 && !ipv4->next_proto_id)
3079 ipv4->next_proto_id = IPPROTO_UDP;
3080 else if (ipv6 && !ipv6->proto)
3081 ipv6->proto = IPPROTO_UDP;
3083 case RTE_FLOW_ITEM_TYPE_VXLAN:
3084 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
3086 return rte_flow_error_set(error, EINVAL,
3087 RTE_FLOW_ERROR_TYPE_ACTION,
3088 (void *)items->type,
3089 "udp header not found");
3091 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
3092 if (!vxlan->vx_flags)
3094 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
3096 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3097 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
3099 return rte_flow_error_set(error, EINVAL,
3100 RTE_FLOW_ERROR_TYPE_ACTION,
3101 (void *)items->type,
3102 "udp header not found");
3103 if (!vxlan_gpe->proto)
3104 return rte_flow_error_set(error, EINVAL,
3105 RTE_FLOW_ERROR_TYPE_ACTION,
3106 (void *)items->type,
3107 "next protocol not found");
3110 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
3111 if (!vxlan_gpe->vx_flags)
3112 vxlan_gpe->vx_flags =
3113 MLX5_ENCAP_VXLAN_GPE_FLAGS;
3115 case RTE_FLOW_ITEM_TYPE_GRE:
3116 case RTE_FLOW_ITEM_TYPE_NVGRE:
3117 gre = (struct rte_gre_hdr *)&buf[temp_size];
3119 return rte_flow_error_set(error, EINVAL,
3120 RTE_FLOW_ERROR_TYPE_ACTION,
3121 (void *)items->type,
3122 "next protocol not found");
3124 return rte_flow_error_set(error, EINVAL,
3125 RTE_FLOW_ERROR_TYPE_ACTION,
3126 (void *)items->type,
3127 "ip header not found");
3128 if (ipv4 && !ipv4->next_proto_id)
3129 ipv4->next_proto_id = IPPROTO_GRE;
3130 else if (ipv6 && !ipv6->proto)
3131 ipv6->proto = IPPROTO_GRE;
3133 case RTE_FLOW_ITEM_TYPE_VOID:
3136 return rte_flow_error_set(error, EINVAL,
3137 RTE_FLOW_ERROR_TYPE_ACTION,
3138 (void *)items->type,
3139 "unsupported item type");
3149 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
3151 struct rte_ether_hdr *eth = NULL;
3152 struct rte_vlan_hdr *vlan = NULL;
3153 struct rte_ipv6_hdr *ipv6 = NULL;
3154 struct rte_udp_hdr *udp = NULL;
3158 eth = (struct rte_ether_hdr *)data;
3159 next_hdr = (char *)(eth + 1);
3160 proto = RTE_BE16(eth->ether_type);
3163 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
3164 vlan = (struct rte_vlan_hdr *)next_hdr;
3165 proto = RTE_BE16(vlan->eth_proto);
3166 next_hdr += sizeof(struct rte_vlan_hdr);
3169 /* HW calculates IPv4 csum. no need to proceed */
3170 if (proto == RTE_ETHER_TYPE_IPV4)
3173 /* non IPv4/IPv6 header. not supported */
3174 if (proto != RTE_ETHER_TYPE_IPV6) {
3175 return rte_flow_error_set(error, ENOTSUP,
3176 RTE_FLOW_ERROR_TYPE_ACTION,
3177 NULL, "Cannot offload non IPv4/IPv6");
3180 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
3182 /* ignore non UDP */
3183 if (ipv6->proto != IPPROTO_UDP)
3186 udp = (struct rte_udp_hdr *)(ipv6 + 1);
3187 udp->dgram_cksum = 0;
3193 * Convert L2 encap action to DV specification.
3196 * Pointer to rte_eth_dev structure.
3198 * Pointer to action structure.
3199 * @param[in, out] dev_flow
3200 * Pointer to the mlx5_flow.
3201 * @param[in] transfer
3202 * Mark if the flow is E-Switch flow.
3204 * Pointer to the error structure.
3207 * 0 on success, a negative errno value otherwise and rte_errno is set.
3210 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
3211 const struct rte_flow_action *action,
3212 struct mlx5_flow *dev_flow,
3214 struct rte_flow_error *error)
3216 const struct rte_flow_item *encap_data;
3217 const struct rte_flow_action_raw_encap *raw_encap_data;
3218 struct mlx5_flow_dv_encap_decap_resource res = {
3220 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
3221 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3222 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
3225 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
3227 (const struct rte_flow_action_raw_encap *)action->conf;
3228 res.size = raw_encap_data->size;
3229 memcpy(res.buf, raw_encap_data->data, res.size);
3231 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
3233 ((const struct rte_flow_action_vxlan_encap *)
3234 action->conf)->definition;
3237 ((const struct rte_flow_action_nvgre_encap *)
3238 action->conf)->definition;
3239 if (flow_dv_convert_encap_data(encap_data, res.buf,
3243 if (flow_dv_zero_encap_udp_csum(res.buf, error))
3245 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3246 return rte_flow_error_set(error, EINVAL,
3247 RTE_FLOW_ERROR_TYPE_ACTION,
3248 NULL, "can't create L2 encap action");
3253 * Convert L2 decap action to DV specification.
3256 * Pointer to rte_eth_dev structure.
3257 * @param[in, out] dev_flow
3258 * Pointer to the mlx5_flow.
3259 * @param[in] transfer
3260 * Mark if the flow is E-Switch flow.
3262 * Pointer to the error structure.
3265 * 0 on success, a negative errno value otherwise and rte_errno is set.
3268 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
3269 struct mlx5_flow *dev_flow,
3271 struct rte_flow_error *error)
3273 struct mlx5_flow_dv_encap_decap_resource res = {
3276 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
3277 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3278 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
3281 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3282 return rte_flow_error_set(error, EINVAL,
3283 RTE_FLOW_ERROR_TYPE_ACTION,
3284 NULL, "can't create L2 decap action");
3289 * Convert raw decap/encap (L3 tunnel) action to DV specification.
3292 * Pointer to rte_eth_dev structure.
3294 * Pointer to action structure.
3295 * @param[in, out] dev_flow
3296 * Pointer to the mlx5_flow.
3298 * Pointer to the flow attributes.
3300 * Pointer to the error structure.
3303 * 0 on success, a negative errno value otherwise and rte_errno is set.
3306 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
3307 const struct rte_flow_action *action,
3308 struct mlx5_flow *dev_flow,
3309 const struct rte_flow_attr *attr,
3310 struct rte_flow_error *error)
3312 const struct rte_flow_action_raw_encap *encap_data;
3313 struct mlx5_flow_dv_encap_decap_resource res;
3315 memset(&res, 0, sizeof(res));
3316 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
3317 res.size = encap_data->size;
3318 memcpy(res.buf, encap_data->data, res.size);
3319 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
3320 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
3321 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
3323 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3325 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3326 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3327 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3328 return rte_flow_error_set(error, EINVAL,
3329 RTE_FLOW_ERROR_TYPE_ACTION,
3330 NULL, "can't create encap action");
3335 * Create action push VLAN.
3338 * Pointer to rte_eth_dev structure.
3340 * Pointer to the flow attributes.
3342 * Pointer to the vlan to push to the Ethernet header.
3343 * @param[in, out] dev_flow
3344 * Pointer to the mlx5_flow.
3346 * Pointer to the error structure.
3349 * 0 on success, a negative errno value otherwise and rte_errno is set.
3352 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
3353 const struct rte_flow_attr *attr,
3354 const struct rte_vlan_hdr *vlan,
3355 struct mlx5_flow *dev_flow,
3356 struct rte_flow_error *error)
3358 struct mlx5_flow_dv_push_vlan_action_resource res;
3360 memset(&res, 0, sizeof(res));
3362 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
3365 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3367 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3368 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3369 return flow_dv_push_vlan_action_resource_register
3370 (dev, &res, dev_flow, error);
3374 * Validate the modify-header actions.
3376 * @param[in] action_flags
3377 * Holds the actions detected until now.
3379 * Pointer to the modify action.
3381 * Pointer to error structure.
3384 * 0 on success, a negative errno value otherwise and rte_errno is set.
3387 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
3388 const struct rte_flow_action *action,
3389 struct rte_flow_error *error)
3391 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
3392 return rte_flow_error_set(error, EINVAL,
3393 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3394 NULL, "action configuration not set");
3395 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3396 return rte_flow_error_set(error, EINVAL,
3397 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3398 "can't have encap action before"
3404 * Validate the modify-header MAC address actions.
3406 * @param[in] action_flags
3407 * Holds the actions detected until now.
3409 * Pointer to the modify action.
3410 * @param[in] item_flags
3411 * Holds the items detected.
3413 * Pointer to error structure.
3416 * 0 on success, a negative errno value otherwise and rte_errno is set.
3419 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
3420 const struct rte_flow_action *action,
3421 const uint64_t item_flags,
3422 struct rte_flow_error *error)
3426 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3428 if (!(item_flags & MLX5_FLOW_LAYER_L2))
3429 return rte_flow_error_set(error, EINVAL,
3430 RTE_FLOW_ERROR_TYPE_ACTION,
3432 "no L2 item in pattern");
3438 * Validate the modify-header IPv4 address actions.
3440 * @param[in] action_flags
3441 * Holds the actions detected until now.
3443 * Pointer to the modify action.
3444 * @param[in] item_flags
3445 * Holds the items detected.
3447 * Pointer to error structure.
3450 * 0 on success, a negative errno value otherwise and rte_errno is set.
3453 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
3454 const struct rte_flow_action *action,
3455 const uint64_t item_flags,
3456 struct rte_flow_error *error)
3461 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3463 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3464 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
3465 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3466 if (!(item_flags & layer))
3467 return rte_flow_error_set(error, EINVAL,
3468 RTE_FLOW_ERROR_TYPE_ACTION,
3470 "no ipv4 item in pattern");
3476 * Validate the modify-header IPv6 address actions.
3478 * @param[in] action_flags
3479 * Holds the actions detected until now.
3481 * Pointer to the modify action.
3482 * @param[in] item_flags
3483 * Holds the items detected.
3485 * Pointer to error structure.
3488 * 0 on success, a negative errno value otherwise and rte_errno is set.
3491 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
3492 const struct rte_flow_action *action,
3493 const uint64_t item_flags,
3494 struct rte_flow_error *error)
3499 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3501 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3502 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
3503 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3504 if (!(item_flags & layer))
3505 return rte_flow_error_set(error, EINVAL,
3506 RTE_FLOW_ERROR_TYPE_ACTION,
3508 "no ipv6 item in pattern");
3514 * Validate the modify-header TP actions.
3516 * @param[in] action_flags
3517 * Holds the actions detected until now.
3519 * Pointer to the modify action.
3520 * @param[in] item_flags
3521 * Holds the items detected.
3523 * Pointer to error structure.
3526 * 0 on success, a negative errno value otherwise and rte_errno is set.
3529 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
3530 const struct rte_flow_action *action,
3531 const uint64_t item_flags,
3532 struct rte_flow_error *error)
3537 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3539 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3540 MLX5_FLOW_LAYER_INNER_L4 :
3541 MLX5_FLOW_LAYER_OUTER_L4;
3542 if (!(item_flags & layer))
3543 return rte_flow_error_set(error, EINVAL,
3544 RTE_FLOW_ERROR_TYPE_ACTION,
3545 NULL, "no transport layer "
3552 * Validate the modify-header actions of increment/decrement
3553 * TCP Sequence-number.
3555 * @param[in] action_flags
3556 * Holds the actions detected until now.
3558 * Pointer to the modify action.
3559 * @param[in] item_flags
3560 * Holds the items detected.
3562 * Pointer to error structure.
3565 * 0 on success, a negative errno value otherwise and rte_errno is set.
3568 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
3569 const struct rte_flow_action *action,
3570 const uint64_t item_flags,
3571 struct rte_flow_error *error)
3576 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3578 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3579 MLX5_FLOW_LAYER_INNER_L4_TCP :
3580 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3581 if (!(item_flags & layer))
3582 return rte_flow_error_set(error, EINVAL,
3583 RTE_FLOW_ERROR_TYPE_ACTION,
3584 NULL, "no TCP item in"
3586 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
3587 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
3588 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
3589 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
3590 return rte_flow_error_set(error, EINVAL,
3591 RTE_FLOW_ERROR_TYPE_ACTION,
3593 "cannot decrease and increase"
3594 " TCP sequence number"
3595 " at the same time");
3601 * Validate the modify-header actions of increment/decrement
3602 * TCP Acknowledgment number.
3604 * @param[in] action_flags
3605 * Holds the actions detected until now.
3607 * Pointer to the modify action.
3608 * @param[in] item_flags
3609 * Holds the items detected.
3611 * Pointer to error structure.
3614 * 0 on success, a negative errno value otherwise and rte_errno is set.
3617 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
3618 const struct rte_flow_action *action,
3619 const uint64_t item_flags,
3620 struct rte_flow_error *error)
3625 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3627 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3628 MLX5_FLOW_LAYER_INNER_L4_TCP :
3629 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3630 if (!(item_flags & layer))
3631 return rte_flow_error_set(error, EINVAL,
3632 RTE_FLOW_ERROR_TYPE_ACTION,
3633 NULL, "no TCP item in"
3635 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
3636 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
3637 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
3638 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
3639 return rte_flow_error_set(error, EINVAL,
3640 RTE_FLOW_ERROR_TYPE_ACTION,
3642 "cannot decrease and increase"
3643 " TCP acknowledgment number"
3644 " at the same time");
3650 * Validate the modify-header TTL actions.
3652 * @param[in] action_flags
3653 * Holds the actions detected until now.
3655 * Pointer to the modify action.
3656 * @param[in] item_flags
3657 * Holds the items detected.
3659 * Pointer to error structure.
3662 * 0 on success, a negative errno value otherwise and rte_errno is set.
3665 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
3666 const struct rte_flow_action *action,
3667 const uint64_t item_flags,
3668 struct rte_flow_error *error)
3673 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3675 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3676 MLX5_FLOW_LAYER_INNER_L3 :
3677 MLX5_FLOW_LAYER_OUTER_L3;
3678 if (!(item_flags & layer))
3679 return rte_flow_error_set(error, EINVAL,
3680 RTE_FLOW_ERROR_TYPE_ACTION,
3682 "no IP protocol in pattern");
3688 * Validate jump action.
3691 * Pointer to the jump action.
3692 * @param[in] action_flags
3693 * Holds the actions detected until now.
3694 * @param[in] attributes
3695 * Pointer to flow attributes
3696 * @param[in] external
3697 * Action belongs to flow rule created by request external to PMD.
3699 * Pointer to error structure.
3702 * 0 on success, a negative errno value otherwise and rte_errno is set.
3705 flow_dv_validate_action_jump(const struct rte_flow_action *action,
3706 uint64_t action_flags,
3707 const struct rte_flow_attr *attributes,
3708 bool external, struct rte_flow_error *error)
3710 uint32_t target_group, table;
3713 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3714 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3715 return rte_flow_error_set(error, EINVAL,
3716 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3717 "can't have 2 fate actions in"
3719 if (action_flags & MLX5_FLOW_ACTION_METER)
3720 return rte_flow_error_set(error, ENOTSUP,
3721 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3722 "jump with meter not support");
3724 return rte_flow_error_set(error, EINVAL,
3725 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3726 NULL, "action configuration not set");
3728 ((const struct rte_flow_action_jump *)action->conf)->group;
3729 ret = mlx5_flow_group_to_table(attributes, external, target_group,
3730 true, &table, error);
3733 if (attributes->group == target_group)
3734 return rte_flow_error_set(error, EINVAL,
3735 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3736 "target group must be other than"
3737 " the current flow group");
3742 * Validate the port_id action.
3745 * Pointer to rte_eth_dev structure.
3746 * @param[in] action_flags
3747 * Bit-fields that holds the actions detected until now.
3749 * Port_id RTE action structure.
3751 * Attributes of flow that includes this action.
3753 * Pointer to error structure.
3756 * 0 on success, a negative errno value otherwise and rte_errno is set.
3759 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
3760 uint64_t action_flags,
3761 const struct rte_flow_action *action,
3762 const struct rte_flow_attr *attr,
3763 struct rte_flow_error *error)
3765 const struct rte_flow_action_port_id *port_id;
3766 struct mlx5_priv *act_priv;
3767 struct mlx5_priv *dev_priv;
3770 if (!attr->transfer)
3771 return rte_flow_error_set(error, ENOTSUP,
3772 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3774 "port id action is valid in transfer"
3776 if (!action || !action->conf)
3777 return rte_flow_error_set(error, ENOTSUP,
3778 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3780 "port id action parameters must be"
3782 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3783 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3784 return rte_flow_error_set(error, EINVAL,
3785 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3786 "can have only one fate actions in"
3788 dev_priv = mlx5_dev_to_eswitch_info(dev);
3790 return rte_flow_error_set(error, rte_errno,
3791 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3793 "failed to obtain E-Switch info");
3794 port_id = action->conf;
3795 port = port_id->original ? dev->data->port_id : port_id->id;
3796 act_priv = mlx5_port_to_eswitch_info(port, false);
3798 return rte_flow_error_set
3800 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
3801 "failed to obtain E-Switch port id for port");
3802 if (act_priv->domain_id != dev_priv->domain_id)
3803 return rte_flow_error_set
3805 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3806 "port does not belong to"
3807 " E-Switch being configured");
3812 * Get the maximum number of modify header actions.
3815 * Pointer to rte_eth_dev structure.
3817 * Flags bits to check if root level.
3820 * Max number of modify header actions device can support.
3822 static inline unsigned int
3823 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
3827 * There's no way to directly query the max capacity from FW.
3828 * The maximal value on root table should be assumed to be supported.
3830 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
3831 return MLX5_MAX_MODIFY_NUM;
3833 return MLX5_ROOT_TBL_MODIFY_NUM;
3837 * Validate the meter action.
3840 * Pointer to rte_eth_dev structure.
3841 * @param[in] action_flags
3842 * Bit-fields that holds the actions detected until now.
3844 * Pointer to the meter action.
3846 * Attributes of flow that includes this action.
3848 * Pointer to error structure.
3851 * 0 on success, a negative errno value otherwise and rte_ernno is set.
3854 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
3855 uint64_t action_flags,
3856 const struct rte_flow_action *action,
3857 const struct rte_flow_attr *attr,
3858 struct rte_flow_error *error)
3860 struct mlx5_priv *priv = dev->data->dev_private;
3861 const struct rte_flow_action_meter *am = action->conf;
3862 struct mlx5_flow_meter *fm;
3865 return rte_flow_error_set(error, EINVAL,
3866 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3867 "meter action conf is NULL");
3869 if (action_flags & MLX5_FLOW_ACTION_METER)
3870 return rte_flow_error_set(error, ENOTSUP,
3871 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3872 "meter chaining not support");
3873 if (action_flags & MLX5_FLOW_ACTION_JUMP)
3874 return rte_flow_error_set(error, ENOTSUP,
3875 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3876 "meter with jump not support");
3878 return rte_flow_error_set(error, ENOTSUP,
3879 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3881 "meter action not supported");
3882 fm = mlx5_flow_meter_find(priv, am->mtr_id);
3884 return rte_flow_error_set(error, EINVAL,
3885 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3887 if (fm->ref_cnt && (!(fm->transfer == attr->transfer ||
3888 (!fm->ingress && !attr->ingress && attr->egress) ||
3889 (!fm->egress && !attr->egress && attr->ingress))))
3890 return rte_flow_error_set(error, EINVAL,
3891 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3892 "Flow attributes are either invalid "
3893 "or have a conflict with current "
3894 "meter attributes");
3899 * Validate the age action.
3901 * @param[in] action_flags
3902 * Holds the actions detected until now.
3904 * Pointer to the age action.
3906 * Pointer to the Ethernet device structure.
3908 * Pointer to error structure.
3911 * 0 on success, a negative errno value otherwise and rte_errno is set.
3914 flow_dv_validate_action_age(uint64_t action_flags,
3915 const struct rte_flow_action *action,
3916 struct rte_eth_dev *dev,
3917 struct rte_flow_error *error)
3919 struct mlx5_priv *priv = dev->data->dev_private;
3920 const struct rte_flow_action_age *age = action->conf;
3922 if (!priv->config.devx || priv->counter_fallback)
3923 return rte_flow_error_set(error, ENOTSUP,
3924 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3926 "age action not supported");
3927 if (!(action->conf))
3928 return rte_flow_error_set(error, EINVAL,
3929 RTE_FLOW_ERROR_TYPE_ACTION, action,
3930 "configuration cannot be null");
3931 if (age->timeout >= UINT16_MAX / 2 / 10)
3932 return rte_flow_error_set(error, ENOTSUP,
3933 RTE_FLOW_ERROR_TYPE_ACTION, action,
3934 "Max age time: 3275 seconds");
3935 if (action_flags & MLX5_FLOW_ACTION_AGE)
3936 return rte_flow_error_set(error, EINVAL,
3937 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3938 "Duplicate age ctions set");
3943 * Validate the modify-header IPv4 DSCP actions.
3945 * @param[in] action_flags
3946 * Holds the actions detected until now.
3948 * Pointer to the modify action.
3949 * @param[in] item_flags
3950 * Holds the items detected.
3952 * Pointer to error structure.
3955 * 0 on success, a negative errno value otherwise and rte_errno is set.
3958 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
3959 const struct rte_flow_action *action,
3960 const uint64_t item_flags,
3961 struct rte_flow_error *error)
3965 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3967 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
3968 return rte_flow_error_set(error, EINVAL,
3969 RTE_FLOW_ERROR_TYPE_ACTION,
3971 "no ipv4 item in pattern");
3977 * Validate the modify-header IPv6 DSCP actions.
3979 * @param[in] action_flags
3980 * Holds the actions detected until now.
3982 * Pointer to the modify action.
3983 * @param[in] item_flags
3984 * Holds the items detected.
3986 * Pointer to error structure.
3989 * 0 on success, a negative errno value otherwise and rte_errno is set.
3992 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
3993 const struct rte_flow_action *action,
3994 const uint64_t item_flags,
3995 struct rte_flow_error *error)
3999 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4001 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
4002 return rte_flow_error_set(error, EINVAL,
4003 RTE_FLOW_ERROR_TYPE_ACTION,
4005 "no ipv6 item in pattern");
4011 * Match modify-header resource.
4014 * Pointer to exist resource entry object.
4016 * Pointer to new modify-header resource.
4019 * 0 on matching, -1 otherwise.
4022 flow_dv_modify_hdr_resource_match(struct mlx5_hlist_entry *entry, void *ctx)
4024 struct mlx5_flow_dv_modify_hdr_resource *resource;
4025 struct mlx5_flow_dv_modify_hdr_resource *cache_resource;
4026 uint32_t actions_len;
4028 resource = (struct mlx5_flow_dv_modify_hdr_resource *)ctx;
4029 cache_resource = container_of(entry,
4030 struct mlx5_flow_dv_modify_hdr_resource,
4032 actions_len = resource->actions_num * sizeof(resource->actions[0]);
4033 if (resource->entry.key == cache_resource->entry.key &&
4034 resource->ft_type == cache_resource->ft_type &&
4035 resource->actions_num == cache_resource->actions_num &&
4036 resource->flags == cache_resource->flags &&
4037 !memcmp((const void *)resource->actions,
4038 (const void *)cache_resource->actions,
4045 * Find existing modify-header resource or create and register a new one.
4047 * @param dev[in, out]
4048 * Pointer to rte_eth_dev structure.
4049 * @param[in, out] resource
4050 * Pointer to modify-header resource.
4051 * @parm[in, out] dev_flow
4052 * Pointer to the dev_flow.
4054 * pointer to error structure.
4057 * 0 on success otherwise -errno and errno is set.
4060 flow_dv_modify_hdr_resource_register
4061 (struct rte_eth_dev *dev,
4062 struct mlx5_flow_dv_modify_hdr_resource *resource,
4063 struct mlx5_flow *dev_flow,
4064 struct rte_flow_error *error)
4066 struct mlx5_priv *priv = dev->data->dev_private;
4067 struct mlx5_dev_ctx_shared *sh = priv->sh;
4068 struct mlx5_flow_dv_modify_hdr_resource *cache_resource;
4069 struct mlx5dv_dr_domain *ns;
4070 uint32_t actions_len;
4071 struct mlx5_hlist_entry *entry;
4072 union mlx5_flow_modify_hdr_key hdr_mod_key = {
4074 .ft_type = resource->ft_type,
4075 .actions_num = resource->actions_num,
4076 .group = dev_flow->dv.group,
4082 resource->flags = dev_flow->dv.group ? 0 :
4083 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
4084 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
4086 return rte_flow_error_set(error, EOVERFLOW,
4087 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4088 "too many modify header items");
4089 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4090 ns = sh->fdb_domain;
4091 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
4095 /* Lookup a matching resource from cache. */
4096 actions_len = resource->actions_num * sizeof(resource->actions[0]);
4097 hdr_mod_key.cksum = __rte_raw_cksum(resource->actions, actions_len, 0);
4098 resource->entry.key = hdr_mod_key.v64;
4099 entry = mlx5_hlist_lookup_ex(sh->modify_cmds, resource->entry.key,
4100 flow_dv_modify_hdr_resource_match,
4103 cache_resource = container_of(entry,
4104 struct mlx5_flow_dv_modify_hdr_resource,
4106 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d++",
4107 (void *)cache_resource,
4108 rte_atomic32_read(&cache_resource->refcnt));
4109 rte_atomic32_inc(&cache_resource->refcnt);
4110 dev_flow->handle->dvh.modify_hdr = cache_resource;
4114 /* Register new modify-header resource. */
4115 cache_resource = mlx5_malloc(MLX5_MEM_ZERO,
4116 sizeof(*cache_resource) + actions_len, 0,
4118 if (!cache_resource)
4119 return rte_flow_error_set(error, ENOMEM,
4120 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4121 "cannot allocate resource memory");
4122 *cache_resource = *resource;
4123 rte_memcpy(cache_resource->actions, resource->actions, actions_len);
4124 ret = mlx5_flow_os_create_flow_action_modify_header
4125 (sh->ctx, ns, cache_resource,
4126 actions_len, &cache_resource->action);
4128 mlx5_free(cache_resource);
4129 return rte_flow_error_set(error, ENOMEM,
4130 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4131 NULL, "cannot create action");
4133 rte_atomic32_init(&cache_resource->refcnt);
4134 rte_atomic32_inc(&cache_resource->refcnt);
4135 if (mlx5_hlist_insert_ex(sh->modify_cmds, &cache_resource->entry,
4136 flow_dv_modify_hdr_resource_match,
4137 (void *)cache_resource)) {
4138 claim_zero(mlx5_flow_os_destroy_flow_action
4139 (cache_resource->action));
4140 mlx5_free(cache_resource);
4141 return rte_flow_error_set(error, EEXIST,
4142 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4143 NULL, "action exist");
4145 dev_flow->handle->dvh.modify_hdr = cache_resource;
4146 DRV_LOG(DEBUG, "new modify-header resource %p: refcnt %d++",
4147 (void *)cache_resource,
4148 rte_atomic32_read(&cache_resource->refcnt));
4153 * Get DV flow counter by index.
4156 * Pointer to the Ethernet device structure.
4158 * mlx5 flow counter index in the container.
4160 * mlx5 flow counter pool in the container,
4163 * Pointer to the counter, NULL otherwise.
4165 static struct mlx5_flow_counter *
4166 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
4168 struct mlx5_flow_counter_pool **ppool)
4170 struct mlx5_priv *priv = dev->data->dev_private;
4171 struct mlx5_pools_container *cont;
4172 struct mlx5_flow_counter_pool *pool;
4173 uint32_t batch = 0, age = 0;
4176 age = MLX_CNT_IS_AGE(idx);
4177 idx = age ? idx - MLX5_CNT_AGE_OFFSET : idx;
4178 if (idx >= MLX5_CNT_BATCH_OFFSET) {
4179 idx -= MLX5_CNT_BATCH_OFFSET;
4182 cont = MLX5_CNT_CONTAINER(priv->sh, batch, age);
4183 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cont->n);
4184 pool = cont->pools[idx / MLX5_COUNTERS_PER_POOL];
4188 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
4192 * Check the devx counter belongs to the pool.
4195 * Pointer to the counter pool.
4197 * The counter devx ID.
4200 * True if counter belongs to the pool, false otherwise.
4203 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
4205 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
4206 MLX5_COUNTERS_PER_POOL;
4208 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
4214 * Get a pool by devx counter ID.
4217 * Pointer to the counter container.
4219 * The counter devx ID.
4222 * The counter pool pointer if exists, NULL otherwise,
4224 static struct mlx5_flow_counter_pool *
4225 flow_dv_find_pool_by_id(struct mlx5_pools_container *cont, int id)
4229 /* Check last used pool. */
4230 if (cont->last_pool_idx != POOL_IDX_INVALID &&
4231 flow_dv_is_counter_in_pool(cont->pools[cont->last_pool_idx], id))
4232 return cont->pools[cont->last_pool_idx];
4233 /* ID out of range means no suitable pool in the container. */
4234 if (id > cont->max_id || id < cont->min_id)
4237 * Find the pool from the end of the container, since mostly counter
4238 * ID is sequence increasing, and the last pool should be the needed
4241 i = rte_atomic16_read(&cont->n_valid);
4243 struct mlx5_flow_counter_pool *pool = cont->pools[i];
4245 if (flow_dv_is_counter_in_pool(pool, id))
4252 * Allocate a new memory for the counter values wrapped by all the needed
4256 * Pointer to the Ethernet device structure.
4258 * The raw memory areas - each one for MLX5_COUNTERS_PER_POOL counters.
4261 * The new memory management pointer on success, otherwise NULL and rte_errno
4264 static struct mlx5_counter_stats_mem_mng *
4265 flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
4267 struct mlx5_priv *priv = dev->data->dev_private;
4268 struct mlx5_dev_ctx_shared *sh = priv->sh;
4269 struct mlx5_devx_mkey_attr mkey_attr;
4270 struct mlx5_counter_stats_mem_mng *mem_mng;
4271 volatile struct flow_counter_stats *raw_data;
4272 int size = (sizeof(struct flow_counter_stats) *
4273 MLX5_COUNTERS_PER_POOL +
4274 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
4275 sizeof(struct mlx5_counter_stats_mem_mng);
4276 size_t pgsize = rte_mem_page_size();
4277 if (pgsize == (size_t)-1) {
4278 DRV_LOG(ERR, "Failed to get mem page size");
4282 uint8_t *mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize,
4290 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
4291 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
4292 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
4293 IBV_ACCESS_LOCAL_WRITE);
4294 if (!mem_mng->umem) {
4299 mkey_attr.addr = (uintptr_t)mem;
4300 mkey_attr.size = size;
4301 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
4302 mkey_attr.pd = sh->pdn;
4303 mkey_attr.log_entity_size = 0;
4304 mkey_attr.pg_access = 0;
4305 mkey_attr.klm_array = NULL;
4306 mkey_attr.klm_num = 0;
4307 if (priv->config.hca_attr.relaxed_ordering_write &&
4308 priv->config.hca_attr.relaxed_ordering_read &&
4309 !haswell_broadwell_cpu)
4310 mkey_attr.relaxed_ordering = 1;
4311 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
4313 mlx5_glue->devx_umem_dereg(mem_mng->umem);
4318 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
4319 raw_data = (volatile struct flow_counter_stats *)mem;
4320 for (i = 0; i < raws_n; ++i) {
4321 mem_mng->raws[i].mem_mng = mem_mng;
4322 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
4324 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
4329 * Resize a counter container.
4332 * Pointer to the Ethernet device structure.
4334 * Whether the pool is for counter that was allocated by batch command.
4336 * Whether the pool is for Aging counter.
4339 * 0 on success, otherwise negative errno value and rte_errno is set.
4342 flow_dv_container_resize(struct rte_eth_dev *dev,
4343 uint32_t batch, uint32_t age)
4345 struct mlx5_priv *priv = dev->data->dev_private;
4346 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4348 struct mlx5_counter_stats_mem_mng *mem_mng = NULL;
4349 void *old_pools = cont->pools;
4350 uint32_t resize = cont->n + MLX5_CNT_CONTAINER_RESIZE;
4351 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
4352 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
4359 memcpy(pools, old_pools, cont->n *
4360 sizeof(struct mlx5_flow_counter_pool *));
4362 * Fallback mode query the counter directly, no background query
4363 * resources are needed.
4365 if (!priv->counter_fallback) {
4368 mem_mng = flow_dv_create_counter_stat_mem_mng(dev,
4369 MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES);
4374 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
4375 LIST_INSERT_HEAD(&priv->sh->cmng.free_stat_raws,
4377 MLX5_CNT_CONTAINER_RESIZE +
4380 rte_spinlock_lock(&cont->resize_sl);
4382 cont->mem_mng = mem_mng;
4383 cont->pools = pools;
4384 rte_spinlock_unlock(&cont->resize_sl);
4386 mlx5_free(old_pools);
4391 * Query a devx flow counter.
4394 * Pointer to the Ethernet device structure.
4396 * Index to the flow counter.
4398 * The statistics value of packets.
4400 * The statistics value of bytes.
4403 * 0 on success, otherwise a negative errno value and rte_errno is set.
4406 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
4409 struct mlx5_priv *priv = dev->data->dev_private;
4410 struct mlx5_flow_counter_pool *pool = NULL;
4411 struct mlx5_flow_counter *cnt;
4412 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4415 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
4417 if (counter < MLX5_CNT_BATCH_OFFSET) {
4418 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt);
4419 if (priv->counter_fallback)
4420 return mlx5_devx_cmd_flow_counter_query(cnt_ext->dcs, 0,
4421 0, pkts, bytes, 0, NULL, NULL, 0);
4424 rte_spinlock_lock(&pool->sl);
4426 * The single counters allocation may allocate smaller ID than the
4427 * current allocated in parallel to the host reading.
4428 * In this case the new counter values must be reported as 0.
4430 if (unlikely(cnt_ext && cnt_ext->dcs->id < pool->raw->min_dcs_id)) {
4434 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
4435 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
4436 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
4438 rte_spinlock_unlock(&pool->sl);
4443 * Create and initialize a new counter pool.
4446 * Pointer to the Ethernet device structure.
4448 * The devX counter handle.
4450 * Whether the pool is for counter that was allocated by batch command.
4452 * Whether the pool is for counter that was allocated for aging.
4453 * @param[in/out] cont_cur
4454 * Pointer to the container pointer, it will be update in pool resize.
4457 * The pool container pointer on success, NULL otherwise and rte_errno is set.
4459 static struct mlx5_flow_counter_pool *
4460 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
4461 uint32_t batch, uint32_t age)
4463 struct mlx5_priv *priv = dev->data->dev_private;
4464 struct mlx5_flow_counter_pool *pool;
4465 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4467 int16_t n_valid = rte_atomic16_read(&cont->n_valid);
4468 uint32_t size = sizeof(*pool);
4470 if (cont->n == n_valid && flow_dv_container_resize(dev, batch, age))
4472 size += MLX5_COUNTERS_PER_POOL * CNT_SIZE;
4473 size += (batch ? 0 : MLX5_COUNTERS_PER_POOL * CNTEXT_SIZE);
4474 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * AGE_SIZE);
4475 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
4480 pool->min_dcs = dcs;
4481 if (!priv->counter_fallback)
4482 pool->raw = cont->mem_mng->raws + n_valid %
4483 MLX5_CNT_CONTAINER_RESIZE;
4484 pool->raw_hw = NULL;
4486 pool->type |= (batch ? 0 : CNT_POOL_TYPE_EXT);
4487 pool->type |= (!age ? 0 : CNT_POOL_TYPE_AGE);
4488 pool->query_gen = 0;
4489 rte_spinlock_init(&pool->sl);
4490 TAILQ_INIT(&pool->counters[0]);
4491 TAILQ_INIT(&pool->counters[1]);
4492 TAILQ_INSERT_HEAD(&cont->pool_list, pool, next);
4493 pool->index = n_valid;
4494 cont->pools[n_valid] = pool;
4496 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
4498 if (base < cont->min_id)
4499 cont->min_id = base;
4500 if (base > cont->max_id)
4501 cont->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
4502 cont->last_pool_idx = pool->index;
4504 /* Pool initialization must be updated before host thread access. */
4506 rte_atomic16_add(&cont->n_valid, 1);
4511 * Restore skipped counters in the pool.
4513 * As counter pool query requires the first counter dcs
4514 * ID start with 4 alinged, if the pool counters with
4515 * min_dcs ID are not aligned with 4, the counters will
4517 * Once other min_dcs ID less than these skipped counter
4518 * dcs ID appears, the skipped counters will be safe to
4520 * Should be called when min_dcs is updated.
4523 * Current counter pool.
4524 * @param[in] last_min_dcs
4528 flow_dv_counter_restore(struct mlx5_flow_counter_pool *pool,
4529 struct mlx5_devx_obj *last_min_dcs)
4531 struct mlx5_flow_counter_ext *cnt_ext;
4532 uint32_t offset, new_offset;
4533 uint32_t skip_cnt = 0;
4536 if (!pool->skip_cnt)
4539 * If last min_dcs is not valid. The skipped counter may even after
4540 * last min_dcs, set the offset to the whole pool.
4542 if (last_min_dcs->id & (MLX5_CNT_BATCH_QUERY_ID_ALIGNMENT - 1))
4543 offset = MLX5_COUNTERS_PER_POOL;
4545 offset = last_min_dcs->id % MLX5_COUNTERS_PER_POOL;
4546 new_offset = pool->min_dcs->id % MLX5_COUNTERS_PER_POOL;
4548 * Check the counters from 1 to the last_min_dcs range. Counters
4549 * before new min_dcs indicates pool still has skipped counters.
4550 * Counters be skipped after new min_dcs will be ready to use.
4551 * Offset 0 counter must be empty or min_dcs, start from 1.
4553 for (i = 1; i < offset; i++) {
4554 cnt_ext = MLX5_GET_POOL_CNT_EXT(pool, i);
4555 if (cnt_ext->skipped) {
4556 if (i > new_offset) {
4557 cnt_ext->skipped = 0;
4559 (&pool->counters[pool->query_gen],
4560 MLX5_POOL_GET_CNT(pool, i), next);
4571 * Prepare a new counter and/or a new counter pool.
4574 * Pointer to the Ethernet device structure.
4575 * @param[out] cnt_free
4576 * Where to put the pointer of a new counter.
4578 * Whether the pool is for counter that was allocated by batch command.
4580 * Whether the pool is for counter that was allocated for aging.
4583 * The counter pool pointer and @p cnt_free is set on success,
4584 * NULL otherwise and rte_errno is set.
4586 static struct mlx5_flow_counter_pool *
4587 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
4588 struct mlx5_flow_counter **cnt_free,
4589 uint32_t batch, uint32_t age)
4591 struct mlx5_priv *priv = dev->data->dev_private;
4592 struct mlx5_pools_container *cont;
4593 struct mlx5_flow_counter_pool *pool;
4594 struct mlx5_counters tmp_tq;
4595 struct mlx5_devx_obj *last_min_dcs;
4596 struct mlx5_devx_obj *dcs = NULL;
4597 struct mlx5_flow_counter *cnt;
4601 cont = MLX5_CNT_CONTAINER(priv->sh, batch, age);
4605 /* bulk_bitmap must be 0 for single counter allocation. */
4606 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
4609 pool = flow_dv_find_pool_by_id(cont, dcs->id);
4610 /* Check if counter belongs to exist pool ID range. */
4612 pool = flow_dv_find_pool_by_id
4614 (priv->sh, batch, (age ^ 0x1)), dcs->id);
4616 * Pool eixsts, counter will be added to the other
4617 * container, need to reallocate it later.
4622 pool = flow_dv_pool_create(dev, dcs, batch,
4625 mlx5_devx_cmd_destroy(dcs);
4630 if ((dcs->id < pool->min_dcs->id ||
4632 (MLX5_CNT_BATCH_QUERY_ID_ALIGNMENT - 1)) &&
4633 !(dcs->id & (MLX5_CNT_BATCH_QUERY_ID_ALIGNMENT - 1))) {
4635 * Update the pool min_dcs only if current dcs is
4636 * valid and exist min_dcs is not valid or greater
4639 last_min_dcs = pool->min_dcs;
4640 rte_atomic64_set(&pool->a64_dcs,
4641 (int64_t)(uintptr_t)dcs);
4643 * Restore any skipped counters if the new min_dcs
4644 * ID is smaller or min_dcs is not valid.
4646 if (dcs->id < last_min_dcs->id ||
4648 (MLX5_CNT_BATCH_QUERY_ID_ALIGNMENT - 1))
4649 flow_dv_counter_restore(pool, last_min_dcs);
4651 i = dcs->id % MLX5_COUNTERS_PER_POOL;
4652 cnt = MLX5_POOL_GET_CNT(pool, i);
4654 MLX5_GET_POOL_CNT_EXT(pool, i)->dcs = dcs;
4656 * If min_dcs is not valid, it means the new allocated dcs
4657 * also fail to become the valid min_dcs, just skip it.
4658 * Or if min_dcs is valid, and new dcs ID is smaller than
4659 * min_dcs, but not become the min_dcs, also skip it.
4661 if (pool->min_dcs->id &
4662 (MLX5_CNT_BATCH_QUERY_ID_ALIGNMENT - 1) ||
4663 dcs->id < pool->min_dcs->id) {
4664 MLX5_GET_POOL_CNT_EXT(pool, i)->skipped = 1;
4669 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen],
4676 /* bulk_bitmap is in 128 counters units. */
4677 if (priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4)
4678 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
4680 rte_errno = ENODATA;
4683 pool = flow_dv_pool_create(dev, dcs, batch, age);
4685 mlx5_devx_cmd_destroy(dcs);
4688 TAILQ_INIT(&tmp_tq);
4689 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
4690 cnt = MLX5_POOL_GET_CNT(pool, i);
4692 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
4694 rte_spinlock_lock(&cont->csl);
4695 TAILQ_CONCAT(&cont->counters, &tmp_tq, next);
4696 rte_spinlock_unlock(&cont->csl);
4697 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
4698 (*cnt_free)->pool = pool;
4703 * Search for existed shared counter.
4706 * Pointer to the Ethernet device structure.
4708 * The shared counter ID to search.
4710 * mlx5 flow counter pool in the container,
4713 * NULL if not existed, otherwise pointer to the shared extend counter.
4715 static struct mlx5_flow_counter_ext *
4716 flow_dv_counter_shared_search(struct rte_eth_dev *dev, uint32_t id,
4717 struct mlx5_flow_counter_pool **ppool)
4719 struct mlx5_priv *priv = dev->data->dev_private;
4720 union mlx5_l3t_data data;
4723 if (mlx5_l3t_get_entry(priv->sh->cnt_id_tbl, id, &data) || !data.dword)
4725 cnt_idx = data.dword;
4727 * Shared counters don't have age info. The counter extend is after
4728 * the counter datat structure.
4730 return (struct mlx5_flow_counter_ext *)
4731 ((flow_dv_counter_get_by_idx(dev, cnt_idx, ppool)) + 1);
4735 * Allocate a flow counter.
4738 * Pointer to the Ethernet device structure.
4740 * Indicate if this counter is shared with other flows.
4742 * Counter identifier.
4744 * Counter flow group.
4746 * Whether the counter was allocated for aging.
4749 * Index to flow counter on success, 0 otherwise and rte_errno is set.
4752 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
4753 uint16_t group, uint32_t age)
4755 struct mlx5_priv *priv = dev->data->dev_private;
4756 struct mlx5_flow_counter_pool *pool = NULL;
4757 struct mlx5_flow_counter *cnt_free = NULL;
4758 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4760 * Currently group 0 flow counter cannot be assigned to a flow if it is
4761 * not the first one in the batch counter allocation, so it is better
4762 * to allocate counters one by one for these flows in a separate
4764 * A counter can be shared between different groups so need to take
4765 * shared counters from the single container.
4767 uint32_t batch = (group && !shared && !priv->counter_fallback) ? 1 : 0;
4768 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4772 if (!priv->config.devx) {
4773 rte_errno = ENOTSUP;
4777 cnt_ext = flow_dv_counter_shared_search(dev, id, &pool);
4779 if (cnt_ext->ref_cnt + 1 == 0) {
4784 cnt_idx = pool->index * MLX5_COUNTERS_PER_POOL +
4785 (cnt_ext->dcs->id % MLX5_COUNTERS_PER_POOL)
4790 /* Get free counters from container. */
4791 rte_spinlock_lock(&cont->csl);
4792 cnt_free = TAILQ_FIRST(&cont->counters);
4794 TAILQ_REMOVE(&cont->counters, cnt_free, next);
4795 rte_spinlock_unlock(&cont->csl);
4796 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free,
4799 pool = cnt_free->pool;
4801 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt_free);
4802 /* Create a DV counter action only in the first time usage. */
4803 if (!cnt_free->action) {
4805 struct mlx5_devx_obj *dcs;
4809 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
4810 dcs = pool->min_dcs;
4815 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
4822 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
4823 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
4824 cnt_idx += batch * MLX5_CNT_BATCH_OFFSET;
4825 cnt_idx += age * MLX5_CNT_AGE_OFFSET;
4826 /* Update the counter reset values. */
4827 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
4831 cnt_ext->shared = shared;
4832 cnt_ext->ref_cnt = 1;
4835 union mlx5_l3t_data data;
4837 data.dword = cnt_idx;
4838 if (mlx5_l3t_set_entry(priv->sh->cnt_id_tbl, id, &data))
4842 if (!priv->counter_fallback && !priv->sh->cmng.query_thread_on)
4843 /* Start the asynchronous batch query by the host thread. */
4844 mlx5_set_query_alarm(priv->sh);
4848 cnt_free->pool = pool;
4849 rte_spinlock_lock(&cont->csl);
4850 TAILQ_INSERT_TAIL(&cont->counters, cnt_free, next);
4851 rte_spinlock_unlock(&cont->csl);
4857 * Get age param from counter index.
4860 * Pointer to the Ethernet device structure.
4861 * @param[in] counter
4862 * Index to the counter handler.
4865 * The aging parameter specified for the counter index.
4867 static struct mlx5_age_param*
4868 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
4871 struct mlx5_flow_counter *cnt;
4872 struct mlx5_flow_counter_pool *pool = NULL;
4874 flow_dv_counter_get_by_idx(dev, counter, &pool);
4875 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
4876 cnt = MLX5_POOL_GET_CNT(pool, counter);
4877 return MLX5_CNT_TO_AGE(cnt);
4881 * Remove a flow counter from aged counter list.
4884 * Pointer to the Ethernet device structure.
4885 * @param[in] counter
4886 * Index to the counter handler.
4888 * Pointer to the counter handler.
4891 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
4892 uint32_t counter, struct mlx5_flow_counter *cnt)
4894 struct mlx5_age_info *age_info;
4895 struct mlx5_age_param *age_param;
4896 struct mlx5_priv *priv = dev->data->dev_private;
4898 age_info = GET_PORT_AGE_INFO(priv);
4899 age_param = flow_dv_counter_idx_get_age(dev, counter);
4900 if (rte_atomic16_cmpset((volatile uint16_t *)
4902 AGE_CANDIDATE, AGE_FREE)
4905 * We need the lock even it is age timeout,
4906 * since counter may still in process.
4908 rte_spinlock_lock(&age_info->aged_sl);
4909 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
4910 rte_spinlock_unlock(&age_info->aged_sl);
4912 rte_atomic16_set(&age_param->state, AGE_FREE);
4915 * Release a flow counter.
4918 * Pointer to the Ethernet device structure.
4919 * @param[in] counter
4920 * Index to the counter handler.
4923 flow_dv_counter_release(struct rte_eth_dev *dev, uint32_t counter)
4925 struct mlx5_priv *priv = dev->data->dev_private;
4926 struct mlx5_flow_counter_pool *pool = NULL;
4927 struct mlx5_flow_counter *cnt;
4928 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4932 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
4934 if (counter < MLX5_CNT_BATCH_OFFSET) {
4935 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt);
4937 if (--cnt_ext->ref_cnt)
4939 if (cnt_ext->shared)
4940 mlx5_l3t_clear_entry(priv->sh->cnt_id_tbl,
4944 if (IS_AGE_POOL(pool))
4945 flow_dv_counter_remove_from_age(dev, counter, cnt);
4948 * Put the counter back to list to be updated in none fallback mode.
4949 * Currently, we are using two list alternately, while one is in query,
4950 * add the freed counter to the other list based on the pool query_gen
4951 * value. After query finishes, add counter the list to the global
4952 * container counter list. The list changes while query starts. In
4953 * this case, lock will not be needed as query callback and release
4954 * function both operate with the different list.
4957 if (!priv->counter_fallback)
4958 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
4960 TAILQ_INSERT_TAIL(&((MLX5_CNT_CONTAINER
4961 (priv->sh, 0, 0))->counters),
4966 * Verify the @p attributes will be correctly understood by the NIC and store
4967 * them in the @p flow if everything is correct.
4970 * Pointer to dev struct.
4971 * @param[in] attributes
4972 * Pointer to flow attributes
4973 * @param[in] external
4974 * This flow rule is created by request external to PMD.
4976 * Pointer to error structure.
4979 * - 0 on success and non root table.
4980 * - 1 on success and root table.
4981 * - a negative errno value otherwise and rte_errno is set.
4984 flow_dv_validate_attributes(struct rte_eth_dev *dev,
4985 const struct rte_flow_attr *attributes,
4986 bool external __rte_unused,
4987 struct rte_flow_error *error)
4989 struct mlx5_priv *priv = dev->data->dev_private;
4990 uint32_t priority_max = priv->config.flow_prio - 1;
4993 #ifndef HAVE_MLX5DV_DR
4994 if (attributes->group)
4995 return rte_flow_error_set(error, ENOTSUP,
4996 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
4998 "groups are not supported");
5002 ret = mlx5_flow_group_to_table(attributes, external,
5003 attributes->group, !!priv->fdb_def_rule,
5008 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
5010 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
5011 attributes->priority >= priority_max)
5012 return rte_flow_error_set(error, ENOTSUP,
5013 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
5015 "priority out of range");
5016 if (attributes->transfer) {
5017 if (!priv->config.dv_esw_en)
5018 return rte_flow_error_set
5020 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5021 "E-Switch dr is not supported");
5022 if (!(priv->representor || priv->master))
5023 return rte_flow_error_set
5024 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5025 NULL, "E-Switch configuration can only be"
5026 " done by a master or a representor device");
5027 if (attributes->egress)
5028 return rte_flow_error_set
5030 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
5031 "egress is not supported");
5033 if (!(attributes->egress ^ attributes->ingress))
5034 return rte_flow_error_set(error, ENOTSUP,
5035 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
5036 "must specify exactly one of "
5037 "ingress or egress");
5042 * Internal validation function. For validating both actions and items.
5045 * Pointer to the rte_eth_dev structure.
5047 * Pointer to the flow attributes.
5049 * Pointer to the list of items.
5050 * @param[in] actions
5051 * Pointer to the list of actions.
5052 * @param[in] external
5053 * This flow rule is created by request external to PMD.
5054 * @param[in] hairpin
5055 * Number of hairpin TX actions, 0 means classic flow.
5057 * Pointer to the error structure.
5060 * 0 on success, a negative errno value otherwise and rte_errno is set.
5063 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
5064 const struct rte_flow_item items[],
5065 const struct rte_flow_action actions[],
5066 bool external, int hairpin, struct rte_flow_error *error)
5069 uint64_t action_flags = 0;
5070 uint64_t item_flags = 0;
5071 uint64_t last_item = 0;
5072 uint8_t next_protocol = 0xff;
5073 uint16_t ether_type = 0;
5075 uint8_t item_ipv6_proto = 0;
5076 const struct rte_flow_item *gre_item = NULL;
5077 const struct rte_flow_action_raw_decap *decap;
5078 const struct rte_flow_action_raw_encap *encap;
5079 const struct rte_flow_action_rss *rss;
5080 const struct rte_flow_item_tcp nic_tcp_mask = {
5083 .src_port = RTE_BE16(UINT16_MAX),
5084 .dst_port = RTE_BE16(UINT16_MAX),
5087 const struct rte_flow_item_ipv4 nic_ipv4_mask = {
5089 .src_addr = RTE_BE32(0xffffffff),
5090 .dst_addr = RTE_BE32(0xffffffff),
5091 .type_of_service = 0xff,
5092 .next_proto_id = 0xff,
5093 .time_to_live = 0xff,
5096 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
5099 "\xff\xff\xff\xff\xff\xff\xff\xff"
5100 "\xff\xff\xff\xff\xff\xff\xff\xff",
5102 "\xff\xff\xff\xff\xff\xff\xff\xff"
5103 "\xff\xff\xff\xff\xff\xff\xff\xff",
5104 .vtc_flow = RTE_BE32(0xffffffff),
5109 const struct rte_flow_item_ecpri nic_ecpri_mask = {
5113 RTE_BE32(((const struct rte_ecpri_common_hdr) {
5117 .dummy[0] = 0xffffffff,
5120 struct mlx5_priv *priv = dev->data->dev_private;
5121 struct mlx5_dev_config *dev_conf = &priv->config;
5122 uint16_t queue_index = 0xFFFF;
5123 const struct rte_flow_item_vlan *vlan_m = NULL;
5124 int16_t rw_act_num = 0;
5129 ret = flow_dv_validate_attributes(dev, attr, external, error);
5132 is_root = (uint64_t)ret;
5133 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5134 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
5135 int type = items->type;
5137 if (!mlx5_flow_os_item_supported(type))
5138 return rte_flow_error_set(error, ENOTSUP,
5139 RTE_FLOW_ERROR_TYPE_ITEM,
5140 NULL, "item not supported");
5142 case RTE_FLOW_ITEM_TYPE_VOID:
5144 case RTE_FLOW_ITEM_TYPE_PORT_ID:
5145 ret = flow_dv_validate_item_port_id
5146 (dev, items, attr, item_flags, error);
5149 last_item = MLX5_FLOW_ITEM_PORT_ID;
5151 case RTE_FLOW_ITEM_TYPE_ETH:
5152 ret = mlx5_flow_validate_item_eth(items, item_flags,
5156 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
5157 MLX5_FLOW_LAYER_OUTER_L2;
5158 if (items->mask != NULL && items->spec != NULL) {
5160 ((const struct rte_flow_item_eth *)
5163 ((const struct rte_flow_item_eth *)
5165 ether_type = rte_be_to_cpu_16(ether_type);
5170 case RTE_FLOW_ITEM_TYPE_VLAN:
5171 ret = flow_dv_validate_item_vlan(items, item_flags,
5175 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
5176 MLX5_FLOW_LAYER_OUTER_VLAN;
5177 if (items->mask != NULL && items->spec != NULL) {
5179 ((const struct rte_flow_item_vlan *)
5180 items->spec)->inner_type;
5182 ((const struct rte_flow_item_vlan *)
5183 items->mask)->inner_type;
5184 ether_type = rte_be_to_cpu_16(ether_type);
5188 /* Store outer VLAN mask for of_push_vlan action. */
5190 vlan_m = items->mask;
5192 case RTE_FLOW_ITEM_TYPE_IPV4:
5193 mlx5_flow_tunnel_ip_check(items, next_protocol,
5194 &item_flags, &tunnel);
5195 ret = mlx5_flow_validate_item_ipv4(items, item_flags,
5202 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5203 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5204 if (items->mask != NULL &&
5205 ((const struct rte_flow_item_ipv4 *)
5206 items->mask)->hdr.next_proto_id) {
5208 ((const struct rte_flow_item_ipv4 *)
5209 (items->spec))->hdr.next_proto_id;
5211 ((const struct rte_flow_item_ipv4 *)
5212 (items->mask))->hdr.next_proto_id;
5214 /* Reset for inner layer. */
5215 next_protocol = 0xff;
5218 case RTE_FLOW_ITEM_TYPE_IPV6:
5219 mlx5_flow_tunnel_ip_check(items, next_protocol,
5220 &item_flags, &tunnel);
5221 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
5228 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5229 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5230 if (items->mask != NULL &&
5231 ((const struct rte_flow_item_ipv6 *)
5232 items->mask)->hdr.proto) {
5234 ((const struct rte_flow_item_ipv6 *)
5235 items->spec)->hdr.proto;
5237 ((const struct rte_flow_item_ipv6 *)
5238 items->spec)->hdr.proto;
5240 ((const struct rte_flow_item_ipv6 *)
5241 items->mask)->hdr.proto;
5243 /* Reset for inner layer. */
5244 next_protocol = 0xff;
5247 case RTE_FLOW_ITEM_TYPE_TCP:
5248 ret = mlx5_flow_validate_item_tcp
5255 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
5256 MLX5_FLOW_LAYER_OUTER_L4_TCP;
5258 case RTE_FLOW_ITEM_TYPE_UDP:
5259 ret = mlx5_flow_validate_item_udp(items, item_flags,
5264 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
5265 MLX5_FLOW_LAYER_OUTER_L4_UDP;
5267 case RTE_FLOW_ITEM_TYPE_GRE:
5268 ret = mlx5_flow_validate_item_gre(items, item_flags,
5269 next_protocol, error);
5273 last_item = MLX5_FLOW_LAYER_GRE;
5275 case RTE_FLOW_ITEM_TYPE_NVGRE:
5276 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
5281 last_item = MLX5_FLOW_LAYER_NVGRE;
5283 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
5284 ret = mlx5_flow_validate_item_gre_key
5285 (items, item_flags, gre_item, error);
5288 last_item = MLX5_FLOW_LAYER_GRE_KEY;
5290 case RTE_FLOW_ITEM_TYPE_VXLAN:
5291 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
5295 last_item = MLX5_FLOW_LAYER_VXLAN;
5297 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
5298 ret = mlx5_flow_validate_item_vxlan_gpe(items,
5303 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
5305 case RTE_FLOW_ITEM_TYPE_GENEVE:
5306 ret = mlx5_flow_validate_item_geneve(items,
5311 last_item = MLX5_FLOW_LAYER_GENEVE;
5313 case RTE_FLOW_ITEM_TYPE_MPLS:
5314 ret = mlx5_flow_validate_item_mpls(dev, items,
5319 last_item = MLX5_FLOW_LAYER_MPLS;
5322 case RTE_FLOW_ITEM_TYPE_MARK:
5323 ret = flow_dv_validate_item_mark(dev, items, attr,
5327 last_item = MLX5_FLOW_ITEM_MARK;
5329 case RTE_FLOW_ITEM_TYPE_META:
5330 ret = flow_dv_validate_item_meta(dev, items, attr,
5334 last_item = MLX5_FLOW_ITEM_METADATA;
5336 case RTE_FLOW_ITEM_TYPE_ICMP:
5337 ret = mlx5_flow_validate_item_icmp(items, item_flags,
5342 last_item = MLX5_FLOW_LAYER_ICMP;
5344 case RTE_FLOW_ITEM_TYPE_ICMP6:
5345 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
5350 item_ipv6_proto = IPPROTO_ICMPV6;
5351 last_item = MLX5_FLOW_LAYER_ICMP6;
5353 case RTE_FLOW_ITEM_TYPE_TAG:
5354 ret = flow_dv_validate_item_tag(dev, items,
5358 last_item = MLX5_FLOW_ITEM_TAG;
5360 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
5361 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
5363 case RTE_FLOW_ITEM_TYPE_GTP:
5364 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
5368 last_item = MLX5_FLOW_LAYER_GTP;
5370 case RTE_FLOW_ITEM_TYPE_ECPRI:
5371 /* Capacity will be checked in the translate stage. */
5372 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
5379 last_item = MLX5_FLOW_LAYER_ECPRI;
5382 return rte_flow_error_set(error, ENOTSUP,
5383 RTE_FLOW_ERROR_TYPE_ITEM,
5384 NULL, "item not supported");
5386 item_flags |= last_item;
5388 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5389 int type = actions->type;
5391 if (!mlx5_flow_os_action_supported(type))
5392 return rte_flow_error_set(error, ENOTSUP,
5393 RTE_FLOW_ERROR_TYPE_ACTION,
5395 "action not supported");
5396 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5397 return rte_flow_error_set(error, ENOTSUP,
5398 RTE_FLOW_ERROR_TYPE_ACTION,
5399 actions, "too many actions");
5401 case RTE_FLOW_ACTION_TYPE_VOID:
5403 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5404 ret = flow_dv_validate_action_port_id(dev,
5411 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5414 case RTE_FLOW_ACTION_TYPE_FLAG:
5415 ret = flow_dv_validate_action_flag(dev, action_flags,
5419 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
5420 /* Count all modify-header actions as one. */
5421 if (!(action_flags &
5422 MLX5_FLOW_MODIFY_HDR_ACTIONS))
5424 action_flags |= MLX5_FLOW_ACTION_FLAG |
5425 MLX5_FLOW_ACTION_MARK_EXT;
5427 action_flags |= MLX5_FLOW_ACTION_FLAG;
5430 rw_act_num += MLX5_ACT_NUM_SET_MARK;
5432 case RTE_FLOW_ACTION_TYPE_MARK:
5433 ret = flow_dv_validate_action_mark(dev, actions,
5438 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
5439 /* Count all modify-header actions as one. */
5440 if (!(action_flags &
5441 MLX5_FLOW_MODIFY_HDR_ACTIONS))
5443 action_flags |= MLX5_FLOW_ACTION_MARK |
5444 MLX5_FLOW_ACTION_MARK_EXT;
5446 action_flags |= MLX5_FLOW_ACTION_MARK;
5449 rw_act_num += MLX5_ACT_NUM_SET_MARK;
5451 case RTE_FLOW_ACTION_TYPE_SET_META:
5452 ret = flow_dv_validate_action_set_meta(dev, actions,
5457 /* Count all modify-header actions as one action. */
5458 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5460 action_flags |= MLX5_FLOW_ACTION_SET_META;
5461 rw_act_num += MLX5_ACT_NUM_SET_META;
5463 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5464 ret = flow_dv_validate_action_set_tag(dev, actions,
5469 /* Count all modify-header actions as one action. */
5470 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5472 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
5473 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5475 case RTE_FLOW_ACTION_TYPE_DROP:
5476 ret = mlx5_flow_validate_action_drop(action_flags,
5480 action_flags |= MLX5_FLOW_ACTION_DROP;
5483 case RTE_FLOW_ACTION_TYPE_QUEUE:
5484 ret = mlx5_flow_validate_action_queue(actions,
5489 queue_index = ((const struct rte_flow_action_queue *)
5490 (actions->conf))->index;
5491 action_flags |= MLX5_FLOW_ACTION_QUEUE;
5494 case RTE_FLOW_ACTION_TYPE_RSS:
5495 rss = actions->conf;
5496 ret = mlx5_flow_validate_action_rss(actions,
5502 if (rss != NULL && rss->queue_num)
5503 queue_index = rss->queue[0];
5504 action_flags |= MLX5_FLOW_ACTION_RSS;
5507 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
5509 mlx5_flow_validate_action_default_miss(action_flags,
5513 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
5516 case RTE_FLOW_ACTION_TYPE_COUNT:
5517 ret = flow_dv_validate_action_count(dev, error);
5520 action_flags |= MLX5_FLOW_ACTION_COUNT;
5523 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5524 if (flow_dv_validate_action_pop_vlan(dev,
5530 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
5533 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5534 ret = flow_dv_validate_action_push_vlan(dev,
5541 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
5544 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5545 ret = flow_dv_validate_action_set_vlan_pcp
5546 (action_flags, actions, error);
5549 /* Count PCP with push_vlan command. */
5550 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
5552 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5553 ret = flow_dv_validate_action_set_vlan_vid
5554 (item_flags, action_flags,
5558 /* Count VID with push_vlan command. */
5559 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
5560 rw_act_num += MLX5_ACT_NUM_MDF_VID;
5562 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5563 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5564 ret = flow_dv_validate_action_l2_encap(dev,
5570 action_flags |= MLX5_FLOW_ACTION_ENCAP;
5573 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5574 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5575 ret = flow_dv_validate_action_decap(dev, action_flags,
5579 action_flags |= MLX5_FLOW_ACTION_DECAP;
5582 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5583 ret = flow_dv_validate_action_raw_encap_decap
5584 (dev, NULL, actions->conf, attr, &action_flags,
5589 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5590 decap = actions->conf;
5591 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5593 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5597 encap = actions->conf;
5599 ret = flow_dv_validate_action_raw_encap_decap
5601 decap ? decap : &empty_decap, encap,
5602 attr, &action_flags, &actions_n,
5607 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5608 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5609 ret = flow_dv_validate_action_modify_mac(action_flags,
5615 /* Count all modify-header actions as one action. */
5616 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5618 action_flags |= actions->type ==
5619 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
5620 MLX5_FLOW_ACTION_SET_MAC_SRC :
5621 MLX5_FLOW_ACTION_SET_MAC_DST;
5623 * Even if the source and destination MAC addresses have
5624 * overlap in the header with 4B alignment, the convert
5625 * function will handle them separately and 4 SW actions
5626 * will be created. And 2 actions will be added each
5627 * time no matter how many bytes of address will be set.
5629 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
5631 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5632 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5633 ret = flow_dv_validate_action_modify_ipv4(action_flags,
5639 /* Count all modify-header actions as one action. */
5640 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5642 action_flags |= actions->type ==
5643 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
5644 MLX5_FLOW_ACTION_SET_IPV4_SRC :
5645 MLX5_FLOW_ACTION_SET_IPV4_DST;
5646 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
5648 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5649 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5650 ret = flow_dv_validate_action_modify_ipv6(action_flags,
5656 if (item_ipv6_proto == IPPROTO_ICMPV6)
5657 return rte_flow_error_set(error, ENOTSUP,
5658 RTE_FLOW_ERROR_TYPE_ACTION,
5660 "Can't change header "
5661 "with ICMPv6 proto");
5662 /* Count all modify-header actions as one action. */
5663 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5665 action_flags |= actions->type ==
5666 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
5667 MLX5_FLOW_ACTION_SET_IPV6_SRC :
5668 MLX5_FLOW_ACTION_SET_IPV6_DST;
5669 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
5671 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5672 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5673 ret = flow_dv_validate_action_modify_tp(action_flags,
5679 /* Count all modify-header actions as one action. */
5680 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5682 action_flags |= actions->type ==
5683 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
5684 MLX5_FLOW_ACTION_SET_TP_SRC :
5685 MLX5_FLOW_ACTION_SET_TP_DST;
5686 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
5688 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5689 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5690 ret = flow_dv_validate_action_modify_ttl(action_flags,
5696 /* Count all modify-header actions as one action. */
5697 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5699 action_flags |= actions->type ==
5700 RTE_FLOW_ACTION_TYPE_SET_TTL ?
5701 MLX5_FLOW_ACTION_SET_TTL :
5702 MLX5_FLOW_ACTION_DEC_TTL;
5703 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
5705 case RTE_FLOW_ACTION_TYPE_JUMP:
5706 ret = flow_dv_validate_action_jump(actions,
5713 action_flags |= MLX5_FLOW_ACTION_JUMP;
5715 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5716 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5717 ret = flow_dv_validate_action_modify_tcp_seq
5724 /* Count all modify-header actions as one action. */
5725 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5727 action_flags |= actions->type ==
5728 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
5729 MLX5_FLOW_ACTION_INC_TCP_SEQ :
5730 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
5731 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
5733 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5734 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5735 ret = flow_dv_validate_action_modify_tcp_ack
5742 /* Count all modify-header actions as one action. */
5743 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5745 action_flags |= actions->type ==
5746 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
5747 MLX5_FLOW_ACTION_INC_TCP_ACK :
5748 MLX5_FLOW_ACTION_DEC_TCP_ACK;
5749 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
5751 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
5753 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
5754 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
5755 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5757 case RTE_FLOW_ACTION_TYPE_METER:
5758 ret = mlx5_flow_validate_action_meter(dev,
5764 action_flags |= MLX5_FLOW_ACTION_METER;
5766 /* Meter action will add one more TAG action. */
5767 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5769 case RTE_FLOW_ACTION_TYPE_AGE:
5770 ret = flow_dv_validate_action_age(action_flags,
5775 action_flags |= MLX5_FLOW_ACTION_AGE;
5778 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5779 ret = flow_dv_validate_action_modify_ipv4_dscp
5786 /* Count all modify-header actions as one action. */
5787 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5789 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
5790 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
5792 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5793 ret = flow_dv_validate_action_modify_ipv6_dscp
5800 /* Count all modify-header actions as one action. */
5801 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5803 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
5804 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
5807 return rte_flow_error_set(error, ENOTSUP,
5808 RTE_FLOW_ERROR_TYPE_ACTION,
5810 "action not supported");
5814 * Validate the drop action mutual exclusion with other actions.
5815 * Drop action is mutually-exclusive with any other action, except for
5818 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
5819 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
5820 return rte_flow_error_set(error, EINVAL,
5821 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5822 "Drop action is mutually-exclusive "
5823 "with any other action, except for "
5825 /* Eswitch has few restrictions on using items and actions */
5826 if (attr->transfer) {
5827 if (!mlx5_flow_ext_mreg_supported(dev) &&
5828 action_flags & MLX5_FLOW_ACTION_FLAG)
5829 return rte_flow_error_set(error, ENOTSUP,
5830 RTE_FLOW_ERROR_TYPE_ACTION,
5832 "unsupported action FLAG");
5833 if (!mlx5_flow_ext_mreg_supported(dev) &&
5834 action_flags & MLX5_FLOW_ACTION_MARK)
5835 return rte_flow_error_set(error, ENOTSUP,
5836 RTE_FLOW_ERROR_TYPE_ACTION,
5838 "unsupported action MARK");
5839 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
5840 return rte_flow_error_set(error, ENOTSUP,
5841 RTE_FLOW_ERROR_TYPE_ACTION,
5843 "unsupported action QUEUE");
5844 if (action_flags & MLX5_FLOW_ACTION_RSS)
5845 return rte_flow_error_set(error, ENOTSUP,
5846 RTE_FLOW_ERROR_TYPE_ACTION,
5848 "unsupported action RSS");
5849 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5850 return rte_flow_error_set(error, EINVAL,
5851 RTE_FLOW_ERROR_TYPE_ACTION,
5853 "no fate action is found");
5855 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
5856 return rte_flow_error_set(error, EINVAL,
5857 RTE_FLOW_ERROR_TYPE_ACTION,
5859 "no fate action is found");
5861 /* Continue validation for Xcap and VLAN actions.*/
5862 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
5863 MLX5_FLOW_VLAN_ACTIONS)) &&
5864 (queue_index == 0xFFFF ||
5865 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5866 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5867 MLX5_FLOW_XCAP_ACTIONS)
5868 return rte_flow_error_set(error, ENOTSUP,
5869 RTE_FLOW_ERROR_TYPE_ACTION,
5870 NULL, "encap and decap "
5871 "combination aren't supported");
5872 if (!attr->transfer && attr->ingress) {
5873 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
5874 return rte_flow_error_set
5876 RTE_FLOW_ERROR_TYPE_ACTION,
5877 NULL, "encap is not supported"
5878 " for ingress traffic");
5879 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
5880 return rte_flow_error_set
5882 RTE_FLOW_ERROR_TYPE_ACTION,
5883 NULL, "push VLAN action not "
5884 "supported for ingress");
5885 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
5886 MLX5_FLOW_VLAN_ACTIONS)
5887 return rte_flow_error_set
5889 RTE_FLOW_ERROR_TYPE_ACTION,
5890 NULL, "no support for "
5891 "multiple VLAN actions");
5894 /* Hairpin flow will add one more TAG action. */
5896 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5897 /* extra metadata enabled: one more TAG action will be add. */
5898 if (dev_conf->dv_flow_en &&
5899 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5900 mlx5_flow_ext_mreg_supported(dev))
5901 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5902 if ((uint32_t)rw_act_num >
5903 flow_dv_modify_hdr_action_max(dev, is_root)) {
5904 return rte_flow_error_set(error, ENOTSUP,
5905 RTE_FLOW_ERROR_TYPE_ACTION,
5906 NULL, "too many header modify"
5907 " actions to support");
5913 * Internal preparation function. Allocates the DV flow size,
5914 * this size is constant.
5917 * Pointer to the rte_eth_dev structure.
5919 * Pointer to the flow attributes.
5921 * Pointer to the list of items.
5922 * @param[in] actions
5923 * Pointer to the list of actions.
5925 * Pointer to the error structure.
5928 * Pointer to mlx5_flow object on success,
5929 * otherwise NULL and rte_errno is set.
5931 static struct mlx5_flow *
5932 flow_dv_prepare(struct rte_eth_dev *dev,
5933 const struct rte_flow_attr *attr __rte_unused,
5934 const struct rte_flow_item items[] __rte_unused,
5935 const struct rte_flow_action actions[] __rte_unused,
5936 struct rte_flow_error *error)
5938 uint32_t handle_idx = 0;
5939 struct mlx5_flow *dev_flow;
5940 struct mlx5_flow_handle *dev_handle;
5941 struct mlx5_priv *priv = dev->data->dev_private;
5943 /* In case of corrupting the memory. */
5944 if (priv->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
5945 rte_flow_error_set(error, ENOSPC,
5946 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5947 "not free temporary device flow");
5950 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
5953 rte_flow_error_set(error, ENOMEM,
5954 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5955 "not enough memory to create flow handle");
5958 /* No multi-thread supporting. */
5959 dev_flow = &((struct mlx5_flow *)priv->inter_flows)[priv->flow_idx++];
5960 dev_flow->handle = dev_handle;
5961 dev_flow->handle_idx = handle_idx;
5963 * In some old rdma-core releases, before continuing, a check of the
5964 * length of matching parameter will be done at first. It needs to use
5965 * the length without misc4 param. If the flow has misc4 support, then
5966 * the length needs to be adjusted accordingly. Each param member is
5967 * aligned with a 64B boundary naturally.
5969 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param) -
5970 MLX5_ST_SZ_BYTES(fte_match_set_misc4);
5972 * The matching value needs to be cleared to 0 before using. In the
5973 * past, it will be automatically cleared when using rte_*alloc
5974 * API. The time consumption will be almost the same as before.
5976 memset(dev_flow->dv.value.buf, 0, MLX5_ST_SZ_BYTES(fte_match_param));
5977 dev_flow->ingress = attr->ingress;
5978 dev_flow->dv.transfer = attr->transfer;
5982 #ifdef RTE_LIBRTE_MLX5_DEBUG
5984 * Sanity check for match mask and value. Similar to check_valid_spec() in
5985 * kernel driver. If unmasked bit is present in value, it returns failure.
5988 * pointer to match mask buffer.
5989 * @param match_value
5990 * pointer to match value buffer.
5993 * 0 if valid, -EINVAL otherwise.
5996 flow_dv_check_valid_spec(void *match_mask, void *match_value)
5998 uint8_t *m = match_mask;
5999 uint8_t *v = match_value;
6002 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
6005 "match_value differs from match_criteria"
6006 " %p[%u] != %p[%u]",
6007 match_value, i, match_mask, i);
6016 * Add match of ip_version.
6020 * @param[in] headers_v
6021 * Values header pointer.
6022 * @param[in] headers_m
6023 * Masks header pointer.
6024 * @param[in] ip_version
6025 * The IP version to set.
6028 flow_dv_set_match_ip_version(uint32_t group,
6034 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
6036 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
6038 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
6039 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
6040 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
6044 * Add Ethernet item to matcher and to the value.
6046 * @param[in, out] matcher
6048 * @param[in, out] key
6049 * Flow matcher value.
6051 * Flow pattern to translate.
6053 * Item is inner pattern.
6056 flow_dv_translate_item_eth(void *matcher, void *key,
6057 const struct rte_flow_item *item, int inner,
6060 const struct rte_flow_item_eth *eth_m = item->mask;
6061 const struct rte_flow_item_eth *eth_v = item->spec;
6062 const struct rte_flow_item_eth nic_mask = {
6063 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
6064 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
6065 .type = RTE_BE16(0xffff),
6077 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6079 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6081 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6083 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6085 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, dmac_47_16),
6086 ð_m->dst, sizeof(eth_m->dst));
6087 /* The value must be in the range of the mask. */
6088 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, dmac_47_16);
6089 for (i = 0; i < sizeof(eth_m->dst); ++i)
6090 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
6091 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, smac_47_16),
6092 ð_m->src, sizeof(eth_m->src));
6093 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, smac_47_16);
6094 /* The value must be in the range of the mask. */
6095 for (i = 0; i < sizeof(eth_m->dst); ++i)
6096 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
6098 /* When ethertype is present set mask for tagged VLAN. */
6099 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
6100 /* Set value for tagged VLAN if ethertype is 802.1Q. */
6101 if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_VLAN) ||
6102 eth_v->type == RTE_BE16(RTE_ETHER_TYPE_QINQ)) {
6103 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag,
6105 /* Return here to avoid setting match on ethertype. */
6110 * HW supports match on one Ethertype, the Ethertype following the last
6111 * VLAN tag of the packet (see PRM).
6112 * Set match on ethertype only if ETH header is not followed by VLAN.
6113 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
6114 * ethertype, and use ip_version field instead.
6115 * eCPRI over Ether layer will use type value 0xAEFE.
6117 if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_IPV4) &&
6118 eth_m->type == 0xFFFF) {
6119 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
6120 } else if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_IPV6) &&
6121 eth_m->type == 0xFFFF) {
6122 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
6124 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
6125 rte_be_to_cpu_16(eth_m->type));
6126 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6128 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
6133 * Add VLAN item to matcher and to the value.
6135 * @param[in, out] dev_flow
6137 * @param[in, out] matcher
6139 * @param[in, out] key
6140 * Flow matcher value.
6142 * Flow pattern to translate.
6144 * Item is inner pattern.
6147 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
6148 void *matcher, void *key,
6149 const struct rte_flow_item *item,
6150 int inner, uint32_t group)
6152 const struct rte_flow_item_vlan *vlan_m = item->mask;
6153 const struct rte_flow_item_vlan *vlan_v = item->spec;
6160 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6162 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6164 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6166 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6168 * This is workaround, masks are not supported,
6169 * and pre-validated.
6172 dev_flow->handle->vf_vlan.tag =
6173 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
6176 * When VLAN item exists in flow, mark packet as tagged,
6177 * even if TCI is not specified.
6179 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
6180 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
6184 vlan_m = &rte_flow_item_vlan_mask;
6185 tci_m = rte_be_to_cpu_16(vlan_m->tci);
6186 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
6187 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_vid, tci_m);
6188 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, tci_v);
6189 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_cfi, tci_m >> 12);
6190 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_cfi, tci_v >> 12);
6191 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_prio, tci_m >> 13);
6192 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, tci_v >> 13);
6194 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
6195 * ethertype, and use ip_version field instead.
6197 if (vlan_v->inner_type == RTE_BE16(RTE_ETHER_TYPE_IPV4) &&
6198 vlan_m->inner_type == 0xFFFF) {
6199 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
6200 } else if (vlan_v->inner_type == RTE_BE16(RTE_ETHER_TYPE_IPV6) &&
6201 vlan_m->inner_type == 0xFFFF) {
6202 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
6204 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
6205 rte_be_to_cpu_16(vlan_m->inner_type));
6206 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
6207 rte_be_to_cpu_16(vlan_m->inner_type &
6208 vlan_v->inner_type));
6213 * Add IPV4 item to matcher and to the value.
6215 * @param[in, out] matcher
6217 * @param[in, out] key
6218 * Flow matcher value.
6220 * Flow pattern to translate.
6221 * @param[in] item_flags
6222 * Bit-fields that holds the items detected until now.
6224 * Item is inner pattern.
6226 * The group to insert the rule.
6229 flow_dv_translate_item_ipv4(void *matcher, void *key,
6230 const struct rte_flow_item *item,
6231 const uint64_t item_flags,
6232 int inner, uint32_t group)
6234 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
6235 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
6236 const struct rte_flow_item_ipv4 nic_mask = {
6238 .src_addr = RTE_BE32(0xffffffff),
6239 .dst_addr = RTE_BE32(0xffffffff),
6240 .type_of_service = 0xff,
6241 .next_proto_id = 0xff,
6242 .time_to_live = 0xff,
6252 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6254 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6256 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6258 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6260 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
6262 * On outer header (which must contains L2), or inner header with L2,
6263 * set cvlan_tag mask bit to mark this packet as untagged.
6264 * This should be done even if item->spec is empty.
6266 if (!inner || item_flags & MLX5_FLOW_LAYER_INNER_L2)
6267 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
6272 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6273 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
6274 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6275 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
6276 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
6277 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
6278 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6279 src_ipv4_src_ipv6.ipv4_layout.ipv4);
6280 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6281 src_ipv4_src_ipv6.ipv4_layout.ipv4);
6282 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
6283 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
6284 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
6285 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
6286 ipv4_m->hdr.type_of_service);
6287 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
6288 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
6289 ipv4_m->hdr.type_of_service >> 2);
6290 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
6291 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
6292 ipv4_m->hdr.next_proto_id);
6293 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6294 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
6295 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
6296 ipv4_m->hdr.time_to_live);
6297 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
6298 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
6302 * Add IPV6 item to matcher and to the value.
6304 * @param[in, out] matcher
6306 * @param[in, out] key
6307 * Flow matcher value.
6309 * Flow pattern to translate.
6310 * @param[in] item_flags
6311 * Bit-fields that holds the items detected until now.
6313 * Item is inner pattern.
6315 * The group to insert the rule.
6318 flow_dv_translate_item_ipv6(void *matcher, void *key,
6319 const struct rte_flow_item *item,
6320 const uint64_t item_flags,
6321 int inner, uint32_t group)
6323 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
6324 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
6325 const struct rte_flow_item_ipv6 nic_mask = {
6328 "\xff\xff\xff\xff\xff\xff\xff\xff"
6329 "\xff\xff\xff\xff\xff\xff\xff\xff",
6331 "\xff\xff\xff\xff\xff\xff\xff\xff"
6332 "\xff\xff\xff\xff\xff\xff\xff\xff",
6333 .vtc_flow = RTE_BE32(0xffffffff),
6340 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6341 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6350 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6352 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6354 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6356 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6358 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
6360 * On outer header (which must contains L2), or inner header with L2,
6361 * set cvlan_tag mask bit to mark this packet as untagged.
6362 * This should be done even if item->spec is empty.
6364 if (!inner || item_flags & MLX5_FLOW_LAYER_INNER_L2)
6365 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
6370 size = sizeof(ipv6_m->hdr.dst_addr);
6371 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6372 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
6373 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6374 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
6375 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
6376 for (i = 0; i < size; ++i)
6377 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
6378 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6379 src_ipv4_src_ipv6.ipv6_layout.ipv6);
6380 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6381 src_ipv4_src_ipv6.ipv6_layout.ipv6);
6382 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
6383 for (i = 0; i < size; ++i)
6384 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
6386 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
6387 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
6388 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
6389 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
6390 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
6391 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
6394 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
6396 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
6399 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
6401 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
6405 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
6407 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6408 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
6410 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
6411 ipv6_m->hdr.hop_limits);
6412 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
6413 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
6417 * Add TCP item to matcher and to the value.
6419 * @param[in, out] matcher
6421 * @param[in, out] key
6422 * Flow matcher value.
6424 * Flow pattern to translate.
6426 * Item is inner pattern.
6429 flow_dv_translate_item_tcp(void *matcher, void *key,
6430 const struct rte_flow_item *item,
6433 const struct rte_flow_item_tcp *tcp_m = item->mask;
6434 const struct rte_flow_item_tcp *tcp_v = item->spec;
6439 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6441 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6443 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6445 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6447 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6448 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
6452 tcp_m = &rte_flow_item_tcp_mask;
6453 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
6454 rte_be_to_cpu_16(tcp_m->hdr.src_port));
6455 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
6456 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
6457 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
6458 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
6459 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
6460 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
6461 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
6462 tcp_m->hdr.tcp_flags);
6463 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
6464 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
6468 * Add UDP item to matcher and to the value.
6470 * @param[in, out] matcher
6472 * @param[in, out] key
6473 * Flow matcher value.
6475 * Flow pattern to translate.
6477 * Item is inner pattern.
6480 flow_dv_translate_item_udp(void *matcher, void *key,
6481 const struct rte_flow_item *item,
6484 const struct rte_flow_item_udp *udp_m = item->mask;
6485 const struct rte_flow_item_udp *udp_v = item->spec;
6490 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6492 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6494 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6496 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6498 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6499 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
6503 udp_m = &rte_flow_item_udp_mask;
6504 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
6505 rte_be_to_cpu_16(udp_m->hdr.src_port));
6506 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
6507 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
6508 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
6509 rte_be_to_cpu_16(udp_m->hdr.dst_port));
6510 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
6511 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
6515 * Add GRE optional Key item to matcher and to the value.
6517 * @param[in, out] matcher
6519 * @param[in, out] key
6520 * Flow matcher value.
6522 * Flow pattern to translate.
6524 * Item is inner pattern.
6527 flow_dv_translate_item_gre_key(void *matcher, void *key,
6528 const struct rte_flow_item *item)
6530 const rte_be32_t *key_m = item->mask;
6531 const rte_be32_t *key_v = item->spec;
6532 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6533 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6534 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6536 /* GRE K bit must be on and should already be validated */
6537 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
6538 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
6542 key_m = &gre_key_default_mask;
6543 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
6544 rte_be_to_cpu_32(*key_m) >> 8);
6545 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
6546 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
6547 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
6548 rte_be_to_cpu_32(*key_m) & 0xFF);
6549 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
6550 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
6554 * Add GRE item to matcher and to the value.
6556 * @param[in, out] matcher
6558 * @param[in, out] key
6559 * Flow matcher value.
6561 * Flow pattern to translate.
6563 * Item is inner pattern.
6566 flow_dv_translate_item_gre(void *matcher, void *key,
6567 const struct rte_flow_item *item,
6570 const struct rte_flow_item_gre *gre_m = item->mask;
6571 const struct rte_flow_item_gre *gre_v = item->spec;
6574 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6575 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6582 uint16_t s_present:1;
6583 uint16_t k_present:1;
6584 uint16_t rsvd_bit1:1;
6585 uint16_t c_present:1;
6589 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
6592 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6594 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6596 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6598 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6600 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6601 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
6605 gre_m = &rte_flow_item_gre_mask;
6606 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
6607 rte_be_to_cpu_16(gre_m->protocol));
6608 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
6609 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
6610 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
6611 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
6612 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
6613 gre_crks_rsvd0_ver_m.c_present);
6614 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
6615 gre_crks_rsvd0_ver_v.c_present &
6616 gre_crks_rsvd0_ver_m.c_present);
6617 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
6618 gre_crks_rsvd0_ver_m.k_present);
6619 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
6620 gre_crks_rsvd0_ver_v.k_present &
6621 gre_crks_rsvd0_ver_m.k_present);
6622 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
6623 gre_crks_rsvd0_ver_m.s_present);
6624 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
6625 gre_crks_rsvd0_ver_v.s_present &
6626 gre_crks_rsvd0_ver_m.s_present);
6630 * Add NVGRE item to matcher and to the value.
6632 * @param[in, out] matcher
6634 * @param[in, out] key
6635 * Flow matcher value.
6637 * Flow pattern to translate.
6639 * Item is inner pattern.
6642 flow_dv_translate_item_nvgre(void *matcher, void *key,
6643 const struct rte_flow_item *item,
6646 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
6647 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
6648 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6649 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6650 const char *tni_flow_id_m;
6651 const char *tni_flow_id_v;
6657 /* For NVGRE, GRE header fields must be set with defined values. */
6658 const struct rte_flow_item_gre gre_spec = {
6659 .c_rsvd0_ver = RTE_BE16(0x2000),
6660 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
6662 const struct rte_flow_item_gre gre_mask = {
6663 .c_rsvd0_ver = RTE_BE16(0xB000),
6664 .protocol = RTE_BE16(UINT16_MAX),
6666 const struct rte_flow_item gre_item = {
6671 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
6675 nvgre_m = &rte_flow_item_nvgre_mask;
6676 tni_flow_id_m = (const char *)nvgre_m->tni;
6677 tni_flow_id_v = (const char *)nvgre_v->tni;
6678 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
6679 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
6680 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
6681 memcpy(gre_key_m, tni_flow_id_m, size);
6682 for (i = 0; i < size; ++i)
6683 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
6687 * Add VXLAN item to matcher and to the value.
6689 * @param[in, out] matcher
6691 * @param[in, out] key
6692 * Flow matcher value.
6694 * Flow pattern to translate.
6696 * Item is inner pattern.
6699 flow_dv_translate_item_vxlan(void *matcher, void *key,
6700 const struct rte_flow_item *item,
6703 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
6704 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
6707 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6708 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6716 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6718 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6720 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6722 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6724 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
6725 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
6726 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6727 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6728 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6733 vxlan_m = &rte_flow_item_vxlan_mask;
6734 size = sizeof(vxlan_m->vni);
6735 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
6736 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
6737 memcpy(vni_m, vxlan_m->vni, size);
6738 for (i = 0; i < size; ++i)
6739 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
6743 * Add VXLAN-GPE item to matcher and to the value.
6745 * @param[in, out] matcher
6747 * @param[in, out] key
6748 * Flow matcher value.
6750 * Flow pattern to translate.
6752 * Item is inner pattern.
6756 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
6757 const struct rte_flow_item *item, int inner)
6759 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
6760 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
6764 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
6766 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6772 uint8_t flags_m = 0xff;
6773 uint8_t flags_v = 0xc;
6776 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6778 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6780 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6782 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6784 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
6785 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
6786 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6787 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6788 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6793 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
6794 size = sizeof(vxlan_m->vni);
6795 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
6796 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
6797 memcpy(vni_m, vxlan_m->vni, size);
6798 for (i = 0; i < size; ++i)
6799 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
6800 if (vxlan_m->flags) {
6801 flags_m = vxlan_m->flags;
6802 flags_v = vxlan_v->flags;
6804 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
6805 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
6806 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
6808 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
6813 * Add Geneve item to matcher and to the value.
6815 * @param[in, out] matcher
6817 * @param[in, out] key
6818 * Flow matcher value.
6820 * Flow pattern to translate.
6822 * Item is inner pattern.
6826 flow_dv_translate_item_geneve(void *matcher, void *key,
6827 const struct rte_flow_item *item, int inner)
6829 const struct rte_flow_item_geneve *geneve_m = item->mask;
6830 const struct rte_flow_item_geneve *geneve_v = item->spec;
6833 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6834 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6843 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6845 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6847 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6849 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6851 dport = MLX5_UDP_PORT_GENEVE;
6852 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6853 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6854 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6859 geneve_m = &rte_flow_item_geneve_mask;
6860 size = sizeof(geneve_m->vni);
6861 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
6862 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
6863 memcpy(vni_m, geneve_m->vni, size);
6864 for (i = 0; i < size; ++i)
6865 vni_v[i] = vni_m[i] & geneve_v->vni[i];
6866 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
6867 rte_be_to_cpu_16(geneve_m->protocol));
6868 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
6869 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
6870 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
6871 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
6872 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
6873 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
6874 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
6875 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
6876 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
6877 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
6878 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
6879 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
6880 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
6884 * Add MPLS item to matcher and to the value.
6886 * @param[in, out] matcher
6888 * @param[in, out] key
6889 * Flow matcher value.
6891 * Flow pattern to translate.
6892 * @param[in] prev_layer
6893 * The protocol layer indicated in previous item.
6895 * Item is inner pattern.
6898 flow_dv_translate_item_mpls(void *matcher, void *key,
6899 const struct rte_flow_item *item,
6900 uint64_t prev_layer,
6903 const uint32_t *in_mpls_m = item->mask;
6904 const uint32_t *in_mpls_v = item->spec;
6905 uint32_t *out_mpls_m = 0;
6906 uint32_t *out_mpls_v = 0;
6907 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6908 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6909 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
6911 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
6912 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
6913 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6915 switch (prev_layer) {
6916 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
6917 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
6918 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
6919 MLX5_UDP_PORT_MPLS);
6921 case MLX5_FLOW_LAYER_GRE:
6922 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
6923 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
6924 RTE_ETHER_TYPE_MPLS);
6927 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6928 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6935 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
6936 switch (prev_layer) {
6937 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
6939 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
6940 outer_first_mpls_over_udp);
6942 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
6943 outer_first_mpls_over_udp);
6945 case MLX5_FLOW_LAYER_GRE:
6947 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
6948 outer_first_mpls_over_gre);
6950 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
6951 outer_first_mpls_over_gre);
6954 /* Inner MPLS not over GRE is not supported. */
6957 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
6961 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
6967 if (out_mpls_m && out_mpls_v) {
6968 *out_mpls_m = *in_mpls_m;
6969 *out_mpls_v = *in_mpls_v & *in_mpls_m;
6974 * Add metadata register item to matcher
6976 * @param[in, out] matcher
6978 * @param[in, out] key
6979 * Flow matcher value.
6980 * @param[in] reg_type
6981 * Type of device metadata register
6988 flow_dv_match_meta_reg(void *matcher, void *key,
6989 enum modify_reg reg_type,
6990 uint32_t data, uint32_t mask)
6993 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
6995 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
7001 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
7002 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
7005 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
7006 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
7010 * The metadata register C0 field might be divided into
7011 * source vport index and META item value, we should set
7012 * this field according to specified mask, not as whole one.
7014 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
7016 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
7017 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
7020 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
7023 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
7024 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
7027 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
7028 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
7031 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
7032 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
7035 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
7036 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
7039 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
7040 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
7043 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
7044 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
7047 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
7048 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
7057 * Add MARK item to matcher
7060 * The device to configure through.
7061 * @param[in, out] matcher
7063 * @param[in, out] key
7064 * Flow matcher value.
7066 * Flow pattern to translate.
7069 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
7070 void *matcher, void *key,
7071 const struct rte_flow_item *item)
7073 struct mlx5_priv *priv = dev->data->dev_private;
7074 const struct rte_flow_item_mark *mark;
7078 mark = item->mask ? (const void *)item->mask :
7079 &rte_flow_item_mark_mask;
7080 mask = mark->id & priv->sh->dv_mark_mask;
7081 mark = (const void *)item->spec;
7083 value = mark->id & priv->sh->dv_mark_mask & mask;
7085 enum modify_reg reg;
7087 /* Get the metadata register index for the mark. */
7088 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
7089 MLX5_ASSERT(reg > 0);
7090 if (reg == REG_C_0) {
7091 struct mlx5_priv *priv = dev->data->dev_private;
7092 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
7093 uint32_t shl_c0 = rte_bsf32(msk_c0);
7099 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
7104 * Add META item to matcher
7107 * The devich to configure through.
7108 * @param[in, out] matcher
7110 * @param[in, out] key
7111 * Flow matcher value.
7113 * Attributes of flow that includes this item.
7115 * Flow pattern to translate.
7118 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
7119 void *matcher, void *key,
7120 const struct rte_flow_attr *attr,
7121 const struct rte_flow_item *item)
7123 const struct rte_flow_item_meta *meta_m;
7124 const struct rte_flow_item_meta *meta_v;
7126 meta_m = (const void *)item->mask;
7128 meta_m = &rte_flow_item_meta_mask;
7129 meta_v = (const void *)item->spec;
7132 uint32_t value = meta_v->data;
7133 uint32_t mask = meta_m->data;
7135 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
7139 * In datapath code there is no endianness
7140 * coversions for perfromance reasons, all
7141 * pattern conversions are done in rte_flow.
7143 value = rte_cpu_to_be_32(value);
7144 mask = rte_cpu_to_be_32(mask);
7145 if (reg == REG_C_0) {
7146 struct mlx5_priv *priv = dev->data->dev_private;
7147 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
7148 uint32_t shl_c0 = rte_bsf32(msk_c0);
7149 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
7150 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
7157 MLX5_ASSERT(msk_c0);
7158 MLX5_ASSERT(!(~msk_c0 & mask));
7160 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
7165 * Add vport metadata Reg C0 item to matcher
7167 * @param[in, out] matcher
7169 * @param[in, out] key
7170 * Flow matcher value.
7172 * Flow pattern to translate.
7175 flow_dv_translate_item_meta_vport(void *matcher, void *key,
7176 uint32_t value, uint32_t mask)
7178 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
7182 * Add tag item to matcher
7185 * The devich to configure through.
7186 * @param[in, out] matcher
7188 * @param[in, out] key
7189 * Flow matcher value.
7191 * Flow pattern to translate.
7194 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
7195 void *matcher, void *key,
7196 const struct rte_flow_item *item)
7198 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
7199 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
7200 uint32_t mask, value;
7203 value = tag_v->data;
7204 mask = tag_m ? tag_m->data : UINT32_MAX;
7205 if (tag_v->id == REG_C_0) {
7206 struct mlx5_priv *priv = dev->data->dev_private;
7207 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
7208 uint32_t shl_c0 = rte_bsf32(msk_c0);
7214 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
7218 * Add TAG item to matcher
7221 * The devich to configure through.
7222 * @param[in, out] matcher
7224 * @param[in, out] key
7225 * Flow matcher value.
7227 * Flow pattern to translate.
7230 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
7231 void *matcher, void *key,
7232 const struct rte_flow_item *item)
7234 const struct rte_flow_item_tag *tag_v = item->spec;
7235 const struct rte_flow_item_tag *tag_m = item->mask;
7236 enum modify_reg reg;
7239 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
7240 /* Get the metadata register index for the tag. */
7241 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
7242 MLX5_ASSERT(reg > 0);
7243 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
7247 * Add source vport match to the specified matcher.
7249 * @param[in, out] matcher
7251 * @param[in, out] key
7252 * Flow matcher value.
7254 * Source vport value to match
7259 flow_dv_translate_item_source_vport(void *matcher, void *key,
7260 int16_t port, uint16_t mask)
7262 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7263 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7265 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
7266 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
7270 * Translate port-id item to eswitch match on port-id.
7273 * The devich to configure through.
7274 * @param[in, out] matcher
7276 * @param[in, out] key
7277 * Flow matcher value.
7279 * Flow pattern to translate.
7282 * 0 on success, a negative errno value otherwise.
7285 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
7286 void *key, const struct rte_flow_item *item)
7288 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
7289 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
7290 struct mlx5_priv *priv;
7293 mask = pid_m ? pid_m->id : 0xffff;
7294 id = pid_v ? pid_v->id : dev->data->port_id;
7295 priv = mlx5_port_to_eswitch_info(id, item == NULL);
7298 /* Translate to vport field or to metadata, depending on mode. */
7299 if (priv->vport_meta_mask)
7300 flow_dv_translate_item_meta_vport(matcher, key,
7301 priv->vport_meta_tag,
7302 priv->vport_meta_mask);
7304 flow_dv_translate_item_source_vport(matcher, key,
7305 priv->vport_id, mask);
7310 * Add ICMP6 item to matcher and to the value.
7312 * @param[in, out] matcher
7314 * @param[in, out] key
7315 * Flow matcher value.
7317 * Flow pattern to translate.
7319 * Item is inner pattern.
7322 flow_dv_translate_item_icmp6(void *matcher, void *key,
7323 const struct rte_flow_item *item,
7326 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
7327 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
7330 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7332 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7334 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7336 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7338 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7340 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7342 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
7343 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
7347 icmp6_m = &rte_flow_item_icmp6_mask;
7349 * Force flow only to match the non-fragmented IPv6 ICMPv6 packets.
7350 * If only the protocol is specified, no need to match the frag.
7352 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
7353 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
7354 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
7355 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
7356 icmp6_v->type & icmp6_m->type);
7357 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
7358 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
7359 icmp6_v->code & icmp6_m->code);
7363 * Add ICMP item to matcher and to the value.
7365 * @param[in, out] matcher
7367 * @param[in, out] key
7368 * Flow matcher value.
7370 * Flow pattern to translate.
7372 * Item is inner pattern.
7375 flow_dv_translate_item_icmp(void *matcher, void *key,
7376 const struct rte_flow_item *item,
7379 const struct rte_flow_item_icmp *icmp_m = item->mask;
7380 const struct rte_flow_item_icmp *icmp_v = item->spec;
7383 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7385 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7387 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7389 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7391 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7393 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7395 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
7396 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
7400 icmp_m = &rte_flow_item_icmp_mask;
7402 * Force flow only to match the non-fragmented IPv4 ICMP packets.
7403 * If only the protocol is specified, no need to match the frag.
7405 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
7406 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
7407 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
7408 icmp_m->hdr.icmp_type);
7409 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
7410 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
7411 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
7412 icmp_m->hdr.icmp_code);
7413 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
7414 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
7418 * Add GTP item to matcher and to the value.
7420 * @param[in, out] matcher
7422 * @param[in, out] key
7423 * Flow matcher value.
7425 * Flow pattern to translate.
7427 * Item is inner pattern.
7430 flow_dv_translate_item_gtp(void *matcher, void *key,
7431 const struct rte_flow_item *item, int inner)
7433 const struct rte_flow_item_gtp *gtp_m = item->mask;
7434 const struct rte_flow_item_gtp *gtp_v = item->spec;
7437 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7439 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7440 uint16_t dport = RTE_GTPU_UDP_PORT;
7443 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7445 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7447 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7449 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7451 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
7452 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
7453 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
7458 gtp_m = &rte_flow_item_gtp_mask;
7459 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
7460 gtp_m->v_pt_rsv_flags);
7461 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
7462 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
7463 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
7464 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
7465 gtp_v->msg_type & gtp_m->msg_type);
7466 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
7467 rte_be_to_cpu_32(gtp_m->teid));
7468 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
7469 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
7473 * Add eCPRI item to matcher and to the value.
7476 * The devich to configure through.
7477 * @param[in, out] matcher
7479 * @param[in, out] key
7480 * Flow matcher value.
7482 * Flow pattern to translate.
7483 * @param[in] samples
7484 * Sample IDs to be used in the matching.
7487 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
7488 void *key, const struct rte_flow_item *item)
7490 struct mlx5_priv *priv = dev->data->dev_private;
7491 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
7492 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
7493 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
7495 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
7503 ecpri_m = &rte_flow_item_ecpri_mask;
7505 * Maximal four DW samples are supported in a single matching now.
7506 * Two are used now for a eCPRI matching:
7507 * 1. Type: one byte, mask should be 0x00ff0000 in network order
7508 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
7511 if (!ecpri_m->hdr.common.u32)
7513 samples = priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0].ids;
7514 /* Need to take the whole DW as the mask to fill the entry. */
7515 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
7516 prog_sample_field_value_0);
7517 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
7518 prog_sample_field_value_0);
7519 /* Already big endian (network order) in the header. */
7520 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
7521 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32;
7522 /* Sample#0, used for matching type, offset 0. */
7523 MLX5_SET(fte_match_set_misc4, misc4_m,
7524 prog_sample_field_id_0, samples[0]);
7525 /* It makes no sense to set the sample ID in the mask field. */
7526 MLX5_SET(fte_match_set_misc4, misc4_v,
7527 prog_sample_field_id_0, samples[0]);
7529 * Checking if message body part needs to be matched.
7530 * Some wildcard rules only matching type field should be supported.
7532 if (ecpri_m->hdr.dummy[0]) {
7533 switch (ecpri_v->hdr.common.type) {
7534 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
7535 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
7536 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
7537 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
7538 prog_sample_field_value_1);
7539 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
7540 prog_sample_field_value_1);
7541 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
7542 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0];
7543 /* Sample#1, to match message body, offset 4. */
7544 MLX5_SET(fte_match_set_misc4, misc4_m,
7545 prog_sample_field_id_1, samples[1]);
7546 MLX5_SET(fte_match_set_misc4, misc4_v,
7547 prog_sample_field_id_1, samples[1]);
7550 /* Others, do not match any sample ID. */
7556 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
7558 #define HEADER_IS_ZERO(match_criteria, headers) \
7559 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
7560 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
7563 * Calculate flow matcher enable bitmap.
7565 * @param match_criteria
7566 * Pointer to flow matcher criteria.
7569 * Bitmap of enabled fields.
7572 flow_dv_matcher_enable(uint32_t *match_criteria)
7574 uint8_t match_criteria_enable;
7576 match_criteria_enable =
7577 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
7578 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
7579 match_criteria_enable |=
7580 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
7581 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
7582 match_criteria_enable |=
7583 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
7584 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
7585 match_criteria_enable |=
7586 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
7587 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
7588 match_criteria_enable |=
7589 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
7590 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
7591 match_criteria_enable |=
7592 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
7593 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
7594 return match_criteria_enable;
7601 * @param[in, out] dev
7602 * Pointer to rte_eth_dev structure.
7603 * @param[in] table_id
7606 * Direction of the table.
7607 * @param[in] transfer
7608 * E-Switch or NIC flow.
7610 * pointer to error structure.
7613 * Returns tables resource based on the index, NULL in case of failed.
7615 static struct mlx5_flow_tbl_resource *
7616 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
7617 uint32_t table_id, uint8_t egress,
7619 struct rte_flow_error *error)
7621 struct mlx5_priv *priv = dev->data->dev_private;
7622 struct mlx5_dev_ctx_shared *sh = priv->sh;
7623 struct mlx5_flow_tbl_resource *tbl;
7624 union mlx5_flow_tbl_key table_key = {
7626 .table_id = table_id,
7628 .domain = !!transfer,
7629 .direction = !!egress,
7632 struct mlx5_hlist_entry *pos = mlx5_hlist_lookup(sh->flow_tbls,
7634 struct mlx5_flow_tbl_data_entry *tbl_data;
7640 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
7642 tbl = &tbl_data->tbl;
7643 rte_atomic32_inc(&tbl->refcnt);
7646 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
7648 rte_flow_error_set(error, ENOMEM,
7649 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7651 "cannot allocate flow table data entry");
7654 tbl_data->idx = idx;
7655 tbl = &tbl_data->tbl;
7656 pos = &tbl_data->entry;
7658 domain = sh->fdb_domain;
7660 domain = sh->tx_domain;
7662 domain = sh->rx_domain;
7663 ret = mlx5_flow_os_create_flow_tbl(domain, table_id, &tbl->obj);
7665 rte_flow_error_set(error, ENOMEM,
7666 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7667 NULL, "cannot create flow table object");
7668 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
7672 * No multi-threads now, but still better to initialize the reference
7673 * count before insert it into the hash list.
7675 rte_atomic32_init(&tbl->refcnt);
7676 /* Jump action reference count is initialized here. */
7677 rte_atomic32_init(&tbl_data->jump.refcnt);
7678 pos->key = table_key.v64;
7679 ret = mlx5_hlist_insert(sh->flow_tbls, pos);
7681 rte_flow_error_set(error, -ret,
7682 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7683 "cannot insert flow table data entry");
7684 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
7685 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
7687 rte_atomic32_inc(&tbl->refcnt);
7692 * Release a flow table.
7695 * Pointer to rte_eth_dev structure.
7697 * Table resource to be released.
7700 * Returns 0 if table was released, else return 1;
7703 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
7704 struct mlx5_flow_tbl_resource *tbl)
7706 struct mlx5_priv *priv = dev->data->dev_private;
7707 struct mlx5_dev_ctx_shared *sh = priv->sh;
7708 struct mlx5_flow_tbl_data_entry *tbl_data =
7709 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
7713 if (rte_atomic32_dec_and_test(&tbl->refcnt)) {
7714 struct mlx5_hlist_entry *pos = &tbl_data->entry;
7716 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
7718 /* remove the entry from the hash list and free memory. */
7719 mlx5_hlist_remove(sh->flow_tbls, pos);
7720 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_JUMP],
7728 * Register the flow matcher.
7730 * @param[in, out] dev
7731 * Pointer to rte_eth_dev structure.
7732 * @param[in, out] matcher
7733 * Pointer to flow matcher.
7734 * @param[in, out] key
7735 * Pointer to flow table key.
7736 * @parm[in, out] dev_flow
7737 * Pointer to the dev_flow.
7739 * pointer to error structure.
7742 * 0 on success otherwise -errno and errno is set.
7745 flow_dv_matcher_register(struct rte_eth_dev *dev,
7746 struct mlx5_flow_dv_matcher *matcher,
7747 union mlx5_flow_tbl_key *key,
7748 struct mlx5_flow *dev_flow,
7749 struct rte_flow_error *error)
7751 struct mlx5_priv *priv = dev->data->dev_private;
7752 struct mlx5_dev_ctx_shared *sh = priv->sh;
7753 struct mlx5_flow_dv_matcher *cache_matcher;
7754 struct mlx5dv_flow_matcher_attr dv_attr = {
7755 .type = IBV_FLOW_ATTR_NORMAL,
7756 .match_mask = (void *)&matcher->mask,
7758 struct mlx5_flow_tbl_resource *tbl;
7759 struct mlx5_flow_tbl_data_entry *tbl_data;
7762 tbl = flow_dv_tbl_resource_get(dev, key->table_id, key->direction,
7763 key->domain, error);
7765 return -rte_errno; /* No need to refill the error info */
7766 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
7767 /* Lookup from cache. */
7768 LIST_FOREACH(cache_matcher, &tbl_data->matchers, next) {
7769 if (matcher->crc == cache_matcher->crc &&
7770 matcher->priority == cache_matcher->priority &&
7771 !memcmp((const void *)matcher->mask.buf,
7772 (const void *)cache_matcher->mask.buf,
7773 cache_matcher->mask.size)) {
7775 "%s group %u priority %hd use %s "
7776 "matcher %p: refcnt %d++",
7777 key->domain ? "FDB" : "NIC", key->table_id,
7778 cache_matcher->priority,
7779 key->direction ? "tx" : "rx",
7780 (void *)cache_matcher,
7781 rte_atomic32_read(&cache_matcher->refcnt));
7782 rte_atomic32_inc(&cache_matcher->refcnt);
7783 dev_flow->handle->dvh.matcher = cache_matcher;
7784 /* old matcher should not make the table ref++. */
7785 flow_dv_tbl_resource_release(dev, tbl);
7789 /* Register new matcher. */
7790 cache_matcher = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*cache_matcher), 0,
7792 if (!cache_matcher) {
7793 flow_dv_tbl_resource_release(dev, tbl);
7794 return rte_flow_error_set(error, ENOMEM,
7795 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7796 "cannot allocate matcher memory");
7798 *cache_matcher = *matcher;
7799 dv_attr.match_criteria_enable =
7800 flow_dv_matcher_enable(cache_matcher->mask.buf);
7801 dv_attr.priority = matcher->priority;
7803 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
7804 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
7805 &cache_matcher->matcher_object);
7807 mlx5_free(cache_matcher);
7808 #ifdef HAVE_MLX5DV_DR
7809 flow_dv_tbl_resource_release(dev, tbl);
7811 return rte_flow_error_set(error, ENOMEM,
7812 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7813 NULL, "cannot create matcher");
7815 /* Save the table information */
7816 cache_matcher->tbl = tbl;
7817 rte_atomic32_init(&cache_matcher->refcnt);
7818 /* only matcher ref++, table ref++ already done above in get API. */
7819 rte_atomic32_inc(&cache_matcher->refcnt);
7820 LIST_INSERT_HEAD(&tbl_data->matchers, cache_matcher, next);
7821 dev_flow->handle->dvh.matcher = cache_matcher;
7822 DRV_LOG(DEBUG, "%s group %u priority %hd new %s matcher %p: refcnt %d",
7823 key->domain ? "FDB" : "NIC", key->table_id,
7824 cache_matcher->priority,
7825 key->direction ? "tx" : "rx", (void *)cache_matcher,
7826 rte_atomic32_read(&cache_matcher->refcnt));
7831 * Find existing tag resource or create and register a new one.
7833 * @param dev[in, out]
7834 * Pointer to rte_eth_dev structure.
7835 * @param[in, out] tag_be24
7836 * Tag value in big endian then R-shift 8.
7837 * @parm[in, out] dev_flow
7838 * Pointer to the dev_flow.
7840 * pointer to error structure.
7843 * 0 on success otherwise -errno and errno is set.
7846 flow_dv_tag_resource_register
7847 (struct rte_eth_dev *dev,
7849 struct mlx5_flow *dev_flow,
7850 struct rte_flow_error *error)
7852 struct mlx5_priv *priv = dev->data->dev_private;
7853 struct mlx5_dev_ctx_shared *sh = priv->sh;
7854 struct mlx5_flow_dv_tag_resource *cache_resource;
7855 struct mlx5_hlist_entry *entry;
7858 /* Lookup a matching resource from cache. */
7859 entry = mlx5_hlist_lookup(sh->tag_table, (uint64_t)tag_be24);
7861 cache_resource = container_of
7862 (entry, struct mlx5_flow_dv_tag_resource, entry);
7863 rte_atomic32_inc(&cache_resource->refcnt);
7864 dev_flow->handle->dvh.rix_tag = cache_resource->idx;
7865 dev_flow->dv.tag_resource = cache_resource;
7866 DRV_LOG(DEBUG, "cached tag resource %p: refcnt now %d++",
7867 (void *)cache_resource,
7868 rte_atomic32_read(&cache_resource->refcnt));
7871 /* Register new resource. */
7872 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG],
7873 &dev_flow->handle->dvh.rix_tag);
7874 if (!cache_resource)
7875 return rte_flow_error_set(error, ENOMEM,
7876 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7877 "cannot allocate resource memory");
7878 cache_resource->entry.key = (uint64_t)tag_be24;
7879 ret = mlx5_flow_os_create_flow_action_tag(tag_be24,
7880 &cache_resource->action);
7882 mlx5_free(cache_resource);
7883 return rte_flow_error_set(error, ENOMEM,
7884 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7885 NULL, "cannot create action");
7887 rte_atomic32_init(&cache_resource->refcnt);
7888 rte_atomic32_inc(&cache_resource->refcnt);
7889 if (mlx5_hlist_insert(sh->tag_table, &cache_resource->entry)) {
7890 mlx5_flow_os_destroy_flow_action(cache_resource->action);
7891 mlx5_free(cache_resource);
7892 return rte_flow_error_set(error, EEXIST,
7893 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7894 NULL, "cannot insert tag");
7896 dev_flow->dv.tag_resource = cache_resource;
7897 DRV_LOG(DEBUG, "new tag resource %p: refcnt now %d++",
7898 (void *)cache_resource,
7899 rte_atomic32_read(&cache_resource->refcnt));
7907 * Pointer to Ethernet device.
7912 * 1 while a reference on it exists, 0 when freed.
7915 flow_dv_tag_release(struct rte_eth_dev *dev,
7918 struct mlx5_priv *priv = dev->data->dev_private;
7919 struct mlx5_dev_ctx_shared *sh = priv->sh;
7920 struct mlx5_flow_dv_tag_resource *tag;
7922 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
7925 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
7926 dev->data->port_id, (void *)tag,
7927 rte_atomic32_read(&tag->refcnt));
7928 if (rte_atomic32_dec_and_test(&tag->refcnt)) {
7929 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
7930 mlx5_hlist_remove(sh->tag_table, &tag->entry);
7931 DRV_LOG(DEBUG, "port %u tag %p: removed",
7932 dev->data->port_id, (void *)tag);
7933 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
7940 * Translate port ID action to vport.
7943 * Pointer to rte_eth_dev structure.
7945 * Pointer to the port ID action.
7946 * @param[out] dst_port_id
7947 * The target port ID.
7949 * Pointer to the error structure.
7952 * 0 on success, a negative errno value otherwise and rte_errno is set.
7955 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
7956 const struct rte_flow_action *action,
7957 uint32_t *dst_port_id,
7958 struct rte_flow_error *error)
7961 struct mlx5_priv *priv;
7962 const struct rte_flow_action_port_id *conf =
7963 (const struct rte_flow_action_port_id *)action->conf;
7965 port = conf->original ? dev->data->port_id : conf->id;
7966 priv = mlx5_port_to_eswitch_info(port, false);
7968 return rte_flow_error_set(error, -rte_errno,
7969 RTE_FLOW_ERROR_TYPE_ACTION,
7971 "No eswitch info was found for port");
7972 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
7974 * This parameter is transferred to
7975 * mlx5dv_dr_action_create_dest_ib_port().
7977 *dst_port_id = priv->dev_port;
7980 * Legacy mode, no LAG configurations is supported.
7981 * This parameter is transferred to
7982 * mlx5dv_dr_action_create_dest_vport().
7984 *dst_port_id = priv->vport_id;
7990 * Create a counter with aging configuration.
7993 * Pointer to rte_eth_dev structure.
7995 * Pointer to the counter action configuration.
7997 * Pointer to the aging action configuration.
8000 * Index to flow counter on success, 0 otherwise.
8003 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
8004 struct mlx5_flow *dev_flow,
8005 const struct rte_flow_action_count *count,
8006 const struct rte_flow_action_age *age)
8009 struct mlx5_age_param *age_param;
8011 counter = flow_dv_counter_alloc(dev,
8012 count ? count->shared : 0,
8013 count ? count->id : 0,
8014 dev_flow->dv.group, !!age);
8015 if (!counter || age == NULL)
8017 age_param = flow_dv_counter_idx_get_age(dev, counter);
8019 * The counter age accuracy may have a bit delay. Have 3/4
8020 * second bias on the timeount in order to let it age in time.
8022 age_param->context = age->context ? age->context :
8023 (void *)(uintptr_t)(dev_flow->flow_idx);
8025 * The counter age accuracy may have a bit delay. Have 3/4
8026 * second bias on the timeount in order to let it age in time.
8028 age_param->timeout = age->timeout * 10 - MLX5_AGING_TIME_DELAY;
8029 /* Set expire time in unit of 0.1 sec. */
8030 age_param->port_id = dev->data->port_id;
8031 age_param->expire = age_param->timeout +
8032 rte_rdtsc() / (rte_get_tsc_hz() / 10);
8033 rte_atomic16_set(&age_param->state, AGE_CANDIDATE);
8037 * Add Tx queue matcher
8040 * Pointer to the dev struct.
8041 * @param[in, out] matcher
8043 * @param[in, out] key
8044 * Flow matcher value.
8046 * Flow pattern to translate.
8048 * Item is inner pattern.
8051 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
8052 void *matcher, void *key,
8053 const struct rte_flow_item *item)
8055 const struct mlx5_rte_flow_item_tx_queue *queue_m;
8056 const struct mlx5_rte_flow_item_tx_queue *queue_v;
8058 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8060 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8061 struct mlx5_txq_ctrl *txq;
8065 queue_m = (const void *)item->mask;
8068 queue_v = (const void *)item->spec;
8071 txq = mlx5_txq_get(dev, queue_v->queue);
8074 queue = txq->obj->sq->id;
8075 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
8076 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
8077 queue & queue_m->queue);
8078 mlx5_txq_release(dev, queue_v->queue);
8082 * Set the hash fields according to the @p flow information.
8084 * @param[in] dev_flow
8085 * Pointer to the mlx5_flow.
8086 * @param[in] rss_desc
8087 * Pointer to the mlx5_flow_rss_desc.
8090 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
8091 struct mlx5_flow_rss_desc *rss_desc)
8093 uint64_t items = dev_flow->handle->layers;
8095 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
8097 dev_flow->hash_fields = 0;
8098 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
8099 if (rss_desc->level >= 2) {
8100 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
8104 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
8105 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
8106 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
8107 if (rss_types & ETH_RSS_L3_SRC_ONLY)
8108 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
8109 else if (rss_types & ETH_RSS_L3_DST_ONLY)
8110 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
8112 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
8114 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
8115 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
8116 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
8117 if (rss_types & ETH_RSS_L3_SRC_ONLY)
8118 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
8119 else if (rss_types & ETH_RSS_L3_DST_ONLY)
8120 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
8122 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
8125 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
8126 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
8127 if (rss_types & ETH_RSS_UDP) {
8128 if (rss_types & ETH_RSS_L4_SRC_ONLY)
8129 dev_flow->hash_fields |=
8130 IBV_RX_HASH_SRC_PORT_UDP;
8131 else if (rss_types & ETH_RSS_L4_DST_ONLY)
8132 dev_flow->hash_fields |=
8133 IBV_RX_HASH_DST_PORT_UDP;
8135 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
8137 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
8138 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
8139 if (rss_types & ETH_RSS_TCP) {
8140 if (rss_types & ETH_RSS_L4_SRC_ONLY)
8141 dev_flow->hash_fields |=
8142 IBV_RX_HASH_SRC_PORT_TCP;
8143 else if (rss_types & ETH_RSS_L4_DST_ONLY)
8144 dev_flow->hash_fields |=
8145 IBV_RX_HASH_DST_PORT_TCP;
8147 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
8153 * Fill the flow with DV spec, lock free
8154 * (mutex should be acquired by caller).
8157 * Pointer to rte_eth_dev structure.
8158 * @param[in, out] dev_flow
8159 * Pointer to the sub flow.
8161 * Pointer to the flow attributes.
8163 * Pointer to the list of items.
8164 * @param[in] actions
8165 * Pointer to the list of actions.
8167 * Pointer to the error structure.
8170 * 0 on success, a negative errno value otherwise and rte_errno is set.
8173 __flow_dv_translate(struct rte_eth_dev *dev,
8174 struct mlx5_flow *dev_flow,
8175 const struct rte_flow_attr *attr,
8176 const struct rte_flow_item items[],
8177 const struct rte_flow_action actions[],
8178 struct rte_flow_error *error)
8180 struct mlx5_priv *priv = dev->data->dev_private;
8181 struct mlx5_dev_config *dev_conf = &priv->config;
8182 struct rte_flow *flow = dev_flow->flow;
8183 struct mlx5_flow_handle *handle = dev_flow->handle;
8184 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
8186 [!!priv->flow_nested_idx];
8187 uint64_t item_flags = 0;
8188 uint64_t last_item = 0;
8189 uint64_t action_flags = 0;
8190 uint64_t priority = attr->priority;
8191 struct mlx5_flow_dv_matcher matcher = {
8193 .size = sizeof(matcher.mask.buf) -
8194 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
8198 bool actions_end = false;
8200 struct mlx5_flow_dv_modify_hdr_resource res;
8201 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
8202 sizeof(struct mlx5_modification_cmd) *
8203 (MLX5_MAX_MODIFY_NUM + 1)];
8205 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
8206 const struct rte_flow_action_count *count = NULL;
8207 const struct rte_flow_action_age *age = NULL;
8208 union flow_dv_attr flow_attr = { .attr = 0 };
8210 union mlx5_flow_tbl_key tbl_key;
8211 uint32_t modify_action_position = UINT32_MAX;
8212 void *match_mask = matcher.mask.buf;
8213 void *match_value = dev_flow->dv.value.buf;
8214 uint8_t next_protocol = 0xff;
8215 struct rte_vlan_hdr vlan = { 0 };
8219 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
8220 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
8221 ret = mlx5_flow_group_to_table(attr, dev_flow->external, attr->group,
8222 !!priv->fdb_def_rule, &table, error);
8225 dev_flow->dv.group = table;
8227 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
8228 if (priority == MLX5_FLOW_PRIO_RSVD)
8229 priority = dev_conf->flow_prio - 1;
8230 /* number of actions must be set to 0 in case of dirty stack. */
8231 mhdr_res->actions_num = 0;
8232 for (; !actions_end ; actions++) {
8233 const struct rte_flow_action_queue *queue;
8234 const struct rte_flow_action_rss *rss;
8235 const struct rte_flow_action *action = actions;
8236 const uint8_t *rss_key;
8237 const struct rte_flow_action_jump *jump_data;
8238 const struct rte_flow_action_meter *mtr;
8239 struct mlx5_flow_tbl_resource *tbl;
8240 uint32_t port_id = 0;
8241 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
8242 int action_type = actions->type;
8243 const struct rte_flow_action *found_action = NULL;
8244 struct mlx5_flow_meter *fm = NULL;
8246 if (!mlx5_flow_os_action_supported(action_type))
8247 return rte_flow_error_set(error, ENOTSUP,
8248 RTE_FLOW_ERROR_TYPE_ACTION,
8250 "action not supported");
8251 switch (action_type) {
8252 case RTE_FLOW_ACTION_TYPE_VOID:
8254 case RTE_FLOW_ACTION_TYPE_PORT_ID:
8255 if (flow_dv_translate_action_port_id(dev, action,
8258 port_id_resource.port_id = port_id;
8259 MLX5_ASSERT(!handle->rix_port_id_action);
8260 if (flow_dv_port_id_action_resource_register
8261 (dev, &port_id_resource, dev_flow, error))
8263 dev_flow->dv.actions[actions_n++] =
8264 dev_flow->dv.port_id_action->action;
8265 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
8266 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
8268 case RTE_FLOW_ACTION_TYPE_FLAG:
8269 action_flags |= MLX5_FLOW_ACTION_FLAG;
8270 dev_flow->handle->mark = 1;
8271 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8272 struct rte_flow_action_mark mark = {
8273 .id = MLX5_FLOW_MARK_DEFAULT,
8276 if (flow_dv_convert_action_mark(dev, &mark,
8280 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
8283 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
8285 * Only one FLAG or MARK is supported per device flow
8286 * right now. So the pointer to the tag resource must be
8287 * zero before the register process.
8289 MLX5_ASSERT(!handle->dvh.rix_tag);
8290 if (flow_dv_tag_resource_register(dev, tag_be,
8293 MLX5_ASSERT(dev_flow->dv.tag_resource);
8294 dev_flow->dv.actions[actions_n++] =
8295 dev_flow->dv.tag_resource->action;
8297 case RTE_FLOW_ACTION_TYPE_MARK:
8298 action_flags |= MLX5_FLOW_ACTION_MARK;
8299 dev_flow->handle->mark = 1;
8300 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8301 const struct rte_flow_action_mark *mark =
8302 (const struct rte_flow_action_mark *)
8305 if (flow_dv_convert_action_mark(dev, mark,
8309 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
8313 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8314 /* Legacy (non-extensive) MARK action. */
8315 tag_be = mlx5_flow_mark_set
8316 (((const struct rte_flow_action_mark *)
8317 (actions->conf))->id);
8318 MLX5_ASSERT(!handle->dvh.rix_tag);
8319 if (flow_dv_tag_resource_register(dev, tag_be,
8322 MLX5_ASSERT(dev_flow->dv.tag_resource);
8323 dev_flow->dv.actions[actions_n++] =
8324 dev_flow->dv.tag_resource->action;
8326 case RTE_FLOW_ACTION_TYPE_SET_META:
8327 if (flow_dv_convert_action_set_meta
8328 (dev, mhdr_res, attr,
8329 (const struct rte_flow_action_set_meta *)
8330 actions->conf, error))
8332 action_flags |= MLX5_FLOW_ACTION_SET_META;
8334 case RTE_FLOW_ACTION_TYPE_SET_TAG:
8335 if (flow_dv_convert_action_set_tag
8337 (const struct rte_flow_action_set_tag *)
8338 actions->conf, error))
8340 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8342 case RTE_FLOW_ACTION_TYPE_DROP:
8343 action_flags |= MLX5_FLOW_ACTION_DROP;
8344 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
8346 case RTE_FLOW_ACTION_TYPE_QUEUE:
8347 queue = actions->conf;
8348 rss_desc->queue_num = 1;
8349 rss_desc->queue[0] = queue->index;
8350 action_flags |= MLX5_FLOW_ACTION_QUEUE;
8351 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
8353 case RTE_FLOW_ACTION_TYPE_RSS:
8354 rss = actions->conf;
8355 memcpy(rss_desc->queue, rss->queue,
8356 rss->queue_num * sizeof(uint16_t));
8357 rss_desc->queue_num = rss->queue_num;
8358 /* NULL RSS key indicates default RSS key. */
8359 rss_key = !rss->key ? rss_hash_default_key : rss->key;
8360 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
8362 * rss->level and rss.types should be set in advance
8363 * when expanding items for RSS.
8365 action_flags |= MLX5_FLOW_ACTION_RSS;
8366 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
8368 case RTE_FLOW_ACTION_TYPE_AGE:
8369 case RTE_FLOW_ACTION_TYPE_COUNT:
8370 if (!dev_conf->devx) {
8371 return rte_flow_error_set
8373 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8375 "count action not supported");
8377 /* Save information first, will apply later. */
8378 if (actions->type == RTE_FLOW_ACTION_TYPE_COUNT)
8379 count = action->conf;
8382 action_flags |= MLX5_FLOW_ACTION_COUNT;
8384 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8385 dev_flow->dv.actions[actions_n++] =
8386 priv->sh->pop_vlan_action;
8387 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8389 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8390 if (!(action_flags &
8391 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
8392 flow_dev_get_vlan_info_from_items(items, &vlan);
8393 vlan.eth_proto = rte_be_to_cpu_16
8394 ((((const struct rte_flow_action_of_push_vlan *)
8395 actions->conf)->ethertype));
8396 found_action = mlx5_flow_find_action
8398 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
8400 mlx5_update_vlan_vid_pcp(found_action, &vlan);
8401 found_action = mlx5_flow_find_action
8403 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
8405 mlx5_update_vlan_vid_pcp(found_action, &vlan);
8406 if (flow_dv_create_action_push_vlan
8407 (dev, attr, &vlan, dev_flow, error))
8409 dev_flow->dv.actions[actions_n++] =
8410 dev_flow->dv.push_vlan_res->action;
8411 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8413 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8414 /* of_vlan_push action handled this action */
8415 MLX5_ASSERT(action_flags &
8416 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
8418 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8419 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
8421 flow_dev_get_vlan_info_from_items(items, &vlan);
8422 mlx5_update_vlan_vid_pcp(actions, &vlan);
8423 /* If no VLAN push - this is a modify header action */
8424 if (flow_dv_convert_action_modify_vlan_vid
8425 (mhdr_res, actions, error))
8427 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8429 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8430 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8431 if (flow_dv_create_action_l2_encap(dev, actions,
8436 dev_flow->dv.actions[actions_n++] =
8437 dev_flow->dv.encap_decap->action;
8438 action_flags |= MLX5_FLOW_ACTION_ENCAP;
8440 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8441 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8442 if (flow_dv_create_action_l2_decap(dev, dev_flow,
8446 dev_flow->dv.actions[actions_n++] =
8447 dev_flow->dv.encap_decap->action;
8448 action_flags |= MLX5_FLOW_ACTION_DECAP;
8450 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8451 /* Handle encap with preceding decap. */
8452 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
8453 if (flow_dv_create_action_raw_encap
8454 (dev, actions, dev_flow, attr, error))
8456 dev_flow->dv.actions[actions_n++] =
8457 dev_flow->dv.encap_decap->action;
8459 /* Handle encap without preceding decap. */
8460 if (flow_dv_create_action_l2_encap
8461 (dev, actions, dev_flow, attr->transfer,
8464 dev_flow->dv.actions[actions_n++] =
8465 dev_flow->dv.encap_decap->action;
8467 action_flags |= MLX5_FLOW_ACTION_ENCAP;
8469 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8470 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
8472 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8473 if (flow_dv_create_action_l2_decap
8474 (dev, dev_flow, attr->transfer, error))
8476 dev_flow->dv.actions[actions_n++] =
8477 dev_flow->dv.encap_decap->action;
8479 /* If decap is followed by encap, handle it at encap. */
8480 action_flags |= MLX5_FLOW_ACTION_DECAP;
8482 case RTE_FLOW_ACTION_TYPE_JUMP:
8483 jump_data = action->conf;
8484 ret = mlx5_flow_group_to_table(attr, dev_flow->external,
8486 !!priv->fdb_def_rule,
8490 tbl = flow_dv_tbl_resource_get(dev, table,
8492 attr->transfer, error);
8494 return rte_flow_error_set
8496 RTE_FLOW_ERROR_TYPE_ACTION,
8498 "cannot create jump action.");
8499 if (flow_dv_jump_tbl_resource_register
8500 (dev, tbl, dev_flow, error)) {
8501 flow_dv_tbl_resource_release(dev, tbl);
8502 return rte_flow_error_set
8504 RTE_FLOW_ERROR_TYPE_ACTION,
8506 "cannot create jump action.");
8508 dev_flow->dv.actions[actions_n++] =
8509 dev_flow->dv.jump->action;
8510 action_flags |= MLX5_FLOW_ACTION_JUMP;
8511 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
8513 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8514 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8515 if (flow_dv_convert_action_modify_mac
8516 (mhdr_res, actions, error))
8518 action_flags |= actions->type ==
8519 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8520 MLX5_FLOW_ACTION_SET_MAC_SRC :
8521 MLX5_FLOW_ACTION_SET_MAC_DST;
8523 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8524 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8525 if (flow_dv_convert_action_modify_ipv4
8526 (mhdr_res, actions, error))
8528 action_flags |= actions->type ==
8529 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8530 MLX5_FLOW_ACTION_SET_IPV4_SRC :
8531 MLX5_FLOW_ACTION_SET_IPV4_DST;
8533 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8534 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8535 if (flow_dv_convert_action_modify_ipv6
8536 (mhdr_res, actions, error))
8538 action_flags |= actions->type ==
8539 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8540 MLX5_FLOW_ACTION_SET_IPV6_SRC :
8541 MLX5_FLOW_ACTION_SET_IPV6_DST;
8543 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8544 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8545 if (flow_dv_convert_action_modify_tp
8546 (mhdr_res, actions, items,
8547 &flow_attr, dev_flow, !!(action_flags &
8548 MLX5_FLOW_ACTION_DECAP), error))
8550 action_flags |= actions->type ==
8551 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8552 MLX5_FLOW_ACTION_SET_TP_SRC :
8553 MLX5_FLOW_ACTION_SET_TP_DST;
8555 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8556 if (flow_dv_convert_action_modify_dec_ttl
8557 (mhdr_res, items, &flow_attr, dev_flow,
8559 MLX5_FLOW_ACTION_DECAP), error))
8561 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
8563 case RTE_FLOW_ACTION_TYPE_SET_TTL:
8564 if (flow_dv_convert_action_modify_ttl
8565 (mhdr_res, actions, items, &flow_attr,
8566 dev_flow, !!(action_flags &
8567 MLX5_FLOW_ACTION_DECAP), error))
8569 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
8571 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8572 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8573 if (flow_dv_convert_action_modify_tcp_seq
8574 (mhdr_res, actions, error))
8576 action_flags |= actions->type ==
8577 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8578 MLX5_FLOW_ACTION_INC_TCP_SEQ :
8579 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8582 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8583 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8584 if (flow_dv_convert_action_modify_tcp_ack
8585 (mhdr_res, actions, error))
8587 action_flags |= actions->type ==
8588 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8589 MLX5_FLOW_ACTION_INC_TCP_ACK :
8590 MLX5_FLOW_ACTION_DEC_TCP_ACK;
8592 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8593 if (flow_dv_convert_action_set_reg
8594 (mhdr_res, actions, error))
8596 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8598 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8599 if (flow_dv_convert_action_copy_mreg
8600 (dev, mhdr_res, actions, error))
8602 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8604 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
8605 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
8606 dev_flow->handle->fate_action =
8607 MLX5_FLOW_FATE_DEFAULT_MISS;
8609 case RTE_FLOW_ACTION_TYPE_METER:
8610 mtr = actions->conf;
8612 fm = mlx5_flow_meter_attach(priv, mtr->mtr_id,
8615 return rte_flow_error_set(error,
8617 RTE_FLOW_ERROR_TYPE_ACTION,
8620 "or invalid parameters");
8621 flow->meter = fm->idx;
8623 /* Set the meter action. */
8625 fm = mlx5_ipool_get(priv->sh->ipool
8626 [MLX5_IPOOL_MTR], flow->meter);
8628 return rte_flow_error_set(error,
8630 RTE_FLOW_ERROR_TYPE_ACTION,
8633 "or invalid parameters");
8635 dev_flow->dv.actions[actions_n++] =
8636 fm->mfts->meter_action;
8637 action_flags |= MLX5_FLOW_ACTION_METER;
8639 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8640 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
8643 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8645 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8646 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
8649 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8651 case RTE_FLOW_ACTION_TYPE_END:
8653 if (mhdr_res->actions_num) {
8654 /* create modify action if needed. */
8655 if (flow_dv_modify_hdr_resource_register
8656 (dev, mhdr_res, dev_flow, error))
8658 dev_flow->dv.actions[modify_action_position] =
8659 handle->dvh.modify_hdr->action;
8661 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
8663 flow_dv_translate_create_counter(dev,
8664 dev_flow, count, age);
8667 return rte_flow_error_set
8669 RTE_FLOW_ERROR_TYPE_ACTION,
8671 "cannot create counter"
8673 dev_flow->dv.actions[actions_n++] =
8674 (flow_dv_counter_get_by_idx(dev,
8675 flow->counter, NULL))->action;
8681 if (mhdr_res->actions_num &&
8682 modify_action_position == UINT32_MAX)
8683 modify_action_position = actions_n++;
8685 dev_flow->dv.actions_n = actions_n;
8686 dev_flow->act_flags = action_flags;
8687 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
8688 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
8689 int item_type = items->type;
8691 if (!mlx5_flow_os_item_supported(item_type))
8692 return rte_flow_error_set(error, ENOTSUP,
8693 RTE_FLOW_ERROR_TYPE_ITEM,
8694 NULL, "item not supported");
8695 switch (item_type) {
8696 case RTE_FLOW_ITEM_TYPE_PORT_ID:
8697 flow_dv_translate_item_port_id(dev, match_mask,
8698 match_value, items);
8699 last_item = MLX5_FLOW_ITEM_PORT_ID;
8701 case RTE_FLOW_ITEM_TYPE_ETH:
8702 flow_dv_translate_item_eth(match_mask, match_value,
8704 dev_flow->dv.group);
8705 matcher.priority = action_flags &
8706 MLX5_FLOW_ACTION_DEFAULT_MISS &&
8707 !dev_flow->external ?
8708 MLX5_PRIORITY_MAP_L3 :
8709 MLX5_PRIORITY_MAP_L2;
8710 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
8711 MLX5_FLOW_LAYER_OUTER_L2;
8713 case RTE_FLOW_ITEM_TYPE_VLAN:
8714 flow_dv_translate_item_vlan(dev_flow,
8715 match_mask, match_value,
8717 dev_flow->dv.group);
8718 matcher.priority = MLX5_PRIORITY_MAP_L2;
8719 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
8720 MLX5_FLOW_LAYER_INNER_VLAN) :
8721 (MLX5_FLOW_LAYER_OUTER_L2 |
8722 MLX5_FLOW_LAYER_OUTER_VLAN);
8724 case RTE_FLOW_ITEM_TYPE_IPV4:
8725 mlx5_flow_tunnel_ip_check(items, next_protocol,
8726 &item_flags, &tunnel);
8727 flow_dv_translate_item_ipv4(match_mask, match_value,
8728 items, item_flags, tunnel,
8729 dev_flow->dv.group);
8730 matcher.priority = MLX5_PRIORITY_MAP_L3;
8731 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
8732 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
8733 if (items->mask != NULL &&
8734 ((const struct rte_flow_item_ipv4 *)
8735 items->mask)->hdr.next_proto_id) {
8737 ((const struct rte_flow_item_ipv4 *)
8738 (items->spec))->hdr.next_proto_id;
8740 ((const struct rte_flow_item_ipv4 *)
8741 (items->mask))->hdr.next_proto_id;
8743 /* Reset for inner layer. */
8744 next_protocol = 0xff;
8747 case RTE_FLOW_ITEM_TYPE_IPV6:
8748 mlx5_flow_tunnel_ip_check(items, next_protocol,
8749 &item_flags, &tunnel);
8750 flow_dv_translate_item_ipv6(match_mask, match_value,
8751 items, item_flags, tunnel,
8752 dev_flow->dv.group);
8753 matcher.priority = MLX5_PRIORITY_MAP_L3;
8754 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
8755 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
8756 if (items->mask != NULL &&
8757 ((const struct rte_flow_item_ipv6 *)
8758 items->mask)->hdr.proto) {
8760 ((const struct rte_flow_item_ipv6 *)
8761 items->spec)->hdr.proto;
8763 ((const struct rte_flow_item_ipv6 *)
8764 items->mask)->hdr.proto;
8766 /* Reset for inner layer. */
8767 next_protocol = 0xff;
8770 case RTE_FLOW_ITEM_TYPE_TCP:
8771 flow_dv_translate_item_tcp(match_mask, match_value,
8773 matcher.priority = MLX5_PRIORITY_MAP_L4;
8774 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
8775 MLX5_FLOW_LAYER_OUTER_L4_TCP;
8777 case RTE_FLOW_ITEM_TYPE_UDP:
8778 flow_dv_translate_item_udp(match_mask, match_value,
8780 matcher.priority = MLX5_PRIORITY_MAP_L4;
8781 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
8782 MLX5_FLOW_LAYER_OUTER_L4_UDP;
8784 case RTE_FLOW_ITEM_TYPE_GRE:
8785 flow_dv_translate_item_gre(match_mask, match_value,
8787 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
8788 last_item = MLX5_FLOW_LAYER_GRE;
8790 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
8791 flow_dv_translate_item_gre_key(match_mask,
8792 match_value, items);
8793 last_item = MLX5_FLOW_LAYER_GRE_KEY;
8795 case RTE_FLOW_ITEM_TYPE_NVGRE:
8796 flow_dv_translate_item_nvgre(match_mask, match_value,
8798 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
8799 last_item = MLX5_FLOW_LAYER_GRE;
8801 case RTE_FLOW_ITEM_TYPE_VXLAN:
8802 flow_dv_translate_item_vxlan(match_mask, match_value,
8804 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
8805 last_item = MLX5_FLOW_LAYER_VXLAN;
8807 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
8808 flow_dv_translate_item_vxlan_gpe(match_mask,
8811 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
8812 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8814 case RTE_FLOW_ITEM_TYPE_GENEVE:
8815 flow_dv_translate_item_geneve(match_mask, match_value,
8817 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
8818 last_item = MLX5_FLOW_LAYER_GENEVE;
8820 case RTE_FLOW_ITEM_TYPE_MPLS:
8821 flow_dv_translate_item_mpls(match_mask, match_value,
8822 items, last_item, tunnel);
8823 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
8824 last_item = MLX5_FLOW_LAYER_MPLS;
8826 case RTE_FLOW_ITEM_TYPE_MARK:
8827 flow_dv_translate_item_mark(dev, match_mask,
8828 match_value, items);
8829 last_item = MLX5_FLOW_ITEM_MARK;
8831 case RTE_FLOW_ITEM_TYPE_META:
8832 flow_dv_translate_item_meta(dev, match_mask,
8833 match_value, attr, items);
8834 last_item = MLX5_FLOW_ITEM_METADATA;
8836 case RTE_FLOW_ITEM_TYPE_ICMP:
8837 flow_dv_translate_item_icmp(match_mask, match_value,
8839 last_item = MLX5_FLOW_LAYER_ICMP;
8841 case RTE_FLOW_ITEM_TYPE_ICMP6:
8842 flow_dv_translate_item_icmp6(match_mask, match_value,
8844 last_item = MLX5_FLOW_LAYER_ICMP6;
8846 case RTE_FLOW_ITEM_TYPE_TAG:
8847 flow_dv_translate_item_tag(dev, match_mask,
8848 match_value, items);
8849 last_item = MLX5_FLOW_ITEM_TAG;
8851 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8852 flow_dv_translate_mlx5_item_tag(dev, match_mask,
8853 match_value, items);
8854 last_item = MLX5_FLOW_ITEM_TAG;
8856 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8857 flow_dv_translate_item_tx_queue(dev, match_mask,
8860 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
8862 case RTE_FLOW_ITEM_TYPE_GTP:
8863 flow_dv_translate_item_gtp(match_mask, match_value,
8865 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
8866 last_item = MLX5_FLOW_LAYER_GTP;
8868 case RTE_FLOW_ITEM_TYPE_ECPRI:
8869 if (!mlx5_flex_parser_ecpri_exist(dev)) {
8870 /* Create it only the first time to be used. */
8871 ret = mlx5_flex_parser_ecpri_alloc(dev);
8873 return rte_flow_error_set
8875 RTE_FLOW_ERROR_TYPE_ITEM,
8877 "cannot create eCPRI parser");
8879 /* Adjust the length matcher and device flow value. */
8880 matcher.mask.size = MLX5_ST_SZ_BYTES(fte_match_param);
8881 dev_flow->dv.value.size =
8882 MLX5_ST_SZ_BYTES(fte_match_param);
8883 flow_dv_translate_item_ecpri(dev, match_mask,
8884 match_value, items);
8885 /* No other protocol should follow eCPRI layer. */
8886 last_item = MLX5_FLOW_LAYER_ECPRI;
8891 item_flags |= last_item;
8894 * When E-Switch mode is enabled, we have two cases where we need to
8895 * set the source port manually.
8896 * The first one, is in case of Nic steering rule, and the second is
8897 * E-Switch rule where no port_id item was found. In both cases
8898 * the source port is set according the current port in use.
8900 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
8901 (priv->representor || priv->master)) {
8902 if (flow_dv_translate_item_port_id(dev, match_mask,
8906 #ifdef RTE_LIBRTE_MLX5_DEBUG
8907 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
8908 dev_flow->dv.value.buf));
8911 * Layers may be already initialized from prefix flow if this dev_flow
8912 * is the suffix flow.
8914 handle->layers |= item_flags;
8915 if (action_flags & MLX5_FLOW_ACTION_RSS)
8916 flow_dv_hashfields_set(dev_flow, rss_desc);
8917 /* Register matcher. */
8918 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
8920 matcher.priority = mlx5_flow_adjust_priority(dev, priority,
8922 /* reserved field no needs to be set to 0 here. */
8923 tbl_key.domain = attr->transfer;
8924 tbl_key.direction = attr->egress;
8925 tbl_key.table_id = dev_flow->dv.group;
8926 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow, error))
8932 * Apply the flow to the NIC, lock free,
8933 * (mutex should be acquired by caller).
8936 * Pointer to the Ethernet device structure.
8937 * @param[in, out] flow
8938 * Pointer to flow structure.
8940 * Pointer to error structure.
8943 * 0 on success, a negative errno value otherwise and rte_errno is set.
8946 __flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
8947 struct rte_flow_error *error)
8949 struct mlx5_flow_dv_workspace *dv;
8950 struct mlx5_flow_handle *dh;
8951 struct mlx5_flow_handle_dv *dv_h;
8952 struct mlx5_flow *dev_flow;
8953 struct mlx5_priv *priv = dev->data->dev_private;
8954 uint32_t handle_idx;
8959 for (idx = priv->flow_idx - 1; idx >= priv->flow_nested_idx; idx--) {
8960 dev_flow = &((struct mlx5_flow *)priv->inter_flows)[idx];
8962 dh = dev_flow->handle;
8965 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
8967 dv->actions[n++] = priv->sh->esw_drop_action;
8969 struct mlx5_hrxq *drop_hrxq;
8970 drop_hrxq = mlx5_drop_action_create(dev);
8974 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8976 "cannot get drop hash queue");
8980 * Drop queues will be released by the specify
8981 * mlx5_drop_action_destroy() function. Assign
8982 * the special index to hrxq to mark the queue
8983 * has been allocated.
8985 dh->rix_hrxq = UINT32_MAX;
8986 dv->actions[n++] = drop_hrxq->action;
8988 } else if (dh->fate_action == MLX5_FLOW_FATE_QUEUE) {
8989 struct mlx5_hrxq *hrxq;
8991 struct mlx5_flow_rss_desc *rss_desc =
8992 &((struct mlx5_flow_rss_desc *)priv->rss_desc)
8993 [!!priv->flow_nested_idx];
8995 MLX5_ASSERT(rss_desc->queue_num);
8996 hrxq_idx = mlx5_hrxq_get(dev, rss_desc->key,
8997 MLX5_RSS_HASH_KEY_LEN,
8998 dev_flow->hash_fields,
9000 rss_desc->queue_num);
9002 hrxq_idx = mlx5_hrxq_new
9003 (dev, rss_desc->key,
9004 MLX5_RSS_HASH_KEY_LEN,
9005 dev_flow->hash_fields,
9007 rss_desc->queue_num,
9009 MLX5_FLOW_LAYER_TUNNEL));
9011 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
9016 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9017 "cannot get hash queue");
9020 dh->rix_hrxq = hrxq_idx;
9021 dv->actions[n++] = hrxq->action;
9022 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
9023 if (flow_dv_default_miss_resource_register
9027 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9028 "cannot create default miss resource");
9029 goto error_default_miss;
9031 dh->rix_default_fate = MLX5_FLOW_FATE_DEFAULT_MISS;
9032 dv->actions[n++] = priv->sh->default_miss.action;
9034 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
9035 (void *)&dv->value, n,
9036 dv->actions, &dh->drv_flow);
9038 rte_flow_error_set(error, errno,
9039 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9041 "hardware refuses to create flow");
9044 if (priv->vmwa_context &&
9045 dh->vf_vlan.tag && !dh->vf_vlan.created) {
9047 * The rule contains the VLAN pattern.
9048 * For VF we are going to create VLAN
9049 * interface to make hypervisor set correct
9050 * e-Switch vport context.
9052 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
9057 if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS)
9058 flow_dv_default_miss_resource_release(dev);
9060 err = rte_errno; /* Save rte_errno before cleanup. */
9061 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
9062 handle_idx, dh, next) {
9063 /* hrxq is union, don't clear it if the flag is not set. */
9065 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
9066 mlx5_drop_action_destroy(dev);
9068 } else if (dh->fate_action == MLX5_FLOW_FATE_QUEUE) {
9069 mlx5_hrxq_release(dev, dh->rix_hrxq);
9073 if (dh->vf_vlan.tag && dh->vf_vlan.created)
9074 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
9076 rte_errno = err; /* Restore rte_errno. */
9081 * Release the flow matcher.
9084 * Pointer to Ethernet device.
9086 * Pointer to mlx5_flow_handle.
9089 * 1 while a reference on it exists, 0 when freed.
9092 flow_dv_matcher_release(struct rte_eth_dev *dev,
9093 struct mlx5_flow_handle *handle)
9095 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
9097 MLX5_ASSERT(matcher->matcher_object);
9098 DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
9099 dev->data->port_id, (void *)matcher,
9100 rte_atomic32_read(&matcher->refcnt));
9101 if (rte_atomic32_dec_and_test(&matcher->refcnt)) {
9102 claim_zero(mlx5_flow_os_destroy_flow_matcher
9103 (matcher->matcher_object));
9104 LIST_REMOVE(matcher, next);
9105 /* table ref-- in release interface. */
9106 flow_dv_tbl_resource_release(dev, matcher->tbl);
9108 DRV_LOG(DEBUG, "port %u matcher %p: removed",
9109 dev->data->port_id, (void *)matcher);
9116 * Release an encap/decap resource.
9119 * Pointer to Ethernet device.
9121 * Pointer to mlx5_flow_handle.
9124 * 1 while a reference on it exists, 0 when freed.
9127 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
9128 struct mlx5_flow_handle *handle)
9130 struct mlx5_priv *priv = dev->data->dev_private;
9131 uint32_t idx = handle->dvh.rix_encap_decap;
9132 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
9134 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
9136 if (!cache_resource)
9138 MLX5_ASSERT(cache_resource->action);
9139 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d--",
9140 (void *)cache_resource,
9141 rte_atomic32_read(&cache_resource->refcnt));
9142 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9143 claim_zero(mlx5_flow_os_destroy_flow_action
9144 (cache_resource->action));
9145 mlx5_hlist_remove(priv->sh->encaps_decaps,
9146 &cache_resource->entry);
9147 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
9148 DRV_LOG(DEBUG, "encap/decap resource %p: removed",
9149 (void *)cache_resource);
9156 * Release an jump to table action resource.
9159 * Pointer to Ethernet device.
9161 * Pointer to mlx5_flow_handle.
9164 * 1 while a reference on it exists, 0 when freed.
9167 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
9168 struct mlx5_flow_handle *handle)
9170 struct mlx5_priv *priv = dev->data->dev_private;
9171 struct mlx5_flow_dv_jump_tbl_resource *cache_resource;
9172 struct mlx5_flow_tbl_data_entry *tbl_data;
9174 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
9178 cache_resource = &tbl_data->jump;
9179 MLX5_ASSERT(cache_resource->action);
9180 DRV_LOG(DEBUG, "jump table resource %p: refcnt %d--",
9181 (void *)cache_resource,
9182 rte_atomic32_read(&cache_resource->refcnt));
9183 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9184 claim_zero(mlx5_flow_os_destroy_flow_action
9185 (cache_resource->action));
9186 /* jump action memory free is inside the table release. */
9187 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
9188 DRV_LOG(DEBUG, "jump table resource %p: removed",
9189 (void *)cache_resource);
9196 * Release a default miss resource.
9199 * Pointer to Ethernet device.
9201 * 1 while a reference on it exists, 0 when freed.
9204 flow_dv_default_miss_resource_release(struct rte_eth_dev *dev)
9206 struct mlx5_priv *priv = dev->data->dev_private;
9207 struct mlx5_dev_ctx_shared *sh = priv->sh;
9208 struct mlx5_flow_default_miss_resource *cache_resource =
9211 MLX5_ASSERT(cache_resource->action);
9212 DRV_LOG(DEBUG, "default miss resource %p: refcnt %d--",
9213 (void *)cache_resource->action,
9214 rte_atomic32_read(&cache_resource->refcnt));
9215 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9216 claim_zero(mlx5_glue->destroy_flow_action
9217 (cache_resource->action));
9218 DRV_LOG(DEBUG, "default miss resource %p: removed",
9219 (void *)cache_resource->action);
9226 * Release a modify-header resource.
9229 * Pointer to Ethernet device.
9231 * Pointer to mlx5_flow_handle.
9234 * 1 while a reference on it exists, 0 when freed.
9237 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
9238 struct mlx5_flow_handle *handle)
9240 struct mlx5_priv *priv = dev->data->dev_private;
9241 struct mlx5_flow_dv_modify_hdr_resource *cache_resource =
9242 handle->dvh.modify_hdr;
9244 MLX5_ASSERT(cache_resource->action);
9245 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d--",
9246 (void *)cache_resource,
9247 rte_atomic32_read(&cache_resource->refcnt));
9248 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9249 claim_zero(mlx5_flow_os_destroy_flow_action
9250 (cache_resource->action));
9251 mlx5_hlist_remove(priv->sh->modify_cmds,
9252 &cache_resource->entry);
9253 mlx5_free(cache_resource);
9254 DRV_LOG(DEBUG, "modify-header resource %p: removed",
9255 (void *)cache_resource);
9262 * Release port ID action resource.
9265 * Pointer to Ethernet device.
9267 * Pointer to mlx5_flow_handle.
9270 * 1 while a reference on it exists, 0 when freed.
9273 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
9274 struct mlx5_flow_handle *handle)
9276 struct mlx5_priv *priv = dev->data->dev_private;
9277 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
9278 uint32_t idx = handle->rix_port_id_action;
9280 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
9282 if (!cache_resource)
9284 MLX5_ASSERT(cache_resource->action);
9285 DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--",
9286 (void *)cache_resource,
9287 rte_atomic32_read(&cache_resource->refcnt));
9288 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9289 claim_zero(mlx5_flow_os_destroy_flow_action
9290 (cache_resource->action));
9291 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
9292 &priv->sh->port_id_action_list, idx,
9293 cache_resource, next);
9294 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_PORT_ID], idx);
9295 DRV_LOG(DEBUG, "port id action resource %p: removed",
9296 (void *)cache_resource);
9303 * Release push vlan action resource.
9306 * Pointer to Ethernet device.
9308 * Pointer to mlx5_flow_handle.
9311 * 1 while a reference on it exists, 0 when freed.
9314 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
9315 struct mlx5_flow_handle *handle)
9317 struct mlx5_priv *priv = dev->data->dev_private;
9318 uint32_t idx = handle->dvh.rix_push_vlan;
9319 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
9321 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN],
9323 if (!cache_resource)
9325 MLX5_ASSERT(cache_resource->action);
9326 DRV_LOG(DEBUG, "push VLAN action resource %p: refcnt %d--",
9327 (void *)cache_resource,
9328 rte_atomic32_read(&cache_resource->refcnt));
9329 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9330 claim_zero(mlx5_flow_os_destroy_flow_action
9331 (cache_resource->action));
9332 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN],
9333 &priv->sh->push_vlan_action_list, idx,
9334 cache_resource, next);
9335 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
9336 DRV_LOG(DEBUG, "push vlan action resource %p: removed",
9337 (void *)cache_resource);
9344 * Release the fate resource.
9347 * Pointer to Ethernet device.
9349 * Pointer to mlx5_flow_handle.
9352 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
9353 struct mlx5_flow_handle *handle)
9355 if (!handle->rix_fate)
9357 switch (handle->fate_action) {
9358 case MLX5_FLOW_FATE_DROP:
9359 mlx5_drop_action_destroy(dev);
9361 case MLX5_FLOW_FATE_QUEUE:
9362 mlx5_hrxq_release(dev, handle->rix_hrxq);
9364 case MLX5_FLOW_FATE_JUMP:
9365 flow_dv_jump_tbl_resource_release(dev, handle);
9367 case MLX5_FLOW_FATE_PORT_ID:
9368 flow_dv_port_id_action_resource_release(dev, handle);
9370 case MLX5_FLOW_FATE_DEFAULT_MISS:
9371 flow_dv_default_miss_resource_release(dev);
9374 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
9377 handle->rix_fate = 0;
9381 * Remove the flow from the NIC but keeps it in memory.
9382 * Lock free, (mutex should be acquired by caller).
9385 * Pointer to Ethernet device.
9386 * @param[in, out] flow
9387 * Pointer to flow structure.
9390 __flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
9392 struct mlx5_flow_handle *dh;
9393 uint32_t handle_idx;
9394 struct mlx5_priv *priv = dev->data->dev_private;
9398 handle_idx = flow->dev_handles;
9399 while (handle_idx) {
9400 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9405 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
9406 dh->drv_flow = NULL;
9408 if (dh->fate_action == MLX5_FLOW_FATE_DROP ||
9409 dh->fate_action == MLX5_FLOW_FATE_QUEUE ||
9410 dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS)
9411 flow_dv_fate_resource_release(dev, dh);
9412 if (dh->vf_vlan.tag && dh->vf_vlan.created)
9413 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
9414 handle_idx = dh->next.next;
9419 * Remove the flow from the NIC and the memory.
9420 * Lock free, (mutex should be acquired by caller).
9423 * Pointer to the Ethernet device structure.
9424 * @param[in, out] flow
9425 * Pointer to flow structure.
9428 __flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
9430 struct mlx5_flow_handle *dev_handle;
9431 struct mlx5_priv *priv = dev->data->dev_private;
9435 __flow_dv_remove(dev, flow);
9436 if (flow->counter) {
9437 flow_dv_counter_release(dev, flow->counter);
9441 struct mlx5_flow_meter *fm;
9443 fm = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MTR],
9446 mlx5_flow_meter_detach(fm);
9449 while (flow->dev_handles) {
9450 uint32_t tmp_idx = flow->dev_handles;
9452 dev_handle = mlx5_ipool_get(priv->sh->ipool
9453 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
9456 flow->dev_handles = dev_handle->next.next;
9457 if (dev_handle->dvh.matcher)
9458 flow_dv_matcher_release(dev, dev_handle);
9459 if (dev_handle->dvh.rix_encap_decap)
9460 flow_dv_encap_decap_resource_release(dev, dev_handle);
9461 if (dev_handle->dvh.modify_hdr)
9462 flow_dv_modify_hdr_resource_release(dev, dev_handle);
9463 if (dev_handle->dvh.rix_push_vlan)
9464 flow_dv_push_vlan_action_resource_release(dev,
9466 if (dev_handle->dvh.rix_tag)
9467 flow_dv_tag_release(dev,
9468 dev_handle->dvh.rix_tag);
9469 flow_dv_fate_resource_release(dev, dev_handle);
9470 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9476 * Query a dv flow rule for its statistics via devx.
9479 * Pointer to Ethernet device.
9481 * Pointer to the sub flow.
9483 * data retrieved by the query.
9485 * Perform verbose error reporting if not NULL.
9488 * 0 on success, a negative errno value otherwise and rte_errno is set.
9491 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
9492 void *data, struct rte_flow_error *error)
9494 struct mlx5_priv *priv = dev->data->dev_private;
9495 struct rte_flow_query_count *qc = data;
9497 if (!priv->config.devx)
9498 return rte_flow_error_set(error, ENOTSUP,
9499 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9501 "counters are not supported");
9502 if (flow->counter) {
9503 uint64_t pkts, bytes;
9504 struct mlx5_flow_counter *cnt;
9506 cnt = flow_dv_counter_get_by_idx(dev, flow->counter,
9508 int err = _flow_dv_query_count(dev, flow->counter, &pkts,
9512 return rte_flow_error_set(error, -err,
9513 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9514 NULL, "cannot read counters");
9517 qc->hits = pkts - cnt->hits;
9518 qc->bytes = bytes - cnt->bytes;
9525 return rte_flow_error_set(error, EINVAL,
9526 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9528 "counters are not available");
9534 * @see rte_flow_query()
9538 flow_dv_query(struct rte_eth_dev *dev,
9539 struct rte_flow *flow __rte_unused,
9540 const struct rte_flow_action *actions __rte_unused,
9541 void *data __rte_unused,
9542 struct rte_flow_error *error __rte_unused)
9546 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
9547 switch (actions->type) {
9548 case RTE_FLOW_ACTION_TYPE_VOID:
9550 case RTE_FLOW_ACTION_TYPE_COUNT:
9551 ret = flow_dv_query_count(dev, flow, data, error);
9554 return rte_flow_error_set(error, ENOTSUP,
9555 RTE_FLOW_ERROR_TYPE_ACTION,
9557 "action not supported");
9564 * Destroy the meter table set.
9565 * Lock free, (mutex should be acquired by caller).
9568 * Pointer to Ethernet device.
9570 * Pointer to the meter table set.
9576 flow_dv_destroy_mtr_tbl(struct rte_eth_dev *dev,
9577 struct mlx5_meter_domains_infos *tbl)
9579 struct mlx5_priv *priv = dev->data->dev_private;
9580 struct mlx5_meter_domains_infos *mtd =
9581 (struct mlx5_meter_domains_infos *)tbl;
9583 if (!mtd || !priv->config.dv_flow_en)
9585 if (mtd->ingress.policer_rules[RTE_MTR_DROPPED])
9586 claim_zero(mlx5_flow_os_destroy_flow
9587 (mtd->ingress.policer_rules[RTE_MTR_DROPPED]));
9588 if (mtd->egress.policer_rules[RTE_MTR_DROPPED])
9589 claim_zero(mlx5_flow_os_destroy_flow
9590 (mtd->egress.policer_rules[RTE_MTR_DROPPED]));
9591 if (mtd->transfer.policer_rules[RTE_MTR_DROPPED])
9592 claim_zero(mlx5_flow_os_destroy_flow
9593 (mtd->transfer.policer_rules[RTE_MTR_DROPPED]));
9594 if (mtd->egress.color_matcher)
9595 claim_zero(mlx5_flow_os_destroy_flow_matcher
9596 (mtd->egress.color_matcher));
9597 if (mtd->egress.any_matcher)
9598 claim_zero(mlx5_flow_os_destroy_flow_matcher
9599 (mtd->egress.any_matcher));
9600 if (mtd->egress.tbl)
9601 flow_dv_tbl_resource_release(dev, mtd->egress.tbl);
9602 if (mtd->egress.sfx_tbl)
9603 flow_dv_tbl_resource_release(dev, mtd->egress.sfx_tbl);
9604 if (mtd->ingress.color_matcher)
9605 claim_zero(mlx5_flow_os_destroy_flow_matcher
9606 (mtd->ingress.color_matcher));
9607 if (mtd->ingress.any_matcher)
9608 claim_zero(mlx5_flow_os_destroy_flow_matcher
9609 (mtd->ingress.any_matcher));
9610 if (mtd->ingress.tbl)
9611 flow_dv_tbl_resource_release(dev, mtd->ingress.tbl);
9612 if (mtd->ingress.sfx_tbl)
9613 flow_dv_tbl_resource_release(dev, mtd->ingress.sfx_tbl);
9614 if (mtd->transfer.color_matcher)
9615 claim_zero(mlx5_flow_os_destroy_flow_matcher
9616 (mtd->transfer.color_matcher));
9617 if (mtd->transfer.any_matcher)
9618 claim_zero(mlx5_flow_os_destroy_flow_matcher
9619 (mtd->transfer.any_matcher));
9620 if (mtd->transfer.tbl)
9621 flow_dv_tbl_resource_release(dev, mtd->transfer.tbl);
9622 if (mtd->transfer.sfx_tbl)
9623 flow_dv_tbl_resource_release(dev, mtd->transfer.sfx_tbl);
9625 claim_zero(mlx5_flow_os_destroy_flow_action(mtd->drop_actn));
9630 /* Number of meter flow actions, count and jump or count and drop. */
9631 #define METER_ACTIONS 2
9634 * Create specify domain meter table and suffix table.
9637 * Pointer to Ethernet device.
9638 * @param[in,out] mtb
9639 * Pointer to DV meter table set.
9642 * @param[in] transfer
9644 * @param[in] color_reg_c_idx
9645 * Reg C index for color match.
9648 * 0 on success, -1 otherwise and rte_errno is set.
9651 flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
9652 struct mlx5_meter_domains_infos *mtb,
9653 uint8_t egress, uint8_t transfer,
9654 uint32_t color_reg_c_idx)
9656 struct mlx5_priv *priv = dev->data->dev_private;
9657 struct mlx5_dev_ctx_shared *sh = priv->sh;
9658 struct mlx5_flow_dv_match_params mask = {
9659 .size = sizeof(mask.buf),
9661 struct mlx5_flow_dv_match_params value = {
9662 .size = sizeof(value.buf),
9664 struct mlx5dv_flow_matcher_attr dv_attr = {
9665 .type = IBV_FLOW_ATTR_NORMAL,
9667 .match_criteria_enable = 0,
9668 .match_mask = (void *)&mask,
9670 void *actions[METER_ACTIONS];
9671 struct mlx5_meter_domain_info *dtb;
9672 struct rte_flow_error error;
9677 dtb = &mtb->transfer;
9681 dtb = &mtb->ingress;
9682 /* Create the meter table with METER level. */
9683 dtb->tbl = flow_dv_tbl_resource_get(dev, MLX5_FLOW_TABLE_LEVEL_METER,
9684 egress, transfer, &error);
9686 DRV_LOG(ERR, "Failed to create meter policer table.");
9689 /* Create the meter suffix table with SUFFIX level. */
9690 dtb->sfx_tbl = flow_dv_tbl_resource_get(dev,
9691 MLX5_FLOW_TABLE_LEVEL_SUFFIX,
9692 egress, transfer, &error);
9693 if (!dtb->sfx_tbl) {
9694 DRV_LOG(ERR, "Failed to create meter suffix table.");
9697 /* Create matchers, Any and Color. */
9698 dv_attr.priority = 3;
9699 dv_attr.match_criteria_enable = 0;
9700 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, dtb->tbl->obj,
9703 DRV_LOG(ERR, "Failed to create meter"
9704 " policer default matcher.");
9707 dv_attr.priority = 0;
9708 dv_attr.match_criteria_enable =
9709 1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
9710 flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
9711 rte_col_2_mlx5_col(RTE_COLORS), UINT8_MAX);
9712 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, dtb->tbl->obj,
9713 &dtb->color_matcher);
9715 DRV_LOG(ERR, "Failed to create meter policer color matcher.");
9718 if (mtb->count_actns[RTE_MTR_DROPPED])
9719 actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
9720 actions[i++] = mtb->drop_actn;
9721 /* Default rule: lowest priority, match any, actions: drop. */
9722 ret = mlx5_flow_os_create_flow(dtb->any_matcher, (void *)&value, i,
9724 &dtb->policer_rules[RTE_MTR_DROPPED]);
9726 DRV_LOG(ERR, "Failed to create meter policer drop rule.");
9735 * Create the needed meter and suffix tables.
9736 * Lock free, (mutex should be acquired by caller).
9739 * Pointer to Ethernet device.
9741 * Pointer to the flow meter.
9744 * Pointer to table set on success, NULL otherwise and rte_errno is set.
9746 static struct mlx5_meter_domains_infos *
9747 flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
9748 const struct mlx5_flow_meter *fm)
9750 struct mlx5_priv *priv = dev->data->dev_private;
9751 struct mlx5_meter_domains_infos *mtb;
9755 if (!priv->mtr_en) {
9756 rte_errno = ENOTSUP;
9759 mtb = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*mtb), 0, SOCKET_ID_ANY);
9761 DRV_LOG(ERR, "Failed to allocate memory for meter.");
9764 /* Create meter count actions */
9765 for (i = 0; i <= RTE_MTR_DROPPED; i++) {
9766 struct mlx5_flow_counter *cnt;
9767 if (!fm->policer_stats.cnt[i])
9769 cnt = flow_dv_counter_get_by_idx(dev,
9770 fm->policer_stats.cnt[i], NULL);
9771 mtb->count_actns[i] = cnt->action;
9773 /* Create drop action. */
9774 ret = mlx5_flow_os_create_flow_action_drop(&mtb->drop_actn);
9776 DRV_LOG(ERR, "Failed to create drop action.");
9779 /* Egress meter table. */
9780 ret = flow_dv_prepare_mtr_tables(dev, mtb, 1, 0, priv->mtr_color_reg);
9782 DRV_LOG(ERR, "Failed to prepare egress meter table.");
9785 /* Ingress meter table. */
9786 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 0, priv->mtr_color_reg);
9788 DRV_LOG(ERR, "Failed to prepare ingress meter table.");
9791 /* FDB meter table. */
9792 if (priv->config.dv_esw_en) {
9793 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 1,
9794 priv->mtr_color_reg);
9796 DRV_LOG(ERR, "Failed to prepare fdb meter table.");
9802 flow_dv_destroy_mtr_tbl(dev, mtb);
9807 * Destroy domain policer rule.
9810 * Pointer to domain table.
9813 flow_dv_destroy_domain_policer_rule(struct mlx5_meter_domain_info *dt)
9817 for (i = 0; i < RTE_MTR_DROPPED; i++) {
9818 if (dt->policer_rules[i]) {
9819 claim_zero(mlx5_flow_os_destroy_flow
9820 (dt->policer_rules[i]));
9821 dt->policer_rules[i] = NULL;
9824 if (dt->jump_actn) {
9825 claim_zero(mlx5_flow_os_destroy_flow_action(dt->jump_actn));
9826 dt->jump_actn = NULL;
9831 * Destroy policer rules.
9834 * Pointer to Ethernet device.
9836 * Pointer to flow meter structure.
9838 * Pointer to flow attributes.
9844 flow_dv_destroy_policer_rules(struct rte_eth_dev *dev __rte_unused,
9845 const struct mlx5_flow_meter *fm,
9846 const struct rte_flow_attr *attr)
9848 struct mlx5_meter_domains_infos *mtb = fm ? fm->mfts : NULL;
9853 flow_dv_destroy_domain_policer_rule(&mtb->egress);
9855 flow_dv_destroy_domain_policer_rule(&mtb->ingress);
9857 flow_dv_destroy_domain_policer_rule(&mtb->transfer);
9862 * Create specify domain meter policer rule.
9865 * Pointer to flow meter structure.
9867 * Pointer to DV meter table set.
9868 * @param[in] mtr_reg_c
9869 * Color match REG_C.
9872 * 0 on success, -1 otherwise.
9875 flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
9876 struct mlx5_meter_domain_info *dtb,
9879 struct mlx5_flow_dv_match_params matcher = {
9880 .size = sizeof(matcher.buf),
9882 struct mlx5_flow_dv_match_params value = {
9883 .size = sizeof(value.buf),
9885 struct mlx5_meter_domains_infos *mtb = fm->mfts;
9886 void *actions[METER_ACTIONS];
9890 /* Create jump action. */
9891 if (!dtb->jump_actn)
9892 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
9893 (dtb->sfx_tbl->obj, &dtb->jump_actn);
9895 DRV_LOG(ERR, "Failed to create policer jump action.");
9898 for (i = 0; i < RTE_MTR_DROPPED; i++) {
9901 flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
9902 rte_col_2_mlx5_col(i), UINT8_MAX);
9903 if (mtb->count_actns[i])
9904 actions[j++] = mtb->count_actns[i];
9905 if (fm->action[i] == MTR_POLICER_ACTION_DROP)
9906 actions[j++] = mtb->drop_actn;
9908 actions[j++] = dtb->jump_actn;
9909 ret = mlx5_flow_os_create_flow(dtb->color_matcher,
9910 (void *)&value, j, actions,
9911 &dtb->policer_rules[i]);
9913 DRV_LOG(ERR, "Failed to create policer rule.");
9924 * Create policer rules.
9927 * Pointer to Ethernet device.
9929 * Pointer to flow meter structure.
9931 * Pointer to flow attributes.
9934 * 0 on success, -1 otherwise.
9937 flow_dv_create_policer_rules(struct rte_eth_dev *dev,
9938 struct mlx5_flow_meter *fm,
9939 const struct rte_flow_attr *attr)
9941 struct mlx5_priv *priv = dev->data->dev_private;
9942 struct mlx5_meter_domains_infos *mtb = fm->mfts;
9946 ret = flow_dv_create_policer_forward_rule(fm, &mtb->egress,
9947 priv->mtr_color_reg);
9949 DRV_LOG(ERR, "Failed to create egress policer.");
9953 if (attr->ingress) {
9954 ret = flow_dv_create_policer_forward_rule(fm, &mtb->ingress,
9955 priv->mtr_color_reg);
9957 DRV_LOG(ERR, "Failed to create ingress policer.");
9961 if (attr->transfer) {
9962 ret = flow_dv_create_policer_forward_rule(fm, &mtb->transfer,
9963 priv->mtr_color_reg);
9965 DRV_LOG(ERR, "Failed to create transfer policer.");
9971 flow_dv_destroy_policer_rules(dev, fm, attr);
9976 * Query a devx counter.
9979 * Pointer to the Ethernet device structure.
9981 * Index to the flow counter.
9983 * Set to clear the counter statistics.
9985 * The statistics value of packets.
9987 * The statistics value of bytes.
9990 * 0 on success, otherwise return -1.
9993 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
9994 uint64_t *pkts, uint64_t *bytes)
9996 struct mlx5_priv *priv = dev->data->dev_private;
9997 struct mlx5_flow_counter *cnt;
9998 uint64_t inn_pkts, inn_bytes;
10001 if (!priv->config.devx)
10004 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
10007 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
10008 *pkts = inn_pkts - cnt->hits;
10009 *bytes = inn_bytes - cnt->bytes;
10011 cnt->hits = inn_pkts;
10012 cnt->bytes = inn_bytes;
10018 * Get aged-out flows.
10021 * Pointer to the Ethernet device structure.
10022 * @param[in] context
10023 * The address of an array of pointers to the aged-out flows contexts.
10024 * @param[in] nb_contexts
10025 * The length of context array pointers.
10026 * @param[out] error
10027 * Perform verbose error reporting if not NULL. Initialized in case of
10031 * how many contexts get in success, otherwise negative errno value.
10032 * if nb_contexts is 0, return the amount of all aged contexts.
10033 * if nb_contexts is not 0 , return the amount of aged flows reported
10034 * in the context array.
10035 * @note: only stub for now
10038 flow_get_aged_flows(struct rte_eth_dev *dev,
10040 uint32_t nb_contexts,
10041 struct rte_flow_error *error)
10043 struct mlx5_priv *priv = dev->data->dev_private;
10044 struct mlx5_age_info *age_info;
10045 struct mlx5_age_param *age_param;
10046 struct mlx5_flow_counter *counter;
10049 if (nb_contexts && !context)
10050 return rte_flow_error_set(error, EINVAL,
10051 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10053 "Should assign at least one flow or"
10054 " context to get if nb_contexts != 0");
10055 age_info = GET_PORT_AGE_INFO(priv);
10056 rte_spinlock_lock(&age_info->aged_sl);
10057 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
10060 age_param = MLX5_CNT_TO_AGE(counter);
10061 context[nb_flows - 1] = age_param->context;
10062 if (!(--nb_contexts))
10066 rte_spinlock_unlock(&age_info->aged_sl);
10067 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
10072 * Mutex-protected thunk to lock-free __flow_dv_translate().
10075 flow_dv_translate(struct rte_eth_dev *dev,
10076 struct mlx5_flow *dev_flow,
10077 const struct rte_flow_attr *attr,
10078 const struct rte_flow_item items[],
10079 const struct rte_flow_action actions[],
10080 struct rte_flow_error *error)
10084 flow_dv_shared_lock(dev);
10085 ret = __flow_dv_translate(dev, dev_flow, attr, items, actions, error);
10086 flow_dv_shared_unlock(dev);
10091 * Mutex-protected thunk to lock-free __flow_dv_apply().
10094 flow_dv_apply(struct rte_eth_dev *dev,
10095 struct rte_flow *flow,
10096 struct rte_flow_error *error)
10100 flow_dv_shared_lock(dev);
10101 ret = __flow_dv_apply(dev, flow, error);
10102 flow_dv_shared_unlock(dev);
10107 * Mutex-protected thunk to lock-free __flow_dv_remove().
10110 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
10112 flow_dv_shared_lock(dev);
10113 __flow_dv_remove(dev, flow);
10114 flow_dv_shared_unlock(dev);
10118 * Mutex-protected thunk to lock-free __flow_dv_destroy().
10121 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
10123 flow_dv_shared_lock(dev);
10124 __flow_dv_destroy(dev, flow);
10125 flow_dv_shared_unlock(dev);
10129 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
10132 flow_dv_counter_allocate(struct rte_eth_dev *dev)
10136 flow_dv_shared_lock(dev);
10137 cnt = flow_dv_counter_alloc(dev, 0, 0, 1, 0);
10138 flow_dv_shared_unlock(dev);
10143 * Mutex-protected thunk to lock-free flow_dv_counter_release().
10146 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
10148 flow_dv_shared_lock(dev);
10149 flow_dv_counter_release(dev, cnt);
10150 flow_dv_shared_unlock(dev);
10153 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
10154 .validate = flow_dv_validate,
10155 .prepare = flow_dv_prepare,
10156 .translate = flow_dv_translate,
10157 .apply = flow_dv_apply,
10158 .remove = flow_dv_remove,
10159 .destroy = flow_dv_destroy,
10160 .query = flow_dv_query,
10161 .create_mtr_tbls = flow_dv_create_mtr_tbl,
10162 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbl,
10163 .create_policer_rules = flow_dv_create_policer_rules,
10164 .destroy_policer_rules = flow_dv_destroy_policer_rules,
10165 .counter_alloc = flow_dv_counter_allocate,
10166 .counter_free = flow_dv_counter_free,
10167 .counter_query = flow_dv_counter_query,
10168 .get_aged_flows = flow_get_aged_flows,
10171 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */