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>
32 #include "mlx5_defs.h"
33 #include "mlx5_glue.h"
34 #include "mlx5_flow.h"
36 #include "mlx5_rxtx.h"
38 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
40 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
41 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
44 #ifndef HAVE_MLX5DV_DR_ESWITCH
45 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
46 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
50 #ifndef HAVE_MLX5DV_DR
51 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
54 #define MLX5_ENCAPSULATION_DECISION_SIZE (sizeof(struct rte_flow_item_eth) + \
55 sizeof(struct rte_flow_item_ipv4))
56 /* VLAN header definitions */
57 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
58 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
59 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
60 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
61 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
76 * Initialize flow attributes structure according to flow items' types.
78 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
79 * mode. For tunnel mode, the items to be modified are the outermost ones.
82 * Pointer to item specification.
84 * Pointer to flow attributes structure.
87 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr)
89 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
91 case RTE_FLOW_ITEM_TYPE_IPV4:
95 case RTE_FLOW_ITEM_TYPE_IPV6:
99 case RTE_FLOW_ITEM_TYPE_UDP:
103 case RTE_FLOW_ITEM_TYPE_TCP:
115 * Convert rte_mtr_color to mlx5 color.
124 rte_col_2_mlx5_col(enum rte_color rcol)
127 case RTE_COLOR_GREEN:
128 return MLX5_FLOW_COLOR_GREEN;
129 case RTE_COLOR_YELLOW:
130 return MLX5_FLOW_COLOR_YELLOW;
132 return MLX5_FLOW_COLOR_RED;
136 return MLX5_FLOW_COLOR_UNDEFINED;
139 struct field_modify_info {
140 uint32_t size; /* Size of field in protocol header, in bytes. */
141 uint32_t offset; /* Offset of field in protocol header, in bytes. */
142 enum mlx5_modification_field id;
145 struct field_modify_info modify_eth[] = {
146 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
147 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
148 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
149 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
153 struct field_modify_info modify_vlan_out_first_vid[] = {
154 /* Size in bits !!! */
155 {12, 0, MLX5_MODI_OUT_FIRST_VID},
159 struct field_modify_info modify_ipv4[] = {
160 {1, 1, MLX5_MODI_OUT_IP_DSCP},
161 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
162 {4, 12, MLX5_MODI_OUT_SIPV4},
163 {4, 16, MLX5_MODI_OUT_DIPV4},
167 struct field_modify_info modify_ipv6[] = {
168 {1, 0, MLX5_MODI_OUT_IP_DSCP},
169 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
170 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
171 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
172 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
173 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
174 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
175 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
176 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
177 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
181 struct field_modify_info modify_udp[] = {
182 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
183 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
187 struct field_modify_info modify_tcp[] = {
188 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
189 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
190 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
191 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
196 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
197 uint8_t next_protocol, uint64_t *item_flags,
200 assert(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
201 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
202 if (next_protocol == IPPROTO_IPIP) {
203 *item_flags |= MLX5_FLOW_LAYER_IPIP;
206 if (next_protocol == IPPROTO_IPV6) {
207 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
213 * Acquire the synchronizing object to protect multithreaded access
214 * to shared dv context. Lock occurs only if context is actually
215 * shared, i.e. we have multiport IB device and representors are
219 * Pointer to the rte_eth_dev structure.
222 flow_dv_shared_lock(struct rte_eth_dev *dev)
224 struct mlx5_priv *priv = dev->data->dev_private;
225 struct mlx5_ibv_shared *sh = priv->sh;
227 if (sh->dv_refcnt > 1) {
230 ret = pthread_mutex_lock(&sh->dv_mutex);
237 flow_dv_shared_unlock(struct rte_eth_dev *dev)
239 struct mlx5_priv *priv = dev->data->dev_private;
240 struct mlx5_ibv_shared *sh = priv->sh;
242 if (sh->dv_refcnt > 1) {
245 ret = pthread_mutex_unlock(&sh->dv_mutex);
251 /* Update VLAN's VID/PCP based on input rte_flow_action.
254 * Pointer to struct rte_flow_action.
256 * Pointer to struct rte_vlan_hdr.
259 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
260 struct rte_vlan_hdr *vlan)
263 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
265 ((const struct rte_flow_action_of_set_vlan_pcp *)
266 action->conf)->vlan_pcp;
267 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
268 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
269 vlan->vlan_tci |= vlan_tci;
270 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
271 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
272 vlan->vlan_tci |= rte_be_to_cpu_16
273 (((const struct rte_flow_action_of_set_vlan_vid *)
274 action->conf)->vlan_vid);
279 * Fetch 1, 2, 3 or 4 byte field from the byte array
280 * and return as unsigned integer in host-endian format.
283 * Pointer to data array.
285 * Size of field to extract.
288 * converted field in host endian format.
290 static inline uint32_t
291 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
300 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
303 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
304 ret = (ret << 8) | *(data + sizeof(uint16_t));
307 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
318 * Convert modify-header action to DV specification.
320 * Data length of each action is determined by provided field description
321 * and the item mask. Data bit offset and width of each action is determined
322 * by provided item mask.
325 * Pointer to item specification.
327 * Pointer to field modification information.
328 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
329 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
330 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
332 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
333 * Negative offset value sets the same offset as source offset.
334 * size field is ignored, value is taken from source field.
335 * @param[in,out] resource
336 * Pointer to the modify-header resource.
338 * Type of modification.
340 * Pointer to the error structure.
343 * 0 on success, a negative errno value otherwise and rte_errno is set.
346 flow_dv_convert_modify_action(struct rte_flow_item *item,
347 struct field_modify_info *field,
348 struct field_modify_info *dcopy,
349 struct mlx5_flow_dv_modify_hdr_resource *resource,
350 uint32_t type, struct rte_flow_error *error)
352 uint32_t i = resource->actions_num;
353 struct mlx5_modification_cmd *actions = resource->actions;
356 * The item and mask are provided in big-endian format.
357 * The fields should be presented as in big-endian format either.
358 * Mask must be always present, it defines the actual field width.
368 if (i >= MLX5_MODIFY_NUM)
369 return rte_flow_error_set(error, EINVAL,
370 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
371 "too many items to modify");
372 /* Fetch variable byte size mask from the array. */
373 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
374 field->offset, field->size);
379 /* Deduce actual data width in bits from mask value. */
380 off_b = rte_bsf32(mask);
381 size_b = sizeof(uint32_t) * CHAR_BIT -
382 off_b - __builtin_clz(mask);
384 size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
385 actions[i].action_type = type;
386 actions[i].field = field->id;
387 actions[i].offset = off_b;
388 actions[i].length = size_b;
389 /* Convert entire record to expected big-endian format. */
390 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
391 if (type == MLX5_MODIFICATION_TYPE_COPY) {
393 actions[i].dst_field = dcopy->id;
394 actions[i].dst_offset =
395 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
396 /* Convert entire record to big-endian format. */
397 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
400 data = flow_dv_fetch_field((const uint8_t *)item->spec +
401 field->offset, field->size);
402 /* Shift out the trailing masked bits from data. */
403 data = (data & mask) >> off_b;
404 actions[i].data1 = rte_cpu_to_be_32(data);
408 } while (field->size);
409 resource->actions_num = i;
410 if (!resource->actions_num)
411 return rte_flow_error_set(error, EINVAL,
412 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
413 "invalid modification flow item");
418 * Convert modify-header set IPv4 address action to DV specification.
420 * @param[in,out] resource
421 * Pointer to the modify-header resource.
423 * Pointer to action specification.
425 * Pointer to the error structure.
428 * 0 on success, a negative errno value otherwise and rte_errno is set.
431 flow_dv_convert_action_modify_ipv4
432 (struct mlx5_flow_dv_modify_hdr_resource *resource,
433 const struct rte_flow_action *action,
434 struct rte_flow_error *error)
436 const struct rte_flow_action_set_ipv4 *conf =
437 (const struct rte_flow_action_set_ipv4 *)(action->conf);
438 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
439 struct rte_flow_item_ipv4 ipv4;
440 struct rte_flow_item_ipv4 ipv4_mask;
442 memset(&ipv4, 0, sizeof(ipv4));
443 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
444 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
445 ipv4.hdr.src_addr = conf->ipv4_addr;
446 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
448 ipv4.hdr.dst_addr = conf->ipv4_addr;
449 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
452 item.mask = &ipv4_mask;
453 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
454 MLX5_MODIFICATION_TYPE_SET, error);
458 * Convert modify-header set IPv6 address action to DV specification.
460 * @param[in,out] resource
461 * Pointer to the modify-header resource.
463 * Pointer to action specification.
465 * Pointer to the error structure.
468 * 0 on success, a negative errno value otherwise and rte_errno is set.
471 flow_dv_convert_action_modify_ipv6
472 (struct mlx5_flow_dv_modify_hdr_resource *resource,
473 const struct rte_flow_action *action,
474 struct rte_flow_error *error)
476 const struct rte_flow_action_set_ipv6 *conf =
477 (const struct rte_flow_action_set_ipv6 *)(action->conf);
478 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
479 struct rte_flow_item_ipv6 ipv6;
480 struct rte_flow_item_ipv6 ipv6_mask;
482 memset(&ipv6, 0, sizeof(ipv6));
483 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
484 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
485 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
486 sizeof(ipv6.hdr.src_addr));
487 memcpy(&ipv6_mask.hdr.src_addr,
488 &rte_flow_item_ipv6_mask.hdr.src_addr,
489 sizeof(ipv6.hdr.src_addr));
491 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
492 sizeof(ipv6.hdr.dst_addr));
493 memcpy(&ipv6_mask.hdr.dst_addr,
494 &rte_flow_item_ipv6_mask.hdr.dst_addr,
495 sizeof(ipv6.hdr.dst_addr));
498 item.mask = &ipv6_mask;
499 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
500 MLX5_MODIFICATION_TYPE_SET, error);
504 * Convert modify-header set MAC address action to DV specification.
506 * @param[in,out] resource
507 * Pointer to the modify-header resource.
509 * Pointer to action specification.
511 * Pointer to the error structure.
514 * 0 on success, a negative errno value otherwise and rte_errno is set.
517 flow_dv_convert_action_modify_mac
518 (struct mlx5_flow_dv_modify_hdr_resource *resource,
519 const struct rte_flow_action *action,
520 struct rte_flow_error *error)
522 const struct rte_flow_action_set_mac *conf =
523 (const struct rte_flow_action_set_mac *)(action->conf);
524 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
525 struct rte_flow_item_eth eth;
526 struct rte_flow_item_eth eth_mask;
528 memset(ð, 0, sizeof(eth));
529 memset(ð_mask, 0, sizeof(eth_mask));
530 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
531 memcpy(ð.src.addr_bytes, &conf->mac_addr,
532 sizeof(eth.src.addr_bytes));
533 memcpy(ð_mask.src.addr_bytes,
534 &rte_flow_item_eth_mask.src.addr_bytes,
535 sizeof(eth_mask.src.addr_bytes));
537 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
538 sizeof(eth.dst.addr_bytes));
539 memcpy(ð_mask.dst.addr_bytes,
540 &rte_flow_item_eth_mask.dst.addr_bytes,
541 sizeof(eth_mask.dst.addr_bytes));
544 item.mask = ð_mask;
545 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
546 MLX5_MODIFICATION_TYPE_SET, error);
550 * Convert modify-header set VLAN VID action to DV specification.
552 * @param[in,out] resource
553 * Pointer to the modify-header resource.
555 * Pointer to action specification.
557 * Pointer to the error structure.
560 * 0 on success, a negative errno value otherwise and rte_errno is set.
563 flow_dv_convert_action_modify_vlan_vid
564 (struct mlx5_flow_dv_modify_hdr_resource *resource,
565 const struct rte_flow_action *action,
566 struct rte_flow_error *error)
568 const struct rte_flow_action_of_set_vlan_vid *conf =
569 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
570 int i = resource->actions_num;
571 struct mlx5_modification_cmd *actions = &resource->actions[i];
572 struct field_modify_info *field = modify_vlan_out_first_vid;
574 if (i >= MLX5_MODIFY_NUM)
575 return rte_flow_error_set(error, EINVAL,
576 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
577 "too many items to modify");
578 actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
579 actions[i].field = field->id;
580 actions[i].length = field->size;
581 actions[i].offset = field->offset;
582 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
583 actions[i].data1 = conf->vlan_vid;
584 actions[i].data1 = actions[i].data1 << 16;
585 resource->actions_num = ++i;
590 * Convert modify-header set TP action to DV specification.
592 * @param[in,out] resource
593 * Pointer to the modify-header resource.
595 * Pointer to action specification.
597 * Pointer to rte_flow_item objects list.
599 * Pointer to flow attributes structure.
601 * Pointer to the error structure.
604 * 0 on success, a negative errno value otherwise and rte_errno is set.
607 flow_dv_convert_action_modify_tp
608 (struct mlx5_flow_dv_modify_hdr_resource *resource,
609 const struct rte_flow_action *action,
610 const struct rte_flow_item *items,
611 union flow_dv_attr *attr,
612 struct rte_flow_error *error)
614 const struct rte_flow_action_set_tp *conf =
615 (const struct rte_flow_action_set_tp *)(action->conf);
616 struct rte_flow_item item;
617 struct rte_flow_item_udp udp;
618 struct rte_flow_item_udp udp_mask;
619 struct rte_flow_item_tcp tcp;
620 struct rte_flow_item_tcp tcp_mask;
621 struct field_modify_info *field;
624 flow_dv_attr_init(items, attr);
626 memset(&udp, 0, sizeof(udp));
627 memset(&udp_mask, 0, sizeof(udp_mask));
628 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
629 udp.hdr.src_port = conf->port;
630 udp_mask.hdr.src_port =
631 rte_flow_item_udp_mask.hdr.src_port;
633 udp.hdr.dst_port = conf->port;
634 udp_mask.hdr.dst_port =
635 rte_flow_item_udp_mask.hdr.dst_port;
637 item.type = RTE_FLOW_ITEM_TYPE_UDP;
639 item.mask = &udp_mask;
643 memset(&tcp, 0, sizeof(tcp));
644 memset(&tcp_mask, 0, sizeof(tcp_mask));
645 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
646 tcp.hdr.src_port = conf->port;
647 tcp_mask.hdr.src_port =
648 rte_flow_item_tcp_mask.hdr.src_port;
650 tcp.hdr.dst_port = conf->port;
651 tcp_mask.hdr.dst_port =
652 rte_flow_item_tcp_mask.hdr.dst_port;
654 item.type = RTE_FLOW_ITEM_TYPE_TCP;
656 item.mask = &tcp_mask;
659 return flow_dv_convert_modify_action(&item, field, NULL, resource,
660 MLX5_MODIFICATION_TYPE_SET, error);
664 * Convert modify-header set TTL action to DV specification.
666 * @param[in,out] resource
667 * Pointer to the modify-header resource.
669 * Pointer to action specification.
671 * Pointer to rte_flow_item objects list.
673 * Pointer to flow attributes structure.
675 * Pointer to the error structure.
678 * 0 on success, a negative errno value otherwise and rte_errno is set.
681 flow_dv_convert_action_modify_ttl
682 (struct mlx5_flow_dv_modify_hdr_resource *resource,
683 const struct rte_flow_action *action,
684 const struct rte_flow_item *items,
685 union flow_dv_attr *attr,
686 struct rte_flow_error *error)
688 const struct rte_flow_action_set_ttl *conf =
689 (const struct rte_flow_action_set_ttl *)(action->conf);
690 struct rte_flow_item item;
691 struct rte_flow_item_ipv4 ipv4;
692 struct rte_flow_item_ipv4 ipv4_mask;
693 struct rte_flow_item_ipv6 ipv6;
694 struct rte_flow_item_ipv6 ipv6_mask;
695 struct field_modify_info *field;
698 flow_dv_attr_init(items, attr);
700 memset(&ipv4, 0, sizeof(ipv4));
701 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
702 ipv4.hdr.time_to_live = conf->ttl_value;
703 ipv4_mask.hdr.time_to_live = 0xFF;
704 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
706 item.mask = &ipv4_mask;
710 memset(&ipv6, 0, sizeof(ipv6));
711 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
712 ipv6.hdr.hop_limits = conf->ttl_value;
713 ipv6_mask.hdr.hop_limits = 0xFF;
714 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
716 item.mask = &ipv6_mask;
719 return flow_dv_convert_modify_action(&item, field, NULL, resource,
720 MLX5_MODIFICATION_TYPE_SET, error);
724 * Convert modify-header decrement TTL action to DV specification.
726 * @param[in,out] resource
727 * Pointer to the modify-header resource.
729 * Pointer to action specification.
731 * Pointer to rte_flow_item objects list.
733 * Pointer to flow attributes structure.
735 * Pointer to the error structure.
738 * 0 on success, a negative errno value otherwise and rte_errno is set.
741 flow_dv_convert_action_modify_dec_ttl
742 (struct mlx5_flow_dv_modify_hdr_resource *resource,
743 const struct rte_flow_item *items,
744 union flow_dv_attr *attr,
745 struct rte_flow_error *error)
747 struct rte_flow_item item;
748 struct rte_flow_item_ipv4 ipv4;
749 struct rte_flow_item_ipv4 ipv4_mask;
750 struct rte_flow_item_ipv6 ipv6;
751 struct rte_flow_item_ipv6 ipv6_mask;
752 struct field_modify_info *field;
755 flow_dv_attr_init(items, attr);
757 memset(&ipv4, 0, sizeof(ipv4));
758 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
759 ipv4.hdr.time_to_live = 0xFF;
760 ipv4_mask.hdr.time_to_live = 0xFF;
761 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
763 item.mask = &ipv4_mask;
767 memset(&ipv6, 0, sizeof(ipv6));
768 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
769 ipv6.hdr.hop_limits = 0xFF;
770 ipv6_mask.hdr.hop_limits = 0xFF;
771 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
773 item.mask = &ipv6_mask;
776 return flow_dv_convert_modify_action(&item, field, NULL, resource,
777 MLX5_MODIFICATION_TYPE_ADD, error);
781 * Convert modify-header increment/decrement TCP Sequence number
782 * to DV specification.
784 * @param[in,out] resource
785 * Pointer to the modify-header resource.
787 * Pointer to action specification.
789 * Pointer to the error structure.
792 * 0 on success, a negative errno value otherwise and rte_errno is set.
795 flow_dv_convert_action_modify_tcp_seq
796 (struct mlx5_flow_dv_modify_hdr_resource *resource,
797 const struct rte_flow_action *action,
798 struct rte_flow_error *error)
800 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
801 uint64_t value = rte_be_to_cpu_32(*conf);
802 struct rte_flow_item item;
803 struct rte_flow_item_tcp tcp;
804 struct rte_flow_item_tcp tcp_mask;
806 memset(&tcp, 0, sizeof(tcp));
807 memset(&tcp_mask, 0, sizeof(tcp_mask));
808 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
810 * The HW has no decrement operation, only increment operation.
811 * To simulate decrement X from Y using increment operation
812 * we need to add UINT32_MAX X times to Y.
813 * Each adding of UINT32_MAX decrements Y by 1.
816 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
817 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
818 item.type = RTE_FLOW_ITEM_TYPE_TCP;
820 item.mask = &tcp_mask;
821 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
822 MLX5_MODIFICATION_TYPE_ADD, error);
826 * Convert modify-header increment/decrement TCP Acknowledgment number
827 * to DV specification.
829 * @param[in,out] resource
830 * Pointer to the modify-header resource.
832 * Pointer to action specification.
834 * Pointer to the error structure.
837 * 0 on success, a negative errno value otherwise and rte_errno is set.
840 flow_dv_convert_action_modify_tcp_ack
841 (struct mlx5_flow_dv_modify_hdr_resource *resource,
842 const struct rte_flow_action *action,
843 struct rte_flow_error *error)
845 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
846 uint64_t value = rte_be_to_cpu_32(*conf);
847 struct rte_flow_item item;
848 struct rte_flow_item_tcp tcp;
849 struct rte_flow_item_tcp tcp_mask;
851 memset(&tcp, 0, sizeof(tcp));
852 memset(&tcp_mask, 0, sizeof(tcp_mask));
853 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
855 * The HW has no decrement operation, only increment operation.
856 * To simulate decrement X from Y using increment operation
857 * we need to add UINT32_MAX X times to Y.
858 * Each adding of UINT32_MAX decrements Y by 1.
861 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
862 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
863 item.type = RTE_FLOW_ITEM_TYPE_TCP;
865 item.mask = &tcp_mask;
866 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
867 MLX5_MODIFICATION_TYPE_ADD, error);
870 static enum mlx5_modification_field reg_to_field[] = {
871 [REG_NONE] = MLX5_MODI_OUT_NONE,
872 [REG_A] = MLX5_MODI_META_DATA_REG_A,
873 [REG_B] = MLX5_MODI_META_DATA_REG_B,
874 [REG_C_0] = MLX5_MODI_META_REG_C_0,
875 [REG_C_1] = MLX5_MODI_META_REG_C_1,
876 [REG_C_2] = MLX5_MODI_META_REG_C_2,
877 [REG_C_3] = MLX5_MODI_META_REG_C_3,
878 [REG_C_4] = MLX5_MODI_META_REG_C_4,
879 [REG_C_5] = MLX5_MODI_META_REG_C_5,
880 [REG_C_6] = MLX5_MODI_META_REG_C_6,
881 [REG_C_7] = MLX5_MODI_META_REG_C_7,
885 * Convert register set to DV specification.
887 * @param[in,out] resource
888 * Pointer to the modify-header resource.
890 * Pointer to action specification.
892 * Pointer to the error structure.
895 * 0 on success, a negative errno value otherwise and rte_errno is set.
898 flow_dv_convert_action_set_reg
899 (struct mlx5_flow_dv_modify_hdr_resource *resource,
900 const struct rte_flow_action *action,
901 struct rte_flow_error *error)
903 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
904 struct mlx5_modification_cmd *actions = resource->actions;
905 uint32_t i = resource->actions_num;
907 if (i >= MLX5_MODIFY_NUM)
908 return rte_flow_error_set(error, EINVAL,
909 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
910 "too many items to modify");
911 assert(conf->id != REG_NONE);
912 assert(conf->id < RTE_DIM(reg_to_field));
913 actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
914 actions[i].field = reg_to_field[conf->id];
915 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
916 actions[i].data1 = rte_cpu_to_be_32(conf->data);
918 resource->actions_num = i;
919 if (!resource->actions_num)
920 return rte_flow_error_set(error, EINVAL,
921 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
922 "invalid modification flow item");
927 * Convert SET_TAG action to DV specification.
930 * Pointer to the rte_eth_dev structure.
931 * @param[in,out] resource
932 * Pointer to the modify-header resource.
934 * Pointer to action specification.
936 * Pointer to the error structure.
939 * 0 on success, a negative errno value otherwise and rte_errno is set.
942 flow_dv_convert_action_set_tag
943 (struct rte_eth_dev *dev,
944 struct mlx5_flow_dv_modify_hdr_resource *resource,
945 const struct rte_flow_action_set_tag *conf,
946 struct rte_flow_error *error)
948 rte_be32_t data = rte_cpu_to_be_32(conf->data);
949 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
950 struct rte_flow_item item = {
954 struct field_modify_info reg_c_x[] = {
957 enum mlx5_modification_field reg_type;
960 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
963 assert(ret != REG_NONE);
964 assert((unsigned int)ret < RTE_DIM(reg_to_field));
965 reg_type = reg_to_field[ret];
966 assert(reg_type > 0);
967 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
968 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
969 MLX5_MODIFICATION_TYPE_SET, error);
973 * Convert internal COPY_REG action to DV specification.
976 * Pointer to the rte_eth_dev structure.
978 * Pointer to the modify-header resource.
980 * Pointer to action specification.
982 * Pointer to the error structure.
985 * 0 on success, a negative errno value otherwise and rte_errno is set.
988 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
989 struct mlx5_flow_dv_modify_hdr_resource *res,
990 const struct rte_flow_action *action,
991 struct rte_flow_error *error)
993 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
994 rte_be32_t mask = RTE_BE32(UINT32_MAX);
995 struct rte_flow_item item = {
999 struct field_modify_info reg_src[] = {
1000 {4, 0, reg_to_field[conf->src]},
1003 struct field_modify_info reg_dst = {
1005 .id = reg_to_field[conf->dst],
1007 /* Adjust reg_c[0] usage according to reported mask. */
1008 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1009 struct mlx5_priv *priv = dev->data->dev_private;
1010 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1013 assert(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1014 if (conf->dst == REG_C_0) {
1015 /* Copy to reg_c[0], within mask only. */
1016 reg_dst.offset = rte_bsf32(reg_c0);
1018 * Mask is ignoring the enianness, because
1019 * there is no conversion in datapath.
1021 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1022 /* Copy from destination lower bits to reg_c[0]. */
1023 mask = reg_c0 >> reg_dst.offset;
1025 /* Copy from destination upper bits to reg_c[0]. */
1026 mask = reg_c0 << (sizeof(reg_c0) * CHAR_BIT -
1027 rte_fls_u32(reg_c0));
1030 mask = rte_cpu_to_be_32(reg_c0);
1031 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1032 /* Copy from reg_c[0] to destination lower bits. */
1035 /* Copy from reg_c[0] to destination upper bits. */
1036 reg_dst.offset = sizeof(reg_c0) * CHAR_BIT -
1037 (rte_fls_u32(reg_c0) -
1042 return flow_dv_convert_modify_action(&item,
1043 reg_src, ®_dst, res,
1044 MLX5_MODIFICATION_TYPE_COPY,
1049 * Convert MARK action to DV specification. This routine is used
1050 * in extensive metadata only and requires metadata register to be
1051 * handled. In legacy mode hardware tag resource is engaged.
1054 * Pointer to the rte_eth_dev structure.
1056 * Pointer to MARK action specification.
1057 * @param[in,out] resource
1058 * Pointer to the modify-header resource.
1060 * Pointer to the error structure.
1063 * 0 on success, a negative errno value otherwise and rte_errno is set.
1066 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1067 const struct rte_flow_action_mark *conf,
1068 struct mlx5_flow_dv_modify_hdr_resource *resource,
1069 struct rte_flow_error *error)
1071 struct mlx5_priv *priv = dev->data->dev_private;
1072 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1073 priv->sh->dv_mark_mask);
1074 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1075 struct rte_flow_item item = {
1079 struct field_modify_info reg_c_x[] = {
1080 {4, 0, 0}, /* dynamic instead of MLX5_MODI_META_REG_C_1. */
1083 enum modify_reg reg;
1086 return rte_flow_error_set(error, EINVAL,
1087 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1088 NULL, "zero mark action mask");
1089 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1093 reg_c_x[0].id = reg_to_field[reg];
1094 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1095 MLX5_MODIFICATION_TYPE_SET, error);
1099 * Get metadata register index for specified steering domain.
1102 * Pointer to the rte_eth_dev structure.
1104 * Attributes of flow to determine steering domain.
1106 * Pointer to the error structure.
1109 * positive index on success, a negative errno value otherwise
1110 * and rte_errno is set.
1112 static enum modify_reg
1113 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1114 const struct rte_flow_attr *attr,
1115 struct rte_flow_error *error)
1117 enum modify_reg reg =
1118 mlx5_flow_get_reg_id(dev, attr->transfer ?
1122 MLX5_METADATA_RX, 0, error);
1124 return rte_flow_error_set(error,
1125 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1126 NULL, "unavailable "
1127 "metadata register");
1132 * Convert SET_META action to DV specification.
1135 * Pointer to the rte_eth_dev structure.
1136 * @param[in,out] resource
1137 * Pointer to the modify-header resource.
1139 * Attributes of flow that includes this item.
1141 * Pointer to action specification.
1143 * Pointer to the error structure.
1146 * 0 on success, a negative errno value otherwise and rte_errno is set.
1149 flow_dv_convert_action_set_meta
1150 (struct rte_eth_dev *dev,
1151 struct mlx5_flow_dv_modify_hdr_resource *resource,
1152 const struct rte_flow_attr *attr,
1153 const struct rte_flow_action_set_meta *conf,
1154 struct rte_flow_error *error)
1156 uint32_t data = conf->data;
1157 uint32_t mask = conf->mask;
1158 struct rte_flow_item item = {
1162 struct field_modify_info reg_c_x[] = {
1165 enum modify_reg reg = flow_dv_get_metadata_reg(dev, attr, error);
1170 * In datapath code there is no endianness
1171 * coversions for perfromance reasons, all
1172 * pattern conversions are done in rte_flow.
1174 if (reg == REG_C_0) {
1175 struct mlx5_priv *priv = dev->data->dev_private;
1176 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1180 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1181 shl_c0 = rte_bsf32(msk_c0);
1183 shl_c0 = sizeof(msk_c0) * CHAR_BIT - rte_fls_u32(msk_c0);
1187 assert(!(~msk_c0 & rte_cpu_to_be_32(mask)));
1189 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1190 /* The routine expects parameters in memory as big-endian ones. */
1191 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1192 MLX5_MODIFICATION_TYPE_SET, error);
1196 * Convert modify-header set IPv4 DSCP action to DV specification.
1198 * @param[in,out] resource
1199 * Pointer to the modify-header resource.
1201 * Pointer to action specification.
1203 * Pointer to the error structure.
1206 * 0 on success, a negative errno value otherwise and rte_errno is set.
1209 flow_dv_convert_action_modify_ipv4_dscp
1210 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1211 const struct rte_flow_action *action,
1212 struct rte_flow_error *error)
1214 const struct rte_flow_action_set_dscp *conf =
1215 (const struct rte_flow_action_set_dscp *)(action->conf);
1216 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1217 struct rte_flow_item_ipv4 ipv4;
1218 struct rte_flow_item_ipv4 ipv4_mask;
1220 memset(&ipv4, 0, sizeof(ipv4));
1221 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1222 ipv4.hdr.type_of_service = conf->dscp;
1223 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1225 item.mask = &ipv4_mask;
1226 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1227 MLX5_MODIFICATION_TYPE_SET, error);
1231 * Convert modify-header set IPv6 DSCP action to DV specification.
1233 * @param[in,out] resource
1234 * Pointer to the modify-header resource.
1236 * Pointer to action specification.
1238 * Pointer to the error structure.
1241 * 0 on success, a negative errno value otherwise and rte_errno is set.
1244 flow_dv_convert_action_modify_ipv6_dscp
1245 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1246 const struct rte_flow_action *action,
1247 struct rte_flow_error *error)
1249 const struct rte_flow_action_set_dscp *conf =
1250 (const struct rte_flow_action_set_dscp *)(action->conf);
1251 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1252 struct rte_flow_item_ipv6 ipv6;
1253 struct rte_flow_item_ipv6 ipv6_mask;
1255 memset(&ipv6, 0, sizeof(ipv6));
1256 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1258 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1259 * rdma-core only accept the DSCP bits byte aligned start from
1260 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1261 * bits in IPv6 case as rdma-core requires byte aligned value.
1263 ipv6.hdr.vtc_flow = conf->dscp;
1264 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1266 item.mask = &ipv6_mask;
1267 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1268 MLX5_MODIFICATION_TYPE_SET, error);
1272 * Validate MARK item.
1275 * Pointer to the rte_eth_dev structure.
1277 * Item specification.
1279 * Attributes of flow that includes this item.
1281 * Pointer to error structure.
1284 * 0 on success, a negative errno value otherwise and rte_errno is set.
1287 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1288 const struct rte_flow_item *item,
1289 const struct rte_flow_attr *attr __rte_unused,
1290 struct rte_flow_error *error)
1292 struct mlx5_priv *priv = dev->data->dev_private;
1293 struct mlx5_dev_config *config = &priv->config;
1294 const struct rte_flow_item_mark *spec = item->spec;
1295 const struct rte_flow_item_mark *mask = item->mask;
1296 const struct rte_flow_item_mark nic_mask = {
1297 .id = priv->sh->dv_mark_mask,
1301 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1302 return rte_flow_error_set(error, ENOTSUP,
1303 RTE_FLOW_ERROR_TYPE_ITEM, item,
1304 "extended metadata feature"
1306 if (!mlx5_flow_ext_mreg_supported(dev))
1307 return rte_flow_error_set(error, ENOTSUP,
1308 RTE_FLOW_ERROR_TYPE_ITEM, item,
1309 "extended metadata register"
1310 " isn't supported");
1312 return rte_flow_error_set(error, ENOTSUP,
1313 RTE_FLOW_ERROR_TYPE_ITEM, item,
1314 "extended metadata register"
1315 " isn't available");
1316 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1320 return rte_flow_error_set(error, EINVAL,
1321 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1323 "data cannot be empty");
1324 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1325 return rte_flow_error_set(error, EINVAL,
1326 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1328 "mark id exceeds the limit");
1331 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1332 (const uint8_t *)&nic_mask,
1333 sizeof(struct rte_flow_item_mark),
1341 * Validate META item.
1344 * Pointer to the rte_eth_dev structure.
1346 * Item specification.
1348 * Attributes of flow that includes this item.
1350 * Pointer to error structure.
1353 * 0 on success, a negative errno value otherwise and rte_errno is set.
1356 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1357 const struct rte_flow_item *item,
1358 const struct rte_flow_attr *attr,
1359 struct rte_flow_error *error)
1361 struct mlx5_priv *priv = dev->data->dev_private;
1362 struct mlx5_dev_config *config = &priv->config;
1363 const struct rte_flow_item_meta *spec = item->spec;
1364 const struct rte_flow_item_meta *mask = item->mask;
1365 struct rte_flow_item_meta nic_mask = {
1368 enum modify_reg reg;
1372 return rte_flow_error_set(error, EINVAL,
1373 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1375 "data cannot be empty");
1377 return rte_flow_error_set(error, EINVAL,
1378 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1379 "data cannot be zero");
1380 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1381 if (!mlx5_flow_ext_mreg_supported(dev))
1382 return rte_flow_error_set(error, ENOTSUP,
1383 RTE_FLOW_ERROR_TYPE_ITEM, item,
1384 "extended metadata register"
1385 " isn't supported");
1386 reg = flow_dv_get_metadata_reg(dev, attr, error);
1390 return rte_flow_error_set(error, ENOTSUP,
1391 RTE_FLOW_ERROR_TYPE_ITEM, item,
1395 nic_mask.data = priv->sh->dv_meta_mask;
1398 mask = &rte_flow_item_meta_mask;
1399 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1400 (const uint8_t *)&nic_mask,
1401 sizeof(struct rte_flow_item_meta),
1407 * Validate TAG item.
1410 * Pointer to the rte_eth_dev structure.
1412 * Item specification.
1414 * Attributes of flow that includes this item.
1416 * Pointer to error structure.
1419 * 0 on success, a negative errno value otherwise and rte_errno is set.
1422 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
1423 const struct rte_flow_item *item,
1424 const struct rte_flow_attr *attr __rte_unused,
1425 struct rte_flow_error *error)
1427 const struct rte_flow_item_tag *spec = item->spec;
1428 const struct rte_flow_item_tag *mask = item->mask;
1429 const struct rte_flow_item_tag nic_mask = {
1430 .data = RTE_BE32(UINT32_MAX),
1435 if (!mlx5_flow_ext_mreg_supported(dev))
1436 return rte_flow_error_set(error, ENOTSUP,
1437 RTE_FLOW_ERROR_TYPE_ITEM, item,
1438 "extensive metadata register"
1439 " isn't supported");
1441 return rte_flow_error_set(error, EINVAL,
1442 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1444 "data cannot be empty");
1446 mask = &rte_flow_item_tag_mask;
1447 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1448 (const uint8_t *)&nic_mask,
1449 sizeof(struct rte_flow_item_tag),
1453 if (mask->index != 0xff)
1454 return rte_flow_error_set(error, EINVAL,
1455 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1456 "partial mask for tag index"
1457 " is not supported");
1458 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
1461 assert(ret != REG_NONE);
1466 * Validate vport item.
1469 * Pointer to the rte_eth_dev structure.
1471 * Item specification.
1473 * Attributes of flow that includes this item.
1474 * @param[in] item_flags
1475 * Bit-fields that holds the items detected until now.
1477 * Pointer to error structure.
1480 * 0 on success, a negative errno value otherwise and rte_errno is set.
1483 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
1484 const struct rte_flow_item *item,
1485 const struct rte_flow_attr *attr,
1486 uint64_t item_flags,
1487 struct rte_flow_error *error)
1489 const struct rte_flow_item_port_id *spec = item->spec;
1490 const struct rte_flow_item_port_id *mask = item->mask;
1491 const struct rte_flow_item_port_id switch_mask = {
1494 struct mlx5_priv *esw_priv;
1495 struct mlx5_priv *dev_priv;
1498 if (!attr->transfer)
1499 return rte_flow_error_set(error, EINVAL,
1500 RTE_FLOW_ERROR_TYPE_ITEM,
1502 "match on port id is valid only"
1503 " when transfer flag is enabled");
1504 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
1505 return rte_flow_error_set(error, ENOTSUP,
1506 RTE_FLOW_ERROR_TYPE_ITEM, item,
1507 "multiple source ports are not"
1510 mask = &switch_mask;
1511 if (mask->id != 0xffffffff)
1512 return rte_flow_error_set(error, ENOTSUP,
1513 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
1515 "no support for partial mask on"
1517 ret = mlx5_flow_item_acceptable
1518 (item, (const uint8_t *)mask,
1519 (const uint8_t *)&rte_flow_item_port_id_mask,
1520 sizeof(struct rte_flow_item_port_id),
1526 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
1528 return rte_flow_error_set(error, rte_errno,
1529 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1530 "failed to obtain E-Switch info for"
1532 dev_priv = mlx5_dev_to_eswitch_info(dev);
1534 return rte_flow_error_set(error, rte_errno,
1535 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1537 "failed to obtain E-Switch info");
1538 if (esw_priv->domain_id != dev_priv->domain_id)
1539 return rte_flow_error_set(error, EINVAL,
1540 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1541 "cannot match on a port from a"
1542 " different E-Switch");
1547 * Validate the pop VLAN action.
1550 * Pointer to the rte_eth_dev structure.
1551 * @param[in] action_flags
1552 * Holds the actions detected until now.
1554 * Pointer to the pop vlan action.
1555 * @param[in] item_flags
1556 * The items found in this flow rule.
1558 * Pointer to flow attributes.
1560 * Pointer to error structure.
1563 * 0 on success, a negative errno value otherwise and rte_errno is set.
1566 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
1567 uint64_t action_flags,
1568 const struct rte_flow_action *action,
1569 uint64_t item_flags,
1570 const struct rte_flow_attr *attr,
1571 struct rte_flow_error *error)
1573 struct mlx5_priv *priv = dev->data->dev_private;
1577 if (!priv->sh->pop_vlan_action)
1578 return rte_flow_error_set(error, ENOTSUP,
1579 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1581 "pop vlan action is not supported");
1583 * Check for inconsistencies:
1584 * fail strip_vlan in a flow that matches packets without VLAN tags.
1585 * fail strip_vlan in a flow that matches packets without explicitly a
1586 * matching on VLAN tag ?
1588 if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN)
1589 return rte_flow_error_set(error, ENOTSUP,
1590 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1592 "no support for multiple vlan pop "
1594 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1595 return rte_flow_error_set(error, ENOTSUP,
1596 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1598 "cannot pop vlan without a "
1599 "match on (outer) vlan in the flow");
1600 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1601 return rte_flow_error_set(error, EINVAL,
1602 RTE_FLOW_ERROR_TYPE_ACTION, action,
1603 "wrong action order, port_id should "
1604 "be after pop VLAN action");
1609 * Get VLAN default info from vlan match info.
1612 * Pointer to the rte_eth_dev structure.
1614 * the list of item specifications.
1616 * pointer VLAN info to fill to.
1618 * Pointer to error structure.
1621 * 0 on success, a negative errno value otherwise and rte_errno is set.
1624 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
1625 struct rte_vlan_hdr *vlan)
1627 const struct rte_flow_item_vlan nic_mask = {
1628 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
1629 MLX5DV_FLOW_VLAN_VID_MASK),
1630 .inner_type = RTE_BE16(0xffff),
1635 for (; items->type != RTE_FLOW_ITEM_TYPE_END &&
1636 items->type != RTE_FLOW_ITEM_TYPE_VLAN; items++)
1638 if (items->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1639 const struct rte_flow_item_vlan *vlan_m = items->mask;
1640 const struct rte_flow_item_vlan *vlan_v = items->spec;
1644 /* Only full match values are accepted */
1645 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
1646 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
1647 vlan->vlan_tci &= MLX5DV_FLOW_VLAN_PCP_MASK;
1649 rte_be_to_cpu_16(vlan_v->tci &
1650 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
1652 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
1653 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
1654 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
1656 rte_be_to_cpu_16(vlan_v->tci &
1657 MLX5DV_FLOW_VLAN_VID_MASK_BE);
1659 if (vlan_m->inner_type == nic_mask.inner_type)
1660 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
1661 vlan_m->inner_type);
1666 * Validate the push VLAN action.
1668 * @param[in] action_flags
1669 * Holds the actions detected until now.
1671 * Pointer to the encap action.
1673 * Pointer to flow attributes
1675 * Pointer to error structure.
1678 * 0 on success, a negative errno value otherwise and rte_errno is set.
1681 flow_dv_validate_action_push_vlan(uint64_t action_flags,
1682 uint64_t item_flags,
1683 const struct rte_flow_action *action,
1684 const struct rte_flow_attr *attr,
1685 struct rte_flow_error *error)
1687 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
1689 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
1690 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
1691 return rte_flow_error_set(error, EINVAL,
1692 RTE_FLOW_ERROR_TYPE_ACTION, action,
1693 "invalid vlan ethertype");
1695 (MLX5_FLOW_ACTION_OF_POP_VLAN | MLX5_FLOW_ACTION_OF_PUSH_VLAN))
1696 return rte_flow_error_set(error, ENOTSUP,
1697 RTE_FLOW_ERROR_TYPE_ACTION, action,
1698 "no support for multiple VLAN "
1700 if (!mlx5_flow_find_action
1701 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) &&
1702 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1703 return rte_flow_error_set(error, ENOTSUP,
1704 RTE_FLOW_ERROR_TYPE_ACTION, action,
1705 "push VLAN needs to match on VLAN in order to "
1706 "get VLAN VID information because there is "
1707 "no followed set VLAN VID action");
1708 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1709 return rte_flow_error_set(error, EINVAL,
1710 RTE_FLOW_ERROR_TYPE_ACTION, action,
1711 "wrong action order, port_id should "
1712 "be after push VLAN");
1718 * Validate the set VLAN PCP.
1720 * @param[in] action_flags
1721 * Holds the actions detected until now.
1722 * @param[in] actions
1723 * Pointer to the list of actions remaining in the flow rule.
1725 * Pointer to flow attributes
1727 * Pointer to error structure.
1730 * 0 on success, a negative errno value otherwise and rte_errno is set.
1733 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
1734 const struct rte_flow_action actions[],
1735 struct rte_flow_error *error)
1737 const struct rte_flow_action *action = actions;
1738 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
1740 if (conf->vlan_pcp > 7)
1741 return rte_flow_error_set(error, EINVAL,
1742 RTE_FLOW_ERROR_TYPE_ACTION, action,
1743 "VLAN PCP value is too big");
1744 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
1745 return rte_flow_error_set(error, ENOTSUP,
1746 RTE_FLOW_ERROR_TYPE_ACTION, action,
1747 "set VLAN PCP action must follow "
1748 "the push VLAN action");
1749 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
1750 return rte_flow_error_set(error, ENOTSUP,
1751 RTE_FLOW_ERROR_TYPE_ACTION, action,
1752 "Multiple VLAN PCP modification are "
1754 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1755 return rte_flow_error_set(error, EINVAL,
1756 RTE_FLOW_ERROR_TYPE_ACTION, action,
1757 "wrong action order, port_id should "
1758 "be after set VLAN PCP");
1763 * Validate the set VLAN VID.
1765 * @param[in] item_flags
1766 * Holds the items detected in this rule.
1767 * @param[in] actions
1768 * Pointer to the list of actions remaining in the flow rule.
1770 * Pointer to flow attributes
1772 * Pointer to error structure.
1775 * 0 on success, a negative errno value otherwise and rte_errno is set.
1778 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
1779 uint64_t action_flags,
1780 const struct rte_flow_action actions[],
1781 struct rte_flow_error *error)
1783 const struct rte_flow_action *action = actions;
1784 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
1786 if (conf->vlan_vid > RTE_BE16(0xFFE))
1787 return rte_flow_error_set(error, EINVAL,
1788 RTE_FLOW_ERROR_TYPE_ACTION, action,
1789 "VLAN VID value is too big");
1790 /* there is an of_push_vlan action before us */
1791 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
1792 if (mlx5_flow_find_action(actions + 1,
1793 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID))
1794 return rte_flow_error_set(error, ENOTSUP,
1795 RTE_FLOW_ERROR_TYPE_ACTION, action,
1796 "Multiple VLAN VID modifications are "
1803 * Action is on an existing VLAN header:
1804 * Need to verify this is a single modify CID action.
1805 * Rule mast include a match on outer VLAN.
1807 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
1808 return rte_flow_error_set(error, ENOTSUP,
1809 RTE_FLOW_ERROR_TYPE_ACTION, action,
1810 "Multiple VLAN VID modifications are "
1812 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1813 return rte_flow_error_set(error, EINVAL,
1814 RTE_FLOW_ERROR_TYPE_ACTION, action,
1815 "match on VLAN is required in order "
1817 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1818 return rte_flow_error_set(error, EINVAL,
1819 RTE_FLOW_ERROR_TYPE_ACTION, action,
1820 "wrong action order, port_id should "
1821 "be after set VLAN VID");
1826 * Validate the FLAG action.
1829 * Pointer to the rte_eth_dev structure.
1830 * @param[in] action_flags
1831 * Holds the actions detected until now.
1833 * Pointer to flow attributes
1835 * Pointer to error structure.
1838 * 0 on success, a negative errno value otherwise and rte_errno is set.
1841 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
1842 uint64_t action_flags,
1843 const struct rte_flow_attr *attr,
1844 struct rte_flow_error *error)
1846 struct mlx5_priv *priv = dev->data->dev_private;
1847 struct mlx5_dev_config *config = &priv->config;
1850 /* Fall back if no extended metadata register support. */
1851 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1852 return mlx5_flow_validate_action_flag(action_flags, attr,
1854 /* Extensive metadata mode requires registers. */
1855 if (!mlx5_flow_ext_mreg_supported(dev))
1856 return rte_flow_error_set(error, ENOTSUP,
1857 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1858 "no metadata registers "
1859 "to support flag action");
1860 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
1861 return rte_flow_error_set(error, ENOTSUP,
1862 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1863 "extended metadata register"
1864 " isn't available");
1865 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1869 if (action_flags & MLX5_FLOW_ACTION_DROP)
1870 return rte_flow_error_set(error, EINVAL,
1871 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1872 "can't drop and flag in same flow");
1873 if (action_flags & MLX5_FLOW_ACTION_MARK)
1874 return rte_flow_error_set(error, EINVAL,
1875 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1876 "can't mark and flag in same flow");
1877 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1878 return rte_flow_error_set(error, EINVAL,
1879 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1881 " actions in same flow");
1886 * Validate MARK action.
1889 * Pointer to the rte_eth_dev structure.
1891 * Pointer to action.
1892 * @param[in] action_flags
1893 * Holds the actions detected until now.
1895 * Pointer to flow attributes
1897 * Pointer to error structure.
1900 * 0 on success, a negative errno value otherwise and rte_errno is set.
1903 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
1904 const struct rte_flow_action *action,
1905 uint64_t action_flags,
1906 const struct rte_flow_attr *attr,
1907 struct rte_flow_error *error)
1909 struct mlx5_priv *priv = dev->data->dev_private;
1910 struct mlx5_dev_config *config = &priv->config;
1911 const struct rte_flow_action_mark *mark = action->conf;
1914 /* Fall back if no extended metadata register support. */
1915 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1916 return mlx5_flow_validate_action_mark(action, action_flags,
1918 /* Extensive metadata mode requires registers. */
1919 if (!mlx5_flow_ext_mreg_supported(dev))
1920 return rte_flow_error_set(error, ENOTSUP,
1921 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1922 "no metadata registers "
1923 "to support mark action");
1924 if (!priv->sh->dv_mark_mask)
1925 return rte_flow_error_set(error, ENOTSUP,
1926 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1927 "extended metadata register"
1928 " isn't available");
1929 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1934 return rte_flow_error_set(error, EINVAL,
1935 RTE_FLOW_ERROR_TYPE_ACTION, action,
1936 "configuration cannot be null");
1937 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
1938 return rte_flow_error_set(error, EINVAL,
1939 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1941 "mark id exceeds the limit");
1942 if (action_flags & MLX5_FLOW_ACTION_DROP)
1943 return rte_flow_error_set(error, EINVAL,
1944 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1945 "can't drop and mark in same flow");
1946 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1947 return rte_flow_error_set(error, EINVAL,
1948 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1949 "can't flag and mark in same flow");
1950 if (action_flags & MLX5_FLOW_ACTION_MARK)
1951 return rte_flow_error_set(error, EINVAL,
1952 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1953 "can't have 2 mark actions in same"
1959 * Validate SET_META action.
1962 * Pointer to the rte_eth_dev structure.
1964 * Pointer to the encap action.
1965 * @param[in] action_flags
1966 * Holds the actions detected until now.
1968 * Pointer to flow attributes
1970 * Pointer to error structure.
1973 * 0 on success, a negative errno value otherwise and rte_errno is set.
1976 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
1977 const struct rte_flow_action *action,
1978 uint64_t action_flags __rte_unused,
1979 const struct rte_flow_attr *attr,
1980 struct rte_flow_error *error)
1982 const struct rte_flow_action_set_meta *conf;
1983 uint32_t nic_mask = UINT32_MAX;
1984 enum modify_reg reg;
1986 if (!mlx5_flow_ext_mreg_supported(dev))
1987 return rte_flow_error_set(error, ENOTSUP,
1988 RTE_FLOW_ERROR_TYPE_ACTION, action,
1989 "extended metadata register"
1990 " isn't supported");
1991 reg = flow_dv_get_metadata_reg(dev, attr, error);
1994 if (reg != REG_A && reg != REG_B) {
1995 struct mlx5_priv *priv = dev->data->dev_private;
1997 nic_mask = priv->sh->dv_meta_mask;
1999 if (!(action->conf))
2000 return rte_flow_error_set(error, EINVAL,
2001 RTE_FLOW_ERROR_TYPE_ACTION, action,
2002 "configuration cannot be null");
2003 conf = (const struct rte_flow_action_set_meta *)action->conf;
2005 return rte_flow_error_set(error, EINVAL,
2006 RTE_FLOW_ERROR_TYPE_ACTION, action,
2007 "zero mask doesn't have any effect");
2008 if (conf->mask & ~nic_mask)
2009 return rte_flow_error_set(error, EINVAL,
2010 RTE_FLOW_ERROR_TYPE_ACTION, action,
2011 "meta data must be within reg C0");
2012 if (!(conf->data & conf->mask))
2013 return rte_flow_error_set(error, EINVAL,
2014 RTE_FLOW_ERROR_TYPE_ACTION, action,
2015 "zero value has no effect");
2020 * Validate SET_TAG action.
2023 * Pointer to the rte_eth_dev structure.
2025 * Pointer to the encap action.
2026 * @param[in] action_flags
2027 * Holds the actions detected until now.
2029 * Pointer to flow attributes
2031 * Pointer to error structure.
2034 * 0 on success, a negative errno value otherwise and rte_errno is set.
2037 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
2038 const struct rte_flow_action *action,
2039 uint64_t action_flags,
2040 const struct rte_flow_attr *attr,
2041 struct rte_flow_error *error)
2043 const struct rte_flow_action_set_tag *conf;
2044 const uint64_t terminal_action_flags =
2045 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
2046 MLX5_FLOW_ACTION_RSS;
2049 if (!mlx5_flow_ext_mreg_supported(dev))
2050 return rte_flow_error_set(error, ENOTSUP,
2051 RTE_FLOW_ERROR_TYPE_ACTION, action,
2052 "extensive metadata register"
2053 " isn't supported");
2054 if (!(action->conf))
2055 return rte_flow_error_set(error, EINVAL,
2056 RTE_FLOW_ERROR_TYPE_ACTION, action,
2057 "configuration cannot be null");
2058 conf = (const struct rte_flow_action_set_tag *)action->conf;
2060 return rte_flow_error_set(error, EINVAL,
2061 RTE_FLOW_ERROR_TYPE_ACTION, action,
2062 "zero mask doesn't have any effect");
2063 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
2066 if (!attr->transfer && attr->ingress &&
2067 (action_flags & terminal_action_flags))
2068 return rte_flow_error_set(error, EINVAL,
2069 RTE_FLOW_ERROR_TYPE_ACTION, action,
2070 "set_tag has no effect"
2071 " with terminal actions");
2076 * Validate count action.
2081 * Pointer to error structure.
2084 * 0 on success, a negative errno value otherwise and rte_errno is set.
2087 flow_dv_validate_action_count(struct rte_eth_dev *dev,
2088 struct rte_flow_error *error)
2090 struct mlx5_priv *priv = dev->data->dev_private;
2092 if (!priv->config.devx)
2094 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
2098 return rte_flow_error_set
2100 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2102 "count action not supported");
2106 * Validate the L2 encap action.
2108 * @param[in] action_flags
2109 * Holds the actions detected until now.
2111 * Pointer to the encap action.
2113 * Pointer to flow attributes
2115 * Pointer to error structure.
2118 * 0 on success, a negative errno value otherwise and rte_errno is set.
2121 flow_dv_validate_action_l2_encap(uint64_t action_flags,
2122 const struct rte_flow_action *action,
2123 const struct rte_flow_attr *attr,
2124 struct rte_flow_error *error)
2126 if (!(action->conf))
2127 return rte_flow_error_set(error, EINVAL,
2128 RTE_FLOW_ERROR_TYPE_ACTION, action,
2129 "configuration cannot be null");
2130 if (action_flags & MLX5_FLOW_ACTION_DROP)
2131 return rte_flow_error_set(error, EINVAL,
2132 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2133 "can't drop and encap in same flow");
2134 if (action_flags & (MLX5_FLOW_ENCAP_ACTIONS | MLX5_FLOW_DECAP_ACTIONS))
2135 return rte_flow_error_set(error, EINVAL,
2136 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2137 "can only have a single encap or"
2138 " decap action in a flow");
2139 if (!attr->transfer && attr->ingress)
2140 return rte_flow_error_set(error, ENOTSUP,
2141 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2143 "encap action not supported for "
2149 * Validate the L2 decap action.
2151 * @param[in] action_flags
2152 * Holds the actions detected until now.
2154 * Pointer to flow attributes
2156 * Pointer to error structure.
2159 * 0 on success, a negative errno value otherwise and rte_errno is set.
2162 flow_dv_validate_action_l2_decap(uint64_t action_flags,
2163 const struct rte_flow_attr *attr,
2164 struct rte_flow_error *error)
2166 if (action_flags & MLX5_FLOW_ACTION_DROP)
2167 return rte_flow_error_set(error, EINVAL,
2168 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2169 "can't drop and decap in same flow");
2170 if (action_flags & (MLX5_FLOW_ENCAP_ACTIONS | MLX5_FLOW_DECAP_ACTIONS))
2171 return rte_flow_error_set(error, EINVAL,
2172 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2173 "can only have a single encap or"
2174 " decap action in a flow");
2175 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
2176 return rte_flow_error_set(error, EINVAL,
2177 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2178 "can't have decap action after"
2181 return rte_flow_error_set(error, ENOTSUP,
2182 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2184 "decap action not supported for "
2190 * Validate the raw encap action.
2192 * @param[in] action_flags
2193 * Holds the actions detected until now.
2195 * Pointer to the encap action.
2197 * Pointer to flow attributes
2199 * Pointer to error structure.
2202 * 0 on success, a negative errno value otherwise and rte_errno is set.
2205 flow_dv_validate_action_raw_encap(uint64_t action_flags,
2206 const struct rte_flow_action *action,
2207 const struct rte_flow_attr *attr,
2208 struct rte_flow_error *error)
2210 const struct rte_flow_action_raw_encap *raw_encap =
2211 (const struct rte_flow_action_raw_encap *)action->conf;
2212 if (!(action->conf))
2213 return rte_flow_error_set(error, EINVAL,
2214 RTE_FLOW_ERROR_TYPE_ACTION, action,
2215 "configuration cannot be null");
2216 if (action_flags & MLX5_FLOW_ACTION_DROP)
2217 return rte_flow_error_set(error, EINVAL,
2218 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2219 "can't drop and encap in same flow");
2220 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
2221 return rte_flow_error_set(error, EINVAL,
2222 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2223 "can only have a single encap"
2224 " action in a flow");
2225 /* encap without preceding decap is not supported for ingress */
2226 if (!attr->transfer && attr->ingress &&
2227 !(action_flags & MLX5_FLOW_ACTION_RAW_DECAP))
2228 return rte_flow_error_set(error, ENOTSUP,
2229 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2231 "encap action not supported for "
2233 if (!raw_encap->size || !raw_encap->data)
2234 return rte_flow_error_set(error, EINVAL,
2235 RTE_FLOW_ERROR_TYPE_ACTION, action,
2236 "raw encap data cannot be empty");
2241 * Validate the raw decap action.
2243 * @param[in] action_flags
2244 * Holds the actions detected until now.
2246 * Pointer to the encap action.
2248 * Pointer to flow attributes
2250 * Pointer to error structure.
2253 * 0 on success, a negative errno value otherwise and rte_errno is set.
2256 flow_dv_validate_action_raw_decap(uint64_t action_flags,
2257 const struct rte_flow_action *action,
2258 const struct rte_flow_attr *attr,
2259 struct rte_flow_error *error)
2261 const struct rte_flow_action_raw_decap *decap = action->conf;
2263 if (action_flags & MLX5_FLOW_ACTION_DROP)
2264 return rte_flow_error_set(error, EINVAL,
2265 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2266 "can't drop and decap in same flow");
2267 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
2268 return rte_flow_error_set(error, EINVAL,
2269 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2270 "can't have encap action before"
2272 if (action_flags & MLX5_FLOW_DECAP_ACTIONS)
2273 return rte_flow_error_set(error, EINVAL,
2274 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2275 "can only have a single decap"
2276 " action in a flow");
2277 /* decap action is valid on egress only if it is followed by encap */
2278 if (attr->egress && decap &&
2279 decap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
2280 return rte_flow_error_set(error, ENOTSUP,
2281 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2282 NULL, "decap action not supported"
2284 } else if (decap && decap->size > MLX5_ENCAPSULATION_DECISION_SIZE &&
2285 (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)) {
2286 return rte_flow_error_set(error, EINVAL,
2287 RTE_FLOW_ERROR_TYPE_ACTION,
2289 "can't have decap action "
2290 "after modify action");
2296 * Find existing encap/decap resource or create and register a new one.
2298 * @param[in, out] dev
2299 * Pointer to rte_eth_dev structure.
2300 * @param[in, out] resource
2301 * Pointer to encap/decap resource.
2302 * @parm[in, out] dev_flow
2303 * Pointer to the dev_flow.
2305 * pointer to error structure.
2308 * 0 on success otherwise -errno and errno is set.
2311 flow_dv_encap_decap_resource_register
2312 (struct rte_eth_dev *dev,
2313 struct mlx5_flow_dv_encap_decap_resource *resource,
2314 struct mlx5_flow *dev_flow,
2315 struct rte_flow_error *error)
2317 struct mlx5_priv *priv = dev->data->dev_private;
2318 struct mlx5_ibv_shared *sh = priv->sh;
2319 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2320 struct mlx5dv_dr_domain *domain;
2322 resource->flags = dev_flow->group ? 0 : 1;
2323 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2324 domain = sh->fdb_domain;
2325 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2326 domain = sh->rx_domain;
2328 domain = sh->tx_domain;
2330 /* Lookup a matching resource from cache. */
2331 LIST_FOREACH(cache_resource, &sh->encaps_decaps, next) {
2332 if (resource->reformat_type == cache_resource->reformat_type &&
2333 resource->ft_type == cache_resource->ft_type &&
2334 resource->flags == cache_resource->flags &&
2335 resource->size == cache_resource->size &&
2336 !memcmp((const void *)resource->buf,
2337 (const void *)cache_resource->buf,
2339 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d++",
2340 (void *)cache_resource,
2341 rte_atomic32_read(&cache_resource->refcnt));
2342 rte_atomic32_inc(&cache_resource->refcnt);
2343 dev_flow->dv.encap_decap = cache_resource;
2347 /* Register new encap/decap resource. */
2348 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
2349 if (!cache_resource)
2350 return rte_flow_error_set(error, ENOMEM,
2351 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2352 "cannot allocate resource memory");
2353 *cache_resource = *resource;
2354 cache_resource->verbs_action =
2355 mlx5_glue->dv_create_flow_action_packet_reformat
2356 (sh->ctx, cache_resource->reformat_type,
2357 cache_resource->ft_type, domain, cache_resource->flags,
2358 cache_resource->size,
2359 (cache_resource->size ? cache_resource->buf : NULL));
2360 if (!cache_resource->verbs_action) {
2361 rte_free(cache_resource);
2362 return rte_flow_error_set(error, ENOMEM,
2363 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2364 NULL, "cannot create action");
2366 rte_atomic32_init(&cache_resource->refcnt);
2367 rte_atomic32_inc(&cache_resource->refcnt);
2368 LIST_INSERT_HEAD(&sh->encaps_decaps, cache_resource, next);
2369 dev_flow->dv.encap_decap = cache_resource;
2370 DRV_LOG(DEBUG, "new encap/decap resource %p: refcnt %d++",
2371 (void *)cache_resource,
2372 rte_atomic32_read(&cache_resource->refcnt));
2377 * Find existing table jump resource or create and register a new one.
2379 * @param[in, out] dev
2380 * Pointer to rte_eth_dev structure.
2381 * @param[in, out] tbl
2382 * Pointer to flow table resource.
2383 * @parm[in, out] dev_flow
2384 * Pointer to the dev_flow.
2386 * pointer to error structure.
2389 * 0 on success otherwise -errno and errno is set.
2392 flow_dv_jump_tbl_resource_register
2393 (struct rte_eth_dev *dev __rte_unused,
2394 struct mlx5_flow_tbl_resource *tbl,
2395 struct mlx5_flow *dev_flow,
2396 struct rte_flow_error *error)
2398 struct mlx5_flow_tbl_data_entry *tbl_data =
2399 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
2403 cnt = rte_atomic32_read(&tbl_data->jump.refcnt);
2405 tbl_data->jump.action =
2406 mlx5_glue->dr_create_flow_action_dest_flow_tbl
2408 if (!tbl_data->jump.action)
2409 return rte_flow_error_set(error, ENOMEM,
2410 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2411 NULL, "cannot create jump action");
2412 DRV_LOG(DEBUG, "new jump table resource %p: refcnt %d++",
2413 (void *)&tbl_data->jump, cnt);
2415 assert(tbl_data->jump.action);
2416 DRV_LOG(DEBUG, "existed jump table resource %p: refcnt %d++",
2417 (void *)&tbl_data->jump, cnt);
2419 rte_atomic32_inc(&tbl_data->jump.refcnt);
2420 dev_flow->dv.jump = &tbl_data->jump;
2425 * Find existing table port ID resource or create and register a new one.
2427 * @param[in, out] dev
2428 * Pointer to rte_eth_dev structure.
2429 * @param[in, out] resource
2430 * Pointer to port ID action resource.
2431 * @parm[in, out] dev_flow
2432 * Pointer to the dev_flow.
2434 * pointer to error structure.
2437 * 0 on success otherwise -errno and errno is set.
2440 flow_dv_port_id_action_resource_register
2441 (struct rte_eth_dev *dev,
2442 struct mlx5_flow_dv_port_id_action_resource *resource,
2443 struct mlx5_flow *dev_flow,
2444 struct rte_flow_error *error)
2446 struct mlx5_priv *priv = dev->data->dev_private;
2447 struct mlx5_ibv_shared *sh = priv->sh;
2448 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
2450 /* Lookup a matching resource from cache. */
2451 LIST_FOREACH(cache_resource, &sh->port_id_action_list, next) {
2452 if (resource->port_id == cache_resource->port_id) {
2453 DRV_LOG(DEBUG, "port id action resource resource %p: "
2455 (void *)cache_resource,
2456 rte_atomic32_read(&cache_resource->refcnt));
2457 rte_atomic32_inc(&cache_resource->refcnt);
2458 dev_flow->dv.port_id_action = cache_resource;
2462 /* Register new port id action resource. */
2463 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
2464 if (!cache_resource)
2465 return rte_flow_error_set(error, ENOMEM,
2466 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2467 "cannot allocate resource memory");
2468 *cache_resource = *resource;
2470 * Depending on rdma_core version the glue routine calls
2471 * either mlx5dv_dr_action_create_dest_ib_port(domain, ibv_port)
2472 * or mlx5dv_dr_action_create_dest_vport(domain, vport_id).
2474 cache_resource->action =
2475 mlx5_glue->dr_create_flow_action_dest_port
2476 (priv->sh->fdb_domain, resource->port_id);
2477 if (!cache_resource->action) {
2478 rte_free(cache_resource);
2479 return rte_flow_error_set(error, ENOMEM,
2480 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2481 NULL, "cannot create action");
2483 rte_atomic32_init(&cache_resource->refcnt);
2484 rte_atomic32_inc(&cache_resource->refcnt);
2485 LIST_INSERT_HEAD(&sh->port_id_action_list, cache_resource, next);
2486 dev_flow->dv.port_id_action = cache_resource;
2487 DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++",
2488 (void *)cache_resource,
2489 rte_atomic32_read(&cache_resource->refcnt));
2494 * Find existing push vlan resource or create and register a new one.
2496 * @param [in, out] dev
2497 * Pointer to rte_eth_dev structure.
2498 * @param[in, out] resource
2499 * Pointer to port ID action resource.
2500 * @parm[in, out] dev_flow
2501 * Pointer to the dev_flow.
2503 * pointer to error structure.
2506 * 0 on success otherwise -errno and errno is set.
2509 flow_dv_push_vlan_action_resource_register
2510 (struct rte_eth_dev *dev,
2511 struct mlx5_flow_dv_push_vlan_action_resource *resource,
2512 struct mlx5_flow *dev_flow,
2513 struct rte_flow_error *error)
2515 struct mlx5_priv *priv = dev->data->dev_private;
2516 struct mlx5_ibv_shared *sh = priv->sh;
2517 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
2518 struct mlx5dv_dr_domain *domain;
2520 /* Lookup a matching resource from cache. */
2521 LIST_FOREACH(cache_resource, &sh->push_vlan_action_list, next) {
2522 if (resource->vlan_tag == cache_resource->vlan_tag &&
2523 resource->ft_type == cache_resource->ft_type) {
2524 DRV_LOG(DEBUG, "push-VLAN action resource resource %p: "
2526 (void *)cache_resource,
2527 rte_atomic32_read(&cache_resource->refcnt));
2528 rte_atomic32_inc(&cache_resource->refcnt);
2529 dev_flow->dv.push_vlan_res = cache_resource;
2533 /* Register new push_vlan action resource. */
2534 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
2535 if (!cache_resource)
2536 return rte_flow_error_set(error, ENOMEM,
2537 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2538 "cannot allocate resource memory");
2539 *cache_resource = *resource;
2540 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2541 domain = sh->fdb_domain;
2542 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2543 domain = sh->rx_domain;
2545 domain = sh->tx_domain;
2546 cache_resource->action =
2547 mlx5_glue->dr_create_flow_action_push_vlan(domain,
2548 resource->vlan_tag);
2549 if (!cache_resource->action) {
2550 rte_free(cache_resource);
2551 return rte_flow_error_set(error, ENOMEM,
2552 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2553 NULL, "cannot create action");
2555 rte_atomic32_init(&cache_resource->refcnt);
2556 rte_atomic32_inc(&cache_resource->refcnt);
2557 LIST_INSERT_HEAD(&sh->push_vlan_action_list, cache_resource, next);
2558 dev_flow->dv.push_vlan_res = cache_resource;
2559 DRV_LOG(DEBUG, "new push vlan action resource %p: refcnt %d++",
2560 (void *)cache_resource,
2561 rte_atomic32_read(&cache_resource->refcnt));
2565 * Get the size of specific rte_flow_item_type
2567 * @param[in] item_type
2568 * Tested rte_flow_item_type.
2571 * sizeof struct item_type, 0 if void or irrelevant.
2574 flow_dv_get_item_len(const enum rte_flow_item_type item_type)
2578 switch (item_type) {
2579 case RTE_FLOW_ITEM_TYPE_ETH:
2580 retval = sizeof(struct rte_flow_item_eth);
2582 case RTE_FLOW_ITEM_TYPE_VLAN:
2583 retval = sizeof(struct rte_flow_item_vlan);
2585 case RTE_FLOW_ITEM_TYPE_IPV4:
2586 retval = sizeof(struct rte_flow_item_ipv4);
2588 case RTE_FLOW_ITEM_TYPE_IPV6:
2589 retval = sizeof(struct rte_flow_item_ipv6);
2591 case RTE_FLOW_ITEM_TYPE_UDP:
2592 retval = sizeof(struct rte_flow_item_udp);
2594 case RTE_FLOW_ITEM_TYPE_TCP:
2595 retval = sizeof(struct rte_flow_item_tcp);
2597 case RTE_FLOW_ITEM_TYPE_VXLAN:
2598 retval = sizeof(struct rte_flow_item_vxlan);
2600 case RTE_FLOW_ITEM_TYPE_GRE:
2601 retval = sizeof(struct rte_flow_item_gre);
2603 case RTE_FLOW_ITEM_TYPE_NVGRE:
2604 retval = sizeof(struct rte_flow_item_nvgre);
2606 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2607 retval = sizeof(struct rte_flow_item_vxlan_gpe);
2609 case RTE_FLOW_ITEM_TYPE_MPLS:
2610 retval = sizeof(struct rte_flow_item_mpls);
2612 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
2620 #define MLX5_ENCAP_IPV4_VERSION 0x40
2621 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
2622 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
2623 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
2624 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
2625 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
2626 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
2629 * Convert the encap action data from list of rte_flow_item to raw buffer
2632 * Pointer to rte_flow_item objects list.
2634 * Pointer to the output buffer.
2636 * Pointer to the output buffer size.
2638 * Pointer to the error structure.
2641 * 0 on success, a negative errno value otherwise and rte_errno is set.
2644 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
2645 size_t *size, struct rte_flow_error *error)
2647 struct rte_ether_hdr *eth = NULL;
2648 struct rte_vlan_hdr *vlan = NULL;
2649 struct rte_ipv4_hdr *ipv4 = NULL;
2650 struct rte_ipv6_hdr *ipv6 = NULL;
2651 struct rte_udp_hdr *udp = NULL;
2652 struct rte_vxlan_hdr *vxlan = NULL;
2653 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
2654 struct rte_gre_hdr *gre = NULL;
2656 size_t temp_size = 0;
2659 return rte_flow_error_set(error, EINVAL,
2660 RTE_FLOW_ERROR_TYPE_ACTION,
2661 NULL, "invalid empty data");
2662 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2663 len = flow_dv_get_item_len(items->type);
2664 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
2665 return rte_flow_error_set(error, EINVAL,
2666 RTE_FLOW_ERROR_TYPE_ACTION,
2667 (void *)items->type,
2668 "items total size is too big"
2669 " for encap action");
2670 rte_memcpy((void *)&buf[temp_size], items->spec, len);
2671 switch (items->type) {
2672 case RTE_FLOW_ITEM_TYPE_ETH:
2673 eth = (struct rte_ether_hdr *)&buf[temp_size];
2675 case RTE_FLOW_ITEM_TYPE_VLAN:
2676 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
2678 return rte_flow_error_set(error, EINVAL,
2679 RTE_FLOW_ERROR_TYPE_ACTION,
2680 (void *)items->type,
2681 "eth header not found");
2682 if (!eth->ether_type)
2683 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
2685 case RTE_FLOW_ITEM_TYPE_IPV4:
2686 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
2688 return rte_flow_error_set(error, EINVAL,
2689 RTE_FLOW_ERROR_TYPE_ACTION,
2690 (void *)items->type,
2691 "neither eth nor vlan"
2693 if (vlan && !vlan->eth_proto)
2694 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2695 else if (eth && !eth->ether_type)
2696 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2697 if (!ipv4->version_ihl)
2698 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
2699 MLX5_ENCAP_IPV4_IHL_MIN;
2700 if (!ipv4->time_to_live)
2701 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
2703 case RTE_FLOW_ITEM_TYPE_IPV6:
2704 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
2706 return rte_flow_error_set(error, EINVAL,
2707 RTE_FLOW_ERROR_TYPE_ACTION,
2708 (void *)items->type,
2709 "neither eth nor vlan"
2711 if (vlan && !vlan->eth_proto)
2712 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2713 else if (eth && !eth->ether_type)
2714 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2715 if (!ipv6->vtc_flow)
2717 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
2718 if (!ipv6->hop_limits)
2719 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
2721 case RTE_FLOW_ITEM_TYPE_UDP:
2722 udp = (struct rte_udp_hdr *)&buf[temp_size];
2724 return rte_flow_error_set(error, EINVAL,
2725 RTE_FLOW_ERROR_TYPE_ACTION,
2726 (void *)items->type,
2727 "ip header not found");
2728 if (ipv4 && !ipv4->next_proto_id)
2729 ipv4->next_proto_id = IPPROTO_UDP;
2730 else if (ipv6 && !ipv6->proto)
2731 ipv6->proto = IPPROTO_UDP;
2733 case RTE_FLOW_ITEM_TYPE_VXLAN:
2734 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
2736 return rte_flow_error_set(error, EINVAL,
2737 RTE_FLOW_ERROR_TYPE_ACTION,
2738 (void *)items->type,
2739 "udp header not found");
2741 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
2742 if (!vxlan->vx_flags)
2744 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
2746 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2747 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
2749 return rte_flow_error_set(error, EINVAL,
2750 RTE_FLOW_ERROR_TYPE_ACTION,
2751 (void *)items->type,
2752 "udp header not found");
2753 if (!vxlan_gpe->proto)
2754 return rte_flow_error_set(error, EINVAL,
2755 RTE_FLOW_ERROR_TYPE_ACTION,
2756 (void *)items->type,
2757 "next protocol not found");
2760 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
2761 if (!vxlan_gpe->vx_flags)
2762 vxlan_gpe->vx_flags =
2763 MLX5_ENCAP_VXLAN_GPE_FLAGS;
2765 case RTE_FLOW_ITEM_TYPE_GRE:
2766 case RTE_FLOW_ITEM_TYPE_NVGRE:
2767 gre = (struct rte_gre_hdr *)&buf[temp_size];
2769 return rte_flow_error_set(error, EINVAL,
2770 RTE_FLOW_ERROR_TYPE_ACTION,
2771 (void *)items->type,
2772 "next protocol not found");
2774 return rte_flow_error_set(error, EINVAL,
2775 RTE_FLOW_ERROR_TYPE_ACTION,
2776 (void *)items->type,
2777 "ip header not found");
2778 if (ipv4 && !ipv4->next_proto_id)
2779 ipv4->next_proto_id = IPPROTO_GRE;
2780 else if (ipv6 && !ipv6->proto)
2781 ipv6->proto = IPPROTO_GRE;
2783 case RTE_FLOW_ITEM_TYPE_VOID:
2786 return rte_flow_error_set(error, EINVAL,
2787 RTE_FLOW_ERROR_TYPE_ACTION,
2788 (void *)items->type,
2789 "unsupported item type");
2799 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
2801 struct rte_ether_hdr *eth = NULL;
2802 struct rte_vlan_hdr *vlan = NULL;
2803 struct rte_ipv6_hdr *ipv6 = NULL;
2804 struct rte_udp_hdr *udp = NULL;
2808 eth = (struct rte_ether_hdr *)data;
2809 next_hdr = (char *)(eth + 1);
2810 proto = RTE_BE16(eth->ether_type);
2813 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
2814 vlan = (struct rte_vlan_hdr *)next_hdr;
2815 proto = RTE_BE16(vlan->eth_proto);
2816 next_hdr += sizeof(struct rte_vlan_hdr);
2819 /* HW calculates IPv4 csum. no need to proceed */
2820 if (proto == RTE_ETHER_TYPE_IPV4)
2823 /* non IPv4/IPv6 header. not supported */
2824 if (proto != RTE_ETHER_TYPE_IPV6) {
2825 return rte_flow_error_set(error, ENOTSUP,
2826 RTE_FLOW_ERROR_TYPE_ACTION,
2827 NULL, "Cannot offload non IPv4/IPv6");
2830 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
2832 /* ignore non UDP */
2833 if (ipv6->proto != IPPROTO_UDP)
2836 udp = (struct rte_udp_hdr *)(ipv6 + 1);
2837 udp->dgram_cksum = 0;
2843 * Convert L2 encap action to DV specification.
2846 * Pointer to rte_eth_dev structure.
2848 * Pointer to action structure.
2849 * @param[in, out] dev_flow
2850 * Pointer to the mlx5_flow.
2851 * @param[in] transfer
2852 * Mark if the flow is E-Switch flow.
2854 * Pointer to the error structure.
2857 * 0 on success, a negative errno value otherwise and rte_errno is set.
2860 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
2861 const struct rte_flow_action *action,
2862 struct mlx5_flow *dev_flow,
2864 struct rte_flow_error *error)
2866 const struct rte_flow_item *encap_data;
2867 const struct rte_flow_action_raw_encap *raw_encap_data;
2868 struct mlx5_flow_dv_encap_decap_resource res = {
2870 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
2871 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
2872 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
2875 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
2877 (const struct rte_flow_action_raw_encap *)action->conf;
2878 res.size = raw_encap_data->size;
2879 memcpy(res.buf, raw_encap_data->data, res.size);
2880 if (flow_dv_zero_encap_udp_csum(res.buf, error))
2883 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
2885 ((const struct rte_flow_action_vxlan_encap *)
2886 action->conf)->definition;
2889 ((const struct rte_flow_action_nvgre_encap *)
2890 action->conf)->definition;
2891 if (flow_dv_convert_encap_data(encap_data, res.buf,
2895 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
2896 return rte_flow_error_set(error, EINVAL,
2897 RTE_FLOW_ERROR_TYPE_ACTION,
2898 NULL, "can't create L2 encap action");
2903 * Convert L2 decap action to DV specification.
2906 * Pointer to rte_eth_dev structure.
2907 * @param[in, out] dev_flow
2908 * Pointer to the mlx5_flow.
2909 * @param[in] transfer
2910 * Mark if the flow is E-Switch flow.
2912 * Pointer to the error structure.
2915 * 0 on success, a negative errno value otherwise and rte_errno is set.
2918 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
2919 struct mlx5_flow *dev_flow,
2921 struct rte_flow_error *error)
2923 struct mlx5_flow_dv_encap_decap_resource res = {
2926 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
2927 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
2928 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
2931 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
2932 return rte_flow_error_set(error, EINVAL,
2933 RTE_FLOW_ERROR_TYPE_ACTION,
2934 NULL, "can't create L2 decap action");
2939 * Convert raw decap/encap (L3 tunnel) action to DV specification.
2942 * Pointer to rte_eth_dev structure.
2944 * Pointer to action structure.
2945 * @param[in, out] dev_flow
2946 * Pointer to the mlx5_flow.
2948 * Pointer to the flow attributes.
2950 * Pointer to the error structure.
2953 * 0 on success, a negative errno value otherwise and rte_errno is set.
2956 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
2957 const struct rte_flow_action *action,
2958 struct mlx5_flow *dev_flow,
2959 const struct rte_flow_attr *attr,
2960 struct rte_flow_error *error)
2962 const struct rte_flow_action_raw_encap *encap_data;
2963 struct mlx5_flow_dv_encap_decap_resource res;
2965 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
2966 res.size = encap_data->size;
2967 memcpy(res.buf, encap_data->data, res.size);
2968 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
2969 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
2970 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
2972 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
2974 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
2975 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
2976 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
2977 return rte_flow_error_set(error, EINVAL,
2978 RTE_FLOW_ERROR_TYPE_ACTION,
2979 NULL, "can't create encap action");
2984 * Create action push VLAN.
2987 * Pointer to rte_eth_dev structure.
2988 * @param[in] vlan_tag
2989 * the vlan tag to push to the Ethernet header.
2990 * @param[in, out] dev_flow
2991 * Pointer to the mlx5_flow.
2993 * Pointer to the flow attributes.
2995 * Pointer to the error structure.
2998 * 0 on success, a negative errno value otherwise and rte_errno is set.
3001 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
3002 const struct rte_flow_attr *attr,
3003 const struct rte_vlan_hdr *vlan,
3004 struct mlx5_flow *dev_flow,
3005 struct rte_flow_error *error)
3007 struct mlx5_flow_dv_push_vlan_action_resource res;
3010 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
3013 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3015 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3016 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3017 return flow_dv_push_vlan_action_resource_register
3018 (dev, &res, dev_flow, error);
3022 * Validate the modify-header actions.
3024 * @param[in] action_flags
3025 * Holds the actions detected until now.
3027 * Pointer to the modify action.
3029 * Pointer to error structure.
3032 * 0 on success, a negative errno value otherwise and rte_errno is set.
3035 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
3036 const struct rte_flow_action *action,
3037 struct rte_flow_error *error)
3039 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
3040 return rte_flow_error_set(error, EINVAL,
3041 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3042 NULL, "action configuration not set");
3043 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
3044 return rte_flow_error_set(error, EINVAL,
3045 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3046 "can't have encap action before"
3052 * Validate the modify-header MAC address actions.
3054 * @param[in] action_flags
3055 * Holds the actions detected until now.
3057 * Pointer to the modify action.
3058 * @param[in] item_flags
3059 * Holds the items detected.
3061 * Pointer to error structure.
3064 * 0 on success, a negative errno value otherwise and rte_errno is set.
3067 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
3068 const struct rte_flow_action *action,
3069 const uint64_t item_flags,
3070 struct rte_flow_error *error)
3074 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3076 if (!(item_flags & MLX5_FLOW_LAYER_L2))
3077 return rte_flow_error_set(error, EINVAL,
3078 RTE_FLOW_ERROR_TYPE_ACTION,
3080 "no L2 item in pattern");
3086 * Validate the modify-header IPv4 address actions.
3088 * @param[in] action_flags
3089 * Holds the actions detected until now.
3091 * Pointer to the modify action.
3092 * @param[in] item_flags
3093 * Holds the items detected.
3095 * Pointer to error structure.
3098 * 0 on success, a negative errno value otherwise and rte_errno is set.
3101 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
3102 const struct rte_flow_action *action,
3103 const uint64_t item_flags,
3104 struct rte_flow_error *error)
3108 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3110 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
3111 return rte_flow_error_set(error, EINVAL,
3112 RTE_FLOW_ERROR_TYPE_ACTION,
3114 "no ipv4 item in pattern");
3120 * Validate the modify-header IPv6 address actions.
3122 * @param[in] action_flags
3123 * Holds the actions detected until now.
3125 * Pointer to the modify action.
3126 * @param[in] item_flags
3127 * Holds the items detected.
3129 * Pointer to error structure.
3132 * 0 on success, a negative errno value otherwise and rte_errno is set.
3135 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
3136 const struct rte_flow_action *action,
3137 const uint64_t item_flags,
3138 struct rte_flow_error *error)
3142 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3144 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
3145 return rte_flow_error_set(error, EINVAL,
3146 RTE_FLOW_ERROR_TYPE_ACTION,
3148 "no ipv6 item in pattern");
3154 * Validate the modify-header TP actions.
3156 * @param[in] action_flags
3157 * Holds the actions detected until now.
3159 * Pointer to the modify action.
3160 * @param[in] item_flags
3161 * Holds the items detected.
3163 * Pointer to error structure.
3166 * 0 on success, a negative errno value otherwise and rte_errno is set.
3169 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
3170 const struct rte_flow_action *action,
3171 const uint64_t item_flags,
3172 struct rte_flow_error *error)
3176 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3178 if (!(item_flags & MLX5_FLOW_LAYER_L4))
3179 return rte_flow_error_set(error, EINVAL,
3180 RTE_FLOW_ERROR_TYPE_ACTION,
3181 NULL, "no transport layer "
3188 * Validate the modify-header actions of increment/decrement
3189 * TCP Sequence-number.
3191 * @param[in] action_flags
3192 * Holds the actions detected until now.
3194 * Pointer to the modify action.
3195 * @param[in] item_flags
3196 * Holds the items detected.
3198 * Pointer to error structure.
3201 * 0 on success, a negative errno value otherwise and rte_errno is set.
3204 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
3205 const struct rte_flow_action *action,
3206 const uint64_t item_flags,
3207 struct rte_flow_error *error)
3211 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3213 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3214 return rte_flow_error_set(error, EINVAL,
3215 RTE_FLOW_ERROR_TYPE_ACTION,
3216 NULL, "no TCP item in"
3218 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
3219 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
3220 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
3221 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
3222 return rte_flow_error_set(error, EINVAL,
3223 RTE_FLOW_ERROR_TYPE_ACTION,
3225 "cannot decrease and increase"
3226 " TCP sequence number"
3227 " at the same time");
3233 * Validate the modify-header actions of increment/decrement
3234 * TCP Acknowledgment number.
3236 * @param[in] action_flags
3237 * Holds the actions detected until now.
3239 * Pointer to the modify action.
3240 * @param[in] item_flags
3241 * Holds the items detected.
3243 * Pointer to error structure.
3246 * 0 on success, a negative errno value otherwise and rte_errno is set.
3249 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
3250 const struct rte_flow_action *action,
3251 const uint64_t item_flags,
3252 struct rte_flow_error *error)
3256 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3258 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3259 return rte_flow_error_set(error, EINVAL,
3260 RTE_FLOW_ERROR_TYPE_ACTION,
3261 NULL, "no TCP item in"
3263 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
3264 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
3265 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
3266 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
3267 return rte_flow_error_set(error, EINVAL,
3268 RTE_FLOW_ERROR_TYPE_ACTION,
3270 "cannot decrease and increase"
3271 " TCP acknowledgment number"
3272 " at the same time");
3278 * Validate the modify-header TTL actions.
3280 * @param[in] action_flags
3281 * Holds the actions detected until now.
3283 * Pointer to the modify action.
3284 * @param[in] item_flags
3285 * Holds the items detected.
3287 * Pointer to error structure.
3290 * 0 on success, a negative errno value otherwise and rte_errno is set.
3293 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
3294 const struct rte_flow_action *action,
3295 const uint64_t item_flags,
3296 struct rte_flow_error *error)
3300 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3302 if (!(item_flags & MLX5_FLOW_LAYER_L3))
3303 return rte_flow_error_set(error, EINVAL,
3304 RTE_FLOW_ERROR_TYPE_ACTION,
3306 "no IP protocol in pattern");
3312 * Validate jump action.
3315 * Pointer to the jump action.
3316 * @param[in] action_flags
3317 * Holds the actions detected until now.
3318 * @param[in] attributes
3319 * Pointer to flow attributes
3320 * @param[in] external
3321 * Action belongs to flow rule created by request external to PMD.
3323 * Pointer to error structure.
3326 * 0 on success, a negative errno value otherwise and rte_errno is set.
3329 flow_dv_validate_action_jump(const struct rte_flow_action *action,
3330 uint64_t action_flags,
3331 const struct rte_flow_attr *attributes,
3332 bool external, struct rte_flow_error *error)
3334 uint32_t target_group, table;
3337 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3338 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3339 return rte_flow_error_set(error, EINVAL,
3340 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3341 "can't have 2 fate actions in"
3343 if (action_flags & MLX5_FLOW_ACTION_METER)
3344 return rte_flow_error_set(error, ENOTSUP,
3345 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3346 "jump with meter not support");
3348 return rte_flow_error_set(error, EINVAL,
3349 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3350 NULL, "action configuration not set");
3352 ((const struct rte_flow_action_jump *)action->conf)->group;
3353 ret = mlx5_flow_group_to_table(attributes, external, target_group,
3357 if (attributes->group == target_group)
3358 return rte_flow_error_set(error, EINVAL,
3359 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3360 "target group must be other than"
3361 " the current flow group");
3366 * Validate the port_id action.
3369 * Pointer to rte_eth_dev structure.
3370 * @param[in] action_flags
3371 * Bit-fields that holds the actions detected until now.
3373 * Port_id RTE action structure.
3375 * Attributes of flow that includes this action.
3377 * Pointer to error structure.
3380 * 0 on success, a negative errno value otherwise and rte_errno is set.
3383 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
3384 uint64_t action_flags,
3385 const struct rte_flow_action *action,
3386 const struct rte_flow_attr *attr,
3387 struct rte_flow_error *error)
3389 const struct rte_flow_action_port_id *port_id;
3390 struct mlx5_priv *act_priv;
3391 struct mlx5_priv *dev_priv;
3394 if (!attr->transfer)
3395 return rte_flow_error_set(error, ENOTSUP,
3396 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3398 "port id action is valid in transfer"
3400 if (!action || !action->conf)
3401 return rte_flow_error_set(error, ENOTSUP,
3402 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3404 "port id action parameters must be"
3406 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3407 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3408 return rte_flow_error_set(error, EINVAL,
3409 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3410 "can have only one fate actions in"
3412 dev_priv = mlx5_dev_to_eswitch_info(dev);
3414 return rte_flow_error_set(error, rte_errno,
3415 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3417 "failed to obtain E-Switch info");
3418 port_id = action->conf;
3419 port = port_id->original ? dev->data->port_id : port_id->id;
3420 act_priv = mlx5_port_to_eswitch_info(port, false);
3422 return rte_flow_error_set
3424 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
3425 "failed to obtain E-Switch port id for port");
3426 if (act_priv->domain_id != dev_priv->domain_id)
3427 return rte_flow_error_set
3429 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3430 "port does not belong to"
3431 " E-Switch being configured");
3436 * Get the maximum number of modify header actions.
3439 * Pointer to rte_eth_dev structure.
3442 * Max number of modify header actions device can support.
3445 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev)
3448 * There's no way to directly query the max cap. Although it has to be
3449 * acquried by iterative trial, it is a safe assumption that more
3450 * actions are supported by FW if extensive metadata register is
3453 return mlx5_flow_ext_mreg_supported(dev) ? MLX5_MODIFY_NUM :
3454 MLX5_MODIFY_NUM_NO_MREG;
3458 * Validate the meter action.
3461 * Pointer to rte_eth_dev structure.
3462 * @param[in] action_flags
3463 * Bit-fields that holds the actions detected until now.
3465 * Pointer to the meter action.
3467 * Attributes of flow that includes this action.
3469 * Pointer to error structure.
3472 * 0 on success, a negative errno value otherwise and rte_ernno is set.
3475 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
3476 uint64_t action_flags,
3477 const struct rte_flow_action *action,
3478 const struct rte_flow_attr *attr,
3479 struct rte_flow_error *error)
3481 struct mlx5_priv *priv = dev->data->dev_private;
3482 const struct rte_flow_action_meter *am = action->conf;
3483 struct mlx5_flow_meter *fm;
3486 return rte_flow_error_set(error, EINVAL,
3487 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3488 "meter action conf is NULL");
3490 if (action_flags & MLX5_FLOW_ACTION_METER)
3491 return rte_flow_error_set(error, ENOTSUP,
3492 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3493 "meter chaining not support");
3494 if (action_flags & MLX5_FLOW_ACTION_JUMP)
3495 return rte_flow_error_set(error, ENOTSUP,
3496 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3497 "meter with jump not support");
3499 return rte_flow_error_set(error, ENOTSUP,
3500 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3502 "meter action not supported");
3503 fm = mlx5_flow_meter_find(priv, am->mtr_id);
3505 return rte_flow_error_set(error, EINVAL,
3506 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3508 if (fm->ref_cnt && (!(fm->attr.transfer == attr->transfer ||
3509 (!fm->attr.ingress && !attr->ingress && attr->egress) ||
3510 (!fm->attr.egress && !attr->egress && attr->ingress))))
3511 return rte_flow_error_set(error, EINVAL,
3512 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3513 "Flow attributes are either invalid "
3514 "or have a conflict with current "
3515 "meter attributes");
3520 * Validate the modify-header IPv4 DSCP actions.
3522 * @param[in] action_flags
3523 * Holds the actions detected until now.
3525 * Pointer to the modify action.
3526 * @param[in] item_flags
3527 * Holds the items detected.
3529 * Pointer to error structure.
3532 * 0 on success, a negative errno value otherwise and rte_errno is set.
3535 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
3536 const struct rte_flow_action *action,
3537 const uint64_t item_flags,
3538 struct rte_flow_error *error)
3542 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3544 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
3545 return rte_flow_error_set(error, EINVAL,
3546 RTE_FLOW_ERROR_TYPE_ACTION,
3548 "no ipv4 item in pattern");
3554 * Validate the modify-header IPv6 DSCP actions.
3556 * @param[in] action_flags
3557 * Holds the actions detected until now.
3559 * Pointer to the modify action.
3560 * @param[in] item_flags
3561 * Holds the items detected.
3563 * Pointer to error structure.
3566 * 0 on success, a negative errno value otherwise and rte_errno is set.
3569 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
3570 const struct rte_flow_action *action,
3571 const uint64_t item_flags,
3572 struct rte_flow_error *error)
3576 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3578 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
3579 return rte_flow_error_set(error, EINVAL,
3580 RTE_FLOW_ERROR_TYPE_ACTION,
3582 "no ipv6 item in pattern");
3588 * Find existing modify-header resource or create and register a new one.
3590 * @param dev[in, out]
3591 * Pointer to rte_eth_dev structure.
3592 * @param[in, out] resource
3593 * Pointer to modify-header resource.
3594 * @parm[in, out] dev_flow
3595 * Pointer to the dev_flow.
3597 * pointer to error structure.
3600 * 0 on success otherwise -errno and errno is set.
3603 flow_dv_modify_hdr_resource_register
3604 (struct rte_eth_dev *dev,
3605 struct mlx5_flow_dv_modify_hdr_resource *resource,
3606 struct mlx5_flow *dev_flow,
3607 struct rte_flow_error *error)
3609 struct mlx5_priv *priv = dev->data->dev_private;
3610 struct mlx5_ibv_shared *sh = priv->sh;
3611 struct mlx5_flow_dv_modify_hdr_resource *cache_resource;
3612 struct mlx5dv_dr_domain *ns;
3614 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev))
3615 return rte_flow_error_set(error, EOVERFLOW,
3616 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3617 "too many modify header items");
3618 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3619 ns = sh->fdb_domain;
3620 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
3625 dev_flow->group ? 0 : MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
3626 /* Lookup a matching resource from cache. */
3627 LIST_FOREACH(cache_resource, &sh->modify_cmds, next) {
3628 if (resource->ft_type == cache_resource->ft_type &&
3629 resource->actions_num == cache_resource->actions_num &&
3630 resource->flags == cache_resource->flags &&
3631 !memcmp((const void *)resource->actions,
3632 (const void *)cache_resource->actions,
3633 (resource->actions_num *
3634 sizeof(resource->actions[0])))) {
3635 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d++",
3636 (void *)cache_resource,
3637 rte_atomic32_read(&cache_resource->refcnt));
3638 rte_atomic32_inc(&cache_resource->refcnt);
3639 dev_flow->dv.modify_hdr = cache_resource;
3643 /* Register new modify-header resource. */
3644 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
3645 if (!cache_resource)
3646 return rte_flow_error_set(error, ENOMEM,
3647 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3648 "cannot allocate resource memory");
3649 *cache_resource = *resource;
3650 cache_resource->verbs_action =
3651 mlx5_glue->dv_create_flow_action_modify_header
3652 (sh->ctx, cache_resource->ft_type,
3653 ns, cache_resource->flags,
3654 cache_resource->actions_num *
3655 sizeof(cache_resource->actions[0]),
3656 (uint64_t *)cache_resource->actions);
3657 if (!cache_resource->verbs_action) {
3658 rte_free(cache_resource);
3659 return rte_flow_error_set(error, ENOMEM,
3660 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3661 NULL, "cannot create action");
3663 rte_atomic32_init(&cache_resource->refcnt);
3664 rte_atomic32_inc(&cache_resource->refcnt);
3665 LIST_INSERT_HEAD(&sh->modify_cmds, cache_resource, next);
3666 dev_flow->dv.modify_hdr = cache_resource;
3667 DRV_LOG(DEBUG, "new modify-header resource %p: refcnt %d++",
3668 (void *)cache_resource,
3669 rte_atomic32_read(&cache_resource->refcnt));
3673 #define MLX5_CNT_CONTAINER_RESIZE 64
3676 * Get or create a flow counter.
3679 * Pointer to the Ethernet device structure.
3681 * Indicate if this counter is shared with other flows.
3683 * Counter identifier.
3686 * pointer to flow counter on success, NULL otherwise and rte_errno is set.
3688 static struct mlx5_flow_counter *
3689 flow_dv_counter_alloc_fallback(struct rte_eth_dev *dev, uint32_t shared,
3692 struct mlx5_priv *priv = dev->data->dev_private;
3693 struct mlx5_flow_counter *cnt = NULL;
3694 struct mlx5_devx_obj *dcs = NULL;
3696 if (!priv->config.devx) {
3697 rte_errno = ENOTSUP;
3701 TAILQ_FOREACH(cnt, &priv->sh->cmng.flow_counters, next) {
3702 if (cnt->shared && cnt->id == id) {
3708 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
3711 cnt = rte_calloc(__func__, 1, sizeof(*cnt), 0);
3713 claim_zero(mlx5_devx_cmd_destroy(cnt->dcs));
3717 struct mlx5_flow_counter tmpl = {
3723 tmpl.action = mlx5_glue->dv_create_flow_action_counter(dcs->obj, 0);
3725 claim_zero(mlx5_devx_cmd_destroy(cnt->dcs));
3731 TAILQ_INSERT_HEAD(&priv->sh->cmng.flow_counters, cnt, next);
3736 * Release a flow counter.
3739 * Pointer to the Ethernet device structure.
3740 * @param[in] counter
3741 * Pointer to the counter handler.
3744 flow_dv_counter_release_fallback(struct rte_eth_dev *dev,
3745 struct mlx5_flow_counter *counter)
3747 struct mlx5_priv *priv = dev->data->dev_private;
3751 if (--counter->ref_cnt == 0) {
3752 TAILQ_REMOVE(&priv->sh->cmng.flow_counters, counter, next);
3753 claim_zero(mlx5_devx_cmd_destroy(counter->dcs));
3759 * Query a devx flow counter.
3762 * Pointer to the Ethernet device structure.
3764 * Pointer to the flow counter.
3766 * The statistics value of packets.
3768 * The statistics value of bytes.
3771 * 0 on success, otherwise a negative errno value and rte_errno is set.
3774 _flow_dv_query_count_fallback(struct rte_eth_dev *dev __rte_unused,
3775 struct mlx5_flow_counter *cnt, uint64_t *pkts,
3778 return mlx5_devx_cmd_flow_counter_query(cnt->dcs, 0, 0, pkts, bytes,
3783 * Get a pool by a counter.
3786 * Pointer to the counter.
3791 static struct mlx5_flow_counter_pool *
3792 flow_dv_counter_pool_get(struct mlx5_flow_counter *cnt)
3795 cnt -= cnt->dcs->id % MLX5_COUNTERS_PER_POOL;
3796 return (struct mlx5_flow_counter_pool *)cnt - 1;
3802 * Get a pool by devx counter ID.
3805 * Pointer to the counter container.
3807 * The counter devx ID.
3810 * The counter pool pointer if exists, NULL otherwise,
3812 static struct mlx5_flow_counter_pool *
3813 flow_dv_find_pool_by_id(struct mlx5_pools_container *cont, int id)
3815 struct mlx5_flow_counter_pool *pool;
3817 TAILQ_FOREACH(pool, &cont->pool_list, next) {
3818 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
3819 MLX5_COUNTERS_PER_POOL;
3821 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
3828 * Allocate a new memory for the counter values wrapped by all the needed
3832 * Pointer to the Ethernet device structure.
3834 * The raw memory areas - each one for MLX5_COUNTERS_PER_POOL counters.
3837 * The new memory management pointer on success, otherwise NULL and rte_errno
3840 static struct mlx5_counter_stats_mem_mng *
3841 flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
3843 struct mlx5_ibv_shared *sh = ((struct mlx5_priv *)
3844 (dev->data->dev_private))->sh;
3845 struct mlx5_devx_mkey_attr mkey_attr;
3846 struct mlx5_counter_stats_mem_mng *mem_mng;
3847 volatile struct flow_counter_stats *raw_data;
3848 int size = (sizeof(struct flow_counter_stats) *
3849 MLX5_COUNTERS_PER_POOL +
3850 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
3851 sizeof(struct mlx5_counter_stats_mem_mng);
3852 uint8_t *mem = rte_calloc(__func__, 1, size, sysconf(_SC_PAGESIZE));
3859 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
3860 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
3861 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
3862 IBV_ACCESS_LOCAL_WRITE);
3863 if (!mem_mng->umem) {
3868 mkey_attr.addr = (uintptr_t)mem;
3869 mkey_attr.size = size;
3870 mkey_attr.umem_id = mem_mng->umem->umem_id;
3871 mkey_attr.pd = sh->pdn;
3872 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
3874 mlx5_glue->devx_umem_dereg(mem_mng->umem);
3879 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
3880 raw_data = (volatile struct flow_counter_stats *)mem;
3881 for (i = 0; i < raws_n; ++i) {
3882 mem_mng->raws[i].mem_mng = mem_mng;
3883 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
3885 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
3890 * Resize a counter container.
3893 * Pointer to the Ethernet device structure.
3895 * Whether the pool is for counter that was allocated by batch command.
3898 * The new container pointer on success, otherwise NULL and rte_errno is set.
3900 static struct mlx5_pools_container *
3901 flow_dv_container_resize(struct rte_eth_dev *dev, uint32_t batch)
3903 struct mlx5_priv *priv = dev->data->dev_private;
3904 struct mlx5_pools_container *cont =
3905 MLX5_CNT_CONTAINER(priv->sh, batch, 0);
3906 struct mlx5_pools_container *new_cont =
3907 MLX5_CNT_CONTAINER_UNUSED(priv->sh, batch, 0);
3908 struct mlx5_counter_stats_mem_mng *mem_mng;
3909 uint32_t resize = cont->n + MLX5_CNT_CONTAINER_RESIZE;
3910 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
3913 if (cont != MLX5_CNT_CONTAINER(priv->sh, batch, 1)) {
3914 /* The last resize still hasn't detected by the host thread. */
3918 new_cont->pools = rte_calloc(__func__, 1, mem_size, 0);
3919 if (!new_cont->pools) {
3924 memcpy(new_cont->pools, cont->pools, cont->n *
3925 sizeof(struct mlx5_flow_counter_pool *));
3926 mem_mng = flow_dv_create_counter_stat_mem_mng(dev,
3927 MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES);
3929 rte_free(new_cont->pools);
3932 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
3933 LIST_INSERT_HEAD(&priv->sh->cmng.free_stat_raws,
3934 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE +
3936 new_cont->n = resize;
3937 rte_atomic16_set(&new_cont->n_valid, rte_atomic16_read(&cont->n_valid));
3938 TAILQ_INIT(&new_cont->pool_list);
3939 TAILQ_CONCAT(&new_cont->pool_list, &cont->pool_list, next);
3940 new_cont->init_mem_mng = mem_mng;
3942 /* Flip the master container. */
3943 priv->sh->cmng.mhi[batch] ^= (uint8_t)1;
3948 * Query a devx flow counter.
3951 * Pointer to the Ethernet device structure.
3953 * Pointer to the flow counter.
3955 * The statistics value of packets.
3957 * The statistics value of bytes.
3960 * 0 on success, otherwise a negative errno value and rte_errno is set.
3963 _flow_dv_query_count(struct rte_eth_dev *dev,
3964 struct mlx5_flow_counter *cnt, uint64_t *pkts,
3967 struct mlx5_priv *priv = dev->data->dev_private;
3968 struct mlx5_flow_counter_pool *pool =
3969 flow_dv_counter_pool_get(cnt);
3970 int offset = cnt - &pool->counters_raw[0];
3972 if (priv->counter_fallback)
3973 return _flow_dv_query_count_fallback(dev, cnt, pkts, bytes);
3975 rte_spinlock_lock(&pool->sl);
3977 * The single counters allocation may allocate smaller ID than the
3978 * current allocated in parallel to the host reading.
3979 * In this case the new counter values must be reported as 0.
3981 if (unlikely(!cnt->batch && cnt->dcs->id < pool->raw->min_dcs_id)) {
3985 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
3986 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
3988 rte_spinlock_unlock(&pool->sl);
3993 * Create and initialize a new counter pool.
3996 * Pointer to the Ethernet device structure.
3998 * The devX counter handle.
4000 * Whether the pool is for counter that was allocated by batch command.
4003 * A new pool pointer on success, NULL otherwise and rte_errno is set.
4005 static struct mlx5_flow_counter_pool *
4006 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
4009 struct mlx5_priv *priv = dev->data->dev_private;
4010 struct mlx5_flow_counter_pool *pool;
4011 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4013 int16_t n_valid = rte_atomic16_read(&cont->n_valid);
4016 if (cont->n == n_valid) {
4017 cont = flow_dv_container_resize(dev, batch);
4021 size = sizeof(*pool) + MLX5_COUNTERS_PER_POOL *
4022 sizeof(struct mlx5_flow_counter);
4023 pool = rte_calloc(__func__, 1, size, 0);
4028 pool->min_dcs = dcs;
4029 pool->raw = cont->init_mem_mng->raws + n_valid %
4030 MLX5_CNT_CONTAINER_RESIZE;
4031 pool->raw_hw = NULL;
4032 rte_spinlock_init(&pool->sl);
4034 * The generation of the new allocated counters in this pool is 0, 2 in
4035 * the pool generation makes all the counters valid for allocation.
4037 rte_atomic64_set(&pool->query_gen, 0x2);
4038 TAILQ_INIT(&pool->counters);
4039 TAILQ_INSERT_TAIL(&cont->pool_list, pool, next);
4040 cont->pools[n_valid] = pool;
4041 /* Pool initialization must be updated before host thread access. */
4043 rte_atomic16_add(&cont->n_valid, 1);
4048 * Prepare a new counter and/or a new counter pool.
4051 * Pointer to the Ethernet device structure.
4052 * @param[out] cnt_free
4053 * Where to put the pointer of a new counter.
4055 * Whether the pool is for counter that was allocated by batch command.
4058 * The free counter pool pointer and @p cnt_free is set on success,
4059 * NULL otherwise and rte_errno is set.
4061 static struct mlx5_flow_counter_pool *
4062 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
4063 struct mlx5_flow_counter **cnt_free,
4066 struct mlx5_priv *priv = dev->data->dev_private;
4067 struct mlx5_flow_counter_pool *pool;
4068 struct mlx5_devx_obj *dcs = NULL;
4069 struct mlx5_flow_counter *cnt;
4073 /* bulk_bitmap must be 0 for single counter allocation. */
4074 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
4077 pool = flow_dv_find_pool_by_id
4078 (MLX5_CNT_CONTAINER(priv->sh, batch, 0), dcs->id);
4080 pool = flow_dv_pool_create(dev, dcs, batch);
4082 mlx5_devx_cmd_destroy(dcs);
4085 } else if (dcs->id < pool->min_dcs->id) {
4086 rte_atomic64_set(&pool->a64_dcs,
4087 (int64_t)(uintptr_t)dcs);
4089 cnt = &pool->counters_raw[dcs->id % MLX5_COUNTERS_PER_POOL];
4090 TAILQ_INSERT_HEAD(&pool->counters, cnt, next);
4095 /* bulk_bitmap is in 128 counters units. */
4096 if (priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4)
4097 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
4099 rte_errno = ENODATA;
4102 pool = flow_dv_pool_create(dev, dcs, batch);
4104 mlx5_devx_cmd_destroy(dcs);
4107 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
4108 cnt = &pool->counters_raw[i];
4110 TAILQ_INSERT_HEAD(&pool->counters, cnt, next);
4112 *cnt_free = &pool->counters_raw[0];
4117 * Search for existed shared counter.
4120 * Pointer to the relevant counter pool container.
4122 * The shared counter ID to search.
4125 * NULL if not existed, otherwise pointer to the shared counter.
4127 static struct mlx5_flow_counter *
4128 flow_dv_counter_shared_search(struct mlx5_pools_container *cont,
4131 static struct mlx5_flow_counter *cnt;
4132 struct mlx5_flow_counter_pool *pool;
4135 TAILQ_FOREACH(pool, &cont->pool_list, next) {
4136 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
4137 cnt = &pool->counters_raw[i];
4138 if (cnt->ref_cnt && cnt->shared && cnt->id == id)
4146 * Allocate a flow counter.
4149 * Pointer to the Ethernet device structure.
4151 * Indicate if this counter is shared with other flows.
4153 * Counter identifier.
4155 * Counter flow group.
4158 * pointer to flow counter on success, NULL otherwise and rte_errno is set.
4160 static struct mlx5_flow_counter *
4161 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
4164 struct mlx5_priv *priv = dev->data->dev_private;
4165 struct mlx5_flow_counter_pool *pool = NULL;
4166 struct mlx5_flow_counter *cnt_free = NULL;
4168 * Currently group 0 flow counter cannot be assigned to a flow if it is
4169 * not the first one in the batch counter allocation, so it is better
4170 * to allocate counters one by one for these flows in a separate
4172 * A counter can be shared between different groups so need to take
4173 * shared counters from the single container.
4175 uint32_t batch = (group && !shared) ? 1 : 0;
4176 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4179 if (priv->counter_fallback)
4180 return flow_dv_counter_alloc_fallback(dev, shared, id);
4181 if (!priv->config.devx) {
4182 rte_errno = ENOTSUP;
4186 cnt_free = flow_dv_counter_shared_search(cont, id);
4188 if (cnt_free->ref_cnt + 1 == 0) {
4192 cnt_free->ref_cnt++;
4196 /* Pools which has a free counters are in the start. */
4197 TAILQ_FOREACH(pool, &cont->pool_list, next) {
4199 * The free counter reset values must be updated between the
4200 * counter release to the counter allocation, so, at least one
4201 * query must be done in this time. ensure it by saving the
4202 * query generation in the release time.
4203 * The free list is sorted according to the generation - so if
4204 * the first one is not updated, all the others are not
4207 cnt_free = TAILQ_FIRST(&pool->counters);
4208 if (cnt_free && cnt_free->query_gen + 1 <
4209 rte_atomic64_read(&pool->query_gen))
4214 pool = flow_dv_counter_pool_prepare(dev, &cnt_free, batch);
4218 cnt_free->batch = batch;
4219 /* Create a DV counter action only in the first time usage. */
4220 if (!cnt_free->action) {
4222 struct mlx5_devx_obj *dcs;
4225 offset = cnt_free - &pool->counters_raw[0];
4226 dcs = pool->min_dcs;
4229 dcs = cnt_free->dcs;
4231 cnt_free->action = mlx5_glue->dv_create_flow_action_counter
4233 if (!cnt_free->action) {
4238 /* Update the counter reset values. */
4239 if (_flow_dv_query_count(dev, cnt_free, &cnt_free->hits,
4242 cnt_free->shared = shared;
4243 cnt_free->ref_cnt = 1;
4245 if (!priv->sh->cmng.query_thread_on)
4246 /* Start the asynchronous batch query by the host thread. */
4247 mlx5_set_query_alarm(priv->sh);
4248 TAILQ_REMOVE(&pool->counters, cnt_free, next);
4249 if (TAILQ_EMPTY(&pool->counters)) {
4250 /* Move the pool to the end of the container pool list. */
4251 TAILQ_REMOVE(&cont->pool_list, pool, next);
4252 TAILQ_INSERT_TAIL(&cont->pool_list, pool, next);
4258 * Release a flow counter.
4261 * Pointer to the Ethernet device structure.
4262 * @param[in] counter
4263 * Pointer to the counter handler.
4266 flow_dv_counter_release(struct rte_eth_dev *dev,
4267 struct mlx5_flow_counter *counter)
4269 struct mlx5_priv *priv = dev->data->dev_private;
4273 if (priv->counter_fallback) {
4274 flow_dv_counter_release_fallback(dev, counter);
4277 if (--counter->ref_cnt == 0) {
4278 struct mlx5_flow_counter_pool *pool =
4279 flow_dv_counter_pool_get(counter);
4281 /* Put the counter in the end - the last updated one. */
4282 TAILQ_INSERT_TAIL(&pool->counters, counter, next);
4283 counter->query_gen = rte_atomic64_read(&pool->query_gen);
4288 * Verify the @p attributes will be correctly understood by the NIC and store
4289 * them in the @p flow if everything is correct.
4292 * Pointer to dev struct.
4293 * @param[in] attributes
4294 * Pointer to flow attributes
4295 * @param[in] external
4296 * This flow rule is created by request external to PMD.
4298 * Pointer to error structure.
4301 * 0 on success, a negative errno value otherwise and rte_errno is set.
4304 flow_dv_validate_attributes(struct rte_eth_dev *dev,
4305 const struct rte_flow_attr *attributes,
4306 bool external __rte_unused,
4307 struct rte_flow_error *error)
4309 struct mlx5_priv *priv = dev->data->dev_private;
4310 uint32_t priority_max = priv->config.flow_prio - 1;
4312 #ifndef HAVE_MLX5DV_DR
4313 if (attributes->group)
4314 return rte_flow_error_set(error, ENOTSUP,
4315 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
4317 "groups are not supported");
4322 ret = mlx5_flow_group_to_table(attributes, external,
4328 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
4329 attributes->priority >= priority_max)
4330 return rte_flow_error_set(error, ENOTSUP,
4331 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
4333 "priority out of range");
4334 if (attributes->transfer) {
4335 if (!priv->config.dv_esw_en)
4336 return rte_flow_error_set
4338 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4339 "E-Switch dr is not supported");
4340 if (!(priv->representor || priv->master))
4341 return rte_flow_error_set
4342 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4343 NULL, "E-Switch configuration can only be"
4344 " done by a master or a representor device");
4345 if (attributes->egress)
4346 return rte_flow_error_set
4348 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
4349 "egress is not supported");
4351 if (!(attributes->egress ^ attributes->ingress))
4352 return rte_flow_error_set(error, ENOTSUP,
4353 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
4354 "must specify exactly one of "
4355 "ingress or egress");
4360 * Internal validation function. For validating both actions and items.
4363 * Pointer to the rte_eth_dev structure.
4365 * Pointer to the flow attributes.
4367 * Pointer to the list of items.
4368 * @param[in] actions
4369 * Pointer to the list of actions.
4370 * @param[in] external
4371 * This flow rule is created by request external to PMD.
4373 * Pointer to the error structure.
4376 * 0 on success, a negative errno value otherwise and rte_errno is set.
4379 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
4380 const struct rte_flow_item items[],
4381 const struct rte_flow_action actions[],
4382 bool external, struct rte_flow_error *error)
4385 uint64_t action_flags = 0;
4386 uint64_t item_flags = 0;
4387 uint64_t last_item = 0;
4388 uint8_t next_protocol = 0xff;
4389 uint16_t ether_type = 0;
4391 const struct rte_flow_item *gre_item = NULL;
4392 struct rte_flow_item_tcp nic_tcp_mask = {
4395 .src_port = RTE_BE16(UINT16_MAX),
4396 .dst_port = RTE_BE16(UINT16_MAX),
4399 struct mlx5_priv *priv = dev->data->dev_private;
4400 struct mlx5_dev_config *dev_conf = &priv->config;
4404 ret = flow_dv_validate_attributes(dev, attr, external, error);
4407 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4408 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
4409 int type = items->type;
4412 case RTE_FLOW_ITEM_TYPE_VOID:
4414 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4415 ret = flow_dv_validate_item_port_id
4416 (dev, items, attr, item_flags, error);
4419 last_item = MLX5_FLOW_ITEM_PORT_ID;
4421 case RTE_FLOW_ITEM_TYPE_ETH:
4422 ret = mlx5_flow_validate_item_eth(items, item_flags,
4426 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
4427 MLX5_FLOW_LAYER_OUTER_L2;
4428 if (items->mask != NULL && items->spec != NULL) {
4430 ((const struct rte_flow_item_eth *)
4433 ((const struct rte_flow_item_eth *)
4435 ether_type = rte_be_to_cpu_16(ether_type);
4440 case RTE_FLOW_ITEM_TYPE_VLAN:
4441 ret = mlx5_flow_validate_item_vlan(items, item_flags,
4445 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
4446 MLX5_FLOW_LAYER_OUTER_VLAN;
4447 if (items->mask != NULL && items->spec != NULL) {
4449 ((const struct rte_flow_item_vlan *)
4450 items->spec)->inner_type;
4452 ((const struct rte_flow_item_vlan *)
4453 items->mask)->inner_type;
4454 ether_type = rte_be_to_cpu_16(ether_type);
4459 case RTE_FLOW_ITEM_TYPE_IPV4:
4460 mlx5_flow_tunnel_ip_check(items, next_protocol,
4461 &item_flags, &tunnel);
4462 ret = mlx5_flow_validate_item_ipv4(items, item_flags,
4468 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4469 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4470 if (items->mask != NULL &&
4471 ((const struct rte_flow_item_ipv4 *)
4472 items->mask)->hdr.next_proto_id) {
4474 ((const struct rte_flow_item_ipv4 *)
4475 (items->spec))->hdr.next_proto_id;
4477 ((const struct rte_flow_item_ipv4 *)
4478 (items->mask))->hdr.next_proto_id;
4480 /* Reset for inner layer. */
4481 next_protocol = 0xff;
4484 case RTE_FLOW_ITEM_TYPE_IPV6:
4485 mlx5_flow_tunnel_ip_check(items, next_protocol,
4486 &item_flags, &tunnel);
4487 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
4493 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4494 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4495 if (items->mask != NULL &&
4496 ((const struct rte_flow_item_ipv6 *)
4497 items->mask)->hdr.proto) {
4499 ((const struct rte_flow_item_ipv6 *)
4500 items->spec)->hdr.proto;
4502 ((const struct rte_flow_item_ipv6 *)
4503 items->mask)->hdr.proto;
4505 /* Reset for inner layer. */
4506 next_protocol = 0xff;
4509 case RTE_FLOW_ITEM_TYPE_TCP:
4510 ret = mlx5_flow_validate_item_tcp
4517 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
4518 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4520 case RTE_FLOW_ITEM_TYPE_UDP:
4521 ret = mlx5_flow_validate_item_udp(items, item_flags,
4526 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
4527 MLX5_FLOW_LAYER_OUTER_L4_UDP;
4529 case RTE_FLOW_ITEM_TYPE_GRE:
4530 ret = mlx5_flow_validate_item_gre(items, item_flags,
4531 next_protocol, error);
4535 last_item = MLX5_FLOW_LAYER_GRE;
4537 case RTE_FLOW_ITEM_TYPE_NVGRE:
4538 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
4543 last_item = MLX5_FLOW_LAYER_NVGRE;
4545 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
4546 ret = mlx5_flow_validate_item_gre_key
4547 (items, item_flags, gre_item, error);
4550 last_item = MLX5_FLOW_LAYER_GRE_KEY;
4552 case RTE_FLOW_ITEM_TYPE_VXLAN:
4553 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
4557 last_item = MLX5_FLOW_LAYER_VXLAN;
4559 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4560 ret = mlx5_flow_validate_item_vxlan_gpe(items,
4565 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
4567 case RTE_FLOW_ITEM_TYPE_GENEVE:
4568 ret = mlx5_flow_validate_item_geneve(items,
4573 last_item = MLX5_FLOW_LAYER_GENEVE;
4575 case RTE_FLOW_ITEM_TYPE_MPLS:
4576 ret = mlx5_flow_validate_item_mpls(dev, items,
4581 last_item = MLX5_FLOW_LAYER_MPLS;
4584 case RTE_FLOW_ITEM_TYPE_MARK:
4585 ret = flow_dv_validate_item_mark(dev, items, attr,
4589 last_item = MLX5_FLOW_ITEM_MARK;
4591 case RTE_FLOW_ITEM_TYPE_META:
4592 ret = flow_dv_validate_item_meta(dev, items, attr,
4596 last_item = MLX5_FLOW_ITEM_METADATA;
4598 case RTE_FLOW_ITEM_TYPE_ICMP:
4599 ret = mlx5_flow_validate_item_icmp(items, item_flags,
4604 last_item = MLX5_FLOW_LAYER_ICMP;
4606 case RTE_FLOW_ITEM_TYPE_ICMP6:
4607 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
4612 last_item = MLX5_FLOW_LAYER_ICMP6;
4614 case RTE_FLOW_ITEM_TYPE_TAG:
4615 ret = flow_dv_validate_item_tag(dev, items,
4619 last_item = MLX5_FLOW_ITEM_TAG;
4621 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
4622 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
4625 return rte_flow_error_set(error, ENOTSUP,
4626 RTE_FLOW_ERROR_TYPE_ITEM,
4627 NULL, "item not supported");
4629 item_flags |= last_item;
4631 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4632 int type = actions->type;
4633 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
4634 return rte_flow_error_set(error, ENOTSUP,
4635 RTE_FLOW_ERROR_TYPE_ACTION,
4636 actions, "too many actions");
4638 case RTE_FLOW_ACTION_TYPE_VOID:
4640 case RTE_FLOW_ACTION_TYPE_PORT_ID:
4641 ret = flow_dv_validate_action_port_id(dev,
4648 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
4651 case RTE_FLOW_ACTION_TYPE_FLAG:
4652 ret = flow_dv_validate_action_flag(dev, action_flags,
4656 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
4657 /* Count all modify-header actions as one. */
4658 if (!(action_flags &
4659 MLX5_FLOW_MODIFY_HDR_ACTIONS))
4661 action_flags |= MLX5_FLOW_ACTION_FLAG |
4662 MLX5_FLOW_ACTION_MARK_EXT;
4664 action_flags |= MLX5_FLOW_ACTION_FLAG;
4668 case RTE_FLOW_ACTION_TYPE_MARK:
4669 ret = flow_dv_validate_action_mark(dev, actions,
4674 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
4675 /* Count all modify-header actions as one. */
4676 if (!(action_flags &
4677 MLX5_FLOW_MODIFY_HDR_ACTIONS))
4679 action_flags |= MLX5_FLOW_ACTION_MARK |
4680 MLX5_FLOW_ACTION_MARK_EXT;
4682 action_flags |= MLX5_FLOW_ACTION_MARK;
4686 case RTE_FLOW_ACTION_TYPE_SET_META:
4687 ret = flow_dv_validate_action_set_meta(dev, actions,
4692 /* Count all modify-header actions as one action. */
4693 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4695 action_flags |= MLX5_FLOW_ACTION_SET_META;
4697 case RTE_FLOW_ACTION_TYPE_SET_TAG:
4698 ret = flow_dv_validate_action_set_tag(dev, actions,
4703 /* Count all modify-header actions as one action. */
4704 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4706 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
4708 case RTE_FLOW_ACTION_TYPE_DROP:
4709 ret = mlx5_flow_validate_action_drop(action_flags,
4713 action_flags |= MLX5_FLOW_ACTION_DROP;
4716 case RTE_FLOW_ACTION_TYPE_QUEUE:
4717 ret = mlx5_flow_validate_action_queue(actions,
4722 action_flags |= MLX5_FLOW_ACTION_QUEUE;
4725 case RTE_FLOW_ACTION_TYPE_RSS:
4726 ret = mlx5_flow_validate_action_rss(actions,
4732 action_flags |= MLX5_FLOW_ACTION_RSS;
4735 case RTE_FLOW_ACTION_TYPE_COUNT:
4736 ret = flow_dv_validate_action_count(dev, error);
4739 action_flags |= MLX5_FLOW_ACTION_COUNT;
4742 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
4743 if (flow_dv_validate_action_pop_vlan(dev,
4749 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
4752 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4753 ret = flow_dv_validate_action_push_vlan(action_flags,
4759 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
4762 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4763 ret = flow_dv_validate_action_set_vlan_pcp
4764 (action_flags, actions, error);
4767 /* Count PCP with push_vlan command. */
4768 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
4770 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4771 ret = flow_dv_validate_action_set_vlan_vid
4772 (item_flags, action_flags,
4776 /* Count VID with push_vlan command. */
4777 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
4779 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4780 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4781 ret = flow_dv_validate_action_l2_encap(action_flags,
4786 action_flags |= actions->type ==
4787 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ?
4788 MLX5_FLOW_ACTION_VXLAN_ENCAP :
4789 MLX5_FLOW_ACTION_NVGRE_ENCAP;
4792 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4793 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4794 ret = flow_dv_validate_action_l2_decap(action_flags,
4798 action_flags |= actions->type ==
4799 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ?
4800 MLX5_FLOW_ACTION_VXLAN_DECAP :
4801 MLX5_FLOW_ACTION_NVGRE_DECAP;
4804 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4805 ret = flow_dv_validate_action_raw_encap(action_flags,
4810 action_flags |= MLX5_FLOW_ACTION_RAW_ENCAP;
4813 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4814 ret = flow_dv_validate_action_raw_decap(action_flags,
4819 action_flags |= MLX5_FLOW_ACTION_RAW_DECAP;
4822 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4823 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4824 ret = flow_dv_validate_action_modify_mac(action_flags,
4830 /* Count all modify-header actions as one action. */
4831 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4833 action_flags |= actions->type ==
4834 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
4835 MLX5_FLOW_ACTION_SET_MAC_SRC :
4836 MLX5_FLOW_ACTION_SET_MAC_DST;
4839 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4840 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4841 ret = flow_dv_validate_action_modify_ipv4(action_flags,
4847 /* Count all modify-header actions as one action. */
4848 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4850 action_flags |= actions->type ==
4851 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
4852 MLX5_FLOW_ACTION_SET_IPV4_SRC :
4853 MLX5_FLOW_ACTION_SET_IPV4_DST;
4855 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4856 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4857 ret = flow_dv_validate_action_modify_ipv6(action_flags,
4863 /* Count all modify-header actions as one action. */
4864 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4866 action_flags |= actions->type ==
4867 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
4868 MLX5_FLOW_ACTION_SET_IPV6_SRC :
4869 MLX5_FLOW_ACTION_SET_IPV6_DST;
4871 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4872 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4873 ret = flow_dv_validate_action_modify_tp(action_flags,
4879 /* Count all modify-header actions as one action. */
4880 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4882 action_flags |= actions->type ==
4883 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
4884 MLX5_FLOW_ACTION_SET_TP_SRC :
4885 MLX5_FLOW_ACTION_SET_TP_DST;
4887 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4888 case RTE_FLOW_ACTION_TYPE_SET_TTL:
4889 ret = flow_dv_validate_action_modify_ttl(action_flags,
4895 /* Count all modify-header actions as one action. */
4896 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4898 action_flags |= actions->type ==
4899 RTE_FLOW_ACTION_TYPE_SET_TTL ?
4900 MLX5_FLOW_ACTION_SET_TTL :
4901 MLX5_FLOW_ACTION_DEC_TTL;
4903 case RTE_FLOW_ACTION_TYPE_JUMP:
4904 ret = flow_dv_validate_action_jump(actions,
4911 action_flags |= MLX5_FLOW_ACTION_JUMP;
4913 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4914 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4915 ret = flow_dv_validate_action_modify_tcp_seq
4922 /* Count all modify-header actions as one action. */
4923 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4925 action_flags |= actions->type ==
4926 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
4927 MLX5_FLOW_ACTION_INC_TCP_SEQ :
4928 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
4930 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4931 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4932 ret = flow_dv_validate_action_modify_tcp_ack
4939 /* Count all modify-header actions as one action. */
4940 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4942 action_flags |= actions->type ==
4943 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
4944 MLX5_FLOW_ACTION_INC_TCP_ACK :
4945 MLX5_FLOW_ACTION_DEC_TCP_ACK;
4947 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
4948 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
4949 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
4951 case RTE_FLOW_ACTION_TYPE_METER:
4952 ret = mlx5_flow_validate_action_meter(dev,
4958 action_flags |= MLX5_FLOW_ACTION_METER;
4961 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4962 ret = flow_dv_validate_action_modify_ipv4_dscp
4969 /* Count all modify-header actions as one action. */
4970 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4972 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
4974 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4975 ret = flow_dv_validate_action_modify_ipv6_dscp
4982 /* Count all modify-header actions as one action. */
4983 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4985 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
4988 return rte_flow_error_set(error, ENOTSUP,
4989 RTE_FLOW_ERROR_TYPE_ACTION,
4991 "action not supported");
4994 if ((action_flags & MLX5_FLOW_LAYER_TUNNEL) &&
4995 (action_flags & MLX5_FLOW_VLAN_ACTIONS))
4996 return rte_flow_error_set(error, ENOTSUP,
4997 RTE_FLOW_ERROR_TYPE_ACTION,
4999 "can't have vxlan and vlan"
5000 " actions in the same rule");
5001 /* Eswitch has few restrictions on using items and actions */
5002 if (attr->transfer) {
5003 if (!mlx5_flow_ext_mreg_supported(dev) &&
5004 action_flags & MLX5_FLOW_ACTION_FLAG)
5005 return rte_flow_error_set(error, ENOTSUP,
5006 RTE_FLOW_ERROR_TYPE_ACTION,
5008 "unsupported action FLAG");
5009 if (!mlx5_flow_ext_mreg_supported(dev) &&
5010 action_flags & MLX5_FLOW_ACTION_MARK)
5011 return rte_flow_error_set(error, ENOTSUP,
5012 RTE_FLOW_ERROR_TYPE_ACTION,
5014 "unsupported action MARK");
5015 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
5016 return rte_flow_error_set(error, ENOTSUP,
5017 RTE_FLOW_ERROR_TYPE_ACTION,
5019 "unsupported action QUEUE");
5020 if (action_flags & MLX5_FLOW_ACTION_RSS)
5021 return rte_flow_error_set(error, ENOTSUP,
5022 RTE_FLOW_ERROR_TYPE_ACTION,
5024 "unsupported action RSS");
5025 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5026 return rte_flow_error_set(error, EINVAL,
5027 RTE_FLOW_ERROR_TYPE_ACTION,
5029 "no fate action is found");
5031 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
5032 return rte_flow_error_set(error, EINVAL,
5033 RTE_FLOW_ERROR_TYPE_ACTION,
5035 "no fate action is found");
5041 * Internal preparation function. Allocates the DV flow size,
5042 * this size is constant.
5045 * Pointer to the flow attributes.
5047 * Pointer to the list of items.
5048 * @param[in] actions
5049 * Pointer to the list of actions.
5051 * Pointer to the error structure.
5054 * Pointer to mlx5_flow object on success,
5055 * otherwise NULL and rte_errno is set.
5057 static struct mlx5_flow *
5058 flow_dv_prepare(const struct rte_flow_attr *attr __rte_unused,
5059 const struct rte_flow_item items[] __rte_unused,
5060 const struct rte_flow_action actions[] __rte_unused,
5061 struct rte_flow_error *error)
5063 size_t size = sizeof(struct mlx5_flow);
5064 struct mlx5_flow *dev_flow;
5066 dev_flow = rte_calloc(__func__, 1, size, 0);
5068 rte_flow_error_set(error, ENOMEM,
5069 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5070 "not enough memory to create flow");
5073 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
5074 dev_flow->ingress = attr->ingress;
5075 dev_flow->transfer = attr->transfer;
5081 * Sanity check for match mask and value. Similar to check_valid_spec() in
5082 * kernel driver. If unmasked bit is present in value, it returns failure.
5085 * pointer to match mask buffer.
5086 * @param match_value
5087 * pointer to match value buffer.
5090 * 0 if valid, -EINVAL otherwise.
5093 flow_dv_check_valid_spec(void *match_mask, void *match_value)
5095 uint8_t *m = match_mask;
5096 uint8_t *v = match_value;
5099 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
5102 "match_value differs from match_criteria"
5103 " %p[%u] != %p[%u]",
5104 match_value, i, match_mask, i);
5113 * Add Ethernet item to matcher and to the value.
5115 * @param[in, out] matcher
5117 * @param[in, out] key
5118 * Flow matcher value.
5120 * Flow pattern to translate.
5122 * Item is inner pattern.
5125 flow_dv_translate_item_eth(void *matcher, void *key,
5126 const struct rte_flow_item *item, int inner)
5128 const struct rte_flow_item_eth *eth_m = item->mask;
5129 const struct rte_flow_item_eth *eth_v = item->spec;
5130 const struct rte_flow_item_eth nic_mask = {
5131 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
5132 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
5133 .type = RTE_BE16(0xffff),
5145 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5147 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5149 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5151 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5153 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, dmac_47_16),
5154 ð_m->dst, sizeof(eth_m->dst));
5155 /* The value must be in the range of the mask. */
5156 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, dmac_47_16);
5157 for (i = 0; i < sizeof(eth_m->dst); ++i)
5158 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
5159 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, smac_47_16),
5160 ð_m->src, sizeof(eth_m->src));
5161 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, smac_47_16);
5162 /* The value must be in the range of the mask. */
5163 for (i = 0; i < sizeof(eth_m->dst); ++i)
5164 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
5165 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
5166 rte_be_to_cpu_16(eth_m->type));
5167 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, ethertype);
5168 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
5172 * Add VLAN item to matcher and to the value.
5174 * @param[in, out] dev_flow
5176 * @param[in, out] matcher
5178 * @param[in, out] key
5179 * Flow matcher value.
5181 * Flow pattern to translate.
5183 * Item is inner pattern.
5186 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
5187 void *matcher, void *key,
5188 const struct rte_flow_item *item,
5191 const struct rte_flow_item_vlan *vlan_m = item->mask;
5192 const struct rte_flow_item_vlan *vlan_v = item->spec;
5201 vlan_m = &rte_flow_item_vlan_mask;
5203 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5205 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5207 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5209 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5211 * This is workaround, masks are not supported,
5212 * and pre-validated.
5214 dev_flow->dv.vf_vlan.tag =
5215 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
5217 tci_m = rte_be_to_cpu_16(vlan_m->tci);
5218 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
5219 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5220 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
5221 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_vid, tci_m);
5222 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, tci_v);
5223 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_cfi, tci_m >> 12);
5224 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_cfi, tci_v >> 12);
5225 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_prio, tci_m >> 13);
5226 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, tci_v >> 13);
5227 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
5228 rte_be_to_cpu_16(vlan_m->inner_type));
5229 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
5230 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
5234 * Add IPV4 item to matcher and to the value.
5236 * @param[in, out] matcher
5238 * @param[in, out] key
5239 * Flow matcher value.
5241 * Flow pattern to translate.
5243 * Item is inner pattern.
5245 * The group to insert the rule.
5248 flow_dv_translate_item_ipv4(void *matcher, void *key,
5249 const struct rte_flow_item *item,
5250 int inner, uint32_t group)
5252 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
5253 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
5254 const struct rte_flow_item_ipv4 nic_mask = {
5256 .src_addr = RTE_BE32(0xffffffff),
5257 .dst_addr = RTE_BE32(0xffffffff),
5258 .type_of_service = 0xff,
5259 .next_proto_id = 0xff,
5269 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5271 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5273 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5275 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5278 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
5280 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0x4);
5281 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 4);
5286 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5287 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
5288 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5289 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
5290 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
5291 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
5292 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5293 src_ipv4_src_ipv6.ipv4_layout.ipv4);
5294 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5295 src_ipv4_src_ipv6.ipv4_layout.ipv4);
5296 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
5297 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
5298 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
5299 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
5300 ipv4_m->hdr.type_of_service);
5301 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
5302 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
5303 ipv4_m->hdr.type_of_service >> 2);
5304 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
5305 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
5306 ipv4_m->hdr.next_proto_id);
5307 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
5308 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
5312 * Add IPV6 item to matcher and to the value.
5314 * @param[in, out] matcher
5316 * @param[in, out] key
5317 * Flow matcher value.
5319 * Flow pattern to translate.
5321 * Item is inner pattern.
5323 * The group to insert the rule.
5326 flow_dv_translate_item_ipv6(void *matcher, void *key,
5327 const struct rte_flow_item *item,
5328 int inner, uint32_t group)
5330 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
5331 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
5332 const struct rte_flow_item_ipv6 nic_mask = {
5335 "\xff\xff\xff\xff\xff\xff\xff\xff"
5336 "\xff\xff\xff\xff\xff\xff\xff\xff",
5338 "\xff\xff\xff\xff\xff\xff\xff\xff"
5339 "\xff\xff\xff\xff\xff\xff\xff\xff",
5340 .vtc_flow = RTE_BE32(0xffffffff),
5347 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5348 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5357 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5359 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5361 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5363 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5366 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
5368 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0x6);
5369 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 6);
5374 size = sizeof(ipv6_m->hdr.dst_addr);
5375 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5376 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
5377 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5378 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
5379 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
5380 for (i = 0; i < size; ++i)
5381 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
5382 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5383 src_ipv4_src_ipv6.ipv6_layout.ipv6);
5384 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5385 src_ipv4_src_ipv6.ipv6_layout.ipv6);
5386 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
5387 for (i = 0; i < size; ++i)
5388 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
5390 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
5391 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
5392 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
5393 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
5394 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
5395 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
5398 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
5400 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
5403 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
5405 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
5409 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
5411 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
5412 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
5416 * Add TCP item to matcher and to the value.
5418 * @param[in, out] matcher
5420 * @param[in, out] key
5421 * Flow matcher value.
5423 * Flow pattern to translate.
5425 * Item is inner pattern.
5428 flow_dv_translate_item_tcp(void *matcher, void *key,
5429 const struct rte_flow_item *item,
5432 const struct rte_flow_item_tcp *tcp_m = item->mask;
5433 const struct rte_flow_item_tcp *tcp_v = item->spec;
5438 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5440 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5442 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5444 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5446 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5447 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
5451 tcp_m = &rte_flow_item_tcp_mask;
5452 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
5453 rte_be_to_cpu_16(tcp_m->hdr.src_port));
5454 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
5455 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
5456 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
5457 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
5458 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
5459 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
5460 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
5461 tcp_m->hdr.tcp_flags);
5462 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
5463 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
5467 * Add UDP item to matcher and to the value.
5469 * @param[in, out] matcher
5471 * @param[in, out] key
5472 * Flow matcher value.
5474 * Flow pattern to translate.
5476 * Item is inner pattern.
5479 flow_dv_translate_item_udp(void *matcher, void *key,
5480 const struct rte_flow_item *item,
5483 const struct rte_flow_item_udp *udp_m = item->mask;
5484 const struct rte_flow_item_udp *udp_v = item->spec;
5489 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5491 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5493 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5495 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5497 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5498 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
5502 udp_m = &rte_flow_item_udp_mask;
5503 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
5504 rte_be_to_cpu_16(udp_m->hdr.src_port));
5505 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
5506 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
5507 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
5508 rte_be_to_cpu_16(udp_m->hdr.dst_port));
5509 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
5510 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
5514 * Add GRE optional Key item to matcher and to the value.
5516 * @param[in, out] matcher
5518 * @param[in, out] key
5519 * Flow matcher value.
5521 * Flow pattern to translate.
5523 * Item is inner pattern.
5526 flow_dv_translate_item_gre_key(void *matcher, void *key,
5527 const struct rte_flow_item *item)
5529 const rte_be32_t *key_m = item->mask;
5530 const rte_be32_t *key_v = item->spec;
5531 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5532 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5533 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
5538 key_m = &gre_key_default_mask;
5539 /* GRE K bit must be on and should already be validated */
5540 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
5541 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
5542 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
5543 rte_be_to_cpu_32(*key_m) >> 8);
5544 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
5545 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
5546 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
5547 rte_be_to_cpu_32(*key_m) & 0xFF);
5548 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
5549 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
5553 * Add GRE item to matcher and to the value.
5555 * @param[in, out] matcher
5557 * @param[in, out] key
5558 * Flow matcher value.
5560 * Flow pattern to translate.
5562 * Item is inner pattern.
5565 flow_dv_translate_item_gre(void *matcher, void *key,
5566 const struct rte_flow_item *item,
5569 const struct rte_flow_item_gre *gre_m = item->mask;
5570 const struct rte_flow_item_gre *gre_v = item->spec;
5573 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5574 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5581 uint16_t s_present:1;
5582 uint16_t k_present:1;
5583 uint16_t rsvd_bit1:1;
5584 uint16_t c_present:1;
5588 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
5591 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5593 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5595 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5597 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5599 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5600 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
5604 gre_m = &rte_flow_item_gre_mask;
5605 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
5606 rte_be_to_cpu_16(gre_m->protocol));
5607 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
5608 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
5609 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
5610 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
5611 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
5612 gre_crks_rsvd0_ver_m.c_present);
5613 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
5614 gre_crks_rsvd0_ver_v.c_present &
5615 gre_crks_rsvd0_ver_m.c_present);
5616 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
5617 gre_crks_rsvd0_ver_m.k_present);
5618 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
5619 gre_crks_rsvd0_ver_v.k_present &
5620 gre_crks_rsvd0_ver_m.k_present);
5621 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
5622 gre_crks_rsvd0_ver_m.s_present);
5623 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
5624 gre_crks_rsvd0_ver_v.s_present &
5625 gre_crks_rsvd0_ver_m.s_present);
5629 * Add NVGRE item to matcher and to the value.
5631 * @param[in, out] matcher
5633 * @param[in, out] key
5634 * Flow matcher value.
5636 * Flow pattern to translate.
5638 * Item is inner pattern.
5641 flow_dv_translate_item_nvgre(void *matcher, void *key,
5642 const struct rte_flow_item *item,
5645 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
5646 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
5647 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5648 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5649 const char *tni_flow_id_m = (const char *)nvgre_m->tni;
5650 const char *tni_flow_id_v = (const char *)nvgre_v->tni;
5656 /* For NVGRE, GRE header fields must be set with defined values. */
5657 const struct rte_flow_item_gre gre_spec = {
5658 .c_rsvd0_ver = RTE_BE16(0x2000),
5659 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
5661 const struct rte_flow_item_gre gre_mask = {
5662 .c_rsvd0_ver = RTE_BE16(0xB000),
5663 .protocol = RTE_BE16(UINT16_MAX),
5665 const struct rte_flow_item gre_item = {
5670 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
5674 nvgre_m = &rte_flow_item_nvgre_mask;
5675 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
5676 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
5677 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
5678 memcpy(gre_key_m, tni_flow_id_m, size);
5679 for (i = 0; i < size; ++i)
5680 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
5684 * Add VXLAN item to matcher and to the value.
5686 * @param[in, out] matcher
5688 * @param[in, out] key
5689 * Flow matcher value.
5691 * Flow pattern to translate.
5693 * Item is inner pattern.
5696 flow_dv_translate_item_vxlan(void *matcher, void *key,
5697 const struct rte_flow_item *item,
5700 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
5701 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
5704 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5705 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5713 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5715 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5717 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5719 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5721 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
5722 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
5723 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
5724 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
5725 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
5730 vxlan_m = &rte_flow_item_vxlan_mask;
5731 size = sizeof(vxlan_m->vni);
5732 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
5733 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
5734 memcpy(vni_m, vxlan_m->vni, size);
5735 for (i = 0; i < size; ++i)
5736 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
5740 * Add Geneve item to matcher and to the value.
5742 * @param[in, out] matcher
5744 * @param[in, out] key
5745 * Flow matcher value.
5747 * Flow pattern to translate.
5749 * Item is inner pattern.
5753 flow_dv_translate_item_geneve(void *matcher, void *key,
5754 const struct rte_flow_item *item, int inner)
5756 const struct rte_flow_item_geneve *geneve_m = item->mask;
5757 const struct rte_flow_item_geneve *geneve_v = item->spec;
5760 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5761 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5770 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5772 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5774 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5776 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5778 dport = MLX5_UDP_PORT_GENEVE;
5779 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
5780 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
5781 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
5786 geneve_m = &rte_flow_item_geneve_mask;
5787 size = sizeof(geneve_m->vni);
5788 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
5789 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
5790 memcpy(vni_m, geneve_m->vni, size);
5791 for (i = 0; i < size; ++i)
5792 vni_v[i] = vni_m[i] & geneve_v->vni[i];
5793 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
5794 rte_be_to_cpu_16(geneve_m->protocol));
5795 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
5796 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
5797 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
5798 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
5799 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
5800 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
5801 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
5802 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
5803 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
5804 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
5805 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
5806 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
5807 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
5811 * Add MPLS item to matcher and to the value.
5813 * @param[in, out] matcher
5815 * @param[in, out] key
5816 * Flow matcher value.
5818 * Flow pattern to translate.
5819 * @param[in] prev_layer
5820 * The protocol layer indicated in previous item.
5822 * Item is inner pattern.
5825 flow_dv_translate_item_mpls(void *matcher, void *key,
5826 const struct rte_flow_item *item,
5827 uint64_t prev_layer,
5830 const uint32_t *in_mpls_m = item->mask;
5831 const uint32_t *in_mpls_v = item->spec;
5832 uint32_t *out_mpls_m = 0;
5833 uint32_t *out_mpls_v = 0;
5834 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5835 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5836 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
5838 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
5839 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
5840 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5842 switch (prev_layer) {
5843 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
5844 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
5845 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
5846 MLX5_UDP_PORT_MPLS);
5848 case MLX5_FLOW_LAYER_GRE:
5849 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
5850 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
5851 RTE_ETHER_TYPE_MPLS);
5854 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5855 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
5862 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
5863 switch (prev_layer) {
5864 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
5866 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
5867 outer_first_mpls_over_udp);
5869 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
5870 outer_first_mpls_over_udp);
5872 case MLX5_FLOW_LAYER_GRE:
5874 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
5875 outer_first_mpls_over_gre);
5877 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
5878 outer_first_mpls_over_gre);
5881 /* Inner MPLS not over GRE is not supported. */
5884 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
5888 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
5894 if (out_mpls_m && out_mpls_v) {
5895 *out_mpls_m = *in_mpls_m;
5896 *out_mpls_v = *in_mpls_v & *in_mpls_m;
5901 * Add metadata register item to matcher
5903 * @param[in, out] matcher
5905 * @param[in, out] key
5906 * Flow matcher value.
5907 * @param[in] reg_type
5908 * Type of device metadata register
5915 flow_dv_match_meta_reg(void *matcher, void *key,
5916 enum modify_reg reg_type,
5917 uint32_t data, uint32_t mask)
5920 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
5922 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
5928 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
5929 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
5932 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
5933 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
5937 * The metadata register C0 field might be divided into
5938 * source vport index and META item value, we should set
5939 * this field according to specified mask, not as whole one.
5941 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
5943 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
5944 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
5947 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
5950 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
5951 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
5954 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
5955 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
5958 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
5959 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
5962 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
5963 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
5966 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
5967 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
5970 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
5971 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
5974 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
5975 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
5984 * Add MARK item to matcher
5987 * The device to configure through.
5988 * @param[in, out] matcher
5990 * @param[in, out] key
5991 * Flow matcher value.
5993 * Flow pattern to translate.
5996 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
5997 void *matcher, void *key,
5998 const struct rte_flow_item *item)
6000 struct mlx5_priv *priv = dev->data->dev_private;
6001 const struct rte_flow_item_mark *mark;
6005 mark = item->mask ? (const void *)item->mask :
6006 &rte_flow_item_mark_mask;
6007 mask = mark->id & priv->sh->dv_mark_mask;
6008 mark = (const void *)item->spec;
6010 value = mark->id & priv->sh->dv_mark_mask & mask;
6012 enum modify_reg reg;
6014 /* Get the metadata register index for the mark. */
6015 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
6017 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6022 * Add META item to matcher
6025 * The devich to configure through.
6026 * @param[in, out] matcher
6028 * @param[in, out] key
6029 * Flow matcher value.
6031 * Attributes of flow that includes this item.
6033 * Flow pattern to translate.
6036 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
6037 void *matcher, void *key,
6038 const struct rte_flow_attr *attr,
6039 const struct rte_flow_item *item)
6041 const struct rte_flow_item_meta *meta_m;
6042 const struct rte_flow_item_meta *meta_v;
6044 meta_m = (const void *)item->mask;
6046 meta_m = &rte_flow_item_meta_mask;
6047 meta_v = (const void *)item->spec;
6049 enum modify_reg reg;
6050 uint32_t value = meta_v->data;
6051 uint32_t mask = meta_m->data;
6053 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
6057 * In datapath code there is no endianness
6058 * coversions for perfromance reasons, all
6059 * pattern conversions are done in rte_flow.
6061 value = rte_cpu_to_be_32(value);
6062 mask = rte_cpu_to_be_32(mask);
6063 if (reg == REG_C_0) {
6064 struct mlx5_priv *priv = dev->data->dev_private;
6065 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6066 uint32_t shl_c0 = rte_bsf32(msk_c0);
6068 msk_c0 = rte_cpu_to_be_32(msk_c0);
6072 assert(!(~msk_c0 & mask));
6074 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6079 * Add vport metadata Reg C0 item to matcher
6081 * @param[in, out] matcher
6083 * @param[in, out] key
6084 * Flow matcher value.
6086 * Flow pattern to translate.
6089 flow_dv_translate_item_meta_vport(void *matcher, void *key,
6090 uint32_t value, uint32_t mask)
6092 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
6096 * Add tag item to matcher
6098 * @param[in, out] matcher
6100 * @param[in, out] key
6101 * Flow matcher value.
6103 * Flow pattern to translate.
6106 flow_dv_translate_mlx5_item_tag(void *matcher, void *key,
6107 const struct rte_flow_item *item)
6109 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
6110 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
6113 flow_dv_match_meta_reg(matcher, key, tag_v->id, tag_v->data,
6114 tag_m ? tag_m->data : UINT32_MAX);
6118 * Add TAG item to matcher
6121 * The devich to configure through.
6122 * @param[in, out] matcher
6124 * @param[in, out] key
6125 * Flow matcher value.
6127 * Flow pattern to translate.
6130 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
6131 void *matcher, void *key,
6132 const struct rte_flow_item *item)
6134 const struct rte_flow_item_tag *tag_v = item->spec;
6135 const struct rte_flow_item_tag *tag_m = item->mask;
6136 enum modify_reg reg;
6139 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
6140 /* Get the metadata register index for the tag. */
6141 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
6143 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
6147 * Add source vport match to the specified matcher.
6149 * @param[in, out] matcher
6151 * @param[in, out] key
6152 * Flow matcher value.
6154 * Source vport value to match
6159 flow_dv_translate_item_source_vport(void *matcher, void *key,
6160 int16_t port, uint16_t mask)
6162 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6163 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6165 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
6166 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
6170 * Translate port-id item to eswitch match on port-id.
6173 * The devich to configure through.
6174 * @param[in, out] matcher
6176 * @param[in, out] key
6177 * Flow matcher value.
6179 * Flow pattern to translate.
6182 * 0 on success, a negative errno value otherwise.
6185 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
6186 void *key, const struct rte_flow_item *item)
6188 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
6189 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
6190 struct mlx5_priv *priv;
6193 mask = pid_m ? pid_m->id : 0xffff;
6194 id = pid_v ? pid_v->id : dev->data->port_id;
6195 priv = mlx5_port_to_eswitch_info(id, item == NULL);
6198 /* Translate to vport field or to metadata, depending on mode. */
6199 if (priv->vport_meta_mask)
6200 flow_dv_translate_item_meta_vport(matcher, key,
6201 priv->vport_meta_tag,
6202 priv->vport_meta_mask);
6204 flow_dv_translate_item_source_vport(matcher, key,
6205 priv->vport_id, mask);
6210 * Add ICMP6 item to matcher and to the value.
6212 * @param[in, out] matcher
6214 * @param[in, out] key
6215 * Flow matcher value.
6217 * Flow pattern to translate.
6219 * Item is inner pattern.
6222 flow_dv_translate_item_icmp6(void *matcher, void *key,
6223 const struct rte_flow_item *item,
6226 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
6227 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
6230 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
6232 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6234 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6236 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6238 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6240 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6242 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
6243 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
6247 icmp6_m = &rte_flow_item_icmp6_mask;
6248 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
6249 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
6250 icmp6_v->type & icmp6_m->type);
6251 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
6252 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
6253 icmp6_v->code & icmp6_m->code);
6257 * Add ICMP item to matcher and to the value.
6259 * @param[in, out] matcher
6261 * @param[in, out] key
6262 * Flow matcher value.
6264 * Flow pattern to translate.
6266 * Item is inner pattern.
6269 flow_dv_translate_item_icmp(void *matcher, void *key,
6270 const struct rte_flow_item *item,
6273 const struct rte_flow_item_icmp *icmp_m = item->mask;
6274 const struct rte_flow_item_icmp *icmp_v = item->spec;
6277 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
6279 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6281 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6283 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6285 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6287 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6289 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
6290 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
6294 icmp_m = &rte_flow_item_icmp_mask;
6295 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
6296 icmp_m->hdr.icmp_type);
6297 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
6298 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
6299 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
6300 icmp_m->hdr.icmp_code);
6301 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
6302 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
6305 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
6307 #define HEADER_IS_ZERO(match_criteria, headers) \
6308 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
6309 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
6312 * Calculate flow matcher enable bitmap.
6314 * @param match_criteria
6315 * Pointer to flow matcher criteria.
6318 * Bitmap of enabled fields.
6321 flow_dv_matcher_enable(uint32_t *match_criteria)
6323 uint8_t match_criteria_enable;
6325 match_criteria_enable =
6326 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
6327 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
6328 match_criteria_enable |=
6329 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
6330 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
6331 match_criteria_enable |=
6332 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
6333 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
6334 match_criteria_enable |=
6335 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
6336 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
6337 match_criteria_enable |=
6338 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
6339 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
6340 return match_criteria_enable;
6347 * @param[in, out] dev
6348 * Pointer to rte_eth_dev structure.
6349 * @param[in] table_id
6352 * Direction of the table.
6353 * @param[in] transfer
6354 * E-Switch or NIC flow.
6356 * pointer to error structure.
6359 * Returns tables resource based on the index, NULL in case of failed.
6361 static struct mlx5_flow_tbl_resource *
6362 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
6363 uint32_t table_id, uint8_t egress,
6365 struct rte_flow_error *error)
6367 struct mlx5_priv *priv = dev->data->dev_private;
6368 struct mlx5_ibv_shared *sh = priv->sh;
6369 struct mlx5_flow_tbl_resource *tbl;
6370 union mlx5_flow_tbl_key table_key = {
6372 .table_id = table_id,
6374 .domain = !!transfer,
6375 .direction = !!egress,
6378 struct mlx5_hlist_entry *pos = mlx5_hlist_lookup(sh->flow_tbls,
6380 struct mlx5_flow_tbl_data_entry *tbl_data;
6385 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
6387 tbl = &tbl_data->tbl;
6388 rte_atomic32_inc(&tbl->refcnt);
6391 tbl_data = rte_zmalloc(NULL, sizeof(*tbl_data), 0);
6393 rte_flow_error_set(error, ENOMEM,
6394 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6396 "cannot allocate flow table data entry");
6399 tbl = &tbl_data->tbl;
6400 pos = &tbl_data->entry;
6402 domain = sh->fdb_domain;
6404 domain = sh->tx_domain;
6406 domain = sh->rx_domain;
6407 tbl->obj = mlx5_glue->dr_create_flow_tbl(domain, table_id);
6409 rte_flow_error_set(error, ENOMEM,
6410 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6411 NULL, "cannot create flow table object");
6416 * No multi-threads now, but still better to initialize the reference
6417 * count before insert it into the hash list.
6419 rte_atomic32_init(&tbl->refcnt);
6420 /* Jump action reference count is initialized here. */
6421 rte_atomic32_init(&tbl_data->jump.refcnt);
6422 pos->key = table_key.v64;
6423 ret = mlx5_hlist_insert(sh->flow_tbls, pos);
6425 rte_flow_error_set(error, -ret,
6426 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6427 "cannot insert flow table data entry");
6428 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
6431 rte_atomic32_inc(&tbl->refcnt);
6436 * Release a flow table.
6439 * Pointer to rte_eth_dev structure.
6441 * Table resource to be released.
6444 * Returns 0 if table was released, else return 1;
6447 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
6448 struct mlx5_flow_tbl_resource *tbl)
6450 struct mlx5_priv *priv = dev->data->dev_private;
6451 struct mlx5_ibv_shared *sh = priv->sh;
6452 struct mlx5_flow_tbl_data_entry *tbl_data =
6453 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
6457 if (rte_atomic32_dec_and_test(&tbl->refcnt)) {
6458 struct mlx5_hlist_entry *pos = &tbl_data->entry;
6460 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
6462 /* remove the entry from the hash list and free memory. */
6463 mlx5_hlist_remove(sh->flow_tbls, pos);
6471 * Register the flow matcher.
6473 * @param[in, out] dev
6474 * Pointer to rte_eth_dev structure.
6475 * @param[in, out] matcher
6476 * Pointer to flow matcher.
6477 * @param[in, out] key
6478 * Pointer to flow table key.
6479 * @parm[in, out] dev_flow
6480 * Pointer to the dev_flow.
6482 * pointer to error structure.
6485 * 0 on success otherwise -errno and errno is set.
6488 flow_dv_matcher_register(struct rte_eth_dev *dev,
6489 struct mlx5_flow_dv_matcher *matcher,
6490 union mlx5_flow_tbl_key *key,
6491 struct mlx5_flow *dev_flow,
6492 struct rte_flow_error *error)
6494 struct mlx5_priv *priv = dev->data->dev_private;
6495 struct mlx5_ibv_shared *sh = priv->sh;
6496 struct mlx5_flow_dv_matcher *cache_matcher;
6497 struct mlx5dv_flow_matcher_attr dv_attr = {
6498 .type = IBV_FLOW_ATTR_NORMAL,
6499 .match_mask = (void *)&matcher->mask,
6501 struct mlx5_flow_tbl_resource *tbl;
6502 struct mlx5_flow_tbl_data_entry *tbl_data;
6504 tbl = flow_dv_tbl_resource_get(dev, key->table_id, key->direction,
6505 key->domain, error);
6507 return -rte_errno; /* No need to refill the error info */
6508 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
6509 /* Lookup from cache. */
6510 LIST_FOREACH(cache_matcher, &tbl_data->matchers, next) {
6511 if (matcher->crc == cache_matcher->crc &&
6512 matcher->priority == cache_matcher->priority &&
6513 !memcmp((const void *)matcher->mask.buf,
6514 (const void *)cache_matcher->mask.buf,
6515 cache_matcher->mask.size)) {
6517 "%s group %u priority %hd use %s "
6518 "matcher %p: refcnt %d++",
6519 key->domain ? "FDB" : "NIC", key->table_id,
6520 cache_matcher->priority,
6521 key->direction ? "tx" : "rx",
6522 (void *)cache_matcher,
6523 rte_atomic32_read(&cache_matcher->refcnt));
6524 rte_atomic32_inc(&cache_matcher->refcnt);
6525 dev_flow->dv.matcher = cache_matcher;
6526 /* old matcher should not make the table ref++. */
6527 flow_dv_tbl_resource_release(dev, tbl);
6531 /* Register new matcher. */
6532 cache_matcher = rte_calloc(__func__, 1, sizeof(*cache_matcher), 0);
6533 if (!cache_matcher) {
6534 flow_dv_tbl_resource_release(dev, tbl);
6535 return rte_flow_error_set(error, ENOMEM,
6536 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6537 "cannot allocate matcher memory");
6539 *cache_matcher = *matcher;
6540 dv_attr.match_criteria_enable =
6541 flow_dv_matcher_enable(cache_matcher->mask.buf);
6542 dv_attr.priority = matcher->priority;
6544 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
6545 cache_matcher->matcher_object =
6546 mlx5_glue->dv_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj);
6547 if (!cache_matcher->matcher_object) {
6548 rte_free(cache_matcher);
6549 #ifdef HAVE_MLX5DV_DR
6550 flow_dv_tbl_resource_release(dev, tbl);
6552 return rte_flow_error_set(error, ENOMEM,
6553 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6554 NULL, "cannot create matcher");
6556 /* Save the table information */
6557 cache_matcher->tbl = tbl;
6558 rte_atomic32_init(&cache_matcher->refcnt);
6559 /* only matcher ref++, table ref++ already done above in get API. */
6560 rte_atomic32_inc(&cache_matcher->refcnt);
6561 LIST_INSERT_HEAD(&tbl_data->matchers, cache_matcher, next);
6562 dev_flow->dv.matcher = cache_matcher;
6563 DRV_LOG(DEBUG, "%s group %u priority %hd new %s matcher %p: refcnt %d",
6564 key->domain ? "FDB" : "NIC", key->table_id,
6565 cache_matcher->priority,
6566 key->direction ? "tx" : "rx", (void *)cache_matcher,
6567 rte_atomic32_read(&cache_matcher->refcnt));
6572 * Find existing tag resource or create and register a new one.
6574 * @param dev[in, out]
6575 * Pointer to rte_eth_dev structure.
6576 * @param[in, out] tag_be24
6577 * Tag value in big endian then R-shift 8.
6578 * @parm[in, out] dev_flow
6579 * Pointer to the dev_flow.
6581 * pointer to error structure.
6584 * 0 on success otherwise -errno and errno is set.
6587 flow_dv_tag_resource_register
6588 (struct rte_eth_dev *dev,
6590 struct mlx5_flow *dev_flow,
6591 struct rte_flow_error *error)
6593 struct mlx5_priv *priv = dev->data->dev_private;
6594 struct mlx5_ibv_shared *sh = priv->sh;
6595 struct mlx5_flow_dv_tag_resource *cache_resource;
6596 struct mlx5_hlist_entry *entry;
6598 /* Lookup a matching resource from cache. */
6599 entry = mlx5_hlist_lookup(sh->tag_table, (uint64_t)tag_be24);
6601 cache_resource = container_of
6602 (entry, struct mlx5_flow_dv_tag_resource, entry);
6603 rte_atomic32_inc(&cache_resource->refcnt);
6604 dev_flow->dv.tag_resource = cache_resource;
6605 DRV_LOG(DEBUG, "cached tag resource %p: refcnt now %d++",
6606 (void *)cache_resource,
6607 rte_atomic32_read(&cache_resource->refcnt));
6610 /* Register new resource. */
6611 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
6612 if (!cache_resource)
6613 return rte_flow_error_set(error, ENOMEM,
6614 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6615 "cannot allocate resource memory");
6616 cache_resource->entry.key = (uint64_t)tag_be24;
6617 cache_resource->action = mlx5_glue->dv_create_flow_action_tag(tag_be24);
6618 if (!cache_resource->action) {
6619 rte_free(cache_resource);
6620 return rte_flow_error_set(error, ENOMEM,
6621 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6622 NULL, "cannot create action");
6624 rte_atomic32_init(&cache_resource->refcnt);
6625 rte_atomic32_inc(&cache_resource->refcnt);
6626 if (mlx5_hlist_insert(sh->tag_table, &cache_resource->entry)) {
6627 mlx5_glue->destroy_flow_action(cache_resource->action);
6628 rte_free(cache_resource);
6629 return rte_flow_error_set(error, EEXIST,
6630 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6631 NULL, "cannot insert tag");
6633 dev_flow->dv.tag_resource = cache_resource;
6634 DRV_LOG(DEBUG, "new tag resource %p: refcnt now %d++",
6635 (void *)cache_resource,
6636 rte_atomic32_read(&cache_resource->refcnt));
6644 * Pointer to Ethernet device.
6646 * Pointer to mlx5_flow.
6649 * 1 while a reference on it exists, 0 when freed.
6652 flow_dv_tag_release(struct rte_eth_dev *dev,
6653 struct mlx5_flow_dv_tag_resource *tag)
6655 struct mlx5_priv *priv = dev->data->dev_private;
6656 struct mlx5_ibv_shared *sh = priv->sh;
6659 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
6660 dev->data->port_id, (void *)tag,
6661 rte_atomic32_read(&tag->refcnt));
6662 if (rte_atomic32_dec_and_test(&tag->refcnt)) {
6663 claim_zero(mlx5_glue->destroy_flow_action(tag->action));
6664 mlx5_hlist_remove(sh->tag_table, &tag->entry);
6665 DRV_LOG(DEBUG, "port %u tag %p: removed",
6666 dev->data->port_id, (void *)tag);
6674 * Translate port ID action to vport.
6677 * Pointer to rte_eth_dev structure.
6679 * Pointer to the port ID action.
6680 * @param[out] dst_port_id
6681 * The target port ID.
6683 * Pointer to the error structure.
6686 * 0 on success, a negative errno value otherwise and rte_errno is set.
6689 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
6690 const struct rte_flow_action *action,
6691 uint32_t *dst_port_id,
6692 struct rte_flow_error *error)
6695 struct mlx5_priv *priv;
6696 const struct rte_flow_action_port_id *conf =
6697 (const struct rte_flow_action_port_id *)action->conf;
6699 port = conf->original ? dev->data->port_id : conf->id;
6700 priv = mlx5_port_to_eswitch_info(port, false);
6702 return rte_flow_error_set(error, -rte_errno,
6703 RTE_FLOW_ERROR_TYPE_ACTION,
6705 "No eswitch info was found for port");
6706 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
6708 * This parameter is transferred to
6709 * mlx5dv_dr_action_create_dest_ib_port().
6711 *dst_port_id = priv->ibv_port;
6714 * Legacy mode, no LAG configurations is supported.
6715 * This parameter is transferred to
6716 * mlx5dv_dr_action_create_dest_vport().
6718 *dst_port_id = priv->vport_id;
6724 * Add Tx queue matcher
6727 * Pointer to the dev struct.
6728 * @param[in, out] matcher
6730 * @param[in, out] key
6731 * Flow matcher value.
6733 * Flow pattern to translate.
6735 * Item is inner pattern.
6738 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
6739 void *matcher, void *key,
6740 const struct rte_flow_item *item)
6742 const struct mlx5_rte_flow_item_tx_queue *queue_m;
6743 const struct mlx5_rte_flow_item_tx_queue *queue_v;
6745 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6747 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6748 struct mlx5_txq_ctrl *txq;
6752 queue_m = (const void *)item->mask;
6755 queue_v = (const void *)item->spec;
6758 txq = mlx5_txq_get(dev, queue_v->queue);
6761 queue = txq->obj->sq->id;
6762 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
6763 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
6764 queue & queue_m->queue);
6765 mlx5_txq_release(dev, queue_v->queue);
6769 * Set the hash fields according to the @p flow information.
6771 * @param[in] dev_flow
6772 * Pointer to the mlx5_flow.
6775 flow_dv_hashfields_set(struct mlx5_flow *dev_flow)
6777 struct rte_flow *flow = dev_flow->flow;
6778 uint64_t items = dev_flow->layers;
6780 uint64_t rss_types = rte_eth_rss_hf_refine(flow->rss.types);
6782 dev_flow->hash_fields = 0;
6783 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
6784 if (flow->rss.level >= 2) {
6785 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
6789 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
6790 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
6791 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
6792 if (rss_types & ETH_RSS_L3_SRC_ONLY)
6793 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
6794 else if (rss_types & ETH_RSS_L3_DST_ONLY)
6795 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
6797 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
6799 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
6800 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
6801 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
6802 if (rss_types & ETH_RSS_L3_SRC_ONLY)
6803 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
6804 else if (rss_types & ETH_RSS_L3_DST_ONLY)
6805 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
6807 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
6810 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
6811 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
6812 if (rss_types & ETH_RSS_UDP) {
6813 if (rss_types & ETH_RSS_L4_SRC_ONLY)
6814 dev_flow->hash_fields |=
6815 IBV_RX_HASH_SRC_PORT_UDP;
6816 else if (rss_types & ETH_RSS_L4_DST_ONLY)
6817 dev_flow->hash_fields |=
6818 IBV_RX_HASH_DST_PORT_UDP;
6820 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
6822 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
6823 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
6824 if (rss_types & ETH_RSS_TCP) {
6825 if (rss_types & ETH_RSS_L4_SRC_ONLY)
6826 dev_flow->hash_fields |=
6827 IBV_RX_HASH_SRC_PORT_TCP;
6828 else if (rss_types & ETH_RSS_L4_DST_ONLY)
6829 dev_flow->hash_fields |=
6830 IBV_RX_HASH_DST_PORT_TCP;
6832 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
6838 * Fill the flow with DV spec, lock free
6839 * (mutex should be acquired by caller).
6842 * Pointer to rte_eth_dev structure.
6843 * @param[in, out] dev_flow
6844 * Pointer to the sub flow.
6846 * Pointer to the flow attributes.
6848 * Pointer to the list of items.
6849 * @param[in] actions
6850 * Pointer to the list of actions.
6852 * Pointer to the error structure.
6855 * 0 on success, a negative errno value otherwise and rte_errno is set.
6858 __flow_dv_translate(struct rte_eth_dev *dev,
6859 struct mlx5_flow *dev_flow,
6860 const struct rte_flow_attr *attr,
6861 const struct rte_flow_item items[],
6862 const struct rte_flow_action actions[],
6863 struct rte_flow_error *error)
6865 struct mlx5_priv *priv = dev->data->dev_private;
6866 struct mlx5_dev_config *dev_conf = &priv->config;
6867 struct rte_flow *flow = dev_flow->flow;
6868 uint64_t item_flags = 0;
6869 uint64_t last_item = 0;
6870 uint64_t action_flags = 0;
6871 uint64_t priority = attr->priority;
6872 struct mlx5_flow_dv_matcher matcher = {
6874 .size = sizeof(matcher.mask.buf),
6878 bool actions_end = false;
6879 struct mlx5_flow_dv_modify_hdr_resource mhdr_res = {
6880 .ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
6881 MLX5DV_FLOW_TABLE_TYPE_NIC_RX
6883 union flow_dv_attr flow_attr = { .attr = 0 };
6885 union mlx5_flow_tbl_key tbl_key;
6886 uint32_t modify_action_position = UINT32_MAX;
6887 void *match_mask = matcher.mask.buf;
6888 void *match_value = dev_flow->dv.value.buf;
6889 uint8_t next_protocol = 0xff;
6890 struct rte_vlan_hdr vlan = { 0 };
6894 ret = mlx5_flow_group_to_table(attr, dev_flow->external, attr->group,
6898 dev_flow->group = table;
6900 mhdr_res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
6901 if (priority == MLX5_FLOW_PRIO_RSVD)
6902 priority = dev_conf->flow_prio - 1;
6903 for (; !actions_end ; actions++) {
6904 const struct rte_flow_action_queue *queue;
6905 const struct rte_flow_action_rss *rss;
6906 const struct rte_flow_action *action = actions;
6907 const struct rte_flow_action_count *count = action->conf;
6908 const uint8_t *rss_key;
6909 const struct rte_flow_action_jump *jump_data;
6910 const struct rte_flow_action_meter *mtr;
6911 struct mlx5_flow_tbl_resource *tbl;
6912 uint32_t port_id = 0;
6913 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
6914 int action_type = actions->type;
6915 const struct rte_flow_action *found_action = NULL;
6917 switch (action_type) {
6918 case RTE_FLOW_ACTION_TYPE_VOID:
6920 case RTE_FLOW_ACTION_TYPE_PORT_ID:
6921 if (flow_dv_translate_action_port_id(dev, action,
6924 port_id_resource.port_id = port_id;
6925 if (flow_dv_port_id_action_resource_register
6926 (dev, &port_id_resource, dev_flow, error))
6928 dev_flow->dv.actions[actions_n++] =
6929 dev_flow->dv.port_id_action->action;
6930 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6932 case RTE_FLOW_ACTION_TYPE_FLAG:
6933 action_flags |= MLX5_FLOW_ACTION_FLAG;
6934 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
6935 struct rte_flow_action_mark mark = {
6936 .id = MLX5_FLOW_MARK_DEFAULT,
6939 if (flow_dv_convert_action_mark(dev, &mark,
6943 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
6946 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
6947 if (!dev_flow->dv.tag_resource)
6948 if (flow_dv_tag_resource_register
6949 (dev, tag_be, dev_flow, error))
6951 dev_flow->dv.actions[actions_n++] =
6952 dev_flow->dv.tag_resource->action;
6954 case RTE_FLOW_ACTION_TYPE_MARK:
6955 action_flags |= MLX5_FLOW_ACTION_MARK;
6956 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
6957 const struct rte_flow_action_mark *mark =
6958 (const struct rte_flow_action_mark *)
6961 if (flow_dv_convert_action_mark(dev, mark,
6965 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
6969 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
6970 /* Legacy (non-extensive) MARK action. */
6971 tag_be = mlx5_flow_mark_set
6972 (((const struct rte_flow_action_mark *)
6973 (actions->conf))->id);
6974 if (!dev_flow->dv.tag_resource)
6975 if (flow_dv_tag_resource_register
6976 (dev, tag_be, dev_flow, error))
6978 dev_flow->dv.actions[actions_n++] =
6979 dev_flow->dv.tag_resource->action;
6981 case RTE_FLOW_ACTION_TYPE_SET_META:
6982 if (flow_dv_convert_action_set_meta
6983 (dev, &mhdr_res, attr,
6984 (const struct rte_flow_action_set_meta *)
6985 actions->conf, error))
6987 action_flags |= MLX5_FLOW_ACTION_SET_META;
6989 case RTE_FLOW_ACTION_TYPE_SET_TAG:
6990 if (flow_dv_convert_action_set_tag
6992 (const struct rte_flow_action_set_tag *)
6993 actions->conf, error))
6995 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
6997 case RTE_FLOW_ACTION_TYPE_DROP:
6998 action_flags |= MLX5_FLOW_ACTION_DROP;
7000 case RTE_FLOW_ACTION_TYPE_QUEUE:
7001 assert(flow->rss.queue);
7002 queue = actions->conf;
7003 flow->rss.queue_num = 1;
7004 (*flow->rss.queue)[0] = queue->index;
7005 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7007 case RTE_FLOW_ACTION_TYPE_RSS:
7008 assert(flow->rss.queue);
7009 rss = actions->conf;
7010 if (flow->rss.queue)
7011 memcpy((*flow->rss.queue), rss->queue,
7012 rss->queue_num * sizeof(uint16_t));
7013 flow->rss.queue_num = rss->queue_num;
7014 /* NULL RSS key indicates default RSS key. */
7015 rss_key = !rss->key ? rss_hash_default_key : rss->key;
7016 memcpy(flow->rss.key, rss_key, MLX5_RSS_HASH_KEY_LEN);
7018 * rss->level and rss.types should be set in advance
7019 * when expanding items for RSS.
7021 action_flags |= MLX5_FLOW_ACTION_RSS;
7023 case RTE_FLOW_ACTION_TYPE_COUNT:
7024 if (!dev_conf->devx) {
7025 rte_errno = ENOTSUP;
7028 flow->counter = flow_dv_counter_alloc(dev,
7032 if (flow->counter == NULL)
7034 dev_flow->dv.actions[actions_n++] =
7035 flow->counter->action;
7036 action_flags |= MLX5_FLOW_ACTION_COUNT;
7039 if (rte_errno == ENOTSUP)
7040 return rte_flow_error_set
7042 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7044 "count action not supported");
7046 return rte_flow_error_set
7048 RTE_FLOW_ERROR_TYPE_ACTION,
7050 "cannot create counter"
7053 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7054 dev_flow->dv.actions[actions_n++] =
7055 priv->sh->pop_vlan_action;
7056 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7058 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7059 flow_dev_get_vlan_info_from_items(items, &vlan);
7060 vlan.eth_proto = rte_be_to_cpu_16
7061 ((((const struct rte_flow_action_of_push_vlan *)
7062 actions->conf)->ethertype));
7063 found_action = mlx5_flow_find_action
7065 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
7067 mlx5_update_vlan_vid_pcp(found_action, &vlan);
7068 found_action = mlx5_flow_find_action
7070 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
7072 mlx5_update_vlan_vid_pcp(found_action, &vlan);
7073 if (flow_dv_create_action_push_vlan
7074 (dev, attr, &vlan, dev_flow, error))
7076 dev_flow->dv.actions[actions_n++] =
7077 dev_flow->dv.push_vlan_res->action;
7078 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7080 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7081 /* of_vlan_push action handled this action */
7082 assert(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN);
7084 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7085 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7087 flow_dev_get_vlan_info_from_items(items, &vlan);
7088 mlx5_update_vlan_vid_pcp(actions, &vlan);
7089 /* If no VLAN push - this is a modify header action */
7090 if (flow_dv_convert_action_modify_vlan_vid
7091 (&mhdr_res, actions, error))
7093 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7095 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7096 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7097 if (flow_dv_create_action_l2_encap(dev, actions,
7102 dev_flow->dv.actions[actions_n++] =
7103 dev_flow->dv.encap_decap->verbs_action;
7104 action_flags |= actions->type ==
7105 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ?
7106 MLX5_FLOW_ACTION_VXLAN_ENCAP :
7107 MLX5_FLOW_ACTION_NVGRE_ENCAP;
7109 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7110 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7111 if (flow_dv_create_action_l2_decap(dev, dev_flow,
7115 dev_flow->dv.actions[actions_n++] =
7116 dev_flow->dv.encap_decap->verbs_action;
7117 action_flags |= actions->type ==
7118 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ?
7119 MLX5_FLOW_ACTION_VXLAN_DECAP :
7120 MLX5_FLOW_ACTION_NVGRE_DECAP;
7122 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7123 /* Handle encap with preceding decap. */
7124 if (action_flags & MLX5_FLOW_ACTION_RAW_DECAP) {
7125 if (flow_dv_create_action_raw_encap
7126 (dev, actions, dev_flow, attr, error))
7128 dev_flow->dv.actions[actions_n++] =
7129 dev_flow->dv.encap_decap->verbs_action;
7131 /* Handle encap without preceding decap. */
7132 if (flow_dv_create_action_l2_encap
7133 (dev, actions, dev_flow, attr->transfer,
7136 dev_flow->dv.actions[actions_n++] =
7137 dev_flow->dv.encap_decap->verbs_action;
7139 action_flags |= MLX5_FLOW_ACTION_RAW_ENCAP;
7141 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7142 /* Check if this decap is followed by encap. */
7143 for (; action->type != RTE_FLOW_ACTION_TYPE_END &&
7144 action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP;
7147 /* Handle decap only if it isn't followed by encap. */
7148 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7149 if (flow_dv_create_action_l2_decap
7150 (dev, dev_flow, attr->transfer, error))
7152 dev_flow->dv.actions[actions_n++] =
7153 dev_flow->dv.encap_decap->verbs_action;
7155 /* If decap is followed by encap, handle it at encap. */
7156 action_flags |= MLX5_FLOW_ACTION_RAW_DECAP;
7158 case RTE_FLOW_ACTION_TYPE_JUMP:
7159 jump_data = action->conf;
7160 ret = mlx5_flow_group_to_table(attr, dev_flow->external,
7161 jump_data->group, &table,
7165 tbl = flow_dv_tbl_resource_get(dev, table,
7167 attr->transfer, error);
7169 return rte_flow_error_set
7171 RTE_FLOW_ERROR_TYPE_ACTION,
7173 "cannot create jump action.");
7174 if (flow_dv_jump_tbl_resource_register
7175 (dev, tbl, dev_flow, error)) {
7176 flow_dv_tbl_resource_release(dev, tbl);
7177 return rte_flow_error_set
7179 RTE_FLOW_ERROR_TYPE_ACTION,
7181 "cannot create jump action.");
7183 dev_flow->dv.actions[actions_n++] =
7184 dev_flow->dv.jump->action;
7185 action_flags |= MLX5_FLOW_ACTION_JUMP;
7187 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7188 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7189 if (flow_dv_convert_action_modify_mac
7190 (&mhdr_res, actions, error))
7192 action_flags |= actions->type ==
7193 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7194 MLX5_FLOW_ACTION_SET_MAC_SRC :
7195 MLX5_FLOW_ACTION_SET_MAC_DST;
7197 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7198 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7199 if (flow_dv_convert_action_modify_ipv4
7200 (&mhdr_res, actions, error))
7202 action_flags |= actions->type ==
7203 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7204 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7205 MLX5_FLOW_ACTION_SET_IPV4_DST;
7207 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7208 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7209 if (flow_dv_convert_action_modify_ipv6
7210 (&mhdr_res, actions, error))
7212 action_flags |= actions->type ==
7213 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7214 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7215 MLX5_FLOW_ACTION_SET_IPV6_DST;
7217 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7218 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7219 if (flow_dv_convert_action_modify_tp
7220 (&mhdr_res, actions, items,
7223 action_flags |= actions->type ==
7224 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7225 MLX5_FLOW_ACTION_SET_TP_SRC :
7226 MLX5_FLOW_ACTION_SET_TP_DST;
7228 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7229 if (flow_dv_convert_action_modify_dec_ttl
7230 (&mhdr_res, items, &flow_attr, error))
7232 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
7234 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7235 if (flow_dv_convert_action_modify_ttl
7236 (&mhdr_res, actions, items,
7239 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
7241 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7242 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7243 if (flow_dv_convert_action_modify_tcp_seq
7244 (&mhdr_res, actions, error))
7246 action_flags |= actions->type ==
7247 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7248 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7249 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7252 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7253 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7254 if (flow_dv_convert_action_modify_tcp_ack
7255 (&mhdr_res, actions, error))
7257 action_flags |= actions->type ==
7258 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7259 MLX5_FLOW_ACTION_INC_TCP_ACK :
7260 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7262 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7263 if (flow_dv_convert_action_set_reg
7264 (&mhdr_res, actions, error))
7266 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7268 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7269 if (flow_dv_convert_action_copy_mreg
7270 (dev, &mhdr_res, actions, error))
7272 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7274 case RTE_FLOW_ACTION_TYPE_METER:
7275 mtr = actions->conf;
7277 flow->meter = mlx5_flow_meter_attach(priv,
7281 return rte_flow_error_set(error,
7283 RTE_FLOW_ERROR_TYPE_ACTION,
7286 "or invalid parameters");
7288 /* Set the meter action. */
7289 dev_flow->dv.actions[actions_n++] =
7290 flow->meter->mfts->meter_action;
7291 action_flags |= MLX5_FLOW_ACTION_METER;
7293 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7294 if (flow_dv_convert_action_modify_ipv4_dscp(&mhdr_res,
7297 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7299 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7300 if (flow_dv_convert_action_modify_ipv6_dscp(&mhdr_res,
7303 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7305 case RTE_FLOW_ACTION_TYPE_END:
7307 if (mhdr_res.actions_num) {
7308 /* create modify action if needed. */
7309 if (flow_dv_modify_hdr_resource_register
7310 (dev, &mhdr_res, dev_flow, error))
7312 dev_flow->dv.actions[modify_action_position] =
7313 dev_flow->dv.modify_hdr->verbs_action;
7319 if (mhdr_res.actions_num &&
7320 modify_action_position == UINT32_MAX)
7321 modify_action_position = actions_n++;
7323 dev_flow->dv.actions_n = actions_n;
7324 dev_flow->actions = action_flags;
7325 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7326 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7327 int item_type = items->type;
7329 switch (item_type) {
7330 case RTE_FLOW_ITEM_TYPE_PORT_ID:
7331 flow_dv_translate_item_port_id(dev, match_mask,
7332 match_value, items);
7333 last_item = MLX5_FLOW_ITEM_PORT_ID;
7335 case RTE_FLOW_ITEM_TYPE_ETH:
7336 flow_dv_translate_item_eth(match_mask, match_value,
7338 matcher.priority = MLX5_PRIORITY_MAP_L2;
7339 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7340 MLX5_FLOW_LAYER_OUTER_L2;
7342 case RTE_FLOW_ITEM_TYPE_VLAN:
7343 flow_dv_translate_item_vlan(dev_flow,
7344 match_mask, match_value,
7346 matcher.priority = MLX5_PRIORITY_MAP_L2;
7347 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
7348 MLX5_FLOW_LAYER_INNER_VLAN) :
7349 (MLX5_FLOW_LAYER_OUTER_L2 |
7350 MLX5_FLOW_LAYER_OUTER_VLAN);
7352 case RTE_FLOW_ITEM_TYPE_IPV4:
7353 mlx5_flow_tunnel_ip_check(items, next_protocol,
7354 &item_flags, &tunnel);
7355 flow_dv_translate_item_ipv4(match_mask, match_value,
7358 matcher.priority = MLX5_PRIORITY_MAP_L3;
7359 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7360 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7361 if (items->mask != NULL &&
7362 ((const struct rte_flow_item_ipv4 *)
7363 items->mask)->hdr.next_proto_id) {
7365 ((const struct rte_flow_item_ipv4 *)
7366 (items->spec))->hdr.next_proto_id;
7368 ((const struct rte_flow_item_ipv4 *)
7369 (items->mask))->hdr.next_proto_id;
7371 /* Reset for inner layer. */
7372 next_protocol = 0xff;
7375 case RTE_FLOW_ITEM_TYPE_IPV6:
7376 mlx5_flow_tunnel_ip_check(items, next_protocol,
7377 &item_flags, &tunnel);
7378 flow_dv_translate_item_ipv6(match_mask, match_value,
7381 matcher.priority = MLX5_PRIORITY_MAP_L3;
7382 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7383 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7384 if (items->mask != NULL &&
7385 ((const struct rte_flow_item_ipv6 *)
7386 items->mask)->hdr.proto) {
7388 ((const struct rte_flow_item_ipv6 *)
7389 items->spec)->hdr.proto;
7391 ((const struct rte_flow_item_ipv6 *)
7392 items->mask)->hdr.proto;
7394 /* Reset for inner layer. */
7395 next_protocol = 0xff;
7398 case RTE_FLOW_ITEM_TYPE_TCP:
7399 flow_dv_translate_item_tcp(match_mask, match_value,
7401 matcher.priority = MLX5_PRIORITY_MAP_L4;
7402 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7403 MLX5_FLOW_LAYER_OUTER_L4_TCP;
7405 case RTE_FLOW_ITEM_TYPE_UDP:
7406 flow_dv_translate_item_udp(match_mask, match_value,
7408 matcher.priority = MLX5_PRIORITY_MAP_L4;
7409 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7410 MLX5_FLOW_LAYER_OUTER_L4_UDP;
7412 case RTE_FLOW_ITEM_TYPE_GRE:
7413 flow_dv_translate_item_gre(match_mask, match_value,
7415 last_item = MLX5_FLOW_LAYER_GRE;
7417 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7418 flow_dv_translate_item_gre_key(match_mask,
7419 match_value, items);
7420 last_item = MLX5_FLOW_LAYER_GRE_KEY;
7422 case RTE_FLOW_ITEM_TYPE_NVGRE:
7423 flow_dv_translate_item_nvgre(match_mask, match_value,
7425 last_item = MLX5_FLOW_LAYER_GRE;
7427 case RTE_FLOW_ITEM_TYPE_VXLAN:
7428 flow_dv_translate_item_vxlan(match_mask, match_value,
7430 last_item = MLX5_FLOW_LAYER_VXLAN;
7432 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7433 flow_dv_translate_item_vxlan(match_mask, match_value,
7435 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7437 case RTE_FLOW_ITEM_TYPE_GENEVE:
7438 flow_dv_translate_item_geneve(match_mask, match_value,
7440 last_item = MLX5_FLOW_LAYER_GENEVE;
7442 case RTE_FLOW_ITEM_TYPE_MPLS:
7443 flow_dv_translate_item_mpls(match_mask, match_value,
7444 items, last_item, tunnel);
7445 last_item = MLX5_FLOW_LAYER_MPLS;
7447 case RTE_FLOW_ITEM_TYPE_MARK:
7448 flow_dv_translate_item_mark(dev, match_mask,
7449 match_value, items);
7450 last_item = MLX5_FLOW_ITEM_MARK;
7452 case RTE_FLOW_ITEM_TYPE_META:
7453 flow_dv_translate_item_meta(dev, match_mask,
7454 match_value, attr, items);
7455 last_item = MLX5_FLOW_ITEM_METADATA;
7457 case RTE_FLOW_ITEM_TYPE_ICMP:
7458 flow_dv_translate_item_icmp(match_mask, match_value,
7460 last_item = MLX5_FLOW_LAYER_ICMP;
7462 case RTE_FLOW_ITEM_TYPE_ICMP6:
7463 flow_dv_translate_item_icmp6(match_mask, match_value,
7465 last_item = MLX5_FLOW_LAYER_ICMP6;
7467 case RTE_FLOW_ITEM_TYPE_TAG:
7468 flow_dv_translate_item_tag(dev, match_mask,
7469 match_value, items);
7470 last_item = MLX5_FLOW_ITEM_TAG;
7472 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7473 flow_dv_translate_mlx5_item_tag(match_mask,
7474 match_value, items);
7475 last_item = MLX5_FLOW_ITEM_TAG;
7477 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
7478 flow_dv_translate_item_tx_queue(dev, match_mask,
7481 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
7486 item_flags |= last_item;
7489 * In case of ingress traffic when E-Switch mode is enabled,
7490 * we have two cases where we need to set the source port manually.
7491 * The first one, is in case of Nic steering rule, and the second is
7492 * E-Switch rule where no port_id item was found. In both cases
7493 * the source port is set according the current port in use.
7495 if ((attr->ingress && !(item_flags & MLX5_FLOW_ITEM_PORT_ID)) &&
7496 (priv->representor || priv->master)) {
7497 if (flow_dv_translate_item_port_id(dev, match_mask,
7501 assert(!flow_dv_check_valid_spec(matcher.mask.buf,
7502 dev_flow->dv.value.buf));
7503 dev_flow->layers = item_flags;
7504 if (action_flags & MLX5_FLOW_ACTION_RSS)
7505 flow_dv_hashfields_set(dev_flow);
7506 /* Register matcher. */
7507 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
7509 matcher.priority = mlx5_flow_adjust_priority(dev, priority,
7511 /* reserved field no needs to be set to 0 here. */
7512 tbl_key.domain = attr->transfer;
7513 tbl_key.direction = attr->egress;
7514 tbl_key.table_id = dev_flow->group;
7515 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow, error))
7521 * Apply the flow to the NIC, lock free,
7522 * (mutex should be acquired by caller).
7525 * Pointer to the Ethernet device structure.
7526 * @param[in, out] flow
7527 * Pointer to flow structure.
7529 * Pointer to error structure.
7532 * 0 on success, a negative errno value otherwise and rte_errno is set.
7535 __flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
7536 struct rte_flow_error *error)
7538 struct mlx5_flow_dv *dv;
7539 struct mlx5_flow *dev_flow;
7540 struct mlx5_priv *priv = dev->data->dev_private;
7544 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
7547 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP) {
7548 if (dev_flow->transfer) {
7549 dv->actions[n++] = priv->sh->esw_drop_action;
7551 dv->hrxq = mlx5_hrxq_drop_new(dev);
7555 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7557 "cannot get drop hash queue");
7560 dv->actions[n++] = dv->hrxq->action;
7562 } else if (dev_flow->actions &
7563 (MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)) {
7564 struct mlx5_hrxq *hrxq;
7566 assert(flow->rss.queue);
7567 hrxq = mlx5_hrxq_get(dev, flow->rss.key,
7568 MLX5_RSS_HASH_KEY_LEN,
7569 dev_flow->hash_fields,
7571 flow->rss.queue_num);
7573 hrxq = mlx5_hrxq_new
7574 (dev, flow->rss.key,
7575 MLX5_RSS_HASH_KEY_LEN,
7576 dev_flow->hash_fields,
7578 flow->rss.queue_num,
7579 !!(dev_flow->layers &
7580 MLX5_FLOW_LAYER_TUNNEL));
7585 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7586 "cannot get hash queue");
7590 dv->actions[n++] = dv->hrxq->action;
7593 mlx5_glue->dv_create_flow(dv->matcher->matcher_object,
7594 (void *)&dv->value, n,
7597 rte_flow_error_set(error, errno,
7598 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7600 "hardware refuses to create flow");
7603 if (priv->vmwa_context &&
7604 dev_flow->dv.vf_vlan.tag &&
7605 !dev_flow->dv.vf_vlan.created) {
7607 * The rule contains the VLAN pattern.
7608 * For VF we are going to create VLAN
7609 * interface to make hypervisor set correct
7610 * e-Switch vport context.
7612 mlx5_vlan_vmwa_acquire(dev, &dev_flow->dv.vf_vlan);
7617 err = rte_errno; /* Save rte_errno before cleanup. */
7618 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
7619 struct mlx5_flow_dv *dv = &dev_flow->dv;
7621 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP)
7622 mlx5_hrxq_drop_release(dev);
7624 mlx5_hrxq_release(dev, dv->hrxq);
7627 if (dev_flow->dv.vf_vlan.tag &&
7628 dev_flow->dv.vf_vlan.created)
7629 mlx5_vlan_vmwa_release(dev, &dev_flow->dv.vf_vlan);
7631 rte_errno = err; /* Restore rte_errno. */
7636 * Release the flow matcher.
7639 * Pointer to Ethernet device.
7641 * Pointer to mlx5_flow.
7644 * 1 while a reference on it exists, 0 when freed.
7647 flow_dv_matcher_release(struct rte_eth_dev *dev,
7648 struct mlx5_flow *flow)
7650 struct mlx5_flow_dv_matcher *matcher = flow->dv.matcher;
7652 assert(matcher->matcher_object);
7653 DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
7654 dev->data->port_id, (void *)matcher,
7655 rte_atomic32_read(&matcher->refcnt));
7656 if (rte_atomic32_dec_and_test(&matcher->refcnt)) {
7657 claim_zero(mlx5_glue->dv_destroy_flow_matcher
7658 (matcher->matcher_object));
7659 LIST_REMOVE(matcher, next);
7660 /* table ref-- in release interface. */
7661 flow_dv_tbl_resource_release(dev, matcher->tbl);
7663 DRV_LOG(DEBUG, "port %u matcher %p: removed",
7664 dev->data->port_id, (void *)matcher);
7671 * Release an encap/decap resource.
7674 * Pointer to mlx5_flow.
7677 * 1 while a reference on it exists, 0 when freed.
7680 flow_dv_encap_decap_resource_release(struct mlx5_flow *flow)
7682 struct mlx5_flow_dv_encap_decap_resource *cache_resource =
7683 flow->dv.encap_decap;
7685 assert(cache_resource->verbs_action);
7686 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d--",
7687 (void *)cache_resource,
7688 rte_atomic32_read(&cache_resource->refcnt));
7689 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7690 claim_zero(mlx5_glue->destroy_flow_action
7691 (cache_resource->verbs_action));
7692 LIST_REMOVE(cache_resource, next);
7693 rte_free(cache_resource);
7694 DRV_LOG(DEBUG, "encap/decap resource %p: removed",
7695 (void *)cache_resource);
7702 * Release an jump to table action resource.
7705 * Pointer to Ethernet device.
7707 * Pointer to mlx5_flow.
7710 * 1 while a reference on it exists, 0 when freed.
7713 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
7714 struct mlx5_flow *flow)
7716 struct mlx5_flow_dv_jump_tbl_resource *cache_resource = flow->dv.jump;
7717 struct mlx5_flow_tbl_data_entry *tbl_data =
7718 container_of(cache_resource,
7719 struct mlx5_flow_tbl_data_entry, jump);
7721 assert(cache_resource->action);
7722 DRV_LOG(DEBUG, "jump table resource %p: refcnt %d--",
7723 (void *)cache_resource,
7724 rte_atomic32_read(&cache_resource->refcnt));
7725 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7726 claim_zero(mlx5_glue->destroy_flow_action
7727 (cache_resource->action));
7728 /* jump action memory free is inside the table release. */
7729 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
7730 DRV_LOG(DEBUG, "jump table resource %p: removed",
7731 (void *)cache_resource);
7738 * Release a modify-header resource.
7741 * Pointer to mlx5_flow.
7744 * 1 while a reference on it exists, 0 when freed.
7747 flow_dv_modify_hdr_resource_release(struct mlx5_flow *flow)
7749 struct mlx5_flow_dv_modify_hdr_resource *cache_resource =
7750 flow->dv.modify_hdr;
7752 assert(cache_resource->verbs_action);
7753 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d--",
7754 (void *)cache_resource,
7755 rte_atomic32_read(&cache_resource->refcnt));
7756 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7757 claim_zero(mlx5_glue->destroy_flow_action
7758 (cache_resource->verbs_action));
7759 LIST_REMOVE(cache_resource, next);
7760 rte_free(cache_resource);
7761 DRV_LOG(DEBUG, "modify-header resource %p: removed",
7762 (void *)cache_resource);
7769 * Release port ID action resource.
7772 * Pointer to mlx5_flow.
7775 * 1 while a reference on it exists, 0 when freed.
7778 flow_dv_port_id_action_resource_release(struct mlx5_flow *flow)
7780 struct mlx5_flow_dv_port_id_action_resource *cache_resource =
7781 flow->dv.port_id_action;
7783 assert(cache_resource->action);
7784 DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--",
7785 (void *)cache_resource,
7786 rte_atomic32_read(&cache_resource->refcnt));
7787 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7788 claim_zero(mlx5_glue->destroy_flow_action
7789 (cache_resource->action));
7790 LIST_REMOVE(cache_resource, next);
7791 rte_free(cache_resource);
7792 DRV_LOG(DEBUG, "port id action resource %p: removed",
7793 (void *)cache_resource);
7800 * Release push vlan action resource.
7803 * Pointer to mlx5_flow.
7806 * 1 while a reference on it exists, 0 when freed.
7809 flow_dv_push_vlan_action_resource_release(struct mlx5_flow *flow)
7811 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource =
7812 flow->dv.push_vlan_res;
7814 assert(cache_resource->action);
7815 DRV_LOG(DEBUG, "push VLAN action resource %p: refcnt %d--",
7816 (void *)cache_resource,
7817 rte_atomic32_read(&cache_resource->refcnt));
7818 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7819 claim_zero(mlx5_glue->destroy_flow_action
7820 (cache_resource->action));
7821 LIST_REMOVE(cache_resource, next);
7822 rte_free(cache_resource);
7823 DRV_LOG(DEBUG, "push vlan action resource %p: removed",
7824 (void *)cache_resource);
7831 * Remove the flow from the NIC but keeps it in memory.
7832 * Lock free, (mutex should be acquired by caller).
7835 * Pointer to Ethernet device.
7836 * @param[in, out] flow
7837 * Pointer to flow structure.
7840 __flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
7842 struct mlx5_flow_dv *dv;
7843 struct mlx5_flow *dev_flow;
7847 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
7850 claim_zero(mlx5_glue->dv_destroy_flow(dv->flow));
7854 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP)
7855 mlx5_hrxq_drop_release(dev);
7857 mlx5_hrxq_release(dev, dv->hrxq);
7860 if (dev_flow->dv.vf_vlan.tag &&
7861 dev_flow->dv.vf_vlan.created)
7862 mlx5_vlan_vmwa_release(dev, &dev_flow->dv.vf_vlan);
7867 * Remove the flow from the NIC and the memory.
7868 * Lock free, (mutex should be acquired by caller).
7871 * Pointer to the Ethernet device structure.
7872 * @param[in, out] flow
7873 * Pointer to flow structure.
7876 __flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
7878 struct mlx5_flow *dev_flow;
7882 __flow_dv_remove(dev, flow);
7883 if (flow->counter) {
7884 flow_dv_counter_release(dev, flow->counter);
7885 flow->counter = NULL;
7888 mlx5_flow_meter_detach(flow->meter);
7891 while (!LIST_EMPTY(&flow->dev_flows)) {
7892 dev_flow = LIST_FIRST(&flow->dev_flows);
7893 LIST_REMOVE(dev_flow, next);
7894 if (dev_flow->dv.matcher)
7895 flow_dv_matcher_release(dev, dev_flow);
7896 if (dev_flow->dv.encap_decap)
7897 flow_dv_encap_decap_resource_release(dev_flow);
7898 if (dev_flow->dv.modify_hdr)
7899 flow_dv_modify_hdr_resource_release(dev_flow);
7900 if (dev_flow->dv.jump)
7901 flow_dv_jump_tbl_resource_release(dev, dev_flow);
7902 if (dev_flow->dv.port_id_action)
7903 flow_dv_port_id_action_resource_release(dev_flow);
7904 if (dev_flow->dv.push_vlan_res)
7905 flow_dv_push_vlan_action_resource_release(dev_flow);
7906 if (dev_flow->dv.tag_resource)
7907 flow_dv_tag_release(dev, dev_flow->dv.tag_resource);
7913 * Query a dv flow rule for its statistics via devx.
7916 * Pointer to Ethernet device.
7918 * Pointer to the sub flow.
7920 * data retrieved by the query.
7922 * Perform verbose error reporting if not NULL.
7925 * 0 on success, a negative errno value otherwise and rte_errno is set.
7928 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
7929 void *data, struct rte_flow_error *error)
7931 struct mlx5_priv *priv = dev->data->dev_private;
7932 struct rte_flow_query_count *qc = data;
7934 if (!priv->config.devx)
7935 return rte_flow_error_set(error, ENOTSUP,
7936 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7938 "counters are not supported");
7939 if (flow->counter) {
7940 uint64_t pkts, bytes;
7941 int err = _flow_dv_query_count(dev, flow->counter, &pkts,
7945 return rte_flow_error_set(error, -err,
7946 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7947 NULL, "cannot read counters");
7950 qc->hits = pkts - flow->counter->hits;
7951 qc->bytes = bytes - flow->counter->bytes;
7953 flow->counter->hits = pkts;
7954 flow->counter->bytes = bytes;
7958 return rte_flow_error_set(error, EINVAL,
7959 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7961 "counters are not available");
7967 * @see rte_flow_query()
7971 flow_dv_query(struct rte_eth_dev *dev,
7972 struct rte_flow *flow __rte_unused,
7973 const struct rte_flow_action *actions __rte_unused,
7974 void *data __rte_unused,
7975 struct rte_flow_error *error __rte_unused)
7979 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7980 switch (actions->type) {
7981 case RTE_FLOW_ACTION_TYPE_VOID:
7983 case RTE_FLOW_ACTION_TYPE_COUNT:
7984 ret = flow_dv_query_count(dev, flow, data, error);
7987 return rte_flow_error_set(error, ENOTSUP,
7988 RTE_FLOW_ERROR_TYPE_ACTION,
7990 "action not supported");
7997 * Destroy the meter table set.
7998 * Lock free, (mutex should be acquired by caller).
8001 * Pointer to Ethernet device.
8003 * Pointer to the meter table set.
8009 flow_dv_destroy_mtr_tbl(struct rte_eth_dev *dev,
8010 struct mlx5_meter_domains_infos *tbl)
8012 struct mlx5_priv *priv = dev->data->dev_private;
8013 struct mlx5_meter_domains_infos *mtd =
8014 (struct mlx5_meter_domains_infos *)tbl;
8016 if (!mtd || !priv->config.dv_flow_en)
8018 if (mtd->ingress.policer_rules[RTE_MTR_DROPPED])
8019 claim_zero(mlx5_glue->dv_destroy_flow
8020 (mtd->ingress.policer_rules[RTE_MTR_DROPPED]));
8021 if (mtd->egress.policer_rules[RTE_MTR_DROPPED])
8022 claim_zero(mlx5_glue->dv_destroy_flow
8023 (mtd->egress.policer_rules[RTE_MTR_DROPPED]));
8024 if (mtd->transfer.policer_rules[RTE_MTR_DROPPED])
8025 claim_zero(mlx5_glue->dv_destroy_flow
8026 (mtd->transfer.policer_rules[RTE_MTR_DROPPED]));
8027 if (mtd->egress.color_matcher)
8028 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8029 (mtd->egress.color_matcher));
8030 if (mtd->egress.any_matcher)
8031 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8032 (mtd->egress.any_matcher));
8033 if (mtd->egress.tbl)
8034 claim_zero(flow_dv_tbl_resource_release(dev,
8036 if (mtd->ingress.color_matcher)
8037 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8038 (mtd->ingress.color_matcher));
8039 if (mtd->ingress.any_matcher)
8040 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8041 (mtd->ingress.any_matcher));
8042 if (mtd->ingress.tbl)
8043 claim_zero(flow_dv_tbl_resource_release(dev,
8045 if (mtd->transfer.color_matcher)
8046 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8047 (mtd->transfer.color_matcher));
8048 if (mtd->transfer.any_matcher)
8049 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8050 (mtd->transfer.any_matcher));
8051 if (mtd->transfer.tbl)
8052 claim_zero(flow_dv_tbl_resource_release(dev,
8053 mtd->transfer.tbl));
8055 claim_zero(mlx5_glue->destroy_flow_action(mtd->drop_actn));
8060 /* Number of meter flow actions, count and jump or count and drop. */
8061 #define METER_ACTIONS 2
8064 * Create specify domain meter table and suffix table.
8067 * Pointer to Ethernet device.
8068 * @param[in,out] mtb
8069 * Pointer to DV meter table set.
8072 * @param[in] transfer
8074 * @param[in] color_reg_c_idx
8075 * Reg C index for color match.
8078 * 0 on success, -1 otherwise and rte_errno is set.
8081 flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
8082 struct mlx5_meter_domains_infos *mtb,
8083 uint8_t egress, uint8_t transfer,
8084 uint32_t color_reg_c_idx)
8086 struct mlx5_priv *priv = dev->data->dev_private;
8087 struct mlx5_ibv_shared *sh = priv->sh;
8088 struct mlx5_flow_dv_match_params mask = {
8089 .size = sizeof(mask.buf),
8091 struct mlx5_flow_dv_match_params value = {
8092 .size = sizeof(value.buf),
8094 struct mlx5dv_flow_matcher_attr dv_attr = {
8095 .type = IBV_FLOW_ATTR_NORMAL,
8097 .match_criteria_enable = 0,
8098 .match_mask = (void *)&mask,
8100 void *actions[METER_ACTIONS];
8101 struct mlx5_flow_tbl_resource **sfx_tbl;
8102 struct mlx5_meter_domain_info *dtb;
8103 struct rte_flow_error error;
8107 sfx_tbl = &sh->fdb_mtr_sfx_tbl;
8108 dtb = &mtb->transfer;
8109 } else if (egress) {
8110 sfx_tbl = &sh->tx_mtr_sfx_tbl;
8113 sfx_tbl = &sh->rx_mtr_sfx_tbl;
8114 dtb = &mtb->ingress;
8116 /* If the suffix table in missing, create it. */
8118 *sfx_tbl = flow_dv_tbl_resource_get(dev,
8119 MLX5_FLOW_TABLE_LEVEL_SUFFIX,
8120 egress, transfer, &error);
8122 DRV_LOG(ERR, "Failed to create meter suffix table.");
8126 /* Create the meter table with METER level. */
8127 dtb->tbl = flow_dv_tbl_resource_get(dev, MLX5_FLOW_TABLE_LEVEL_METER,
8128 egress, transfer, &error);
8130 DRV_LOG(ERR, "Failed to create meter policer table.");
8133 /* Create matchers, Any and Color. */
8134 dv_attr.priority = 3;
8135 dv_attr.match_criteria_enable = 0;
8136 dtb->any_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
8139 if (!dtb->any_matcher) {
8140 DRV_LOG(ERR, "Failed to create meter"
8141 " policer default matcher.");
8144 dv_attr.priority = 0;
8145 dv_attr.match_criteria_enable =
8146 1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
8147 flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
8148 rte_col_2_mlx5_col(RTE_COLORS), UINT32_MAX);
8149 dtb->color_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
8152 if (!dtb->color_matcher) {
8153 DRV_LOG(ERR, "Failed to create meter policer color matcher.");
8156 if (mtb->count_actns[RTE_MTR_DROPPED])
8157 actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
8158 actions[i++] = mtb->drop_actn;
8159 /* Default rule: lowest priority, match any, actions: drop. */
8160 dtb->policer_rules[RTE_MTR_DROPPED] =
8161 mlx5_glue->dv_create_flow(dtb->any_matcher,
8162 (void *)&value, i, actions);
8163 if (!dtb->policer_rules[RTE_MTR_DROPPED]) {
8164 DRV_LOG(ERR, "Failed to create meter policer drop rule.");
8173 * Create the needed meter and suffix tables.
8174 * Lock free, (mutex should be acquired by caller).
8177 * Pointer to Ethernet device.
8179 * Pointer to the flow meter.
8182 * Pointer to table set on success, NULL otherwise and rte_errno is set.
8184 static struct mlx5_meter_domains_infos *
8185 flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
8186 const struct mlx5_flow_meter *fm)
8188 struct mlx5_priv *priv = dev->data->dev_private;
8189 struct mlx5_meter_domains_infos *mtb;
8193 if (!priv->mtr_en) {
8194 rte_errno = ENOTSUP;
8197 mtb = rte_calloc(__func__, 1, sizeof(*mtb), 0);
8199 DRV_LOG(ERR, "Failed to allocate memory for meter.");
8202 /* Create meter count actions */
8203 for (i = 0; i <= RTE_MTR_DROPPED; i++) {
8204 if (!fm->policer_stats.cnt[i])
8206 mtb->count_actns[i] = fm->policer_stats.cnt[i]->action;
8208 /* Create drop action. */
8209 mtb->drop_actn = mlx5_glue->dr_create_flow_action_drop();
8210 if (!mtb->drop_actn) {
8211 DRV_LOG(ERR, "Failed to create drop action.");
8214 /* Egress meter table. */
8215 ret = flow_dv_prepare_mtr_tables(dev, mtb, 1, 0, priv->mtr_color_reg);
8217 DRV_LOG(ERR, "Failed to prepare egress meter table.");
8220 /* Ingress meter table. */
8221 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 0, priv->mtr_color_reg);
8223 DRV_LOG(ERR, "Failed to prepare ingress meter table.");
8226 /* FDB meter table. */
8227 if (priv->config.dv_esw_en) {
8228 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 1,
8229 priv->mtr_color_reg);
8231 DRV_LOG(ERR, "Failed to prepare fdb meter table.");
8237 flow_dv_destroy_mtr_tbl(dev, mtb);
8242 * Destroy domain policer rule.
8245 * Pointer to domain table.
8248 flow_dv_destroy_domain_policer_rule(struct mlx5_meter_domain_info *dt)
8252 for (i = 0; i < RTE_MTR_DROPPED; i++) {
8253 if (dt->policer_rules[i]) {
8254 claim_zero(mlx5_glue->dv_destroy_flow
8255 (dt->policer_rules[i]));
8256 dt->policer_rules[i] = NULL;
8259 if (dt->jump_actn) {
8260 claim_zero(mlx5_glue->destroy_flow_action(dt->jump_actn));
8261 dt->jump_actn = NULL;
8266 * Destroy policer rules.
8269 * Pointer to Ethernet device.
8271 * Pointer to flow meter structure.
8273 * Pointer to flow attributes.
8279 flow_dv_destroy_policer_rules(struct rte_eth_dev *dev __rte_unused,
8280 const struct mlx5_flow_meter *fm,
8281 const struct rte_flow_attr *attr)
8283 struct mlx5_meter_domains_infos *mtb = fm ? fm->mfts : NULL;
8288 flow_dv_destroy_domain_policer_rule(&mtb->egress);
8290 flow_dv_destroy_domain_policer_rule(&mtb->ingress);
8292 flow_dv_destroy_domain_policer_rule(&mtb->transfer);
8297 * Create specify domain meter policer rule.
8300 * Pointer to flow meter structure.
8302 * Pointer to DV meter table set.
8304 * Pointer to suffix table.
8305 * @param[in] mtr_reg_c
8306 * Color match REG_C.
8309 * 0 on success, -1 otherwise.
8312 flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
8313 struct mlx5_meter_domain_info *dtb,
8314 struct mlx5_flow_tbl_resource *sfx_tb,
8317 struct mlx5_flow_dv_match_params matcher = {
8318 .size = sizeof(matcher.buf),
8320 struct mlx5_flow_dv_match_params value = {
8321 .size = sizeof(value.buf),
8323 struct mlx5_meter_domains_infos *mtb = fm->mfts;
8324 void *actions[METER_ACTIONS];
8327 /* Create jump action. */
8330 if (!dtb->jump_actn)
8332 mlx5_glue->dr_create_flow_action_dest_flow_tbl
8334 if (!dtb->jump_actn) {
8335 DRV_LOG(ERR, "Failed to create policer jump action.");
8338 for (i = 0; i < RTE_MTR_DROPPED; i++) {
8341 flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
8342 rte_col_2_mlx5_col(i), UINT32_MAX);
8343 if (mtb->count_actns[i])
8344 actions[j++] = mtb->count_actns[i];
8345 if (fm->params.action[i] == MTR_POLICER_ACTION_DROP)
8346 actions[j++] = mtb->drop_actn;
8348 actions[j++] = dtb->jump_actn;
8349 dtb->policer_rules[i] =
8350 mlx5_glue->dv_create_flow(dtb->color_matcher,
8353 if (!dtb->policer_rules[i]) {
8354 DRV_LOG(ERR, "Failed to create policer rule.");
8365 * Create policer rules.
8368 * Pointer to Ethernet device.
8370 * Pointer to flow meter structure.
8372 * Pointer to flow attributes.
8375 * 0 on success, -1 otherwise.
8378 flow_dv_create_policer_rules(struct rte_eth_dev *dev,
8379 struct mlx5_flow_meter *fm,
8380 const struct rte_flow_attr *attr)
8382 struct mlx5_priv *priv = dev->data->dev_private;
8383 struct mlx5_meter_domains_infos *mtb = fm->mfts;
8387 ret = flow_dv_create_policer_forward_rule(fm, &mtb->egress,
8388 priv->sh->tx_mtr_sfx_tbl,
8389 priv->mtr_color_reg);
8391 DRV_LOG(ERR, "Failed to create egress policer.");
8395 if (attr->ingress) {
8396 ret = flow_dv_create_policer_forward_rule(fm, &mtb->ingress,
8397 priv->sh->rx_mtr_sfx_tbl,
8398 priv->mtr_color_reg);
8400 DRV_LOG(ERR, "Failed to create ingress policer.");
8404 if (attr->transfer) {
8405 ret = flow_dv_create_policer_forward_rule(fm, &mtb->transfer,
8406 priv->sh->fdb_mtr_sfx_tbl,
8407 priv->mtr_color_reg);
8409 DRV_LOG(ERR, "Failed to create transfer policer.");
8415 flow_dv_destroy_policer_rules(dev, fm, attr);
8420 * Query a devx counter.
8423 * Pointer to the Ethernet device structure.
8425 * Pointer to the flow counter.
8427 * Set to clear the counter statistics.
8429 * The statistics value of packets.
8431 * The statistics value of bytes.
8434 * 0 on success, otherwise return -1.
8437 flow_dv_counter_query(struct rte_eth_dev *dev,
8438 struct mlx5_flow_counter *cnt, bool clear,
8439 uint64_t *pkts, uint64_t *bytes)
8441 struct mlx5_priv *priv = dev->data->dev_private;
8442 uint64_t inn_pkts, inn_bytes;
8445 if (!priv->config.devx)
8447 ret = _flow_dv_query_count(dev, cnt, &inn_pkts, &inn_bytes);
8450 *pkts = inn_pkts - cnt->hits;
8451 *bytes = inn_bytes - cnt->bytes;
8453 cnt->hits = inn_pkts;
8454 cnt->bytes = inn_bytes;
8460 * Mutex-protected thunk to lock-free __flow_dv_translate().
8463 flow_dv_translate(struct rte_eth_dev *dev,
8464 struct mlx5_flow *dev_flow,
8465 const struct rte_flow_attr *attr,
8466 const struct rte_flow_item items[],
8467 const struct rte_flow_action actions[],
8468 struct rte_flow_error *error)
8472 flow_dv_shared_lock(dev);
8473 ret = __flow_dv_translate(dev, dev_flow, attr, items, actions, error);
8474 flow_dv_shared_unlock(dev);
8479 * Mutex-protected thunk to lock-free __flow_dv_apply().
8482 flow_dv_apply(struct rte_eth_dev *dev,
8483 struct rte_flow *flow,
8484 struct rte_flow_error *error)
8488 flow_dv_shared_lock(dev);
8489 ret = __flow_dv_apply(dev, flow, error);
8490 flow_dv_shared_unlock(dev);
8495 * Mutex-protected thunk to lock-free __flow_dv_remove().
8498 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
8500 flow_dv_shared_lock(dev);
8501 __flow_dv_remove(dev, flow);
8502 flow_dv_shared_unlock(dev);
8506 * Mutex-protected thunk to lock-free __flow_dv_destroy().
8509 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
8511 flow_dv_shared_lock(dev);
8512 __flow_dv_destroy(dev, flow);
8513 flow_dv_shared_unlock(dev);
8517 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
8519 static struct mlx5_flow_counter *
8520 flow_dv_counter_allocate(struct rte_eth_dev *dev)
8522 struct mlx5_flow_counter *cnt;
8524 flow_dv_shared_lock(dev);
8525 cnt = flow_dv_counter_alloc(dev, 0, 0, 1);
8526 flow_dv_shared_unlock(dev);
8531 * Mutex-protected thunk to lock-free flow_dv_counter_release().
8534 flow_dv_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt)
8536 flow_dv_shared_lock(dev);
8537 flow_dv_counter_release(dev, cnt);
8538 flow_dv_shared_unlock(dev);
8541 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
8542 .validate = flow_dv_validate,
8543 .prepare = flow_dv_prepare,
8544 .translate = flow_dv_translate,
8545 .apply = flow_dv_apply,
8546 .remove = flow_dv_remove,
8547 .destroy = flow_dv_destroy,
8548 .query = flow_dv_query,
8549 .create_mtr_tbls = flow_dv_create_mtr_tbl,
8550 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbl,
8551 .create_policer_rules = flow_dv_create_policer_rules,
8552 .destroy_policer_rules = flow_dv_destroy_policer_rules,
8553 .counter_alloc = flow_dv_counter_allocate,
8554 .counter_free = flow_dv_counter_free,
8555 .counter_query = flow_dv_counter_query,
8558 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */