1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd
12 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
14 #pragma GCC diagnostic ignored "-Wpedantic"
16 #include <infiniband/verbs.h>
18 #pragma GCC diagnostic error "-Wpedantic"
21 #include <rte_common.h>
22 #include <rte_ether.h>
23 #include <rte_ethdev_driver.h>
25 #include <rte_flow_driver.h>
26 #include <rte_malloc.h>
29 #include <rte_vxlan.h>
33 #include "mlx5_defs.h"
34 #include "mlx5_glue.h"
35 #include "mlx5_flow.h"
37 #include "mlx5_rxtx.h"
39 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
41 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
42 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
45 #ifndef HAVE_MLX5DV_DR_ESWITCH
46 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
47 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
51 #ifndef HAVE_MLX5DV_DR
52 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
55 #define MLX5_ENCAPSULATION_DECISION_SIZE (sizeof(struct rte_flow_item_eth) + \
56 sizeof(struct rte_flow_item_ipv4))
57 /* VLAN header definitions */
58 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
59 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
60 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
61 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
62 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
77 * Initialize flow attributes structure according to flow items' types.
79 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
80 * mode. For tunnel mode, the items to be modified are the outermost ones.
83 * Pointer to item specification.
85 * Pointer to flow attributes structure.
88 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr)
90 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
92 case RTE_FLOW_ITEM_TYPE_IPV4:
96 case RTE_FLOW_ITEM_TYPE_IPV6:
100 case RTE_FLOW_ITEM_TYPE_UDP:
104 case RTE_FLOW_ITEM_TYPE_TCP:
116 * Convert rte_mtr_color to mlx5 color.
125 rte_col_2_mlx5_col(enum rte_color rcol)
128 case RTE_COLOR_GREEN:
129 return MLX5_FLOW_COLOR_GREEN;
130 case RTE_COLOR_YELLOW:
131 return MLX5_FLOW_COLOR_YELLOW;
133 return MLX5_FLOW_COLOR_RED;
137 return MLX5_FLOW_COLOR_UNDEFINED;
140 struct field_modify_info {
141 uint32_t size; /* Size of field in protocol header, in bytes. */
142 uint32_t offset; /* Offset of field in protocol header, in bytes. */
143 enum mlx5_modification_field id;
146 struct field_modify_info modify_eth[] = {
147 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
148 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
149 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
150 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
154 struct field_modify_info modify_vlan_out_first_vid[] = {
155 /* Size in bits !!! */
156 {12, 0, MLX5_MODI_OUT_FIRST_VID},
160 struct field_modify_info modify_ipv4[] = {
161 {1, 1, MLX5_MODI_OUT_IP_DSCP},
162 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
163 {4, 12, MLX5_MODI_OUT_SIPV4},
164 {4, 16, MLX5_MODI_OUT_DIPV4},
168 struct field_modify_info modify_ipv6[] = {
169 {1, 0, MLX5_MODI_OUT_IP_DSCP},
170 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
171 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
172 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
173 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
174 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
175 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
176 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
177 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
178 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
182 struct field_modify_info modify_udp[] = {
183 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
184 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
188 struct field_modify_info modify_tcp[] = {
189 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
190 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
191 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
192 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
197 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
198 uint8_t next_protocol, uint64_t *item_flags,
201 assert(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
202 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
203 if (next_protocol == IPPROTO_IPIP) {
204 *item_flags |= MLX5_FLOW_LAYER_IPIP;
207 if (next_protocol == IPPROTO_IPV6) {
208 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
214 * Acquire the synchronizing object to protect multithreaded access
215 * to shared dv context. Lock occurs only if context is actually
216 * shared, i.e. we have multiport IB device and representors are
220 * Pointer to the rte_eth_dev structure.
223 flow_dv_shared_lock(struct rte_eth_dev *dev)
225 struct mlx5_priv *priv = dev->data->dev_private;
226 struct mlx5_ibv_shared *sh = priv->sh;
228 if (sh->dv_refcnt > 1) {
231 ret = pthread_mutex_lock(&sh->dv_mutex);
238 flow_dv_shared_unlock(struct rte_eth_dev *dev)
240 struct mlx5_priv *priv = dev->data->dev_private;
241 struct mlx5_ibv_shared *sh = priv->sh;
243 if (sh->dv_refcnt > 1) {
246 ret = pthread_mutex_unlock(&sh->dv_mutex);
252 /* Update VLAN's VID/PCP based on input rte_flow_action.
255 * Pointer to struct rte_flow_action.
257 * Pointer to struct rte_vlan_hdr.
260 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
261 struct rte_vlan_hdr *vlan)
264 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
266 ((const struct rte_flow_action_of_set_vlan_pcp *)
267 action->conf)->vlan_pcp;
268 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
269 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
270 vlan->vlan_tci |= vlan_tci;
271 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
272 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
273 vlan->vlan_tci |= rte_be_to_cpu_16
274 (((const struct rte_flow_action_of_set_vlan_vid *)
275 action->conf)->vlan_vid);
280 * Fetch 1, 2, 3 or 4 byte field from the byte array
281 * and return as unsigned integer in host-endian format.
284 * Pointer to data array.
286 * Size of field to extract.
289 * converted field in host endian format.
291 static inline uint32_t
292 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
301 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
304 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
305 ret = (ret << 8) | *(data + sizeof(uint16_t));
308 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
319 * Convert modify-header action to DV specification.
321 * Data length of each action is determined by provided field description
322 * and the item mask. Data bit offset and width of each action is determined
323 * by provided item mask.
326 * Pointer to item specification.
328 * Pointer to field modification information.
329 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
330 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
331 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
333 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
334 * Negative offset value sets the same offset as source offset.
335 * size field is ignored, value is taken from source field.
336 * @param[in,out] resource
337 * Pointer to the modify-header resource.
339 * Type of modification.
341 * Pointer to the error structure.
344 * 0 on success, a negative errno value otherwise and rte_errno is set.
347 flow_dv_convert_modify_action(struct rte_flow_item *item,
348 struct field_modify_info *field,
349 struct field_modify_info *dcopy,
350 struct mlx5_flow_dv_modify_hdr_resource *resource,
351 uint32_t type, struct rte_flow_error *error)
353 uint32_t i = resource->actions_num;
354 struct mlx5_modification_cmd *actions = resource->actions;
357 * The item and mask are provided in big-endian format.
358 * The fields should be presented as in big-endian format either.
359 * Mask must be always present, it defines the actual field width.
369 if (i >= MLX5_MAX_MODIFY_NUM)
370 return rte_flow_error_set(error, EINVAL,
371 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
372 "too many items to modify");
373 /* Fetch variable byte size mask from the array. */
374 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
375 field->offset, field->size);
380 /* Deduce actual data width in bits from mask value. */
381 off_b = rte_bsf32(mask);
382 size_b = sizeof(uint32_t) * CHAR_BIT -
383 off_b - __builtin_clz(mask);
385 size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
386 actions[i].action_type = type;
387 actions[i].field = field->id;
388 actions[i].offset = off_b;
389 actions[i].length = size_b;
390 /* Convert entire record to expected big-endian format. */
391 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
392 if (type == MLX5_MODIFICATION_TYPE_COPY) {
394 actions[i].dst_field = dcopy->id;
395 actions[i].dst_offset =
396 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
397 /* Convert entire record to big-endian format. */
398 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
401 data = flow_dv_fetch_field((const uint8_t *)item->spec +
402 field->offset, field->size);
403 /* Shift out the trailing masked bits from data. */
404 data = (data & mask) >> off_b;
405 actions[i].data1 = rte_cpu_to_be_32(data);
409 } while (field->size);
410 if (resource->actions_num == i)
411 return rte_flow_error_set(error, EINVAL,
412 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
413 "invalid modification flow item");
414 resource->actions_num = i;
419 * Convert modify-header set IPv4 address action to DV specification.
421 * @param[in,out] resource
422 * Pointer to the modify-header resource.
424 * Pointer to action specification.
426 * Pointer to the error structure.
429 * 0 on success, a negative errno value otherwise and rte_errno is set.
432 flow_dv_convert_action_modify_ipv4
433 (struct mlx5_flow_dv_modify_hdr_resource *resource,
434 const struct rte_flow_action *action,
435 struct rte_flow_error *error)
437 const struct rte_flow_action_set_ipv4 *conf =
438 (const struct rte_flow_action_set_ipv4 *)(action->conf);
439 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
440 struct rte_flow_item_ipv4 ipv4;
441 struct rte_flow_item_ipv4 ipv4_mask;
443 memset(&ipv4, 0, sizeof(ipv4));
444 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
445 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
446 ipv4.hdr.src_addr = conf->ipv4_addr;
447 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
449 ipv4.hdr.dst_addr = conf->ipv4_addr;
450 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
453 item.mask = &ipv4_mask;
454 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
455 MLX5_MODIFICATION_TYPE_SET, error);
459 * Convert modify-header set IPv6 address action to DV specification.
461 * @param[in,out] resource
462 * Pointer to the modify-header resource.
464 * Pointer to action specification.
466 * Pointer to the error structure.
469 * 0 on success, a negative errno value otherwise and rte_errno is set.
472 flow_dv_convert_action_modify_ipv6
473 (struct mlx5_flow_dv_modify_hdr_resource *resource,
474 const struct rte_flow_action *action,
475 struct rte_flow_error *error)
477 const struct rte_flow_action_set_ipv6 *conf =
478 (const struct rte_flow_action_set_ipv6 *)(action->conf);
479 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
480 struct rte_flow_item_ipv6 ipv6;
481 struct rte_flow_item_ipv6 ipv6_mask;
483 memset(&ipv6, 0, sizeof(ipv6));
484 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
485 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
486 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
487 sizeof(ipv6.hdr.src_addr));
488 memcpy(&ipv6_mask.hdr.src_addr,
489 &rte_flow_item_ipv6_mask.hdr.src_addr,
490 sizeof(ipv6.hdr.src_addr));
492 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
493 sizeof(ipv6.hdr.dst_addr));
494 memcpy(&ipv6_mask.hdr.dst_addr,
495 &rte_flow_item_ipv6_mask.hdr.dst_addr,
496 sizeof(ipv6.hdr.dst_addr));
499 item.mask = &ipv6_mask;
500 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
501 MLX5_MODIFICATION_TYPE_SET, error);
505 * Convert modify-header set MAC address action to DV specification.
507 * @param[in,out] resource
508 * Pointer to the modify-header resource.
510 * Pointer to action specification.
512 * Pointer to the error structure.
515 * 0 on success, a negative errno value otherwise and rte_errno is set.
518 flow_dv_convert_action_modify_mac
519 (struct mlx5_flow_dv_modify_hdr_resource *resource,
520 const struct rte_flow_action *action,
521 struct rte_flow_error *error)
523 const struct rte_flow_action_set_mac *conf =
524 (const struct rte_flow_action_set_mac *)(action->conf);
525 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
526 struct rte_flow_item_eth eth;
527 struct rte_flow_item_eth eth_mask;
529 memset(ð, 0, sizeof(eth));
530 memset(ð_mask, 0, sizeof(eth_mask));
531 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
532 memcpy(ð.src.addr_bytes, &conf->mac_addr,
533 sizeof(eth.src.addr_bytes));
534 memcpy(ð_mask.src.addr_bytes,
535 &rte_flow_item_eth_mask.src.addr_bytes,
536 sizeof(eth_mask.src.addr_bytes));
538 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
539 sizeof(eth.dst.addr_bytes));
540 memcpy(ð_mask.dst.addr_bytes,
541 &rte_flow_item_eth_mask.dst.addr_bytes,
542 sizeof(eth_mask.dst.addr_bytes));
545 item.mask = ð_mask;
546 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
547 MLX5_MODIFICATION_TYPE_SET, error);
551 * Convert modify-header set VLAN VID action to DV specification.
553 * @param[in,out] resource
554 * Pointer to the modify-header resource.
556 * Pointer to action specification.
558 * Pointer to the error structure.
561 * 0 on success, a negative errno value otherwise and rte_errno is set.
564 flow_dv_convert_action_modify_vlan_vid
565 (struct mlx5_flow_dv_modify_hdr_resource *resource,
566 const struct rte_flow_action *action,
567 struct rte_flow_error *error)
569 const struct rte_flow_action_of_set_vlan_vid *conf =
570 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
571 int i = resource->actions_num;
572 struct mlx5_modification_cmd *actions = &resource->actions[i];
573 struct field_modify_info *field = modify_vlan_out_first_vid;
575 if (i >= MLX5_MAX_MODIFY_NUM)
576 return rte_flow_error_set(error, EINVAL,
577 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
578 "too many items to modify");
579 actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
580 actions[i].field = field->id;
581 actions[i].length = field->size;
582 actions[i].offset = field->offset;
583 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
584 actions[i].data1 = conf->vlan_vid;
585 actions[i].data1 = actions[i].data1 << 16;
586 resource->actions_num = ++i;
591 * Convert modify-header set TP action to DV specification.
593 * @param[in,out] resource
594 * Pointer to the modify-header resource.
596 * Pointer to action specification.
598 * Pointer to rte_flow_item objects list.
600 * Pointer to flow attributes structure.
602 * Pointer to the error structure.
605 * 0 on success, a negative errno value otherwise and rte_errno is set.
608 flow_dv_convert_action_modify_tp
609 (struct mlx5_flow_dv_modify_hdr_resource *resource,
610 const struct rte_flow_action *action,
611 const struct rte_flow_item *items,
612 union flow_dv_attr *attr,
613 struct rte_flow_error *error)
615 const struct rte_flow_action_set_tp *conf =
616 (const struct rte_flow_action_set_tp *)(action->conf);
617 struct rte_flow_item item;
618 struct rte_flow_item_udp udp;
619 struct rte_flow_item_udp udp_mask;
620 struct rte_flow_item_tcp tcp;
621 struct rte_flow_item_tcp tcp_mask;
622 struct field_modify_info *field;
625 flow_dv_attr_init(items, attr);
627 memset(&udp, 0, sizeof(udp));
628 memset(&udp_mask, 0, sizeof(udp_mask));
629 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
630 udp.hdr.src_port = conf->port;
631 udp_mask.hdr.src_port =
632 rte_flow_item_udp_mask.hdr.src_port;
634 udp.hdr.dst_port = conf->port;
635 udp_mask.hdr.dst_port =
636 rte_flow_item_udp_mask.hdr.dst_port;
638 item.type = RTE_FLOW_ITEM_TYPE_UDP;
640 item.mask = &udp_mask;
644 memset(&tcp, 0, sizeof(tcp));
645 memset(&tcp_mask, 0, sizeof(tcp_mask));
646 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
647 tcp.hdr.src_port = conf->port;
648 tcp_mask.hdr.src_port =
649 rte_flow_item_tcp_mask.hdr.src_port;
651 tcp.hdr.dst_port = conf->port;
652 tcp_mask.hdr.dst_port =
653 rte_flow_item_tcp_mask.hdr.dst_port;
655 item.type = RTE_FLOW_ITEM_TYPE_TCP;
657 item.mask = &tcp_mask;
660 return flow_dv_convert_modify_action(&item, field, NULL, resource,
661 MLX5_MODIFICATION_TYPE_SET, error);
665 * Convert modify-header set TTL action to DV specification.
667 * @param[in,out] resource
668 * Pointer to the modify-header resource.
670 * Pointer to action specification.
672 * Pointer to rte_flow_item objects list.
674 * Pointer to flow attributes structure.
676 * Pointer to the error structure.
679 * 0 on success, a negative errno value otherwise and rte_errno is set.
682 flow_dv_convert_action_modify_ttl
683 (struct mlx5_flow_dv_modify_hdr_resource *resource,
684 const struct rte_flow_action *action,
685 const struct rte_flow_item *items,
686 union flow_dv_attr *attr,
687 struct rte_flow_error *error)
689 const struct rte_flow_action_set_ttl *conf =
690 (const struct rte_flow_action_set_ttl *)(action->conf);
691 struct rte_flow_item item;
692 struct rte_flow_item_ipv4 ipv4;
693 struct rte_flow_item_ipv4 ipv4_mask;
694 struct rte_flow_item_ipv6 ipv6;
695 struct rte_flow_item_ipv6 ipv6_mask;
696 struct field_modify_info *field;
699 flow_dv_attr_init(items, attr);
701 memset(&ipv4, 0, sizeof(ipv4));
702 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
703 ipv4.hdr.time_to_live = conf->ttl_value;
704 ipv4_mask.hdr.time_to_live = 0xFF;
705 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
707 item.mask = &ipv4_mask;
711 memset(&ipv6, 0, sizeof(ipv6));
712 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
713 ipv6.hdr.hop_limits = conf->ttl_value;
714 ipv6_mask.hdr.hop_limits = 0xFF;
715 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
717 item.mask = &ipv6_mask;
720 return flow_dv_convert_modify_action(&item, field, NULL, resource,
721 MLX5_MODIFICATION_TYPE_SET, error);
725 * Convert modify-header decrement TTL action to DV specification.
727 * @param[in,out] resource
728 * Pointer to the modify-header resource.
730 * Pointer to action specification.
732 * Pointer to rte_flow_item objects list.
734 * Pointer to flow attributes structure.
736 * Pointer to the error structure.
739 * 0 on success, a negative errno value otherwise and rte_errno is set.
742 flow_dv_convert_action_modify_dec_ttl
743 (struct mlx5_flow_dv_modify_hdr_resource *resource,
744 const struct rte_flow_item *items,
745 union flow_dv_attr *attr,
746 struct rte_flow_error *error)
748 struct rte_flow_item item;
749 struct rte_flow_item_ipv4 ipv4;
750 struct rte_flow_item_ipv4 ipv4_mask;
751 struct rte_flow_item_ipv6 ipv6;
752 struct rte_flow_item_ipv6 ipv6_mask;
753 struct field_modify_info *field;
756 flow_dv_attr_init(items, attr);
758 memset(&ipv4, 0, sizeof(ipv4));
759 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
760 ipv4.hdr.time_to_live = 0xFF;
761 ipv4_mask.hdr.time_to_live = 0xFF;
762 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
764 item.mask = &ipv4_mask;
768 memset(&ipv6, 0, sizeof(ipv6));
769 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
770 ipv6.hdr.hop_limits = 0xFF;
771 ipv6_mask.hdr.hop_limits = 0xFF;
772 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
774 item.mask = &ipv6_mask;
777 return flow_dv_convert_modify_action(&item, field, NULL, resource,
778 MLX5_MODIFICATION_TYPE_ADD, error);
782 * Convert modify-header increment/decrement TCP Sequence number
783 * to DV specification.
785 * @param[in,out] resource
786 * Pointer to the modify-header resource.
788 * Pointer to action specification.
790 * Pointer to the error structure.
793 * 0 on success, a negative errno value otherwise and rte_errno is set.
796 flow_dv_convert_action_modify_tcp_seq
797 (struct mlx5_flow_dv_modify_hdr_resource *resource,
798 const struct rte_flow_action *action,
799 struct rte_flow_error *error)
801 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
802 uint64_t value = rte_be_to_cpu_32(*conf);
803 struct rte_flow_item item;
804 struct rte_flow_item_tcp tcp;
805 struct rte_flow_item_tcp tcp_mask;
807 memset(&tcp, 0, sizeof(tcp));
808 memset(&tcp_mask, 0, sizeof(tcp_mask));
809 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
811 * The HW has no decrement operation, only increment operation.
812 * To simulate decrement X from Y using increment operation
813 * we need to add UINT32_MAX X times to Y.
814 * Each adding of UINT32_MAX decrements Y by 1.
817 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
818 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
819 item.type = RTE_FLOW_ITEM_TYPE_TCP;
821 item.mask = &tcp_mask;
822 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
823 MLX5_MODIFICATION_TYPE_ADD, error);
827 * Convert modify-header increment/decrement TCP Acknowledgment number
828 * to DV specification.
830 * @param[in,out] resource
831 * Pointer to the modify-header resource.
833 * Pointer to action specification.
835 * Pointer to the error structure.
838 * 0 on success, a negative errno value otherwise and rte_errno is set.
841 flow_dv_convert_action_modify_tcp_ack
842 (struct mlx5_flow_dv_modify_hdr_resource *resource,
843 const struct rte_flow_action *action,
844 struct rte_flow_error *error)
846 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
847 uint64_t value = rte_be_to_cpu_32(*conf);
848 struct rte_flow_item item;
849 struct rte_flow_item_tcp tcp;
850 struct rte_flow_item_tcp tcp_mask;
852 memset(&tcp, 0, sizeof(tcp));
853 memset(&tcp_mask, 0, sizeof(tcp_mask));
854 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
856 * The HW has no decrement operation, only increment operation.
857 * To simulate decrement X from Y using increment operation
858 * we need to add UINT32_MAX X times to Y.
859 * Each adding of UINT32_MAX decrements Y by 1.
862 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
863 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
864 item.type = RTE_FLOW_ITEM_TYPE_TCP;
866 item.mask = &tcp_mask;
867 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
868 MLX5_MODIFICATION_TYPE_ADD, error);
871 static enum mlx5_modification_field reg_to_field[] = {
872 [REG_NONE] = MLX5_MODI_OUT_NONE,
873 [REG_A] = MLX5_MODI_META_DATA_REG_A,
874 [REG_B] = MLX5_MODI_META_DATA_REG_B,
875 [REG_C_0] = MLX5_MODI_META_REG_C_0,
876 [REG_C_1] = MLX5_MODI_META_REG_C_1,
877 [REG_C_2] = MLX5_MODI_META_REG_C_2,
878 [REG_C_3] = MLX5_MODI_META_REG_C_3,
879 [REG_C_4] = MLX5_MODI_META_REG_C_4,
880 [REG_C_5] = MLX5_MODI_META_REG_C_5,
881 [REG_C_6] = MLX5_MODI_META_REG_C_6,
882 [REG_C_7] = MLX5_MODI_META_REG_C_7,
886 * Convert register set to DV specification.
888 * @param[in,out] resource
889 * Pointer to the modify-header resource.
891 * Pointer to action specification.
893 * Pointer to the error structure.
896 * 0 on success, a negative errno value otherwise and rte_errno is set.
899 flow_dv_convert_action_set_reg
900 (struct mlx5_flow_dv_modify_hdr_resource *resource,
901 const struct rte_flow_action *action,
902 struct rte_flow_error *error)
904 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
905 struct mlx5_modification_cmd *actions = resource->actions;
906 uint32_t i = resource->actions_num;
908 if (i >= MLX5_MAX_MODIFY_NUM)
909 return rte_flow_error_set(error, EINVAL,
910 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
911 "too many items to modify");
912 assert(conf->id != REG_NONE);
913 assert(conf->id < RTE_DIM(reg_to_field));
914 actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
915 actions[i].field = reg_to_field[conf->id];
916 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
917 actions[i].data1 = rte_cpu_to_be_32(conf->data);
919 resource->actions_num = i;
924 * Convert SET_TAG action to DV specification.
927 * Pointer to the rte_eth_dev structure.
928 * @param[in,out] resource
929 * Pointer to the modify-header resource.
931 * Pointer to action specification.
933 * Pointer to the error structure.
936 * 0 on success, a negative errno value otherwise and rte_errno is set.
939 flow_dv_convert_action_set_tag
940 (struct rte_eth_dev *dev,
941 struct mlx5_flow_dv_modify_hdr_resource *resource,
942 const struct rte_flow_action_set_tag *conf,
943 struct rte_flow_error *error)
945 rte_be32_t data = rte_cpu_to_be_32(conf->data);
946 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
947 struct rte_flow_item item = {
951 struct field_modify_info reg_c_x[] = {
954 enum mlx5_modification_field reg_type;
957 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
960 assert(ret != REG_NONE);
961 assert((unsigned int)ret < RTE_DIM(reg_to_field));
962 reg_type = reg_to_field[ret];
963 assert(reg_type > 0);
964 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
965 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
966 MLX5_MODIFICATION_TYPE_SET, error);
970 * Convert internal COPY_REG action to DV specification.
973 * Pointer to the rte_eth_dev structure.
975 * Pointer to the modify-header resource.
977 * Pointer to action specification.
979 * Pointer to the error structure.
982 * 0 on success, a negative errno value otherwise and rte_errno is set.
985 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
986 struct mlx5_flow_dv_modify_hdr_resource *res,
987 const struct rte_flow_action *action,
988 struct rte_flow_error *error)
990 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
991 rte_be32_t mask = RTE_BE32(UINT32_MAX);
992 struct rte_flow_item item = {
996 struct field_modify_info reg_src[] = {
997 {4, 0, reg_to_field[conf->src]},
1000 struct field_modify_info reg_dst = {
1002 .id = reg_to_field[conf->dst],
1004 /* Adjust reg_c[0] usage according to reported mask. */
1005 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1006 struct mlx5_priv *priv = dev->data->dev_private;
1007 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1010 assert(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1011 if (conf->dst == REG_C_0) {
1012 /* Copy to reg_c[0], within mask only. */
1013 reg_dst.offset = rte_bsf32(reg_c0);
1015 * Mask is ignoring the enianness, because
1016 * there is no conversion in datapath.
1018 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1019 /* Copy from destination lower bits to reg_c[0]. */
1020 mask = reg_c0 >> reg_dst.offset;
1022 /* Copy from destination upper bits to reg_c[0]. */
1023 mask = reg_c0 << (sizeof(reg_c0) * CHAR_BIT -
1024 rte_fls_u32(reg_c0));
1027 mask = rte_cpu_to_be_32(reg_c0);
1028 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1029 /* Copy from reg_c[0] to destination lower bits. */
1032 /* Copy from reg_c[0] to destination upper bits. */
1033 reg_dst.offset = sizeof(reg_c0) * CHAR_BIT -
1034 (rte_fls_u32(reg_c0) -
1039 return flow_dv_convert_modify_action(&item,
1040 reg_src, ®_dst, res,
1041 MLX5_MODIFICATION_TYPE_COPY,
1046 * Convert MARK action to DV specification. This routine is used
1047 * in extensive metadata only and requires metadata register to be
1048 * handled. In legacy mode hardware tag resource is engaged.
1051 * Pointer to the rte_eth_dev structure.
1053 * Pointer to MARK action specification.
1054 * @param[in,out] resource
1055 * Pointer to the modify-header resource.
1057 * Pointer to the error structure.
1060 * 0 on success, a negative errno value otherwise and rte_errno is set.
1063 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1064 const struct rte_flow_action_mark *conf,
1065 struct mlx5_flow_dv_modify_hdr_resource *resource,
1066 struct rte_flow_error *error)
1068 struct mlx5_priv *priv = dev->data->dev_private;
1069 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1070 priv->sh->dv_mark_mask);
1071 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1072 struct rte_flow_item item = {
1076 struct field_modify_info reg_c_x[] = {
1077 {4, 0, 0}, /* dynamic instead of MLX5_MODI_META_REG_C_1. */
1080 enum modify_reg reg;
1083 return rte_flow_error_set(error, EINVAL,
1084 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1085 NULL, "zero mark action mask");
1086 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1090 if (reg == REG_C_0) {
1091 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1092 uint32_t shl_c0 = rte_bsf32(msk_c0);
1094 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1095 mask = rte_cpu_to_be_32(mask) & msk_c0;
1096 mask = rte_cpu_to_be_32(mask << shl_c0);
1098 reg_c_x[0].id = reg_to_field[reg];
1099 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1100 MLX5_MODIFICATION_TYPE_SET, error);
1104 * Get metadata register index for specified steering domain.
1107 * Pointer to the rte_eth_dev structure.
1109 * Attributes of flow to determine steering domain.
1111 * Pointer to the error structure.
1114 * positive index on success, a negative errno value otherwise
1115 * and rte_errno is set.
1117 static enum modify_reg
1118 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1119 const struct rte_flow_attr *attr,
1120 struct rte_flow_error *error)
1122 enum modify_reg reg =
1123 mlx5_flow_get_reg_id(dev, attr->transfer ?
1127 MLX5_METADATA_RX, 0, error);
1129 return rte_flow_error_set(error,
1130 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1131 NULL, "unavailable "
1132 "metadata register");
1137 * Convert SET_META action to DV specification.
1140 * Pointer to the rte_eth_dev structure.
1141 * @param[in,out] resource
1142 * Pointer to the modify-header resource.
1144 * Attributes of flow that includes this item.
1146 * Pointer to action specification.
1148 * Pointer to the error structure.
1151 * 0 on success, a negative errno value otherwise and rte_errno is set.
1154 flow_dv_convert_action_set_meta
1155 (struct rte_eth_dev *dev,
1156 struct mlx5_flow_dv_modify_hdr_resource *resource,
1157 const struct rte_flow_attr *attr,
1158 const struct rte_flow_action_set_meta *conf,
1159 struct rte_flow_error *error)
1161 uint32_t data = conf->data;
1162 uint32_t mask = conf->mask;
1163 struct rte_flow_item item = {
1167 struct field_modify_info reg_c_x[] = {
1170 enum modify_reg reg = flow_dv_get_metadata_reg(dev, attr, error);
1175 * In datapath code there is no endianness
1176 * coversions for perfromance reasons, all
1177 * pattern conversions are done in rte_flow.
1179 if (reg == REG_C_0) {
1180 struct mlx5_priv *priv = dev->data->dev_private;
1181 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1185 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1186 shl_c0 = rte_bsf32(msk_c0);
1188 shl_c0 = sizeof(msk_c0) * CHAR_BIT - rte_fls_u32(msk_c0);
1192 assert(!(~msk_c0 & rte_cpu_to_be_32(mask)));
1194 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1195 /* The routine expects parameters in memory as big-endian ones. */
1196 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1197 MLX5_MODIFICATION_TYPE_SET, error);
1201 * Convert modify-header set IPv4 DSCP action to DV specification.
1203 * @param[in,out] resource
1204 * Pointer to the modify-header resource.
1206 * Pointer to action specification.
1208 * Pointer to the error structure.
1211 * 0 on success, a negative errno value otherwise and rte_errno is set.
1214 flow_dv_convert_action_modify_ipv4_dscp
1215 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1216 const struct rte_flow_action *action,
1217 struct rte_flow_error *error)
1219 const struct rte_flow_action_set_dscp *conf =
1220 (const struct rte_flow_action_set_dscp *)(action->conf);
1221 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1222 struct rte_flow_item_ipv4 ipv4;
1223 struct rte_flow_item_ipv4 ipv4_mask;
1225 memset(&ipv4, 0, sizeof(ipv4));
1226 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1227 ipv4.hdr.type_of_service = conf->dscp;
1228 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1230 item.mask = &ipv4_mask;
1231 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1232 MLX5_MODIFICATION_TYPE_SET, error);
1236 * Convert modify-header set IPv6 DSCP action to DV specification.
1238 * @param[in,out] resource
1239 * Pointer to the modify-header resource.
1241 * Pointer to action specification.
1243 * Pointer to the error structure.
1246 * 0 on success, a negative errno value otherwise and rte_errno is set.
1249 flow_dv_convert_action_modify_ipv6_dscp
1250 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1251 const struct rte_flow_action *action,
1252 struct rte_flow_error *error)
1254 const struct rte_flow_action_set_dscp *conf =
1255 (const struct rte_flow_action_set_dscp *)(action->conf);
1256 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1257 struct rte_flow_item_ipv6 ipv6;
1258 struct rte_flow_item_ipv6 ipv6_mask;
1260 memset(&ipv6, 0, sizeof(ipv6));
1261 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1263 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1264 * rdma-core only accept the DSCP bits byte aligned start from
1265 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1266 * bits in IPv6 case as rdma-core requires byte aligned value.
1268 ipv6.hdr.vtc_flow = conf->dscp;
1269 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1271 item.mask = &ipv6_mask;
1272 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1273 MLX5_MODIFICATION_TYPE_SET, error);
1277 * Validate MARK item.
1280 * Pointer to the rte_eth_dev structure.
1282 * Item specification.
1284 * Attributes of flow that includes this item.
1286 * Pointer to error structure.
1289 * 0 on success, a negative errno value otherwise and rte_errno is set.
1292 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1293 const struct rte_flow_item *item,
1294 const struct rte_flow_attr *attr __rte_unused,
1295 struct rte_flow_error *error)
1297 struct mlx5_priv *priv = dev->data->dev_private;
1298 struct mlx5_dev_config *config = &priv->config;
1299 const struct rte_flow_item_mark *spec = item->spec;
1300 const struct rte_flow_item_mark *mask = item->mask;
1301 const struct rte_flow_item_mark nic_mask = {
1302 .id = priv->sh->dv_mark_mask,
1306 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1307 return rte_flow_error_set(error, ENOTSUP,
1308 RTE_FLOW_ERROR_TYPE_ITEM, item,
1309 "extended metadata feature"
1311 if (!mlx5_flow_ext_mreg_supported(dev))
1312 return rte_flow_error_set(error, ENOTSUP,
1313 RTE_FLOW_ERROR_TYPE_ITEM, item,
1314 "extended metadata register"
1315 " isn't supported");
1317 return rte_flow_error_set(error, ENOTSUP,
1318 RTE_FLOW_ERROR_TYPE_ITEM, item,
1319 "extended metadata register"
1320 " isn't available");
1321 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1325 return rte_flow_error_set(error, EINVAL,
1326 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1328 "data cannot be empty");
1329 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1330 return rte_flow_error_set(error, EINVAL,
1331 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1333 "mark id exceeds the limit");
1336 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1337 (const uint8_t *)&nic_mask,
1338 sizeof(struct rte_flow_item_mark),
1346 * Validate META item.
1349 * Pointer to the rte_eth_dev structure.
1351 * Item specification.
1353 * Attributes of flow that includes this item.
1355 * Pointer to error structure.
1358 * 0 on success, a negative errno value otherwise and rte_errno is set.
1361 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1362 const struct rte_flow_item *item,
1363 const struct rte_flow_attr *attr,
1364 struct rte_flow_error *error)
1366 struct mlx5_priv *priv = dev->data->dev_private;
1367 struct mlx5_dev_config *config = &priv->config;
1368 const struct rte_flow_item_meta *spec = item->spec;
1369 const struct rte_flow_item_meta *mask = item->mask;
1370 struct rte_flow_item_meta nic_mask = {
1373 enum modify_reg reg;
1377 return rte_flow_error_set(error, EINVAL,
1378 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1380 "data cannot be empty");
1382 return rte_flow_error_set(error, EINVAL,
1383 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1384 "data cannot be zero");
1385 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1386 if (!mlx5_flow_ext_mreg_supported(dev))
1387 return rte_flow_error_set(error, ENOTSUP,
1388 RTE_FLOW_ERROR_TYPE_ITEM, item,
1389 "extended metadata register"
1390 " isn't supported");
1391 reg = flow_dv_get_metadata_reg(dev, attr, error);
1395 return rte_flow_error_set(error, ENOTSUP,
1396 RTE_FLOW_ERROR_TYPE_ITEM, item,
1400 nic_mask.data = priv->sh->dv_meta_mask;
1403 mask = &rte_flow_item_meta_mask;
1404 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1405 (const uint8_t *)&nic_mask,
1406 sizeof(struct rte_flow_item_meta),
1412 * Validate TAG item.
1415 * Pointer to the rte_eth_dev structure.
1417 * Item specification.
1419 * Attributes of flow that includes this item.
1421 * Pointer to error structure.
1424 * 0 on success, a negative errno value otherwise and rte_errno is set.
1427 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
1428 const struct rte_flow_item *item,
1429 const struct rte_flow_attr *attr __rte_unused,
1430 struct rte_flow_error *error)
1432 const struct rte_flow_item_tag *spec = item->spec;
1433 const struct rte_flow_item_tag *mask = item->mask;
1434 const struct rte_flow_item_tag nic_mask = {
1435 .data = RTE_BE32(UINT32_MAX),
1440 if (!mlx5_flow_ext_mreg_supported(dev))
1441 return rte_flow_error_set(error, ENOTSUP,
1442 RTE_FLOW_ERROR_TYPE_ITEM, item,
1443 "extensive metadata register"
1444 " isn't supported");
1446 return rte_flow_error_set(error, EINVAL,
1447 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1449 "data cannot be empty");
1451 mask = &rte_flow_item_tag_mask;
1452 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1453 (const uint8_t *)&nic_mask,
1454 sizeof(struct rte_flow_item_tag),
1458 if (mask->index != 0xff)
1459 return rte_flow_error_set(error, EINVAL,
1460 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1461 "partial mask for tag index"
1462 " is not supported");
1463 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
1466 assert(ret != REG_NONE);
1471 * Validate vport item.
1474 * Pointer to the rte_eth_dev structure.
1476 * Item specification.
1478 * Attributes of flow that includes this item.
1479 * @param[in] item_flags
1480 * Bit-fields that holds the items detected until now.
1482 * Pointer to error structure.
1485 * 0 on success, a negative errno value otherwise and rte_errno is set.
1488 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
1489 const struct rte_flow_item *item,
1490 const struct rte_flow_attr *attr,
1491 uint64_t item_flags,
1492 struct rte_flow_error *error)
1494 const struct rte_flow_item_port_id *spec = item->spec;
1495 const struct rte_flow_item_port_id *mask = item->mask;
1496 const struct rte_flow_item_port_id switch_mask = {
1499 struct mlx5_priv *esw_priv;
1500 struct mlx5_priv *dev_priv;
1503 if (!attr->transfer)
1504 return rte_flow_error_set(error, EINVAL,
1505 RTE_FLOW_ERROR_TYPE_ITEM,
1507 "match on port id is valid only"
1508 " when transfer flag is enabled");
1509 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
1510 return rte_flow_error_set(error, ENOTSUP,
1511 RTE_FLOW_ERROR_TYPE_ITEM, item,
1512 "multiple source ports are not"
1515 mask = &switch_mask;
1516 if (mask->id != 0xffffffff)
1517 return rte_flow_error_set(error, ENOTSUP,
1518 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
1520 "no support for partial mask on"
1522 ret = mlx5_flow_item_acceptable
1523 (item, (const uint8_t *)mask,
1524 (const uint8_t *)&rte_flow_item_port_id_mask,
1525 sizeof(struct rte_flow_item_port_id),
1531 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
1533 return rte_flow_error_set(error, rte_errno,
1534 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1535 "failed to obtain E-Switch info for"
1537 dev_priv = mlx5_dev_to_eswitch_info(dev);
1539 return rte_flow_error_set(error, rte_errno,
1540 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1542 "failed to obtain E-Switch info");
1543 if (esw_priv->domain_id != dev_priv->domain_id)
1544 return rte_flow_error_set(error, EINVAL,
1545 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1546 "cannot match on a port from a"
1547 " different E-Switch");
1552 * Validate GTP item.
1555 * Pointer to the rte_eth_dev structure.
1557 * Item specification.
1558 * @param[in] item_flags
1559 * Bit-fields that holds the items detected until now.
1561 * Pointer to error structure.
1564 * 0 on success, a negative errno value otherwise and rte_errno is set.
1567 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
1568 const struct rte_flow_item *item,
1569 uint64_t item_flags,
1570 struct rte_flow_error *error)
1572 struct mlx5_priv *priv = dev->data->dev_private;
1573 const struct rte_flow_item_gtp *mask = item->mask;
1574 const struct rte_flow_item_gtp nic_mask = {
1576 .teid = RTE_BE32(0xffffffff),
1579 if (!priv->config.hca_attr.tunnel_stateless_gtp)
1580 return rte_flow_error_set(error, ENOTSUP,
1581 RTE_FLOW_ERROR_TYPE_ITEM, item,
1582 "GTP support is not enabled");
1583 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1584 return rte_flow_error_set(error, ENOTSUP,
1585 RTE_FLOW_ERROR_TYPE_ITEM, item,
1586 "multiple tunnel layers not"
1588 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1589 return rte_flow_error_set(error, EINVAL,
1590 RTE_FLOW_ERROR_TYPE_ITEM, item,
1591 "no outer UDP layer found");
1593 mask = &rte_flow_item_gtp_mask;
1594 return mlx5_flow_item_acceptable
1595 (item, (const uint8_t *)mask,
1596 (const uint8_t *)&nic_mask,
1597 sizeof(struct rte_flow_item_gtp),
1602 * Validate the pop VLAN action.
1605 * Pointer to the rte_eth_dev structure.
1606 * @param[in] action_flags
1607 * Holds the actions detected until now.
1609 * Pointer to the pop vlan action.
1610 * @param[in] item_flags
1611 * The items found in this flow rule.
1613 * Pointer to flow attributes.
1615 * Pointer to error structure.
1618 * 0 on success, a negative errno value otherwise and rte_errno is set.
1621 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
1622 uint64_t action_flags,
1623 const struct rte_flow_action *action,
1624 uint64_t item_flags,
1625 const struct rte_flow_attr *attr,
1626 struct rte_flow_error *error)
1628 struct mlx5_priv *priv = dev->data->dev_private;
1632 if (!priv->sh->pop_vlan_action)
1633 return rte_flow_error_set(error, ENOTSUP,
1634 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1636 "pop vlan action is not supported");
1638 return rte_flow_error_set(error, ENOTSUP,
1639 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1641 "pop vlan action not supported for "
1643 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
1644 return rte_flow_error_set(error, ENOTSUP,
1645 RTE_FLOW_ERROR_TYPE_ACTION, action,
1646 "no support for multiple VLAN "
1648 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1649 return rte_flow_error_set(error, ENOTSUP,
1650 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1652 "cannot pop vlan without a "
1653 "match on (outer) vlan in the flow");
1654 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1655 return rte_flow_error_set(error, EINVAL,
1656 RTE_FLOW_ERROR_TYPE_ACTION, action,
1657 "wrong action order, port_id should "
1658 "be after pop VLAN action");
1663 * Get VLAN default info from vlan match info.
1666 * Pointer to the rte_eth_dev structure.
1668 * the list of item specifications.
1670 * pointer VLAN info to fill to.
1672 * Pointer to error structure.
1675 * 0 on success, a negative errno value otherwise and rte_errno is set.
1678 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
1679 struct rte_vlan_hdr *vlan)
1681 const struct rte_flow_item_vlan nic_mask = {
1682 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
1683 MLX5DV_FLOW_VLAN_VID_MASK),
1684 .inner_type = RTE_BE16(0xffff),
1689 for (; items->type != RTE_FLOW_ITEM_TYPE_END &&
1690 items->type != RTE_FLOW_ITEM_TYPE_VLAN; items++)
1692 if (items->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1693 const struct rte_flow_item_vlan *vlan_m = items->mask;
1694 const struct rte_flow_item_vlan *vlan_v = items->spec;
1698 /* Only full match values are accepted */
1699 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
1700 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
1701 vlan->vlan_tci &= MLX5DV_FLOW_VLAN_PCP_MASK;
1703 rte_be_to_cpu_16(vlan_v->tci &
1704 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
1706 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
1707 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
1708 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
1710 rte_be_to_cpu_16(vlan_v->tci &
1711 MLX5DV_FLOW_VLAN_VID_MASK_BE);
1713 if (vlan_m->inner_type == nic_mask.inner_type)
1714 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
1715 vlan_m->inner_type);
1720 * Validate the push VLAN action.
1722 * @param[in] action_flags
1723 * Holds the actions detected until now.
1725 * Pointer to the encap action.
1727 * Pointer to flow attributes
1729 * Pointer to error structure.
1732 * 0 on success, a negative errno value otherwise and rte_errno is set.
1735 flow_dv_validate_action_push_vlan(uint64_t action_flags,
1736 uint64_t item_flags __rte_unused,
1737 const struct rte_flow_action *action,
1738 const struct rte_flow_attr *attr,
1739 struct rte_flow_error *error)
1741 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
1744 return rte_flow_error_set(error, ENOTSUP,
1745 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1747 "push VLAN action not supported for "
1749 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
1750 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
1751 return rte_flow_error_set(error, EINVAL,
1752 RTE_FLOW_ERROR_TYPE_ACTION, action,
1753 "invalid vlan ethertype");
1754 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
1755 return rte_flow_error_set(error, ENOTSUP,
1756 RTE_FLOW_ERROR_TYPE_ACTION, action,
1757 "no support for multiple VLAN "
1759 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1760 return rte_flow_error_set(error, EINVAL,
1761 RTE_FLOW_ERROR_TYPE_ACTION, action,
1762 "wrong action order, port_id should "
1763 "be after push VLAN");
1769 * Validate the set VLAN PCP.
1771 * @param[in] action_flags
1772 * Holds the actions detected until now.
1773 * @param[in] actions
1774 * Pointer to the list of actions remaining in the flow rule.
1776 * Pointer to flow attributes
1778 * Pointer to error structure.
1781 * 0 on success, a negative errno value otherwise and rte_errno is set.
1784 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
1785 const struct rte_flow_action actions[],
1786 struct rte_flow_error *error)
1788 const struct rte_flow_action *action = actions;
1789 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
1791 if (conf->vlan_pcp > 7)
1792 return rte_flow_error_set(error, EINVAL,
1793 RTE_FLOW_ERROR_TYPE_ACTION, action,
1794 "VLAN PCP value is too big");
1795 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
1796 return rte_flow_error_set(error, ENOTSUP,
1797 RTE_FLOW_ERROR_TYPE_ACTION, action,
1798 "set VLAN PCP action must follow "
1799 "the push VLAN action");
1800 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
1801 return rte_flow_error_set(error, ENOTSUP,
1802 RTE_FLOW_ERROR_TYPE_ACTION, action,
1803 "Multiple VLAN PCP modification are "
1805 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1806 return rte_flow_error_set(error, EINVAL,
1807 RTE_FLOW_ERROR_TYPE_ACTION, action,
1808 "wrong action order, port_id should "
1809 "be after set VLAN PCP");
1814 * Validate the set VLAN VID.
1816 * @param[in] item_flags
1817 * Holds the items detected in this rule.
1818 * @param[in] action_flags
1819 * Holds the actions detected until now.
1820 * @param[in] actions
1821 * Pointer to the list of actions remaining in the flow rule.
1823 * Pointer to error structure.
1826 * 0 on success, a negative errno value otherwise and rte_errno is set.
1829 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
1830 uint64_t action_flags,
1831 const struct rte_flow_action actions[],
1832 struct rte_flow_error *error)
1834 const struct rte_flow_action *action = actions;
1835 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
1837 if (conf->vlan_vid > RTE_BE16(0xFFE))
1838 return rte_flow_error_set(error, EINVAL,
1839 RTE_FLOW_ERROR_TYPE_ACTION, action,
1840 "VLAN VID value is too big");
1841 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
1842 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1843 return rte_flow_error_set(error, ENOTSUP,
1844 RTE_FLOW_ERROR_TYPE_ACTION, action,
1845 "set VLAN VID action must follow push"
1846 " VLAN action or match on VLAN item");
1847 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
1848 return rte_flow_error_set(error, ENOTSUP,
1849 RTE_FLOW_ERROR_TYPE_ACTION, action,
1850 "Multiple VLAN VID modifications are "
1852 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1853 return rte_flow_error_set(error, EINVAL,
1854 RTE_FLOW_ERROR_TYPE_ACTION, action,
1855 "wrong action order, port_id should "
1856 "be after set VLAN VID");
1861 * Validate the FLAG action.
1864 * Pointer to the rte_eth_dev structure.
1865 * @param[in] action_flags
1866 * Holds the actions detected until now.
1868 * Pointer to flow attributes
1870 * Pointer to error structure.
1873 * 0 on success, a negative errno value otherwise and rte_errno is set.
1876 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
1877 uint64_t action_flags,
1878 const struct rte_flow_attr *attr,
1879 struct rte_flow_error *error)
1881 struct mlx5_priv *priv = dev->data->dev_private;
1882 struct mlx5_dev_config *config = &priv->config;
1885 /* Fall back if no extended metadata register support. */
1886 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1887 return mlx5_flow_validate_action_flag(action_flags, attr,
1889 /* Extensive metadata mode requires registers. */
1890 if (!mlx5_flow_ext_mreg_supported(dev))
1891 return rte_flow_error_set(error, ENOTSUP,
1892 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1893 "no metadata registers "
1894 "to support flag action");
1895 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
1896 return rte_flow_error_set(error, ENOTSUP,
1897 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1898 "extended metadata register"
1899 " isn't available");
1900 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1904 if (action_flags & MLX5_FLOW_ACTION_MARK)
1905 return rte_flow_error_set(error, EINVAL,
1906 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1907 "can't mark and flag in same flow");
1908 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1909 return rte_flow_error_set(error, EINVAL,
1910 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1912 " actions in same flow");
1917 * Validate MARK action.
1920 * Pointer to the rte_eth_dev structure.
1922 * Pointer to action.
1923 * @param[in] action_flags
1924 * Holds the actions detected until now.
1926 * Pointer to flow attributes
1928 * Pointer to error structure.
1931 * 0 on success, a negative errno value otherwise and rte_errno is set.
1934 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
1935 const struct rte_flow_action *action,
1936 uint64_t action_flags,
1937 const struct rte_flow_attr *attr,
1938 struct rte_flow_error *error)
1940 struct mlx5_priv *priv = dev->data->dev_private;
1941 struct mlx5_dev_config *config = &priv->config;
1942 const struct rte_flow_action_mark *mark = action->conf;
1945 /* Fall back if no extended metadata register support. */
1946 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1947 return mlx5_flow_validate_action_mark(action, action_flags,
1949 /* Extensive metadata mode requires registers. */
1950 if (!mlx5_flow_ext_mreg_supported(dev))
1951 return rte_flow_error_set(error, ENOTSUP,
1952 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1953 "no metadata registers "
1954 "to support mark action");
1955 if (!priv->sh->dv_mark_mask)
1956 return rte_flow_error_set(error, ENOTSUP,
1957 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1958 "extended metadata register"
1959 " isn't available");
1960 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1965 return rte_flow_error_set(error, EINVAL,
1966 RTE_FLOW_ERROR_TYPE_ACTION, action,
1967 "configuration cannot be null");
1968 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
1969 return rte_flow_error_set(error, EINVAL,
1970 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1972 "mark id exceeds the limit");
1973 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1974 return rte_flow_error_set(error, EINVAL,
1975 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1976 "can't flag and mark in same flow");
1977 if (action_flags & MLX5_FLOW_ACTION_MARK)
1978 return rte_flow_error_set(error, EINVAL,
1979 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1980 "can't have 2 mark actions in same"
1986 * Validate SET_META action.
1989 * Pointer to the rte_eth_dev structure.
1991 * Pointer to the encap action.
1992 * @param[in] action_flags
1993 * Holds the actions detected until now.
1995 * Pointer to flow attributes
1997 * Pointer to error structure.
2000 * 0 on success, a negative errno value otherwise and rte_errno is set.
2003 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
2004 const struct rte_flow_action *action,
2005 uint64_t action_flags __rte_unused,
2006 const struct rte_flow_attr *attr,
2007 struct rte_flow_error *error)
2009 const struct rte_flow_action_set_meta *conf;
2010 uint32_t nic_mask = UINT32_MAX;
2011 enum modify_reg reg;
2013 if (!mlx5_flow_ext_mreg_supported(dev))
2014 return rte_flow_error_set(error, ENOTSUP,
2015 RTE_FLOW_ERROR_TYPE_ACTION, action,
2016 "extended metadata register"
2017 " isn't supported");
2018 reg = flow_dv_get_metadata_reg(dev, attr, error);
2021 if (reg != REG_A && reg != REG_B) {
2022 struct mlx5_priv *priv = dev->data->dev_private;
2024 nic_mask = priv->sh->dv_meta_mask;
2026 if (!(action->conf))
2027 return rte_flow_error_set(error, EINVAL,
2028 RTE_FLOW_ERROR_TYPE_ACTION, action,
2029 "configuration cannot be null");
2030 conf = (const struct rte_flow_action_set_meta *)action->conf;
2032 return rte_flow_error_set(error, EINVAL,
2033 RTE_FLOW_ERROR_TYPE_ACTION, action,
2034 "zero mask doesn't have any effect");
2035 if (conf->mask & ~nic_mask)
2036 return rte_flow_error_set(error, EINVAL,
2037 RTE_FLOW_ERROR_TYPE_ACTION, action,
2038 "meta data must be within reg C0");
2039 if (!(conf->data & conf->mask))
2040 return rte_flow_error_set(error, EINVAL,
2041 RTE_FLOW_ERROR_TYPE_ACTION, action,
2042 "zero value has no effect");
2047 * Validate SET_TAG action.
2050 * Pointer to the rte_eth_dev structure.
2052 * Pointer to the encap action.
2053 * @param[in] action_flags
2054 * Holds the actions detected until now.
2056 * Pointer to flow attributes
2058 * Pointer to error structure.
2061 * 0 on success, a negative errno value otherwise and rte_errno is set.
2064 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
2065 const struct rte_flow_action *action,
2066 uint64_t action_flags,
2067 const struct rte_flow_attr *attr,
2068 struct rte_flow_error *error)
2070 const struct rte_flow_action_set_tag *conf;
2071 const uint64_t terminal_action_flags =
2072 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
2073 MLX5_FLOW_ACTION_RSS;
2076 if (!mlx5_flow_ext_mreg_supported(dev))
2077 return rte_flow_error_set(error, ENOTSUP,
2078 RTE_FLOW_ERROR_TYPE_ACTION, action,
2079 "extensive metadata register"
2080 " isn't supported");
2081 if (!(action->conf))
2082 return rte_flow_error_set(error, EINVAL,
2083 RTE_FLOW_ERROR_TYPE_ACTION, action,
2084 "configuration cannot be null");
2085 conf = (const struct rte_flow_action_set_tag *)action->conf;
2087 return rte_flow_error_set(error, EINVAL,
2088 RTE_FLOW_ERROR_TYPE_ACTION, action,
2089 "zero mask doesn't have any effect");
2090 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
2093 if (!attr->transfer && attr->ingress &&
2094 (action_flags & terminal_action_flags))
2095 return rte_flow_error_set(error, EINVAL,
2096 RTE_FLOW_ERROR_TYPE_ACTION, action,
2097 "set_tag has no effect"
2098 " with terminal actions");
2103 * Validate count action.
2108 * Pointer to error structure.
2111 * 0 on success, a negative errno value otherwise and rte_errno is set.
2114 flow_dv_validate_action_count(struct rte_eth_dev *dev,
2115 struct rte_flow_error *error)
2117 struct mlx5_priv *priv = dev->data->dev_private;
2119 if (!priv->config.devx)
2121 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
2125 return rte_flow_error_set
2127 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2129 "count action not supported");
2133 * Validate the L2 encap action.
2135 * @param[in] action_flags
2136 * Holds the actions detected until now.
2138 * Pointer to the encap action.
2140 * Pointer to flow attributes
2142 * Pointer to error structure.
2145 * 0 on success, a negative errno value otherwise and rte_errno is set.
2148 flow_dv_validate_action_l2_encap(uint64_t action_flags,
2149 const struct rte_flow_action *action,
2150 const struct rte_flow_attr *attr,
2151 struct rte_flow_error *error)
2153 if (!(action->conf))
2154 return rte_flow_error_set(error, EINVAL,
2155 RTE_FLOW_ERROR_TYPE_ACTION, action,
2156 "configuration cannot be null");
2157 if (action_flags & (MLX5_FLOW_ENCAP_ACTIONS | MLX5_FLOW_DECAP_ACTIONS))
2158 return rte_flow_error_set(error, EINVAL,
2159 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2160 "can only have a single encap or"
2161 " decap action in a flow");
2162 if (!attr->transfer && attr->ingress)
2163 return rte_flow_error_set(error, ENOTSUP,
2164 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2166 "encap action not supported for "
2172 * Validate the L2 decap action.
2174 * @param[in] action_flags
2175 * Holds the actions detected until now.
2177 * Pointer to flow attributes
2179 * Pointer to error structure.
2182 * 0 on success, a negative errno value otherwise and rte_errno is set.
2185 flow_dv_validate_action_l2_decap(uint64_t action_flags,
2186 const struct rte_flow_attr *attr,
2187 struct rte_flow_error *error)
2189 if (action_flags & (MLX5_FLOW_ENCAP_ACTIONS | MLX5_FLOW_DECAP_ACTIONS))
2190 return rte_flow_error_set(error, EINVAL,
2191 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2192 "can only have a single encap or"
2193 " decap action in a flow");
2194 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
2195 return rte_flow_error_set(error, EINVAL,
2196 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2197 "can't have decap action after"
2200 return rte_flow_error_set(error, ENOTSUP,
2201 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2203 "decap action not supported for "
2209 * Validate the raw encap action.
2211 * @param[in] action_flags
2212 * Holds the actions detected until now.
2214 * Pointer to the encap action.
2216 * Pointer to flow attributes
2218 * Pointer to error structure.
2221 * 0 on success, a negative errno value otherwise and rte_errno is set.
2224 flow_dv_validate_action_raw_encap(uint64_t action_flags,
2225 const struct rte_flow_action *action,
2226 const struct rte_flow_attr *attr,
2227 struct rte_flow_error *error)
2229 const struct rte_flow_action_raw_encap *raw_encap =
2230 (const struct rte_flow_action_raw_encap *)action->conf;
2231 if (!(action->conf))
2232 return rte_flow_error_set(error, EINVAL,
2233 RTE_FLOW_ERROR_TYPE_ACTION, action,
2234 "configuration cannot be null");
2235 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
2236 return rte_flow_error_set(error, EINVAL,
2237 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2238 "can only have a single encap"
2239 " action in a flow");
2240 /* encap without preceding decap is not supported for ingress */
2241 if (!attr->transfer && attr->ingress &&
2242 !(action_flags & MLX5_FLOW_ACTION_RAW_DECAP))
2243 return rte_flow_error_set(error, ENOTSUP,
2244 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2246 "encap action not supported for "
2248 if (!raw_encap->size || !raw_encap->data)
2249 return rte_flow_error_set(error, EINVAL,
2250 RTE_FLOW_ERROR_TYPE_ACTION, action,
2251 "raw encap data cannot be empty");
2256 * Validate the raw decap action.
2258 * @param[in] action_flags
2259 * Holds the actions detected until now.
2261 * Pointer to the encap action.
2263 * Pointer to flow attributes
2265 * Pointer to error structure.
2268 * 0 on success, a negative errno value otherwise and rte_errno is set.
2271 flow_dv_validate_action_raw_decap(uint64_t action_flags,
2272 const struct rte_flow_action *action,
2273 const struct rte_flow_attr *attr,
2274 struct rte_flow_error *error)
2276 const struct rte_flow_action_raw_decap *decap = action->conf;
2278 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
2279 return rte_flow_error_set(error, EINVAL,
2280 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2281 "can't have encap action before"
2283 if (action_flags & MLX5_FLOW_DECAP_ACTIONS)
2284 return rte_flow_error_set(error, EINVAL,
2285 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2286 "can only have a single decap"
2287 " action in a flow");
2288 /* decap action is valid on egress only if it is followed by encap */
2289 if (attr->egress && decap &&
2290 decap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
2291 return rte_flow_error_set(error, ENOTSUP,
2292 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2293 NULL, "decap action not supported"
2295 } else if (decap && decap->size > MLX5_ENCAPSULATION_DECISION_SIZE &&
2296 (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)) {
2297 return rte_flow_error_set(error, EINVAL,
2298 RTE_FLOW_ERROR_TYPE_ACTION,
2300 "can't have decap action "
2301 "after modify action");
2307 * Find existing encap/decap resource or create and register a new one.
2309 * @param[in, out] dev
2310 * Pointer to rte_eth_dev structure.
2311 * @param[in, out] resource
2312 * Pointer to encap/decap resource.
2313 * @parm[in, out] dev_flow
2314 * Pointer to the dev_flow.
2316 * pointer to error structure.
2319 * 0 on success otherwise -errno and errno is set.
2322 flow_dv_encap_decap_resource_register
2323 (struct rte_eth_dev *dev,
2324 struct mlx5_flow_dv_encap_decap_resource *resource,
2325 struct mlx5_flow *dev_flow,
2326 struct rte_flow_error *error)
2328 struct mlx5_priv *priv = dev->data->dev_private;
2329 struct mlx5_ibv_shared *sh = priv->sh;
2330 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2331 struct mlx5dv_dr_domain *domain;
2333 resource->flags = dev_flow->group ? 0 : 1;
2334 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2335 domain = sh->fdb_domain;
2336 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2337 domain = sh->rx_domain;
2339 domain = sh->tx_domain;
2340 /* Lookup a matching resource from cache. */
2341 LIST_FOREACH(cache_resource, &sh->encaps_decaps, next) {
2342 if (resource->reformat_type == cache_resource->reformat_type &&
2343 resource->ft_type == cache_resource->ft_type &&
2344 resource->flags == cache_resource->flags &&
2345 resource->size == cache_resource->size &&
2346 !memcmp((const void *)resource->buf,
2347 (const void *)cache_resource->buf,
2349 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d++",
2350 (void *)cache_resource,
2351 rte_atomic32_read(&cache_resource->refcnt));
2352 rte_atomic32_inc(&cache_resource->refcnt);
2353 dev_flow->dv.encap_decap = cache_resource;
2357 /* Register new encap/decap resource. */
2358 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
2359 if (!cache_resource)
2360 return rte_flow_error_set(error, ENOMEM,
2361 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2362 "cannot allocate resource memory");
2363 *cache_resource = *resource;
2364 cache_resource->verbs_action =
2365 mlx5_glue->dv_create_flow_action_packet_reformat
2366 (sh->ctx, cache_resource->reformat_type,
2367 cache_resource->ft_type, domain, cache_resource->flags,
2368 cache_resource->size,
2369 (cache_resource->size ? cache_resource->buf : NULL));
2370 if (!cache_resource->verbs_action) {
2371 rte_free(cache_resource);
2372 return rte_flow_error_set(error, ENOMEM,
2373 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2374 NULL, "cannot create action");
2376 rte_atomic32_init(&cache_resource->refcnt);
2377 rte_atomic32_inc(&cache_resource->refcnt);
2378 LIST_INSERT_HEAD(&sh->encaps_decaps, cache_resource, next);
2379 dev_flow->dv.encap_decap = cache_resource;
2380 DRV_LOG(DEBUG, "new encap/decap resource %p: refcnt %d++",
2381 (void *)cache_resource,
2382 rte_atomic32_read(&cache_resource->refcnt));
2387 * Find existing table jump resource or create and register a new one.
2389 * @param[in, out] dev
2390 * Pointer to rte_eth_dev structure.
2391 * @param[in, out] tbl
2392 * Pointer to flow table resource.
2393 * @parm[in, out] dev_flow
2394 * Pointer to the dev_flow.
2396 * pointer to error structure.
2399 * 0 on success otherwise -errno and errno is set.
2402 flow_dv_jump_tbl_resource_register
2403 (struct rte_eth_dev *dev __rte_unused,
2404 struct mlx5_flow_tbl_resource *tbl,
2405 struct mlx5_flow *dev_flow,
2406 struct rte_flow_error *error)
2408 struct mlx5_flow_tbl_data_entry *tbl_data =
2409 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
2413 cnt = rte_atomic32_read(&tbl_data->jump.refcnt);
2415 tbl_data->jump.action =
2416 mlx5_glue->dr_create_flow_action_dest_flow_tbl
2418 if (!tbl_data->jump.action)
2419 return rte_flow_error_set(error, ENOMEM,
2420 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2421 NULL, "cannot create jump action");
2422 DRV_LOG(DEBUG, "new jump table resource %p: refcnt %d++",
2423 (void *)&tbl_data->jump, cnt);
2425 assert(tbl_data->jump.action);
2426 DRV_LOG(DEBUG, "existed jump table resource %p: refcnt %d++",
2427 (void *)&tbl_data->jump, cnt);
2429 rte_atomic32_inc(&tbl_data->jump.refcnt);
2430 dev_flow->dv.jump = &tbl_data->jump;
2435 * Find existing table port ID resource or create and register a new one.
2437 * @param[in, out] dev
2438 * Pointer to rte_eth_dev structure.
2439 * @param[in, out] resource
2440 * Pointer to port ID action resource.
2441 * @parm[in, out] dev_flow
2442 * Pointer to the dev_flow.
2444 * pointer to error structure.
2447 * 0 on success otherwise -errno and errno is set.
2450 flow_dv_port_id_action_resource_register
2451 (struct rte_eth_dev *dev,
2452 struct mlx5_flow_dv_port_id_action_resource *resource,
2453 struct mlx5_flow *dev_flow,
2454 struct rte_flow_error *error)
2456 struct mlx5_priv *priv = dev->data->dev_private;
2457 struct mlx5_ibv_shared *sh = priv->sh;
2458 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
2460 /* Lookup a matching resource from cache. */
2461 LIST_FOREACH(cache_resource, &sh->port_id_action_list, next) {
2462 if (resource->port_id == cache_resource->port_id) {
2463 DRV_LOG(DEBUG, "port id action resource resource %p: "
2465 (void *)cache_resource,
2466 rte_atomic32_read(&cache_resource->refcnt));
2467 rte_atomic32_inc(&cache_resource->refcnt);
2468 dev_flow->dv.port_id_action = cache_resource;
2472 /* Register new port id action resource. */
2473 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
2474 if (!cache_resource)
2475 return rte_flow_error_set(error, ENOMEM,
2476 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2477 "cannot allocate resource memory");
2478 *cache_resource = *resource;
2480 * Depending on rdma_core version the glue routine calls
2481 * either mlx5dv_dr_action_create_dest_ib_port(domain, ibv_port)
2482 * or mlx5dv_dr_action_create_dest_vport(domain, vport_id).
2484 cache_resource->action =
2485 mlx5_glue->dr_create_flow_action_dest_port
2486 (priv->sh->fdb_domain, resource->port_id);
2487 if (!cache_resource->action) {
2488 rte_free(cache_resource);
2489 return rte_flow_error_set(error, ENOMEM,
2490 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2491 NULL, "cannot create action");
2493 rte_atomic32_init(&cache_resource->refcnt);
2494 rte_atomic32_inc(&cache_resource->refcnt);
2495 LIST_INSERT_HEAD(&sh->port_id_action_list, cache_resource, next);
2496 dev_flow->dv.port_id_action = cache_resource;
2497 DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++",
2498 (void *)cache_resource,
2499 rte_atomic32_read(&cache_resource->refcnt));
2504 * Find existing push vlan resource or create and register a new one.
2506 * @param [in, out] dev
2507 * Pointer to rte_eth_dev structure.
2508 * @param[in, out] resource
2509 * Pointer to port ID action resource.
2510 * @parm[in, out] dev_flow
2511 * Pointer to the dev_flow.
2513 * pointer to error structure.
2516 * 0 on success otherwise -errno and errno is set.
2519 flow_dv_push_vlan_action_resource_register
2520 (struct rte_eth_dev *dev,
2521 struct mlx5_flow_dv_push_vlan_action_resource *resource,
2522 struct mlx5_flow *dev_flow,
2523 struct rte_flow_error *error)
2525 struct mlx5_priv *priv = dev->data->dev_private;
2526 struct mlx5_ibv_shared *sh = priv->sh;
2527 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
2528 struct mlx5dv_dr_domain *domain;
2530 /* Lookup a matching resource from cache. */
2531 LIST_FOREACH(cache_resource, &sh->push_vlan_action_list, next) {
2532 if (resource->vlan_tag == cache_resource->vlan_tag &&
2533 resource->ft_type == cache_resource->ft_type) {
2534 DRV_LOG(DEBUG, "push-VLAN action resource resource %p: "
2536 (void *)cache_resource,
2537 rte_atomic32_read(&cache_resource->refcnt));
2538 rte_atomic32_inc(&cache_resource->refcnt);
2539 dev_flow->dv.push_vlan_res = cache_resource;
2543 /* Register new push_vlan action resource. */
2544 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
2545 if (!cache_resource)
2546 return rte_flow_error_set(error, ENOMEM,
2547 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2548 "cannot allocate resource memory");
2549 *cache_resource = *resource;
2550 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2551 domain = sh->fdb_domain;
2552 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2553 domain = sh->rx_domain;
2555 domain = sh->tx_domain;
2556 cache_resource->action =
2557 mlx5_glue->dr_create_flow_action_push_vlan(domain,
2558 resource->vlan_tag);
2559 if (!cache_resource->action) {
2560 rte_free(cache_resource);
2561 return rte_flow_error_set(error, ENOMEM,
2562 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2563 NULL, "cannot create action");
2565 rte_atomic32_init(&cache_resource->refcnt);
2566 rte_atomic32_inc(&cache_resource->refcnt);
2567 LIST_INSERT_HEAD(&sh->push_vlan_action_list, cache_resource, next);
2568 dev_flow->dv.push_vlan_res = cache_resource;
2569 DRV_LOG(DEBUG, "new push vlan action resource %p: refcnt %d++",
2570 (void *)cache_resource,
2571 rte_atomic32_read(&cache_resource->refcnt));
2575 * Get the size of specific rte_flow_item_type
2577 * @param[in] item_type
2578 * Tested rte_flow_item_type.
2581 * sizeof struct item_type, 0 if void or irrelevant.
2584 flow_dv_get_item_len(const enum rte_flow_item_type item_type)
2588 switch (item_type) {
2589 case RTE_FLOW_ITEM_TYPE_ETH:
2590 retval = sizeof(struct rte_flow_item_eth);
2592 case RTE_FLOW_ITEM_TYPE_VLAN:
2593 retval = sizeof(struct rte_flow_item_vlan);
2595 case RTE_FLOW_ITEM_TYPE_IPV4:
2596 retval = sizeof(struct rte_flow_item_ipv4);
2598 case RTE_FLOW_ITEM_TYPE_IPV6:
2599 retval = sizeof(struct rte_flow_item_ipv6);
2601 case RTE_FLOW_ITEM_TYPE_UDP:
2602 retval = sizeof(struct rte_flow_item_udp);
2604 case RTE_FLOW_ITEM_TYPE_TCP:
2605 retval = sizeof(struct rte_flow_item_tcp);
2607 case RTE_FLOW_ITEM_TYPE_VXLAN:
2608 retval = sizeof(struct rte_flow_item_vxlan);
2610 case RTE_FLOW_ITEM_TYPE_GRE:
2611 retval = sizeof(struct rte_flow_item_gre);
2613 case RTE_FLOW_ITEM_TYPE_NVGRE:
2614 retval = sizeof(struct rte_flow_item_nvgre);
2616 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2617 retval = sizeof(struct rte_flow_item_vxlan_gpe);
2619 case RTE_FLOW_ITEM_TYPE_MPLS:
2620 retval = sizeof(struct rte_flow_item_mpls);
2622 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
2630 #define MLX5_ENCAP_IPV4_VERSION 0x40
2631 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
2632 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
2633 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
2634 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
2635 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
2636 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
2639 * Convert the encap action data from list of rte_flow_item to raw buffer
2642 * Pointer to rte_flow_item objects list.
2644 * Pointer to the output buffer.
2646 * Pointer to the output buffer size.
2648 * Pointer to the error structure.
2651 * 0 on success, a negative errno value otherwise and rte_errno is set.
2654 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
2655 size_t *size, struct rte_flow_error *error)
2657 struct rte_ether_hdr *eth = NULL;
2658 struct rte_vlan_hdr *vlan = NULL;
2659 struct rte_ipv4_hdr *ipv4 = NULL;
2660 struct rte_ipv6_hdr *ipv6 = NULL;
2661 struct rte_udp_hdr *udp = NULL;
2662 struct rte_vxlan_hdr *vxlan = NULL;
2663 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
2664 struct rte_gre_hdr *gre = NULL;
2666 size_t temp_size = 0;
2669 return rte_flow_error_set(error, EINVAL,
2670 RTE_FLOW_ERROR_TYPE_ACTION,
2671 NULL, "invalid empty data");
2672 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2673 len = flow_dv_get_item_len(items->type);
2674 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
2675 return rte_flow_error_set(error, EINVAL,
2676 RTE_FLOW_ERROR_TYPE_ACTION,
2677 (void *)items->type,
2678 "items total size is too big"
2679 " for encap action");
2680 rte_memcpy((void *)&buf[temp_size], items->spec, len);
2681 switch (items->type) {
2682 case RTE_FLOW_ITEM_TYPE_ETH:
2683 eth = (struct rte_ether_hdr *)&buf[temp_size];
2685 case RTE_FLOW_ITEM_TYPE_VLAN:
2686 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
2688 return rte_flow_error_set(error, EINVAL,
2689 RTE_FLOW_ERROR_TYPE_ACTION,
2690 (void *)items->type,
2691 "eth header not found");
2692 if (!eth->ether_type)
2693 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
2695 case RTE_FLOW_ITEM_TYPE_IPV4:
2696 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
2698 return rte_flow_error_set(error, EINVAL,
2699 RTE_FLOW_ERROR_TYPE_ACTION,
2700 (void *)items->type,
2701 "neither eth nor vlan"
2703 if (vlan && !vlan->eth_proto)
2704 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2705 else if (eth && !eth->ether_type)
2706 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2707 if (!ipv4->version_ihl)
2708 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
2709 MLX5_ENCAP_IPV4_IHL_MIN;
2710 if (!ipv4->time_to_live)
2711 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
2713 case RTE_FLOW_ITEM_TYPE_IPV6:
2714 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
2716 return rte_flow_error_set(error, EINVAL,
2717 RTE_FLOW_ERROR_TYPE_ACTION,
2718 (void *)items->type,
2719 "neither eth nor vlan"
2721 if (vlan && !vlan->eth_proto)
2722 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2723 else if (eth && !eth->ether_type)
2724 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2725 if (!ipv6->vtc_flow)
2727 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
2728 if (!ipv6->hop_limits)
2729 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
2731 case RTE_FLOW_ITEM_TYPE_UDP:
2732 udp = (struct rte_udp_hdr *)&buf[temp_size];
2734 return rte_flow_error_set(error, EINVAL,
2735 RTE_FLOW_ERROR_TYPE_ACTION,
2736 (void *)items->type,
2737 "ip header not found");
2738 if (ipv4 && !ipv4->next_proto_id)
2739 ipv4->next_proto_id = IPPROTO_UDP;
2740 else if (ipv6 && !ipv6->proto)
2741 ipv6->proto = IPPROTO_UDP;
2743 case RTE_FLOW_ITEM_TYPE_VXLAN:
2744 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
2746 return rte_flow_error_set(error, EINVAL,
2747 RTE_FLOW_ERROR_TYPE_ACTION,
2748 (void *)items->type,
2749 "udp header not found");
2751 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
2752 if (!vxlan->vx_flags)
2754 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
2756 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2757 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
2759 return rte_flow_error_set(error, EINVAL,
2760 RTE_FLOW_ERROR_TYPE_ACTION,
2761 (void *)items->type,
2762 "udp header not found");
2763 if (!vxlan_gpe->proto)
2764 return rte_flow_error_set(error, EINVAL,
2765 RTE_FLOW_ERROR_TYPE_ACTION,
2766 (void *)items->type,
2767 "next protocol not found");
2770 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
2771 if (!vxlan_gpe->vx_flags)
2772 vxlan_gpe->vx_flags =
2773 MLX5_ENCAP_VXLAN_GPE_FLAGS;
2775 case RTE_FLOW_ITEM_TYPE_GRE:
2776 case RTE_FLOW_ITEM_TYPE_NVGRE:
2777 gre = (struct rte_gre_hdr *)&buf[temp_size];
2779 return rte_flow_error_set(error, EINVAL,
2780 RTE_FLOW_ERROR_TYPE_ACTION,
2781 (void *)items->type,
2782 "next protocol not found");
2784 return rte_flow_error_set(error, EINVAL,
2785 RTE_FLOW_ERROR_TYPE_ACTION,
2786 (void *)items->type,
2787 "ip header not found");
2788 if (ipv4 && !ipv4->next_proto_id)
2789 ipv4->next_proto_id = IPPROTO_GRE;
2790 else if (ipv6 && !ipv6->proto)
2791 ipv6->proto = IPPROTO_GRE;
2793 case RTE_FLOW_ITEM_TYPE_VOID:
2796 return rte_flow_error_set(error, EINVAL,
2797 RTE_FLOW_ERROR_TYPE_ACTION,
2798 (void *)items->type,
2799 "unsupported item type");
2809 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
2811 struct rte_ether_hdr *eth = NULL;
2812 struct rte_vlan_hdr *vlan = NULL;
2813 struct rte_ipv6_hdr *ipv6 = NULL;
2814 struct rte_udp_hdr *udp = NULL;
2818 eth = (struct rte_ether_hdr *)data;
2819 next_hdr = (char *)(eth + 1);
2820 proto = RTE_BE16(eth->ether_type);
2823 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
2824 vlan = (struct rte_vlan_hdr *)next_hdr;
2825 proto = RTE_BE16(vlan->eth_proto);
2826 next_hdr += sizeof(struct rte_vlan_hdr);
2829 /* HW calculates IPv4 csum. no need to proceed */
2830 if (proto == RTE_ETHER_TYPE_IPV4)
2833 /* non IPv4/IPv6 header. not supported */
2834 if (proto != RTE_ETHER_TYPE_IPV6) {
2835 return rte_flow_error_set(error, ENOTSUP,
2836 RTE_FLOW_ERROR_TYPE_ACTION,
2837 NULL, "Cannot offload non IPv4/IPv6");
2840 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
2842 /* ignore non UDP */
2843 if (ipv6->proto != IPPROTO_UDP)
2846 udp = (struct rte_udp_hdr *)(ipv6 + 1);
2847 udp->dgram_cksum = 0;
2853 * Convert L2 encap action to DV specification.
2856 * Pointer to rte_eth_dev structure.
2858 * Pointer to action structure.
2859 * @param[in, out] dev_flow
2860 * Pointer to the mlx5_flow.
2861 * @param[in] transfer
2862 * Mark if the flow is E-Switch flow.
2864 * Pointer to the error structure.
2867 * 0 on success, a negative errno value otherwise and rte_errno is set.
2870 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
2871 const struct rte_flow_action *action,
2872 struct mlx5_flow *dev_flow,
2874 struct rte_flow_error *error)
2876 const struct rte_flow_item *encap_data;
2877 const struct rte_flow_action_raw_encap *raw_encap_data;
2878 struct mlx5_flow_dv_encap_decap_resource res = {
2880 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
2881 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
2882 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
2885 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
2887 (const struct rte_flow_action_raw_encap *)action->conf;
2888 res.size = raw_encap_data->size;
2889 memcpy(res.buf, raw_encap_data->data, res.size);
2890 if (flow_dv_zero_encap_udp_csum(res.buf, error))
2893 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
2895 ((const struct rte_flow_action_vxlan_encap *)
2896 action->conf)->definition;
2899 ((const struct rte_flow_action_nvgre_encap *)
2900 action->conf)->definition;
2901 if (flow_dv_convert_encap_data(encap_data, res.buf,
2905 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
2906 return rte_flow_error_set(error, EINVAL,
2907 RTE_FLOW_ERROR_TYPE_ACTION,
2908 NULL, "can't create L2 encap action");
2913 * Convert L2 decap action to DV specification.
2916 * Pointer to rte_eth_dev structure.
2917 * @param[in, out] dev_flow
2918 * Pointer to the mlx5_flow.
2919 * @param[in] transfer
2920 * Mark if the flow is E-Switch flow.
2922 * Pointer to the error structure.
2925 * 0 on success, a negative errno value otherwise and rte_errno is set.
2928 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
2929 struct mlx5_flow *dev_flow,
2931 struct rte_flow_error *error)
2933 struct mlx5_flow_dv_encap_decap_resource res = {
2936 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
2937 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
2938 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
2941 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
2942 return rte_flow_error_set(error, EINVAL,
2943 RTE_FLOW_ERROR_TYPE_ACTION,
2944 NULL, "can't create L2 decap action");
2949 * Convert raw decap/encap (L3 tunnel) action to DV specification.
2952 * Pointer to rte_eth_dev structure.
2954 * Pointer to action structure.
2955 * @param[in, out] dev_flow
2956 * Pointer to the mlx5_flow.
2958 * Pointer to the flow attributes.
2960 * Pointer to the error structure.
2963 * 0 on success, a negative errno value otherwise and rte_errno is set.
2966 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
2967 const struct rte_flow_action *action,
2968 struct mlx5_flow *dev_flow,
2969 const struct rte_flow_attr *attr,
2970 struct rte_flow_error *error)
2972 const struct rte_flow_action_raw_encap *encap_data;
2973 struct mlx5_flow_dv_encap_decap_resource res;
2975 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
2976 res.size = encap_data->size;
2977 memcpy(res.buf, encap_data->data, res.size);
2978 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
2979 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
2980 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
2982 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
2984 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
2985 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
2986 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
2987 return rte_flow_error_set(error, EINVAL,
2988 RTE_FLOW_ERROR_TYPE_ACTION,
2989 NULL, "can't create encap action");
2994 * Create action push VLAN.
2997 * Pointer to rte_eth_dev structure.
2998 * @param[in] vlan_tag
2999 * the vlan tag to push to the Ethernet header.
3000 * @param[in, out] dev_flow
3001 * Pointer to the mlx5_flow.
3003 * Pointer to the flow attributes.
3005 * Pointer to the error structure.
3008 * 0 on success, a negative errno value otherwise and rte_errno is set.
3011 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
3012 const struct rte_flow_attr *attr,
3013 const struct rte_vlan_hdr *vlan,
3014 struct mlx5_flow *dev_flow,
3015 struct rte_flow_error *error)
3017 struct mlx5_flow_dv_push_vlan_action_resource res;
3020 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
3023 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3025 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3026 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3027 return flow_dv_push_vlan_action_resource_register
3028 (dev, &res, dev_flow, error);
3032 * Validate the modify-header actions.
3034 * @param[in] action_flags
3035 * Holds the actions detected until now.
3037 * Pointer to the modify action.
3039 * Pointer to error structure.
3042 * 0 on success, a negative errno value otherwise and rte_errno is set.
3045 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
3046 const struct rte_flow_action *action,
3047 struct rte_flow_error *error)
3049 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
3050 return rte_flow_error_set(error, EINVAL,
3051 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3052 NULL, "action configuration not set");
3053 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
3054 return rte_flow_error_set(error, EINVAL,
3055 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3056 "can't have encap action before"
3062 * Validate the modify-header MAC address actions.
3064 * @param[in] action_flags
3065 * Holds the actions detected until now.
3067 * Pointer to the modify action.
3068 * @param[in] item_flags
3069 * Holds the items detected.
3071 * Pointer to error structure.
3074 * 0 on success, a negative errno value otherwise and rte_errno is set.
3077 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
3078 const struct rte_flow_action *action,
3079 const uint64_t item_flags,
3080 struct rte_flow_error *error)
3084 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3086 if (!(item_flags & MLX5_FLOW_LAYER_L2))
3087 return rte_flow_error_set(error, EINVAL,
3088 RTE_FLOW_ERROR_TYPE_ACTION,
3090 "no L2 item in pattern");
3096 * Validate the modify-header IPv4 address actions.
3098 * @param[in] action_flags
3099 * Holds the actions detected until now.
3101 * Pointer to the modify action.
3102 * @param[in] item_flags
3103 * Holds the items detected.
3105 * Pointer to error structure.
3108 * 0 on success, a negative errno value otherwise and rte_errno is set.
3111 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
3112 const struct rte_flow_action *action,
3113 const uint64_t item_flags,
3114 struct rte_flow_error *error)
3118 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3120 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
3121 return rte_flow_error_set(error, EINVAL,
3122 RTE_FLOW_ERROR_TYPE_ACTION,
3124 "no ipv4 item in pattern");
3130 * Validate the modify-header IPv6 address actions.
3132 * @param[in] action_flags
3133 * Holds the actions detected until now.
3135 * Pointer to the modify action.
3136 * @param[in] item_flags
3137 * Holds the items detected.
3139 * Pointer to error structure.
3142 * 0 on success, a negative errno value otherwise and rte_errno is set.
3145 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
3146 const struct rte_flow_action *action,
3147 const uint64_t item_flags,
3148 struct rte_flow_error *error)
3152 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3154 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
3155 return rte_flow_error_set(error, EINVAL,
3156 RTE_FLOW_ERROR_TYPE_ACTION,
3158 "no ipv6 item in pattern");
3164 * Validate the modify-header TP actions.
3166 * @param[in] action_flags
3167 * Holds the actions detected until now.
3169 * Pointer to the modify action.
3170 * @param[in] item_flags
3171 * Holds the items detected.
3173 * Pointer to error structure.
3176 * 0 on success, a negative errno value otherwise and rte_errno is set.
3179 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
3180 const struct rte_flow_action *action,
3181 const uint64_t item_flags,
3182 struct rte_flow_error *error)
3186 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3188 if (!(item_flags & MLX5_FLOW_LAYER_L4))
3189 return rte_flow_error_set(error, EINVAL,
3190 RTE_FLOW_ERROR_TYPE_ACTION,
3191 NULL, "no transport layer "
3198 * Validate the modify-header actions of increment/decrement
3199 * TCP Sequence-number.
3201 * @param[in] action_flags
3202 * Holds the actions detected until now.
3204 * Pointer to the modify action.
3205 * @param[in] item_flags
3206 * Holds the items detected.
3208 * Pointer to error structure.
3211 * 0 on success, a negative errno value otherwise and rte_errno is set.
3214 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
3215 const struct rte_flow_action *action,
3216 const uint64_t item_flags,
3217 struct rte_flow_error *error)
3221 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3223 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3224 return rte_flow_error_set(error, EINVAL,
3225 RTE_FLOW_ERROR_TYPE_ACTION,
3226 NULL, "no TCP item in"
3228 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
3229 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
3230 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
3231 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
3232 return rte_flow_error_set(error, EINVAL,
3233 RTE_FLOW_ERROR_TYPE_ACTION,
3235 "cannot decrease and increase"
3236 " TCP sequence number"
3237 " at the same time");
3243 * Validate the modify-header actions of increment/decrement
3244 * TCP Acknowledgment number.
3246 * @param[in] action_flags
3247 * Holds the actions detected until now.
3249 * Pointer to the modify action.
3250 * @param[in] item_flags
3251 * Holds the items detected.
3253 * Pointer to error structure.
3256 * 0 on success, a negative errno value otherwise and rte_errno is set.
3259 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
3260 const struct rte_flow_action *action,
3261 const uint64_t item_flags,
3262 struct rte_flow_error *error)
3266 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3268 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3269 return rte_flow_error_set(error, EINVAL,
3270 RTE_FLOW_ERROR_TYPE_ACTION,
3271 NULL, "no TCP item in"
3273 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
3274 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
3275 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
3276 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
3277 return rte_flow_error_set(error, EINVAL,
3278 RTE_FLOW_ERROR_TYPE_ACTION,
3280 "cannot decrease and increase"
3281 " TCP acknowledgment number"
3282 " at the same time");
3288 * Validate the modify-header TTL actions.
3290 * @param[in] action_flags
3291 * Holds the actions detected until now.
3293 * Pointer to the modify action.
3294 * @param[in] item_flags
3295 * Holds the items detected.
3297 * Pointer to error structure.
3300 * 0 on success, a negative errno value otherwise and rte_errno is set.
3303 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
3304 const struct rte_flow_action *action,
3305 const uint64_t item_flags,
3306 struct rte_flow_error *error)
3310 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3312 if (!(item_flags & MLX5_FLOW_LAYER_L3))
3313 return rte_flow_error_set(error, EINVAL,
3314 RTE_FLOW_ERROR_TYPE_ACTION,
3316 "no IP protocol in pattern");
3322 * Validate jump action.
3325 * Pointer to the jump action.
3326 * @param[in] action_flags
3327 * Holds the actions detected until now.
3328 * @param[in] attributes
3329 * Pointer to flow attributes
3330 * @param[in] external
3331 * Action belongs to flow rule created by request external to PMD.
3333 * Pointer to error structure.
3336 * 0 on success, a negative errno value otherwise and rte_errno is set.
3339 flow_dv_validate_action_jump(const struct rte_flow_action *action,
3340 uint64_t action_flags,
3341 const struct rte_flow_attr *attributes,
3342 bool external, struct rte_flow_error *error)
3344 uint32_t target_group, table;
3347 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3348 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3349 return rte_flow_error_set(error, EINVAL,
3350 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3351 "can't have 2 fate actions in"
3353 if (action_flags & MLX5_FLOW_ACTION_METER)
3354 return rte_flow_error_set(error, ENOTSUP,
3355 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3356 "jump with meter not support");
3358 return rte_flow_error_set(error, EINVAL,
3359 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3360 NULL, "action configuration not set");
3362 ((const struct rte_flow_action_jump *)action->conf)->group;
3363 ret = mlx5_flow_group_to_table(attributes, external, target_group,
3367 if (attributes->group == target_group)
3368 return rte_flow_error_set(error, EINVAL,
3369 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3370 "target group must be other than"
3371 " the current flow group");
3376 * Validate the port_id action.
3379 * Pointer to rte_eth_dev structure.
3380 * @param[in] action_flags
3381 * Bit-fields that holds the actions detected until now.
3383 * Port_id RTE action structure.
3385 * Attributes of flow that includes this action.
3387 * Pointer to error structure.
3390 * 0 on success, a negative errno value otherwise and rte_errno is set.
3393 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
3394 uint64_t action_flags,
3395 const struct rte_flow_action *action,
3396 const struct rte_flow_attr *attr,
3397 struct rte_flow_error *error)
3399 const struct rte_flow_action_port_id *port_id;
3400 struct mlx5_priv *act_priv;
3401 struct mlx5_priv *dev_priv;
3404 if (!attr->transfer)
3405 return rte_flow_error_set(error, ENOTSUP,
3406 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3408 "port id action is valid in transfer"
3410 if (!action || !action->conf)
3411 return rte_flow_error_set(error, ENOTSUP,
3412 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3414 "port id action parameters must be"
3416 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3417 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3418 return rte_flow_error_set(error, EINVAL,
3419 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3420 "can have only one fate actions in"
3422 dev_priv = mlx5_dev_to_eswitch_info(dev);
3424 return rte_flow_error_set(error, rte_errno,
3425 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3427 "failed to obtain E-Switch info");
3428 port_id = action->conf;
3429 port = port_id->original ? dev->data->port_id : port_id->id;
3430 act_priv = mlx5_port_to_eswitch_info(port, false);
3432 return rte_flow_error_set
3434 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
3435 "failed to obtain E-Switch port id for port");
3436 if (act_priv->domain_id != dev_priv->domain_id)
3437 return rte_flow_error_set
3439 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3440 "port does not belong to"
3441 " E-Switch being configured");
3446 * Get the maximum number of modify header actions.
3449 * Pointer to rte_eth_dev structure.
3451 * Flags bits to check if root level.
3454 * Max number of modify header actions device can support.
3457 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev, uint64_t flags)
3460 * There's no way to directly query the max cap. Although it has to be
3461 * acquried by iterative trial, it is a safe assumption that more
3462 * actions are supported by FW if extensive metadata register is
3463 * supported. (Only in the root table)
3465 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
3466 return MLX5_MAX_MODIFY_NUM;
3468 return mlx5_flow_ext_mreg_supported(dev) ?
3469 MLX5_ROOT_TBL_MODIFY_NUM :
3470 MLX5_ROOT_TBL_MODIFY_NUM_NO_MREG;
3474 * Validate the meter action.
3477 * Pointer to rte_eth_dev structure.
3478 * @param[in] action_flags
3479 * Bit-fields that holds the actions detected until now.
3481 * Pointer to the meter action.
3483 * Attributes of flow that includes this action.
3485 * Pointer to error structure.
3488 * 0 on success, a negative errno value otherwise and rte_ernno is set.
3491 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
3492 uint64_t action_flags,
3493 const struct rte_flow_action *action,
3494 const struct rte_flow_attr *attr,
3495 struct rte_flow_error *error)
3497 struct mlx5_priv *priv = dev->data->dev_private;
3498 const struct rte_flow_action_meter *am = action->conf;
3499 struct mlx5_flow_meter *fm;
3502 return rte_flow_error_set(error, EINVAL,
3503 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3504 "meter action conf is NULL");
3506 if (action_flags & MLX5_FLOW_ACTION_METER)
3507 return rte_flow_error_set(error, ENOTSUP,
3508 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3509 "meter chaining not support");
3510 if (action_flags & MLX5_FLOW_ACTION_JUMP)
3511 return rte_flow_error_set(error, ENOTSUP,
3512 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3513 "meter with jump not support");
3515 return rte_flow_error_set(error, ENOTSUP,
3516 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3518 "meter action not supported");
3519 fm = mlx5_flow_meter_find(priv, am->mtr_id);
3521 return rte_flow_error_set(error, EINVAL,
3522 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3524 if (fm->ref_cnt && (!(fm->attr.transfer == attr->transfer ||
3525 (!fm->attr.ingress && !attr->ingress && attr->egress) ||
3526 (!fm->attr.egress && !attr->egress && attr->ingress))))
3527 return rte_flow_error_set(error, EINVAL,
3528 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3529 "Flow attributes are either invalid "
3530 "or have a conflict with current "
3531 "meter attributes");
3536 * Validate the modify-header IPv4 DSCP actions.
3538 * @param[in] action_flags
3539 * Holds the actions detected until now.
3541 * Pointer to the modify action.
3542 * @param[in] item_flags
3543 * Holds the items detected.
3545 * Pointer to error structure.
3548 * 0 on success, a negative errno value otherwise and rte_errno is set.
3551 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
3552 const struct rte_flow_action *action,
3553 const uint64_t item_flags,
3554 struct rte_flow_error *error)
3558 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3560 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
3561 return rte_flow_error_set(error, EINVAL,
3562 RTE_FLOW_ERROR_TYPE_ACTION,
3564 "no ipv4 item in pattern");
3570 * Validate the modify-header IPv6 DSCP actions.
3572 * @param[in] action_flags
3573 * Holds the actions detected until now.
3575 * Pointer to the modify action.
3576 * @param[in] item_flags
3577 * Holds the items detected.
3579 * Pointer to error structure.
3582 * 0 on success, a negative errno value otherwise and rte_errno is set.
3585 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
3586 const struct rte_flow_action *action,
3587 const uint64_t item_flags,
3588 struct rte_flow_error *error)
3592 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3594 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
3595 return rte_flow_error_set(error, EINVAL,
3596 RTE_FLOW_ERROR_TYPE_ACTION,
3598 "no ipv6 item in pattern");
3604 * Find existing modify-header resource or create and register a new one.
3606 * @param dev[in, out]
3607 * Pointer to rte_eth_dev structure.
3608 * @param[in, out] resource
3609 * Pointer to modify-header resource.
3610 * @parm[in, out] dev_flow
3611 * Pointer to the dev_flow.
3613 * pointer to error structure.
3616 * 0 on success otherwise -errno and errno is set.
3619 flow_dv_modify_hdr_resource_register
3620 (struct rte_eth_dev *dev,
3621 struct mlx5_flow_dv_modify_hdr_resource *resource,
3622 struct mlx5_flow *dev_flow,
3623 struct rte_flow_error *error)
3625 struct mlx5_priv *priv = dev->data->dev_private;
3626 struct mlx5_ibv_shared *sh = priv->sh;
3627 struct mlx5_flow_dv_modify_hdr_resource *cache_resource;
3628 struct mlx5dv_dr_domain *ns;
3629 uint32_t actions_len;
3632 dev_flow->group ? 0 : MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
3633 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
3635 return rte_flow_error_set(error, EOVERFLOW,
3636 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3637 "too many modify header items");
3638 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3639 ns = sh->fdb_domain;
3640 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
3644 /* Lookup a matching resource from cache. */
3645 actions_len = resource->actions_num * sizeof(resource->actions[0]);
3646 LIST_FOREACH(cache_resource, &sh->modify_cmds, next) {
3647 if (resource->ft_type == cache_resource->ft_type &&
3648 resource->actions_num == cache_resource->actions_num &&
3649 resource->flags == cache_resource->flags &&
3650 !memcmp((const void *)resource->actions,
3651 (const void *)cache_resource->actions,
3653 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d++",
3654 (void *)cache_resource,
3655 rte_atomic32_read(&cache_resource->refcnt));
3656 rte_atomic32_inc(&cache_resource->refcnt);
3657 dev_flow->dv.modify_hdr = cache_resource;
3661 /* Register new modify-header resource. */
3662 cache_resource = rte_calloc(__func__, 1,
3663 sizeof(*cache_resource) + actions_len, 0);
3664 if (!cache_resource)
3665 return rte_flow_error_set(error, ENOMEM,
3666 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3667 "cannot allocate resource memory");
3668 *cache_resource = *resource;
3669 rte_memcpy(cache_resource->actions, resource->actions, actions_len);
3670 cache_resource->verbs_action =
3671 mlx5_glue->dv_create_flow_action_modify_header
3672 (sh->ctx, cache_resource->ft_type, ns,
3673 cache_resource->flags, actions_len,
3674 (uint64_t *)cache_resource->actions);
3675 if (!cache_resource->verbs_action) {
3676 rte_free(cache_resource);
3677 return rte_flow_error_set(error, ENOMEM,
3678 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3679 NULL, "cannot create action");
3681 rte_atomic32_init(&cache_resource->refcnt);
3682 rte_atomic32_inc(&cache_resource->refcnt);
3683 LIST_INSERT_HEAD(&sh->modify_cmds, cache_resource, next);
3684 dev_flow->dv.modify_hdr = cache_resource;
3685 DRV_LOG(DEBUG, "new modify-header resource %p: refcnt %d++",
3686 (void *)cache_resource,
3687 rte_atomic32_read(&cache_resource->refcnt));
3691 #define MLX5_CNT_CONTAINER_RESIZE 64
3694 * Get or create a flow counter.
3697 * Pointer to the Ethernet device structure.
3699 * Indicate if this counter is shared with other flows.
3701 * Counter identifier.
3704 * pointer to flow counter on success, NULL otherwise and rte_errno is set.
3706 static struct mlx5_flow_counter *
3707 flow_dv_counter_alloc_fallback(struct rte_eth_dev *dev, uint32_t shared,
3710 struct mlx5_priv *priv = dev->data->dev_private;
3711 struct mlx5_flow_counter *cnt = NULL;
3712 struct mlx5_devx_obj *dcs = NULL;
3714 if (!priv->config.devx) {
3715 rte_errno = ENOTSUP;
3719 TAILQ_FOREACH(cnt, &priv->sh->cmng.flow_counters, next) {
3720 if (cnt->shared && cnt->id == id) {
3726 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
3729 cnt = rte_calloc(__func__, 1, sizeof(*cnt), 0);
3731 claim_zero(mlx5_devx_cmd_destroy(cnt->dcs));
3735 struct mlx5_flow_counter tmpl = {
3741 tmpl.action = mlx5_glue->dv_create_flow_action_counter(dcs->obj, 0);
3743 claim_zero(mlx5_devx_cmd_destroy(cnt->dcs));
3749 TAILQ_INSERT_HEAD(&priv->sh->cmng.flow_counters, cnt, next);
3754 * Release a flow counter.
3757 * Pointer to the Ethernet device structure.
3758 * @param[in] counter
3759 * Pointer to the counter handler.
3762 flow_dv_counter_release_fallback(struct rte_eth_dev *dev,
3763 struct mlx5_flow_counter *counter)
3765 struct mlx5_priv *priv = dev->data->dev_private;
3769 if (--counter->ref_cnt == 0) {
3770 TAILQ_REMOVE(&priv->sh->cmng.flow_counters, counter, next);
3771 claim_zero(mlx5_devx_cmd_destroy(counter->dcs));
3777 * Query a devx flow counter.
3780 * Pointer to the Ethernet device structure.
3782 * Pointer to the flow counter.
3784 * The statistics value of packets.
3786 * The statistics value of bytes.
3789 * 0 on success, otherwise a negative errno value and rte_errno is set.
3792 _flow_dv_query_count_fallback(struct rte_eth_dev *dev __rte_unused,
3793 struct mlx5_flow_counter *cnt, uint64_t *pkts,
3796 return mlx5_devx_cmd_flow_counter_query(cnt->dcs, 0, 0, pkts, bytes,
3801 * Get a pool by a counter.
3804 * Pointer to the counter.
3809 static struct mlx5_flow_counter_pool *
3810 flow_dv_counter_pool_get(struct mlx5_flow_counter *cnt)
3813 cnt -= cnt->dcs->id % MLX5_COUNTERS_PER_POOL;
3814 return (struct mlx5_flow_counter_pool *)cnt - 1;
3820 * Get a pool by devx counter ID.
3823 * Pointer to the counter container.
3825 * The counter devx ID.
3828 * The counter pool pointer if exists, NULL otherwise,
3830 static struct mlx5_flow_counter_pool *
3831 flow_dv_find_pool_by_id(struct mlx5_pools_container *cont, int id)
3833 struct mlx5_flow_counter_pool *pool;
3835 TAILQ_FOREACH(pool, &cont->pool_list, next) {
3836 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
3837 MLX5_COUNTERS_PER_POOL;
3839 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
3846 * Allocate a new memory for the counter values wrapped by all the needed
3850 * Pointer to the Ethernet device structure.
3852 * The raw memory areas - each one for MLX5_COUNTERS_PER_POOL counters.
3855 * The new memory management pointer on success, otherwise NULL and rte_errno
3858 static struct mlx5_counter_stats_mem_mng *
3859 flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
3861 struct mlx5_ibv_shared *sh = ((struct mlx5_priv *)
3862 (dev->data->dev_private))->sh;
3863 struct mlx5_devx_mkey_attr mkey_attr;
3864 struct mlx5_counter_stats_mem_mng *mem_mng;
3865 volatile struct flow_counter_stats *raw_data;
3866 int size = (sizeof(struct flow_counter_stats) *
3867 MLX5_COUNTERS_PER_POOL +
3868 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
3869 sizeof(struct mlx5_counter_stats_mem_mng);
3870 uint8_t *mem = rte_calloc(__func__, 1, size, sysconf(_SC_PAGESIZE));
3877 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
3878 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
3879 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
3880 IBV_ACCESS_LOCAL_WRITE);
3881 if (!mem_mng->umem) {
3886 mkey_attr.addr = (uintptr_t)mem;
3887 mkey_attr.size = size;
3888 mkey_attr.umem_id = mem_mng->umem->umem_id;
3889 mkey_attr.pd = sh->pdn;
3890 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
3892 mlx5_glue->devx_umem_dereg(mem_mng->umem);
3897 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
3898 raw_data = (volatile struct flow_counter_stats *)mem;
3899 for (i = 0; i < raws_n; ++i) {
3900 mem_mng->raws[i].mem_mng = mem_mng;
3901 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
3903 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
3908 * Resize a counter container.
3911 * Pointer to the Ethernet device structure.
3913 * Whether the pool is for counter that was allocated by batch command.
3916 * The new container pointer on success, otherwise NULL and rte_errno is set.
3918 static struct mlx5_pools_container *
3919 flow_dv_container_resize(struct rte_eth_dev *dev, uint32_t batch)
3921 struct mlx5_priv *priv = dev->data->dev_private;
3922 struct mlx5_pools_container *cont =
3923 MLX5_CNT_CONTAINER(priv->sh, batch, 0);
3924 struct mlx5_pools_container *new_cont =
3925 MLX5_CNT_CONTAINER_UNUSED(priv->sh, batch, 0);
3926 struct mlx5_counter_stats_mem_mng *mem_mng;
3927 uint32_t resize = cont->n + MLX5_CNT_CONTAINER_RESIZE;
3928 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
3931 if (cont != MLX5_CNT_CONTAINER(priv->sh, batch, 1)) {
3932 /* The last resize still hasn't detected by the host thread. */
3936 new_cont->pools = rte_calloc(__func__, 1, mem_size, 0);
3937 if (!new_cont->pools) {
3942 memcpy(new_cont->pools, cont->pools, cont->n *
3943 sizeof(struct mlx5_flow_counter_pool *));
3944 mem_mng = flow_dv_create_counter_stat_mem_mng(dev,
3945 MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES);
3947 rte_free(new_cont->pools);
3950 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
3951 LIST_INSERT_HEAD(&priv->sh->cmng.free_stat_raws,
3952 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE +
3954 new_cont->n = resize;
3955 rte_atomic16_set(&new_cont->n_valid, rte_atomic16_read(&cont->n_valid));
3956 TAILQ_INIT(&new_cont->pool_list);
3957 TAILQ_CONCAT(&new_cont->pool_list, &cont->pool_list, next);
3958 new_cont->init_mem_mng = mem_mng;
3960 /* Flip the master container. */
3961 priv->sh->cmng.mhi[batch] ^= (uint8_t)1;
3966 * Query a devx flow counter.
3969 * Pointer to the Ethernet device structure.
3971 * Pointer to the flow counter.
3973 * The statistics value of packets.
3975 * The statistics value of bytes.
3978 * 0 on success, otherwise a negative errno value and rte_errno is set.
3981 _flow_dv_query_count(struct rte_eth_dev *dev,
3982 struct mlx5_flow_counter *cnt, uint64_t *pkts,
3985 struct mlx5_priv *priv = dev->data->dev_private;
3986 struct mlx5_flow_counter_pool *pool =
3987 flow_dv_counter_pool_get(cnt);
3988 int offset = cnt - &pool->counters_raw[0];
3990 if (priv->counter_fallback)
3991 return _flow_dv_query_count_fallback(dev, cnt, pkts, bytes);
3993 rte_spinlock_lock(&pool->sl);
3995 * The single counters allocation may allocate smaller ID than the
3996 * current allocated in parallel to the host reading.
3997 * In this case the new counter values must be reported as 0.
3999 if (unlikely(!cnt->batch && cnt->dcs->id < pool->raw->min_dcs_id)) {
4003 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
4004 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
4006 rte_spinlock_unlock(&pool->sl);
4011 * Create and initialize a new counter pool.
4014 * Pointer to the Ethernet device structure.
4016 * The devX counter handle.
4018 * Whether the pool is for counter that was allocated by batch command.
4021 * A new pool pointer on success, NULL otherwise and rte_errno is set.
4023 static struct mlx5_flow_counter_pool *
4024 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
4027 struct mlx5_priv *priv = dev->data->dev_private;
4028 struct mlx5_flow_counter_pool *pool;
4029 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4031 int16_t n_valid = rte_atomic16_read(&cont->n_valid);
4034 if (cont->n == n_valid) {
4035 cont = flow_dv_container_resize(dev, batch);
4039 size = sizeof(*pool) + MLX5_COUNTERS_PER_POOL *
4040 sizeof(struct mlx5_flow_counter);
4041 pool = rte_calloc(__func__, 1, size, 0);
4046 pool->min_dcs = dcs;
4047 pool->raw = cont->init_mem_mng->raws + n_valid %
4048 MLX5_CNT_CONTAINER_RESIZE;
4049 pool->raw_hw = NULL;
4050 rte_spinlock_init(&pool->sl);
4052 * The generation of the new allocated counters in this pool is 0, 2 in
4053 * the pool generation makes all the counters valid for allocation.
4055 rte_atomic64_set(&pool->query_gen, 0x2);
4056 TAILQ_INIT(&pool->counters);
4057 TAILQ_INSERT_TAIL(&cont->pool_list, pool, next);
4058 cont->pools[n_valid] = pool;
4059 /* Pool initialization must be updated before host thread access. */
4061 rte_atomic16_add(&cont->n_valid, 1);
4066 * Prepare a new counter and/or a new counter pool.
4069 * Pointer to the Ethernet device structure.
4070 * @param[out] cnt_free
4071 * Where to put the pointer of a new counter.
4073 * Whether the pool is for counter that was allocated by batch command.
4076 * The free counter pool pointer and @p cnt_free is set on success,
4077 * NULL otherwise and rte_errno is set.
4079 static struct mlx5_flow_counter_pool *
4080 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
4081 struct mlx5_flow_counter **cnt_free,
4084 struct mlx5_priv *priv = dev->data->dev_private;
4085 struct mlx5_flow_counter_pool *pool;
4086 struct mlx5_devx_obj *dcs = NULL;
4087 struct mlx5_flow_counter *cnt;
4091 /* bulk_bitmap must be 0 for single counter allocation. */
4092 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
4095 pool = flow_dv_find_pool_by_id
4096 (MLX5_CNT_CONTAINER(priv->sh, batch, 0), dcs->id);
4098 pool = flow_dv_pool_create(dev, dcs, batch);
4100 mlx5_devx_cmd_destroy(dcs);
4103 } else if (dcs->id < pool->min_dcs->id) {
4104 rte_atomic64_set(&pool->a64_dcs,
4105 (int64_t)(uintptr_t)dcs);
4107 cnt = &pool->counters_raw[dcs->id % MLX5_COUNTERS_PER_POOL];
4108 TAILQ_INSERT_HEAD(&pool->counters, cnt, next);
4113 /* bulk_bitmap is in 128 counters units. */
4114 if (priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4)
4115 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
4117 rte_errno = ENODATA;
4120 pool = flow_dv_pool_create(dev, dcs, batch);
4122 mlx5_devx_cmd_destroy(dcs);
4125 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
4126 cnt = &pool->counters_raw[i];
4128 TAILQ_INSERT_HEAD(&pool->counters, cnt, next);
4130 *cnt_free = &pool->counters_raw[0];
4135 * Search for existed shared counter.
4138 * Pointer to the relevant counter pool container.
4140 * The shared counter ID to search.
4143 * NULL if not existed, otherwise pointer to the shared counter.
4145 static struct mlx5_flow_counter *
4146 flow_dv_counter_shared_search(struct mlx5_pools_container *cont,
4149 static struct mlx5_flow_counter *cnt;
4150 struct mlx5_flow_counter_pool *pool;
4153 TAILQ_FOREACH(pool, &cont->pool_list, next) {
4154 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
4155 cnt = &pool->counters_raw[i];
4156 if (cnt->ref_cnt && cnt->shared && cnt->id == id)
4164 * Allocate a flow counter.
4167 * Pointer to the Ethernet device structure.
4169 * Indicate if this counter is shared with other flows.
4171 * Counter identifier.
4173 * Counter flow group.
4176 * pointer to flow counter on success, NULL otherwise and rte_errno is set.
4178 static struct mlx5_flow_counter *
4179 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
4182 struct mlx5_priv *priv = dev->data->dev_private;
4183 struct mlx5_flow_counter_pool *pool = NULL;
4184 struct mlx5_flow_counter *cnt_free = NULL;
4186 * Currently group 0 flow counter cannot be assigned to a flow if it is
4187 * not the first one in the batch counter allocation, so it is better
4188 * to allocate counters one by one for these flows in a separate
4190 * A counter can be shared between different groups so need to take
4191 * shared counters from the single container.
4193 uint32_t batch = (group && !shared) ? 1 : 0;
4194 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4197 if (priv->counter_fallback)
4198 return flow_dv_counter_alloc_fallback(dev, shared, id);
4199 if (!priv->config.devx) {
4200 rte_errno = ENOTSUP;
4204 cnt_free = flow_dv_counter_shared_search(cont, id);
4206 if (cnt_free->ref_cnt + 1 == 0) {
4210 cnt_free->ref_cnt++;
4214 /* Pools which has a free counters are in the start. */
4215 TAILQ_FOREACH(pool, &cont->pool_list, next) {
4217 * The free counter reset values must be updated between the
4218 * counter release to the counter allocation, so, at least one
4219 * query must be done in this time. ensure it by saving the
4220 * query generation in the release time.
4221 * The free list is sorted according to the generation - so if
4222 * the first one is not updated, all the others are not
4225 cnt_free = TAILQ_FIRST(&pool->counters);
4226 if (cnt_free && cnt_free->query_gen + 1 <
4227 rte_atomic64_read(&pool->query_gen))
4232 pool = flow_dv_counter_pool_prepare(dev, &cnt_free, batch);
4236 cnt_free->batch = batch;
4237 /* Create a DV counter action only in the first time usage. */
4238 if (!cnt_free->action) {
4240 struct mlx5_devx_obj *dcs;
4243 offset = cnt_free - &pool->counters_raw[0];
4244 dcs = pool->min_dcs;
4247 dcs = cnt_free->dcs;
4249 cnt_free->action = mlx5_glue->dv_create_flow_action_counter
4251 if (!cnt_free->action) {
4256 /* Update the counter reset values. */
4257 if (_flow_dv_query_count(dev, cnt_free, &cnt_free->hits,
4260 cnt_free->shared = shared;
4261 cnt_free->ref_cnt = 1;
4263 if (!priv->sh->cmng.query_thread_on)
4264 /* Start the asynchronous batch query by the host thread. */
4265 mlx5_set_query_alarm(priv->sh);
4266 TAILQ_REMOVE(&pool->counters, cnt_free, next);
4267 if (TAILQ_EMPTY(&pool->counters)) {
4268 /* Move the pool to the end of the container pool list. */
4269 TAILQ_REMOVE(&cont->pool_list, pool, next);
4270 TAILQ_INSERT_TAIL(&cont->pool_list, pool, next);
4276 * Release a flow counter.
4279 * Pointer to the Ethernet device structure.
4280 * @param[in] counter
4281 * Pointer to the counter handler.
4284 flow_dv_counter_release(struct rte_eth_dev *dev,
4285 struct mlx5_flow_counter *counter)
4287 struct mlx5_priv *priv = dev->data->dev_private;
4291 if (priv->counter_fallback) {
4292 flow_dv_counter_release_fallback(dev, counter);
4295 if (--counter->ref_cnt == 0) {
4296 struct mlx5_flow_counter_pool *pool =
4297 flow_dv_counter_pool_get(counter);
4299 /* Put the counter in the end - the last updated one. */
4300 TAILQ_INSERT_TAIL(&pool->counters, counter, next);
4301 counter->query_gen = rte_atomic64_read(&pool->query_gen);
4306 * Verify the @p attributes will be correctly understood by the NIC and store
4307 * them in the @p flow if everything is correct.
4310 * Pointer to dev struct.
4311 * @param[in] attributes
4312 * Pointer to flow attributes
4313 * @param[in] external
4314 * This flow rule is created by request external to PMD.
4316 * Pointer to error structure.
4319 * 0 on success, a negative errno value otherwise and rte_errno is set.
4322 flow_dv_validate_attributes(struct rte_eth_dev *dev,
4323 const struct rte_flow_attr *attributes,
4324 bool external __rte_unused,
4325 struct rte_flow_error *error)
4327 struct mlx5_priv *priv = dev->data->dev_private;
4328 uint32_t priority_max = priv->config.flow_prio - 1;
4330 #ifndef HAVE_MLX5DV_DR
4331 if (attributes->group)
4332 return rte_flow_error_set(error, ENOTSUP,
4333 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
4335 "groups are not supported");
4340 ret = mlx5_flow_group_to_table(attributes, external,
4346 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
4347 attributes->priority >= priority_max)
4348 return rte_flow_error_set(error, ENOTSUP,
4349 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
4351 "priority out of range");
4352 if (attributes->transfer) {
4353 if (!priv->config.dv_esw_en)
4354 return rte_flow_error_set
4356 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4357 "E-Switch dr is not supported");
4358 if (!(priv->representor || priv->master))
4359 return rte_flow_error_set
4360 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4361 NULL, "E-Switch configuration can only be"
4362 " done by a master or a representor device");
4363 if (attributes->egress)
4364 return rte_flow_error_set
4366 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
4367 "egress is not supported");
4369 if (!(attributes->egress ^ attributes->ingress))
4370 return rte_flow_error_set(error, ENOTSUP,
4371 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
4372 "must specify exactly one of "
4373 "ingress or egress");
4378 * Internal validation function. For validating both actions and items.
4381 * Pointer to the rte_eth_dev structure.
4383 * Pointer to the flow attributes.
4385 * Pointer to the list of items.
4386 * @param[in] actions
4387 * Pointer to the list of actions.
4388 * @param[in] external
4389 * This flow rule is created by request external to PMD.
4391 * Pointer to the error structure.
4394 * 0 on success, a negative errno value otherwise and rte_errno is set.
4397 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
4398 const struct rte_flow_item items[],
4399 const struct rte_flow_action actions[],
4400 bool external, struct rte_flow_error *error)
4403 uint64_t action_flags = 0;
4404 uint64_t item_flags = 0;
4405 uint64_t last_item = 0;
4406 uint8_t next_protocol = 0xff;
4407 uint16_t ether_type = 0;
4409 const struct rte_flow_item *gre_item = NULL;
4410 struct rte_flow_item_tcp nic_tcp_mask = {
4413 .src_port = RTE_BE16(UINT16_MAX),
4414 .dst_port = RTE_BE16(UINT16_MAX),
4417 struct mlx5_priv *priv = dev->data->dev_private;
4418 struct mlx5_dev_config *dev_conf = &priv->config;
4422 ret = flow_dv_validate_attributes(dev, attr, external, error);
4425 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4426 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
4427 int type = items->type;
4430 case RTE_FLOW_ITEM_TYPE_VOID:
4432 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4433 ret = flow_dv_validate_item_port_id
4434 (dev, items, attr, item_flags, error);
4437 last_item = MLX5_FLOW_ITEM_PORT_ID;
4439 case RTE_FLOW_ITEM_TYPE_ETH:
4440 ret = mlx5_flow_validate_item_eth(items, item_flags,
4444 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
4445 MLX5_FLOW_LAYER_OUTER_L2;
4446 if (items->mask != NULL && items->spec != NULL) {
4448 ((const struct rte_flow_item_eth *)
4451 ((const struct rte_flow_item_eth *)
4453 ether_type = rte_be_to_cpu_16(ether_type);
4458 case RTE_FLOW_ITEM_TYPE_VLAN:
4459 ret = mlx5_flow_validate_item_vlan(items, item_flags,
4463 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
4464 MLX5_FLOW_LAYER_OUTER_VLAN;
4465 if (items->mask != NULL && items->spec != NULL) {
4467 ((const struct rte_flow_item_vlan *)
4468 items->spec)->inner_type;
4470 ((const struct rte_flow_item_vlan *)
4471 items->mask)->inner_type;
4472 ether_type = rte_be_to_cpu_16(ether_type);
4477 case RTE_FLOW_ITEM_TYPE_IPV4:
4478 mlx5_flow_tunnel_ip_check(items, next_protocol,
4479 &item_flags, &tunnel);
4480 ret = mlx5_flow_validate_item_ipv4(items, item_flags,
4486 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4487 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4488 if (items->mask != NULL &&
4489 ((const struct rte_flow_item_ipv4 *)
4490 items->mask)->hdr.next_proto_id) {
4492 ((const struct rte_flow_item_ipv4 *)
4493 (items->spec))->hdr.next_proto_id;
4495 ((const struct rte_flow_item_ipv4 *)
4496 (items->mask))->hdr.next_proto_id;
4498 /* Reset for inner layer. */
4499 next_protocol = 0xff;
4502 case RTE_FLOW_ITEM_TYPE_IPV6:
4503 mlx5_flow_tunnel_ip_check(items, next_protocol,
4504 &item_flags, &tunnel);
4505 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
4511 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4512 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4513 if (items->mask != NULL &&
4514 ((const struct rte_flow_item_ipv6 *)
4515 items->mask)->hdr.proto) {
4517 ((const struct rte_flow_item_ipv6 *)
4518 items->spec)->hdr.proto;
4520 ((const struct rte_flow_item_ipv6 *)
4521 items->mask)->hdr.proto;
4523 /* Reset for inner layer. */
4524 next_protocol = 0xff;
4527 case RTE_FLOW_ITEM_TYPE_TCP:
4528 ret = mlx5_flow_validate_item_tcp
4535 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
4536 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4538 case RTE_FLOW_ITEM_TYPE_UDP:
4539 ret = mlx5_flow_validate_item_udp(items, item_flags,
4544 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
4545 MLX5_FLOW_LAYER_OUTER_L4_UDP;
4547 case RTE_FLOW_ITEM_TYPE_GRE:
4548 ret = mlx5_flow_validate_item_gre(items, item_flags,
4549 next_protocol, error);
4553 last_item = MLX5_FLOW_LAYER_GRE;
4555 case RTE_FLOW_ITEM_TYPE_NVGRE:
4556 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
4561 last_item = MLX5_FLOW_LAYER_NVGRE;
4563 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
4564 ret = mlx5_flow_validate_item_gre_key
4565 (items, item_flags, gre_item, error);
4568 last_item = MLX5_FLOW_LAYER_GRE_KEY;
4570 case RTE_FLOW_ITEM_TYPE_VXLAN:
4571 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
4575 last_item = MLX5_FLOW_LAYER_VXLAN;
4577 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4578 ret = mlx5_flow_validate_item_vxlan_gpe(items,
4583 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
4585 case RTE_FLOW_ITEM_TYPE_GENEVE:
4586 ret = mlx5_flow_validate_item_geneve(items,
4591 last_item = MLX5_FLOW_LAYER_GENEVE;
4593 case RTE_FLOW_ITEM_TYPE_MPLS:
4594 ret = mlx5_flow_validate_item_mpls(dev, items,
4599 last_item = MLX5_FLOW_LAYER_MPLS;
4602 case RTE_FLOW_ITEM_TYPE_MARK:
4603 ret = flow_dv_validate_item_mark(dev, items, attr,
4607 last_item = MLX5_FLOW_ITEM_MARK;
4609 case RTE_FLOW_ITEM_TYPE_META:
4610 ret = flow_dv_validate_item_meta(dev, items, attr,
4614 last_item = MLX5_FLOW_ITEM_METADATA;
4616 case RTE_FLOW_ITEM_TYPE_ICMP:
4617 ret = mlx5_flow_validate_item_icmp(items, item_flags,
4622 last_item = MLX5_FLOW_LAYER_ICMP;
4624 case RTE_FLOW_ITEM_TYPE_ICMP6:
4625 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
4630 last_item = MLX5_FLOW_LAYER_ICMP6;
4632 case RTE_FLOW_ITEM_TYPE_TAG:
4633 ret = flow_dv_validate_item_tag(dev, items,
4637 last_item = MLX5_FLOW_ITEM_TAG;
4639 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
4640 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
4642 case RTE_FLOW_ITEM_TYPE_GTP:
4643 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
4647 last_item = MLX5_FLOW_LAYER_GTP;
4650 return rte_flow_error_set(error, ENOTSUP,
4651 RTE_FLOW_ERROR_TYPE_ITEM,
4652 NULL, "item not supported");
4654 item_flags |= last_item;
4656 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4657 int type = actions->type;
4658 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
4659 return rte_flow_error_set(error, ENOTSUP,
4660 RTE_FLOW_ERROR_TYPE_ACTION,
4661 actions, "too many actions");
4663 case RTE_FLOW_ACTION_TYPE_VOID:
4665 case RTE_FLOW_ACTION_TYPE_PORT_ID:
4666 ret = flow_dv_validate_action_port_id(dev,
4673 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
4676 case RTE_FLOW_ACTION_TYPE_FLAG:
4677 ret = flow_dv_validate_action_flag(dev, action_flags,
4681 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
4682 /* Count all modify-header actions as one. */
4683 if (!(action_flags &
4684 MLX5_FLOW_MODIFY_HDR_ACTIONS))
4686 action_flags |= MLX5_FLOW_ACTION_FLAG |
4687 MLX5_FLOW_ACTION_MARK_EXT;
4689 action_flags |= MLX5_FLOW_ACTION_FLAG;
4693 case RTE_FLOW_ACTION_TYPE_MARK:
4694 ret = flow_dv_validate_action_mark(dev, actions,
4699 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
4700 /* Count all modify-header actions as one. */
4701 if (!(action_flags &
4702 MLX5_FLOW_MODIFY_HDR_ACTIONS))
4704 action_flags |= MLX5_FLOW_ACTION_MARK |
4705 MLX5_FLOW_ACTION_MARK_EXT;
4707 action_flags |= MLX5_FLOW_ACTION_MARK;
4711 case RTE_FLOW_ACTION_TYPE_SET_META:
4712 ret = flow_dv_validate_action_set_meta(dev, actions,
4717 /* Count all modify-header actions as one action. */
4718 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4720 action_flags |= MLX5_FLOW_ACTION_SET_META;
4722 case RTE_FLOW_ACTION_TYPE_SET_TAG:
4723 ret = flow_dv_validate_action_set_tag(dev, actions,
4728 /* Count all modify-header actions as one action. */
4729 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4731 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
4733 case RTE_FLOW_ACTION_TYPE_DROP:
4734 ret = mlx5_flow_validate_action_drop(action_flags,
4738 action_flags |= MLX5_FLOW_ACTION_DROP;
4741 case RTE_FLOW_ACTION_TYPE_QUEUE:
4742 ret = mlx5_flow_validate_action_queue(actions,
4747 action_flags |= MLX5_FLOW_ACTION_QUEUE;
4750 case RTE_FLOW_ACTION_TYPE_RSS:
4751 ret = mlx5_flow_validate_action_rss(actions,
4757 action_flags |= MLX5_FLOW_ACTION_RSS;
4760 case RTE_FLOW_ACTION_TYPE_COUNT:
4761 ret = flow_dv_validate_action_count(dev, error);
4764 action_flags |= MLX5_FLOW_ACTION_COUNT;
4767 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
4768 if (flow_dv_validate_action_pop_vlan(dev,
4774 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
4777 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4778 ret = flow_dv_validate_action_push_vlan(action_flags,
4784 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
4787 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4788 ret = flow_dv_validate_action_set_vlan_pcp
4789 (action_flags, actions, error);
4792 /* Count PCP with push_vlan command. */
4793 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
4795 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4796 ret = flow_dv_validate_action_set_vlan_vid
4797 (item_flags, action_flags,
4801 /* Count VID with push_vlan command. */
4802 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
4804 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4805 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4806 ret = flow_dv_validate_action_l2_encap(action_flags,
4811 action_flags |= actions->type ==
4812 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ?
4813 MLX5_FLOW_ACTION_VXLAN_ENCAP :
4814 MLX5_FLOW_ACTION_NVGRE_ENCAP;
4817 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4818 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4819 ret = flow_dv_validate_action_l2_decap(action_flags,
4823 action_flags |= actions->type ==
4824 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ?
4825 MLX5_FLOW_ACTION_VXLAN_DECAP :
4826 MLX5_FLOW_ACTION_NVGRE_DECAP;
4829 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4830 ret = flow_dv_validate_action_raw_encap(action_flags,
4835 action_flags |= MLX5_FLOW_ACTION_RAW_ENCAP;
4838 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4839 ret = flow_dv_validate_action_raw_decap(action_flags,
4844 action_flags |= MLX5_FLOW_ACTION_RAW_DECAP;
4847 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4848 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4849 ret = flow_dv_validate_action_modify_mac(action_flags,
4855 /* Count all modify-header actions as one action. */
4856 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4858 action_flags |= actions->type ==
4859 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
4860 MLX5_FLOW_ACTION_SET_MAC_SRC :
4861 MLX5_FLOW_ACTION_SET_MAC_DST;
4864 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4865 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4866 ret = flow_dv_validate_action_modify_ipv4(action_flags,
4872 /* Count all modify-header actions as one action. */
4873 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4875 action_flags |= actions->type ==
4876 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
4877 MLX5_FLOW_ACTION_SET_IPV4_SRC :
4878 MLX5_FLOW_ACTION_SET_IPV4_DST;
4880 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4881 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4882 ret = flow_dv_validate_action_modify_ipv6(action_flags,
4888 /* Count all modify-header actions as one action. */
4889 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4891 action_flags |= actions->type ==
4892 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
4893 MLX5_FLOW_ACTION_SET_IPV6_SRC :
4894 MLX5_FLOW_ACTION_SET_IPV6_DST;
4896 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4897 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4898 ret = flow_dv_validate_action_modify_tp(action_flags,
4904 /* Count all modify-header actions as one action. */
4905 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4907 action_flags |= actions->type ==
4908 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
4909 MLX5_FLOW_ACTION_SET_TP_SRC :
4910 MLX5_FLOW_ACTION_SET_TP_DST;
4912 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4913 case RTE_FLOW_ACTION_TYPE_SET_TTL:
4914 ret = flow_dv_validate_action_modify_ttl(action_flags,
4920 /* Count all modify-header actions as one action. */
4921 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4923 action_flags |= actions->type ==
4924 RTE_FLOW_ACTION_TYPE_SET_TTL ?
4925 MLX5_FLOW_ACTION_SET_TTL :
4926 MLX5_FLOW_ACTION_DEC_TTL;
4928 case RTE_FLOW_ACTION_TYPE_JUMP:
4929 ret = flow_dv_validate_action_jump(actions,
4936 action_flags |= MLX5_FLOW_ACTION_JUMP;
4938 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4939 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4940 ret = flow_dv_validate_action_modify_tcp_seq
4947 /* Count all modify-header actions as one action. */
4948 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4950 action_flags |= actions->type ==
4951 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
4952 MLX5_FLOW_ACTION_INC_TCP_SEQ :
4953 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
4955 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4956 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4957 ret = flow_dv_validate_action_modify_tcp_ack
4964 /* Count all modify-header actions as one action. */
4965 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4967 action_flags |= actions->type ==
4968 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
4969 MLX5_FLOW_ACTION_INC_TCP_ACK :
4970 MLX5_FLOW_ACTION_DEC_TCP_ACK;
4972 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
4973 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
4974 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
4976 case RTE_FLOW_ACTION_TYPE_METER:
4977 ret = mlx5_flow_validate_action_meter(dev,
4983 action_flags |= MLX5_FLOW_ACTION_METER;
4986 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4987 ret = flow_dv_validate_action_modify_ipv4_dscp
4994 /* Count all modify-header actions as one action. */
4995 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4997 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
4999 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5000 ret = flow_dv_validate_action_modify_ipv6_dscp
5007 /* Count all modify-header actions as one action. */
5008 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5010 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
5013 return rte_flow_error_set(error, ENOTSUP,
5014 RTE_FLOW_ERROR_TYPE_ACTION,
5016 "action not supported");
5020 * Validate the drop action mutual exclusion with other actions.
5021 * Drop action is mutually-exclusive with any other action, except for
5024 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
5025 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
5026 return rte_flow_error_set(error, EINVAL,
5027 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5028 "Drop action is mutually-exclusive "
5029 "with any other action, except for "
5031 /* Eswitch has few restrictions on using items and actions */
5032 if (attr->transfer) {
5033 if (!mlx5_flow_ext_mreg_supported(dev) &&
5034 action_flags & MLX5_FLOW_ACTION_FLAG)
5035 return rte_flow_error_set(error, ENOTSUP,
5036 RTE_FLOW_ERROR_TYPE_ACTION,
5038 "unsupported action FLAG");
5039 if (!mlx5_flow_ext_mreg_supported(dev) &&
5040 action_flags & MLX5_FLOW_ACTION_MARK)
5041 return rte_flow_error_set(error, ENOTSUP,
5042 RTE_FLOW_ERROR_TYPE_ACTION,
5044 "unsupported action MARK");
5045 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
5046 return rte_flow_error_set(error, ENOTSUP,
5047 RTE_FLOW_ERROR_TYPE_ACTION,
5049 "unsupported action QUEUE");
5050 if (action_flags & MLX5_FLOW_ACTION_RSS)
5051 return rte_flow_error_set(error, ENOTSUP,
5052 RTE_FLOW_ERROR_TYPE_ACTION,
5054 "unsupported action RSS");
5055 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5056 return rte_flow_error_set(error, EINVAL,
5057 RTE_FLOW_ERROR_TYPE_ACTION,
5059 "no fate action is found");
5061 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
5062 return rte_flow_error_set(error, EINVAL,
5063 RTE_FLOW_ERROR_TYPE_ACTION,
5065 "no fate action is found");
5071 * Internal preparation function. Allocates the DV flow size,
5072 * this size is constant.
5075 * Pointer to the flow attributes.
5077 * Pointer to the list of items.
5078 * @param[in] actions
5079 * Pointer to the list of actions.
5081 * Pointer to the error structure.
5084 * Pointer to mlx5_flow object on success,
5085 * otherwise NULL and rte_errno is set.
5087 static struct mlx5_flow *
5088 flow_dv_prepare(const struct rte_flow_attr *attr __rte_unused,
5089 const struct rte_flow_item items[] __rte_unused,
5090 const struct rte_flow_action actions[] __rte_unused,
5091 struct rte_flow_error *error)
5093 size_t size = sizeof(struct mlx5_flow);
5094 struct mlx5_flow *dev_flow;
5096 dev_flow = rte_calloc(__func__, 1, size, 0);
5098 rte_flow_error_set(error, ENOMEM,
5099 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5100 "not enough memory to create flow");
5103 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
5104 dev_flow->ingress = attr->ingress;
5105 dev_flow->transfer = attr->transfer;
5111 * Sanity check for match mask and value. Similar to check_valid_spec() in
5112 * kernel driver. If unmasked bit is present in value, it returns failure.
5115 * pointer to match mask buffer.
5116 * @param match_value
5117 * pointer to match value buffer.
5120 * 0 if valid, -EINVAL otherwise.
5123 flow_dv_check_valid_spec(void *match_mask, void *match_value)
5125 uint8_t *m = match_mask;
5126 uint8_t *v = match_value;
5129 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
5132 "match_value differs from match_criteria"
5133 " %p[%u] != %p[%u]",
5134 match_value, i, match_mask, i);
5143 * Add Ethernet item to matcher and to the value.
5145 * @param[in, out] matcher
5147 * @param[in, out] key
5148 * Flow matcher value.
5150 * Flow pattern to translate.
5152 * Item is inner pattern.
5155 flow_dv_translate_item_eth(void *matcher, void *key,
5156 const struct rte_flow_item *item, int inner)
5158 const struct rte_flow_item_eth *eth_m = item->mask;
5159 const struct rte_flow_item_eth *eth_v = item->spec;
5160 const struct rte_flow_item_eth nic_mask = {
5161 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
5162 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
5163 .type = RTE_BE16(0xffff),
5175 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5177 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5179 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5181 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5183 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, dmac_47_16),
5184 ð_m->dst, sizeof(eth_m->dst));
5185 /* The value must be in the range of the mask. */
5186 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, dmac_47_16);
5187 for (i = 0; i < sizeof(eth_m->dst); ++i)
5188 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
5189 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, smac_47_16),
5190 ð_m->src, sizeof(eth_m->src));
5191 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, smac_47_16);
5192 /* The value must be in the range of the mask. */
5193 for (i = 0; i < sizeof(eth_m->dst); ++i)
5194 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
5195 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
5196 rte_be_to_cpu_16(eth_m->type));
5197 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, ethertype);
5198 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
5202 * Add VLAN item to matcher and to the value.
5204 * @param[in, out] dev_flow
5206 * @param[in, out] matcher
5208 * @param[in, out] key
5209 * Flow matcher value.
5211 * Flow pattern to translate.
5213 * Item is inner pattern.
5216 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
5217 void *matcher, void *key,
5218 const struct rte_flow_item *item,
5221 const struct rte_flow_item_vlan *vlan_m = item->mask;
5222 const struct rte_flow_item_vlan *vlan_v = item->spec;
5231 vlan_m = &rte_flow_item_vlan_mask;
5233 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5235 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5237 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5239 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5241 * This is workaround, masks are not supported,
5242 * and pre-validated.
5244 dev_flow->dv.vf_vlan.tag =
5245 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
5247 tci_m = rte_be_to_cpu_16(vlan_m->tci);
5248 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
5249 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5250 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
5251 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_vid, tci_m);
5252 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, tci_v);
5253 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_cfi, tci_m >> 12);
5254 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_cfi, tci_v >> 12);
5255 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_prio, tci_m >> 13);
5256 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, tci_v >> 13);
5257 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
5258 rte_be_to_cpu_16(vlan_m->inner_type));
5259 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
5260 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
5264 * Add IPV4 item to matcher and to the value.
5266 * @param[in, out] matcher
5268 * @param[in, out] key
5269 * Flow matcher value.
5271 * Flow pattern to translate.
5273 * Item is inner pattern.
5275 * The group to insert the rule.
5278 flow_dv_translate_item_ipv4(void *matcher, void *key,
5279 const struct rte_flow_item *item,
5280 int inner, uint32_t group)
5282 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
5283 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
5284 const struct rte_flow_item_ipv4 nic_mask = {
5286 .src_addr = RTE_BE32(0xffffffff),
5287 .dst_addr = RTE_BE32(0xffffffff),
5288 .type_of_service = 0xff,
5289 .next_proto_id = 0xff,
5299 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5301 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5303 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5305 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5308 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
5310 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0x4);
5311 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 4);
5316 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5317 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
5318 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5319 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
5320 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
5321 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
5322 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5323 src_ipv4_src_ipv6.ipv4_layout.ipv4);
5324 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5325 src_ipv4_src_ipv6.ipv4_layout.ipv4);
5326 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
5327 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
5328 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
5329 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
5330 ipv4_m->hdr.type_of_service);
5331 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
5332 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
5333 ipv4_m->hdr.type_of_service >> 2);
5334 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
5335 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
5336 ipv4_m->hdr.next_proto_id);
5337 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
5338 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
5342 * Add IPV6 item to matcher and to the value.
5344 * @param[in, out] matcher
5346 * @param[in, out] key
5347 * Flow matcher value.
5349 * Flow pattern to translate.
5351 * Item is inner pattern.
5353 * The group to insert the rule.
5356 flow_dv_translate_item_ipv6(void *matcher, void *key,
5357 const struct rte_flow_item *item,
5358 int inner, uint32_t group)
5360 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
5361 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
5362 const struct rte_flow_item_ipv6 nic_mask = {
5365 "\xff\xff\xff\xff\xff\xff\xff\xff"
5366 "\xff\xff\xff\xff\xff\xff\xff\xff",
5368 "\xff\xff\xff\xff\xff\xff\xff\xff"
5369 "\xff\xff\xff\xff\xff\xff\xff\xff",
5370 .vtc_flow = RTE_BE32(0xffffffff),
5377 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5378 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5387 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5389 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5391 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5393 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5396 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
5398 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0x6);
5399 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 6);
5404 size = sizeof(ipv6_m->hdr.dst_addr);
5405 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5406 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
5407 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5408 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
5409 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
5410 for (i = 0; i < size; ++i)
5411 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
5412 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5413 src_ipv4_src_ipv6.ipv6_layout.ipv6);
5414 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5415 src_ipv4_src_ipv6.ipv6_layout.ipv6);
5416 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
5417 for (i = 0; i < size; ++i)
5418 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
5420 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
5421 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
5422 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
5423 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
5424 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
5425 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
5428 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
5430 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
5433 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
5435 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
5439 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
5441 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
5442 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
5446 * Add TCP item to matcher and to the value.
5448 * @param[in, out] matcher
5450 * @param[in, out] key
5451 * Flow matcher value.
5453 * Flow pattern to translate.
5455 * Item is inner pattern.
5458 flow_dv_translate_item_tcp(void *matcher, void *key,
5459 const struct rte_flow_item *item,
5462 const struct rte_flow_item_tcp *tcp_m = item->mask;
5463 const struct rte_flow_item_tcp *tcp_v = item->spec;
5468 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5470 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5472 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5474 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5476 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5477 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
5481 tcp_m = &rte_flow_item_tcp_mask;
5482 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
5483 rte_be_to_cpu_16(tcp_m->hdr.src_port));
5484 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
5485 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
5486 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
5487 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
5488 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
5489 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
5490 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
5491 tcp_m->hdr.tcp_flags);
5492 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
5493 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
5497 * Add UDP item to matcher and to the value.
5499 * @param[in, out] matcher
5501 * @param[in, out] key
5502 * Flow matcher value.
5504 * Flow pattern to translate.
5506 * Item is inner pattern.
5509 flow_dv_translate_item_udp(void *matcher, void *key,
5510 const struct rte_flow_item *item,
5513 const struct rte_flow_item_udp *udp_m = item->mask;
5514 const struct rte_flow_item_udp *udp_v = item->spec;
5519 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5521 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5523 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5525 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5527 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5528 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
5532 udp_m = &rte_flow_item_udp_mask;
5533 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
5534 rte_be_to_cpu_16(udp_m->hdr.src_port));
5535 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
5536 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
5537 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
5538 rte_be_to_cpu_16(udp_m->hdr.dst_port));
5539 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
5540 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
5544 * Add GRE optional Key item to matcher and to the value.
5546 * @param[in, out] matcher
5548 * @param[in, out] key
5549 * Flow matcher value.
5551 * Flow pattern to translate.
5553 * Item is inner pattern.
5556 flow_dv_translate_item_gre_key(void *matcher, void *key,
5557 const struct rte_flow_item *item)
5559 const rte_be32_t *key_m = item->mask;
5560 const rte_be32_t *key_v = item->spec;
5561 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5562 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5563 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
5568 key_m = &gre_key_default_mask;
5569 /* GRE K bit must be on and should already be validated */
5570 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
5571 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
5572 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
5573 rte_be_to_cpu_32(*key_m) >> 8);
5574 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
5575 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
5576 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
5577 rte_be_to_cpu_32(*key_m) & 0xFF);
5578 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
5579 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
5583 * Add GRE item to matcher and to the value.
5585 * @param[in, out] matcher
5587 * @param[in, out] key
5588 * Flow matcher value.
5590 * Flow pattern to translate.
5592 * Item is inner pattern.
5595 flow_dv_translate_item_gre(void *matcher, void *key,
5596 const struct rte_flow_item *item,
5599 const struct rte_flow_item_gre *gre_m = item->mask;
5600 const struct rte_flow_item_gre *gre_v = item->spec;
5603 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5604 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5611 uint16_t s_present:1;
5612 uint16_t k_present:1;
5613 uint16_t rsvd_bit1:1;
5614 uint16_t c_present:1;
5618 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
5621 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5623 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5625 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5627 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5629 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5630 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
5634 gre_m = &rte_flow_item_gre_mask;
5635 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
5636 rte_be_to_cpu_16(gre_m->protocol));
5637 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
5638 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
5639 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
5640 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
5641 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
5642 gre_crks_rsvd0_ver_m.c_present);
5643 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
5644 gre_crks_rsvd0_ver_v.c_present &
5645 gre_crks_rsvd0_ver_m.c_present);
5646 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
5647 gre_crks_rsvd0_ver_m.k_present);
5648 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
5649 gre_crks_rsvd0_ver_v.k_present &
5650 gre_crks_rsvd0_ver_m.k_present);
5651 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
5652 gre_crks_rsvd0_ver_m.s_present);
5653 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
5654 gre_crks_rsvd0_ver_v.s_present &
5655 gre_crks_rsvd0_ver_m.s_present);
5659 * Add NVGRE item to matcher and to the value.
5661 * @param[in, out] matcher
5663 * @param[in, out] key
5664 * Flow matcher value.
5666 * Flow pattern to translate.
5668 * Item is inner pattern.
5671 flow_dv_translate_item_nvgre(void *matcher, void *key,
5672 const struct rte_flow_item *item,
5675 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
5676 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
5677 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5678 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5679 const char *tni_flow_id_m = (const char *)nvgre_m->tni;
5680 const char *tni_flow_id_v = (const char *)nvgre_v->tni;
5686 /* For NVGRE, GRE header fields must be set with defined values. */
5687 const struct rte_flow_item_gre gre_spec = {
5688 .c_rsvd0_ver = RTE_BE16(0x2000),
5689 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
5691 const struct rte_flow_item_gre gre_mask = {
5692 .c_rsvd0_ver = RTE_BE16(0xB000),
5693 .protocol = RTE_BE16(UINT16_MAX),
5695 const struct rte_flow_item gre_item = {
5700 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
5704 nvgre_m = &rte_flow_item_nvgre_mask;
5705 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
5706 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
5707 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
5708 memcpy(gre_key_m, tni_flow_id_m, size);
5709 for (i = 0; i < size; ++i)
5710 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
5714 * Add VXLAN item to matcher and to the value.
5716 * @param[in, out] matcher
5718 * @param[in, out] key
5719 * Flow matcher value.
5721 * Flow pattern to translate.
5723 * Item is inner pattern.
5726 flow_dv_translate_item_vxlan(void *matcher, void *key,
5727 const struct rte_flow_item *item,
5730 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
5731 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
5734 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5735 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5743 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5745 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5747 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5749 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5751 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
5752 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
5753 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
5754 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
5755 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
5760 vxlan_m = &rte_flow_item_vxlan_mask;
5761 size = sizeof(vxlan_m->vni);
5762 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
5763 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
5764 memcpy(vni_m, vxlan_m->vni, size);
5765 for (i = 0; i < size; ++i)
5766 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
5770 * Add Geneve item to matcher and to the value.
5772 * @param[in, out] matcher
5774 * @param[in, out] key
5775 * Flow matcher value.
5777 * Flow pattern to translate.
5779 * Item is inner pattern.
5783 flow_dv_translate_item_geneve(void *matcher, void *key,
5784 const struct rte_flow_item *item, int inner)
5786 const struct rte_flow_item_geneve *geneve_m = item->mask;
5787 const struct rte_flow_item_geneve *geneve_v = item->spec;
5790 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5791 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5800 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5802 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5804 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5806 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5808 dport = MLX5_UDP_PORT_GENEVE;
5809 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
5810 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
5811 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
5816 geneve_m = &rte_flow_item_geneve_mask;
5817 size = sizeof(geneve_m->vni);
5818 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
5819 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
5820 memcpy(vni_m, geneve_m->vni, size);
5821 for (i = 0; i < size; ++i)
5822 vni_v[i] = vni_m[i] & geneve_v->vni[i];
5823 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
5824 rte_be_to_cpu_16(geneve_m->protocol));
5825 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
5826 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
5827 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
5828 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
5829 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
5830 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
5831 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
5832 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
5833 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
5834 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
5835 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
5836 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
5837 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
5841 * Add MPLS item to matcher and to the value.
5843 * @param[in, out] matcher
5845 * @param[in, out] key
5846 * Flow matcher value.
5848 * Flow pattern to translate.
5849 * @param[in] prev_layer
5850 * The protocol layer indicated in previous item.
5852 * Item is inner pattern.
5855 flow_dv_translate_item_mpls(void *matcher, void *key,
5856 const struct rte_flow_item *item,
5857 uint64_t prev_layer,
5860 const uint32_t *in_mpls_m = item->mask;
5861 const uint32_t *in_mpls_v = item->spec;
5862 uint32_t *out_mpls_m = 0;
5863 uint32_t *out_mpls_v = 0;
5864 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5865 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5866 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
5868 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
5869 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
5870 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5872 switch (prev_layer) {
5873 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
5874 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
5875 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
5876 MLX5_UDP_PORT_MPLS);
5878 case MLX5_FLOW_LAYER_GRE:
5879 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
5880 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
5881 RTE_ETHER_TYPE_MPLS);
5884 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5885 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
5892 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
5893 switch (prev_layer) {
5894 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
5896 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
5897 outer_first_mpls_over_udp);
5899 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
5900 outer_first_mpls_over_udp);
5902 case MLX5_FLOW_LAYER_GRE:
5904 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
5905 outer_first_mpls_over_gre);
5907 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
5908 outer_first_mpls_over_gre);
5911 /* Inner MPLS not over GRE is not supported. */
5914 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
5918 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
5924 if (out_mpls_m && out_mpls_v) {
5925 *out_mpls_m = *in_mpls_m;
5926 *out_mpls_v = *in_mpls_v & *in_mpls_m;
5931 * Add metadata register item to matcher
5933 * @param[in, out] matcher
5935 * @param[in, out] key
5936 * Flow matcher value.
5937 * @param[in] reg_type
5938 * Type of device metadata register
5945 flow_dv_match_meta_reg(void *matcher, void *key,
5946 enum modify_reg reg_type,
5947 uint32_t data, uint32_t mask)
5950 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
5952 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
5958 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
5959 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
5962 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
5963 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
5967 * The metadata register C0 field might be divided into
5968 * source vport index and META item value, we should set
5969 * this field according to specified mask, not as whole one.
5971 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
5973 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
5974 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
5977 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
5980 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
5981 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
5984 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
5985 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
5988 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
5989 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
5992 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
5993 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
5996 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
5997 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
6000 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
6001 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
6004 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
6005 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
6014 * Add MARK item to matcher
6017 * The device to configure through.
6018 * @param[in, out] matcher
6020 * @param[in, out] key
6021 * Flow matcher value.
6023 * Flow pattern to translate.
6026 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
6027 void *matcher, void *key,
6028 const struct rte_flow_item *item)
6030 struct mlx5_priv *priv = dev->data->dev_private;
6031 const struct rte_flow_item_mark *mark;
6035 mark = item->mask ? (const void *)item->mask :
6036 &rte_flow_item_mark_mask;
6037 mask = mark->id & priv->sh->dv_mark_mask;
6038 mark = (const void *)item->spec;
6040 value = mark->id & priv->sh->dv_mark_mask & mask;
6042 enum modify_reg reg;
6044 /* Get the metadata register index for the mark. */
6045 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
6047 if (reg == REG_C_0) {
6048 struct mlx5_priv *priv = dev->data->dev_private;
6049 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6050 uint32_t shl_c0 = rte_bsf32(msk_c0);
6056 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6061 * Add META item to matcher
6064 * The devich to configure through.
6065 * @param[in, out] matcher
6067 * @param[in, out] key
6068 * Flow matcher value.
6070 * Attributes of flow that includes this item.
6072 * Flow pattern to translate.
6075 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
6076 void *matcher, void *key,
6077 const struct rte_flow_attr *attr,
6078 const struct rte_flow_item *item)
6080 const struct rte_flow_item_meta *meta_m;
6081 const struct rte_flow_item_meta *meta_v;
6083 meta_m = (const void *)item->mask;
6085 meta_m = &rte_flow_item_meta_mask;
6086 meta_v = (const void *)item->spec;
6088 enum modify_reg reg;
6089 uint32_t value = meta_v->data;
6090 uint32_t mask = meta_m->data;
6092 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
6096 * In datapath code there is no endianness
6097 * coversions for perfromance reasons, all
6098 * pattern conversions are done in rte_flow.
6100 value = rte_cpu_to_be_32(value);
6101 mask = rte_cpu_to_be_32(mask);
6102 if (reg == REG_C_0) {
6103 struct mlx5_priv *priv = dev->data->dev_private;
6104 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6105 uint32_t shl_c0 = rte_bsf32(msk_c0);
6106 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
6107 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
6115 assert(!(~msk_c0 & mask));
6117 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6122 * Add vport metadata Reg C0 item to matcher
6124 * @param[in, out] matcher
6126 * @param[in, out] key
6127 * Flow matcher value.
6129 * Flow pattern to translate.
6132 flow_dv_translate_item_meta_vport(void *matcher, void *key,
6133 uint32_t value, uint32_t mask)
6135 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
6139 * Add tag item to matcher
6142 * The devich to configure through.
6143 * @param[in, out] matcher
6145 * @param[in, out] key
6146 * Flow matcher value.
6148 * Flow pattern to translate.
6151 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
6152 void *matcher, void *key,
6153 const struct rte_flow_item *item)
6155 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
6156 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
6157 uint32_t mask, value;
6160 value = tag_v->data;
6161 mask = tag_m ? tag_m->data : UINT32_MAX;
6162 if (tag_v->id == REG_C_0) {
6163 struct mlx5_priv *priv = dev->data->dev_private;
6164 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6165 uint32_t shl_c0 = rte_bsf32(msk_c0);
6171 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
6175 * Add TAG item to matcher
6178 * The devich to configure through.
6179 * @param[in, out] matcher
6181 * @param[in, out] key
6182 * Flow matcher value.
6184 * Flow pattern to translate.
6187 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
6188 void *matcher, void *key,
6189 const struct rte_flow_item *item)
6191 const struct rte_flow_item_tag *tag_v = item->spec;
6192 const struct rte_flow_item_tag *tag_m = item->mask;
6193 enum modify_reg reg;
6196 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
6197 /* Get the metadata register index for the tag. */
6198 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
6200 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
6204 * Add source vport match to the specified matcher.
6206 * @param[in, out] matcher
6208 * @param[in, out] key
6209 * Flow matcher value.
6211 * Source vport value to match
6216 flow_dv_translate_item_source_vport(void *matcher, void *key,
6217 int16_t port, uint16_t mask)
6219 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6220 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6222 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
6223 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
6227 * Translate port-id item to eswitch match on port-id.
6230 * The devich to configure through.
6231 * @param[in, out] matcher
6233 * @param[in, out] key
6234 * Flow matcher value.
6236 * Flow pattern to translate.
6239 * 0 on success, a negative errno value otherwise.
6242 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
6243 void *key, const struct rte_flow_item *item)
6245 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
6246 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
6247 struct mlx5_priv *priv;
6250 mask = pid_m ? pid_m->id : 0xffff;
6251 id = pid_v ? pid_v->id : dev->data->port_id;
6252 priv = mlx5_port_to_eswitch_info(id, item == NULL);
6255 /* Translate to vport field or to metadata, depending on mode. */
6256 if (priv->vport_meta_mask)
6257 flow_dv_translate_item_meta_vport(matcher, key,
6258 priv->vport_meta_tag,
6259 priv->vport_meta_mask);
6261 flow_dv_translate_item_source_vport(matcher, key,
6262 priv->vport_id, mask);
6267 * Add ICMP6 item to matcher and to the value.
6269 * @param[in, out] matcher
6271 * @param[in, out] key
6272 * Flow matcher value.
6274 * Flow pattern to translate.
6276 * Item is inner pattern.
6279 flow_dv_translate_item_icmp6(void *matcher, void *key,
6280 const struct rte_flow_item *item,
6283 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
6284 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
6287 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
6289 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6291 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6293 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6295 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6297 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6299 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
6300 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
6304 icmp6_m = &rte_flow_item_icmp6_mask;
6305 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
6306 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
6307 icmp6_v->type & icmp6_m->type);
6308 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
6309 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
6310 icmp6_v->code & icmp6_m->code);
6314 * Add ICMP item to matcher and to the value.
6316 * @param[in, out] matcher
6318 * @param[in, out] key
6319 * Flow matcher value.
6321 * Flow pattern to translate.
6323 * Item is inner pattern.
6326 flow_dv_translate_item_icmp(void *matcher, void *key,
6327 const struct rte_flow_item *item,
6330 const struct rte_flow_item_icmp *icmp_m = item->mask;
6331 const struct rte_flow_item_icmp *icmp_v = item->spec;
6334 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
6336 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6338 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6340 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6342 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6344 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6346 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
6347 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
6351 icmp_m = &rte_flow_item_icmp_mask;
6352 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
6353 icmp_m->hdr.icmp_type);
6354 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
6355 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
6356 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
6357 icmp_m->hdr.icmp_code);
6358 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
6359 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
6363 * Add GTP item to matcher and to the value.
6365 * @param[in, out] matcher
6367 * @param[in, out] key
6368 * Flow matcher value.
6370 * Flow pattern to translate.
6372 * Item is inner pattern.
6375 flow_dv_translate_item_gtp(void *matcher, void *key,
6376 const struct rte_flow_item *item, int inner)
6378 const struct rte_flow_item_gtp *gtp_m = item->mask;
6379 const struct rte_flow_item_gtp *gtp_v = item->spec;
6382 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
6384 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6385 uint16_t dport = RTE_GTPU_UDP_PORT;
6388 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6390 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6392 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6394 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6396 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6397 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6398 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6403 gtp_m = &rte_flow_item_gtp_mask;
6404 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
6405 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
6406 gtp_v->msg_type & gtp_m->msg_type);
6407 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
6408 rte_be_to_cpu_32(gtp_m->teid));
6409 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
6410 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
6413 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
6415 #define HEADER_IS_ZERO(match_criteria, headers) \
6416 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
6417 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
6420 * Calculate flow matcher enable bitmap.
6422 * @param match_criteria
6423 * Pointer to flow matcher criteria.
6426 * Bitmap of enabled fields.
6429 flow_dv_matcher_enable(uint32_t *match_criteria)
6431 uint8_t match_criteria_enable;
6433 match_criteria_enable =
6434 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
6435 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
6436 match_criteria_enable |=
6437 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
6438 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
6439 match_criteria_enable |=
6440 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
6441 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
6442 match_criteria_enable |=
6443 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
6444 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
6445 match_criteria_enable |=
6446 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
6447 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
6448 return match_criteria_enable;
6455 * @param[in, out] dev
6456 * Pointer to rte_eth_dev structure.
6457 * @param[in] table_id
6460 * Direction of the table.
6461 * @param[in] transfer
6462 * E-Switch or NIC flow.
6464 * pointer to error structure.
6467 * Returns tables resource based on the index, NULL in case of failed.
6469 static struct mlx5_flow_tbl_resource *
6470 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
6471 uint32_t table_id, uint8_t egress,
6473 struct rte_flow_error *error)
6475 struct mlx5_priv *priv = dev->data->dev_private;
6476 struct mlx5_ibv_shared *sh = priv->sh;
6477 struct mlx5_flow_tbl_resource *tbl;
6478 union mlx5_flow_tbl_key table_key = {
6480 .table_id = table_id,
6482 .domain = !!transfer,
6483 .direction = !!egress,
6486 struct mlx5_hlist_entry *pos = mlx5_hlist_lookup(sh->flow_tbls,
6488 struct mlx5_flow_tbl_data_entry *tbl_data;
6493 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
6495 tbl = &tbl_data->tbl;
6496 rte_atomic32_inc(&tbl->refcnt);
6499 tbl_data = rte_zmalloc(NULL, sizeof(*tbl_data), 0);
6501 rte_flow_error_set(error, ENOMEM,
6502 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6504 "cannot allocate flow table data entry");
6507 tbl = &tbl_data->tbl;
6508 pos = &tbl_data->entry;
6510 domain = sh->fdb_domain;
6512 domain = sh->tx_domain;
6514 domain = sh->rx_domain;
6515 tbl->obj = mlx5_glue->dr_create_flow_tbl(domain, table_id);
6517 rte_flow_error_set(error, ENOMEM,
6518 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6519 NULL, "cannot create flow table object");
6524 * No multi-threads now, but still better to initialize the reference
6525 * count before insert it into the hash list.
6527 rte_atomic32_init(&tbl->refcnt);
6528 /* Jump action reference count is initialized here. */
6529 rte_atomic32_init(&tbl_data->jump.refcnt);
6530 pos->key = table_key.v64;
6531 ret = mlx5_hlist_insert(sh->flow_tbls, pos);
6533 rte_flow_error_set(error, -ret,
6534 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6535 "cannot insert flow table data entry");
6536 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
6539 rte_atomic32_inc(&tbl->refcnt);
6544 * Release a flow table.
6547 * Pointer to rte_eth_dev structure.
6549 * Table resource to be released.
6552 * Returns 0 if table was released, else return 1;
6555 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
6556 struct mlx5_flow_tbl_resource *tbl)
6558 struct mlx5_priv *priv = dev->data->dev_private;
6559 struct mlx5_ibv_shared *sh = priv->sh;
6560 struct mlx5_flow_tbl_data_entry *tbl_data =
6561 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
6565 if (rte_atomic32_dec_and_test(&tbl->refcnt)) {
6566 struct mlx5_hlist_entry *pos = &tbl_data->entry;
6568 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
6570 /* remove the entry from the hash list and free memory. */
6571 mlx5_hlist_remove(sh->flow_tbls, pos);
6579 * Register the flow matcher.
6581 * @param[in, out] dev
6582 * Pointer to rte_eth_dev structure.
6583 * @param[in, out] matcher
6584 * Pointer to flow matcher.
6585 * @param[in, out] key
6586 * Pointer to flow table key.
6587 * @parm[in, out] dev_flow
6588 * Pointer to the dev_flow.
6590 * pointer to error structure.
6593 * 0 on success otherwise -errno and errno is set.
6596 flow_dv_matcher_register(struct rte_eth_dev *dev,
6597 struct mlx5_flow_dv_matcher *matcher,
6598 union mlx5_flow_tbl_key *key,
6599 struct mlx5_flow *dev_flow,
6600 struct rte_flow_error *error)
6602 struct mlx5_priv *priv = dev->data->dev_private;
6603 struct mlx5_ibv_shared *sh = priv->sh;
6604 struct mlx5_flow_dv_matcher *cache_matcher;
6605 struct mlx5dv_flow_matcher_attr dv_attr = {
6606 .type = IBV_FLOW_ATTR_NORMAL,
6607 .match_mask = (void *)&matcher->mask,
6609 struct mlx5_flow_tbl_resource *tbl;
6610 struct mlx5_flow_tbl_data_entry *tbl_data;
6612 tbl = flow_dv_tbl_resource_get(dev, key->table_id, key->direction,
6613 key->domain, error);
6615 return -rte_errno; /* No need to refill the error info */
6616 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
6617 /* Lookup from cache. */
6618 LIST_FOREACH(cache_matcher, &tbl_data->matchers, next) {
6619 if (matcher->crc == cache_matcher->crc &&
6620 matcher->priority == cache_matcher->priority &&
6621 !memcmp((const void *)matcher->mask.buf,
6622 (const void *)cache_matcher->mask.buf,
6623 cache_matcher->mask.size)) {
6625 "%s group %u priority %hd use %s "
6626 "matcher %p: refcnt %d++",
6627 key->domain ? "FDB" : "NIC", key->table_id,
6628 cache_matcher->priority,
6629 key->direction ? "tx" : "rx",
6630 (void *)cache_matcher,
6631 rte_atomic32_read(&cache_matcher->refcnt));
6632 rte_atomic32_inc(&cache_matcher->refcnt);
6633 dev_flow->dv.matcher = cache_matcher;
6634 /* old matcher should not make the table ref++. */
6635 flow_dv_tbl_resource_release(dev, tbl);
6639 /* Register new matcher. */
6640 cache_matcher = rte_calloc(__func__, 1, sizeof(*cache_matcher), 0);
6641 if (!cache_matcher) {
6642 flow_dv_tbl_resource_release(dev, tbl);
6643 return rte_flow_error_set(error, ENOMEM,
6644 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6645 "cannot allocate matcher memory");
6647 *cache_matcher = *matcher;
6648 dv_attr.match_criteria_enable =
6649 flow_dv_matcher_enable(cache_matcher->mask.buf);
6650 dv_attr.priority = matcher->priority;
6652 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
6653 cache_matcher->matcher_object =
6654 mlx5_glue->dv_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj);
6655 if (!cache_matcher->matcher_object) {
6656 rte_free(cache_matcher);
6657 #ifdef HAVE_MLX5DV_DR
6658 flow_dv_tbl_resource_release(dev, tbl);
6660 return rte_flow_error_set(error, ENOMEM,
6661 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6662 NULL, "cannot create matcher");
6664 /* Save the table information */
6665 cache_matcher->tbl = tbl;
6666 rte_atomic32_init(&cache_matcher->refcnt);
6667 /* only matcher ref++, table ref++ already done above in get API. */
6668 rte_atomic32_inc(&cache_matcher->refcnt);
6669 LIST_INSERT_HEAD(&tbl_data->matchers, cache_matcher, next);
6670 dev_flow->dv.matcher = cache_matcher;
6671 DRV_LOG(DEBUG, "%s group %u priority %hd new %s matcher %p: refcnt %d",
6672 key->domain ? "FDB" : "NIC", key->table_id,
6673 cache_matcher->priority,
6674 key->direction ? "tx" : "rx", (void *)cache_matcher,
6675 rte_atomic32_read(&cache_matcher->refcnt));
6680 * Find existing tag resource or create and register a new one.
6682 * @param dev[in, out]
6683 * Pointer to rte_eth_dev structure.
6684 * @param[in, out] tag_be24
6685 * Tag value in big endian then R-shift 8.
6686 * @parm[in, out] dev_flow
6687 * Pointer to the dev_flow.
6689 * pointer to error structure.
6692 * 0 on success otherwise -errno and errno is set.
6695 flow_dv_tag_resource_register
6696 (struct rte_eth_dev *dev,
6698 struct mlx5_flow *dev_flow,
6699 struct rte_flow_error *error)
6701 struct mlx5_priv *priv = dev->data->dev_private;
6702 struct mlx5_ibv_shared *sh = priv->sh;
6703 struct mlx5_flow_dv_tag_resource *cache_resource;
6704 struct mlx5_hlist_entry *entry;
6706 /* Lookup a matching resource from cache. */
6707 entry = mlx5_hlist_lookup(sh->tag_table, (uint64_t)tag_be24);
6709 cache_resource = container_of
6710 (entry, struct mlx5_flow_dv_tag_resource, entry);
6711 rte_atomic32_inc(&cache_resource->refcnt);
6712 dev_flow->dv.tag_resource = cache_resource;
6713 DRV_LOG(DEBUG, "cached tag resource %p: refcnt now %d++",
6714 (void *)cache_resource,
6715 rte_atomic32_read(&cache_resource->refcnt));
6718 /* Register new resource. */
6719 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
6720 if (!cache_resource)
6721 return rte_flow_error_set(error, ENOMEM,
6722 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6723 "cannot allocate resource memory");
6724 cache_resource->entry.key = (uint64_t)tag_be24;
6725 cache_resource->action = mlx5_glue->dv_create_flow_action_tag(tag_be24);
6726 if (!cache_resource->action) {
6727 rte_free(cache_resource);
6728 return rte_flow_error_set(error, ENOMEM,
6729 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6730 NULL, "cannot create action");
6732 rte_atomic32_init(&cache_resource->refcnt);
6733 rte_atomic32_inc(&cache_resource->refcnt);
6734 if (mlx5_hlist_insert(sh->tag_table, &cache_resource->entry)) {
6735 mlx5_glue->destroy_flow_action(cache_resource->action);
6736 rte_free(cache_resource);
6737 return rte_flow_error_set(error, EEXIST,
6738 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6739 NULL, "cannot insert tag");
6741 dev_flow->dv.tag_resource = cache_resource;
6742 DRV_LOG(DEBUG, "new tag resource %p: refcnt now %d++",
6743 (void *)cache_resource,
6744 rte_atomic32_read(&cache_resource->refcnt));
6752 * Pointer to Ethernet device.
6754 * Pointer to mlx5_flow.
6757 * 1 while a reference on it exists, 0 when freed.
6760 flow_dv_tag_release(struct rte_eth_dev *dev,
6761 struct mlx5_flow_dv_tag_resource *tag)
6763 struct mlx5_priv *priv = dev->data->dev_private;
6764 struct mlx5_ibv_shared *sh = priv->sh;
6767 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
6768 dev->data->port_id, (void *)tag,
6769 rte_atomic32_read(&tag->refcnt));
6770 if (rte_atomic32_dec_and_test(&tag->refcnt)) {
6771 claim_zero(mlx5_glue->destroy_flow_action(tag->action));
6772 mlx5_hlist_remove(sh->tag_table, &tag->entry);
6773 DRV_LOG(DEBUG, "port %u tag %p: removed",
6774 dev->data->port_id, (void *)tag);
6782 * Translate port ID action to vport.
6785 * Pointer to rte_eth_dev structure.
6787 * Pointer to the port ID action.
6788 * @param[out] dst_port_id
6789 * The target port ID.
6791 * Pointer to the error structure.
6794 * 0 on success, a negative errno value otherwise and rte_errno is set.
6797 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
6798 const struct rte_flow_action *action,
6799 uint32_t *dst_port_id,
6800 struct rte_flow_error *error)
6803 struct mlx5_priv *priv;
6804 const struct rte_flow_action_port_id *conf =
6805 (const struct rte_flow_action_port_id *)action->conf;
6807 port = conf->original ? dev->data->port_id : conf->id;
6808 priv = mlx5_port_to_eswitch_info(port, false);
6810 return rte_flow_error_set(error, -rte_errno,
6811 RTE_FLOW_ERROR_TYPE_ACTION,
6813 "No eswitch info was found for port");
6814 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
6816 * This parameter is transferred to
6817 * mlx5dv_dr_action_create_dest_ib_port().
6819 *dst_port_id = priv->ibv_port;
6822 * Legacy mode, no LAG configurations is supported.
6823 * This parameter is transferred to
6824 * mlx5dv_dr_action_create_dest_vport().
6826 *dst_port_id = priv->vport_id;
6832 * Add Tx queue matcher
6835 * Pointer to the dev struct.
6836 * @param[in, out] matcher
6838 * @param[in, out] key
6839 * Flow matcher value.
6841 * Flow pattern to translate.
6843 * Item is inner pattern.
6846 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
6847 void *matcher, void *key,
6848 const struct rte_flow_item *item)
6850 const struct mlx5_rte_flow_item_tx_queue *queue_m;
6851 const struct mlx5_rte_flow_item_tx_queue *queue_v;
6853 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6855 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6856 struct mlx5_txq_ctrl *txq;
6860 queue_m = (const void *)item->mask;
6863 queue_v = (const void *)item->spec;
6866 txq = mlx5_txq_get(dev, queue_v->queue);
6869 queue = txq->obj->sq->id;
6870 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
6871 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
6872 queue & queue_m->queue);
6873 mlx5_txq_release(dev, queue_v->queue);
6877 * Set the hash fields according to the @p flow information.
6879 * @param[in] dev_flow
6880 * Pointer to the mlx5_flow.
6883 flow_dv_hashfields_set(struct mlx5_flow *dev_flow)
6885 struct rte_flow *flow = dev_flow->flow;
6886 uint64_t items = dev_flow->layers;
6888 uint64_t rss_types = rte_eth_rss_hf_refine(flow->rss.types);
6890 dev_flow->hash_fields = 0;
6891 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
6892 if (flow->rss.level >= 2) {
6893 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
6897 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
6898 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
6899 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
6900 if (rss_types & ETH_RSS_L3_SRC_ONLY)
6901 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
6902 else if (rss_types & ETH_RSS_L3_DST_ONLY)
6903 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
6905 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
6907 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
6908 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
6909 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
6910 if (rss_types & ETH_RSS_L3_SRC_ONLY)
6911 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
6912 else if (rss_types & ETH_RSS_L3_DST_ONLY)
6913 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
6915 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
6918 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
6919 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
6920 if (rss_types & ETH_RSS_UDP) {
6921 if (rss_types & ETH_RSS_L4_SRC_ONLY)
6922 dev_flow->hash_fields |=
6923 IBV_RX_HASH_SRC_PORT_UDP;
6924 else if (rss_types & ETH_RSS_L4_DST_ONLY)
6925 dev_flow->hash_fields |=
6926 IBV_RX_HASH_DST_PORT_UDP;
6928 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
6930 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
6931 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
6932 if (rss_types & ETH_RSS_TCP) {
6933 if (rss_types & ETH_RSS_L4_SRC_ONLY)
6934 dev_flow->hash_fields |=
6935 IBV_RX_HASH_SRC_PORT_TCP;
6936 else if (rss_types & ETH_RSS_L4_DST_ONLY)
6937 dev_flow->hash_fields |=
6938 IBV_RX_HASH_DST_PORT_TCP;
6940 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
6946 * Fill the flow with DV spec, lock free
6947 * (mutex should be acquired by caller).
6950 * Pointer to rte_eth_dev structure.
6951 * @param[in, out] dev_flow
6952 * Pointer to the sub flow.
6954 * Pointer to the flow attributes.
6956 * Pointer to the list of items.
6957 * @param[in] actions
6958 * Pointer to the list of actions.
6960 * Pointer to the error structure.
6963 * 0 on success, a negative errno value otherwise and rte_errno is set.
6966 __flow_dv_translate(struct rte_eth_dev *dev,
6967 struct mlx5_flow *dev_flow,
6968 const struct rte_flow_attr *attr,
6969 const struct rte_flow_item items[],
6970 const struct rte_flow_action actions[],
6971 struct rte_flow_error *error)
6973 struct mlx5_priv *priv = dev->data->dev_private;
6974 struct mlx5_dev_config *dev_conf = &priv->config;
6975 struct rte_flow *flow = dev_flow->flow;
6976 uint64_t item_flags = 0;
6977 uint64_t last_item = 0;
6978 uint64_t action_flags = 0;
6979 uint64_t priority = attr->priority;
6980 struct mlx5_flow_dv_matcher matcher = {
6982 .size = sizeof(matcher.mask.buf),
6986 bool actions_end = false;
6988 struct mlx5_flow_dv_modify_hdr_resource res;
6989 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
6990 sizeof(struct mlx5_modification_cmd) *
6991 (MLX5_MAX_MODIFY_NUM + 1)];
6993 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
6994 union flow_dv_attr flow_attr = { .attr = 0 };
6996 union mlx5_flow_tbl_key tbl_key;
6997 uint32_t modify_action_position = UINT32_MAX;
6998 void *match_mask = matcher.mask.buf;
6999 void *match_value = dev_flow->dv.value.buf;
7000 uint8_t next_protocol = 0xff;
7001 struct rte_vlan_hdr vlan = { 0 };
7005 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
7006 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
7007 ret = mlx5_flow_group_to_table(attr, dev_flow->external, attr->group,
7011 dev_flow->group = table;
7013 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
7014 if (priority == MLX5_FLOW_PRIO_RSVD)
7015 priority = dev_conf->flow_prio - 1;
7016 /* number of actions must be set to 0 in case of dirty stack. */
7017 mhdr_res->actions_num = 0;
7018 for (; !actions_end ; actions++) {
7019 const struct rte_flow_action_queue *queue;
7020 const struct rte_flow_action_rss *rss;
7021 const struct rte_flow_action *action = actions;
7022 const struct rte_flow_action_count *count = action->conf;
7023 const uint8_t *rss_key;
7024 const struct rte_flow_action_jump *jump_data;
7025 const struct rte_flow_action_meter *mtr;
7026 struct mlx5_flow_tbl_resource *tbl;
7027 uint32_t port_id = 0;
7028 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
7029 int action_type = actions->type;
7030 const struct rte_flow_action *found_action = NULL;
7032 switch (action_type) {
7033 case RTE_FLOW_ACTION_TYPE_VOID:
7035 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7036 if (flow_dv_translate_action_port_id(dev, action,
7039 port_id_resource.port_id = port_id;
7040 if (flow_dv_port_id_action_resource_register
7041 (dev, &port_id_resource, dev_flow, error))
7043 dev_flow->dv.actions[actions_n++] =
7044 dev_flow->dv.port_id_action->action;
7045 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7047 case RTE_FLOW_ACTION_TYPE_FLAG:
7048 action_flags |= MLX5_FLOW_ACTION_FLAG;
7049 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7050 struct rte_flow_action_mark mark = {
7051 .id = MLX5_FLOW_MARK_DEFAULT,
7054 if (flow_dv_convert_action_mark(dev, &mark,
7058 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
7061 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
7062 if (!dev_flow->dv.tag_resource)
7063 if (flow_dv_tag_resource_register
7064 (dev, tag_be, dev_flow, error))
7066 dev_flow->dv.actions[actions_n++] =
7067 dev_flow->dv.tag_resource->action;
7069 case RTE_FLOW_ACTION_TYPE_MARK:
7070 action_flags |= MLX5_FLOW_ACTION_MARK;
7071 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7072 const struct rte_flow_action_mark *mark =
7073 (const struct rte_flow_action_mark *)
7076 if (flow_dv_convert_action_mark(dev, mark,
7080 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
7084 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7085 /* Legacy (non-extensive) MARK action. */
7086 tag_be = mlx5_flow_mark_set
7087 (((const struct rte_flow_action_mark *)
7088 (actions->conf))->id);
7089 if (!dev_flow->dv.tag_resource)
7090 if (flow_dv_tag_resource_register
7091 (dev, tag_be, dev_flow, error))
7093 dev_flow->dv.actions[actions_n++] =
7094 dev_flow->dv.tag_resource->action;
7096 case RTE_FLOW_ACTION_TYPE_SET_META:
7097 if (flow_dv_convert_action_set_meta
7098 (dev, mhdr_res, attr,
7099 (const struct rte_flow_action_set_meta *)
7100 actions->conf, error))
7102 action_flags |= MLX5_FLOW_ACTION_SET_META;
7104 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7105 if (flow_dv_convert_action_set_tag
7107 (const struct rte_flow_action_set_tag *)
7108 actions->conf, error))
7110 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7112 case RTE_FLOW_ACTION_TYPE_DROP:
7113 action_flags |= MLX5_FLOW_ACTION_DROP;
7115 case RTE_FLOW_ACTION_TYPE_QUEUE:
7116 assert(flow->rss.queue);
7117 queue = actions->conf;
7118 flow->rss.queue_num = 1;
7119 (*flow->rss.queue)[0] = queue->index;
7120 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7122 case RTE_FLOW_ACTION_TYPE_RSS:
7123 assert(flow->rss.queue);
7124 rss = actions->conf;
7125 if (flow->rss.queue)
7126 memcpy((*flow->rss.queue), rss->queue,
7127 rss->queue_num * sizeof(uint16_t));
7128 flow->rss.queue_num = rss->queue_num;
7129 /* NULL RSS key indicates default RSS key. */
7130 rss_key = !rss->key ? rss_hash_default_key : rss->key;
7131 memcpy(flow->rss.key, rss_key, MLX5_RSS_HASH_KEY_LEN);
7133 * rss->level and rss.types should be set in advance
7134 * when expanding items for RSS.
7136 action_flags |= MLX5_FLOW_ACTION_RSS;
7138 case RTE_FLOW_ACTION_TYPE_COUNT:
7139 if (!dev_conf->devx) {
7140 rte_errno = ENOTSUP;
7143 flow->counter = flow_dv_counter_alloc(dev,
7147 if (flow->counter == NULL)
7149 dev_flow->dv.actions[actions_n++] =
7150 flow->counter->action;
7151 action_flags |= MLX5_FLOW_ACTION_COUNT;
7154 if (rte_errno == ENOTSUP)
7155 return rte_flow_error_set
7157 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7159 "count action not supported");
7161 return rte_flow_error_set
7163 RTE_FLOW_ERROR_TYPE_ACTION,
7165 "cannot create counter"
7168 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7169 dev_flow->dv.actions[actions_n++] =
7170 priv->sh->pop_vlan_action;
7171 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7173 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7174 flow_dev_get_vlan_info_from_items(items, &vlan);
7175 vlan.eth_proto = rte_be_to_cpu_16
7176 ((((const struct rte_flow_action_of_push_vlan *)
7177 actions->conf)->ethertype));
7178 found_action = mlx5_flow_find_action
7180 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
7182 mlx5_update_vlan_vid_pcp(found_action, &vlan);
7183 found_action = mlx5_flow_find_action
7185 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
7187 mlx5_update_vlan_vid_pcp(found_action, &vlan);
7188 if (flow_dv_create_action_push_vlan
7189 (dev, attr, &vlan, dev_flow, error))
7191 dev_flow->dv.actions[actions_n++] =
7192 dev_flow->dv.push_vlan_res->action;
7193 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7195 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7196 /* of_vlan_push action handled this action */
7197 assert(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN);
7199 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7200 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7202 flow_dev_get_vlan_info_from_items(items, &vlan);
7203 mlx5_update_vlan_vid_pcp(actions, &vlan);
7204 /* If no VLAN push - this is a modify header action */
7205 if (flow_dv_convert_action_modify_vlan_vid
7206 (mhdr_res, actions, error))
7208 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7210 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7211 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7212 if (flow_dv_create_action_l2_encap(dev, actions,
7217 dev_flow->dv.actions[actions_n++] =
7218 dev_flow->dv.encap_decap->verbs_action;
7219 action_flags |= actions->type ==
7220 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ?
7221 MLX5_FLOW_ACTION_VXLAN_ENCAP :
7222 MLX5_FLOW_ACTION_NVGRE_ENCAP;
7224 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7225 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7226 if (flow_dv_create_action_l2_decap(dev, dev_flow,
7230 dev_flow->dv.actions[actions_n++] =
7231 dev_flow->dv.encap_decap->verbs_action;
7232 action_flags |= actions->type ==
7233 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ?
7234 MLX5_FLOW_ACTION_VXLAN_DECAP :
7235 MLX5_FLOW_ACTION_NVGRE_DECAP;
7237 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7238 /* Handle encap with preceding decap. */
7239 if (action_flags & MLX5_FLOW_ACTION_RAW_DECAP) {
7240 if (flow_dv_create_action_raw_encap
7241 (dev, actions, dev_flow, attr, error))
7243 dev_flow->dv.actions[actions_n++] =
7244 dev_flow->dv.encap_decap->verbs_action;
7246 /* Handle encap without preceding decap. */
7247 if (flow_dv_create_action_l2_encap
7248 (dev, actions, dev_flow, attr->transfer,
7251 dev_flow->dv.actions[actions_n++] =
7252 dev_flow->dv.encap_decap->verbs_action;
7254 action_flags |= MLX5_FLOW_ACTION_RAW_ENCAP;
7256 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7257 /* Check if this decap is followed by encap. */
7258 for (; action->type != RTE_FLOW_ACTION_TYPE_END &&
7259 action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP;
7262 /* Handle decap only if it isn't followed by encap. */
7263 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7264 if (flow_dv_create_action_l2_decap
7265 (dev, dev_flow, attr->transfer, error))
7267 dev_flow->dv.actions[actions_n++] =
7268 dev_flow->dv.encap_decap->verbs_action;
7270 /* If decap is followed by encap, handle it at encap. */
7271 action_flags |= MLX5_FLOW_ACTION_RAW_DECAP;
7273 case RTE_FLOW_ACTION_TYPE_JUMP:
7274 jump_data = action->conf;
7275 ret = mlx5_flow_group_to_table(attr, dev_flow->external,
7276 jump_data->group, &table,
7280 tbl = flow_dv_tbl_resource_get(dev, table,
7282 attr->transfer, error);
7284 return rte_flow_error_set
7286 RTE_FLOW_ERROR_TYPE_ACTION,
7288 "cannot create jump action.");
7289 if (flow_dv_jump_tbl_resource_register
7290 (dev, tbl, dev_flow, error)) {
7291 flow_dv_tbl_resource_release(dev, tbl);
7292 return rte_flow_error_set
7294 RTE_FLOW_ERROR_TYPE_ACTION,
7296 "cannot create jump action.");
7298 dev_flow->dv.actions[actions_n++] =
7299 dev_flow->dv.jump->action;
7300 action_flags |= MLX5_FLOW_ACTION_JUMP;
7302 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7303 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7304 if (flow_dv_convert_action_modify_mac
7305 (mhdr_res, actions, error))
7307 action_flags |= actions->type ==
7308 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7309 MLX5_FLOW_ACTION_SET_MAC_SRC :
7310 MLX5_FLOW_ACTION_SET_MAC_DST;
7312 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7313 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7314 if (flow_dv_convert_action_modify_ipv4
7315 (mhdr_res, actions, error))
7317 action_flags |= actions->type ==
7318 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7319 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7320 MLX5_FLOW_ACTION_SET_IPV4_DST;
7322 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7323 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7324 if (flow_dv_convert_action_modify_ipv6
7325 (mhdr_res, actions, error))
7327 action_flags |= actions->type ==
7328 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7329 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7330 MLX5_FLOW_ACTION_SET_IPV6_DST;
7332 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7333 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7334 if (flow_dv_convert_action_modify_tp
7335 (mhdr_res, actions, items,
7338 action_flags |= actions->type ==
7339 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7340 MLX5_FLOW_ACTION_SET_TP_SRC :
7341 MLX5_FLOW_ACTION_SET_TP_DST;
7343 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7344 if (flow_dv_convert_action_modify_dec_ttl
7345 (mhdr_res, items, &flow_attr, error))
7347 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
7349 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7350 if (flow_dv_convert_action_modify_ttl
7351 (mhdr_res, actions, items,
7354 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
7356 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7357 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7358 if (flow_dv_convert_action_modify_tcp_seq
7359 (mhdr_res, actions, error))
7361 action_flags |= actions->type ==
7362 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7363 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7364 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7367 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7368 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7369 if (flow_dv_convert_action_modify_tcp_ack
7370 (mhdr_res, actions, error))
7372 action_flags |= actions->type ==
7373 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7374 MLX5_FLOW_ACTION_INC_TCP_ACK :
7375 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7377 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7378 if (flow_dv_convert_action_set_reg
7379 (mhdr_res, actions, error))
7381 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7383 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7384 if (flow_dv_convert_action_copy_mreg
7385 (dev, mhdr_res, actions, error))
7387 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7389 case RTE_FLOW_ACTION_TYPE_METER:
7390 mtr = actions->conf;
7392 flow->meter = mlx5_flow_meter_attach(priv,
7396 return rte_flow_error_set(error,
7398 RTE_FLOW_ERROR_TYPE_ACTION,
7401 "or invalid parameters");
7403 /* Set the meter action. */
7404 dev_flow->dv.actions[actions_n++] =
7405 flow->meter->mfts->meter_action;
7406 action_flags |= MLX5_FLOW_ACTION_METER;
7408 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7409 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
7412 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7414 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7415 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
7418 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7420 case RTE_FLOW_ACTION_TYPE_END:
7422 if (mhdr_res->actions_num) {
7423 /* create modify action if needed. */
7424 if (flow_dv_modify_hdr_resource_register
7425 (dev, mhdr_res, dev_flow, error))
7427 dev_flow->dv.actions[modify_action_position] =
7428 dev_flow->dv.modify_hdr->verbs_action;
7434 if (mhdr_res->actions_num &&
7435 modify_action_position == UINT32_MAX)
7436 modify_action_position = actions_n++;
7438 dev_flow->dv.actions_n = actions_n;
7439 dev_flow->actions = action_flags;
7440 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7441 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7442 int item_type = items->type;
7444 switch (item_type) {
7445 case RTE_FLOW_ITEM_TYPE_PORT_ID:
7446 flow_dv_translate_item_port_id(dev, match_mask,
7447 match_value, items);
7448 last_item = MLX5_FLOW_ITEM_PORT_ID;
7450 case RTE_FLOW_ITEM_TYPE_ETH:
7451 flow_dv_translate_item_eth(match_mask, match_value,
7453 matcher.priority = MLX5_PRIORITY_MAP_L2;
7454 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7455 MLX5_FLOW_LAYER_OUTER_L2;
7457 case RTE_FLOW_ITEM_TYPE_VLAN:
7458 flow_dv_translate_item_vlan(dev_flow,
7459 match_mask, match_value,
7461 matcher.priority = MLX5_PRIORITY_MAP_L2;
7462 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
7463 MLX5_FLOW_LAYER_INNER_VLAN) :
7464 (MLX5_FLOW_LAYER_OUTER_L2 |
7465 MLX5_FLOW_LAYER_OUTER_VLAN);
7467 case RTE_FLOW_ITEM_TYPE_IPV4:
7468 mlx5_flow_tunnel_ip_check(items, next_protocol,
7469 &item_flags, &tunnel);
7470 flow_dv_translate_item_ipv4(match_mask, match_value,
7473 matcher.priority = MLX5_PRIORITY_MAP_L3;
7474 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7475 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7476 if (items->mask != NULL &&
7477 ((const struct rte_flow_item_ipv4 *)
7478 items->mask)->hdr.next_proto_id) {
7480 ((const struct rte_flow_item_ipv4 *)
7481 (items->spec))->hdr.next_proto_id;
7483 ((const struct rte_flow_item_ipv4 *)
7484 (items->mask))->hdr.next_proto_id;
7486 /* Reset for inner layer. */
7487 next_protocol = 0xff;
7490 case RTE_FLOW_ITEM_TYPE_IPV6:
7491 mlx5_flow_tunnel_ip_check(items, next_protocol,
7492 &item_flags, &tunnel);
7493 flow_dv_translate_item_ipv6(match_mask, match_value,
7496 matcher.priority = MLX5_PRIORITY_MAP_L3;
7497 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7498 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7499 if (items->mask != NULL &&
7500 ((const struct rte_flow_item_ipv6 *)
7501 items->mask)->hdr.proto) {
7503 ((const struct rte_flow_item_ipv6 *)
7504 items->spec)->hdr.proto;
7506 ((const struct rte_flow_item_ipv6 *)
7507 items->mask)->hdr.proto;
7509 /* Reset for inner layer. */
7510 next_protocol = 0xff;
7513 case RTE_FLOW_ITEM_TYPE_TCP:
7514 flow_dv_translate_item_tcp(match_mask, match_value,
7516 matcher.priority = MLX5_PRIORITY_MAP_L4;
7517 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7518 MLX5_FLOW_LAYER_OUTER_L4_TCP;
7520 case RTE_FLOW_ITEM_TYPE_UDP:
7521 flow_dv_translate_item_udp(match_mask, match_value,
7523 matcher.priority = MLX5_PRIORITY_MAP_L4;
7524 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7525 MLX5_FLOW_LAYER_OUTER_L4_UDP;
7527 case RTE_FLOW_ITEM_TYPE_GRE:
7528 flow_dv_translate_item_gre(match_mask, match_value,
7530 last_item = MLX5_FLOW_LAYER_GRE;
7532 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7533 flow_dv_translate_item_gre_key(match_mask,
7534 match_value, items);
7535 last_item = MLX5_FLOW_LAYER_GRE_KEY;
7537 case RTE_FLOW_ITEM_TYPE_NVGRE:
7538 flow_dv_translate_item_nvgre(match_mask, match_value,
7540 last_item = MLX5_FLOW_LAYER_GRE;
7542 case RTE_FLOW_ITEM_TYPE_VXLAN:
7543 flow_dv_translate_item_vxlan(match_mask, match_value,
7545 last_item = MLX5_FLOW_LAYER_VXLAN;
7547 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7548 flow_dv_translate_item_vxlan(match_mask, match_value,
7550 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7552 case RTE_FLOW_ITEM_TYPE_GENEVE:
7553 flow_dv_translate_item_geneve(match_mask, match_value,
7555 last_item = MLX5_FLOW_LAYER_GENEVE;
7557 case RTE_FLOW_ITEM_TYPE_MPLS:
7558 flow_dv_translate_item_mpls(match_mask, match_value,
7559 items, last_item, tunnel);
7560 last_item = MLX5_FLOW_LAYER_MPLS;
7562 case RTE_FLOW_ITEM_TYPE_MARK:
7563 flow_dv_translate_item_mark(dev, match_mask,
7564 match_value, items);
7565 last_item = MLX5_FLOW_ITEM_MARK;
7567 case RTE_FLOW_ITEM_TYPE_META:
7568 flow_dv_translate_item_meta(dev, match_mask,
7569 match_value, attr, items);
7570 last_item = MLX5_FLOW_ITEM_METADATA;
7572 case RTE_FLOW_ITEM_TYPE_ICMP:
7573 flow_dv_translate_item_icmp(match_mask, match_value,
7575 last_item = MLX5_FLOW_LAYER_ICMP;
7577 case RTE_FLOW_ITEM_TYPE_ICMP6:
7578 flow_dv_translate_item_icmp6(match_mask, match_value,
7580 last_item = MLX5_FLOW_LAYER_ICMP6;
7582 case RTE_FLOW_ITEM_TYPE_TAG:
7583 flow_dv_translate_item_tag(dev, match_mask,
7584 match_value, items);
7585 last_item = MLX5_FLOW_ITEM_TAG;
7587 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7588 flow_dv_translate_mlx5_item_tag(dev, match_mask,
7589 match_value, items);
7590 last_item = MLX5_FLOW_ITEM_TAG;
7592 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
7593 flow_dv_translate_item_tx_queue(dev, match_mask,
7596 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
7598 case RTE_FLOW_ITEM_TYPE_GTP:
7599 flow_dv_translate_item_gtp(match_mask, match_value,
7601 last_item = MLX5_FLOW_LAYER_GTP;
7606 item_flags |= last_item;
7609 * In case of ingress traffic when E-Switch mode is enabled,
7610 * we have two cases where we need to set the source port manually.
7611 * The first one, is in case of Nic steering rule, and the second is
7612 * E-Switch rule where no port_id item was found. In both cases
7613 * the source port is set according the current port in use.
7615 if ((attr->ingress && !(item_flags & MLX5_FLOW_ITEM_PORT_ID)) &&
7616 (priv->representor || priv->master)) {
7617 if (flow_dv_translate_item_port_id(dev, match_mask,
7621 assert(!flow_dv_check_valid_spec(matcher.mask.buf,
7622 dev_flow->dv.value.buf));
7623 dev_flow->layers = item_flags;
7624 if (action_flags & MLX5_FLOW_ACTION_RSS)
7625 flow_dv_hashfields_set(dev_flow);
7626 /* Register matcher. */
7627 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
7629 matcher.priority = mlx5_flow_adjust_priority(dev, priority,
7631 /* reserved field no needs to be set to 0 here. */
7632 tbl_key.domain = attr->transfer;
7633 tbl_key.direction = attr->egress;
7634 tbl_key.table_id = dev_flow->group;
7635 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow, error))
7641 * Apply the flow to the NIC, lock free,
7642 * (mutex should be acquired by caller).
7645 * Pointer to the Ethernet device structure.
7646 * @param[in, out] flow
7647 * Pointer to flow structure.
7649 * Pointer to error structure.
7652 * 0 on success, a negative errno value otherwise and rte_errno is set.
7655 __flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
7656 struct rte_flow_error *error)
7658 struct mlx5_flow_dv *dv;
7659 struct mlx5_flow *dev_flow;
7660 struct mlx5_priv *priv = dev->data->dev_private;
7664 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
7667 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP) {
7668 if (dev_flow->transfer) {
7669 dv->actions[n++] = priv->sh->esw_drop_action;
7671 dv->hrxq = mlx5_hrxq_drop_new(dev);
7675 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7677 "cannot get drop hash queue");
7680 dv->actions[n++] = dv->hrxq->action;
7682 } else if (dev_flow->actions &
7683 (MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)) {
7684 struct mlx5_hrxq *hrxq;
7686 assert(flow->rss.queue);
7687 hrxq = mlx5_hrxq_get(dev, flow->rss.key,
7688 MLX5_RSS_HASH_KEY_LEN,
7689 dev_flow->hash_fields,
7691 flow->rss.queue_num);
7693 hrxq = mlx5_hrxq_new
7694 (dev, flow->rss.key,
7695 MLX5_RSS_HASH_KEY_LEN,
7696 dev_flow->hash_fields,
7698 flow->rss.queue_num,
7699 !!(dev_flow->layers &
7700 MLX5_FLOW_LAYER_TUNNEL));
7705 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7706 "cannot get hash queue");
7710 dv->actions[n++] = dv->hrxq->action;
7713 mlx5_glue->dv_create_flow(dv->matcher->matcher_object,
7714 (void *)&dv->value, n,
7717 rte_flow_error_set(error, errno,
7718 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7720 "hardware refuses to create flow");
7723 if (priv->vmwa_context &&
7724 dev_flow->dv.vf_vlan.tag &&
7725 !dev_flow->dv.vf_vlan.created) {
7727 * The rule contains the VLAN pattern.
7728 * For VF we are going to create VLAN
7729 * interface to make hypervisor set correct
7730 * e-Switch vport context.
7732 mlx5_vlan_vmwa_acquire(dev, &dev_flow->dv.vf_vlan);
7737 err = rte_errno; /* Save rte_errno before cleanup. */
7738 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
7739 struct mlx5_flow_dv *dv = &dev_flow->dv;
7741 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP)
7742 mlx5_hrxq_drop_release(dev);
7744 mlx5_hrxq_release(dev, dv->hrxq);
7747 if (dev_flow->dv.vf_vlan.tag &&
7748 dev_flow->dv.vf_vlan.created)
7749 mlx5_vlan_vmwa_release(dev, &dev_flow->dv.vf_vlan);
7751 rte_errno = err; /* Restore rte_errno. */
7756 * Release the flow matcher.
7759 * Pointer to Ethernet device.
7761 * Pointer to mlx5_flow.
7764 * 1 while a reference on it exists, 0 when freed.
7767 flow_dv_matcher_release(struct rte_eth_dev *dev,
7768 struct mlx5_flow *flow)
7770 struct mlx5_flow_dv_matcher *matcher = flow->dv.matcher;
7772 assert(matcher->matcher_object);
7773 DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
7774 dev->data->port_id, (void *)matcher,
7775 rte_atomic32_read(&matcher->refcnt));
7776 if (rte_atomic32_dec_and_test(&matcher->refcnt)) {
7777 claim_zero(mlx5_glue->dv_destroy_flow_matcher
7778 (matcher->matcher_object));
7779 LIST_REMOVE(matcher, next);
7780 /* table ref-- in release interface. */
7781 flow_dv_tbl_resource_release(dev, matcher->tbl);
7783 DRV_LOG(DEBUG, "port %u matcher %p: removed",
7784 dev->data->port_id, (void *)matcher);
7791 * Release an encap/decap resource.
7794 * Pointer to mlx5_flow.
7797 * 1 while a reference on it exists, 0 when freed.
7800 flow_dv_encap_decap_resource_release(struct mlx5_flow *flow)
7802 struct mlx5_flow_dv_encap_decap_resource *cache_resource =
7803 flow->dv.encap_decap;
7805 assert(cache_resource->verbs_action);
7806 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d--",
7807 (void *)cache_resource,
7808 rte_atomic32_read(&cache_resource->refcnt));
7809 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7810 claim_zero(mlx5_glue->destroy_flow_action
7811 (cache_resource->verbs_action));
7812 LIST_REMOVE(cache_resource, next);
7813 rte_free(cache_resource);
7814 DRV_LOG(DEBUG, "encap/decap resource %p: removed",
7815 (void *)cache_resource);
7822 * Release an jump to table action resource.
7825 * Pointer to Ethernet device.
7827 * Pointer to mlx5_flow.
7830 * 1 while a reference on it exists, 0 when freed.
7833 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
7834 struct mlx5_flow *flow)
7836 struct mlx5_flow_dv_jump_tbl_resource *cache_resource = flow->dv.jump;
7837 struct mlx5_flow_tbl_data_entry *tbl_data =
7838 container_of(cache_resource,
7839 struct mlx5_flow_tbl_data_entry, jump);
7841 assert(cache_resource->action);
7842 DRV_LOG(DEBUG, "jump table resource %p: refcnt %d--",
7843 (void *)cache_resource,
7844 rte_atomic32_read(&cache_resource->refcnt));
7845 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7846 claim_zero(mlx5_glue->destroy_flow_action
7847 (cache_resource->action));
7848 /* jump action memory free is inside the table release. */
7849 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
7850 DRV_LOG(DEBUG, "jump table resource %p: removed",
7851 (void *)cache_resource);
7858 * Release a modify-header resource.
7861 * Pointer to mlx5_flow.
7864 * 1 while a reference on it exists, 0 when freed.
7867 flow_dv_modify_hdr_resource_release(struct mlx5_flow *flow)
7869 struct mlx5_flow_dv_modify_hdr_resource *cache_resource =
7870 flow->dv.modify_hdr;
7872 assert(cache_resource->verbs_action);
7873 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d--",
7874 (void *)cache_resource,
7875 rte_atomic32_read(&cache_resource->refcnt));
7876 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7877 claim_zero(mlx5_glue->destroy_flow_action
7878 (cache_resource->verbs_action));
7879 LIST_REMOVE(cache_resource, next);
7880 rte_free(cache_resource);
7881 DRV_LOG(DEBUG, "modify-header resource %p: removed",
7882 (void *)cache_resource);
7889 * Release port ID action resource.
7892 * Pointer to mlx5_flow.
7895 * 1 while a reference on it exists, 0 when freed.
7898 flow_dv_port_id_action_resource_release(struct mlx5_flow *flow)
7900 struct mlx5_flow_dv_port_id_action_resource *cache_resource =
7901 flow->dv.port_id_action;
7903 assert(cache_resource->action);
7904 DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--",
7905 (void *)cache_resource,
7906 rte_atomic32_read(&cache_resource->refcnt));
7907 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7908 claim_zero(mlx5_glue->destroy_flow_action
7909 (cache_resource->action));
7910 LIST_REMOVE(cache_resource, next);
7911 rte_free(cache_resource);
7912 DRV_LOG(DEBUG, "port id action resource %p: removed",
7913 (void *)cache_resource);
7920 * Release push vlan action resource.
7923 * Pointer to mlx5_flow.
7926 * 1 while a reference on it exists, 0 when freed.
7929 flow_dv_push_vlan_action_resource_release(struct mlx5_flow *flow)
7931 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource =
7932 flow->dv.push_vlan_res;
7934 assert(cache_resource->action);
7935 DRV_LOG(DEBUG, "push VLAN action resource %p: refcnt %d--",
7936 (void *)cache_resource,
7937 rte_atomic32_read(&cache_resource->refcnt));
7938 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7939 claim_zero(mlx5_glue->destroy_flow_action
7940 (cache_resource->action));
7941 LIST_REMOVE(cache_resource, next);
7942 rte_free(cache_resource);
7943 DRV_LOG(DEBUG, "push vlan action resource %p: removed",
7944 (void *)cache_resource);
7951 * Remove the flow from the NIC but keeps it in memory.
7952 * Lock free, (mutex should be acquired by caller).
7955 * Pointer to Ethernet device.
7956 * @param[in, out] flow
7957 * Pointer to flow structure.
7960 __flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
7962 struct mlx5_flow_dv *dv;
7963 struct mlx5_flow *dev_flow;
7967 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
7970 claim_zero(mlx5_glue->dv_destroy_flow(dv->flow));
7974 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP)
7975 mlx5_hrxq_drop_release(dev);
7977 mlx5_hrxq_release(dev, dv->hrxq);
7980 if (dev_flow->dv.vf_vlan.tag &&
7981 dev_flow->dv.vf_vlan.created)
7982 mlx5_vlan_vmwa_release(dev, &dev_flow->dv.vf_vlan);
7987 * Remove the flow from the NIC and the memory.
7988 * Lock free, (mutex should be acquired by caller).
7991 * Pointer to the Ethernet device structure.
7992 * @param[in, out] flow
7993 * Pointer to flow structure.
7996 __flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
7998 struct mlx5_flow *dev_flow;
8002 __flow_dv_remove(dev, flow);
8003 if (flow->counter) {
8004 flow_dv_counter_release(dev, flow->counter);
8005 flow->counter = NULL;
8008 mlx5_flow_meter_detach(flow->meter);
8011 while (!LIST_EMPTY(&flow->dev_flows)) {
8012 dev_flow = LIST_FIRST(&flow->dev_flows);
8013 LIST_REMOVE(dev_flow, next);
8014 if (dev_flow->dv.matcher)
8015 flow_dv_matcher_release(dev, dev_flow);
8016 if (dev_flow->dv.encap_decap)
8017 flow_dv_encap_decap_resource_release(dev_flow);
8018 if (dev_flow->dv.modify_hdr)
8019 flow_dv_modify_hdr_resource_release(dev_flow);
8020 if (dev_flow->dv.jump)
8021 flow_dv_jump_tbl_resource_release(dev, dev_flow);
8022 if (dev_flow->dv.port_id_action)
8023 flow_dv_port_id_action_resource_release(dev_flow);
8024 if (dev_flow->dv.push_vlan_res)
8025 flow_dv_push_vlan_action_resource_release(dev_flow);
8026 if (dev_flow->dv.tag_resource)
8027 flow_dv_tag_release(dev, dev_flow->dv.tag_resource);
8033 * Query a dv flow rule for its statistics via devx.
8036 * Pointer to Ethernet device.
8038 * Pointer to the sub flow.
8040 * data retrieved by the query.
8042 * Perform verbose error reporting if not NULL.
8045 * 0 on success, a negative errno value otherwise and rte_errno is set.
8048 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
8049 void *data, struct rte_flow_error *error)
8051 struct mlx5_priv *priv = dev->data->dev_private;
8052 struct rte_flow_query_count *qc = data;
8054 if (!priv->config.devx)
8055 return rte_flow_error_set(error, ENOTSUP,
8056 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8058 "counters are not supported");
8059 if (flow->counter) {
8060 uint64_t pkts, bytes;
8061 int err = _flow_dv_query_count(dev, flow->counter, &pkts,
8065 return rte_flow_error_set(error, -err,
8066 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8067 NULL, "cannot read counters");
8070 qc->hits = pkts - flow->counter->hits;
8071 qc->bytes = bytes - flow->counter->bytes;
8073 flow->counter->hits = pkts;
8074 flow->counter->bytes = bytes;
8078 return rte_flow_error_set(error, EINVAL,
8079 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8081 "counters are not available");
8087 * @see rte_flow_query()
8091 flow_dv_query(struct rte_eth_dev *dev,
8092 struct rte_flow *flow __rte_unused,
8093 const struct rte_flow_action *actions __rte_unused,
8094 void *data __rte_unused,
8095 struct rte_flow_error *error __rte_unused)
8099 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
8100 switch (actions->type) {
8101 case RTE_FLOW_ACTION_TYPE_VOID:
8103 case RTE_FLOW_ACTION_TYPE_COUNT:
8104 ret = flow_dv_query_count(dev, flow, data, error);
8107 return rte_flow_error_set(error, ENOTSUP,
8108 RTE_FLOW_ERROR_TYPE_ACTION,
8110 "action not supported");
8117 * Destroy the meter table set.
8118 * Lock free, (mutex should be acquired by caller).
8121 * Pointer to Ethernet device.
8123 * Pointer to the meter table set.
8129 flow_dv_destroy_mtr_tbl(struct rte_eth_dev *dev,
8130 struct mlx5_meter_domains_infos *tbl)
8132 struct mlx5_priv *priv = dev->data->dev_private;
8133 struct mlx5_meter_domains_infos *mtd =
8134 (struct mlx5_meter_domains_infos *)tbl;
8136 if (!mtd || !priv->config.dv_flow_en)
8138 if (mtd->ingress.policer_rules[RTE_MTR_DROPPED])
8139 claim_zero(mlx5_glue->dv_destroy_flow
8140 (mtd->ingress.policer_rules[RTE_MTR_DROPPED]));
8141 if (mtd->egress.policer_rules[RTE_MTR_DROPPED])
8142 claim_zero(mlx5_glue->dv_destroy_flow
8143 (mtd->egress.policer_rules[RTE_MTR_DROPPED]));
8144 if (mtd->transfer.policer_rules[RTE_MTR_DROPPED])
8145 claim_zero(mlx5_glue->dv_destroy_flow
8146 (mtd->transfer.policer_rules[RTE_MTR_DROPPED]));
8147 if (mtd->egress.color_matcher)
8148 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8149 (mtd->egress.color_matcher));
8150 if (mtd->egress.any_matcher)
8151 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8152 (mtd->egress.any_matcher));
8153 if (mtd->egress.tbl)
8154 claim_zero(flow_dv_tbl_resource_release(dev,
8156 if (mtd->ingress.color_matcher)
8157 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8158 (mtd->ingress.color_matcher));
8159 if (mtd->ingress.any_matcher)
8160 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8161 (mtd->ingress.any_matcher));
8162 if (mtd->ingress.tbl)
8163 claim_zero(flow_dv_tbl_resource_release(dev,
8165 if (mtd->transfer.color_matcher)
8166 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8167 (mtd->transfer.color_matcher));
8168 if (mtd->transfer.any_matcher)
8169 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8170 (mtd->transfer.any_matcher));
8171 if (mtd->transfer.tbl)
8172 claim_zero(flow_dv_tbl_resource_release(dev,
8173 mtd->transfer.tbl));
8175 claim_zero(mlx5_glue->destroy_flow_action(mtd->drop_actn));
8180 /* Number of meter flow actions, count and jump or count and drop. */
8181 #define METER_ACTIONS 2
8184 * Create specify domain meter table and suffix table.
8187 * Pointer to Ethernet device.
8188 * @param[in,out] mtb
8189 * Pointer to DV meter table set.
8192 * @param[in] transfer
8194 * @param[in] color_reg_c_idx
8195 * Reg C index for color match.
8198 * 0 on success, -1 otherwise and rte_errno is set.
8201 flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
8202 struct mlx5_meter_domains_infos *mtb,
8203 uint8_t egress, uint8_t transfer,
8204 uint32_t color_reg_c_idx)
8206 struct mlx5_priv *priv = dev->data->dev_private;
8207 struct mlx5_ibv_shared *sh = priv->sh;
8208 struct mlx5_flow_dv_match_params mask = {
8209 .size = sizeof(mask.buf),
8211 struct mlx5_flow_dv_match_params value = {
8212 .size = sizeof(value.buf),
8214 struct mlx5dv_flow_matcher_attr dv_attr = {
8215 .type = IBV_FLOW_ATTR_NORMAL,
8217 .match_criteria_enable = 0,
8218 .match_mask = (void *)&mask,
8220 void *actions[METER_ACTIONS];
8221 struct mlx5_flow_tbl_resource **sfx_tbl;
8222 struct mlx5_meter_domain_info *dtb;
8223 struct rte_flow_error error;
8227 sfx_tbl = &sh->fdb_mtr_sfx_tbl;
8228 dtb = &mtb->transfer;
8229 } else if (egress) {
8230 sfx_tbl = &sh->tx_mtr_sfx_tbl;
8233 sfx_tbl = &sh->rx_mtr_sfx_tbl;
8234 dtb = &mtb->ingress;
8236 /* If the suffix table in missing, create it. */
8238 *sfx_tbl = flow_dv_tbl_resource_get(dev,
8239 MLX5_FLOW_TABLE_LEVEL_SUFFIX,
8240 egress, transfer, &error);
8242 DRV_LOG(ERR, "Failed to create meter suffix table.");
8246 /* Create the meter table with METER level. */
8247 dtb->tbl = flow_dv_tbl_resource_get(dev, MLX5_FLOW_TABLE_LEVEL_METER,
8248 egress, transfer, &error);
8250 DRV_LOG(ERR, "Failed to create meter policer table.");
8253 /* Create matchers, Any and Color. */
8254 dv_attr.priority = 3;
8255 dv_attr.match_criteria_enable = 0;
8256 dtb->any_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
8259 if (!dtb->any_matcher) {
8260 DRV_LOG(ERR, "Failed to create meter"
8261 " policer default matcher.");
8264 dv_attr.priority = 0;
8265 dv_attr.match_criteria_enable =
8266 1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
8267 flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
8268 rte_col_2_mlx5_col(RTE_COLORS), UINT32_MAX);
8269 dtb->color_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
8272 if (!dtb->color_matcher) {
8273 DRV_LOG(ERR, "Failed to create meter policer color matcher.");
8276 if (mtb->count_actns[RTE_MTR_DROPPED])
8277 actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
8278 actions[i++] = mtb->drop_actn;
8279 /* Default rule: lowest priority, match any, actions: drop. */
8280 dtb->policer_rules[RTE_MTR_DROPPED] =
8281 mlx5_glue->dv_create_flow(dtb->any_matcher,
8282 (void *)&value, i, actions);
8283 if (!dtb->policer_rules[RTE_MTR_DROPPED]) {
8284 DRV_LOG(ERR, "Failed to create meter policer drop rule.");
8293 * Create the needed meter and suffix tables.
8294 * Lock free, (mutex should be acquired by caller).
8297 * Pointer to Ethernet device.
8299 * Pointer to the flow meter.
8302 * Pointer to table set on success, NULL otherwise and rte_errno is set.
8304 static struct mlx5_meter_domains_infos *
8305 flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
8306 const struct mlx5_flow_meter *fm)
8308 struct mlx5_priv *priv = dev->data->dev_private;
8309 struct mlx5_meter_domains_infos *mtb;
8313 if (!priv->mtr_en) {
8314 rte_errno = ENOTSUP;
8317 mtb = rte_calloc(__func__, 1, sizeof(*mtb), 0);
8319 DRV_LOG(ERR, "Failed to allocate memory for meter.");
8322 /* Create meter count actions */
8323 for (i = 0; i <= RTE_MTR_DROPPED; i++) {
8324 if (!fm->policer_stats.cnt[i])
8326 mtb->count_actns[i] = fm->policer_stats.cnt[i]->action;
8328 /* Create drop action. */
8329 mtb->drop_actn = mlx5_glue->dr_create_flow_action_drop();
8330 if (!mtb->drop_actn) {
8331 DRV_LOG(ERR, "Failed to create drop action.");
8334 /* Egress meter table. */
8335 ret = flow_dv_prepare_mtr_tables(dev, mtb, 1, 0, priv->mtr_color_reg);
8337 DRV_LOG(ERR, "Failed to prepare egress meter table.");
8340 /* Ingress meter table. */
8341 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 0, priv->mtr_color_reg);
8343 DRV_LOG(ERR, "Failed to prepare ingress meter table.");
8346 /* FDB meter table. */
8347 if (priv->config.dv_esw_en) {
8348 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 1,
8349 priv->mtr_color_reg);
8351 DRV_LOG(ERR, "Failed to prepare fdb meter table.");
8357 flow_dv_destroy_mtr_tbl(dev, mtb);
8362 * Destroy domain policer rule.
8365 * Pointer to domain table.
8368 flow_dv_destroy_domain_policer_rule(struct mlx5_meter_domain_info *dt)
8372 for (i = 0; i < RTE_MTR_DROPPED; i++) {
8373 if (dt->policer_rules[i]) {
8374 claim_zero(mlx5_glue->dv_destroy_flow
8375 (dt->policer_rules[i]));
8376 dt->policer_rules[i] = NULL;
8379 if (dt->jump_actn) {
8380 claim_zero(mlx5_glue->destroy_flow_action(dt->jump_actn));
8381 dt->jump_actn = NULL;
8386 * Destroy policer rules.
8389 * Pointer to Ethernet device.
8391 * Pointer to flow meter structure.
8393 * Pointer to flow attributes.
8399 flow_dv_destroy_policer_rules(struct rte_eth_dev *dev __rte_unused,
8400 const struct mlx5_flow_meter *fm,
8401 const struct rte_flow_attr *attr)
8403 struct mlx5_meter_domains_infos *mtb = fm ? fm->mfts : NULL;
8408 flow_dv_destroy_domain_policer_rule(&mtb->egress);
8410 flow_dv_destroy_domain_policer_rule(&mtb->ingress);
8412 flow_dv_destroy_domain_policer_rule(&mtb->transfer);
8417 * Create specify domain meter policer rule.
8420 * Pointer to flow meter structure.
8422 * Pointer to DV meter table set.
8424 * Pointer to suffix table.
8425 * @param[in] mtr_reg_c
8426 * Color match REG_C.
8429 * 0 on success, -1 otherwise.
8432 flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
8433 struct mlx5_meter_domain_info *dtb,
8434 struct mlx5_flow_tbl_resource *sfx_tb,
8437 struct mlx5_flow_dv_match_params matcher = {
8438 .size = sizeof(matcher.buf),
8440 struct mlx5_flow_dv_match_params value = {
8441 .size = sizeof(value.buf),
8443 struct mlx5_meter_domains_infos *mtb = fm->mfts;
8444 void *actions[METER_ACTIONS];
8447 /* Create jump action. */
8450 if (!dtb->jump_actn)
8452 mlx5_glue->dr_create_flow_action_dest_flow_tbl
8454 if (!dtb->jump_actn) {
8455 DRV_LOG(ERR, "Failed to create policer jump action.");
8458 for (i = 0; i < RTE_MTR_DROPPED; i++) {
8461 flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
8462 rte_col_2_mlx5_col(i), UINT32_MAX);
8463 if (mtb->count_actns[i])
8464 actions[j++] = mtb->count_actns[i];
8465 if (fm->params.action[i] == MTR_POLICER_ACTION_DROP)
8466 actions[j++] = mtb->drop_actn;
8468 actions[j++] = dtb->jump_actn;
8469 dtb->policer_rules[i] =
8470 mlx5_glue->dv_create_flow(dtb->color_matcher,
8473 if (!dtb->policer_rules[i]) {
8474 DRV_LOG(ERR, "Failed to create policer rule.");
8485 * Create policer rules.
8488 * Pointer to Ethernet device.
8490 * Pointer to flow meter structure.
8492 * Pointer to flow attributes.
8495 * 0 on success, -1 otherwise.
8498 flow_dv_create_policer_rules(struct rte_eth_dev *dev,
8499 struct mlx5_flow_meter *fm,
8500 const struct rte_flow_attr *attr)
8502 struct mlx5_priv *priv = dev->data->dev_private;
8503 struct mlx5_meter_domains_infos *mtb = fm->mfts;
8507 ret = flow_dv_create_policer_forward_rule(fm, &mtb->egress,
8508 priv->sh->tx_mtr_sfx_tbl,
8509 priv->mtr_color_reg);
8511 DRV_LOG(ERR, "Failed to create egress policer.");
8515 if (attr->ingress) {
8516 ret = flow_dv_create_policer_forward_rule(fm, &mtb->ingress,
8517 priv->sh->rx_mtr_sfx_tbl,
8518 priv->mtr_color_reg);
8520 DRV_LOG(ERR, "Failed to create ingress policer.");
8524 if (attr->transfer) {
8525 ret = flow_dv_create_policer_forward_rule(fm, &mtb->transfer,
8526 priv->sh->fdb_mtr_sfx_tbl,
8527 priv->mtr_color_reg);
8529 DRV_LOG(ERR, "Failed to create transfer policer.");
8535 flow_dv_destroy_policer_rules(dev, fm, attr);
8540 * Query a devx counter.
8543 * Pointer to the Ethernet device structure.
8545 * Pointer to the flow counter.
8547 * Set to clear the counter statistics.
8549 * The statistics value of packets.
8551 * The statistics value of bytes.
8554 * 0 on success, otherwise return -1.
8557 flow_dv_counter_query(struct rte_eth_dev *dev,
8558 struct mlx5_flow_counter *cnt, bool clear,
8559 uint64_t *pkts, uint64_t *bytes)
8561 struct mlx5_priv *priv = dev->data->dev_private;
8562 uint64_t inn_pkts, inn_bytes;
8565 if (!priv->config.devx)
8567 ret = _flow_dv_query_count(dev, cnt, &inn_pkts, &inn_bytes);
8570 *pkts = inn_pkts - cnt->hits;
8571 *bytes = inn_bytes - cnt->bytes;
8573 cnt->hits = inn_pkts;
8574 cnt->bytes = inn_bytes;
8580 * Mutex-protected thunk to lock-free __flow_dv_translate().
8583 flow_dv_translate(struct rte_eth_dev *dev,
8584 struct mlx5_flow *dev_flow,
8585 const struct rte_flow_attr *attr,
8586 const struct rte_flow_item items[],
8587 const struct rte_flow_action actions[],
8588 struct rte_flow_error *error)
8592 flow_dv_shared_lock(dev);
8593 ret = __flow_dv_translate(dev, dev_flow, attr, items, actions, error);
8594 flow_dv_shared_unlock(dev);
8599 * Mutex-protected thunk to lock-free __flow_dv_apply().
8602 flow_dv_apply(struct rte_eth_dev *dev,
8603 struct rte_flow *flow,
8604 struct rte_flow_error *error)
8608 flow_dv_shared_lock(dev);
8609 ret = __flow_dv_apply(dev, flow, error);
8610 flow_dv_shared_unlock(dev);
8615 * Mutex-protected thunk to lock-free __flow_dv_remove().
8618 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
8620 flow_dv_shared_lock(dev);
8621 __flow_dv_remove(dev, flow);
8622 flow_dv_shared_unlock(dev);
8626 * Mutex-protected thunk to lock-free __flow_dv_destroy().
8629 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
8631 flow_dv_shared_lock(dev);
8632 __flow_dv_destroy(dev, flow);
8633 flow_dv_shared_unlock(dev);
8637 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
8639 static struct mlx5_flow_counter *
8640 flow_dv_counter_allocate(struct rte_eth_dev *dev)
8642 struct mlx5_flow_counter *cnt;
8644 flow_dv_shared_lock(dev);
8645 cnt = flow_dv_counter_alloc(dev, 0, 0, 1);
8646 flow_dv_shared_unlock(dev);
8651 * Mutex-protected thunk to lock-free flow_dv_counter_release().
8654 flow_dv_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt)
8656 flow_dv_shared_lock(dev);
8657 flow_dv_counter_release(dev, cnt);
8658 flow_dv_shared_unlock(dev);
8661 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
8662 .validate = flow_dv_validate,
8663 .prepare = flow_dv_prepare,
8664 .translate = flow_dv_translate,
8665 .apply = flow_dv_apply,
8666 .remove = flow_dv_remove,
8667 .destroy = flow_dv_destroy,
8668 .query = flow_dv_query,
8669 .create_mtr_tbls = flow_dv_create_mtr_tbl,
8670 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbl,
8671 .create_policer_rules = flow_dv_create_policer_rules,
8672 .destroy_policer_rules = flow_dv_destroy_policer_rules,
8673 .counter_alloc = flow_dv_counter_allocate,
8674 .counter_free = flow_dv_counter_free,
8675 .counter_query = flow_dv_counter_query,
8678 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */