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 /* VLAN header definitions */
55 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
56 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
57 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
58 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
59 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
74 * Initialize flow attributes structure according to flow items' types.
77 * Pointer to item specification.
79 * Pointer to flow attributes structure.
82 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr)
84 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
86 case RTE_FLOW_ITEM_TYPE_IPV4:
89 case RTE_FLOW_ITEM_TYPE_IPV6:
92 case RTE_FLOW_ITEM_TYPE_UDP:
95 case RTE_FLOW_ITEM_TYPE_TCP:
105 struct field_modify_info {
106 uint32_t size; /* Size of field in protocol header, in bytes. */
107 uint32_t offset; /* Offset of field in protocol header, in bytes. */
108 enum mlx5_modification_field id;
111 struct field_modify_info modify_eth[] = {
112 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
113 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
114 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
115 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
119 struct field_modify_info modify_vlan_out_first_vid[] = {
120 /* Size in bits !!! */
121 {12, 0, MLX5_MODI_OUT_FIRST_VID},
125 struct field_modify_info modify_ipv4[] = {
126 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
127 {4, 12, MLX5_MODI_OUT_SIPV4},
128 {4, 16, MLX5_MODI_OUT_DIPV4},
132 struct field_modify_info modify_ipv6[] = {
133 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
134 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
135 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
136 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
137 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
138 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
139 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
140 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
141 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
145 struct field_modify_info modify_udp[] = {
146 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
147 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
151 struct field_modify_info modify_tcp[] = {
152 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
153 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
154 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
155 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
160 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
161 uint8_t next_protocol, uint64_t *item_flags,
164 assert(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
165 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
166 if (next_protocol == IPPROTO_IPIP) {
167 *item_flags |= MLX5_FLOW_LAYER_IPIP;
170 if (next_protocol == IPPROTO_IPV6) {
171 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
177 * Acquire the synchronizing object to protect multithreaded access
178 * to shared dv context. Lock occurs only if context is actually
179 * shared, i.e. we have multiport IB device and representors are
183 * Pointer to the rte_eth_dev structure.
186 flow_d_shared_lock(struct rte_eth_dev *dev)
188 struct mlx5_priv *priv = dev->data->dev_private;
189 struct mlx5_ibv_shared *sh = priv->sh;
191 if (sh->dv_refcnt > 1) {
194 ret = pthread_mutex_lock(&sh->dv_mutex);
201 flow_d_shared_unlock(struct rte_eth_dev *dev)
203 struct mlx5_priv *priv = dev->data->dev_private;
204 struct mlx5_ibv_shared *sh = priv->sh;
206 if (sh->dv_refcnt > 1) {
209 ret = pthread_mutex_unlock(&sh->dv_mutex);
215 /* Update VLAN's VID/PCP based on input rte_flow_action.
218 * Pointer to struct rte_flow_action.
220 * Pointer to struct rte_vlan_hdr.
223 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
224 struct rte_vlan_hdr *vlan)
227 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
229 ((const struct rte_flow_action_of_set_vlan_pcp *)
230 action->conf)->vlan_pcp;
231 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
232 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
233 vlan->vlan_tci |= vlan_tci;
234 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
235 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
236 vlan->vlan_tci |= rte_be_to_cpu_16
237 (((const struct rte_flow_action_of_set_vlan_vid *)
238 action->conf)->vlan_vid);
243 * Convert modify-header action to DV specification.
246 * Pointer to item specification.
248 * Pointer to field modification information.
249 * @param[in,out] resource
250 * Pointer to the modify-header resource.
252 * Type of modification.
254 * Pointer to the error structure.
257 * 0 on success, a negative errno value otherwise and rte_errno is set.
260 flow_dv_convert_modify_action(struct rte_flow_item *item,
261 struct field_modify_info *field,
262 struct mlx5_flow_dv_modify_hdr_resource *resource,
264 struct rte_flow_error *error)
266 uint32_t i = resource->actions_num;
267 struct mlx5_modification_cmd *actions = resource->actions;
268 const uint8_t *spec = item->spec;
269 const uint8_t *mask = item->mask;
272 while (field->size) {
274 /* Generate modify command for each mask segment. */
275 memcpy(&set, &mask[field->offset], field->size);
277 if (i >= MLX5_MODIFY_NUM)
278 return rte_flow_error_set(error, EINVAL,
279 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
280 "too many items to modify");
281 actions[i].action_type = type;
282 actions[i].field = field->id;
283 actions[i].length = field->size ==
284 4 ? 0 : field->size * 8;
285 rte_memcpy(&actions[i].data[4 - field->size],
286 &spec[field->offset], field->size);
287 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
290 if (resource->actions_num != i)
291 resource->actions_num = i;
294 if (!resource->actions_num)
295 return rte_flow_error_set(error, EINVAL,
296 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
297 "invalid modification flow item");
302 * Convert modify-header set IPv4 address action to DV specification.
304 * @param[in,out] resource
305 * Pointer to the modify-header resource.
307 * Pointer to action specification.
309 * Pointer to the error structure.
312 * 0 on success, a negative errno value otherwise and rte_errno is set.
315 flow_dv_convert_action_modify_ipv4
316 (struct mlx5_flow_dv_modify_hdr_resource *resource,
317 const struct rte_flow_action *action,
318 struct rte_flow_error *error)
320 const struct rte_flow_action_set_ipv4 *conf =
321 (const struct rte_flow_action_set_ipv4 *)(action->conf);
322 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
323 struct rte_flow_item_ipv4 ipv4;
324 struct rte_flow_item_ipv4 ipv4_mask;
326 memset(&ipv4, 0, sizeof(ipv4));
327 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
328 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
329 ipv4.hdr.src_addr = conf->ipv4_addr;
330 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
332 ipv4.hdr.dst_addr = conf->ipv4_addr;
333 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
336 item.mask = &ipv4_mask;
337 return flow_dv_convert_modify_action(&item, modify_ipv4, resource,
338 MLX5_MODIFICATION_TYPE_SET, error);
342 * Convert modify-header set IPv6 address action to DV specification.
344 * @param[in,out] resource
345 * Pointer to the modify-header resource.
347 * Pointer to action specification.
349 * Pointer to the error structure.
352 * 0 on success, a negative errno value otherwise and rte_errno is set.
355 flow_dv_convert_action_modify_ipv6
356 (struct mlx5_flow_dv_modify_hdr_resource *resource,
357 const struct rte_flow_action *action,
358 struct rte_flow_error *error)
360 const struct rte_flow_action_set_ipv6 *conf =
361 (const struct rte_flow_action_set_ipv6 *)(action->conf);
362 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
363 struct rte_flow_item_ipv6 ipv6;
364 struct rte_flow_item_ipv6 ipv6_mask;
366 memset(&ipv6, 0, sizeof(ipv6));
367 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
368 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
369 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
370 sizeof(ipv6.hdr.src_addr));
371 memcpy(&ipv6_mask.hdr.src_addr,
372 &rte_flow_item_ipv6_mask.hdr.src_addr,
373 sizeof(ipv6.hdr.src_addr));
375 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
376 sizeof(ipv6.hdr.dst_addr));
377 memcpy(&ipv6_mask.hdr.dst_addr,
378 &rte_flow_item_ipv6_mask.hdr.dst_addr,
379 sizeof(ipv6.hdr.dst_addr));
382 item.mask = &ipv6_mask;
383 return flow_dv_convert_modify_action(&item, modify_ipv6, resource,
384 MLX5_MODIFICATION_TYPE_SET, error);
388 * Convert modify-header set MAC address action to DV specification.
390 * @param[in,out] resource
391 * Pointer to the modify-header resource.
393 * Pointer to action specification.
395 * Pointer to the error structure.
398 * 0 on success, a negative errno value otherwise and rte_errno is set.
401 flow_dv_convert_action_modify_mac
402 (struct mlx5_flow_dv_modify_hdr_resource *resource,
403 const struct rte_flow_action *action,
404 struct rte_flow_error *error)
406 const struct rte_flow_action_set_mac *conf =
407 (const struct rte_flow_action_set_mac *)(action->conf);
408 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
409 struct rte_flow_item_eth eth;
410 struct rte_flow_item_eth eth_mask;
412 memset(ð, 0, sizeof(eth));
413 memset(ð_mask, 0, sizeof(eth_mask));
414 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
415 memcpy(ð.src.addr_bytes, &conf->mac_addr,
416 sizeof(eth.src.addr_bytes));
417 memcpy(ð_mask.src.addr_bytes,
418 &rte_flow_item_eth_mask.src.addr_bytes,
419 sizeof(eth_mask.src.addr_bytes));
421 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
422 sizeof(eth.dst.addr_bytes));
423 memcpy(ð_mask.dst.addr_bytes,
424 &rte_flow_item_eth_mask.dst.addr_bytes,
425 sizeof(eth_mask.dst.addr_bytes));
428 item.mask = ð_mask;
429 return flow_dv_convert_modify_action(&item, modify_eth, resource,
430 MLX5_MODIFICATION_TYPE_SET, error);
434 * Convert modify-header set VLAN VID action to DV specification.
436 * @param[in,out] resource
437 * Pointer to the modify-header resource.
439 * Pointer to action specification.
441 * Pointer to the error structure.
444 * 0 on success, a negative errno value otherwise and rte_errno is set.
447 flow_dv_convert_action_modify_vlan_vid
448 (struct mlx5_flow_dv_modify_hdr_resource *resource,
449 const struct rte_flow_action *action,
450 struct rte_flow_error *error)
452 const struct rte_flow_action_of_set_vlan_vid *conf =
453 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
454 int i = resource->actions_num;
455 struct mlx5_modification_cmd *actions = &resource->actions[i];
456 struct field_modify_info *field = modify_vlan_out_first_vid;
458 if (i >= MLX5_MODIFY_NUM)
459 return rte_flow_error_set(error, EINVAL,
460 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
461 "too many items to modify");
462 actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
463 actions[i].field = field->id;
464 actions[i].length = field->size;
465 actions[i].offset = field->offset;
466 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
467 actions[i].data1 = conf->vlan_vid;
468 actions[i].data1 = actions[i].data1 << 16;
469 resource->actions_num = ++i;
474 * Convert modify-header set TP action to DV specification.
476 * @param[in,out] resource
477 * Pointer to the modify-header resource.
479 * Pointer to action specification.
481 * Pointer to rte_flow_item objects list.
483 * Pointer to flow attributes structure.
485 * Pointer to the error structure.
488 * 0 on success, a negative errno value otherwise and rte_errno is set.
491 flow_dv_convert_action_modify_tp
492 (struct mlx5_flow_dv_modify_hdr_resource *resource,
493 const struct rte_flow_action *action,
494 const struct rte_flow_item *items,
495 union flow_dv_attr *attr,
496 struct rte_flow_error *error)
498 const struct rte_flow_action_set_tp *conf =
499 (const struct rte_flow_action_set_tp *)(action->conf);
500 struct rte_flow_item item;
501 struct rte_flow_item_udp udp;
502 struct rte_flow_item_udp udp_mask;
503 struct rte_flow_item_tcp tcp;
504 struct rte_flow_item_tcp tcp_mask;
505 struct field_modify_info *field;
508 flow_dv_attr_init(items, attr);
510 memset(&udp, 0, sizeof(udp));
511 memset(&udp_mask, 0, sizeof(udp_mask));
512 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
513 udp.hdr.src_port = conf->port;
514 udp_mask.hdr.src_port =
515 rte_flow_item_udp_mask.hdr.src_port;
517 udp.hdr.dst_port = conf->port;
518 udp_mask.hdr.dst_port =
519 rte_flow_item_udp_mask.hdr.dst_port;
521 item.type = RTE_FLOW_ITEM_TYPE_UDP;
523 item.mask = &udp_mask;
527 memset(&tcp, 0, sizeof(tcp));
528 memset(&tcp_mask, 0, sizeof(tcp_mask));
529 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
530 tcp.hdr.src_port = conf->port;
531 tcp_mask.hdr.src_port =
532 rte_flow_item_tcp_mask.hdr.src_port;
534 tcp.hdr.dst_port = conf->port;
535 tcp_mask.hdr.dst_port =
536 rte_flow_item_tcp_mask.hdr.dst_port;
538 item.type = RTE_FLOW_ITEM_TYPE_TCP;
540 item.mask = &tcp_mask;
543 return flow_dv_convert_modify_action(&item, field, resource,
544 MLX5_MODIFICATION_TYPE_SET, error);
548 * Convert modify-header set TTL action to DV specification.
550 * @param[in,out] resource
551 * Pointer to the modify-header resource.
553 * Pointer to action specification.
555 * Pointer to rte_flow_item objects list.
557 * Pointer to flow attributes structure.
559 * Pointer to the error structure.
562 * 0 on success, a negative errno value otherwise and rte_errno is set.
565 flow_dv_convert_action_modify_ttl
566 (struct mlx5_flow_dv_modify_hdr_resource *resource,
567 const struct rte_flow_action *action,
568 const struct rte_flow_item *items,
569 union flow_dv_attr *attr,
570 struct rte_flow_error *error)
572 const struct rte_flow_action_set_ttl *conf =
573 (const struct rte_flow_action_set_ttl *)(action->conf);
574 struct rte_flow_item item;
575 struct rte_flow_item_ipv4 ipv4;
576 struct rte_flow_item_ipv4 ipv4_mask;
577 struct rte_flow_item_ipv6 ipv6;
578 struct rte_flow_item_ipv6 ipv6_mask;
579 struct field_modify_info *field;
582 flow_dv_attr_init(items, attr);
584 memset(&ipv4, 0, sizeof(ipv4));
585 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
586 ipv4.hdr.time_to_live = conf->ttl_value;
587 ipv4_mask.hdr.time_to_live = 0xFF;
588 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
590 item.mask = &ipv4_mask;
594 memset(&ipv6, 0, sizeof(ipv6));
595 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
596 ipv6.hdr.hop_limits = conf->ttl_value;
597 ipv6_mask.hdr.hop_limits = 0xFF;
598 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
600 item.mask = &ipv6_mask;
603 return flow_dv_convert_modify_action(&item, field, resource,
604 MLX5_MODIFICATION_TYPE_SET, error);
608 * Convert modify-header decrement TTL action to DV specification.
610 * @param[in,out] resource
611 * Pointer to the modify-header resource.
613 * Pointer to action specification.
615 * Pointer to rte_flow_item objects list.
617 * Pointer to flow attributes structure.
619 * Pointer to the error structure.
622 * 0 on success, a negative errno value otherwise and rte_errno is set.
625 flow_dv_convert_action_modify_dec_ttl
626 (struct mlx5_flow_dv_modify_hdr_resource *resource,
627 const struct rte_flow_item *items,
628 union flow_dv_attr *attr,
629 struct rte_flow_error *error)
631 struct rte_flow_item item;
632 struct rte_flow_item_ipv4 ipv4;
633 struct rte_flow_item_ipv4 ipv4_mask;
634 struct rte_flow_item_ipv6 ipv6;
635 struct rte_flow_item_ipv6 ipv6_mask;
636 struct field_modify_info *field;
639 flow_dv_attr_init(items, attr);
641 memset(&ipv4, 0, sizeof(ipv4));
642 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
643 ipv4.hdr.time_to_live = 0xFF;
644 ipv4_mask.hdr.time_to_live = 0xFF;
645 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
647 item.mask = &ipv4_mask;
651 memset(&ipv6, 0, sizeof(ipv6));
652 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
653 ipv6.hdr.hop_limits = 0xFF;
654 ipv6_mask.hdr.hop_limits = 0xFF;
655 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
657 item.mask = &ipv6_mask;
660 return flow_dv_convert_modify_action(&item, field, resource,
661 MLX5_MODIFICATION_TYPE_ADD, error);
665 * Convert modify-header increment/decrement TCP Sequence number
666 * to DV specification.
668 * @param[in,out] resource
669 * Pointer to the modify-header resource.
671 * Pointer to action specification.
673 * Pointer to the error structure.
676 * 0 on success, a negative errno value otherwise and rte_errno is set.
679 flow_dv_convert_action_modify_tcp_seq
680 (struct mlx5_flow_dv_modify_hdr_resource *resource,
681 const struct rte_flow_action *action,
682 struct rte_flow_error *error)
684 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
685 uint64_t value = rte_be_to_cpu_32(*conf);
686 struct rte_flow_item item;
687 struct rte_flow_item_tcp tcp;
688 struct rte_flow_item_tcp tcp_mask;
690 memset(&tcp, 0, sizeof(tcp));
691 memset(&tcp_mask, 0, sizeof(tcp_mask));
692 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
694 * The HW has no decrement operation, only increment operation.
695 * To simulate decrement X from Y using increment operation
696 * we need to add UINT32_MAX X times to Y.
697 * Each adding of UINT32_MAX decrements Y by 1.
700 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
701 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
702 item.type = RTE_FLOW_ITEM_TYPE_TCP;
704 item.mask = &tcp_mask;
705 return flow_dv_convert_modify_action(&item, modify_tcp, resource,
706 MLX5_MODIFICATION_TYPE_ADD, error);
710 * Convert modify-header increment/decrement TCP Acknowledgment number
711 * to DV specification.
713 * @param[in,out] resource
714 * Pointer to the modify-header resource.
716 * Pointer to action specification.
718 * Pointer to the error structure.
721 * 0 on success, a negative errno value otherwise and rte_errno is set.
724 flow_dv_convert_action_modify_tcp_ack
725 (struct mlx5_flow_dv_modify_hdr_resource *resource,
726 const struct rte_flow_action *action,
727 struct rte_flow_error *error)
729 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
730 uint64_t value = rte_be_to_cpu_32(*conf);
731 struct rte_flow_item item;
732 struct rte_flow_item_tcp tcp;
733 struct rte_flow_item_tcp tcp_mask;
735 memset(&tcp, 0, sizeof(tcp));
736 memset(&tcp_mask, 0, sizeof(tcp_mask));
737 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
739 * The HW has no decrement operation, only increment operation.
740 * To simulate decrement X from Y using increment operation
741 * we need to add UINT32_MAX X times to Y.
742 * Each adding of UINT32_MAX decrements Y by 1.
745 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
746 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
747 item.type = RTE_FLOW_ITEM_TYPE_TCP;
749 item.mask = &tcp_mask;
750 return flow_dv_convert_modify_action(&item, modify_tcp, resource,
751 MLX5_MODIFICATION_TYPE_ADD, error);
754 static enum mlx5_modification_field reg_to_field[] = {
755 [REG_A] = MLX5_MODI_META_DATA_REG_A,
756 [REG_B] = MLX5_MODI_META_DATA_REG_B,
757 [REG_C_0] = MLX5_MODI_META_REG_C_0,
758 [REG_C_1] = MLX5_MODI_META_REG_C_1,
759 [REG_C_2] = MLX5_MODI_META_REG_C_2,
760 [REG_C_3] = MLX5_MODI_META_REG_C_3,
761 [REG_C_4] = MLX5_MODI_META_REG_C_4,
762 [REG_C_5] = MLX5_MODI_META_REG_C_5,
763 [REG_C_6] = MLX5_MODI_META_REG_C_6,
764 [REG_C_7] = MLX5_MODI_META_REG_C_7,
768 * Convert register set to DV specification.
770 * @param[in,out] resource
771 * Pointer to the modify-header resource.
773 * Pointer to action specification.
775 * Pointer to the error structure.
778 * 0 on success, a negative errno value otherwise and rte_errno is set.
781 flow_dv_convert_action_set_reg
782 (struct mlx5_flow_dv_modify_hdr_resource *resource,
783 const struct rte_flow_action *action,
784 struct rte_flow_error *error)
786 const struct mlx5_rte_flow_action_set_tag *conf = (action->conf);
787 struct mlx5_modification_cmd *actions = resource->actions;
788 uint32_t i = resource->actions_num;
790 if (i >= MLX5_MODIFY_NUM)
791 return rte_flow_error_set(error, EINVAL,
792 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
793 "too many items to modify");
794 actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
795 actions[i].field = reg_to_field[conf->id];
796 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
797 actions[i].data1 = conf->data;
799 resource->actions_num = i;
800 if (!resource->actions_num)
801 return rte_flow_error_set(error, EINVAL,
802 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
803 "invalid modification flow item");
808 * Validate META item.
811 * Pointer to the rte_eth_dev structure.
813 * Item specification.
815 * Attributes of flow that includes this item.
817 * Pointer to error structure.
820 * 0 on success, a negative errno value otherwise and rte_errno is set.
823 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
824 const struct rte_flow_item *item,
825 const struct rte_flow_attr *attr,
826 struct rte_flow_error *error)
828 const struct rte_flow_item_meta *spec = item->spec;
829 const struct rte_flow_item_meta *mask = item->mask;
830 const struct rte_flow_item_meta nic_mask = {
836 return rte_flow_error_set(error, EINVAL,
837 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
839 "data cannot be empty");
841 return rte_flow_error_set(error, EINVAL,
842 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
844 "data cannot be zero");
846 mask = &rte_flow_item_meta_mask;
847 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
848 (const uint8_t *)&nic_mask,
849 sizeof(struct rte_flow_item_meta),
854 return rte_flow_error_set(error, ENOTSUP,
855 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
857 "pattern not supported for ingress");
862 * Validate vport item.
865 * Pointer to the rte_eth_dev structure.
867 * Item specification.
869 * Attributes of flow that includes this item.
870 * @param[in] item_flags
871 * Bit-fields that holds the items detected until now.
873 * Pointer to error structure.
876 * 0 on success, a negative errno value otherwise and rte_errno is set.
879 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
880 const struct rte_flow_item *item,
881 const struct rte_flow_attr *attr,
883 struct rte_flow_error *error)
885 const struct rte_flow_item_port_id *spec = item->spec;
886 const struct rte_flow_item_port_id *mask = item->mask;
887 const struct rte_flow_item_port_id switch_mask = {
890 struct mlx5_priv *esw_priv;
891 struct mlx5_priv *dev_priv;
895 return rte_flow_error_set(error, EINVAL,
896 RTE_FLOW_ERROR_TYPE_ITEM,
898 "match on port id is valid only"
899 " when transfer flag is enabled");
900 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
901 return rte_flow_error_set(error, ENOTSUP,
902 RTE_FLOW_ERROR_TYPE_ITEM, item,
903 "multiple source ports are not"
907 if (mask->id != 0xffffffff)
908 return rte_flow_error_set(error, ENOTSUP,
909 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
911 "no support for partial mask on"
913 ret = mlx5_flow_item_acceptable
914 (item, (const uint8_t *)mask,
915 (const uint8_t *)&rte_flow_item_port_id_mask,
916 sizeof(struct rte_flow_item_port_id),
922 esw_priv = mlx5_port_to_eswitch_info(spec->id);
924 return rte_flow_error_set(error, rte_errno,
925 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
926 "failed to obtain E-Switch info for"
928 dev_priv = mlx5_dev_to_eswitch_info(dev);
930 return rte_flow_error_set(error, rte_errno,
931 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
933 "failed to obtain E-Switch info");
934 if (esw_priv->domain_id != dev_priv->domain_id)
935 return rte_flow_error_set(error, EINVAL,
936 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
937 "cannot match on a port from a"
938 " different E-Switch");
943 * Validate the pop VLAN action.
946 * Pointer to the rte_eth_dev structure.
947 * @param[in] action_flags
948 * Holds the actions detected until now.
950 * Pointer to the pop vlan action.
951 * @param[in] item_flags
952 * The items found in this flow rule.
954 * Pointer to flow attributes.
956 * Pointer to error structure.
959 * 0 on success, a negative errno value otherwise and rte_errno is set.
962 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
963 uint64_t action_flags,
964 const struct rte_flow_action *action,
966 const struct rte_flow_attr *attr,
967 struct rte_flow_error *error)
969 struct mlx5_priv *priv = dev->data->dev_private;
973 if (!priv->sh->pop_vlan_action)
974 return rte_flow_error_set(error, ENOTSUP,
975 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
977 "pop vlan action is not supported");
979 * Check for inconsistencies:
980 * fail strip_vlan in a flow that matches packets without VLAN tags.
981 * fail strip_vlan in a flow that matches packets without explicitly a
982 * matching on VLAN tag ?
984 if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN)
985 return rte_flow_error_set(error, ENOTSUP,
986 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
988 "no support for multiple vlan pop "
990 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
991 return rte_flow_error_set(error, ENOTSUP,
992 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
994 "cannot pop vlan without a "
995 "match on (outer) vlan in the flow");
996 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
997 return rte_flow_error_set(error, EINVAL,
998 RTE_FLOW_ERROR_TYPE_ACTION, action,
999 "wrong action order, port_id should "
1000 "be after pop VLAN action");
1005 * Get VLAN default info from vlan match info.
1008 * Pointer to the rte_eth_dev structure.
1010 * the list of item specifications.
1012 * pointer VLAN info to fill to.
1014 * Pointer to error structure.
1017 * 0 on success, a negative errno value otherwise and rte_errno is set.
1020 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
1021 struct rte_vlan_hdr *vlan)
1023 const struct rte_flow_item_vlan nic_mask = {
1024 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
1025 MLX5DV_FLOW_VLAN_VID_MASK),
1026 .inner_type = RTE_BE16(0xffff),
1031 for (; items->type != RTE_FLOW_ITEM_TYPE_END &&
1032 items->type != RTE_FLOW_ITEM_TYPE_VLAN; items++)
1034 if (items->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1035 const struct rte_flow_item_vlan *vlan_m = items->mask;
1036 const struct rte_flow_item_vlan *vlan_v = items->spec;
1040 /* Only full match values are accepted */
1041 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
1042 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
1043 vlan->vlan_tci &= MLX5DV_FLOW_VLAN_PCP_MASK;
1045 rte_be_to_cpu_16(vlan_v->tci &
1046 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
1048 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
1049 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
1050 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
1052 rte_be_to_cpu_16(vlan_v->tci &
1053 MLX5DV_FLOW_VLAN_VID_MASK_BE);
1055 if (vlan_m->inner_type == nic_mask.inner_type)
1056 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
1057 vlan_m->inner_type);
1062 * Validate the push VLAN action.
1064 * @param[in] action_flags
1065 * Holds the actions detected until now.
1067 * Pointer to the encap action.
1069 * Pointer to flow attributes
1071 * Pointer to error structure.
1074 * 0 on success, a negative errno value otherwise and rte_errno is set.
1077 flow_dv_validate_action_push_vlan(uint64_t action_flags,
1078 uint64_t item_flags,
1079 const struct rte_flow_action *action,
1080 const struct rte_flow_attr *attr,
1081 struct rte_flow_error *error)
1083 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
1085 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
1086 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
1087 return rte_flow_error_set(error, EINVAL,
1088 RTE_FLOW_ERROR_TYPE_ACTION, action,
1089 "invalid vlan ethertype");
1091 (MLX5_FLOW_ACTION_OF_POP_VLAN | MLX5_FLOW_ACTION_OF_PUSH_VLAN))
1092 return rte_flow_error_set(error, ENOTSUP,
1093 RTE_FLOW_ERROR_TYPE_ACTION, action,
1094 "no support for multiple VLAN "
1096 if (!mlx5_flow_find_action
1097 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) &&
1098 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1099 return rte_flow_error_set(error, ENOTSUP,
1100 RTE_FLOW_ERROR_TYPE_ACTION, action,
1101 "push VLAN needs to match on VLAN in order to "
1102 "get VLAN VID information because there is "
1103 "no followed set VLAN VID action");
1104 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1105 return rte_flow_error_set(error, EINVAL,
1106 RTE_FLOW_ERROR_TYPE_ACTION, action,
1107 "wrong action order, port_id should "
1108 "be after push VLAN");
1114 * Validate the set VLAN PCP.
1116 * @param[in] action_flags
1117 * Holds the actions detected until now.
1118 * @param[in] actions
1119 * Pointer to the list of actions remaining in the flow rule.
1121 * Pointer to flow attributes
1123 * Pointer to error structure.
1126 * 0 on success, a negative errno value otherwise and rte_errno is set.
1129 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
1130 const struct rte_flow_action actions[],
1131 struct rte_flow_error *error)
1133 const struct rte_flow_action *action = actions;
1134 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
1136 if (conf->vlan_pcp > 7)
1137 return rte_flow_error_set(error, EINVAL,
1138 RTE_FLOW_ERROR_TYPE_ACTION, action,
1139 "VLAN PCP value is too big");
1140 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
1141 return rte_flow_error_set(error, ENOTSUP,
1142 RTE_FLOW_ERROR_TYPE_ACTION, action,
1143 "set VLAN PCP action must follow "
1144 "the push VLAN action");
1145 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
1146 return rte_flow_error_set(error, ENOTSUP,
1147 RTE_FLOW_ERROR_TYPE_ACTION, action,
1148 "Multiple VLAN PCP modification are "
1150 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1151 return rte_flow_error_set(error, EINVAL,
1152 RTE_FLOW_ERROR_TYPE_ACTION, action,
1153 "wrong action order, port_id should "
1154 "be after set VLAN PCP");
1159 * Validate the set VLAN VID.
1161 * @param[in] item_flags
1162 * Holds the items detected in this rule.
1163 * @param[in] actions
1164 * Pointer to the list of actions remaining in the flow rule.
1166 * Pointer to flow attributes
1168 * Pointer to error structure.
1171 * 0 on success, a negative errno value otherwise and rte_errno is set.
1174 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
1175 uint64_t action_flags,
1176 const struct rte_flow_action actions[],
1177 struct rte_flow_error *error)
1179 const struct rte_flow_action *action = actions;
1180 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
1182 if (conf->vlan_vid > RTE_BE16(0xFFE))
1183 return rte_flow_error_set(error, EINVAL,
1184 RTE_FLOW_ERROR_TYPE_ACTION, action,
1185 "VLAN VID value is too big");
1186 /* there is an of_push_vlan action before us */
1187 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
1188 if (mlx5_flow_find_action(actions + 1,
1189 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID))
1190 return rte_flow_error_set(error, ENOTSUP,
1191 RTE_FLOW_ERROR_TYPE_ACTION, action,
1192 "Multiple VLAN VID modifications are "
1199 * Action is on an existing VLAN header:
1200 * Need to verify this is a single modify CID action.
1201 * Rule mast include a match on outer VLAN.
1203 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
1204 return rte_flow_error_set(error, ENOTSUP,
1205 RTE_FLOW_ERROR_TYPE_ACTION, action,
1206 "Multiple VLAN VID modifications are "
1208 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1209 return rte_flow_error_set(error, EINVAL,
1210 RTE_FLOW_ERROR_TYPE_ACTION, action,
1211 "match on VLAN is required in order "
1213 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1214 return rte_flow_error_set(error, EINVAL,
1215 RTE_FLOW_ERROR_TYPE_ACTION, action,
1216 "wrong action order, port_id should "
1217 "be after set VLAN VID");
1222 * Validate count action.
1227 * Pointer to error structure.
1230 * 0 on success, a negative errno value otherwise and rte_errno is set.
1233 flow_dv_validate_action_count(struct rte_eth_dev *dev,
1234 struct rte_flow_error *error)
1236 struct mlx5_priv *priv = dev->data->dev_private;
1238 if (!priv->config.devx)
1240 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
1244 return rte_flow_error_set
1246 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1248 "count action not supported");
1252 * Validate the L2 encap action.
1254 * @param[in] action_flags
1255 * Holds the actions detected until now.
1257 * Pointer to the encap action.
1259 * Pointer to flow attributes
1261 * Pointer to error structure.
1264 * 0 on success, a negative errno value otherwise and rte_errno is set.
1267 flow_dv_validate_action_l2_encap(uint64_t action_flags,
1268 const struct rte_flow_action *action,
1269 const struct rte_flow_attr *attr,
1270 struct rte_flow_error *error)
1272 if (!(action->conf))
1273 return rte_flow_error_set(error, EINVAL,
1274 RTE_FLOW_ERROR_TYPE_ACTION, action,
1275 "configuration cannot be null");
1276 if (action_flags & MLX5_FLOW_ACTION_DROP)
1277 return rte_flow_error_set(error, EINVAL,
1278 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1279 "can't drop and encap in same flow");
1280 if (action_flags & (MLX5_FLOW_ENCAP_ACTIONS | MLX5_FLOW_DECAP_ACTIONS))
1281 return rte_flow_error_set(error, EINVAL,
1282 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1283 "can only have a single encap or"
1284 " decap action in a flow");
1285 if (!attr->transfer && attr->ingress)
1286 return rte_flow_error_set(error, ENOTSUP,
1287 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1289 "encap action not supported for "
1295 * Validate the L2 decap action.
1297 * @param[in] action_flags
1298 * Holds the actions detected until now.
1300 * Pointer to flow attributes
1302 * Pointer to error structure.
1305 * 0 on success, a negative errno value otherwise and rte_errno is set.
1308 flow_dv_validate_action_l2_decap(uint64_t action_flags,
1309 const struct rte_flow_attr *attr,
1310 struct rte_flow_error *error)
1312 if (action_flags & MLX5_FLOW_ACTION_DROP)
1313 return rte_flow_error_set(error, EINVAL,
1314 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1315 "can't drop and decap in same flow");
1316 if (action_flags & (MLX5_FLOW_ENCAP_ACTIONS | MLX5_FLOW_DECAP_ACTIONS))
1317 return rte_flow_error_set(error, EINVAL,
1318 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1319 "can only have a single encap or"
1320 " decap action in a flow");
1321 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
1322 return rte_flow_error_set(error, EINVAL,
1323 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1324 "can't have decap action after"
1327 return rte_flow_error_set(error, ENOTSUP,
1328 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1330 "decap action not supported for "
1336 * Validate the raw encap action.
1338 * @param[in] action_flags
1339 * Holds the actions detected until now.
1341 * Pointer to the encap action.
1343 * Pointer to flow attributes
1345 * Pointer to error structure.
1348 * 0 on success, a negative errno value otherwise and rte_errno is set.
1351 flow_dv_validate_action_raw_encap(uint64_t action_flags,
1352 const struct rte_flow_action *action,
1353 const struct rte_flow_attr *attr,
1354 struct rte_flow_error *error)
1356 const struct rte_flow_action_raw_encap *raw_encap =
1357 (const struct rte_flow_action_raw_encap *)action->conf;
1358 if (!(action->conf))
1359 return rte_flow_error_set(error, EINVAL,
1360 RTE_FLOW_ERROR_TYPE_ACTION, action,
1361 "configuration cannot be null");
1362 if (action_flags & MLX5_FLOW_ACTION_DROP)
1363 return rte_flow_error_set(error, EINVAL,
1364 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1365 "can't drop and encap in same flow");
1366 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
1367 return rte_flow_error_set(error, EINVAL,
1368 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1369 "can only have a single encap"
1370 " action in a flow");
1371 /* encap without preceding decap is not supported for ingress */
1372 if (!attr->transfer && attr->ingress &&
1373 !(action_flags & MLX5_FLOW_ACTION_RAW_DECAP))
1374 return rte_flow_error_set(error, ENOTSUP,
1375 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1377 "encap action not supported for "
1379 if (!raw_encap->size || !raw_encap->data)
1380 return rte_flow_error_set(error, EINVAL,
1381 RTE_FLOW_ERROR_TYPE_ACTION, action,
1382 "raw encap data cannot be empty");
1387 * Validate the raw decap action.
1389 * @param[in] action_flags
1390 * Holds the actions detected until now.
1392 * Pointer to the encap action.
1394 * Pointer to flow attributes
1396 * Pointer to error structure.
1399 * 0 on success, a negative errno value otherwise and rte_errno is set.
1402 flow_dv_validate_action_raw_decap(uint64_t action_flags,
1403 const struct rte_flow_action *action,
1404 const struct rte_flow_attr *attr,
1405 struct rte_flow_error *error)
1407 if (action_flags & MLX5_FLOW_ACTION_DROP)
1408 return rte_flow_error_set(error, EINVAL,
1409 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1410 "can't drop and decap in same flow");
1411 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
1412 return rte_flow_error_set(error, EINVAL,
1413 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1414 "can't have encap action before"
1416 if (action_flags & MLX5_FLOW_DECAP_ACTIONS)
1417 return rte_flow_error_set(error, EINVAL,
1418 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1419 "can only have a single decap"
1420 " action in a flow");
1421 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
1422 return rte_flow_error_set(error, EINVAL,
1423 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1424 "can't have decap action after"
1426 /* decap action is valid on egress only if it is followed by encap */
1428 for (; action->type != RTE_FLOW_ACTION_TYPE_END &&
1429 action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP;
1432 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP)
1433 return rte_flow_error_set
1435 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1436 NULL, "decap action not supported"
1443 * Find existing encap/decap resource or create and register a new one.
1445 * @param dev[in, out]
1446 * Pointer to rte_eth_dev structure.
1447 * @param[in, out] resource
1448 * Pointer to encap/decap resource.
1449 * @parm[in, out] dev_flow
1450 * Pointer to the dev_flow.
1452 * pointer to error structure.
1455 * 0 on success otherwise -errno and errno is set.
1458 flow_dv_encap_decap_resource_register
1459 (struct rte_eth_dev *dev,
1460 struct mlx5_flow_dv_encap_decap_resource *resource,
1461 struct mlx5_flow *dev_flow,
1462 struct rte_flow_error *error)
1464 struct mlx5_priv *priv = dev->data->dev_private;
1465 struct mlx5_ibv_shared *sh = priv->sh;
1466 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
1467 struct rte_flow *flow = dev_flow->flow;
1468 struct mlx5dv_dr_domain *domain;
1470 resource->flags = flow->group ? 0 : 1;
1471 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
1472 domain = sh->fdb_domain;
1473 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
1474 domain = sh->rx_domain;
1476 domain = sh->tx_domain;
1478 /* Lookup a matching resource from cache. */
1479 LIST_FOREACH(cache_resource, &sh->encaps_decaps, next) {
1480 if (resource->reformat_type == cache_resource->reformat_type &&
1481 resource->ft_type == cache_resource->ft_type &&
1482 resource->flags == cache_resource->flags &&
1483 resource->size == cache_resource->size &&
1484 !memcmp((const void *)resource->buf,
1485 (const void *)cache_resource->buf,
1487 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d++",
1488 (void *)cache_resource,
1489 rte_atomic32_read(&cache_resource->refcnt));
1490 rte_atomic32_inc(&cache_resource->refcnt);
1491 dev_flow->dv.encap_decap = cache_resource;
1495 /* Register new encap/decap resource. */
1496 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
1497 if (!cache_resource)
1498 return rte_flow_error_set(error, ENOMEM,
1499 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1500 "cannot allocate resource memory");
1501 *cache_resource = *resource;
1502 cache_resource->verbs_action =
1503 mlx5_glue->dv_create_flow_action_packet_reformat
1504 (sh->ctx, cache_resource->reformat_type,
1505 cache_resource->ft_type, domain, cache_resource->flags,
1506 cache_resource->size,
1507 (cache_resource->size ? cache_resource->buf : NULL));
1508 if (!cache_resource->verbs_action) {
1509 rte_free(cache_resource);
1510 return rte_flow_error_set(error, ENOMEM,
1511 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1512 NULL, "cannot create action");
1514 rte_atomic32_init(&cache_resource->refcnt);
1515 rte_atomic32_inc(&cache_resource->refcnt);
1516 LIST_INSERT_HEAD(&sh->encaps_decaps, cache_resource, next);
1517 dev_flow->dv.encap_decap = cache_resource;
1518 DRV_LOG(DEBUG, "new encap/decap resource %p: refcnt %d++",
1519 (void *)cache_resource,
1520 rte_atomic32_read(&cache_resource->refcnt));
1525 * Find existing table jump resource or create and register a new one.
1527 * @param dev[in, out]
1528 * Pointer to rte_eth_dev structure.
1529 * @param[in, out] resource
1530 * Pointer to jump table resource.
1531 * @parm[in, out] dev_flow
1532 * Pointer to the dev_flow.
1534 * pointer to error structure.
1537 * 0 on success otherwise -errno and errno is set.
1540 flow_dv_jump_tbl_resource_register
1541 (struct rte_eth_dev *dev,
1542 struct mlx5_flow_dv_jump_tbl_resource *resource,
1543 struct mlx5_flow *dev_flow,
1544 struct rte_flow_error *error)
1546 struct mlx5_priv *priv = dev->data->dev_private;
1547 struct mlx5_ibv_shared *sh = priv->sh;
1548 struct mlx5_flow_dv_jump_tbl_resource *cache_resource;
1550 /* Lookup a matching resource from cache. */
1551 LIST_FOREACH(cache_resource, &sh->jump_tbl, next) {
1552 if (resource->tbl == cache_resource->tbl) {
1553 DRV_LOG(DEBUG, "jump table resource resource %p: refcnt %d++",
1554 (void *)cache_resource,
1555 rte_atomic32_read(&cache_resource->refcnt));
1556 rte_atomic32_inc(&cache_resource->refcnt);
1557 dev_flow->dv.jump = cache_resource;
1561 /* Register new jump table resource. */
1562 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
1563 if (!cache_resource)
1564 return rte_flow_error_set(error, ENOMEM,
1565 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1566 "cannot allocate resource memory");
1567 *cache_resource = *resource;
1568 cache_resource->action =
1569 mlx5_glue->dr_create_flow_action_dest_flow_tbl
1570 (resource->tbl->obj);
1571 if (!cache_resource->action) {
1572 rte_free(cache_resource);
1573 return rte_flow_error_set(error, ENOMEM,
1574 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1575 NULL, "cannot create action");
1577 rte_atomic32_init(&cache_resource->refcnt);
1578 rte_atomic32_inc(&cache_resource->refcnt);
1579 LIST_INSERT_HEAD(&sh->jump_tbl, cache_resource, next);
1580 dev_flow->dv.jump = cache_resource;
1581 DRV_LOG(DEBUG, "new jump table resource %p: refcnt %d++",
1582 (void *)cache_resource,
1583 rte_atomic32_read(&cache_resource->refcnt));
1588 * Find existing table port ID resource or create and register a new one.
1590 * @param dev[in, out]
1591 * Pointer to rte_eth_dev structure.
1592 * @param[in, out] resource
1593 * Pointer to port ID action resource.
1594 * @parm[in, out] dev_flow
1595 * Pointer to the dev_flow.
1597 * pointer to error structure.
1600 * 0 on success otherwise -errno and errno is set.
1603 flow_dv_port_id_action_resource_register
1604 (struct rte_eth_dev *dev,
1605 struct mlx5_flow_dv_port_id_action_resource *resource,
1606 struct mlx5_flow *dev_flow,
1607 struct rte_flow_error *error)
1609 struct mlx5_priv *priv = dev->data->dev_private;
1610 struct mlx5_ibv_shared *sh = priv->sh;
1611 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
1613 /* Lookup a matching resource from cache. */
1614 LIST_FOREACH(cache_resource, &sh->port_id_action_list, next) {
1615 if (resource->port_id == cache_resource->port_id) {
1616 DRV_LOG(DEBUG, "port id action resource resource %p: "
1618 (void *)cache_resource,
1619 rte_atomic32_read(&cache_resource->refcnt));
1620 rte_atomic32_inc(&cache_resource->refcnt);
1621 dev_flow->dv.port_id_action = cache_resource;
1625 /* Register new port id action resource. */
1626 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
1627 if (!cache_resource)
1628 return rte_flow_error_set(error, ENOMEM,
1629 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1630 "cannot allocate resource memory");
1631 *cache_resource = *resource;
1632 cache_resource->action =
1633 mlx5_glue->dr_create_flow_action_dest_vport
1634 (priv->sh->fdb_domain, resource->port_id);
1635 if (!cache_resource->action) {
1636 rte_free(cache_resource);
1637 return rte_flow_error_set(error, ENOMEM,
1638 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1639 NULL, "cannot create action");
1641 rte_atomic32_init(&cache_resource->refcnt);
1642 rte_atomic32_inc(&cache_resource->refcnt);
1643 LIST_INSERT_HEAD(&sh->port_id_action_list, cache_resource, next);
1644 dev_flow->dv.port_id_action = cache_resource;
1645 DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++",
1646 (void *)cache_resource,
1647 rte_atomic32_read(&cache_resource->refcnt));
1652 * Find existing push vlan resource or create and register a new one.
1654 * @param dev[in, out]
1655 * Pointer to rte_eth_dev structure.
1656 * @param[in, out] resource
1657 * Pointer to port ID action resource.
1658 * @parm[in, out] dev_flow
1659 * Pointer to the dev_flow.
1661 * pointer to error structure.
1664 * 0 on success otherwise -errno and errno is set.
1667 flow_dv_push_vlan_action_resource_register
1668 (struct rte_eth_dev *dev,
1669 struct mlx5_flow_dv_push_vlan_action_resource *resource,
1670 struct mlx5_flow *dev_flow,
1671 struct rte_flow_error *error)
1673 struct mlx5_priv *priv = dev->data->dev_private;
1674 struct mlx5_ibv_shared *sh = priv->sh;
1675 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
1676 struct mlx5dv_dr_domain *domain;
1678 /* Lookup a matching resource from cache. */
1679 LIST_FOREACH(cache_resource, &sh->push_vlan_action_list, next) {
1680 if (resource->vlan_tag == cache_resource->vlan_tag &&
1681 resource->ft_type == cache_resource->ft_type) {
1682 DRV_LOG(DEBUG, "push-VLAN action resource resource %p: "
1684 (void *)cache_resource,
1685 rte_atomic32_read(&cache_resource->refcnt));
1686 rte_atomic32_inc(&cache_resource->refcnt);
1687 dev_flow->dv.push_vlan_res = cache_resource;
1691 /* Register new push_vlan action resource. */
1692 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
1693 if (!cache_resource)
1694 return rte_flow_error_set(error, ENOMEM,
1695 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1696 "cannot allocate resource memory");
1697 *cache_resource = *resource;
1698 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
1699 domain = sh->fdb_domain;
1700 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
1701 domain = sh->rx_domain;
1703 domain = sh->tx_domain;
1704 cache_resource->action =
1705 mlx5_glue->dr_create_flow_action_push_vlan(domain,
1706 resource->vlan_tag);
1707 if (!cache_resource->action) {
1708 rte_free(cache_resource);
1709 return rte_flow_error_set(error, ENOMEM,
1710 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1711 NULL, "cannot create action");
1713 rte_atomic32_init(&cache_resource->refcnt);
1714 rte_atomic32_inc(&cache_resource->refcnt);
1715 LIST_INSERT_HEAD(&sh->push_vlan_action_list, cache_resource, next);
1716 dev_flow->dv.push_vlan_res = cache_resource;
1717 DRV_LOG(DEBUG, "new push vlan action resource %p: refcnt %d++",
1718 (void *)cache_resource,
1719 rte_atomic32_read(&cache_resource->refcnt));
1723 * Get the size of specific rte_flow_item_type
1725 * @param[in] item_type
1726 * Tested rte_flow_item_type.
1729 * sizeof struct item_type, 0 if void or irrelevant.
1732 flow_dv_get_item_len(const enum rte_flow_item_type item_type)
1736 switch (item_type) {
1737 case RTE_FLOW_ITEM_TYPE_ETH:
1738 retval = sizeof(struct rte_flow_item_eth);
1740 case RTE_FLOW_ITEM_TYPE_VLAN:
1741 retval = sizeof(struct rte_flow_item_vlan);
1743 case RTE_FLOW_ITEM_TYPE_IPV4:
1744 retval = sizeof(struct rte_flow_item_ipv4);
1746 case RTE_FLOW_ITEM_TYPE_IPV6:
1747 retval = sizeof(struct rte_flow_item_ipv6);
1749 case RTE_FLOW_ITEM_TYPE_UDP:
1750 retval = sizeof(struct rte_flow_item_udp);
1752 case RTE_FLOW_ITEM_TYPE_TCP:
1753 retval = sizeof(struct rte_flow_item_tcp);
1755 case RTE_FLOW_ITEM_TYPE_VXLAN:
1756 retval = sizeof(struct rte_flow_item_vxlan);
1758 case RTE_FLOW_ITEM_TYPE_GRE:
1759 retval = sizeof(struct rte_flow_item_gre);
1761 case RTE_FLOW_ITEM_TYPE_NVGRE:
1762 retval = sizeof(struct rte_flow_item_nvgre);
1764 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
1765 retval = sizeof(struct rte_flow_item_vxlan_gpe);
1767 case RTE_FLOW_ITEM_TYPE_MPLS:
1768 retval = sizeof(struct rte_flow_item_mpls);
1770 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
1778 #define MLX5_ENCAP_IPV4_VERSION 0x40
1779 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
1780 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
1781 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
1782 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
1783 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
1784 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
1787 * Convert the encap action data from list of rte_flow_item to raw buffer
1790 * Pointer to rte_flow_item objects list.
1792 * Pointer to the output buffer.
1794 * Pointer to the output buffer size.
1796 * Pointer to the error structure.
1799 * 0 on success, a negative errno value otherwise and rte_errno is set.
1802 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
1803 size_t *size, struct rte_flow_error *error)
1805 struct rte_ether_hdr *eth = NULL;
1806 struct rte_vlan_hdr *vlan = NULL;
1807 struct rte_ipv4_hdr *ipv4 = NULL;
1808 struct rte_ipv6_hdr *ipv6 = NULL;
1809 struct rte_udp_hdr *udp = NULL;
1810 struct rte_vxlan_hdr *vxlan = NULL;
1811 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
1812 struct rte_gre_hdr *gre = NULL;
1814 size_t temp_size = 0;
1817 return rte_flow_error_set(error, EINVAL,
1818 RTE_FLOW_ERROR_TYPE_ACTION,
1819 NULL, "invalid empty data");
1820 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
1821 len = flow_dv_get_item_len(items->type);
1822 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
1823 return rte_flow_error_set(error, EINVAL,
1824 RTE_FLOW_ERROR_TYPE_ACTION,
1825 (void *)items->type,
1826 "items total size is too big"
1827 " for encap action");
1828 rte_memcpy((void *)&buf[temp_size], items->spec, len);
1829 switch (items->type) {
1830 case RTE_FLOW_ITEM_TYPE_ETH:
1831 eth = (struct rte_ether_hdr *)&buf[temp_size];
1833 case RTE_FLOW_ITEM_TYPE_VLAN:
1834 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
1836 return rte_flow_error_set(error, EINVAL,
1837 RTE_FLOW_ERROR_TYPE_ACTION,
1838 (void *)items->type,
1839 "eth header not found");
1840 if (!eth->ether_type)
1841 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
1843 case RTE_FLOW_ITEM_TYPE_IPV4:
1844 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
1846 return rte_flow_error_set(error, EINVAL,
1847 RTE_FLOW_ERROR_TYPE_ACTION,
1848 (void *)items->type,
1849 "neither eth nor vlan"
1851 if (vlan && !vlan->eth_proto)
1852 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
1853 else if (eth && !eth->ether_type)
1854 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
1855 if (!ipv4->version_ihl)
1856 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
1857 MLX5_ENCAP_IPV4_IHL_MIN;
1858 if (!ipv4->time_to_live)
1859 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
1861 case RTE_FLOW_ITEM_TYPE_IPV6:
1862 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
1864 return rte_flow_error_set(error, EINVAL,
1865 RTE_FLOW_ERROR_TYPE_ACTION,
1866 (void *)items->type,
1867 "neither eth nor vlan"
1869 if (vlan && !vlan->eth_proto)
1870 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
1871 else if (eth && !eth->ether_type)
1872 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
1873 if (!ipv6->vtc_flow)
1875 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
1876 if (!ipv6->hop_limits)
1877 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
1879 case RTE_FLOW_ITEM_TYPE_UDP:
1880 udp = (struct rte_udp_hdr *)&buf[temp_size];
1882 return rte_flow_error_set(error, EINVAL,
1883 RTE_FLOW_ERROR_TYPE_ACTION,
1884 (void *)items->type,
1885 "ip header not found");
1886 if (ipv4 && !ipv4->next_proto_id)
1887 ipv4->next_proto_id = IPPROTO_UDP;
1888 else if (ipv6 && !ipv6->proto)
1889 ipv6->proto = IPPROTO_UDP;
1891 case RTE_FLOW_ITEM_TYPE_VXLAN:
1892 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
1894 return rte_flow_error_set(error, EINVAL,
1895 RTE_FLOW_ERROR_TYPE_ACTION,
1896 (void *)items->type,
1897 "udp header not found");
1899 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
1900 if (!vxlan->vx_flags)
1902 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
1904 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
1905 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
1907 return rte_flow_error_set(error, EINVAL,
1908 RTE_FLOW_ERROR_TYPE_ACTION,
1909 (void *)items->type,
1910 "udp header not found");
1911 if (!vxlan_gpe->proto)
1912 return rte_flow_error_set(error, EINVAL,
1913 RTE_FLOW_ERROR_TYPE_ACTION,
1914 (void *)items->type,
1915 "next protocol not found");
1918 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
1919 if (!vxlan_gpe->vx_flags)
1920 vxlan_gpe->vx_flags =
1921 MLX5_ENCAP_VXLAN_GPE_FLAGS;
1923 case RTE_FLOW_ITEM_TYPE_GRE:
1924 case RTE_FLOW_ITEM_TYPE_NVGRE:
1925 gre = (struct rte_gre_hdr *)&buf[temp_size];
1927 return rte_flow_error_set(error, EINVAL,
1928 RTE_FLOW_ERROR_TYPE_ACTION,
1929 (void *)items->type,
1930 "next protocol not found");
1932 return rte_flow_error_set(error, EINVAL,
1933 RTE_FLOW_ERROR_TYPE_ACTION,
1934 (void *)items->type,
1935 "ip header not found");
1936 if (ipv4 && !ipv4->next_proto_id)
1937 ipv4->next_proto_id = IPPROTO_GRE;
1938 else if (ipv6 && !ipv6->proto)
1939 ipv6->proto = IPPROTO_GRE;
1941 case RTE_FLOW_ITEM_TYPE_VOID:
1944 return rte_flow_error_set(error, EINVAL,
1945 RTE_FLOW_ERROR_TYPE_ACTION,
1946 (void *)items->type,
1947 "unsupported item type");
1957 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
1959 struct rte_ether_hdr *eth = NULL;
1960 struct rte_vlan_hdr *vlan = NULL;
1961 struct rte_ipv6_hdr *ipv6 = NULL;
1962 struct rte_udp_hdr *udp = NULL;
1966 eth = (struct rte_ether_hdr *)data;
1967 next_hdr = (char *)(eth + 1);
1968 proto = RTE_BE16(eth->ether_type);
1971 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
1972 vlan = (struct rte_vlan_hdr *)next_hdr;
1973 proto = RTE_BE16(vlan->eth_proto);
1974 next_hdr += sizeof(struct rte_vlan_hdr);
1977 /* HW calculates IPv4 csum. no need to proceed */
1978 if (proto == RTE_ETHER_TYPE_IPV4)
1981 /* non IPv4/IPv6 header. not supported */
1982 if (proto != RTE_ETHER_TYPE_IPV6) {
1983 return rte_flow_error_set(error, ENOTSUP,
1984 RTE_FLOW_ERROR_TYPE_ACTION,
1985 NULL, "Cannot offload non IPv4/IPv6");
1988 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
1990 /* ignore non UDP */
1991 if (ipv6->proto != IPPROTO_UDP)
1994 udp = (struct rte_udp_hdr *)(ipv6 + 1);
1995 udp->dgram_cksum = 0;
2001 * Convert L2 encap action to DV specification.
2004 * Pointer to rte_eth_dev structure.
2006 * Pointer to action structure.
2007 * @param[in, out] dev_flow
2008 * Pointer to the mlx5_flow.
2009 * @param[in] transfer
2010 * Mark if the flow is E-Switch flow.
2012 * Pointer to the error structure.
2015 * 0 on success, a negative errno value otherwise and rte_errno is set.
2018 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
2019 const struct rte_flow_action *action,
2020 struct mlx5_flow *dev_flow,
2022 struct rte_flow_error *error)
2024 const struct rte_flow_item *encap_data;
2025 const struct rte_flow_action_raw_encap *raw_encap_data;
2026 struct mlx5_flow_dv_encap_decap_resource res = {
2028 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
2029 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
2030 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
2033 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
2035 (const struct rte_flow_action_raw_encap *)action->conf;
2036 res.size = raw_encap_data->size;
2037 memcpy(res.buf, raw_encap_data->data, res.size);
2038 if (flow_dv_zero_encap_udp_csum(res.buf, error))
2041 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
2043 ((const struct rte_flow_action_vxlan_encap *)
2044 action->conf)->definition;
2047 ((const struct rte_flow_action_nvgre_encap *)
2048 action->conf)->definition;
2049 if (flow_dv_convert_encap_data(encap_data, res.buf,
2053 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
2054 return rte_flow_error_set(error, EINVAL,
2055 RTE_FLOW_ERROR_TYPE_ACTION,
2056 NULL, "can't create L2 encap action");
2061 * Convert L2 decap action to DV specification.
2064 * Pointer to rte_eth_dev structure.
2065 * @param[in, out] dev_flow
2066 * Pointer to the mlx5_flow.
2067 * @param[in] transfer
2068 * Mark if the flow is E-Switch flow.
2070 * Pointer to the error structure.
2073 * 0 on success, a negative errno value otherwise and rte_errno is set.
2076 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
2077 struct mlx5_flow *dev_flow,
2079 struct rte_flow_error *error)
2081 struct mlx5_flow_dv_encap_decap_resource res = {
2084 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
2085 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
2086 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
2089 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
2090 return rte_flow_error_set(error, EINVAL,
2091 RTE_FLOW_ERROR_TYPE_ACTION,
2092 NULL, "can't create L2 decap action");
2097 * Convert raw decap/encap (L3 tunnel) action to DV specification.
2100 * Pointer to rte_eth_dev structure.
2102 * Pointer to action structure.
2103 * @param[in, out] dev_flow
2104 * Pointer to the mlx5_flow.
2106 * Pointer to the flow attributes.
2108 * Pointer to the error structure.
2111 * 0 on success, a negative errno value otherwise and rte_errno is set.
2114 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
2115 const struct rte_flow_action *action,
2116 struct mlx5_flow *dev_flow,
2117 const struct rte_flow_attr *attr,
2118 struct rte_flow_error *error)
2120 const struct rte_flow_action_raw_encap *encap_data;
2121 struct mlx5_flow_dv_encap_decap_resource res;
2123 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
2124 res.size = encap_data->size;
2125 memcpy(res.buf, encap_data->data, res.size);
2126 res.reformat_type = attr->egress ?
2127 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL :
2128 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2;
2130 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
2132 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
2133 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
2134 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
2135 return rte_flow_error_set(error, EINVAL,
2136 RTE_FLOW_ERROR_TYPE_ACTION,
2137 NULL, "can't create encap action");
2142 * Create action push VLAN.
2145 * Pointer to rte_eth_dev structure.
2146 * @param[in] vlan_tag
2147 * the vlan tag to push to the Ethernet header.
2148 * @param[in, out] dev_flow
2149 * Pointer to the mlx5_flow.
2151 * Pointer to the flow attributes.
2153 * Pointer to the error structure.
2156 * 0 on success, a negative errno value otherwise and rte_errno is set.
2159 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
2160 const struct rte_flow_attr *attr,
2161 const struct rte_vlan_hdr *vlan,
2162 struct mlx5_flow *dev_flow,
2163 struct rte_flow_error *error)
2165 struct mlx5_flow_dv_push_vlan_action_resource res;
2168 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
2171 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
2173 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
2174 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
2175 return flow_dv_push_vlan_action_resource_register
2176 (dev, &res, dev_flow, error);
2180 * Validate the modify-header actions.
2182 * @param[in] action_flags
2183 * Holds the actions detected until now.
2185 * Pointer to the modify action.
2187 * Pointer to error structure.
2190 * 0 on success, a negative errno value otherwise and rte_errno is set.
2193 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
2194 const struct rte_flow_action *action,
2195 struct rte_flow_error *error)
2197 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
2198 return rte_flow_error_set(error, EINVAL,
2199 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2200 NULL, "action configuration not set");
2201 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
2202 return rte_flow_error_set(error, EINVAL,
2203 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2204 "can't have encap action before"
2210 * Validate the modify-header MAC address actions.
2212 * @param[in] action_flags
2213 * Holds the actions detected until now.
2215 * Pointer to the modify action.
2216 * @param[in] item_flags
2217 * Holds the items detected.
2219 * Pointer to error structure.
2222 * 0 on success, a negative errno value otherwise and rte_errno is set.
2225 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
2226 const struct rte_flow_action *action,
2227 const uint64_t item_flags,
2228 struct rte_flow_error *error)
2232 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
2234 if (!(item_flags & MLX5_FLOW_LAYER_L2))
2235 return rte_flow_error_set(error, EINVAL,
2236 RTE_FLOW_ERROR_TYPE_ACTION,
2238 "no L2 item in pattern");
2244 * Validate the modify-header IPv4 address actions.
2246 * @param[in] action_flags
2247 * Holds the actions detected until now.
2249 * Pointer to the modify action.
2250 * @param[in] item_flags
2251 * Holds the items detected.
2253 * Pointer to error structure.
2256 * 0 on success, a negative errno value otherwise and rte_errno is set.
2259 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
2260 const struct rte_flow_action *action,
2261 const uint64_t item_flags,
2262 struct rte_flow_error *error)
2266 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
2268 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
2269 return rte_flow_error_set(error, EINVAL,
2270 RTE_FLOW_ERROR_TYPE_ACTION,
2272 "no ipv4 item in pattern");
2278 * Validate the modify-header IPv6 address actions.
2280 * @param[in] action_flags
2281 * Holds the actions detected until now.
2283 * Pointer to the modify action.
2284 * @param[in] item_flags
2285 * Holds the items detected.
2287 * Pointer to error structure.
2290 * 0 on success, a negative errno value otherwise and rte_errno is set.
2293 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
2294 const struct rte_flow_action *action,
2295 const uint64_t item_flags,
2296 struct rte_flow_error *error)
2300 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
2302 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
2303 return rte_flow_error_set(error, EINVAL,
2304 RTE_FLOW_ERROR_TYPE_ACTION,
2306 "no ipv6 item in pattern");
2312 * Validate the modify-header TP actions.
2314 * @param[in] action_flags
2315 * Holds the actions detected until now.
2317 * Pointer to the modify action.
2318 * @param[in] item_flags
2319 * Holds the items detected.
2321 * Pointer to error structure.
2324 * 0 on success, a negative errno value otherwise and rte_errno is set.
2327 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
2328 const struct rte_flow_action *action,
2329 const uint64_t item_flags,
2330 struct rte_flow_error *error)
2334 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
2336 if (!(item_flags & MLX5_FLOW_LAYER_L4))
2337 return rte_flow_error_set(error, EINVAL,
2338 RTE_FLOW_ERROR_TYPE_ACTION,
2339 NULL, "no transport layer "
2346 * Validate the modify-header actions of increment/decrement
2347 * TCP Sequence-number.
2349 * @param[in] action_flags
2350 * Holds the actions detected until now.
2352 * Pointer to the modify action.
2353 * @param[in] item_flags
2354 * Holds the items detected.
2356 * Pointer to error structure.
2359 * 0 on success, a negative errno value otherwise and rte_errno is set.
2362 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
2363 const struct rte_flow_action *action,
2364 const uint64_t item_flags,
2365 struct rte_flow_error *error)
2369 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
2371 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
2372 return rte_flow_error_set(error, EINVAL,
2373 RTE_FLOW_ERROR_TYPE_ACTION,
2374 NULL, "no TCP item in"
2376 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
2377 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
2378 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
2379 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
2380 return rte_flow_error_set(error, EINVAL,
2381 RTE_FLOW_ERROR_TYPE_ACTION,
2383 "cannot decrease and increase"
2384 " TCP sequence number"
2385 " at the same time");
2391 * Validate the modify-header actions of increment/decrement
2392 * TCP Acknowledgment number.
2394 * @param[in] action_flags
2395 * Holds the actions detected until now.
2397 * Pointer to the modify action.
2398 * @param[in] item_flags
2399 * Holds the items detected.
2401 * Pointer to error structure.
2404 * 0 on success, a negative errno value otherwise and rte_errno is set.
2407 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
2408 const struct rte_flow_action *action,
2409 const uint64_t item_flags,
2410 struct rte_flow_error *error)
2414 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
2416 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
2417 return rte_flow_error_set(error, EINVAL,
2418 RTE_FLOW_ERROR_TYPE_ACTION,
2419 NULL, "no TCP item in"
2421 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
2422 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
2423 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
2424 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
2425 return rte_flow_error_set(error, EINVAL,
2426 RTE_FLOW_ERROR_TYPE_ACTION,
2428 "cannot decrease and increase"
2429 " TCP acknowledgment number"
2430 " at the same time");
2436 * Validate the modify-header TTL actions.
2438 * @param[in] action_flags
2439 * Holds the actions detected until now.
2441 * Pointer to the modify action.
2442 * @param[in] item_flags
2443 * Holds the items detected.
2445 * Pointer to error structure.
2448 * 0 on success, a negative errno value otherwise and rte_errno is set.
2451 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
2452 const struct rte_flow_action *action,
2453 const uint64_t item_flags,
2454 struct rte_flow_error *error)
2458 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
2460 if (!(item_flags & MLX5_FLOW_LAYER_L3))
2461 return rte_flow_error_set(error, EINVAL,
2462 RTE_FLOW_ERROR_TYPE_ACTION,
2464 "no IP protocol in pattern");
2470 * Validate jump action.
2473 * Pointer to the jump action.
2474 * @param[in] action_flags
2475 * Holds the actions detected until now.
2476 * @param[in] attributes
2477 * Pointer to flow attributes
2478 * @param[in] external
2479 * Action belongs to flow rule created by request external to PMD.
2481 * Pointer to error structure.
2484 * 0 on success, a negative errno value otherwise and rte_errno is set.
2487 flow_dv_validate_action_jump(const struct rte_flow_action *action,
2488 uint64_t action_flags,
2489 const struct rte_flow_attr *attributes,
2490 bool external, struct rte_flow_error *error)
2492 uint32_t max_group = attributes->transfer ? MLX5_MAX_TABLES_FDB :
2494 uint32_t target_group, table;
2497 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
2498 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
2499 return rte_flow_error_set(error, EINVAL,
2500 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2501 "can't have 2 fate actions in"
2504 return rte_flow_error_set(error, EINVAL,
2505 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2506 NULL, "action configuration not set");
2508 ((const struct rte_flow_action_jump *)action->conf)->group;
2509 ret = mlx5_flow_group_to_table(attributes, external, target_group,
2513 if (table >= max_group)
2514 return rte_flow_error_set(error, EINVAL,
2515 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
2516 "target group index out of range");
2517 if (attributes->group >= target_group)
2518 return rte_flow_error_set(error, EINVAL,
2519 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2520 "target group must be higher than"
2521 " the current flow group");
2526 * Validate the port_id action.
2529 * Pointer to rte_eth_dev structure.
2530 * @param[in] action_flags
2531 * Bit-fields that holds the actions detected until now.
2533 * Port_id RTE action structure.
2535 * Attributes of flow that includes this action.
2537 * Pointer to error structure.
2540 * 0 on success, a negative errno value otherwise and rte_errno is set.
2543 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
2544 uint64_t action_flags,
2545 const struct rte_flow_action *action,
2546 const struct rte_flow_attr *attr,
2547 struct rte_flow_error *error)
2549 const struct rte_flow_action_port_id *port_id;
2550 struct mlx5_priv *act_priv;
2551 struct mlx5_priv *dev_priv;
2554 if (!attr->transfer)
2555 return rte_flow_error_set(error, ENOTSUP,
2556 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2558 "port id action is valid in transfer"
2560 if (!action || !action->conf)
2561 return rte_flow_error_set(error, ENOTSUP,
2562 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2564 "port id action parameters must be"
2566 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
2567 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
2568 return rte_flow_error_set(error, EINVAL,
2569 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2570 "can have only one fate actions in"
2572 dev_priv = mlx5_dev_to_eswitch_info(dev);
2574 return rte_flow_error_set(error, rte_errno,
2575 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2577 "failed to obtain E-Switch info");
2578 port_id = action->conf;
2579 port = port_id->original ? dev->data->port_id : port_id->id;
2580 act_priv = mlx5_port_to_eswitch_info(port);
2582 return rte_flow_error_set
2584 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
2585 "failed to obtain E-Switch port id for port");
2586 if (act_priv->domain_id != dev_priv->domain_id)
2587 return rte_flow_error_set
2589 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2590 "port does not belong to"
2591 " E-Switch being configured");
2596 * Find existing modify-header resource or create and register a new one.
2598 * @param dev[in, out]
2599 * Pointer to rte_eth_dev structure.
2600 * @param[in, out] resource
2601 * Pointer to modify-header resource.
2602 * @parm[in, out] dev_flow
2603 * Pointer to the dev_flow.
2605 * pointer to error structure.
2608 * 0 on success otherwise -errno and errno is set.
2611 flow_dv_modify_hdr_resource_register
2612 (struct rte_eth_dev *dev,
2613 struct mlx5_flow_dv_modify_hdr_resource *resource,
2614 struct mlx5_flow *dev_flow,
2615 struct rte_flow_error *error)
2617 struct mlx5_priv *priv = dev->data->dev_private;
2618 struct mlx5_ibv_shared *sh = priv->sh;
2619 struct mlx5_flow_dv_modify_hdr_resource *cache_resource;
2620 struct mlx5dv_dr_domain *ns;
2622 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2623 ns = sh->fdb_domain;
2624 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
2629 dev_flow->flow->group ? 0 : MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
2630 /* Lookup a matching resource from cache. */
2631 LIST_FOREACH(cache_resource, &sh->modify_cmds, next) {
2632 if (resource->ft_type == cache_resource->ft_type &&
2633 resource->actions_num == cache_resource->actions_num &&
2634 resource->flags == cache_resource->flags &&
2635 !memcmp((const void *)resource->actions,
2636 (const void *)cache_resource->actions,
2637 (resource->actions_num *
2638 sizeof(resource->actions[0])))) {
2639 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d++",
2640 (void *)cache_resource,
2641 rte_atomic32_read(&cache_resource->refcnt));
2642 rte_atomic32_inc(&cache_resource->refcnt);
2643 dev_flow->dv.modify_hdr = cache_resource;
2647 /* Register new modify-header resource. */
2648 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
2649 if (!cache_resource)
2650 return rte_flow_error_set(error, ENOMEM,
2651 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2652 "cannot allocate resource memory");
2653 *cache_resource = *resource;
2654 cache_resource->verbs_action =
2655 mlx5_glue->dv_create_flow_action_modify_header
2656 (sh->ctx, cache_resource->ft_type,
2657 ns, cache_resource->flags,
2658 cache_resource->actions_num *
2659 sizeof(cache_resource->actions[0]),
2660 (uint64_t *)cache_resource->actions);
2661 if (!cache_resource->verbs_action) {
2662 rte_free(cache_resource);
2663 return rte_flow_error_set(error, ENOMEM,
2664 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2665 NULL, "cannot create action");
2667 rte_atomic32_init(&cache_resource->refcnt);
2668 rte_atomic32_inc(&cache_resource->refcnt);
2669 LIST_INSERT_HEAD(&sh->modify_cmds, cache_resource, next);
2670 dev_flow->dv.modify_hdr = cache_resource;
2671 DRV_LOG(DEBUG, "new modify-header resource %p: refcnt %d++",
2672 (void *)cache_resource,
2673 rte_atomic32_read(&cache_resource->refcnt));
2677 #define MLX5_CNT_CONTAINER_RESIZE 64
2680 * Get or create a flow counter.
2683 * Pointer to the Ethernet device structure.
2685 * Indicate if this counter is shared with other flows.
2687 * Counter identifier.
2690 * pointer to flow counter on success, NULL otherwise and rte_errno is set.
2692 static struct mlx5_flow_counter *
2693 flow_dv_counter_alloc_fallback(struct rte_eth_dev *dev, uint32_t shared,
2696 struct mlx5_priv *priv = dev->data->dev_private;
2697 struct mlx5_flow_counter *cnt = NULL;
2698 struct mlx5_devx_obj *dcs = NULL;
2700 if (!priv->config.devx) {
2701 rte_errno = ENOTSUP;
2705 TAILQ_FOREACH(cnt, &priv->sh->cmng.flow_counters, next) {
2706 if (cnt->shared && cnt->id == id) {
2712 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
2715 cnt = rte_calloc(__func__, 1, sizeof(*cnt), 0);
2717 claim_zero(mlx5_devx_cmd_destroy(cnt->dcs));
2721 struct mlx5_flow_counter tmpl = {
2727 tmpl.action = mlx5_glue->dv_create_flow_action_counter(dcs->obj, 0);
2729 claim_zero(mlx5_devx_cmd_destroy(cnt->dcs));
2735 TAILQ_INSERT_HEAD(&priv->sh->cmng.flow_counters, cnt, next);
2740 * Release a flow counter.
2743 * Pointer to the Ethernet device structure.
2744 * @param[in] counter
2745 * Pointer to the counter handler.
2748 flow_dv_counter_release_fallback(struct rte_eth_dev *dev,
2749 struct mlx5_flow_counter *counter)
2751 struct mlx5_priv *priv = dev->data->dev_private;
2755 if (--counter->ref_cnt == 0) {
2756 TAILQ_REMOVE(&priv->sh->cmng.flow_counters, counter, next);
2757 claim_zero(mlx5_devx_cmd_destroy(counter->dcs));
2763 * Query a devx flow counter.
2766 * Pointer to the Ethernet device structure.
2768 * Pointer to the flow counter.
2770 * The statistics value of packets.
2772 * The statistics value of bytes.
2775 * 0 on success, otherwise a negative errno value and rte_errno is set.
2778 _flow_dv_query_count_fallback(struct rte_eth_dev *dev __rte_unused,
2779 struct mlx5_flow_counter *cnt, uint64_t *pkts,
2782 return mlx5_devx_cmd_flow_counter_query(cnt->dcs, 0, 0, pkts, bytes,
2787 * Get a pool by a counter.
2790 * Pointer to the counter.
2795 static struct mlx5_flow_counter_pool *
2796 flow_dv_counter_pool_get(struct mlx5_flow_counter *cnt)
2799 cnt -= cnt->dcs->id % MLX5_COUNTERS_PER_POOL;
2800 return (struct mlx5_flow_counter_pool *)cnt - 1;
2806 * Get a pool by devx counter ID.
2809 * Pointer to the counter container.
2811 * The counter devx ID.
2814 * The counter pool pointer if exists, NULL otherwise,
2816 static struct mlx5_flow_counter_pool *
2817 flow_dv_find_pool_by_id(struct mlx5_pools_container *cont, int id)
2819 struct mlx5_flow_counter_pool *pool;
2821 TAILQ_FOREACH(pool, &cont->pool_list, next) {
2822 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
2823 MLX5_COUNTERS_PER_POOL;
2825 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
2832 * Allocate a new memory for the counter values wrapped by all the needed
2836 * Pointer to the Ethernet device structure.
2838 * The raw memory areas - each one for MLX5_COUNTERS_PER_POOL counters.
2841 * The new memory management pointer on success, otherwise NULL and rte_errno
2844 static struct mlx5_counter_stats_mem_mng *
2845 flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
2847 struct mlx5_ibv_shared *sh = ((struct mlx5_priv *)
2848 (dev->data->dev_private))->sh;
2849 struct mlx5_devx_mkey_attr mkey_attr;
2850 struct mlx5_counter_stats_mem_mng *mem_mng;
2851 volatile struct flow_counter_stats *raw_data;
2852 int size = (sizeof(struct flow_counter_stats) *
2853 MLX5_COUNTERS_PER_POOL +
2854 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
2855 sizeof(struct mlx5_counter_stats_mem_mng);
2856 uint8_t *mem = rte_calloc(__func__, 1, size, sysconf(_SC_PAGESIZE));
2863 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
2864 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
2865 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
2866 IBV_ACCESS_LOCAL_WRITE);
2867 if (!mem_mng->umem) {
2872 mkey_attr.addr = (uintptr_t)mem;
2873 mkey_attr.size = size;
2874 mkey_attr.umem_id = mem_mng->umem->umem_id;
2875 mkey_attr.pd = sh->pdn;
2876 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
2878 mlx5_glue->devx_umem_dereg(mem_mng->umem);
2883 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
2884 raw_data = (volatile struct flow_counter_stats *)mem;
2885 for (i = 0; i < raws_n; ++i) {
2886 mem_mng->raws[i].mem_mng = mem_mng;
2887 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
2889 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
2894 * Resize a counter container.
2897 * Pointer to the Ethernet device structure.
2899 * Whether the pool is for counter that was allocated by batch command.
2902 * The new container pointer on success, otherwise NULL and rte_errno is set.
2904 static struct mlx5_pools_container *
2905 flow_dv_container_resize(struct rte_eth_dev *dev, uint32_t batch)
2907 struct mlx5_priv *priv = dev->data->dev_private;
2908 struct mlx5_pools_container *cont =
2909 MLX5_CNT_CONTAINER(priv->sh, batch, 0);
2910 struct mlx5_pools_container *new_cont =
2911 MLX5_CNT_CONTAINER_UNUSED(priv->sh, batch, 0);
2912 struct mlx5_counter_stats_mem_mng *mem_mng;
2913 uint32_t resize = cont->n + MLX5_CNT_CONTAINER_RESIZE;
2914 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
2917 if (cont != MLX5_CNT_CONTAINER(priv->sh, batch, 1)) {
2918 /* The last resize still hasn't detected by the host thread. */
2922 new_cont->pools = rte_calloc(__func__, 1, mem_size, 0);
2923 if (!new_cont->pools) {
2928 memcpy(new_cont->pools, cont->pools, cont->n *
2929 sizeof(struct mlx5_flow_counter_pool *));
2930 mem_mng = flow_dv_create_counter_stat_mem_mng(dev,
2931 MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES);
2933 rte_free(new_cont->pools);
2936 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
2937 LIST_INSERT_HEAD(&priv->sh->cmng.free_stat_raws,
2938 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE +
2940 new_cont->n = resize;
2941 rte_atomic16_set(&new_cont->n_valid, rte_atomic16_read(&cont->n_valid));
2942 TAILQ_INIT(&new_cont->pool_list);
2943 TAILQ_CONCAT(&new_cont->pool_list, &cont->pool_list, next);
2944 new_cont->init_mem_mng = mem_mng;
2946 /* Flip the master container. */
2947 priv->sh->cmng.mhi[batch] ^= (uint8_t)1;
2952 * Query a devx flow counter.
2955 * Pointer to the Ethernet device structure.
2957 * Pointer to the flow counter.
2959 * The statistics value of packets.
2961 * The statistics value of bytes.
2964 * 0 on success, otherwise a negative errno value and rte_errno is set.
2967 _flow_dv_query_count(struct rte_eth_dev *dev,
2968 struct mlx5_flow_counter *cnt, uint64_t *pkts,
2971 struct mlx5_priv *priv = dev->data->dev_private;
2972 struct mlx5_flow_counter_pool *pool =
2973 flow_dv_counter_pool_get(cnt);
2974 int offset = cnt - &pool->counters_raw[0];
2976 if (priv->counter_fallback)
2977 return _flow_dv_query_count_fallback(dev, cnt, pkts, bytes);
2979 rte_spinlock_lock(&pool->sl);
2981 * The single counters allocation may allocate smaller ID than the
2982 * current allocated in parallel to the host reading.
2983 * In this case the new counter values must be reported as 0.
2985 if (unlikely(!cnt->batch && cnt->dcs->id < pool->raw->min_dcs_id)) {
2989 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
2990 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
2992 rte_spinlock_unlock(&pool->sl);
2997 * Create and initialize a new counter pool.
3000 * Pointer to the Ethernet device structure.
3002 * The devX counter handle.
3004 * Whether the pool is for counter that was allocated by batch command.
3007 * A new pool pointer on success, NULL otherwise and rte_errno is set.
3009 static struct mlx5_flow_counter_pool *
3010 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
3013 struct mlx5_priv *priv = dev->data->dev_private;
3014 struct mlx5_flow_counter_pool *pool;
3015 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
3017 int16_t n_valid = rte_atomic16_read(&cont->n_valid);
3020 if (cont->n == n_valid) {
3021 cont = flow_dv_container_resize(dev, batch);
3025 size = sizeof(*pool) + MLX5_COUNTERS_PER_POOL *
3026 sizeof(struct mlx5_flow_counter);
3027 pool = rte_calloc(__func__, 1, size, 0);
3032 pool->min_dcs = dcs;
3033 pool->raw = cont->init_mem_mng->raws + n_valid %
3034 MLX5_CNT_CONTAINER_RESIZE;
3035 pool->raw_hw = NULL;
3036 rte_spinlock_init(&pool->sl);
3038 * The generation of the new allocated counters in this pool is 0, 2 in
3039 * the pool generation makes all the counters valid for allocation.
3041 rte_atomic64_set(&pool->query_gen, 0x2);
3042 TAILQ_INIT(&pool->counters);
3043 TAILQ_INSERT_TAIL(&cont->pool_list, pool, next);
3044 cont->pools[n_valid] = pool;
3045 /* Pool initialization must be updated before host thread access. */
3047 rte_atomic16_add(&cont->n_valid, 1);
3052 * Prepare a new counter and/or a new counter pool.
3055 * Pointer to the Ethernet device structure.
3056 * @param[out] cnt_free
3057 * Where to put the pointer of a new counter.
3059 * Whether the pool is for counter that was allocated by batch command.
3062 * The free counter pool pointer and @p cnt_free is set on success,
3063 * NULL otherwise and rte_errno is set.
3065 static struct mlx5_flow_counter_pool *
3066 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
3067 struct mlx5_flow_counter **cnt_free,
3070 struct mlx5_priv *priv = dev->data->dev_private;
3071 struct mlx5_flow_counter_pool *pool;
3072 struct mlx5_devx_obj *dcs = NULL;
3073 struct mlx5_flow_counter *cnt;
3077 /* bulk_bitmap must be 0 for single counter allocation. */
3078 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
3081 pool = flow_dv_find_pool_by_id
3082 (MLX5_CNT_CONTAINER(priv->sh, batch, 0), dcs->id);
3084 pool = flow_dv_pool_create(dev, dcs, batch);
3086 mlx5_devx_cmd_destroy(dcs);
3089 } else if (dcs->id < pool->min_dcs->id) {
3090 rte_atomic64_set(&pool->a64_dcs,
3091 (int64_t)(uintptr_t)dcs);
3093 cnt = &pool->counters_raw[dcs->id % MLX5_COUNTERS_PER_POOL];
3094 TAILQ_INSERT_HEAD(&pool->counters, cnt, next);
3099 /* bulk_bitmap is in 128 counters units. */
3100 if (priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4)
3101 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
3103 rte_errno = ENODATA;
3106 pool = flow_dv_pool_create(dev, dcs, batch);
3108 mlx5_devx_cmd_destroy(dcs);
3111 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
3112 cnt = &pool->counters_raw[i];
3114 TAILQ_INSERT_HEAD(&pool->counters, cnt, next);
3116 *cnt_free = &pool->counters_raw[0];
3121 * Search for existed shared counter.
3124 * Pointer to the relevant counter pool container.
3126 * The shared counter ID to search.
3129 * NULL if not existed, otherwise pointer to the shared counter.
3131 static struct mlx5_flow_counter *
3132 flow_dv_counter_shared_search(struct mlx5_pools_container *cont,
3135 static struct mlx5_flow_counter *cnt;
3136 struct mlx5_flow_counter_pool *pool;
3139 TAILQ_FOREACH(pool, &cont->pool_list, next) {
3140 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
3141 cnt = &pool->counters_raw[i];
3142 if (cnt->ref_cnt && cnt->shared && cnt->id == id)
3150 * Allocate a flow counter.
3153 * Pointer to the Ethernet device structure.
3155 * Indicate if this counter is shared with other flows.
3157 * Counter identifier.
3159 * Counter flow group.
3162 * pointer to flow counter on success, NULL otherwise and rte_errno is set.
3164 static struct mlx5_flow_counter *
3165 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
3168 struct mlx5_priv *priv = dev->data->dev_private;
3169 struct mlx5_flow_counter_pool *pool = NULL;
3170 struct mlx5_flow_counter *cnt_free = NULL;
3172 * Currently group 0 flow counter cannot be assigned to a flow if it is
3173 * not the first one in the batch counter allocation, so it is better
3174 * to allocate counters one by one for these flows in a separate
3176 * A counter can be shared between different groups so need to take
3177 * shared counters from the single container.
3179 uint32_t batch = (group && !shared) ? 1 : 0;
3180 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
3183 if (priv->counter_fallback)
3184 return flow_dv_counter_alloc_fallback(dev, shared, id);
3185 if (!priv->config.devx) {
3186 rte_errno = ENOTSUP;
3190 cnt_free = flow_dv_counter_shared_search(cont, id);
3192 if (cnt_free->ref_cnt + 1 == 0) {
3196 cnt_free->ref_cnt++;
3200 /* Pools which has a free counters are in the start. */
3201 TAILQ_FOREACH(pool, &cont->pool_list, next) {
3203 * The free counter reset values must be updated between the
3204 * counter release to the counter allocation, so, at least one
3205 * query must be done in this time. ensure it by saving the
3206 * query generation in the release time.
3207 * The free list is sorted according to the generation - so if
3208 * the first one is not updated, all the others are not
3211 cnt_free = TAILQ_FIRST(&pool->counters);
3212 if (cnt_free && cnt_free->query_gen + 1 <
3213 rte_atomic64_read(&pool->query_gen))
3218 pool = flow_dv_counter_pool_prepare(dev, &cnt_free, batch);
3222 cnt_free->batch = batch;
3223 /* Create a DV counter action only in the first time usage. */
3224 if (!cnt_free->action) {
3226 struct mlx5_devx_obj *dcs;
3229 offset = cnt_free - &pool->counters_raw[0];
3230 dcs = pool->min_dcs;
3233 dcs = cnt_free->dcs;
3235 cnt_free->action = mlx5_glue->dv_create_flow_action_counter
3237 if (!cnt_free->action) {
3242 /* Update the counter reset values. */
3243 if (_flow_dv_query_count(dev, cnt_free, &cnt_free->hits,
3246 cnt_free->shared = shared;
3247 cnt_free->ref_cnt = 1;
3249 if (!priv->sh->cmng.query_thread_on)
3250 /* Start the asynchronous batch query by the host thread. */
3251 mlx5_set_query_alarm(priv->sh);
3252 TAILQ_REMOVE(&pool->counters, cnt_free, next);
3253 if (TAILQ_EMPTY(&pool->counters)) {
3254 /* Move the pool to the end of the container pool list. */
3255 TAILQ_REMOVE(&cont->pool_list, pool, next);
3256 TAILQ_INSERT_TAIL(&cont->pool_list, pool, next);
3262 * Release a flow counter.
3265 * Pointer to the Ethernet device structure.
3266 * @param[in] counter
3267 * Pointer to the counter handler.
3270 flow_dv_counter_release(struct rte_eth_dev *dev,
3271 struct mlx5_flow_counter *counter)
3273 struct mlx5_priv *priv = dev->data->dev_private;
3277 if (priv->counter_fallback) {
3278 flow_dv_counter_release_fallback(dev, counter);
3281 if (--counter->ref_cnt == 0) {
3282 struct mlx5_flow_counter_pool *pool =
3283 flow_dv_counter_pool_get(counter);
3285 /* Put the counter in the end - the last updated one. */
3286 TAILQ_INSERT_TAIL(&pool->counters, counter, next);
3287 counter->query_gen = rte_atomic64_read(&pool->query_gen);
3292 * Verify the @p attributes will be correctly understood by the NIC and store
3293 * them in the @p flow if everything is correct.
3296 * Pointer to dev struct.
3297 * @param[in] attributes
3298 * Pointer to flow attributes
3299 * @param[in] external
3300 * This flow rule is created by request external to PMD.
3302 * Pointer to error structure.
3305 * 0 on success, a negative errno value otherwise and rte_errno is set.
3308 flow_dv_validate_attributes(struct rte_eth_dev *dev,
3309 const struct rte_flow_attr *attributes,
3310 bool external __rte_unused,
3311 struct rte_flow_error *error)
3313 struct mlx5_priv *priv = dev->data->dev_private;
3314 uint32_t priority_max = priv->config.flow_prio - 1;
3316 #ifndef HAVE_MLX5DV_DR
3317 if (attributes->group)
3318 return rte_flow_error_set(error, ENOTSUP,
3319 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
3321 "groups are not supported");
3323 uint32_t max_group = attributes->transfer ? MLX5_MAX_TABLES_FDB :
3328 ret = mlx5_flow_group_to_table(attributes, external,
3333 if (table >= max_group)
3334 return rte_flow_error_set(error, EINVAL,
3335 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
3336 "group index out of range");
3338 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
3339 attributes->priority >= priority_max)
3340 return rte_flow_error_set(error, ENOTSUP,
3341 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
3343 "priority out of range");
3344 if (attributes->transfer) {
3345 if (!priv->config.dv_esw_en)
3346 return rte_flow_error_set
3348 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3349 "E-Switch dr is not supported");
3350 if (!(priv->representor || priv->master))
3351 return rte_flow_error_set
3352 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3353 NULL, "E-Switch configuration can only be"
3354 " done by a master or a representor device");
3355 if (attributes->egress)
3356 return rte_flow_error_set
3358 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
3359 "egress is not supported");
3361 if (!(attributes->egress ^ attributes->ingress))
3362 return rte_flow_error_set(error, ENOTSUP,
3363 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
3364 "must specify exactly one of "
3365 "ingress or egress");
3370 * Internal validation function. For validating both actions and items.
3373 * Pointer to the rte_eth_dev structure.
3375 * Pointer to the flow attributes.
3377 * Pointer to the list of items.
3378 * @param[in] actions
3379 * Pointer to the list of actions.
3380 * @param[in] external
3381 * This flow rule is created by request external to PMD.
3383 * Pointer to the error structure.
3386 * 0 on success, a negative errno value otherwise and rte_errno is set.
3389 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
3390 const struct rte_flow_item items[],
3391 const struct rte_flow_action actions[],
3392 bool external, struct rte_flow_error *error)
3395 uint64_t action_flags = 0;
3396 uint64_t item_flags = 0;
3397 uint64_t last_item = 0;
3398 uint8_t next_protocol = 0xff;
3399 uint16_t ether_type = 0;
3401 const struct rte_flow_item *gre_item = NULL;
3402 struct rte_flow_item_tcp nic_tcp_mask = {
3405 .src_port = RTE_BE16(UINT16_MAX),
3406 .dst_port = RTE_BE16(UINT16_MAX),
3412 ret = flow_dv_validate_attributes(dev, attr, external, error);
3415 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3416 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3417 int type = items->type;
3420 case RTE_FLOW_ITEM_TYPE_VOID:
3422 case RTE_FLOW_ITEM_TYPE_PORT_ID:
3423 ret = flow_dv_validate_item_port_id
3424 (dev, items, attr, item_flags, error);
3427 last_item = MLX5_FLOW_ITEM_PORT_ID;
3429 case RTE_FLOW_ITEM_TYPE_ETH:
3430 ret = mlx5_flow_validate_item_eth(items, item_flags,
3434 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
3435 MLX5_FLOW_LAYER_OUTER_L2;
3436 if (items->mask != NULL && items->spec != NULL) {
3438 ((const struct rte_flow_item_eth *)
3441 ((const struct rte_flow_item_eth *)
3443 ether_type = rte_be_to_cpu_16(ether_type);
3448 case RTE_FLOW_ITEM_TYPE_VLAN:
3449 ret = mlx5_flow_validate_item_vlan(items, item_flags,
3453 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
3454 MLX5_FLOW_LAYER_OUTER_VLAN;
3455 if (items->mask != NULL && items->spec != NULL) {
3457 ((const struct rte_flow_item_vlan *)
3458 items->spec)->inner_type;
3460 ((const struct rte_flow_item_vlan *)
3461 items->mask)->inner_type;
3462 ether_type = rte_be_to_cpu_16(ether_type);
3467 case RTE_FLOW_ITEM_TYPE_IPV4:
3468 mlx5_flow_tunnel_ip_check(items, next_protocol,
3469 &item_flags, &tunnel);
3470 ret = mlx5_flow_validate_item_ipv4(items, item_flags,
3476 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
3477 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3478 if (items->mask != NULL &&
3479 ((const struct rte_flow_item_ipv4 *)
3480 items->mask)->hdr.next_proto_id) {
3482 ((const struct rte_flow_item_ipv4 *)
3483 (items->spec))->hdr.next_proto_id;
3485 ((const struct rte_flow_item_ipv4 *)
3486 (items->mask))->hdr.next_proto_id;
3488 /* Reset for inner layer. */
3489 next_protocol = 0xff;
3492 case RTE_FLOW_ITEM_TYPE_IPV6:
3493 mlx5_flow_tunnel_ip_check(items, next_protocol,
3494 &item_flags, &tunnel);
3495 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
3501 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
3502 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3503 if (items->mask != NULL &&
3504 ((const struct rte_flow_item_ipv6 *)
3505 items->mask)->hdr.proto) {
3507 ((const struct rte_flow_item_ipv6 *)
3508 items->spec)->hdr.proto;
3510 ((const struct rte_flow_item_ipv6 *)
3511 items->mask)->hdr.proto;
3513 /* Reset for inner layer. */
3514 next_protocol = 0xff;
3517 case RTE_FLOW_ITEM_TYPE_TCP:
3518 ret = mlx5_flow_validate_item_tcp
3525 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
3526 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3528 case RTE_FLOW_ITEM_TYPE_UDP:
3529 ret = mlx5_flow_validate_item_udp(items, item_flags,
3534 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
3535 MLX5_FLOW_LAYER_OUTER_L4_UDP;
3537 case RTE_FLOW_ITEM_TYPE_GRE:
3538 ret = mlx5_flow_validate_item_gre(items, item_flags,
3539 next_protocol, error);
3543 last_item = MLX5_FLOW_LAYER_GRE;
3545 case RTE_FLOW_ITEM_TYPE_NVGRE:
3546 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
3551 last_item = MLX5_FLOW_LAYER_NVGRE;
3553 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
3554 ret = mlx5_flow_validate_item_gre_key
3555 (items, item_flags, gre_item, error);
3558 last_item = MLX5_FLOW_LAYER_GRE_KEY;
3560 case RTE_FLOW_ITEM_TYPE_VXLAN:
3561 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
3565 last_item = MLX5_FLOW_LAYER_VXLAN;
3567 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3568 ret = mlx5_flow_validate_item_vxlan_gpe(items,
3573 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
3575 case RTE_FLOW_ITEM_TYPE_GENEVE:
3576 ret = mlx5_flow_validate_item_geneve(items,
3581 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
3583 case RTE_FLOW_ITEM_TYPE_MPLS:
3584 ret = mlx5_flow_validate_item_mpls(dev, items,
3589 last_item = MLX5_FLOW_LAYER_MPLS;
3591 case RTE_FLOW_ITEM_TYPE_META:
3592 ret = flow_dv_validate_item_meta(dev, items, attr,
3596 last_item = MLX5_FLOW_ITEM_METADATA;
3598 case RTE_FLOW_ITEM_TYPE_ICMP:
3599 ret = mlx5_flow_validate_item_icmp(items, item_flags,
3604 last_item = MLX5_FLOW_LAYER_ICMP;
3606 case RTE_FLOW_ITEM_TYPE_ICMP6:
3607 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
3612 last_item = MLX5_FLOW_LAYER_ICMP6;
3614 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
3615 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
3618 return rte_flow_error_set(error, ENOTSUP,
3619 RTE_FLOW_ERROR_TYPE_ITEM,
3620 NULL, "item not supported");
3622 item_flags |= last_item;
3624 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3625 int type = actions->type;
3626 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
3627 return rte_flow_error_set(error, ENOTSUP,
3628 RTE_FLOW_ERROR_TYPE_ACTION,
3629 actions, "too many actions");
3631 case RTE_FLOW_ACTION_TYPE_VOID:
3633 case RTE_FLOW_ACTION_TYPE_PORT_ID:
3634 ret = flow_dv_validate_action_port_id(dev,
3641 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
3644 case RTE_FLOW_ACTION_TYPE_FLAG:
3645 ret = mlx5_flow_validate_action_flag(action_flags,
3649 action_flags |= MLX5_FLOW_ACTION_FLAG;
3652 case RTE_FLOW_ACTION_TYPE_MARK:
3653 ret = mlx5_flow_validate_action_mark(actions,
3658 action_flags |= MLX5_FLOW_ACTION_MARK;
3661 case RTE_FLOW_ACTION_TYPE_DROP:
3662 ret = mlx5_flow_validate_action_drop(action_flags,
3666 action_flags |= MLX5_FLOW_ACTION_DROP;
3669 case RTE_FLOW_ACTION_TYPE_QUEUE:
3670 ret = mlx5_flow_validate_action_queue(actions,
3675 action_flags |= MLX5_FLOW_ACTION_QUEUE;
3678 case RTE_FLOW_ACTION_TYPE_RSS:
3679 ret = mlx5_flow_validate_action_rss(actions,
3685 action_flags |= MLX5_FLOW_ACTION_RSS;
3688 case RTE_FLOW_ACTION_TYPE_COUNT:
3689 ret = flow_dv_validate_action_count(dev, error);
3692 action_flags |= MLX5_FLOW_ACTION_COUNT;
3695 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3696 if (flow_dv_validate_action_pop_vlan(dev,
3702 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
3705 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3706 ret = flow_dv_validate_action_push_vlan(action_flags,
3712 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
3715 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3716 ret = flow_dv_validate_action_set_vlan_pcp
3717 (action_flags, actions, error);
3720 /* Count PCP with push_vlan command. */
3721 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
3723 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3724 ret = flow_dv_validate_action_set_vlan_vid
3725 (item_flags, action_flags,
3729 /* Count VID with push_vlan command. */
3730 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
3732 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3733 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3734 ret = flow_dv_validate_action_l2_encap(action_flags,
3739 action_flags |= actions->type ==
3740 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ?
3741 MLX5_FLOW_ACTION_VXLAN_ENCAP :
3742 MLX5_FLOW_ACTION_NVGRE_ENCAP;
3745 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3746 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3747 ret = flow_dv_validate_action_l2_decap(action_flags,
3751 action_flags |= actions->type ==
3752 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ?
3753 MLX5_FLOW_ACTION_VXLAN_DECAP :
3754 MLX5_FLOW_ACTION_NVGRE_DECAP;
3757 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3758 ret = flow_dv_validate_action_raw_encap(action_flags,
3763 action_flags |= MLX5_FLOW_ACTION_RAW_ENCAP;
3766 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3767 ret = flow_dv_validate_action_raw_decap(action_flags,
3772 action_flags |= MLX5_FLOW_ACTION_RAW_DECAP;
3775 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3776 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3777 ret = flow_dv_validate_action_modify_mac(action_flags,
3783 /* Count all modify-header actions as one action. */
3784 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
3786 action_flags |= actions->type ==
3787 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
3788 MLX5_FLOW_ACTION_SET_MAC_SRC :
3789 MLX5_FLOW_ACTION_SET_MAC_DST;
3792 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
3793 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
3794 ret = flow_dv_validate_action_modify_ipv4(action_flags,
3800 /* Count all modify-header actions as one action. */
3801 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
3803 action_flags |= actions->type ==
3804 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
3805 MLX5_FLOW_ACTION_SET_IPV4_SRC :
3806 MLX5_FLOW_ACTION_SET_IPV4_DST;
3808 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
3809 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
3810 ret = flow_dv_validate_action_modify_ipv6(action_flags,
3816 /* Count all modify-header actions as one action. */
3817 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
3819 action_flags |= actions->type ==
3820 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
3821 MLX5_FLOW_ACTION_SET_IPV6_SRC :
3822 MLX5_FLOW_ACTION_SET_IPV6_DST;
3824 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
3825 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
3826 ret = flow_dv_validate_action_modify_tp(action_flags,
3832 /* Count all modify-header actions as one action. */
3833 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
3835 action_flags |= actions->type ==
3836 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
3837 MLX5_FLOW_ACTION_SET_TP_SRC :
3838 MLX5_FLOW_ACTION_SET_TP_DST;
3840 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3841 case RTE_FLOW_ACTION_TYPE_SET_TTL:
3842 ret = flow_dv_validate_action_modify_ttl(action_flags,
3848 /* Count all modify-header actions as one action. */
3849 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
3851 action_flags |= actions->type ==
3852 RTE_FLOW_ACTION_TYPE_SET_TTL ?
3853 MLX5_FLOW_ACTION_SET_TTL :
3854 MLX5_FLOW_ACTION_DEC_TTL;
3856 case RTE_FLOW_ACTION_TYPE_JUMP:
3857 ret = flow_dv_validate_action_jump(actions,
3864 action_flags |= MLX5_FLOW_ACTION_JUMP;
3866 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
3867 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
3868 ret = flow_dv_validate_action_modify_tcp_seq
3875 /* Count all modify-header actions as one action. */
3876 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
3878 action_flags |= actions->type ==
3879 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
3880 MLX5_FLOW_ACTION_INC_TCP_SEQ :
3881 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
3883 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
3884 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
3885 ret = flow_dv_validate_action_modify_tcp_ack
3892 /* Count all modify-header actions as one action. */
3893 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
3895 action_flags |= actions->type ==
3896 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
3897 MLX5_FLOW_ACTION_INC_TCP_ACK :
3898 MLX5_FLOW_ACTION_DEC_TCP_ACK;
3900 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
3903 return rte_flow_error_set(error, ENOTSUP,
3904 RTE_FLOW_ERROR_TYPE_ACTION,
3906 "action not supported");
3909 if ((action_flags & MLX5_FLOW_LAYER_TUNNEL) &&
3910 (action_flags & MLX5_FLOW_VLAN_ACTIONS))
3911 return rte_flow_error_set(error, ENOTSUP,
3912 RTE_FLOW_ERROR_TYPE_ACTION,
3914 "can't have vxlan and vlan"
3915 " actions in the same rule");
3916 /* Eswitch has few restrictions on using items and actions */
3917 if (attr->transfer) {
3918 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3919 return rte_flow_error_set(error, ENOTSUP,
3920 RTE_FLOW_ERROR_TYPE_ACTION,
3922 "unsupported action FLAG");
3923 if (action_flags & MLX5_FLOW_ACTION_MARK)
3924 return rte_flow_error_set(error, ENOTSUP,
3925 RTE_FLOW_ERROR_TYPE_ACTION,
3927 "unsupported action MARK");
3928 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
3929 return rte_flow_error_set(error, ENOTSUP,
3930 RTE_FLOW_ERROR_TYPE_ACTION,
3932 "unsupported action QUEUE");
3933 if (action_flags & MLX5_FLOW_ACTION_RSS)
3934 return rte_flow_error_set(error, ENOTSUP,
3935 RTE_FLOW_ERROR_TYPE_ACTION,
3937 "unsupported action RSS");
3938 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3939 return rte_flow_error_set(error, EINVAL,
3940 RTE_FLOW_ERROR_TYPE_ACTION,
3942 "no fate action is found");
3944 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
3945 return rte_flow_error_set(error, EINVAL,
3946 RTE_FLOW_ERROR_TYPE_ACTION,
3948 "no fate action is found");
3954 * Internal preparation function. Allocates the DV flow size,
3955 * this size is constant.
3958 * Pointer to the flow attributes.
3960 * Pointer to the list of items.
3961 * @param[in] actions
3962 * Pointer to the list of actions.
3964 * Pointer to the error structure.
3967 * Pointer to mlx5_flow object on success,
3968 * otherwise NULL and rte_errno is set.
3970 static struct mlx5_flow *
3971 flow_dv_prepare(const struct rte_flow_attr *attr __rte_unused,
3972 const struct rte_flow_item items[] __rte_unused,
3973 const struct rte_flow_action actions[] __rte_unused,
3974 struct rte_flow_error *error)
3976 uint32_t size = sizeof(struct mlx5_flow);
3977 struct mlx5_flow *flow;
3979 flow = rte_calloc(__func__, 1, size, 0);
3981 rte_flow_error_set(error, ENOMEM,
3982 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3983 "not enough memory to create flow");
3986 flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
3992 * Sanity check for match mask and value. Similar to check_valid_spec() in
3993 * kernel driver. If unmasked bit is present in value, it returns failure.
3996 * pointer to match mask buffer.
3997 * @param match_value
3998 * pointer to match value buffer.
4001 * 0 if valid, -EINVAL otherwise.
4004 flow_dv_check_valid_spec(void *match_mask, void *match_value)
4006 uint8_t *m = match_mask;
4007 uint8_t *v = match_value;
4010 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
4013 "match_value differs from match_criteria"
4014 " %p[%u] != %p[%u]",
4015 match_value, i, match_mask, i);
4024 * Add Ethernet item to matcher and to the value.
4026 * @param[in, out] matcher
4028 * @param[in, out] key
4029 * Flow matcher value.
4031 * Flow pattern to translate.
4033 * Item is inner pattern.
4036 flow_dv_translate_item_eth(void *matcher, void *key,
4037 const struct rte_flow_item *item, int inner)
4039 const struct rte_flow_item_eth *eth_m = item->mask;
4040 const struct rte_flow_item_eth *eth_v = item->spec;
4041 const struct rte_flow_item_eth nic_mask = {
4042 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
4043 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
4044 .type = RTE_BE16(0xffff),
4056 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4058 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
4060 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4062 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
4064 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, dmac_47_16),
4065 ð_m->dst, sizeof(eth_m->dst));
4066 /* The value must be in the range of the mask. */
4067 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, dmac_47_16);
4068 for (i = 0; i < sizeof(eth_m->dst); ++i)
4069 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
4070 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, smac_47_16),
4071 ð_m->src, sizeof(eth_m->src));
4072 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, smac_47_16);
4073 /* The value must be in the range of the mask. */
4074 for (i = 0; i < sizeof(eth_m->dst); ++i)
4075 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
4076 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
4077 rte_be_to_cpu_16(eth_m->type));
4078 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, ethertype);
4079 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
4083 * Add VLAN item to matcher and to the value.
4085 * @param[in, out] dev_flow
4087 * @param[in, out] matcher
4089 * @param[in, out] key
4090 * Flow matcher value.
4092 * Flow pattern to translate.
4094 * Item is inner pattern.
4097 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
4098 void *matcher, void *key,
4099 const struct rte_flow_item *item,
4102 const struct rte_flow_item_vlan *vlan_m = item->mask;
4103 const struct rte_flow_item_vlan *vlan_v = item->spec;
4112 vlan_m = &rte_flow_item_vlan_mask;
4114 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4116 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
4118 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4120 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
4122 * This is workaround, masks are not supported,
4123 * and pre-validated.
4125 dev_flow->dv.vf_vlan.tag =
4126 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
4128 tci_m = rte_be_to_cpu_16(vlan_m->tci);
4129 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
4130 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
4131 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
4132 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_vid, tci_m);
4133 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, tci_v);
4134 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_cfi, tci_m >> 12);
4135 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_cfi, tci_v >> 12);
4136 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_prio, tci_m >> 13);
4137 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, tci_v >> 13);
4138 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
4139 rte_be_to_cpu_16(vlan_m->inner_type));
4140 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
4141 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
4145 * Add IPV4 item to matcher and to the value.
4147 * @param[in, out] matcher
4149 * @param[in, out] key
4150 * Flow matcher value.
4152 * Flow pattern to translate.
4154 * Item is inner pattern.
4156 * The group to insert the rule.
4159 flow_dv_translate_item_ipv4(void *matcher, void *key,
4160 const struct rte_flow_item *item,
4161 int inner, uint32_t group)
4163 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
4164 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
4165 const struct rte_flow_item_ipv4 nic_mask = {
4167 .src_addr = RTE_BE32(0xffffffff),
4168 .dst_addr = RTE_BE32(0xffffffff),
4169 .type_of_service = 0xff,
4170 .next_proto_id = 0xff,
4180 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4182 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
4184 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4186 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
4189 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
4191 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0x4);
4192 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 4);
4197 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
4198 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
4199 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
4200 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
4201 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
4202 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
4203 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
4204 src_ipv4_src_ipv6.ipv4_layout.ipv4);
4205 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
4206 src_ipv4_src_ipv6.ipv4_layout.ipv4);
4207 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
4208 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
4209 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
4210 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
4211 ipv4_m->hdr.type_of_service);
4212 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
4213 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
4214 ipv4_m->hdr.type_of_service >> 2);
4215 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
4216 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
4217 ipv4_m->hdr.next_proto_id);
4218 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
4219 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
4223 * Add IPV6 item to matcher and to the value.
4225 * @param[in, out] matcher
4227 * @param[in, out] key
4228 * Flow matcher value.
4230 * Flow pattern to translate.
4232 * Item is inner pattern.
4234 * The group to insert the rule.
4237 flow_dv_translate_item_ipv6(void *matcher, void *key,
4238 const struct rte_flow_item *item,
4239 int inner, uint32_t group)
4241 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
4242 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
4243 const struct rte_flow_item_ipv6 nic_mask = {
4246 "\xff\xff\xff\xff\xff\xff\xff\xff"
4247 "\xff\xff\xff\xff\xff\xff\xff\xff",
4249 "\xff\xff\xff\xff\xff\xff\xff\xff"
4250 "\xff\xff\xff\xff\xff\xff\xff\xff",
4251 .vtc_flow = RTE_BE32(0xffffffff),
4258 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
4259 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
4268 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4270 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
4272 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4274 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
4277 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
4279 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0x6);
4280 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 6);
4285 size = sizeof(ipv6_m->hdr.dst_addr);
4286 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
4287 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
4288 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
4289 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
4290 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
4291 for (i = 0; i < size; ++i)
4292 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
4293 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
4294 src_ipv4_src_ipv6.ipv6_layout.ipv6);
4295 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
4296 src_ipv4_src_ipv6.ipv6_layout.ipv6);
4297 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
4298 for (i = 0; i < size; ++i)
4299 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
4301 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
4302 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
4303 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
4304 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
4305 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
4306 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
4309 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
4311 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
4314 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
4316 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
4320 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
4322 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
4323 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
4327 * Add TCP item to matcher and to the value.
4329 * @param[in, out] matcher
4331 * @param[in, out] key
4332 * Flow matcher value.
4334 * Flow pattern to translate.
4336 * Item is inner pattern.
4339 flow_dv_translate_item_tcp(void *matcher, void *key,
4340 const struct rte_flow_item *item,
4343 const struct rte_flow_item_tcp *tcp_m = item->mask;
4344 const struct rte_flow_item_tcp *tcp_v = item->spec;
4349 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4351 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
4353 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4355 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
4357 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
4358 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
4362 tcp_m = &rte_flow_item_tcp_mask;
4363 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
4364 rte_be_to_cpu_16(tcp_m->hdr.src_port));
4365 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
4366 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
4367 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
4368 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
4369 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
4370 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
4371 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
4372 tcp_m->hdr.tcp_flags);
4373 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
4374 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
4378 * Add UDP item to matcher and to the value.
4380 * @param[in, out] matcher
4382 * @param[in, out] key
4383 * Flow matcher value.
4385 * Flow pattern to translate.
4387 * Item is inner pattern.
4390 flow_dv_translate_item_udp(void *matcher, void *key,
4391 const struct rte_flow_item *item,
4394 const struct rte_flow_item_udp *udp_m = item->mask;
4395 const struct rte_flow_item_udp *udp_v = item->spec;
4400 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4402 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
4404 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4406 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
4408 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
4409 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
4413 udp_m = &rte_flow_item_udp_mask;
4414 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
4415 rte_be_to_cpu_16(udp_m->hdr.src_port));
4416 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
4417 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
4418 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
4419 rte_be_to_cpu_16(udp_m->hdr.dst_port));
4420 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
4421 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
4425 * Add GRE optional Key item to matcher and to the value.
4427 * @param[in, out] matcher
4429 * @param[in, out] key
4430 * Flow matcher value.
4432 * Flow pattern to translate.
4434 * Item is inner pattern.
4437 flow_dv_translate_item_gre_key(void *matcher, void *key,
4438 const struct rte_flow_item *item)
4440 const rte_be32_t *key_m = item->mask;
4441 const rte_be32_t *key_v = item->spec;
4442 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
4443 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
4444 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
4449 key_m = &gre_key_default_mask;
4450 /* GRE K bit must be on and should already be validated */
4451 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
4452 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
4453 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
4454 rte_be_to_cpu_32(*key_m) >> 8);
4455 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
4456 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
4457 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
4458 rte_be_to_cpu_32(*key_m) & 0xFF);
4459 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
4460 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
4464 * Add GRE item to matcher and to the value.
4466 * @param[in, out] matcher
4468 * @param[in, out] key
4469 * Flow matcher value.
4471 * Flow pattern to translate.
4473 * Item is inner pattern.
4476 flow_dv_translate_item_gre(void *matcher, void *key,
4477 const struct rte_flow_item *item,
4480 const struct rte_flow_item_gre *gre_m = item->mask;
4481 const struct rte_flow_item_gre *gre_v = item->spec;
4484 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
4485 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
4492 uint16_t s_present:1;
4493 uint16_t k_present:1;
4494 uint16_t rsvd_bit1:1;
4495 uint16_t c_present:1;
4499 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
4502 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4504 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
4506 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4508 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
4510 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
4511 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
4515 gre_m = &rte_flow_item_gre_mask;
4516 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
4517 rte_be_to_cpu_16(gre_m->protocol));
4518 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
4519 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
4520 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
4521 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
4522 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
4523 gre_crks_rsvd0_ver_m.c_present);
4524 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
4525 gre_crks_rsvd0_ver_v.c_present &
4526 gre_crks_rsvd0_ver_m.c_present);
4527 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
4528 gre_crks_rsvd0_ver_m.k_present);
4529 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
4530 gre_crks_rsvd0_ver_v.k_present &
4531 gre_crks_rsvd0_ver_m.k_present);
4532 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
4533 gre_crks_rsvd0_ver_m.s_present);
4534 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
4535 gre_crks_rsvd0_ver_v.s_present &
4536 gre_crks_rsvd0_ver_m.s_present);
4540 * Add NVGRE item to matcher and to the value.
4542 * @param[in, out] matcher
4544 * @param[in, out] key
4545 * Flow matcher value.
4547 * Flow pattern to translate.
4549 * Item is inner pattern.
4552 flow_dv_translate_item_nvgre(void *matcher, void *key,
4553 const struct rte_flow_item *item,
4556 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
4557 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
4558 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
4559 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
4560 const char *tni_flow_id_m = (const char *)nvgre_m->tni;
4561 const char *tni_flow_id_v = (const char *)nvgre_v->tni;
4567 /* For NVGRE, GRE header fields must be set with defined values. */
4568 const struct rte_flow_item_gre gre_spec = {
4569 .c_rsvd0_ver = RTE_BE16(0x2000),
4570 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
4572 const struct rte_flow_item_gre gre_mask = {
4573 .c_rsvd0_ver = RTE_BE16(0xB000),
4574 .protocol = RTE_BE16(UINT16_MAX),
4576 const struct rte_flow_item gre_item = {
4581 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
4585 nvgre_m = &rte_flow_item_nvgre_mask;
4586 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
4587 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
4588 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
4589 memcpy(gre_key_m, tni_flow_id_m, size);
4590 for (i = 0; i < size; ++i)
4591 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
4595 * Add VXLAN item to matcher and to the value.
4597 * @param[in, out] matcher
4599 * @param[in, out] key
4600 * Flow matcher value.
4602 * Flow pattern to translate.
4604 * Item is inner pattern.
4607 flow_dv_translate_item_vxlan(void *matcher, void *key,
4608 const struct rte_flow_item *item,
4611 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
4612 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
4615 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
4616 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
4624 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4626 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
4628 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4630 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
4632 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
4633 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
4634 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
4635 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
4636 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
4641 vxlan_m = &rte_flow_item_vxlan_mask;
4642 size = sizeof(vxlan_m->vni);
4643 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
4644 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
4645 memcpy(vni_m, vxlan_m->vni, size);
4646 for (i = 0; i < size; ++i)
4647 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
4651 * Add Geneve item to matcher and to the value.
4653 * @param[in, out] matcher
4655 * @param[in, out] key
4656 * Flow matcher value.
4658 * Flow pattern to translate.
4660 * Item is inner pattern.
4664 flow_dv_translate_item_geneve(void *matcher, void *key,
4665 const struct rte_flow_item *item, int inner)
4667 const struct rte_flow_item_geneve *geneve_m = item->mask;
4668 const struct rte_flow_item_geneve *geneve_v = item->spec;
4671 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
4672 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
4681 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4683 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
4685 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
4687 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
4689 dport = MLX5_UDP_PORT_GENEVE;
4690 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
4691 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
4692 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
4697 geneve_m = &rte_flow_item_geneve_mask;
4698 size = sizeof(geneve_m->vni);
4699 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
4700 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
4701 memcpy(vni_m, geneve_m->vni, size);
4702 for (i = 0; i < size; ++i)
4703 vni_v[i] = vni_m[i] & geneve_v->vni[i];
4704 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
4705 rte_be_to_cpu_16(geneve_m->protocol));
4706 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
4707 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
4708 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
4709 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
4710 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
4711 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
4712 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
4713 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
4714 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
4715 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
4716 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
4717 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
4718 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
4722 * Add MPLS item to matcher and to the value.
4724 * @param[in, out] matcher
4726 * @param[in, out] key
4727 * Flow matcher value.
4729 * Flow pattern to translate.
4730 * @param[in] prev_layer
4731 * The protocol layer indicated in previous item.
4733 * Item is inner pattern.
4736 flow_dv_translate_item_mpls(void *matcher, void *key,
4737 const struct rte_flow_item *item,
4738 uint64_t prev_layer,
4741 const uint32_t *in_mpls_m = item->mask;
4742 const uint32_t *in_mpls_v = item->spec;
4743 uint32_t *out_mpls_m = 0;
4744 uint32_t *out_mpls_v = 0;
4745 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
4746 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
4747 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
4749 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
4750 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
4751 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
4753 switch (prev_layer) {
4754 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
4755 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
4756 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
4757 MLX5_UDP_PORT_MPLS);
4759 case MLX5_FLOW_LAYER_GRE:
4760 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
4761 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
4762 RTE_ETHER_TYPE_MPLS);
4765 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
4766 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
4773 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
4774 switch (prev_layer) {
4775 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
4777 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
4778 outer_first_mpls_over_udp);
4780 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
4781 outer_first_mpls_over_udp);
4783 case MLX5_FLOW_LAYER_GRE:
4785 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
4786 outer_first_mpls_over_gre);
4788 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
4789 outer_first_mpls_over_gre);
4792 /* Inner MPLS not over GRE is not supported. */
4795 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
4799 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
4805 if (out_mpls_m && out_mpls_v) {
4806 *out_mpls_m = *in_mpls_m;
4807 *out_mpls_v = *in_mpls_v & *in_mpls_m;
4812 * Add META item to matcher
4814 * @param[in, out] matcher
4816 * @param[in, out] key
4817 * Flow matcher value.
4819 * Flow pattern to translate.
4821 * Item is inner pattern.
4824 flow_dv_translate_item_meta(void *matcher, void *key,
4825 const struct rte_flow_item *item)
4827 const struct rte_flow_item_meta *meta_m;
4828 const struct rte_flow_item_meta *meta_v;
4830 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
4832 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
4834 meta_m = (const void *)item->mask;
4836 meta_m = &rte_flow_item_meta_mask;
4837 meta_v = (const void *)item->spec;
4839 MLX5_SET(fte_match_set_misc2, misc2_m,
4840 metadata_reg_a, meta_m->data);
4841 MLX5_SET(fte_match_set_misc2, misc2_v,
4842 metadata_reg_a, meta_v->data & meta_m->data);
4847 * Add vport metadata Reg C0 item to matcher
4849 * @param[in, out] matcher
4851 * @param[in, out] key
4852 * Flow matcher value.
4854 * Flow pattern to translate.
4857 flow_dv_translate_item_meta_vport(void *matcher, void *key,
4858 uint32_t value, uint32_t mask)
4861 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
4863 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
4865 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, mask);
4866 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, value);
4870 * Add tag item to matcher
4872 * @param[in, out] matcher
4874 * @param[in, out] key
4875 * Flow matcher value.
4877 * Flow pattern to translate.
4880 flow_dv_translate_item_tag(void *matcher, void *key,
4881 const struct rte_flow_item *item)
4884 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
4886 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
4887 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
4888 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
4889 enum modify_reg reg = tag_v->id;
4890 rte_be32_t value = tag_v->data;
4891 rte_be32_t mask = tag_m->data;
4895 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a,
4896 rte_be_to_cpu_32(mask));
4897 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a,
4898 rte_be_to_cpu_32(value));
4901 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b,
4902 rte_be_to_cpu_32(mask));
4903 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b,
4904 rte_be_to_cpu_32(value));
4907 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0,
4908 rte_be_to_cpu_32(mask));
4909 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0,
4910 rte_be_to_cpu_32(value));
4913 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1,
4914 rte_be_to_cpu_32(mask));
4915 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1,
4916 rte_be_to_cpu_32(value));
4919 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2,
4920 rte_be_to_cpu_32(mask));
4921 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2,
4922 rte_be_to_cpu_32(value));
4925 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3,
4926 rte_be_to_cpu_32(mask));
4927 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3,
4928 rte_be_to_cpu_32(value));
4931 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4,
4932 rte_be_to_cpu_32(mask));
4933 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4,
4934 rte_be_to_cpu_32(value));
4937 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5,
4938 rte_be_to_cpu_32(mask));
4939 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5,
4940 rte_be_to_cpu_32(value));
4943 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6,
4944 rte_be_to_cpu_32(mask));
4945 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6,
4946 rte_be_to_cpu_32(value));
4949 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7,
4950 rte_be_to_cpu_32(mask));
4951 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7,
4952 rte_be_to_cpu_32(value));
4958 * Add source vport match to the specified matcher.
4960 * @param[in, out] matcher
4962 * @param[in, out] key
4963 * Flow matcher value.
4965 * Source vport value to match
4970 flow_dv_translate_item_source_vport(void *matcher, void *key,
4971 int16_t port, uint16_t mask)
4973 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
4974 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
4976 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
4977 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
4981 * Translate port-id item to eswitch match on port-id.
4984 * The devich to configure through.
4985 * @param[in, out] matcher
4987 * @param[in, out] key
4988 * Flow matcher value.
4990 * Flow pattern to translate.
4993 * 0 on success, a negative errno value otherwise.
4996 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
4997 void *key, const struct rte_flow_item *item)
4999 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
5000 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
5001 struct mlx5_priv *priv;
5004 mask = pid_m ? pid_m->id : 0xffff;
5005 id = pid_v ? pid_v->id : dev->data->port_id;
5006 priv = mlx5_port_to_eswitch_info(id);
5009 /* Translate to vport field or to metadata, depending on mode. */
5010 if (priv->vport_meta_mask)
5011 flow_dv_translate_item_meta_vport(matcher, key,
5012 priv->vport_meta_tag,
5013 priv->vport_meta_mask);
5015 flow_dv_translate_item_source_vport(matcher, key,
5016 priv->vport_id, mask);
5021 * Add ICMP6 item to matcher and to the value.
5023 * @param[in, out] matcher
5025 * @param[in, out] key
5026 * Flow matcher value.
5028 * Flow pattern to translate.
5030 * Item is inner pattern.
5033 flow_dv_translate_item_icmp6(void *matcher, void *key,
5034 const struct rte_flow_item *item,
5037 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
5038 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
5041 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
5043 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
5045 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5047 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5049 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5051 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5053 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
5054 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
5058 icmp6_m = &rte_flow_item_icmp6_mask;
5059 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
5060 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
5061 icmp6_v->type & icmp6_m->type);
5062 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
5063 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
5064 icmp6_v->code & icmp6_m->code);
5068 * Add ICMP item to matcher and to the value.
5070 * @param[in, out] matcher
5072 * @param[in, out] key
5073 * Flow matcher value.
5075 * Flow pattern to translate.
5077 * Item is inner pattern.
5080 flow_dv_translate_item_icmp(void *matcher, void *key,
5081 const struct rte_flow_item *item,
5084 const struct rte_flow_item_icmp *icmp_m = item->mask;
5085 const struct rte_flow_item_icmp *icmp_v = item->spec;
5088 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
5090 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
5092 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5094 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5096 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5098 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5100 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
5101 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
5105 icmp_m = &rte_flow_item_icmp_mask;
5106 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
5107 icmp_m->hdr.icmp_type);
5108 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
5109 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
5110 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
5111 icmp_m->hdr.icmp_code);
5112 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
5113 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
5116 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
5118 #define HEADER_IS_ZERO(match_criteria, headers) \
5119 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
5120 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
5123 * Calculate flow matcher enable bitmap.
5125 * @param match_criteria
5126 * Pointer to flow matcher criteria.
5129 * Bitmap of enabled fields.
5132 flow_dv_matcher_enable(uint32_t *match_criteria)
5134 uint8_t match_criteria_enable;
5136 match_criteria_enable =
5137 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
5138 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
5139 match_criteria_enable |=
5140 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
5141 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
5142 match_criteria_enable |=
5143 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
5144 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
5145 match_criteria_enable |=
5146 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
5147 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
5148 match_criteria_enable |=
5149 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
5150 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
5151 return match_criteria_enable;
5158 * @param dev[in, out]
5159 * Pointer to rte_eth_dev structure.
5160 * @param[in] table_id
5163 * Direction of the table.
5164 * @param[in] transfer
5165 * E-Switch or NIC flow.
5167 * pointer to error structure.
5170 * Returns tables resource based on the index, NULL in case of failed.
5172 static struct mlx5_flow_tbl_resource *
5173 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
5174 uint32_t table_id, uint8_t egress,
5176 struct rte_flow_error *error)
5178 struct mlx5_priv *priv = dev->data->dev_private;
5179 struct mlx5_ibv_shared *sh = priv->sh;
5180 struct mlx5_flow_tbl_resource *tbl;
5182 #ifdef HAVE_MLX5DV_DR
5184 tbl = &sh->fdb_tbl[table_id];
5186 tbl->obj = mlx5_glue->dr_create_flow_tbl
5187 (sh->fdb_domain, table_id);
5188 } else if (egress) {
5189 tbl = &sh->tx_tbl[table_id];
5191 tbl->obj = mlx5_glue->dr_create_flow_tbl
5192 (sh->tx_domain, table_id);
5194 tbl = &sh->rx_tbl[table_id];
5196 tbl->obj = mlx5_glue->dr_create_flow_tbl
5197 (sh->rx_domain, table_id);
5200 rte_flow_error_set(error, ENOMEM,
5201 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5202 NULL, "cannot create table");
5205 rte_atomic32_inc(&tbl->refcnt);
5211 return &sh->fdb_tbl[table_id];
5213 return &sh->tx_tbl[table_id];
5215 return &sh->rx_tbl[table_id];
5220 * Release a flow table.
5223 * Table resource to be released.
5226 * Returns 0 if table was released, else return 1;
5229 flow_dv_tbl_resource_release(struct mlx5_flow_tbl_resource *tbl)
5233 if (rte_atomic32_dec_and_test(&tbl->refcnt)) {
5234 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
5242 * Register the flow matcher.
5244 * @param dev[in, out]
5245 * Pointer to rte_eth_dev structure.
5246 * @param[in, out] matcher
5247 * Pointer to flow matcher.
5248 * @parm[in, out] dev_flow
5249 * Pointer to the dev_flow.
5251 * pointer to error structure.
5254 * 0 on success otherwise -errno and errno is set.
5257 flow_dv_matcher_register(struct rte_eth_dev *dev,
5258 struct mlx5_flow_dv_matcher *matcher,
5259 struct mlx5_flow *dev_flow,
5260 struct rte_flow_error *error)
5262 struct mlx5_priv *priv = dev->data->dev_private;
5263 struct mlx5_ibv_shared *sh = priv->sh;
5264 struct mlx5_flow_dv_matcher *cache_matcher;
5265 struct mlx5dv_flow_matcher_attr dv_attr = {
5266 .type = IBV_FLOW_ATTR_NORMAL,
5267 .match_mask = (void *)&matcher->mask,
5269 struct mlx5_flow_tbl_resource *tbl = NULL;
5271 /* Lookup from cache. */
5272 LIST_FOREACH(cache_matcher, &sh->matchers, next) {
5273 if (matcher->crc == cache_matcher->crc &&
5274 matcher->priority == cache_matcher->priority &&
5275 matcher->egress == cache_matcher->egress &&
5276 matcher->group == cache_matcher->group &&
5277 matcher->transfer == cache_matcher->transfer &&
5278 !memcmp((const void *)matcher->mask.buf,
5279 (const void *)cache_matcher->mask.buf,
5280 cache_matcher->mask.size)) {
5282 "priority %hd use %s matcher %p: refcnt %d++",
5283 cache_matcher->priority,
5284 cache_matcher->egress ? "tx" : "rx",
5285 (void *)cache_matcher,
5286 rte_atomic32_read(&cache_matcher->refcnt));
5287 rte_atomic32_inc(&cache_matcher->refcnt);
5288 dev_flow->dv.matcher = cache_matcher;
5292 /* Register new matcher. */
5293 cache_matcher = rte_calloc(__func__, 1, sizeof(*cache_matcher), 0);
5295 return rte_flow_error_set(error, ENOMEM,
5296 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5297 "cannot allocate matcher memory");
5298 tbl = flow_dv_tbl_resource_get(dev, matcher->group,
5299 matcher->egress, matcher->transfer,
5302 rte_free(cache_matcher);
5303 return rte_flow_error_set(error, ENOMEM,
5304 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5305 NULL, "cannot create table");
5307 *cache_matcher = *matcher;
5308 dv_attr.match_criteria_enable =
5309 flow_dv_matcher_enable(cache_matcher->mask.buf);
5310 dv_attr.priority = matcher->priority;
5311 if (matcher->egress)
5312 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
5313 cache_matcher->matcher_object =
5314 mlx5_glue->dv_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj);
5315 if (!cache_matcher->matcher_object) {
5316 rte_free(cache_matcher);
5317 #ifdef HAVE_MLX5DV_DR
5318 flow_dv_tbl_resource_release(tbl);
5320 return rte_flow_error_set(error, ENOMEM,
5321 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5322 NULL, "cannot create matcher");
5324 rte_atomic32_inc(&cache_matcher->refcnt);
5325 LIST_INSERT_HEAD(&sh->matchers, cache_matcher, next);
5326 dev_flow->dv.matcher = cache_matcher;
5327 DRV_LOG(DEBUG, "priority %hd new %s matcher %p: refcnt %d",
5328 cache_matcher->priority,
5329 cache_matcher->egress ? "tx" : "rx", (void *)cache_matcher,
5330 rte_atomic32_read(&cache_matcher->refcnt));
5331 rte_atomic32_inc(&tbl->refcnt);
5336 * Find existing tag resource or create and register a new one.
5338 * @param dev[in, out]
5339 * Pointer to rte_eth_dev structure.
5340 * @param[in, out] resource
5341 * Pointer to tag resource.
5342 * @parm[in, out] dev_flow
5343 * Pointer to the dev_flow.
5345 * pointer to error structure.
5348 * 0 on success otherwise -errno and errno is set.
5351 flow_dv_tag_resource_register
5352 (struct rte_eth_dev *dev,
5353 struct mlx5_flow_dv_tag_resource *resource,
5354 struct mlx5_flow *dev_flow,
5355 struct rte_flow_error *error)
5357 struct mlx5_priv *priv = dev->data->dev_private;
5358 struct mlx5_ibv_shared *sh = priv->sh;
5359 struct mlx5_flow_dv_tag_resource *cache_resource;
5361 /* Lookup a matching resource from cache. */
5362 LIST_FOREACH(cache_resource, &sh->tags, next) {
5363 if (resource->tag == cache_resource->tag) {
5364 DRV_LOG(DEBUG, "tag resource %p: refcnt %d++",
5365 (void *)cache_resource,
5366 rte_atomic32_read(&cache_resource->refcnt));
5367 rte_atomic32_inc(&cache_resource->refcnt);
5368 dev_flow->flow->tag_resource = cache_resource;
5372 /* Register new resource. */
5373 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
5374 if (!cache_resource)
5375 return rte_flow_error_set(error, ENOMEM,
5376 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5377 "cannot allocate resource memory");
5378 *cache_resource = *resource;
5379 cache_resource->action = mlx5_glue->dv_create_flow_action_tag
5381 if (!cache_resource->action) {
5382 rte_free(cache_resource);
5383 return rte_flow_error_set(error, ENOMEM,
5384 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5385 NULL, "cannot create action");
5387 rte_atomic32_init(&cache_resource->refcnt);
5388 rte_atomic32_inc(&cache_resource->refcnt);
5389 LIST_INSERT_HEAD(&sh->tags, cache_resource, next);
5390 dev_flow->flow->tag_resource = cache_resource;
5391 DRV_LOG(DEBUG, "new tag resource %p: refcnt %d++",
5392 (void *)cache_resource,
5393 rte_atomic32_read(&cache_resource->refcnt));
5401 * Pointer to Ethernet device.
5403 * Pointer to mlx5_flow.
5406 * 1 while a reference on it exists, 0 when freed.
5409 flow_dv_tag_release(struct rte_eth_dev *dev,
5410 struct mlx5_flow_dv_tag_resource *tag)
5413 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
5414 dev->data->port_id, (void *)tag,
5415 rte_atomic32_read(&tag->refcnt));
5416 if (rte_atomic32_dec_and_test(&tag->refcnt)) {
5417 claim_zero(mlx5_glue->destroy_flow_action(tag->action));
5418 LIST_REMOVE(tag, next);
5419 DRV_LOG(DEBUG, "port %u tag %p: removed",
5420 dev->data->port_id, (void *)tag);
5428 * Translate port ID action to vport.
5431 * Pointer to rte_eth_dev structure.
5433 * Pointer to the port ID action.
5434 * @param[out] dst_port_id
5435 * The target port ID.
5437 * Pointer to the error structure.
5440 * 0 on success, a negative errno value otherwise and rte_errno is set.
5443 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
5444 const struct rte_flow_action *action,
5445 uint32_t *dst_port_id,
5446 struct rte_flow_error *error)
5449 struct mlx5_priv *priv;
5450 const struct rte_flow_action_port_id *conf =
5451 (const struct rte_flow_action_port_id *)action->conf;
5453 port = conf->original ? dev->data->port_id : conf->id;
5454 priv = mlx5_port_to_eswitch_info(port);
5456 return rte_flow_error_set(error, -rte_errno,
5457 RTE_FLOW_ERROR_TYPE_ACTION,
5459 "No eswitch info was found for port");
5460 if (priv->vport_meta_mask)
5461 *dst_port_id = priv->vport_meta_tag;
5463 *dst_port_id = priv->vport_id;
5468 * Add Tx queue matcher
5471 * Pointer to the dev struct.
5472 * @param[in, out] matcher
5474 * @param[in, out] key
5475 * Flow matcher value.
5477 * Flow pattern to translate.
5479 * Item is inner pattern.
5482 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
5483 void *matcher, void *key,
5484 const struct rte_flow_item *item)
5486 const struct mlx5_rte_flow_item_tx_queue *queue_m;
5487 const struct mlx5_rte_flow_item_tx_queue *queue_v;
5489 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5491 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5492 struct mlx5_txq_ctrl *txq;
5496 queue_m = (const void *)item->mask;
5499 queue_v = (const void *)item->spec;
5502 txq = mlx5_txq_get(dev, queue_v->queue);
5505 queue = txq->obj->sq->id;
5506 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
5507 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
5508 queue & queue_m->queue);
5509 mlx5_txq_release(dev, queue_v->queue);
5513 * Fill the flow with DV spec.
5516 * Pointer to rte_eth_dev structure.
5517 * @param[in, out] dev_flow
5518 * Pointer to the sub flow.
5520 * Pointer to the flow attributes.
5522 * Pointer to the list of items.
5523 * @param[in] actions
5524 * Pointer to the list of actions.
5526 * Pointer to the error structure.
5529 * 0 on success, a negative errno value otherwise and rte_errno is set.
5532 flow_dv_translate(struct rte_eth_dev *dev,
5533 struct mlx5_flow *dev_flow,
5534 const struct rte_flow_attr *attr,
5535 const struct rte_flow_item items[],
5536 const struct rte_flow_action actions[],
5537 struct rte_flow_error *error)
5539 struct mlx5_priv *priv = dev->data->dev_private;
5540 struct rte_flow *flow = dev_flow->flow;
5541 uint64_t item_flags = 0;
5542 uint64_t last_item = 0;
5543 uint64_t action_flags = 0;
5544 uint64_t priority = attr->priority;
5545 struct mlx5_flow_dv_matcher matcher = {
5547 .size = sizeof(matcher.mask.buf),
5551 bool actions_end = false;
5552 struct mlx5_flow_dv_modify_hdr_resource res = {
5553 .ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5554 MLX5DV_FLOW_TABLE_TYPE_NIC_RX
5556 union flow_dv_attr flow_attr = { .attr = 0 };
5557 struct mlx5_flow_dv_tag_resource tag_resource;
5558 uint32_t modify_action_position = UINT32_MAX;
5559 void *match_mask = matcher.mask.buf;
5560 void *match_value = dev_flow->dv.value.buf;
5561 uint8_t next_protocol = 0xff;
5562 struct rte_vlan_hdr vlan = { 0 };
5566 ret = mlx5_flow_group_to_table(attr, dev_flow->external, attr->group,
5570 flow->group = table;
5572 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5573 if (priority == MLX5_FLOW_PRIO_RSVD)
5574 priority = priv->config.flow_prio - 1;
5575 for (; !actions_end ; actions++) {
5576 const struct rte_flow_action_queue *queue;
5577 const struct rte_flow_action_rss *rss;
5578 const struct rte_flow_action *action = actions;
5579 const struct rte_flow_action_count *count = action->conf;
5580 const uint8_t *rss_key;
5581 const struct rte_flow_action_jump *jump_data;
5582 struct mlx5_flow_dv_jump_tbl_resource jump_tbl_resource;
5583 struct mlx5_flow_tbl_resource *tbl;
5584 uint32_t port_id = 0;
5585 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
5586 int action_type = actions->type;
5587 const struct rte_flow_action *found_action = NULL;
5589 switch (action_type) {
5590 case RTE_FLOW_ACTION_TYPE_VOID:
5592 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5593 if (flow_dv_translate_action_port_id(dev, action,
5596 port_id_resource.port_id = port_id;
5597 if (flow_dv_port_id_action_resource_register
5598 (dev, &port_id_resource, dev_flow, error))
5600 dev_flow->dv.actions[actions_n++] =
5601 dev_flow->dv.port_id_action->action;
5602 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5604 case RTE_FLOW_ACTION_TYPE_FLAG:
5606 mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
5607 if (!flow->tag_resource)
5608 if (flow_dv_tag_resource_register
5609 (dev, &tag_resource, dev_flow, error))
5611 dev_flow->dv.actions[actions_n++] =
5612 flow->tag_resource->action;
5613 action_flags |= MLX5_FLOW_ACTION_FLAG;
5615 case RTE_FLOW_ACTION_TYPE_MARK:
5616 tag_resource.tag = mlx5_flow_mark_set
5617 (((const struct rte_flow_action_mark *)
5618 (actions->conf))->id);
5619 if (!flow->tag_resource)
5620 if (flow_dv_tag_resource_register
5621 (dev, &tag_resource, dev_flow, error))
5623 dev_flow->dv.actions[actions_n++] =
5624 flow->tag_resource->action;
5625 action_flags |= MLX5_FLOW_ACTION_MARK;
5627 case RTE_FLOW_ACTION_TYPE_DROP:
5628 action_flags |= MLX5_FLOW_ACTION_DROP;
5630 case RTE_FLOW_ACTION_TYPE_QUEUE:
5631 queue = actions->conf;
5632 flow->rss.queue_num = 1;
5633 (*flow->queue)[0] = queue->index;
5634 action_flags |= MLX5_FLOW_ACTION_QUEUE;
5636 case RTE_FLOW_ACTION_TYPE_RSS:
5637 rss = actions->conf;
5639 memcpy((*flow->queue), rss->queue,
5640 rss->queue_num * sizeof(uint16_t));
5641 flow->rss.queue_num = rss->queue_num;
5642 /* NULL RSS key indicates default RSS key. */
5643 rss_key = !rss->key ? rss_hash_default_key : rss->key;
5644 memcpy(flow->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
5645 /* RSS type 0 indicates default RSS type ETH_RSS_IP. */
5646 flow->rss.types = !rss->types ? ETH_RSS_IP : rss->types;
5647 flow->rss.level = rss->level;
5648 action_flags |= MLX5_FLOW_ACTION_RSS;
5650 case RTE_FLOW_ACTION_TYPE_COUNT:
5651 if (!priv->config.devx) {
5652 rte_errno = ENOTSUP;
5655 flow->counter = flow_dv_counter_alloc(dev,
5659 if (flow->counter == NULL)
5661 dev_flow->dv.actions[actions_n++] =
5662 flow->counter->action;
5663 action_flags |= MLX5_FLOW_ACTION_COUNT;
5666 if (rte_errno == ENOTSUP)
5667 return rte_flow_error_set
5669 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5671 "count action not supported");
5673 return rte_flow_error_set
5675 RTE_FLOW_ERROR_TYPE_ACTION,
5677 "cannot create counter"
5680 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5681 dev_flow->dv.actions[actions_n++] =
5682 priv->sh->pop_vlan_action;
5683 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
5685 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5686 flow_dev_get_vlan_info_from_items(items, &vlan);
5687 vlan.eth_proto = rte_be_to_cpu_16
5688 ((((const struct rte_flow_action_of_push_vlan *)
5689 actions->conf)->ethertype));
5690 found_action = mlx5_flow_find_action
5692 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
5694 mlx5_update_vlan_vid_pcp(found_action, &vlan);
5695 found_action = mlx5_flow_find_action
5697 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
5699 mlx5_update_vlan_vid_pcp(found_action, &vlan);
5700 if (flow_dv_create_action_push_vlan
5701 (dev, attr, &vlan, dev_flow, error))
5703 dev_flow->dv.actions[actions_n++] =
5704 dev_flow->dv.push_vlan_res->action;
5705 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
5707 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5708 /* of_vlan_push action handled this action */
5709 assert(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN);
5711 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5712 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
5714 flow_dev_get_vlan_info_from_items(items, &vlan);
5715 mlx5_update_vlan_vid_pcp(actions, &vlan);
5716 /* If no VLAN push - this is a modify header action */
5717 if (flow_dv_convert_action_modify_vlan_vid
5718 (&res, actions, error))
5720 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
5722 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5723 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5724 if (flow_dv_create_action_l2_encap(dev, actions,
5729 dev_flow->dv.actions[actions_n++] =
5730 dev_flow->dv.encap_decap->verbs_action;
5731 action_flags |= actions->type ==
5732 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ?
5733 MLX5_FLOW_ACTION_VXLAN_ENCAP :
5734 MLX5_FLOW_ACTION_NVGRE_ENCAP;
5736 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5737 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5738 if (flow_dv_create_action_l2_decap(dev, dev_flow,
5742 dev_flow->dv.actions[actions_n++] =
5743 dev_flow->dv.encap_decap->verbs_action;
5744 action_flags |= actions->type ==
5745 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ?
5746 MLX5_FLOW_ACTION_VXLAN_DECAP :
5747 MLX5_FLOW_ACTION_NVGRE_DECAP;
5749 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5750 /* Handle encap with preceding decap. */
5751 if (action_flags & MLX5_FLOW_ACTION_RAW_DECAP) {
5752 if (flow_dv_create_action_raw_encap
5753 (dev, actions, dev_flow, attr, error))
5755 dev_flow->dv.actions[actions_n++] =
5756 dev_flow->dv.encap_decap->verbs_action;
5758 /* Handle encap without preceding decap. */
5759 if (flow_dv_create_action_l2_encap
5760 (dev, actions, dev_flow, attr->transfer,
5763 dev_flow->dv.actions[actions_n++] =
5764 dev_flow->dv.encap_decap->verbs_action;
5766 action_flags |= MLX5_FLOW_ACTION_RAW_ENCAP;
5768 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5769 /* Check if this decap is followed by encap. */
5770 for (; action->type != RTE_FLOW_ACTION_TYPE_END &&
5771 action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP;
5774 /* Handle decap only if it isn't followed by encap. */
5775 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5776 if (flow_dv_create_action_l2_decap
5777 (dev, dev_flow, attr->transfer, error))
5779 dev_flow->dv.actions[actions_n++] =
5780 dev_flow->dv.encap_decap->verbs_action;
5782 /* If decap is followed by encap, handle it at encap. */
5783 action_flags |= MLX5_FLOW_ACTION_RAW_DECAP;
5785 case RTE_FLOW_ACTION_TYPE_JUMP:
5786 jump_data = action->conf;
5787 ret = mlx5_flow_group_to_table(attr, dev_flow->external,
5788 jump_data->group, &table,
5792 tbl = flow_dv_tbl_resource_get(dev, table,
5794 attr->transfer, error);
5796 return rte_flow_error_set
5798 RTE_FLOW_ERROR_TYPE_ACTION,
5800 "cannot create jump action.");
5801 jump_tbl_resource.tbl = tbl;
5802 if (flow_dv_jump_tbl_resource_register
5803 (dev, &jump_tbl_resource, dev_flow, error)) {
5804 flow_dv_tbl_resource_release(tbl);
5805 return rte_flow_error_set
5807 RTE_FLOW_ERROR_TYPE_ACTION,
5809 "cannot create jump action.");
5811 dev_flow->dv.actions[actions_n++] =
5812 dev_flow->dv.jump->action;
5813 action_flags |= MLX5_FLOW_ACTION_JUMP;
5815 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5816 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5817 if (flow_dv_convert_action_modify_mac(&res, actions,
5820 action_flags |= actions->type ==
5821 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
5822 MLX5_FLOW_ACTION_SET_MAC_SRC :
5823 MLX5_FLOW_ACTION_SET_MAC_DST;
5825 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5826 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5827 if (flow_dv_convert_action_modify_ipv4(&res, actions,
5830 action_flags |= actions->type ==
5831 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
5832 MLX5_FLOW_ACTION_SET_IPV4_SRC :
5833 MLX5_FLOW_ACTION_SET_IPV4_DST;
5835 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5836 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5837 if (flow_dv_convert_action_modify_ipv6(&res, actions,
5840 action_flags |= actions->type ==
5841 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
5842 MLX5_FLOW_ACTION_SET_IPV6_SRC :
5843 MLX5_FLOW_ACTION_SET_IPV6_DST;
5845 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5846 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5847 if (flow_dv_convert_action_modify_tp(&res, actions,
5851 action_flags |= actions->type ==
5852 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
5853 MLX5_FLOW_ACTION_SET_TP_SRC :
5854 MLX5_FLOW_ACTION_SET_TP_DST;
5856 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5857 if (flow_dv_convert_action_modify_dec_ttl(&res, items,
5861 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
5863 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5864 if (flow_dv_convert_action_modify_ttl(&res, actions,
5868 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
5870 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5871 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5872 if (flow_dv_convert_action_modify_tcp_seq(&res, actions,
5875 action_flags |= actions->type ==
5876 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
5877 MLX5_FLOW_ACTION_INC_TCP_SEQ :
5878 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
5881 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5882 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5883 if (flow_dv_convert_action_modify_tcp_ack(&res, actions,
5886 action_flags |= actions->type ==
5887 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
5888 MLX5_FLOW_ACTION_INC_TCP_ACK :
5889 MLX5_FLOW_ACTION_DEC_TCP_ACK;
5891 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
5892 if (flow_dv_convert_action_set_reg(&res, actions,
5895 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
5897 case RTE_FLOW_ACTION_TYPE_END:
5899 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS) {
5900 /* create modify action if needed. */
5901 if (flow_dv_modify_hdr_resource_register
5906 dev_flow->dv.actions[modify_action_position] =
5907 dev_flow->dv.modify_hdr->verbs_action;
5913 if ((action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS) &&
5914 modify_action_position == UINT32_MAX)
5915 modify_action_position = actions_n++;
5917 dev_flow->dv.actions_n = actions_n;
5918 dev_flow->actions = action_flags;
5919 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5920 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
5921 int item_type = items->type;
5923 switch (item_type) {
5924 case RTE_FLOW_ITEM_TYPE_PORT_ID:
5925 flow_dv_translate_item_port_id(dev, match_mask,
5926 match_value, items);
5927 last_item = MLX5_FLOW_ITEM_PORT_ID;
5929 case RTE_FLOW_ITEM_TYPE_ETH:
5930 flow_dv_translate_item_eth(match_mask, match_value,
5932 matcher.priority = MLX5_PRIORITY_MAP_L2;
5933 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
5934 MLX5_FLOW_LAYER_OUTER_L2;
5936 case RTE_FLOW_ITEM_TYPE_VLAN:
5937 flow_dv_translate_item_vlan(dev_flow,
5938 match_mask, match_value,
5940 matcher.priority = MLX5_PRIORITY_MAP_L2;
5941 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
5942 MLX5_FLOW_LAYER_INNER_VLAN) :
5943 (MLX5_FLOW_LAYER_OUTER_L2 |
5944 MLX5_FLOW_LAYER_OUTER_VLAN);
5946 case RTE_FLOW_ITEM_TYPE_IPV4:
5947 mlx5_flow_tunnel_ip_check(items, next_protocol,
5948 &item_flags, &tunnel);
5949 flow_dv_translate_item_ipv4(match_mask, match_value,
5950 items, tunnel, flow->group);
5951 matcher.priority = MLX5_PRIORITY_MAP_L3;
5952 dev_flow->dv.hash_fields |=
5953 mlx5_flow_hashfields_adjust
5955 MLX5_IPV4_LAYER_TYPES,
5956 MLX5_IPV4_IBV_RX_HASH);
5957 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5958 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5959 if (items->mask != NULL &&
5960 ((const struct rte_flow_item_ipv4 *)
5961 items->mask)->hdr.next_proto_id) {
5963 ((const struct rte_flow_item_ipv4 *)
5964 (items->spec))->hdr.next_proto_id;
5966 ((const struct rte_flow_item_ipv4 *)
5967 (items->mask))->hdr.next_proto_id;
5969 /* Reset for inner layer. */
5970 next_protocol = 0xff;
5973 case RTE_FLOW_ITEM_TYPE_IPV6:
5974 mlx5_flow_tunnel_ip_check(items, next_protocol,
5975 &item_flags, &tunnel);
5976 flow_dv_translate_item_ipv6(match_mask, match_value,
5977 items, tunnel, flow->group);
5978 matcher.priority = MLX5_PRIORITY_MAP_L3;
5979 dev_flow->dv.hash_fields |=
5980 mlx5_flow_hashfields_adjust
5982 MLX5_IPV6_LAYER_TYPES,
5983 MLX5_IPV6_IBV_RX_HASH);
5984 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5985 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5986 if (items->mask != NULL &&
5987 ((const struct rte_flow_item_ipv6 *)
5988 items->mask)->hdr.proto) {
5990 ((const struct rte_flow_item_ipv6 *)
5991 items->spec)->hdr.proto;
5993 ((const struct rte_flow_item_ipv6 *)
5994 items->mask)->hdr.proto;
5996 /* Reset for inner layer. */
5997 next_protocol = 0xff;
6000 case RTE_FLOW_ITEM_TYPE_TCP:
6001 flow_dv_translate_item_tcp(match_mask, match_value,
6003 matcher.priority = MLX5_PRIORITY_MAP_L4;
6004 dev_flow->dv.hash_fields |=
6005 mlx5_flow_hashfields_adjust
6006 (dev_flow, tunnel, ETH_RSS_TCP,
6007 IBV_RX_HASH_SRC_PORT_TCP |
6008 IBV_RX_HASH_DST_PORT_TCP);
6009 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
6010 MLX5_FLOW_LAYER_OUTER_L4_TCP;
6012 case RTE_FLOW_ITEM_TYPE_UDP:
6013 flow_dv_translate_item_udp(match_mask, match_value,
6015 matcher.priority = MLX5_PRIORITY_MAP_L4;
6016 dev_flow->dv.hash_fields |=
6017 mlx5_flow_hashfields_adjust
6018 (dev_flow, tunnel, ETH_RSS_UDP,
6019 IBV_RX_HASH_SRC_PORT_UDP |
6020 IBV_RX_HASH_DST_PORT_UDP);
6021 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
6022 MLX5_FLOW_LAYER_OUTER_L4_UDP;
6024 case RTE_FLOW_ITEM_TYPE_GRE:
6025 flow_dv_translate_item_gre(match_mask, match_value,
6027 last_item = MLX5_FLOW_LAYER_GRE;
6029 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6030 flow_dv_translate_item_gre_key(match_mask,
6031 match_value, items);
6032 last_item = MLX5_FLOW_LAYER_GRE_KEY;
6034 case RTE_FLOW_ITEM_TYPE_NVGRE:
6035 flow_dv_translate_item_nvgre(match_mask, match_value,
6037 last_item = MLX5_FLOW_LAYER_GRE;
6039 case RTE_FLOW_ITEM_TYPE_VXLAN:
6040 flow_dv_translate_item_vxlan(match_mask, match_value,
6042 last_item = MLX5_FLOW_LAYER_VXLAN;
6044 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6045 flow_dv_translate_item_vxlan(match_mask, match_value,
6047 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
6049 case RTE_FLOW_ITEM_TYPE_GENEVE:
6050 flow_dv_translate_item_geneve(match_mask, match_value,
6052 last_item = MLX5_FLOW_LAYER_GENEVE;
6054 case RTE_FLOW_ITEM_TYPE_MPLS:
6055 flow_dv_translate_item_mpls(match_mask, match_value,
6056 items, last_item, tunnel);
6057 last_item = MLX5_FLOW_LAYER_MPLS;
6059 case RTE_FLOW_ITEM_TYPE_META:
6060 flow_dv_translate_item_meta(match_mask, match_value,
6062 last_item = MLX5_FLOW_ITEM_METADATA;
6064 case RTE_FLOW_ITEM_TYPE_ICMP:
6065 flow_dv_translate_item_icmp(match_mask, match_value,
6067 last_item = MLX5_FLOW_LAYER_ICMP;
6069 case RTE_FLOW_ITEM_TYPE_ICMP6:
6070 flow_dv_translate_item_icmp6(match_mask, match_value,
6072 last_item = MLX5_FLOW_LAYER_ICMP6;
6074 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
6075 flow_dv_translate_item_tag(match_mask, match_value,
6077 last_item = MLX5_FLOW_ITEM_TAG;
6079 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
6080 flow_dv_translate_item_tx_queue(dev, match_mask,
6083 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
6088 item_flags |= last_item;
6091 * In case of ingress traffic when E-Switch mode is enabled,
6092 * we have two cases where we need to set the source port manually.
6093 * The first one, is in case of Nic steering rule, and the second is
6094 * E-Switch rule where no port_id item was found. In both cases
6095 * the source port is set according the current port in use.
6097 if ((attr->ingress && !(item_flags & MLX5_FLOW_ITEM_PORT_ID)) &&
6098 (priv->representor || priv->master)) {
6099 if (flow_dv_translate_item_port_id(dev, match_mask,
6103 assert(!flow_dv_check_valid_spec(matcher.mask.buf,
6104 dev_flow->dv.value.buf));
6105 dev_flow->layers = item_flags;
6106 /* Register matcher. */
6107 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
6109 matcher.priority = mlx5_flow_adjust_priority(dev, priority,
6111 matcher.egress = attr->egress;
6112 matcher.group = flow->group;
6113 matcher.transfer = attr->transfer;
6114 if (flow_dv_matcher_register(dev, &matcher, dev_flow, error))
6120 * Apply the flow to the NIC.
6123 * Pointer to the Ethernet device structure.
6124 * @param[in, out] flow
6125 * Pointer to flow structure.
6127 * Pointer to error structure.
6130 * 0 on success, a negative errno value otherwise and rte_errno is set.
6133 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
6134 struct rte_flow_error *error)
6136 struct mlx5_flow_dv *dv;
6137 struct mlx5_flow *dev_flow;
6138 struct mlx5_priv *priv = dev->data->dev_private;
6142 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
6145 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP) {
6146 if (flow->transfer) {
6147 dv->actions[n++] = priv->sh->esw_drop_action;
6149 dv->hrxq = mlx5_hrxq_drop_new(dev);
6153 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6155 "cannot get drop hash queue");
6158 dv->actions[n++] = dv->hrxq->action;
6160 } else if (dev_flow->actions &
6161 (MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)) {
6162 struct mlx5_hrxq *hrxq;
6164 hrxq = mlx5_hrxq_get(dev, flow->key,
6165 MLX5_RSS_HASH_KEY_LEN,
6168 flow->rss.queue_num);
6170 hrxq = mlx5_hrxq_new
6171 (dev, flow->key, MLX5_RSS_HASH_KEY_LEN,
6172 dv->hash_fields, (*flow->queue),
6173 flow->rss.queue_num,
6174 !!(dev_flow->layers &
6175 MLX5_FLOW_LAYER_TUNNEL));
6180 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6181 "cannot get hash queue");
6185 dv->actions[n++] = dv->hrxq->action;
6188 mlx5_glue->dv_create_flow(dv->matcher->matcher_object,
6189 (void *)&dv->value, n,
6192 rte_flow_error_set(error, errno,
6193 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6195 "hardware refuses to create flow");
6198 if (priv->vmwa_context &&
6199 dev_flow->dv.vf_vlan.tag &&
6200 !dev_flow->dv.vf_vlan.created) {
6202 * The rule contains the VLAN pattern.
6203 * For VF we are going to create VLAN
6204 * interface to make hypervisor set correct
6205 * e-Switch vport context.
6207 mlx5_vlan_vmwa_acquire(dev, &dev_flow->dv.vf_vlan);
6212 err = rte_errno; /* Save rte_errno before cleanup. */
6213 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
6214 struct mlx5_flow_dv *dv = &dev_flow->dv;
6216 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP)
6217 mlx5_hrxq_drop_release(dev);
6219 mlx5_hrxq_release(dev, dv->hrxq);
6222 if (dev_flow->dv.vf_vlan.tag &&
6223 dev_flow->dv.vf_vlan.created)
6224 mlx5_vlan_vmwa_release(dev, &dev_flow->dv.vf_vlan);
6226 rte_errno = err; /* Restore rte_errno. */
6231 * Release the flow matcher.
6234 * Pointer to Ethernet device.
6236 * Pointer to mlx5_flow.
6239 * 1 while a reference on it exists, 0 when freed.
6242 flow_dv_matcher_release(struct rte_eth_dev *dev,
6243 struct mlx5_flow *flow)
6245 struct mlx5_flow_dv_matcher *matcher = flow->dv.matcher;
6246 struct mlx5_priv *priv = dev->data->dev_private;
6247 struct mlx5_ibv_shared *sh = priv->sh;
6248 struct mlx5_flow_tbl_resource *tbl;
6250 assert(matcher->matcher_object);
6251 DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
6252 dev->data->port_id, (void *)matcher,
6253 rte_atomic32_read(&matcher->refcnt));
6254 if (rte_atomic32_dec_and_test(&matcher->refcnt)) {
6255 claim_zero(mlx5_glue->dv_destroy_flow_matcher
6256 (matcher->matcher_object));
6257 LIST_REMOVE(matcher, next);
6258 if (matcher->egress)
6259 tbl = &sh->tx_tbl[matcher->group];
6261 tbl = &sh->rx_tbl[matcher->group];
6262 flow_dv_tbl_resource_release(tbl);
6264 DRV_LOG(DEBUG, "port %u matcher %p: removed",
6265 dev->data->port_id, (void *)matcher);
6272 * Release an encap/decap resource.
6275 * Pointer to mlx5_flow.
6278 * 1 while a reference on it exists, 0 when freed.
6281 flow_dv_encap_decap_resource_release(struct mlx5_flow *flow)
6283 struct mlx5_flow_dv_encap_decap_resource *cache_resource =
6284 flow->dv.encap_decap;
6286 assert(cache_resource->verbs_action);
6287 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d--",
6288 (void *)cache_resource,
6289 rte_atomic32_read(&cache_resource->refcnt));
6290 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
6291 claim_zero(mlx5_glue->destroy_flow_action
6292 (cache_resource->verbs_action));
6293 LIST_REMOVE(cache_resource, next);
6294 rte_free(cache_resource);
6295 DRV_LOG(DEBUG, "encap/decap resource %p: removed",
6296 (void *)cache_resource);
6303 * Release an jump to table action resource.
6306 * Pointer to mlx5_flow.
6309 * 1 while a reference on it exists, 0 when freed.
6312 flow_dv_jump_tbl_resource_release(struct mlx5_flow *flow)
6314 struct mlx5_flow_dv_jump_tbl_resource *cache_resource =
6317 assert(cache_resource->action);
6318 DRV_LOG(DEBUG, "jump table resource %p: refcnt %d--",
6319 (void *)cache_resource,
6320 rte_atomic32_read(&cache_resource->refcnt));
6321 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
6322 claim_zero(mlx5_glue->destroy_flow_action
6323 (cache_resource->action));
6324 LIST_REMOVE(cache_resource, next);
6325 flow_dv_tbl_resource_release(cache_resource->tbl);
6326 rte_free(cache_resource);
6327 DRV_LOG(DEBUG, "jump table resource %p: removed",
6328 (void *)cache_resource);
6335 * Release a modify-header resource.
6338 * Pointer to mlx5_flow.
6341 * 1 while a reference on it exists, 0 when freed.
6344 flow_dv_modify_hdr_resource_release(struct mlx5_flow *flow)
6346 struct mlx5_flow_dv_modify_hdr_resource *cache_resource =
6347 flow->dv.modify_hdr;
6349 assert(cache_resource->verbs_action);
6350 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d--",
6351 (void *)cache_resource,
6352 rte_atomic32_read(&cache_resource->refcnt));
6353 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
6354 claim_zero(mlx5_glue->destroy_flow_action
6355 (cache_resource->verbs_action));
6356 LIST_REMOVE(cache_resource, next);
6357 rte_free(cache_resource);
6358 DRV_LOG(DEBUG, "modify-header resource %p: removed",
6359 (void *)cache_resource);
6366 * Release port ID action resource.
6369 * Pointer to mlx5_flow.
6372 * 1 while a reference on it exists, 0 when freed.
6375 flow_dv_port_id_action_resource_release(struct mlx5_flow *flow)
6377 struct mlx5_flow_dv_port_id_action_resource *cache_resource =
6378 flow->dv.port_id_action;
6380 assert(cache_resource->action);
6381 DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--",
6382 (void *)cache_resource,
6383 rte_atomic32_read(&cache_resource->refcnt));
6384 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
6385 claim_zero(mlx5_glue->destroy_flow_action
6386 (cache_resource->action));
6387 LIST_REMOVE(cache_resource, next);
6388 rte_free(cache_resource);
6389 DRV_LOG(DEBUG, "port id action resource %p: removed",
6390 (void *)cache_resource);
6397 * Release push vlan action resource.
6400 * Pointer to mlx5_flow.
6403 * 1 while a reference on it exists, 0 when freed.
6406 flow_dv_push_vlan_action_resource_release(struct mlx5_flow *flow)
6408 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource =
6409 flow->dv.push_vlan_res;
6411 assert(cache_resource->action);
6412 DRV_LOG(DEBUG, "push VLAN action resource %p: refcnt %d--",
6413 (void *)cache_resource,
6414 rte_atomic32_read(&cache_resource->refcnt));
6415 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
6416 claim_zero(mlx5_glue->destroy_flow_action
6417 (cache_resource->action));
6418 LIST_REMOVE(cache_resource, next);
6419 rte_free(cache_resource);
6420 DRV_LOG(DEBUG, "push vlan action resource %p: removed",
6421 (void *)cache_resource);
6428 * Remove the flow from the NIC but keeps it in memory.
6431 * Pointer to Ethernet device.
6432 * @param[in, out] flow
6433 * Pointer to flow structure.
6436 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
6438 struct mlx5_flow_dv *dv;
6439 struct mlx5_flow *dev_flow;
6443 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
6446 claim_zero(mlx5_glue->dv_destroy_flow(dv->flow));
6450 if (dev_flow->actions & MLX5_FLOW_ACTION_DROP)
6451 mlx5_hrxq_drop_release(dev);
6453 mlx5_hrxq_release(dev, dv->hrxq);
6456 if (dev_flow->dv.vf_vlan.tag &&
6457 dev_flow->dv.vf_vlan.created)
6458 mlx5_vlan_vmwa_release(dev, &dev_flow->dv.vf_vlan);
6463 * Remove the flow from the NIC and the memory.
6466 * Pointer to the Ethernet device structure.
6467 * @param[in, out] flow
6468 * Pointer to flow structure.
6471 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
6473 struct mlx5_flow *dev_flow;
6477 flow_dv_remove(dev, flow);
6478 if (flow->counter) {
6479 flow_dv_counter_release(dev, flow->counter);
6480 flow->counter = NULL;
6482 if (flow->tag_resource) {
6483 flow_dv_tag_release(dev, flow->tag_resource);
6484 flow->tag_resource = NULL;
6486 while (!LIST_EMPTY(&flow->dev_flows)) {
6487 dev_flow = LIST_FIRST(&flow->dev_flows);
6488 LIST_REMOVE(dev_flow, next);
6489 if (dev_flow->dv.matcher)
6490 flow_dv_matcher_release(dev, dev_flow);
6491 if (dev_flow->dv.encap_decap)
6492 flow_dv_encap_decap_resource_release(dev_flow);
6493 if (dev_flow->dv.modify_hdr)
6494 flow_dv_modify_hdr_resource_release(dev_flow);
6495 if (dev_flow->dv.jump)
6496 flow_dv_jump_tbl_resource_release(dev_flow);
6497 if (dev_flow->dv.port_id_action)
6498 flow_dv_port_id_action_resource_release(dev_flow);
6499 if (dev_flow->dv.push_vlan_res)
6500 flow_dv_push_vlan_action_resource_release(dev_flow);
6506 * Query a dv flow rule for its statistics via devx.
6509 * Pointer to Ethernet device.
6511 * Pointer to the sub flow.
6513 * data retrieved by the query.
6515 * Perform verbose error reporting if not NULL.
6518 * 0 on success, a negative errno value otherwise and rte_errno is set.
6521 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
6522 void *data, struct rte_flow_error *error)
6524 struct mlx5_priv *priv = dev->data->dev_private;
6525 struct rte_flow_query_count *qc = data;
6527 if (!priv->config.devx)
6528 return rte_flow_error_set(error, ENOTSUP,
6529 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6531 "counters are not supported");
6532 if (flow->counter) {
6533 uint64_t pkts, bytes;
6534 int err = _flow_dv_query_count(dev, flow->counter, &pkts,
6538 return rte_flow_error_set(error, -err,
6539 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6540 NULL, "cannot read counters");
6543 qc->hits = pkts - flow->counter->hits;
6544 qc->bytes = bytes - flow->counter->bytes;
6546 flow->counter->hits = pkts;
6547 flow->counter->bytes = bytes;
6551 return rte_flow_error_set(error, EINVAL,
6552 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6554 "counters are not available");
6560 * @see rte_flow_query()
6564 flow_dv_query(struct rte_eth_dev *dev,
6565 struct rte_flow *flow __rte_unused,
6566 const struct rte_flow_action *actions __rte_unused,
6567 void *data __rte_unused,
6568 struct rte_flow_error *error __rte_unused)
6572 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
6573 switch (actions->type) {
6574 case RTE_FLOW_ACTION_TYPE_VOID:
6576 case RTE_FLOW_ACTION_TYPE_COUNT:
6577 ret = flow_dv_query_count(dev, flow, data, error);
6580 return rte_flow_error_set(error, ENOTSUP,
6581 RTE_FLOW_ERROR_TYPE_ACTION,
6583 "action not supported");
6590 * Mutex-protected thunk to flow_dv_translate().
6593 flow_d_translate(struct rte_eth_dev *dev,
6594 struct mlx5_flow *dev_flow,
6595 const struct rte_flow_attr *attr,
6596 const struct rte_flow_item items[],
6597 const struct rte_flow_action actions[],
6598 struct rte_flow_error *error)
6602 flow_d_shared_lock(dev);
6603 ret = flow_dv_translate(dev, dev_flow, attr, items, actions, error);
6604 flow_d_shared_unlock(dev);
6609 * Mutex-protected thunk to flow_dv_apply().
6612 flow_d_apply(struct rte_eth_dev *dev,
6613 struct rte_flow *flow,
6614 struct rte_flow_error *error)
6618 flow_d_shared_lock(dev);
6619 ret = flow_dv_apply(dev, flow, error);
6620 flow_d_shared_unlock(dev);
6625 * Mutex-protected thunk to flow_dv_remove().
6628 flow_d_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
6630 flow_d_shared_lock(dev);
6631 flow_dv_remove(dev, flow);
6632 flow_d_shared_unlock(dev);
6636 * Mutex-protected thunk to flow_dv_destroy().
6639 flow_d_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
6641 flow_d_shared_lock(dev);
6642 flow_dv_destroy(dev, flow);
6643 flow_d_shared_unlock(dev);
6646 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
6647 .validate = flow_dv_validate,
6648 .prepare = flow_dv_prepare,
6649 .translate = flow_d_translate,
6650 .apply = flow_d_apply,
6651 .remove = flow_d_remove,
6652 .destroy = flow_d_destroy,
6653 .query = flow_dv_query,
6656 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */