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