]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/infiniband/hw/ehca/ehca_classes.h
1e9e99a13933bd7dfa671cc8a125c9abddb526fc
[linux-2.6-omap-h63xx.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 #define EHCA_MAX_NUM_QUEUES 0xffff
70
71 struct ehca_eqe_cache_entry {
72         struct ehca_eqe *eqe;
73         struct ehca_cq *cq;
74 };
75
76 struct ehca_eq {
77         u32 length;
78         struct ipz_queue ipz_queue;
79         struct ipz_eq_handle ipz_eq_handle;
80         struct work_struct work;
81         struct h_galpas galpas;
82         int is_initialized;
83         struct ehca_pfeq pf;
84         spinlock_t spinlock;
85         struct tasklet_struct interrupt_task;
86         u32 ist;
87         spinlock_t irq_spinlock;
88         struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
89 };
90
91 struct ehca_sma_attr {
92         u16 lid, lmc, sm_sl, sm_lid;
93         u16 pkey_tbl_len, pkeys[16];
94 };
95
96 struct ehca_sport {
97         struct ib_cq *ibcq_aqp1;
98         struct ib_qp *ibqp_sqp[2];
99         /* lock to serialze modify_qp() calls for sqp in normal
100          * and irq path (when event PORT_ACTIVE is received first time)
101          */
102         spinlock_t mod_sqp_lock;
103         enum ib_port_state port_state;
104         struct ehca_sma_attr saved_attr;
105         u32 pma_qp_nr;
106 };
107
108 #define HCA_CAP_MR_PGSIZE_4K  0x80000000
109 #define HCA_CAP_MR_PGSIZE_64K 0x40000000
110 #define HCA_CAP_MR_PGSIZE_1M  0x20000000
111 #define HCA_CAP_MR_PGSIZE_16M 0x10000000
112
113 struct ehca_shca {
114         struct ib_device ib_device;
115         struct of_device *ofdev;
116         u8 num_ports;
117         int hw_level;
118         struct list_head shca_list;
119         struct ipz_adapter_handle ipz_hca_handle;
120         struct ehca_sport sport[2];
121         struct ehca_eq eq;
122         struct ehca_eq neq;
123         struct ehca_mr *maxmr;
124         struct ehca_pd *pd;
125         struct h_galpas galpas;
126         struct mutex modify_mutex;
127         u64 hca_cap;
128         /* MR pgsize: bit 0-3 means 4K, 64K, 1M, 16M respectively */
129         u32 hca_cap_mr_pgsize;
130         int max_mtu;
131         atomic_t num_cqs;
132         atomic_t num_qps;
133 };
134
135 struct ehca_pd {
136         struct ib_pd ib_pd;
137         struct ipz_pd fw_pd;
138         /* small queue mgmt */
139         struct mutex lock;
140         struct list_head free[2];
141         struct list_head full[2];
142 };
143
144 enum ehca_ext_qp_type {
145         EQPT_NORMAL    = 0,
146         EQPT_LLQP      = 1,
147         EQPT_SRQBASE   = 2,
148         EQPT_SRQ       = 3,
149 };
150
151 /* struct to cache modify_qp()'s parms for GSI/SMI qp */
152 struct ehca_mod_qp_parm {
153         int mask;
154         struct ib_qp_attr attr;
155 };
156
157 #define EHCA_MOD_QP_PARM_MAX 4
158
159 struct ehca_qp {
160         union {
161                 struct ib_qp ib_qp;
162                 struct ib_srq ib_srq;
163         };
164         u32 qp_type;
165         enum ehca_ext_qp_type ext_type;
166         enum ib_qp_state state;
167         struct ipz_queue ipz_squeue;
168         struct ipz_queue ipz_rqueue;
169         struct h_galpas galpas;
170         u32 qkey;
171         u32 real_qp_num;
172         u32 token;
173         spinlock_t spinlock_s;
174         spinlock_t spinlock_r;
175         u32 sq_max_inline_data_size;
176         struct ipz_qp_handle ipz_qp_handle;
177         struct ehca_pfqp pf;
178         struct ib_qp_init_attr init_attr;
179         struct ehca_cq *send_cq;
180         struct ehca_cq *recv_cq;
181         unsigned int sqerr_purgeflag;
182         struct hlist_node list_entries;
183         /* array to cache modify_qp()'s parms for GSI/SMI qp */
184         struct ehca_mod_qp_parm *mod_qp_parm;
185         int mod_qp_parm_idx;
186         /* mmap counter for resources mapped into user space */
187         u32 mm_count_squeue;
188         u32 mm_count_rqueue;
189         u32 mm_count_galpa;
190         /* unsolicited ack circumvention */
191         int unsol_ack_circ;
192         int mtu_shift;
193         u32 message_count;
194         u32 packet_count;
195         atomic_t nr_events; /* events seen */
196         wait_queue_head_t wait_completion;
197 };
198
199 #define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
200 #define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)
201 #define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)
202
203 /* must be power of 2 */
204 #define QP_HASHTAB_LEN 8
205
206 struct ehca_cq {
207         struct ib_cq ib_cq;
208         struct ipz_queue ipz_queue;
209         struct h_galpas galpas;
210         spinlock_t spinlock;
211         u32 cq_number;
212         u32 token;
213         u32 nr_of_entries;
214         struct ipz_cq_handle ipz_cq_handle;
215         struct ehca_pfcq pf;
216         spinlock_t cb_lock;
217         struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
218         struct list_head entry;
219         u32 nr_callbacks;   /* #events assigned to cpu by scaling code */
220         atomic_t nr_events; /* #events seen */
221         wait_queue_head_t wait_completion;
222         spinlock_t task_lock;
223         /* mmap counter for resources mapped into user space */
224         u32 mm_count_queue;
225         u32 mm_count_galpa;
226 };
227
228 enum ehca_mr_flag {
229         EHCA_MR_FLAG_FMR = 0x80000000,   /* FMR, created with ehca_alloc_fmr */
230         EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR                           */
231 };
232
233 struct ehca_mr {
234         union {
235                 struct ib_mr ib_mr;     /* must always be first in ehca_mr */
236                 struct ib_fmr ib_fmr;   /* must always be first in ehca_mr */
237         } ib;
238         struct ib_umem *umem;
239         spinlock_t mrlock;
240
241         enum ehca_mr_flag flags;
242         u32 num_kpages;         /* number of kernel pages */
243         u32 num_hwpages;        /* number of hw pages to form MR */
244         u64 hwpage_size;        /* hw page size used for this MR */
245         int acl;                /* ACL (stored here for usage in reregister) */
246         u64 *start;             /* virtual start address (stored here for */
247                                 /* usage in reregister) */
248         u64 size;               /* size (stored here for usage in reregister) */
249         u32 fmr_page_size;      /* page size for FMR */
250         u32 fmr_max_pages;      /* max pages for FMR */
251         u32 fmr_max_maps;       /* max outstanding maps for FMR */
252         u32 fmr_map_cnt;        /* map counter for FMR */
253         /* fw specific data */
254         struct ipz_mrmw_handle ipz_mr_handle;   /* MR handle for h-calls */
255         struct h_galpas galpas;
256 };
257
258 struct ehca_mw {
259         struct ib_mw ib_mw;     /* gen2 mw, must always be first in ehca_mw */
260         spinlock_t mwlock;
261
262         u8 never_bound;         /* indication MW was never bound */
263         struct ipz_mrmw_handle ipz_mw_handle;   /* MW handle for h-calls */
264         struct h_galpas galpas;
265 };
266
267 enum ehca_mr_pgi_type {
268         EHCA_MR_PGI_PHYS   = 1,  /* type of ehca_reg_phys_mr,
269                                   * ehca_rereg_phys_mr,
270                                   * ehca_reg_internal_maxmr */
271         EHCA_MR_PGI_USER   = 2,  /* type of ehca_reg_user_mr */
272         EHCA_MR_PGI_FMR    = 3   /* type of ehca_map_phys_fmr */
273 };
274
275 struct ehca_mr_pginfo {
276         enum ehca_mr_pgi_type type;
277         u64 num_kpages;
278         u64 kpage_cnt;
279         u64 hwpage_size;     /* hw page size used for this MR */
280         u64 num_hwpages;     /* number of hw pages */
281         u64 hwpage_cnt;      /* counter for hw pages */
282         u64 next_hwpage;     /* next hw page in buffer/chunk/listelem */
283
284         union {
285                 struct { /* type EHCA_MR_PGI_PHYS section */
286                         int num_phys_buf;
287                         struct ib_phys_buf *phys_buf_array;
288                         u64 next_buf;
289                 } phy;
290                 struct { /* type EHCA_MR_PGI_USER section */
291                         struct ib_umem *region;
292                         struct ib_umem_chunk *next_chunk;
293                         u64 next_nmap;
294                 } usr;
295                 struct { /* type EHCA_MR_PGI_FMR section */
296                         u64 fmr_pgsize;
297                         u64 *page_list;
298                         u64 next_listelem;
299                 } fmr;
300         } u;
301 };
302
303 /* output parameters for MR/FMR hipz calls */
304 struct ehca_mr_hipzout_parms {
305         struct ipz_mrmw_handle handle;
306         u32 lkey;
307         u32 rkey;
308         u64 len;
309         u64 vaddr;
310         u32 acl;
311 };
312
313 /* output parameters for MW hipz calls */
314 struct ehca_mw_hipzout_parms {
315         struct ipz_mrmw_handle handle;
316         u32 rkey;
317 };
318
319 struct ehca_av {
320         struct ib_ah ib_ah;
321         struct ehca_ud_av av;
322 };
323
324 struct ehca_ucontext {
325         struct ib_ucontext ib_ucontext;
326 };
327
328 int ehca_init_pd_cache(void);
329 void ehca_cleanup_pd_cache(void);
330 int ehca_init_cq_cache(void);
331 void ehca_cleanup_cq_cache(void);
332 int ehca_init_qp_cache(void);
333 void ehca_cleanup_qp_cache(void);
334 int ehca_init_av_cache(void);
335 void ehca_cleanup_av_cache(void);
336 int ehca_init_mrmw_cache(void);
337 void ehca_cleanup_mrmw_cache(void);
338 int ehca_init_small_qp_cache(void);
339 void ehca_cleanup_small_qp_cache(void);
340
341 extern rwlock_t ehca_qp_idr_lock;
342 extern rwlock_t ehca_cq_idr_lock;
343 extern struct idr ehca_qp_idr;
344 extern struct idr ehca_cq_idr;
345
346 extern int ehca_static_rate;
347 extern int ehca_port_act_time;
348 extern int ehca_use_hp_mr;
349 extern int ehca_scaling_code;
350 extern int ehca_lock_hcalls;
351 extern int ehca_nr_ports;
352 extern int ehca_max_cq;
353 extern int ehca_max_qp;
354
355 struct ipzu_queue_resp {
356         u32 qe_size;      /* queue entry size */
357         u32 act_nr_of_sg;
358         u32 queue_length; /* queue length allocated in bytes */
359         u32 pagesize;
360         u32 toggle_state;
361         u32 offset; /* save offset within a page for small_qp */
362 };
363
364 struct ehca_create_cq_resp {
365         u32 cq_number;
366         u32 token;
367         struct ipzu_queue_resp ipz_queue;
368         u32 fw_handle_ofs;
369         u32 dummy;
370 };
371
372 struct ehca_create_qp_resp {
373         u32 qp_num;
374         u32 token;
375         u32 qp_type;
376         u32 ext_type;
377         u32 qkey;
378         /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
379         u32 real_qp_num;
380         u32 fw_handle_ofs;
381         u32 dummy;
382         struct ipzu_queue_resp ipz_squeue;
383         struct ipzu_queue_resp ipz_rqueue;
384 };
385
386 struct ehca_alloc_cq_parms {
387         u32 nr_cqe;
388         u32 act_nr_of_entries;
389         u32 act_pages;
390         struct ipz_eq_handle eq_handle;
391 };
392
393 enum ehca_service_type {
394         ST_RC  = 0,
395         ST_UC  = 1,
396         ST_RD  = 2,
397         ST_UD  = 3,
398 };
399
400 enum ehca_ll_comp_flags {
401         LLQP_SEND_COMP = 0x20,
402         LLQP_RECV_COMP = 0x40,
403         LLQP_COMP_MASK = 0x60,
404 };
405
406 struct ehca_alloc_queue_parms {
407         /* input parameters */
408         int max_wr;
409         int max_sge;
410         int page_size;
411         int is_small;
412
413         /* output parameters */
414         u16 act_nr_wqes;
415         u8  act_nr_sges;
416         u32 queue_size; /* bytes for small queues, pages otherwise */
417 };
418
419 struct ehca_alloc_qp_parms {
420         struct ehca_alloc_queue_parms squeue;
421         struct ehca_alloc_queue_parms rqueue;
422
423         /* input parameters */
424         enum ehca_service_type servicetype;
425         int qp_storage;
426         int sigtype;
427         enum ehca_ext_qp_type ext_type;
428         enum ehca_ll_comp_flags ll_comp_flags;
429         int ud_av_l_key_ctl;
430
431         u32 token;
432         struct ipz_eq_handle eq_handle;
433         struct ipz_pd pd;
434         struct ipz_cq_handle send_cq_handle, recv_cq_handle;
435
436         u32 srq_qpn, srq_token, srq_limit;
437
438         /* output parameters */
439         u32 real_qp_num;
440         struct ipz_qp_handle qp_handle;
441         struct h_galpas galpas;
442 };
443
444 int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
445 int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
446 struct ehca_qp *ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);
447
448 #endif