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);
5927 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
5928 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
5931 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
5932 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
5935 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, mask);
5936 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, data);
5939 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
5940 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
5943 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
5944 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
5947 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
5948 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
5951 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
5952 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
5955 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
5956 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
5959 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
5960 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
5963 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
5964 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
5973 * Add MARK item to matcher
5976 * The device to configure through.
5977 * @param[in, out] matcher
5979 * @param[in, out] key
5980 * Flow matcher value.
5982 * Flow pattern to translate.
5985 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
5986 void *matcher, void *key,
5987 const struct rte_flow_item *item)
5989 struct mlx5_priv *priv = dev->data->dev_private;
5990 const struct rte_flow_item_mark *mark;
5994 mark = item->mask ? (const void *)item->mask :
5995 &rte_flow_item_mark_mask;
5996 mask = mark->id & priv->sh->dv_mark_mask;
5997 mark = (const void *)item->spec;
5999 value = mark->id & priv->sh->dv_mark_mask & mask;
6001 enum modify_reg reg;
6003 /* Get the metadata register index for the mark. */
6004 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
6006 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6011 * Add META item to matcher
6014 * The devich to configure through.
6015 * @param[in, out] matcher
6017 * @param[in, out] key
6018 * Flow matcher value.
6020 * Attributes of flow that includes this item.
6022 * Flow pattern to translate.
6025 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
6026 void *matcher, void *key,
6027 const struct rte_flow_attr *attr,
6028 const struct rte_flow_item *item)
6030 const struct rte_flow_item_meta *meta_m;
6031 const struct rte_flow_item_meta *meta_v;
6033 meta_m = (const void *)item->mask;
6035 meta_m = &rte_flow_item_meta_mask;
6036 meta_v = (const void *)item->spec;
6038 enum modify_reg reg;
6039 uint32_t value = meta_v->data;
6040 uint32_t mask = meta_m->data;
6042 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
6046 * In datapath code there is no endianness
6047 * coversions for perfromance reasons, all
6048 * pattern conversions are done in rte_flow.
6050 value = rte_cpu_to_be_32(value);
6051 mask = rte_cpu_to_be_32(mask);
6052 if (reg == REG_C_0) {
6053 struct mlx5_priv *priv = dev->data->dev_private;
6054 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6055 uint32_t shl_c0 = rte_bsf32(msk_c0);
6057 msk_c0 = rte_cpu_to_be_32(msk_c0);
6061 assert(!(~msk_c0 & mask));
6063 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6068 * Add vport metadata Reg C0 item to matcher
6070 * @param[in, out] matcher
6072 * @param[in, out] key
6073 * Flow matcher value.
6075 * Flow pattern to translate.
6078 flow_dv_translate_item_meta_vport(void *matcher, void *key,
6079 uint32_t value, uint32_t mask)
6081 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
6085 * Add tag item to matcher
6087 * @param[in, out] matcher
6089 * @param[in, out] key
6090 * Flow matcher value.
6092 * Flow pattern to translate.
6095 flow_dv_translate_mlx5_item_tag(void *matcher, void *key,
6096 const struct rte_flow_item *item)
6098 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
6099 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
6102 flow_dv_match_meta_reg(matcher, key, tag_v->id, tag_v->data,
6103 tag_m ? tag_m->data : UINT32_MAX);
6107 * Add TAG item to matcher
6110 * The devich to configure through.
6111 * @param[in, out] matcher
6113 * @param[in, out] key
6114 * Flow matcher value.
6116 * Flow pattern to translate.
6119 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
6120 void *matcher, void *key,
6121 const struct rte_flow_item *item)
6123 const struct rte_flow_item_tag *tag_v = item->spec;
6124 const struct rte_flow_item_tag *tag_m = item->mask;
6125 enum modify_reg reg;
6128 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
6129 /* Get the metadata register index for the tag. */
6130 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
6132 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
6136 * Add source vport match to the specified matcher.
6138 * @param[in, out] matcher
6140 * @param[in, out] key
6141 * Flow matcher value.
6143 * Source vport value to match
6148 flow_dv_translate_item_source_vport(void *matcher, void *key,
6149 int16_t port, uint16_t mask)
6151 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6152 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6154 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
6155 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
6159 * Translate port-id item to eswitch match on port-id.
6162 * The devich to configure through.
6163 * @param[in, out] matcher
6165 * @param[in, out] key
6166 * Flow matcher value.
6168 * Flow pattern to translate.
6171 * 0 on success, a negative errno value otherwise.
6174 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
6175 void *key, const struct rte_flow_item *item)
6177 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
6178 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
6179 struct mlx5_priv *priv;
6182 mask = pid_m ? pid_m->id : 0xffff;
6183 id = pid_v ? pid_v->id : dev->data->port_id;
6184 priv = mlx5_port_to_eswitch_info(id, item == NULL);
6187 /* Translate to vport field or to metadata, depending on mode. */
6188 if (priv->vport_meta_mask)
6189 flow_dv_translate_item_meta_vport(matcher, key,
6190 priv->vport_meta_tag,
6191 priv->vport_meta_mask);
6193 flow_dv_translate_item_source_vport(matcher, key,
6194 priv->vport_id, mask);
6199 * Add ICMP6 item to matcher and to the value.
6201 * @param[in, out] matcher
6203 * @param[in, out] key
6204 * Flow matcher value.
6206 * Flow pattern to translate.
6208 * Item is inner pattern.
6211 flow_dv_translate_item_icmp6(void *matcher, void *key,
6212 const struct rte_flow_item *item,
6215 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
6216 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
6219 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
6221 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6223 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6225 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6227 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6229 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6231 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
6232 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
6236 icmp6_m = &rte_flow_item_icmp6_mask;
6237 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
6238 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
6239 icmp6_v->type & icmp6_m->type);
6240 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
6241 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
6242 icmp6_v->code & icmp6_m->code);
6246 * Add ICMP item to matcher and to the value.
6248 * @param[in, out] matcher
6250 * @param[in, out] key
6251 * Flow matcher value.
6253 * Flow pattern to translate.
6255 * Item is inner pattern.
6258 flow_dv_translate_item_icmp(void *matcher, void *key,
6259 const struct rte_flow_item *item,
6262 const struct rte_flow_item_icmp *icmp_m = item->mask;
6263 const struct rte_flow_item_icmp *icmp_v = item->spec;
6266 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
6268 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6270 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6272 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6274 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6276 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6278 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
6279 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
6283 icmp_m = &rte_flow_item_icmp_mask;
6284 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
6285 icmp_m->hdr.icmp_type);
6286 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
6287 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
6288 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
6289 icmp_m->hdr.icmp_code);
6290 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
6291 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
6294 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
6296 #define HEADER_IS_ZERO(match_criteria, headers) \
6297 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
6298 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
6301 * Calculate flow matcher enable bitmap.
6303 * @param match_criteria
6304 * Pointer to flow matcher criteria.
6307 * Bitmap of enabled fields.
6310 flow_dv_matcher_enable(uint32_t *match_criteria)
6312 uint8_t match_criteria_enable;
6314 match_criteria_enable =
6315 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
6316 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
6317 match_criteria_enable |=
6318 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
6319 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
6320 match_criteria_enable |=
6321 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
6322 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
6323 match_criteria_enable |=
6324 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
6325 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
6326 match_criteria_enable |=
6327 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
6328 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
6329 return match_criteria_enable;
6336 * @param[in, out] dev
6337 * Pointer to rte_eth_dev structure.
6338 * @param[in] table_id
6341 * Direction of the table.
6342 * @param[in] transfer
6343 * E-Switch or NIC flow.
6345 * pointer to error structure.
6348 * Returns tables resource based on the index, NULL in case of failed.
6350 static struct mlx5_flow_tbl_resource *
6351 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
6352 uint32_t table_id, uint8_t egress,
6354 struct rte_flow_error *error)
6356 struct mlx5_priv *priv = dev->data->dev_private;
6357 struct mlx5_ibv_shared *sh = priv->sh;
6358 struct mlx5_flow_tbl_resource *tbl;
6359 union mlx5_flow_tbl_key table_key = {
6361 .table_id = table_id,
6363 .domain = !!transfer,
6364 .direction = !!egress,
6367 struct mlx5_hlist_entry *pos = mlx5_hlist_lookup(sh->flow_tbls,
6369 struct mlx5_flow_tbl_data_entry *tbl_data;
6374 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
6376 tbl = &tbl_data->tbl;
6377 rte_atomic32_inc(&tbl->refcnt);
6380 tbl_data = rte_zmalloc(NULL, sizeof(*tbl_data), 0);
6382 rte_flow_error_set(error, ENOMEM,
6383 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6385 "cannot allocate flow table data entry");
6388 tbl = &tbl_data->tbl;
6389 pos = &tbl_data->entry;
6391 domain = sh->fdb_domain;
6393 domain = sh->tx_domain;
6395 domain = sh->rx_domain;
6396 tbl->obj = mlx5_glue->dr_create_flow_tbl(domain, table_id);
6398 rte_flow_error_set(error, ENOMEM,
6399 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6400 NULL, "cannot create flow table object");
6405 * No multi-threads now, but still better to initialize the reference
6406 * count before insert it into the hash list.
6408 rte_atomic32_init(&tbl->refcnt);
6409 /* Jump action reference count is initialized here. */
6410 rte_atomic32_init(&tbl_data->jump.refcnt);
6411 pos->key = table_key.v64;
6412 ret = mlx5_hlist_insert(sh->flow_tbls, pos);
6414 rte_flow_error_set(error, -ret,
6415 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6416 "cannot insert flow table data entry");
6417 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
6420 rte_atomic32_inc(&tbl->refcnt);
6425 * Release a flow table.
6428 * Pointer to rte_eth_dev structure.
6430 * Table resource to be released.
6433 * Returns 0 if table was released, else return 1;
6436 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
6437 struct mlx5_flow_tbl_resource *tbl)
6439 struct mlx5_priv *priv = dev->data->dev_private;
6440 struct mlx5_ibv_shared *sh = priv->sh;
6441 struct mlx5_flow_tbl_data_entry *tbl_data =
6442 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
6446 if (rte_atomic32_dec_and_test(&tbl->refcnt)) {
6447 struct mlx5_hlist_entry *pos = &tbl_data->entry;
6449 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
6451 /* remove the entry from the hash list and free memory. */
6452 mlx5_hlist_remove(sh->flow_tbls, pos);
6460 * Register the flow matcher.
6462 * @param[in, out] dev
6463 * Pointer to rte_eth_dev structure.
6464 * @param[in, out] matcher
6465 * Pointer to flow matcher.
6466 * @param[in, out] key
6467 * Pointer to flow table key.
6468 * @parm[in, out] dev_flow
6469 * Pointer to the dev_flow.
6471 * pointer to error structure.
6474 * 0 on success otherwise -errno and errno is set.
6477 flow_dv_matcher_register(struct rte_eth_dev *dev,
6478 struct mlx5_flow_dv_matcher *matcher,
6479 union mlx5_flow_tbl_key *key,
6480 struct mlx5_flow *dev_flow,
6481 struct rte_flow_error *error)
6483 struct mlx5_priv *priv = dev->data->dev_private;
6484 struct mlx5_ibv_shared *sh = priv->sh;
6485 struct mlx5_flow_dv_matcher *cache_matcher;
6486 struct mlx5dv_flow_matcher_attr dv_attr = {
6487 .type = IBV_FLOW_ATTR_NORMAL,
6488 .match_mask = (void *)&matcher->mask,
6490 struct mlx5_flow_tbl_resource *tbl;
6491 struct mlx5_flow_tbl_data_entry *tbl_data;
6493 tbl = flow_dv_tbl_resource_get(dev, key->table_id, key->direction,
6494 key->domain, error);
6496 return -rte_errno; /* No need to refill the error info */
6497 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
6498 /* Lookup from cache. */
6499 LIST_FOREACH(cache_matcher, &tbl_data->matchers, next) {
6500 if (matcher->crc == cache_matcher->crc &&
6501 matcher->priority == cache_matcher->priority &&
6502 !memcmp((const void *)matcher->mask.buf,
6503 (const void *)cache_matcher->mask.buf,
6504 cache_matcher->mask.size)) {
6506 "%s group %u priority %hd use %s "
6507 "matcher %p: refcnt %d++",
6508 key->domain ? "FDB" : "NIC", key->table_id,
6509 cache_matcher->priority,
6510 key->direction ? "tx" : "rx",
6511 (void *)cache_matcher,
6512 rte_atomic32_read(&cache_matcher->refcnt));
6513 rte_atomic32_inc(&cache_matcher->refcnt);
6514 dev_flow->dv.matcher = cache_matcher;
6515 /* old matcher should not make the table ref++. */
6516 flow_dv_tbl_resource_release(dev, tbl);
6520 /* Register new matcher. */
6521 cache_matcher = rte_calloc(__func__, 1, sizeof(*cache_matcher), 0);
6522 if (!cache_matcher) {
6523 flow_dv_tbl_resource_release(dev, tbl);
6524 return rte_flow_error_set(error, ENOMEM,
6525 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6526 "cannot allocate matcher memory");
6528 *cache_matcher = *matcher;
6529 dv_attr.match_criteria_enable =
6530 flow_dv_matcher_enable(cache_matcher->mask.buf);
6531 dv_attr.priority = matcher->priority;
6533 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
6534 cache_matcher->matcher_object =
6535 mlx5_glue->dv_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj);
6536 if (!cache_matcher->matcher_object) {
6537 rte_free(cache_matcher);
6538 #ifdef HAVE_MLX5DV_DR
6539 flow_dv_tbl_resource_release(dev, tbl);
6541 return rte_flow_error_set(error, ENOMEM,
6542 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6543 NULL, "cannot create matcher");
6545 /* Save the table information */
6546 cache_matcher->tbl = tbl;
6547 rte_atomic32_init(&cache_matcher->refcnt);
6548 /* only matcher ref++, table ref++ already done above in get API. */
6549 rte_atomic32_inc(&cache_matcher->refcnt);
6550 LIST_INSERT_HEAD(&tbl_data->matchers, cache_matcher, next);
6551 dev_flow->dv.matcher = cache_matcher;
6552 DRV_LOG(DEBUG, "%s group %u priority %hd new %s matcher %p: refcnt %d",
6553 key->domain ? "FDB" : "NIC", key->table_id,
6554 cache_matcher->priority,
6555 key->direction ? "tx" : "rx", (void *)cache_matcher,
6556 rte_atomic32_read(&cache_matcher->refcnt));
6561 * Find existing tag resource or create and register a new one.
6563 * @param dev[in, out]
6564 * Pointer to rte_eth_dev structure.
6565 * @param[in, out] tag_be24
6566 * Tag value in big endian then R-shift 8.
6567 * @parm[in, out] dev_flow
6568 * Pointer to the dev_flow.
6570 * pointer to error structure.
6573 * 0 on success otherwise -errno and errno is set.
6576 flow_dv_tag_resource_register
6577 (struct rte_eth_dev *dev,
6579 struct mlx5_flow *dev_flow,
6580 struct rte_flow_error *error)
6582 struct mlx5_priv *priv = dev->data->dev_private;
6583 struct mlx5_ibv_shared *sh = priv->sh;
6584 struct mlx5_flow_dv_tag_resource *cache_resource;
6585 struct mlx5_hlist_entry *entry;
6587 /* Lookup a matching resource from cache. */
6588 entry = mlx5_hlist_lookup(sh->tag_table, (uint64_t)tag_be24);
6590 cache_resource = container_of
6591 (entry, struct mlx5_flow_dv_tag_resource, entry);
6592 rte_atomic32_inc(&cache_resource->refcnt);
6593 dev_flow->dv.tag_resource = cache_resource;
6594 DRV_LOG(DEBUG, "cached tag resource %p: refcnt now %d++",
6595 (void *)cache_resource,
6596 rte_atomic32_read(&cache_resource->refcnt));
6599 /* Register new resource. */
6600 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
6601 if (!cache_resource)
6602 return rte_flow_error_set(error, ENOMEM,
6603 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6604 "cannot allocate resource memory");
6605 cache_resource->entry.key = (uint64_t)tag_be24;
6606 cache_resource->action = mlx5_glue->dv_create_flow_action_tag(tag_be24);
6607 if (!cache_resource->action) {
6608 rte_free(cache_resource);
6609 return rte_flow_error_set(error, ENOMEM,
6610 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6611 NULL, "cannot create action");
6613 rte_atomic32_init(&cache_resource->refcnt);
6614 rte_atomic32_inc(&cache_resource->refcnt);
6615 if (mlx5_hlist_insert(sh->tag_table, &cache_resource->entry)) {
6616 mlx5_glue->destroy_flow_action(cache_resource->action);
6617 rte_free(cache_resource);
6618 return rte_flow_error_set(error, EEXIST,
6619 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6620 NULL, "cannot insert tag");
6622 dev_flow->dv.tag_resource = cache_resource;
6623 DRV_LOG(DEBUG, "new tag resource %p: refcnt now %d++",
6624 (void *)cache_resource,
6625 rte_atomic32_read(&cache_resource->refcnt));
6633 * Pointer to Ethernet device.
6635 * Pointer to mlx5_flow.
6638 * 1 while a reference on it exists, 0 when freed.
6641 flow_dv_tag_release(struct rte_eth_dev *dev,
6642 struct mlx5_flow_dv_tag_resource *tag)
6644 struct mlx5_priv *priv = dev->data->dev_private;
6645 struct mlx5_ibv_shared *sh = priv->sh;
6648 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
6649 dev->data->port_id, (void *)tag,
6650 rte_atomic32_read(&tag->refcnt));
6651 if (rte_atomic32_dec_and_test(&tag->refcnt)) {
6652 claim_zero(mlx5_glue->destroy_flow_action(tag->action));
6653 mlx5_hlist_remove(sh->tag_table, &tag->entry);
6654 DRV_LOG(DEBUG, "port %u tag %p: removed",
6655 dev->data->port_id, (void *)tag);
6663 * Translate port ID action to vport.
6666 * Pointer to rte_eth_dev structure.
6668 * Pointer to the port ID action.
6669 * @param[out] dst_port_id
6670 * The target port ID.
6672 * Pointer to the error structure.
6675 * 0 on success, a negative errno value otherwise and rte_errno is set.
6678 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
6679 const struct rte_flow_action *action,
6680 uint32_t *dst_port_id,
6681 struct rte_flow_error *error)
6684 struct mlx5_priv *priv;
6685 const struct rte_flow_action_port_id *conf =
6686 (const struct rte_flow_action_port_id *)action->conf;
6688 port = conf->original ? dev->data->port_id : conf->id;
6689 priv = mlx5_port_to_eswitch_info(port, false);
6691 return rte_flow_error_set(error, -rte_errno,
6692 RTE_FLOW_ERROR_TYPE_ACTION,
6694 "No eswitch info was found for port");
6695 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
6697 * This parameter is transferred to
6698 * mlx5dv_dr_action_create_dest_ib_port().
6700 *dst_port_id = priv->ibv_port;
6703 * Legacy mode, no LAG configurations is supported.
6704 * This parameter is transferred to
6705 * mlx5dv_dr_action_create_dest_vport().
6707 *dst_port_id = priv->vport_id;
6713 * Add Tx queue matcher
6716 * Pointer to the dev struct.
6717 * @param[in, out] matcher
6719 * @param[in, out] key
6720 * Flow matcher value.
6722 * Flow pattern to translate.
6724 * Item is inner pattern.
6727 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
6728 void *matcher, void *key,
6729 const struct rte_flow_item *item)
6731 const struct mlx5_rte_flow_item_tx_queue *queue_m;
6732 const struct mlx5_rte_flow_item_tx_queue *queue_v;
6734 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6736 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6737 struct mlx5_txq_ctrl *txq;
6741 queue_m = (const void *)item->mask;
6744 queue_v = (const void *)item->spec;
6747 txq = mlx5_txq_get(dev, queue_v->queue);
6750 queue = txq->obj->sq->id;
6751 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
6752 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
6753 queue & queue_m->queue);
6754 mlx5_txq_release(dev, queue_v->queue);
6758 * Set the hash fields according to the @p flow information.
6760 * @param[in] dev_flow
6761 * Pointer to the mlx5_flow.
6764 flow_dv_hashfields_set(struct mlx5_flow *dev_flow)
6766 struct rte_flow *flow = dev_flow->flow;
6767 uint64_t items = dev_flow->layers;
6769 uint64_t rss_types = rte_eth_rss_hf_refine(flow->rss.types);
6771 dev_flow->hash_fields = 0;
6772 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
6773 if (flow->rss.level >= 2) {
6774 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
6778 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
6779 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
6780 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
6781 if (rss_types & ETH_RSS_L3_SRC_ONLY)
6782 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
6783 else if (rss_types & ETH_RSS_L3_DST_ONLY)
6784 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
6786 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
6788 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
6789 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
6790 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
6791 if (rss_types & ETH_RSS_L3_SRC_ONLY)
6792 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
6793 else if (rss_types & ETH_RSS_L3_DST_ONLY)
6794 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
6796 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
6799 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
6800 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
6801 if (rss_types & ETH_RSS_UDP) {
6802 if (rss_types & ETH_RSS_L4_SRC_ONLY)
6803 dev_flow->hash_fields |=
6804 IBV_RX_HASH_SRC_PORT_UDP;
6805 else if (rss_types & ETH_RSS_L4_DST_ONLY)
6806 dev_flow->hash_fields |=
6807 IBV_RX_HASH_DST_PORT_UDP;
6809 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
6811 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
6812 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
6813 if (rss_types & ETH_RSS_TCP) {
6814 if (rss_types & ETH_RSS_L4_SRC_ONLY)
6815 dev_flow->hash_fields |=
6816 IBV_RX_HASH_SRC_PORT_TCP;
6817 else if (rss_types & ETH_RSS_L4_DST_ONLY)
6818 dev_flow->hash_fields |=
6819 IBV_RX_HASH_DST_PORT_TCP;
6821 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
6827 * Fill the flow with DV spec, lock free
6828 * (mutex should be acquired by caller).
6831 * Pointer to rte_eth_dev structure.
6832 * @param[in, out] dev_flow
6833 * Pointer to the sub flow.
6835 * Pointer to the flow attributes.
6837 * Pointer to the list of items.
6838 * @param[in] actions
6839 * Pointer to the list of actions.
6841 * Pointer to the error structure.
6844 * 0 on success, a negative errno value otherwise and rte_errno is set.
6847 __flow_dv_translate(struct rte_eth_dev *dev,
6848 struct mlx5_flow *dev_flow,
6849 const struct rte_flow_attr *attr,
6850 const struct rte_flow_item items[],
6851 const struct rte_flow_action actions[],
6852 struct rte_flow_error *error)
6854 struct mlx5_priv *priv = dev->data->dev_private;
6855 struct mlx5_dev_config *dev_conf = &priv->config;
6856 struct rte_flow *flow = dev_flow->flow;
6857 uint64_t item_flags = 0;
6858 uint64_t last_item = 0;
6859 uint64_t action_flags = 0;
6860 uint64_t priority = attr->priority;
6861 struct mlx5_flow_dv_matcher matcher = {
6863 .size = sizeof(matcher.mask.buf),
6867 bool actions_end = false;
6868 struct mlx5_flow_dv_modify_hdr_resource mhdr_res = {
6869 .ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
6870 MLX5DV_FLOW_TABLE_TYPE_NIC_RX
6872 union flow_dv_attr flow_attr = { .attr = 0 };
6874 union mlx5_flow_tbl_key tbl_key;
6875 uint32_t modify_action_position = UINT32_MAX;
6876 void *match_mask = matcher.mask.buf;
6877 void *match_value = dev_flow->dv.value.buf;
6878 uint8_t next_protocol = 0xff;
6879 struct rte_vlan_hdr vlan = { 0 };
6883 ret = mlx5_flow_group_to_table(attr, dev_flow->external, attr->group,
6887 dev_flow->group = table;
6889 mhdr_res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
6890 if (priority == MLX5_FLOW_PRIO_RSVD)
6891 priority = dev_conf->flow_prio - 1;
6892 for (; !actions_end ; actions++) {
6893 const struct rte_flow_action_queue *queue;
6894 const struct rte_flow_action_rss *rss;
6895 const struct rte_flow_action *action = actions;
6896 const struct rte_flow_action_count *count = action->conf;
6897 const uint8_t *rss_key;
6898 const struct rte_flow_action_jump *jump_data;
6899 const struct rte_flow_action_meter *mtr;
6900 struct mlx5_flow_tbl_resource *tbl;
6901 uint32_t port_id = 0;
6902 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
6903 int action_type = actions->type;
6904 const struct rte_flow_action *found_action = NULL;
6906 switch (action_type) {
6907 case RTE_FLOW_ACTION_TYPE_VOID:
6909 case RTE_FLOW_ACTION_TYPE_PORT_ID:
6910 if (flow_dv_translate_action_port_id(dev, action,
6913 port_id_resource.port_id = port_id;
6914 if (flow_dv_port_id_action_resource_register
6915 (dev, &port_id_resource, dev_flow, error))
6917 dev_flow->dv.actions[actions_n++] =
6918 dev_flow->dv.port_id_action->action;
6919 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6921 case RTE_FLOW_ACTION_TYPE_FLAG:
6922 action_flags |= MLX5_FLOW_ACTION_FLAG;
6923 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
6924 struct rte_flow_action_mark mark = {
6925 .id = MLX5_FLOW_MARK_DEFAULT,
6928 if (flow_dv_convert_action_mark(dev, &mark,
6932 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
6935 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
6936 if (!dev_flow->dv.tag_resource)
6937 if (flow_dv_tag_resource_register
6938 (dev, tag_be, dev_flow, error))
6940 dev_flow->dv.actions[actions_n++] =
6941 dev_flow->dv.tag_resource->action;
6943 case RTE_FLOW_ACTION_TYPE_MARK:
6944 action_flags |= MLX5_FLOW_ACTION_MARK;
6945 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
6946 const struct rte_flow_action_mark *mark =
6947 (const struct rte_flow_action_mark *)
6950 if (flow_dv_convert_action_mark(dev, mark,
6954 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
6958 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
6959 /* Legacy (non-extensive) MARK action. */
6960 tag_be = mlx5_flow_mark_set
6961 (((const struct rte_flow_action_mark *)
6962 (actions->conf))->id);
6963 if (!dev_flow->dv.tag_resource)
6964 if (flow_dv_tag_resource_register
6965 (dev, tag_be, dev_flow, error))
6967 dev_flow->dv.actions[actions_n++] =
6968 dev_flow->dv.tag_resource->action;
6970 case RTE_FLOW_ACTION_TYPE_SET_META:
6971 if (flow_dv_convert_action_set_meta
6972 (dev, &mhdr_res, attr,
6973 (const struct rte_flow_action_set_meta *)
6974 actions->conf, error))
6976 action_flags |= MLX5_FLOW_ACTION_SET_META;
6978 case RTE_FLOW_ACTION_TYPE_SET_TAG:
6979 if (flow_dv_convert_action_set_tag
6981 (const struct rte_flow_action_set_tag *)
6982 actions->conf, error))
6984 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
6986 case RTE_FLOW_ACTION_TYPE_DROP:
6987 action_flags |= MLX5_FLOW_ACTION_DROP;
6989 case RTE_FLOW_ACTION_TYPE_QUEUE:
6990 assert(flow->rss.queue);
6991 queue = actions->conf;
6992 flow->rss.queue_num = 1;
6993 (*flow->rss.queue)[0] = queue->index;
6994 action_flags |= MLX5_FLOW_ACTION_QUEUE;
6996 case RTE_FLOW_ACTION_TYPE_RSS:
6997 assert(flow->rss.queue);
6998 rss = actions->conf;
6999 if (flow->rss.queue)
7000 memcpy((*flow->rss.queue), rss->queue,
7001 rss->queue_num * sizeof(uint16_t));
7002 flow->rss.queue_num = rss->queue_num;
7003 /* NULL RSS key indicates default RSS key. */
7004 rss_key = !rss->key ? rss_hash_default_key : rss->key;
7005 memcpy(flow->rss.key, rss_key, MLX5_RSS_HASH_KEY_LEN);
7007 * rss->level and rss.types should be set in advance
7008 * when expanding items for RSS.
7010 action_flags |= MLX5_FLOW_ACTION_RSS;
7012 case RTE_FLOW_ACTION_TYPE_COUNT:
7013 if (!dev_conf->devx) {
7014 rte_errno = ENOTSUP;
7017 flow->counter = flow_dv_counter_alloc(dev,
7021 if (flow->counter == NULL)
7023 dev_flow->dv.actions[actions_n++] =
7024 flow->counter->action;
7025 action_flags |= MLX5_FLOW_ACTION_COUNT;
7028 if (rte_errno == ENOTSUP)
7029 return rte_flow_error_set
7031 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7033 "count action not supported");
7035 return rte_flow_error_set
7037 RTE_FLOW_ERROR_TYPE_ACTION,
7039 "cannot create counter"
7042 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7043 dev_flow->dv.actions[actions_n++] =
7044 priv->sh->pop_vlan_action;
7045 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7047 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7048 flow_dev_get_vlan_info_from_items(items, &vlan);
7049 vlan.eth_proto = rte_be_to_cpu_16
7050 ((((const struct rte_flow_action_of_push_vlan *)
7051 actions->conf)->ethertype));
7052 found_action = mlx5_flow_find_action
7054 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
7056 mlx5_update_vlan_vid_pcp(found_action, &vlan);
7057 found_action = mlx5_flow_find_action
7059 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
7061 mlx5_update_vlan_vid_pcp(found_action, &vlan);
7062 if (flow_dv_create_action_push_vlan
7063 (dev, attr, &vlan, dev_flow, error))
7065 dev_flow->dv.actions[actions_n++] =
7066 dev_flow->dv.push_vlan_res->action;
7067 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7069 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7070 /* of_vlan_push action handled this action */
7071 assert(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN);
7073 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7074 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7076 flow_dev_get_vlan_info_from_items(items, &vlan);
7077 mlx5_update_vlan_vid_pcp(actions, &vlan);
7078 /* If no VLAN push - this is a modify header action */
7079 if (flow_dv_convert_action_modify_vlan_vid
7080 (&mhdr_res, actions, error))
7082 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7084 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7085 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7086 if (flow_dv_create_action_l2_encap(dev, actions,
7091 dev_flow->dv.actions[actions_n++] =
7092 dev_flow->dv.encap_decap->verbs_action;
7093 action_flags |= actions->type ==
7094 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ?
7095 MLX5_FLOW_ACTION_VXLAN_ENCAP :
7096 MLX5_FLOW_ACTION_NVGRE_ENCAP;
7098 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7099 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7100 if (flow_dv_create_action_l2_decap(dev, dev_flow,
7104 dev_flow->dv.actions[actions_n++] =
7105 dev_flow->dv.encap_decap->verbs_action;
7106 action_flags |= actions->type ==
7107 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ?
7108 MLX5_FLOW_ACTION_VXLAN_DECAP :
7109 MLX5_FLOW_ACTION_NVGRE_DECAP;
7111 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7112 /* Handle encap with preceding decap. */
7113 if (action_flags & MLX5_FLOW_ACTION_RAW_DECAP) {
7114 if (flow_dv_create_action_raw_encap
7115 (dev, actions, dev_flow, attr, error))
7117 dev_flow->dv.actions[actions_n++] =
7118 dev_flow->dv.encap_decap->verbs_action;
7120 /* Handle encap without preceding decap. */
7121 if (flow_dv_create_action_l2_encap
7122 (dev, actions, dev_flow, attr->transfer,
7125 dev_flow->dv.actions[actions_n++] =
7126 dev_flow->dv.encap_decap->verbs_action;
7128 action_flags |= MLX5_FLOW_ACTION_RAW_ENCAP;
7130 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7131 /* Check if this decap is followed by encap. */
7132 for (; action->type != RTE_FLOW_ACTION_TYPE_END &&
7133 action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP;
7136 /* Handle decap only if it isn't followed by encap. */
7137 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7138 if (flow_dv_create_action_l2_decap
7139 (dev, dev_flow, attr->transfer, error))
7141 dev_flow->dv.actions[actions_n++] =
7142 dev_flow->dv.encap_decap->verbs_action;
7144 /* If decap is followed by encap, handle it at encap. */
7145 action_flags |= MLX5_FLOW_ACTION_RAW_DECAP;
7147 case RTE_FLOW_ACTION_TYPE_JUMP:
7148 jump_data = action->conf;
7149 ret = mlx5_flow_group_to_table(attr, dev_flow->external,
7150 jump_data->group, &table,
7154 tbl = flow_dv_tbl_resource_get(dev, table,
7156 attr->transfer, error);
7158 return rte_flow_error_set
7160 RTE_FLOW_ERROR_TYPE_ACTION,
7162 "cannot create jump action.");
7163 if (flow_dv_jump_tbl_resource_register
7164 (dev, tbl, dev_flow, error)) {
7165 flow_dv_tbl_resource_release(dev, tbl);
7166 return rte_flow_error_set
7168 RTE_FLOW_ERROR_TYPE_ACTION,
7170 "cannot create jump action.");
7172 dev_flow->dv.actions[actions_n++] =
7173 dev_flow->dv.jump->action;
7174 action_flags |= MLX5_FLOW_ACTION_JUMP;
7176 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7177 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7178 if (flow_dv_convert_action_modify_mac
7179 (&mhdr_res, actions, error))
7181 action_flags |= actions->type ==
7182 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7183 MLX5_FLOW_ACTION_SET_MAC_SRC :
7184 MLX5_FLOW_ACTION_SET_MAC_DST;
7186 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7187 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7188 if (flow_dv_convert_action_modify_ipv4
7189 (&mhdr_res, actions, error))
7191 action_flags |= actions->type ==
7192 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7193 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7194 MLX5_FLOW_ACTION_SET_IPV4_DST;
7196 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7197 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7198 if (flow_dv_convert_action_modify_ipv6
7199 (&mhdr_res, actions, error))
7201 action_flags |= actions->type ==
7202 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7203 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7204 MLX5_FLOW_ACTION_SET_IPV6_DST;
7206 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7207 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7208 if (flow_dv_convert_action_modify_tp
7209 (&mhdr_res, actions, items,
7212 action_flags |= actions->type ==
7213 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7214 MLX5_FLOW_ACTION_SET_TP_SRC :
7215 MLX5_FLOW_ACTION_SET_TP_DST;
7217 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7218 if (flow_dv_convert_action_modify_dec_ttl
7219 (&mhdr_res, items, &flow_attr, error))
7221 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
7223 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7224 if (flow_dv_convert_action_modify_ttl
7225 (&mhdr_res, actions, items,
7228 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
7230 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7231 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7232 if (flow_dv_convert_action_modify_tcp_seq
7233 (&mhdr_res, actions, error))
7235 action_flags |= actions->type ==
7236 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7237 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7238 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7241 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7242 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7243 if (flow_dv_convert_action_modify_tcp_ack
7244 (&mhdr_res, actions, error))
7246 action_flags |= actions->type ==
7247 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7248 MLX5_FLOW_ACTION_INC_TCP_ACK :
7249 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7251 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7252 if (flow_dv_convert_action_set_reg
7253 (&mhdr_res, actions, error))
7255 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7257 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7258 if (flow_dv_convert_action_copy_mreg
7259 (dev, &mhdr_res, actions, error))
7261 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7263 case RTE_FLOW_ACTION_TYPE_METER:
7264 mtr = actions->conf;
7266 flow->meter = mlx5_flow_meter_attach(priv,
7270 return rte_flow_error_set(error,
7272 RTE_FLOW_ERROR_TYPE_ACTION,
7275 "or invalid parameters");
7277 /* Set the meter action. */
7278 dev_flow->dv.actions[actions_n++] =
7279 flow->meter->mfts->meter_action;
7280 action_flags |= MLX5_FLOW_ACTION_METER;
7282 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7283 if (flow_dv_convert_action_modify_ipv4_dscp(&mhdr_res,
7286 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7288 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7289 if (flow_dv_convert_action_modify_ipv6_dscp(&mhdr_res,
7292 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7294 case RTE_FLOW_ACTION_TYPE_END:
7296 if (mhdr_res.actions_num) {
7297 /* create modify action if needed. */
7298 if (flow_dv_modify_hdr_resource_register
7299 (dev, &mhdr_res, dev_flow, error))
7301 dev_flow->dv.actions[modify_action_position] =
7302 dev_flow->dv.modify_hdr->verbs_action;
7308 if (mhdr_res.actions_num &&
7309 modify_action_position == UINT32_MAX)
7310 modify_action_position = actions_n++;
7312 dev_flow->dv.actions_n = actions_n;
7313 dev_flow->actions = action_flags;
7314 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7315 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7316 int item_type = items->type;
7318 switch (item_type) {
7319 case RTE_FLOW_ITEM_TYPE_PORT_ID:
7320 flow_dv_translate_item_port_id(dev, match_mask,
7321 match_value, items);
7322 last_item = MLX5_FLOW_ITEM_PORT_ID;
7324 case RTE_FLOW_ITEM_TYPE_ETH:
7325 flow_dv_translate_item_eth(match_mask, match_value,
7327 matcher.priority = MLX5_PRIORITY_MAP_L2;
7328 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7329 MLX5_FLOW_LAYER_OUTER_L2;
7331 case RTE_FLOW_ITEM_TYPE_VLAN:
7332 flow_dv_translate_item_vlan(dev_flow,
7333 match_mask, match_value,
7335 matcher.priority = MLX5_PRIORITY_MAP_L2;
7336 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
7337 MLX5_FLOW_LAYER_INNER_VLAN) :
7338 (MLX5_FLOW_LAYER_OUTER_L2 |
7339 MLX5_FLOW_LAYER_OUTER_VLAN);
7341 case RTE_FLOW_ITEM_TYPE_IPV4:
7342 mlx5_flow_tunnel_ip_check(items, next_protocol,
7343 &item_flags, &tunnel);
7344 flow_dv_translate_item_ipv4(match_mask, match_value,
7347 matcher.priority = MLX5_PRIORITY_MAP_L3;
7348 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7349 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7350 if (items->mask != NULL &&
7351 ((const struct rte_flow_item_ipv4 *)
7352 items->mask)->hdr.next_proto_id) {
7354 ((const struct rte_flow_item_ipv4 *)
7355 (items->spec))->hdr.next_proto_id;
7357 ((const struct rte_flow_item_ipv4 *)
7358 (items->mask))->hdr.next_proto_id;
7360 /* Reset for inner layer. */
7361 next_protocol = 0xff;
7364 case RTE_FLOW_ITEM_TYPE_IPV6:
7365 mlx5_flow_tunnel_ip_check(items, next_protocol,
7366 &item_flags, &tunnel);
7367 flow_dv_translate_item_ipv6(match_mask, match_value,
7370 matcher.priority = MLX5_PRIORITY_MAP_L3;
7371 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7372 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7373 if (items->mask != NULL &&
7374 ((const struct rte_flow_item_ipv6 *)
7375 items->mask)->hdr.proto) {
7377 ((const struct rte_flow_item_ipv6 *)
7378 items->spec)->hdr.proto;
7380 ((const struct rte_flow_item_ipv6 *)
7381 items->mask)->hdr.proto;
7383 /* Reset for inner layer. */
7384 next_protocol = 0xff;
7387 case RTE_FLOW_ITEM_TYPE_TCP:
7388 flow_dv_translate_item_tcp(match_mask, match_value,
7390 matcher.priority = MLX5_PRIORITY_MAP_L4;
7391 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7392 MLX5_FLOW_LAYER_OUTER_L4_TCP;
7394 case RTE_FLOW_ITEM_TYPE_UDP:
7395 flow_dv_translate_item_udp(match_mask, match_value,
7397 matcher.priority = MLX5_PRIORITY_MAP_L4;
7398 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7399 MLX5_FLOW_LAYER_OUTER_L4_UDP;
7401 case RTE_FLOW_ITEM_TYPE_GRE:
7402 flow_dv_translate_item_gre(match_mask, match_value,
7404 last_item = MLX5_FLOW_LAYER_GRE;
7406 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7407 flow_dv_translate_item_gre_key(match_mask,
7408 match_value, items);
7409 last_item = MLX5_FLOW_LAYER_GRE_KEY;
7411 case RTE_FLOW_ITEM_TYPE_NVGRE:
7412 flow_dv_translate_item_nvgre(match_mask, match_value,
7414 last_item = MLX5_FLOW_LAYER_GRE;
7416 case RTE_FLOW_ITEM_TYPE_VXLAN:
7417 flow_dv_translate_item_vxlan(match_mask, match_value,
7419 last_item = MLX5_FLOW_LAYER_VXLAN;
7421 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7422 flow_dv_translate_item_vxlan(match_mask, match_value,
7424 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7426 case RTE_FLOW_ITEM_TYPE_GENEVE:
7427 flow_dv_translate_item_geneve(match_mask, match_value,
7429 last_item = MLX5_FLOW_LAYER_GENEVE;
7431 case RTE_FLOW_ITEM_TYPE_MPLS:
7432 flow_dv_translate_item_mpls(match_mask, match_value,
7433 items, last_item, tunnel);
7434 last_item = MLX5_FLOW_LAYER_MPLS;
7436 case RTE_FLOW_ITEM_TYPE_MARK:
7437 flow_dv_translate_item_mark(dev, match_mask,
7438 match_value, items);
7439 last_item = MLX5_FLOW_ITEM_MARK;
7441 case RTE_FLOW_ITEM_TYPE_META:
7442 flow_dv_translate_item_meta(dev, match_mask,
7443 match_value, attr, items);
7444 last_item = MLX5_FLOW_ITEM_METADATA;
7446 case RTE_FLOW_ITEM_TYPE_ICMP:
7447 flow_dv_translate_item_icmp(match_mask, match_value,
7449 last_item = MLX5_FLOW_LAYER_ICMP;
7451 case RTE_FLOW_ITEM_TYPE_ICMP6:
7452 flow_dv_translate_item_icmp6(match_mask, match_value,
7454 last_item = MLX5_FLOW_LAYER_ICMP6;
7456 case RTE_FLOW_ITEM_TYPE_TAG:
7457 flow_dv_translate_item_tag(dev, match_mask,
7458 match_value, items);
7459 last_item = MLX5_FLOW_ITEM_TAG;
7461 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7462 flow_dv_translate_mlx5_item_tag(match_mask,
7463 match_value, items);
7464 last_item = MLX5_FLOW_ITEM_TAG;
7466 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
7467 flow_dv_translate_item_tx_queue(dev, match_mask,
7470 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
7475 item_flags |= last_item;
7478 * In case of ingress traffic when E-Switch mode is enabled,
7479 * we have two cases where we need to set the source port manually.
7480 * The first one, is in case of Nic steering rule, and the second is
7481 * E-Switch rule where no port_id item was found. In both cases
7482 * the source port is set according the current port in use.
7484 if ((attr->ingress && !(item_flags & MLX5_FLOW_ITEM_PORT_ID)) &&
7485 (priv->representor || priv->master)) {
7486 if (flow_dv_translate_item_port_id(dev, match_mask,
7490 assert(!flow_dv_check_valid_spec(matcher.mask.buf,
7491 dev_flow->dv.value.buf));
7492 dev_flow->layers = item_flags;
7493 if (action_flags & MLX5_FLOW_ACTION_RSS)
7494 flow_dv_hashfields_set(dev_flow);
7495 /* Register matcher. */
7496 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
7498 matcher.priority = mlx5_flow_adjust_priority(dev, priority,
7500 /* reserved field no needs to be set to 0 here. */
7501 tbl_key.domain = attr->transfer;
7502 tbl_key.direction = attr->egress;
7503 tbl_key.table_id = dev_flow->group;
7504 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow, error))
7510 * Apply the flow to the NIC, lock free,
7511 * (mutex should be acquired by caller).
7514 * Pointer to the Ethernet device structure.
7515 * @param[in, out] flow
7516 * Pointer to flow structure.
7518 * Pointer to error structure.
7521 * 0 on success, a negative errno value otherwise and rte_errno is set.
7524 __flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
7525 struct rte_flow_error *error)
7527 struct mlx5_flow_dv *dv;
7528 struct mlx5_flow *dev_flow;
7529 struct mlx5_priv *priv = dev->data->dev_private;
7533 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
7536 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP) {
7537 if (dev_flow->transfer) {
7538 dv->actions[n++] = priv->sh->esw_drop_action;
7540 dv->hrxq = mlx5_hrxq_drop_new(dev);
7544 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7546 "cannot get drop hash queue");
7549 dv->actions[n++] = dv->hrxq->action;
7551 } else if (dev_flow->actions &
7552 (MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)) {
7553 struct mlx5_hrxq *hrxq;
7555 assert(flow->rss.queue);
7556 hrxq = mlx5_hrxq_get(dev, flow->rss.key,
7557 MLX5_RSS_HASH_KEY_LEN,
7558 dev_flow->hash_fields,
7560 flow->rss.queue_num);
7562 hrxq = mlx5_hrxq_new
7563 (dev, flow->rss.key,
7564 MLX5_RSS_HASH_KEY_LEN,
7565 dev_flow->hash_fields,
7567 flow->rss.queue_num,
7568 !!(dev_flow->layers &
7569 MLX5_FLOW_LAYER_TUNNEL));
7574 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7575 "cannot get hash queue");
7579 dv->actions[n++] = dv->hrxq->action;
7582 mlx5_glue->dv_create_flow(dv->matcher->matcher_object,
7583 (void *)&dv->value, n,
7586 rte_flow_error_set(error, errno,
7587 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7589 "hardware refuses to create flow");
7592 if (priv->vmwa_context &&
7593 dev_flow->dv.vf_vlan.tag &&
7594 !dev_flow->dv.vf_vlan.created) {
7596 * The rule contains the VLAN pattern.
7597 * For VF we are going to create VLAN
7598 * interface to make hypervisor set correct
7599 * e-Switch vport context.
7601 mlx5_vlan_vmwa_acquire(dev, &dev_flow->dv.vf_vlan);
7606 err = rte_errno; /* Save rte_errno before cleanup. */
7607 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
7608 struct mlx5_flow_dv *dv = &dev_flow->dv;
7610 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP)
7611 mlx5_hrxq_drop_release(dev);
7613 mlx5_hrxq_release(dev, dv->hrxq);
7616 if (dev_flow->dv.vf_vlan.tag &&
7617 dev_flow->dv.vf_vlan.created)
7618 mlx5_vlan_vmwa_release(dev, &dev_flow->dv.vf_vlan);
7620 rte_errno = err; /* Restore rte_errno. */
7625 * Release the flow matcher.
7628 * Pointer to Ethernet device.
7630 * Pointer to mlx5_flow.
7633 * 1 while a reference on it exists, 0 when freed.
7636 flow_dv_matcher_release(struct rte_eth_dev *dev,
7637 struct mlx5_flow *flow)
7639 struct mlx5_flow_dv_matcher *matcher = flow->dv.matcher;
7641 assert(matcher->matcher_object);
7642 DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
7643 dev->data->port_id, (void *)matcher,
7644 rte_atomic32_read(&matcher->refcnt));
7645 if (rte_atomic32_dec_and_test(&matcher->refcnt)) {
7646 claim_zero(mlx5_glue->dv_destroy_flow_matcher
7647 (matcher->matcher_object));
7648 LIST_REMOVE(matcher, next);
7649 /* table ref-- in release interface. */
7650 flow_dv_tbl_resource_release(dev, matcher->tbl);
7652 DRV_LOG(DEBUG, "port %u matcher %p: removed",
7653 dev->data->port_id, (void *)matcher);
7660 * Release an encap/decap resource.
7663 * Pointer to mlx5_flow.
7666 * 1 while a reference on it exists, 0 when freed.
7669 flow_dv_encap_decap_resource_release(struct mlx5_flow *flow)
7671 struct mlx5_flow_dv_encap_decap_resource *cache_resource =
7672 flow->dv.encap_decap;
7674 assert(cache_resource->verbs_action);
7675 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d--",
7676 (void *)cache_resource,
7677 rte_atomic32_read(&cache_resource->refcnt));
7678 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7679 claim_zero(mlx5_glue->destroy_flow_action
7680 (cache_resource->verbs_action));
7681 LIST_REMOVE(cache_resource, next);
7682 rte_free(cache_resource);
7683 DRV_LOG(DEBUG, "encap/decap resource %p: removed",
7684 (void *)cache_resource);
7691 * Release an jump to table action resource.
7694 * Pointer to Ethernet device.
7696 * Pointer to mlx5_flow.
7699 * 1 while a reference on it exists, 0 when freed.
7702 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
7703 struct mlx5_flow *flow)
7705 struct mlx5_flow_dv_jump_tbl_resource *cache_resource = flow->dv.jump;
7706 struct mlx5_flow_tbl_data_entry *tbl_data =
7707 container_of(cache_resource,
7708 struct mlx5_flow_tbl_data_entry, jump);
7710 assert(cache_resource->action);
7711 DRV_LOG(DEBUG, "jump table resource %p: refcnt %d--",
7712 (void *)cache_resource,
7713 rte_atomic32_read(&cache_resource->refcnt));
7714 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7715 claim_zero(mlx5_glue->destroy_flow_action
7716 (cache_resource->action));
7717 /* jump action memory free is inside the table release. */
7718 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
7719 DRV_LOG(DEBUG, "jump table resource %p: removed",
7720 (void *)cache_resource);
7727 * Release a modify-header resource.
7730 * Pointer to mlx5_flow.
7733 * 1 while a reference on it exists, 0 when freed.
7736 flow_dv_modify_hdr_resource_release(struct mlx5_flow *flow)
7738 struct mlx5_flow_dv_modify_hdr_resource *cache_resource =
7739 flow->dv.modify_hdr;
7741 assert(cache_resource->verbs_action);
7742 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d--",
7743 (void *)cache_resource,
7744 rte_atomic32_read(&cache_resource->refcnt));
7745 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7746 claim_zero(mlx5_glue->destroy_flow_action
7747 (cache_resource->verbs_action));
7748 LIST_REMOVE(cache_resource, next);
7749 rte_free(cache_resource);
7750 DRV_LOG(DEBUG, "modify-header resource %p: removed",
7751 (void *)cache_resource);
7758 * Release port ID action resource.
7761 * Pointer to mlx5_flow.
7764 * 1 while a reference on it exists, 0 when freed.
7767 flow_dv_port_id_action_resource_release(struct mlx5_flow *flow)
7769 struct mlx5_flow_dv_port_id_action_resource *cache_resource =
7770 flow->dv.port_id_action;
7772 assert(cache_resource->action);
7773 DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--",
7774 (void *)cache_resource,
7775 rte_atomic32_read(&cache_resource->refcnt));
7776 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7777 claim_zero(mlx5_glue->destroy_flow_action
7778 (cache_resource->action));
7779 LIST_REMOVE(cache_resource, next);
7780 rte_free(cache_resource);
7781 DRV_LOG(DEBUG, "port id action resource %p: removed",
7782 (void *)cache_resource);
7789 * Release push vlan action resource.
7792 * Pointer to mlx5_flow.
7795 * 1 while a reference on it exists, 0 when freed.
7798 flow_dv_push_vlan_action_resource_release(struct mlx5_flow *flow)
7800 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource =
7801 flow->dv.push_vlan_res;
7803 assert(cache_resource->action);
7804 DRV_LOG(DEBUG, "push VLAN action resource %p: refcnt %d--",
7805 (void *)cache_resource,
7806 rte_atomic32_read(&cache_resource->refcnt));
7807 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
7808 claim_zero(mlx5_glue->destroy_flow_action
7809 (cache_resource->action));
7810 LIST_REMOVE(cache_resource, next);
7811 rte_free(cache_resource);
7812 DRV_LOG(DEBUG, "push vlan action resource %p: removed",
7813 (void *)cache_resource);
7820 * Remove the flow from the NIC but keeps it in memory.
7821 * Lock free, (mutex should be acquired by caller).
7824 * Pointer to Ethernet device.
7825 * @param[in, out] flow
7826 * Pointer to flow structure.
7829 __flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
7831 struct mlx5_flow_dv *dv;
7832 struct mlx5_flow *dev_flow;
7836 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
7839 claim_zero(mlx5_glue->dv_destroy_flow(dv->flow));
7843 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP)
7844 mlx5_hrxq_drop_release(dev);
7846 mlx5_hrxq_release(dev, dv->hrxq);
7849 if (dev_flow->dv.vf_vlan.tag &&
7850 dev_flow->dv.vf_vlan.created)
7851 mlx5_vlan_vmwa_release(dev, &dev_flow->dv.vf_vlan);
7856 * Remove the flow from the NIC and the memory.
7857 * Lock free, (mutex should be acquired by caller).
7860 * Pointer to the Ethernet device structure.
7861 * @param[in, out] flow
7862 * Pointer to flow structure.
7865 __flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
7867 struct mlx5_flow *dev_flow;
7871 __flow_dv_remove(dev, flow);
7872 if (flow->counter) {
7873 flow_dv_counter_release(dev, flow->counter);
7874 flow->counter = NULL;
7877 mlx5_flow_meter_detach(flow->meter);
7880 while (!LIST_EMPTY(&flow->dev_flows)) {
7881 dev_flow = LIST_FIRST(&flow->dev_flows);
7882 LIST_REMOVE(dev_flow, next);
7883 if (dev_flow->dv.matcher)
7884 flow_dv_matcher_release(dev, dev_flow);
7885 if (dev_flow->dv.encap_decap)
7886 flow_dv_encap_decap_resource_release(dev_flow);
7887 if (dev_flow->dv.modify_hdr)
7888 flow_dv_modify_hdr_resource_release(dev_flow);
7889 if (dev_flow->dv.jump)
7890 flow_dv_jump_tbl_resource_release(dev, dev_flow);
7891 if (dev_flow->dv.port_id_action)
7892 flow_dv_port_id_action_resource_release(dev_flow);
7893 if (dev_flow->dv.push_vlan_res)
7894 flow_dv_push_vlan_action_resource_release(dev_flow);
7895 if (dev_flow->dv.tag_resource)
7896 flow_dv_tag_release(dev, dev_flow->dv.tag_resource);
7902 * Query a dv flow rule for its statistics via devx.
7905 * Pointer to Ethernet device.
7907 * Pointer to the sub flow.
7909 * data retrieved by the query.
7911 * Perform verbose error reporting if not NULL.
7914 * 0 on success, a negative errno value otherwise and rte_errno is set.
7917 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
7918 void *data, struct rte_flow_error *error)
7920 struct mlx5_priv *priv = dev->data->dev_private;
7921 struct rte_flow_query_count *qc = data;
7923 if (!priv->config.devx)
7924 return rte_flow_error_set(error, ENOTSUP,
7925 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7927 "counters are not supported");
7928 if (flow->counter) {
7929 uint64_t pkts, bytes;
7930 int err = _flow_dv_query_count(dev, flow->counter, &pkts,
7934 return rte_flow_error_set(error, -err,
7935 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7936 NULL, "cannot read counters");
7939 qc->hits = pkts - flow->counter->hits;
7940 qc->bytes = bytes - flow->counter->bytes;
7942 flow->counter->hits = pkts;
7943 flow->counter->bytes = bytes;
7947 return rte_flow_error_set(error, EINVAL,
7948 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7950 "counters are not available");
7956 * @see rte_flow_query()
7960 flow_dv_query(struct rte_eth_dev *dev,
7961 struct rte_flow *flow __rte_unused,
7962 const struct rte_flow_action *actions __rte_unused,
7963 void *data __rte_unused,
7964 struct rte_flow_error *error __rte_unused)
7968 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7969 switch (actions->type) {
7970 case RTE_FLOW_ACTION_TYPE_VOID:
7972 case RTE_FLOW_ACTION_TYPE_COUNT:
7973 ret = flow_dv_query_count(dev, flow, data, error);
7976 return rte_flow_error_set(error, ENOTSUP,
7977 RTE_FLOW_ERROR_TYPE_ACTION,
7979 "action not supported");
7986 * Destroy the meter table set.
7987 * Lock free, (mutex should be acquired by caller).
7990 * Pointer to Ethernet device.
7992 * Pointer to the meter table set.
7998 flow_dv_destroy_mtr_tbl(struct rte_eth_dev *dev,
7999 struct mlx5_meter_domains_infos *tbl)
8001 struct mlx5_priv *priv = dev->data->dev_private;
8002 struct mlx5_meter_domains_infos *mtd =
8003 (struct mlx5_meter_domains_infos *)tbl;
8005 if (!mtd || !priv->config.dv_flow_en)
8007 if (mtd->ingress.policer_rules[RTE_MTR_DROPPED])
8008 claim_zero(mlx5_glue->dv_destroy_flow
8009 (mtd->ingress.policer_rules[RTE_MTR_DROPPED]));
8010 if (mtd->egress.policer_rules[RTE_MTR_DROPPED])
8011 claim_zero(mlx5_glue->dv_destroy_flow
8012 (mtd->egress.policer_rules[RTE_MTR_DROPPED]));
8013 if (mtd->transfer.policer_rules[RTE_MTR_DROPPED])
8014 claim_zero(mlx5_glue->dv_destroy_flow
8015 (mtd->transfer.policer_rules[RTE_MTR_DROPPED]));
8016 if (mtd->egress.color_matcher)
8017 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8018 (mtd->egress.color_matcher));
8019 if (mtd->egress.any_matcher)
8020 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8021 (mtd->egress.any_matcher));
8022 if (mtd->egress.tbl)
8023 claim_zero(flow_dv_tbl_resource_release(dev,
8025 if (mtd->ingress.color_matcher)
8026 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8027 (mtd->ingress.color_matcher));
8028 if (mtd->ingress.any_matcher)
8029 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8030 (mtd->ingress.any_matcher));
8031 if (mtd->ingress.tbl)
8032 claim_zero(flow_dv_tbl_resource_release(dev,
8034 if (mtd->transfer.color_matcher)
8035 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8036 (mtd->transfer.color_matcher));
8037 if (mtd->transfer.any_matcher)
8038 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8039 (mtd->transfer.any_matcher));
8040 if (mtd->transfer.tbl)
8041 claim_zero(flow_dv_tbl_resource_release(dev,
8042 mtd->transfer.tbl));
8044 claim_zero(mlx5_glue->destroy_flow_action(mtd->drop_actn));
8049 /* Number of meter flow actions, count and jump or count and drop. */
8050 #define METER_ACTIONS 2
8053 * Create specify domain meter table and suffix table.
8056 * Pointer to Ethernet device.
8057 * @param[in,out] mtb
8058 * Pointer to DV meter table set.
8061 * @param[in] transfer
8063 * @param[in] color_reg_c_idx
8064 * Reg C index for color match.
8067 * 0 on success, -1 otherwise and rte_errno is set.
8070 flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
8071 struct mlx5_meter_domains_infos *mtb,
8072 uint8_t egress, uint8_t transfer,
8073 uint32_t color_reg_c_idx)
8075 struct mlx5_priv *priv = dev->data->dev_private;
8076 struct mlx5_ibv_shared *sh = priv->sh;
8077 struct mlx5_flow_dv_match_params mask = {
8078 .size = sizeof(mask.buf),
8080 struct mlx5_flow_dv_match_params value = {
8081 .size = sizeof(value.buf),
8083 struct mlx5dv_flow_matcher_attr dv_attr = {
8084 .type = IBV_FLOW_ATTR_NORMAL,
8086 .match_criteria_enable = 0,
8087 .match_mask = (void *)&mask,
8089 void *actions[METER_ACTIONS];
8090 struct mlx5_flow_tbl_resource **sfx_tbl;
8091 struct mlx5_meter_domain_info *dtb;
8092 struct rte_flow_error error;
8096 sfx_tbl = &sh->fdb_mtr_sfx_tbl;
8097 dtb = &mtb->transfer;
8098 } else if (egress) {
8099 sfx_tbl = &sh->tx_mtr_sfx_tbl;
8102 sfx_tbl = &sh->rx_mtr_sfx_tbl;
8103 dtb = &mtb->ingress;
8105 /* If the suffix table in missing, create it. */
8107 *sfx_tbl = flow_dv_tbl_resource_get(dev,
8108 MLX5_FLOW_TABLE_LEVEL_SUFFIX,
8109 egress, transfer, &error);
8111 DRV_LOG(ERR, "Failed to create meter suffix table.");
8115 /* Create the meter table with METER level. */
8116 dtb->tbl = flow_dv_tbl_resource_get(dev, MLX5_FLOW_TABLE_LEVEL_METER,
8117 egress, transfer, &error);
8119 DRV_LOG(ERR, "Failed to create meter policer table.");
8122 /* Create matchers, Any and Color. */
8123 dv_attr.priority = 3;
8124 dv_attr.match_criteria_enable = 0;
8125 dtb->any_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
8128 if (!dtb->any_matcher) {
8129 DRV_LOG(ERR, "Failed to create meter"
8130 " policer default matcher.");
8133 dv_attr.priority = 0;
8134 dv_attr.match_criteria_enable =
8135 1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
8136 flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
8137 rte_col_2_mlx5_col(RTE_COLORS), UINT32_MAX);
8138 dtb->color_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
8141 if (!dtb->color_matcher) {
8142 DRV_LOG(ERR, "Failed to create meter policer color matcher.");
8145 if (mtb->count_actns[RTE_MTR_DROPPED])
8146 actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
8147 actions[i++] = mtb->drop_actn;
8148 /* Default rule: lowest priority, match any, actions: drop. */
8149 dtb->policer_rules[RTE_MTR_DROPPED] =
8150 mlx5_glue->dv_create_flow(dtb->any_matcher,
8151 (void *)&value, i, actions);
8152 if (!dtb->policer_rules[RTE_MTR_DROPPED]) {
8153 DRV_LOG(ERR, "Failed to create meter policer drop rule.");
8162 * Create the needed meter and suffix tables.
8163 * Lock free, (mutex should be acquired by caller).
8166 * Pointer to Ethernet device.
8168 * Pointer to the flow meter.
8171 * Pointer to table set on success, NULL otherwise and rte_errno is set.
8173 static struct mlx5_meter_domains_infos *
8174 flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
8175 const struct mlx5_flow_meter *fm)
8177 struct mlx5_priv *priv = dev->data->dev_private;
8178 struct mlx5_meter_domains_infos *mtb;
8182 if (!priv->mtr_en) {
8183 rte_errno = ENOTSUP;
8186 mtb = rte_calloc(__func__, 1, sizeof(*mtb), 0);
8188 DRV_LOG(ERR, "Failed to allocate memory for meter.");
8191 /* Create meter count actions */
8192 for (i = 0; i <= RTE_MTR_DROPPED; i++) {
8193 if (!fm->policer_stats.cnt[i])
8195 mtb->count_actns[i] = fm->policer_stats.cnt[i]->action;
8197 /* Create drop action. */
8198 mtb->drop_actn = mlx5_glue->dr_create_flow_action_drop();
8199 if (!mtb->drop_actn) {
8200 DRV_LOG(ERR, "Failed to create drop action.");
8203 /* Egress meter table. */
8204 ret = flow_dv_prepare_mtr_tables(dev, mtb, 1, 0, priv->mtr_color_reg);
8206 DRV_LOG(ERR, "Failed to prepare egress meter table.");
8209 /* Ingress meter table. */
8210 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 0, priv->mtr_color_reg);
8212 DRV_LOG(ERR, "Failed to prepare ingress meter table.");
8215 /* FDB meter table. */
8216 if (priv->config.dv_esw_en) {
8217 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 1,
8218 priv->mtr_color_reg);
8220 DRV_LOG(ERR, "Failed to prepare fdb meter table.");
8226 flow_dv_destroy_mtr_tbl(dev, mtb);
8231 * Destroy domain policer rule.
8234 * Pointer to domain table.
8237 flow_dv_destroy_domain_policer_rule(struct mlx5_meter_domain_info *dt)
8241 for (i = 0; i < RTE_MTR_DROPPED; i++) {
8242 if (dt->policer_rules[i]) {
8243 claim_zero(mlx5_glue->dv_destroy_flow
8244 (dt->policer_rules[i]));
8245 dt->policer_rules[i] = NULL;
8248 if (dt->jump_actn) {
8249 claim_zero(mlx5_glue->destroy_flow_action(dt->jump_actn));
8250 dt->jump_actn = NULL;
8255 * Destroy policer rules.
8258 * Pointer to Ethernet device.
8260 * Pointer to flow meter structure.
8262 * Pointer to flow attributes.
8268 flow_dv_destroy_policer_rules(struct rte_eth_dev *dev __rte_unused,
8269 const struct mlx5_flow_meter *fm,
8270 const struct rte_flow_attr *attr)
8272 struct mlx5_meter_domains_infos *mtb = fm ? fm->mfts : NULL;
8277 flow_dv_destroy_domain_policer_rule(&mtb->egress);
8279 flow_dv_destroy_domain_policer_rule(&mtb->ingress);
8281 flow_dv_destroy_domain_policer_rule(&mtb->transfer);
8286 * Create specify domain meter policer rule.
8289 * Pointer to flow meter structure.
8291 * Pointer to DV meter table set.
8293 * Pointer to suffix table.
8294 * @param[in] mtr_reg_c
8295 * Color match REG_C.
8298 * 0 on success, -1 otherwise.
8301 flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
8302 struct mlx5_meter_domain_info *dtb,
8303 struct mlx5_flow_tbl_resource *sfx_tb,
8306 struct mlx5_flow_dv_match_params matcher = {
8307 .size = sizeof(matcher.buf),
8309 struct mlx5_flow_dv_match_params value = {
8310 .size = sizeof(value.buf),
8312 struct mlx5_meter_domains_infos *mtb = fm->mfts;
8313 void *actions[METER_ACTIONS];
8316 /* Create jump action. */
8319 if (!dtb->jump_actn)
8321 mlx5_glue->dr_create_flow_action_dest_flow_tbl
8323 if (!dtb->jump_actn) {
8324 DRV_LOG(ERR, "Failed to create policer jump action.");
8327 for (i = 0; i < RTE_MTR_DROPPED; i++) {
8330 flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
8331 rte_col_2_mlx5_col(i), UINT32_MAX);
8332 if (mtb->count_actns[i])
8333 actions[j++] = mtb->count_actns[i];
8334 if (fm->params.action[i] == MTR_POLICER_ACTION_DROP)
8335 actions[j++] = mtb->drop_actn;
8337 actions[j++] = dtb->jump_actn;
8338 dtb->policer_rules[i] =
8339 mlx5_glue->dv_create_flow(dtb->color_matcher,
8342 if (!dtb->policer_rules[i]) {
8343 DRV_LOG(ERR, "Failed to create policer rule.");
8354 * Create policer rules.
8357 * Pointer to Ethernet device.
8359 * Pointer to flow meter structure.
8361 * Pointer to flow attributes.
8364 * 0 on success, -1 otherwise.
8367 flow_dv_create_policer_rules(struct rte_eth_dev *dev,
8368 struct mlx5_flow_meter *fm,
8369 const struct rte_flow_attr *attr)
8371 struct mlx5_priv *priv = dev->data->dev_private;
8372 struct mlx5_meter_domains_infos *mtb = fm->mfts;
8376 ret = flow_dv_create_policer_forward_rule(fm, &mtb->egress,
8377 priv->sh->tx_mtr_sfx_tbl,
8378 priv->mtr_color_reg);
8380 DRV_LOG(ERR, "Failed to create egress policer.");
8384 if (attr->ingress) {
8385 ret = flow_dv_create_policer_forward_rule(fm, &mtb->ingress,
8386 priv->sh->rx_mtr_sfx_tbl,
8387 priv->mtr_color_reg);
8389 DRV_LOG(ERR, "Failed to create ingress policer.");
8393 if (attr->transfer) {
8394 ret = flow_dv_create_policer_forward_rule(fm, &mtb->transfer,
8395 priv->sh->fdb_mtr_sfx_tbl,
8396 priv->mtr_color_reg);
8398 DRV_LOG(ERR, "Failed to create transfer policer.");
8404 flow_dv_destroy_policer_rules(dev, fm, attr);
8409 * Query a devx counter.
8412 * Pointer to the Ethernet device structure.
8414 * Pointer to the flow counter.
8416 * Set to clear the counter statistics.
8418 * The statistics value of packets.
8420 * The statistics value of bytes.
8423 * 0 on success, otherwise return -1.
8426 flow_dv_counter_query(struct rte_eth_dev *dev,
8427 struct mlx5_flow_counter *cnt, bool clear,
8428 uint64_t *pkts, uint64_t *bytes)
8430 struct mlx5_priv *priv = dev->data->dev_private;
8431 uint64_t inn_pkts, inn_bytes;
8434 if (!priv->config.devx)
8436 ret = _flow_dv_query_count(dev, cnt, &inn_pkts, &inn_bytes);
8439 *pkts = inn_pkts - cnt->hits;
8440 *bytes = inn_bytes - cnt->bytes;
8442 cnt->hits = inn_pkts;
8443 cnt->bytes = inn_bytes;
8449 * Mutex-protected thunk to lock-free __flow_dv_translate().
8452 flow_dv_translate(struct rte_eth_dev *dev,
8453 struct mlx5_flow *dev_flow,
8454 const struct rte_flow_attr *attr,
8455 const struct rte_flow_item items[],
8456 const struct rte_flow_action actions[],
8457 struct rte_flow_error *error)
8461 flow_dv_shared_lock(dev);
8462 ret = __flow_dv_translate(dev, dev_flow, attr, items, actions, error);
8463 flow_dv_shared_unlock(dev);
8468 * Mutex-protected thunk to lock-free __flow_dv_apply().
8471 flow_dv_apply(struct rte_eth_dev *dev,
8472 struct rte_flow *flow,
8473 struct rte_flow_error *error)
8477 flow_dv_shared_lock(dev);
8478 ret = __flow_dv_apply(dev, flow, error);
8479 flow_dv_shared_unlock(dev);
8484 * Mutex-protected thunk to lock-free __flow_dv_remove().
8487 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
8489 flow_dv_shared_lock(dev);
8490 __flow_dv_remove(dev, flow);
8491 flow_dv_shared_unlock(dev);
8495 * Mutex-protected thunk to lock-free __flow_dv_destroy().
8498 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
8500 flow_dv_shared_lock(dev);
8501 __flow_dv_destroy(dev, flow);
8502 flow_dv_shared_unlock(dev);
8506 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
8508 static struct mlx5_flow_counter *
8509 flow_dv_counter_allocate(struct rte_eth_dev *dev)
8511 struct mlx5_flow_counter *cnt;
8513 flow_dv_shared_lock(dev);
8514 cnt = flow_dv_counter_alloc(dev, 0, 0, 1);
8515 flow_dv_shared_unlock(dev);
8520 * Mutex-protected thunk to lock-free flow_dv_counter_release().
8523 flow_dv_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt)
8525 flow_dv_shared_lock(dev);
8526 flow_dv_counter_release(dev, cnt);
8527 flow_dv_shared_unlock(dev);
8530 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
8531 .validate = flow_dv_validate,
8532 .prepare = flow_dv_prepare,
8533 .translate = flow_dv_translate,
8534 .apply = flow_dv_apply,
8535 .remove = flow_dv_remove,
8536 .destroy = flow_dv_destroy,
8537 .query = flow_dv_query,
8538 .create_mtr_tbls = flow_dv_create_mtr_tbl,
8539 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbl,
8540 .create_policer_rules = flow_dv_create_policer_rules,
8541 .destroy_policer_rules = flow_dv_destroy_policer_rules,
8542 .counter_alloc = flow_dv_counter_allocate,
8543 .counter_free = flow_dv_counter_free,
8544 .counter_query = flow_dv_counter_query,
8547 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */