rdma: add Mellanox mlx5 Direct Verbs receive support
[vpp.git] / src / plugins / rdma / rdma.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #ifndef _RDMA_H_
19 #define _RDMA_H_
20
21 #include <infiniband/verbs.h>
22 #include <vlib/log.h>
23 #include <vlib/pci/pci.h>
24 #include <vnet/interface.h>
25 #include <vnet/ethernet/mac_address.h>
26 #include <rdma/rdma_mlx5dv.h>
27
28 #define foreach_rdma_device_flags \
29   _(0, ERROR, "error") \
30   _(1, ADMIN_UP, "admin-up") \
31   _(2, LINK_UP, "link-up") \
32   _(3, PROMISC, "promiscuous") \
33   _(4, MLX5DV, "mlx5dv")
34
35 enum
36 {
37 #define _(a, b, c) RDMA_DEVICE_F_##b = (1 << a),
38   foreach_rdma_device_flags
39 #undef _
40 };
41
42 typedef struct
43 {
44   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
45   struct ibv_cq *cq;
46   struct ibv_wq *wq;
47   u32 *bufs;
48   u32 size;
49   u32 head;
50   u32 tail;
51   u32 cq_ci;
52   u16 log2_cq_size;
53   u16 n_mini_cqes;
54   u16 n_mini_cqes_left;
55   u16 last_cqe_flags;
56   mlx5dv_cqe_t *cqes;
57   mlx5dv_rwq_t *wqes;
58   volatile u32 *wq_db;
59   volatile u32 *cq_db;
60   u32 cqn;
61   u32 wqe_cnt;
62   u32 wq_stride;
63 } rdma_rxq_t;
64
65 typedef struct
66 {
67   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
68   clib_spinlock_t lock;
69   struct ibv_cq *cq;
70   struct ibv_qp *qp;
71   u32 *bufs;
72   u32 size;
73   u32 head;
74   u32 tail;
75 } rdma_txq_t;
76
77 typedef struct
78 {
79   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
80
81   /* following fields are accessed in datapath */
82   rdma_rxq_t *rxqs;
83   rdma_txq_t *txqs;
84   u32 flags;
85   u32 per_interface_next_index;
86   u32 sw_if_index;
87   u32 hw_if_index;
88   u32 lkey;                     /* cache of mr->lkey */
89   u8 pool;                      /* buffer pool index */
90
91   /* fields below are not accessed in datapath */
92   vlib_pci_device_info_t *pci;
93   u8 *name;
94   u8 *linux_ifname;
95   mac_address_t hwaddr;
96   u32 async_event_clib_file_index;
97   u32 dev_instance;
98
99   struct ibv_context *ctx;
100   struct ibv_pd *pd;
101   struct ibv_mr *mr;
102   struct ibv_qp *rx_qp;
103   struct ibv_rwq_ind_table *rx_rwq_ind_tbl;
104   struct ibv_flow *flow_ucast;
105   struct ibv_flow *flow_mcast;
106
107   clib_error_t *error;
108 } rdma_device_t;
109
110 typedef struct
111 {
112   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
113   union
114   {
115     u16 cqe_flags[VLIB_FRAME_SIZE];
116     u16x8 cqe_flags8[VLIB_FRAME_SIZE / 8];
117     u16x16 cqe_flags16[VLIB_FRAME_SIZE / 16];
118   };
119   vlib_buffer_t buffer_template;
120 } rdma_per_thread_data_t;
121
122 typedef struct
123 {
124   rdma_per_thread_data_t *per_thread_data;
125   rdma_device_t *devices;
126   vlib_log_class_t log_class;
127   u16 msg_id_base;
128 } rdma_main_t;
129
130 extern rdma_main_t rdma_main;
131
132 typedef enum
133 {
134   RDMA_MODE_AUTO = 0,
135   RDMA_MODE_IBV,
136   RDMA_MODE_DV,
137 } rdma_mode_t;
138
139 typedef struct
140 {
141   u8 *ifname;
142   u8 *name;
143   u32 rxq_size;
144   u32 txq_size;
145   u32 rxq_num;
146   rdma_mode_t mode;
147
148   /* return */
149   int rv;
150   u32 sw_if_index;
151   clib_error_t *error;
152 } rdma_create_if_args_t;
153
154 void rdma_create_if (vlib_main_t * vm, rdma_create_if_args_t * args);
155 void rdma_delete_if (vlib_main_t * vm, rdma_device_t * rd);
156
157 extern vlib_node_registration_t rdma_input_node;
158 extern vnet_device_class_t rdma_device_class;
159
160 format_function_t format_rdma_device;
161 format_function_t format_rdma_device_name;
162 format_function_t format_rdma_input_trace;
163 format_function_t format_rdma_rxq;
164 unformat_function_t unformat_rdma_create_if_args;
165
166 typedef struct
167 {
168   u32 next_index;
169   u32 hw_if_index;
170   u16 cqe_flags;
171 } rdma_input_trace_t;
172
173 #define foreach_rdma_tx_func_error             \
174 _(NO_FREE_SLOTS, "no free tx slots")
175
176 typedef enum
177 {
178 #define _(f,s) RDMA_TX_ERROR_##f,
179   foreach_rdma_tx_func_error
180 #undef _
181     RDMA_TX_N_ERROR,
182 } rdma_tx_func_error_t;
183
184 #endif /* AVF_H */
185
186 /*
187  * fd.io coding-style-patch-verification: ON
188  *
189  * Local Variables:
190  * eval: (c-set-style "gnu")
191  * End:
192  */