blob: b09a9e26ca73478318562b05e951e3a43fcf3bff [file] [log] [blame]
Moni Shoua8700e3e2016-06-16 16:45:23 +03001/*
2 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#ifndef RXE_VERBS_H
35#define RXE_VERBS_H
36
37#include <linux/interrupt.h>
38#include <rdma/rdma_user_rxe.h>
39#include "rxe_pool.h"
40#include "rxe_task.h"
Yonatan Cohen0b1e5b92017-03-10 18:23:56 +020041#include "rxe_hw_counters.h"
Moni Shoua8700e3e2016-06-16 16:45:23 +030042
43static inline int pkey_match(u16 key1, u16 key2)
44{
45 return (((key1 & 0x7fff) != 0) &&
46 ((key1 & 0x7fff) == (key2 & 0x7fff)) &&
47 ((key1 & 0x8000) || (key2 & 0x8000))) ? 1 : 0;
48}
49
50/* Return >0 if psn_a > psn_b
51 * 0 if psn_a == psn_b
52 * <0 if psn_a < psn_b
53 */
54static inline int psn_compare(u32 psn_a, u32 psn_b)
55{
56 s32 diff;
57
58 diff = (psn_a - psn_b) << 8;
59 return diff;
60}
61
62struct rxe_ucontext {
63 struct rxe_pool_entry pelem;
64 struct ib_ucontext ibuc;
65};
66
67struct rxe_pd {
68 struct rxe_pool_entry pelem;
69 struct ib_pd ibpd;
70};
71
72struct rxe_ah {
73 struct rxe_pool_entry pelem;
74 struct ib_ah ibah;
75 struct rxe_pd *pd;
76 struct rxe_av av;
77};
78
79struct rxe_cqe {
80 union {
81 struct ib_wc ibwc;
82 struct ib_uverbs_wc uibwc;
83 };
84};
85
86struct rxe_cq {
87 struct rxe_pool_entry pelem;
88 struct ib_cq ibcq;
89 struct rxe_queue *queue;
90 spinlock_t cq_lock;
91 u8 notify;
Andrew Boyerbfc3ae02017-08-28 16:11:50 -040092 bool is_dying;
Moni Shoua8700e3e2016-06-16 16:45:23 +030093 int is_user;
94 struct tasklet_struct comp_task;
95};
96
97enum wqe_state {
98 wqe_state_posted,
99 wqe_state_processing,
100 wqe_state_pending,
101 wqe_state_done,
102 wqe_state_error,
103};
104
105struct rxe_sq {
106 int max_wr;
107 int max_sge;
108 int max_inline;
109 spinlock_t sq_lock; /* guard queue */
110 struct rxe_queue *queue;
111};
112
113struct rxe_rq {
114 int max_wr;
115 int max_sge;
116 spinlock_t producer_lock; /* guard queue producer */
117 spinlock_t consumer_lock; /* guard queue consumer */
118 struct rxe_queue *queue;
119};
120
121struct rxe_srq {
122 struct rxe_pool_entry pelem;
123 struct ib_srq ibsrq;
124 struct rxe_pd *pd;
125 struct rxe_rq rq;
126 u32 srq_num;
127
128 int limit;
129 int error;
130};
131
132enum rxe_qp_state {
133 QP_STATE_RESET,
134 QP_STATE_INIT,
135 QP_STATE_READY,
136 QP_STATE_DRAIN, /* req only */
137 QP_STATE_DRAINED, /* req only */
138 QP_STATE_ERROR
139};
140
141extern char *rxe_qp_state_name[];
142
143struct rxe_req_info {
144 enum rxe_qp_state state;
145 int wqe_index;
146 u32 psn;
147 int opcode;
148 atomic_t rd_atomic;
149 int wait_fence;
150 int need_rd_atomic;
151 int wait_psn;
152 int need_retry;
153 int noack_pkts;
154 struct rxe_task task;
155};
156
157struct rxe_comp_info {
158 u32 psn;
159 int opcode;
160 int timeout;
161 int timeout_retry;
162 u32 retry_cnt;
163 u32 rnr_retry;
164 struct rxe_task task;
165};
166
167enum rdatm_res_state {
168 rdatm_res_state_next,
169 rdatm_res_state_new,
170 rdatm_res_state_replay,
171};
172
173struct resp_res {
174 int type;
175 u32 first_psn;
176 u32 last_psn;
177 u32 cur_psn;
178 enum rdatm_res_state state;
179
180 union {
181 struct {
182 struct sk_buff *skb;
183 } atomic;
184 struct {
185 struct rxe_mem *mr;
186 u64 va_org;
187 u32 rkey;
188 u32 length;
189 u64 va;
190 u32 resid;
191 } read;
192 };
193};
194
195struct rxe_resp_info {
196 enum rxe_qp_state state;
197 u32 msn;
198 u32 psn;
199 int opcode;
200 int drop_msg;
201 int goto_error;
202 int sent_psn_nak;
203 enum ib_wc_status status;
204 u8 aeth_syndrome;
205
206 /* Receive only */
207 struct rxe_recv_wqe *wqe;
208
209 /* RDMA read / atomic only */
210 u64 va;
211 struct rxe_mem *mr;
212 u32 resid;
213 u32 rkey;
214 u64 atomic_orig;
215
216 /* SRQ only */
217 struct {
218 struct rxe_recv_wqe wqe;
219 struct ib_sge sge[RXE_MAX_SGE];
220 } srq_wqe;
221
222 /* Responder resources. It's a circular list where the oldest
223 * resource is dropped first.
224 */
225 struct resp_res *resources;
226 unsigned int res_head;
227 unsigned int res_tail;
228 struct resp_res *res;
229 struct rxe_task task;
230};
231
232struct rxe_qp {
233 struct rxe_pool_entry pelem;
234 struct ib_qp ibqp;
235 struct ib_qp_attr attr;
236 unsigned int valid;
237 unsigned int mtu;
238 int is_user;
239
240 struct rxe_pd *pd;
241 struct rxe_srq *srq;
242 struct rxe_cq *scq;
243 struct rxe_cq *rcq;
244
245 enum ib_sig_type sq_sig_type;
246
247 struct rxe_sq sq;
248 struct rxe_rq rq;
249
250 struct socket *sk;
251
252 struct rxe_av pri_av;
253 struct rxe_av alt_av;
254
255 /* list of mcast groups qp has joined (for cleanup) */
256 struct list_head grp_list;
257 spinlock_t grp_lock; /* guard grp_list */
258
259 struct sk_buff_head req_pkts;
260 struct sk_buff_head resp_pkts;
261 struct sk_buff_head send_pkts;
262
263 struct rxe_req_info req;
264 struct rxe_comp_info comp;
265 struct rxe_resp_info resp;
266
267 atomic_t ssn;
268 atomic_t skb_out;
269 int need_req_skb;
270
271 /* Timer for retranmitting packet when ACKs have been lost. RC
272 * only. The requester sets it when it is not already
273 * started. The responder resets it whenever an ack is
274 * received.
275 */
276 struct timer_list retrans_timer;
277 u64 qp_timeout_jiffies;
278
279 /* Timer for handling RNR NAKS. */
280 struct timer_list rnr_nak_timer;
281
282 spinlock_t state_lock; /* guard requester and completer */
283};
284
285enum rxe_mem_state {
286 RXE_MEM_STATE_ZOMBIE,
287 RXE_MEM_STATE_INVALID,
288 RXE_MEM_STATE_FREE,
289 RXE_MEM_STATE_VALID,
290};
291
292enum rxe_mem_type {
293 RXE_MEM_TYPE_NONE,
294 RXE_MEM_TYPE_DMA,
295 RXE_MEM_TYPE_MR,
296 RXE_MEM_TYPE_FMR,
297 RXE_MEM_TYPE_MW,
298};
299
300#define RXE_BUF_PER_MAP (PAGE_SIZE / sizeof(struct rxe_phys_buf))
301
302struct rxe_phys_buf {
303 u64 addr;
304 u64 size;
305};
306
307struct rxe_map {
308 struct rxe_phys_buf buf[RXE_BUF_PER_MAP];
309};
310
311struct rxe_mem {
312 struct rxe_pool_entry pelem;
313 union {
314 struct ib_mr ibmr;
315 struct ib_mw ibmw;
316 };
317
318 struct rxe_pd *pd;
319 struct ib_umem *umem;
320
321 u32 lkey;
322 u32 rkey;
323
324 enum rxe_mem_state state;
325 enum rxe_mem_type type;
326 u64 va;
327 u64 iova;
328 size_t length;
329 u32 offset;
330 int access;
331
332 int page_shift;
333 int page_mask;
334 int map_shift;
335 int map_mask;
336
337 u32 num_buf;
338 u32 nbuf;
339
340 u32 max_buf;
341 u32 num_map;
342
343 struct rxe_map **map;
344};
345
346struct rxe_mc_grp {
347 struct rxe_pool_entry pelem;
348 spinlock_t mcg_lock; /* guard group */
349 struct rxe_dev *rxe;
350 struct list_head qp_list;
351 union ib_gid mgid;
352 int num_qp;
353 u32 qkey;
354 u16 pkey;
355};
356
357struct rxe_mc_elem {
358 struct rxe_pool_entry pelem;
359 struct list_head qp_list;
360 struct list_head grp_list;
361 struct rxe_qp *qp;
362 struct rxe_mc_grp *grp;
363};
364
365struct rxe_port {
366 struct ib_port_attr attr;
367 u16 *pkey_tbl;
368 __be64 port_guid;
369 __be64 subnet_prefix;
370 spinlock_t port_lock; /* guard port */
371 unsigned int mtu_cap;
372 /* special QPs */
373 u32 qp_smi_index;
374 u32 qp_gsi_index;
375};
376
Moni Shoua8700e3e2016-06-16 16:45:23 +0300377struct rxe_dev {
378 struct ib_device ib_dev;
379 struct ib_device_attr attr;
380 int max_ucontext;
381 int max_inline_data;
382 struct kref ref_cnt;
383 struct mutex usdev_lock;
384
Moni Shoua8700e3e2016-06-16 16:45:23 +0300385 struct net_device *ndev;
386
387 int xmit_errors;
388
389 struct rxe_pool uc_pool;
390 struct rxe_pool pd_pool;
391 struct rxe_pool ah_pool;
392 struct rxe_pool srq_pool;
393 struct rxe_pool qp_pool;
394 struct rxe_pool cq_pool;
395 struct rxe_pool mr_pool;
396 struct rxe_pool mw_pool;
397 struct rxe_pool mc_grp_pool;
398 struct rxe_pool mc_elem_pool;
399
400 spinlock_t pending_lock; /* guard pending_mmaps */
401 struct list_head pending_mmaps;
402
403 spinlock_t mmap_offset_lock; /* guard mmap_offset */
404 int mmap_offset;
405
Yonatan Cohen0b1e5b92017-03-10 18:23:56 +0200406 u64 stats_counters[RXE_NUM_OF_COUNTERS];
407
Moni Shoua8700e3e2016-06-16 16:45:23 +0300408 struct rxe_port port;
409 struct list_head list;
yonatanccee26882017-04-20 20:55:55 +0300410 struct crypto_shash *tfm;
Moni Shoua8700e3e2016-06-16 16:45:23 +0300411};
412
Yonatan Cohen0b1e5b92017-03-10 18:23:56 +0200413static inline void rxe_counter_inc(struct rxe_dev *rxe, enum rxe_counters cnt)
414{
415 rxe->stats_counters[cnt]++;
416}
417
Moni Shoua8700e3e2016-06-16 16:45:23 +0300418static inline struct rxe_dev *to_rdev(struct ib_device *dev)
419{
420 return dev ? container_of(dev, struct rxe_dev, ib_dev) : NULL;
421}
422
423static inline struct rxe_ucontext *to_ruc(struct ib_ucontext *uc)
424{
425 return uc ? container_of(uc, struct rxe_ucontext, ibuc) : NULL;
426}
427
428static inline struct rxe_pd *to_rpd(struct ib_pd *pd)
429{
430 return pd ? container_of(pd, struct rxe_pd, ibpd) : NULL;
431}
432
433static inline struct rxe_ah *to_rah(struct ib_ah *ah)
434{
435 return ah ? container_of(ah, struct rxe_ah, ibah) : NULL;
436}
437
438static inline struct rxe_srq *to_rsrq(struct ib_srq *srq)
439{
440 return srq ? container_of(srq, struct rxe_srq, ibsrq) : NULL;
441}
442
443static inline struct rxe_qp *to_rqp(struct ib_qp *qp)
444{
445 return qp ? container_of(qp, struct rxe_qp, ibqp) : NULL;
446}
447
448static inline struct rxe_cq *to_rcq(struct ib_cq *cq)
449{
450 return cq ? container_of(cq, struct rxe_cq, ibcq) : NULL;
451}
452
453static inline struct rxe_mem *to_rmr(struct ib_mr *mr)
454{
455 return mr ? container_of(mr, struct rxe_mem, ibmr) : NULL;
456}
457
458static inline struct rxe_mem *to_rmw(struct ib_mw *mw)
459{
460 return mw ? container_of(mw, struct rxe_mem, ibmw) : NULL;
461}
462
463int rxe_register_device(struct rxe_dev *rxe);
464int rxe_unregister_device(struct rxe_dev *rxe);
465
Bart Van Assche32404fb2017-01-10 11:15:46 -0800466void rxe_mc_cleanup(struct rxe_pool_entry *arg);
Moni Shoua8700e3e2016-06-16 16:45:23 +0300467
468#endif /* RXE_VERBS_H */