blob: f281d16040f5ac794e14e28820b37e537a7db51f [file] [log] [blame]
Heiko J Schickfab97222006-09-22 15:22:22 -07001/*
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>
Joachim Fenkesa6a12942007-07-09 15:25:10 +02008 * Joachim Fenkes <fenkes@de.ibm.com>
Heiko J Schickfab97222006-09-22 15:22:22 -07009 *
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
Heiko J Schickfab97222006-09-22 15:22:22 -070046struct ehca_module;
47struct ehca_qp;
48struct ehca_cq;
49struct ehca_eq;
50struct ehca_mr;
51struct ehca_mw;
52struct ehca_pd;
53struct ehca_av;
54
Hoang-Nam Nguyen31726792007-02-28 18:01:02 +010055#include <linux/wait.h>
Roland Dreier1fea3912007-10-09 19:59:05 -070056#include <linux/mutex.h>
Hoang-Nam Nguyen31726792007-02-28 18:01:02 +010057
Heiko J Schickfab97222006-09-22 15:22:22 -070058#include <rdma/ib_verbs.h>
59#include <rdma/ib_user_verbs.h>
60
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +010061#ifdef CONFIG_PPC64
62#include "ehca_classes_pSeries.h"
63#endif
64#include "ipz_pt_fn.h"
65#include "ehca_qes.h"
Heiko J Schickfab97222006-09-22 15:22:22 -070066#include "ehca_irq.h"
67
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +010068#define EHCA_EQE_CACHE_SIZE 20
69
70struct ehca_eqe_cache_entry {
71 struct ehca_eqe *eqe;
72 struct ehca_cq *cq;
73};
74
Heiko J Schickfab97222006-09-22 15:22:22 -070075struct 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;
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +010086 spinlock_t irq_spinlock;
87 struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
Heiko J Schickfab97222006-09-22 15:22:22 -070088};
89
Joachim Fenkes8705ce52007-07-09 15:32:22 +020090struct ehca_sma_attr {
91 u16 lid, lmc, sm_sl, sm_lid;
92 u16 pkey_tbl_len, pkeys[16];
93};
94
Heiko J Schickfab97222006-09-22 15:22:22 -070095struct ehca_sport {
96 struct ib_cq *ibcq_aqp1;
Hoang-Nam Nguyenb8b50e32008-01-17 15:04:32 +010097 struct ib_qp *ibqp_sqp[2];
Hoang-Nam Nguyenbbdd2672008-01-17 15:05:45 +010098 /* 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;
Heiko J Schickfab97222006-09-22 15:22:22 -0700102 enum ib_port_state port_state;
Joachim Fenkes8705ce52007-07-09 15:32:22 +0200103 struct ehca_sma_attr saved_attr;
Heiko J Schickfab97222006-09-22 15:22:22 -0700104};
105
Hoang-Nam Nguyen08c283a2007-09-13 18:14:58 +0200106#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
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200110
Heiko J Schickfab97222006-09-22 15:22:22 -0700111struct ehca_shca {
112 struct ib_device ib_device;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000113 struct of_device *ofdev;
Heiko J Schickfab97222006-09-22 15:22:22 -0700114 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;
Joachim Fenkesc4ed7902007-04-24 17:44:31 +0200124 struct mutex modify_mutex;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200125 u64 hca_cap;
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200126 /* MR pgsize: bit 0-3 means 4K, 64K, 1M, 16M respectively */
127 u32 hca_cap_mr_pgsize;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200128 int max_mtu;
Heiko J Schickfab97222006-09-22 15:22:22 -0700129};
130
131struct ehca_pd {
132 struct ib_pd ib_pd;
133 struct ipz_pd fw_pd;
134 u32 ownpid;
Stefan Roschere2f81da2007-07-20 16:04:17 +0200135 /* small queue mgmt */
136 struct mutex lock;
137 struct list_head free[2];
138 struct list_head full[2];
Heiko J Schickfab97222006-09-22 15:22:22 -0700139};
140
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200141enum ehca_ext_qp_type {
142 EQPT_NORMAL = 0,
143 EQPT_LLQP = 1,
144 EQPT_SRQBASE = 2,
145 EQPT_SRQ = 3,
146};
147
Hoang-Nam Nguyenbbdd2672008-01-17 15:05:45 +0100148/* struct to cache modify_qp()'s parms for GSI/SMI qp */
149struct ehca_mod_qp_parm {
150 int mask;
151 struct ib_qp_attr attr;
152};
153
154#define EHCA_MOD_QP_PARM_MAX 4
155
Heiko J Schickfab97222006-09-22 15:22:22 -0700156struct ehca_qp {
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200157 union {
158 struct ib_qp ib_qp;
159 struct ib_srq ib_srq;
160 };
Heiko J Schickfab97222006-09-22 15:22:22 -0700161 u32 qp_type;
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200162 enum ehca_ext_qp_type ext_type;
Heiko J Schickfab97222006-09-22 15:22:22 -0700163 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;
Heiko J Schickfab97222006-09-22 15:22:22 -0700175 struct ehca_cq *send_cq;
176 struct ehca_cq *recv_cq;
177 unsigned int sqerr_purgeflag;
178 struct hlist_node list_entries;
Hoang-Nam Nguyenbbdd2672008-01-17 15:05:45 +0100179 /* 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;
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100182 /* mmap counter for resources mapped into user space */
183 u32 mm_count_squeue;
184 u32 mm_count_rqueue;
185 u32 mm_count_galpa;
Joachim Fenkes2ec8e662008-01-17 15:07:24 +0100186 /* unsolicited ack circumvention */
187 int unsol_ack_circ;
188 int mtu_shift;
189 u32 message_count;
190 u32 packet_count;
Heiko J Schickfab97222006-09-22 15:22:22 -0700191};
192
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200193#define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
194#define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)
195#define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)
196
Heiko J Schickfab97222006-09-22 15:22:22 -0700197/* must be power of 2 */
198#define QP_HASHTAB_LEN 8
199
200struct ehca_cq {
201 struct ib_cq ib_cq;
202 struct ipz_queue ipz_queue;
203 struct h_galpas galpas;
204 spinlock_t spinlock;
205 u32 cq_number;
206 u32 token;
207 u32 nr_of_entries;
208 struct ipz_cq_handle ipz_cq_handle;
209 struct ehca_pfcq pf;
210 spinlock_t cb_lock;
Heiko J Schickfab97222006-09-22 15:22:22 -0700211 struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
212 struct list_head entry;
Joachim Fenkes28db6be2007-07-09 15:30:39 +0200213 u32 nr_callbacks; /* #events assigned to cpu by scaling code */
214 atomic_t nr_events; /* #events seen */
Hoang-Nam Nguyen31726792007-02-28 18:01:02 +0100215 wait_queue_head_t wait_completion;
Heiko J Schickfab97222006-09-22 15:22:22 -0700216 spinlock_t task_lock;
217 u32 ownpid;
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100218 /* mmap counter for resources mapped into user space */
219 u32 mm_count_queue;
220 u32 mm_count_galpa;
Heiko J Schickfab97222006-09-22 15:22:22 -0700221};
222
223enum ehca_mr_flag {
224 EHCA_MR_FLAG_FMR = 0x80000000, /* FMR, created with ehca_alloc_fmr */
225 EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR */
226};
227
228struct ehca_mr {
229 union {
230 struct ib_mr ib_mr; /* must always be first in ehca_mr */
231 struct ib_fmr ib_fmr; /* must always be first in ehca_mr */
232 } ib;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -0800233 struct ib_umem *umem;
Heiko J Schickfab97222006-09-22 15:22:22 -0700234 spinlock_t mrlock;
235
236 enum ehca_mr_flag flags;
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200237 u32 num_kpages; /* number of kernel pages */
238 u32 num_hwpages; /* number of hw pages to form MR */
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200239 u64 hwpage_size; /* hw page size used for this MR */
Heiko J Schickfab97222006-09-22 15:22:22 -0700240 int acl; /* ACL (stored here for usage in reregister) */
241 u64 *start; /* virtual start address (stored here for */
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200242 /* usage in reregister) */
Heiko J Schickfab97222006-09-22 15:22:22 -0700243 u64 size; /* size (stored here for usage in reregister) */
244 u32 fmr_page_size; /* page size for FMR */
245 u32 fmr_max_pages; /* max pages for FMR */
246 u32 fmr_max_maps; /* max outstanding maps for FMR */
247 u32 fmr_map_cnt; /* map counter for FMR */
248 /* fw specific data */
249 struct ipz_mrmw_handle ipz_mr_handle; /* MR handle for h-calls */
250 struct h_galpas galpas;
Heiko J Schickfab97222006-09-22 15:22:22 -0700251};
252
253struct ehca_mw {
254 struct ib_mw ib_mw; /* gen2 mw, must always be first in ehca_mw */
255 spinlock_t mwlock;
256
257 u8 never_bound; /* indication MW was never bound */
258 struct ipz_mrmw_handle ipz_mw_handle; /* MW handle for h-calls */
259 struct h_galpas galpas;
260};
261
262enum ehca_mr_pgi_type {
263 EHCA_MR_PGI_PHYS = 1, /* type of ehca_reg_phys_mr,
264 * ehca_rereg_phys_mr,
265 * ehca_reg_internal_maxmr */
266 EHCA_MR_PGI_USER = 2, /* type of ehca_reg_user_mr */
267 EHCA_MR_PGI_FMR = 3 /* type of ehca_map_phys_fmr */
268};
269
270struct ehca_mr_pginfo {
271 enum ehca_mr_pgi_type type;
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200272 u64 num_kpages;
273 u64 kpage_cnt;
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200274 u64 hwpage_size; /* hw page size used for this MR */
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200275 u64 num_hwpages; /* number of hw pages */
276 u64 hwpage_cnt; /* counter for hw pages */
277 u64 next_hwpage; /* next hw page in buffer/chunk/listelem */
Heiko J Schickfab97222006-09-22 15:22:22 -0700278
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200279 union {
280 struct { /* type EHCA_MR_PGI_PHYS section */
281 int num_phys_buf;
282 struct ib_phys_buf *phys_buf_array;
283 u64 next_buf;
284 } phy;
285 struct { /* type EHCA_MR_PGI_USER section */
286 struct ib_umem *region;
287 struct ib_umem_chunk *next_chunk;
288 u64 next_nmap;
289 } usr;
290 struct { /* type EHCA_MR_PGI_FMR section */
291 u64 fmr_pgsize;
292 u64 *page_list;
293 u64 next_listelem;
294 } fmr;
295 } u;
Heiko J Schickfab97222006-09-22 15:22:22 -0700296};
297
298/* output parameters for MR/FMR hipz calls */
299struct ehca_mr_hipzout_parms {
300 struct ipz_mrmw_handle handle;
301 u32 lkey;
302 u32 rkey;
303 u64 len;
304 u64 vaddr;
305 u32 acl;
306};
307
308/* output parameters for MW hipz calls */
309struct ehca_mw_hipzout_parms {
310 struct ipz_mrmw_handle handle;
311 u32 rkey;
312};
313
314struct ehca_av {
315 struct ib_ah ib_ah;
316 struct ehca_ud_av av;
317};
318
319struct ehca_ucontext {
320 struct ib_ucontext ib_ucontext;
321};
322
Heiko J Schickfab97222006-09-22 15:22:22 -0700323int ehca_init_pd_cache(void);
324void ehca_cleanup_pd_cache(void);
325int ehca_init_cq_cache(void);
326void ehca_cleanup_cq_cache(void);
327int ehca_init_qp_cache(void);
328void ehca_cleanup_qp_cache(void);
329int ehca_init_av_cache(void);
330void ehca_cleanup_av_cache(void);
331int ehca_init_mrmw_cache(void);
332void ehca_cleanup_mrmw_cache(void);
Stefan Roschere2f81da2007-07-20 16:04:17 +0200333int ehca_init_small_qp_cache(void);
334void ehca_cleanup_small_qp_cache(void);
Heiko J Schickfab97222006-09-22 15:22:22 -0700335
Joachim Fenkes26ed6872007-07-09 15:31:10 +0200336extern rwlock_t ehca_qp_idr_lock;
337extern rwlock_t ehca_cq_idr_lock;
Heiko J Schickfab97222006-09-22 15:22:22 -0700338extern struct idr ehca_qp_idr;
339extern struct idr ehca_cq_idr;
340
341extern int ehca_static_rate;
342extern int ehca_port_act_time;
343extern int ehca_use_hp_mr;
Hoang-Nam Nguyen4fd30062007-02-15 17:08:33 +0100344extern int ehca_scaling_code;
Joachim Fenkes3d758a42007-12-13 13:35:57 +0100345extern int ehca_lock_hcalls;
Hoang-Nam Nguyenbbdd2672008-01-17 15:05:45 +0100346extern int ehca_nr_ports;
Heiko J Schickfab97222006-09-22 15:22:22 -0700347
348struct ipzu_queue_resp {
Heiko J Schickfab97222006-09-22 15:22:22 -0700349 u32 qe_size; /* queue entry size */
350 u32 act_nr_of_sg;
351 u32 queue_length; /* queue length allocated in bytes */
352 u32 pagesize;
353 u32 toggle_state;
Stefan Roschere2f81da2007-07-20 16:04:17 +0200354 u32 offset; /* save offset within a page for small_qp */
Heiko J Schickfab97222006-09-22 15:22:22 -0700355};
356
357struct ehca_create_cq_resp {
358 u32 cq_number;
359 u32 token;
360 struct ipzu_queue_resp ipz_queue;
Hoang-Nam Nguyene390d3b2007-09-11 15:31:06 +0200361 u32 fw_handle_ofs;
362 u32 dummy;
Heiko J Schickfab97222006-09-22 15:22:22 -0700363};
364
365struct ehca_create_qp_resp {
366 u32 qp_num;
367 u32 token;
368 u32 qp_type;
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200369 u32 ext_type;
Heiko J Schickfab97222006-09-22 15:22:22 -0700370 u32 qkey;
371 /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
372 u32 real_qp_num;
Hoang-Nam Nguyene390d3b2007-09-11 15:31:06 +0200373 u32 fw_handle_ofs;
Hoang-Nam Nguyena6607222007-09-28 17:18:47 +0200374 u32 dummy;
Heiko J Schickfab97222006-09-22 15:22:22 -0700375 struct ipzu_queue_resp ipz_squeue;
376 struct ipzu_queue_resp ipz_rqueue;
Heiko J Schickfab97222006-09-22 15:22:22 -0700377};
378
379struct ehca_alloc_cq_parms {
380 u32 nr_cqe;
381 u32 act_nr_of_entries;
382 u32 act_pages;
383 struct ipz_eq_handle eq_handle;
384};
385
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200386enum ehca_service_type {
387 ST_RC = 0,
388 ST_UC = 1,
389 ST_RD = 2,
390 ST_UD = 3,
391};
392
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200393enum ehca_ll_comp_flags {
394 LLQP_SEND_COMP = 0x20,
395 LLQP_RECV_COMP = 0x40,
396 LLQP_COMP_MASK = 0x60,
397};
398
Stefan Roschere2f81da2007-07-20 16:04:17 +0200399struct ehca_alloc_queue_parms {
400 /* input parameters */
401 int max_wr;
402 int max_sge;
403 int page_size;
404 int is_small;
405
406 /* output parameters */
407 u16 act_nr_wqes;
408 u8 act_nr_sges;
409 u32 queue_size; /* bytes for small queues, pages otherwise */
410};
411
Heiko J Schickfab97222006-09-22 15:22:22 -0700412struct ehca_alloc_qp_parms {
Stefan Roschere2f81da2007-07-20 16:04:17 +0200413 struct ehca_alloc_queue_parms squeue;
414 struct ehca_alloc_queue_parms rqueue;
415
416 /* input parameters */
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200417 enum ehca_service_type servicetype;
Stefan Roschere2f81da2007-07-20 16:04:17 +0200418 int qp_storage;
Heiko J Schickfab97222006-09-22 15:22:22 -0700419 int sigtype;
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200420 enum ehca_ext_qp_type ext_type;
421 enum ehca_ll_comp_flags ll_comp_flags;
Heiko J Schickfab97222006-09-22 15:22:22 -0700422 int ud_av_l_key_ctl;
423
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200424 u32 token;
425 struct ipz_eq_handle eq_handle;
426 struct ipz_pd pd;
427 struct ipz_cq_handle send_cq_handle, recv_cq_handle;
428
429 u32 srq_qpn, srq_token, srq_limit;
430
Stefan Roschere2f81da2007-07-20 16:04:17 +0200431 /* output parameters */
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200432 u32 real_qp_num;
433 struct ipz_qp_handle qp_handle;
434 struct h_galpas galpas;
Heiko J Schickfab97222006-09-22 15:22:22 -0700435};
436
437int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
438int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200439struct ehca_qp *ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);
Heiko J Schickfab97222006-09-22 15:22:22 -0700440
441#endif