6271f0f1eafe6463bef64ee914033a4f4456e8e2
[dpdk.git] / drivers / net / mlx5 / linux / mlx5_verbs.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4
5 #include <stddef.h>
6 #include <errno.h>
7 #include <string.h>
8 #include <stdint.h>
9 #include <unistd.h>
10 #include <inttypes.h>
11
12 #include "mlx5_autoconf.h"
13
14 #include <rte_mbuf.h>
15 #include <rte_malloc.h>
16 #include <rte_ethdev_driver.h>
17 #include <rte_common.h>
18
19 #include <mlx5_glue.h>
20 #include <mlx5_common.h>
21 #include <mlx5_common_mr.h>
22 #include <mlx5_rxtx.h>
23 #include <mlx5_verbs.h>
24 /**
25  * Register mr. Given protection domain pointer, pointer to addr and length
26  * register the memory region.
27  *
28  * @param[in] pd
29  *   Pointer to protection domain context.
30  * @param[in] addr
31  *   Pointer to memory start address.
32  * @param[in] length
33  *   Length of the memory to register.
34  * @param[out] pmd_mr
35  *   pmd_mr struct set with lkey, address, length and pointer to mr object
36  *
37  * @return
38  *   0 on successful registration, -1 otherwise
39  */
40 static int
41 mlx5_reg_mr(void *pd, void *addr, size_t length,
42                  struct mlx5_pmd_mr *pmd_mr)
43 {
44         return mlx5_common_verbs_reg_mr(pd, addr, length, pmd_mr);
45 }
46
47 /**
48  * Deregister mr. Given the mlx5 pmd MR - deregister the MR
49  *
50  * @param[in] pmd_mr
51  *   pmd_mr struct set with lkey, address, length and pointer to mr object
52  *
53  */
54 static void
55 mlx5_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
56 {
57         mlx5_common_verbs_dereg_mr(pmd_mr);
58 }
59
60 /* verbs operations. */
61 const struct mlx5_verbs_ops mlx5_verbs_ops = {
62         .reg_mr = mlx5_reg_mr,
63         .dereg_mr = mlx5_dereg_mr,
64 };
65
66 /**
67  * Modify Rx WQ vlan stripping offload
68  *
69  * @param rxq_obj
70  *   Rx queue object.
71  *
72  * @return 0 on success, non-0 otherwise
73  */
74 static int
75 mlx5_rxq_obj_modify_wq_vlan_strip(struct mlx5_rxq_obj *rxq_obj, int on)
76 {
77         uint16_t vlan_offloads =
78                 (on ? IBV_WQ_FLAGS_CVLAN_STRIPPING : 0) |
79                 0;
80         struct ibv_wq_attr mod;
81         mod = (struct ibv_wq_attr){
82                 .attr_mask = IBV_WQ_ATTR_FLAGS,
83                 .flags_mask = IBV_WQ_FLAGS_CVLAN_STRIPPING,
84                 .flags = vlan_offloads,
85         };
86         return mlx5_glue->modify_wq(rxq_obj->wq, &mod);
87 }
88
89 struct mlx5_obj_ops ibv_obj_ops = {
90         .rxq_obj_modify_vlan_strip = mlx5_rxq_obj_modify_wq_vlan_strip,
91 };