blob: 1b51e67a26d7eaedea09ca6905452bc9b5237afe [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;
Naresh Gottumukkala7c338802013-08-26 15:27:39 +053059 u16 max_srq;
Parav Panditfe2caef2012-03-21 04:09:06 +053060 u32 max_inline_data;
61 int max_send_sge;
62 int max_recv_sge;
Mahesh Vardhamanaiah634c5792012-06-08 21:26:11 +053063 int max_srq_sge;
Naresh Gottumukkala45e86b32013-08-07 12:52:37 +053064 int max_rdma_sge;
Parav Panditfe2caef2012-03-21 04:09:06 +053065 int max_mr;
66 u64 max_mr_size;
67 u32 max_num_mr_pbl;
68 int max_fmr;
69 int max_map_per_fmr;
70 int max_pages_per_frmr;
71 u16 max_ord_per_qp;
72 u16 max_ird_per_qp;
73
74 int device_cap_flags;
75 u8 cq_overflow_detect;
76 u8 srq_supported;
77
78 u32 wqe_size;
79 u32 rqe_size;
80 u32 ird_page_size;
81 u8 local_ca_ack_delay;
82 u8 ird;
83 u8 num_ird_pages;
84};
85
86struct ocrdma_pbl {
87 void *va;
88 dma_addr_t pa;
89};
90
91struct ocrdma_queue_info {
92 void *va;
93 dma_addr_t dma;
94 u32 size;
95 u16 len;
96 u16 entry_size; /* Size of an element in the queue */
97 u16 id; /* qid, where to ring the doorbell. */
98 u16 head, tail;
99 bool created;
Parav Panditfe2caef2012-03-21 04:09:06 +0530100};
101
102struct ocrdma_eq {
103 struct ocrdma_queue_info q;
104 u32 vector;
105 int cq_cnt;
106 struct ocrdma_dev *dev;
107 char irq_name[32];
108};
109
110struct ocrdma_mq {
111 struct ocrdma_queue_info sq;
112 struct ocrdma_queue_info cq;
113 bool rearm_cq;
114};
115
116struct mqe_ctx {
117 struct mutex lock; /* for serializing mailbox commands on MQ */
118 wait_queue_head_t cmd_wait;
119 u32 tag;
120 u16 cqe_status;
121 u16 ext_status;
122 bool cmd_done;
123};
124
Naresh Gottumukkala1852d1d2013-09-06 15:02:47 +0530125struct ocrdma_hw_mr {
126 u32 lkey;
127 u8 fr_mr;
128 u8 remote_atomic;
129 u8 remote_rd;
130 u8 remote_wr;
131 u8 local_rd;
132 u8 local_wr;
133 u8 mw_bind;
134 u8 rsvd;
135 u64 len;
136 struct ocrdma_pbl *pbl_table;
137 u32 num_pbls;
138 u32 num_pbes;
139 u32 pbl_size;
140 u32 pbe_size;
141 u64 fbo;
142 u64 va;
143};
144
145struct ocrdma_mr {
146 struct ib_mr ibmr;
147 struct ib_umem *umem;
148 struct ocrdma_hw_mr hwmr;
149};
150
Parav Panditfe2caef2012-03-21 04:09:06 +0530151struct ocrdma_dev {
152 struct ib_device ibdev;
153 struct ocrdma_dev_attr attr;
154
155 struct mutex dev_lock; /* provides syncronise access to device data */
156 spinlock_t flush_q_lock ____cacheline_aligned;
157
158 struct ocrdma_cq **cq_tbl;
159 struct ocrdma_qp **qp_tbl;
160
Naresh Gottumukkalac88bd032013-08-26 15:27:41 +0530161 struct ocrdma_eq *eq_tbl;
Parav Panditfe2caef2012-03-21 04:09:06 +0530162 int eq_cnt;
163 u16 base_eqid;
164 u16 max_eq;
165
166 union ib_gid *sgid_tbl;
167 /* provided synchronization to sgid table for
168 * updating gid entries triggered by notifier.
169 */
170 spinlock_t sgid_lock;
171
172 int gsi_qp_created;
173 struct ocrdma_cq *gsi_sqcq;
174 struct ocrdma_cq *gsi_rqcq;
175
176 struct {
177 struct ocrdma_av *va;
178 dma_addr_t pa;
179 u32 size;
180 u32 num_ah;
181 /* provide synchronization for av
182 * entry allocations.
183 */
184 spinlock_t lock;
185 u32 ahid;
186 struct ocrdma_pbl pbl;
187 } av_tbl;
188
189 void *mbx_cmd;
190 struct ocrdma_mq mq;
191 struct mqe_ctx mqe_ctx;
192
193 struct be_dev_info nic_info;
194
195 struct list_head entry;
Sasha Levin3e4d60a2012-04-28 07:40:01 +0200196 struct rcu_head rcu;
Parav Panditfe2caef2012-03-21 04:09:06 +0530197 int id;
Naresh Gottumukkala1852d1d2013-09-06 15:02:47 +0530198 struct ocrdma_mr *stag_arr[OCRDMA_MAX_STAG];
Naresh Gottumukkala84b105d2013-08-26 15:27:50 +0530199 u16 pvid;
Parav Panditfe2caef2012-03-21 04:09:06 +0530200};
201
202struct ocrdma_cq {
203 struct ib_cq ibcq;
Parav Panditfe2caef2012-03-21 04:09:06 +0530204 struct ocrdma_cqe *va;
205 u32 phase;
206 u32 getp; /* pointer to pending wrs to
207 * return to stack, wrap arounds
208 * at max_hw_cqe
209 */
210 u32 max_hw_cqe;
211 bool phase_change;
Devesh Sharmaea617622014-02-04 11:56:54 +0530212 bool deferred_arm, deferred_sol;
213 bool first_arm;
Parav Panditfe2caef2012-03-21 04:09:06 +0530214
215 spinlock_t cq_lock ____cacheline_aligned; /* provide synchronization
216 * to cq polling
217 */
218 /* syncronizes cq completion handler invoked from multiple context */
219 spinlock_t comp_handler_lock ____cacheline_aligned;
220 u16 id;
221 u16 eqn;
222
223 struct ocrdma_ucontext *ucontext;
224 dma_addr_t pa;
225 u32 len;
Devesh Sharmaea617622014-02-04 11:56:54 +0530226 u32 cqe_cnt;
Parav Panditfe2caef2012-03-21 04:09:06 +0530227
228 /* head of all qp's sq and rq for which cqes need to be flushed
229 * by the software.
230 */
231 struct list_head sq_head, rq_head;
232};
233
234struct ocrdma_pd {
235 struct ib_pd ibpd;
236 struct ocrdma_dev *dev;
237 struct ocrdma_ucontext *uctx;
Parav Panditfe2caef2012-03-21 04:09:06 +0530238 u32 id;
239 int num_dpp_qp;
240 u32 dpp_page;
241 bool dpp_enabled;
242};
243
244struct ocrdma_ah {
245 struct ib_ah ibah;
Parav Panditfe2caef2012-03-21 04:09:06 +0530246 struct ocrdma_av *av;
247 u16 sgid_index;
248 u32 id;
249};
250
251struct ocrdma_qp_hwq_info {
252 u8 *va; /* virtual address */
253 u32 max_sges;
254 u32 head, tail;
255 u32 entry_size;
256 u32 max_cnt;
257 u32 max_wqe_idx;
Parav Panditfe2caef2012-03-21 04:09:06 +0530258 u16 dbid; /* qid, where to ring the doorbell. */
259 u32 len;
260 dma_addr_t pa;
261};
262
263struct ocrdma_srq {
264 struct ib_srq ibsrq;
Parav Panditfe2caef2012-03-21 04:09:06 +0530265 u8 __iomem *db;
Parav Panditfe2caef2012-03-21 04:09:06 +0530266 struct ocrdma_qp_hwq_info rq;
Parav Panditfe2caef2012-03-21 04:09:06 +0530267 u64 *rqe_wr_id_tbl;
268 u32 *idx_bit_fields;
269 u32 bit_fields_len;
Naresh Gottumukkala9884bcd2013-06-10 04:42:42 +0000270
271 /* provide synchronization to multiple context(s) posting rqe */
272 spinlock_t q_lock ____cacheline_aligned;
273
274 struct ocrdma_pd *pd;
275 u32 id;
Parav Panditfe2caef2012-03-21 04:09:06 +0530276};
277
278struct ocrdma_qp {
279 struct ib_qp ibqp;
280 struct ocrdma_dev *dev;
281
282 u8 __iomem *sq_db;
Parav Panditfe2caef2012-03-21 04:09:06 +0530283 struct ocrdma_qp_hwq_info sq;
284 struct {
285 uint64_t wrid;
286 uint16_t dpp_wqe_idx;
287 uint16_t dpp_wqe;
288 uint8_t signaled;
289 uint8_t rsvd[3];
290 } *wqe_wr_id_tbl;
291 u32 max_inline_data;
Naresh Gottumukkala9884bcd2013-06-10 04:42:42 +0000292
293 /* provide synchronization to multiple context(s) posting wqe, rqe */
294 spinlock_t q_lock ____cacheline_aligned;
Parav Panditfe2caef2012-03-21 04:09:06 +0530295 struct ocrdma_cq *sq_cq;
296 /* list maintained per CQ to flush SQ errors */
297 struct list_head sq_entry;
298
299 u8 __iomem *rq_db;
300 struct ocrdma_qp_hwq_info rq;
301 u64 *rqe_wr_id_tbl;
302 struct ocrdma_cq *rq_cq;
303 struct ocrdma_srq *srq;
304 /* list maintained per CQ to flush RQ errors */
305 struct list_head rq_entry;
306
307 enum ocrdma_qp_state state; /* QP state */
308 int cap_flags;
309 u32 max_ord, max_ird;
310
311 u32 id;
312 struct ocrdma_pd *pd;
313
314 enum ib_qp_type qp_type;
315
316 int sgid_idx;
317 u32 qkey;
318 bool dpp_enabled;
319 u8 *ird_q_va;
Naresh Gottumukkala2b51a9b2013-08-26 15:27:43 +0530320 bool signaled;
Naresh Gottumukkala45e86b32013-08-07 12:52:37 +0530321 u16 db_cache;
Parav Panditfe2caef2012-03-21 04:09:06 +0530322};
323
Parav Panditfe2caef2012-03-21 04:09:06 +0530324
325struct ocrdma_ucontext {
326 struct ib_ucontext ibucontext;
Parav Panditfe2caef2012-03-21 04:09:06 +0530327
328 struct list_head mm_head;
329 struct mutex mm_list_lock; /* protects list entries of mm type */
Naresh Gottumukkalacffce992013-08-26 15:27:44 +0530330 struct ocrdma_pd *cntxt_pd;
331 int pd_in_use;
332
Parav Panditfe2caef2012-03-21 04:09:06 +0530333 struct {
334 u32 *va;
335 dma_addr_t pa;
336 u32 len;
337 } ah_tbl;
338};
339
340struct ocrdma_mm {
341 struct {
342 u64 phy_addr;
343 unsigned long len;
344 } key;
345 struct list_head entry;
346};
347
348static inline struct ocrdma_dev *get_ocrdma_dev(struct ib_device *ibdev)
349{
350 return container_of(ibdev, struct ocrdma_dev, ibdev);
351}
352
353static inline struct ocrdma_ucontext *get_ocrdma_ucontext(struct ib_ucontext
354 *ibucontext)
355{
356 return container_of(ibucontext, struct ocrdma_ucontext, ibucontext);
357}
358
359static inline struct ocrdma_pd *get_ocrdma_pd(struct ib_pd *ibpd)
360{
361 return container_of(ibpd, struct ocrdma_pd, ibpd);
362}
363
364static inline struct ocrdma_cq *get_ocrdma_cq(struct ib_cq *ibcq)
365{
366 return container_of(ibcq, struct ocrdma_cq, ibcq);
367}
368
369static inline struct ocrdma_qp *get_ocrdma_qp(struct ib_qp *ibqp)
370{
371 return container_of(ibqp, struct ocrdma_qp, ibqp);
372}
373
374static inline struct ocrdma_mr *get_ocrdma_mr(struct ib_mr *ibmr)
375{
376 return container_of(ibmr, struct ocrdma_mr, ibmr);
377}
378
379static inline struct ocrdma_ah *get_ocrdma_ah(struct ib_ah *ibah)
380{
381 return container_of(ibah, struct ocrdma_ah, ibah);
382}
383
384static inline struct ocrdma_srq *get_ocrdma_srq(struct ib_srq *ibsrq)
385{
386 return container_of(ibsrq, struct ocrdma_srq, ibsrq);
387}
388
Naresh Gottumukkaladf176ea2013-06-10 04:42:41 +0000389static inline int is_cqe_valid(struct ocrdma_cq *cq, struct ocrdma_cqe *cqe)
390{
391 int cqe_valid;
392 cqe_valid = le32_to_cpu(cqe->flags_status_srcqpn) & OCRDMA_CQE_VALID;
Naresh Gottumukkalaf99b1642013-08-07 12:52:32 +0530393 return (cqe_valid == cq->phase);
Naresh Gottumukkaladf176ea2013-06-10 04:42:41 +0000394}
395
396static inline int is_cqe_for_sq(struct ocrdma_cqe *cqe)
397{
398 return (le32_to_cpu(cqe->flags_status_srcqpn) &
399 OCRDMA_CQE_QTYPE) ? 0 : 1;
400}
401
402static inline int is_cqe_invalidated(struct ocrdma_cqe *cqe)
403{
404 return (le32_to_cpu(cqe->flags_status_srcqpn) &
405 OCRDMA_CQE_INVALIDATE) ? 1 : 0;
406}
407
408static inline int is_cqe_imm(struct ocrdma_cqe *cqe)
409{
410 return (le32_to_cpu(cqe->flags_status_srcqpn) &
411 OCRDMA_CQE_IMM) ? 1 : 0;
412}
413
414static inline int is_cqe_wr_imm(struct ocrdma_cqe *cqe)
415{
416 return (le32_to_cpu(cqe->flags_status_srcqpn) &
417 OCRDMA_CQE_WRITE_IMM) ? 1 : 0;
418}
419
Moni Shoua40aca6f2013-12-12 18:03:15 +0200420static inline int ocrdma_resolve_dmac(struct ocrdma_dev *dev,
421 struct ib_ah_attr *ah_attr, u8 *mac_addr)
422{
423 struct in6_addr in6;
424
425 memcpy(&in6, ah_attr->grh.dgid.raw, sizeof(in6));
426 if (rdma_is_multicast_addr(&in6))
427 rdma_get_mcast_mac(&in6, mac_addr);
428 else
429 memcpy(mac_addr, ah_attr->dmac, ETH_ALEN);
430 return 0;
431}
Naresh Gottumukkaladf176ea2013-06-10 04:42:41 +0000432
Devesh Sharmaea617622014-02-04 11:56:54 +0530433static inline int ocrdma_get_eq_table_index(struct ocrdma_dev *dev,
434 int eqid)
435{
436 int indx;
437
438 for (indx = 0; indx < dev->eq_cnt; indx++) {
439 if (dev->eq_tbl[indx].q.id == eqid)
440 return indx;
441 }
442
443 return -EINVAL;
444}
445
Parav Panditfe2caef2012-03-21 04:09:06 +0530446#endif