blob: 0f7a55d35ea7e1f6e4dfd385c12108d5638fe576 [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;
97 struct ib_qp *ibqp_aqp1;
98 enum ib_rate rate;
99 enum ib_port_state port_state;
Joachim Fenkes8705ce52007-07-09 15:32:22 +0200100 struct ehca_sma_attr saved_attr;
Heiko J Schickfab97222006-09-22 15:22:22 -0700101};
102
Hoang-Nam Nguyen08c283a2007-09-13 18:14:58 +0200103#define HCA_CAP_MR_PGSIZE_4K 0x80000000
104#define HCA_CAP_MR_PGSIZE_64K 0x40000000
105#define HCA_CAP_MR_PGSIZE_1M 0x20000000
106#define HCA_CAP_MR_PGSIZE_16M 0x10000000
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200107
Heiko J Schickfab97222006-09-22 15:22:22 -0700108struct ehca_shca {
109 struct ib_device ib_device;
110 struct ibmebus_dev *ibmebus_dev;
111 u8 num_ports;
112 int hw_level;
113 struct list_head shca_list;
114 struct ipz_adapter_handle ipz_hca_handle;
115 struct ehca_sport sport[2];
116 struct ehca_eq eq;
117 struct ehca_eq neq;
118 struct ehca_mr *maxmr;
119 struct ehca_pd *pd;
120 struct h_galpas galpas;
Joachim Fenkesc4ed7902007-04-24 17:44:31 +0200121 struct mutex modify_mutex;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200122 u64 hca_cap;
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200123 /* MR pgsize: bit 0-3 means 4K, 64K, 1M, 16M respectively */
124 u32 hca_cap_mr_pgsize;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200125 int max_mtu;
Heiko J Schickfab97222006-09-22 15:22:22 -0700126};
127
128struct ehca_pd {
129 struct ib_pd ib_pd;
130 struct ipz_pd fw_pd;
131 u32 ownpid;
Stefan Roschere2f81da2007-07-20 16:04:17 +0200132 /* small queue mgmt */
133 struct mutex lock;
134 struct list_head free[2];
135 struct list_head full[2];
Heiko J Schickfab97222006-09-22 15:22:22 -0700136};
137
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200138enum ehca_ext_qp_type {
139 EQPT_NORMAL = 0,
140 EQPT_LLQP = 1,
141 EQPT_SRQBASE = 2,
142 EQPT_SRQ = 3,
143};
144
Heiko J Schickfab97222006-09-22 15:22:22 -0700145struct ehca_qp {
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200146 union {
147 struct ib_qp ib_qp;
148 struct ib_srq ib_srq;
149 };
Heiko J Schickfab97222006-09-22 15:22:22 -0700150 u32 qp_type;
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200151 enum ehca_ext_qp_type ext_type;
Heiko J Schickfab97222006-09-22 15:22:22 -0700152 struct ipz_queue ipz_squeue;
153 struct ipz_queue ipz_rqueue;
154 struct h_galpas galpas;
155 u32 qkey;
156 u32 real_qp_num;
157 u32 token;
158 spinlock_t spinlock_s;
159 spinlock_t spinlock_r;
160 u32 sq_max_inline_data_size;
161 struct ipz_qp_handle ipz_qp_handle;
162 struct ehca_pfqp pf;
163 struct ib_qp_init_attr init_attr;
Heiko J Schickfab97222006-09-22 15:22:22 -0700164 struct ehca_cq *send_cq;
165 struct ehca_cq *recv_cq;
166 unsigned int sqerr_purgeflag;
167 struct hlist_node list_entries;
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100168 /* mmap counter for resources mapped into user space */
169 u32 mm_count_squeue;
170 u32 mm_count_rqueue;
171 u32 mm_count_galpa;
Heiko J Schickfab97222006-09-22 15:22:22 -0700172};
173
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200174#define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
175#define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)
176#define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)
177
Heiko J Schickfab97222006-09-22 15:22:22 -0700178/* must be power of 2 */
179#define QP_HASHTAB_LEN 8
180
181struct ehca_cq {
182 struct ib_cq ib_cq;
183 struct ipz_queue ipz_queue;
184 struct h_galpas galpas;
185 spinlock_t spinlock;
186 u32 cq_number;
187 u32 token;
188 u32 nr_of_entries;
189 struct ipz_cq_handle ipz_cq_handle;
190 struct ehca_pfcq pf;
191 spinlock_t cb_lock;
Heiko J Schickfab97222006-09-22 15:22:22 -0700192 struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
193 struct list_head entry;
Joachim Fenkes28db6be2007-07-09 15:30:39 +0200194 u32 nr_callbacks; /* #events assigned to cpu by scaling code */
195 atomic_t nr_events; /* #events seen */
Hoang-Nam Nguyen31726792007-02-28 18:01:02 +0100196 wait_queue_head_t wait_completion;
Heiko J Schickfab97222006-09-22 15:22:22 -0700197 spinlock_t task_lock;
198 u32 ownpid;
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100199 /* mmap counter for resources mapped into user space */
200 u32 mm_count_queue;
201 u32 mm_count_galpa;
Heiko J Schickfab97222006-09-22 15:22:22 -0700202};
203
204enum ehca_mr_flag {
205 EHCA_MR_FLAG_FMR = 0x80000000, /* FMR, created with ehca_alloc_fmr */
206 EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR */
207};
208
209struct ehca_mr {
210 union {
211 struct ib_mr ib_mr; /* must always be first in ehca_mr */
212 struct ib_fmr ib_fmr; /* must always be first in ehca_mr */
213 } ib;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -0800214 struct ib_umem *umem;
Heiko J Schickfab97222006-09-22 15:22:22 -0700215 spinlock_t mrlock;
216
217 enum ehca_mr_flag flags;
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200218 u32 num_kpages; /* number of kernel pages */
219 u32 num_hwpages; /* number of hw pages to form MR */
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200220 u64 hwpage_size; /* hw page size used for this MR */
Heiko J Schickfab97222006-09-22 15:22:22 -0700221 int acl; /* ACL (stored here for usage in reregister) */
222 u64 *start; /* virtual start address (stored here for */
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200223 /* usage in reregister) */
Heiko J Schickfab97222006-09-22 15:22:22 -0700224 u64 size; /* size (stored here for usage in reregister) */
225 u32 fmr_page_size; /* page size for FMR */
226 u32 fmr_max_pages; /* max pages for FMR */
227 u32 fmr_max_maps; /* max outstanding maps for FMR */
228 u32 fmr_map_cnt; /* map counter for FMR */
229 /* fw specific data */
230 struct ipz_mrmw_handle ipz_mr_handle; /* MR handle for h-calls */
231 struct h_galpas galpas;
Heiko J Schickfab97222006-09-22 15:22:22 -0700232};
233
234struct ehca_mw {
235 struct ib_mw ib_mw; /* gen2 mw, must always be first in ehca_mw */
236 spinlock_t mwlock;
237
238 u8 never_bound; /* indication MW was never bound */
239 struct ipz_mrmw_handle ipz_mw_handle; /* MW handle for h-calls */
240 struct h_galpas galpas;
241};
242
243enum ehca_mr_pgi_type {
244 EHCA_MR_PGI_PHYS = 1, /* type of ehca_reg_phys_mr,
245 * ehca_rereg_phys_mr,
246 * ehca_reg_internal_maxmr */
247 EHCA_MR_PGI_USER = 2, /* type of ehca_reg_user_mr */
248 EHCA_MR_PGI_FMR = 3 /* type of ehca_map_phys_fmr */
249};
250
251struct ehca_mr_pginfo {
252 enum ehca_mr_pgi_type type;
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200253 u64 num_kpages;
254 u64 kpage_cnt;
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200255 u64 hwpage_size; /* hw page size used for this MR */
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200256 u64 num_hwpages; /* number of hw pages */
257 u64 hwpage_cnt; /* counter for hw pages */
258 u64 next_hwpage; /* next hw page in buffer/chunk/listelem */
Heiko J Schickfab97222006-09-22 15:22:22 -0700259
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200260 union {
261 struct { /* type EHCA_MR_PGI_PHYS section */
262 int num_phys_buf;
263 struct ib_phys_buf *phys_buf_array;
264 u64 next_buf;
265 } phy;
266 struct { /* type EHCA_MR_PGI_USER section */
267 struct ib_umem *region;
268 struct ib_umem_chunk *next_chunk;
269 u64 next_nmap;
270 } usr;
271 struct { /* type EHCA_MR_PGI_FMR section */
272 u64 fmr_pgsize;
273 u64 *page_list;
274 u64 next_listelem;
275 } fmr;
276 } u;
Heiko J Schickfab97222006-09-22 15:22:22 -0700277};
278
279/* output parameters for MR/FMR hipz calls */
280struct ehca_mr_hipzout_parms {
281 struct ipz_mrmw_handle handle;
282 u32 lkey;
283 u32 rkey;
284 u64 len;
285 u64 vaddr;
286 u32 acl;
287};
288
289/* output parameters for MW hipz calls */
290struct ehca_mw_hipzout_parms {
291 struct ipz_mrmw_handle handle;
292 u32 rkey;
293};
294
295struct ehca_av {
296 struct ib_ah ib_ah;
297 struct ehca_ud_av av;
298};
299
300struct ehca_ucontext {
301 struct ib_ucontext ib_ucontext;
302};
303
Heiko J Schickfab97222006-09-22 15:22:22 -0700304int ehca_init_pd_cache(void);
305void ehca_cleanup_pd_cache(void);
306int ehca_init_cq_cache(void);
307void ehca_cleanup_cq_cache(void);
308int ehca_init_qp_cache(void);
309void ehca_cleanup_qp_cache(void);
310int ehca_init_av_cache(void);
311void ehca_cleanup_av_cache(void);
312int ehca_init_mrmw_cache(void);
313void ehca_cleanup_mrmw_cache(void);
Stefan Roschere2f81da2007-07-20 16:04:17 +0200314int ehca_init_small_qp_cache(void);
315void ehca_cleanup_small_qp_cache(void);
Heiko J Schickfab97222006-09-22 15:22:22 -0700316
Joachim Fenkes26ed6872007-07-09 15:31:10 +0200317extern rwlock_t ehca_qp_idr_lock;
318extern rwlock_t ehca_cq_idr_lock;
Heiko J Schickfab97222006-09-22 15:22:22 -0700319extern struct idr ehca_qp_idr;
320extern struct idr ehca_cq_idr;
321
322extern int ehca_static_rate;
323extern int ehca_port_act_time;
324extern int ehca_use_hp_mr;
Hoang-Nam Nguyen4fd30062007-02-15 17:08:33 +0100325extern int ehca_scaling_code;
Hoang-Nam Nguyen1655fc22007-07-28 21:47:53 -0700326extern int ehca_mr_largepage;
Heiko J Schickfab97222006-09-22 15:22:22 -0700327
328struct ipzu_queue_resp {
Heiko J Schickfab97222006-09-22 15:22:22 -0700329 u32 qe_size; /* queue entry size */
330 u32 act_nr_of_sg;
331 u32 queue_length; /* queue length allocated in bytes */
332 u32 pagesize;
333 u32 toggle_state;
Stefan Roschere2f81da2007-07-20 16:04:17 +0200334 u32 offset; /* save offset within a page for small_qp */
Heiko J Schickfab97222006-09-22 15:22:22 -0700335};
336
337struct ehca_create_cq_resp {
338 u32 cq_number;
339 u32 token;
340 struct ipzu_queue_resp ipz_queue;
Hoang-Nam Nguyene390d3b2007-09-11 15:31:06 +0200341 u32 fw_handle_ofs;
342 u32 dummy;
Heiko J Schickfab97222006-09-22 15:22:22 -0700343};
344
345struct ehca_create_qp_resp {
346 u32 qp_num;
347 u32 token;
348 u32 qp_type;
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200349 u32 ext_type;
Heiko J Schickfab97222006-09-22 15:22:22 -0700350 u32 qkey;
351 /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
352 u32 real_qp_num;
Hoang-Nam Nguyene390d3b2007-09-11 15:31:06 +0200353 u32 fw_handle_ofs;
Hoang-Nam Nguyena6607222007-09-28 17:18:47 +0200354 u32 dummy;
Heiko J Schickfab97222006-09-22 15:22:22 -0700355 struct ipzu_queue_resp ipz_squeue;
356 struct ipzu_queue_resp ipz_rqueue;
Heiko J Schickfab97222006-09-22 15:22:22 -0700357};
358
359struct ehca_alloc_cq_parms {
360 u32 nr_cqe;
361 u32 act_nr_of_entries;
362 u32 act_pages;
363 struct ipz_eq_handle eq_handle;
364};
365
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200366enum ehca_service_type {
367 ST_RC = 0,
368 ST_UC = 1,
369 ST_RD = 2,
370 ST_UD = 3,
371};
372
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200373enum ehca_ll_comp_flags {
374 LLQP_SEND_COMP = 0x20,
375 LLQP_RECV_COMP = 0x40,
376 LLQP_COMP_MASK = 0x60,
377};
378
Stefan Roschere2f81da2007-07-20 16:04:17 +0200379struct ehca_alloc_queue_parms {
380 /* input parameters */
381 int max_wr;
382 int max_sge;
383 int page_size;
384 int is_small;
385
386 /* output parameters */
387 u16 act_nr_wqes;
388 u8 act_nr_sges;
389 u32 queue_size; /* bytes for small queues, pages otherwise */
390};
391
Heiko J Schickfab97222006-09-22 15:22:22 -0700392struct ehca_alloc_qp_parms {
Stefan Roschere2f81da2007-07-20 16:04:17 +0200393 struct ehca_alloc_queue_parms squeue;
394 struct ehca_alloc_queue_parms rqueue;
395
396 /* input parameters */
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200397 enum ehca_service_type servicetype;
Stefan Roschere2f81da2007-07-20 16:04:17 +0200398 int qp_storage;
Heiko J Schickfab97222006-09-22 15:22:22 -0700399 int sigtype;
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200400 enum ehca_ext_qp_type ext_type;
401 enum ehca_ll_comp_flags ll_comp_flags;
Heiko J Schickfab97222006-09-22 15:22:22 -0700402 int ud_av_l_key_ctl;
403
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200404 u32 token;
405 struct ipz_eq_handle eq_handle;
406 struct ipz_pd pd;
407 struct ipz_cq_handle send_cq_handle, recv_cq_handle;
408
409 u32 srq_qpn, srq_token, srq_limit;
410
Stefan Roschere2f81da2007-07-20 16:04:17 +0200411 /* output parameters */
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200412 u32 real_qp_num;
413 struct ipz_qp_handle qp_handle;
414 struct h_galpas galpas;
Heiko J Schickfab97222006-09-22 15:22:22 -0700415};
416
417int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
418int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200419struct ehca_qp *ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);
Heiko J Schickfab97222006-09-22 15:22:22 -0700420
421#endif