]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/infiniband/hw/ocrdma/ocrdma.h
4ea8496c7107ad5335a21f4385774f13b28cca44
[karo-tx-linux.git] / drivers / infiniband / hw / ocrdma / ocrdma.h
1 /*******************************************************************
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_DRV_VERSION "10.2.145.0u"
43
44 #define OCRDMA_ROCE_DRV_DESC "Emulex OneConnect RoCE Driver"
45 #define OCRDMA_NODE_DESC "Emulex OneConnect RoCE HCA"
46
47 #define OCRDMA_MAX_AH 512
48
49 #define OCRDMA_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
50
51 struct ocrdma_dev_attr {
52         u8 fw_ver[32];
53         u32 vendor_id;
54         u32 device_id;
55         u16 max_pd;
56         u16 max_cq;
57         u16 max_cqe;
58         u16 max_qp;
59         u16 max_wqe;
60         u16 max_rqe;
61         u16 max_srq;
62         u32 max_inline_data;
63         int max_send_sge;
64         int max_recv_sge;
65         int max_srq_sge;
66         int max_rdma_sge;
67         int max_mr;
68         u64 max_mr_size;
69         u32 max_num_mr_pbl;
70         int max_mw;
71         int max_fmr;
72         int max_map_per_fmr;
73         int max_pages_per_frmr;
74         u16 max_ord_per_qp;
75         u16 max_ird_per_qp;
76
77         int device_cap_flags;
78         u8 cq_overflow_detect;
79         u8 srq_supported;
80
81         u32 wqe_size;
82         u32 rqe_size;
83         u32 ird_page_size;
84         u8 local_ca_ack_delay;
85         u8 ird;
86         u8 num_ird_pages;
87 };
88
89 struct ocrdma_pbl {
90         void *va;
91         dma_addr_t pa;
92 };
93
94 struct ocrdma_queue_info {
95         void *va;
96         dma_addr_t dma;
97         u32 size;
98         u16 len;
99         u16 entry_size;         /* Size of an element in the queue */
100         u16 id;                 /* qid, where to ring the doorbell. */
101         u16 head, tail;
102         bool created;
103 };
104
105 struct ocrdma_eq {
106         struct ocrdma_queue_info q;
107         u32 vector;
108         int cq_cnt;
109         struct ocrdma_dev *dev;
110         char irq_name[32];
111 };
112
113 struct ocrdma_mq {
114         struct ocrdma_queue_info sq;
115         struct ocrdma_queue_info cq;
116         bool rearm_cq;
117 };
118
119 struct mqe_ctx {
120         struct mutex lock; /* for serializing mailbox commands on MQ */
121         wait_queue_head_t cmd_wait;
122         u32 tag;
123         u16 cqe_status;
124         u16 ext_status;
125         bool cmd_done;
126 };
127
128 struct ocrdma_hw_mr {
129         u32 lkey;
130         u8 fr_mr;
131         u8 remote_atomic;
132         u8 remote_rd;
133         u8 remote_wr;
134         u8 local_rd;
135         u8 local_wr;
136         u8 mw_bind;
137         u8 rsvd;
138         u64 len;
139         struct ocrdma_pbl *pbl_table;
140         u32 num_pbls;
141         u32 num_pbes;
142         u32 pbl_size;
143         u32 pbe_size;
144         u64 fbo;
145         u64 va;
146 };
147
148 struct ocrdma_mr {
149         struct ib_mr ibmr;
150         struct ib_umem *umem;
151         struct ocrdma_hw_mr hwmr;
152 };
153
154 struct ocrdma_dev {
155         struct ib_device ibdev;
156         struct ocrdma_dev_attr attr;
157
158         struct mutex dev_lock; /* provides syncronise access to device data */
159         spinlock_t flush_q_lock ____cacheline_aligned;
160
161         struct ocrdma_cq **cq_tbl;
162         struct ocrdma_qp **qp_tbl;
163
164         struct ocrdma_eq *eq_tbl;
165         int eq_cnt;
166         u16 base_eqid;
167         u16 max_eq;
168
169         union ib_gid *sgid_tbl;
170         /* provided synchronization to sgid table for
171          * updating gid entries triggered by notifier.
172          */
173         spinlock_t sgid_lock;
174
175         int gsi_qp_created;
176         struct ocrdma_cq *gsi_sqcq;
177         struct ocrdma_cq *gsi_rqcq;
178
179         struct {
180                 struct ocrdma_av *va;
181                 dma_addr_t pa;
182                 u32 size;
183                 u32 num_ah;
184                 /* provide synchronization for av
185                  * entry allocations.
186                  */
187                 spinlock_t lock;
188                 u32 ahid;
189                 struct ocrdma_pbl pbl;
190         } av_tbl;
191
192         void *mbx_cmd;
193         struct ocrdma_mq mq;
194         struct mqe_ctx mqe_ctx;
195
196         struct be_dev_info nic_info;
197
198         struct list_head entry;
199         struct rcu_head rcu;
200         int id;
201         struct ocrdma_mr *stag_arr[OCRDMA_MAX_STAG];
202         u16 pvid;
203         u32 asic_id;
204 };
205
206 struct ocrdma_cq {
207         struct ib_cq ibcq;
208         struct ocrdma_cqe *va;
209         u32 phase;
210         u32 getp;       /* pointer to pending wrs to
211                          * return to stack, wrap arounds
212                          * at max_hw_cqe
213                          */
214         u32 max_hw_cqe;
215         bool phase_change;
216         bool deferred_arm, deferred_sol;
217         bool first_arm;
218
219         spinlock_t cq_lock ____cacheline_aligned; /* provide synchronization
220                                                    * to cq polling
221                                                    */
222         /* syncronizes cq completion handler invoked from multiple context */
223         spinlock_t comp_handler_lock ____cacheline_aligned;
224         u16 id;
225         u16 eqn;
226
227         struct ocrdma_ucontext *ucontext;
228         dma_addr_t pa;
229         u32 len;
230         u32 cqe_cnt;
231
232         /* head of all qp's sq and rq for which cqes need to be flushed
233          * by the software.
234          */
235         struct list_head sq_head, rq_head;
236 };
237
238 struct ocrdma_pd {
239         struct ib_pd ibpd;
240         struct ocrdma_dev *dev;
241         struct ocrdma_ucontext *uctx;
242         u32 id;
243         int num_dpp_qp;
244         u32 dpp_page;
245         bool dpp_enabled;
246 };
247
248 struct ocrdma_ah {
249         struct ib_ah ibah;
250         struct ocrdma_av *av;
251         u16 sgid_index;
252         u32 id;
253 };
254
255 struct ocrdma_qp_hwq_info {
256         u8 *va;                 /* virtual address */
257         u32 max_sges;
258         u32 head, tail;
259         u32 entry_size;
260         u32 max_cnt;
261         u32 max_wqe_idx;
262         u16 dbid;               /* qid, where to ring the doorbell. */
263         u32 len;
264         dma_addr_t pa;
265 };
266
267 struct ocrdma_srq {
268         struct ib_srq ibsrq;
269         u8 __iomem *db;
270         struct ocrdma_qp_hwq_info rq;
271         u64 *rqe_wr_id_tbl;
272         u32 *idx_bit_fields;
273         u32 bit_fields_len;
274
275         /* provide synchronization to multiple context(s) posting rqe */
276         spinlock_t q_lock ____cacheline_aligned;
277
278         struct ocrdma_pd *pd;
279         u32 id;
280 };
281
282 struct ocrdma_qp {
283         struct ib_qp ibqp;
284         struct ocrdma_dev *dev;
285
286         u8 __iomem *sq_db;
287         struct ocrdma_qp_hwq_info sq;
288         struct {
289                 uint64_t wrid;
290                 uint16_t dpp_wqe_idx;
291                 uint16_t dpp_wqe;
292                 uint8_t  signaled;
293                 uint8_t  rsvd[3];
294         } *wqe_wr_id_tbl;
295         u32 max_inline_data;
296
297         /* provide synchronization to multiple context(s) posting wqe, rqe */
298         spinlock_t q_lock ____cacheline_aligned;
299         struct ocrdma_cq *sq_cq;
300         /* list maintained per CQ to flush SQ errors */
301         struct list_head sq_entry;
302
303         u8 __iomem *rq_db;
304         struct ocrdma_qp_hwq_info rq;
305         u64 *rqe_wr_id_tbl;
306         struct ocrdma_cq *rq_cq;
307         struct ocrdma_srq *srq;
308         /* list maintained per CQ to flush RQ errors */
309         struct list_head rq_entry;
310
311         enum ocrdma_qp_state state;     /*  QP state */
312         int cap_flags;
313         u32 max_ord, max_ird;
314
315         u32 id;
316         struct ocrdma_pd *pd;
317
318         enum ib_qp_type qp_type;
319
320         int sgid_idx;
321         u32 qkey;
322         bool dpp_enabled;
323         u8 *ird_q_va;
324         bool signaled;
325         u16 db_cache;
326 };
327
328
329 struct ocrdma_ucontext {
330         struct ib_ucontext ibucontext;
331
332         struct list_head mm_head;
333         struct mutex mm_list_lock; /* protects list entries of mm type */
334         struct ocrdma_pd *cntxt_pd;
335         int pd_in_use;
336
337         struct {
338                 u32 *va;
339                 dma_addr_t pa;
340                 u32 len;
341         } ah_tbl;
342 };
343
344 struct ocrdma_mm {
345         struct {
346                 u64 phy_addr;
347                 unsigned long len;
348         } key;
349         struct list_head entry;
350 };
351
352 static inline struct ocrdma_dev *get_ocrdma_dev(struct ib_device *ibdev)
353 {
354         return container_of(ibdev, struct ocrdma_dev, ibdev);
355 }
356
357 static inline struct ocrdma_ucontext *get_ocrdma_ucontext(struct ib_ucontext
358                                                           *ibucontext)
359 {
360         return container_of(ibucontext, struct ocrdma_ucontext, ibucontext);
361 }
362
363 static inline struct ocrdma_pd *get_ocrdma_pd(struct ib_pd *ibpd)
364 {
365         return container_of(ibpd, struct ocrdma_pd, ibpd);
366 }
367
368 static inline struct ocrdma_cq *get_ocrdma_cq(struct ib_cq *ibcq)
369 {
370         return container_of(ibcq, struct ocrdma_cq, ibcq);
371 }
372
373 static inline struct ocrdma_qp *get_ocrdma_qp(struct ib_qp *ibqp)
374 {
375         return container_of(ibqp, struct ocrdma_qp, ibqp);
376 }
377
378 static inline struct ocrdma_mr *get_ocrdma_mr(struct ib_mr *ibmr)
379 {
380         return container_of(ibmr, struct ocrdma_mr, ibmr);
381 }
382
383 static inline struct ocrdma_ah *get_ocrdma_ah(struct ib_ah *ibah)
384 {
385         return container_of(ibah, struct ocrdma_ah, ibah);
386 }
387
388 static inline struct ocrdma_srq *get_ocrdma_srq(struct ib_srq *ibsrq)
389 {
390         return container_of(ibsrq, struct ocrdma_srq, ibsrq);
391 }
392
393 static inline int is_cqe_valid(struct ocrdma_cq *cq, struct ocrdma_cqe *cqe)
394 {
395         int cqe_valid;
396         cqe_valid = le32_to_cpu(cqe->flags_status_srcqpn) & OCRDMA_CQE_VALID;
397         return (cqe_valid == cq->phase);
398 }
399
400 static inline int is_cqe_for_sq(struct ocrdma_cqe *cqe)
401 {
402         return (le32_to_cpu(cqe->flags_status_srcqpn) &
403                 OCRDMA_CQE_QTYPE) ? 0 : 1;
404 }
405
406 static inline int is_cqe_invalidated(struct ocrdma_cqe *cqe)
407 {
408         return (le32_to_cpu(cqe->flags_status_srcqpn) &
409                 OCRDMA_CQE_INVALIDATE) ? 1 : 0;
410 }
411
412 static inline int is_cqe_imm(struct ocrdma_cqe *cqe)
413 {
414         return (le32_to_cpu(cqe->flags_status_srcqpn) &
415                 OCRDMA_CQE_IMM) ? 1 : 0;
416 }
417
418 static inline int is_cqe_wr_imm(struct ocrdma_cqe *cqe)
419 {
420         return (le32_to_cpu(cqe->flags_status_srcqpn) &
421                 OCRDMA_CQE_WRITE_IMM) ? 1 : 0;
422 }
423
424 static inline int ocrdma_resolve_dmac(struct ocrdma_dev *dev,
425                 struct ib_ah_attr *ah_attr, u8 *mac_addr)
426 {
427         struct in6_addr in6;
428
429         memcpy(&in6, ah_attr->grh.dgid.raw, sizeof(in6));
430         if (rdma_is_multicast_addr(&in6))
431                 rdma_get_mcast_mac(&in6, mac_addr);
432         else
433                 memcpy(mac_addr, ah_attr->dmac, ETH_ALEN);
434         return 0;
435 }
436
437 static inline int ocrdma_get_eq_table_index(struct ocrdma_dev *dev,
438                 int eqid)
439 {
440         int indx;
441
442         for (indx = 0; indx < dev->eq_cnt; indx++) {
443                 if (dev->eq_tbl[indx].q.id == eqid)
444                         return indx;
445         }
446
447         return -EINVAL;
448 }
449
450 static inline u8 ocrdma_get_asic_type(struct ocrdma_dev *dev)
451 {
452         if (dev->nic_info.dev_family == 0xF && !dev->asic_id) {
453                 pci_read_config_dword(
454                         dev->nic_info.pdev,
455                         OCRDMA_SLI_ASIC_ID_OFFSET, &dev->asic_id);
456         }
457
458         return (dev->asic_id & OCRDMA_SLI_ASIC_GEN_NUM_MASK) >>
459                                 OCRDMA_SLI_ASIC_GEN_NUM_SHIFT;
460 }
461
462 #endif