blob: e798837f1fe0dcb250bbdb3ef750d578147dae3c [file] [log] [blame]
Parav Panditfe2caef2012-03-21 04:09:06 +05301/*******************************************************************
2 * This file is part of the Emulex RoCE Device Driver for *
3 * RoCE (RDMA over Converged Ethernet) adapters. *
4 * Copyright (C) 2008-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *
20 * Contact Information:
21 * linux-drivers@emulex.com
22 *
23 * Emulex
24 * 3333 Susan Street
25 * Costa Mesa, CA 92626
26 *******************************************************************/
27
28#ifndef __OCRDMA_H__
29#define __OCRDMA_H__
30
31#include <linux/mutex.h>
32#include <linux/list.h>
33#include <linux/spinlock.h>
34#include <linux/pci.h>
35
36#include <rdma/ib_verbs.h>
37#include <rdma/ib_user_verbs.h>
38
39#include <be_roce.h>
40#include "ocrdma_sli.h"
41
42#define OCRDMA_ROCE_DEV_VERSION "1.0.0"
43#define OCRDMA_NODE_DESC "Emulex OneConnect RoCE HCA"
44
Parav Panditfe2caef2012-03-21 04:09:06 +053045#define OCRDMA_MAX_AH 512
46
47#define OCRDMA_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
48
49struct ocrdma_dev_attr {
50 u8 fw_ver[32];
51 u32 vendor_id;
52 u32 device_id;
53 u16 max_pd;
54 u16 max_cq;
55 u16 max_cqe;
56 u16 max_qp;
57 u16 max_wqe;
58 u16 max_rqe;
59 u32 max_inline_data;
60 int max_send_sge;
61 int max_recv_sge;
Mahesh Vardhamanaiah634c5792012-06-08 21:26:11 +053062 int max_srq_sge;
Naresh Gottumukkala45e86b32013-08-07 12:52:37 +053063 int max_rdma_sge;
Parav Panditfe2caef2012-03-21 04:09:06 +053064 int max_mr;
65 u64 max_mr_size;
66 u32 max_num_mr_pbl;
67 int max_fmr;
68 int max_map_per_fmr;
69 int max_pages_per_frmr;
70 u16 max_ord_per_qp;
71 u16 max_ird_per_qp;
72
73 int device_cap_flags;
74 u8 cq_overflow_detect;
75 u8 srq_supported;
76
77 u32 wqe_size;
78 u32 rqe_size;
79 u32 ird_page_size;
80 u8 local_ca_ack_delay;
81 u8 ird;
82 u8 num_ird_pages;
83};
84
85struct ocrdma_pbl {
86 void *va;
87 dma_addr_t pa;
88};
89
90struct ocrdma_queue_info {
91 void *va;
92 dma_addr_t dma;
93 u32 size;
94 u16 len;
95 u16 entry_size; /* Size of an element in the queue */
96 u16 id; /* qid, where to ring the doorbell. */
97 u16 head, tail;
98 bool created;
Parav Panditfe2caef2012-03-21 04:09:06 +053099};
100
101struct ocrdma_eq {
102 struct ocrdma_queue_info q;
103 u32 vector;
104 int cq_cnt;
105 struct ocrdma_dev *dev;
106 char irq_name[32];
107};
108
109struct ocrdma_mq {
110 struct ocrdma_queue_info sq;
111 struct ocrdma_queue_info cq;
112 bool rearm_cq;
113};
114
115struct mqe_ctx {
116 struct mutex lock; /* for serializing mailbox commands on MQ */
117 wait_queue_head_t cmd_wait;
118 u32 tag;
119 u16 cqe_status;
120 u16 ext_status;
121 bool cmd_done;
122};
123
124struct ocrdma_dev {
125 struct ib_device ibdev;
126 struct ocrdma_dev_attr attr;
127
128 struct mutex dev_lock; /* provides syncronise access to device data */
129 spinlock_t flush_q_lock ____cacheline_aligned;
130
131 struct ocrdma_cq **cq_tbl;
132 struct ocrdma_qp **qp_tbl;
133
134 struct ocrdma_eq meq;
135 struct ocrdma_eq *qp_eq_tbl;
136 int eq_cnt;
137 u16 base_eqid;
138 u16 max_eq;
139
140 union ib_gid *sgid_tbl;
141 /* provided synchronization to sgid table for
142 * updating gid entries triggered by notifier.
143 */
144 spinlock_t sgid_lock;
145
146 int gsi_qp_created;
147 struct ocrdma_cq *gsi_sqcq;
148 struct ocrdma_cq *gsi_rqcq;
149
150 struct {
151 struct ocrdma_av *va;
152 dma_addr_t pa;
153 u32 size;
154 u32 num_ah;
155 /* provide synchronization for av
156 * entry allocations.
157 */
158 spinlock_t lock;
159 u32 ahid;
160 struct ocrdma_pbl pbl;
161 } av_tbl;
162
163 void *mbx_cmd;
164 struct ocrdma_mq mq;
165 struct mqe_ctx mqe_ctx;
166
167 struct be_dev_info nic_info;
168
169 struct list_head entry;
Sasha Levin3e4d60a2012-04-28 07:40:01 +0200170 struct rcu_head rcu;
Parav Panditfe2caef2012-03-21 04:09:06 +0530171 int id;
172};
173
174struct ocrdma_cq {
175 struct ib_cq ibcq;
Parav Panditfe2caef2012-03-21 04:09:06 +0530176 struct ocrdma_cqe *va;
177 u32 phase;
178 u32 getp; /* pointer to pending wrs to
179 * return to stack, wrap arounds
180 * at max_hw_cqe
181 */
182 u32 max_hw_cqe;
183 bool phase_change;
184 bool armed, solicited;
185 bool arm_needed;
186
187 spinlock_t cq_lock ____cacheline_aligned; /* provide synchronization
188 * to cq polling
189 */
190 /* syncronizes cq completion handler invoked from multiple context */
191 spinlock_t comp_handler_lock ____cacheline_aligned;
192 u16 id;
193 u16 eqn;
194
195 struct ocrdma_ucontext *ucontext;
196 dma_addr_t pa;
197 u32 len;
Parav Panditfe2caef2012-03-21 04:09:06 +0530198
199 /* head of all qp's sq and rq for which cqes need to be flushed
200 * by the software.
201 */
202 struct list_head sq_head, rq_head;
203};
204
205struct ocrdma_pd {
206 struct ib_pd ibpd;
207 struct ocrdma_dev *dev;
208 struct ocrdma_ucontext *uctx;
Parav Panditfe2caef2012-03-21 04:09:06 +0530209 u32 id;
210 int num_dpp_qp;
211 u32 dpp_page;
212 bool dpp_enabled;
213};
214
215struct ocrdma_ah {
216 struct ib_ah ibah;
Parav Panditfe2caef2012-03-21 04:09:06 +0530217 struct ocrdma_av *av;
218 u16 sgid_index;
219 u32 id;
220};
221
222struct ocrdma_qp_hwq_info {
223 u8 *va; /* virtual address */
224 u32 max_sges;
225 u32 head, tail;
226 u32 entry_size;
227 u32 max_cnt;
228 u32 max_wqe_idx;
Parav Panditfe2caef2012-03-21 04:09:06 +0530229 u16 dbid; /* qid, where to ring the doorbell. */
230 u32 len;
231 dma_addr_t pa;
232};
233
234struct ocrdma_srq {
235 struct ib_srq ibsrq;
Parav Panditfe2caef2012-03-21 04:09:06 +0530236 u8 __iomem *db;
Parav Panditfe2caef2012-03-21 04:09:06 +0530237 struct ocrdma_qp_hwq_info rq;
Parav Panditfe2caef2012-03-21 04:09:06 +0530238 u64 *rqe_wr_id_tbl;
239 u32 *idx_bit_fields;
240 u32 bit_fields_len;
Naresh Gottumukkala9884bcd2013-06-10 04:42:42 +0000241
242 /* provide synchronization to multiple context(s) posting rqe */
243 spinlock_t q_lock ____cacheline_aligned;
244
245 struct ocrdma_pd *pd;
246 u32 id;
Parav Panditfe2caef2012-03-21 04:09:06 +0530247};
248
249struct ocrdma_qp {
250 struct ib_qp ibqp;
251 struct ocrdma_dev *dev;
252
253 u8 __iomem *sq_db;
Parav Panditfe2caef2012-03-21 04:09:06 +0530254 struct ocrdma_qp_hwq_info sq;
255 struct {
256 uint64_t wrid;
257 uint16_t dpp_wqe_idx;
258 uint16_t dpp_wqe;
259 uint8_t signaled;
260 uint8_t rsvd[3];
261 } *wqe_wr_id_tbl;
262 u32 max_inline_data;
Naresh Gottumukkala9884bcd2013-06-10 04:42:42 +0000263
264 /* provide synchronization to multiple context(s) posting wqe, rqe */
265 spinlock_t q_lock ____cacheline_aligned;
Parav Panditfe2caef2012-03-21 04:09:06 +0530266 struct ocrdma_cq *sq_cq;
267 /* list maintained per CQ to flush SQ errors */
268 struct list_head sq_entry;
269
270 u8 __iomem *rq_db;
271 struct ocrdma_qp_hwq_info rq;
272 u64 *rqe_wr_id_tbl;
273 struct ocrdma_cq *rq_cq;
274 struct ocrdma_srq *srq;
275 /* list maintained per CQ to flush RQ errors */
276 struct list_head rq_entry;
277
278 enum ocrdma_qp_state state; /* QP state */
279 int cap_flags;
280 u32 max_ord, max_ird;
281
282 u32 id;
283 struct ocrdma_pd *pd;
284
285 enum ib_qp_type qp_type;
286
287 int sgid_idx;
288 u32 qkey;
289 bool dpp_enabled;
290 u8 *ird_q_va;
Naresh Gottumukkala45e86b32013-08-07 12:52:37 +0530291 u16 db_cache;
Parav Panditfe2caef2012-03-21 04:09:06 +0530292};
293
Parav Panditfe2caef2012-03-21 04:09:06 +0530294struct ocrdma_hw_mr {
Parav Panditfe2caef2012-03-21 04:09:06 +0530295 u32 lkey;
296 u8 fr_mr;
297 u8 remote_atomic;
298 u8 remote_rd;
299 u8 remote_wr;
300 u8 local_rd;
301 u8 local_wr;
302 u8 mw_bind;
303 u8 rsvd;
304 u64 len;
305 struct ocrdma_pbl *pbl_table;
306 u32 num_pbls;
307 u32 num_pbes;
308 u32 pbl_size;
309 u32 pbe_size;
310 u64 fbo;
311 u64 va;
312};
313
314struct ocrdma_mr {
315 struct ib_mr ibmr;
316 struct ib_umem *umem;
317 struct ocrdma_hw_mr hwmr;
Parav Panditfe2caef2012-03-21 04:09:06 +0530318};
319
320struct ocrdma_ucontext {
321 struct ib_ucontext ibucontext;
Parav Panditfe2caef2012-03-21 04:09:06 +0530322
323 struct list_head mm_head;
324 struct mutex mm_list_lock; /* protects list entries of mm type */
325 struct {
326 u32 *va;
327 dma_addr_t pa;
328 u32 len;
329 } ah_tbl;
330};
331
332struct ocrdma_mm {
333 struct {
334 u64 phy_addr;
335 unsigned long len;
336 } key;
337 struct list_head entry;
338};
339
340static inline struct ocrdma_dev *get_ocrdma_dev(struct ib_device *ibdev)
341{
342 return container_of(ibdev, struct ocrdma_dev, ibdev);
343}
344
345static inline struct ocrdma_ucontext *get_ocrdma_ucontext(struct ib_ucontext
346 *ibucontext)
347{
348 return container_of(ibucontext, struct ocrdma_ucontext, ibucontext);
349}
350
351static inline struct ocrdma_pd *get_ocrdma_pd(struct ib_pd *ibpd)
352{
353 return container_of(ibpd, struct ocrdma_pd, ibpd);
354}
355
356static inline struct ocrdma_cq *get_ocrdma_cq(struct ib_cq *ibcq)
357{
358 return container_of(ibcq, struct ocrdma_cq, ibcq);
359}
360
361static inline struct ocrdma_qp *get_ocrdma_qp(struct ib_qp *ibqp)
362{
363 return container_of(ibqp, struct ocrdma_qp, ibqp);
364}
365
366static inline struct ocrdma_mr *get_ocrdma_mr(struct ib_mr *ibmr)
367{
368 return container_of(ibmr, struct ocrdma_mr, ibmr);
369}
370
371static inline struct ocrdma_ah *get_ocrdma_ah(struct ib_ah *ibah)
372{
373 return container_of(ibah, struct ocrdma_ah, ibah);
374}
375
376static inline struct ocrdma_srq *get_ocrdma_srq(struct ib_srq *ibsrq)
377{
378 return container_of(ibsrq, struct ocrdma_srq, ibsrq);
379}
380
Naresh Gottumukkaladf176ea2013-06-10 04:42:41 +0000381
382static inline int ocrdma_get_num_posted_shift(struct ocrdma_qp *qp)
383{
384 return ((qp->dev->nic_info.dev_family == OCRDMA_GEN2_FAMILY &&
385 qp->id < 64) ? 24 : 16);
386}
387
388static inline int is_cqe_valid(struct ocrdma_cq *cq, struct ocrdma_cqe *cqe)
389{
390 int cqe_valid;
391 cqe_valid = le32_to_cpu(cqe->flags_status_srcqpn) & OCRDMA_CQE_VALID;
Naresh Gottumukkalaf99b1642013-08-07 12:52:32 +0530392 return (cqe_valid == cq->phase);
Naresh Gottumukkaladf176ea2013-06-10 04:42:41 +0000393}
394
395static inline int is_cqe_for_sq(struct ocrdma_cqe *cqe)
396{
397 return (le32_to_cpu(cqe->flags_status_srcqpn) &
398 OCRDMA_CQE_QTYPE) ? 0 : 1;
399}
400
401static inline int is_cqe_invalidated(struct ocrdma_cqe *cqe)
402{
403 return (le32_to_cpu(cqe->flags_status_srcqpn) &
404 OCRDMA_CQE_INVALIDATE) ? 1 : 0;
405}
406
407static inline int is_cqe_imm(struct ocrdma_cqe *cqe)
408{
409 return (le32_to_cpu(cqe->flags_status_srcqpn) &
410 OCRDMA_CQE_IMM) ? 1 : 0;
411}
412
413static inline int is_cqe_wr_imm(struct ocrdma_cqe *cqe)
414{
415 return (le32_to_cpu(cqe->flags_status_srcqpn) &
416 OCRDMA_CQE_WRITE_IMM) ? 1 : 0;
417}
418
419
Parav Panditfe2caef2012-03-21 04:09:06 +0530420#endif