2 * IBM eServer eHCA Infiniband device driver for Linux on POWER
4 * Struct definition for eHCA internal structures
6 * Authors: Heiko J Schick <schickhj@de.ibm.com>
7 * Christoph Raisch <raisch@de.ibm.com>
8 * Joachim Fenkes <fenkes@de.ibm.com>
10 * Copyright (c) 2005 IBM Corporation
12 * All rights reserved.
14 * This source code is distributed under a dual license of GPL v2.0 and OpenIB
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are met:
22 * Redistributions of source code must retain the above copyright notice, this
23 * list of conditions and the following disclaimer.
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.
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.
43 #ifndef __EHCA_CLASSES_H__
44 #define __EHCA_CLASSES_H__
55 #include <linux/wait.h>
56 #include <linux/mutex.h>
58 #include <rdma/ib_verbs.h>
59 #include <rdma/ib_user_verbs.h>
62 #include "ehca_classes_pSeries.h"
64 #include "ipz_pt_fn.h"
68 #define EHCA_EQE_CACHE_SIZE 20
69 #define EHCA_MAX_NUM_QUEUES 0xffff
71 struct ehca_eqe_cache_entry {
78 struct ipz_queue ipz_queue;
79 struct ipz_eq_handle ipz_eq_handle;
80 struct work_struct work;
81 struct h_galpas galpas;
85 struct tasklet_struct interrupt_task;
87 spinlock_t irq_spinlock;
88 struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
91 struct ehca_sma_attr {
92 u16 lid, lmc, sm_sl, sm_lid;
93 u16 pkey_tbl_len, pkeys[16];
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)
102 spinlock_t mod_sqp_lock;
103 enum ib_port_state port_state;
104 struct ehca_sma_attr saved_attr;
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
114 struct ib_device ib_device;
115 struct of_device *ofdev;
118 struct list_head shca_list;
119 struct ipz_adapter_handle ipz_hca_handle;
120 struct ehca_sport sport[2];
123 struct ehca_mr *maxmr;
125 struct h_galpas galpas;
126 struct mutex modify_mutex;
128 /* MR pgsize: bit 0-3 means 4K, 64K, 1M, 16M respectively */
129 u32 hca_cap_mr_pgsize;
140 /* small queue mgmt */
142 struct list_head free[2];
143 struct list_head full[2];
146 enum ehca_ext_qp_type {
153 /* struct to cache modify_qp()'s parms for GSI/SMI qp */
154 struct ehca_mod_qp_parm {
156 struct ib_qp_attr attr;
159 #define EHCA_MOD_QP_PARM_MAX 4
161 #define QMAP_IDX_MASK 0xFFFFULL
163 /* struct for tracking if cqes have been reported to the application */
164 struct ehca_qmap_entry {
170 struct ehca_queue_map {
171 struct ehca_qmap_entry *map;
172 unsigned int entries;
174 unsigned int left_to_poll;
175 unsigned int next_wqe_idx; /* Idx to first wqe to be flushed */
181 struct ib_srq ib_srq;
184 enum ehca_ext_qp_type ext_type;
185 enum ib_qp_state state;
186 struct ipz_queue ipz_squeue;
187 struct ehca_queue_map sq_map;
188 struct ipz_queue ipz_rqueue;
189 struct ehca_queue_map rq_map;
190 struct h_galpas galpas;
194 spinlock_t spinlock_s;
195 spinlock_t spinlock_r;
196 u32 sq_max_inline_data_size;
197 struct ipz_qp_handle ipz_qp_handle;
199 struct ib_qp_init_attr init_attr;
200 struct ehca_cq *send_cq;
201 struct ehca_cq *recv_cq;
202 unsigned int sqerr_purgeflag;
203 struct hlist_node list_entries;
204 /* array to cache modify_qp()'s parms for GSI/SMI qp */
205 struct ehca_mod_qp_parm *mod_qp_parm;
207 /* mmap counter for resources mapped into user space */
211 /* unsolicited ack circumvention */
216 atomic_t nr_events; /* events seen */
217 wait_queue_head_t wait_completion;
219 struct list_head sq_err_node;
220 struct list_head rq_err_node;
223 #define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
224 #define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)
225 #define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)
227 /* must be power of 2 */
228 #define QP_HASHTAB_LEN 8
232 struct ipz_queue ipz_queue;
233 struct h_galpas galpas;
238 struct ipz_cq_handle ipz_cq_handle;
241 struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
242 struct list_head entry;
243 u32 nr_callbacks; /* #events assigned to cpu by scaling code */
244 atomic_t nr_events; /* #events seen */
245 wait_queue_head_t wait_completion;
246 spinlock_t task_lock;
247 /* mmap counter for resources mapped into user space */
250 struct list_head sqp_err_list;
251 struct list_head rqp_err_list;
255 EHCA_MR_FLAG_FMR = 0x80000000, /* FMR, created with ehca_alloc_fmr */
256 EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR */
261 struct ib_mr ib_mr; /* must always be first in ehca_mr */
262 struct ib_fmr ib_fmr; /* must always be first in ehca_mr */
264 struct ib_umem *umem;
267 enum ehca_mr_flag flags;
268 u32 num_kpages; /* number of kernel pages */
269 u32 num_hwpages; /* number of hw pages to form MR */
270 u64 hwpage_size; /* hw page size used for this MR */
271 int acl; /* ACL (stored here for usage in reregister) */
272 u64 *start; /* virtual start address (stored here for */
273 /* usage in reregister) */
274 u64 size; /* size (stored here for usage in reregister) */
275 u32 fmr_page_size; /* page size for FMR */
276 u32 fmr_max_pages; /* max pages for FMR */
277 u32 fmr_max_maps; /* max outstanding maps for FMR */
278 u32 fmr_map_cnt; /* map counter for FMR */
279 /* fw specific data */
280 struct ipz_mrmw_handle ipz_mr_handle; /* MR handle for h-calls */
281 struct h_galpas galpas;
285 struct ib_mw ib_mw; /* gen2 mw, must always be first in ehca_mw */
288 u8 never_bound; /* indication MW was never bound */
289 struct ipz_mrmw_handle ipz_mw_handle; /* MW handle for h-calls */
290 struct h_galpas galpas;
293 enum ehca_mr_pgi_type {
294 EHCA_MR_PGI_PHYS = 1, /* type of ehca_reg_phys_mr,
295 * ehca_rereg_phys_mr,
296 * ehca_reg_internal_maxmr */
297 EHCA_MR_PGI_USER = 2, /* type of ehca_reg_user_mr */
298 EHCA_MR_PGI_FMR = 3 /* type of ehca_map_phys_fmr */
301 struct ehca_mr_pginfo {
302 enum ehca_mr_pgi_type type;
305 u64 hwpage_size; /* hw page size used for this MR */
306 u64 num_hwpages; /* number of hw pages */
307 u64 hwpage_cnt; /* counter for hw pages */
308 u64 next_hwpage; /* next hw page in buffer/chunk/listelem */
311 struct { /* type EHCA_MR_PGI_PHYS section */
313 struct ib_phys_buf *phys_buf_array;
316 struct { /* type EHCA_MR_PGI_USER section */
317 struct ib_umem *region;
318 struct ib_umem_chunk *next_chunk;
321 struct { /* type EHCA_MR_PGI_FMR section */
329 /* output parameters for MR/FMR hipz calls */
330 struct ehca_mr_hipzout_parms {
331 struct ipz_mrmw_handle handle;
339 /* output parameters for MW hipz calls */
340 struct ehca_mw_hipzout_parms {
341 struct ipz_mrmw_handle handle;
347 struct ehca_ud_av av;
350 struct ehca_ucontext {
351 struct ib_ucontext ib_ucontext;
354 int ehca_init_pd_cache(void);
355 void ehca_cleanup_pd_cache(void);
356 int ehca_init_cq_cache(void);
357 void ehca_cleanup_cq_cache(void);
358 int ehca_init_qp_cache(void);
359 void ehca_cleanup_qp_cache(void);
360 int ehca_init_av_cache(void);
361 void ehca_cleanup_av_cache(void);
362 int ehca_init_mrmw_cache(void);
363 void ehca_cleanup_mrmw_cache(void);
364 int ehca_init_small_qp_cache(void);
365 void ehca_cleanup_small_qp_cache(void);
367 extern rwlock_t ehca_qp_idr_lock;
368 extern rwlock_t ehca_cq_idr_lock;
369 extern struct idr ehca_qp_idr;
370 extern struct idr ehca_cq_idr;
372 extern int ehca_static_rate;
373 extern int ehca_port_act_time;
374 extern int ehca_use_hp_mr;
375 extern int ehca_scaling_code;
376 extern int ehca_lock_hcalls;
377 extern int ehca_nr_ports;
378 extern int ehca_max_cq;
379 extern int ehca_max_qp;
381 struct ipzu_queue_resp {
382 u32 qe_size; /* queue entry size */
384 u32 queue_length; /* queue length allocated in bytes */
387 u32 offset; /* save offset within a page for small_qp */
390 struct ehca_create_cq_resp {
393 struct ipzu_queue_resp ipz_queue;
398 struct ehca_create_qp_resp {
404 /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
408 struct ipzu_queue_resp ipz_squeue;
409 struct ipzu_queue_resp ipz_rqueue;
412 struct ehca_alloc_cq_parms {
414 u32 act_nr_of_entries;
416 struct ipz_eq_handle eq_handle;
419 enum ehca_service_type {
426 enum ehca_ll_comp_flags {
427 LLQP_SEND_COMP = 0x20,
428 LLQP_RECV_COMP = 0x40,
429 LLQP_COMP_MASK = 0x60,
432 struct ehca_alloc_queue_parms {
433 /* input parameters */
439 /* output parameters */
442 u32 queue_size; /* bytes for small queues, pages otherwise */
445 struct ehca_alloc_qp_parms {
446 struct ehca_alloc_queue_parms squeue;
447 struct ehca_alloc_queue_parms rqueue;
449 /* input parameters */
450 enum ehca_service_type servicetype;
453 enum ehca_ext_qp_type ext_type;
454 enum ehca_ll_comp_flags ll_comp_flags;
458 struct ipz_eq_handle eq_handle;
460 struct ipz_cq_handle send_cq_handle, recv_cq_handle;
462 u32 srq_qpn, srq_token, srq_limit;
464 /* output parameters */
466 struct ipz_qp_handle qp_handle;
467 struct h_galpas galpas;
470 int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
471 int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
472 struct ehca_qp *ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);