1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd
11 #include <rte_common.h>
12 #include <rte_ether.h>
13 #include <ethdev_driver.h>
15 #include <rte_flow_driver.h>
16 #include <rte_malloc.h>
17 #include <rte_cycles.h>
18 #include <rte_bus_pci.h>
21 #include <rte_vxlan.h>
23 #include <rte_eal_paging.h>
26 #include <rte_mtr_driver.h>
27 #include <rte_tailq.h>
29 #include <mlx5_glue.h>
30 #include <mlx5_devx_cmds.h>
32 #include <mlx5_malloc.h>
34 #include "mlx5_defs.h"
36 #include "mlx5_common_os.h"
37 #include "mlx5_flow.h"
38 #include "mlx5_flow_os.h"
41 #include "rte_pmd_mlx5.h"
43 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
45 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
46 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
49 #ifndef HAVE_MLX5DV_DR_ESWITCH
50 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
51 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
55 #ifndef HAVE_MLX5DV_DR
56 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
59 /* VLAN header definitions */
60 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
61 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
62 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
63 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
64 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
79 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
80 struct mlx5_flow_tbl_resource *tbl);
83 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
84 uint32_t encap_decap_idx);
87 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
90 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
93 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
97 flow_dv_get_esw_manager_vport_id(struct rte_eth_dev *dev)
99 struct mlx5_priv *priv = dev->data->dev_private;
101 if (priv->pci_dev == NULL)
103 switch (priv->pci_dev->id.device_id) {
104 case PCI_DEVICE_ID_MELLANOX_CONNECTX5BF:
105 case PCI_DEVICE_ID_MELLANOX_CONNECTX6DXBF:
106 case PCI_DEVICE_ID_MELLANOX_CONNECTX7BF:
107 return (int16_t)0xfffe;
114 * Initialize flow attributes structure according to flow items' types.
116 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
117 * mode. For tunnel mode, the items to be modified are the outermost ones.
120 * Pointer to item specification.
122 * Pointer to flow attributes structure.
123 * @param[in] dev_flow
124 * Pointer to the sub flow.
125 * @param[in] tunnel_decap
126 * Whether action is after tunnel decapsulation.
129 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
130 struct mlx5_flow *dev_flow, bool tunnel_decap)
132 uint64_t layers = dev_flow->handle->layers;
135 * If layers is already initialized, it means this dev_flow is the
136 * suffix flow, the layers flags is set by the prefix flow. Need to
137 * use the layer flags from prefix flow as the suffix flow may not
138 * have the user defined items as the flow is split.
141 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
143 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
145 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
147 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
152 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
153 uint8_t next_protocol = 0xff;
154 switch (item->type) {
155 case RTE_FLOW_ITEM_TYPE_GRE:
156 case RTE_FLOW_ITEM_TYPE_NVGRE:
157 case RTE_FLOW_ITEM_TYPE_VXLAN:
158 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
159 case RTE_FLOW_ITEM_TYPE_GENEVE:
160 case RTE_FLOW_ITEM_TYPE_MPLS:
164 case RTE_FLOW_ITEM_TYPE_IPV4:
167 if (item->mask != NULL &&
168 ((const struct rte_flow_item_ipv4 *)
169 item->mask)->hdr.next_proto_id)
171 ((const struct rte_flow_item_ipv4 *)
172 (item->spec))->hdr.next_proto_id &
173 ((const struct rte_flow_item_ipv4 *)
174 (item->mask))->hdr.next_proto_id;
175 if ((next_protocol == IPPROTO_IPIP ||
176 next_protocol == IPPROTO_IPV6) && tunnel_decap)
179 case RTE_FLOW_ITEM_TYPE_IPV6:
182 if (item->mask != NULL &&
183 ((const struct rte_flow_item_ipv6 *)
184 item->mask)->hdr.proto)
186 ((const struct rte_flow_item_ipv6 *)
187 (item->spec))->hdr.proto &
188 ((const struct rte_flow_item_ipv6 *)
189 (item->mask))->hdr.proto;
190 if ((next_protocol == IPPROTO_IPIP ||
191 next_protocol == IPPROTO_IPV6) && tunnel_decap)
194 case RTE_FLOW_ITEM_TYPE_UDP:
198 case RTE_FLOW_ITEM_TYPE_TCP:
210 * Convert rte_mtr_color to mlx5 color.
219 rte_col_2_mlx5_col(enum rte_color rcol)
222 case RTE_COLOR_GREEN:
223 return MLX5_FLOW_COLOR_GREEN;
224 case RTE_COLOR_YELLOW:
225 return MLX5_FLOW_COLOR_YELLOW;
227 return MLX5_FLOW_COLOR_RED;
231 return MLX5_FLOW_COLOR_UNDEFINED;
234 struct field_modify_info {
235 uint32_t size; /* Size of field in protocol header, in bytes. */
236 uint32_t offset; /* Offset of field in protocol header, in bytes. */
237 enum mlx5_modification_field id;
240 struct field_modify_info modify_eth[] = {
241 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
242 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
243 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
244 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
248 struct field_modify_info modify_vlan_out_first_vid[] = {
249 /* Size in bits !!! */
250 {12, 0, MLX5_MODI_OUT_FIRST_VID},
254 struct field_modify_info modify_ipv4[] = {
255 {1, 1, MLX5_MODI_OUT_IP_DSCP},
256 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
257 {4, 12, MLX5_MODI_OUT_SIPV4},
258 {4, 16, MLX5_MODI_OUT_DIPV4},
262 struct field_modify_info modify_ipv6[] = {
263 {1, 0, MLX5_MODI_OUT_IP_DSCP},
264 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
265 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
266 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
267 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
268 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
269 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
270 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
271 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
272 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
276 struct field_modify_info modify_udp[] = {
277 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
278 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
282 struct field_modify_info modify_tcp[] = {
283 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
284 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
285 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
286 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
291 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
292 uint8_t next_protocol, uint64_t *item_flags,
295 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
296 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
297 if (next_protocol == IPPROTO_IPIP) {
298 *item_flags |= MLX5_FLOW_LAYER_IPIP;
301 if (next_protocol == IPPROTO_IPV6) {
302 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
307 static inline struct mlx5_hlist *
308 flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, struct mlx5_hlist **phl,
309 const char *name, uint32_t size, bool direct_key,
310 bool lcores_share, void *ctx,
311 mlx5_list_create_cb cb_create,
312 mlx5_list_match_cb cb_match,
313 mlx5_list_remove_cb cb_remove,
314 mlx5_list_clone_cb cb_clone,
315 mlx5_list_clone_free_cb cb_clone_free,
316 struct rte_flow_error *error)
318 struct mlx5_hlist *hl;
319 struct mlx5_hlist *expected = NULL;
320 char s[MLX5_NAME_SIZE];
322 hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
325 snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
326 hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
327 ctx, cb_create, cb_match, cb_remove, cb_clone,
330 DRV_LOG(ERR, "%s hash creation failed", name);
331 rte_flow_error_set(error, ENOMEM,
332 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
333 "cannot allocate resource memory");
336 if (!__atomic_compare_exchange_n(phl, &expected, hl, false,
339 mlx5_hlist_destroy(hl);
340 hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
345 /* Update VLAN's VID/PCP based on input rte_flow_action.
348 * Pointer to struct rte_flow_action.
350 * Pointer to struct rte_vlan_hdr.
353 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
354 struct rte_vlan_hdr *vlan)
357 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
359 ((const struct rte_flow_action_of_set_vlan_pcp *)
360 action->conf)->vlan_pcp;
361 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
362 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
363 vlan->vlan_tci |= vlan_tci;
364 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
365 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
366 vlan->vlan_tci |= rte_be_to_cpu_16
367 (((const struct rte_flow_action_of_set_vlan_vid *)
368 action->conf)->vlan_vid);
373 * Fetch 1, 2, 3 or 4 byte field from the byte array
374 * and return as unsigned integer in host-endian format.
377 * Pointer to data array.
379 * Size of field to extract.
382 * converted field in host endian format.
384 static inline uint32_t
385 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
394 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
397 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
398 ret = (ret << 8) | *(data + sizeof(uint16_t));
401 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
412 * Convert modify-header action to DV specification.
414 * Data length of each action is determined by provided field description
415 * and the item mask. Data bit offset and width of each action is determined
416 * by provided item mask.
419 * Pointer to item specification.
421 * Pointer to field modification information.
422 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
423 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
424 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
426 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
427 * Negative offset value sets the same offset as source offset.
428 * size field is ignored, value is taken from source field.
429 * @param[in,out] resource
430 * Pointer to the modify-header resource.
432 * Type of modification.
434 * Pointer to the error structure.
437 * 0 on success, a negative errno value otherwise and rte_errno is set.
440 flow_dv_convert_modify_action(struct rte_flow_item *item,
441 struct field_modify_info *field,
442 struct field_modify_info *dcopy,
443 struct mlx5_flow_dv_modify_hdr_resource *resource,
444 uint32_t type, struct rte_flow_error *error)
446 uint32_t i = resource->actions_num;
447 struct mlx5_modification_cmd *actions = resource->actions;
448 uint32_t carry_b = 0;
451 * The item and mask are provided in big-endian format.
452 * The fields should be presented as in big-endian format either.
453 * Mask must be always present, it defines the actual field width.
455 MLX5_ASSERT(item->mask);
456 MLX5_ASSERT(field->size);
462 bool next_field = true;
463 bool next_dcopy = true;
465 if (i >= MLX5_MAX_MODIFY_NUM)
466 return rte_flow_error_set(error, EINVAL,
467 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
468 "too many items to modify");
469 /* Fetch variable byte size mask from the array. */
470 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
471 field->offset, field->size);
476 /* Deduce actual data width in bits from mask value. */
477 off_b = rte_bsf32(mask) + carry_b;
478 size_b = sizeof(uint32_t) * CHAR_BIT -
479 off_b - __builtin_clz(mask);
481 actions[i] = (struct mlx5_modification_cmd) {
485 .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
488 if (type == MLX5_MODIFICATION_TYPE_COPY) {
490 actions[i].dst_field = dcopy->id;
491 actions[i].dst_offset =
492 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
493 /* Convert entire record to big-endian format. */
494 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
496 * Destination field overflow. Copy leftovers of
497 * a source field to the next destination field.
500 if ((size_b > dcopy->size * CHAR_BIT - dcopy->offset) &&
503 dcopy->size * CHAR_BIT - dcopy->offset;
504 carry_b = actions[i].length;
508 * Not enough bits in a source filed to fill a
509 * destination field. Switch to the next source.
511 if ((size_b < dcopy->size * CHAR_BIT - dcopy->offset) &&
512 (size_b == field->size * CHAR_BIT - off_b)) {
514 field->size * CHAR_BIT - off_b;
515 dcopy->offset += actions[i].length;
521 MLX5_ASSERT(item->spec);
522 data = flow_dv_fetch_field((const uint8_t *)item->spec +
523 field->offset, field->size);
524 /* Shift out the trailing masked bits from data. */
525 data = (data & mask) >> off_b;
526 actions[i].data1 = rte_cpu_to_be_32(data);
528 /* Convert entire record to expected big-endian format. */
529 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
533 } while (field->size);
534 if (resource->actions_num == i)
535 return rte_flow_error_set(error, EINVAL,
536 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
537 "invalid modification flow item");
538 resource->actions_num = i;
543 * Convert modify-header set IPv4 address action to DV specification.
545 * @param[in,out] resource
546 * Pointer to the modify-header resource.
548 * Pointer to action specification.
550 * Pointer to the error structure.
553 * 0 on success, a negative errno value otherwise and rte_errno is set.
556 flow_dv_convert_action_modify_ipv4
557 (struct mlx5_flow_dv_modify_hdr_resource *resource,
558 const struct rte_flow_action *action,
559 struct rte_flow_error *error)
561 const struct rte_flow_action_set_ipv4 *conf =
562 (const struct rte_flow_action_set_ipv4 *)(action->conf);
563 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
564 struct rte_flow_item_ipv4 ipv4;
565 struct rte_flow_item_ipv4 ipv4_mask;
567 memset(&ipv4, 0, sizeof(ipv4));
568 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
569 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
570 ipv4.hdr.src_addr = conf->ipv4_addr;
571 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
573 ipv4.hdr.dst_addr = conf->ipv4_addr;
574 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
577 item.mask = &ipv4_mask;
578 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
579 MLX5_MODIFICATION_TYPE_SET, error);
583 * Convert modify-header set IPv6 address action to DV specification.
585 * @param[in,out] resource
586 * Pointer to the modify-header resource.
588 * Pointer to action specification.
590 * Pointer to the error structure.
593 * 0 on success, a negative errno value otherwise and rte_errno is set.
596 flow_dv_convert_action_modify_ipv6
597 (struct mlx5_flow_dv_modify_hdr_resource *resource,
598 const struct rte_flow_action *action,
599 struct rte_flow_error *error)
601 const struct rte_flow_action_set_ipv6 *conf =
602 (const struct rte_flow_action_set_ipv6 *)(action->conf);
603 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
604 struct rte_flow_item_ipv6 ipv6;
605 struct rte_flow_item_ipv6 ipv6_mask;
607 memset(&ipv6, 0, sizeof(ipv6));
608 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
609 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
610 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
611 sizeof(ipv6.hdr.src_addr));
612 memcpy(&ipv6_mask.hdr.src_addr,
613 &rte_flow_item_ipv6_mask.hdr.src_addr,
614 sizeof(ipv6.hdr.src_addr));
616 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
617 sizeof(ipv6.hdr.dst_addr));
618 memcpy(&ipv6_mask.hdr.dst_addr,
619 &rte_flow_item_ipv6_mask.hdr.dst_addr,
620 sizeof(ipv6.hdr.dst_addr));
623 item.mask = &ipv6_mask;
624 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
625 MLX5_MODIFICATION_TYPE_SET, error);
629 * Convert modify-header set MAC address action to DV specification.
631 * @param[in,out] resource
632 * Pointer to the modify-header resource.
634 * Pointer to action specification.
636 * Pointer to the error structure.
639 * 0 on success, a negative errno value otherwise and rte_errno is set.
642 flow_dv_convert_action_modify_mac
643 (struct mlx5_flow_dv_modify_hdr_resource *resource,
644 const struct rte_flow_action *action,
645 struct rte_flow_error *error)
647 const struct rte_flow_action_set_mac *conf =
648 (const struct rte_flow_action_set_mac *)(action->conf);
649 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
650 struct rte_flow_item_eth eth;
651 struct rte_flow_item_eth eth_mask;
653 memset(ð, 0, sizeof(eth));
654 memset(ð_mask, 0, sizeof(eth_mask));
655 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
656 memcpy(ð.src.addr_bytes, &conf->mac_addr,
657 sizeof(eth.src.addr_bytes));
658 memcpy(ð_mask.src.addr_bytes,
659 &rte_flow_item_eth_mask.src.addr_bytes,
660 sizeof(eth_mask.src.addr_bytes));
662 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
663 sizeof(eth.dst.addr_bytes));
664 memcpy(ð_mask.dst.addr_bytes,
665 &rte_flow_item_eth_mask.dst.addr_bytes,
666 sizeof(eth_mask.dst.addr_bytes));
669 item.mask = ð_mask;
670 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
671 MLX5_MODIFICATION_TYPE_SET, error);
675 * Convert modify-header set VLAN VID action to DV specification.
677 * @param[in,out] resource
678 * Pointer to the modify-header resource.
680 * Pointer to action specification.
682 * Pointer to the error structure.
685 * 0 on success, a negative errno value otherwise and rte_errno is set.
688 flow_dv_convert_action_modify_vlan_vid
689 (struct mlx5_flow_dv_modify_hdr_resource *resource,
690 const struct rte_flow_action *action,
691 struct rte_flow_error *error)
693 const struct rte_flow_action_of_set_vlan_vid *conf =
694 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
695 int i = resource->actions_num;
696 struct mlx5_modification_cmd *actions = resource->actions;
697 struct field_modify_info *field = modify_vlan_out_first_vid;
699 if (i >= MLX5_MAX_MODIFY_NUM)
700 return rte_flow_error_set(error, EINVAL,
701 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
702 "too many items to modify");
703 actions[i] = (struct mlx5_modification_cmd) {
704 .action_type = MLX5_MODIFICATION_TYPE_SET,
706 .length = field->size,
707 .offset = field->offset,
709 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
710 actions[i].data1 = conf->vlan_vid;
711 actions[i].data1 = actions[i].data1 << 16;
712 resource->actions_num = ++i;
717 * Convert modify-header set TP action to DV specification.
719 * @param[in,out] resource
720 * Pointer to the modify-header resource.
722 * Pointer to action specification.
724 * Pointer to rte_flow_item objects list.
726 * Pointer to flow attributes structure.
727 * @param[in] dev_flow
728 * Pointer to the sub flow.
729 * @param[in] tunnel_decap
730 * Whether action is after tunnel decapsulation.
732 * Pointer to the error structure.
735 * 0 on success, a negative errno value otherwise and rte_errno is set.
738 flow_dv_convert_action_modify_tp
739 (struct mlx5_flow_dv_modify_hdr_resource *resource,
740 const struct rte_flow_action *action,
741 const struct rte_flow_item *items,
742 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
743 bool tunnel_decap, struct rte_flow_error *error)
745 const struct rte_flow_action_set_tp *conf =
746 (const struct rte_flow_action_set_tp *)(action->conf);
747 struct rte_flow_item item;
748 struct rte_flow_item_udp udp;
749 struct rte_flow_item_udp udp_mask;
750 struct rte_flow_item_tcp tcp;
751 struct rte_flow_item_tcp tcp_mask;
752 struct field_modify_info *field;
755 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
757 memset(&udp, 0, sizeof(udp));
758 memset(&udp_mask, 0, sizeof(udp_mask));
759 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
760 udp.hdr.src_port = conf->port;
761 udp_mask.hdr.src_port =
762 rte_flow_item_udp_mask.hdr.src_port;
764 udp.hdr.dst_port = conf->port;
765 udp_mask.hdr.dst_port =
766 rte_flow_item_udp_mask.hdr.dst_port;
768 item.type = RTE_FLOW_ITEM_TYPE_UDP;
770 item.mask = &udp_mask;
773 MLX5_ASSERT(attr->tcp);
774 memset(&tcp, 0, sizeof(tcp));
775 memset(&tcp_mask, 0, sizeof(tcp_mask));
776 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
777 tcp.hdr.src_port = conf->port;
778 tcp_mask.hdr.src_port =
779 rte_flow_item_tcp_mask.hdr.src_port;
781 tcp.hdr.dst_port = conf->port;
782 tcp_mask.hdr.dst_port =
783 rte_flow_item_tcp_mask.hdr.dst_port;
785 item.type = RTE_FLOW_ITEM_TYPE_TCP;
787 item.mask = &tcp_mask;
790 return flow_dv_convert_modify_action(&item, field, NULL, resource,
791 MLX5_MODIFICATION_TYPE_SET, error);
795 * Convert modify-header set TTL action to DV specification.
797 * @param[in,out] resource
798 * Pointer to the modify-header resource.
800 * Pointer to action specification.
802 * Pointer to rte_flow_item objects list.
804 * Pointer to flow attributes structure.
805 * @param[in] dev_flow
806 * Pointer to the sub flow.
807 * @param[in] tunnel_decap
808 * Whether action is after tunnel decapsulation.
810 * Pointer to the error structure.
813 * 0 on success, a negative errno value otherwise and rte_errno is set.
816 flow_dv_convert_action_modify_ttl
817 (struct mlx5_flow_dv_modify_hdr_resource *resource,
818 const struct rte_flow_action *action,
819 const struct rte_flow_item *items,
820 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
821 bool tunnel_decap, struct rte_flow_error *error)
823 const struct rte_flow_action_set_ttl *conf =
824 (const struct rte_flow_action_set_ttl *)(action->conf);
825 struct rte_flow_item item;
826 struct rte_flow_item_ipv4 ipv4;
827 struct rte_flow_item_ipv4 ipv4_mask;
828 struct rte_flow_item_ipv6 ipv6;
829 struct rte_flow_item_ipv6 ipv6_mask;
830 struct field_modify_info *field;
833 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
835 memset(&ipv4, 0, sizeof(ipv4));
836 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
837 ipv4.hdr.time_to_live = conf->ttl_value;
838 ipv4_mask.hdr.time_to_live = 0xFF;
839 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
841 item.mask = &ipv4_mask;
844 MLX5_ASSERT(attr->ipv6);
845 memset(&ipv6, 0, sizeof(ipv6));
846 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
847 ipv6.hdr.hop_limits = conf->ttl_value;
848 ipv6_mask.hdr.hop_limits = 0xFF;
849 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
851 item.mask = &ipv6_mask;
854 return flow_dv_convert_modify_action(&item, field, NULL, resource,
855 MLX5_MODIFICATION_TYPE_SET, error);
859 * Convert modify-header decrement TTL action to DV specification.
861 * @param[in,out] resource
862 * Pointer to the modify-header resource.
864 * Pointer to action specification.
866 * Pointer to rte_flow_item objects list.
868 * Pointer to flow attributes structure.
869 * @param[in] dev_flow
870 * Pointer to the sub flow.
871 * @param[in] tunnel_decap
872 * Whether action is after tunnel decapsulation.
874 * Pointer to the error structure.
877 * 0 on success, a negative errno value otherwise and rte_errno is set.
880 flow_dv_convert_action_modify_dec_ttl
881 (struct mlx5_flow_dv_modify_hdr_resource *resource,
882 const struct rte_flow_item *items,
883 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
884 bool tunnel_decap, struct rte_flow_error *error)
886 struct rte_flow_item item;
887 struct rte_flow_item_ipv4 ipv4;
888 struct rte_flow_item_ipv4 ipv4_mask;
889 struct rte_flow_item_ipv6 ipv6;
890 struct rte_flow_item_ipv6 ipv6_mask;
891 struct field_modify_info *field;
894 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
896 memset(&ipv4, 0, sizeof(ipv4));
897 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
898 ipv4.hdr.time_to_live = 0xFF;
899 ipv4_mask.hdr.time_to_live = 0xFF;
900 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
902 item.mask = &ipv4_mask;
905 MLX5_ASSERT(attr->ipv6);
906 memset(&ipv6, 0, sizeof(ipv6));
907 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
908 ipv6.hdr.hop_limits = 0xFF;
909 ipv6_mask.hdr.hop_limits = 0xFF;
910 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
912 item.mask = &ipv6_mask;
915 return flow_dv_convert_modify_action(&item, field, NULL, resource,
916 MLX5_MODIFICATION_TYPE_ADD, error);
920 * Convert modify-header increment/decrement TCP Sequence number
921 * to DV specification.
923 * @param[in,out] resource
924 * Pointer to the modify-header resource.
926 * Pointer to action specification.
928 * Pointer to the error structure.
931 * 0 on success, a negative errno value otherwise and rte_errno is set.
934 flow_dv_convert_action_modify_tcp_seq
935 (struct mlx5_flow_dv_modify_hdr_resource *resource,
936 const struct rte_flow_action *action,
937 struct rte_flow_error *error)
939 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
940 uint64_t value = rte_be_to_cpu_32(*conf);
941 struct rte_flow_item item;
942 struct rte_flow_item_tcp tcp;
943 struct rte_flow_item_tcp tcp_mask;
945 memset(&tcp, 0, sizeof(tcp));
946 memset(&tcp_mask, 0, sizeof(tcp_mask));
947 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
949 * The HW has no decrement operation, only increment operation.
950 * To simulate decrement X from Y using increment operation
951 * we need to add UINT32_MAX X times to Y.
952 * Each adding of UINT32_MAX decrements Y by 1.
955 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
956 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
957 item.type = RTE_FLOW_ITEM_TYPE_TCP;
959 item.mask = &tcp_mask;
960 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
961 MLX5_MODIFICATION_TYPE_ADD, error);
965 * Convert modify-header increment/decrement TCP Acknowledgment number
966 * to DV specification.
968 * @param[in,out] resource
969 * Pointer to the modify-header resource.
971 * Pointer to action specification.
973 * Pointer to the error structure.
976 * 0 on success, a negative errno value otherwise and rte_errno is set.
979 flow_dv_convert_action_modify_tcp_ack
980 (struct mlx5_flow_dv_modify_hdr_resource *resource,
981 const struct rte_flow_action *action,
982 struct rte_flow_error *error)
984 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
985 uint64_t value = rte_be_to_cpu_32(*conf);
986 struct rte_flow_item item;
987 struct rte_flow_item_tcp tcp;
988 struct rte_flow_item_tcp tcp_mask;
990 memset(&tcp, 0, sizeof(tcp));
991 memset(&tcp_mask, 0, sizeof(tcp_mask));
992 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
994 * The HW has no decrement operation, only increment operation.
995 * To simulate decrement X from Y using increment operation
996 * we need to add UINT32_MAX X times to Y.
997 * Each adding of UINT32_MAX decrements Y by 1.
1000 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
1001 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
1002 item.type = RTE_FLOW_ITEM_TYPE_TCP;
1004 item.mask = &tcp_mask;
1005 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
1006 MLX5_MODIFICATION_TYPE_ADD, error);
1009 static enum mlx5_modification_field reg_to_field[] = {
1010 [REG_NON] = MLX5_MODI_OUT_NONE,
1011 [REG_A] = MLX5_MODI_META_DATA_REG_A,
1012 [REG_B] = MLX5_MODI_META_DATA_REG_B,
1013 [REG_C_0] = MLX5_MODI_META_REG_C_0,
1014 [REG_C_1] = MLX5_MODI_META_REG_C_1,
1015 [REG_C_2] = MLX5_MODI_META_REG_C_2,
1016 [REG_C_3] = MLX5_MODI_META_REG_C_3,
1017 [REG_C_4] = MLX5_MODI_META_REG_C_4,
1018 [REG_C_5] = MLX5_MODI_META_REG_C_5,
1019 [REG_C_6] = MLX5_MODI_META_REG_C_6,
1020 [REG_C_7] = MLX5_MODI_META_REG_C_7,
1024 * Convert register set to DV specification.
1026 * @param[in,out] resource
1027 * Pointer to the modify-header resource.
1029 * Pointer to action specification.
1031 * Pointer to the error structure.
1034 * 0 on success, a negative errno value otherwise and rte_errno is set.
1037 flow_dv_convert_action_set_reg
1038 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1039 const struct rte_flow_action *action,
1040 struct rte_flow_error *error)
1042 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
1043 struct mlx5_modification_cmd *actions = resource->actions;
1044 uint32_t i = resource->actions_num;
1046 if (i >= MLX5_MAX_MODIFY_NUM)
1047 return rte_flow_error_set(error, EINVAL,
1048 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1049 "too many items to modify");
1050 MLX5_ASSERT(conf->id != REG_NON);
1051 MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
1052 actions[i] = (struct mlx5_modification_cmd) {
1053 .action_type = MLX5_MODIFICATION_TYPE_SET,
1054 .field = reg_to_field[conf->id],
1055 .offset = conf->offset,
1056 .length = conf->length,
1058 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1059 actions[i].data1 = rte_cpu_to_be_32(conf->data);
1061 resource->actions_num = i;
1066 * Convert SET_TAG action to DV specification.
1069 * Pointer to the rte_eth_dev structure.
1070 * @param[in,out] resource
1071 * Pointer to the modify-header resource.
1073 * Pointer to action specification.
1075 * Pointer to the error structure.
1078 * 0 on success, a negative errno value otherwise and rte_errno is set.
1081 flow_dv_convert_action_set_tag
1082 (struct rte_eth_dev *dev,
1083 struct mlx5_flow_dv_modify_hdr_resource *resource,
1084 const struct rte_flow_action_set_tag *conf,
1085 struct rte_flow_error *error)
1087 rte_be32_t data = rte_cpu_to_be_32(conf->data);
1088 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1089 struct rte_flow_item item = {
1093 struct field_modify_info reg_c_x[] = {
1096 enum mlx5_modification_field reg_type;
1099 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1102 MLX5_ASSERT(ret != REG_NON);
1103 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1104 reg_type = reg_to_field[ret];
1105 MLX5_ASSERT(reg_type > 0);
1106 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1107 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1108 MLX5_MODIFICATION_TYPE_SET, error);
1112 * Convert internal COPY_REG action to DV specification.
1115 * Pointer to the rte_eth_dev structure.
1116 * @param[in,out] res
1117 * Pointer to the modify-header resource.
1119 * Pointer to action specification.
1121 * Pointer to the error structure.
1124 * 0 on success, a negative errno value otherwise and rte_errno is set.
1127 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1128 struct mlx5_flow_dv_modify_hdr_resource *res,
1129 const struct rte_flow_action *action,
1130 struct rte_flow_error *error)
1132 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1133 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1134 struct rte_flow_item item = {
1138 struct field_modify_info reg_src[] = {
1139 {4, 0, reg_to_field[conf->src]},
1142 struct field_modify_info reg_dst = {
1144 .id = reg_to_field[conf->dst],
1146 /* Adjust reg_c[0] usage according to reported mask. */
1147 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1148 struct mlx5_priv *priv = dev->data->dev_private;
1149 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1151 MLX5_ASSERT(reg_c0);
1152 MLX5_ASSERT(priv->sh->config.dv_xmeta_en !=
1153 MLX5_XMETA_MODE_LEGACY);
1154 if (conf->dst == REG_C_0) {
1155 /* Copy to reg_c[0], within mask only. */
1156 reg_dst.offset = rte_bsf32(reg_c0);
1157 mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1160 mask = rte_cpu_to_be_32(reg_c0);
1163 return flow_dv_convert_modify_action(&item,
1164 reg_src, ®_dst, res,
1165 MLX5_MODIFICATION_TYPE_COPY,
1170 * Convert MARK action to DV specification. This routine is used
1171 * in extensive metadata only and requires metadata register to be
1172 * handled. In legacy mode hardware tag resource is engaged.
1175 * Pointer to the rte_eth_dev structure.
1177 * Pointer to MARK action specification.
1178 * @param[in,out] resource
1179 * Pointer to the modify-header resource.
1181 * Pointer to the error structure.
1184 * 0 on success, a negative errno value otherwise and rte_errno is set.
1187 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1188 const struct rte_flow_action_mark *conf,
1189 struct mlx5_flow_dv_modify_hdr_resource *resource,
1190 struct rte_flow_error *error)
1192 struct mlx5_priv *priv = dev->data->dev_private;
1193 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1194 priv->sh->dv_mark_mask);
1195 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1196 struct rte_flow_item item = {
1200 struct field_modify_info reg_c_x[] = {
1206 return rte_flow_error_set(error, EINVAL,
1207 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1208 NULL, "zero mark action mask");
1209 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1212 MLX5_ASSERT(reg > 0);
1213 if (reg == REG_C_0) {
1214 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1215 uint32_t shl_c0 = rte_bsf32(msk_c0);
1217 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1218 mask = rte_cpu_to_be_32(mask) & msk_c0;
1219 mask = rte_cpu_to_be_32(mask << shl_c0);
1221 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1222 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1223 MLX5_MODIFICATION_TYPE_SET, error);
1227 * Get metadata register index for specified steering domain.
1230 * Pointer to the rte_eth_dev structure.
1232 * Attributes of flow to determine steering domain.
1234 * Pointer to the error structure.
1237 * positive index on success, a negative errno value otherwise
1238 * and rte_errno is set.
1240 static enum modify_reg
1241 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1242 const struct rte_flow_attr *attr,
1243 struct rte_flow_error *error)
1246 mlx5_flow_get_reg_id(dev, attr->transfer ?
1250 MLX5_METADATA_RX, 0, error);
1252 return rte_flow_error_set(error,
1253 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1254 NULL, "unavailable "
1255 "metadata register");
1260 * Convert SET_META action to DV specification.
1263 * Pointer to the rte_eth_dev structure.
1264 * @param[in,out] resource
1265 * Pointer to the modify-header resource.
1267 * Attributes of flow that includes this item.
1269 * Pointer to action specification.
1271 * Pointer to the error structure.
1274 * 0 on success, a negative errno value otherwise and rte_errno is set.
1277 flow_dv_convert_action_set_meta
1278 (struct rte_eth_dev *dev,
1279 struct mlx5_flow_dv_modify_hdr_resource *resource,
1280 const struct rte_flow_attr *attr,
1281 const struct rte_flow_action_set_meta *conf,
1282 struct rte_flow_error *error)
1284 uint32_t mask = rte_cpu_to_be_32(conf->mask);
1285 uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1286 struct rte_flow_item item = {
1290 struct field_modify_info reg_c_x[] = {
1293 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1297 MLX5_ASSERT(reg != REG_NON);
1298 if (reg == REG_C_0) {
1299 struct mlx5_priv *priv = dev->data->dev_private;
1300 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1301 uint32_t shl_c0 = rte_bsf32(msk_c0);
1303 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1304 mask = rte_cpu_to_be_32(mask) & msk_c0;
1305 mask = rte_cpu_to_be_32(mask << shl_c0);
1307 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1308 /* The routine expects parameters in memory as big-endian ones. */
1309 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1310 MLX5_MODIFICATION_TYPE_SET, error);
1314 * Convert modify-header set IPv4 DSCP action to DV specification.
1316 * @param[in,out] resource
1317 * Pointer to the modify-header resource.
1319 * Pointer to action specification.
1321 * Pointer to the error structure.
1324 * 0 on success, a negative errno value otherwise and rte_errno is set.
1327 flow_dv_convert_action_modify_ipv4_dscp
1328 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1329 const struct rte_flow_action *action,
1330 struct rte_flow_error *error)
1332 const struct rte_flow_action_set_dscp *conf =
1333 (const struct rte_flow_action_set_dscp *)(action->conf);
1334 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1335 struct rte_flow_item_ipv4 ipv4;
1336 struct rte_flow_item_ipv4 ipv4_mask;
1338 memset(&ipv4, 0, sizeof(ipv4));
1339 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1340 ipv4.hdr.type_of_service = conf->dscp;
1341 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1343 item.mask = &ipv4_mask;
1344 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1345 MLX5_MODIFICATION_TYPE_SET, error);
1349 * Convert modify-header set IPv6 DSCP action to DV specification.
1351 * @param[in,out] resource
1352 * Pointer to the modify-header resource.
1354 * Pointer to action specification.
1356 * Pointer to the error structure.
1359 * 0 on success, a negative errno value otherwise and rte_errno is set.
1362 flow_dv_convert_action_modify_ipv6_dscp
1363 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1364 const struct rte_flow_action *action,
1365 struct rte_flow_error *error)
1367 const struct rte_flow_action_set_dscp *conf =
1368 (const struct rte_flow_action_set_dscp *)(action->conf);
1369 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1370 struct rte_flow_item_ipv6 ipv6;
1371 struct rte_flow_item_ipv6 ipv6_mask;
1373 memset(&ipv6, 0, sizeof(ipv6));
1374 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1376 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1377 * rdma-core only accept the DSCP bits byte aligned start from
1378 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1379 * bits in IPv6 case as rdma-core requires byte aligned value.
1381 ipv6.hdr.vtc_flow = conf->dscp;
1382 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1384 item.mask = &ipv6_mask;
1385 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1386 MLX5_MODIFICATION_TYPE_SET, error);
1390 mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1391 enum rte_flow_field_id field, int inherit,
1392 const struct rte_flow_attr *attr,
1393 struct rte_flow_error *error)
1395 struct mlx5_priv *priv = dev->data->dev_private;
1398 case RTE_FLOW_FIELD_START:
1400 case RTE_FLOW_FIELD_MAC_DST:
1401 case RTE_FLOW_FIELD_MAC_SRC:
1403 case RTE_FLOW_FIELD_VLAN_TYPE:
1405 case RTE_FLOW_FIELD_VLAN_ID:
1407 case RTE_FLOW_FIELD_MAC_TYPE:
1409 case RTE_FLOW_FIELD_IPV4_DSCP:
1411 case RTE_FLOW_FIELD_IPV4_TTL:
1413 case RTE_FLOW_FIELD_IPV4_SRC:
1414 case RTE_FLOW_FIELD_IPV4_DST:
1416 case RTE_FLOW_FIELD_IPV6_DSCP:
1418 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1420 case RTE_FLOW_FIELD_IPV6_SRC:
1421 case RTE_FLOW_FIELD_IPV6_DST:
1423 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1424 case RTE_FLOW_FIELD_TCP_PORT_DST:
1426 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1427 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1429 case RTE_FLOW_FIELD_TCP_FLAGS:
1431 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1432 case RTE_FLOW_FIELD_UDP_PORT_DST:
1434 case RTE_FLOW_FIELD_VXLAN_VNI:
1435 case RTE_FLOW_FIELD_GENEVE_VNI:
1437 case RTE_FLOW_FIELD_GTP_TEID:
1438 case RTE_FLOW_FIELD_TAG:
1440 case RTE_FLOW_FIELD_MARK:
1441 return __builtin_popcount(priv->sh->dv_mark_mask);
1442 case RTE_FLOW_FIELD_META:
1443 return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1444 __builtin_popcount(priv->sh->dv_meta_mask) : 32;
1445 case RTE_FLOW_FIELD_POINTER:
1446 case RTE_FLOW_FIELD_VALUE:
1447 return inherit < 0 ? 0 : inherit;
1455 mlx5_flow_field_id_to_modify_info
1456 (const struct rte_flow_action_modify_data *data,
1457 struct field_modify_info *info, uint32_t *mask,
1458 uint32_t width, struct rte_eth_dev *dev,
1459 const struct rte_flow_attr *attr, struct rte_flow_error *error)
1461 struct mlx5_priv *priv = dev->data->dev_private;
1465 switch (data->field) {
1466 case RTE_FLOW_FIELD_START:
1467 /* not supported yet */
1470 case RTE_FLOW_FIELD_MAC_DST:
1471 off = data->offset > 16 ? data->offset - 16 : 0;
1473 if (data->offset < 16) {
1474 info[idx] = (struct field_modify_info){2, 4,
1475 MLX5_MODI_OUT_DMAC_15_0};
1477 mask[1] = rte_cpu_to_be_16(0xffff >>
1481 mask[1] = RTE_BE16(0xffff);
1488 info[idx] = (struct field_modify_info){4, 0,
1489 MLX5_MODI_OUT_DMAC_47_16};
1490 mask[0] = rte_cpu_to_be_32((0xffffffff >>
1491 (32 - width)) << off);
1493 if (data->offset < 16)
1494 info[idx++] = (struct field_modify_info){2, 0,
1495 MLX5_MODI_OUT_DMAC_15_0};
1496 info[idx] = (struct field_modify_info){4, off,
1497 MLX5_MODI_OUT_DMAC_47_16};
1500 case RTE_FLOW_FIELD_MAC_SRC:
1501 off = data->offset > 16 ? data->offset - 16 : 0;
1503 if (data->offset < 16) {
1504 info[idx] = (struct field_modify_info){2, 4,
1505 MLX5_MODI_OUT_SMAC_15_0};
1507 mask[1] = rte_cpu_to_be_16(0xffff >>
1511 mask[1] = RTE_BE16(0xffff);
1518 info[idx] = (struct field_modify_info){4, 0,
1519 MLX5_MODI_OUT_SMAC_47_16};
1520 mask[0] = rte_cpu_to_be_32((0xffffffff >>
1521 (32 - width)) << off);
1523 if (data->offset < 16)
1524 info[idx++] = (struct field_modify_info){2, 0,
1525 MLX5_MODI_OUT_SMAC_15_0};
1526 info[idx] = (struct field_modify_info){4, off,
1527 MLX5_MODI_OUT_SMAC_47_16};
1530 case RTE_FLOW_FIELD_VLAN_TYPE:
1531 /* not supported yet */
1533 case RTE_FLOW_FIELD_VLAN_ID:
1534 info[idx] = (struct field_modify_info){2, 0,
1535 MLX5_MODI_OUT_FIRST_VID};
1537 mask[idx] = rte_cpu_to_be_16(0x0fff >> (12 - width));
1539 case RTE_FLOW_FIELD_MAC_TYPE:
1540 info[idx] = (struct field_modify_info){2, 0,
1541 MLX5_MODI_OUT_ETHERTYPE};
1543 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1545 case RTE_FLOW_FIELD_IPV4_DSCP:
1546 info[idx] = (struct field_modify_info){1, 0,
1547 MLX5_MODI_OUT_IP_DSCP};
1549 mask[idx] = 0x3f >> (6 - width);
1551 case RTE_FLOW_FIELD_IPV4_TTL:
1552 info[idx] = (struct field_modify_info){1, 0,
1553 MLX5_MODI_OUT_IPV4_TTL};
1555 mask[idx] = 0xff >> (8 - width);
1557 case RTE_FLOW_FIELD_IPV4_SRC:
1558 info[idx] = (struct field_modify_info){4, 0,
1559 MLX5_MODI_OUT_SIPV4};
1561 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1564 case RTE_FLOW_FIELD_IPV4_DST:
1565 info[idx] = (struct field_modify_info){4, 0,
1566 MLX5_MODI_OUT_DIPV4};
1568 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1571 case RTE_FLOW_FIELD_IPV6_DSCP:
1572 info[idx] = (struct field_modify_info){1, 0,
1573 MLX5_MODI_OUT_IP_DSCP};
1575 mask[idx] = 0x3f >> (6 - width);
1577 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1578 info[idx] = (struct field_modify_info){1, 0,
1579 MLX5_MODI_OUT_IPV6_HOPLIMIT};
1581 mask[idx] = 0xff >> (8 - width);
1583 case RTE_FLOW_FIELD_IPV6_SRC:
1585 if (data->offset < 32) {
1586 info[idx] = (struct field_modify_info){4, 12,
1587 MLX5_MODI_OUT_SIPV6_31_0};
1590 rte_cpu_to_be_32(0xffffffff >>
1594 mask[3] = RTE_BE32(0xffffffff);
1601 if (data->offset < 64) {
1602 info[idx] = (struct field_modify_info){4, 8,
1603 MLX5_MODI_OUT_SIPV6_63_32};
1606 rte_cpu_to_be_32(0xffffffff >>
1610 mask[2] = RTE_BE32(0xffffffff);
1617 if (data->offset < 96) {
1618 info[idx] = (struct field_modify_info){4, 4,
1619 MLX5_MODI_OUT_SIPV6_95_64};
1622 rte_cpu_to_be_32(0xffffffff >>
1626 mask[1] = RTE_BE32(0xffffffff);
1633 info[idx] = (struct field_modify_info){4, 0,
1634 MLX5_MODI_OUT_SIPV6_127_96};
1635 mask[0] = rte_cpu_to_be_32(0xffffffff >> (32 - width));
1637 if (data->offset < 32)
1638 info[idx++] = (struct field_modify_info){4, 0,
1639 MLX5_MODI_OUT_SIPV6_31_0};
1640 if (data->offset < 64)
1641 info[idx++] = (struct field_modify_info){4, 0,
1642 MLX5_MODI_OUT_SIPV6_63_32};
1643 if (data->offset < 96)
1644 info[idx++] = (struct field_modify_info){4, 0,
1645 MLX5_MODI_OUT_SIPV6_95_64};
1646 if (data->offset < 128)
1647 info[idx++] = (struct field_modify_info){4, 0,
1648 MLX5_MODI_OUT_SIPV6_127_96};
1651 case RTE_FLOW_FIELD_IPV6_DST:
1653 if (data->offset < 32) {
1654 info[idx] = (struct field_modify_info){4, 12,
1655 MLX5_MODI_OUT_DIPV6_31_0};
1658 rte_cpu_to_be_32(0xffffffff >>
1662 mask[3] = RTE_BE32(0xffffffff);
1669 if (data->offset < 64) {
1670 info[idx] = (struct field_modify_info){4, 8,
1671 MLX5_MODI_OUT_DIPV6_63_32};
1674 rte_cpu_to_be_32(0xffffffff >>
1678 mask[2] = RTE_BE32(0xffffffff);
1685 if (data->offset < 96) {
1686 info[idx] = (struct field_modify_info){4, 4,
1687 MLX5_MODI_OUT_DIPV6_95_64};
1690 rte_cpu_to_be_32(0xffffffff >>
1694 mask[1] = RTE_BE32(0xffffffff);
1701 info[idx] = (struct field_modify_info){4, 0,
1702 MLX5_MODI_OUT_DIPV6_127_96};
1703 mask[0] = rte_cpu_to_be_32(0xffffffff >> (32 - width));
1705 if (data->offset < 32)
1706 info[idx++] = (struct field_modify_info){4, 0,
1707 MLX5_MODI_OUT_DIPV6_31_0};
1708 if (data->offset < 64)
1709 info[idx++] = (struct field_modify_info){4, 0,
1710 MLX5_MODI_OUT_DIPV6_63_32};
1711 if (data->offset < 96)
1712 info[idx++] = (struct field_modify_info){4, 0,
1713 MLX5_MODI_OUT_DIPV6_95_64};
1714 if (data->offset < 128)
1715 info[idx++] = (struct field_modify_info){4, 0,
1716 MLX5_MODI_OUT_DIPV6_127_96};
1719 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1720 info[idx] = (struct field_modify_info){2, 0,
1721 MLX5_MODI_OUT_TCP_SPORT};
1723 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1725 case RTE_FLOW_FIELD_TCP_PORT_DST:
1726 info[idx] = (struct field_modify_info){2, 0,
1727 MLX5_MODI_OUT_TCP_DPORT};
1729 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1731 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1732 info[idx] = (struct field_modify_info){4, 0,
1733 MLX5_MODI_OUT_TCP_SEQ_NUM};
1735 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1738 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1739 info[idx] = (struct field_modify_info){4, 0,
1740 MLX5_MODI_OUT_TCP_ACK_NUM};
1742 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1745 case RTE_FLOW_FIELD_TCP_FLAGS:
1746 info[idx] = (struct field_modify_info){2, 0,
1747 MLX5_MODI_OUT_TCP_FLAGS};
1749 mask[idx] = rte_cpu_to_be_16(0x1ff >> (9 - width));
1751 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1752 info[idx] = (struct field_modify_info){2, 0,
1753 MLX5_MODI_OUT_UDP_SPORT};
1755 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1757 case RTE_FLOW_FIELD_UDP_PORT_DST:
1758 info[idx] = (struct field_modify_info){2, 0,
1759 MLX5_MODI_OUT_UDP_DPORT};
1761 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1763 case RTE_FLOW_FIELD_VXLAN_VNI:
1764 /* not supported yet */
1766 case RTE_FLOW_FIELD_GENEVE_VNI:
1767 /* not supported yet*/
1769 case RTE_FLOW_FIELD_GTP_TEID:
1770 info[idx] = (struct field_modify_info){4, 0,
1771 MLX5_MODI_GTP_TEID};
1773 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1776 case RTE_FLOW_FIELD_TAG:
1778 int reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1779 data->level, error);
1782 MLX5_ASSERT(reg != REG_NON);
1783 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1784 info[idx] = (struct field_modify_info){4, 0,
1788 rte_cpu_to_be_32(0xffffffff >>
1792 case RTE_FLOW_FIELD_MARK:
1794 uint32_t mark_mask = priv->sh->dv_mark_mask;
1795 uint32_t mark_count = __builtin_popcount(mark_mask);
1796 int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1800 MLX5_ASSERT(reg != REG_NON);
1801 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1802 info[idx] = (struct field_modify_info){4, 0,
1805 mask[idx] = rte_cpu_to_be_32((mark_mask >>
1806 (mark_count - width)) & mark_mask);
1809 case RTE_FLOW_FIELD_META:
1811 uint32_t meta_mask = priv->sh->dv_meta_mask;
1812 uint32_t meta_count = __builtin_popcount(meta_mask);
1813 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1816 MLX5_ASSERT(reg != REG_NON);
1817 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1818 info[idx] = (struct field_modify_info){4, 0,
1821 mask[idx] = rte_cpu_to_be_32((meta_mask >>
1822 (meta_count - width)) & meta_mask);
1825 case RTE_FLOW_FIELD_POINTER:
1826 case RTE_FLOW_FIELD_VALUE:
1834 * Convert modify_field action to DV specification.
1837 * Pointer to the rte_eth_dev structure.
1838 * @param[in,out] resource
1839 * Pointer to the modify-header resource.
1841 * Pointer to action specification.
1843 * Attributes of flow that includes this item.
1845 * Pointer to the error structure.
1848 * 0 on success, a negative errno value otherwise and rte_errno is set.
1851 flow_dv_convert_action_modify_field
1852 (struct rte_eth_dev *dev,
1853 struct mlx5_flow_dv_modify_hdr_resource *resource,
1854 const struct rte_flow_action *action,
1855 const struct rte_flow_attr *attr,
1856 struct rte_flow_error *error)
1858 const struct rte_flow_action_modify_field *conf =
1859 (const struct rte_flow_action_modify_field *)(action->conf);
1860 struct rte_flow_item item = {
1864 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1866 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1868 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1869 uint32_t type, meta = 0;
1871 if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1872 conf->src.field == RTE_FLOW_FIELD_VALUE) {
1873 type = MLX5_MODIFICATION_TYPE_SET;
1874 /** For SET fill the destination field (field) first. */
1875 mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1878 item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
1879 (void *)(uintptr_t)conf->src.pvalue :
1880 (void *)(uintptr_t)&conf->src.value;
1881 if (conf->dst.field == RTE_FLOW_FIELD_META) {
1882 meta = *(const unaligned_uint32_t *)item.spec;
1883 meta = rte_cpu_to_be_32(meta);
1887 type = MLX5_MODIFICATION_TYPE_COPY;
1888 /** For COPY fill the destination field (dcopy) without mask. */
1889 mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1892 /** Then construct the source field (field) with mask. */
1893 mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1898 return flow_dv_convert_modify_action(&item,
1899 field, dcopy, resource, type, error);
1903 * Validate MARK item.
1906 * Pointer to the rte_eth_dev structure.
1908 * Item specification.
1910 * Attributes of flow that includes this item.
1912 * Pointer to error structure.
1915 * 0 on success, a negative errno value otherwise and rte_errno is set.
1918 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1919 const struct rte_flow_item *item,
1920 const struct rte_flow_attr *attr __rte_unused,
1921 struct rte_flow_error *error)
1923 struct mlx5_priv *priv = dev->data->dev_private;
1924 struct mlx5_sh_config *config = &priv->sh->config;
1925 const struct rte_flow_item_mark *spec = item->spec;
1926 const struct rte_flow_item_mark *mask = item->mask;
1927 const struct rte_flow_item_mark nic_mask = {
1928 .id = priv->sh->dv_mark_mask,
1932 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1933 return rte_flow_error_set(error, ENOTSUP,
1934 RTE_FLOW_ERROR_TYPE_ITEM, item,
1935 "extended metadata feature"
1937 if (!mlx5_flow_ext_mreg_supported(dev))
1938 return rte_flow_error_set(error, ENOTSUP,
1939 RTE_FLOW_ERROR_TYPE_ITEM, item,
1940 "extended metadata register"
1941 " isn't supported");
1943 return rte_flow_error_set(error, ENOTSUP,
1944 RTE_FLOW_ERROR_TYPE_ITEM, item,
1945 "extended metadata register"
1946 " isn't available");
1947 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1951 return rte_flow_error_set(error, EINVAL,
1952 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1954 "data cannot be empty");
1955 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1956 return rte_flow_error_set(error, EINVAL,
1957 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1959 "mark id exceeds the limit");
1963 return rte_flow_error_set(error, EINVAL,
1964 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1965 "mask cannot be zero");
1967 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1968 (const uint8_t *)&nic_mask,
1969 sizeof(struct rte_flow_item_mark),
1970 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1977 * Validate META item.
1980 * Pointer to the rte_eth_dev structure.
1982 * Item specification.
1984 * Attributes of flow that includes this item.
1986 * Pointer to error structure.
1989 * 0 on success, a negative errno value otherwise and rte_errno is set.
1992 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1993 const struct rte_flow_item *item,
1994 const struct rte_flow_attr *attr,
1995 struct rte_flow_error *error)
1997 struct mlx5_priv *priv = dev->data->dev_private;
1998 struct mlx5_sh_config *config = &priv->sh->config;
1999 const struct rte_flow_item_meta *spec = item->spec;
2000 const struct rte_flow_item_meta *mask = item->mask;
2001 struct rte_flow_item_meta nic_mask = {
2008 return rte_flow_error_set(error, EINVAL,
2009 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2011 "data cannot be empty");
2012 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2013 if (!mlx5_flow_ext_mreg_supported(dev))
2014 return rte_flow_error_set(error, ENOTSUP,
2015 RTE_FLOW_ERROR_TYPE_ITEM, item,
2016 "extended metadata register"
2017 " isn't supported");
2018 reg = flow_dv_get_metadata_reg(dev, attr, error);
2022 return rte_flow_error_set(error, ENOTSUP,
2023 RTE_FLOW_ERROR_TYPE_ITEM, item,
2024 "unavailable extended metadata register");
2026 return rte_flow_error_set(error, ENOTSUP,
2027 RTE_FLOW_ERROR_TYPE_ITEM, item,
2031 nic_mask.data = priv->sh->dv_meta_mask;
2034 return rte_flow_error_set(error, ENOTSUP,
2035 RTE_FLOW_ERROR_TYPE_ITEM, item,
2036 "extended metadata feature "
2037 "should be enabled when "
2038 "meta item is requested "
2039 "with e-switch mode ");
2041 return rte_flow_error_set(error, ENOTSUP,
2042 RTE_FLOW_ERROR_TYPE_ITEM, item,
2043 "match on metadata for ingress "
2044 "is not supported in legacy "
2048 mask = &rte_flow_item_meta_mask;
2050 return rte_flow_error_set(error, EINVAL,
2051 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2052 "mask cannot be zero");
2054 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2055 (const uint8_t *)&nic_mask,
2056 sizeof(struct rte_flow_item_meta),
2057 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2062 * Validate TAG item.
2065 * Pointer to the rte_eth_dev structure.
2067 * Item specification.
2069 * Attributes of flow that includes this item.
2071 * Pointer to error structure.
2074 * 0 on success, a negative errno value otherwise and rte_errno is set.
2077 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2078 const struct rte_flow_item *item,
2079 const struct rte_flow_attr *attr __rte_unused,
2080 struct rte_flow_error *error)
2082 const struct rte_flow_item_tag *spec = item->spec;
2083 const struct rte_flow_item_tag *mask = item->mask;
2084 const struct rte_flow_item_tag nic_mask = {
2085 .data = RTE_BE32(UINT32_MAX),
2090 if (!mlx5_flow_ext_mreg_supported(dev))
2091 return rte_flow_error_set(error, ENOTSUP,
2092 RTE_FLOW_ERROR_TYPE_ITEM, item,
2093 "extensive metadata register"
2094 " isn't supported");
2096 return rte_flow_error_set(error, EINVAL,
2097 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2099 "data cannot be empty");
2101 mask = &rte_flow_item_tag_mask;
2103 return rte_flow_error_set(error, EINVAL,
2104 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2105 "mask cannot be zero");
2107 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2108 (const uint8_t *)&nic_mask,
2109 sizeof(struct rte_flow_item_tag),
2110 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2113 if (mask->index != 0xff)
2114 return rte_flow_error_set(error, EINVAL,
2115 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2116 "partial mask for tag index"
2117 " is not supported");
2118 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2121 MLX5_ASSERT(ret != REG_NON);
2126 * Validate vport item.
2129 * Pointer to the rte_eth_dev structure.
2131 * Item specification.
2133 * Attributes of flow that includes this item.
2134 * @param[in] item_flags
2135 * Bit-fields that holds the items detected until now.
2137 * Pointer to error structure.
2140 * 0 on success, a negative errno value otherwise and rte_errno is set.
2143 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2144 const struct rte_flow_item *item,
2145 const struct rte_flow_attr *attr,
2146 uint64_t item_flags,
2147 struct rte_flow_error *error)
2149 const struct rte_flow_item_port_id *spec = item->spec;
2150 const struct rte_flow_item_port_id *mask = item->mask;
2151 const struct rte_flow_item_port_id switch_mask = {
2154 struct mlx5_priv *esw_priv;
2155 struct mlx5_priv *dev_priv;
2158 if (!attr->transfer)
2159 return rte_flow_error_set(error, EINVAL,
2160 RTE_FLOW_ERROR_TYPE_ITEM,
2162 "match on port id is valid only"
2163 " when transfer flag is enabled");
2164 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2165 return rte_flow_error_set(error, ENOTSUP,
2166 RTE_FLOW_ERROR_TYPE_ITEM, item,
2167 "multiple source ports are not"
2170 mask = &switch_mask;
2171 if (mask->id != 0xffffffff)
2172 return rte_flow_error_set(error, ENOTSUP,
2173 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2175 "no support for partial mask on"
2177 ret = mlx5_flow_item_acceptable
2178 (item, (const uint8_t *)mask,
2179 (const uint8_t *)&rte_flow_item_port_id_mask,
2180 sizeof(struct rte_flow_item_port_id),
2181 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2186 if (spec->id == MLX5_PORT_ESW_MGR)
2188 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2190 return rte_flow_error_set(error, rte_errno,
2191 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2192 "failed to obtain E-Switch info for"
2194 dev_priv = mlx5_dev_to_eswitch_info(dev);
2196 return rte_flow_error_set(error, rte_errno,
2197 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2199 "failed to obtain E-Switch info");
2200 if (esw_priv->domain_id != dev_priv->domain_id)
2201 return rte_flow_error_set(error, EINVAL,
2202 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2203 "cannot match on a port from a"
2204 " different E-Switch");
2209 * Validate VLAN item.
2212 * Item specification.
2213 * @param[in] item_flags
2214 * Bit-fields that holds the items detected until now.
2216 * Ethernet device flow is being created on.
2218 * Pointer to error structure.
2221 * 0 on success, a negative errno value otherwise and rte_errno is set.
2224 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2225 uint64_t item_flags,
2226 struct rte_eth_dev *dev,
2227 struct rte_flow_error *error)
2229 const struct rte_flow_item_vlan *mask = item->mask;
2230 const struct rte_flow_item_vlan nic_mask = {
2231 .tci = RTE_BE16(UINT16_MAX),
2232 .inner_type = RTE_BE16(UINT16_MAX),
2235 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2237 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2238 MLX5_FLOW_LAYER_INNER_L4) :
2239 (MLX5_FLOW_LAYER_OUTER_L3 |
2240 MLX5_FLOW_LAYER_OUTER_L4);
2241 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2242 MLX5_FLOW_LAYER_OUTER_VLAN;
2244 if (item_flags & vlanm)
2245 return rte_flow_error_set(error, EINVAL,
2246 RTE_FLOW_ERROR_TYPE_ITEM, item,
2247 "multiple VLAN layers not supported");
2248 else if ((item_flags & l34m) != 0)
2249 return rte_flow_error_set(error, EINVAL,
2250 RTE_FLOW_ERROR_TYPE_ITEM, item,
2251 "VLAN cannot follow L3/L4 layer");
2253 mask = &rte_flow_item_vlan_mask;
2254 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2255 (const uint8_t *)&nic_mask,
2256 sizeof(struct rte_flow_item_vlan),
2257 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2260 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2261 struct mlx5_priv *priv = dev->data->dev_private;
2263 if (priv->vmwa_context) {
2265 * Non-NULL context means we have a virtual machine
2266 * and SR-IOV enabled, we have to create VLAN interface
2267 * to make hypervisor to setup E-Switch vport
2268 * context correctly. We avoid creating the multiple
2269 * VLAN interfaces, so we cannot support VLAN tag mask.
2271 return rte_flow_error_set(error, EINVAL,
2272 RTE_FLOW_ERROR_TYPE_ITEM,
2274 "VLAN tag mask is not"
2275 " supported in virtual"
2283 * GTP flags are contained in 1 byte of the format:
2284 * -------------------------------------------
2285 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2286 * |-----------------------------------------|
2287 * | value | Version | PT | Res | E | S | PN |
2288 * -------------------------------------------
2290 * Matching is supported only for GTP flags E, S, PN.
2292 #define MLX5_GTP_FLAGS_MASK 0x07
2295 * Validate GTP item.
2298 * Pointer to the rte_eth_dev structure.
2300 * Item specification.
2301 * @param[in] item_flags
2302 * Bit-fields that holds the items detected until now.
2304 * Pointer to error structure.
2307 * 0 on success, a negative errno value otherwise and rte_errno is set.
2310 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2311 const struct rte_flow_item *item,
2312 uint64_t item_flags,
2313 struct rte_flow_error *error)
2315 struct mlx5_priv *priv = dev->data->dev_private;
2316 const struct rte_flow_item_gtp *spec = item->spec;
2317 const struct rte_flow_item_gtp *mask = item->mask;
2318 const struct rte_flow_item_gtp nic_mask = {
2319 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
2321 .teid = RTE_BE32(0xffffffff),
2324 if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_gtp)
2325 return rte_flow_error_set(error, ENOTSUP,
2326 RTE_FLOW_ERROR_TYPE_ITEM, item,
2327 "GTP support is not enabled");
2328 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2329 return rte_flow_error_set(error, ENOTSUP,
2330 RTE_FLOW_ERROR_TYPE_ITEM, item,
2331 "multiple tunnel layers not"
2333 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2334 return rte_flow_error_set(error, EINVAL,
2335 RTE_FLOW_ERROR_TYPE_ITEM, item,
2336 "no outer UDP layer found");
2338 mask = &rte_flow_item_gtp_mask;
2339 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
2340 return rte_flow_error_set(error, ENOTSUP,
2341 RTE_FLOW_ERROR_TYPE_ITEM, item,
2342 "Match is supported for GTP"
2344 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2345 (const uint8_t *)&nic_mask,
2346 sizeof(struct rte_flow_item_gtp),
2347 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2351 * Validate GTP PSC item.
2354 * Item specification.
2355 * @param[in] last_item
2356 * Previous validated item in the pattern items.
2357 * @param[in] gtp_item
2358 * Previous GTP item specification.
2360 * Pointer to flow attributes.
2362 * Pointer to error structure.
2365 * 0 on success, a negative errno value otherwise and rte_errno is set.
2368 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2370 const struct rte_flow_item *gtp_item,
2371 const struct rte_flow_attr *attr,
2372 struct rte_flow_error *error)
2374 const struct rte_flow_item_gtp *gtp_spec;
2375 const struct rte_flow_item_gtp *gtp_mask;
2376 const struct rte_flow_item_gtp_psc *mask;
2377 const struct rte_flow_item_gtp_psc nic_mask = {
2382 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2383 return rte_flow_error_set
2384 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2385 "GTP PSC item must be preceded with GTP item");
2386 gtp_spec = gtp_item->spec;
2387 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2388 /* GTP spec and E flag is requested to match zero. */
2390 (gtp_mask->v_pt_rsv_flags &
2391 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
2392 return rte_flow_error_set
2393 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2394 "GTP E flag must be 1 to match GTP PSC");
2395 /* Check the flow is not created in group zero. */
2396 if (!attr->transfer && !attr->group)
2397 return rte_flow_error_set
2398 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2399 "GTP PSC is not supported for group 0");
2400 /* GTP spec is here and E flag is requested to match zero. */
2403 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2404 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2405 (const uint8_t *)&nic_mask,
2406 sizeof(struct rte_flow_item_gtp_psc),
2407 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2411 * Validate IPV4 item.
2412 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2413 * add specific validation of fragment_offset field,
2416 * Item specification.
2417 * @param[in] item_flags
2418 * Bit-fields that holds the items detected until now.
2420 * Pointer to error structure.
2423 * 0 on success, a negative errno value otherwise and rte_errno is set.
2426 flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
2427 const struct rte_flow_item *item,
2428 uint64_t item_flags, uint64_t last_item,
2429 uint16_t ether_type, struct rte_flow_error *error)
2432 struct mlx5_priv *priv = dev->data->dev_private;
2433 struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
2434 const struct rte_flow_item_ipv4 *spec = item->spec;
2435 const struct rte_flow_item_ipv4 *last = item->last;
2436 const struct rte_flow_item_ipv4 *mask = item->mask;
2437 rte_be16_t fragment_offset_spec = 0;
2438 rte_be16_t fragment_offset_last = 0;
2439 struct rte_flow_item_ipv4 nic_ipv4_mask = {
2441 .src_addr = RTE_BE32(0xffffffff),
2442 .dst_addr = RTE_BE32(0xffffffff),
2443 .type_of_service = 0xff,
2444 .fragment_offset = RTE_BE16(0xffff),
2445 .next_proto_id = 0xff,
2446 .time_to_live = 0xff,
2450 if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
2451 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2452 bool ihl_cap = !tunnel ?
2453 attr->outer_ipv4_ihl : attr->inner_ipv4_ihl;
2455 return rte_flow_error_set(error, ENOTSUP,
2456 RTE_FLOW_ERROR_TYPE_ITEM,
2458 "IPV4 ihl offload not supported");
2459 nic_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
2461 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2462 ether_type, &nic_ipv4_mask,
2463 MLX5_ITEM_RANGE_ACCEPTED, error);
2467 fragment_offset_spec = spec->hdr.fragment_offset &
2468 mask->hdr.fragment_offset;
2469 if (!fragment_offset_spec)
2472 * spec and mask are valid, enforce using full mask to make sure the
2473 * complete value is used correctly.
2475 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2476 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2477 return rte_flow_error_set(error, EINVAL,
2478 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2479 item, "must use full mask for"
2480 " fragment_offset");
2482 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2483 * indicating this is 1st fragment of fragmented packet.
2484 * This is not yet supported in MLX5, return appropriate error message.
2486 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2487 return rte_flow_error_set(error, ENOTSUP,
2488 RTE_FLOW_ERROR_TYPE_ITEM, item,
2489 "match on first fragment not "
2491 if (fragment_offset_spec && !last)
2492 return rte_flow_error_set(error, ENOTSUP,
2493 RTE_FLOW_ERROR_TYPE_ITEM, item,
2494 "specified value not supported");
2495 /* spec and last are valid, validate the specified range. */
2496 fragment_offset_last = last->hdr.fragment_offset &
2497 mask->hdr.fragment_offset;
2499 * Match on fragment_offset spec 0x2001 and last 0x3fff
2500 * means MF is 1 and frag-offset is > 0.
2501 * This packet is fragment 2nd and onward, excluding last.
2502 * This is not yet supported in MLX5, return appropriate
2505 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2506 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2507 return rte_flow_error_set(error, ENOTSUP,
2508 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2509 last, "match on following "
2510 "fragments not supported");
2512 * Match on fragment_offset spec 0x0001 and last 0x1fff
2513 * means MF is 0 and frag-offset is > 0.
2514 * This packet is last fragment of fragmented packet.
2515 * This is not yet supported in MLX5, return appropriate
2518 if (fragment_offset_spec == RTE_BE16(1) &&
2519 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2520 return rte_flow_error_set(error, ENOTSUP,
2521 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2522 last, "match on last "
2523 "fragment not supported");
2525 * Match on fragment_offset spec 0x0001 and last 0x3fff
2526 * means MF and/or frag-offset is not 0.
2527 * This is a fragmented packet.
2528 * Other range values are invalid and rejected.
2530 if (!(fragment_offset_spec == RTE_BE16(1) &&
2531 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2532 return rte_flow_error_set(error, ENOTSUP,
2533 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2534 "specified range not supported");
2539 * Validate IPV6 fragment extension item.
2542 * Item specification.
2543 * @param[in] item_flags
2544 * Bit-fields that holds the items detected until now.
2546 * Pointer to error structure.
2549 * 0 on success, a negative errno value otherwise and rte_errno is set.
2552 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2553 uint64_t item_flags,
2554 struct rte_flow_error *error)
2556 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2557 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2558 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2559 rte_be16_t frag_data_spec = 0;
2560 rte_be16_t frag_data_last = 0;
2561 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2562 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2563 MLX5_FLOW_LAYER_OUTER_L4;
2565 struct rte_flow_item_ipv6_frag_ext nic_mask = {
2567 .next_header = 0xff,
2568 .frag_data = RTE_BE16(0xffff),
2572 if (item_flags & l4m)
2573 return rte_flow_error_set(error, EINVAL,
2574 RTE_FLOW_ERROR_TYPE_ITEM, item,
2575 "ipv6 fragment extension item cannot "
2577 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
2578 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2579 return rte_flow_error_set(error, EINVAL,
2580 RTE_FLOW_ERROR_TYPE_ITEM, item,
2581 "ipv6 fragment extension item must "
2582 "follow ipv6 item");
2584 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2585 if (!frag_data_spec)
2588 * spec and mask are valid, enforce using full mask to make sure the
2589 * complete value is used correctly.
2591 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2592 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2593 return rte_flow_error_set(error, EINVAL,
2594 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2595 item, "must use full mask for"
2598 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2599 * This is 1st fragment of fragmented packet.
2601 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2602 return rte_flow_error_set(error, ENOTSUP,
2603 RTE_FLOW_ERROR_TYPE_ITEM, item,
2604 "match on first fragment not "
2606 if (frag_data_spec && !last)
2607 return rte_flow_error_set(error, EINVAL,
2608 RTE_FLOW_ERROR_TYPE_ITEM, item,
2609 "specified value not supported");
2610 ret = mlx5_flow_item_acceptable
2611 (item, (const uint8_t *)mask,
2612 (const uint8_t *)&nic_mask,
2613 sizeof(struct rte_flow_item_ipv6_frag_ext),
2614 MLX5_ITEM_RANGE_ACCEPTED, error);
2617 /* spec and last are valid, validate the specified range. */
2618 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2620 * Match on frag_data spec 0x0009 and last 0xfff9
2621 * means M is 1 and frag-offset is > 0.
2622 * This packet is fragment 2nd and onward, excluding last.
2623 * This is not yet supported in MLX5, return appropriate
2626 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2627 RTE_IPV6_EHDR_MF_MASK) &&
2628 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2629 return rte_flow_error_set(error, ENOTSUP,
2630 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2631 last, "match on following "
2632 "fragments not supported");
2634 * Match on frag_data spec 0x0008 and last 0xfff8
2635 * means M is 0 and frag-offset is > 0.
2636 * This packet is last fragment of fragmented packet.
2637 * This is not yet supported in MLX5, return appropriate
2640 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2641 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2642 return rte_flow_error_set(error, ENOTSUP,
2643 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2644 last, "match on last "
2645 "fragment not supported");
2646 /* Other range values are invalid and rejected. */
2647 return rte_flow_error_set(error, EINVAL,
2648 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2649 "specified range not supported");
2653 * Validate ASO CT item.
2656 * Pointer to the rte_eth_dev structure.
2658 * Item specification.
2659 * @param[in] item_flags
2660 * Pointer to bit-fields that holds the items detected until now.
2662 * Pointer to error structure.
2665 * 0 on success, a negative errno value otherwise and rte_errno is set.
2668 flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
2669 const struct rte_flow_item *item,
2670 uint64_t *item_flags,
2671 struct rte_flow_error *error)
2673 const struct rte_flow_item_conntrack *spec = item->spec;
2674 const struct rte_flow_item_conntrack *mask = item->mask;
2678 if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
2679 return rte_flow_error_set(error, EINVAL,
2680 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2681 "Only one CT is supported");
2683 mask = &rte_flow_item_conntrack_mask;
2684 flags = spec->flags & mask->flags;
2685 if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
2686 ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
2687 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
2688 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
2689 return rte_flow_error_set(error, EINVAL,
2690 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2691 "Conflict status bits");
2692 /* State change also needs to be considered. */
2693 *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
2698 * Validate the pop VLAN action.
2701 * Pointer to the rte_eth_dev structure.
2702 * @param[in] action_flags
2703 * Holds the actions detected until now.
2705 * Pointer to the pop vlan action.
2706 * @param[in] item_flags
2707 * The items found in this flow rule.
2709 * Pointer to flow attributes.
2711 * Pointer to error structure.
2714 * 0 on success, a negative errno value otherwise and rte_errno is set.
2717 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2718 uint64_t action_flags,
2719 const struct rte_flow_action *action,
2720 uint64_t item_flags,
2721 const struct rte_flow_attr *attr,
2722 struct rte_flow_error *error)
2724 const struct mlx5_priv *priv = dev->data->dev_private;
2725 struct mlx5_dev_ctx_shared *sh = priv->sh;
2726 bool direction_error = false;
2728 if (!priv->sh->pop_vlan_action)
2729 return rte_flow_error_set(error, ENOTSUP,
2730 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2732 "pop vlan action is not supported");
2733 /* Pop VLAN is not supported in egress except for CX6 FDB mode. */
2734 if (attr->transfer) {
2735 bool fdb_tx = priv->representor_id != UINT16_MAX;
2736 bool is_cx5 = sh->steering_format_version ==
2737 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2739 if (fdb_tx && is_cx5)
2740 direction_error = true;
2741 } else if (attr->egress) {
2742 direction_error = true;
2744 if (direction_error)
2745 return rte_flow_error_set(error, ENOTSUP,
2746 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2748 "pop vlan action not supported for egress");
2749 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2750 return rte_flow_error_set(error, ENOTSUP,
2751 RTE_FLOW_ERROR_TYPE_ACTION, action,
2752 "no support for multiple VLAN "
2754 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2755 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2756 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2757 return rte_flow_error_set(error, ENOTSUP,
2758 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2760 "cannot pop vlan after decap without "
2761 "match on inner vlan in the flow");
2762 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2763 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2764 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2765 return rte_flow_error_set(error, ENOTSUP,
2766 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2768 "cannot pop vlan without a "
2769 "match on (outer) vlan in the flow");
2770 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2771 return rte_flow_error_set(error, EINVAL,
2772 RTE_FLOW_ERROR_TYPE_ACTION, action,
2773 "wrong action order, port_id should "
2774 "be after pop VLAN action");
2775 if (!attr->transfer && priv->representor)
2776 return rte_flow_error_set(error, ENOTSUP,
2777 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2778 "pop vlan action for VF representor "
2779 "not supported on NIC table");
2784 * Get VLAN default info from vlan match info.
2787 * the list of item specifications.
2789 * pointer VLAN info to fill to.
2792 * 0 on success, a negative errno value otherwise and rte_errno is set.
2795 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2796 struct rte_vlan_hdr *vlan)
2798 const struct rte_flow_item_vlan nic_mask = {
2799 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2800 MLX5DV_FLOW_VLAN_VID_MASK),
2801 .inner_type = RTE_BE16(0xffff),
2806 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2807 int type = items->type;
2809 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2810 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2813 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2814 const struct rte_flow_item_vlan *vlan_m = items->mask;
2815 const struct rte_flow_item_vlan *vlan_v = items->spec;
2817 /* If VLAN item in pattern doesn't contain data, return here. */
2822 /* Only full match values are accepted */
2823 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2824 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2825 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2827 rte_be_to_cpu_16(vlan_v->tci &
2828 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2830 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2831 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2832 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2834 rte_be_to_cpu_16(vlan_v->tci &
2835 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2837 if (vlan_m->inner_type == nic_mask.inner_type)
2838 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2839 vlan_m->inner_type);
2844 * Validate the push VLAN action.
2847 * Pointer to the rte_eth_dev structure.
2848 * @param[in] action_flags
2849 * Holds the actions detected until now.
2850 * @param[in] item_flags
2851 * The items found in this flow rule.
2853 * Pointer to the action structure.
2855 * Pointer to flow attributes
2857 * Pointer to error structure.
2860 * 0 on success, a negative errno value otherwise and rte_errno is set.
2863 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2864 uint64_t action_flags,
2865 const struct rte_flow_item_vlan *vlan_m,
2866 const struct rte_flow_action *action,
2867 const struct rte_flow_attr *attr,
2868 struct rte_flow_error *error)
2870 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2871 const struct mlx5_priv *priv = dev->data->dev_private;
2872 struct mlx5_dev_ctx_shared *sh = priv->sh;
2873 bool direction_error = false;
2875 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2876 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2877 return rte_flow_error_set(error, EINVAL,
2878 RTE_FLOW_ERROR_TYPE_ACTION, action,
2879 "invalid vlan ethertype");
2880 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2881 return rte_flow_error_set(error, EINVAL,
2882 RTE_FLOW_ERROR_TYPE_ACTION, action,
2883 "wrong action order, port_id should "
2884 "be after push VLAN");
2885 /* Push VLAN is not supported in ingress except for CX6 FDB mode. */
2886 if (attr->transfer) {
2887 bool fdb_tx = priv->representor_id != UINT16_MAX;
2888 bool is_cx5 = sh->steering_format_version ==
2889 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2891 if (!fdb_tx && is_cx5)
2892 direction_error = true;
2893 } else if (attr->ingress) {
2894 direction_error = true;
2896 if (direction_error)
2897 return rte_flow_error_set(error, ENOTSUP,
2898 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2900 "push vlan action not supported for ingress");
2901 if (!attr->transfer && priv->representor)
2902 return rte_flow_error_set(error, ENOTSUP,
2903 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2904 "push vlan action for VF representor "
2905 "not supported on NIC table");
2907 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2908 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2909 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2910 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2911 !(mlx5_flow_find_action
2912 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2913 return rte_flow_error_set(error, EINVAL,
2914 RTE_FLOW_ERROR_TYPE_ACTION, action,
2915 "not full match mask on VLAN PCP and "
2916 "there is no of_set_vlan_pcp action, "
2917 "push VLAN action cannot figure out "
2920 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2921 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2922 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2923 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2924 !(mlx5_flow_find_action
2925 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2926 return rte_flow_error_set(error, EINVAL,
2927 RTE_FLOW_ERROR_TYPE_ACTION, action,
2928 "not full match mask on VLAN VID and "
2929 "there is no of_set_vlan_vid action, "
2930 "push VLAN action cannot figure out "
2937 * Validate the set VLAN PCP.
2939 * @param[in] action_flags
2940 * Holds the actions detected until now.
2941 * @param[in] actions
2942 * Pointer to the list of actions remaining in the flow rule.
2944 * Pointer to error structure.
2947 * 0 on success, a negative errno value otherwise and rte_errno is set.
2950 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2951 const struct rte_flow_action actions[],
2952 struct rte_flow_error *error)
2954 const struct rte_flow_action *action = actions;
2955 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2957 if (conf->vlan_pcp > 7)
2958 return rte_flow_error_set(error, EINVAL,
2959 RTE_FLOW_ERROR_TYPE_ACTION, action,
2960 "VLAN PCP value is too big");
2961 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2962 return rte_flow_error_set(error, ENOTSUP,
2963 RTE_FLOW_ERROR_TYPE_ACTION, action,
2964 "set VLAN PCP action must follow "
2965 "the push VLAN action");
2966 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2967 return rte_flow_error_set(error, ENOTSUP,
2968 RTE_FLOW_ERROR_TYPE_ACTION, action,
2969 "Multiple VLAN PCP modification are "
2971 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2972 return rte_flow_error_set(error, EINVAL,
2973 RTE_FLOW_ERROR_TYPE_ACTION, action,
2974 "wrong action order, port_id should "
2975 "be after set VLAN PCP");
2980 * Validate the set VLAN VID.
2982 * @param[in] item_flags
2983 * Holds the items detected in this rule.
2984 * @param[in] action_flags
2985 * Holds the actions detected until now.
2986 * @param[in] actions
2987 * Pointer to the list of actions remaining in the flow rule.
2989 * Pointer to error structure.
2992 * 0 on success, a negative errno value otherwise and rte_errno is set.
2995 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2996 uint64_t action_flags,
2997 const struct rte_flow_action actions[],
2998 struct rte_flow_error *error)
3000 const struct rte_flow_action *action = actions;
3001 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3003 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3004 return rte_flow_error_set(error, EINVAL,
3005 RTE_FLOW_ERROR_TYPE_ACTION, action,
3006 "VLAN VID value is too big");
3007 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3008 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3009 return rte_flow_error_set(error, ENOTSUP,
3010 RTE_FLOW_ERROR_TYPE_ACTION, action,
3011 "set VLAN VID action must follow push"
3012 " VLAN action or match on VLAN item");
3013 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3014 return rte_flow_error_set(error, ENOTSUP,
3015 RTE_FLOW_ERROR_TYPE_ACTION, action,
3016 "Multiple VLAN VID modifications are "
3018 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3019 return rte_flow_error_set(error, EINVAL,
3020 RTE_FLOW_ERROR_TYPE_ACTION, action,
3021 "wrong action order, port_id should "
3022 "be after set VLAN VID");
3027 * Validate the FLAG action.
3030 * Pointer to the rte_eth_dev structure.
3031 * @param[in] action_flags
3032 * Holds the actions detected until now.
3034 * Pointer to flow attributes
3036 * Pointer to error structure.
3039 * 0 on success, a negative errno value otherwise and rte_errno is set.
3042 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3043 uint64_t action_flags,
3044 const struct rte_flow_attr *attr,
3045 struct rte_flow_error *error)
3047 struct mlx5_priv *priv = dev->data->dev_private;
3048 struct mlx5_sh_config *config = &priv->sh->config;
3051 /* Fall back if no extended metadata register support. */
3052 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3053 return mlx5_flow_validate_action_flag(action_flags, attr,
3055 /* Extensive metadata mode requires registers. */
3056 if (!mlx5_flow_ext_mreg_supported(dev))
3057 return rte_flow_error_set(error, ENOTSUP,
3058 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3059 "no metadata registers "
3060 "to support flag action");
3061 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3062 return rte_flow_error_set(error, ENOTSUP,
3063 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3064 "extended metadata register"
3065 " isn't available");
3066 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3069 MLX5_ASSERT(ret > 0);
3070 if (action_flags & MLX5_FLOW_ACTION_MARK)
3071 return rte_flow_error_set(error, EINVAL,
3072 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3073 "can't mark and flag in same flow");
3074 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3075 return rte_flow_error_set(error, EINVAL,
3076 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3078 " actions in same flow");
3083 * Validate MARK action.
3086 * Pointer to the rte_eth_dev structure.
3088 * Pointer to action.
3089 * @param[in] action_flags
3090 * Holds the actions detected until now.
3092 * Pointer to flow attributes
3094 * Pointer to error structure.
3097 * 0 on success, a negative errno value otherwise and rte_errno is set.
3100 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3101 const struct rte_flow_action *action,
3102 uint64_t action_flags,
3103 const struct rte_flow_attr *attr,
3104 struct rte_flow_error *error)
3106 struct mlx5_priv *priv = dev->data->dev_private;
3107 struct mlx5_sh_config *config = &priv->sh->config;
3108 const struct rte_flow_action_mark *mark = action->conf;
3111 if (is_tunnel_offload_active(dev))
3112 return rte_flow_error_set(error, ENOTSUP,
3113 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3115 "if tunnel offload active");
3116 /* Fall back if no extended metadata register support. */
3117 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3118 return mlx5_flow_validate_action_mark(action, action_flags,
3120 /* Extensive metadata mode requires registers. */
3121 if (!mlx5_flow_ext_mreg_supported(dev))
3122 return rte_flow_error_set(error, ENOTSUP,
3123 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3124 "no metadata registers "
3125 "to support mark action");
3126 if (!priv->sh->dv_mark_mask)
3127 return rte_flow_error_set(error, ENOTSUP,
3128 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3129 "extended metadata register"
3130 " isn't available");
3131 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3134 MLX5_ASSERT(ret > 0);
3136 return rte_flow_error_set(error, EINVAL,
3137 RTE_FLOW_ERROR_TYPE_ACTION, action,
3138 "configuration cannot be null");
3139 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3140 return rte_flow_error_set(error, EINVAL,
3141 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3143 "mark id exceeds the limit");
3144 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3145 return rte_flow_error_set(error, EINVAL,
3146 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3147 "can't flag and mark in same flow");
3148 if (action_flags & MLX5_FLOW_ACTION_MARK)
3149 return rte_flow_error_set(error, EINVAL,
3150 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3151 "can't have 2 mark actions in same"
3157 * Validate SET_META action.
3160 * Pointer to the rte_eth_dev structure.
3162 * Pointer to the action structure.
3163 * @param[in] action_flags
3164 * Holds the actions detected until now.
3166 * Pointer to flow attributes
3168 * Pointer to error structure.
3171 * 0 on success, a negative errno value otherwise and rte_errno is set.
3174 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3175 const struct rte_flow_action *action,
3176 uint64_t action_flags __rte_unused,
3177 const struct rte_flow_attr *attr,
3178 struct rte_flow_error *error)
3180 struct mlx5_priv *priv = dev->data->dev_private;
3181 struct mlx5_sh_config *config = &priv->sh->config;
3182 const struct rte_flow_action_set_meta *conf;
3183 uint32_t nic_mask = UINT32_MAX;
3186 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3187 !mlx5_flow_ext_mreg_supported(dev))
3188 return rte_flow_error_set(error, ENOTSUP,
3189 RTE_FLOW_ERROR_TYPE_ACTION, action,
3190 "extended metadata register"
3191 " isn't supported");
3192 reg = flow_dv_get_metadata_reg(dev, attr, error);
3196 return rte_flow_error_set(error, ENOTSUP,
3197 RTE_FLOW_ERROR_TYPE_ACTION, action,
3198 "unavailable extended metadata register");
3199 if (reg != REG_A && reg != REG_B) {
3200 struct mlx5_priv *priv = dev->data->dev_private;
3202 nic_mask = priv->sh->dv_meta_mask;
3204 if (!(action->conf))
3205 return rte_flow_error_set(error, EINVAL,
3206 RTE_FLOW_ERROR_TYPE_ACTION, action,
3207 "configuration cannot be null");
3208 conf = (const struct rte_flow_action_set_meta *)action->conf;
3210 return rte_flow_error_set(error, EINVAL,
3211 RTE_FLOW_ERROR_TYPE_ACTION, action,
3212 "zero mask doesn't have any effect");
3213 if (conf->mask & ~nic_mask)
3214 return rte_flow_error_set(error, EINVAL,
3215 RTE_FLOW_ERROR_TYPE_ACTION, action,
3216 "meta data must be within reg C0");
3221 * Validate SET_TAG action.
3224 * Pointer to the rte_eth_dev structure.
3226 * Pointer to the action structure.
3227 * @param[in] action_flags
3228 * Holds the actions detected until now.
3230 * Pointer to flow attributes
3232 * Pointer to error structure.
3235 * 0 on success, a negative errno value otherwise and rte_errno is set.
3238 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3239 const struct rte_flow_action *action,
3240 uint64_t action_flags,
3241 const struct rte_flow_attr *attr,
3242 struct rte_flow_error *error)
3244 const struct rte_flow_action_set_tag *conf;
3245 const uint64_t terminal_action_flags =
3246 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3247 MLX5_FLOW_ACTION_RSS;
3250 if (!mlx5_flow_ext_mreg_supported(dev))
3251 return rte_flow_error_set(error, ENOTSUP,
3252 RTE_FLOW_ERROR_TYPE_ACTION, action,
3253 "extensive metadata register"
3254 " isn't supported");
3255 if (!(action->conf))
3256 return rte_flow_error_set(error, EINVAL,
3257 RTE_FLOW_ERROR_TYPE_ACTION, action,
3258 "configuration cannot be null");
3259 conf = (const struct rte_flow_action_set_tag *)action->conf;
3261 return rte_flow_error_set(error, EINVAL,
3262 RTE_FLOW_ERROR_TYPE_ACTION, action,
3263 "zero mask doesn't have any effect");
3264 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3267 if (!attr->transfer && attr->ingress &&
3268 (action_flags & terminal_action_flags))
3269 return rte_flow_error_set(error, EINVAL,
3270 RTE_FLOW_ERROR_TYPE_ACTION, action,
3271 "set_tag has no effect"
3272 " with terminal actions");
3277 * Validate count action.
3280 * Pointer to rte_eth_dev structure.
3282 * Indicator if action is shared.
3283 * @param[in] action_flags
3284 * Holds the actions detected until now.
3286 * Pointer to error structure.
3289 * 0 on success, a negative errno value otherwise and rte_errno is set.
3292 flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3293 uint64_t action_flags,
3294 struct rte_flow_error *error)
3296 struct mlx5_priv *priv = dev->data->dev_private;
3298 if (!priv->sh->cdev->config.devx)
3300 if (action_flags & MLX5_FLOW_ACTION_COUNT)
3301 return rte_flow_error_set(error, EINVAL,
3302 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3303 "duplicate count actions set");
3304 if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
3305 !priv->sh->flow_hit_aso_en)
3306 return rte_flow_error_set(error, EINVAL,
3307 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3308 "old age and shared count combination is not supported");
3309 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3313 return rte_flow_error_set
3315 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3317 "count action not supported");
3321 * Validate the L2 encap action.
3324 * Pointer to the rte_eth_dev structure.
3325 * @param[in] action_flags
3326 * Holds the actions detected until now.
3328 * Pointer to the action structure.
3330 * Pointer to flow attributes.
3332 * Pointer to error structure.
3335 * 0 on success, a negative errno value otherwise and rte_errno is set.
3338 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3339 uint64_t action_flags,
3340 const struct rte_flow_action *action,
3341 const struct rte_flow_attr *attr,
3342 struct rte_flow_error *error)
3344 const struct mlx5_priv *priv = dev->data->dev_private;
3346 if (!(action->conf))
3347 return rte_flow_error_set(error, EINVAL,
3348 RTE_FLOW_ERROR_TYPE_ACTION, action,
3349 "configuration cannot be null");
3350 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3351 return rte_flow_error_set(error, EINVAL,
3352 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3353 "can only have a single encap action "
3355 if (!attr->transfer && priv->representor)
3356 return rte_flow_error_set(error, ENOTSUP,
3357 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3358 "encap action for VF representor "
3359 "not supported on NIC table");
3364 * Validate a decap action.
3367 * Pointer to the rte_eth_dev structure.
3368 * @param[in] action_flags
3369 * Holds the actions detected until now.
3371 * Pointer to the action structure.
3372 * @param[in] item_flags
3373 * Holds the items detected.
3375 * Pointer to flow attributes
3377 * Pointer to error structure.
3380 * 0 on success, a negative errno value otherwise and rte_errno is set.
3383 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3384 uint64_t action_flags,
3385 const struct rte_flow_action *action,
3386 const uint64_t item_flags,
3387 const struct rte_flow_attr *attr,
3388 struct rte_flow_error *error)
3390 const struct mlx5_priv *priv = dev->data->dev_private;
3392 if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3393 !priv->sh->config.decap_en)
3394 return rte_flow_error_set(error, ENOTSUP,
3395 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3396 "decap is not enabled");
3397 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3398 return rte_flow_error_set(error, ENOTSUP,
3399 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3401 MLX5_FLOW_ACTION_DECAP ? "can only "
3402 "have a single decap action" : "decap "
3403 "after encap is not supported");
3404 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3405 return rte_flow_error_set(error, EINVAL,
3406 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3407 "can't have decap action after"
3410 return rte_flow_error_set(error, ENOTSUP,
3411 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3413 "decap action not supported for "
3415 if (!attr->transfer && priv->representor)
3416 return rte_flow_error_set(error, ENOTSUP,
3417 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3418 "decap action for VF representor "
3419 "not supported on NIC table");
3420 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3421 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3422 return rte_flow_error_set(error, ENOTSUP,
3423 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3424 "VXLAN item should be present for VXLAN decap");
3428 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3431 * Validate the raw encap and decap actions.
3434 * Pointer to the rte_eth_dev structure.
3436 * Pointer to the decap action.
3438 * Pointer to the encap action.
3440 * Pointer to flow attributes
3441 * @param[in/out] action_flags
3442 * Holds the actions detected until now.
3443 * @param[out] actions_n
3444 * pointer to the number of actions counter.
3446 * Pointer to the action structure.
3447 * @param[in] item_flags
3448 * Holds the items detected.
3450 * Pointer to error structure.
3453 * 0 on success, a negative errno value otherwise and rte_errno is set.
3456 flow_dv_validate_action_raw_encap_decap
3457 (struct rte_eth_dev *dev,
3458 const struct rte_flow_action_raw_decap *decap,
3459 const struct rte_flow_action_raw_encap *encap,
3460 const struct rte_flow_attr *attr, uint64_t *action_flags,
3461 int *actions_n, const struct rte_flow_action *action,
3462 uint64_t item_flags, struct rte_flow_error *error)
3464 const struct mlx5_priv *priv = dev->data->dev_private;
3467 if (encap && (!encap->size || !encap->data))
3468 return rte_flow_error_set(error, EINVAL,
3469 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3470 "raw encap data cannot be empty");
3471 if (decap && encap) {
3472 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3473 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3476 else if (encap->size <=
3477 MLX5_ENCAPSULATION_DECISION_SIZE &&
3479 MLX5_ENCAPSULATION_DECISION_SIZE)
3482 else if (encap->size >
3483 MLX5_ENCAPSULATION_DECISION_SIZE &&
3485 MLX5_ENCAPSULATION_DECISION_SIZE)
3486 /* 2 L2 actions: encap and decap. */
3489 return rte_flow_error_set(error,
3491 RTE_FLOW_ERROR_TYPE_ACTION,
3492 NULL, "unsupported too small "
3493 "raw decap and too small raw "
3494 "encap combination");
3497 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3498 item_flags, attr, error);
3501 *action_flags |= MLX5_FLOW_ACTION_DECAP;
3505 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3506 return rte_flow_error_set(error, ENOTSUP,
3507 RTE_FLOW_ERROR_TYPE_ACTION,
3509 "small raw encap size");
3510 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3511 return rte_flow_error_set(error, EINVAL,
3512 RTE_FLOW_ERROR_TYPE_ACTION,
3514 "more than one encap action");
3515 if (!attr->transfer && priv->representor)
3516 return rte_flow_error_set
3518 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3519 "encap action for VF representor "
3520 "not supported on NIC table");
3521 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3528 * Validate the ASO CT action.
3531 * Pointer to the rte_eth_dev structure.
3532 * @param[in] action_flags
3533 * Holds the actions detected until now.
3534 * @param[in] item_flags
3535 * The items found in this flow rule.
3537 * Pointer to flow attributes.
3539 * Pointer to error structure.
3542 * 0 on success, a negative errno value otherwise and rte_errno is set.
3545 flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
3546 uint64_t action_flags,
3547 uint64_t item_flags,
3548 const struct rte_flow_attr *attr,
3549 struct rte_flow_error *error)
3553 if (attr->group == 0 && !attr->transfer)
3554 return rte_flow_error_set(error, ENOTSUP,
3555 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3557 "Only support non-root table");
3558 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
3559 return rte_flow_error_set(error, ENOTSUP,
3560 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3561 "CT cannot follow a fate action");
3562 if ((action_flags & MLX5_FLOW_ACTION_METER) ||
3563 (action_flags & MLX5_FLOW_ACTION_AGE))
3564 return rte_flow_error_set(error, EINVAL,
3565 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3566 "Only one ASO action is supported");
3567 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3568 return rte_flow_error_set(error, EINVAL,
3569 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3570 "Encap cannot exist before CT");
3571 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3572 return rte_flow_error_set(error, EINVAL,
3573 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3574 "Not a outer TCP packet");
3579 flow_dv_encap_decap_match_cb(void *tool_ctx __rte_unused,
3580 struct mlx5_list_entry *entry, void *cb_ctx)
3582 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3583 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3584 struct mlx5_flow_dv_encap_decap_resource *resource;
3586 resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
3588 if (resource->reformat_type == ctx_resource->reformat_type &&
3589 resource->ft_type == ctx_resource->ft_type &&
3590 resource->flags == ctx_resource->flags &&
3591 resource->size == ctx_resource->size &&
3592 !memcmp((const void *)resource->buf,
3593 (const void *)ctx_resource->buf,
3599 struct mlx5_list_entry *
3600 flow_dv_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
3602 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3603 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3604 struct mlx5dv_dr_domain *domain;
3605 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3606 struct mlx5_flow_dv_encap_decap_resource *resource;
3610 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3611 domain = sh->fdb_domain;
3612 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3613 domain = sh->rx_domain;
3615 domain = sh->tx_domain;
3616 /* Register new encap/decap resource. */
3617 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
3619 rte_flow_error_set(ctx->error, ENOMEM,
3620 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3621 "cannot allocate resource memory");
3624 *resource = *ctx_resource;
3625 resource->idx = idx;
3626 ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
3630 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
3631 rte_flow_error_set(ctx->error, ENOMEM,
3632 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3633 NULL, "cannot create action");
3637 return &resource->entry;
3640 struct mlx5_list_entry *
3641 flow_dv_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
3644 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3645 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3646 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3649 cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
3651 if (!cache_resource) {
3652 rte_flow_error_set(ctx->error, ENOMEM,
3653 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3654 "cannot allocate resource memory");
3657 memcpy(cache_resource, oentry, sizeof(*cache_resource));
3658 cache_resource->idx = idx;
3659 return &cache_resource->entry;
3663 flow_dv_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3665 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3666 struct mlx5_flow_dv_encap_decap_resource *res =
3667 container_of(entry, typeof(*res), entry);
3669 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
3673 * Find existing encap/decap resource or create and register a new one.
3675 * @param[in, out] dev
3676 * Pointer to rte_eth_dev structure.
3677 * @param[in, out] resource
3678 * Pointer to encap/decap resource.
3679 * @parm[in, out] dev_flow
3680 * Pointer to the dev_flow.
3682 * pointer to error structure.
3685 * 0 on success otherwise -errno and errno is set.
3688 flow_dv_encap_decap_resource_register
3689 (struct rte_eth_dev *dev,
3690 struct mlx5_flow_dv_encap_decap_resource *resource,
3691 struct mlx5_flow *dev_flow,
3692 struct rte_flow_error *error)
3694 struct mlx5_priv *priv = dev->data->dev_private;
3695 struct mlx5_dev_ctx_shared *sh = priv->sh;
3696 struct mlx5_list_entry *entry;
3700 uint32_t refmt_type:8;
3702 * Header reformat actions can be shared between
3703 * non-root tables. One bit to indicate non-root
3707 uint32_t reserve:15;
3710 } encap_decap_key = {
3712 .ft_type = resource->ft_type,
3713 .refmt_type = resource->reformat_type,
3714 .is_root = !!dev_flow->dv.group,
3718 struct mlx5_flow_cb_ctx ctx = {
3722 struct mlx5_hlist *encaps_decaps;
3725 encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
3727 MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
3729 flow_dv_encap_decap_create_cb,
3730 flow_dv_encap_decap_match_cb,
3731 flow_dv_encap_decap_remove_cb,
3732 flow_dv_encap_decap_clone_cb,
3733 flow_dv_encap_decap_clone_free_cb,
3735 if (unlikely(!encaps_decaps))
3737 resource->flags = dev_flow->dv.group ? 0 : 1;
3738 key64 = __rte_raw_cksum(&encap_decap_key.v32,
3739 sizeof(encap_decap_key.v32), 0);
3740 if (resource->reformat_type !=
3741 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
3743 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
3744 entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
3747 resource = container_of(entry, typeof(*resource), entry);
3748 dev_flow->dv.encap_decap = resource;
3749 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3754 * Find existing table jump resource or create and register a new one.
3756 * @param[in, out] dev
3757 * Pointer to rte_eth_dev structure.
3758 * @param[in, out] tbl
3759 * Pointer to flow table resource.
3760 * @parm[in, out] dev_flow
3761 * Pointer to the dev_flow.
3763 * pointer to error structure.
3766 * 0 on success otherwise -errno and errno is set.
3769 flow_dv_jump_tbl_resource_register
3770 (struct rte_eth_dev *dev __rte_unused,
3771 struct mlx5_flow_tbl_resource *tbl,
3772 struct mlx5_flow *dev_flow,
3773 struct rte_flow_error *error __rte_unused)
3775 struct mlx5_flow_tbl_data_entry *tbl_data =
3776 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3779 MLX5_ASSERT(tbl_data->jump.action);
3780 dev_flow->handle->rix_jump = tbl_data->idx;
3781 dev_flow->dv.jump = &tbl_data->jump;
3786 flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
3787 struct mlx5_list_entry *entry, void *cb_ctx)
3789 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3790 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3791 struct mlx5_flow_dv_port_id_action_resource *res =
3792 container_of(entry, typeof(*res), entry);
3794 return ref->port_id != res->port_id;
3797 struct mlx5_list_entry *
3798 flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
3800 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3801 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3802 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3803 struct mlx5_flow_dv_port_id_action_resource *resource;
3807 /* Register new port id action resource. */
3808 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3810 rte_flow_error_set(ctx->error, ENOMEM,
3811 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3812 "cannot allocate port_id action memory");
3816 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3820 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3821 rte_flow_error_set(ctx->error, ENOMEM,
3822 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3823 "cannot create action");
3826 resource->idx = idx;
3827 return &resource->entry;
3830 struct mlx5_list_entry *
3831 flow_dv_port_id_clone_cb(void *tool_ctx,
3832 struct mlx5_list_entry *entry __rte_unused,
3835 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3836 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3837 struct mlx5_flow_dv_port_id_action_resource *resource;
3840 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3842 rte_flow_error_set(ctx->error, ENOMEM,
3843 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3844 "cannot allocate port_id action memory");
3847 memcpy(resource, entry, sizeof(*resource));
3848 resource->idx = idx;
3849 return &resource->entry;
3853 flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3855 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3856 struct mlx5_flow_dv_port_id_action_resource *resource =
3857 container_of(entry, typeof(*resource), entry);
3859 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
3863 * Find existing table port ID resource or create and register a new one.
3865 * @param[in, out] dev
3866 * Pointer to rte_eth_dev structure.
3867 * @param[in, out] ref
3868 * Pointer to port ID action resource reference.
3869 * @parm[in, out] dev_flow
3870 * Pointer to the dev_flow.
3872 * pointer to error structure.
3875 * 0 on success otherwise -errno and errno is set.
3878 flow_dv_port_id_action_resource_register
3879 (struct rte_eth_dev *dev,
3880 struct mlx5_flow_dv_port_id_action_resource *ref,
3881 struct mlx5_flow *dev_flow,
3882 struct rte_flow_error *error)
3884 struct mlx5_priv *priv = dev->data->dev_private;
3885 struct mlx5_list_entry *entry;
3886 struct mlx5_flow_dv_port_id_action_resource *resource;
3887 struct mlx5_flow_cb_ctx ctx = {
3892 entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
3895 resource = container_of(entry, typeof(*resource), entry);
3896 dev_flow->dv.port_id_action = resource;
3897 dev_flow->handle->rix_port_id_action = resource->idx;
3902 flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
3903 struct mlx5_list_entry *entry, void *cb_ctx)
3905 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3906 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3907 struct mlx5_flow_dv_push_vlan_action_resource *res =
3908 container_of(entry, typeof(*res), entry);
3910 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
3913 struct mlx5_list_entry *
3914 flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
3916 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3917 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3918 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3919 struct mlx5_flow_dv_push_vlan_action_resource *resource;
3920 struct mlx5dv_dr_domain *domain;
3924 /* Register new port id action resource. */
3925 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3927 rte_flow_error_set(ctx->error, ENOMEM,
3928 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3929 "cannot allocate push_vlan action memory");
3933 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3934 domain = sh->fdb_domain;
3935 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3936 domain = sh->rx_domain;
3938 domain = sh->tx_domain;
3939 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
3942 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
3943 rte_flow_error_set(ctx->error, ENOMEM,
3944 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3945 "cannot create push vlan action");
3948 resource->idx = idx;
3949 return &resource->entry;
3952 struct mlx5_list_entry *
3953 flow_dv_push_vlan_clone_cb(void *tool_ctx,
3954 struct mlx5_list_entry *entry __rte_unused,
3957 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3958 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3959 struct mlx5_flow_dv_push_vlan_action_resource *resource;
3962 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3964 rte_flow_error_set(ctx->error, ENOMEM,
3965 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3966 "cannot allocate push_vlan action memory");
3969 memcpy(resource, entry, sizeof(*resource));
3970 resource->idx = idx;
3971 return &resource->entry;
3975 flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3977 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3978 struct mlx5_flow_dv_push_vlan_action_resource *resource =
3979 container_of(entry, typeof(*resource), entry);
3981 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
3985 * Find existing push vlan resource or create and register a new one.
3987 * @param [in, out] dev
3988 * Pointer to rte_eth_dev structure.
3989 * @param[in, out] ref
3990 * Pointer to port ID action resource reference.
3991 * @parm[in, out] dev_flow
3992 * Pointer to the dev_flow.
3994 * pointer to error structure.
3997 * 0 on success otherwise -errno and errno is set.
4000 flow_dv_push_vlan_action_resource_register
4001 (struct rte_eth_dev *dev,
4002 struct mlx5_flow_dv_push_vlan_action_resource *ref,
4003 struct mlx5_flow *dev_flow,
4004 struct rte_flow_error *error)
4006 struct mlx5_priv *priv = dev->data->dev_private;
4007 struct mlx5_flow_dv_push_vlan_action_resource *resource;
4008 struct mlx5_list_entry *entry;
4009 struct mlx5_flow_cb_ctx ctx = {
4014 entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4017 resource = container_of(entry, typeof(*resource), entry);
4019 dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4020 dev_flow->dv.push_vlan_res = resource;
4025 * Get the size of specific rte_flow_item_type hdr size
4027 * @param[in] item_type
4028 * Tested rte_flow_item_type.
4031 * sizeof struct item_type, 0 if void or irrelevant.
4034 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4038 switch (item_type) {
4039 case RTE_FLOW_ITEM_TYPE_ETH:
4040 retval = sizeof(struct rte_ether_hdr);
4042 case RTE_FLOW_ITEM_TYPE_VLAN:
4043 retval = sizeof(struct rte_vlan_hdr);
4045 case RTE_FLOW_ITEM_TYPE_IPV4:
4046 retval = sizeof(struct rte_ipv4_hdr);
4048 case RTE_FLOW_ITEM_TYPE_IPV6:
4049 retval = sizeof(struct rte_ipv6_hdr);
4051 case RTE_FLOW_ITEM_TYPE_UDP:
4052 retval = sizeof(struct rte_udp_hdr);
4054 case RTE_FLOW_ITEM_TYPE_TCP:
4055 retval = sizeof(struct rte_tcp_hdr);
4057 case RTE_FLOW_ITEM_TYPE_VXLAN:
4058 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4059 retval = sizeof(struct rte_vxlan_hdr);
4061 case RTE_FLOW_ITEM_TYPE_GRE:
4062 case RTE_FLOW_ITEM_TYPE_NVGRE:
4063 retval = sizeof(struct rte_gre_hdr);
4065 case RTE_FLOW_ITEM_TYPE_MPLS:
4066 retval = sizeof(struct rte_mpls_hdr);
4068 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4076 #define MLX5_ENCAP_IPV4_VERSION 0x40
4077 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4078 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4079 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4080 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4081 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4082 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4085 * Convert the encap action data from list of rte_flow_item to raw buffer
4088 * Pointer to rte_flow_item objects list.
4090 * Pointer to the output buffer.
4092 * Pointer to the output buffer size.
4094 * Pointer to the error structure.
4097 * 0 on success, a negative errno value otherwise and rte_errno is set.
4100 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4101 size_t *size, struct rte_flow_error *error)
4103 struct rte_ether_hdr *eth = NULL;
4104 struct rte_vlan_hdr *vlan = NULL;
4105 struct rte_ipv4_hdr *ipv4 = NULL;
4106 struct rte_ipv6_hdr *ipv6 = NULL;
4107 struct rte_udp_hdr *udp = NULL;
4108 struct rte_vxlan_hdr *vxlan = NULL;
4109 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4110 struct rte_gre_hdr *gre = NULL;
4112 size_t temp_size = 0;
4115 return rte_flow_error_set(error, EINVAL,
4116 RTE_FLOW_ERROR_TYPE_ACTION,
4117 NULL, "invalid empty data");
4118 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4119 len = flow_dv_get_item_hdr_len(items->type);
4120 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4121 return rte_flow_error_set(error, EINVAL,
4122 RTE_FLOW_ERROR_TYPE_ACTION,
4123 (void *)items->type,
4124 "items total size is too big"
4125 " for encap action");
4126 rte_memcpy((void *)&buf[temp_size], items->spec, len);
4127 switch (items->type) {
4128 case RTE_FLOW_ITEM_TYPE_ETH:
4129 eth = (struct rte_ether_hdr *)&buf[temp_size];
4131 case RTE_FLOW_ITEM_TYPE_VLAN:
4132 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4134 return rte_flow_error_set(error, EINVAL,
4135 RTE_FLOW_ERROR_TYPE_ACTION,
4136 (void *)items->type,
4137 "eth header not found");
4138 if (!eth->ether_type)
4139 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4141 case RTE_FLOW_ITEM_TYPE_IPV4:
4142 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4144 return rte_flow_error_set(error, EINVAL,
4145 RTE_FLOW_ERROR_TYPE_ACTION,
4146 (void *)items->type,
4147 "neither eth nor vlan"
4149 if (vlan && !vlan->eth_proto)
4150 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4151 else if (eth && !eth->ether_type)
4152 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4153 if (!ipv4->version_ihl)
4154 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4155 MLX5_ENCAP_IPV4_IHL_MIN;
4156 if (!ipv4->time_to_live)
4157 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4159 case RTE_FLOW_ITEM_TYPE_IPV6:
4160 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4162 return rte_flow_error_set(error, EINVAL,
4163 RTE_FLOW_ERROR_TYPE_ACTION,
4164 (void *)items->type,
4165 "neither eth nor vlan"
4167 if (vlan && !vlan->eth_proto)
4168 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4169 else if (eth && !eth->ether_type)
4170 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4171 if (!ipv6->vtc_flow)
4173 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4174 if (!ipv6->hop_limits)
4175 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4177 case RTE_FLOW_ITEM_TYPE_UDP:
4178 udp = (struct rte_udp_hdr *)&buf[temp_size];
4180 return rte_flow_error_set(error, EINVAL,
4181 RTE_FLOW_ERROR_TYPE_ACTION,
4182 (void *)items->type,
4183 "ip header not found");
4184 if (ipv4 && !ipv4->next_proto_id)
4185 ipv4->next_proto_id = IPPROTO_UDP;
4186 else if (ipv6 && !ipv6->proto)
4187 ipv6->proto = IPPROTO_UDP;
4189 case RTE_FLOW_ITEM_TYPE_VXLAN:
4190 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4192 return rte_flow_error_set(error, EINVAL,
4193 RTE_FLOW_ERROR_TYPE_ACTION,
4194 (void *)items->type,
4195 "udp header not found");
4197 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4198 if (!vxlan->vx_flags)
4200 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4202 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4203 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4205 return rte_flow_error_set(error, EINVAL,
4206 RTE_FLOW_ERROR_TYPE_ACTION,
4207 (void *)items->type,
4208 "udp header not found");
4209 if (!vxlan_gpe->proto)
4210 return rte_flow_error_set(error, EINVAL,
4211 RTE_FLOW_ERROR_TYPE_ACTION,
4212 (void *)items->type,
4213 "next protocol not found");
4216 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4217 if (!vxlan_gpe->vx_flags)
4218 vxlan_gpe->vx_flags =
4219 MLX5_ENCAP_VXLAN_GPE_FLAGS;
4221 case RTE_FLOW_ITEM_TYPE_GRE:
4222 case RTE_FLOW_ITEM_TYPE_NVGRE:
4223 gre = (struct rte_gre_hdr *)&buf[temp_size];
4225 return rte_flow_error_set(error, EINVAL,
4226 RTE_FLOW_ERROR_TYPE_ACTION,
4227 (void *)items->type,
4228 "next protocol not found");
4230 return rte_flow_error_set(error, EINVAL,
4231 RTE_FLOW_ERROR_TYPE_ACTION,
4232 (void *)items->type,
4233 "ip header not found");
4234 if (ipv4 && !ipv4->next_proto_id)
4235 ipv4->next_proto_id = IPPROTO_GRE;
4236 else if (ipv6 && !ipv6->proto)
4237 ipv6->proto = IPPROTO_GRE;
4239 case RTE_FLOW_ITEM_TYPE_VOID:
4242 return rte_flow_error_set(error, EINVAL,
4243 RTE_FLOW_ERROR_TYPE_ACTION,
4244 (void *)items->type,
4245 "unsupported item type");
4255 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4257 struct rte_ether_hdr *eth = NULL;
4258 struct rte_vlan_hdr *vlan = NULL;
4259 struct rte_ipv6_hdr *ipv6 = NULL;
4260 struct rte_udp_hdr *udp = NULL;
4264 eth = (struct rte_ether_hdr *)data;
4265 next_hdr = (char *)(eth + 1);
4266 proto = RTE_BE16(eth->ether_type);
4269 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4270 vlan = (struct rte_vlan_hdr *)next_hdr;
4271 proto = RTE_BE16(vlan->eth_proto);
4272 next_hdr += sizeof(struct rte_vlan_hdr);
4275 /* HW calculates IPv4 csum. no need to proceed */
4276 if (proto == RTE_ETHER_TYPE_IPV4)
4279 /* non IPv4/IPv6 header. not supported */
4280 if (proto != RTE_ETHER_TYPE_IPV6) {
4281 return rte_flow_error_set(error, ENOTSUP,
4282 RTE_FLOW_ERROR_TYPE_ACTION,
4283 NULL, "Cannot offload non IPv4/IPv6");
4286 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4288 /* ignore non UDP */
4289 if (ipv6->proto != IPPROTO_UDP)
4292 udp = (struct rte_udp_hdr *)(ipv6 + 1);
4293 udp->dgram_cksum = 0;
4299 * Convert L2 encap action to DV specification.
4302 * Pointer to rte_eth_dev structure.
4304 * Pointer to action structure.
4305 * @param[in, out] dev_flow
4306 * Pointer to the mlx5_flow.
4307 * @param[in] transfer
4308 * Mark if the flow is E-Switch flow.
4310 * Pointer to the error structure.
4313 * 0 on success, a negative errno value otherwise and rte_errno is set.
4316 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4317 const struct rte_flow_action *action,
4318 struct mlx5_flow *dev_flow,
4320 struct rte_flow_error *error)
4322 const struct rte_flow_item *encap_data;
4323 const struct rte_flow_action_raw_encap *raw_encap_data;
4324 struct mlx5_flow_dv_encap_decap_resource res = {
4326 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4327 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4328 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4331 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4333 (const struct rte_flow_action_raw_encap *)action->conf;
4334 res.size = raw_encap_data->size;
4335 memcpy(res.buf, raw_encap_data->data, res.size);
4337 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4339 ((const struct rte_flow_action_vxlan_encap *)
4340 action->conf)->definition;
4343 ((const struct rte_flow_action_nvgre_encap *)
4344 action->conf)->definition;
4345 if (flow_dv_convert_encap_data(encap_data, res.buf,
4349 if (flow_dv_zero_encap_udp_csum(res.buf, error))
4351 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4352 return rte_flow_error_set(error, EINVAL,
4353 RTE_FLOW_ERROR_TYPE_ACTION,
4354 NULL, "can't create L2 encap action");
4359 * Convert L2 decap action to DV specification.
4362 * Pointer to rte_eth_dev structure.
4363 * @param[in, out] dev_flow
4364 * Pointer to the mlx5_flow.
4365 * @param[in] transfer
4366 * Mark if the flow is E-Switch flow.
4368 * Pointer to the error structure.
4371 * 0 on success, a negative errno value otherwise and rte_errno is set.
4374 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4375 struct mlx5_flow *dev_flow,
4377 struct rte_flow_error *error)
4379 struct mlx5_flow_dv_encap_decap_resource res = {
4382 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4383 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4384 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4387 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4388 return rte_flow_error_set(error, EINVAL,
4389 RTE_FLOW_ERROR_TYPE_ACTION,
4390 NULL, "can't create L2 decap action");
4395 * Convert raw decap/encap (L3 tunnel) action to DV specification.
4398 * Pointer to rte_eth_dev structure.
4400 * Pointer to action structure.
4401 * @param[in, out] dev_flow
4402 * Pointer to the mlx5_flow.
4404 * Pointer to the flow attributes.
4406 * Pointer to the error structure.
4409 * 0 on success, a negative errno value otherwise and rte_errno is set.
4412 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4413 const struct rte_flow_action *action,
4414 struct mlx5_flow *dev_flow,
4415 const struct rte_flow_attr *attr,
4416 struct rte_flow_error *error)
4418 const struct rte_flow_action_raw_encap *encap_data;
4419 struct mlx5_flow_dv_encap_decap_resource res;
4421 memset(&res, 0, sizeof(res));
4422 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4423 res.size = encap_data->size;
4424 memcpy(res.buf, encap_data->data, res.size);
4425 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4426 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4427 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4429 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4431 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4432 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4433 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4434 return rte_flow_error_set(error, EINVAL,
4435 RTE_FLOW_ERROR_TYPE_ACTION,
4436 NULL, "can't create encap action");
4441 * Create action push VLAN.
4444 * Pointer to rte_eth_dev structure.
4446 * Pointer to the flow attributes.
4448 * Pointer to the vlan to push to the Ethernet header.
4449 * @param[in, out] dev_flow
4450 * Pointer to the mlx5_flow.
4452 * Pointer to the error structure.
4455 * 0 on success, a negative errno value otherwise and rte_errno is set.
4458 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4459 const struct rte_flow_attr *attr,
4460 const struct rte_vlan_hdr *vlan,
4461 struct mlx5_flow *dev_flow,
4462 struct rte_flow_error *error)
4464 struct mlx5_flow_dv_push_vlan_action_resource res;
4466 memset(&res, 0, sizeof(res));
4468 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4471 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4473 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4474 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4475 return flow_dv_push_vlan_action_resource_register
4476 (dev, &res, dev_flow, error);
4480 * Validate the modify-header actions.
4482 * @param[in] action_flags
4483 * Holds the actions detected until now.
4485 * Pointer to the modify action.
4487 * Pointer to error structure.
4490 * 0 on success, a negative errno value otherwise and rte_errno is set.
4493 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4494 const struct rte_flow_action *action,
4495 struct rte_flow_error *error)
4497 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4498 return rte_flow_error_set(error, EINVAL,
4499 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4500 NULL, "action configuration not set");
4501 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4502 return rte_flow_error_set(error, EINVAL,
4503 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4504 "can't have encap action before"
4510 * Validate the modify-header MAC address actions.
4512 * @param[in] action_flags
4513 * Holds the actions detected until now.
4515 * Pointer to the modify action.
4516 * @param[in] item_flags
4517 * Holds the items detected.
4519 * Pointer to error structure.
4522 * 0 on success, a negative errno value otherwise and rte_errno is set.
4525 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
4526 const struct rte_flow_action *action,
4527 const uint64_t item_flags,
4528 struct rte_flow_error *error)
4532 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4534 if (!(item_flags & MLX5_FLOW_LAYER_L2))
4535 return rte_flow_error_set(error, EINVAL,
4536 RTE_FLOW_ERROR_TYPE_ACTION,
4538 "no L2 item in pattern");
4544 * Validate the modify-header IPv4 address actions.
4546 * @param[in] action_flags
4547 * Holds the actions detected until now.
4549 * Pointer to the modify action.
4550 * @param[in] item_flags
4551 * Holds the items detected.
4553 * Pointer to error structure.
4556 * 0 on success, a negative errno value otherwise and rte_errno is set.
4559 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
4560 const struct rte_flow_action *action,
4561 const uint64_t item_flags,
4562 struct rte_flow_error *error)
4567 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4569 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4570 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4571 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4572 if (!(item_flags & layer))
4573 return rte_flow_error_set(error, EINVAL,
4574 RTE_FLOW_ERROR_TYPE_ACTION,
4576 "no ipv4 item in pattern");
4582 * Validate the modify-header IPv6 address actions.
4584 * @param[in] action_flags
4585 * Holds the actions detected until now.
4587 * Pointer to the modify action.
4588 * @param[in] item_flags
4589 * Holds the items detected.
4591 * Pointer to error structure.
4594 * 0 on success, a negative errno value otherwise and rte_errno is set.
4597 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
4598 const struct rte_flow_action *action,
4599 const uint64_t item_flags,
4600 struct rte_flow_error *error)
4605 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4607 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4608 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4609 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4610 if (!(item_flags & layer))
4611 return rte_flow_error_set(error, EINVAL,
4612 RTE_FLOW_ERROR_TYPE_ACTION,
4614 "no ipv6 item in pattern");
4620 * Validate the modify-header TP actions.
4622 * @param[in] action_flags
4623 * Holds the actions detected until now.
4625 * Pointer to the modify action.
4626 * @param[in] item_flags
4627 * Holds the items detected.
4629 * Pointer to error structure.
4632 * 0 on success, a negative errno value otherwise and rte_errno is set.
4635 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
4636 const struct rte_flow_action *action,
4637 const uint64_t item_flags,
4638 struct rte_flow_error *error)
4643 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4645 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4646 MLX5_FLOW_LAYER_INNER_L4 :
4647 MLX5_FLOW_LAYER_OUTER_L4;
4648 if (!(item_flags & layer))
4649 return rte_flow_error_set(error, EINVAL,
4650 RTE_FLOW_ERROR_TYPE_ACTION,
4651 NULL, "no transport layer "
4658 * Validate the modify-header actions of increment/decrement
4659 * TCP Sequence-number.
4661 * @param[in] action_flags
4662 * Holds the actions detected until now.
4664 * Pointer to the modify action.
4665 * @param[in] item_flags
4666 * Holds the items detected.
4668 * Pointer to error structure.
4671 * 0 on success, a negative errno value otherwise and rte_errno is set.
4674 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
4675 const struct rte_flow_action *action,
4676 const uint64_t item_flags,
4677 struct rte_flow_error *error)
4682 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4684 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4685 MLX5_FLOW_LAYER_INNER_L4_TCP :
4686 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4687 if (!(item_flags & layer))
4688 return rte_flow_error_set(error, EINVAL,
4689 RTE_FLOW_ERROR_TYPE_ACTION,
4690 NULL, "no TCP item in"
4692 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
4693 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
4694 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
4695 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
4696 return rte_flow_error_set(error, EINVAL,
4697 RTE_FLOW_ERROR_TYPE_ACTION,
4699 "cannot decrease and increase"
4700 " TCP sequence number"
4701 " at the same time");
4707 * Validate the modify-header actions of increment/decrement
4708 * TCP Acknowledgment number.
4710 * @param[in] action_flags
4711 * Holds the actions detected until now.
4713 * Pointer to the modify action.
4714 * @param[in] item_flags
4715 * Holds the items detected.
4717 * Pointer to error structure.
4720 * 0 on success, a negative errno value otherwise and rte_errno is set.
4723 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
4724 const struct rte_flow_action *action,
4725 const uint64_t item_flags,
4726 struct rte_flow_error *error)
4731 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4733 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4734 MLX5_FLOW_LAYER_INNER_L4_TCP :
4735 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4736 if (!(item_flags & layer))
4737 return rte_flow_error_set(error, EINVAL,
4738 RTE_FLOW_ERROR_TYPE_ACTION,
4739 NULL, "no TCP item in"
4741 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
4742 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
4743 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
4744 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
4745 return rte_flow_error_set(error, EINVAL,
4746 RTE_FLOW_ERROR_TYPE_ACTION,
4748 "cannot decrease and increase"
4749 " TCP acknowledgment number"
4750 " at the same time");
4756 * Validate the modify-header TTL actions.
4758 * @param[in] action_flags
4759 * Holds the actions detected until now.
4761 * Pointer to the modify action.
4762 * @param[in] item_flags
4763 * Holds the items detected.
4765 * Pointer to error structure.
4768 * 0 on success, a negative errno value otherwise and rte_errno is set.
4771 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
4772 const struct rte_flow_action *action,
4773 const uint64_t item_flags,
4774 struct rte_flow_error *error)
4779 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4781 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4782 MLX5_FLOW_LAYER_INNER_L3 :
4783 MLX5_FLOW_LAYER_OUTER_L3;
4784 if (!(item_flags & layer))
4785 return rte_flow_error_set(error, EINVAL,
4786 RTE_FLOW_ERROR_TYPE_ACTION,
4788 "no IP protocol in pattern");
4794 * Validate the generic modify field actions.
4796 * Pointer to the rte_eth_dev structure.
4797 * @param[in] action_flags
4798 * Holds the actions detected until now.
4800 * Pointer to the modify action.
4802 * Pointer to the flow attributes.
4804 * Pointer to error structure.
4807 * Number of header fields to modify (0 or more) on success,
4808 * a negative errno value otherwise and rte_errno is set.
4811 flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
4812 const uint64_t action_flags,
4813 const struct rte_flow_action *action,
4814 const struct rte_flow_attr *attr,
4815 struct rte_flow_error *error)
4818 struct mlx5_priv *priv = dev->data->dev_private;
4819 struct mlx5_sh_config *config = &priv->sh->config;
4820 const struct rte_flow_action_modify_field *action_modify_field =
4822 uint32_t dst_width = mlx5_flow_item_field_width(dev,
4823 action_modify_field->dst.field,
4825 uint32_t src_width = mlx5_flow_item_field_width(dev,
4826 action_modify_field->src.field,
4827 dst_width, attr, error);
4829 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4833 if (action_modify_field->width == 0)
4834 return rte_flow_error_set(error, EINVAL,
4835 RTE_FLOW_ERROR_TYPE_ACTION, action,
4836 "no bits are requested to be modified");
4837 else if (action_modify_field->width > dst_width ||
4838 action_modify_field->width > src_width)
4839 return rte_flow_error_set(error, EINVAL,
4840 RTE_FLOW_ERROR_TYPE_ACTION, action,
4841 "cannot modify more bits than"
4842 " the width of a field");
4843 if (action_modify_field->dst.field != RTE_FLOW_FIELD_VALUE &&
4844 action_modify_field->dst.field != RTE_FLOW_FIELD_POINTER) {
4845 if ((action_modify_field->dst.offset +
4846 action_modify_field->width > dst_width) ||
4847 (action_modify_field->dst.offset % 32))
4848 return rte_flow_error_set(error, EINVAL,
4849 RTE_FLOW_ERROR_TYPE_ACTION, action,
4850 "destination offset is too big"
4851 " or not aligned to 4 bytes");
4852 if (action_modify_field->dst.level &&
4853 action_modify_field->dst.field != RTE_FLOW_FIELD_TAG)
4854 return rte_flow_error_set(error, ENOTSUP,
4855 RTE_FLOW_ERROR_TYPE_ACTION, action,
4856 "inner header fields modification"
4857 " is not supported");
4859 if (action_modify_field->src.field != RTE_FLOW_FIELD_VALUE &&
4860 action_modify_field->src.field != RTE_FLOW_FIELD_POINTER) {
4861 if (!attr->transfer && !attr->group)
4862 return rte_flow_error_set(error, ENOTSUP,
4863 RTE_FLOW_ERROR_TYPE_ACTION, action,
4864 "modify field action is not"
4865 " supported for group 0");
4866 if ((action_modify_field->src.offset +
4867 action_modify_field->width > src_width) ||
4868 (action_modify_field->src.offset % 32))
4869 return rte_flow_error_set(error, EINVAL,
4870 RTE_FLOW_ERROR_TYPE_ACTION, action,
4871 "source offset is too big"
4872 " or not aligned to 4 bytes");
4873 if (action_modify_field->src.level &&
4874 action_modify_field->src.field != RTE_FLOW_FIELD_TAG)
4875 return rte_flow_error_set(error, ENOTSUP,
4876 RTE_FLOW_ERROR_TYPE_ACTION, action,
4877 "inner header fields modification"
4878 " is not supported");
4880 if ((action_modify_field->dst.field ==
4881 action_modify_field->src.field) &&
4882 (action_modify_field->dst.level ==
4883 action_modify_field->src.level))
4884 return rte_flow_error_set(error, EINVAL,
4885 RTE_FLOW_ERROR_TYPE_ACTION, action,
4886 "source and destination fields"
4887 " cannot be the same");
4888 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VALUE ||
4889 action_modify_field->dst.field == RTE_FLOW_FIELD_POINTER ||
4890 action_modify_field->dst.field == RTE_FLOW_FIELD_MARK)
4891 return rte_flow_error_set(error, EINVAL,
4892 RTE_FLOW_ERROR_TYPE_ACTION, action,
4893 "mark, immediate value or a pointer to it"
4894 " cannot be used as a destination");
4895 if (action_modify_field->dst.field == RTE_FLOW_FIELD_START ||
4896 action_modify_field->src.field == RTE_FLOW_FIELD_START)
4897 return rte_flow_error_set(error, ENOTSUP,
4898 RTE_FLOW_ERROR_TYPE_ACTION, action,
4899 "modifications of an arbitrary"
4900 " place in a packet is not supported");
4901 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VLAN_TYPE ||
4902 action_modify_field->src.field == RTE_FLOW_FIELD_VLAN_TYPE)
4903 return rte_flow_error_set(error, ENOTSUP,
4904 RTE_FLOW_ERROR_TYPE_ACTION, action,
4905 "modifications of the 802.1Q Tag"
4906 " Identifier is not supported");
4907 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VXLAN_VNI ||
4908 action_modify_field->src.field == RTE_FLOW_FIELD_VXLAN_VNI)
4909 return rte_flow_error_set(error, ENOTSUP,
4910 RTE_FLOW_ERROR_TYPE_ACTION, action,
4911 "modifications of the VXLAN Network"
4912 " Identifier is not supported");
4913 if (action_modify_field->dst.field == RTE_FLOW_FIELD_GENEVE_VNI ||
4914 action_modify_field->src.field == RTE_FLOW_FIELD_GENEVE_VNI)
4915 return rte_flow_error_set(error, ENOTSUP,
4916 RTE_FLOW_ERROR_TYPE_ACTION, action,
4917 "modifications of the GENEVE Network"
4918 " Identifier is not supported");
4919 if (action_modify_field->dst.field == RTE_FLOW_FIELD_MARK ||
4920 action_modify_field->src.field == RTE_FLOW_FIELD_MARK)
4921 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4922 !mlx5_flow_ext_mreg_supported(dev))
4923 return rte_flow_error_set(error, ENOTSUP,
4924 RTE_FLOW_ERROR_TYPE_ACTION, action,
4925 "cannot modify mark in legacy mode"
4926 " or without extensive registers");
4927 if (action_modify_field->dst.field == RTE_FLOW_FIELD_META ||
4928 action_modify_field->src.field == RTE_FLOW_FIELD_META) {
4929 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
4930 !mlx5_flow_ext_mreg_supported(dev))
4931 return rte_flow_error_set(error, ENOTSUP,
4932 RTE_FLOW_ERROR_TYPE_ACTION, action,
4933 "cannot modify meta without"
4934 " extensive registers support");
4935 ret = flow_dv_get_metadata_reg(dev, attr, error);
4936 if (ret < 0 || ret == REG_NON)
4937 return rte_flow_error_set(error, ENOTSUP,
4938 RTE_FLOW_ERROR_TYPE_ACTION, action,
4939 "cannot modify meta without"
4940 " extensive registers available");
4942 if (action_modify_field->operation != RTE_FLOW_MODIFY_SET)
4943 return rte_flow_error_set(error, ENOTSUP,
4944 RTE_FLOW_ERROR_TYPE_ACTION, action,
4945 "add and sub operations"
4946 " are not supported");
4947 return (action_modify_field->width / 32) +
4948 !!(action_modify_field->width % 32);
4952 * Validate jump action.
4955 * Pointer to the jump action.
4956 * @param[in] action_flags
4957 * Holds the actions detected until now.
4958 * @param[in] attributes
4959 * Pointer to flow attributes
4960 * @param[in] external
4961 * Action belongs to flow rule created by request external to PMD.
4963 * Pointer to error structure.
4966 * 0 on success, a negative errno value otherwise and rte_errno is set.
4969 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
4970 const struct mlx5_flow_tunnel *tunnel,
4971 const struct rte_flow_action *action,
4972 uint64_t action_flags,
4973 const struct rte_flow_attr *attributes,
4974 bool external, struct rte_flow_error *error)
4976 uint32_t target_group, table = 0;
4978 struct flow_grp_info grp_info = {
4979 .external = !!external,
4980 .transfer = !!attributes->transfer,
4984 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4985 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4986 return rte_flow_error_set(error, EINVAL,
4987 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4988 "can't have 2 fate actions in"
4991 return rte_flow_error_set(error, EINVAL,
4992 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4993 NULL, "action configuration not set");
4995 ((const struct rte_flow_action_jump *)action->conf)->group;
4996 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5000 if (attributes->group == target_group &&
5001 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
5002 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
5003 return rte_flow_error_set(error, EINVAL,
5004 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5005 "target group must be other than"
5006 " the current flow group");
5008 return rte_flow_error_set(error, EINVAL,
5009 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5010 NULL, "root table shouldn't be destination");
5015 * Validate action PORT_ID / REPRESENTED_PORT.
5018 * Pointer to rte_eth_dev structure.
5019 * @param[in] action_flags
5020 * Bit-fields that holds the actions detected until now.
5022 * PORT_ID / REPRESENTED_PORT action structure.
5024 * Attributes of flow that includes this action.
5026 * Pointer to error structure.
5029 * 0 on success, a negative errno value otherwise and rte_errno is set.
5032 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5033 uint64_t action_flags,
5034 const struct rte_flow_action *action,
5035 const struct rte_flow_attr *attr,
5036 struct rte_flow_error *error)
5038 const struct rte_flow_action_port_id *port_id;
5039 const struct rte_flow_action_ethdev *ethdev;
5040 struct mlx5_priv *act_priv;
5041 struct mlx5_priv *dev_priv;
5044 if (!attr->transfer)
5045 return rte_flow_error_set(error, ENOTSUP,
5046 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5048 "port action is valid in transfer"
5050 if (!action || !action->conf)
5051 return rte_flow_error_set(error, ENOTSUP,
5052 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5054 "port action parameters must be"
5056 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5057 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5058 return rte_flow_error_set(error, EINVAL,
5059 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5060 "can have only one fate actions in"
5062 dev_priv = mlx5_dev_to_eswitch_info(dev);
5064 return rte_flow_error_set(error, rte_errno,
5065 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5067 "failed to obtain E-Switch info");
5068 switch (action->type) {
5069 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5070 port_id = action->conf;
5071 port = port_id->original ? dev->data->port_id : port_id->id;
5073 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5074 ethdev = action->conf;
5075 port = ethdev->port_id;
5079 return rte_flow_error_set
5081 RTE_FLOW_ERROR_TYPE_ACTION, action,
5082 "unknown E-Switch action");
5084 act_priv = mlx5_port_to_eswitch_info(port, false);
5086 return rte_flow_error_set
5088 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5089 "failed to obtain E-Switch port id for port");
5090 if (act_priv->domain_id != dev_priv->domain_id)
5091 return rte_flow_error_set
5093 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5094 "port does not belong to"
5095 " E-Switch being configured");
5100 * Get the maximum number of modify header actions.
5103 * Pointer to rte_eth_dev structure.
5105 * Whether action is on root table.
5108 * Max number of modify header actions device can support.
5110 static inline unsigned int
5111 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5115 * There's no way to directly query the max capacity from FW.
5116 * The maximal value on root table should be assumed to be supported.
5119 return MLX5_MAX_MODIFY_NUM;
5121 return MLX5_ROOT_TBL_MODIFY_NUM;
5125 * Validate the meter action.
5128 * Pointer to rte_eth_dev structure.
5129 * @param[in] action_flags
5130 * Bit-fields that holds the actions detected until now.
5131 * @param[in] item_flags
5132 * Holds the items detected.
5134 * Pointer to the meter action.
5136 * Attributes of flow that includes this action.
5137 * @param[in] port_id_item
5138 * Pointer to item indicating port id.
5140 * Pointer to error structure.
5143 * 0 on success, a negative errno value otherwise and rte_errno is set.
5146 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5147 uint64_t action_flags, uint64_t item_flags,
5148 const struct rte_flow_action *action,
5149 const struct rte_flow_attr *attr,
5150 const struct rte_flow_item *port_id_item,
5152 struct rte_flow_error *error)
5154 struct mlx5_priv *priv = dev->data->dev_private;
5155 const struct rte_flow_action_meter *am = action->conf;
5156 struct mlx5_flow_meter_info *fm;
5157 struct mlx5_flow_meter_policy *mtr_policy;
5158 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5161 return rte_flow_error_set(error, EINVAL,
5162 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5163 "meter action conf is NULL");
5165 if (action_flags & MLX5_FLOW_ACTION_METER)
5166 return rte_flow_error_set(error, ENOTSUP,
5167 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5168 "meter chaining not support");
5169 if (action_flags & MLX5_FLOW_ACTION_JUMP)
5170 return rte_flow_error_set(error, ENOTSUP,
5171 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5172 "meter with jump not support");
5174 return rte_flow_error_set(error, ENOTSUP,
5175 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5177 "meter action not supported");
5178 fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5180 return rte_flow_error_set(error, EINVAL,
5181 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5183 /* aso meter can always be shared by different domains */
5184 if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5185 !(fm->transfer == attr->transfer ||
5186 (!fm->ingress && !attr->ingress && attr->egress) ||
5187 (!fm->egress && !attr->egress && attr->ingress)))
5188 return rte_flow_error_set(error, EINVAL,
5189 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5190 "Flow attributes domain are either invalid "
5191 "or have a domain conflict with current "
5192 "meter attributes");
5193 if (fm->def_policy) {
5194 if (!((attr->transfer &&
5195 mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5197 mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5199 mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5200 return rte_flow_error_set(error, EINVAL,
5201 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5202 "Flow attributes domain "
5203 "have a conflict with current "
5204 "meter domain attributes");
5207 mtr_policy = mlx5_flow_meter_policy_find(dev,
5208 fm->policy_id, NULL);
5210 return rte_flow_error_set(error, EINVAL,
5211 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5212 "Invalid policy id for meter ");
5213 if (!((attr->transfer && mtr_policy->transfer) ||
5214 (attr->egress && mtr_policy->egress) ||
5215 (attr->ingress && mtr_policy->ingress)))
5216 return rte_flow_error_set(error, EINVAL,
5217 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5218 "Flow attributes domain "
5219 "have a conflict with current "
5220 "meter domain attributes");
5221 if (attr->transfer && mtr_policy->dev) {
5223 * When policy has fate action of port_id,
5224 * the flow should have the same src port as policy.
5226 struct mlx5_priv *policy_port_priv =
5227 mtr_policy->dev->data->dev_private;
5228 int32_t flow_src_port = priv->representor_id;
5231 const struct rte_flow_item_port_id *spec =
5233 struct mlx5_priv *port_priv =
5234 mlx5_port_to_eswitch_info(spec->id,
5237 return rte_flow_error_set(error,
5239 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5241 "Failed to get port info.");
5242 flow_src_port = port_priv->representor_id;
5244 if (flow_src_port != policy_port_priv->representor_id)
5245 return rte_flow_error_set(error,
5247 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5249 "Flow and meter policy "
5250 "have different src port.");
5251 } else if (mtr_policy->is_rss) {
5252 struct mlx5_flow_meter_policy *fp;
5253 struct mlx5_meter_policy_action_container *acg;
5254 struct mlx5_meter_policy_action_container *acy;
5255 const struct rte_flow_action *rss_act;
5258 fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
5261 return rte_flow_error_set(error, EINVAL,
5262 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5263 "Unable to get the final "
5264 "policy in the hierarchy");
5265 acg = &fp->act_cnt[RTE_COLOR_GREEN];
5266 acy = &fp->act_cnt[RTE_COLOR_YELLOW];
5267 MLX5_ASSERT(acg->fate_action ==
5268 MLX5_FLOW_FATE_SHARED_RSS ||
5270 MLX5_FLOW_FATE_SHARED_RSS);
5271 if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
5275 ret = mlx5_flow_validate_action_rss(rss_act,
5276 action_flags, dev, attr,
5281 *def_policy = false;
5287 * Validate the age action.
5289 * @param[in] action_flags
5290 * Holds the actions detected until now.
5292 * Pointer to the age action.
5294 * Pointer to the Ethernet device structure.
5296 * Pointer to error structure.
5299 * 0 on success, a negative errno value otherwise and rte_errno is set.
5302 flow_dv_validate_action_age(uint64_t action_flags,
5303 const struct rte_flow_action *action,
5304 struct rte_eth_dev *dev,
5305 struct rte_flow_error *error)
5307 struct mlx5_priv *priv = dev->data->dev_private;
5308 const struct rte_flow_action_age *age = action->conf;
5310 if (!priv->sh->cdev->config.devx ||
5311 (priv->sh->cmng.counter_fallback && !priv->sh->aso_age_mng))
5312 return rte_flow_error_set(error, ENOTSUP,
5313 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5315 "age action not supported");
5316 if (!(action->conf))
5317 return rte_flow_error_set(error, EINVAL,
5318 RTE_FLOW_ERROR_TYPE_ACTION, action,
5319 "configuration cannot be null");
5320 if (!(age->timeout))
5321 return rte_flow_error_set(error, EINVAL,
5322 RTE_FLOW_ERROR_TYPE_ACTION, action,
5323 "invalid timeout value 0");
5324 if (action_flags & MLX5_FLOW_ACTION_AGE)
5325 return rte_flow_error_set(error, EINVAL,
5326 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5327 "duplicate age actions set");
5332 * Validate the modify-header IPv4 DSCP actions.
5334 * @param[in] action_flags
5335 * Holds the actions detected until now.
5337 * Pointer to the modify action.
5338 * @param[in] item_flags
5339 * Holds the items detected.
5341 * Pointer to error structure.
5344 * 0 on success, a negative errno value otherwise and rte_errno is set.
5347 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
5348 const struct rte_flow_action *action,
5349 const uint64_t item_flags,
5350 struct rte_flow_error *error)
5354 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5356 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
5357 return rte_flow_error_set(error, EINVAL,
5358 RTE_FLOW_ERROR_TYPE_ACTION,
5360 "no ipv4 item in pattern");
5366 * Validate the modify-header IPv6 DSCP actions.
5368 * @param[in] action_flags
5369 * Holds the actions detected until now.
5371 * Pointer to the modify action.
5372 * @param[in] item_flags
5373 * Holds the items detected.
5375 * Pointer to error structure.
5378 * 0 on success, a negative errno value otherwise and rte_errno is set.
5381 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
5382 const struct rte_flow_action *action,
5383 const uint64_t item_flags,
5384 struct rte_flow_error *error)
5388 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5390 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5391 return rte_flow_error_set(error, EINVAL,
5392 RTE_FLOW_ERROR_TYPE_ACTION,
5394 "no ipv6 item in pattern");
5400 flow_dv_modify_match_cb(void *tool_ctx __rte_unused,
5401 struct mlx5_list_entry *entry, void *cb_ctx)
5403 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5404 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5405 struct mlx5_flow_dv_modify_hdr_resource *resource =
5406 container_of(entry, typeof(*resource), entry);
5407 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5409 key_len += ref->actions_num * sizeof(ref->actions[0]);
5410 return ref->actions_num != resource->actions_num ||
5411 memcmp(&ref->ft_type, &resource->ft_type, key_len);
5414 static struct mlx5_indexed_pool *
5415 flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
5417 struct mlx5_indexed_pool *ipool = __atomic_load_n
5418 (&sh->mdh_ipools[index], __ATOMIC_SEQ_CST);
5421 struct mlx5_indexed_pool *expected = NULL;
5422 struct mlx5_indexed_pool_config cfg =
5423 (struct mlx5_indexed_pool_config) {
5424 .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
5426 sizeof(struct mlx5_modification_cmd),
5431 .release_mem_en = !!sh->config.reclaim_mode,
5433 sh->config.reclaim_mode ? 0 : (1 << 16),
5434 .malloc = mlx5_malloc,
5436 .type = "mlx5_modify_action_resource",
5439 cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
5440 ipool = mlx5_ipool_create(&cfg);
5443 if (!__atomic_compare_exchange_n(&sh->mdh_ipools[index],
5444 &expected, ipool, false,
5446 __ATOMIC_SEQ_CST)) {
5447 mlx5_ipool_destroy(ipool);
5448 ipool = __atomic_load_n(&sh->mdh_ipools[index],
5455 struct mlx5_list_entry *
5456 flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
5458 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5459 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5460 struct mlx5dv_dr_domain *ns;
5461 struct mlx5_flow_dv_modify_hdr_resource *entry;
5462 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5463 struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
5464 ref->actions_num - 1);
5466 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5467 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5470 if (unlikely(!ipool)) {
5471 rte_flow_error_set(ctx->error, ENOMEM,
5472 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5473 NULL, "cannot allocate modify ipool");
5476 entry = mlx5_ipool_zmalloc(ipool, &idx);
5478 rte_flow_error_set(ctx->error, ENOMEM,
5479 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5480 "cannot allocate resource memory");
5483 rte_memcpy(&entry->ft_type,
5484 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5485 key_len + data_len);
5486 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5487 ns = sh->fdb_domain;
5488 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5492 ret = mlx5_flow_os_create_flow_action_modify_header
5493 (sh->cdev->ctx, ns, entry,
5494 data_len, &entry->action);
5496 mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
5497 rte_flow_error_set(ctx->error, ENOMEM,
5498 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5499 NULL, "cannot create modification action");
5503 return &entry->entry;
5506 struct mlx5_list_entry *
5507 flow_dv_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5510 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5511 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5512 struct mlx5_flow_dv_modify_hdr_resource *entry;
5513 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5514 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5517 entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
5520 rte_flow_error_set(ctx->error, ENOMEM,
5521 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5522 "cannot allocate resource memory");
5525 memcpy(entry, oentry, sizeof(*entry) + data_len);
5527 return &entry->entry;
5531 flow_dv_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5533 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5534 struct mlx5_flow_dv_modify_hdr_resource *res =
5535 container_of(entry, typeof(*res), entry);
5537 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
5541 * Validate the sample action.
5543 * @param[in, out] action_flags
5544 * Holds the actions detected until now.
5546 * Pointer to the sample action.
5548 * Pointer to the Ethernet device structure.
5550 * Attributes of flow that includes this action.
5551 * @param[in] item_flags
5552 * Holds the items detected.
5554 * Pointer to the RSS action.
5555 * @param[out] sample_rss
5556 * Pointer to the RSS action in sample action list.
5558 * Pointer to the COUNT action in sample action list.
5559 * @param[out] fdb_mirror_limit
5560 * Pointer to the FDB mirror limitation flag.
5562 * Pointer to error structure.
5565 * 0 on success, a negative errno value otherwise and rte_errno is set.
5568 flow_dv_validate_action_sample(uint64_t *action_flags,
5569 const struct rte_flow_action *action,
5570 struct rte_eth_dev *dev,
5571 const struct rte_flow_attr *attr,
5572 uint64_t item_flags,
5573 const struct rte_flow_action_rss *rss,
5574 const struct rte_flow_action_rss **sample_rss,
5575 const struct rte_flow_action_count **count,
5576 int *fdb_mirror_limit,
5577 struct rte_flow_error *error)
5579 struct mlx5_priv *priv = dev->data->dev_private;
5580 struct mlx5_sh_config *dev_conf = &priv->sh->config;
5581 const struct rte_flow_action_sample *sample = action->conf;
5582 const struct rte_flow_action *act;
5583 uint64_t sub_action_flags = 0;
5584 uint16_t queue_index = 0xFFFF;
5589 return rte_flow_error_set(error, EINVAL,
5590 RTE_FLOW_ERROR_TYPE_ACTION, action,
5591 "configuration cannot be NULL");
5592 if (sample->ratio == 0)
5593 return rte_flow_error_set(error, EINVAL,
5594 RTE_FLOW_ERROR_TYPE_ACTION, action,
5595 "ratio value starts from 1");
5596 if (!priv->sh->cdev->config.devx ||
5597 (sample->ratio > 0 && !priv->sampler_en))
5598 return rte_flow_error_set(error, ENOTSUP,
5599 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5601 "sample action not supported");
5602 if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
5603 return rte_flow_error_set(error, EINVAL,
5604 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5605 "Multiple sample actions not "
5607 if (*action_flags & MLX5_FLOW_ACTION_METER)
5608 return rte_flow_error_set(error, EINVAL,
5609 RTE_FLOW_ERROR_TYPE_ACTION, action,
5610 "wrong action order, meter should "
5611 "be after sample action");
5612 if (*action_flags & MLX5_FLOW_ACTION_JUMP)
5613 return rte_flow_error_set(error, EINVAL,
5614 RTE_FLOW_ERROR_TYPE_ACTION, action,
5615 "wrong action order, jump should "
5616 "be after sample action");
5617 if (*action_flags & MLX5_FLOW_ACTION_CT)
5618 return rte_flow_error_set(error, EINVAL,
5619 RTE_FLOW_ERROR_TYPE_ACTION, action,
5620 "Sample after CT not supported");
5621 act = sample->actions;
5622 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
5623 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5624 return rte_flow_error_set(error, ENOTSUP,
5625 RTE_FLOW_ERROR_TYPE_ACTION,
5626 act, "too many actions");
5627 switch (act->type) {
5628 case RTE_FLOW_ACTION_TYPE_QUEUE:
5629 ret = mlx5_flow_validate_action_queue(act,
5635 queue_index = ((const struct rte_flow_action_queue *)
5636 (act->conf))->index;
5637 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
5640 case RTE_FLOW_ACTION_TYPE_RSS:
5641 *sample_rss = act->conf;
5642 ret = mlx5_flow_validate_action_rss(act,
5649 if (rss && *sample_rss &&
5650 ((*sample_rss)->level != rss->level ||
5651 (*sample_rss)->types != rss->types))
5652 return rte_flow_error_set(error, ENOTSUP,
5653 RTE_FLOW_ERROR_TYPE_ACTION,
5655 "Can't use the different RSS types "
5656 "or level in the same flow");
5657 if (*sample_rss != NULL && (*sample_rss)->queue_num)
5658 queue_index = (*sample_rss)->queue[0];
5659 sub_action_flags |= MLX5_FLOW_ACTION_RSS;
5662 case RTE_FLOW_ACTION_TYPE_MARK:
5663 ret = flow_dv_validate_action_mark(dev, act,
5668 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
5669 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
5670 MLX5_FLOW_ACTION_MARK_EXT;
5672 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
5675 case RTE_FLOW_ACTION_TYPE_COUNT:
5676 ret = flow_dv_validate_action_count
5677 (dev, false, *action_flags | sub_action_flags,
5682 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
5683 *action_flags |= MLX5_FLOW_ACTION_COUNT;
5686 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5687 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5688 ret = flow_dv_validate_action_port_id(dev,
5695 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5698 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5699 ret = flow_dv_validate_action_raw_encap_decap
5700 (dev, NULL, act->conf, attr, &sub_action_flags,
5701 &actions_n, action, item_flags, error);
5706 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5707 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5708 ret = flow_dv_validate_action_l2_encap(dev,
5714 sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
5718 return rte_flow_error_set(error, ENOTSUP,
5719 RTE_FLOW_ERROR_TYPE_ACTION,
5721 "Doesn't support optional "
5725 if (attr->ingress && !attr->transfer) {
5726 if (!(sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
5727 MLX5_FLOW_ACTION_RSS)))
5728 return rte_flow_error_set(error, EINVAL,
5729 RTE_FLOW_ERROR_TYPE_ACTION,
5731 "Ingress must has a dest "
5732 "QUEUE for Sample");
5733 } else if (attr->egress && !attr->transfer) {
5734 return rte_flow_error_set(error, ENOTSUP,
5735 RTE_FLOW_ERROR_TYPE_ACTION,
5737 "Sample Only support Ingress "
5739 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
5740 MLX5_ASSERT(attr->transfer);
5741 if (sample->ratio > 1)
5742 return rte_flow_error_set(error, ENOTSUP,
5743 RTE_FLOW_ERROR_TYPE_ACTION,
5745 "E-Switch doesn't support "
5746 "any optional action "
5748 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
5749 return rte_flow_error_set(error, ENOTSUP,
5750 RTE_FLOW_ERROR_TYPE_ACTION,
5752 "unsupported action QUEUE");
5753 if (sub_action_flags & MLX5_FLOW_ACTION_RSS)
5754 return rte_flow_error_set(error, ENOTSUP,
5755 RTE_FLOW_ERROR_TYPE_ACTION,
5757 "unsupported action QUEUE");
5758 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
5759 return rte_flow_error_set(error, EINVAL,
5760 RTE_FLOW_ERROR_TYPE_ACTION,
5762 "E-Switch must has a dest "
5763 "port for mirroring");
5764 if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
5765 priv->representor_id != UINT16_MAX)
5766 *fdb_mirror_limit = 1;
5768 /* Continue validation for Xcap actions.*/
5769 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
5770 (queue_index == 0xFFFF ||
5771 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5772 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5773 MLX5_FLOW_XCAP_ACTIONS)
5774 return rte_flow_error_set(error, ENOTSUP,
5775 RTE_FLOW_ERROR_TYPE_ACTION,
5776 NULL, "encap and decap "
5777 "combination aren't "
5779 if (!attr->transfer && attr->ingress && (sub_action_flags &
5780 MLX5_FLOW_ACTION_ENCAP))
5781 return rte_flow_error_set(error, ENOTSUP,
5782 RTE_FLOW_ERROR_TYPE_ACTION,
5783 NULL, "encap is not supported"
5784 " for ingress traffic");
5790 * Find existing modify-header resource or create and register a new one.
5792 * @param dev[in, out]
5793 * Pointer to rte_eth_dev structure.
5794 * @param[in, out] resource
5795 * Pointer to modify-header resource.
5796 * @parm[in, out] dev_flow
5797 * Pointer to the dev_flow.
5799 * pointer to error structure.
5802 * 0 on success otherwise -errno and errno is set.
5805 flow_dv_modify_hdr_resource_register
5806 (struct rte_eth_dev *dev,
5807 struct mlx5_flow_dv_modify_hdr_resource *resource,
5808 struct mlx5_flow *dev_flow,
5809 struct rte_flow_error *error)
5811 struct mlx5_priv *priv = dev->data->dev_private;
5812 struct mlx5_dev_ctx_shared *sh = priv->sh;
5813 uint32_t key_len = sizeof(*resource) -
5814 offsetof(typeof(*resource), ft_type) +
5815 resource->actions_num * sizeof(resource->actions[0]);
5816 struct mlx5_list_entry *entry;
5817 struct mlx5_flow_cb_ctx ctx = {
5821 struct mlx5_hlist *modify_cmds;
5824 modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
5826 MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
5828 flow_dv_modify_create_cb,
5829 flow_dv_modify_match_cb,
5830 flow_dv_modify_remove_cb,
5831 flow_dv_modify_clone_cb,
5832 flow_dv_modify_clone_free_cb,
5834 if (unlikely(!modify_cmds))
5836 resource->root = !dev_flow->dv.group;
5837 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
5839 return rte_flow_error_set(error, EOVERFLOW,
5840 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5841 "too many modify header items");
5842 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
5843 entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
5846 resource = container_of(entry, typeof(*resource), entry);
5847 dev_flow->handle->dvh.modify_hdr = resource;
5852 * Get DV flow counter by index.
5855 * Pointer to the Ethernet device structure.
5857 * mlx5 flow counter index in the container.
5859 * mlx5 flow counter pool in the container.
5862 * Pointer to the counter, NULL otherwise.
5864 static struct mlx5_flow_counter *
5865 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
5867 struct mlx5_flow_counter_pool **ppool)
5869 struct mlx5_priv *priv = dev->data->dev_private;
5870 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5871 struct mlx5_flow_counter_pool *pool;
5873 /* Decrease to original index and clear shared bit. */
5874 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
5875 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
5876 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
5880 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
5884 * Check the devx counter belongs to the pool.
5887 * Pointer to the counter pool.
5889 * The counter devx ID.
5892 * True if counter belongs to the pool, false otherwise.
5895 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
5897 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
5898 MLX5_COUNTERS_PER_POOL;
5900 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
5906 * Get a pool by devx counter ID.
5909 * Pointer to the counter management.
5911 * The counter devx ID.
5914 * The counter pool pointer if exists, NULL otherwise,
5916 static struct mlx5_flow_counter_pool *
5917 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
5920 struct mlx5_flow_counter_pool *pool = NULL;
5922 rte_spinlock_lock(&cmng->pool_update_sl);
5923 /* Check last used pool. */
5924 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
5925 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
5926 pool = cmng->pools[cmng->last_pool_idx];
5929 /* ID out of range means no suitable pool in the container. */
5930 if (id > cmng->max_id || id < cmng->min_id)
5933 * Find the pool from the end of the container, since mostly counter
5934 * ID is sequence increasing, and the last pool should be the needed
5939 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
5941 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
5947 rte_spinlock_unlock(&cmng->pool_update_sl);
5952 * Resize a counter container.
5955 * Pointer to the Ethernet device structure.
5958 * 0 on success, otherwise negative errno value and rte_errno is set.
5961 flow_dv_container_resize(struct rte_eth_dev *dev)
5963 struct mlx5_priv *priv = dev->data->dev_private;
5964 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5965 void *old_pools = cmng->pools;
5966 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
5967 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
5968 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
5975 memcpy(pools, old_pools, cmng->n *
5976 sizeof(struct mlx5_flow_counter_pool *));
5978 cmng->pools = pools;
5980 mlx5_free(old_pools);
5985 * Query a devx flow counter.
5988 * Pointer to the Ethernet device structure.
5989 * @param[in] counter
5990 * Index to the flow counter.
5992 * The statistics value of packets.
5994 * The statistics value of bytes.
5997 * 0 on success, otherwise a negative errno value and rte_errno is set.
6000 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6003 struct mlx5_priv *priv = dev->data->dev_private;
6004 struct mlx5_flow_counter_pool *pool = NULL;
6005 struct mlx5_flow_counter *cnt;
6008 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6010 if (priv->sh->cmng.counter_fallback)
6011 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6012 0, pkts, bytes, 0, NULL, NULL, 0);
6013 rte_spinlock_lock(&pool->sl);
6018 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6019 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6020 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6022 rte_spinlock_unlock(&pool->sl);
6027 * Create and initialize a new counter pool.
6030 * Pointer to the Ethernet device structure.
6032 * The devX counter handle.
6034 * Whether the pool is for counter that was allocated for aging.
6035 * @param[in/out] cont_cur
6036 * Pointer to the container pointer, it will be update in pool resize.
6039 * The pool container pointer on success, NULL otherwise and rte_errno is set.
6041 static struct mlx5_flow_counter_pool *
6042 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6045 struct mlx5_priv *priv = dev->data->dev_private;
6046 struct mlx5_flow_counter_pool *pool;
6047 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6048 bool fallback = priv->sh->cmng.counter_fallback;
6049 uint32_t size = sizeof(*pool);
6051 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6052 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6053 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6059 pool->is_aged = !!age;
6060 pool->query_gen = 0;
6061 pool->min_dcs = dcs;
6062 rte_spinlock_init(&pool->sl);
6063 rte_spinlock_init(&pool->csl);
6064 TAILQ_INIT(&pool->counters[0]);
6065 TAILQ_INIT(&pool->counters[1]);
6066 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6067 rte_spinlock_lock(&cmng->pool_update_sl);
6068 pool->index = cmng->n_valid;
6069 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
6071 rte_spinlock_unlock(&cmng->pool_update_sl);
6074 cmng->pools[pool->index] = pool;
6076 if (unlikely(fallback)) {
6077 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6079 if (base < cmng->min_id)
6080 cmng->min_id = base;
6081 if (base > cmng->max_id)
6082 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6083 cmng->last_pool_idx = pool->index;
6085 rte_spinlock_unlock(&cmng->pool_update_sl);
6090 * Prepare a new counter and/or a new counter pool.
6093 * Pointer to the Ethernet device structure.
6094 * @param[out] cnt_free
6095 * Where to put the pointer of a new counter.
6097 * Whether the pool is for counter that was allocated for aging.
6100 * The counter pool pointer and @p cnt_free is set on success,
6101 * NULL otherwise and rte_errno is set.
6103 static struct mlx5_flow_counter_pool *
6104 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6105 struct mlx5_flow_counter **cnt_free,
6108 struct mlx5_priv *priv = dev->data->dev_private;
6109 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6110 struct mlx5_flow_counter_pool *pool;
6111 struct mlx5_counters tmp_tq;
6112 struct mlx5_devx_obj *dcs = NULL;
6113 struct mlx5_flow_counter *cnt;
6114 enum mlx5_counter_type cnt_type =
6115 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6116 bool fallback = priv->sh->cmng.counter_fallback;
6120 /* bulk_bitmap must be 0 for single counter allocation. */
6121 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6124 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6126 pool = flow_dv_pool_create(dev, dcs, age);
6128 mlx5_devx_cmd_destroy(dcs);
6132 i = dcs->id % MLX5_COUNTERS_PER_POOL;
6133 cnt = MLX5_POOL_GET_CNT(pool, i);
6135 cnt->dcs_when_free = dcs;
6139 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6141 rte_errno = ENODATA;
6144 pool = flow_dv_pool_create(dev, dcs, age);
6146 mlx5_devx_cmd_destroy(dcs);
6149 TAILQ_INIT(&tmp_tq);
6150 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6151 cnt = MLX5_POOL_GET_CNT(pool, i);
6153 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6155 rte_spinlock_lock(&cmng->csl[cnt_type]);
6156 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6157 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6158 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6159 (*cnt_free)->pool = pool;
6164 * Allocate a flow counter.
6167 * Pointer to the Ethernet device structure.
6169 * Whether the counter was allocated for aging.
6172 * Index to flow counter on success, 0 otherwise and rte_errno is set.
6175 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6177 struct mlx5_priv *priv = dev->data->dev_private;
6178 struct mlx5_flow_counter_pool *pool = NULL;
6179 struct mlx5_flow_counter *cnt_free = NULL;
6180 bool fallback = priv->sh->cmng.counter_fallback;
6181 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6182 enum mlx5_counter_type cnt_type =
6183 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6186 if (!priv->sh->cdev->config.devx) {
6187 rte_errno = ENOTSUP;
6190 /* Get free counters from container. */
6191 rte_spinlock_lock(&cmng->csl[cnt_type]);
6192 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6194 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6195 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6196 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6198 pool = cnt_free->pool;
6200 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6201 /* Create a DV counter action only in the first time usage. */
6202 if (!cnt_free->action) {
6204 struct mlx5_devx_obj *dcs;
6208 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
6209 dcs = pool->min_dcs;
6212 dcs = cnt_free->dcs_when_free;
6214 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
6221 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
6222 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
6223 /* Update the counter reset values. */
6224 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
6227 if (!fallback && !priv->sh->cmng.query_thread_on)
6228 /* Start the asynchronous batch query by the host thread. */
6229 mlx5_set_query_alarm(priv->sh);
6231 * When the count action isn't shared (by ID), shared_info field is
6232 * used for indirect action API's refcnt.
6233 * When the counter action is not shared neither by ID nor by indirect
6234 * action API, shared info must be 1.
6236 cnt_free->shared_info.refcnt = 1;
6240 cnt_free->pool = pool;
6242 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
6243 rte_spinlock_lock(&cmng->csl[cnt_type]);
6244 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
6245 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6251 * Get age param from counter index.
6254 * Pointer to the Ethernet device structure.
6255 * @param[in] counter
6256 * Index to the counter handler.
6259 * The aging parameter specified for the counter index.
6261 static struct mlx5_age_param*
6262 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6265 struct mlx5_flow_counter *cnt;
6266 struct mlx5_flow_counter_pool *pool = NULL;
6268 flow_dv_counter_get_by_idx(dev, counter, &pool);
6269 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6270 cnt = MLX5_POOL_GET_CNT(pool, counter);
6271 return MLX5_CNT_TO_AGE(cnt);
6275 * Remove a flow counter from aged counter list.
6278 * Pointer to the Ethernet device structure.
6279 * @param[in] counter
6280 * Index to the counter handler.
6282 * Pointer to the counter handler.
6285 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6286 uint32_t counter, struct mlx5_flow_counter *cnt)
6288 struct mlx5_age_info *age_info;
6289 struct mlx5_age_param *age_param;
6290 struct mlx5_priv *priv = dev->data->dev_private;
6291 uint16_t expected = AGE_CANDIDATE;
6293 age_info = GET_PORT_AGE_INFO(priv);
6294 age_param = flow_dv_counter_idx_get_age(dev, counter);
6295 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6296 AGE_FREE, false, __ATOMIC_RELAXED,
6297 __ATOMIC_RELAXED)) {
6299 * We need the lock even it is age timeout,
6300 * since counter may still in process.
6302 rte_spinlock_lock(&age_info->aged_sl);
6303 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6304 rte_spinlock_unlock(&age_info->aged_sl);
6305 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6310 * Release a flow counter.
6313 * Pointer to the Ethernet device structure.
6314 * @param[in] counter
6315 * Index to the counter handler.
6318 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6320 struct mlx5_priv *priv = dev->data->dev_private;
6321 struct mlx5_flow_counter_pool *pool = NULL;
6322 struct mlx5_flow_counter *cnt;
6323 enum mlx5_counter_type cnt_type;
6327 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6329 if (pool->is_aged) {
6330 flow_dv_counter_remove_from_age(dev, counter, cnt);
6333 * If the counter action is shared by indirect action API,
6334 * the atomic function reduces its references counter.
6335 * If after the reduction the action is still referenced, the
6336 * function returns here and does not release it.
6337 * When the counter action is not shared by
6338 * indirect action API, shared info is 1 before the reduction,
6339 * so this condition is failed and function doesn't return here.
6341 if (__atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
6347 * Put the counter back to list to be updated in none fallback mode.
6348 * Currently, we are using two list alternately, while one is in query,
6349 * add the freed counter to the other list based on the pool query_gen
6350 * value. After query finishes, add counter the list to the global
6351 * container counter list. The list changes while query starts. In
6352 * this case, lock will not be needed as query callback and release
6353 * function both operate with the different list.
6355 if (!priv->sh->cmng.counter_fallback) {
6356 rte_spinlock_lock(&pool->csl);
6357 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
6358 rte_spinlock_unlock(&pool->csl);
6360 cnt->dcs_when_free = cnt->dcs_when_active;
6361 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6362 MLX5_COUNTER_TYPE_ORIGIN;
6363 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
6364 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
6366 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
6371 * Resize a meter id container.
6374 * Pointer to the Ethernet device structure.
6377 * 0 on success, otherwise negative errno value and rte_errno is set.
6380 flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
6382 struct mlx5_priv *priv = dev->data->dev_private;
6383 struct mlx5_aso_mtr_pools_mng *pools_mng =
6384 &priv->sh->mtrmng->pools_mng;
6385 void *old_pools = pools_mng->pools;
6386 uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
6387 uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
6388 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6395 if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER)) {
6400 memcpy(pools, old_pools, pools_mng->n *
6401 sizeof(struct mlx5_aso_mtr_pool *));
6402 pools_mng->n = resize;
6403 pools_mng->pools = pools;
6405 mlx5_free(old_pools);
6410 * Prepare a new meter and/or a new meter pool.
6413 * Pointer to the Ethernet device structure.
6414 * @param[out] mtr_free
6415 * Where to put the pointer of a new meter.g.
6418 * The meter pool pointer and @mtr_free is set on success,
6419 * NULL otherwise and rte_errno is set.
6421 static struct mlx5_aso_mtr_pool *
6422 flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
6424 struct mlx5_priv *priv = dev->data->dev_private;
6425 struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
6426 struct mlx5_aso_mtr_pool *pool = NULL;
6427 struct mlx5_devx_obj *dcs = NULL;
6429 uint32_t log_obj_size;
6431 log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
6432 dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
6433 priv->sh->cdev->pdn,
6436 rte_errno = ENODATA;
6439 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
6442 claim_zero(mlx5_devx_cmd_destroy(dcs));
6445 pool->devx_obj = dcs;
6446 rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
6447 pool->index = pools_mng->n_valid;
6448 if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
6450 claim_zero(mlx5_devx_cmd_destroy(dcs));
6451 rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
6454 pools_mng->pools[pool->index] = pool;
6455 pools_mng->n_valid++;
6456 rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
6457 for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
6458 pool->mtrs[i].offset = i;
6459 LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
6461 pool->mtrs[0].offset = 0;
6462 *mtr_free = &pool->mtrs[0];
6467 * Release a flow meter into pool.
6470 * Pointer to the Ethernet device structure.
6471 * @param[in] mtr_idx
6472 * Index to aso flow meter.
6475 flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
6477 struct mlx5_priv *priv = dev->data->dev_private;
6478 struct mlx5_aso_mtr_pools_mng *pools_mng =
6479 &priv->sh->mtrmng->pools_mng;
6480 struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
6482 MLX5_ASSERT(aso_mtr);
6483 rte_spinlock_lock(&pools_mng->mtrsl);
6484 memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
6485 aso_mtr->state = ASO_METER_FREE;
6486 LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
6487 rte_spinlock_unlock(&pools_mng->mtrsl);
6491 * Allocate a aso flow meter.
6494 * Pointer to the Ethernet device structure.
6497 * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
6500 flow_dv_mtr_alloc(struct rte_eth_dev *dev)
6502 struct mlx5_priv *priv = dev->data->dev_private;
6503 struct mlx5_aso_mtr *mtr_free = NULL;
6504 struct mlx5_aso_mtr_pools_mng *pools_mng =
6505 &priv->sh->mtrmng->pools_mng;
6506 struct mlx5_aso_mtr_pool *pool;
6507 uint32_t mtr_idx = 0;
6509 if (!priv->sh->cdev->config.devx) {
6510 rte_errno = ENOTSUP;
6513 /* Allocate the flow meter memory. */
6514 /* Get free meters from management. */
6515 rte_spinlock_lock(&pools_mng->mtrsl);
6516 mtr_free = LIST_FIRST(&pools_mng->meters);
6518 LIST_REMOVE(mtr_free, next);
6519 if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
6520 rte_spinlock_unlock(&pools_mng->mtrsl);
6523 mtr_free->state = ASO_METER_WAIT;
6524 rte_spinlock_unlock(&pools_mng->mtrsl);
6525 pool = container_of(mtr_free,
6526 struct mlx5_aso_mtr_pool,
6527 mtrs[mtr_free->offset]);
6528 mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
6529 if (!mtr_free->fm.meter_action) {
6530 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
6531 struct rte_flow_error error;
6534 reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
6535 mtr_free->fm.meter_action =
6536 mlx5_glue->dv_create_flow_action_aso
6537 (priv->sh->rx_domain,
6538 pool->devx_obj->obj,
6540 (1 << MLX5_FLOW_COLOR_GREEN),
6542 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
6543 if (!mtr_free->fm.meter_action) {
6544 flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
6552 * Verify the @p attributes will be correctly understood by the NIC and store
6553 * them in the @p flow if everything is correct.
6556 * Pointer to dev struct.
6557 * @param[in] attributes
6558 * Pointer to flow attributes
6559 * @param[in] external
6560 * This flow rule is created by request external to PMD.
6562 * Pointer to error structure.
6565 * - 0 on success and non root table.
6566 * - 1 on success and root table.
6567 * - a negative errno value otherwise and rte_errno is set.
6570 flow_dv_validate_attributes(struct rte_eth_dev *dev,
6571 const struct mlx5_flow_tunnel *tunnel,
6572 const struct rte_flow_attr *attributes,
6573 const struct flow_grp_info *grp_info,
6574 struct rte_flow_error *error)
6576 struct mlx5_priv *priv = dev->data->dev_private;
6577 uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
6580 #ifndef HAVE_MLX5DV_DR
6581 RTE_SET_USED(tunnel);
6582 RTE_SET_USED(grp_info);
6583 if (attributes->group)
6584 return rte_flow_error_set(error, ENOTSUP,
6585 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6587 "groups are not supported");
6591 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
6596 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
6598 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
6599 attributes->priority > lowest_priority)
6600 return rte_flow_error_set(error, ENOTSUP,
6601 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
6603 "priority out of range");
6604 if (attributes->transfer) {
6605 if (!priv->sh->config.dv_esw_en)
6606 return rte_flow_error_set
6608 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6609 "E-Switch dr is not supported");
6610 if (attributes->egress)
6611 return rte_flow_error_set
6613 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
6614 "egress is not supported");
6616 if (!(attributes->egress ^ attributes->ingress))
6617 return rte_flow_error_set(error, ENOTSUP,
6618 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6619 "must specify exactly one of "
6620 "ingress or egress");
6625 validate_integrity_bits(const struct rte_flow_item_integrity *mask,
6626 int64_t pattern_flags, uint64_t l3_flags,
6627 uint64_t l4_flags, uint64_t ip4_flag,
6628 struct rte_flow_error *error)
6630 if (mask->l3_ok && !(pattern_flags & l3_flags))
6631 return rte_flow_error_set(error, EINVAL,
6632 RTE_FLOW_ERROR_TYPE_ITEM,
6633 NULL, "missing L3 protocol");
6635 if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
6636 return rte_flow_error_set(error, EINVAL,
6637 RTE_FLOW_ERROR_TYPE_ITEM,
6638 NULL, "missing IPv4 protocol");
6640 if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
6641 return rte_flow_error_set(error, EINVAL,
6642 RTE_FLOW_ERROR_TYPE_ITEM,
6643 NULL, "missing L4 protocol");
6649 flow_dv_validate_item_integrity_post(const struct
6650 rte_flow_item *integrity_items[2],
6651 int64_t pattern_flags,
6652 struct rte_flow_error *error)
6654 const struct rte_flow_item_integrity *mask;
6657 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
6658 mask = (typeof(mask))integrity_items[0]->mask;
6659 ret = validate_integrity_bits(mask, pattern_flags,
6660 MLX5_FLOW_LAYER_OUTER_L3,
6661 MLX5_FLOW_LAYER_OUTER_L4,
6662 MLX5_FLOW_LAYER_OUTER_L3_IPV4,
6667 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
6668 mask = (typeof(mask))integrity_items[1]->mask;
6669 ret = validate_integrity_bits(mask, pattern_flags,
6670 MLX5_FLOW_LAYER_INNER_L3,
6671 MLX5_FLOW_LAYER_INNER_L4,
6672 MLX5_FLOW_LAYER_INNER_L3_IPV4,
6681 flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
6682 const struct rte_flow_item *integrity_item,
6683 uint64_t pattern_flags, uint64_t *last_item,
6684 const struct rte_flow_item *integrity_items[2],
6685 struct rte_flow_error *error)
6687 struct mlx5_priv *priv = dev->data->dev_private;
6688 const struct rte_flow_item_integrity *mask = (typeof(mask))
6689 integrity_item->mask;
6690 const struct rte_flow_item_integrity *spec = (typeof(spec))
6691 integrity_item->spec;
6693 if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
6694 return rte_flow_error_set(error, ENOTSUP,
6695 RTE_FLOW_ERROR_TYPE_ITEM,
6697 "packet integrity integrity_item not supported");
6699 return rte_flow_error_set(error, ENOTSUP,
6700 RTE_FLOW_ERROR_TYPE_ITEM,
6702 "no spec for integrity item");
6704 mask = &rte_flow_item_integrity_mask;
6705 if (!mlx5_validate_integrity_item(mask))
6706 return rte_flow_error_set(error, ENOTSUP,
6707 RTE_FLOW_ERROR_TYPE_ITEM,
6709 "unsupported integrity filter");
6710 if (spec->level > 1) {
6711 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
6712 return rte_flow_error_set
6714 RTE_FLOW_ERROR_TYPE_ITEM,
6715 NULL, "multiple inner integrity items not supported");
6716 integrity_items[1] = integrity_item;
6717 *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
6719 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
6720 return rte_flow_error_set
6722 RTE_FLOW_ERROR_TYPE_ITEM,
6723 NULL, "multiple outer integrity items not supported");
6724 integrity_items[0] = integrity_item;
6725 *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
6731 flow_dv_validate_item_flex(struct rte_eth_dev *dev,
6732 const struct rte_flow_item *item,
6733 uint64_t item_flags,
6734 uint64_t *last_item,
6736 struct rte_flow_error *error)
6738 const struct rte_flow_item_flex *flow_spec = item->spec;
6739 const struct rte_flow_item_flex *flow_mask = item->mask;
6740 struct mlx5_flex_item *flex;
6743 return rte_flow_error_set(error, EINVAL,
6744 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6745 "flex flow item spec cannot be NULL");
6747 return rte_flow_error_set(error, EINVAL,
6748 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6749 "flex flow item mask cannot be NULL");
6751 return rte_flow_error_set(error, ENOTSUP,
6752 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6753 "flex flow item last not supported");
6754 if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
6755 return rte_flow_error_set(error, EINVAL,
6756 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6757 "invalid flex flow item handle");
6758 flex = (struct mlx5_flex_item *)flow_spec->handle;
6759 switch (flex->tunnel_mode) {
6760 case FLEX_TUNNEL_MODE_SINGLE:
6762 (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
6763 rte_flow_error_set(error, EINVAL,
6764 RTE_FLOW_ERROR_TYPE_ITEM,
6765 NULL, "multiple flex items not supported");
6767 case FLEX_TUNNEL_MODE_OUTER:
6769 rte_flow_error_set(error, EINVAL,
6770 RTE_FLOW_ERROR_TYPE_ITEM,
6771 NULL, "inner flex item was not configured");
6772 if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
6773 rte_flow_error_set(error, ENOTSUP,
6774 RTE_FLOW_ERROR_TYPE_ITEM,
6775 NULL, "multiple flex items not supported");
6777 case FLEX_TUNNEL_MODE_INNER:
6779 rte_flow_error_set(error, EINVAL,
6780 RTE_FLOW_ERROR_TYPE_ITEM,
6781 NULL, "outer flex item was not configured");
6782 if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
6783 rte_flow_error_set(error, EINVAL,
6784 RTE_FLOW_ERROR_TYPE_ITEM,
6785 NULL, "multiple flex items not supported");
6787 case FLEX_TUNNEL_MODE_MULTI:
6788 if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
6789 (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
6790 rte_flow_error_set(error, EINVAL,
6791 RTE_FLOW_ERROR_TYPE_ITEM,
6792 NULL, "multiple flex items not supported");
6795 case FLEX_TUNNEL_MODE_TUNNEL:
6796 if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
6797 rte_flow_error_set(error, EINVAL,
6798 RTE_FLOW_ERROR_TYPE_ITEM,
6799 NULL, "multiple flex tunnel items not supported");
6802 rte_flow_error_set(error, EINVAL,
6803 RTE_FLOW_ERROR_TYPE_ITEM,
6804 NULL, "invalid flex item configuration");
6806 *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
6807 MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
6808 MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
6813 * Internal validation function. For validating both actions and items.
6816 * Pointer to the rte_eth_dev structure.
6818 * Pointer to the flow attributes.
6820 * Pointer to the list of items.
6821 * @param[in] actions
6822 * Pointer to the list of actions.
6823 * @param[in] external
6824 * This flow rule is created by request external to PMD.
6825 * @param[in] hairpin
6826 * Number of hairpin TX actions, 0 means classic flow.
6828 * Pointer to the error structure.
6831 * 0 on success, a negative errno value otherwise and rte_errno is set.
6834 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
6835 const struct rte_flow_item items[],
6836 const struct rte_flow_action actions[],
6837 bool external, int hairpin, struct rte_flow_error *error)
6840 uint64_t action_flags = 0;
6841 uint64_t item_flags = 0;
6842 uint64_t last_item = 0;
6843 uint8_t next_protocol = 0xff;
6844 uint16_t ether_type = 0;
6846 uint8_t item_ipv6_proto = 0;
6847 int fdb_mirror_limit = 0;
6848 int modify_after_mirror = 0;
6849 const struct rte_flow_item *geneve_item = NULL;
6850 const struct rte_flow_item *gre_item = NULL;
6851 const struct rte_flow_item *gtp_item = NULL;
6852 const struct rte_flow_action_raw_decap *decap;
6853 const struct rte_flow_action_raw_encap *encap;
6854 const struct rte_flow_action_rss *rss = NULL;
6855 const struct rte_flow_action_rss *sample_rss = NULL;
6856 const struct rte_flow_action_count *sample_count = NULL;
6857 const struct rte_flow_item_tcp nic_tcp_mask = {
6860 .src_port = RTE_BE16(UINT16_MAX),
6861 .dst_port = RTE_BE16(UINT16_MAX),
6864 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
6867 "\xff\xff\xff\xff\xff\xff\xff\xff"
6868 "\xff\xff\xff\xff\xff\xff\xff\xff",
6870 "\xff\xff\xff\xff\xff\xff\xff\xff"
6871 "\xff\xff\xff\xff\xff\xff\xff\xff",
6872 .vtc_flow = RTE_BE32(0xffffffff),
6878 const struct rte_flow_item_ecpri nic_ecpri_mask = {
6882 RTE_BE32(((const struct rte_ecpri_common_hdr) {
6886 .dummy[0] = 0xffffffff,
6889 struct mlx5_priv *priv = dev->data->dev_private;
6890 struct mlx5_sh_config *dev_conf = &priv->sh->config;
6891 uint16_t queue_index = 0xFFFF;
6892 const struct rte_flow_item_vlan *vlan_m = NULL;
6893 uint32_t rw_act_num = 0;
6895 const struct mlx5_flow_tunnel *tunnel;
6896 enum mlx5_tof_rule_type tof_rule_type;
6897 struct flow_grp_info grp_info = {
6898 .external = !!external,
6899 .transfer = !!attr->transfer,
6900 .fdb_def_rule = !!priv->fdb_def_rule,
6901 .std_tbl_fix = true,
6903 const struct rte_eth_hairpin_conf *conf;
6904 const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
6905 const struct rte_flow_item *port_id_item = NULL;
6906 bool def_policy = false;
6907 uint16_t udp_dport = 0;
6911 tunnel = is_tunnel_offload_active(dev) ?
6912 mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
6914 if (!dev_conf->dv_flow_en)
6915 return rte_flow_error_set
6917 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6918 NULL, "tunnel offload requires DV flow interface");
6919 if (priv->representor)
6920 return rte_flow_error_set
6922 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6923 NULL, "decap not supported for VF representor");
6924 if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
6925 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6926 else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
6927 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
6928 MLX5_FLOW_ACTION_DECAP;
6929 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
6930 (dev, attr, tunnel, tof_rule_type);
6932 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
6935 is_root = (uint64_t)ret;
6936 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6937 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
6938 int type = items->type;
6940 if (!mlx5_flow_os_item_supported(type))
6941 return rte_flow_error_set(error, ENOTSUP,
6942 RTE_FLOW_ERROR_TYPE_ITEM,
6943 NULL, "item not supported");
6945 case RTE_FLOW_ITEM_TYPE_VOID:
6947 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6948 ret = flow_dv_validate_item_port_id
6949 (dev, items, attr, item_flags, error);
6952 last_item = MLX5_FLOW_ITEM_PORT_ID;
6953 port_id_item = items;
6955 case RTE_FLOW_ITEM_TYPE_ETH:
6956 ret = mlx5_flow_validate_item_eth(items, item_flags,
6960 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
6961 MLX5_FLOW_LAYER_OUTER_L2;
6962 if (items->mask != NULL && items->spec != NULL) {
6964 ((const struct rte_flow_item_eth *)
6967 ((const struct rte_flow_item_eth *)
6969 ether_type = rte_be_to_cpu_16(ether_type);
6974 case RTE_FLOW_ITEM_TYPE_VLAN:
6975 ret = flow_dv_validate_item_vlan(items, item_flags,
6979 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
6980 MLX5_FLOW_LAYER_OUTER_VLAN;
6981 if (items->mask != NULL && items->spec != NULL) {
6983 ((const struct rte_flow_item_vlan *)
6984 items->spec)->inner_type;
6986 ((const struct rte_flow_item_vlan *)
6987 items->mask)->inner_type;
6988 ether_type = rte_be_to_cpu_16(ether_type);
6992 /* Store outer VLAN mask for of_push_vlan action. */
6994 vlan_m = items->mask;
6996 case RTE_FLOW_ITEM_TYPE_IPV4:
6997 mlx5_flow_tunnel_ip_check(items, next_protocol,
6998 &item_flags, &tunnel);
6999 ret = flow_dv_validate_item_ipv4(dev, items, item_flags,
7000 last_item, ether_type,
7004 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7005 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7006 if (items->mask != NULL &&
7007 ((const struct rte_flow_item_ipv4 *)
7008 items->mask)->hdr.next_proto_id) {
7010 ((const struct rte_flow_item_ipv4 *)
7011 (items->spec))->hdr.next_proto_id;
7013 ((const struct rte_flow_item_ipv4 *)
7014 (items->mask))->hdr.next_proto_id;
7016 /* Reset for inner layer. */
7017 next_protocol = 0xff;
7020 case RTE_FLOW_ITEM_TYPE_IPV6:
7021 mlx5_flow_tunnel_ip_check(items, next_protocol,
7022 &item_flags, &tunnel);
7023 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
7030 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7031 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7032 if (items->mask != NULL &&
7033 ((const struct rte_flow_item_ipv6 *)
7034 items->mask)->hdr.proto) {
7036 ((const struct rte_flow_item_ipv6 *)
7037 items->spec)->hdr.proto;
7039 ((const struct rte_flow_item_ipv6 *)
7040 items->spec)->hdr.proto;
7042 ((const struct rte_flow_item_ipv6 *)
7043 items->mask)->hdr.proto;
7045 /* Reset for inner layer. */
7046 next_protocol = 0xff;
7049 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7050 ret = flow_dv_validate_item_ipv6_frag_ext(items,
7055 last_item = tunnel ?
7056 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7057 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7058 if (items->mask != NULL &&
7059 ((const struct rte_flow_item_ipv6_frag_ext *)
7060 items->mask)->hdr.next_header) {
7062 ((const struct rte_flow_item_ipv6_frag_ext *)
7063 items->spec)->hdr.next_header;
7065 ((const struct rte_flow_item_ipv6_frag_ext *)
7066 items->mask)->hdr.next_header;
7068 /* Reset for inner layer. */
7069 next_protocol = 0xff;
7072 case RTE_FLOW_ITEM_TYPE_TCP:
7073 ret = mlx5_flow_validate_item_tcp
7080 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7081 MLX5_FLOW_LAYER_OUTER_L4_TCP;
7083 case RTE_FLOW_ITEM_TYPE_UDP:
7084 ret = mlx5_flow_validate_item_udp(items, item_flags,
7087 const struct rte_flow_item_udp *spec = items->spec;
7088 const struct rte_flow_item_udp *mask = items->mask;
7090 mask = &rte_flow_item_udp_mask;
7092 udp_dport = rte_be_to_cpu_16
7093 (spec->hdr.dst_port &
7094 mask->hdr.dst_port);
7097 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7098 MLX5_FLOW_LAYER_OUTER_L4_UDP;
7100 case RTE_FLOW_ITEM_TYPE_GRE:
7101 ret = mlx5_flow_validate_item_gre(items, item_flags,
7102 next_protocol, error);
7106 last_item = MLX5_FLOW_LAYER_GRE;
7108 case RTE_FLOW_ITEM_TYPE_NVGRE:
7109 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
7114 last_item = MLX5_FLOW_LAYER_NVGRE;
7116 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7117 ret = mlx5_flow_validate_item_gre_key
7118 (items, item_flags, gre_item, error);
7121 last_item = MLX5_FLOW_LAYER_GRE_KEY;
7123 case RTE_FLOW_ITEM_TYPE_VXLAN:
7124 ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
7129 last_item = MLX5_FLOW_LAYER_VXLAN;
7131 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7132 ret = mlx5_flow_validate_item_vxlan_gpe(items,
7137 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7139 case RTE_FLOW_ITEM_TYPE_GENEVE:
7140 ret = mlx5_flow_validate_item_geneve(items,
7145 geneve_item = items;
7146 last_item = MLX5_FLOW_LAYER_GENEVE;
7148 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
7149 ret = mlx5_flow_validate_item_geneve_opt(items,
7156 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
7158 case RTE_FLOW_ITEM_TYPE_MPLS:
7159 ret = mlx5_flow_validate_item_mpls(dev, items,
7164 last_item = MLX5_FLOW_LAYER_MPLS;
7167 case RTE_FLOW_ITEM_TYPE_MARK:
7168 ret = flow_dv_validate_item_mark(dev, items, attr,
7172 last_item = MLX5_FLOW_ITEM_MARK;
7174 case RTE_FLOW_ITEM_TYPE_META:
7175 ret = flow_dv_validate_item_meta(dev, items, attr,
7179 last_item = MLX5_FLOW_ITEM_METADATA;
7181 case RTE_FLOW_ITEM_TYPE_ICMP:
7182 ret = mlx5_flow_validate_item_icmp(items, item_flags,
7187 last_item = MLX5_FLOW_LAYER_ICMP;
7189 case RTE_FLOW_ITEM_TYPE_ICMP6:
7190 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
7195 item_ipv6_proto = IPPROTO_ICMPV6;
7196 last_item = MLX5_FLOW_LAYER_ICMP6;
7198 case RTE_FLOW_ITEM_TYPE_TAG:
7199 ret = flow_dv_validate_item_tag(dev, items,
7203 last_item = MLX5_FLOW_ITEM_TAG;
7205 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7206 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
7208 case RTE_FLOW_ITEM_TYPE_GTP:
7209 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
7214 last_item = MLX5_FLOW_LAYER_GTP;
7216 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
7217 ret = flow_dv_validate_item_gtp_psc(items, last_item,
7222 last_item = MLX5_FLOW_LAYER_GTP_PSC;
7224 case RTE_FLOW_ITEM_TYPE_ECPRI:
7225 /* Capacity will be checked in the translate stage. */
7226 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
7233 last_item = MLX5_FLOW_LAYER_ECPRI;
7235 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
7236 ret = flow_dv_validate_item_integrity(dev, items,
7244 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
7245 ret = flow_dv_validate_item_aso_ct(dev, items,
7246 &item_flags, error);
7250 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
7251 /* tunnel offload item was processed before
7252 * list it here as a supported type
7255 case RTE_FLOW_ITEM_TYPE_FLEX:
7256 ret = flow_dv_validate_item_flex(dev, items, item_flags,
7258 tunnel != 0, error);
7263 return rte_flow_error_set(error, ENOTSUP,
7264 RTE_FLOW_ERROR_TYPE_ITEM,
7265 NULL, "item not supported");
7267 item_flags |= last_item;
7269 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
7270 ret = flow_dv_validate_item_integrity_post(integrity_items,
7275 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7276 int type = actions->type;
7277 bool shared_count = false;
7279 if (!mlx5_flow_os_action_supported(type))
7280 return rte_flow_error_set(error, ENOTSUP,
7281 RTE_FLOW_ERROR_TYPE_ACTION,
7283 "action not supported");
7284 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
7285 return rte_flow_error_set(error, ENOTSUP,
7286 RTE_FLOW_ERROR_TYPE_ACTION,
7287 actions, "too many actions");
7289 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
7290 return rte_flow_error_set(error, ENOTSUP,
7291 RTE_FLOW_ERROR_TYPE_ACTION,
7292 NULL, "meter action with policy "
7293 "must be the last action");
7295 case RTE_FLOW_ACTION_TYPE_VOID:
7297 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7298 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
7299 ret = flow_dv_validate_action_port_id(dev,
7306 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7309 case RTE_FLOW_ACTION_TYPE_FLAG:
7310 ret = flow_dv_validate_action_flag(dev, action_flags,
7314 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7315 /* Count all modify-header actions as one. */
7316 if (!(action_flags &
7317 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7319 action_flags |= MLX5_FLOW_ACTION_FLAG |
7320 MLX5_FLOW_ACTION_MARK_EXT;
7321 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7322 modify_after_mirror = 1;
7325 action_flags |= MLX5_FLOW_ACTION_FLAG;
7328 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7330 case RTE_FLOW_ACTION_TYPE_MARK:
7331 ret = flow_dv_validate_action_mark(dev, actions,
7336 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7337 /* Count all modify-header actions as one. */
7338 if (!(action_flags &
7339 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7341 action_flags |= MLX5_FLOW_ACTION_MARK |
7342 MLX5_FLOW_ACTION_MARK_EXT;
7343 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7344 modify_after_mirror = 1;
7346 action_flags |= MLX5_FLOW_ACTION_MARK;
7349 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7351 case RTE_FLOW_ACTION_TYPE_SET_META:
7352 ret = flow_dv_validate_action_set_meta(dev, actions,
7357 /* Count all modify-header actions as one action. */
7358 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7360 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7361 modify_after_mirror = 1;
7362 action_flags |= MLX5_FLOW_ACTION_SET_META;
7363 rw_act_num += MLX5_ACT_NUM_SET_META;
7365 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7366 ret = flow_dv_validate_action_set_tag(dev, actions,
7371 /* Count all modify-header actions as one action. */
7372 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7374 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7375 modify_after_mirror = 1;
7376 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7377 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7379 case RTE_FLOW_ACTION_TYPE_DROP:
7380 ret = mlx5_flow_validate_action_drop(action_flags,
7384 action_flags |= MLX5_FLOW_ACTION_DROP;
7387 case RTE_FLOW_ACTION_TYPE_QUEUE:
7388 ret = mlx5_flow_validate_action_queue(actions,
7393 queue_index = ((const struct rte_flow_action_queue *)
7394 (actions->conf))->index;
7395 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7398 case RTE_FLOW_ACTION_TYPE_RSS:
7399 rss = actions->conf;
7400 ret = mlx5_flow_validate_action_rss(actions,
7406 if (rss && sample_rss &&
7407 (sample_rss->level != rss->level ||
7408 sample_rss->types != rss->types))
7409 return rte_flow_error_set(error, ENOTSUP,
7410 RTE_FLOW_ERROR_TYPE_ACTION,
7412 "Can't use the different RSS types "
7413 "or level in the same flow");
7414 if (rss != NULL && rss->queue_num)
7415 queue_index = rss->queue[0];
7416 action_flags |= MLX5_FLOW_ACTION_RSS;
7419 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7421 mlx5_flow_validate_action_default_miss(action_flags,
7425 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7428 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
7429 shared_count = true;
7431 case RTE_FLOW_ACTION_TYPE_COUNT:
7432 ret = flow_dv_validate_action_count(dev, shared_count,
7437 action_flags |= MLX5_FLOW_ACTION_COUNT;
7440 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7441 if (flow_dv_validate_action_pop_vlan(dev,
7447 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7448 modify_after_mirror = 1;
7449 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7452 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7453 ret = flow_dv_validate_action_push_vlan(dev,
7460 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7461 modify_after_mirror = 1;
7462 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7465 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7466 ret = flow_dv_validate_action_set_vlan_pcp
7467 (action_flags, actions, error);
7470 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7471 modify_after_mirror = 1;
7472 /* Count PCP with push_vlan command. */
7473 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
7475 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7476 ret = flow_dv_validate_action_set_vlan_vid
7477 (item_flags, action_flags,
7481 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7482 modify_after_mirror = 1;
7483 /* Count VID with push_vlan command. */
7484 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7485 rw_act_num += MLX5_ACT_NUM_MDF_VID;
7487 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7488 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7489 ret = flow_dv_validate_action_l2_encap(dev,
7495 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7498 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7499 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7500 ret = flow_dv_validate_action_decap(dev, action_flags,
7501 actions, item_flags,
7505 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7506 modify_after_mirror = 1;
7507 action_flags |= MLX5_FLOW_ACTION_DECAP;
7510 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7511 ret = flow_dv_validate_action_raw_encap_decap
7512 (dev, NULL, actions->conf, attr, &action_flags,
7513 &actions_n, actions, item_flags, error);
7517 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7518 decap = actions->conf;
7519 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
7521 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7525 encap = actions->conf;
7527 ret = flow_dv_validate_action_raw_encap_decap
7529 decap ? decap : &empty_decap, encap,
7530 attr, &action_flags, &actions_n,
7531 actions, item_flags, error);
7534 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7535 (action_flags & MLX5_FLOW_ACTION_DECAP))
7536 modify_after_mirror = 1;
7538 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7539 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7540 ret = flow_dv_validate_action_modify_mac(action_flags,
7546 /* Count all modify-header actions as one action. */
7547 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7549 action_flags |= actions->type ==
7550 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7551 MLX5_FLOW_ACTION_SET_MAC_SRC :
7552 MLX5_FLOW_ACTION_SET_MAC_DST;
7553 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7554 modify_after_mirror = 1;
7556 * Even if the source and destination MAC addresses have
7557 * overlap in the header with 4B alignment, the convert
7558 * function will handle them separately and 4 SW actions
7559 * will be created. And 2 actions will be added each
7560 * time no matter how many bytes of address will be set.
7562 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
7564 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7565 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7566 ret = flow_dv_validate_action_modify_ipv4(action_flags,
7572 /* Count all modify-header actions as one action. */
7573 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7575 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7576 modify_after_mirror = 1;
7577 action_flags |= actions->type ==
7578 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7579 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7580 MLX5_FLOW_ACTION_SET_IPV4_DST;
7581 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
7583 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7584 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7585 ret = flow_dv_validate_action_modify_ipv6(action_flags,
7591 if (item_ipv6_proto == IPPROTO_ICMPV6)
7592 return rte_flow_error_set(error, ENOTSUP,
7593 RTE_FLOW_ERROR_TYPE_ACTION,
7595 "Can't change header "
7596 "with ICMPv6 proto");
7597 /* Count all modify-header actions as one action. */
7598 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7600 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7601 modify_after_mirror = 1;
7602 action_flags |= actions->type ==
7603 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7604 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7605 MLX5_FLOW_ACTION_SET_IPV6_DST;
7606 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
7608 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7609 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7610 ret = flow_dv_validate_action_modify_tp(action_flags,
7616 /* Count all modify-header actions as one action. */
7617 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7619 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7620 modify_after_mirror = 1;
7621 action_flags |= actions->type ==
7622 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7623 MLX5_FLOW_ACTION_SET_TP_SRC :
7624 MLX5_FLOW_ACTION_SET_TP_DST;
7625 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
7627 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7628 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7629 ret = flow_dv_validate_action_modify_ttl(action_flags,
7635 /* Count all modify-header actions as one action. */
7636 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7638 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7639 modify_after_mirror = 1;
7640 action_flags |= actions->type ==
7641 RTE_FLOW_ACTION_TYPE_SET_TTL ?
7642 MLX5_FLOW_ACTION_SET_TTL :
7643 MLX5_FLOW_ACTION_DEC_TTL;
7644 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
7646 case RTE_FLOW_ACTION_TYPE_JUMP:
7647 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
7653 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7655 return rte_flow_error_set(error, EINVAL,
7656 RTE_FLOW_ERROR_TYPE_ACTION,
7658 "sample and jump action combination is not supported");
7660 action_flags |= MLX5_FLOW_ACTION_JUMP;
7662 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7663 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7664 ret = flow_dv_validate_action_modify_tcp_seq
7671 /* Count all modify-header actions as one action. */
7672 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7674 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7675 modify_after_mirror = 1;
7676 action_flags |= actions->type ==
7677 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7678 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7679 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7680 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
7682 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7683 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7684 ret = flow_dv_validate_action_modify_tcp_ack
7691 /* Count all modify-header actions as one action. */
7692 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7694 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7695 modify_after_mirror = 1;
7696 action_flags |= actions->type ==
7697 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7698 MLX5_FLOW_ACTION_INC_TCP_ACK :
7699 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7700 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
7702 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7704 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7705 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7706 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7708 case RTE_FLOW_ACTION_TYPE_METER:
7709 ret = mlx5_flow_validate_action_meter(dev,
7718 action_flags |= MLX5_FLOW_ACTION_METER;
7721 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
7723 /* Meter action will add one more TAG action. */
7724 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7726 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
7727 if (!attr->transfer && !attr->group)
7728 return rte_flow_error_set(error, ENOTSUP,
7729 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7731 "Shared ASO age action is not supported for group 0");
7732 if (action_flags & MLX5_FLOW_ACTION_AGE)
7733 return rte_flow_error_set
7735 RTE_FLOW_ERROR_TYPE_ACTION,
7737 "duplicate age actions set");
7738 action_flags |= MLX5_FLOW_ACTION_AGE;
7741 case RTE_FLOW_ACTION_TYPE_AGE:
7742 ret = flow_dv_validate_action_age(action_flags,
7748 * Validate the regular AGE action (using counter)
7749 * mutual exclusion with share counter actions.
7751 if (!priv->sh->flow_hit_aso_en) {
7753 return rte_flow_error_set
7755 RTE_FLOW_ERROR_TYPE_ACTION,
7757 "old age and shared count combination is not supported");
7759 return rte_flow_error_set
7761 RTE_FLOW_ERROR_TYPE_ACTION,
7763 "old age action and count must be in the same sub flow");
7765 action_flags |= MLX5_FLOW_ACTION_AGE;
7768 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7769 ret = flow_dv_validate_action_modify_ipv4_dscp
7776 /* Count all modify-header actions as one action. */
7777 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7779 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7780 modify_after_mirror = 1;
7781 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7782 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7784 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7785 ret = flow_dv_validate_action_modify_ipv6_dscp
7792 /* Count all modify-header actions as one action. */
7793 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7795 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7796 modify_after_mirror = 1;
7797 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7798 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7800 case RTE_FLOW_ACTION_TYPE_SAMPLE:
7801 ret = flow_dv_validate_action_sample(&action_flags,
7810 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
7813 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7814 ret = flow_dv_validate_action_modify_field(dev,
7821 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7822 modify_after_mirror = 1;
7823 /* Count all modify-header actions as one action. */
7824 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7826 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7829 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7830 ret = flow_dv_validate_action_aso_ct(dev, action_flags,
7835 action_flags |= MLX5_FLOW_ACTION_CT;
7837 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
7838 /* tunnel offload action was processed before
7839 * list it here as a supported type
7843 return rte_flow_error_set(error, ENOTSUP,
7844 RTE_FLOW_ERROR_TYPE_ACTION,
7846 "action not supported");
7850 * Validate actions in flow rules
7851 * - Explicit decap action is prohibited by the tunnel offload API.
7852 * - Drop action in tunnel steer rule is prohibited by the API.
7853 * - Application cannot use MARK action because it's value can mask
7854 * tunnel default miss notification.
7855 * - JUMP in tunnel match rule has no support in current PMD
7857 * - TAG & META are reserved for future uses.
7859 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
7860 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7861 MLX5_FLOW_ACTION_MARK |
7862 MLX5_FLOW_ACTION_SET_TAG |
7863 MLX5_FLOW_ACTION_SET_META |
7864 MLX5_FLOW_ACTION_DROP;
7866 if (action_flags & bad_actions_mask)
7867 return rte_flow_error_set
7869 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7870 "Invalid RTE action in tunnel "
7872 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
7873 return rte_flow_error_set
7875 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7876 "tunnel set decap rule must terminate "
7879 return rte_flow_error_set
7881 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7882 "tunnel flows for ingress traffic only");
7884 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
7885 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
7886 MLX5_FLOW_ACTION_MARK |
7887 MLX5_FLOW_ACTION_SET_TAG |
7888 MLX5_FLOW_ACTION_SET_META;
7890 if (action_flags & bad_actions_mask)
7891 return rte_flow_error_set
7893 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7894 "Invalid RTE action in tunnel "
7898 * Validate the drop action mutual exclusion with other actions.
7899 * Drop action is mutually-exclusive with any other action, except for
7901 * Drop action compatibility with tunnel offload was already validated.
7903 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
7904 MLX5_FLOW_ACTION_TUNNEL_MATCH));
7905 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
7906 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
7907 return rte_flow_error_set(error, EINVAL,
7908 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7909 "Drop action is mutually-exclusive "
7910 "with any other action, except for "
7912 /* Eswitch has few restrictions on using items and actions */
7913 if (attr->transfer) {
7914 if (!mlx5_flow_ext_mreg_supported(dev) &&
7915 action_flags & MLX5_FLOW_ACTION_FLAG)
7916 return rte_flow_error_set(error, ENOTSUP,
7917 RTE_FLOW_ERROR_TYPE_ACTION,
7919 "unsupported action FLAG");
7920 if (!mlx5_flow_ext_mreg_supported(dev) &&
7921 action_flags & MLX5_FLOW_ACTION_MARK)
7922 return rte_flow_error_set(error, ENOTSUP,
7923 RTE_FLOW_ERROR_TYPE_ACTION,
7925 "unsupported action MARK");
7926 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
7927 return rte_flow_error_set(error, ENOTSUP,
7928 RTE_FLOW_ERROR_TYPE_ACTION,
7930 "unsupported action QUEUE");
7931 if (action_flags & MLX5_FLOW_ACTION_RSS)
7932 return rte_flow_error_set(error, ENOTSUP,
7933 RTE_FLOW_ERROR_TYPE_ACTION,
7935 "unsupported action RSS");
7936 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
7937 return rte_flow_error_set(error, EINVAL,
7938 RTE_FLOW_ERROR_TYPE_ACTION,
7940 "no fate action is found");
7942 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
7943 return rte_flow_error_set(error, EINVAL,
7944 RTE_FLOW_ERROR_TYPE_ACTION,
7946 "no fate action is found");
7949 * Continue validation for Xcap and VLAN actions.
7950 * If hairpin is working in explicit TX rule mode, there is no actions
7951 * splitting and the validation of hairpin ingress flow should be the
7952 * same as other standard flows.
7954 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
7955 MLX5_FLOW_VLAN_ACTIONS)) &&
7956 (queue_index == 0xFFFF ||
7957 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN ||
7958 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
7959 conf->tx_explicit != 0))) {
7960 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
7961 MLX5_FLOW_XCAP_ACTIONS)
7962 return rte_flow_error_set(error, ENOTSUP,
7963 RTE_FLOW_ERROR_TYPE_ACTION,
7964 NULL, "encap and decap "
7965 "combination aren't supported");
7966 if (!attr->transfer && attr->ingress) {
7967 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7968 return rte_flow_error_set
7970 RTE_FLOW_ERROR_TYPE_ACTION,
7971 NULL, "encap is not supported"
7972 " for ingress traffic");
7973 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7974 return rte_flow_error_set
7976 RTE_FLOW_ERROR_TYPE_ACTION,
7977 NULL, "push VLAN action not "
7978 "supported for ingress");
7979 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
7980 MLX5_FLOW_VLAN_ACTIONS)
7981 return rte_flow_error_set
7983 RTE_FLOW_ERROR_TYPE_ACTION,
7984 NULL, "no support for "
7985 "multiple VLAN actions");
7988 if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
7989 if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
7990 ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
7992 return rte_flow_error_set
7994 RTE_FLOW_ERROR_TYPE_ACTION,
7995 NULL, "fate action not supported for "
7996 "meter with policy");
7998 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
7999 return rte_flow_error_set
8001 RTE_FLOW_ERROR_TYPE_ACTION,
8002 NULL, "modify header action in egress "
8003 "cannot be done before meter action");
8004 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
8005 return rte_flow_error_set
8007 RTE_FLOW_ERROR_TYPE_ACTION,
8008 NULL, "encap action in egress "
8009 "cannot be done before meter action");
8010 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
8011 return rte_flow_error_set
8013 RTE_FLOW_ERROR_TYPE_ACTION,
8014 NULL, "push vlan action in egress "
8015 "cannot be done before meter action");
8019 * Hairpin flow will add one more TAG action in TX implicit mode.
8020 * In TX explicit mode, there will be no hairpin flow ID.
8023 rw_act_num += MLX5_ACT_NUM_SET_TAG;
8024 /* extra metadata enabled: one more TAG action will be add. */
8025 if (dev_conf->dv_flow_en &&
8026 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
8027 mlx5_flow_ext_mreg_supported(dev))
8028 rw_act_num += MLX5_ACT_NUM_SET_TAG;
8030 flow_dv_modify_hdr_action_max(dev, is_root)) {
8031 return rte_flow_error_set(error, ENOTSUP,
8032 RTE_FLOW_ERROR_TYPE_ACTION,
8033 NULL, "too many header modify"
8034 " actions to support");
8036 /* Eswitch egress mirror and modify flow has limitation on CX5 */
8037 if (fdb_mirror_limit && modify_after_mirror)
8038 return rte_flow_error_set(error, EINVAL,
8039 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8040 "sample before modify action is not supported");
8045 * Internal preparation function. Allocates the DV flow size,
8046 * this size is constant.
8049 * Pointer to the rte_eth_dev structure.
8051 * Pointer to the flow attributes.
8053 * Pointer to the list of items.
8054 * @param[in] actions
8055 * Pointer to the list of actions.
8057 * Pointer to the error structure.
8060 * Pointer to mlx5_flow object on success,
8061 * otherwise NULL and rte_errno is set.
8063 static struct mlx5_flow *
8064 flow_dv_prepare(struct rte_eth_dev *dev,
8065 const struct rte_flow_attr *attr __rte_unused,
8066 const struct rte_flow_item items[] __rte_unused,
8067 const struct rte_flow_action actions[] __rte_unused,
8068 struct rte_flow_error *error)
8070 uint32_t handle_idx = 0;
8071 struct mlx5_flow *dev_flow;
8072 struct mlx5_flow_handle *dev_handle;
8073 struct mlx5_priv *priv = dev->data->dev_private;
8074 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
8077 wks->skip_matcher_reg = 0;
8079 wks->final_policy = NULL;
8080 /* In case of corrupting the memory. */
8081 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
8082 rte_flow_error_set(error, ENOSPC,
8083 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8084 "not free temporary device flow");
8087 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8090 rte_flow_error_set(error, ENOMEM,
8091 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8092 "not enough memory to create flow handle");
8095 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
8096 dev_flow = &wks->flows[wks->flow_idx++];
8097 memset(dev_flow, 0, sizeof(*dev_flow));
8098 dev_flow->handle = dev_handle;
8099 dev_flow->handle_idx = handle_idx;
8100 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
8101 dev_flow->ingress = attr->ingress;
8102 dev_flow->dv.transfer = attr->transfer;
8106 #ifdef RTE_LIBRTE_MLX5_DEBUG
8108 * Sanity check for match mask and value. Similar to check_valid_spec() in
8109 * kernel driver. If unmasked bit is present in value, it returns failure.
8112 * pointer to match mask buffer.
8113 * @param match_value
8114 * pointer to match value buffer.
8117 * 0 if valid, -EINVAL otherwise.
8120 flow_dv_check_valid_spec(void *match_mask, void *match_value)
8122 uint8_t *m = match_mask;
8123 uint8_t *v = match_value;
8126 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
8129 "match_value differs from match_criteria"
8130 " %p[%u] != %p[%u]",
8131 match_value, i, match_mask, i);
8140 * Add match of ip_version.
8144 * @param[in] headers_v
8145 * Values header pointer.
8146 * @param[in] headers_m
8147 * Masks header pointer.
8148 * @param[in] ip_version
8149 * The IP version to set.
8152 flow_dv_set_match_ip_version(uint32_t group,
8158 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
8160 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
8162 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
8163 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
8164 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
8168 * Add Ethernet item to matcher and to the value.
8170 * @param[in, out] matcher
8172 * @param[in, out] key
8173 * Flow matcher value.
8175 * Flow pattern to translate.
8177 * Item is inner pattern.
8180 flow_dv_translate_item_eth(void *matcher, void *key,
8181 const struct rte_flow_item *item, int inner,
8184 const struct rte_flow_item_eth *eth_m = item->mask;
8185 const struct rte_flow_item_eth *eth_v = item->spec;
8186 const struct rte_flow_item_eth nic_mask = {
8187 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8188 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8189 .type = RTE_BE16(0xffff),
8202 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8204 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8206 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8208 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8210 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
8211 ð_m->dst, sizeof(eth_m->dst));
8212 /* The value must be in the range of the mask. */
8213 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
8214 for (i = 0; i < sizeof(eth_m->dst); ++i)
8215 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
8216 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
8217 ð_m->src, sizeof(eth_m->src));
8218 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
8219 /* The value must be in the range of the mask. */
8220 for (i = 0; i < sizeof(eth_m->dst); ++i)
8221 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
8223 * HW supports match on one Ethertype, the Ethertype following the last
8224 * VLAN tag of the packet (see PRM).
8225 * Set match on ethertype only if ETH header is not followed by VLAN.
8226 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8227 * ethertype, and use ip_version field instead.
8228 * eCPRI over Ether layer will use type value 0xAEFE.
8230 if (eth_m->type == 0xFFFF) {
8231 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
8232 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8233 switch (eth_v->type) {
8234 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8235 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8237 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
8238 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8239 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8241 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8242 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8244 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8245 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8251 if (eth_m->has_vlan) {
8252 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8253 if (eth_v->has_vlan) {
8255 * Here, when also has_more_vlan field in VLAN item is
8256 * not set, only single-tagged packets will be matched.
8258 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8262 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8263 rte_be_to_cpu_16(eth_m->type));
8264 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
8265 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
8269 * Add VLAN item to matcher and to the value.
8271 * @param[in, out] dev_flow
8273 * @param[in, out] matcher
8275 * @param[in, out] key
8276 * Flow matcher value.
8278 * Flow pattern to translate.
8280 * Item is inner pattern.
8283 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
8284 void *matcher, void *key,
8285 const struct rte_flow_item *item,
8286 int inner, uint32_t group)
8288 const struct rte_flow_item_vlan *vlan_m = item->mask;
8289 const struct rte_flow_item_vlan *vlan_v = item->spec;
8296 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8298 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8300 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8302 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8304 * This is workaround, masks are not supported,
8305 * and pre-validated.
8308 dev_flow->handle->vf_vlan.tag =
8309 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
8312 * When VLAN item exists in flow, mark packet as tagged,
8313 * even if TCI is not specified.
8315 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
8316 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8317 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8322 vlan_m = &rte_flow_item_vlan_mask;
8323 tci_m = rte_be_to_cpu_16(vlan_m->tci);
8324 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
8325 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
8326 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
8327 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
8328 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
8329 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
8330 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
8332 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8333 * ethertype, and use ip_version field instead.
8335 if (vlan_m->inner_type == 0xFFFF) {
8336 switch (vlan_v->inner_type) {
8337 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8338 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8339 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8340 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8342 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8343 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8345 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8346 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8352 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
8353 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8354 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8355 /* Only one vlan_tag bit can be set. */
8356 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8359 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8360 rte_be_to_cpu_16(vlan_m->inner_type));
8361 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
8362 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
8366 * Add IPV4 item to matcher and to the value.
8368 * @param[in, out] matcher
8370 * @param[in, out] key
8371 * Flow matcher value.
8373 * Flow pattern to translate.
8375 * Item is inner pattern.
8377 * The group to insert the rule.
8380 flow_dv_translate_item_ipv4(void *matcher, void *key,
8381 const struct rte_flow_item *item,
8382 int inner, uint32_t group)
8384 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
8385 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
8386 const struct rte_flow_item_ipv4 nic_mask = {
8388 .src_addr = RTE_BE32(0xffffffff),
8389 .dst_addr = RTE_BE32(0xffffffff),
8390 .type_of_service = 0xff,
8391 .next_proto_id = 0xff,
8392 .time_to_live = 0xff,
8399 uint8_t tos, ihl_m, ihl_v;
8402 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8404 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8406 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8408 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8410 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
8415 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8416 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8417 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8418 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8419 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
8420 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
8421 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8422 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8423 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8424 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8425 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
8426 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
8427 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
8428 ihl_m = ipv4_m->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8429 ihl_v = ipv4_v->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8430 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_ihl, ihl_m);
8431 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl, ihl_m & ihl_v);
8432 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
8433 ipv4_m->hdr.type_of_service);
8434 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
8435 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
8436 ipv4_m->hdr.type_of_service >> 2);
8437 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
8438 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8439 ipv4_m->hdr.next_proto_id);
8440 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8441 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
8442 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8443 ipv4_m->hdr.time_to_live);
8444 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8445 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
8446 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8447 !!(ipv4_m->hdr.fragment_offset));
8448 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8449 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
8453 * Add IPV6 item to matcher and to the value.
8455 * @param[in, out] matcher
8457 * @param[in, out] key
8458 * Flow matcher value.
8460 * Flow pattern to translate.
8462 * Item is inner pattern.
8464 * The group to insert the rule.
8467 flow_dv_translate_item_ipv6(void *matcher, void *key,
8468 const struct rte_flow_item *item,
8469 int inner, uint32_t group)
8471 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
8472 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
8473 const struct rte_flow_item_ipv6 nic_mask = {
8476 "\xff\xff\xff\xff\xff\xff\xff\xff"
8477 "\xff\xff\xff\xff\xff\xff\xff\xff",
8479 "\xff\xff\xff\xff\xff\xff\xff\xff"
8480 "\xff\xff\xff\xff\xff\xff\xff\xff",
8481 .vtc_flow = RTE_BE32(0xffffffff),
8488 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8489 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8498 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8500 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8502 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8504 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8506 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
8511 size = sizeof(ipv6_m->hdr.dst_addr);
8512 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8513 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8514 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8515 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8516 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
8517 for (i = 0; i < size; ++i)
8518 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
8519 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8520 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8521 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8522 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8523 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
8524 for (i = 0; i < size; ++i)
8525 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
8527 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
8528 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
8529 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
8530 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
8531 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
8532 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
8535 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
8537 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
8540 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
8542 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
8546 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8548 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8549 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
8551 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8552 ipv6_m->hdr.hop_limits);
8553 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8554 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
8555 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8556 !!(ipv6_m->has_frag_ext));
8557 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8558 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
8562 * Add IPV6 fragment extension item to matcher and to the value.
8564 * @param[in, out] matcher
8566 * @param[in, out] key
8567 * Flow matcher value.
8569 * Flow pattern to translate.
8571 * Item is inner pattern.
8574 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
8575 const struct rte_flow_item *item,
8578 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
8579 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
8580 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
8582 .next_header = 0xff,
8583 .frag_data = RTE_BE16(0xffff),
8590 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8592 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8594 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8596 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8598 /* IPv6 fragment extension item exists, so packet is IP fragment. */
8599 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
8600 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
8601 if (!ipv6_frag_ext_v)
8603 if (!ipv6_frag_ext_m)
8604 ipv6_frag_ext_m = &nic_mask;
8605 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8606 ipv6_frag_ext_m->hdr.next_header);
8607 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8608 ipv6_frag_ext_v->hdr.next_header &
8609 ipv6_frag_ext_m->hdr.next_header);
8613 * Add TCP item to matcher and to the value.
8615 * @param[in, out] matcher
8617 * @param[in, out] key
8618 * Flow matcher value.
8620 * Flow pattern to translate.
8622 * Item is inner pattern.
8625 flow_dv_translate_item_tcp(void *matcher, void *key,
8626 const struct rte_flow_item *item,
8629 const struct rte_flow_item_tcp *tcp_m = item->mask;
8630 const struct rte_flow_item_tcp *tcp_v = item->spec;
8635 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8637 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8639 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8641 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8643 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8644 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
8648 tcp_m = &rte_flow_item_tcp_mask;
8649 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
8650 rte_be_to_cpu_16(tcp_m->hdr.src_port));
8651 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
8652 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
8653 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
8654 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
8655 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
8656 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
8657 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
8658 tcp_m->hdr.tcp_flags);
8659 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
8660 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
8664 * Add UDP item to matcher and to the value.
8666 * @param[in, out] matcher
8668 * @param[in, out] key
8669 * Flow matcher value.
8671 * Flow pattern to translate.
8673 * Item is inner pattern.
8676 flow_dv_translate_item_udp(void *matcher, void *key,
8677 const struct rte_flow_item *item,
8680 const struct rte_flow_item_udp *udp_m = item->mask;
8681 const struct rte_flow_item_udp *udp_v = item->spec;
8686 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8688 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8690 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8692 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8694 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8695 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
8699 udp_m = &rte_flow_item_udp_mask;
8700 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
8701 rte_be_to_cpu_16(udp_m->hdr.src_port));
8702 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
8703 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
8704 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
8705 rte_be_to_cpu_16(udp_m->hdr.dst_port));
8706 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8707 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
8711 * Add GRE optional Key item to matcher and to the value.
8713 * @param[in, out] matcher
8715 * @param[in, out] key
8716 * Flow matcher value.
8718 * Flow pattern to translate.
8720 * Item is inner pattern.
8723 flow_dv_translate_item_gre_key(void *matcher, void *key,
8724 const struct rte_flow_item *item)
8726 const rte_be32_t *key_m = item->mask;
8727 const rte_be32_t *key_v = item->spec;
8728 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8729 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8730 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
8732 /* GRE K bit must be on and should already be validated */
8733 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
8734 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
8738 key_m = &gre_key_default_mask;
8739 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
8740 rte_be_to_cpu_32(*key_m) >> 8);
8741 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
8742 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
8743 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
8744 rte_be_to_cpu_32(*key_m) & 0xFF);
8745 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
8746 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
8750 * Add GRE item to matcher and to the value.
8752 * @param[in, out] matcher
8754 * @param[in, out] key
8755 * Flow matcher value.
8757 * Flow pattern to translate.
8758 * @param[in] pattern_flags
8759 * Accumulated pattern flags.
8762 flow_dv_translate_item_gre(void *matcher, void *key,
8763 const struct rte_flow_item *item,
8764 uint64_t pattern_flags)
8766 static const struct rte_flow_item_gre empty_gre = {0,};
8767 const struct rte_flow_item_gre *gre_m = item->mask;
8768 const struct rte_flow_item_gre *gre_v = item->spec;
8769 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
8770 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8771 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8772 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8779 uint16_t s_present:1;
8780 uint16_t k_present:1;
8781 uint16_t rsvd_bit1:1;
8782 uint16_t c_present:1;
8786 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
8787 uint16_t protocol_m, protocol_v;
8789 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8790 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
8796 gre_m = &rte_flow_item_gre_mask;
8798 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
8799 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
8800 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
8801 gre_crks_rsvd0_ver_m.c_present);
8802 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
8803 gre_crks_rsvd0_ver_v.c_present &
8804 gre_crks_rsvd0_ver_m.c_present);
8805 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
8806 gre_crks_rsvd0_ver_m.k_present);
8807 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
8808 gre_crks_rsvd0_ver_v.k_present &
8809 gre_crks_rsvd0_ver_m.k_present);
8810 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
8811 gre_crks_rsvd0_ver_m.s_present);
8812 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
8813 gre_crks_rsvd0_ver_v.s_present &
8814 gre_crks_rsvd0_ver_m.s_present);
8815 protocol_m = rte_be_to_cpu_16(gre_m->protocol);
8816 protocol_v = rte_be_to_cpu_16(gre_v->protocol);
8818 /* Force next protocol to prevent matchers duplication */
8819 protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
8821 protocol_m = 0xFFFF;
8823 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, protocol_m);
8824 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8825 protocol_m & protocol_v);
8829 * Add NVGRE item to matcher and to the value.
8831 * @param[in, out] matcher
8833 * @param[in, out] key
8834 * Flow matcher value.
8836 * Flow pattern to translate.
8837 * @param[in] pattern_flags
8838 * Accumulated pattern flags.
8841 flow_dv_translate_item_nvgre(void *matcher, void *key,
8842 const struct rte_flow_item *item,
8843 unsigned long pattern_flags)
8845 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
8846 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
8847 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8848 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8849 const char *tni_flow_id_m;
8850 const char *tni_flow_id_v;
8856 /* For NVGRE, GRE header fields must be set with defined values. */
8857 const struct rte_flow_item_gre gre_spec = {
8858 .c_rsvd0_ver = RTE_BE16(0x2000),
8859 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
8861 const struct rte_flow_item_gre gre_mask = {
8862 .c_rsvd0_ver = RTE_BE16(0xB000),
8863 .protocol = RTE_BE16(UINT16_MAX),
8865 const struct rte_flow_item gre_item = {
8870 flow_dv_translate_item_gre(matcher, key, &gre_item, pattern_flags);
8874 nvgre_m = &rte_flow_item_nvgre_mask;
8875 tni_flow_id_m = (const char *)nvgre_m->tni;
8876 tni_flow_id_v = (const char *)nvgre_v->tni;
8877 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
8878 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
8879 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
8880 memcpy(gre_key_m, tni_flow_id_m, size);
8881 for (i = 0; i < size; ++i)
8882 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
8886 * Add VXLAN item to matcher and to the value.
8889 * Pointer to the Ethernet device structure.
8891 * Flow rule attributes.
8892 * @param[in, out] matcher
8894 * @param[in, out] key
8895 * Flow matcher value.
8897 * Flow pattern to translate.
8899 * Item is inner pattern.
8902 flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
8903 const struct rte_flow_attr *attr,
8904 void *matcher, void *key,
8905 const struct rte_flow_item *item,
8908 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
8909 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
8914 uint32_t *tunnel_header_v;
8915 uint32_t *tunnel_header_m;
8917 struct mlx5_priv *priv = dev->data->dev_private;
8918 const struct rte_flow_item_vxlan nic_mask = {
8919 .vni = "\xff\xff\xff",
8924 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8926 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8928 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8930 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8932 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8933 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8934 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8935 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8936 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8938 dport = MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport);
8942 if ((!attr->group && !priv->sh->tunnel_header_0_1) ||
8943 (attr->group && !priv->sh->misc5_cap))
8944 vxlan_m = &rte_flow_item_vxlan_mask;
8946 vxlan_m = &nic_mask;
8948 if ((priv->sh->steering_format_version ==
8949 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
8950 dport != MLX5_UDP_PORT_VXLAN) ||
8951 (!attr->group && !attr->transfer && !priv->sh->tunnel_header_0_1) ||
8952 ((attr->group || attr->transfer) && !priv->sh->misc5_cap)) {
8959 misc_m = MLX5_ADDR_OF(fte_match_param,
8960 matcher, misc_parameters);
8961 misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8962 size = sizeof(vxlan_m->vni);
8963 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
8964 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
8965 memcpy(vni_m, vxlan_m->vni, size);
8966 for (i = 0; i < size; ++i)
8967 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8970 misc5_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_5);
8971 misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
8972 tunnel_header_v = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
8975 tunnel_header_m = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
8978 *tunnel_header_v = (vxlan_v->vni[0] & vxlan_m->vni[0]) |
8979 (vxlan_v->vni[1] & vxlan_m->vni[1]) << 8 |
8980 (vxlan_v->vni[2] & vxlan_m->vni[2]) << 16;
8981 if (*tunnel_header_v)
8982 *tunnel_header_m = vxlan_m->vni[0] |
8983 vxlan_m->vni[1] << 8 |
8984 vxlan_m->vni[2] << 16;
8986 *tunnel_header_m = 0x0;
8987 *tunnel_header_v |= (vxlan_v->rsvd1 & vxlan_m->rsvd1) << 24;
8988 if (vxlan_v->rsvd1 & vxlan_m->rsvd1)
8989 *tunnel_header_m |= vxlan_m->rsvd1 << 24;
8993 * Add VXLAN-GPE item to matcher and to the value.
8995 * @param[in, out] matcher
8997 * @param[in, out] key
8998 * Flow matcher value.
9000 * Flow pattern to translate.
9002 * Item is inner pattern.
9006 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
9007 const struct rte_flow_item *item,
9008 const uint64_t pattern_flags)
9010 static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {0, };
9011 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
9012 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
9013 /* The item was validated to be on the outer side */
9014 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9015 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9017 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
9019 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9021 MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
9023 MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
9024 int i, size = sizeof(vxlan_m->vni);
9025 uint8_t flags_m = 0xff;
9026 uint8_t flags_v = 0xc;
9027 uint8_t m_protocol, v_protocol;
9029 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9030 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9031 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9032 MLX5_UDP_PORT_VXLAN_GPE);
9035 vxlan_v = &dummy_vxlan_gpe_hdr;
9036 vxlan_m = &dummy_vxlan_gpe_hdr;
9039 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
9041 memcpy(vni_m, vxlan_m->vni, size);
9042 for (i = 0; i < size; ++i)
9043 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
9044 if (vxlan_m->flags) {
9045 flags_m = vxlan_m->flags;
9046 flags_v = vxlan_v->flags;
9048 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
9049 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
9050 m_protocol = vxlan_m->protocol;
9051 v_protocol = vxlan_v->protocol;
9053 /* Force next protocol to ensure next headers parsing. */
9054 if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
9055 v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
9056 else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
9057 v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
9058 else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
9059 v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
9063 MLX5_SET(fte_match_set_misc3, misc_m,
9064 outer_vxlan_gpe_next_protocol, m_protocol);
9065 MLX5_SET(fte_match_set_misc3, misc_v,
9066 outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
9070 * Add Geneve item to matcher and to the value.
9072 * @param[in, out] matcher
9074 * @param[in, out] key
9075 * Flow matcher value.
9077 * Flow pattern to translate.
9079 * Item is inner pattern.
9083 flow_dv_translate_item_geneve(void *matcher, void *key,
9084 const struct rte_flow_item *item,
9085 uint64_t pattern_flags)
9087 static const struct rte_flow_item_geneve empty_geneve = {0,};
9088 const struct rte_flow_item_geneve *geneve_m = item->mask;
9089 const struct rte_flow_item_geneve *geneve_v = item->spec;
9090 /* GENEVE flow item validation allows single tunnel item */
9091 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9092 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9093 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9094 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9097 char *vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
9098 char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
9099 size_t size = sizeof(geneve_m->vni), i;
9100 uint16_t protocol_m, protocol_v;
9102 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9103 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9104 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9105 MLX5_UDP_PORT_GENEVE);
9108 geneve_v = &empty_geneve;
9109 geneve_m = &empty_geneve;
9112 geneve_m = &rte_flow_item_geneve_mask;
9114 memcpy(vni_m, geneve_m->vni, size);
9115 for (i = 0; i < size; ++i)
9116 vni_v[i] = vni_m[i] & geneve_v->vni[i];
9117 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
9118 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
9119 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
9120 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9121 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
9122 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9123 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9124 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9125 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9126 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
9127 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9128 protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
9129 protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
9131 /* Force next protocol to prevent matchers duplication */
9132 protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9134 protocol_m = 0xFFFF;
9136 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type, protocol_m);
9137 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
9138 protocol_m & protocol_v);
9142 * Create Geneve TLV option resource.
9144 * @param dev[in, out]
9145 * Pointer to rte_eth_dev structure.
9146 * @param[in, out] tag_be24
9147 * Tag value in big endian then R-shift 8.
9148 * @parm[in, out] dev_flow
9149 * Pointer to the dev_flow.
9151 * pointer to error structure.
9154 * 0 on success otherwise -errno and errno is set.
9158 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
9159 const struct rte_flow_item *item,
9160 struct rte_flow_error *error)
9162 struct mlx5_priv *priv = dev->data->dev_private;
9163 struct mlx5_dev_ctx_shared *sh = priv->sh;
9164 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
9165 sh->geneve_tlv_option_resource;
9166 struct mlx5_devx_obj *obj;
9167 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9172 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
9173 if (geneve_opt_resource != NULL) {
9174 if (geneve_opt_resource->option_class ==
9175 geneve_opt_v->option_class &&
9176 geneve_opt_resource->option_type ==
9177 geneve_opt_v->option_type &&
9178 geneve_opt_resource->length ==
9179 geneve_opt_v->option_len) {
9180 /* We already have GENEVE TLV option obj allocated. */
9181 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
9184 ret = rte_flow_error_set(error, ENOMEM,
9185 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9186 "Only one GENEVE TLV option supported");
9190 /* Create a GENEVE TLV object and resource. */
9191 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
9192 geneve_opt_v->option_class,
9193 geneve_opt_v->option_type,
9194 geneve_opt_v->option_len);
9196 ret = rte_flow_error_set(error, ENODATA,
9197 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9198 "Failed to create GENEVE TLV Devx object");
9201 sh->geneve_tlv_option_resource =
9202 mlx5_malloc(MLX5_MEM_ZERO,
9203 sizeof(*geneve_opt_resource),
9205 if (!sh->geneve_tlv_option_resource) {
9206 claim_zero(mlx5_devx_cmd_destroy(obj));
9207 ret = rte_flow_error_set(error, ENOMEM,
9208 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9209 "GENEVE TLV object memory allocation failed");
9212 geneve_opt_resource = sh->geneve_tlv_option_resource;
9213 geneve_opt_resource->obj = obj;
9214 geneve_opt_resource->option_class = geneve_opt_v->option_class;
9215 geneve_opt_resource->option_type = geneve_opt_v->option_type;
9216 geneve_opt_resource->length = geneve_opt_v->option_len;
9217 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
9221 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
9226 * Add Geneve TLV option item to matcher.
9228 * @param[in, out] dev
9229 * Pointer to rte_eth_dev structure.
9230 * @param[in, out] matcher
9232 * @param[in, out] key
9233 * Flow matcher value.
9235 * Flow pattern to translate.
9237 * Pointer to error structure.
9240 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
9241 void *key, const struct rte_flow_item *item,
9242 struct rte_flow_error *error)
9244 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
9245 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9246 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9247 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9248 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9250 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9251 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
9257 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
9258 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
9261 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
9265 * Set the option length in GENEVE header if not requested.
9266 * The GENEVE TLV option length is expressed by the option length field
9267 * in the GENEVE header.
9268 * If the option length was not requested but the GENEVE TLV option item
9269 * is present we set the option length field implicitly.
9271 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
9272 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9273 MLX5_GENEVE_OPTLEN_MASK);
9274 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9275 geneve_opt_v->option_len + 1);
9277 MLX5_SET(fte_match_set_misc, misc_m, geneve_tlv_option_0_exist, 1);
9278 MLX5_SET(fte_match_set_misc, misc_v, geneve_tlv_option_0_exist, 1);
9280 if (geneve_opt_v->data) {
9281 memcpy(&opt_data_key, geneve_opt_v->data,
9282 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9283 sizeof(opt_data_key)));
9284 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9285 sizeof(opt_data_key));
9286 memcpy(&opt_data_mask, geneve_opt_m->data,
9287 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9288 sizeof(opt_data_mask)));
9289 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9290 sizeof(opt_data_mask));
9291 MLX5_SET(fte_match_set_misc3, misc3_m,
9292 geneve_tlv_option_0_data,
9293 rte_be_to_cpu_32(opt_data_mask));
9294 MLX5_SET(fte_match_set_misc3, misc3_v,
9295 geneve_tlv_option_0_data,
9296 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
9302 * Add MPLS item to matcher and to the value.
9304 * @param[in, out] matcher
9306 * @param[in, out] key
9307 * Flow matcher value.
9309 * Flow pattern to translate.
9310 * @param[in] prev_layer
9311 * The protocol layer indicated in previous item.
9313 * Item is inner pattern.
9316 flow_dv_translate_item_mpls(void *matcher, void *key,
9317 const struct rte_flow_item *item,
9318 uint64_t prev_layer,
9321 const uint32_t *in_mpls_m = item->mask;
9322 const uint32_t *in_mpls_v = item->spec;
9323 uint32_t *out_mpls_m = 0;
9324 uint32_t *out_mpls_v = 0;
9325 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9326 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9327 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
9329 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9330 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9331 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9333 switch (prev_layer) {
9334 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9335 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9336 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
9338 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9339 MLX5_UDP_PORT_MPLS);
9342 case MLX5_FLOW_LAYER_GRE:
9344 case MLX5_FLOW_LAYER_GRE_KEY:
9345 if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
9346 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
9348 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9349 RTE_ETHER_TYPE_MPLS);
9358 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
9359 switch (prev_layer) {
9360 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9362 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9363 outer_first_mpls_over_udp);
9365 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9366 outer_first_mpls_over_udp);
9368 case MLX5_FLOW_LAYER_GRE:
9370 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9371 outer_first_mpls_over_gre);
9373 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9374 outer_first_mpls_over_gre);
9377 /* Inner MPLS not over GRE is not supported. */
9380 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9384 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9390 if (out_mpls_m && out_mpls_v) {
9391 *out_mpls_m = *in_mpls_m;
9392 *out_mpls_v = *in_mpls_v & *in_mpls_m;
9397 * Add metadata register item to matcher
9399 * @param[in, out] matcher
9401 * @param[in, out] key
9402 * Flow matcher value.
9403 * @param[in] reg_type
9404 * Type of device metadata register
9411 flow_dv_match_meta_reg(void *matcher, void *key,
9412 enum modify_reg reg_type,
9413 uint32_t data, uint32_t mask)
9416 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
9418 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9424 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
9425 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
9428 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
9429 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
9433 * The metadata register C0 field might be divided into
9434 * source vport index and META item value, we should set
9435 * this field according to specified mask, not as whole one.
9437 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
9439 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
9440 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
9443 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
9446 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
9447 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
9450 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
9451 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
9454 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
9455 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
9458 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
9459 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
9462 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
9463 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
9466 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
9467 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
9470 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
9471 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
9480 * Add MARK item to matcher
9483 * The device to configure through.
9484 * @param[in, out] matcher
9486 * @param[in, out] key
9487 * Flow matcher value.
9489 * Flow pattern to translate.
9492 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
9493 void *matcher, void *key,
9494 const struct rte_flow_item *item)
9496 struct mlx5_priv *priv = dev->data->dev_private;
9497 const struct rte_flow_item_mark *mark;
9501 mark = item->mask ? (const void *)item->mask :
9502 &rte_flow_item_mark_mask;
9503 mask = mark->id & priv->sh->dv_mark_mask;
9504 mark = (const void *)item->spec;
9506 value = mark->id & priv->sh->dv_mark_mask & mask;
9508 enum modify_reg reg;
9510 /* Get the metadata register index for the mark. */
9511 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
9512 MLX5_ASSERT(reg > 0);
9513 if (reg == REG_C_0) {
9514 struct mlx5_priv *priv = dev->data->dev_private;
9515 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9516 uint32_t shl_c0 = rte_bsf32(msk_c0);
9522 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9527 * Add META item to matcher
9530 * The devich to configure through.
9531 * @param[in, out] matcher
9533 * @param[in, out] key
9534 * Flow matcher value.
9536 * Attributes of flow that includes this item.
9538 * Flow pattern to translate.
9541 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
9542 void *matcher, void *key,
9543 const struct rte_flow_attr *attr,
9544 const struct rte_flow_item *item)
9546 const struct rte_flow_item_meta *meta_m;
9547 const struct rte_flow_item_meta *meta_v;
9549 meta_m = (const void *)item->mask;
9551 meta_m = &rte_flow_item_meta_mask;
9552 meta_v = (const void *)item->spec;
9555 uint32_t value = meta_v->data;
9556 uint32_t mask = meta_m->data;
9558 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
9561 MLX5_ASSERT(reg != REG_NON);
9562 if (reg == REG_C_0) {
9563 struct mlx5_priv *priv = dev->data->dev_private;
9564 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9565 uint32_t shl_c0 = rte_bsf32(msk_c0);
9571 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9576 * Add vport metadata Reg C0 item to matcher
9578 * @param[in, out] matcher
9580 * @param[in, out] key
9581 * Flow matcher value.
9583 * Flow pattern to translate.
9586 flow_dv_translate_item_meta_vport(void *matcher, void *key,
9587 uint32_t value, uint32_t mask)
9589 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
9593 * Add tag item to matcher
9596 * The devich to configure through.
9597 * @param[in, out] matcher
9599 * @param[in, out] key
9600 * Flow matcher value.
9602 * Flow pattern to translate.
9605 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
9606 void *matcher, void *key,
9607 const struct rte_flow_item *item)
9609 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
9610 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
9611 uint32_t mask, value;
9614 value = tag_v->data;
9615 mask = tag_m ? tag_m->data : UINT32_MAX;
9616 if (tag_v->id == REG_C_0) {
9617 struct mlx5_priv *priv = dev->data->dev_private;
9618 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9619 uint32_t shl_c0 = rte_bsf32(msk_c0);
9625 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
9629 * Add TAG item to matcher
9632 * The devich to configure through.
9633 * @param[in, out] matcher
9635 * @param[in, out] key
9636 * Flow matcher value.
9638 * Flow pattern to translate.
9641 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
9642 void *matcher, void *key,
9643 const struct rte_flow_item *item)
9645 const struct rte_flow_item_tag *tag_v = item->spec;
9646 const struct rte_flow_item_tag *tag_m = item->mask;
9647 enum modify_reg reg;
9650 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
9651 /* Get the metadata register index for the tag. */
9652 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
9653 MLX5_ASSERT(reg > 0);
9654 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
9658 * Add source vport match to the specified matcher.
9660 * @param[in, out] matcher
9662 * @param[in, out] key
9663 * Flow matcher value.
9665 * Source vport value to match
9670 flow_dv_translate_item_source_vport(void *matcher, void *key,
9671 int16_t port, uint16_t mask)
9673 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9674 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9676 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
9677 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
9681 * Translate port-id item to eswitch match on port-id.
9684 * The devich to configure through.
9685 * @param[in, out] matcher
9687 * @param[in, out] key
9688 * Flow matcher value.
9690 * Flow pattern to translate.
9695 * 0 on success, a negative errno value otherwise.
9698 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
9699 void *key, const struct rte_flow_item *item,
9700 const struct rte_flow_attr *attr)
9702 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
9703 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
9704 struct mlx5_priv *priv;
9707 if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
9708 flow_dv_translate_item_source_vport(matcher, key,
9709 flow_dv_get_esw_manager_vport_id(dev), 0xffff);
9712 mask = pid_m ? pid_m->id : 0xffff;
9713 id = pid_v ? pid_v->id : dev->data->port_id;
9714 priv = mlx5_port_to_eswitch_info(id, item == NULL);
9718 * Translate to vport field or to metadata, depending on mode.
9719 * Kernel can use either misc.source_port or half of C0 metadata
9722 if (priv->vport_meta_mask) {
9724 * Provide the hint for SW steering library
9725 * to insert the flow into ingress domain and
9726 * save the extra vport match.
9728 if (mask == 0xffff && priv->vport_id == 0xffff &&
9729 priv->pf_bond < 0 && attr->transfer)
9730 flow_dv_translate_item_source_vport
9731 (matcher, key, priv->vport_id, mask);
9733 * We should always set the vport metadata register,
9734 * otherwise the SW steering library can drop
9735 * the rule if wire vport metadata value is not zero,
9736 * it depends on kernel configuration.
9738 flow_dv_translate_item_meta_vport(matcher, key,
9739 priv->vport_meta_tag,
9740 priv->vport_meta_mask);
9742 flow_dv_translate_item_source_vport(matcher, key,
9743 priv->vport_id, mask);
9749 * Add ICMP6 item to matcher and to the value.
9751 * @param[in, out] matcher
9753 * @param[in, out] key
9754 * Flow matcher value.
9756 * Flow pattern to translate.
9758 * Item is inner pattern.
9761 flow_dv_translate_item_icmp6(void *matcher, void *key,
9762 const struct rte_flow_item *item,
9765 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
9766 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
9769 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9771 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9773 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9775 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9777 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9779 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9781 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9782 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
9786 icmp6_m = &rte_flow_item_icmp6_mask;
9787 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
9788 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
9789 icmp6_v->type & icmp6_m->type);
9790 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
9791 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
9792 icmp6_v->code & icmp6_m->code);
9796 * Add ICMP item to matcher and to the value.
9798 * @param[in, out] matcher
9800 * @param[in, out] key
9801 * Flow matcher value.
9803 * Flow pattern to translate.
9805 * Item is inner pattern.
9808 flow_dv_translate_item_icmp(void *matcher, void *key,
9809 const struct rte_flow_item *item,
9812 const struct rte_flow_item_icmp *icmp_m = item->mask;
9813 const struct rte_flow_item_icmp *icmp_v = item->spec;
9814 uint32_t icmp_header_data_m = 0;
9815 uint32_t icmp_header_data_v = 0;
9818 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9820 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9822 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9824 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9826 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9828 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9830 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9831 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
9835 icmp_m = &rte_flow_item_icmp_mask;
9836 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
9837 icmp_m->hdr.icmp_type);
9838 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
9839 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
9840 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
9841 icmp_m->hdr.icmp_code);
9842 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
9843 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
9844 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
9845 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
9846 if (icmp_header_data_m) {
9847 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
9848 icmp_header_data_v |=
9849 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
9850 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
9851 icmp_header_data_m);
9852 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
9853 icmp_header_data_v & icmp_header_data_m);
9858 * Add GTP item to matcher and to the value.
9860 * @param[in, out] matcher
9862 * @param[in, out] key
9863 * Flow matcher value.
9865 * Flow pattern to translate.
9867 * Item is inner pattern.
9870 flow_dv_translate_item_gtp(void *matcher, void *key,
9871 const struct rte_flow_item *item, int inner)
9873 const struct rte_flow_item_gtp *gtp_m = item->mask;
9874 const struct rte_flow_item_gtp *gtp_v = item->spec;
9877 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9879 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9880 uint16_t dport = RTE_GTPU_UDP_PORT;
9883 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9885 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9887 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9889 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9891 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9892 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9893 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9898 gtp_m = &rte_flow_item_gtp_mask;
9899 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
9900 gtp_m->v_pt_rsv_flags);
9901 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
9902 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
9903 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
9904 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
9905 gtp_v->msg_type & gtp_m->msg_type);
9906 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
9907 rte_be_to_cpu_32(gtp_m->teid));
9908 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
9909 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
9913 * Add GTP PSC item to matcher.
9915 * @param[in, out] matcher
9917 * @param[in, out] key
9918 * Flow matcher value.
9920 * Flow pattern to translate.
9923 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
9924 const struct rte_flow_item *item)
9926 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
9927 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
9928 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9930 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9936 uint8_t next_ext_header_type;
9941 /* Always set E-flag match on one, regardless of GTP item settings. */
9942 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
9943 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9944 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
9945 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
9946 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9947 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
9948 /*Set next extension header type. */
9951 dw_2.next_ext_header_type = 0xff;
9952 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
9953 rte_cpu_to_be_32(dw_2.w32));
9956 dw_2.next_ext_header_type = 0x85;
9957 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
9958 rte_cpu_to_be_32(dw_2.w32));
9970 /*Set extension header PDU type and Qos. */
9972 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
9974 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->hdr.type);
9975 dw_0.qfi = gtp_psc_m->hdr.qfi;
9976 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
9977 rte_cpu_to_be_32(dw_0.w32));
9979 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
9980 gtp_psc_m->hdr.type);
9981 dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
9982 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
9983 rte_cpu_to_be_32(dw_0.w32));
9989 * Add eCPRI item to matcher and to the value.
9992 * The devich to configure through.
9993 * @param[in, out] matcher
9995 * @param[in, out] key
9996 * Flow matcher value.
9998 * Flow pattern to translate.
9999 * @param[in] last_item
10003 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
10004 void *key, const struct rte_flow_item *item,
10005 uint64_t last_item)
10007 struct mlx5_priv *priv = dev->data->dev_private;
10008 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
10009 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
10010 struct rte_ecpri_common_hdr common;
10011 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
10012 misc_parameters_4);
10013 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
10019 * In case of eCPRI over Ethernet, if EtherType is not specified,
10020 * match on eCPRI EtherType implicitly.
10022 if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
10023 void *hdrs_m, *hdrs_v, *l2m, *l2v;
10025 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
10026 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10027 l2m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, ethertype);
10028 l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
10029 if (*(uint16_t *)l2m == 0 && *(uint16_t *)l2v == 0) {
10030 *(uint16_t *)l2m = UINT16_MAX;
10031 *(uint16_t *)l2v = RTE_BE16(RTE_ETHER_TYPE_ECPRI);
10037 ecpri_m = &rte_flow_item_ecpri_mask;
10039 * Maximal four DW samples are supported in a single matching now.
10040 * Two are used now for a eCPRI matching:
10041 * 1. Type: one byte, mask should be 0x00ff0000 in network order
10042 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
10045 if (!ecpri_m->hdr.common.u32)
10047 samples = priv->sh->ecpri_parser.ids;
10048 /* Need to take the whole DW as the mask to fill the entry. */
10049 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
10050 prog_sample_field_value_0);
10051 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
10052 prog_sample_field_value_0);
10053 /* Already big endian (network order) in the header. */
10054 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
10055 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
10056 /* Sample#0, used for matching type, offset 0. */
10057 MLX5_SET(fte_match_set_misc4, misc4_m,
10058 prog_sample_field_id_0, samples[0]);
10059 /* It makes no sense to set the sample ID in the mask field. */
10060 MLX5_SET(fte_match_set_misc4, misc4_v,
10061 prog_sample_field_id_0, samples[0]);
10063 * Checking if message body part needs to be matched.
10064 * Some wildcard rules only matching type field should be supported.
10066 if (ecpri_m->hdr.dummy[0]) {
10067 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
10068 switch (common.type) {
10069 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
10070 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
10071 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
10072 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
10073 prog_sample_field_value_1);
10074 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
10075 prog_sample_field_value_1);
10076 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
10077 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
10078 ecpri_m->hdr.dummy[0];
10079 /* Sample#1, to match message body, offset 4. */
10080 MLX5_SET(fte_match_set_misc4, misc4_m,
10081 prog_sample_field_id_1, samples[1]);
10082 MLX5_SET(fte_match_set_misc4, misc4_v,
10083 prog_sample_field_id_1, samples[1]);
10086 /* Others, do not match any sample ID. */
10093 * Add connection tracking status item to matcher
10096 * The devich to configure through.
10097 * @param[in, out] matcher
10099 * @param[in, out] key
10100 * Flow matcher value.
10102 * Flow pattern to translate.
10105 flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
10106 void *matcher, void *key,
10107 const struct rte_flow_item *item)
10109 uint32_t reg_value = 0;
10111 /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
10112 uint32_t reg_mask = 0;
10113 const struct rte_flow_item_conntrack *spec = item->spec;
10114 const struct rte_flow_item_conntrack *mask = item->mask;
10116 struct rte_flow_error error;
10119 mask = &rte_flow_item_conntrack_mask;
10120 if (!spec || !mask->flags)
10122 flags = spec->flags & mask->flags;
10123 /* The conflict should be checked in the validation. */
10124 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
10125 reg_value |= MLX5_CT_SYNDROME_VALID;
10126 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10127 reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
10128 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
10129 reg_value |= MLX5_CT_SYNDROME_INVALID;
10130 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
10131 reg_value |= MLX5_CT_SYNDROME_TRAP;
10132 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10133 reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
10134 if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
10135 RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
10136 RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
10138 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10139 reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
10140 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10141 reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
10142 /* The REG_C_x value could be saved during startup. */
10143 reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
10144 if (reg_id == REG_NON)
10146 flow_dv_match_meta_reg(matcher, key, (enum modify_reg)reg_id,
10147 reg_value, reg_mask);
10151 flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
10152 const struct rte_flow_item *item,
10153 struct mlx5_flow *dev_flow, bool is_inner)
10155 const struct rte_flow_item_flex *spec =
10156 (const struct rte_flow_item_flex *)item->spec;
10157 int index = mlx5_flex_acquire_index(dev, spec->handle, false);
10159 MLX5_ASSERT(index >= 0 && index <= (int)(sizeof(uint32_t) * CHAR_BIT));
10162 if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
10163 /* Don't count both inner and outer flex items in one rule. */
10164 if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
10165 MLX5_ASSERT(false);
10166 dev_flow->handle->flex_item |= RTE_BIT32(index);
10168 mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
10171 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
10173 #define HEADER_IS_ZERO(match_criteria, headers) \
10174 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
10175 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
10178 * Calculate flow matcher enable bitmap.
10180 * @param match_criteria
10181 * Pointer to flow matcher criteria.
10184 * Bitmap of enabled fields.
10187 flow_dv_matcher_enable(uint32_t *match_criteria)
10189 uint8_t match_criteria_enable;
10191 match_criteria_enable =
10192 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
10193 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
10194 match_criteria_enable |=
10195 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
10196 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
10197 match_criteria_enable |=
10198 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
10199 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
10200 match_criteria_enable |=
10201 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
10202 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
10203 match_criteria_enable |=
10204 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
10205 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
10206 match_criteria_enable |=
10207 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
10208 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
10209 match_criteria_enable |=
10210 (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
10211 MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
10212 return match_criteria_enable;
10216 __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
10219 * Check flow matching criteria first, subtract misc5/4 length if flow
10220 * doesn't own misc5/4 parameters. In some old rdma-core releases,
10221 * misc5/4 are not supported, and matcher creation failure is expected
10222 * w/o subtraction. If misc5 is provided, misc4 must be counted in since
10223 * misc5 is right after misc4.
10225 if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
10226 *size = MLX5_ST_SZ_BYTES(fte_match_param) -
10227 MLX5_ST_SZ_BYTES(fte_match_set_misc5);
10228 if (!(match_criteria & (1 <<
10229 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
10230 *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
10235 static struct mlx5_list_entry *
10236 flow_dv_matcher_clone_cb(void *tool_ctx __rte_unused,
10237 struct mlx5_list_entry *entry, void *cb_ctx)
10239 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10240 struct mlx5_flow_dv_matcher *ref = ctx->data;
10241 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10242 typeof(*tbl), tbl);
10243 struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
10248 rte_flow_error_set(ctx->error, ENOMEM,
10249 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10250 "cannot create matcher");
10253 memcpy(resource, entry, sizeof(*resource));
10254 resource->tbl = &tbl->tbl;
10255 return &resource->entry;
10259 flow_dv_matcher_clone_free_cb(void *tool_ctx __rte_unused,
10260 struct mlx5_list_entry *entry)
10265 struct mlx5_list_entry *
10266 flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
10268 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10269 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10270 struct rte_eth_dev *dev = ctx->dev;
10271 struct mlx5_flow_tbl_data_entry *tbl_data;
10272 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
10273 struct rte_flow_error *error = ctx->error;
10274 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10275 struct mlx5_flow_tbl_resource *tbl;
10280 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10282 rte_flow_error_set(error, ENOMEM,
10283 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10285 "cannot allocate flow table data entry");
10288 tbl_data->idx = idx;
10289 tbl_data->tunnel = tt_prm->tunnel;
10290 tbl_data->group_id = tt_prm->group_id;
10291 tbl_data->external = !!tt_prm->external;
10292 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
10293 tbl_data->is_egress = !!key.is_egress;
10294 tbl_data->is_transfer = !!key.is_fdb;
10295 tbl_data->dummy = !!key.dummy;
10296 tbl_data->level = key.level;
10297 tbl_data->id = key.id;
10298 tbl = &tbl_data->tbl;
10300 return &tbl_data->entry;
10302 domain = sh->fdb_domain;
10303 else if (key.is_egress)
10304 domain = sh->tx_domain;
10306 domain = sh->rx_domain;
10307 ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
10309 rte_flow_error_set(error, ENOMEM,
10310 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10311 NULL, "cannot create flow table object");
10312 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10315 if (key.level != 0) {
10316 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
10317 (tbl->obj, &tbl_data->jump.action);
10319 rte_flow_error_set(error, ENOMEM,
10320 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10322 "cannot create flow jump action");
10323 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10324 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10328 MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
10329 key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
10330 key.level, key.id);
10331 tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
10332 flow_dv_matcher_create_cb,
10333 flow_dv_matcher_match_cb,
10334 flow_dv_matcher_remove_cb,
10335 flow_dv_matcher_clone_cb,
10336 flow_dv_matcher_clone_free_cb);
10337 if (!tbl_data->matchers) {
10338 rte_flow_error_set(error, ENOMEM,
10339 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10341 "cannot create tbl matcher list");
10342 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10343 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10344 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10347 return &tbl_data->entry;
10351 flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10354 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10355 struct mlx5_flow_tbl_data_entry *tbl_data =
10356 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10357 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10359 return tbl_data->level != key.level ||
10360 tbl_data->id != key.id ||
10361 tbl_data->dummy != key.dummy ||
10362 tbl_data->is_transfer != !!key.is_fdb ||
10363 tbl_data->is_egress != !!key.is_egress;
10366 struct mlx5_list_entry *
10367 flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10370 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10371 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10372 struct mlx5_flow_tbl_data_entry *tbl_data;
10373 struct rte_flow_error *error = ctx->error;
10376 tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10378 rte_flow_error_set(error, ENOMEM,
10379 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10381 "cannot allocate flow table data entry");
10384 memcpy(tbl_data, oentry, sizeof(*tbl_data));
10385 tbl_data->idx = idx;
10386 return &tbl_data->entry;
10390 flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10392 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10393 struct mlx5_flow_tbl_data_entry *tbl_data =
10394 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10396 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10400 * Get a flow table.
10402 * @param[in, out] dev
10403 * Pointer to rte_eth_dev structure.
10404 * @param[in] table_level
10405 * Table level to use.
10406 * @param[in] egress
10407 * Direction of the table.
10408 * @param[in] transfer
10409 * E-Switch or NIC flow.
10411 * Dummy entry for dv API.
10412 * @param[in] table_id
10414 * @param[out] error
10415 * pointer to error structure.
10418 * Returns tables resource based on the index, NULL in case of failed.
10420 struct mlx5_flow_tbl_resource *
10421 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
10422 uint32_t table_level, uint8_t egress,
10425 const struct mlx5_flow_tunnel *tunnel,
10426 uint32_t group_id, uint8_t dummy,
10428 struct rte_flow_error *error)
10430 struct mlx5_priv *priv = dev->data->dev_private;
10431 union mlx5_flow_tbl_key table_key = {
10433 .level = table_level,
10437 .is_fdb = !!transfer,
10438 .is_egress = !!egress,
10441 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
10443 .group_id = group_id,
10444 .external = external,
10446 struct mlx5_flow_cb_ctx ctx = {
10449 .data = &table_key.v64,
10452 struct mlx5_list_entry *entry;
10453 struct mlx5_flow_tbl_data_entry *tbl_data;
10455 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
10457 rte_flow_error_set(error, ENOMEM,
10458 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10459 "cannot get table");
10462 DRV_LOG(DEBUG, "table_level %u table_id %u "
10463 "tunnel %u group %u registered.",
10464 table_level, table_id,
10465 tunnel ? tunnel->tunnel_id : 0, group_id);
10466 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10467 return &tbl_data->tbl;
10471 flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10473 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10474 struct mlx5_flow_tbl_data_entry *tbl_data =
10475 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10477 MLX5_ASSERT(entry && sh);
10478 if (tbl_data->jump.action)
10479 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10480 if (tbl_data->tbl.obj)
10481 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
10482 if (tbl_data->tunnel_offload && tbl_data->external) {
10483 struct mlx5_list_entry *he;
10484 struct mlx5_hlist *tunnel_grp_hash;
10485 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
10486 union tunnel_tbl_key tunnel_key = {
10487 .tunnel_id = tbl_data->tunnel ?
10488 tbl_data->tunnel->tunnel_id : 0,
10489 .group = tbl_data->group_id
10491 uint32_t table_level = tbl_data->level;
10492 struct mlx5_flow_cb_ctx ctx = {
10493 .data = (void *)&tunnel_key.val,
10496 tunnel_grp_hash = tbl_data->tunnel ?
10497 tbl_data->tunnel->groups :
10499 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
10501 mlx5_hlist_unregister(tunnel_grp_hash, he);
10503 "table_level %u id %u tunnel %u group %u released.",
10507 tbl_data->tunnel->tunnel_id : 0,
10508 tbl_data->group_id);
10510 mlx5_list_destroy(tbl_data->matchers);
10511 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10515 * Release a flow table.
10518 * Pointer to device shared structure.
10520 * Table resource to be released.
10523 * Returns 0 if table was released, else return 1;
10526 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
10527 struct mlx5_flow_tbl_resource *tbl)
10529 struct mlx5_flow_tbl_data_entry *tbl_data =
10530 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10534 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
10538 flow_dv_matcher_match_cb(void *tool_ctx __rte_unused,
10539 struct mlx5_list_entry *entry, void *cb_ctx)
10541 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10542 struct mlx5_flow_dv_matcher *ref = ctx->data;
10543 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
10546 return cur->crc != ref->crc ||
10547 cur->priority != ref->priority ||
10548 memcmp((const void *)cur->mask.buf,
10549 (const void *)ref->mask.buf, ref->mask.size);
10552 struct mlx5_list_entry *
10553 flow_dv_matcher_create_cb(void *tool_ctx, void *cb_ctx)
10555 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10556 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10557 struct mlx5_flow_dv_matcher *ref = ctx->data;
10558 struct mlx5_flow_dv_matcher *resource;
10559 struct mlx5dv_flow_matcher_attr dv_attr = {
10560 .type = IBV_FLOW_ATTR_NORMAL,
10561 .match_mask = (void *)&ref->mask,
10563 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10564 typeof(*tbl), tbl);
10567 resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
10570 rte_flow_error_set(ctx->error, ENOMEM,
10571 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10572 "cannot create matcher");
10576 dv_attr.match_criteria_enable =
10577 flow_dv_matcher_enable(resource->mask.buf);
10578 __flow_dv_adjust_buf_size(&ref->mask.size,
10579 dv_attr.match_criteria_enable);
10580 dv_attr.priority = ref->priority;
10581 if (tbl->is_egress)
10582 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
10583 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
10585 &resource->matcher_object);
10587 mlx5_free(resource);
10588 rte_flow_error_set(ctx->error, ENOMEM,
10589 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10590 "cannot create matcher");
10593 return &resource->entry;
10597 * Register the flow matcher.
10599 * @param[in, out] dev
10600 * Pointer to rte_eth_dev structure.
10601 * @param[in, out] matcher
10602 * Pointer to flow matcher.
10603 * @param[in, out] key
10604 * Pointer to flow table key.
10605 * @parm[in, out] dev_flow
10606 * Pointer to the dev_flow.
10607 * @param[out] error
10608 * pointer to error structure.
10611 * 0 on success otherwise -errno and errno is set.
10614 flow_dv_matcher_register(struct rte_eth_dev *dev,
10615 struct mlx5_flow_dv_matcher *ref,
10616 union mlx5_flow_tbl_key *key,
10617 struct mlx5_flow *dev_flow,
10618 const struct mlx5_flow_tunnel *tunnel,
10620 struct rte_flow_error *error)
10622 struct mlx5_list_entry *entry;
10623 struct mlx5_flow_dv_matcher *resource;
10624 struct mlx5_flow_tbl_resource *tbl;
10625 struct mlx5_flow_tbl_data_entry *tbl_data;
10626 struct mlx5_flow_cb_ctx ctx = {
10631 * tunnel offload API requires this registration for cases when
10632 * tunnel match rule was inserted before tunnel set rule.
10634 tbl = flow_dv_tbl_resource_get(dev, key->level,
10635 key->is_egress, key->is_fdb,
10636 dev_flow->external, tunnel,
10637 group_id, 0, key->id, error);
10639 return -rte_errno; /* No need to refill the error info */
10640 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10642 entry = mlx5_list_register(tbl_data->matchers, &ctx);
10644 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
10645 return rte_flow_error_set(error, ENOMEM,
10646 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10647 "cannot allocate ref memory");
10649 resource = container_of(entry, typeof(*resource), entry);
10650 dev_flow->handle->dvh.matcher = resource;
10654 struct mlx5_list_entry *
10655 flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
10657 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10658 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10659 struct mlx5_flow_dv_tag_resource *entry;
10663 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10665 rte_flow_error_set(ctx->error, ENOMEM,
10666 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10667 "cannot allocate resource memory");
10671 entry->tag_id = *(uint32_t *)(ctx->data);
10672 ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
10675 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
10676 rte_flow_error_set(ctx->error, ENOMEM,
10677 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10678 NULL, "cannot create action");
10681 return &entry->entry;
10685 flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10688 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10689 struct mlx5_flow_dv_tag_resource *tag =
10690 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10692 return *(uint32_t *)(ctx->data) != tag->tag_id;
10695 struct mlx5_list_entry *
10696 flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10699 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10700 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10701 struct mlx5_flow_dv_tag_resource *entry;
10704 entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10706 rte_flow_error_set(ctx->error, ENOMEM,
10707 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10708 "cannot allocate tag resource memory");
10711 memcpy(entry, oentry, sizeof(*entry));
10713 return &entry->entry;
10717 flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10719 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10720 struct mlx5_flow_dv_tag_resource *tag =
10721 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10723 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10727 * Find existing tag resource or create and register a new one.
10729 * @param dev[in, out]
10730 * Pointer to rte_eth_dev structure.
10731 * @param[in, out] tag_be24
10732 * Tag value in big endian then R-shift 8.
10733 * @parm[in, out] dev_flow
10734 * Pointer to the dev_flow.
10735 * @param[out] error
10736 * pointer to error structure.
10739 * 0 on success otherwise -errno and errno is set.
10742 flow_dv_tag_resource_register
10743 (struct rte_eth_dev *dev,
10745 struct mlx5_flow *dev_flow,
10746 struct rte_flow_error *error)
10748 struct mlx5_priv *priv = dev->data->dev_private;
10749 struct mlx5_flow_dv_tag_resource *resource;
10750 struct mlx5_list_entry *entry;
10751 struct mlx5_flow_cb_ctx ctx = {
10755 struct mlx5_hlist *tag_table;
10757 tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
10759 MLX5_TAGS_HLIST_ARRAY_SIZE,
10760 false, false, priv->sh,
10761 flow_dv_tag_create_cb,
10762 flow_dv_tag_match_cb,
10763 flow_dv_tag_remove_cb,
10764 flow_dv_tag_clone_cb,
10765 flow_dv_tag_clone_free_cb,
10767 if (unlikely(!tag_table))
10769 entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
10771 resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
10773 dev_flow->handle->dvh.rix_tag = resource->idx;
10774 dev_flow->dv.tag_resource = resource;
10781 flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10783 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10784 struct mlx5_flow_dv_tag_resource *tag =
10785 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10787 MLX5_ASSERT(tag && sh && tag->action);
10788 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
10789 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
10790 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10797 * Pointer to Ethernet device.
10802 * 1 while a reference on it exists, 0 when freed.
10805 flow_dv_tag_release(struct rte_eth_dev *dev,
10808 struct mlx5_priv *priv = dev->data->dev_private;
10809 struct mlx5_flow_dv_tag_resource *tag;
10811 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
10814 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
10815 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
10816 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
10820 * Translate action PORT_ID / REPRESENTED_PORT to vport.
10823 * Pointer to rte_eth_dev structure.
10824 * @param[in] action
10825 * Pointer to action PORT_ID / REPRESENTED_PORT.
10826 * @param[out] dst_port_id
10827 * The target port ID.
10828 * @param[out] error
10829 * Pointer to the error structure.
10832 * 0 on success, a negative errno value otherwise and rte_errno is set.
10835 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
10836 const struct rte_flow_action *action,
10837 uint32_t *dst_port_id,
10838 struct rte_flow_error *error)
10841 struct mlx5_priv *priv;
10843 switch (action->type) {
10844 case RTE_FLOW_ACTION_TYPE_PORT_ID: {
10845 const struct rte_flow_action_port_id *conf;
10847 conf = (const struct rte_flow_action_port_id *)action->conf;
10848 port = conf->original ? dev->data->port_id : conf->id;
10851 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
10852 const struct rte_flow_action_ethdev *ethdev;
10854 ethdev = (const struct rte_flow_action_ethdev *)action->conf;
10855 port = ethdev->port_id;
10859 MLX5_ASSERT(false);
10860 return rte_flow_error_set(error, EINVAL,
10861 RTE_FLOW_ERROR_TYPE_ACTION, action,
10862 "unknown E-Switch action");
10865 priv = mlx5_port_to_eswitch_info(port, false);
10867 return rte_flow_error_set(error, -rte_errno,
10868 RTE_FLOW_ERROR_TYPE_ACTION,
10870 "No eswitch info was found for port");
10871 #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
10873 * This parameter is transferred to
10874 * mlx5dv_dr_action_create_dest_ib_port().
10876 *dst_port_id = priv->dev_port;
10879 * Legacy mode, no LAG configurations is supported.
10880 * This parameter is transferred to
10881 * mlx5dv_dr_action_create_dest_vport().
10883 *dst_port_id = priv->vport_id;
10889 * Create a counter with aging configuration.
10892 * Pointer to rte_eth_dev structure.
10893 * @param[in] dev_flow
10894 * Pointer to the mlx5_flow.
10895 * @param[out] count
10896 * Pointer to the counter action configuration.
10898 * Pointer to the aging action configuration.
10901 * Index to flow counter on success, 0 otherwise.
10904 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
10905 struct mlx5_flow *dev_flow,
10906 const struct rte_flow_action_count *count
10908 const struct rte_flow_action_age *age)
10911 struct mlx5_age_param *age_param;
10913 counter = flow_dv_counter_alloc(dev, !!age);
10914 if (!counter || age == NULL)
10916 age_param = flow_dv_counter_idx_get_age(dev, counter);
10917 age_param->context = age->context ? age->context :
10918 (void *)(uintptr_t)(dev_flow->flow_idx);
10919 age_param->timeout = age->timeout;
10920 age_param->port_id = dev->data->port_id;
10921 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
10922 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
10927 * Add Tx queue matcher
10930 * Pointer to the dev struct.
10931 * @param[in, out] matcher
10933 * @param[in, out] key
10934 * Flow matcher value.
10936 * Flow pattern to translate.
10938 * Item is inner pattern.
10941 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
10942 void *matcher, void *key,
10943 const struct rte_flow_item *item)
10945 const struct mlx5_rte_flow_item_tx_queue *queue_m;
10946 const struct mlx5_rte_flow_item_tx_queue *queue_v;
10948 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
10950 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10951 struct mlx5_txq_ctrl *txq;
10952 uint32_t queue, mask;
10954 queue_m = (const void *)item->mask;
10955 queue_v = (const void *)item->spec;
10958 txq = mlx5_txq_get(dev, queue_v->queue);
10961 if (txq->type == MLX5_TXQ_TYPE_HAIRPIN)
10962 queue = txq->obj->sq->id;
10964 queue = txq->obj->sq_obj.sq->id;
10965 mask = queue_m == NULL ? UINT32_MAX : queue_m->queue;
10966 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, mask);
10967 MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue & mask);
10968 mlx5_txq_release(dev, queue_v->queue);
10972 * Set the hash fields according to the @p flow information.
10974 * @param[in] dev_flow
10975 * Pointer to the mlx5_flow.
10976 * @param[in] rss_desc
10977 * Pointer to the mlx5_flow_rss_desc.
10980 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
10981 struct mlx5_flow_rss_desc *rss_desc)
10983 uint64_t items = dev_flow->handle->layers;
10985 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
10987 dev_flow->hash_fields = 0;
10988 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
10989 if (rss_desc->level >= 2)
10992 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
10993 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
10994 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
10995 if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
10996 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
10997 else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
10998 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
11000 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
11002 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
11003 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
11004 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
11005 if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
11006 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
11007 else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
11008 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
11010 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
11013 if (dev_flow->hash_fields == 0)
11015 * There is no match between the RSS types and the
11016 * L3 protocol (IPv4/IPv6) defined in the flow rule.
11019 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
11020 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
11021 if (rss_types & RTE_ETH_RSS_UDP) {
11022 if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
11023 dev_flow->hash_fields |=
11024 IBV_RX_HASH_SRC_PORT_UDP;
11025 else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
11026 dev_flow->hash_fields |=
11027 IBV_RX_HASH_DST_PORT_UDP;
11029 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
11031 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
11032 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
11033 if (rss_types & RTE_ETH_RSS_TCP) {
11034 if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
11035 dev_flow->hash_fields |=
11036 IBV_RX_HASH_SRC_PORT_TCP;
11037 else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
11038 dev_flow->hash_fields |=
11039 IBV_RX_HASH_DST_PORT_TCP;
11041 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
11045 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
11049 * Prepare an Rx Hash queue.
11052 * Pointer to Ethernet device.
11053 * @param[in] dev_flow
11054 * Pointer to the mlx5_flow.
11055 * @param[in] rss_desc
11056 * Pointer to the mlx5_flow_rss_desc.
11057 * @param[out] hrxq_idx
11058 * Hash Rx queue index.
11061 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
11063 static struct mlx5_hrxq *
11064 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
11065 struct mlx5_flow *dev_flow,
11066 struct mlx5_flow_rss_desc *rss_desc,
11067 uint32_t *hrxq_idx)
11069 struct mlx5_priv *priv = dev->data->dev_private;
11070 struct mlx5_flow_handle *dh = dev_flow->handle;
11071 struct mlx5_hrxq *hrxq;
11073 MLX5_ASSERT(rss_desc->queue_num);
11074 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
11075 rss_desc->hash_fields = dev_flow->hash_fields;
11076 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
11077 rss_desc->shared_rss = 0;
11078 if (rss_desc->hash_fields == 0)
11079 rss_desc->queue_num = 1;
11080 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc);
11083 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
11089 * Release sample sub action resource.
11091 * @param[in, out] dev
11092 * Pointer to rte_eth_dev structure.
11093 * @param[in] act_res
11094 * Pointer to sample sub action resource.
11097 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
11098 struct mlx5_flow_sub_actions_idx *act_res)
11100 if (act_res->rix_hrxq) {
11101 mlx5_hrxq_release(dev, act_res->rix_hrxq);
11102 act_res->rix_hrxq = 0;
11104 if (act_res->rix_encap_decap) {
11105 flow_dv_encap_decap_resource_release(dev,
11106 act_res->rix_encap_decap);
11107 act_res->rix_encap_decap = 0;
11109 if (act_res->rix_port_id_action) {
11110 flow_dv_port_id_action_resource_release(dev,
11111 act_res->rix_port_id_action);
11112 act_res->rix_port_id_action = 0;
11114 if (act_res->rix_tag) {
11115 flow_dv_tag_release(dev, act_res->rix_tag);
11116 act_res->rix_tag = 0;
11118 if (act_res->rix_jump) {
11119 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
11120 act_res->rix_jump = 0;
11125 flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
11126 struct mlx5_list_entry *entry, void *cb_ctx)
11128 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11129 struct rte_eth_dev *dev = ctx->dev;
11130 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11131 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
11135 if (ctx_resource->ratio == resource->ratio &&
11136 ctx_resource->ft_type == resource->ft_type &&
11137 ctx_resource->ft_id == resource->ft_id &&
11138 ctx_resource->set_action == resource->set_action &&
11139 !memcmp((void *)&ctx_resource->sample_act,
11140 (void *)&resource->sample_act,
11141 sizeof(struct mlx5_flow_sub_actions_list))) {
11143 * Existing sample action should release the prepared
11144 * sub-actions reference counter.
11146 flow_dv_sample_sub_actions_release(dev,
11147 &ctx_resource->sample_idx);
11153 struct mlx5_list_entry *
11154 flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11156 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11157 struct rte_eth_dev *dev = ctx->dev;
11158 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11159 void **sample_dv_actions = ctx_resource->sub_actions;
11160 struct mlx5_flow_dv_sample_resource *resource;
11161 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
11162 struct mlx5_priv *priv = dev->data->dev_private;
11163 struct mlx5_dev_ctx_shared *sh = priv->sh;
11164 struct mlx5_flow_tbl_resource *tbl;
11166 const uint32_t next_ft_step = 1;
11167 uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
11168 uint8_t is_egress = 0;
11169 uint8_t is_transfer = 0;
11170 struct rte_flow_error *error = ctx->error;
11172 /* Register new sample resource. */
11173 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11175 rte_flow_error_set(error, ENOMEM,
11176 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11178 "cannot allocate resource memory");
11181 *resource = *ctx_resource;
11182 /* Create normal path table level */
11183 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11185 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
11187 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
11188 is_egress, is_transfer,
11189 true, NULL, 0, 0, 0, error);
11191 rte_flow_error_set(error, ENOMEM,
11192 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11194 "fail to create normal path table "
11198 resource->normal_path_tbl = tbl;
11199 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
11200 if (!sh->default_miss_action) {
11201 rte_flow_error_set(error, ENOMEM,
11202 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11204 "default miss action was not "
11208 sample_dv_actions[ctx_resource->sample_act.actions_num++] =
11209 sh->default_miss_action;
11211 /* Create a DR sample action */
11212 sampler_attr.sample_ratio = resource->ratio;
11213 sampler_attr.default_next_table = tbl->obj;
11214 sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
11215 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
11216 &sample_dv_actions[0];
11217 sampler_attr.action = resource->set_action;
11218 if (mlx5_os_flow_dr_create_flow_action_sampler
11219 (&sampler_attr, &resource->verbs_action)) {
11220 rte_flow_error_set(error, ENOMEM,
11221 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11222 NULL, "cannot create sample action");
11225 resource->idx = idx;
11226 resource->dev = dev;
11227 return &resource->entry;
11229 if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
11230 flow_dv_sample_sub_actions_release(dev,
11231 &resource->sample_idx);
11232 if (resource->normal_path_tbl)
11233 flow_dv_tbl_resource_release(MLX5_SH(dev),
11234 resource->normal_path_tbl);
11235 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
11240 struct mlx5_list_entry *
11241 flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
11242 struct mlx5_list_entry *entry __rte_unused,
11245 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11246 struct rte_eth_dev *dev = ctx->dev;
11247 struct mlx5_flow_dv_sample_resource *resource;
11248 struct mlx5_priv *priv = dev->data->dev_private;
11249 struct mlx5_dev_ctx_shared *sh = priv->sh;
11252 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11254 rte_flow_error_set(ctx->error, ENOMEM,
11255 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11257 "cannot allocate resource memory");
11260 memcpy(resource, entry, sizeof(*resource));
11261 resource->idx = idx;
11262 resource->dev = dev;
11263 return &resource->entry;
11267 flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
11268 struct mlx5_list_entry *entry)
11270 struct mlx5_flow_dv_sample_resource *resource =
11271 container_of(entry, typeof(*resource), entry);
11272 struct rte_eth_dev *dev = resource->dev;
11273 struct mlx5_priv *priv = dev->data->dev_private;
11275 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
11279 * Find existing sample resource or create and register a new one.
11281 * @param[in, out] dev
11282 * Pointer to rte_eth_dev structure.
11284 * Pointer to sample resource reference.
11285 * @parm[in, out] dev_flow
11286 * Pointer to the dev_flow.
11287 * @param[out] error
11288 * pointer to error structure.
11291 * 0 on success otherwise -errno and errno is set.
11294 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
11295 struct mlx5_flow_dv_sample_resource *ref,
11296 struct mlx5_flow *dev_flow,
11297 struct rte_flow_error *error)
11299 struct mlx5_flow_dv_sample_resource *resource;
11300 struct mlx5_list_entry *entry;
11301 struct mlx5_priv *priv = dev->data->dev_private;
11302 struct mlx5_flow_cb_ctx ctx = {
11308 entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
11311 resource = container_of(entry, typeof(*resource), entry);
11312 dev_flow->handle->dvh.rix_sample = resource->idx;
11313 dev_flow->dv.sample_res = resource;
11318 flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
11319 struct mlx5_list_entry *entry, void *cb_ctx)
11321 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11322 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11323 struct rte_eth_dev *dev = ctx->dev;
11324 struct mlx5_flow_dv_dest_array_resource *resource =
11325 container_of(entry, typeof(*resource), entry);
11328 if (ctx_resource->num_of_dest == resource->num_of_dest &&
11329 ctx_resource->ft_type == resource->ft_type &&
11330 !memcmp((void *)resource->sample_act,
11331 (void *)ctx_resource->sample_act,
11332 (ctx_resource->num_of_dest *
11333 sizeof(struct mlx5_flow_sub_actions_list)))) {
11335 * Existing sample action should release the prepared
11336 * sub-actions reference counter.
11338 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11339 flow_dv_sample_sub_actions_release(dev,
11340 &ctx_resource->sample_idx[idx]);
11346 struct mlx5_list_entry *
11347 flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11349 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11350 struct rte_eth_dev *dev = ctx->dev;
11351 struct mlx5_flow_dv_dest_array_resource *resource;
11352 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11353 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
11354 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
11355 struct mlx5_priv *priv = dev->data->dev_private;
11356 struct mlx5_dev_ctx_shared *sh = priv->sh;
11357 struct mlx5_flow_sub_actions_list *sample_act;
11358 struct mlx5dv_dr_domain *domain;
11359 uint32_t idx = 0, res_idx = 0;
11360 struct rte_flow_error *error = ctx->error;
11361 uint64_t action_flags;
11364 /* Register new destination array resource. */
11365 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11368 rte_flow_error_set(error, ENOMEM,
11369 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11371 "cannot allocate resource memory");
11374 *resource = *ctx_resource;
11375 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11376 domain = sh->fdb_domain;
11377 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
11378 domain = sh->rx_domain;
11380 domain = sh->tx_domain;
11381 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11382 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
11383 mlx5_malloc(MLX5_MEM_ZERO,
11384 sizeof(struct mlx5dv_dr_action_dest_attr),
11386 if (!dest_attr[idx]) {
11387 rte_flow_error_set(error, ENOMEM,
11388 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11390 "cannot allocate resource memory");
11393 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
11394 sample_act = &ctx_resource->sample_act[idx];
11395 action_flags = sample_act->action_flags;
11396 switch (action_flags) {
11397 case MLX5_FLOW_ACTION_QUEUE:
11398 dest_attr[idx]->dest = sample_act->dr_queue_action;
11400 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
11401 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
11402 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
11403 dest_attr[idx]->dest_reformat->reformat =
11404 sample_act->dr_encap_action;
11405 dest_attr[idx]->dest_reformat->dest =
11406 sample_act->dr_port_id_action;
11408 case MLX5_FLOW_ACTION_PORT_ID:
11409 dest_attr[idx]->dest = sample_act->dr_port_id_action;
11411 case MLX5_FLOW_ACTION_JUMP:
11412 dest_attr[idx]->dest = sample_act->dr_jump_action;
11415 rte_flow_error_set(error, EINVAL,
11416 RTE_FLOW_ERROR_TYPE_ACTION,
11418 "unsupported actions type");
11422 /* create a dest array action */
11423 ret = mlx5_os_flow_dr_create_flow_action_dest_array
11425 resource->num_of_dest,
11427 &resource->action);
11429 rte_flow_error_set(error, ENOMEM,
11430 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11432 "cannot create destination array action");
11435 resource->idx = res_idx;
11436 resource->dev = dev;
11437 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11438 mlx5_free(dest_attr[idx]);
11439 return &resource->entry;
11441 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11442 flow_dv_sample_sub_actions_release(dev,
11443 &resource->sample_idx[idx]);
11444 if (dest_attr[idx])
11445 mlx5_free(dest_attr[idx]);
11447 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
11451 struct mlx5_list_entry *
11452 flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
11453 struct mlx5_list_entry *entry __rte_unused,
11456 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11457 struct rte_eth_dev *dev = ctx->dev;
11458 struct mlx5_flow_dv_dest_array_resource *resource;
11459 struct mlx5_priv *priv = dev->data->dev_private;
11460 struct mlx5_dev_ctx_shared *sh = priv->sh;
11461 uint32_t res_idx = 0;
11462 struct rte_flow_error *error = ctx->error;
11464 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11467 rte_flow_error_set(error, ENOMEM,
11468 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11470 "cannot allocate dest-array memory");
11473 memcpy(resource, entry, sizeof(*resource));
11474 resource->idx = res_idx;
11475 resource->dev = dev;
11476 return &resource->entry;
11480 flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
11481 struct mlx5_list_entry *entry)
11483 struct mlx5_flow_dv_dest_array_resource *resource =
11484 container_of(entry, typeof(*resource), entry);
11485 struct rte_eth_dev *dev = resource->dev;
11486 struct mlx5_priv *priv = dev->data->dev_private;
11488 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
11492 * Find existing destination array resource or create and register a new one.
11494 * @param[in, out] dev
11495 * Pointer to rte_eth_dev structure.
11497 * Pointer to destination array resource reference.
11498 * @parm[in, out] dev_flow
11499 * Pointer to the dev_flow.
11500 * @param[out] error
11501 * pointer to error structure.
11504 * 0 on success otherwise -errno and errno is set.
11507 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
11508 struct mlx5_flow_dv_dest_array_resource *ref,
11509 struct mlx5_flow *dev_flow,
11510 struct rte_flow_error *error)
11512 struct mlx5_flow_dv_dest_array_resource *resource;
11513 struct mlx5_priv *priv = dev->data->dev_private;
11514 struct mlx5_list_entry *entry;
11515 struct mlx5_flow_cb_ctx ctx = {
11521 entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
11524 resource = container_of(entry, typeof(*resource), entry);
11525 dev_flow->handle->dvh.rix_dest_array = resource->idx;
11526 dev_flow->dv.dest_array_res = resource;
11531 * Convert Sample action to DV specification.
11534 * Pointer to rte_eth_dev structure.
11535 * @param[in] action
11536 * Pointer to sample action structure.
11537 * @param[in, out] dev_flow
11538 * Pointer to the mlx5_flow.
11540 * Pointer to the flow attributes.
11541 * @param[in, out] num_of_dest
11542 * Pointer to the num of destination.
11543 * @param[in, out] sample_actions
11544 * Pointer to sample actions list.
11545 * @param[in, out] res
11546 * Pointer to sample resource.
11547 * @param[out] error
11548 * Pointer to the error structure.
11551 * 0 on success, a negative errno value otherwise and rte_errno is set.
11554 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
11555 const struct rte_flow_action_sample *action,
11556 struct mlx5_flow *dev_flow,
11557 const struct rte_flow_attr *attr,
11558 uint32_t *num_of_dest,
11559 void **sample_actions,
11560 struct mlx5_flow_dv_sample_resource *res,
11561 struct rte_flow_error *error)
11563 struct mlx5_priv *priv = dev->data->dev_private;
11564 const struct rte_flow_action *sub_actions;
11565 struct mlx5_flow_sub_actions_list *sample_act;
11566 struct mlx5_flow_sub_actions_idx *sample_idx;
11567 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11568 struct rte_flow *flow = dev_flow->flow;
11569 struct mlx5_flow_rss_desc *rss_desc;
11570 uint64_t action_flags = 0;
11573 rss_desc = &wks->rss_desc;
11574 sample_act = &res->sample_act;
11575 sample_idx = &res->sample_idx;
11576 res->ratio = action->ratio;
11577 sub_actions = action->actions;
11578 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
11579 int type = sub_actions->type;
11580 uint32_t pre_rix = 0;
11583 case RTE_FLOW_ACTION_TYPE_QUEUE:
11585 const struct rte_flow_action_queue *queue;
11586 struct mlx5_hrxq *hrxq;
11589 queue = sub_actions->conf;
11590 rss_desc->queue_num = 1;
11591 rss_desc->queue[0] = queue->index;
11592 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11593 rss_desc, &hrxq_idx);
11595 return rte_flow_error_set
11597 RTE_FLOW_ERROR_TYPE_ACTION,
11599 "cannot create fate queue");
11600 sample_act->dr_queue_action = hrxq->action;
11601 sample_idx->rix_hrxq = hrxq_idx;
11602 sample_actions[sample_act->actions_num++] =
11605 action_flags |= MLX5_FLOW_ACTION_QUEUE;
11606 if (action_flags & MLX5_FLOW_ACTION_MARK)
11607 dev_flow->handle->rix_hrxq = hrxq_idx;
11608 dev_flow->handle->fate_action =
11609 MLX5_FLOW_FATE_QUEUE;
11612 case RTE_FLOW_ACTION_TYPE_RSS:
11614 struct mlx5_hrxq *hrxq;
11616 const struct rte_flow_action_rss *rss;
11617 const uint8_t *rss_key;
11619 rss = sub_actions->conf;
11620 memcpy(rss_desc->queue, rss->queue,
11621 rss->queue_num * sizeof(uint16_t));
11622 rss_desc->queue_num = rss->queue_num;
11623 /* NULL RSS key indicates default RSS key. */
11624 rss_key = !rss->key ? rss_hash_default_key : rss->key;
11625 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
11627 * rss->level and rss.types should be set in advance
11628 * when expanding items for RSS.
11630 flow_dv_hashfields_set(dev_flow, rss_desc);
11631 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11632 rss_desc, &hrxq_idx);
11634 return rte_flow_error_set
11636 RTE_FLOW_ERROR_TYPE_ACTION,
11638 "cannot create fate queue");
11639 sample_act->dr_queue_action = hrxq->action;
11640 sample_idx->rix_hrxq = hrxq_idx;
11641 sample_actions[sample_act->actions_num++] =
11644 action_flags |= MLX5_FLOW_ACTION_RSS;
11645 if (action_flags & MLX5_FLOW_ACTION_MARK)
11646 dev_flow->handle->rix_hrxq = hrxq_idx;
11647 dev_flow->handle->fate_action =
11648 MLX5_FLOW_FATE_QUEUE;
11651 case RTE_FLOW_ACTION_TYPE_MARK:
11653 uint32_t tag_be = mlx5_flow_mark_set
11654 (((const struct rte_flow_action_mark *)
11655 (sub_actions->conf))->id);
11658 pre_rix = dev_flow->handle->dvh.rix_tag;
11659 /* Save the mark resource before sample */
11660 pre_r = dev_flow->dv.tag_resource;
11661 if (flow_dv_tag_resource_register(dev, tag_be,
11664 MLX5_ASSERT(dev_flow->dv.tag_resource);
11665 sample_act->dr_tag_action =
11666 dev_flow->dv.tag_resource->action;
11667 sample_idx->rix_tag =
11668 dev_flow->handle->dvh.rix_tag;
11669 sample_actions[sample_act->actions_num++] =
11670 sample_act->dr_tag_action;
11671 /* Recover the mark resource after sample */
11672 dev_flow->dv.tag_resource = pre_r;
11673 dev_flow->handle->dvh.rix_tag = pre_rix;
11674 action_flags |= MLX5_FLOW_ACTION_MARK;
11677 case RTE_FLOW_ACTION_TYPE_COUNT:
11679 if (!flow->counter) {
11681 flow_dv_translate_create_counter(dev,
11682 dev_flow, sub_actions->conf,
11684 if (!flow->counter)
11685 return rte_flow_error_set
11687 RTE_FLOW_ERROR_TYPE_ACTION,
11689 "cannot create counter"
11692 sample_act->dr_cnt_action =
11693 (flow_dv_counter_get_by_idx(dev,
11694 flow->counter, NULL))->action;
11695 sample_actions[sample_act->actions_num++] =
11696 sample_act->dr_cnt_action;
11697 action_flags |= MLX5_FLOW_ACTION_COUNT;
11700 case RTE_FLOW_ACTION_TYPE_PORT_ID:
11701 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
11703 struct mlx5_flow_dv_port_id_action_resource
11705 uint32_t port_id = 0;
11707 memset(&port_id_resource, 0, sizeof(port_id_resource));
11708 /* Save the port id resource before sample */
11709 pre_rix = dev_flow->handle->rix_port_id_action;
11710 pre_r = dev_flow->dv.port_id_action;
11711 if (flow_dv_translate_action_port_id(dev, sub_actions,
11714 port_id_resource.port_id = port_id;
11715 if (flow_dv_port_id_action_resource_register
11716 (dev, &port_id_resource, dev_flow, error))
11718 sample_act->dr_port_id_action =
11719 dev_flow->dv.port_id_action->action;
11720 sample_idx->rix_port_id_action =
11721 dev_flow->handle->rix_port_id_action;
11722 sample_actions[sample_act->actions_num++] =
11723 sample_act->dr_port_id_action;
11724 /* Recover the port id resource after sample */
11725 dev_flow->dv.port_id_action = pre_r;
11726 dev_flow->handle->rix_port_id_action = pre_rix;
11728 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11731 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11732 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11733 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11734 /* Save the encap resource before sample */
11735 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
11736 pre_r = dev_flow->dv.encap_decap;
11737 if (flow_dv_create_action_l2_encap(dev, sub_actions,
11742 sample_act->dr_encap_action =
11743 dev_flow->dv.encap_decap->action;
11744 sample_idx->rix_encap_decap =
11745 dev_flow->handle->dvh.rix_encap_decap;
11746 sample_actions[sample_act->actions_num++] =
11747 sample_act->dr_encap_action;
11748 /* Recover the encap resource after sample */
11749 dev_flow->dv.encap_decap = pre_r;
11750 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
11751 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11754 return rte_flow_error_set(error, EINVAL,
11755 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11757 "Not support for sampler action");
11760 sample_act->action_flags = action_flags;
11761 res->ft_id = dev_flow->dv.group;
11762 if (attr->transfer) {
11764 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
11765 uint64_t set_action;
11766 } action_ctx = { .set_action = 0 };
11768 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
11769 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
11770 MLX5_MODIFICATION_TYPE_SET);
11771 MLX5_SET(set_action_in, action_ctx.action_in, field,
11772 MLX5_MODI_META_REG_C_0);
11773 MLX5_SET(set_action_in, action_ctx.action_in, data,
11774 priv->vport_meta_tag);
11775 res->set_action = action_ctx.set_action;
11776 } else if (attr->ingress) {
11777 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
11779 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
11785 * Convert Sample action to DV specification.
11788 * Pointer to rte_eth_dev structure.
11789 * @param[in, out] dev_flow
11790 * Pointer to the mlx5_flow.
11791 * @param[in] num_of_dest
11792 * The num of destination.
11793 * @param[in, out] res
11794 * Pointer to sample resource.
11795 * @param[in, out] mdest_res
11796 * Pointer to destination array resource.
11797 * @param[in] sample_actions
11798 * Pointer to sample path actions list.
11799 * @param[in] action_flags
11800 * Holds the actions detected until now.
11801 * @param[out] error
11802 * Pointer to the error structure.
11805 * 0 on success, a negative errno value otherwise and rte_errno is set.
11808 flow_dv_create_action_sample(struct rte_eth_dev *dev,
11809 struct mlx5_flow *dev_flow,
11810 uint32_t num_of_dest,
11811 struct mlx5_flow_dv_sample_resource *res,
11812 struct mlx5_flow_dv_dest_array_resource *mdest_res,
11813 void **sample_actions,
11814 uint64_t action_flags,
11815 struct rte_flow_error *error)
11817 /* update normal path action resource into last index of array */
11818 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
11819 struct mlx5_flow_sub_actions_list *sample_act =
11820 &mdest_res->sample_act[dest_index];
11821 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11822 struct mlx5_flow_rss_desc *rss_desc;
11823 uint32_t normal_idx = 0;
11824 struct mlx5_hrxq *hrxq;
11828 rss_desc = &wks->rss_desc;
11829 if (num_of_dest > 1) {
11830 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
11831 /* Handle QP action for mirroring */
11832 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11833 rss_desc, &hrxq_idx);
11835 return rte_flow_error_set
11837 RTE_FLOW_ERROR_TYPE_ACTION,
11839 "cannot create rx queue");
11841 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
11842 sample_act->dr_queue_action = hrxq->action;
11843 if (action_flags & MLX5_FLOW_ACTION_MARK)
11844 dev_flow->handle->rix_hrxq = hrxq_idx;
11845 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
11847 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
11849 mdest_res->sample_idx[dest_index].rix_encap_decap =
11850 dev_flow->handle->dvh.rix_encap_decap;
11851 sample_act->dr_encap_action =
11852 dev_flow->dv.encap_decap->action;
11853 dev_flow->handle->dvh.rix_encap_decap = 0;
11855 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
11857 mdest_res->sample_idx[dest_index].rix_port_id_action =
11858 dev_flow->handle->rix_port_id_action;
11859 sample_act->dr_port_id_action =
11860 dev_flow->dv.port_id_action->action;
11861 dev_flow->handle->rix_port_id_action = 0;
11863 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
11865 mdest_res->sample_idx[dest_index].rix_jump =
11866 dev_flow->handle->rix_jump;
11867 sample_act->dr_jump_action =
11868 dev_flow->dv.jump->action;
11869 dev_flow->handle->rix_jump = 0;
11871 sample_act->actions_num = normal_idx;
11872 /* update sample action resource into first index of array */
11873 mdest_res->ft_type = res->ft_type;
11874 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
11875 sizeof(struct mlx5_flow_sub_actions_idx));
11876 memcpy(&mdest_res->sample_act[0], &res->sample_act,
11877 sizeof(struct mlx5_flow_sub_actions_list));
11878 mdest_res->num_of_dest = num_of_dest;
11879 if (flow_dv_dest_array_resource_register(dev, mdest_res,
11881 return rte_flow_error_set(error, EINVAL,
11882 RTE_FLOW_ERROR_TYPE_ACTION,
11883 NULL, "can't create sample "
11886 res->sub_actions = sample_actions;
11887 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
11888 return rte_flow_error_set(error, EINVAL,
11889 RTE_FLOW_ERROR_TYPE_ACTION,
11891 "can't create sample action");
11897 * Remove an ASO age action from age actions list.
11900 * Pointer to the Ethernet device structure.
11902 * Pointer to the aso age action handler.
11905 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
11906 struct mlx5_aso_age_action *age)
11908 struct mlx5_age_info *age_info;
11909 struct mlx5_age_param *age_param = &age->age_params;
11910 struct mlx5_priv *priv = dev->data->dev_private;
11911 uint16_t expected = AGE_CANDIDATE;
11913 age_info = GET_PORT_AGE_INFO(priv);
11914 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
11915 AGE_FREE, false, __ATOMIC_RELAXED,
11916 __ATOMIC_RELAXED)) {
11918 * We need the lock even it is age timeout,
11919 * since age action may still in process.
11921 rte_spinlock_lock(&age_info->aged_sl);
11922 LIST_REMOVE(age, next);
11923 rte_spinlock_unlock(&age_info->aged_sl);
11924 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
11929 * Release an ASO age action.
11932 * Pointer to the Ethernet device structure.
11933 * @param[in] age_idx
11934 * Index of ASO age action to release.
11936 * True if the release operation is during flow destroy operation.
11937 * False if the release operation is during action destroy operation.
11940 * 0 when age action was removed, otherwise the number of references.
11943 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
11945 struct mlx5_priv *priv = dev->data->dev_private;
11946 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11947 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
11948 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
11951 flow_dv_aso_age_remove_from_age(dev, age);
11952 rte_spinlock_lock(&mng->free_sl);
11953 LIST_INSERT_HEAD(&mng->free, age, next);
11954 rte_spinlock_unlock(&mng->free_sl);
11960 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
11963 * Pointer to the Ethernet device structure.
11966 * 0 on success, otherwise negative errno value and rte_errno is set.
11969 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
11971 struct mlx5_priv *priv = dev->data->dev_private;
11972 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11973 void *old_pools = mng->pools;
11974 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
11975 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
11976 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11979 rte_errno = ENOMEM;
11983 memcpy(pools, old_pools,
11984 mng->n * sizeof(struct mlx5_flow_counter_pool *));
11985 mlx5_free(old_pools);
11987 /* First ASO flow hit allocation - starting ASO data-path. */
11988 int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
11996 mng->pools = pools;
12001 * Create and initialize a new ASO aging pool.
12004 * Pointer to the Ethernet device structure.
12005 * @param[out] age_free
12006 * Where to put the pointer of a new age action.
12009 * The age actions pool pointer and @p age_free is set on success,
12010 * NULL otherwise and rte_errno is set.
12012 static struct mlx5_aso_age_pool *
12013 flow_dv_age_pool_create(struct rte_eth_dev *dev,
12014 struct mlx5_aso_age_action **age_free)
12016 struct mlx5_priv *priv = dev->data->dev_private;
12017 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12018 struct mlx5_aso_age_pool *pool = NULL;
12019 struct mlx5_devx_obj *obj = NULL;
12022 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
12023 priv->sh->cdev->pdn);
12025 rte_errno = ENODATA;
12026 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
12029 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
12031 claim_zero(mlx5_devx_cmd_destroy(obj));
12032 rte_errno = ENOMEM;
12035 pool->flow_hit_aso_obj = obj;
12036 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
12037 rte_rwlock_write_lock(&mng->resize_rwl);
12038 pool->index = mng->next;
12039 /* Resize pools array if there is no room for the new pool in it. */
12040 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
12041 claim_zero(mlx5_devx_cmd_destroy(obj));
12043 rte_rwlock_write_unlock(&mng->resize_rwl);
12046 mng->pools[pool->index] = pool;
12048 rte_rwlock_write_unlock(&mng->resize_rwl);
12049 /* Assign the first action in the new pool, the rest go to free list. */
12050 *age_free = &pool->actions[0];
12051 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
12052 pool->actions[i].offset = i;
12053 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
12059 * Allocate a ASO aging bit.
12062 * Pointer to the Ethernet device structure.
12063 * @param[out] error
12064 * Pointer to the error structure.
12067 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
12070 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
12072 struct mlx5_priv *priv = dev->data->dev_private;
12073 const struct mlx5_aso_age_pool *pool;
12074 struct mlx5_aso_age_action *age_free = NULL;
12075 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12078 /* Try to get the next free age action bit. */
12079 rte_spinlock_lock(&mng->free_sl);
12080 age_free = LIST_FIRST(&mng->free);
12082 LIST_REMOVE(age_free, next);
12083 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
12084 rte_spinlock_unlock(&mng->free_sl);
12085 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12086 NULL, "failed to create ASO age pool");
12087 return 0; /* 0 is an error. */
12089 rte_spinlock_unlock(&mng->free_sl);
12090 pool = container_of
12091 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
12092 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
12094 if (!age_free->dr_action) {
12095 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
12099 rte_flow_error_set(error, rte_errno,
12100 RTE_FLOW_ERROR_TYPE_ACTION,
12101 NULL, "failed to get reg_c "
12102 "for ASO flow hit");
12103 return 0; /* 0 is an error. */
12105 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
12106 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
12107 (priv->sh->rx_domain,
12108 pool->flow_hit_aso_obj->obj, age_free->offset,
12109 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
12110 (reg_c - REG_C_0));
12111 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
12112 if (!age_free->dr_action) {
12114 rte_spinlock_lock(&mng->free_sl);
12115 LIST_INSERT_HEAD(&mng->free, age_free, next);
12116 rte_spinlock_unlock(&mng->free_sl);
12117 rte_flow_error_set(error, rte_errno,
12118 RTE_FLOW_ERROR_TYPE_ACTION,
12119 NULL, "failed to create ASO "
12120 "flow hit action");
12121 return 0; /* 0 is an error. */
12124 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
12125 return pool->index | ((age_free->offset + 1) << 16);
12129 * Initialize flow ASO age parameters.
12132 * Pointer to rte_eth_dev structure.
12133 * @param[in] age_idx
12134 * Index of ASO age action.
12135 * @param[in] context
12136 * Pointer to flow counter age context.
12137 * @param[in] timeout
12138 * Aging timeout in seconds.
12142 flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
12147 struct mlx5_aso_age_action *aso_age;
12149 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
12150 MLX5_ASSERT(aso_age);
12151 aso_age->age_params.context = context;
12152 aso_age->age_params.timeout = timeout;
12153 aso_age->age_params.port_id = dev->data->port_id;
12154 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
12156 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
12161 flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
12162 const struct rte_flow_item_integrity *value,
12163 void *headers_m, void *headers_v)
12166 /* RTE l4_ok filter aggregates hardware l4_ok and
12167 * l4_checksum_ok filters.
12168 * Positive RTE l4_ok match requires hardware match on both L4
12169 * hardware integrity bits.
12170 * For negative match, check hardware l4_checksum_ok bit only,
12171 * because hardware sets that bit to 0 for all packets
12174 if (value->l4_ok) {
12175 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_ok, 1);
12176 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_ok, 1);
12178 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok, 1);
12179 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
12182 if (mask->l4_csum_ok) {
12183 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok, 1);
12184 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
12185 value->l4_csum_ok);
12190 flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
12191 const struct rte_flow_item_integrity *value,
12192 void *headers_m, void *headers_v, bool is_ipv4)
12195 /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
12196 * ipv4_csum_ok filters.
12197 * Positive RTE l3_ok match requires hardware match on both L3
12198 * hardware integrity bits.
12199 * For negative match, check hardware l3_csum_ok bit only,
12200 * because hardware sets that bit to 0 for all packets
12204 if (value->l3_ok) {
12205 MLX5_SET(fte_match_set_lyr_2_4, headers_m,
12207 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12210 MLX5_SET(fte_match_set_lyr_2_4, headers_m,
12211 ipv4_checksum_ok, 1);
12212 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12213 ipv4_checksum_ok, !!value->l3_ok);
12215 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l3_ok, 1);
12216 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l3_ok,
12220 if (mask->ipv4_csum_ok) {
12221 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok, 1);
12222 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
12223 value->ipv4_csum_ok);
12228 set_integrity_bits(void *headers_m, void *headers_v,
12229 const struct rte_flow_item *integrity_item, bool is_l3_ip4)
12231 const struct rte_flow_item_integrity *spec = integrity_item->spec;
12232 const struct rte_flow_item_integrity *mask = integrity_item->mask;
12234 /* Integrity bits validation cleared spec pointer */
12235 MLX5_ASSERT(spec != NULL);
12237 mask = &rte_flow_item_integrity_mask;
12238 flow_dv_translate_integrity_l3(mask, spec, headers_m, headers_v,
12240 flow_dv_translate_integrity_l4(mask, spec, headers_m, headers_v);
12244 flow_dv_translate_item_integrity_post(void *matcher, void *key,
12246 struct rte_flow_item *integrity_items[2],
12247 uint64_t pattern_flags)
12249 void *headers_m, *headers_v;
12252 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
12253 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12255 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
12256 is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
12258 set_integrity_bits(headers_m, headers_v,
12259 integrity_items[1], is_l3_ip4);
12261 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
12262 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12264 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
12265 is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
12267 set_integrity_bits(headers_m, headers_v,
12268 integrity_items[0], is_l3_ip4);
12273 flow_dv_translate_item_integrity(const struct rte_flow_item *item,
12274 const struct rte_flow_item *integrity_items[2],
12275 uint64_t *last_item)
12277 const struct rte_flow_item_integrity *spec = (typeof(spec))item->spec;
12279 /* integrity bits validation cleared spec pointer */
12280 MLX5_ASSERT(spec != NULL);
12281 if (spec->level > 1) {
12282 integrity_items[1] = item;
12283 *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
12285 integrity_items[0] = item;
12286 *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
12291 * Prepares DV flow counter with aging configuration.
12292 * Gets it by index when exists, creates a new one when doesn't.
12295 * Pointer to rte_eth_dev structure.
12296 * @param[in] dev_flow
12297 * Pointer to the mlx5_flow.
12298 * @param[in, out] flow
12299 * Pointer to the sub flow.
12301 * Pointer to the counter action configuration.
12303 * Pointer to the aging action configuration.
12304 * @param[out] error
12305 * Pointer to the error structure.
12308 * Pointer to the counter, NULL otherwise.
12310 static struct mlx5_flow_counter *
12311 flow_dv_prepare_counter(struct rte_eth_dev *dev,
12312 struct mlx5_flow *dev_flow,
12313 struct rte_flow *flow,
12314 const struct rte_flow_action_count *count,
12315 const struct rte_flow_action_age *age,
12316 struct rte_flow_error *error)
12318 if (!flow->counter) {
12319 flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
12321 if (!flow->counter) {
12322 rte_flow_error_set(error, rte_errno,
12323 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12324 "cannot create counter object.");
12328 return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
12332 * Release an ASO CT action by its own device.
12335 * Pointer to the Ethernet device structure.
12337 * Index of ASO CT action to release.
12340 * 0 when CT action was removed, otherwise the number of references.
12343 flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
12345 struct mlx5_priv *priv = dev->data->dev_private;
12346 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12348 struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12349 enum mlx5_aso_ct_state state =
12350 __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
12352 /* Cannot release when CT is in the ASO SQ. */
12353 if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
12355 ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
12357 if (ct->dr_action_orig) {
12358 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12359 claim_zero(mlx5_glue->destroy_flow_action
12360 (ct->dr_action_orig));
12362 ct->dr_action_orig = NULL;
12364 if (ct->dr_action_rply) {
12365 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12366 claim_zero(mlx5_glue->destroy_flow_action
12367 (ct->dr_action_rply));
12369 ct->dr_action_rply = NULL;
12371 /* Clear the state to free, no need in 1st allocation. */
12372 MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
12373 rte_spinlock_lock(&mng->ct_sl);
12374 LIST_INSERT_HEAD(&mng->free_cts, ct, next);
12375 rte_spinlock_unlock(&mng->ct_sl);
12381 flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
12382 struct rte_flow_error *error)
12384 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
12385 uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
12386 struct rte_eth_dev *owndev = &rte_eth_devices[owner];
12389 MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
12390 if (dev->data->dev_started != 1)
12391 return rte_flow_error_set(error, EAGAIN,
12392 RTE_FLOW_ERROR_TYPE_ACTION,
12394 "Indirect CT action cannot be destroyed when the port is stopped");
12395 ret = flow_dv_aso_ct_dev_release(owndev, idx);
12397 return rte_flow_error_set(error, EAGAIN,
12398 RTE_FLOW_ERROR_TYPE_ACTION,
12400 "Current state prevents indirect CT action from being destroyed");
12405 * Resize the ASO CT pools array by 64 pools.
12408 * Pointer to the Ethernet device structure.
12411 * 0 on success, otherwise negative errno value and rte_errno is set.
12414 flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
12416 struct mlx5_priv *priv = dev->data->dev_private;
12417 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12418 void *old_pools = mng->pools;
12419 /* Magic number now, need a macro. */
12420 uint32_t resize = mng->n + 64;
12421 uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
12422 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
12425 rte_errno = ENOMEM;
12428 rte_rwlock_write_lock(&mng->resize_rwl);
12429 /* ASO SQ/QP was already initialized in the startup. */
12431 /* Realloc could be an alternative choice. */
12432 rte_memcpy(pools, old_pools,
12433 mng->n * sizeof(struct mlx5_aso_ct_pool *));
12434 mlx5_free(old_pools);
12437 mng->pools = pools;
12438 rte_rwlock_write_unlock(&mng->resize_rwl);
12443 * Create and initialize a new ASO CT pool.
12446 * Pointer to the Ethernet device structure.
12447 * @param[out] ct_free
12448 * Where to put the pointer of a new CT action.
12451 * The CT actions pool pointer and @p ct_free is set on success,
12452 * NULL otherwise and rte_errno is set.
12454 static struct mlx5_aso_ct_pool *
12455 flow_dv_ct_pool_create(struct rte_eth_dev *dev,
12456 struct mlx5_aso_ct_action **ct_free)
12458 struct mlx5_priv *priv = dev->data->dev_private;
12459 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12460 struct mlx5_aso_ct_pool *pool = NULL;
12461 struct mlx5_devx_obj *obj = NULL;
12463 uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
12465 obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
12466 priv->sh->cdev->pdn,
12469 rte_errno = ENODATA;
12470 DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
12473 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
12475 rte_errno = ENOMEM;
12476 claim_zero(mlx5_devx_cmd_destroy(obj));
12479 pool->devx_obj = obj;
12480 pool->index = mng->next;
12481 /* Resize pools array if there is no room for the new pool in it. */
12482 if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
12483 claim_zero(mlx5_devx_cmd_destroy(obj));
12487 mng->pools[pool->index] = pool;
12489 /* Assign the first action in the new pool, the rest go to free list. */
12490 *ct_free = &pool->actions[0];
12491 /* Lock outside, the list operation is safe here. */
12492 for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
12493 /* refcnt is 0 when allocating the memory. */
12494 pool->actions[i].offset = i;
12495 LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
12501 * Allocate a ASO CT action from free list.
12504 * Pointer to the Ethernet device structure.
12505 * @param[out] error
12506 * Pointer to the error structure.
12509 * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
12512 flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
12514 struct mlx5_priv *priv = dev->data->dev_private;
12515 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12516 struct mlx5_aso_ct_action *ct = NULL;
12517 struct mlx5_aso_ct_pool *pool;
12522 if (!priv->sh->cdev->config.devx) {
12523 rte_errno = ENOTSUP;
12526 /* Get a free CT action, if no, a new pool will be created. */
12527 rte_spinlock_lock(&mng->ct_sl);
12528 ct = LIST_FIRST(&mng->free_cts);
12530 LIST_REMOVE(ct, next);
12531 } else if (!flow_dv_ct_pool_create(dev, &ct)) {
12532 rte_spinlock_unlock(&mng->ct_sl);
12533 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12534 NULL, "failed to create ASO CT pool");
12537 rte_spinlock_unlock(&mng->ct_sl);
12538 pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
12539 ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
12540 /* 0: inactive, 1: created, 2+: used by flows. */
12541 __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
12542 reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
12543 if (!ct->dr_action_orig) {
12544 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12545 ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
12546 (priv->sh->rx_domain, pool->devx_obj->obj,
12548 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
12551 RTE_SET_USED(reg_c);
12553 if (!ct->dr_action_orig) {
12554 flow_dv_aso_ct_dev_release(dev, ct_idx);
12555 rte_flow_error_set(error, rte_errno,
12556 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12557 "failed to create ASO CT action");
12561 if (!ct->dr_action_rply) {
12562 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12563 ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
12564 (priv->sh->rx_domain, pool->devx_obj->obj,
12566 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
12569 if (!ct->dr_action_rply) {
12570 flow_dv_aso_ct_dev_release(dev, ct_idx);
12571 rte_flow_error_set(error, rte_errno,
12572 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12573 "failed to create ASO CT action");
12581 * Create a conntrack object with context and actions by using ASO mechanism.
12584 * Pointer to rte_eth_dev structure.
12586 * Pointer to conntrack information profile.
12587 * @param[out] error
12588 * Pointer to the error structure.
12591 * Index to conntrack object on success, 0 otherwise.
12594 flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
12595 const struct rte_flow_action_conntrack *pro,
12596 struct rte_flow_error *error)
12598 struct mlx5_priv *priv = dev->data->dev_private;
12599 struct mlx5_dev_ctx_shared *sh = priv->sh;
12600 struct mlx5_aso_ct_action *ct;
12603 if (!sh->ct_aso_en)
12604 return rte_flow_error_set(error, ENOTSUP,
12605 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12606 "Connection is not supported");
12607 idx = flow_dv_aso_ct_alloc(dev, error);
12609 return rte_flow_error_set(error, rte_errno,
12610 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12611 "Failed to allocate CT object");
12612 ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12613 if (mlx5_aso_ct_update_by_wqe(sh, ct, pro))
12614 return rte_flow_error_set(error, EBUSY,
12615 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12616 "Failed to update CT");
12617 ct->is_original = !!pro->is_original_dir;
12618 ct->peer = pro->peer_port;
12623 * Fill the flow with DV spec, lock free
12624 * (mutex should be acquired by caller).
12627 * Pointer to rte_eth_dev structure.
12628 * @param[in, out] dev_flow
12629 * Pointer to the sub flow.
12631 * Pointer to the flow attributes.
12633 * Pointer to the list of items.
12634 * @param[in] actions
12635 * Pointer to the list of actions.
12636 * @param[out] error
12637 * Pointer to the error structure.
12640 * 0 on success, a negative errno value otherwise and rte_errno is set.
12643 flow_dv_translate(struct rte_eth_dev *dev,
12644 struct mlx5_flow *dev_flow,
12645 const struct rte_flow_attr *attr,
12646 const struct rte_flow_item items[],
12647 const struct rte_flow_action actions[],
12648 struct rte_flow_error *error)
12650 struct mlx5_priv *priv = dev->data->dev_private;
12651 struct mlx5_sh_config *dev_conf = &priv->sh->config;
12652 struct rte_flow *flow = dev_flow->flow;
12653 struct mlx5_flow_handle *handle = dev_flow->handle;
12654 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12655 struct mlx5_flow_rss_desc *rss_desc;
12656 uint64_t item_flags = 0;
12657 uint64_t last_item = 0;
12658 uint64_t action_flags = 0;
12659 struct mlx5_flow_dv_matcher matcher = {
12661 .size = sizeof(matcher.mask.buf),
12665 bool actions_end = false;
12667 struct mlx5_flow_dv_modify_hdr_resource res;
12668 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
12669 sizeof(struct mlx5_modification_cmd) *
12670 (MLX5_MAX_MODIFY_NUM + 1)];
12672 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
12673 const struct rte_flow_action_count *count = NULL;
12674 const struct rte_flow_action_age *non_shared_age = NULL;
12675 union flow_dv_attr flow_attr = { .attr = 0 };
12677 union mlx5_flow_tbl_key tbl_key;
12678 uint32_t modify_action_position = UINT32_MAX;
12679 void *match_mask = matcher.mask.buf;
12680 void *match_value = dev_flow->dv.value.buf;
12681 uint8_t next_protocol = 0xff;
12682 struct rte_vlan_hdr vlan = { 0 };
12683 struct mlx5_flow_dv_dest_array_resource mdest_res;
12684 struct mlx5_flow_dv_sample_resource sample_res;
12685 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12686 const struct rte_flow_action_sample *sample = NULL;
12687 struct mlx5_flow_sub_actions_list *sample_act;
12688 uint32_t sample_act_pos = UINT32_MAX;
12689 uint32_t age_act_pos = UINT32_MAX;
12690 uint32_t num_of_dest = 0;
12691 int tmp_actions_n = 0;
12694 const struct mlx5_flow_tunnel *tunnel = NULL;
12695 struct flow_grp_info grp_info = {
12696 .external = !!dev_flow->external,
12697 .transfer = !!attr->transfer,
12698 .fdb_def_rule = !!priv->fdb_def_rule,
12699 .skip_scale = dev_flow->skip_scale &
12700 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
12701 .std_tbl_fix = true,
12703 const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
12704 const struct rte_flow_item *tunnel_item = NULL;
12707 return rte_flow_error_set(error, ENOMEM,
12708 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12710 "failed to push flow workspace");
12711 rss_desc = &wks->rss_desc;
12712 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
12713 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
12714 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12715 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12716 /* update normal path action resource into last index of array */
12717 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
12718 if (is_tunnel_offload_active(dev)) {
12719 if (dev_flow->tunnel) {
12720 RTE_VERIFY(dev_flow->tof_type ==
12721 MLX5_TUNNEL_OFFLOAD_MISS_RULE);
12722 tunnel = dev_flow->tunnel;
12724 tunnel = mlx5_get_tof(items, actions,
12725 &dev_flow->tof_type);
12726 dev_flow->tunnel = tunnel;
12728 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
12729 (dev, attr, tunnel, dev_flow->tof_type);
12731 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12732 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12733 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
12737 dev_flow->dv.group = table;
12738 if (attr->transfer)
12739 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12740 /* number of actions must be set to 0 in case of dirty stack. */
12741 mhdr_res->actions_num = 0;
12742 if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
12744 * do not add decap action if match rule drops packet
12745 * HW rejects rules with decap & drop
12747 * if tunnel match rule was inserted before matching tunnel set
12748 * rule flow table used in the match rule must be registered.
12749 * current implementation handles that in the
12750 * flow_dv_match_register() at the function end.
12752 bool add_decap = true;
12753 const struct rte_flow_action *ptr = actions;
12755 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
12756 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
12762 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12766 dev_flow->dv.actions[actions_n++] =
12767 dev_flow->dv.encap_decap->action;
12768 action_flags |= MLX5_FLOW_ACTION_DECAP;
12771 for (; !actions_end ; actions++) {
12772 const struct rte_flow_action_queue *queue;
12773 const struct rte_flow_action_rss *rss;
12774 const struct rte_flow_action *action = actions;
12775 const uint8_t *rss_key;
12776 struct mlx5_flow_tbl_resource *tbl;
12777 struct mlx5_aso_age_action *age_act;
12778 struct mlx5_flow_counter *cnt_act;
12779 uint32_t port_id = 0;
12780 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
12781 int action_type = actions->type;
12782 const struct rte_flow_action *found_action = NULL;
12783 uint32_t jump_group = 0;
12784 uint32_t owner_idx;
12785 struct mlx5_aso_ct_action *ct;
12787 if (!mlx5_flow_os_action_supported(action_type))
12788 return rte_flow_error_set(error, ENOTSUP,
12789 RTE_FLOW_ERROR_TYPE_ACTION,
12791 "action not supported");
12792 switch (action_type) {
12793 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
12794 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
12796 case RTE_FLOW_ACTION_TYPE_VOID:
12798 case RTE_FLOW_ACTION_TYPE_PORT_ID:
12799 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
12800 if (flow_dv_translate_action_port_id(dev, action,
12803 port_id_resource.port_id = port_id;
12804 MLX5_ASSERT(!handle->rix_port_id_action);
12805 if (flow_dv_port_id_action_resource_register
12806 (dev, &port_id_resource, dev_flow, error))
12808 dev_flow->dv.actions[actions_n++] =
12809 dev_flow->dv.port_id_action->action;
12810 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12811 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
12812 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12815 case RTE_FLOW_ACTION_TYPE_FLAG:
12816 action_flags |= MLX5_FLOW_ACTION_FLAG;
12818 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12819 struct rte_flow_action_mark mark = {
12820 .id = MLX5_FLOW_MARK_DEFAULT,
12823 if (flow_dv_convert_action_mark(dev, &mark,
12827 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12830 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
12832 * Only one FLAG or MARK is supported per device flow
12833 * right now. So the pointer to the tag resource must be
12834 * zero before the register process.
12836 MLX5_ASSERT(!handle->dvh.rix_tag);
12837 if (flow_dv_tag_resource_register(dev, tag_be,
12840 MLX5_ASSERT(dev_flow->dv.tag_resource);
12841 dev_flow->dv.actions[actions_n++] =
12842 dev_flow->dv.tag_resource->action;
12844 case RTE_FLOW_ACTION_TYPE_MARK:
12845 action_flags |= MLX5_FLOW_ACTION_MARK;
12847 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12848 const struct rte_flow_action_mark *mark =
12849 (const struct rte_flow_action_mark *)
12852 if (flow_dv_convert_action_mark(dev, mark,
12856 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12860 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
12861 /* Legacy (non-extensive) MARK action. */
12862 tag_be = mlx5_flow_mark_set
12863 (((const struct rte_flow_action_mark *)
12864 (actions->conf))->id);
12865 MLX5_ASSERT(!handle->dvh.rix_tag);
12866 if (flow_dv_tag_resource_register(dev, tag_be,
12869 MLX5_ASSERT(dev_flow->dv.tag_resource);
12870 dev_flow->dv.actions[actions_n++] =
12871 dev_flow->dv.tag_resource->action;
12873 case RTE_FLOW_ACTION_TYPE_SET_META:
12874 if (flow_dv_convert_action_set_meta
12875 (dev, mhdr_res, attr,
12876 (const struct rte_flow_action_set_meta *)
12877 actions->conf, error))
12879 action_flags |= MLX5_FLOW_ACTION_SET_META;
12881 case RTE_FLOW_ACTION_TYPE_SET_TAG:
12882 if (flow_dv_convert_action_set_tag
12884 (const struct rte_flow_action_set_tag *)
12885 actions->conf, error))
12887 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12889 case RTE_FLOW_ACTION_TYPE_DROP:
12890 action_flags |= MLX5_FLOW_ACTION_DROP;
12891 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
12893 case RTE_FLOW_ACTION_TYPE_QUEUE:
12894 queue = actions->conf;
12895 rss_desc->queue_num = 1;
12896 rss_desc->queue[0] = queue->index;
12897 action_flags |= MLX5_FLOW_ACTION_QUEUE;
12898 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
12899 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
12902 case RTE_FLOW_ACTION_TYPE_RSS:
12903 rss = actions->conf;
12904 memcpy(rss_desc->queue, rss->queue,
12905 rss->queue_num * sizeof(uint16_t));
12906 rss_desc->queue_num = rss->queue_num;
12907 /* NULL RSS key indicates default RSS key. */
12908 rss_key = !rss->key ? rss_hash_default_key : rss->key;
12909 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12911 * rss->level and rss.types should be set in advance
12912 * when expanding items for RSS.
12914 action_flags |= MLX5_FLOW_ACTION_RSS;
12915 dev_flow->handle->fate_action = rss_desc->shared_rss ?
12916 MLX5_FLOW_FATE_SHARED_RSS :
12917 MLX5_FLOW_FATE_QUEUE;
12919 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
12920 owner_idx = (uint32_t)(uintptr_t)action->conf;
12921 age_act = flow_aso_age_get_by_idx(dev, owner_idx);
12922 if (flow->age == 0) {
12923 flow->age = owner_idx;
12924 __atomic_fetch_add(&age_act->refcnt, 1,
12927 age_act_pos = actions_n++;
12928 action_flags |= MLX5_FLOW_ACTION_AGE;
12930 case RTE_FLOW_ACTION_TYPE_AGE:
12931 non_shared_age = action->conf;
12932 age_act_pos = actions_n++;
12933 action_flags |= MLX5_FLOW_ACTION_AGE;
12935 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
12936 owner_idx = (uint32_t)(uintptr_t)action->conf;
12937 cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
12939 MLX5_ASSERT(cnt_act != NULL);
12941 * When creating meter drop flow in drop table, the
12942 * counter should not overwrite the rte flow counter.
12944 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
12945 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
12946 dev_flow->dv.actions[actions_n++] =
12949 if (flow->counter == 0) {
12950 flow->counter = owner_idx;
12952 (&cnt_act->shared_info.refcnt,
12953 1, __ATOMIC_RELAXED);
12955 /* Save information first, will apply later. */
12956 action_flags |= MLX5_FLOW_ACTION_COUNT;
12959 case RTE_FLOW_ACTION_TYPE_COUNT:
12960 if (!priv->sh->cdev->config.devx) {
12961 return rte_flow_error_set
12963 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12965 "count action not supported");
12967 /* Save information first, will apply later. */
12968 count = action->conf;
12969 action_flags |= MLX5_FLOW_ACTION_COUNT;
12971 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
12972 dev_flow->dv.actions[actions_n++] =
12973 priv->sh->pop_vlan_action;
12974 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
12976 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
12977 if (!(action_flags &
12978 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
12979 flow_dev_get_vlan_info_from_items(items, &vlan);
12980 vlan.eth_proto = rte_be_to_cpu_16
12981 ((((const struct rte_flow_action_of_push_vlan *)
12982 actions->conf)->ethertype));
12983 found_action = mlx5_flow_find_action
12985 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
12987 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12988 found_action = mlx5_flow_find_action
12990 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
12992 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12993 if (flow_dv_create_action_push_vlan
12994 (dev, attr, &vlan, dev_flow, error))
12996 dev_flow->dv.actions[actions_n++] =
12997 dev_flow->dv.push_vlan_res->action;
12998 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
13000 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
13001 /* of_vlan_push action handled this action */
13002 MLX5_ASSERT(action_flags &
13003 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
13005 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
13006 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
13008 flow_dev_get_vlan_info_from_items(items, &vlan);
13009 mlx5_update_vlan_vid_pcp(actions, &vlan);
13010 /* If no VLAN push - this is a modify header action */
13011 if (flow_dv_convert_action_modify_vlan_vid
13012 (mhdr_res, actions, error))
13014 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
13016 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13017 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13018 if (flow_dv_create_action_l2_encap(dev, actions,
13023 dev_flow->dv.actions[actions_n++] =
13024 dev_flow->dv.encap_decap->action;
13025 action_flags |= MLX5_FLOW_ACTION_ENCAP;
13026 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
13027 sample_act->action_flags |=
13028 MLX5_FLOW_ACTION_ENCAP;
13030 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
13031 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
13032 if (flow_dv_create_action_l2_decap(dev, dev_flow,
13036 dev_flow->dv.actions[actions_n++] =
13037 dev_flow->dv.encap_decap->action;
13038 action_flags |= MLX5_FLOW_ACTION_DECAP;
13040 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13041 /* Handle encap with preceding decap. */
13042 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
13043 if (flow_dv_create_action_raw_encap
13044 (dev, actions, dev_flow, attr, error))
13046 dev_flow->dv.actions[actions_n++] =
13047 dev_flow->dv.encap_decap->action;
13049 /* Handle encap without preceding decap. */
13050 if (flow_dv_create_action_l2_encap
13051 (dev, actions, dev_flow, attr->transfer,
13054 dev_flow->dv.actions[actions_n++] =
13055 dev_flow->dv.encap_decap->action;
13057 action_flags |= MLX5_FLOW_ACTION_ENCAP;
13058 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
13059 sample_act->action_flags |=
13060 MLX5_FLOW_ACTION_ENCAP;
13062 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
13063 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
13065 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
13066 if (flow_dv_create_action_l2_decap
13067 (dev, dev_flow, attr->transfer, error))
13069 dev_flow->dv.actions[actions_n++] =
13070 dev_flow->dv.encap_decap->action;
13072 /* If decap is followed by encap, handle it at encap. */
13073 action_flags |= MLX5_FLOW_ACTION_DECAP;
13075 case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
13076 dev_flow->dv.actions[actions_n++] =
13077 (void *)(uintptr_t)action->conf;
13078 action_flags |= MLX5_FLOW_ACTION_JUMP;
13080 case RTE_FLOW_ACTION_TYPE_JUMP:
13081 jump_group = ((const struct rte_flow_action_jump *)
13082 action->conf)->group;
13083 grp_info.std_tbl_fix = 0;
13084 if (dev_flow->skip_scale &
13085 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
13086 grp_info.skip_scale = 1;
13088 grp_info.skip_scale = 0;
13089 ret = mlx5_flow_group_to_table(dev, tunnel,
13095 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
13097 !!dev_flow->external,
13098 tunnel, jump_group, 0,
13101 return rte_flow_error_set
13103 RTE_FLOW_ERROR_TYPE_ACTION,
13105 "cannot create jump action.");
13106 if (flow_dv_jump_tbl_resource_register
13107 (dev, tbl, dev_flow, error)) {
13108 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
13109 return rte_flow_error_set
13111 RTE_FLOW_ERROR_TYPE_ACTION,
13113 "cannot create jump action.");
13115 dev_flow->dv.actions[actions_n++] =
13116 dev_flow->dv.jump->action;
13117 action_flags |= MLX5_FLOW_ACTION_JUMP;
13118 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
13119 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
13122 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
13123 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
13124 if (flow_dv_convert_action_modify_mac
13125 (mhdr_res, actions, error))
13127 action_flags |= actions->type ==
13128 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
13129 MLX5_FLOW_ACTION_SET_MAC_SRC :
13130 MLX5_FLOW_ACTION_SET_MAC_DST;
13132 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
13133 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
13134 if (flow_dv_convert_action_modify_ipv4
13135 (mhdr_res, actions, error))
13137 action_flags |= actions->type ==
13138 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
13139 MLX5_FLOW_ACTION_SET_IPV4_SRC :
13140 MLX5_FLOW_ACTION_SET_IPV4_DST;
13142 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
13143 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
13144 if (flow_dv_convert_action_modify_ipv6
13145 (mhdr_res, actions, error))
13147 action_flags |= actions->type ==
13148 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
13149 MLX5_FLOW_ACTION_SET_IPV6_SRC :
13150 MLX5_FLOW_ACTION_SET_IPV6_DST;
13152 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
13153 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
13154 if (flow_dv_convert_action_modify_tp
13155 (mhdr_res, actions, items,
13156 &flow_attr, dev_flow, !!(action_flags &
13157 MLX5_FLOW_ACTION_DECAP), error))
13159 action_flags |= actions->type ==
13160 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
13161 MLX5_FLOW_ACTION_SET_TP_SRC :
13162 MLX5_FLOW_ACTION_SET_TP_DST;
13164 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
13165 if (flow_dv_convert_action_modify_dec_ttl
13166 (mhdr_res, items, &flow_attr, dev_flow,
13168 MLX5_FLOW_ACTION_DECAP), error))
13170 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
13172 case RTE_FLOW_ACTION_TYPE_SET_TTL:
13173 if (flow_dv_convert_action_modify_ttl
13174 (mhdr_res, actions, items, &flow_attr,
13175 dev_flow, !!(action_flags &
13176 MLX5_FLOW_ACTION_DECAP), error))
13178 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
13180 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
13181 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
13182 if (flow_dv_convert_action_modify_tcp_seq
13183 (mhdr_res, actions, error))
13185 action_flags |= actions->type ==
13186 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
13187 MLX5_FLOW_ACTION_INC_TCP_SEQ :
13188 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
13191 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
13192 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
13193 if (flow_dv_convert_action_modify_tcp_ack
13194 (mhdr_res, actions, error))
13196 action_flags |= actions->type ==
13197 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
13198 MLX5_FLOW_ACTION_INC_TCP_ACK :
13199 MLX5_FLOW_ACTION_DEC_TCP_ACK;
13201 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
13202 if (flow_dv_convert_action_set_reg
13203 (mhdr_res, actions, error))
13205 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13207 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
13208 if (flow_dv_convert_action_copy_mreg
13209 (dev, mhdr_res, actions, error))
13211 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13213 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
13214 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
13215 dev_flow->handle->fate_action =
13216 MLX5_FLOW_FATE_DEFAULT_MISS;
13218 case RTE_FLOW_ACTION_TYPE_METER:
13220 return rte_flow_error_set(error, rte_errno,
13221 RTE_FLOW_ERROR_TYPE_ACTION,
13222 NULL, "Failed to get meter in flow.");
13223 /* Set the meter action. */
13224 dev_flow->dv.actions[actions_n++] =
13225 wks->fm->meter_action;
13226 action_flags |= MLX5_FLOW_ACTION_METER;
13228 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
13229 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
13232 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
13234 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
13235 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
13238 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
13240 case RTE_FLOW_ACTION_TYPE_SAMPLE:
13241 sample_act_pos = actions_n;
13242 sample = (const struct rte_flow_action_sample *)
13245 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
13246 /* put encap action into group if work with port id */
13247 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
13248 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
13249 sample_act->action_flags |=
13250 MLX5_FLOW_ACTION_ENCAP;
13252 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
13253 if (flow_dv_convert_action_modify_field
13254 (dev, mhdr_res, actions, attr, error))
13256 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
13258 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
13259 owner_idx = (uint32_t)(uintptr_t)action->conf;
13260 ct = flow_aso_ct_get_by_idx(dev, owner_idx);
13262 return rte_flow_error_set(error, EINVAL,
13263 RTE_FLOW_ERROR_TYPE_ACTION,
13265 "Failed to get CT object.");
13266 if (mlx5_aso_ct_available(priv->sh, ct))
13267 return rte_flow_error_set(error, rte_errno,
13268 RTE_FLOW_ERROR_TYPE_ACTION,
13270 "CT is unavailable.");
13271 if (ct->is_original)
13272 dev_flow->dv.actions[actions_n] =
13273 ct->dr_action_orig;
13275 dev_flow->dv.actions[actions_n] =
13276 ct->dr_action_rply;
13277 if (flow->ct == 0) {
13278 flow->indirect_type =
13279 MLX5_INDIRECT_ACTION_TYPE_CT;
13280 flow->ct = owner_idx;
13281 __atomic_fetch_add(&ct->refcnt, 1,
13285 action_flags |= MLX5_FLOW_ACTION_CT;
13287 case RTE_FLOW_ACTION_TYPE_END:
13288 actions_end = true;
13289 if (mhdr_res->actions_num) {
13290 /* create modify action if needed. */
13291 if (flow_dv_modify_hdr_resource_register
13292 (dev, mhdr_res, dev_flow, error))
13294 dev_flow->dv.actions[modify_action_position] =
13295 handle->dvh.modify_hdr->action;
13298 * Handle AGE and COUNT action by single HW counter
13299 * when they are not shared.
13301 if (action_flags & MLX5_FLOW_ACTION_AGE) {
13302 if ((non_shared_age && count) ||
13303 !(priv->sh->flow_hit_aso_en &&
13304 (attr->group || attr->transfer))) {
13305 /* Creates age by counters. */
13306 cnt_act = flow_dv_prepare_counter
13313 dev_flow->dv.actions[age_act_pos] =
13317 if (!flow->age && non_shared_age) {
13318 flow->age = flow_dv_aso_age_alloc
13322 flow_dv_aso_age_params_init
13324 non_shared_age->context ?
13325 non_shared_age->context :
13326 (void *)(uintptr_t)
13327 (dev_flow->flow_idx),
13328 non_shared_age->timeout);
13330 age_act = flow_aso_age_get_by_idx(dev,
13332 dev_flow->dv.actions[age_act_pos] =
13333 age_act->dr_action;
13335 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
13337 * Create one count action, to be used
13338 * by all sub-flows.
13340 cnt_act = flow_dv_prepare_counter(dev, dev_flow,
13345 dev_flow->dv.actions[actions_n++] =
13351 if (mhdr_res->actions_num &&
13352 modify_action_position == UINT32_MAX)
13353 modify_action_position = actions_n++;
13355 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
13356 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
13357 int item_type = items->type;
13359 if (!mlx5_flow_os_item_supported(item_type))
13360 return rte_flow_error_set(error, ENOTSUP,
13361 RTE_FLOW_ERROR_TYPE_ITEM,
13362 NULL, "item not supported");
13363 switch (item_type) {
13364 case RTE_FLOW_ITEM_TYPE_PORT_ID:
13365 flow_dv_translate_item_port_id
13366 (dev, match_mask, match_value, items, attr);
13367 last_item = MLX5_FLOW_ITEM_PORT_ID;
13369 case RTE_FLOW_ITEM_TYPE_ETH:
13370 flow_dv_translate_item_eth(match_mask, match_value,
13372 dev_flow->dv.group);
13373 matcher.priority = action_flags &
13374 MLX5_FLOW_ACTION_DEFAULT_MISS &&
13375 !dev_flow->external ?
13376 MLX5_PRIORITY_MAP_L3 :
13377 MLX5_PRIORITY_MAP_L2;
13378 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
13379 MLX5_FLOW_LAYER_OUTER_L2;
13381 case RTE_FLOW_ITEM_TYPE_VLAN:
13382 flow_dv_translate_item_vlan(dev_flow,
13383 match_mask, match_value,
13385 dev_flow->dv.group);
13386 matcher.priority = MLX5_PRIORITY_MAP_L2;
13387 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
13388 MLX5_FLOW_LAYER_INNER_VLAN) :
13389 (MLX5_FLOW_LAYER_OUTER_L2 |
13390 MLX5_FLOW_LAYER_OUTER_VLAN);
13392 case RTE_FLOW_ITEM_TYPE_IPV4:
13393 mlx5_flow_tunnel_ip_check(items, next_protocol,
13394 &item_flags, &tunnel);
13395 flow_dv_translate_item_ipv4(match_mask, match_value,
13397 dev_flow->dv.group);
13398 matcher.priority = MLX5_PRIORITY_MAP_L3;
13399 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
13400 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
13401 if (items->mask != NULL &&
13402 ((const struct rte_flow_item_ipv4 *)
13403 items->mask)->hdr.next_proto_id) {
13405 ((const struct rte_flow_item_ipv4 *)
13406 (items->spec))->hdr.next_proto_id;
13408 ((const struct rte_flow_item_ipv4 *)
13409 (items->mask))->hdr.next_proto_id;
13411 /* Reset for inner layer. */
13412 next_protocol = 0xff;
13415 case RTE_FLOW_ITEM_TYPE_IPV6:
13416 mlx5_flow_tunnel_ip_check(items, next_protocol,
13417 &item_flags, &tunnel);
13418 flow_dv_translate_item_ipv6(match_mask, match_value,
13420 dev_flow->dv.group);
13421 matcher.priority = MLX5_PRIORITY_MAP_L3;
13422 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
13423 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
13424 if (items->mask != NULL &&
13425 ((const struct rte_flow_item_ipv6 *)
13426 items->mask)->hdr.proto) {
13428 ((const struct rte_flow_item_ipv6 *)
13429 items->spec)->hdr.proto;
13431 ((const struct rte_flow_item_ipv6 *)
13432 items->mask)->hdr.proto;
13434 /* Reset for inner layer. */
13435 next_protocol = 0xff;
13438 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
13439 flow_dv_translate_item_ipv6_frag_ext(match_mask,
13442 last_item = tunnel ?
13443 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
13444 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
13445 if (items->mask != NULL &&
13446 ((const struct rte_flow_item_ipv6_frag_ext *)
13447 items->mask)->hdr.next_header) {
13449 ((const struct rte_flow_item_ipv6_frag_ext *)
13450 items->spec)->hdr.next_header;
13452 ((const struct rte_flow_item_ipv6_frag_ext *)
13453 items->mask)->hdr.next_header;
13455 /* Reset for inner layer. */
13456 next_protocol = 0xff;
13459 case RTE_FLOW_ITEM_TYPE_TCP:
13460 flow_dv_translate_item_tcp(match_mask, match_value,
13462 matcher.priority = MLX5_PRIORITY_MAP_L4;
13463 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
13464 MLX5_FLOW_LAYER_OUTER_L4_TCP;
13466 case RTE_FLOW_ITEM_TYPE_UDP:
13467 flow_dv_translate_item_udp(match_mask, match_value,
13469 matcher.priority = MLX5_PRIORITY_MAP_L4;
13470 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
13471 MLX5_FLOW_LAYER_OUTER_L4_UDP;
13473 case RTE_FLOW_ITEM_TYPE_GRE:
13474 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13475 last_item = MLX5_FLOW_LAYER_GRE;
13476 tunnel_item = items;
13478 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
13479 flow_dv_translate_item_gre_key(match_mask,
13480 match_value, items);
13481 last_item = MLX5_FLOW_LAYER_GRE_KEY;
13483 case RTE_FLOW_ITEM_TYPE_NVGRE:
13484 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13485 last_item = MLX5_FLOW_LAYER_GRE;
13486 tunnel_item = items;
13488 case RTE_FLOW_ITEM_TYPE_VXLAN:
13489 flow_dv_translate_item_vxlan(dev, attr,
13490 match_mask, match_value,
13492 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13493 last_item = MLX5_FLOW_LAYER_VXLAN;
13495 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
13496 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13497 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
13498 tunnel_item = items;
13500 case RTE_FLOW_ITEM_TYPE_GENEVE:
13501 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13502 last_item = MLX5_FLOW_LAYER_GENEVE;
13503 tunnel_item = items;
13505 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
13506 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
13510 return rte_flow_error_set(error, -ret,
13511 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13512 "cannot create GENEVE TLV option");
13513 flow->geneve_tlv_option = 1;
13514 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
13516 case RTE_FLOW_ITEM_TYPE_MPLS:
13517 flow_dv_translate_item_mpls(match_mask, match_value,
13518 items, last_item, tunnel);
13519 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13520 last_item = MLX5_FLOW_LAYER_MPLS;
13522 case RTE_FLOW_ITEM_TYPE_MARK:
13523 flow_dv_translate_item_mark(dev, match_mask,
13524 match_value, items);
13525 last_item = MLX5_FLOW_ITEM_MARK;
13527 case RTE_FLOW_ITEM_TYPE_META:
13528 flow_dv_translate_item_meta(dev, match_mask,
13529 match_value, attr, items);
13530 last_item = MLX5_FLOW_ITEM_METADATA;
13532 case RTE_FLOW_ITEM_TYPE_ICMP:
13533 flow_dv_translate_item_icmp(match_mask, match_value,
13535 last_item = MLX5_FLOW_LAYER_ICMP;
13537 case RTE_FLOW_ITEM_TYPE_ICMP6:
13538 flow_dv_translate_item_icmp6(match_mask, match_value,
13540 last_item = MLX5_FLOW_LAYER_ICMP6;
13542 case RTE_FLOW_ITEM_TYPE_TAG:
13543 flow_dv_translate_item_tag(dev, match_mask,
13544 match_value, items);
13545 last_item = MLX5_FLOW_ITEM_TAG;
13547 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
13548 flow_dv_translate_mlx5_item_tag(dev, match_mask,
13549 match_value, items);
13550 last_item = MLX5_FLOW_ITEM_TAG;
13552 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
13553 flow_dv_translate_item_tx_queue(dev, match_mask,
13556 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
13558 case RTE_FLOW_ITEM_TYPE_GTP:
13559 flow_dv_translate_item_gtp(match_mask, match_value,
13561 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13562 last_item = MLX5_FLOW_LAYER_GTP;
13564 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
13565 ret = flow_dv_translate_item_gtp_psc(match_mask,
13569 return rte_flow_error_set(error, -ret,
13570 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13571 "cannot create GTP PSC item");
13572 last_item = MLX5_FLOW_LAYER_GTP_PSC;
13574 case RTE_FLOW_ITEM_TYPE_ECPRI:
13575 if (!mlx5_flex_parser_ecpri_exist(dev)) {
13576 /* Create it only the first time to be used. */
13577 ret = mlx5_flex_parser_ecpri_alloc(dev);
13579 return rte_flow_error_set
13581 RTE_FLOW_ERROR_TYPE_ITEM,
13583 "cannot create eCPRI parser");
13585 flow_dv_translate_item_ecpri(dev, match_mask,
13586 match_value, items,
13588 /* No other protocol should follow eCPRI layer. */
13589 last_item = MLX5_FLOW_LAYER_ECPRI;
13591 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
13592 flow_dv_translate_item_integrity(items, integrity_items,
13595 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
13596 flow_dv_translate_item_aso_ct(dev, match_mask,
13597 match_value, items);
13599 case RTE_FLOW_ITEM_TYPE_FLEX:
13600 flow_dv_translate_item_flex(dev, match_mask,
13601 match_value, items,
13602 dev_flow, tunnel != 0);
13603 last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
13604 MLX5_FLOW_ITEM_OUTER_FLEX;
13609 item_flags |= last_item;
13612 * When E-Switch mode is enabled, we have two cases where we need to
13613 * set the source port manually.
13614 * The first one, is in case of Nic steering rule, and the second is
13615 * E-Switch rule where no port_id item was found. In both cases
13616 * the source port is set according the current port in use.
13618 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) && priv->sh->esw_mode) {
13619 if (flow_dv_translate_item_port_id(dev, match_mask,
13620 match_value, NULL, attr))
13623 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
13624 flow_dv_translate_item_integrity_post(match_mask, match_value,
13628 if (item_flags & MLX5_FLOW_LAYER_VXLAN_GPE)
13629 flow_dv_translate_item_vxlan_gpe(match_mask, match_value,
13630 tunnel_item, item_flags);
13631 else if (item_flags & MLX5_FLOW_LAYER_GENEVE)
13632 flow_dv_translate_item_geneve(match_mask, match_value,
13633 tunnel_item, item_flags);
13634 else if (item_flags & MLX5_FLOW_LAYER_GRE) {
13635 if (tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE)
13636 flow_dv_translate_item_gre(match_mask, match_value,
13637 tunnel_item, item_flags);
13638 else if (tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE)
13639 flow_dv_translate_item_nvgre(match_mask, match_value,
13640 tunnel_item, item_flags);
13642 MLX5_ASSERT(false);
13644 #ifdef RTE_LIBRTE_MLX5_DEBUG
13645 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
13646 dev_flow->dv.value.buf));
13649 * Layers may be already initialized from prefix flow if this dev_flow
13650 * is the suffix flow.
13652 handle->layers |= item_flags;
13653 if (action_flags & MLX5_FLOW_ACTION_RSS)
13654 flow_dv_hashfields_set(dev_flow, rss_desc);
13655 /* If has RSS action in the sample action, the Sample/Mirror resource
13656 * should be registered after the hash filed be update.
13658 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
13659 ret = flow_dv_translate_action_sample(dev,
13668 ret = flow_dv_create_action_sample(dev,
13677 return rte_flow_error_set
13679 RTE_FLOW_ERROR_TYPE_ACTION,
13681 "cannot create sample action");
13682 if (num_of_dest > 1) {
13683 dev_flow->dv.actions[sample_act_pos] =
13684 dev_flow->dv.dest_array_res->action;
13686 dev_flow->dv.actions[sample_act_pos] =
13687 dev_flow->dv.sample_res->verbs_action;
13691 * For multiple destination (sample action with ratio=1), the encap
13692 * action and port id action will be combined into group action.
13693 * So need remove the original these actions in the flow and only
13694 * use the sample action instead of.
13696 if (num_of_dest > 1 &&
13697 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
13699 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
13701 for (i = 0; i < actions_n; i++) {
13702 if ((sample_act->dr_encap_action &&
13703 sample_act->dr_encap_action ==
13704 dev_flow->dv.actions[i]) ||
13705 (sample_act->dr_port_id_action &&
13706 sample_act->dr_port_id_action ==
13707 dev_flow->dv.actions[i]) ||
13708 (sample_act->dr_jump_action &&
13709 sample_act->dr_jump_action ==
13710 dev_flow->dv.actions[i]))
13712 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
13714 memcpy((void *)dev_flow->dv.actions,
13715 (void *)temp_actions,
13716 tmp_actions_n * sizeof(void *));
13717 actions_n = tmp_actions_n;
13719 dev_flow->dv.actions_n = actions_n;
13720 dev_flow->act_flags = action_flags;
13721 if (wks->skip_matcher_reg)
13723 /* Register matcher. */
13724 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
13725 matcher.mask.size);
13726 matcher.priority = mlx5_get_matcher_priority(dev, attr,
13728 dev_flow->external);
13730 * When creating meter drop flow in drop table, using original
13731 * 5-tuple match, the matcher priority should be lower than
13734 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
13735 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
13736 matcher.priority <= MLX5_REG_BITS)
13737 matcher.priority += MLX5_REG_BITS;
13738 /* reserved field no needs to be set to 0 here. */
13739 tbl_key.is_fdb = attr->transfer;
13740 tbl_key.is_egress = attr->egress;
13741 tbl_key.level = dev_flow->dv.group;
13742 tbl_key.id = dev_flow->dv.table_id;
13743 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
13744 tunnel, attr->group, error))
13750 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13753 * @param[in, out] action
13754 * Shred RSS action holding hash RX queue objects.
13755 * @param[in] hash_fields
13756 * Defines combination of packet fields to participate in RX hash.
13757 * @param[in] tunnel
13759 * @param[in] hrxq_idx
13760 * Hash RX queue index to set.
13763 * 0 on success, otherwise negative errno value.
13766 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
13767 const uint64_t hash_fields,
13770 uint32_t *hrxqs = action->hrxq;
13772 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13773 case MLX5_RSS_HASH_IPV4:
13774 /* fall-through. */
13775 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13776 /* fall-through. */
13777 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13778 hrxqs[0] = hrxq_idx;
13780 case MLX5_RSS_HASH_IPV4_TCP:
13781 /* fall-through. */
13782 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13783 /* fall-through. */
13784 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13785 hrxqs[1] = hrxq_idx;
13787 case MLX5_RSS_HASH_IPV4_UDP:
13788 /* fall-through. */
13789 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13790 /* fall-through. */
13791 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13792 hrxqs[2] = hrxq_idx;
13794 case MLX5_RSS_HASH_IPV6:
13795 /* fall-through. */
13796 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13797 /* fall-through. */
13798 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13799 hrxqs[3] = hrxq_idx;
13801 case MLX5_RSS_HASH_IPV6_TCP:
13802 /* fall-through. */
13803 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13804 /* fall-through. */
13805 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13806 hrxqs[4] = hrxq_idx;
13808 case MLX5_RSS_HASH_IPV6_UDP:
13809 /* fall-through. */
13810 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13811 /* fall-through. */
13812 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13813 hrxqs[5] = hrxq_idx;
13815 case MLX5_RSS_HASH_NONE:
13816 hrxqs[6] = hrxq_idx;
13824 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13828 * Pointer to the Ethernet device structure.
13830 * Shared RSS action ID holding hash RX queue objects.
13831 * @param[in] hash_fields
13832 * Defines combination of packet fields to participate in RX hash.
13833 * @param[in] tunnel
13837 * Valid hash RX queue index, otherwise 0.
13840 __flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
13841 const uint64_t hash_fields)
13843 struct mlx5_priv *priv = dev->data->dev_private;
13844 struct mlx5_shared_action_rss *shared_rss =
13845 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
13846 const uint32_t *hrxqs = shared_rss->hrxq;
13848 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13849 case MLX5_RSS_HASH_IPV4:
13850 /* fall-through. */
13851 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13852 /* fall-through. */
13853 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13855 case MLX5_RSS_HASH_IPV4_TCP:
13856 /* fall-through. */
13857 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13858 /* fall-through. */
13859 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13861 case MLX5_RSS_HASH_IPV4_UDP:
13862 /* fall-through. */
13863 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13864 /* fall-through. */
13865 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13867 case MLX5_RSS_HASH_IPV6:
13868 /* fall-through. */
13869 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13870 /* fall-through. */
13871 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13873 case MLX5_RSS_HASH_IPV6_TCP:
13874 /* fall-through. */
13875 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13876 /* fall-through. */
13877 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13879 case MLX5_RSS_HASH_IPV6_UDP:
13880 /* fall-through. */
13881 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13882 /* fall-through. */
13883 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13885 case MLX5_RSS_HASH_NONE:
13894 * Apply the flow to the NIC, lock free,
13895 * (mutex should be acquired by caller).
13898 * Pointer to the Ethernet device structure.
13899 * @param[in, out] flow
13900 * Pointer to flow structure.
13901 * @param[out] error
13902 * Pointer to error structure.
13905 * 0 on success, a negative errno value otherwise and rte_errno is set.
13908 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
13909 struct rte_flow_error *error)
13911 struct mlx5_flow_dv_workspace *dv;
13912 struct mlx5_flow_handle *dh;
13913 struct mlx5_flow_handle_dv *dv_h;
13914 struct mlx5_flow *dev_flow;
13915 struct mlx5_priv *priv = dev->data->dev_private;
13916 uint32_t handle_idx;
13920 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13921 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
13925 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
13926 dev_flow = &wks->flows[idx];
13927 dv = &dev_flow->dv;
13928 dh = dev_flow->handle;
13931 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
13932 if (dv->transfer) {
13933 MLX5_ASSERT(priv->sh->dr_drop_action);
13934 dv->actions[n++] = priv->sh->dr_drop_action;
13936 #ifdef HAVE_MLX5DV_DR
13937 /* DR supports drop action placeholder. */
13938 MLX5_ASSERT(priv->sh->dr_drop_action);
13939 dv->actions[n++] = dv->group ?
13940 priv->sh->dr_drop_action :
13941 priv->root_drop_action;
13943 /* For DV we use the explicit drop queue. */
13944 MLX5_ASSERT(priv->drop_queue.hrxq);
13946 priv->drop_queue.hrxq->action;
13949 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
13950 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
13951 struct mlx5_hrxq *hrxq;
13954 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
13959 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13960 "cannot get hash queue");
13963 dh->rix_hrxq = hrxq_idx;
13964 dv->actions[n++] = hrxq->action;
13965 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13966 struct mlx5_hrxq *hrxq = NULL;
13969 hrxq_idx = __flow_dv_action_rss_hrxq_lookup(dev,
13970 rss_desc->shared_rss,
13971 dev_flow->hash_fields);
13973 hrxq = mlx5_ipool_get
13974 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
13979 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13980 "cannot get hash queue");
13983 dh->rix_srss = rss_desc->shared_rss;
13984 dv->actions[n++] = hrxq->action;
13985 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
13986 if (!priv->sh->default_miss_action) {
13989 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13990 "default miss action not be created.");
13993 dv->actions[n++] = priv->sh->default_miss_action;
13995 misc_mask = flow_dv_matcher_enable(dv->value.buf);
13996 __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
13997 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
13998 (void *)&dv->value, n,
13999 dv->actions, &dh->drv_flow);
14003 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14005 (!priv->sh->config.allow_duplicate_pattern &&
14007 "duplicating pattern is not allowed" :
14008 "hardware refuses to create flow");
14011 if (priv->vmwa_context &&
14012 dh->vf_vlan.tag && !dh->vf_vlan.created) {
14014 * The rule contains the VLAN pattern.
14015 * For VF we are going to create VLAN
14016 * interface to make hypervisor set correct
14017 * e-Switch vport context.
14019 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
14024 err = rte_errno; /* Save rte_errno before cleanup. */
14025 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
14026 handle_idx, dh, next) {
14027 /* hrxq is union, don't clear it if the flag is not set. */
14028 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
14029 mlx5_hrxq_release(dev, dh->rix_hrxq);
14031 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
14034 if (dh->vf_vlan.tag && dh->vf_vlan.created)
14035 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
14037 rte_errno = err; /* Restore rte_errno. */
14042 flow_dv_matcher_remove_cb(void *tool_ctx __rte_unused,
14043 struct mlx5_list_entry *entry)
14045 struct mlx5_flow_dv_matcher *resource = container_of(entry,
14049 claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
14050 mlx5_free(resource);
14054 * Release the flow matcher.
14057 * Pointer to Ethernet device.
14059 * Index to port ID action resource.
14062 * 1 while a reference on it exists, 0 when freed.
14065 flow_dv_matcher_release(struct rte_eth_dev *dev,
14066 struct mlx5_flow_handle *handle)
14068 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
14069 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
14070 typeof(*tbl), tbl);
14073 MLX5_ASSERT(matcher->matcher_object);
14074 ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
14075 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
14080 flow_dv_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14082 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14083 struct mlx5_flow_dv_encap_decap_resource *res =
14084 container_of(entry, typeof(*res), entry);
14086 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
14087 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
14091 * Release an encap/decap resource.
14094 * Pointer to Ethernet device.
14095 * @param encap_decap_idx
14096 * Index of encap decap resource.
14099 * 1 while a reference on it exists, 0 when freed.
14102 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
14103 uint32_t encap_decap_idx)
14105 struct mlx5_priv *priv = dev->data->dev_private;
14106 struct mlx5_flow_dv_encap_decap_resource *resource;
14108 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
14112 MLX5_ASSERT(resource->action);
14113 return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
14117 * Release an jump to table action resource.
14120 * Pointer to Ethernet device.
14122 * Index to the jump action resource.
14125 * 1 while a reference on it exists, 0 when freed.
14128 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
14131 struct mlx5_priv *priv = dev->data->dev_private;
14132 struct mlx5_flow_tbl_data_entry *tbl_data;
14134 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
14138 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
14142 flow_dv_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14144 struct mlx5_flow_dv_modify_hdr_resource *res =
14145 container_of(entry, typeof(*res), entry);
14146 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14148 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
14149 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
14153 * Release a modify-header resource.
14156 * Pointer to Ethernet device.
14158 * Pointer to mlx5_flow_handle.
14161 * 1 while a reference on it exists, 0 when freed.
14164 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
14165 struct mlx5_flow_handle *handle)
14167 struct mlx5_priv *priv = dev->data->dev_private;
14168 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
14170 MLX5_ASSERT(entry->action);
14171 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
14175 flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14177 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14178 struct mlx5_flow_dv_port_id_action_resource *resource =
14179 container_of(entry, typeof(*resource), entry);
14181 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14182 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
14186 * Release port ID action resource.
14189 * Pointer to Ethernet device.
14191 * Pointer to mlx5_flow_handle.
14194 * 1 while a reference on it exists, 0 when freed.
14197 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
14200 struct mlx5_priv *priv = dev->data->dev_private;
14201 struct mlx5_flow_dv_port_id_action_resource *resource;
14203 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
14206 MLX5_ASSERT(resource->action);
14207 return mlx5_list_unregister(priv->sh->port_id_action_list,
14212 * Release shared RSS action resource.
14215 * Pointer to Ethernet device.
14217 * Shared RSS action index.
14220 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
14222 struct mlx5_priv *priv = dev->data->dev_private;
14223 struct mlx5_shared_action_rss *shared_rss;
14225 shared_rss = mlx5_ipool_get
14226 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
14227 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14231 flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14233 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14234 struct mlx5_flow_dv_push_vlan_action_resource *resource =
14235 container_of(entry, typeof(*resource), entry);
14237 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14238 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
14242 * Release push vlan action resource.
14245 * Pointer to Ethernet device.
14247 * Pointer to mlx5_flow_handle.
14250 * 1 while a reference on it exists, 0 when freed.
14253 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
14254 struct mlx5_flow_handle *handle)
14256 struct mlx5_priv *priv = dev->data->dev_private;
14257 struct mlx5_flow_dv_push_vlan_action_resource *resource;
14258 uint32_t idx = handle->dvh.rix_push_vlan;
14260 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
14263 MLX5_ASSERT(resource->action);
14264 return mlx5_list_unregister(priv->sh->push_vlan_action_list,
14269 * Release the fate resource.
14272 * Pointer to Ethernet device.
14274 * Pointer to mlx5_flow_handle.
14277 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
14278 struct mlx5_flow_handle *handle)
14280 if (!handle->rix_fate)
14282 switch (handle->fate_action) {
14283 case MLX5_FLOW_FATE_QUEUE:
14284 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
14285 mlx5_hrxq_release(dev, handle->rix_hrxq);
14287 case MLX5_FLOW_FATE_JUMP:
14288 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
14290 case MLX5_FLOW_FATE_PORT_ID:
14291 flow_dv_port_id_action_resource_release(dev,
14292 handle->rix_port_id_action);
14295 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
14298 handle->rix_fate = 0;
14302 flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
14303 struct mlx5_list_entry *entry)
14305 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
14308 struct rte_eth_dev *dev = resource->dev;
14309 struct mlx5_priv *priv = dev->data->dev_private;
14311 if (resource->verbs_action)
14312 claim_zero(mlx5_flow_os_destroy_flow_action
14313 (resource->verbs_action));
14314 if (resource->normal_path_tbl)
14315 flow_dv_tbl_resource_release(MLX5_SH(dev),
14316 resource->normal_path_tbl);
14317 flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
14318 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
14319 DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
14323 * Release an sample resource.
14326 * Pointer to Ethernet device.
14328 * Pointer to mlx5_flow_handle.
14331 * 1 while a reference on it exists, 0 when freed.
14334 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
14335 struct mlx5_flow_handle *handle)
14337 struct mlx5_priv *priv = dev->data->dev_private;
14338 struct mlx5_flow_dv_sample_resource *resource;
14340 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
14341 handle->dvh.rix_sample);
14344 MLX5_ASSERT(resource->verbs_action);
14345 return mlx5_list_unregister(priv->sh->sample_action_list,
14350 flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
14351 struct mlx5_list_entry *entry)
14353 struct mlx5_flow_dv_dest_array_resource *resource =
14354 container_of(entry, typeof(*resource), entry);
14355 struct rte_eth_dev *dev = resource->dev;
14356 struct mlx5_priv *priv = dev->data->dev_private;
14359 MLX5_ASSERT(resource->action);
14360 if (resource->action)
14361 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14362 for (; i < resource->num_of_dest; i++)
14363 flow_dv_sample_sub_actions_release(dev,
14364 &resource->sample_idx[i]);
14365 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
14366 DRV_LOG(DEBUG, "destination array resource %p: removed",
14371 * Release an destination array resource.
14374 * Pointer to Ethernet device.
14376 * Pointer to mlx5_flow_handle.
14379 * 1 while a reference on it exists, 0 when freed.
14382 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
14383 struct mlx5_flow_handle *handle)
14385 struct mlx5_priv *priv = dev->data->dev_private;
14386 struct mlx5_flow_dv_dest_array_resource *resource;
14388 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
14389 handle->dvh.rix_dest_array);
14392 MLX5_ASSERT(resource->action);
14393 return mlx5_list_unregister(priv->sh->dest_array_list,
14398 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
14400 struct mlx5_priv *priv = dev->data->dev_private;
14401 struct mlx5_dev_ctx_shared *sh = priv->sh;
14402 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
14403 sh->geneve_tlv_option_resource;
14404 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
14405 if (geneve_opt_resource) {
14406 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
14407 __ATOMIC_RELAXED))) {
14408 claim_zero(mlx5_devx_cmd_destroy
14409 (geneve_opt_resource->obj));
14410 mlx5_free(sh->geneve_tlv_option_resource);
14411 sh->geneve_tlv_option_resource = NULL;
14414 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
14418 * Remove the flow from the NIC but keeps it in memory.
14419 * Lock free, (mutex should be acquired by caller).
14422 * Pointer to Ethernet device.
14423 * @param[in, out] flow
14424 * Pointer to flow structure.
14427 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
14429 struct mlx5_flow_handle *dh;
14430 uint32_t handle_idx;
14431 struct mlx5_priv *priv = dev->data->dev_private;
14435 handle_idx = flow->dev_handles;
14436 while (handle_idx) {
14437 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14441 if (dh->drv_flow) {
14442 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
14443 dh->drv_flow = NULL;
14445 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
14446 flow_dv_fate_resource_release(dev, dh);
14447 if (dh->vf_vlan.tag && dh->vf_vlan.created)
14448 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
14449 handle_idx = dh->next.next;
14454 * Remove the flow from the NIC and the memory.
14455 * Lock free, (mutex should be acquired by caller).
14458 * Pointer to the Ethernet device structure.
14459 * @param[in, out] flow
14460 * Pointer to flow structure.
14463 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
14465 struct mlx5_flow_handle *dev_handle;
14466 struct mlx5_priv *priv = dev->data->dev_private;
14467 struct mlx5_flow_meter_info *fm = NULL;
14472 flow_dv_remove(dev, flow);
14473 if (flow->counter) {
14474 flow_dv_counter_free(dev, flow->counter);
14478 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
14480 mlx5_flow_meter_detach(priv, fm);
14483 /* Keep the current age handling by default. */
14484 if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
14485 flow_dv_aso_ct_release(dev, flow->ct, NULL);
14486 else if (flow->age)
14487 flow_dv_aso_age_release(dev, flow->age);
14488 if (flow->geneve_tlv_option) {
14489 flow_dv_geneve_tlv_option_resource_release(dev);
14490 flow->geneve_tlv_option = 0;
14492 while (flow->dev_handles) {
14493 uint32_t tmp_idx = flow->dev_handles;
14495 dev_handle = mlx5_ipool_get(priv->sh->ipool
14496 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
14499 flow->dev_handles = dev_handle->next.next;
14500 while (dev_handle->flex_item) {
14501 int index = rte_bsf32(dev_handle->flex_item);
14503 mlx5_flex_release_index(dev, index);
14504 dev_handle->flex_item &= ~RTE_BIT32(index);
14506 if (dev_handle->dvh.matcher)
14507 flow_dv_matcher_release(dev, dev_handle);
14508 if (dev_handle->dvh.rix_sample)
14509 flow_dv_sample_resource_release(dev, dev_handle);
14510 if (dev_handle->dvh.rix_dest_array)
14511 flow_dv_dest_array_resource_release(dev, dev_handle);
14512 if (dev_handle->dvh.rix_encap_decap)
14513 flow_dv_encap_decap_resource_release(dev,
14514 dev_handle->dvh.rix_encap_decap);
14515 if (dev_handle->dvh.modify_hdr)
14516 flow_dv_modify_hdr_resource_release(dev, dev_handle);
14517 if (dev_handle->dvh.rix_push_vlan)
14518 flow_dv_push_vlan_action_resource_release(dev,
14520 if (dev_handle->dvh.rix_tag)
14521 flow_dv_tag_release(dev,
14522 dev_handle->dvh.rix_tag);
14523 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
14524 flow_dv_fate_resource_release(dev, dev_handle);
14526 srss = dev_handle->rix_srss;
14527 if (fm && dev_handle->is_meter_flow_id &&
14528 dev_handle->split_flow_id)
14529 mlx5_ipool_free(fm->flow_ipool,
14530 dev_handle->split_flow_id);
14531 else if (dev_handle->split_flow_id &&
14532 !dev_handle->is_meter_flow_id)
14533 mlx5_ipool_free(priv->sh->ipool
14534 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
14535 dev_handle->split_flow_id);
14536 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14540 flow_dv_shared_rss_action_release(dev, srss);
14544 * Release array of hash RX queue objects.
14548 * Pointer to the Ethernet device structure.
14549 * @param[in, out] hrxqs
14550 * Array of hash RX queue objects.
14553 * Total number of references to hash RX queue objects in *hrxqs* array
14554 * after this operation.
14557 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
14558 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
14563 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
14564 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
14574 * Release all hash RX queue objects representing shared RSS action.
14577 * Pointer to the Ethernet device structure.
14578 * @param[in, out] action
14579 * Shared RSS action to remove hash RX queue objects from.
14582 * Total number of references to hash RX queue objects stored in *action*
14583 * after this operation.
14584 * Expected to be 0 if no external references held.
14587 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
14588 struct mlx5_shared_action_rss *shared_rss)
14590 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
14594 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
14597 * Only one hash value is available for one L3+L4 combination:
14599 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
14600 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
14601 * same slot in mlx5_rss_hash_fields.
14604 * Pointer to the shared action RSS conf.
14605 * @param[in, out] hash_field
14606 * hash_field variable needed to be adjusted.
14612 __flow_dv_action_rss_l34_hash_adjust(struct mlx5_shared_action_rss *rss,
14613 uint64_t *hash_field)
14615 uint64_t rss_types = rss->origin.types;
14617 switch (*hash_field & ~IBV_RX_HASH_INNER) {
14618 case MLX5_RSS_HASH_IPV4:
14619 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
14620 *hash_field &= ~MLX5_RSS_HASH_IPV4;
14621 if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
14622 *hash_field |= IBV_RX_HASH_DST_IPV4;
14623 else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
14624 *hash_field |= IBV_RX_HASH_SRC_IPV4;
14626 *hash_field |= MLX5_RSS_HASH_IPV4;
14629 case MLX5_RSS_HASH_IPV6:
14630 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
14631 *hash_field &= ~MLX5_RSS_HASH_IPV6;
14632 if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
14633 *hash_field |= IBV_RX_HASH_DST_IPV6;
14634 else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
14635 *hash_field |= IBV_RX_HASH_SRC_IPV6;
14637 *hash_field |= MLX5_RSS_HASH_IPV6;
14640 case MLX5_RSS_HASH_IPV4_UDP:
14641 /* fall-through. */
14642 case MLX5_RSS_HASH_IPV6_UDP:
14643 if (rss_types & RTE_ETH_RSS_UDP) {
14644 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
14645 if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
14646 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
14647 else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
14648 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
14650 *hash_field |= MLX5_UDP_IBV_RX_HASH;
14653 case MLX5_RSS_HASH_IPV4_TCP:
14654 /* fall-through. */
14655 case MLX5_RSS_HASH_IPV6_TCP:
14656 if (rss_types & RTE_ETH_RSS_TCP) {
14657 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
14658 if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
14659 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
14660 else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
14661 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
14663 *hash_field |= MLX5_TCP_IBV_RX_HASH;
14672 * Setup shared RSS action.
14673 * Prepare set of hash RX queue objects sufficient to handle all valid
14674 * hash_fields combinations (see enum ibv_rx_hash_fields).
14677 * Pointer to the Ethernet device structure.
14678 * @param[in] action_idx
14679 * Shared RSS action ipool index.
14680 * @param[in, out] action
14681 * Partially initialized shared RSS action.
14682 * @param[out] error
14683 * Perform verbose error reporting if not NULL. Initialized in case of
14687 * 0 on success, otherwise negative errno value.
14690 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
14691 uint32_t action_idx,
14692 struct mlx5_shared_action_rss *shared_rss,
14693 struct rte_flow_error *error)
14695 struct mlx5_flow_rss_desc rss_desc = { 0 };
14699 if (mlx5_ind_table_obj_setup(dev, shared_rss->ind_tbl,
14700 !!dev->data->dev_started)) {
14701 return rte_flow_error_set(error, rte_errno,
14702 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14703 "cannot setup indirection table");
14705 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
14706 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
14707 rss_desc.const_q = shared_rss->origin.queue;
14708 rss_desc.queue_num = shared_rss->origin.queue_num;
14709 /* Set non-zero value to indicate a shared RSS. */
14710 rss_desc.shared_rss = action_idx;
14711 rss_desc.ind_tbl = shared_rss->ind_tbl;
14712 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
14714 uint64_t hash_fields = mlx5_rss_hash_fields[i];
14717 __flow_dv_action_rss_l34_hash_adjust(shared_rss, &hash_fields);
14718 if (shared_rss->origin.level > 1) {
14719 hash_fields |= IBV_RX_HASH_INNER;
14722 rss_desc.tunnel = tunnel;
14723 rss_desc.hash_fields = hash_fields;
14724 hrxq_idx = mlx5_hrxq_get(dev, &rss_desc);
14728 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14729 "cannot get hash queue");
14730 goto error_hrxq_new;
14732 err = __flow_dv_action_rss_hrxq_set
14733 (shared_rss, hash_fields, hrxq_idx);
14739 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14740 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true, true))
14741 shared_rss->ind_tbl = NULL;
14747 * Create shared RSS action.
14750 * Pointer to the Ethernet device structure.
14752 * Shared action configuration.
14754 * RSS action specification used to create shared action.
14755 * @param[out] error
14756 * Perform verbose error reporting if not NULL. Initialized in case of
14760 * A valid shared action ID in case of success, 0 otherwise and
14761 * rte_errno is set.
14764 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
14765 const struct rte_flow_indir_action_conf *conf,
14766 const struct rte_flow_action_rss *rss,
14767 struct rte_flow_error *error)
14769 struct mlx5_priv *priv = dev->data->dev_private;
14770 struct mlx5_shared_action_rss *shared_rss = NULL;
14771 void *queue = NULL;
14772 struct rte_flow_action_rss *origin;
14773 const uint8_t *rss_key;
14774 uint32_t queue_size = rss->queue_num * sizeof(uint16_t);
14777 RTE_SET_USED(conf);
14778 queue = mlx5_malloc(0, RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14780 shared_rss = mlx5_ipool_zmalloc
14781 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
14782 if (!shared_rss || !queue) {
14783 rte_flow_error_set(error, ENOMEM,
14784 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14785 "cannot allocate resource memory");
14786 goto error_rss_init;
14788 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
14789 rte_flow_error_set(error, E2BIG,
14790 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14791 "rss action number out of range");
14792 goto error_rss_init;
14794 shared_rss->ind_tbl = mlx5_malloc(MLX5_MEM_ZERO,
14795 sizeof(*shared_rss->ind_tbl),
14797 if (!shared_rss->ind_tbl) {
14798 rte_flow_error_set(error, ENOMEM,
14799 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14800 "cannot allocate resource memory");
14801 goto error_rss_init;
14803 memcpy(queue, rss->queue, queue_size);
14804 shared_rss->ind_tbl->queues = queue;
14805 shared_rss->ind_tbl->queues_n = rss->queue_num;
14806 origin = &shared_rss->origin;
14807 origin->func = rss->func;
14808 origin->level = rss->level;
14809 /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
14810 origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
14811 /* NULL RSS key indicates default RSS key. */
14812 rss_key = !rss->key ? rss_hash_default_key : rss->key;
14813 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14814 origin->key = &shared_rss->key[0];
14815 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
14816 origin->queue = queue;
14817 origin->queue_num = rss->queue_num;
14818 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
14819 goto error_rss_init;
14820 rte_spinlock_init(&shared_rss->action_rss_sl);
14821 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14822 rte_spinlock_lock(&priv->shared_act_sl);
14823 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14824 &priv->rss_shared_actions, idx, shared_rss, next);
14825 rte_spinlock_unlock(&priv->shared_act_sl);
14829 if (shared_rss->ind_tbl)
14830 mlx5_free(shared_rss->ind_tbl);
14831 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14840 * Destroy the shared RSS action.
14841 * Release related hash RX queue objects.
14844 * Pointer to the Ethernet device structure.
14846 * The shared RSS action object ID to be removed.
14847 * @param[out] error
14848 * Perform verbose error reporting if not NULL. Initialized in case of
14852 * 0 on success, otherwise negative errno value.
14855 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
14856 struct rte_flow_error *error)
14858 struct mlx5_priv *priv = dev->data->dev_private;
14859 struct mlx5_shared_action_rss *shared_rss =
14860 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14861 uint32_t old_refcnt = 1;
14863 uint16_t *queue = NULL;
14866 return rte_flow_error_set(error, EINVAL,
14867 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14868 "invalid shared action");
14869 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
14870 0, 0, __ATOMIC_ACQUIRE,
14872 return rte_flow_error_set(error, EBUSY,
14873 RTE_FLOW_ERROR_TYPE_ACTION,
14875 "shared rss has references");
14876 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14878 return rte_flow_error_set(error, EBUSY,
14879 RTE_FLOW_ERROR_TYPE_ACTION,
14881 "shared rss hrxq has references");
14882 queue = shared_rss->ind_tbl->queues;
14883 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true,
14884 !!dev->data->dev_started);
14886 return rte_flow_error_set(error, EBUSY,
14887 RTE_FLOW_ERROR_TYPE_ACTION,
14889 "shared rss indirection table has"
14892 rte_spinlock_lock(&priv->shared_act_sl);
14893 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14894 &priv->rss_shared_actions, idx, shared_rss, next);
14895 rte_spinlock_unlock(&priv->shared_act_sl);
14896 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14902 * Create indirect action, lock free,
14903 * (mutex should be acquired by caller).
14904 * Dispatcher for action type specific call.
14907 * Pointer to the Ethernet device structure.
14909 * Shared action configuration.
14910 * @param[in] action
14911 * Action specification used to create indirect action.
14912 * @param[out] error
14913 * Perform verbose error reporting if not NULL. Initialized in case of
14917 * A valid shared action handle in case of success, NULL otherwise and
14918 * rte_errno is set.
14920 static struct rte_flow_action_handle *
14921 flow_dv_action_create(struct rte_eth_dev *dev,
14922 const struct rte_flow_indir_action_conf *conf,
14923 const struct rte_flow_action *action,
14924 struct rte_flow_error *err)
14926 struct mlx5_priv *priv = dev->data->dev_private;
14927 uint32_t age_idx = 0;
14931 switch (action->type) {
14932 case RTE_FLOW_ACTION_TYPE_RSS:
14933 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
14934 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
14935 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14937 case RTE_FLOW_ACTION_TYPE_AGE:
14938 age_idx = flow_dv_aso_age_alloc(dev, err);
14943 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
14944 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
14945 flow_dv_aso_age_params_init(dev, age_idx,
14946 ((const struct rte_flow_action_age *)
14947 action->conf)->context ?
14948 ((const struct rte_flow_action_age *)
14949 action->conf)->context :
14950 (void *)(uintptr_t)idx,
14951 ((const struct rte_flow_action_age *)
14952 action->conf)->timeout);
14955 case RTE_FLOW_ACTION_TYPE_COUNT:
14956 ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
14957 idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
14958 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14960 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
14961 ret = flow_dv_translate_create_conntrack(dev, action->conf,
14963 idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
14966 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
14967 NULL, "action type not supported");
14970 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
14974 * Destroy the indirect action.
14975 * Release action related resources on the NIC and the memory.
14976 * Lock free, (mutex should be acquired by caller).
14977 * Dispatcher for action type specific call.
14980 * Pointer to the Ethernet device structure.
14981 * @param[in] handle
14982 * The indirect action object handle to be removed.
14983 * @param[out] error
14984 * Perform verbose error reporting if not NULL. Initialized in case of
14988 * 0 on success, otherwise negative errno value.
14991 flow_dv_action_destroy(struct rte_eth_dev *dev,
14992 struct rte_flow_action_handle *handle,
14993 struct rte_flow_error *error)
14995 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14996 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14997 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14998 struct mlx5_flow_counter *cnt;
14999 uint32_t no_flow_refcnt = 1;
15003 case MLX5_INDIRECT_ACTION_TYPE_RSS:
15004 return __flow_dv_action_rss_release(dev, idx, error);
15005 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15006 cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
15007 if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
15008 &no_flow_refcnt, 1, false,
15011 return rte_flow_error_set(error, EBUSY,
15012 RTE_FLOW_ERROR_TYPE_ACTION,
15014 "Indirect count action has references");
15015 flow_dv_counter_free(dev, idx);
15017 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15018 ret = flow_dv_aso_age_release(dev, idx);
15021 * In this case, the last flow has a reference will
15022 * actually release the age action.
15024 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
15025 " released with references %d.", idx, ret);
15027 case MLX5_INDIRECT_ACTION_TYPE_CT:
15028 ret = flow_dv_aso_ct_release(dev, idx, error);
15032 DRV_LOG(DEBUG, "Connection tracking object %u still "
15033 "has references %d.", idx, ret);
15036 return rte_flow_error_set(error, ENOTSUP,
15037 RTE_FLOW_ERROR_TYPE_ACTION,
15039 "action type not supported");
15044 * Updates in place shared RSS action configuration.
15047 * Pointer to the Ethernet device structure.
15049 * The shared RSS action object ID to be updated.
15050 * @param[in] action_conf
15051 * RSS action specification used to modify *shared_rss*.
15052 * @param[out] error
15053 * Perform verbose error reporting if not NULL. Initialized in case of
15057 * 0 on success, otherwise negative errno value.
15058 * @note: currently only support update of RSS queues.
15061 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
15062 const struct rte_flow_action_rss *action_conf,
15063 struct rte_flow_error *error)
15065 struct mlx5_priv *priv = dev->data->dev_private;
15066 struct mlx5_shared_action_rss *shared_rss =
15067 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15069 void *queue = NULL;
15070 uint16_t *queue_old = NULL;
15071 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
15072 bool dev_started = !!dev->data->dev_started;
15075 return rte_flow_error_set(error, EINVAL,
15076 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15077 "invalid shared action to update");
15078 if (priv->obj_ops.ind_table_modify == NULL)
15079 return rte_flow_error_set(error, ENOTSUP,
15080 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15081 "cannot modify indirection table");
15082 queue = mlx5_malloc(MLX5_MEM_ZERO,
15083 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
15086 return rte_flow_error_set(error, ENOMEM,
15087 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15089 "cannot allocate resource memory");
15090 memcpy(queue, action_conf->queue, queue_size);
15091 MLX5_ASSERT(shared_rss->ind_tbl);
15092 rte_spinlock_lock(&shared_rss->action_rss_sl);
15093 queue_old = shared_rss->ind_tbl->queues;
15094 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
15095 queue, action_conf->queue_num,
15096 true /* standalone */,
15097 dev_started /* ref_new_qs */,
15098 dev_started /* deref_old_qs */);
15101 ret = rte_flow_error_set(error, rte_errno,
15102 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15103 "cannot update indirection table");
15105 mlx5_free(queue_old);
15106 shared_rss->origin.queue = queue;
15107 shared_rss->origin.queue_num = action_conf->queue_num;
15109 rte_spinlock_unlock(&shared_rss->action_rss_sl);
15114 * Updates in place conntrack context or direction.
15115 * Context update should be synchronized.
15118 * Pointer to the Ethernet device structure.
15120 * The conntrack object ID to be updated.
15121 * @param[in] update
15122 * Pointer to the structure of information to update.
15123 * @param[out] error
15124 * Perform verbose error reporting if not NULL. Initialized in case of
15128 * 0 on success, otherwise negative errno value.
15131 __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
15132 const struct rte_flow_modify_conntrack *update,
15133 struct rte_flow_error *error)
15135 struct mlx5_priv *priv = dev->data->dev_private;
15136 struct mlx5_aso_ct_action *ct;
15137 const struct rte_flow_action_conntrack *new_prf;
15139 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15142 if (PORT_ID(priv) != owner)
15143 return rte_flow_error_set(error, EACCES,
15144 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15146 "CT object owned by another port");
15147 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15148 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15150 return rte_flow_error_set(error, ENOMEM,
15151 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15153 "CT object is inactive");
15154 new_prf = &update->new_ct;
15155 if (update->direction)
15156 ct->is_original = !!new_prf->is_original_dir;
15157 if (update->state) {
15158 /* Only validate the profile when it needs to be updated. */
15159 ret = mlx5_validate_action_ct(dev, new_prf, error);
15162 ret = mlx5_aso_ct_update_by_wqe(priv->sh, ct, new_prf);
15164 return rte_flow_error_set(error, EIO,
15165 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15167 "Failed to send CT context update WQE");
15168 /* Block until ready or a failure. */
15169 ret = mlx5_aso_ct_available(priv->sh, ct);
15171 rte_flow_error_set(error, rte_errno,
15172 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15174 "Timeout to get the CT update");
15180 * Updates in place shared action configuration, lock free,
15181 * (mutex should be acquired by caller).
15184 * Pointer to the Ethernet device structure.
15185 * @param[in] handle
15186 * The indirect action object handle to be updated.
15187 * @param[in] update
15188 * Action specification used to modify the action pointed by *handle*.
15189 * *update* could be of same type with the action pointed by the *handle*
15190 * handle argument, or some other structures like a wrapper, depending on
15191 * the indirect action type.
15192 * @param[out] error
15193 * Perform verbose error reporting if not NULL. Initialized in case of
15197 * 0 on success, otherwise negative errno value.
15200 flow_dv_action_update(struct rte_eth_dev *dev,
15201 struct rte_flow_action_handle *handle,
15202 const void *update,
15203 struct rte_flow_error *err)
15205 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15206 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15207 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15208 const void *action_conf;
15211 case MLX5_INDIRECT_ACTION_TYPE_RSS:
15212 action_conf = ((const struct rte_flow_action *)update)->conf;
15213 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
15214 case MLX5_INDIRECT_ACTION_TYPE_CT:
15215 return __flow_dv_action_ct_update(dev, idx, update, err);
15217 return rte_flow_error_set(err, ENOTSUP,
15218 RTE_FLOW_ERROR_TYPE_ACTION,
15220 "action type update not supported");
15225 * Destroy the meter sub policy table rules.
15226 * Lock free, (mutex should be acquired by caller).
15229 * Pointer to Ethernet device.
15230 * @param[in] sub_policy
15231 * Pointer to meter sub policy table.
15234 __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
15235 struct mlx5_flow_meter_sub_policy *sub_policy)
15237 struct mlx5_priv *priv = dev->data->dev_private;
15238 struct mlx5_flow_tbl_data_entry *tbl;
15239 struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
15240 struct mlx5_flow_meter_info *next_fm;
15241 struct mlx5_sub_policy_color_rule *color_rule;
15245 for (i = 0; i < RTE_COLORS; i++) {
15247 if (i == RTE_COLOR_GREEN && policy &&
15248 policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
15249 next_fm = mlx5_flow_meter_find(priv,
15250 policy->act_cnt[i].next_mtr_id, NULL);
15251 RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
15253 claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
15254 tbl = container_of(color_rule->matcher->tbl,
15255 typeof(*tbl), tbl);
15256 mlx5_list_unregister(tbl->matchers,
15257 &color_rule->matcher->entry);
15258 TAILQ_REMOVE(&sub_policy->color_rules[i],
15259 color_rule, next_port);
15260 mlx5_free(color_rule);
15262 mlx5_flow_meter_detach(priv, next_fm);
15265 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15266 if (sub_policy->rix_hrxq[i]) {
15267 if (policy && !policy->is_hierarchy)
15268 mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
15269 sub_policy->rix_hrxq[i] = 0;
15271 if (sub_policy->jump_tbl[i]) {
15272 flow_dv_tbl_resource_release(MLX5_SH(dev),
15273 sub_policy->jump_tbl[i]);
15274 sub_policy->jump_tbl[i] = NULL;
15277 if (sub_policy->tbl_rsc) {
15278 flow_dv_tbl_resource_release(MLX5_SH(dev),
15279 sub_policy->tbl_rsc);
15280 sub_policy->tbl_rsc = NULL;
15285 * Destroy policy rules, lock free,
15286 * (mutex should be acquired by caller).
15287 * Dispatcher for action type specific call.
15290 * Pointer to the Ethernet device structure.
15291 * @param[in] mtr_policy
15292 * Meter policy struct.
15295 flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
15296 struct mlx5_flow_meter_policy *mtr_policy)
15299 struct mlx5_flow_meter_sub_policy *sub_policy;
15300 uint16_t sub_policy_num;
15302 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15303 sub_policy_num = (mtr_policy->sub_policy_num >>
15304 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15305 MLX5_MTR_SUB_POLICY_NUM_MASK;
15306 for (j = 0; j < sub_policy_num; j++) {
15307 sub_policy = mtr_policy->sub_policys[i][j];
15309 __flow_dv_destroy_sub_policy_rules(dev,
15316 * Destroy policy action, lock free,
15317 * (mutex should be acquired by caller).
15318 * Dispatcher for action type specific call.
15321 * Pointer to the Ethernet device structure.
15322 * @param[in] mtr_policy
15323 * Meter policy struct.
15326 flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
15327 struct mlx5_flow_meter_policy *mtr_policy)
15329 struct rte_flow_action *rss_action;
15330 struct mlx5_flow_handle dev_handle;
15333 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15334 if (mtr_policy->act_cnt[i].rix_mark) {
15335 flow_dv_tag_release(dev,
15336 mtr_policy->act_cnt[i].rix_mark);
15337 mtr_policy->act_cnt[i].rix_mark = 0;
15339 if (mtr_policy->act_cnt[i].modify_hdr) {
15340 dev_handle.dvh.modify_hdr =
15341 mtr_policy->act_cnt[i].modify_hdr;
15342 flow_dv_modify_hdr_resource_release(dev, &dev_handle);
15344 switch (mtr_policy->act_cnt[i].fate_action) {
15345 case MLX5_FLOW_FATE_SHARED_RSS:
15346 rss_action = mtr_policy->act_cnt[i].rss;
15347 mlx5_free(rss_action);
15349 case MLX5_FLOW_FATE_PORT_ID:
15350 if (mtr_policy->act_cnt[i].rix_port_id_action) {
15351 flow_dv_port_id_action_resource_release(dev,
15352 mtr_policy->act_cnt[i].rix_port_id_action);
15353 mtr_policy->act_cnt[i].rix_port_id_action = 0;
15356 case MLX5_FLOW_FATE_DROP:
15357 case MLX5_FLOW_FATE_JUMP:
15358 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15359 mtr_policy->act_cnt[i].dr_jump_action[j] =
15363 /*Queue action do nothing*/
15367 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15368 mtr_policy->dr_drop_action[j] = NULL;
15372 * Create policy action per domain, lock free,
15373 * (mutex should be acquired by caller).
15374 * Dispatcher for action type specific call.
15377 * Pointer to the Ethernet device structure.
15378 * @param[in] mtr_policy
15379 * Meter policy struct.
15380 * @param[in] action
15381 * Action specification used to create meter actions.
15382 * @param[out] error
15383 * Perform verbose error reporting if not NULL. Initialized in case of
15387 * 0 on success, otherwise negative errno value.
15390 __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
15391 struct mlx5_flow_meter_policy *mtr_policy,
15392 const struct rte_flow_action *actions[RTE_COLORS],
15393 enum mlx5_meter_domain domain,
15394 struct rte_mtr_error *error)
15396 struct mlx5_priv *priv = dev->data->dev_private;
15397 struct rte_flow_error flow_err;
15398 const struct rte_flow_action *act;
15399 uint64_t action_flags;
15400 struct mlx5_flow_handle dh;
15401 struct mlx5_flow dev_flow;
15402 struct mlx5_flow_dv_port_id_action_resource port_id_action;
15404 uint8_t egress, transfer;
15405 struct mlx5_meter_policy_action_container *act_cnt = NULL;
15407 struct mlx5_flow_dv_modify_hdr_resource res;
15408 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
15409 sizeof(struct mlx5_modification_cmd) *
15410 (MLX5_MAX_MODIFY_NUM + 1)];
15412 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
15413 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15416 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15417 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15418 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
15419 memset(&dev_flow, 0, sizeof(struct mlx5_flow));
15420 memset(&port_id_action, 0,
15421 sizeof(struct mlx5_flow_dv_port_id_action_resource));
15422 memset(mhdr_res, 0, sizeof(*mhdr_res));
15423 mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
15424 (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15425 MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
15426 dev_flow.handle = &dh;
15427 dev_flow.dv.port_id_action = &port_id_action;
15428 dev_flow.external = true;
15429 for (i = 0; i < RTE_COLORS; i++) {
15430 if (i < MLX5_MTR_RTE_COLORS)
15431 act_cnt = &mtr_policy->act_cnt[i];
15432 /* Skip the color policy actions creation. */
15433 if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
15434 (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
15437 for (act = actions[i];
15438 act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
15439 switch (act->type) {
15440 case RTE_FLOW_ACTION_TYPE_MARK:
15442 uint32_t tag_be = mlx5_flow_mark_set
15443 (((const struct rte_flow_action_mark *)
15446 if (i >= MLX5_MTR_RTE_COLORS)
15447 return -rte_mtr_error_set(error,
15449 RTE_MTR_ERROR_TYPE_METER_POLICY,
15451 "cannot create policy "
15452 "mark action for this color");
15454 if (flow_dv_tag_resource_register(dev, tag_be,
15455 &dev_flow, &flow_err))
15456 return -rte_mtr_error_set(error,
15458 RTE_MTR_ERROR_TYPE_METER_POLICY,
15460 "cannot setup policy mark action");
15461 MLX5_ASSERT(dev_flow.dv.tag_resource);
15462 act_cnt->rix_mark =
15463 dev_flow.handle->dvh.rix_tag;
15464 action_flags |= MLX5_FLOW_ACTION_MARK;
15467 case RTE_FLOW_ACTION_TYPE_SET_TAG:
15468 if (i >= MLX5_MTR_RTE_COLORS)
15469 return -rte_mtr_error_set(error,
15471 RTE_MTR_ERROR_TYPE_METER_POLICY,
15473 "cannot create policy "
15474 "set tag action for this color");
15475 if (flow_dv_convert_action_set_tag
15477 (const struct rte_flow_action_set_tag *)
15478 act->conf, &flow_err))
15479 return -rte_mtr_error_set(error,
15481 RTE_MTR_ERROR_TYPE_METER_POLICY,
15482 NULL, "cannot convert policy "
15484 if (!mhdr_res->actions_num)
15485 return -rte_mtr_error_set(error,
15487 RTE_MTR_ERROR_TYPE_METER_POLICY,
15488 NULL, "cannot find policy "
15490 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15492 case RTE_FLOW_ACTION_TYPE_DROP:
15494 struct mlx5_flow_mtr_mng *mtrmng =
15496 struct mlx5_flow_tbl_data_entry *tbl_data;
15499 * Create the drop table with
15500 * METER DROP level.
15502 if (!mtrmng->drop_tbl[domain]) {
15503 mtrmng->drop_tbl[domain] =
15504 flow_dv_tbl_resource_get(dev,
15505 MLX5_FLOW_TABLE_LEVEL_METER,
15506 egress, transfer, false, NULL, 0,
15507 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
15508 if (!mtrmng->drop_tbl[domain])
15509 return -rte_mtr_error_set
15511 RTE_MTR_ERROR_TYPE_METER_POLICY,
15513 "Failed to create meter drop table");
15515 tbl_data = container_of
15516 (mtrmng->drop_tbl[domain],
15517 struct mlx5_flow_tbl_data_entry, tbl);
15518 if (i < MLX5_MTR_RTE_COLORS) {
15519 act_cnt->dr_jump_action[domain] =
15520 tbl_data->jump.action;
15521 act_cnt->fate_action =
15522 MLX5_FLOW_FATE_DROP;
15524 if (i == RTE_COLOR_RED)
15525 mtr_policy->dr_drop_action[domain] =
15526 tbl_data->jump.action;
15527 action_flags |= MLX5_FLOW_ACTION_DROP;
15530 case RTE_FLOW_ACTION_TYPE_QUEUE:
15532 if (i >= MLX5_MTR_RTE_COLORS)
15533 return -rte_mtr_error_set(error,
15535 RTE_MTR_ERROR_TYPE_METER_POLICY,
15536 NULL, "cannot create policy "
15537 "fate queue for this color");
15539 ((const struct rte_flow_action_queue *)
15540 (act->conf))->index;
15541 act_cnt->fate_action =
15542 MLX5_FLOW_FATE_QUEUE;
15543 dev_flow.handle->fate_action =
15544 MLX5_FLOW_FATE_QUEUE;
15545 mtr_policy->is_queue = 1;
15546 action_flags |= MLX5_FLOW_ACTION_QUEUE;
15549 case RTE_FLOW_ACTION_TYPE_RSS:
15553 if (i >= MLX5_MTR_RTE_COLORS)
15554 return -rte_mtr_error_set(error,
15556 RTE_MTR_ERROR_TYPE_METER_POLICY,
15558 "cannot create policy "
15559 "rss action for this color");
15561 * Save RSS conf into policy struct
15562 * for translate stage.
15564 rss_size = (int)rte_flow_conv
15565 (RTE_FLOW_CONV_OP_ACTION,
15566 NULL, 0, act, &flow_err);
15568 return -rte_mtr_error_set(error,
15570 RTE_MTR_ERROR_TYPE_METER_POLICY,
15571 NULL, "Get the wrong "
15572 "rss action struct size");
15573 act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
15574 rss_size, 0, SOCKET_ID_ANY);
15576 return -rte_mtr_error_set(error,
15578 RTE_MTR_ERROR_TYPE_METER_POLICY,
15580 "Fail to malloc rss action memory");
15581 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
15582 act_cnt->rss, rss_size,
15585 return -rte_mtr_error_set(error,
15587 RTE_MTR_ERROR_TYPE_METER_POLICY,
15588 NULL, "Fail to save "
15589 "rss action into policy struct");
15590 act_cnt->fate_action =
15591 MLX5_FLOW_FATE_SHARED_RSS;
15592 action_flags |= MLX5_FLOW_ACTION_RSS;
15595 case RTE_FLOW_ACTION_TYPE_PORT_ID:
15596 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15598 struct mlx5_flow_dv_port_id_action_resource
15600 uint32_t port_id = 0;
15602 if (i >= MLX5_MTR_RTE_COLORS)
15603 return -rte_mtr_error_set(error,
15605 RTE_MTR_ERROR_TYPE_METER_POLICY,
15606 NULL, "cannot create policy "
15607 "port action for this color");
15608 memset(&port_id_resource, 0,
15609 sizeof(port_id_resource));
15610 if (flow_dv_translate_action_port_id(dev, act,
15611 &port_id, &flow_err))
15612 return -rte_mtr_error_set(error,
15614 RTE_MTR_ERROR_TYPE_METER_POLICY,
15615 NULL, "cannot translate "
15616 "policy port action");
15617 port_id_resource.port_id = port_id;
15618 if (flow_dv_port_id_action_resource_register
15619 (dev, &port_id_resource,
15620 &dev_flow, &flow_err))
15621 return -rte_mtr_error_set(error,
15623 RTE_MTR_ERROR_TYPE_METER_POLICY,
15624 NULL, "cannot setup "
15625 "policy port action");
15626 act_cnt->rix_port_id_action =
15627 dev_flow.handle->rix_port_id_action;
15628 act_cnt->fate_action =
15629 MLX5_FLOW_FATE_PORT_ID;
15630 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15633 case RTE_FLOW_ACTION_TYPE_JUMP:
15635 uint32_t jump_group = 0;
15636 uint32_t table = 0;
15637 struct mlx5_flow_tbl_data_entry *tbl_data;
15638 struct flow_grp_info grp_info = {
15639 .external = !!dev_flow.external,
15640 .transfer = !!transfer,
15641 .fdb_def_rule = !!priv->fdb_def_rule,
15643 .skip_scale = dev_flow.skip_scale &
15644 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15646 struct mlx5_flow_meter_sub_policy *sub_policy =
15647 mtr_policy->sub_policys[domain][0];
15649 if (i >= MLX5_MTR_RTE_COLORS)
15650 return -rte_mtr_error_set(error,
15652 RTE_MTR_ERROR_TYPE_METER_POLICY,
15654 "cannot create policy "
15655 "jump action for this color");
15657 ((const struct rte_flow_action_jump *)
15659 if (mlx5_flow_group_to_table(dev, NULL,
15662 &grp_info, &flow_err))
15663 return -rte_mtr_error_set(error,
15665 RTE_MTR_ERROR_TYPE_METER_POLICY,
15666 NULL, "cannot setup "
15667 "policy jump action");
15668 sub_policy->jump_tbl[i] =
15669 flow_dv_tbl_resource_get(dev,
15672 !!dev_flow.external,
15673 NULL, jump_group, 0,
15676 (!sub_policy->jump_tbl[i])
15677 return -rte_mtr_error_set(error,
15679 RTE_MTR_ERROR_TYPE_METER_POLICY,
15680 NULL, "cannot create jump action.");
15681 tbl_data = container_of
15682 (sub_policy->jump_tbl[i],
15683 struct mlx5_flow_tbl_data_entry, tbl);
15684 act_cnt->dr_jump_action[domain] =
15685 tbl_data->jump.action;
15686 act_cnt->fate_action =
15687 MLX5_FLOW_FATE_JUMP;
15688 action_flags |= MLX5_FLOW_ACTION_JUMP;
15692 * No need to check meter hierarchy for Y or R colors
15693 * here since it is done in the validation stage.
15695 case RTE_FLOW_ACTION_TYPE_METER:
15697 const struct rte_flow_action_meter *mtr;
15698 struct mlx5_flow_meter_info *next_fm;
15699 struct mlx5_flow_meter_policy *next_policy;
15700 struct rte_flow_action tag_action;
15701 struct mlx5_rte_flow_action_set_tag set_tag;
15702 uint32_t next_mtr_idx = 0;
15705 next_fm = mlx5_flow_meter_find(priv,
15709 return -rte_mtr_error_set(error, EINVAL,
15710 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15711 "Fail to find next meter.");
15712 if (next_fm->def_policy)
15713 return -rte_mtr_error_set(error, EINVAL,
15714 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15715 "Hierarchy only supports termination meter.");
15716 next_policy = mlx5_flow_meter_policy_find(dev,
15717 next_fm->policy_id, NULL);
15718 MLX5_ASSERT(next_policy);
15719 if (next_fm->drop_cnt) {
15722 mlx5_flow_get_reg_id(dev,
15725 (struct rte_flow_error *)error);
15726 set_tag.offset = (priv->mtr_reg_share ?
15727 MLX5_MTR_COLOR_BITS : 0);
15728 set_tag.length = (priv->mtr_reg_share ?
15729 MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
15731 set_tag.data = next_mtr_idx;
15733 (enum rte_flow_action_type)
15734 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
15735 tag_action.conf = &set_tag;
15736 if (flow_dv_convert_action_set_reg
15737 (mhdr_res, &tag_action,
15738 (struct rte_flow_error *)error))
15741 MLX5_FLOW_ACTION_SET_TAG;
15743 act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
15744 act_cnt->next_mtr_id = next_fm->meter_id;
15745 act_cnt->next_sub_policy = NULL;
15746 mtr_policy->is_hierarchy = 1;
15747 mtr_policy->dev = next_policy->dev;
15749 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
15753 return -rte_mtr_error_set(error, ENOTSUP,
15754 RTE_MTR_ERROR_TYPE_METER_POLICY,
15755 NULL, "action type not supported");
15757 if (action_flags & MLX5_FLOW_ACTION_SET_TAG) {
15758 /* create modify action if needed. */
15759 dev_flow.dv.group = 1;
15760 if (flow_dv_modify_hdr_resource_register
15761 (dev, mhdr_res, &dev_flow, &flow_err))
15762 return -rte_mtr_error_set(error,
15764 RTE_MTR_ERROR_TYPE_METER_POLICY,
15765 NULL, "cannot register policy "
15767 act_cnt->modify_hdr =
15768 dev_flow.handle->dvh.modify_hdr;
15776 * Create policy action per domain, lock free,
15777 * (mutex should be acquired by caller).
15778 * Dispatcher for action type specific call.
15781 * Pointer to the Ethernet device structure.
15782 * @param[in] mtr_policy
15783 * Meter policy struct.
15784 * @param[in] action
15785 * Action specification used to create meter actions.
15786 * @param[out] error
15787 * Perform verbose error reporting if not NULL. Initialized in case of
15791 * 0 on success, otherwise negative errno value.
15794 flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
15795 struct mlx5_flow_meter_policy *mtr_policy,
15796 const struct rte_flow_action *actions[RTE_COLORS],
15797 struct rte_mtr_error *error)
15800 uint16_t sub_policy_num;
15802 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15803 sub_policy_num = (mtr_policy->sub_policy_num >>
15804 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15805 MLX5_MTR_SUB_POLICY_NUM_MASK;
15806 if (sub_policy_num) {
15807 ret = __flow_dv_create_domain_policy_acts(dev,
15808 mtr_policy, actions,
15809 (enum mlx5_meter_domain)i, error);
15810 /* Cleaning resource is done in the caller level. */
15819 * Query a DV flow rule for its statistics via DevX.
15822 * Pointer to Ethernet device.
15823 * @param[in] cnt_idx
15824 * Index to the flow counter.
15826 * Data retrieved by the query.
15827 * @param[out] error
15828 * Perform verbose error reporting if not NULL.
15831 * 0 on success, a negative errno value otherwise and rte_errno is set.
15834 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
15835 struct rte_flow_error *error)
15837 struct mlx5_priv *priv = dev->data->dev_private;
15838 struct rte_flow_query_count *qc = data;
15840 if (!priv->sh->cdev->config.devx)
15841 return rte_flow_error_set(error, ENOTSUP,
15842 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15844 "counters are not supported");
15846 uint64_t pkts, bytes;
15847 struct mlx5_flow_counter *cnt;
15848 int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
15851 return rte_flow_error_set(error, -err,
15852 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15853 NULL, "cannot read counters");
15854 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
15857 qc->hits = pkts - cnt->hits;
15858 qc->bytes = bytes - cnt->bytes;
15861 cnt->bytes = bytes;
15865 return rte_flow_error_set(error, EINVAL,
15866 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15868 "counters are not available");
15872 flow_dv_action_query(struct rte_eth_dev *dev,
15873 const struct rte_flow_action_handle *handle, void *data,
15874 struct rte_flow_error *error)
15876 struct mlx5_age_param *age_param;
15877 struct rte_flow_query_age *resp;
15878 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15879 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15880 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15881 struct mlx5_priv *priv = dev->data->dev_private;
15882 struct mlx5_aso_ct_action *ct;
15887 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15888 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
15890 resp->aged = __atomic_load_n(&age_param->state,
15891 __ATOMIC_RELAXED) == AGE_TMOUT ?
15893 resp->sec_since_last_hit_valid = !resp->aged;
15894 if (resp->sec_since_last_hit_valid)
15895 resp->sec_since_last_hit = __atomic_load_n
15896 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15898 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15899 return flow_dv_query_count(dev, idx, data, error);
15900 case MLX5_INDIRECT_ACTION_TYPE_CT:
15901 owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15902 if (owner != PORT_ID(priv))
15903 return rte_flow_error_set(error, EACCES,
15904 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15906 "CT object owned by another port");
15907 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15908 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15911 return rte_flow_error_set(error, EFAULT,
15912 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15914 "CT object is inactive");
15915 ((struct rte_flow_action_conntrack *)data)->peer_port =
15917 ((struct rte_flow_action_conntrack *)data)->is_original_dir =
15919 if (mlx5_aso_ct_query_by_wqe(priv->sh, ct, data))
15920 return rte_flow_error_set(error, EIO,
15921 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15923 "Failed to query CT context");
15926 return rte_flow_error_set(error, ENOTSUP,
15927 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15928 "action type query not supported");
15933 * Query a flow rule AGE action for aging information.
15936 * Pointer to Ethernet device.
15938 * Pointer to the sub flow.
15940 * data retrieved by the query.
15941 * @param[out] error
15942 * Perform verbose error reporting if not NULL.
15945 * 0 on success, a negative errno value otherwise and rte_errno is set.
15948 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
15949 void *data, struct rte_flow_error *error)
15951 struct rte_flow_query_age *resp = data;
15952 struct mlx5_age_param *age_param;
15955 struct mlx5_aso_age_action *act =
15956 flow_aso_age_get_by_idx(dev, flow->age);
15958 age_param = &act->age_params;
15959 } else if (flow->counter) {
15960 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
15962 if (!age_param || !age_param->timeout)
15963 return rte_flow_error_set
15965 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15966 NULL, "cannot read age data");
15968 return rte_flow_error_set(error, EINVAL,
15969 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15970 NULL, "age data not available");
15972 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
15974 resp->sec_since_last_hit_valid = !resp->aged;
15975 if (resp->sec_since_last_hit_valid)
15976 resp->sec_since_last_hit = __atomic_load_n
15977 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15984 * @see rte_flow_query()
15985 * @see rte_flow_ops
15988 flow_dv_query(struct rte_eth_dev *dev,
15989 struct rte_flow *flow __rte_unused,
15990 const struct rte_flow_action *actions __rte_unused,
15991 void *data __rte_unused,
15992 struct rte_flow_error *error __rte_unused)
15996 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
15997 switch (actions->type) {
15998 case RTE_FLOW_ACTION_TYPE_VOID:
16000 case RTE_FLOW_ACTION_TYPE_COUNT:
16001 ret = flow_dv_query_count(dev, flow->counter, data,
16004 case RTE_FLOW_ACTION_TYPE_AGE:
16005 ret = flow_dv_query_age(dev, flow, data, error);
16008 return rte_flow_error_set(error, ENOTSUP,
16009 RTE_FLOW_ERROR_TYPE_ACTION,
16011 "action not supported");
16018 * Destroy the meter table set.
16019 * Lock free, (mutex should be acquired by caller).
16022 * Pointer to Ethernet device.
16024 * Meter information table.
16027 flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
16028 struct mlx5_flow_meter_info *fm)
16030 struct mlx5_priv *priv = dev->data->dev_private;
16033 if (!fm || !priv->sh->config.dv_flow_en)
16035 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16036 if (fm->drop_rule[i]) {
16037 claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
16038 fm->drop_rule[i] = NULL;
16044 flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
16046 struct mlx5_priv *priv = dev->data->dev_private;
16047 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16048 struct mlx5_flow_tbl_data_entry *tbl;
16051 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16052 if (mtrmng->def_rule[i]) {
16053 claim_zero(mlx5_flow_os_destroy_flow
16054 (mtrmng->def_rule[i]));
16055 mtrmng->def_rule[i] = NULL;
16057 if (mtrmng->def_matcher[i]) {
16058 tbl = container_of(mtrmng->def_matcher[i]->tbl,
16059 struct mlx5_flow_tbl_data_entry, tbl);
16060 mlx5_list_unregister(tbl->matchers,
16061 &mtrmng->def_matcher[i]->entry);
16062 mtrmng->def_matcher[i] = NULL;
16064 for (j = 0; j < MLX5_REG_BITS; j++) {
16065 if (mtrmng->drop_matcher[i][j]) {
16067 container_of(mtrmng->drop_matcher[i][j]->tbl,
16068 struct mlx5_flow_tbl_data_entry,
16070 mlx5_list_unregister(tbl->matchers,
16071 &mtrmng->drop_matcher[i][j]->entry);
16072 mtrmng->drop_matcher[i][j] = NULL;
16075 if (mtrmng->drop_tbl[i]) {
16076 flow_dv_tbl_resource_release(MLX5_SH(dev),
16077 mtrmng->drop_tbl[i]);
16078 mtrmng->drop_tbl[i] = NULL;
16083 /* Number of meter flow actions, count and jump or count and drop. */
16084 #define METER_ACTIONS 2
16087 __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
16088 enum mlx5_meter_domain domain)
16090 struct mlx5_priv *priv = dev->data->dev_private;
16091 struct mlx5_flow_meter_def_policy *def_policy =
16092 priv->sh->mtrmng->def_policy[domain];
16094 __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
16095 mlx5_free(def_policy);
16096 priv->sh->mtrmng->def_policy[domain] = NULL;
16100 * Destroy the default policy table set.
16103 * Pointer to Ethernet device.
16106 flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
16108 struct mlx5_priv *priv = dev->data->dev_private;
16111 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
16112 if (priv->sh->mtrmng->def_policy[i])
16113 __flow_dv_destroy_domain_def_policy(dev,
16114 (enum mlx5_meter_domain)i);
16115 priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
16119 __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
16120 uint32_t color_reg_c_idx,
16121 enum rte_color color, void *matcher_object,
16122 int actions_n, void *actions,
16123 bool match_src_port, const struct rte_flow_item *item,
16124 void **rule, const struct rte_flow_attr *attr)
16127 struct mlx5_flow_dv_match_params value = {
16128 .size = sizeof(value.buf),
16130 struct mlx5_flow_dv_match_params matcher = {
16131 .size = sizeof(matcher.buf),
16133 struct mlx5_priv *priv = dev->data->dev_private;
16136 if (match_src_port && priv->sh->esw_mode) {
16137 if (flow_dv_translate_item_port_id(dev, matcher.buf,
16138 value.buf, item, attr)) {
16139 DRV_LOG(ERR, "Failed to create meter policy%d flow's"
16140 " value with port.", color);
16144 flow_dv_match_meta_reg(matcher.buf, value.buf,
16145 (enum modify_reg)color_reg_c_idx,
16146 rte_col_2_mlx5_col(color), UINT32_MAX);
16147 misc_mask = flow_dv_matcher_enable(value.buf);
16148 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16149 ret = mlx5_flow_os_create_flow(matcher_object, (void *)&value,
16150 actions_n, actions, rule);
16152 DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
16159 __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
16160 uint32_t color_reg_c_idx,
16162 struct mlx5_flow_meter_sub_policy *sub_policy,
16163 const struct rte_flow_attr *attr,
16164 bool match_src_port,
16165 const struct rte_flow_item *item,
16166 struct mlx5_flow_dv_matcher **policy_matcher,
16167 struct rte_flow_error *error)
16169 struct mlx5_list_entry *entry;
16170 struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
16171 struct mlx5_flow_dv_matcher matcher = {
16173 .size = sizeof(matcher.mask.buf),
16177 struct mlx5_flow_dv_match_params value = {
16178 .size = sizeof(value.buf),
16180 struct mlx5_flow_cb_ctx ctx = {
16184 struct mlx5_flow_tbl_data_entry *tbl_data;
16185 struct mlx5_priv *priv = dev->data->dev_private;
16186 const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
16188 if (match_src_port && priv->sh->esw_mode) {
16189 if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
16190 value.buf, item, attr)) {
16191 DRV_LOG(ERR, "Failed to register meter policy%d matcher"
16192 " with port.", priority);
16196 tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
16197 if (priority < RTE_COLOR_RED)
16198 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16199 (enum modify_reg)color_reg_c_idx, 0, color_mask);
16200 matcher.priority = priority;
16201 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
16202 matcher.mask.size);
16203 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16205 DRV_LOG(ERR, "Failed to register meter drop matcher.");
16209 container_of(entry, struct mlx5_flow_dv_matcher, entry);
16214 * Create the policy rules per domain.
16217 * Pointer to Ethernet device.
16218 * @param[in] sub_policy
16219 * Pointer to sub policy table..
16220 * @param[in] egress
16221 * Direction of the table.
16222 * @param[in] transfer
16223 * E-Switch or NIC flow.
16225 * Pointer to policy action list per color.
16228 * 0 on success, -1 otherwise.
16231 __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
16232 struct mlx5_flow_meter_sub_policy *sub_policy,
16233 uint8_t egress, uint8_t transfer, bool match_src_port,
16234 struct mlx5_meter_policy_acts acts[RTE_COLORS])
16236 struct mlx5_priv *priv = dev->data->dev_private;
16237 struct rte_flow_error flow_err;
16238 uint32_t color_reg_c_idx;
16239 struct rte_flow_attr attr = {
16240 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
16243 .egress = !!egress,
16244 .transfer = !!transfer,
16248 int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
16249 struct mlx5_sub_policy_color_rule *color_rule;
16251 struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
16255 /* Create policy table with POLICY level. */
16256 if (!sub_policy->tbl_rsc)
16257 sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
16258 MLX5_FLOW_TABLE_LEVEL_POLICY,
16259 egress, transfer, false, NULL, 0, 0,
16260 sub_policy->idx, &flow_err);
16261 if (!sub_policy->tbl_rsc) {
16263 "Failed to create meter sub policy table.");
16266 /* Prepare matchers. */
16267 color_reg_c_idx = ret;
16268 for (i = 0; i < RTE_COLORS; i++) {
16269 TAILQ_INIT(&sub_policy->color_rules[i]);
16270 if (!acts[i].actions_n)
16272 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
16273 sizeof(struct mlx5_sub_policy_color_rule),
16276 DRV_LOG(ERR, "No memory to create color rule.");
16279 tmp_rules[i] = color_rule;
16280 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
16281 color_rule, next_port);
16282 color_rule->src_port = priv->representor_id;
16285 /* Create matchers for colors. */
16286 svport_match = (i != RTE_COLOR_RED) ? match_src_port : false;
16287 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
16288 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
16289 &attr, svport_match, NULL,
16290 &color_rule->matcher, &flow_err)) {
16291 DRV_LOG(ERR, "Failed to create color%u matcher.", i);
16294 /* Create flow, matching color. */
16295 if (__flow_dv_create_policy_flow(dev,
16296 color_reg_c_idx, (enum rte_color)i,
16297 color_rule->matcher->matcher_object,
16298 acts[i].actions_n, acts[i].dv_actions,
16299 svport_match, NULL, &color_rule->rule,
16301 DRV_LOG(ERR, "Failed to create color%u rule.", i);
16307 /* All the policy rules will be cleared. */
16309 color_rule = tmp_rules[i];
16311 if (color_rule->rule)
16312 mlx5_flow_os_destroy_flow(color_rule->rule);
16313 if (color_rule->matcher) {
16314 struct mlx5_flow_tbl_data_entry *tbl =
16315 container_of(color_rule->matcher->tbl,
16316 typeof(*tbl), tbl);
16317 mlx5_list_unregister(tbl->matchers,
16318 &color_rule->matcher->entry);
16320 TAILQ_REMOVE(&sub_policy->color_rules[i],
16321 color_rule, next_port);
16322 mlx5_free(color_rule);
16329 __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
16330 struct mlx5_flow_meter_policy *mtr_policy,
16331 struct mlx5_flow_meter_sub_policy *sub_policy,
16334 struct mlx5_priv *priv = dev->data->dev_private;
16335 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16336 struct mlx5_flow_dv_tag_resource *tag;
16337 struct mlx5_flow_dv_port_id_action_resource *port_action;
16338 struct mlx5_hrxq *hrxq;
16339 struct mlx5_flow_meter_info *next_fm = NULL;
16340 struct mlx5_flow_meter_policy *next_policy;
16341 struct mlx5_flow_meter_sub_policy *next_sub_policy;
16342 struct mlx5_flow_tbl_data_entry *tbl_data;
16343 struct rte_flow_error error;
16344 uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16345 uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16346 bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
16347 bool match_src_port = false;
16350 /* If RSS or Queue, no previous actions / rules is created. */
16351 for (i = 0; i < RTE_COLORS; i++) {
16352 acts[i].actions_n = 0;
16353 if (i == RTE_COLOR_RED) {
16354 /* Only support drop on red. */
16355 acts[i].dv_actions[0] =
16356 mtr_policy->dr_drop_action[domain];
16357 acts[i].actions_n = 1;
16360 if (i == RTE_COLOR_GREEN &&
16361 mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
16362 struct rte_flow_attr attr = {
16363 .transfer = transfer
16366 next_fm = mlx5_flow_meter_find(priv,
16367 mtr_policy->act_cnt[i].next_mtr_id,
16371 "Failed to get next hierarchy meter.");
16374 if (mlx5_flow_meter_attach(priv, next_fm,
16376 DRV_LOG(ERR, "%s", error.message);
16380 /* Meter action must be the first for TX. */
16382 acts[i].dv_actions[acts[i].actions_n] =
16383 next_fm->meter_action;
16384 acts[i].actions_n++;
16387 if (mtr_policy->act_cnt[i].rix_mark) {
16388 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
16389 mtr_policy->act_cnt[i].rix_mark);
16391 DRV_LOG(ERR, "Failed to find "
16392 "mark action for policy.");
16395 acts[i].dv_actions[acts[i].actions_n] = tag->action;
16396 acts[i].actions_n++;
16398 if (mtr_policy->act_cnt[i].modify_hdr) {
16399 acts[i].dv_actions[acts[i].actions_n] =
16400 mtr_policy->act_cnt[i].modify_hdr->action;
16401 acts[i].actions_n++;
16403 if (mtr_policy->act_cnt[i].fate_action) {
16404 switch (mtr_policy->act_cnt[i].fate_action) {
16405 case MLX5_FLOW_FATE_PORT_ID:
16406 port_action = mlx5_ipool_get
16407 (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
16408 mtr_policy->act_cnt[i].rix_port_id_action);
16409 if (!port_action) {
16410 DRV_LOG(ERR, "Failed to find "
16411 "port action for policy.");
16414 acts[i].dv_actions[acts[i].actions_n] =
16415 port_action->action;
16416 acts[i].actions_n++;
16417 mtr_policy->dev = dev;
16418 match_src_port = true;
16420 case MLX5_FLOW_FATE_DROP:
16421 case MLX5_FLOW_FATE_JUMP:
16422 acts[i].dv_actions[acts[i].actions_n] =
16423 mtr_policy->act_cnt[i].dr_jump_action[domain];
16424 acts[i].actions_n++;
16426 case MLX5_FLOW_FATE_SHARED_RSS:
16427 case MLX5_FLOW_FATE_QUEUE:
16428 hrxq = mlx5_ipool_get
16429 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16430 sub_policy->rix_hrxq[i]);
16432 DRV_LOG(ERR, "Failed to find "
16433 "queue action for policy.");
16436 acts[i].dv_actions[acts[i].actions_n] =
16438 acts[i].actions_n++;
16440 case MLX5_FLOW_FATE_MTR:
16443 "No next hierarchy meter.");
16447 acts[i].dv_actions[acts[i].actions_n] =
16448 next_fm->meter_action;
16449 acts[i].actions_n++;
16451 if (mtr_policy->act_cnt[i].next_sub_policy) {
16453 mtr_policy->act_cnt[i].next_sub_policy;
16456 mlx5_flow_meter_policy_find(dev,
16457 next_fm->policy_id, NULL);
16458 MLX5_ASSERT(next_policy);
16460 next_policy->sub_policys[domain][0];
16463 container_of(next_sub_policy->tbl_rsc,
16464 struct mlx5_flow_tbl_data_entry, tbl);
16465 acts[i].dv_actions[acts[i].actions_n++] =
16466 tbl_data->jump.action;
16467 if (mtr_policy->act_cnt[i].modify_hdr)
16468 match_src_port = !!transfer;
16471 /*Queue action do nothing*/
16476 if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
16477 egress, transfer, match_src_port, acts)) {
16479 "Failed to create policy rules per domain.");
16485 mlx5_flow_meter_detach(priv, next_fm);
16490 * Create the policy rules.
16493 * Pointer to Ethernet device.
16494 * @param[in,out] mtr_policy
16495 * Pointer to meter policy table.
16498 * 0 on success, -1 otherwise.
16501 flow_dv_create_policy_rules(struct rte_eth_dev *dev,
16502 struct mlx5_flow_meter_policy *mtr_policy)
16505 uint16_t sub_policy_num;
16507 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16508 sub_policy_num = (mtr_policy->sub_policy_num >>
16509 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
16510 MLX5_MTR_SUB_POLICY_NUM_MASK;
16511 if (!sub_policy_num)
16513 /* Prepare actions list and create policy rules. */
16514 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16515 mtr_policy->sub_policys[i][0], i)) {
16516 DRV_LOG(ERR, "Failed to create policy action "
16517 "list per domain.");
16525 __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
16527 struct mlx5_priv *priv = dev->data->dev_private;
16528 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16529 struct mlx5_flow_meter_def_policy *def_policy;
16530 struct mlx5_flow_tbl_resource *jump_tbl;
16531 struct mlx5_flow_tbl_data_entry *tbl_data;
16532 uint8_t egress, transfer;
16533 struct rte_flow_error error;
16534 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16537 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16538 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16539 def_policy = mtrmng->def_policy[domain];
16541 def_policy = mlx5_malloc(MLX5_MEM_ZERO,
16542 sizeof(struct mlx5_flow_meter_def_policy),
16543 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
16545 DRV_LOG(ERR, "Failed to alloc default policy table.");
16546 goto def_policy_error;
16548 mtrmng->def_policy[domain] = def_policy;
16549 /* Create the meter suffix table with SUFFIX level. */
16550 jump_tbl = flow_dv_tbl_resource_get(dev,
16551 MLX5_FLOW_TABLE_LEVEL_METER,
16552 egress, transfer, false, NULL, 0,
16553 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
16556 "Failed to create meter suffix table.");
16557 goto def_policy_error;
16559 def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
16560 tbl_data = container_of(jump_tbl,
16561 struct mlx5_flow_tbl_data_entry, tbl);
16562 def_policy->dr_jump_action[RTE_COLOR_GREEN] =
16563 tbl_data->jump.action;
16564 acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
16565 acts[RTE_COLOR_GREEN].actions_n = 1;
16567 * YELLOW has the same default policy as GREEN does.
16568 * G & Y share the same table and action. The 2nd time of table
16569 * resource getting is just to update the reference count for
16570 * the releasing stage.
16572 jump_tbl = flow_dv_tbl_resource_get(dev,
16573 MLX5_FLOW_TABLE_LEVEL_METER,
16574 egress, transfer, false, NULL, 0,
16575 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
16578 "Failed to get meter suffix table.");
16579 goto def_policy_error;
16581 def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
16582 tbl_data = container_of(jump_tbl,
16583 struct mlx5_flow_tbl_data_entry, tbl);
16584 def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
16585 tbl_data->jump.action;
16586 acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
16587 acts[RTE_COLOR_YELLOW].actions_n = 1;
16588 /* Create jump action to the drop table. */
16589 if (!mtrmng->drop_tbl[domain]) {
16590 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
16591 (dev, MLX5_FLOW_TABLE_LEVEL_METER,
16592 egress, transfer, false, NULL, 0,
16593 0, MLX5_MTR_TABLE_ID_DROP, &error);
16594 if (!mtrmng->drop_tbl[domain]) {
16595 DRV_LOG(ERR, "Failed to create meter "
16596 "drop table for default policy.");
16597 goto def_policy_error;
16600 /* all RED: unique Drop table for jump action. */
16601 tbl_data = container_of(mtrmng->drop_tbl[domain],
16602 struct mlx5_flow_tbl_data_entry, tbl);
16603 def_policy->dr_jump_action[RTE_COLOR_RED] =
16604 tbl_data->jump.action;
16605 acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
16606 acts[RTE_COLOR_RED].actions_n = 1;
16607 /* Create default policy rules. */
16608 ret = __flow_dv_create_domain_policy_rules(dev,
16609 &def_policy->sub_policy,
16610 egress, transfer, false, acts);
16612 DRV_LOG(ERR, "Failed to create default policy rules.");
16613 goto def_policy_error;
16618 __flow_dv_destroy_domain_def_policy(dev,
16619 (enum mlx5_meter_domain)domain);
16624 * Create the default policy table set.
16627 * Pointer to Ethernet device.
16629 * 0 on success, -1 otherwise.
16632 flow_dv_create_def_policy(struct rte_eth_dev *dev)
16634 struct mlx5_priv *priv = dev->data->dev_private;
16637 /* Non-termination policy table. */
16638 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16639 if (!priv->sh->config.dv_esw_en &&
16640 i == MLX5_MTR_DOMAIN_TRANSFER)
16642 if (__flow_dv_create_domain_def_policy(dev, i)) {
16643 DRV_LOG(ERR, "Failed to create default policy");
16644 /* Rollback the created default policies for others. */
16645 flow_dv_destroy_def_policy(dev);
16653 * Create the needed meter tables.
16654 * Lock free, (mutex should be acquired by caller).
16657 * Pointer to Ethernet device.
16659 * Meter information table.
16660 * @param[in] mtr_idx
16662 * @param[in] domain_bitmap
16665 * 0 on success, -1 otherwise.
16668 flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
16669 struct mlx5_flow_meter_info *fm,
16671 uint8_t domain_bitmap)
16673 struct mlx5_priv *priv = dev->data->dev_private;
16674 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16675 struct rte_flow_error error;
16676 struct mlx5_flow_tbl_data_entry *tbl_data;
16677 uint8_t egress, transfer;
16678 void *actions[METER_ACTIONS];
16679 int domain, ret, i;
16680 struct mlx5_flow_counter *cnt;
16681 struct mlx5_flow_dv_match_params value = {
16682 .size = sizeof(value.buf),
16684 struct mlx5_flow_dv_match_params matcher_para = {
16685 .size = sizeof(matcher_para.buf),
16687 int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
16689 uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
16690 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
16691 struct mlx5_list_entry *entry;
16692 struct mlx5_flow_dv_matcher matcher = {
16694 .size = sizeof(matcher.mask.buf),
16697 struct mlx5_flow_dv_matcher *drop_matcher;
16698 struct mlx5_flow_cb_ctx ctx = {
16704 if (!priv->mtr_en || mtr_id_reg_c < 0) {
16705 rte_errno = ENOTSUP;
16708 for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
16709 if (!(domain_bitmap & (1 << domain)) ||
16710 (mtrmng->def_rule[domain] && !fm->drop_cnt))
16712 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16713 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16714 /* Create the drop table with METER DROP level. */
16715 if (!mtrmng->drop_tbl[domain]) {
16716 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
16717 MLX5_FLOW_TABLE_LEVEL_METER,
16718 egress, transfer, false, NULL, 0,
16719 0, MLX5_MTR_TABLE_ID_DROP, &error);
16720 if (!mtrmng->drop_tbl[domain]) {
16721 DRV_LOG(ERR, "Failed to create meter drop table.");
16725 /* Create default matcher in drop table. */
16726 matcher.tbl = mtrmng->drop_tbl[domain],
16727 tbl_data = container_of(mtrmng->drop_tbl[domain],
16728 struct mlx5_flow_tbl_data_entry, tbl);
16729 if (!mtrmng->def_matcher[domain]) {
16730 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16731 (enum modify_reg)mtr_id_reg_c,
16733 matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
16734 matcher.crc = rte_raw_cksum
16735 ((const void *)matcher.mask.buf,
16736 matcher.mask.size);
16737 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16739 DRV_LOG(ERR, "Failed to register meter "
16740 "drop default matcher.");
16743 mtrmng->def_matcher[domain] = container_of(entry,
16744 struct mlx5_flow_dv_matcher, entry);
16746 /* Create default rule in drop table. */
16747 if (!mtrmng->def_rule[domain]) {
16749 actions[i++] = priv->sh->dr_drop_action;
16750 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16751 (enum modify_reg)mtr_id_reg_c, 0, 0);
16752 misc_mask = flow_dv_matcher_enable(value.buf);
16753 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16754 ret = mlx5_flow_os_create_flow
16755 (mtrmng->def_matcher[domain]->matcher_object,
16756 (void *)&value, i, actions,
16757 &mtrmng->def_rule[domain]);
16759 DRV_LOG(ERR, "Failed to create meter "
16760 "default drop rule for drop table.");
16766 MLX5_ASSERT(mtrmng->max_mtr_bits);
16767 if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
16768 /* Create matchers for Drop. */
16769 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16770 (enum modify_reg)mtr_id_reg_c, 0,
16771 (mtr_id_mask << mtr_id_offset));
16772 matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
16773 matcher.crc = rte_raw_cksum
16774 ((const void *)matcher.mask.buf,
16775 matcher.mask.size);
16776 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16779 "Failed to register meter drop matcher.");
16782 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
16783 container_of(entry, struct mlx5_flow_dv_matcher,
16787 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
16788 /* Create drop rule, matching meter_id only. */
16789 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16790 (enum modify_reg)mtr_id_reg_c,
16791 (mtr_idx << mtr_id_offset), UINT32_MAX);
16793 cnt = flow_dv_counter_get_by_idx(dev,
16794 fm->drop_cnt, NULL);
16795 actions[i++] = cnt->action;
16796 actions[i++] = priv->sh->dr_drop_action;
16797 misc_mask = flow_dv_matcher_enable(value.buf);
16798 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16799 ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
16800 (void *)&value, i, actions,
16801 &fm->drop_rule[domain]);
16803 DRV_LOG(ERR, "Failed to create meter "
16804 "drop rule for drop table.");
16810 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16811 if (fm->drop_rule[i]) {
16812 claim_zero(mlx5_flow_os_destroy_flow
16813 (fm->drop_rule[i]));
16814 fm->drop_rule[i] = NULL;
16820 static struct mlx5_flow_meter_sub_policy *
16821 __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
16822 struct mlx5_flow_meter_policy *mtr_policy,
16823 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
16824 struct mlx5_flow_meter_sub_policy *next_sub_policy,
16827 struct mlx5_priv *priv = dev->data->dev_private;
16828 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16829 uint32_t sub_policy_idx = 0;
16830 uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
16832 struct mlx5_hrxq *hrxq;
16833 struct mlx5_flow_handle dh;
16834 struct mlx5_meter_policy_action_container *act_cnt;
16835 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16836 uint16_t sub_policy_num;
16837 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
16840 rte_spinlock_lock(&mtr_policy->sl);
16841 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16844 hrxq_idx[i] = mlx5_hrxq_get(dev, rss_desc[i]);
16845 if (!hrxq_idx[i]) {
16846 rte_spinlock_unlock(&mtr_policy->sl);
16850 sub_policy_num = (mtr_policy->sub_policy_num >>
16851 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16852 MLX5_MTR_SUB_POLICY_NUM_MASK;
16853 for (j = 0; j < sub_policy_num; j++) {
16854 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16857 mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
16860 if (i >= MLX5_MTR_RTE_COLORS) {
16862 * Found the sub policy table with
16863 * the same queue per color.
16865 rte_spinlock_unlock(&mtr_policy->sl);
16866 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
16867 mlx5_hrxq_release(dev, hrxq_idx[i]);
16869 return mtr_policy->sub_policys[domain][j];
16872 /* Create sub policy. */
16873 if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[0]) {
16874 /* Reuse the first pre-allocated sub_policy. */
16875 sub_policy = mtr_policy->sub_policys[domain][0];
16876 sub_policy_idx = sub_policy->idx;
16878 sub_policy = mlx5_ipool_zmalloc
16879 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16882 sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
16883 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
16884 mlx5_hrxq_release(dev, hrxq_idx[i]);
16885 goto rss_sub_policy_error;
16887 sub_policy->idx = sub_policy_idx;
16888 sub_policy->main_policy = mtr_policy;
16890 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16893 sub_policy->rix_hrxq[i] = hrxq_idx[i];
16894 if (mtr_policy->is_hierarchy) {
16895 act_cnt = &mtr_policy->act_cnt[i];
16896 act_cnt->next_sub_policy = next_sub_policy;
16897 mlx5_hrxq_release(dev, hrxq_idx[i]);
16900 * Overwrite the last action from
16901 * RSS action to Queue action.
16903 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
16906 DRV_LOG(ERR, "Failed to get policy hrxq");
16907 goto rss_sub_policy_error;
16909 act_cnt = &mtr_policy->act_cnt[i];
16910 if (act_cnt->rix_mark || act_cnt->modify_hdr) {
16911 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
16912 if (act_cnt->rix_mark)
16914 dh.fate_action = MLX5_FLOW_FATE_QUEUE;
16915 dh.rix_hrxq = hrxq_idx[i];
16916 flow_drv_rxq_flags_set(dev, &dh);
16920 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16921 sub_policy, domain)) {
16922 DRV_LOG(ERR, "Failed to create policy "
16923 "rules for ingress domain.");
16924 goto rss_sub_policy_error;
16926 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16927 i = (mtr_policy->sub_policy_num >>
16928 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16929 MLX5_MTR_SUB_POLICY_NUM_MASK;
16930 if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
16931 DRV_LOG(ERR, "No free sub-policy slot.");
16932 goto rss_sub_policy_error;
16934 mtr_policy->sub_policys[domain][i] = sub_policy;
16936 mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16937 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
16938 mtr_policy->sub_policy_num |=
16939 (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16940 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
16942 rte_spinlock_unlock(&mtr_policy->sl);
16945 rss_sub_policy_error:
16947 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16948 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16949 i = (mtr_policy->sub_policy_num >>
16950 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16951 MLX5_MTR_SUB_POLICY_NUM_MASK;
16952 mtr_policy->sub_policys[domain][i] = NULL;
16953 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16957 rte_spinlock_unlock(&mtr_policy->sl);
16962 * Find the policy table for prefix table with RSS.
16965 * Pointer to Ethernet device.
16966 * @param[in] mtr_policy
16967 * Pointer to meter policy table.
16968 * @param[in] rss_desc
16969 * Pointer to rss_desc
16971 * Pointer to table set on success, NULL otherwise and rte_errno is set.
16973 static struct mlx5_flow_meter_sub_policy *
16974 flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
16975 struct mlx5_flow_meter_policy *mtr_policy,
16976 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
16978 struct mlx5_priv *priv = dev->data->dev_private;
16979 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16980 struct mlx5_flow_meter_info *next_fm;
16981 struct mlx5_flow_meter_policy *next_policy;
16982 struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
16983 struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
16984 struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
16985 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16986 bool reuse_sub_policy;
16991 /* Iterate hierarchy to get all policies in this hierarchy. */
16992 policies[i++] = mtr_policy;
16993 if (!mtr_policy->is_hierarchy)
16995 if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
16996 DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
16999 next_fm = mlx5_flow_meter_find(priv,
17000 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
17002 DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
17006 mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
17008 MLX5_ASSERT(next_policy);
17009 mtr_policy = next_policy;
17013 * From last policy to the first one in hierarchy,
17014 * create / get the sub policy for each of them.
17016 sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
17020 &reuse_sub_policy);
17022 DRV_LOG(ERR, "Failed to get the sub policy.");
17025 if (!reuse_sub_policy)
17026 sub_policies[j++] = sub_policy;
17027 next_sub_policy = sub_policy;
17032 uint16_t sub_policy_num;
17034 sub_policy = sub_policies[--j];
17035 mtr_policy = sub_policy->main_policy;
17036 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
17037 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
17038 sub_policy_num = (mtr_policy->sub_policy_num >>
17039 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17040 MLX5_MTR_SUB_POLICY_NUM_MASK;
17041 mtr_policy->sub_policys[domain][sub_policy_num - 1] =
17044 mtr_policy->sub_policy_num &=
17045 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17046 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
17047 mtr_policy->sub_policy_num |=
17048 (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17049 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
17050 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17058 * Create the sub policy tag rule for all meters in hierarchy.
17061 * Pointer to Ethernet device.
17063 * Meter information table.
17064 * @param[in] src_port
17065 * The src port this extra rule should use.
17067 * The src port match item.
17068 * @param[out] error
17069 * Perform verbose error reporting if not NULL.
17071 * 0 on success, a negative errno value otherwise and rte_errno is set.
17074 flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
17075 struct mlx5_flow_meter_info *fm,
17077 const struct rte_flow_item *item,
17078 struct rte_flow_error *error)
17080 struct mlx5_priv *priv = dev->data->dev_private;
17081 struct mlx5_flow_meter_policy *mtr_policy;
17082 struct mlx5_flow_meter_sub_policy *sub_policy;
17083 struct mlx5_flow_meter_info *next_fm = NULL;
17084 struct mlx5_flow_meter_policy *next_policy;
17085 struct mlx5_flow_meter_sub_policy *next_sub_policy;
17086 struct mlx5_flow_tbl_data_entry *tbl_data;
17087 struct mlx5_sub_policy_color_rule *color_rule;
17088 struct mlx5_meter_policy_acts acts;
17089 uint32_t color_reg_c_idx;
17090 bool mtr_first = (src_port != UINT16_MAX) ? true : false;
17091 struct rte_flow_attr attr = {
17092 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
17099 uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
17102 mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
17103 MLX5_ASSERT(mtr_policy);
17104 if (!mtr_policy->is_hierarchy)
17106 next_fm = mlx5_flow_meter_find(priv,
17107 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
17109 return rte_flow_error_set(error, EINVAL,
17110 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17111 "Failed to find next meter in hierarchy.");
17113 if (!next_fm->drop_cnt)
17115 color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
17116 sub_policy = mtr_policy->sub_policys[domain][0];
17117 for (i = 0; i < RTE_COLORS; i++) {
17118 bool rule_exist = false;
17119 struct mlx5_meter_policy_action_container *act_cnt;
17121 if (i >= RTE_COLOR_YELLOW)
17123 TAILQ_FOREACH(color_rule,
17124 &sub_policy->color_rules[i], next_port)
17125 if (color_rule->src_port == src_port) {
17131 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
17132 sizeof(struct mlx5_sub_policy_color_rule),
17135 return rte_flow_error_set(error, ENOMEM,
17136 RTE_FLOW_ERROR_TYPE_ACTION,
17137 NULL, "No memory to create tag color rule.");
17138 color_rule->src_port = src_port;
17140 next_policy = mlx5_flow_meter_policy_find(dev,
17141 next_fm->policy_id, NULL);
17142 MLX5_ASSERT(next_policy);
17143 next_sub_policy = next_policy->sub_policys[domain][0];
17144 tbl_data = container_of(next_sub_policy->tbl_rsc,
17145 struct mlx5_flow_tbl_data_entry, tbl);
17146 act_cnt = &mtr_policy->act_cnt[i];
17148 acts.dv_actions[0] = next_fm->meter_action;
17149 acts.dv_actions[1] = act_cnt->modify_hdr->action;
17151 acts.dv_actions[0] = act_cnt->modify_hdr->action;
17152 acts.dv_actions[1] = next_fm->meter_action;
17154 acts.dv_actions[2] = tbl_data->jump.action;
17155 acts.actions_n = 3;
17156 if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
17160 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
17161 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
17163 &color_rule->matcher, error)) {
17164 rte_flow_error_set(error, errno,
17165 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17166 "Failed to create hierarchy meter matcher.");
17169 if (__flow_dv_create_policy_flow(dev, color_reg_c_idx,
17171 color_rule->matcher->matcher_object,
17172 acts.actions_n, acts.dv_actions,
17174 &color_rule->rule, &attr)) {
17175 rte_flow_error_set(error, errno,
17176 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17177 "Failed to create hierarchy meter rule.");
17180 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
17181 color_rule, next_port);
17185 * Recursive call to iterate all meters in hierarchy and
17186 * create needed rules.
17188 return flow_dv_meter_hierarchy_rule_create(dev, next_fm,
17189 src_port, item, error);
17192 if (color_rule->rule)
17193 mlx5_flow_os_destroy_flow(color_rule->rule);
17194 if (color_rule->matcher) {
17195 struct mlx5_flow_tbl_data_entry *tbl =
17196 container_of(color_rule->matcher->tbl,
17197 typeof(*tbl), tbl);
17198 mlx5_list_unregister(tbl->matchers,
17199 &color_rule->matcher->entry);
17201 mlx5_free(color_rule);
17204 mlx5_flow_meter_detach(priv, next_fm);
17209 * Destroy the sub policy table with RX queue.
17212 * Pointer to Ethernet device.
17213 * @param[in] mtr_policy
17214 * Pointer to meter policy table.
17217 flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
17218 struct mlx5_flow_meter_policy *mtr_policy)
17220 struct mlx5_priv *priv = dev->data->dev_private;
17221 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
17222 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
17224 uint16_t sub_policy_num, new_policy_num;
17226 rte_spinlock_lock(&mtr_policy->sl);
17227 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17228 switch (mtr_policy->act_cnt[i].fate_action) {
17229 case MLX5_FLOW_FATE_SHARED_RSS:
17230 sub_policy_num = (mtr_policy->sub_policy_num >>
17231 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17232 MLX5_MTR_SUB_POLICY_NUM_MASK;
17233 new_policy_num = sub_policy_num;
17234 for (j = 0; j < sub_policy_num; j++) {
17236 mtr_policy->sub_policys[domain][j];
17238 __flow_dv_destroy_sub_policy_rules(dev,
17241 mtr_policy->sub_policys[domain][0]) {
17242 mtr_policy->sub_policys[domain][j] =
17245 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17251 if (new_policy_num != sub_policy_num) {
17252 mtr_policy->sub_policy_num &=
17253 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17254 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
17255 mtr_policy->sub_policy_num |=
17257 MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17258 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
17261 case MLX5_FLOW_FATE_QUEUE:
17262 sub_policy = mtr_policy->sub_policys[domain][0];
17263 __flow_dv_destroy_sub_policy_rules(dev,
17267 /*Other actions without queue and do nothing*/
17271 rte_spinlock_unlock(&mtr_policy->sl);
17274 * Check whether the DR drop action is supported on the root table or not.
17276 * Create a simple flow with DR drop action on root table to validate
17277 * if DR drop action on root table is supported or not.
17280 * Pointer to rte_eth_dev structure.
17283 * 0 on success, a negative errno value otherwise and rte_errno is set.
17286 mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
17288 struct mlx5_priv *priv = dev->data->dev_private;
17289 struct mlx5_dev_ctx_shared *sh = priv->sh;
17290 struct mlx5_flow_dv_match_params mask = {
17291 .size = sizeof(mask.buf),
17293 struct mlx5_flow_dv_match_params value = {
17294 .size = sizeof(value.buf),
17296 struct mlx5dv_flow_matcher_attr dv_attr = {
17297 .type = IBV_FLOW_ATTR_NORMAL,
17299 .match_criteria_enable = 0,
17300 .match_mask = (void *)&mask,
17302 struct mlx5_flow_tbl_resource *tbl = NULL;
17303 void *matcher = NULL;
17307 tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
17311 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17312 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17313 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
17314 tbl->obj, &matcher);
17317 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17318 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17319 &sh->dr_drop_action, &flow);
17322 * If DR drop action is not supported on root table, flow create will
17323 * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
17327 (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
17328 DRV_LOG(INFO, "DR drop action is not supported in root table.");
17330 DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
17333 claim_zero(mlx5_flow_os_destroy_flow(flow));
17336 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17338 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17343 * Validate the batch counter support in root table.
17345 * Create a simple flow with invalid counter and drop action on root table to
17346 * validate if batch counter with offset on root table is supported or not.
17349 * Pointer to rte_eth_dev structure.
17352 * 0 on success, a negative errno value otherwise and rte_errno is set.
17355 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
17357 struct mlx5_priv *priv = dev->data->dev_private;
17358 struct mlx5_dev_ctx_shared *sh = priv->sh;
17359 struct mlx5_flow_dv_match_params mask = {
17360 .size = sizeof(mask.buf),
17362 struct mlx5_flow_dv_match_params value = {
17363 .size = sizeof(value.buf),
17365 struct mlx5dv_flow_matcher_attr dv_attr = {
17366 .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
17368 .match_criteria_enable = 0,
17369 .match_mask = (void *)&mask,
17371 void *actions[2] = { 0 };
17372 struct mlx5_flow_tbl_resource *tbl = NULL;
17373 struct mlx5_devx_obj *dcs = NULL;
17374 void *matcher = NULL;
17378 tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
17382 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
17385 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
17389 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17390 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17391 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
17392 tbl->obj, &matcher);
17395 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17396 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17400 * If batch counter with offset is not supported, the driver will not
17401 * validate the invalid offset value, flow create should success.
17402 * In this case, it means batch counter is not supported in root table.
17404 * Otherwise, if flow create is failed, counter offset is supported.
17407 DRV_LOG(INFO, "Batch counter is not supported in root "
17408 "table. Switch to fallback mode.");
17409 rte_errno = ENOTSUP;
17411 claim_zero(mlx5_flow_os_destroy_flow(flow));
17413 /* Check matcher to make sure validate fail at flow create. */
17414 if (!matcher || (matcher && errno != EINVAL))
17415 DRV_LOG(ERR, "Unexpected error in counter offset "
17416 "support detection");
17420 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
17422 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17424 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17426 claim_zero(mlx5_devx_cmd_destroy(dcs));
17431 * Query a devx counter.
17434 * Pointer to the Ethernet device structure.
17436 * Index to the flow counter.
17438 * Set to clear the counter statistics.
17440 * The statistics value of packets.
17441 * @param[out] bytes
17442 * The statistics value of bytes.
17445 * 0 on success, otherwise return -1.
17448 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
17449 uint64_t *pkts, uint64_t *bytes, void **action)
17451 struct mlx5_priv *priv = dev->data->dev_private;
17452 struct mlx5_flow_counter *cnt;
17453 uint64_t inn_pkts, inn_bytes;
17456 if (!priv->sh->cdev->config.devx)
17459 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
17462 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
17464 *action = cnt->action;
17466 *pkts = inn_pkts - cnt->hits;
17467 *bytes = inn_bytes - cnt->bytes;
17469 cnt->hits = inn_pkts;
17470 cnt->bytes = inn_bytes;
17476 * Get aged-out flows.
17479 * Pointer to the Ethernet device structure.
17480 * @param[in] context
17481 * The address of an array of pointers to the aged-out flows contexts.
17482 * @param[in] nb_contexts
17483 * The length of context array pointers.
17484 * @param[out] error
17485 * Perform verbose error reporting if not NULL. Initialized in case of
17489 * how many contexts get in success, otherwise negative errno value.
17490 * if nb_contexts is 0, return the amount of all aged contexts.
17491 * if nb_contexts is not 0 , return the amount of aged flows reported
17492 * in the context array.
17493 * @note: only stub for now
17496 flow_dv_get_aged_flows(struct rte_eth_dev *dev,
17498 uint32_t nb_contexts,
17499 struct rte_flow_error *error)
17501 struct mlx5_priv *priv = dev->data->dev_private;
17502 struct mlx5_age_info *age_info;
17503 struct mlx5_age_param *age_param;
17504 struct mlx5_flow_counter *counter;
17505 struct mlx5_aso_age_action *act;
17508 if (nb_contexts && !context)
17509 return rte_flow_error_set(error, EINVAL,
17510 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17511 NULL, "empty context");
17512 age_info = GET_PORT_AGE_INFO(priv);
17513 rte_spinlock_lock(&age_info->aged_sl);
17514 LIST_FOREACH(act, &age_info->aged_aso, next) {
17517 context[nb_flows - 1] =
17518 act->age_params.context;
17519 if (!(--nb_contexts))
17523 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
17526 age_param = MLX5_CNT_TO_AGE(counter);
17527 context[nb_flows - 1] = age_param->context;
17528 if (!(--nb_contexts))
17532 rte_spinlock_unlock(&age_info->aged_sl);
17533 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
17538 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
17541 flow_dv_counter_allocate(struct rte_eth_dev *dev)
17543 return flow_dv_counter_alloc(dev, 0);
17547 * Validate indirect action.
17548 * Dispatcher for action type specific validation.
17551 * Pointer to the Ethernet device structure.
17553 * Indirect action configuration.
17554 * @param[in] action
17555 * The indirect action object to validate.
17556 * @param[out] error
17557 * Perform verbose error reporting if not NULL. Initialized in case of
17561 * 0 on success, otherwise negative errno value.
17564 flow_dv_action_validate(struct rte_eth_dev *dev,
17565 const struct rte_flow_indir_action_conf *conf,
17566 const struct rte_flow_action *action,
17567 struct rte_flow_error *err)
17569 struct mlx5_priv *priv = dev->data->dev_private;
17571 RTE_SET_USED(conf);
17572 switch (action->type) {
17573 case RTE_FLOW_ACTION_TYPE_RSS:
17575 * priv->obj_ops is set according to driver capabilities.
17576 * When DevX capabilities are
17577 * sufficient, it is set to devx_obj_ops.
17578 * Otherwise, it is set to ibv_obj_ops.
17579 * ibv_obj_ops doesn't support ind_table_modify operation.
17580 * In this case the indirect RSS action can't be used.
17582 if (priv->obj_ops.ind_table_modify == NULL)
17583 return rte_flow_error_set
17585 RTE_FLOW_ERROR_TYPE_ACTION,
17587 "Indirect RSS action not supported");
17588 return mlx5_validate_action_rss(dev, action, err);
17589 case RTE_FLOW_ACTION_TYPE_AGE:
17590 if (!priv->sh->aso_age_mng)
17591 return rte_flow_error_set(err, ENOTSUP,
17592 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17594 "Indirect age action not supported");
17595 return flow_dv_validate_action_age(0, action, dev, err);
17596 case RTE_FLOW_ACTION_TYPE_COUNT:
17597 return flow_dv_validate_action_count(dev, true, 0, err);
17598 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17599 if (!priv->sh->ct_aso_en)
17600 return rte_flow_error_set(err, ENOTSUP,
17601 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17602 "ASO CT is not supported");
17603 return mlx5_validate_action_ct(dev, action->conf, err);
17605 return rte_flow_error_set(err, ENOTSUP,
17606 RTE_FLOW_ERROR_TYPE_ACTION,
17608 "action type not supported");
17613 * Check if the RSS configurations for colors of a meter policy match
17614 * each other, except the queues.
17617 * Pointer to the first RSS flow action.
17619 * Pointer to the second RSS flow action.
17622 * 0 on match, 1 on conflict.
17625 flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
17626 const struct rte_flow_action_rss *r2)
17628 if (r1 == NULL || r2 == NULL)
17630 if (!(r1->level <= 1 && r2->level <= 1) &&
17631 !(r1->level > 1 && r2->level > 1))
17633 if (r1->types != r2->types &&
17634 !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
17635 (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
17637 if (r1->key || r2->key) {
17638 const void *key1 = r1->key ? r1->key : rss_hash_default_key;
17639 const void *key2 = r2->key ? r2->key : rss_hash_default_key;
17641 if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
17648 * Validate the meter hierarchy chain for meter policy.
17651 * Pointer to the Ethernet device structure.
17652 * @param[in] meter_id
17654 * @param[in] action_flags
17655 * Holds the actions detected until now.
17656 * @param[out] is_rss
17658 * @param[out] hierarchy_domain
17659 * The domain bitmap for hierarchy policy.
17660 * @param[out] error
17661 * Perform verbose error reporting if not NULL. Initialized in case of
17665 * 0 on success, otherwise negative errno value with error set.
17668 flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
17670 uint64_t action_flags,
17672 uint8_t *hierarchy_domain,
17673 struct rte_mtr_error *error)
17675 struct mlx5_priv *priv = dev->data->dev_private;
17676 struct mlx5_flow_meter_info *fm;
17677 struct mlx5_flow_meter_policy *policy;
17680 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
17681 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
17682 return -rte_mtr_error_set(error, EINVAL,
17683 RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
17685 "Multiple fate actions not supported.");
17686 *hierarchy_domain = 0;
17688 fm = mlx5_flow_meter_find(priv, meter_id, NULL);
17690 return -rte_mtr_error_set(error, EINVAL,
17691 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17692 "Meter not found in meter hierarchy.");
17693 if (fm->def_policy)
17694 return -rte_mtr_error_set(error, EINVAL,
17695 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17696 "Non termination meter not supported in hierarchy.");
17697 policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
17698 MLX5_ASSERT(policy);
17700 * Only inherit the supported domains of the first meter in
17702 * One meter supports at least one domain.
17704 if (!*hierarchy_domain) {
17705 if (policy->transfer)
17706 *hierarchy_domain |=
17707 MLX5_MTR_DOMAIN_TRANSFER_BIT;
17708 if (policy->ingress)
17709 *hierarchy_domain |=
17710 MLX5_MTR_DOMAIN_INGRESS_BIT;
17711 if (policy->egress)
17712 *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
17714 if (!policy->is_hierarchy) {
17715 *is_rss = policy->is_rss;
17718 meter_id = policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id;
17719 if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
17720 return -rte_mtr_error_set(error, EINVAL,
17721 RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
17722 "Exceed max hierarchy meter number.");
17728 * Validate meter policy actions.
17729 * Dispatcher for action type specific validation.
17732 * Pointer to the Ethernet device structure.
17733 * @param[in] action
17734 * The meter policy action object to validate.
17736 * Attributes of flow to determine steering domain.
17737 * @param[out] error
17738 * Perform verbose error reporting if not NULL. Initialized in case of
17742 * 0 on success, otherwise negative errno value.
17745 flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
17746 const struct rte_flow_action *actions[RTE_COLORS],
17747 struct rte_flow_attr *attr,
17749 uint8_t *domain_bitmap,
17750 uint8_t *policy_mode,
17751 struct rte_mtr_error *error)
17753 struct mlx5_priv *priv = dev->data->dev_private;
17754 struct mlx5_sh_config *dev_conf = &priv->sh->config;
17755 const struct rte_flow_action *act;
17756 uint64_t action_flags[RTE_COLORS] = {0};
17759 struct rte_flow_error flow_err;
17760 uint8_t domain_color[RTE_COLORS] = {0};
17761 uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
17762 uint8_t hierarchy_domain = 0;
17763 const struct rte_flow_action_meter *mtr;
17764 bool def_green = false;
17765 bool def_yellow = false;
17766 const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
17768 if (!dev_conf->dv_esw_en)
17769 def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
17770 *domain_bitmap = def_domain;
17771 /* Red color could only support DROP action. */
17772 if (!actions[RTE_COLOR_RED] ||
17773 actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
17774 return -rte_mtr_error_set(error, ENOTSUP,
17775 RTE_MTR_ERROR_TYPE_METER_POLICY,
17776 NULL, "Red color only supports drop action.");
17778 * Check default policy actions:
17779 * Green / Yellow: no action, Red: drop action
17780 * Either G or Y will trigger default policy actions to be created.
17782 if (!actions[RTE_COLOR_GREEN] ||
17783 actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
17785 if (!actions[RTE_COLOR_YELLOW] ||
17786 actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
17788 if (def_green && def_yellow) {
17789 *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
17791 } else if (!def_green && def_yellow) {
17792 *policy_mode = MLX5_MTR_POLICY_MODE_OG;
17793 } else if (def_green && !def_yellow) {
17794 *policy_mode = MLX5_MTR_POLICY_MODE_OY;
17796 *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
17798 /* Set to empty string in case of NULL pointer access by user. */
17799 flow_err.message = "";
17800 for (i = 0; i < RTE_COLORS; i++) {
17802 for (action_flags[i] = 0, actions_n = 0;
17803 act && act->type != RTE_FLOW_ACTION_TYPE_END;
17805 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
17806 return -rte_mtr_error_set(error, ENOTSUP,
17807 RTE_MTR_ERROR_TYPE_METER_POLICY,
17808 NULL, "too many actions");
17809 switch (act->type) {
17810 case RTE_FLOW_ACTION_TYPE_PORT_ID:
17811 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17812 if (!dev_conf->dv_esw_en)
17813 return -rte_mtr_error_set(error,
17815 RTE_MTR_ERROR_TYPE_METER_POLICY,
17816 NULL, "PORT action validate check"
17817 " fail for ESW disable");
17818 ret = flow_dv_validate_action_port_id(dev,
17820 act, attr, &flow_err);
17822 return -rte_mtr_error_set(error,
17824 RTE_MTR_ERROR_TYPE_METER_POLICY,
17825 NULL, flow_err.message ?
17827 "PORT action validate check fail");
17829 action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
17831 case RTE_FLOW_ACTION_TYPE_MARK:
17832 ret = flow_dv_validate_action_mark(dev, act,
17836 return -rte_mtr_error_set(error,
17838 RTE_MTR_ERROR_TYPE_METER_POLICY,
17839 NULL, flow_err.message ?
17841 "Mark action validate check fail");
17842 if (dev_conf->dv_xmeta_en !=
17843 MLX5_XMETA_MODE_LEGACY)
17844 return -rte_mtr_error_set(error,
17846 RTE_MTR_ERROR_TYPE_METER_POLICY,
17847 NULL, "Extend MARK action is "
17848 "not supported. Please try use "
17849 "default policy for meter.");
17850 action_flags[i] |= MLX5_FLOW_ACTION_MARK;
17853 case RTE_FLOW_ACTION_TYPE_SET_TAG:
17854 ret = flow_dv_validate_action_set_tag(dev,
17855 act, action_flags[i],
17858 return -rte_mtr_error_set(error,
17860 RTE_MTR_ERROR_TYPE_METER_POLICY,
17861 NULL, flow_err.message ?
17863 "Set tag action validate check fail");
17864 action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
17867 case RTE_FLOW_ACTION_TYPE_DROP:
17868 ret = mlx5_flow_validate_action_drop
17869 (action_flags[i], attr, &flow_err);
17871 return -rte_mtr_error_set(error,
17873 RTE_MTR_ERROR_TYPE_METER_POLICY,
17874 NULL, flow_err.message ?
17876 "Drop action validate check fail");
17877 action_flags[i] |= MLX5_FLOW_ACTION_DROP;
17880 case RTE_FLOW_ACTION_TYPE_QUEUE:
17882 * Check whether extensive
17883 * metadata feature is engaged.
17885 if (dev_conf->dv_flow_en &&
17886 (dev_conf->dv_xmeta_en !=
17887 MLX5_XMETA_MODE_LEGACY) &&
17888 mlx5_flow_ext_mreg_supported(dev))
17889 return -rte_mtr_error_set(error,
17891 RTE_MTR_ERROR_TYPE_METER_POLICY,
17892 NULL, "Queue action with meta "
17893 "is not supported. Please try use "
17894 "default policy for meter.");
17895 ret = mlx5_flow_validate_action_queue(act,
17896 action_flags[i], dev,
17899 return -rte_mtr_error_set(error,
17901 RTE_MTR_ERROR_TYPE_METER_POLICY,
17902 NULL, flow_err.message ?
17904 "Queue action validate check fail");
17905 action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
17908 case RTE_FLOW_ACTION_TYPE_RSS:
17909 if (dev_conf->dv_flow_en &&
17910 (dev_conf->dv_xmeta_en !=
17911 MLX5_XMETA_MODE_LEGACY) &&
17912 mlx5_flow_ext_mreg_supported(dev))
17913 return -rte_mtr_error_set(error,
17915 RTE_MTR_ERROR_TYPE_METER_POLICY,
17916 NULL, "RSS action with meta "
17917 "is not supported. Please try use "
17918 "default policy for meter.");
17919 ret = mlx5_validate_action_rss(dev, act,
17922 return -rte_mtr_error_set(error,
17924 RTE_MTR_ERROR_TYPE_METER_POLICY,
17925 NULL, flow_err.message ?
17927 "RSS action validate check fail");
17928 action_flags[i] |= MLX5_FLOW_ACTION_RSS;
17930 /* Either G or Y will set the RSS. */
17931 rss_color[i] = act->conf;
17933 case RTE_FLOW_ACTION_TYPE_JUMP:
17934 ret = flow_dv_validate_action_jump(dev,
17935 NULL, act, action_flags[i],
17936 attr, true, &flow_err);
17938 return -rte_mtr_error_set(error,
17940 RTE_MTR_ERROR_TYPE_METER_POLICY,
17941 NULL, flow_err.message ?
17943 "Jump action validate check fail");
17945 action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
17948 * Only the last meter in the hierarchy will support
17949 * the YELLOW color steering. Then in the meter policy
17950 * actions list, there should be no other meter inside.
17952 case RTE_FLOW_ACTION_TYPE_METER:
17953 if (i != RTE_COLOR_GREEN)
17954 return -rte_mtr_error_set(error,
17956 RTE_MTR_ERROR_TYPE_METER_POLICY,
17958 "Meter hierarchy only supports GREEN color.");
17959 if (*policy_mode != MLX5_MTR_POLICY_MODE_OG)
17960 return -rte_mtr_error_set(error,
17962 RTE_MTR_ERROR_TYPE_METER_POLICY,
17964 "No yellow policy should be provided in meter hierarchy.");
17966 ret = flow_dv_validate_policy_mtr_hierarchy(dev,
17976 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
17979 return -rte_mtr_error_set(error, ENOTSUP,
17980 RTE_MTR_ERROR_TYPE_METER_POLICY,
17982 "Doesn't support optional action");
17985 if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
17986 domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
17987 } else if ((action_flags[i] &
17988 (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
17989 (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
17991 * Only support MLX5_XMETA_MODE_LEGACY
17992 * so MARK action is only in ingress domain.
17994 domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
17996 domain_color[i] = def_domain;
17997 if (action_flags[i] &&
17998 !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
18000 ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
18002 if (action_flags[i] &
18003 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
18004 domain_color[i] &= hierarchy_domain;
18006 * Non-termination actions only support NIC Tx domain.
18007 * The adjustion should be skipped when there is no
18008 * action or only END is provided. The default domains
18009 * bit-mask is set to find the MIN intersection.
18010 * The action flags checking should also be skipped.
18012 if ((def_green && i == RTE_COLOR_GREEN) ||
18013 (def_yellow && i == RTE_COLOR_YELLOW))
18016 * Validate the drop action mutual exclusion
18017 * with other actions. Drop action is mutually-exclusive
18018 * with any other action, except for Count action.
18020 if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
18021 (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
18022 return -rte_mtr_error_set(error, ENOTSUP,
18023 RTE_MTR_ERROR_TYPE_METER_POLICY,
18024 NULL, "Drop action is mutually-exclusive "
18025 "with any other action");
18027 /* Eswitch has few restrictions on using items and actions */
18028 if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
18029 if (!mlx5_flow_ext_mreg_supported(dev) &&
18030 action_flags[i] & MLX5_FLOW_ACTION_MARK)
18031 return -rte_mtr_error_set(error, ENOTSUP,
18032 RTE_MTR_ERROR_TYPE_METER_POLICY,
18033 NULL, "unsupported action MARK");
18034 if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
18035 return -rte_mtr_error_set(error, ENOTSUP,
18036 RTE_MTR_ERROR_TYPE_METER_POLICY,
18037 NULL, "unsupported action QUEUE");
18038 if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
18039 return -rte_mtr_error_set(error, ENOTSUP,
18040 RTE_MTR_ERROR_TYPE_METER_POLICY,
18041 NULL, "unsupported action RSS");
18042 if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
18043 return -rte_mtr_error_set(error, ENOTSUP,
18044 RTE_MTR_ERROR_TYPE_METER_POLICY,
18045 NULL, "no fate action is found");
18047 if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
18048 (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
18049 if ((domain_color[i] &
18050 MLX5_MTR_DOMAIN_EGRESS_BIT))
18052 MLX5_MTR_DOMAIN_EGRESS_BIT;
18054 return -rte_mtr_error_set(error,
18056 RTE_MTR_ERROR_TYPE_METER_POLICY,
18058 "no fate action is found");
18062 /* If both colors have RSS, the attributes should be the same. */
18063 if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
18064 rss_color[RTE_COLOR_YELLOW]))
18065 return -rte_mtr_error_set(error, EINVAL,
18066 RTE_MTR_ERROR_TYPE_METER_POLICY,
18067 NULL, "policy RSS attr conflict");
18068 if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
18070 /* "domain_color[C]" is non-zero for each color, default is ALL. */
18071 if (!def_green && !def_yellow &&
18072 domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
18073 !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
18074 !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
18075 return -rte_mtr_error_set(error, EINVAL,
18076 RTE_MTR_ERROR_TYPE_METER_POLICY,
18077 NULL, "policy domains conflict");
18079 * At least one color policy is listed in the actions, the domains
18080 * to be supported should be the intersection.
18082 *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
18083 domain_color[RTE_COLOR_YELLOW];
18088 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
18090 struct mlx5_priv *priv = dev->data->dev_private;
18093 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
18094 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
18099 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
18100 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
18104 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
18105 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
18113 * Discover the number of available flow priorities
18114 * by trying to create a flow with the highest priority value
18115 * for each possible number.
18120 * List of possible number of available priorities.
18121 * @param[in] vprio_n
18122 * Size of @p vprio array.
18124 * On success, number of available flow priorities.
18125 * On failure, a negative errno-style code and rte_errno is set.
18128 flow_dv_discover_priorities(struct rte_eth_dev *dev,
18129 const uint16_t *vprio, int vprio_n)
18131 struct mlx5_priv *priv = dev->data->dev_private;
18132 struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
18133 struct rte_flow_item_eth eth;
18134 struct rte_flow_item item = {
18135 .type = RTE_FLOW_ITEM_TYPE_ETH,
18139 struct mlx5_flow_dv_matcher matcher = {
18141 .size = sizeof(matcher.mask.buf),
18144 union mlx5_flow_tbl_key tbl_key;
18145 struct mlx5_flow flow;
18147 struct rte_flow_error error;
18149 int i, err, ret = -ENOTSUP;
18152 * Prepare a flow with a catch-all pattern and a drop action.
18153 * Use drop queue, because shared drop action may be unavailable.
18155 action = priv->drop_queue.hrxq->action;
18156 if (action == NULL) {
18157 DRV_LOG(ERR, "Priority discovery requires a drop action");
18158 rte_errno = ENOTSUP;
18161 memset(&flow, 0, sizeof(flow));
18162 flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
18163 if (flow.handle == NULL) {
18164 DRV_LOG(ERR, "Cannot create flow handle");
18165 rte_errno = ENOMEM;
18168 flow.ingress = true;
18169 flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
18170 flow.dv.actions[0] = action;
18171 flow.dv.actions_n = 1;
18172 memset(ð, 0, sizeof(eth));
18173 flow_dv_translate_item_eth(matcher.mask.buf, flow.dv.value.buf,
18174 &item, /* inner */ false, /* group */ 0);
18175 matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
18176 for (i = 0; i < vprio_n; i++) {
18177 /* Configure the next proposed maximum priority. */
18178 matcher.priority = vprio[i] - 1;
18179 memset(&tbl_key, 0, sizeof(tbl_key));
18180 err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
18185 /* This action is pure SW and must always succeed. */
18186 DRV_LOG(ERR, "Cannot register matcher");
18190 /* Try to apply the flow to HW. */
18191 misc_mask = flow_dv_matcher_enable(flow.dv.value.buf);
18192 __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
18193 err = mlx5_flow_os_create_flow
18194 (flow.handle->dvh.matcher->matcher_object,
18195 (void *)&flow.dv.value, flow.dv.actions_n,
18196 flow.dv.actions, &flow.handle->drv_flow);
18198 claim_zero(mlx5_flow_os_destroy_flow
18199 (flow.handle->drv_flow));
18200 flow.handle->drv_flow = NULL;
18202 claim_zero(flow_dv_matcher_release(dev, flow.handle));
18207 mlx5_ipool_free(pool, flow.handle_idx);
18208 /* Set rte_errno if no expected priority value matched. */
18214 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
18215 .validate = flow_dv_validate,
18216 .prepare = flow_dv_prepare,
18217 .translate = flow_dv_translate,
18218 .apply = flow_dv_apply,
18219 .remove = flow_dv_remove,
18220 .destroy = flow_dv_destroy,
18221 .query = flow_dv_query,
18222 .create_mtr_tbls = flow_dv_create_mtr_tbls,
18223 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
18224 .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
18225 .create_meter = flow_dv_mtr_alloc,
18226 .free_meter = flow_dv_aso_mtr_release_to_pool,
18227 .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
18228 .create_mtr_acts = flow_dv_create_mtr_policy_acts,
18229 .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
18230 .create_policy_rules = flow_dv_create_policy_rules,
18231 .destroy_policy_rules = flow_dv_destroy_policy_rules,
18232 .create_def_policy = flow_dv_create_def_policy,
18233 .destroy_def_policy = flow_dv_destroy_def_policy,
18234 .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
18235 .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
18236 .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
18237 .counter_alloc = flow_dv_counter_allocate,
18238 .counter_free = flow_dv_counter_free,
18239 .counter_query = flow_dv_counter_query,
18240 .get_aged_flows = flow_dv_get_aged_flows,
18241 .action_validate = flow_dv_action_validate,
18242 .action_create = flow_dv_action_create,
18243 .action_destroy = flow_dv_action_destroy,
18244 .action_update = flow_dv_action_update,
18245 .action_query = flow_dv_action_query,
18246 .sync_domain = flow_dv_sync_domain,
18247 .discover_priorities = flow_dv_discover_priorities,
18248 .item_create = flow_dv_item_create,
18249 .item_release = flow_dv_item_release,
18252 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */