IB/ehca: Add "port connection autodetect mode"
[pandora-kernel.git] / drivers / infiniband / hw / ehca / ehca_classes.h
1 /*
2  *  IBM eServer eHCA Infiniband device driver for Linux on POWER
3  *
4  *  Struct definition for eHCA internal structures
5  *
6  *  Authors: Heiko J Schick <schickhj@de.ibm.com>
7  *           Christoph Raisch <raisch@de.ibm.com>
8  *           Joachim Fenkes <fenkes@de.ibm.com>
9  *
10  *  Copyright (c) 2005 IBM Corporation
11  *
12  *  All rights reserved.
13  *
14  *  This source code is distributed under a dual license of GPL v2.0 and OpenIB
15  *  BSD.
16  *
17  * OpenIB BSD License
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are met:
21  *
22  * Redistributions of source code must retain the above copyright notice, this
23  * list of conditions and the following disclaimer.
24  *
25  * Redistributions in binary form must reproduce the above copyright notice,
26  * this list of conditions and the following disclaimer in the documentation
27  * and/or other materials
28  * provided with the distribution.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
37  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
38  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40  * POSSIBILITY OF SUCH DAMAGE.
41  */
42
43 #ifndef __EHCA_CLASSES_H__
44 #define __EHCA_CLASSES_H__
45
46 struct ehca_module;
47 struct ehca_qp;
48 struct ehca_cq;
49 struct ehca_eq;
50 struct ehca_mr;
51 struct ehca_mw;
52 struct ehca_pd;
53 struct ehca_av;
54
55 #include <linux/wait.h>
56 #include <linux/mutex.h>
57
58 #include <rdma/ib_verbs.h>
59 #include <rdma/ib_user_verbs.h>
60
61 #ifdef CONFIG_PPC64
62 #include "ehca_classes_pSeries.h"
63 #endif
64 #include "ipz_pt_fn.h"
65 #include "ehca_qes.h"
66 #include "ehca_irq.h"
67
68 #define EHCA_EQE_CACHE_SIZE 20
69
70 struct ehca_eqe_cache_entry {
71         struct ehca_eqe *eqe;
72         struct ehca_cq *cq;
73 };
74
75 struct ehca_eq {
76         u32 length;
77         struct ipz_queue ipz_queue;
78         struct ipz_eq_handle ipz_eq_handle;
79         struct work_struct work;
80         struct h_galpas galpas;
81         int is_initialized;
82         struct ehca_pfeq pf;
83         spinlock_t spinlock;
84         struct tasklet_struct interrupt_task;
85         u32 ist;
86         spinlock_t irq_spinlock;
87         struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
88 };
89
90 struct ehca_sma_attr {
91         u16 lid, lmc, sm_sl, sm_lid;
92         u16 pkey_tbl_len, pkeys[16];
93 };
94
95 struct ehca_sport {
96         struct ib_cq *ibcq_aqp1;
97         struct ib_qp *ibqp_sqp[2];
98         /* lock to serialze modify_qp() calls for sqp in normal
99          * and irq path (when event PORT_ACTIVE is received first time)
100          */
101         spinlock_t mod_sqp_lock;
102         enum ib_port_state port_state;
103         struct ehca_sma_attr saved_attr;
104 };
105
106 #define HCA_CAP_MR_PGSIZE_4K  0x80000000
107 #define HCA_CAP_MR_PGSIZE_64K 0x40000000
108 #define HCA_CAP_MR_PGSIZE_1M  0x20000000
109 #define HCA_CAP_MR_PGSIZE_16M 0x10000000
110
111 struct ehca_shca {
112         struct ib_device ib_device;
113         struct of_device *ofdev;
114         u8 num_ports;
115         int hw_level;
116         struct list_head shca_list;
117         struct ipz_adapter_handle ipz_hca_handle;
118         struct ehca_sport sport[2];
119         struct ehca_eq eq;
120         struct ehca_eq neq;
121         struct ehca_mr *maxmr;
122         struct ehca_pd *pd;
123         struct h_galpas galpas;
124         struct mutex modify_mutex;
125         u64 hca_cap;
126         /* MR pgsize: bit 0-3 means 4K, 64K, 1M, 16M respectively */
127         u32 hca_cap_mr_pgsize;
128         int max_mtu;
129 };
130
131 struct ehca_pd {
132         struct ib_pd ib_pd;
133         struct ipz_pd fw_pd;
134         u32 ownpid;
135         /* small queue mgmt */
136         struct mutex lock;
137         struct list_head free[2];
138         struct list_head full[2];
139 };
140
141 enum ehca_ext_qp_type {
142         EQPT_NORMAL    = 0,
143         EQPT_LLQP      = 1,
144         EQPT_SRQBASE   = 2,
145         EQPT_SRQ       = 3,
146 };
147
148 /* struct to cache modify_qp()'s parms for GSI/SMI qp */
149 struct ehca_mod_qp_parm {
150         int mask;
151         struct ib_qp_attr attr;
152 };
153
154 #define EHCA_MOD_QP_PARM_MAX 4
155
156 struct ehca_qp {
157         union {
158                 struct ib_qp ib_qp;
159                 struct ib_srq ib_srq;
160         };
161         u32 qp_type;
162         enum ehca_ext_qp_type ext_type;
163         struct ipz_queue ipz_squeue;
164         struct ipz_queue ipz_rqueue;
165         struct h_galpas galpas;
166         u32 qkey;
167         u32 real_qp_num;
168         u32 token;
169         spinlock_t spinlock_s;
170         spinlock_t spinlock_r;
171         u32 sq_max_inline_data_size;
172         struct ipz_qp_handle ipz_qp_handle;
173         struct ehca_pfqp pf;
174         struct ib_qp_init_attr init_attr;
175         struct ehca_cq *send_cq;
176         struct ehca_cq *recv_cq;
177         unsigned int sqerr_purgeflag;
178         struct hlist_node list_entries;
179         /* array to cache modify_qp()'s parms for GSI/SMI qp */
180         struct ehca_mod_qp_parm *mod_qp_parm;
181         int mod_qp_parm_idx;
182         /* mmap counter for resources mapped into user space */
183         u32 mm_count_squeue;
184         u32 mm_count_rqueue;
185         u32 mm_count_galpa;
186 };
187
188 #define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
189 #define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)
190 #define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)
191
192 /* must be power of 2 */
193 #define QP_HASHTAB_LEN 8
194
195 struct ehca_cq {
196         struct ib_cq ib_cq;
197         struct ipz_queue ipz_queue;
198         struct h_galpas galpas;
199         spinlock_t spinlock;
200         u32 cq_number;
201         u32 token;
202         u32 nr_of_entries;
203         struct ipz_cq_handle ipz_cq_handle;
204         struct ehca_pfcq pf;
205         spinlock_t cb_lock;
206         struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
207         struct list_head entry;
208         u32 nr_callbacks;   /* #events assigned to cpu by scaling code */
209         atomic_t nr_events; /* #events seen */
210         wait_queue_head_t wait_completion;
211         spinlock_t task_lock;
212         u32 ownpid;
213         /* mmap counter for resources mapped into user space */
214         u32 mm_count_queue;
215         u32 mm_count_galpa;
216 };
217
218 enum ehca_mr_flag {
219         EHCA_MR_FLAG_FMR = 0x80000000,   /* FMR, created with ehca_alloc_fmr */
220         EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR                           */
221 };
222
223 struct ehca_mr {
224         union {
225                 struct ib_mr ib_mr;     /* must always be first in ehca_mr */
226                 struct ib_fmr ib_fmr;   /* must always be first in ehca_mr */
227         } ib;
228         struct ib_umem *umem;
229         spinlock_t mrlock;
230
231         enum ehca_mr_flag flags;
232         u32 num_kpages;         /* number of kernel pages */
233         u32 num_hwpages;        /* number of hw pages to form MR */
234         u64 hwpage_size;        /* hw page size used for this MR */
235         int acl;                /* ACL (stored here for usage in reregister) */
236         u64 *start;             /* virtual start address (stored here for */
237                                 /* usage in reregister) */
238         u64 size;               /* size (stored here for usage in reregister) */
239         u32 fmr_page_size;      /* page size for FMR */
240         u32 fmr_max_pages;      /* max pages for FMR */
241         u32 fmr_max_maps;       /* max outstanding maps for FMR */
242         u32 fmr_map_cnt;        /* map counter for FMR */
243         /* fw specific data */
244         struct ipz_mrmw_handle ipz_mr_handle;   /* MR handle for h-calls */
245         struct h_galpas galpas;
246 };
247
248 struct ehca_mw {
249         struct ib_mw ib_mw;     /* gen2 mw, must always be first in ehca_mw */
250         spinlock_t mwlock;
251
252         u8 never_bound;         /* indication MW was never bound */
253         struct ipz_mrmw_handle ipz_mw_handle;   /* MW handle for h-calls */
254         struct h_galpas galpas;
255 };
256
257 enum ehca_mr_pgi_type {
258         EHCA_MR_PGI_PHYS   = 1,  /* type of ehca_reg_phys_mr,
259                                   * ehca_rereg_phys_mr,
260                                   * ehca_reg_internal_maxmr */
261         EHCA_MR_PGI_USER   = 2,  /* type of ehca_reg_user_mr */
262         EHCA_MR_PGI_FMR    = 3   /* type of ehca_map_phys_fmr */
263 };
264
265 struct ehca_mr_pginfo {
266         enum ehca_mr_pgi_type type;
267         u64 num_kpages;
268         u64 kpage_cnt;
269         u64 hwpage_size;     /* hw page size used for this MR */
270         u64 num_hwpages;     /* number of hw pages */
271         u64 hwpage_cnt;      /* counter for hw pages */
272         u64 next_hwpage;     /* next hw page in buffer/chunk/listelem */
273
274         union {
275                 struct { /* type EHCA_MR_PGI_PHYS section */
276                         int num_phys_buf;
277                         struct ib_phys_buf *phys_buf_array;
278                         u64 next_buf;
279                 } phy;
280                 struct { /* type EHCA_MR_PGI_USER section */
281                         struct ib_umem *region;
282                         struct ib_umem_chunk *next_chunk;
283                         u64 next_nmap;
284                 } usr;
285                 struct { /* type EHCA_MR_PGI_FMR section */
286                         u64 fmr_pgsize;
287                         u64 *page_list;
288                         u64 next_listelem;
289                 } fmr;
290         } u;
291 };
292
293 /* output parameters for MR/FMR hipz calls */
294 struct ehca_mr_hipzout_parms {
295         struct ipz_mrmw_handle handle;
296         u32 lkey;
297         u32 rkey;
298         u64 len;
299         u64 vaddr;
300         u32 acl;
301 };
302
303 /* output parameters for MW hipz calls */
304 struct ehca_mw_hipzout_parms {
305         struct ipz_mrmw_handle handle;
306         u32 rkey;
307 };
308
309 struct ehca_av {
310         struct ib_ah ib_ah;
311         struct ehca_ud_av av;
312 };
313
314 struct ehca_ucontext {
315         struct ib_ucontext ib_ucontext;
316 };
317
318 int ehca_init_pd_cache(void);
319 void ehca_cleanup_pd_cache(void);
320 int ehca_init_cq_cache(void);
321 void ehca_cleanup_cq_cache(void);
322 int ehca_init_qp_cache(void);
323 void ehca_cleanup_qp_cache(void);
324 int ehca_init_av_cache(void);
325 void ehca_cleanup_av_cache(void);
326 int ehca_init_mrmw_cache(void);
327 void ehca_cleanup_mrmw_cache(void);
328 int ehca_init_small_qp_cache(void);
329 void ehca_cleanup_small_qp_cache(void);
330
331 extern rwlock_t ehca_qp_idr_lock;
332 extern rwlock_t ehca_cq_idr_lock;
333 extern struct idr ehca_qp_idr;
334 extern struct idr ehca_cq_idr;
335
336 extern int ehca_static_rate;
337 extern int ehca_port_act_time;
338 extern int ehca_use_hp_mr;
339 extern int ehca_scaling_code;
340 extern int ehca_lock_hcalls;
341 extern int ehca_nr_ports;
342
343 struct ipzu_queue_resp {
344         u32 qe_size;      /* queue entry size */
345         u32 act_nr_of_sg;
346         u32 queue_length; /* queue length allocated in bytes */
347         u32 pagesize;
348         u32 toggle_state;
349         u32 offset; /* save offset within a page for small_qp */
350 };
351
352 struct ehca_create_cq_resp {
353         u32 cq_number;
354         u32 token;
355         struct ipzu_queue_resp ipz_queue;
356         u32 fw_handle_ofs;
357         u32 dummy;
358 };
359
360 struct ehca_create_qp_resp {
361         u32 qp_num;
362         u32 token;
363         u32 qp_type;
364         u32 ext_type;
365         u32 qkey;
366         /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
367         u32 real_qp_num;
368         u32 fw_handle_ofs;
369         u32 dummy;
370         struct ipzu_queue_resp ipz_squeue;
371         struct ipzu_queue_resp ipz_rqueue;
372 };
373
374 struct ehca_alloc_cq_parms {
375         u32 nr_cqe;
376         u32 act_nr_of_entries;
377         u32 act_pages;
378         struct ipz_eq_handle eq_handle;
379 };
380
381 enum ehca_service_type {
382         ST_RC  = 0,
383         ST_UC  = 1,
384         ST_RD  = 2,
385         ST_UD  = 3,
386 };
387
388 enum ehca_ll_comp_flags {
389         LLQP_SEND_COMP = 0x20,
390         LLQP_RECV_COMP = 0x40,
391         LLQP_COMP_MASK = 0x60,
392 };
393
394 struct ehca_alloc_queue_parms {
395         /* input parameters */
396         int max_wr;
397         int max_sge;
398         int page_size;
399         int is_small;
400
401         /* output parameters */
402         u16 act_nr_wqes;
403         u8  act_nr_sges;
404         u32 queue_size; /* bytes for small queues, pages otherwise */
405 };
406
407 struct ehca_alloc_qp_parms {
408         struct ehca_alloc_queue_parms squeue;
409         struct ehca_alloc_queue_parms rqueue;
410
411         /* input parameters */
412         enum ehca_service_type servicetype;
413         int qp_storage;
414         int sigtype;
415         enum ehca_ext_qp_type ext_type;
416         enum ehca_ll_comp_flags ll_comp_flags;
417         int ud_av_l_key_ctl;
418
419         u32 token;
420         struct ipz_eq_handle eq_handle;
421         struct ipz_pd pd;
422         struct ipz_cq_handle send_cq_handle, recv_cq_handle;
423
424         u32 srq_qpn, srq_token, srq_limit;
425
426         /* output parameters */
427         u32 real_qp_num;
428         struct ipz_qp_handle qp_handle;
429         struct h_galpas galpas;
430 };
431
432 int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
433 int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
434 struct ehca_qp *ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);
435
436 #endif