1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd
5 #include <netinet/in.h>
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_eth_ctrl.h>
24 #include <rte_ethdev_driver.h>
26 #include <rte_flow_driver.h>
27 #include <rte_malloc.h>
31 #include "mlx5_defs.h"
33 #include "mlx5_glue.h"
34 #include "mlx5_flow.h"
36 #define VERBS_SPEC_INNER(item_flags) \
37 (!!((item_flags) & MLX5_FLOW_LAYER_TUNNEL) ? IBV_FLOW_SPEC_INNER : 0)
40 * Create Verbs flow counter with Verbs library.
43 * Pointer to the Ethernet device structure.
44 * @param[in, out] counter
45 * mlx5 flow counter object, contains the counter id,
46 * handle of created Verbs flow counter is returned
47 * in cs field (if counters are supported).
50 * 0 On success else a negative errno value is returned
51 * and rte_errno is set.
54 flow_verbs_counter_create(struct rte_eth_dev *dev,
55 struct mlx5_flow_counter *counter)
57 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42)
58 struct priv *priv = dev->data->dev_private;
59 struct ibv_counter_set_init_attr init = {
60 .counter_set_id = counter->id};
62 counter->cs = mlx5_glue->create_counter_set(priv->ctx, &init);
68 #elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
69 struct priv *priv = dev->data->dev_private;
70 struct ibv_counters_init_attr init = {0};
71 struct ibv_counter_attach_attr attach;
74 memset(&attach, 0, sizeof(attach));
75 counter->cs = mlx5_glue->create_counters(priv->ctx, &init);
80 attach.counter_desc = IBV_COUNTER_PACKETS;
82 ret = mlx5_glue->attach_counters(counter->cs, &attach, NULL);
84 attach.counter_desc = IBV_COUNTER_BYTES;
86 ret = mlx5_glue->attach_counters
87 (counter->cs, &attach, NULL);
90 claim_zero(mlx5_glue->destroy_counters(counter->cs));
105 * Get a flow counter.
108 * Pointer to the Ethernet device structure.
110 * Indicate if this counter is shared with other flows.
112 * Counter identifier.
115 * A pointer to the counter, NULL otherwise and rte_errno is set.
117 static struct mlx5_flow_counter *
118 flow_verbs_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id)
120 struct priv *priv = dev->data->dev_private;
121 struct mlx5_flow_counter *cnt;
124 LIST_FOREACH(cnt, &priv->flow_counters, next) {
125 if (!cnt->shared || cnt->shared != shared)
132 cnt = rte_calloc(__func__, 1, sizeof(*cnt), 0);
138 cnt->shared = shared;
142 /* Create counter with Verbs. */
143 ret = flow_verbs_counter_create(dev, cnt);
145 LIST_INSERT_HEAD(&priv->flow_counters, cnt, next);
148 /* Some error occurred in Verbs library. */
155 * Release a flow counter.
158 * Pointer to the counter handler.
161 flow_verbs_counter_release(struct mlx5_flow_counter *counter)
163 if (--counter->ref_cnt == 0) {
164 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42)
165 claim_zero(mlx5_glue->destroy_counter_set(counter->cs));
166 #elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
167 claim_zero(mlx5_glue->destroy_counters(counter->cs));
169 LIST_REMOVE(counter, next);
175 * Query a flow counter via Verbs library call.
177 * @see rte_flow_query()
181 flow_verbs_counter_query(struct rte_eth_dev *dev __rte_unused,
182 struct rte_flow *flow, void *data,
183 struct rte_flow_error *error)
185 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \
186 defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
187 if (flow->actions & MLX5_FLOW_ACTION_COUNT) {
188 struct rte_flow_query_count *qc = data;
189 uint64_t counters[2] = {0, 0};
190 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42)
191 struct ibv_query_counter_set_attr query_cs_attr = {
192 .cs = flow->counter->cs,
193 .query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
195 struct ibv_counter_set_data query_out = {
197 .outlen = 2 * sizeof(uint64_t),
199 int err = mlx5_glue->query_counter_set(&query_cs_attr,
201 #elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
202 int err = mlx5_glue->query_counters
203 (flow->counter->cs, counters,
205 IBV_READ_COUNTERS_ATTR_PREFER_CACHED);
208 return rte_flow_error_set
210 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
212 "cannot read counter");
215 qc->hits = counters[0] - flow->counter->hits;
216 qc->bytes = counters[1] - flow->counter->bytes;
218 flow->counter->hits = counters[0];
219 flow->counter->bytes = counters[1];
223 return rte_flow_error_set(error, EINVAL,
224 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
226 "flow does not have counter");
230 return rte_flow_error_set(error, ENOTSUP,
231 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
233 "counters are not available");
238 * Add a verbs item specification into @p verbs.
241 * Pointer to verbs structure.
243 * Create specification.
245 * Size in bytes of the specification to copy.
248 flow_verbs_spec_add(struct mlx5_flow_verbs *verbs, void *src, unsigned int size)
254 assert(verbs->specs);
255 dst = (void *)(verbs->specs + verbs->size);
256 memcpy(dst, src, size);
257 ++verbs->attr->num_of_specs;
262 * Convert the @p item into a Verbs specification. This function assumes that
263 * the input is valid and that there is space to insert the requested item
266 * @param[in, out] dev_flow
267 * Pointer to dev_flow structure.
269 * Item specification.
270 * @param[in] item_flags
274 flow_verbs_translate_item_eth(struct mlx5_flow *dev_flow,
275 const struct rte_flow_item *item,
278 const struct rte_flow_item_eth *spec = item->spec;
279 const struct rte_flow_item_eth *mask = item->mask;
280 const unsigned int size = sizeof(struct ibv_flow_spec_eth);
281 struct ibv_flow_spec_eth eth = {
282 .type = IBV_FLOW_SPEC_ETH | VERBS_SPEC_INNER(item_flags),
287 mask = &rte_flow_item_eth_mask;
291 memcpy(ð.val.dst_mac, spec->dst.addr_bytes, ETHER_ADDR_LEN);
292 memcpy(ð.val.src_mac, spec->src.addr_bytes, ETHER_ADDR_LEN);
293 eth.val.ether_type = spec->type;
294 memcpy(ð.mask.dst_mac, mask->dst.addr_bytes, ETHER_ADDR_LEN);
295 memcpy(ð.mask.src_mac, mask->src.addr_bytes, ETHER_ADDR_LEN);
296 eth.mask.ether_type = mask->type;
297 /* Remove unwanted bits from values. */
298 for (i = 0; i < ETHER_ADDR_LEN; ++i) {
299 eth.val.dst_mac[i] &= eth.mask.dst_mac[i];
300 eth.val.src_mac[i] &= eth.mask.src_mac[i];
302 eth.val.ether_type &= eth.mask.ether_type;
304 flow_verbs_spec_add(&dev_flow->verbs, ð, size);
308 * Update the VLAN tag in the Verbs Ethernet specification.
309 * This function assumes that the input is valid and there is space to add
310 * the requested item.
312 * @param[in, out] attr
313 * Pointer to Verbs attributes structure.
315 * Verbs structure containing the VLAN information to copy.
318 flow_verbs_item_vlan_update(struct ibv_flow_attr *attr,
319 struct ibv_flow_spec_eth *eth)
322 const enum ibv_flow_spec_type search = eth->type;
323 struct ibv_spec_header *hdr = (struct ibv_spec_header *)
324 ((uint8_t *)attr + sizeof(struct ibv_flow_attr));
326 for (i = 0; i != attr->num_of_specs; ++i) {
327 if (hdr->type == search) {
328 struct ibv_flow_spec_eth *e =
329 (struct ibv_flow_spec_eth *)hdr;
331 e->val.vlan_tag = eth->val.vlan_tag;
332 e->mask.vlan_tag = eth->mask.vlan_tag;
333 e->val.ether_type = eth->val.ether_type;
334 e->mask.ether_type = eth->mask.ether_type;
337 hdr = (struct ibv_spec_header *)((uint8_t *)hdr + hdr->size);
342 * Convert the @p item into a Verbs specification. This function assumes that
343 * the input is valid and that there is space to insert the requested item
346 * @param[in, out] dev_flow
347 * Pointer to dev_flow structure.
349 * Item specification.
350 * @param[in] item_flags
354 flow_verbs_translate_item_vlan(struct mlx5_flow *dev_flow,
355 const struct rte_flow_item *item,
358 const struct rte_flow_item_vlan *spec = item->spec;
359 const struct rte_flow_item_vlan *mask = item->mask;
360 unsigned int size = sizeof(struct ibv_flow_spec_eth);
361 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
362 struct ibv_flow_spec_eth eth = {
363 .type = IBV_FLOW_SPEC_ETH | VERBS_SPEC_INNER(item_flags),
366 const uint32_t l2m = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
367 MLX5_FLOW_LAYER_OUTER_L2;
370 mask = &rte_flow_item_vlan_mask;
372 eth.val.vlan_tag = spec->tci;
373 eth.mask.vlan_tag = mask->tci;
374 eth.val.vlan_tag &= eth.mask.vlan_tag;
375 eth.val.ether_type = spec->inner_type;
376 eth.mask.ether_type = mask->inner_type;
377 eth.val.ether_type &= eth.mask.ether_type;
379 if (!(item_flags & l2m))
380 flow_verbs_spec_add(&dev_flow->verbs, ð, size);
382 flow_verbs_item_vlan_update(dev_flow->verbs.attr, ð);
386 * Convert the @p item into a Verbs specification. This function assumes that
387 * the input is valid and that there is space to insert the requested item
390 * @param[in, out] dev_flow
391 * Pointer to dev_flow structure.
393 * Item specification.
394 * @param[in] item_flags
398 flow_verbs_translate_item_ipv4(struct mlx5_flow *dev_flow,
399 const struct rte_flow_item *item,
402 const struct rte_flow_item_ipv4 *spec = item->spec;
403 const struct rte_flow_item_ipv4 *mask = item->mask;
404 unsigned int size = sizeof(struct ibv_flow_spec_ipv4_ext);
405 struct ibv_flow_spec_ipv4_ext ipv4 = {
406 .type = IBV_FLOW_SPEC_IPV4_EXT | VERBS_SPEC_INNER(item_flags),
411 mask = &rte_flow_item_ipv4_mask;
413 ipv4.val = (struct ibv_flow_ipv4_ext_filter){
414 .src_ip = spec->hdr.src_addr,
415 .dst_ip = spec->hdr.dst_addr,
416 .proto = spec->hdr.next_proto_id,
417 .tos = spec->hdr.type_of_service,
419 ipv4.mask = (struct ibv_flow_ipv4_ext_filter){
420 .src_ip = mask->hdr.src_addr,
421 .dst_ip = mask->hdr.dst_addr,
422 .proto = mask->hdr.next_proto_id,
423 .tos = mask->hdr.type_of_service,
425 /* Remove unwanted bits from values. */
426 ipv4.val.src_ip &= ipv4.mask.src_ip;
427 ipv4.val.dst_ip &= ipv4.mask.dst_ip;
428 ipv4.val.proto &= ipv4.mask.proto;
429 ipv4.val.tos &= ipv4.mask.tos;
431 flow_verbs_spec_add(&dev_flow->verbs, &ipv4, size);
435 * Convert the @p item into a Verbs specification. This function assumes that
436 * the input is valid and that there is space to insert the requested item
439 * @param[in, out] dev_flow
440 * Pointer to dev_flow structure.
442 * Item specification.
443 * @param[in] item_flags
447 flow_verbs_translate_item_ipv6(struct mlx5_flow *dev_flow,
448 const struct rte_flow_item *item,
451 const struct rte_flow_item_ipv6 *spec = item->spec;
452 const struct rte_flow_item_ipv6 *mask = item->mask;
453 unsigned int size = sizeof(struct ibv_flow_spec_ipv6);
454 struct ibv_flow_spec_ipv6 ipv6 = {
455 .type = IBV_FLOW_SPEC_IPV6 | VERBS_SPEC_INNER(item_flags),
460 mask = &rte_flow_item_ipv6_mask;
463 uint32_t vtc_flow_val;
464 uint32_t vtc_flow_mask;
466 memcpy(&ipv6.val.src_ip, spec->hdr.src_addr,
467 RTE_DIM(ipv6.val.src_ip));
468 memcpy(&ipv6.val.dst_ip, spec->hdr.dst_addr,
469 RTE_DIM(ipv6.val.dst_ip));
470 memcpy(&ipv6.mask.src_ip, mask->hdr.src_addr,
471 RTE_DIM(ipv6.mask.src_ip));
472 memcpy(&ipv6.mask.dst_ip, mask->hdr.dst_addr,
473 RTE_DIM(ipv6.mask.dst_ip));
474 vtc_flow_val = rte_be_to_cpu_32(spec->hdr.vtc_flow);
475 vtc_flow_mask = rte_be_to_cpu_32(mask->hdr.vtc_flow);
476 ipv6.val.flow_label =
477 rte_cpu_to_be_32((vtc_flow_val & IPV6_HDR_FL_MASK) >>
479 ipv6.val.traffic_class = (vtc_flow_val & IPV6_HDR_TC_MASK) >>
481 ipv6.val.next_hdr = spec->hdr.proto;
482 ipv6.val.hop_limit = spec->hdr.hop_limits;
483 ipv6.mask.flow_label =
484 rte_cpu_to_be_32((vtc_flow_mask & IPV6_HDR_FL_MASK) >>
486 ipv6.mask.traffic_class = (vtc_flow_mask & IPV6_HDR_TC_MASK) >>
488 ipv6.mask.next_hdr = mask->hdr.proto;
489 ipv6.mask.hop_limit = mask->hdr.hop_limits;
490 /* Remove unwanted bits from values. */
491 for (i = 0; i < RTE_DIM(ipv6.val.src_ip); ++i) {
492 ipv6.val.src_ip[i] &= ipv6.mask.src_ip[i];
493 ipv6.val.dst_ip[i] &= ipv6.mask.dst_ip[i];
495 ipv6.val.flow_label &= ipv6.mask.flow_label;
496 ipv6.val.traffic_class &= ipv6.mask.traffic_class;
497 ipv6.val.next_hdr &= ipv6.mask.next_hdr;
498 ipv6.val.hop_limit &= ipv6.mask.hop_limit;
500 flow_verbs_spec_add(&dev_flow->verbs, &ipv6, size);
504 * Convert the @p item into a Verbs specification. This function assumes that
505 * the input is valid and that there is space to insert the requested item
508 * @param[in, out] dev_flow
509 * Pointer to dev_flow structure.
511 * Item specification.
512 * @param[in] item_flags
516 flow_verbs_translate_item_tcp(struct mlx5_flow *dev_flow,
517 const struct rte_flow_item *item,
518 uint64_t item_flags __rte_unused)
520 const struct rte_flow_item_tcp *spec = item->spec;
521 const struct rte_flow_item_tcp *mask = item->mask;
522 unsigned int size = sizeof(struct ibv_flow_spec_tcp_udp);
523 struct ibv_flow_spec_tcp_udp tcp = {
524 .type = IBV_FLOW_SPEC_TCP | VERBS_SPEC_INNER(item_flags),
529 mask = &rte_flow_item_tcp_mask;
531 tcp.val.dst_port = spec->hdr.dst_port;
532 tcp.val.src_port = spec->hdr.src_port;
533 tcp.mask.dst_port = mask->hdr.dst_port;
534 tcp.mask.src_port = mask->hdr.src_port;
535 /* Remove unwanted bits from values. */
536 tcp.val.src_port &= tcp.mask.src_port;
537 tcp.val.dst_port &= tcp.mask.dst_port;
539 flow_verbs_spec_add(&dev_flow->verbs, &tcp, size);
543 * Convert the @p item into a Verbs specification. This function assumes that
544 * the input is valid and that there is space to insert the requested item
547 * @param[in, out] dev_flow
548 * Pointer to dev_flow structure.
550 * Item specification.
551 * @param[in] item_flags
555 flow_verbs_translate_item_udp(struct mlx5_flow *dev_flow,
556 const struct rte_flow_item *item,
557 uint64_t item_flags __rte_unused)
559 const struct rte_flow_item_udp *spec = item->spec;
560 const struct rte_flow_item_udp *mask = item->mask;
561 unsigned int size = sizeof(struct ibv_flow_spec_tcp_udp);
562 struct ibv_flow_spec_tcp_udp udp = {
563 .type = IBV_FLOW_SPEC_UDP | VERBS_SPEC_INNER(item_flags),
568 mask = &rte_flow_item_udp_mask;
570 udp.val.dst_port = spec->hdr.dst_port;
571 udp.val.src_port = spec->hdr.src_port;
572 udp.mask.dst_port = mask->hdr.dst_port;
573 udp.mask.src_port = mask->hdr.src_port;
574 /* Remove unwanted bits from values. */
575 udp.val.src_port &= udp.mask.src_port;
576 udp.val.dst_port &= udp.mask.dst_port;
578 flow_verbs_spec_add(&dev_flow->verbs, &udp, size);
582 * Convert the @p item into a Verbs specification. This function assumes that
583 * the input is valid and that there is space to insert the requested item
586 * @param[in, out] dev_flow
587 * Pointer to dev_flow structure.
589 * Item specification.
590 * @param[in] item_flags
594 flow_verbs_translate_item_vxlan(struct mlx5_flow *dev_flow,
595 const struct rte_flow_item *item,
596 uint64_t item_flags __rte_unused)
598 const struct rte_flow_item_vxlan *spec = item->spec;
599 const struct rte_flow_item_vxlan *mask = item->mask;
600 unsigned int size = sizeof(struct ibv_flow_spec_tunnel);
601 struct ibv_flow_spec_tunnel vxlan = {
602 .type = IBV_FLOW_SPEC_VXLAN_TUNNEL,
608 } id = { .vlan_id = 0, };
611 mask = &rte_flow_item_vxlan_mask;
613 memcpy(&id.vni[1], spec->vni, 3);
614 vxlan.val.tunnel_id = id.vlan_id;
615 memcpy(&id.vni[1], mask->vni, 3);
616 vxlan.mask.tunnel_id = id.vlan_id;
617 /* Remove unwanted bits from values. */
618 vxlan.val.tunnel_id &= vxlan.mask.tunnel_id;
620 flow_verbs_spec_add(&dev_flow->verbs, &vxlan, size);
624 * Convert the @p item into a Verbs specification. This function assumes that
625 * the input is valid and that there is space to insert the requested item
628 * @param[in, out] dev_flow
629 * Pointer to dev_flow structure.
631 * Item specification.
632 * @param[in] item_flags
636 flow_verbs_translate_item_vxlan_gpe(struct mlx5_flow *dev_flow,
637 const struct rte_flow_item *item,
638 uint64_t item_flags __rte_unused)
640 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
641 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
642 unsigned int size = sizeof(struct ibv_flow_spec_tunnel);
643 struct ibv_flow_spec_tunnel vxlan_gpe = {
644 .type = IBV_FLOW_SPEC_VXLAN_TUNNEL,
650 } id = { .vlan_id = 0, };
653 mask = &rte_flow_item_vxlan_gpe_mask;
655 memcpy(&id.vni[1], spec->vni, 3);
656 vxlan_gpe.val.tunnel_id = id.vlan_id;
657 memcpy(&id.vni[1], mask->vni, 3);
658 vxlan_gpe.mask.tunnel_id = id.vlan_id;
659 /* Remove unwanted bits from values. */
660 vxlan_gpe.val.tunnel_id &= vxlan_gpe.mask.tunnel_id;
662 flow_verbs_spec_add(&dev_flow->verbs, &vxlan_gpe, size);
666 * Update the protocol in Verbs IPv4/IPv6 spec.
668 * @param[in, out] attr
669 * Pointer to Verbs attributes structure.
671 * Specification type to search in order to update the IP protocol.
672 * @param[in] protocol
673 * Protocol value to set if none is present in the specification.
676 flow_verbs_item_gre_ip_protocol_update(struct ibv_flow_attr *attr,
677 enum ibv_flow_spec_type search,
681 struct ibv_spec_header *hdr = (struct ibv_spec_header *)
682 ((uint8_t *)attr + sizeof(struct ibv_flow_attr));
686 for (i = 0; i != attr->num_of_specs; ++i) {
687 if (hdr->type == search) {
689 struct ibv_flow_spec_ipv4_ext *ipv4;
690 struct ibv_flow_spec_ipv6 *ipv6;
694 case IBV_FLOW_SPEC_IPV4_EXT:
695 ip.ipv4 = (struct ibv_flow_spec_ipv4_ext *)hdr;
696 if (!ip.ipv4->val.proto) {
697 ip.ipv4->val.proto = protocol;
698 ip.ipv4->mask.proto = 0xff;
701 case IBV_FLOW_SPEC_IPV6:
702 ip.ipv6 = (struct ibv_flow_spec_ipv6 *)hdr;
703 if (!ip.ipv6->val.next_hdr) {
704 ip.ipv6->val.next_hdr = protocol;
705 ip.ipv6->mask.next_hdr = 0xff;
713 hdr = (struct ibv_spec_header *)((uint8_t *)hdr + hdr->size);
718 * Convert the @p item into a Verbs specification. This function assumes that
719 * the input is valid and that there is space to insert the requested item
722 * @param[in, out] dev_flow
723 * Pointer to dev_flow structure.
725 * Item specification.
726 * @param[in] item_flags
730 flow_verbs_translate_item_gre(struct mlx5_flow *dev_flow,
731 const struct rte_flow_item *item __rte_unused,
734 struct mlx5_flow_verbs *verbs = &dev_flow->verbs;
735 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
736 unsigned int size = sizeof(struct ibv_flow_spec_tunnel);
737 struct ibv_flow_spec_tunnel tunnel = {
738 .type = IBV_FLOW_SPEC_VXLAN_TUNNEL,
742 const struct rte_flow_item_gre *spec = item->spec;
743 const struct rte_flow_item_gre *mask = item->mask;
744 unsigned int size = sizeof(struct ibv_flow_spec_gre);
745 struct ibv_flow_spec_gre tunnel = {
746 .type = IBV_FLOW_SPEC_GRE,
751 mask = &rte_flow_item_gre_mask;
753 tunnel.val.c_ks_res0_ver = spec->c_rsvd0_ver;
754 tunnel.val.protocol = spec->protocol;
755 tunnel.mask.c_ks_res0_ver = mask->c_rsvd0_ver;
756 tunnel.mask.protocol = mask->protocol;
757 /* Remove unwanted bits from values. */
758 tunnel.val.c_ks_res0_ver &= tunnel.mask.c_ks_res0_ver;
759 tunnel.val.protocol &= tunnel.mask.protocol;
760 tunnel.val.key &= tunnel.mask.key;
763 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
764 flow_verbs_item_gre_ip_protocol_update(verbs->attr,
765 IBV_FLOW_SPEC_IPV4_EXT,
768 flow_verbs_item_gre_ip_protocol_update(verbs->attr,
771 flow_verbs_spec_add(verbs, &tunnel, size);
775 * Convert the @p action into a Verbs specification. This function assumes that
776 * the input is valid and that there is space to insert the requested action
777 * into the flow. This function also return the action that was added.
779 * @param[in, out] dev_flow
780 * Pointer to dev_flow structure.
782 * Item specification.
783 * @param[in] item_flags
787 flow_verbs_translate_item_mpls(struct mlx5_flow *dev_flow __rte_unused,
788 const struct rte_flow_item *item __rte_unused,
789 uint64_t item_flags __rte_unused)
791 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
792 const struct rte_flow_item_mpls *spec = item->spec;
793 const struct rte_flow_item_mpls *mask = item->mask;
794 unsigned int size = sizeof(struct ibv_flow_spec_mpls);
795 struct ibv_flow_spec_mpls mpls = {
796 .type = IBV_FLOW_SPEC_MPLS,
801 mask = &rte_flow_item_mpls_mask;
803 memcpy(&mpls.val.label, spec, sizeof(mpls.val.label));
804 memcpy(&mpls.mask.label, mask, sizeof(mpls.mask.label));
805 /* Remove unwanted bits from values. */
806 mpls.val.label &= mpls.mask.label;
808 flow_verbs_spec_add(&dev_flow->verbs, &mpls, size);
813 * Convert the @p action into a Verbs specification. This function assumes that
814 * the input is valid and that there is space to insert the requested action
817 * @param[in] dev_flow
818 * Pointer to mlx5_flow.
820 * Action configuration.
823 flow_verbs_translate_action_drop
824 (struct mlx5_flow *dev_flow,
825 const struct rte_flow_action *action __rte_unused)
827 unsigned int size = sizeof(struct ibv_flow_spec_action_drop);
828 struct ibv_flow_spec_action_drop drop = {
829 .type = IBV_FLOW_SPEC_ACTION_DROP,
833 flow_verbs_spec_add(&dev_flow->verbs, &drop, size);
837 * Convert the @p action into a Verbs specification. This function assumes that
838 * the input is valid and that there is space to insert the requested action
841 * @param[in] dev_flow
842 * Pointer to mlx5_flow.
844 * Action configuration.
847 flow_verbs_translate_action_queue(struct mlx5_flow *dev_flow,
848 const struct rte_flow_action *action)
850 const struct rte_flow_action_queue *queue = action->conf;
851 struct rte_flow *flow = dev_flow->flow;
854 (*flow->queue)[0] = queue->index;
855 flow->rss.queue_num = 1;
859 * Convert the @p action into a Verbs specification. This function assumes that
860 * the input is valid and that there is space to insert the requested action
864 * Action configuration.
865 * @param[in, out] action_flags
866 * Pointer to the detected actions.
867 * @param[in] dev_flow
868 * Pointer to mlx5_flow.
871 flow_verbs_translate_action_rss(struct mlx5_flow *dev_flow,
872 const struct rte_flow_action *action)
874 const struct rte_flow_action_rss *rss = action->conf;
875 const uint8_t *rss_key;
876 struct rte_flow *flow = dev_flow->flow;
879 memcpy((*flow->queue), rss->queue,
880 rss->queue_num * sizeof(uint16_t));
881 flow->rss.queue_num = rss->queue_num;
882 /* NULL RSS key indicates default RSS key. */
883 rss_key = !rss->key ? rss_hash_default_key : rss->key;
884 memcpy(flow->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
885 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
886 flow->rss.types = !rss->types ? ETH_RSS_IP : rss->types;
887 flow->rss.level = rss->level;
891 * Convert the @p action into a Verbs specification. This function assumes that
892 * the input is valid and that there is space to insert the requested action
895 * @param[in] dev_flow
896 * Pointer to mlx5_flow.
898 * Action configuration.
901 flow_verbs_translate_action_flag
902 (struct mlx5_flow *dev_flow,
903 const struct rte_flow_action *action __rte_unused)
905 unsigned int size = sizeof(struct ibv_flow_spec_action_tag);
906 struct ibv_flow_spec_action_tag tag = {
907 .type = IBV_FLOW_SPEC_ACTION_TAG,
909 .tag_id = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT),
912 flow_verbs_spec_add(&dev_flow->verbs, &tag, size);
916 * Convert the @p action into a Verbs specification. This function assumes that
917 * the input is valid and that there is space to insert the requested action
920 * @param[in] dev_flow
921 * Pointer to mlx5_flow.
923 * Action configuration.
926 flow_verbs_translate_action_mark(struct mlx5_flow *dev_flow,
927 const struct rte_flow_action *action)
929 const struct rte_flow_action_mark *mark = action->conf;
930 unsigned int size = sizeof(struct ibv_flow_spec_action_tag);
931 struct ibv_flow_spec_action_tag tag = {
932 .type = IBV_FLOW_SPEC_ACTION_TAG,
934 .tag_id = mlx5_flow_mark_set(mark->id),
937 flow_verbs_spec_add(&dev_flow->verbs, &tag, size);
941 * Convert the @p action into a Verbs specification. This function assumes that
942 * the input is valid and that there is space to insert the requested action
946 * Pointer to the Ethernet device structure.
948 * Action configuration.
949 * @param[in] dev_flow
950 * Pointer to mlx5_flow.
952 * Pointer to error structure.
955 * 0 On success else a negative errno value is returned and rte_errno is set.
958 flow_verbs_translate_action_count(struct mlx5_flow *dev_flow,
959 const struct rte_flow_action *action,
960 struct rte_eth_dev *dev,
961 struct rte_flow_error *error)
963 const struct rte_flow_action_count *count = action->conf;
964 struct rte_flow *flow = dev_flow->flow;
965 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \
966 defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
967 unsigned int size = sizeof(struct ibv_flow_spec_counter_action);
968 struct ibv_flow_spec_counter_action counter = {
969 .type = IBV_FLOW_SPEC_ACTION_COUNT,
974 if (!flow->counter) {
975 flow->counter = flow_verbs_counter_new(dev, count->shared,
978 return rte_flow_error_set(error, rte_errno,
979 RTE_FLOW_ERROR_TYPE_ACTION,
984 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42)
985 counter.counter_set_handle = flow->counter->cs->handle;
986 flow_verbs_spec_add(&dev_flow->verbs, &counter, size);
987 #elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
988 counter.counters = flow->counter->cs;
989 flow_verbs_spec_add(&dev_flow->verbs, &counter, size);
995 * Internal validation function. For validating both actions and items.
998 * Pointer to the Ethernet device structure.
1000 * Pointer to the flow attributes.
1002 * Pointer to the list of items.
1003 * @param[in] actions
1004 * Pointer to the list of actions.
1006 * Pointer to the error structure.
1009 * 0 on success, a negative errno value otherwise and rte_errno is set.
1012 flow_verbs_validate(struct rte_eth_dev *dev,
1013 const struct rte_flow_attr *attr,
1014 const struct rte_flow_item items[],
1015 const struct rte_flow_action actions[],
1016 struct rte_flow_error *error)
1019 uint64_t action_flags = 0;
1020 uint64_t item_flags = 0;
1021 uint8_t next_protocol = 0xff;
1025 ret = mlx5_flow_validate_attributes(dev, attr, error);
1028 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
1029 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1032 switch (items->type) {
1033 case RTE_FLOW_ITEM_TYPE_VOID:
1035 case RTE_FLOW_ITEM_TYPE_ETH:
1036 ret = mlx5_flow_validate_item_eth(items, item_flags,
1040 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1041 MLX5_FLOW_LAYER_OUTER_L2;
1043 case RTE_FLOW_ITEM_TYPE_VLAN:
1044 ret = mlx5_flow_validate_item_vlan(items, item_flags,
1048 item_flags |= tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
1049 MLX5_FLOW_LAYER_INNER_VLAN) :
1050 (MLX5_FLOW_LAYER_OUTER_L2 |
1051 MLX5_FLOW_LAYER_OUTER_VLAN);
1053 case RTE_FLOW_ITEM_TYPE_IPV4:
1054 ret = mlx5_flow_validate_item_ipv4(items, item_flags,
1058 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1059 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1060 if (items->mask != NULL &&
1061 ((const struct rte_flow_item_ipv4 *)
1062 items->mask)->hdr.next_proto_id) {
1064 ((const struct rte_flow_item_ipv4 *)
1065 (items->spec))->hdr.next_proto_id;
1067 ((const struct rte_flow_item_ipv4 *)
1068 (items->mask))->hdr.next_proto_id;
1070 /* Reset for inner layer. */
1071 next_protocol = 0xff;
1074 case RTE_FLOW_ITEM_TYPE_IPV6:
1075 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
1079 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1080 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1081 if (items->mask != NULL &&
1082 ((const struct rte_flow_item_ipv6 *)
1083 items->mask)->hdr.proto) {
1085 ((const struct rte_flow_item_ipv6 *)
1086 items->spec)->hdr.proto;
1088 ((const struct rte_flow_item_ipv6 *)
1089 items->mask)->hdr.proto;
1091 /* Reset for inner layer. */
1092 next_protocol = 0xff;
1095 case RTE_FLOW_ITEM_TYPE_UDP:
1096 ret = mlx5_flow_validate_item_udp(items, item_flags,
1101 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
1102 MLX5_FLOW_LAYER_OUTER_L4_UDP;
1104 case RTE_FLOW_ITEM_TYPE_TCP:
1105 ret = mlx5_flow_validate_item_tcp
1108 &rte_flow_item_tcp_mask,
1112 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
1113 MLX5_FLOW_LAYER_OUTER_L4_TCP;
1115 case RTE_FLOW_ITEM_TYPE_VXLAN:
1116 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
1120 item_flags |= MLX5_FLOW_LAYER_VXLAN;
1122 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
1123 ret = mlx5_flow_validate_item_vxlan_gpe(items,
1128 item_flags |= MLX5_FLOW_LAYER_VXLAN_GPE;
1130 case RTE_FLOW_ITEM_TYPE_GRE:
1131 ret = mlx5_flow_validate_item_gre(items, item_flags,
1132 next_protocol, error);
1135 item_flags |= MLX5_FLOW_LAYER_GRE;
1137 case RTE_FLOW_ITEM_TYPE_MPLS:
1138 ret = mlx5_flow_validate_item_mpls(items, item_flags,
1143 item_flags |= MLX5_FLOW_LAYER_MPLS;
1146 return rte_flow_error_set(error, ENOTSUP,
1147 RTE_FLOW_ERROR_TYPE_ITEM,
1148 NULL, "item not supported");
1151 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1152 switch (actions->type) {
1153 case RTE_FLOW_ACTION_TYPE_VOID:
1155 case RTE_FLOW_ACTION_TYPE_FLAG:
1156 ret = mlx5_flow_validate_action_flag(action_flags,
1161 action_flags |= MLX5_FLOW_ACTION_FLAG;
1163 case RTE_FLOW_ACTION_TYPE_MARK:
1164 ret = mlx5_flow_validate_action_mark(actions,
1170 action_flags |= MLX5_FLOW_ACTION_MARK;
1172 case RTE_FLOW_ACTION_TYPE_DROP:
1173 ret = mlx5_flow_validate_action_drop(action_flags,
1178 action_flags |= MLX5_FLOW_ACTION_DROP;
1180 case RTE_FLOW_ACTION_TYPE_QUEUE:
1181 ret = mlx5_flow_validate_action_queue(actions,
1187 action_flags |= MLX5_FLOW_ACTION_QUEUE;
1189 case RTE_FLOW_ACTION_TYPE_RSS:
1190 ret = mlx5_flow_validate_action_rss(actions,
1196 action_flags |= MLX5_FLOW_ACTION_RSS;
1198 case RTE_FLOW_ACTION_TYPE_COUNT:
1199 ret = mlx5_flow_validate_action_count(dev, attr, error);
1202 action_flags |= MLX5_FLOW_ACTION_COUNT;
1205 return rte_flow_error_set(error, ENOTSUP,
1206 RTE_FLOW_ERROR_TYPE_ACTION,
1208 "action not supported");
1211 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS))
1212 return rte_flow_error_set(error, EINVAL,
1213 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1214 "no fate action is found");
1219 * Calculate the required bytes that are needed for the action part of the verbs
1222 * @param[in] actions
1223 * Pointer to the list of actions.
1226 * The size of the memory needed for all actions.
1229 flow_verbs_get_actions_size(const struct rte_flow_action actions[])
1233 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1234 switch (actions->type) {
1235 case RTE_FLOW_ACTION_TYPE_VOID:
1237 case RTE_FLOW_ACTION_TYPE_FLAG:
1238 size += sizeof(struct ibv_flow_spec_action_tag);
1240 case RTE_FLOW_ACTION_TYPE_MARK:
1241 size += sizeof(struct ibv_flow_spec_action_tag);
1243 case RTE_FLOW_ACTION_TYPE_DROP:
1244 size += sizeof(struct ibv_flow_spec_action_drop);
1246 case RTE_FLOW_ACTION_TYPE_QUEUE:
1248 case RTE_FLOW_ACTION_TYPE_RSS:
1250 case RTE_FLOW_ACTION_TYPE_COUNT:
1251 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \
1252 defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
1253 size += sizeof(struct ibv_flow_spec_counter_action);
1264 * Calculate the required bytes that are needed for the item part of the verbs
1268 * Pointer to the list of items.
1271 * The size of the memory needed for all items.
1274 flow_verbs_get_items_size(const struct rte_flow_item items[])
1278 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
1279 switch (items->type) {
1280 case RTE_FLOW_ITEM_TYPE_VOID:
1282 case RTE_FLOW_ITEM_TYPE_ETH:
1283 size += sizeof(struct ibv_flow_spec_eth);
1285 case RTE_FLOW_ITEM_TYPE_VLAN:
1286 size += sizeof(struct ibv_flow_spec_eth);
1288 case RTE_FLOW_ITEM_TYPE_IPV4:
1289 size += sizeof(struct ibv_flow_spec_ipv4_ext);
1291 case RTE_FLOW_ITEM_TYPE_IPV6:
1292 size += sizeof(struct ibv_flow_spec_ipv6);
1294 case RTE_FLOW_ITEM_TYPE_UDP:
1295 size += sizeof(struct ibv_flow_spec_tcp_udp);
1297 case RTE_FLOW_ITEM_TYPE_TCP:
1298 size += sizeof(struct ibv_flow_spec_tcp_udp);
1300 case RTE_FLOW_ITEM_TYPE_VXLAN:
1301 size += sizeof(struct ibv_flow_spec_tunnel);
1303 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
1304 size += sizeof(struct ibv_flow_spec_tunnel);
1306 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
1307 case RTE_FLOW_ITEM_TYPE_GRE:
1308 size += sizeof(struct ibv_flow_spec_gre);
1310 case RTE_FLOW_ITEM_TYPE_MPLS:
1311 size += sizeof(struct ibv_flow_spec_mpls);
1314 case RTE_FLOW_ITEM_TYPE_GRE:
1315 size += sizeof(struct ibv_flow_spec_tunnel);
1326 * Internal preparation function. Allocate mlx5_flow with the required size.
1327 * The required size is calculate based on the actions and items. This function
1328 * also returns the detected actions and items for later use.
1331 * Pointer to the flow attributes.
1333 * Pointer to the list of items.
1334 * @param[in] actions
1335 * Pointer to the list of actions.
1337 * Pointer to the error structure.
1340 * Pointer to mlx5_flow object on success, otherwise NULL and rte_errno
1343 static struct mlx5_flow *
1344 flow_verbs_prepare(const struct rte_flow_attr *attr __rte_unused,
1345 const struct rte_flow_item items[],
1346 const struct rte_flow_action actions[],
1347 struct rte_flow_error *error)
1349 uint32_t size = sizeof(struct mlx5_flow) + sizeof(struct ibv_flow_attr);
1350 struct mlx5_flow *flow;
1352 size += flow_verbs_get_actions_size(actions);
1353 size += flow_verbs_get_items_size(items);
1354 flow = rte_calloc(__func__, 1, size, 0);
1356 rte_flow_error_set(error, ENOMEM,
1357 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1358 "not enough memory to create flow");
1361 flow->verbs.attr = (void *)(flow + 1);
1363 (uint8_t *)(flow + 1) + sizeof(struct ibv_flow_attr);
1368 * Fill the flow with verb spec.
1371 * Pointer to Ethernet device.
1372 * @param[in, out] dev_flow
1373 * Pointer to the mlx5 flow.
1375 * Pointer to the flow attributes.
1377 * Pointer to the list of items.
1378 * @param[in] actions
1379 * Pointer to the list of actions.
1381 * Pointer to the error structure.
1384 * 0 on success, else a negative errno value otherwise and rte_ernno is set.
1387 flow_verbs_translate(struct rte_eth_dev *dev,
1388 struct mlx5_flow *dev_flow,
1389 const struct rte_flow_attr *attr,
1390 const struct rte_flow_item items[],
1391 const struct rte_flow_action actions[],
1392 struct rte_flow_error *error)
1394 struct rte_flow *flow = dev_flow->flow;
1395 uint64_t item_flags = 0;
1396 uint64_t action_flags = 0;
1397 uint64_t priority = attr->priority;
1398 uint32_t subpriority = 0;
1399 struct priv *priv = dev->data->dev_private;
1401 if (priority == MLX5_FLOW_PRIO_RSVD)
1402 priority = priv->config.flow_prio - 1;
1403 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1406 switch (actions->type) {
1407 case RTE_FLOW_ACTION_TYPE_VOID:
1409 case RTE_FLOW_ACTION_TYPE_FLAG:
1410 flow_verbs_translate_action_flag(dev_flow, actions);
1411 action_flags |= MLX5_FLOW_ACTION_FLAG;
1413 case RTE_FLOW_ACTION_TYPE_MARK:
1414 flow_verbs_translate_action_mark(dev_flow, actions);
1415 action_flags |= MLX5_FLOW_ACTION_MARK;
1417 case RTE_FLOW_ACTION_TYPE_DROP:
1418 flow_verbs_translate_action_drop(dev_flow, actions);
1419 action_flags |= MLX5_FLOW_ACTION_DROP;
1421 case RTE_FLOW_ACTION_TYPE_QUEUE:
1422 flow_verbs_translate_action_queue(dev_flow, actions);
1423 action_flags |= MLX5_FLOW_ACTION_QUEUE;
1425 case RTE_FLOW_ACTION_TYPE_RSS:
1426 flow_verbs_translate_action_rss(dev_flow, actions);
1427 action_flags |= MLX5_FLOW_ACTION_RSS;
1429 case RTE_FLOW_ACTION_TYPE_COUNT:
1430 ret = flow_verbs_translate_action_count(dev_flow,
1435 action_flags |= MLX5_FLOW_ACTION_COUNT;
1438 return rte_flow_error_set(error, ENOTSUP,
1439 RTE_FLOW_ERROR_TYPE_ACTION,
1441 "action not supported");
1444 flow->actions = action_flags;
1445 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
1446 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1448 switch (items->type) {
1449 case RTE_FLOW_ITEM_TYPE_VOID:
1451 case RTE_FLOW_ITEM_TYPE_ETH:
1452 flow_verbs_translate_item_eth(dev_flow, items,
1454 subpriority = MLX5_PRIORITY_MAP_L2;
1455 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1456 MLX5_FLOW_LAYER_OUTER_L2;
1458 case RTE_FLOW_ITEM_TYPE_VLAN:
1459 flow_verbs_translate_item_vlan(dev_flow, items,
1461 subpriority = MLX5_PRIORITY_MAP_L2;
1462 item_flags |= tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
1463 MLX5_FLOW_LAYER_INNER_VLAN) :
1464 (MLX5_FLOW_LAYER_OUTER_L2 |
1465 MLX5_FLOW_LAYER_OUTER_VLAN);
1467 case RTE_FLOW_ITEM_TYPE_IPV4:
1468 flow_verbs_translate_item_ipv4(dev_flow, items,
1470 subpriority = MLX5_PRIORITY_MAP_L3;
1471 dev_flow->verbs.hash_fields |=
1472 mlx5_flow_hashfields_adjust
1474 MLX5_IPV4_LAYER_TYPES,
1475 MLX5_IPV4_IBV_RX_HASH);
1476 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1477 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1479 case RTE_FLOW_ITEM_TYPE_IPV6:
1480 flow_verbs_translate_item_ipv6(dev_flow, items,
1482 subpriority = MLX5_PRIORITY_MAP_L3;
1483 dev_flow->verbs.hash_fields |=
1484 mlx5_flow_hashfields_adjust
1486 MLX5_IPV6_LAYER_TYPES,
1487 MLX5_IPV6_IBV_RX_HASH);
1488 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1489 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1491 case RTE_FLOW_ITEM_TYPE_TCP:
1492 flow_verbs_translate_item_tcp(dev_flow, items,
1494 subpriority = MLX5_PRIORITY_MAP_L4;
1495 dev_flow->verbs.hash_fields |=
1496 mlx5_flow_hashfields_adjust
1497 (dev_flow, tunnel, ETH_RSS_TCP,
1498 (IBV_RX_HASH_SRC_PORT_TCP |
1499 IBV_RX_HASH_DST_PORT_TCP));
1500 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
1501 MLX5_FLOW_LAYER_OUTER_L4_TCP;
1503 case RTE_FLOW_ITEM_TYPE_UDP:
1504 flow_verbs_translate_item_udp(dev_flow, items,
1506 subpriority = MLX5_PRIORITY_MAP_L4;
1507 dev_flow->verbs.hash_fields |=
1508 mlx5_flow_hashfields_adjust
1509 (dev_flow, tunnel, ETH_RSS_UDP,
1510 (IBV_RX_HASH_SRC_PORT_UDP |
1511 IBV_RX_HASH_DST_PORT_UDP));
1512 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
1513 MLX5_FLOW_LAYER_OUTER_L4_UDP;
1515 case RTE_FLOW_ITEM_TYPE_VXLAN:
1516 flow_verbs_translate_item_vxlan(dev_flow, items,
1518 subpriority = MLX5_PRIORITY_MAP_L2;
1519 item_flags |= MLX5_FLOW_LAYER_VXLAN;
1521 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
1522 flow_verbs_translate_item_vxlan_gpe(dev_flow, items,
1524 subpriority = MLX5_PRIORITY_MAP_L2;
1525 item_flags |= MLX5_FLOW_LAYER_VXLAN_GPE;
1527 case RTE_FLOW_ITEM_TYPE_GRE:
1528 flow_verbs_translate_item_gre(dev_flow, items,
1530 subpriority = MLX5_PRIORITY_MAP_L2;
1531 item_flags |= MLX5_FLOW_LAYER_GRE;
1533 case RTE_FLOW_ITEM_TYPE_MPLS:
1534 flow_verbs_translate_item_mpls(dev_flow, items,
1536 subpriority = MLX5_PRIORITY_MAP_L2;
1537 item_flags |= MLX5_FLOW_LAYER_MPLS;
1540 return rte_flow_error_set(error, ENOTSUP,
1541 RTE_FLOW_ERROR_TYPE_ITEM,
1543 "item not supported");
1546 dev_flow->layers = item_flags;
1547 dev_flow->verbs.attr->priority =
1548 mlx5_flow_adjust_priority(dev, priority, subpriority);
1553 * Remove the flow from the NIC but keeps it in memory.
1556 * Pointer to the Ethernet device structure.
1557 * @param[in, out] flow
1558 * Pointer to flow structure.
1561 flow_verbs_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
1563 struct mlx5_flow_verbs *verbs;
1564 struct mlx5_flow *dev_flow;
1568 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
1569 verbs = &dev_flow->verbs;
1571 claim_zero(mlx5_glue->destroy_flow(verbs->flow));
1575 if (flow->actions & MLX5_FLOW_ACTION_DROP)
1576 mlx5_hrxq_drop_release(dev);
1578 mlx5_hrxq_release(dev, verbs->hrxq);
1585 * Remove the flow from the NIC and the memory.
1588 * Pointer to the Ethernet device structure.
1589 * @param[in, out] flow
1590 * Pointer to flow structure.
1593 flow_verbs_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
1595 struct mlx5_flow *dev_flow;
1599 flow_verbs_remove(dev, flow);
1600 while (!LIST_EMPTY(&flow->dev_flows)) {
1601 dev_flow = LIST_FIRST(&flow->dev_flows);
1602 LIST_REMOVE(dev_flow, next);
1605 if (flow->counter) {
1606 flow_verbs_counter_release(flow->counter);
1607 flow->counter = NULL;
1612 * Apply the flow to the NIC.
1615 * Pointer to the Ethernet device structure.
1616 * @param[in, out] flow
1617 * Pointer to flow structure.
1619 * Pointer to error structure.
1622 * 0 on success, a negative errno value otherwise and rte_errno is set.
1625 flow_verbs_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
1626 struct rte_flow_error *error)
1628 struct mlx5_flow_verbs *verbs;
1629 struct mlx5_flow *dev_flow;
1632 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
1633 verbs = &dev_flow->verbs;
1634 if (flow->actions & MLX5_FLOW_ACTION_DROP) {
1635 verbs->hrxq = mlx5_hrxq_drop_new(dev);
1639 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1640 "cannot get drop hash queue");
1644 struct mlx5_hrxq *hrxq;
1646 hrxq = mlx5_hrxq_get(dev, flow->key,
1647 MLX5_RSS_HASH_KEY_LEN,
1650 flow->rss.queue_num);
1652 hrxq = mlx5_hrxq_new(dev, flow->key,
1653 MLX5_RSS_HASH_KEY_LEN,
1656 flow->rss.queue_num,
1657 !!(dev_flow->layers &
1658 MLX5_FLOW_LAYER_TUNNEL));
1662 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1663 "cannot get hash queue");
1668 verbs->flow = mlx5_glue->create_flow(verbs->hrxq->qp,
1671 rte_flow_error_set(error, errno,
1672 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1674 "hardware refuses to create flow");
1680 err = rte_errno; /* Save rte_errno before cleanup. */
1681 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
1682 verbs = &dev_flow->verbs;
1684 if (flow->actions & MLX5_FLOW_ACTION_DROP)
1685 mlx5_hrxq_drop_release(dev);
1687 mlx5_hrxq_release(dev, verbs->hrxq);
1691 rte_errno = err; /* Restore rte_errno. */
1698 * @see rte_flow_query()
1702 flow_verbs_query(struct rte_eth_dev *dev,
1703 struct rte_flow *flow,
1704 const struct rte_flow_action *actions,
1706 struct rte_flow_error *error)
1710 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1711 switch (actions->type) {
1712 case RTE_FLOW_ACTION_TYPE_VOID:
1714 case RTE_FLOW_ACTION_TYPE_COUNT:
1715 ret = flow_verbs_counter_query(dev, flow, data, error);
1718 return rte_flow_error_set(error, ENOTSUP,
1719 RTE_FLOW_ERROR_TYPE_ACTION,
1721 "action not supported");
1727 const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops = {
1728 .validate = flow_verbs_validate,
1729 .prepare = flow_verbs_prepare,
1730 .translate = flow_verbs_translate,
1731 .apply = flow_verbs_apply,
1732 .remove = flow_verbs_remove,
1733 .destroy = flow_verbs_destroy,
1734 .query = flow_verbs_query,