blob: b5e96030531642c7a95fc6141d1a4228137fa3ac [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>
56
Heiko J Schickfab97222006-09-22 15:22:22 -070057#include <rdma/ib_verbs.h>
58#include <rdma/ib_user_verbs.h>
59
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +010060#ifdef CONFIG_PPC64
61#include "ehca_classes_pSeries.h"
62#endif
63#include "ipz_pt_fn.h"
64#include "ehca_qes.h"
Heiko J Schickfab97222006-09-22 15:22:22 -070065#include "ehca_irq.h"
66
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +010067#define EHCA_EQE_CACHE_SIZE 20
68
69struct ehca_eqe_cache_entry {
70 struct ehca_eqe *eqe;
71 struct ehca_cq *cq;
72};
73
Heiko J Schickfab97222006-09-22 15:22:22 -070074struct ehca_eq {
75 u32 length;
76 struct ipz_queue ipz_queue;
77 struct ipz_eq_handle ipz_eq_handle;
78 struct work_struct work;
79 struct h_galpas galpas;
80 int is_initialized;
81 struct ehca_pfeq pf;
82 spinlock_t spinlock;
83 struct tasklet_struct interrupt_task;
84 u32 ist;
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +010085 spinlock_t irq_spinlock;
86 struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
Heiko J Schickfab97222006-09-22 15:22:22 -070087};
88
Joachim Fenkes8705ce52007-07-09 15:32:22 +020089struct ehca_sma_attr {
90 u16 lid, lmc, sm_sl, sm_lid;
91 u16 pkey_tbl_len, pkeys[16];
92};
93
Heiko J Schickfab97222006-09-22 15:22:22 -070094struct ehca_sport {
95 struct ib_cq *ibcq_aqp1;
96 struct ib_qp *ibqp_aqp1;
97 enum ib_rate rate;
98 enum ib_port_state port_state;
Joachim Fenkes8705ce52007-07-09 15:32:22 +020099 struct ehca_sma_attr saved_attr;
Heiko J Schickfab97222006-09-22 15:22:22 -0700100};
101
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200102#define HCA_CAP_MR_PGSIZE_4K 1
103#define HCA_CAP_MR_PGSIZE_64K 2
104#define HCA_CAP_MR_PGSIZE_1M 4
105#define HCA_CAP_MR_PGSIZE_16M 8
106
Heiko J Schickfab97222006-09-22 15:22:22 -0700107struct ehca_shca {
108 struct ib_device ib_device;
109 struct ibmebus_dev *ibmebus_dev;
110 u8 num_ports;
111 int hw_level;
112 struct list_head shca_list;
113 struct ipz_adapter_handle ipz_hca_handle;
114 struct ehca_sport sport[2];
115 struct ehca_eq eq;
116 struct ehca_eq neq;
117 struct ehca_mr *maxmr;
118 struct ehca_pd *pd;
119 struct h_galpas galpas;
Joachim Fenkesc4ed7902007-04-24 17:44:31 +0200120 struct mutex modify_mutex;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200121 u64 hca_cap;
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200122 /* MR pgsize: bit 0-3 means 4K, 64K, 1M, 16M respectively */
123 u32 hca_cap_mr_pgsize;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200124 int max_mtu;
Heiko J Schickfab97222006-09-22 15:22:22 -0700125};
126
127struct ehca_pd {
128 struct ib_pd ib_pd;
129 struct ipz_pd fw_pd;
130 u32 ownpid;
Stefan Roschere2f81da2007-07-20 16:04:17 +0200131 /* small queue mgmt */
132 struct mutex lock;
133 struct list_head free[2];
134 struct list_head full[2];
Heiko J Schickfab97222006-09-22 15:22:22 -0700135};
136
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200137enum ehca_ext_qp_type {
138 EQPT_NORMAL = 0,
139 EQPT_LLQP = 1,
140 EQPT_SRQBASE = 2,
141 EQPT_SRQ = 3,
142};
143
Heiko J Schickfab97222006-09-22 15:22:22 -0700144struct ehca_qp {
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200145 union {
146 struct ib_qp ib_qp;
147 struct ib_srq ib_srq;
148 };
Heiko J Schickfab97222006-09-22 15:22:22 -0700149 u32 qp_type;
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200150 enum ehca_ext_qp_type ext_type;
Heiko J Schickfab97222006-09-22 15:22:22 -0700151 struct ipz_queue ipz_squeue;
152 struct ipz_queue ipz_rqueue;
153 struct h_galpas galpas;
154 u32 qkey;
155 u32 real_qp_num;
156 u32 token;
157 spinlock_t spinlock_s;
158 spinlock_t spinlock_r;
159 u32 sq_max_inline_data_size;
160 struct ipz_qp_handle ipz_qp_handle;
161 struct ehca_pfqp pf;
162 struct ib_qp_init_attr init_attr;
Heiko J Schickfab97222006-09-22 15:22:22 -0700163 struct ehca_cq *send_cq;
164 struct ehca_cq *recv_cq;
165 unsigned int sqerr_purgeflag;
166 struct hlist_node list_entries;
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100167 /* mmap counter for resources mapped into user space */
168 u32 mm_count_squeue;
169 u32 mm_count_rqueue;
170 u32 mm_count_galpa;
Heiko J Schickfab97222006-09-22 15:22:22 -0700171};
172
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200173#define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
174#define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)
175#define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)
176
Heiko J Schickfab97222006-09-22 15:22:22 -0700177/* must be power of 2 */
178#define QP_HASHTAB_LEN 8
179
180struct ehca_cq {
181 struct ib_cq ib_cq;
182 struct ipz_queue ipz_queue;
183 struct h_galpas galpas;
184 spinlock_t spinlock;
185 u32 cq_number;
186 u32 token;
187 u32 nr_of_entries;
188 struct ipz_cq_handle ipz_cq_handle;
189 struct ehca_pfcq pf;
190 spinlock_t cb_lock;
Heiko J Schickfab97222006-09-22 15:22:22 -0700191 struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
192 struct list_head entry;
Joachim Fenkes28db6be2007-07-09 15:30:39 +0200193 u32 nr_callbacks; /* #events assigned to cpu by scaling code */
194 atomic_t nr_events; /* #events seen */
Hoang-Nam Nguyen31726792007-02-28 18:01:02 +0100195 wait_queue_head_t wait_completion;
Heiko J Schickfab97222006-09-22 15:22:22 -0700196 spinlock_t task_lock;
197 u32 ownpid;
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100198 /* mmap counter for resources mapped into user space */
199 u32 mm_count_queue;
200 u32 mm_count_galpa;
Heiko J Schickfab97222006-09-22 15:22:22 -0700201};
202
203enum ehca_mr_flag {
204 EHCA_MR_FLAG_FMR = 0x80000000, /* FMR, created with ehca_alloc_fmr */
205 EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR */
206};
207
208struct ehca_mr {
209 union {
210 struct ib_mr ib_mr; /* must always be first in ehca_mr */
211 struct ib_fmr ib_fmr; /* must always be first in ehca_mr */
212 } ib;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -0800213 struct ib_umem *umem;
Heiko J Schickfab97222006-09-22 15:22:22 -0700214 spinlock_t mrlock;
215
216 enum ehca_mr_flag flags;
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200217 u32 num_kpages; /* number of kernel pages */
218 u32 num_hwpages; /* number of hw pages to form MR */
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200219 u64 hwpage_size; /* hw page size used for this MR */
Heiko J Schickfab97222006-09-22 15:22:22 -0700220 int acl; /* ACL (stored here for usage in reregister) */
221 u64 *start; /* virtual start address (stored here for */
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200222 /* usage in reregister) */
Heiko J Schickfab97222006-09-22 15:22:22 -0700223 u64 size; /* size (stored here for usage in reregister) */
224 u32 fmr_page_size; /* page size for FMR */
225 u32 fmr_max_pages; /* max pages for FMR */
226 u32 fmr_max_maps; /* max outstanding maps for FMR */
227 u32 fmr_map_cnt; /* map counter for FMR */
228 /* fw specific data */
229 struct ipz_mrmw_handle ipz_mr_handle; /* MR handle for h-calls */
230 struct h_galpas galpas;
Heiko J Schickfab97222006-09-22 15:22:22 -0700231};
232
233struct ehca_mw {
234 struct ib_mw ib_mw; /* gen2 mw, must always be first in ehca_mw */
235 spinlock_t mwlock;
236
237 u8 never_bound; /* indication MW was never bound */
238 struct ipz_mrmw_handle ipz_mw_handle; /* MW handle for h-calls */
239 struct h_galpas galpas;
240};
241
242enum ehca_mr_pgi_type {
243 EHCA_MR_PGI_PHYS = 1, /* type of ehca_reg_phys_mr,
244 * ehca_rereg_phys_mr,
245 * ehca_reg_internal_maxmr */
246 EHCA_MR_PGI_USER = 2, /* type of ehca_reg_user_mr */
247 EHCA_MR_PGI_FMR = 3 /* type of ehca_map_phys_fmr */
248};
249
250struct ehca_mr_pginfo {
251 enum ehca_mr_pgi_type type;
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200252 u64 num_kpages;
253 u64 kpage_cnt;
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200254 u64 hwpage_size; /* hw page size used for this MR */
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200255 u64 num_hwpages; /* number of hw pages */
256 u64 hwpage_cnt; /* counter for hw pages */
257 u64 next_hwpage; /* next hw page in buffer/chunk/listelem */
Heiko J Schickfab97222006-09-22 15:22:22 -0700258
Hoang-Nam Nguyendf17bfd2007-07-12 17:52:29 +0200259 union {
260 struct { /* type EHCA_MR_PGI_PHYS section */
261 int num_phys_buf;
262 struct ib_phys_buf *phys_buf_array;
263 u64 next_buf;
264 } phy;
265 struct { /* type EHCA_MR_PGI_USER section */
266 struct ib_umem *region;
267 struct ib_umem_chunk *next_chunk;
268 u64 next_nmap;
269 } usr;
270 struct { /* type EHCA_MR_PGI_FMR section */
271 u64 fmr_pgsize;
272 u64 *page_list;
273 u64 next_listelem;
274 } fmr;
275 } u;
Heiko J Schickfab97222006-09-22 15:22:22 -0700276};
277
278/* output parameters for MR/FMR hipz calls */
279struct ehca_mr_hipzout_parms {
280 struct ipz_mrmw_handle handle;
281 u32 lkey;
282 u32 rkey;
283 u64 len;
284 u64 vaddr;
285 u32 acl;
286};
287
288/* output parameters for MW hipz calls */
289struct ehca_mw_hipzout_parms {
290 struct ipz_mrmw_handle handle;
291 u32 rkey;
292};
293
294struct ehca_av {
295 struct ib_ah ib_ah;
296 struct ehca_ud_av av;
297};
298
299struct ehca_ucontext {
300 struct ib_ucontext ib_ucontext;
301};
302
Heiko J Schickfab97222006-09-22 15:22:22 -0700303int ehca_init_pd_cache(void);
304void ehca_cleanup_pd_cache(void);
305int ehca_init_cq_cache(void);
306void ehca_cleanup_cq_cache(void);
307int ehca_init_qp_cache(void);
308void ehca_cleanup_qp_cache(void);
309int ehca_init_av_cache(void);
310void ehca_cleanup_av_cache(void);
311int ehca_init_mrmw_cache(void);
312void ehca_cleanup_mrmw_cache(void);
Stefan Roschere2f81da2007-07-20 16:04:17 +0200313int ehca_init_small_qp_cache(void);
314void ehca_cleanup_small_qp_cache(void);
Heiko J Schickfab97222006-09-22 15:22:22 -0700315
Joachim Fenkes26ed6872007-07-09 15:31:10 +0200316extern rwlock_t ehca_qp_idr_lock;
317extern rwlock_t ehca_cq_idr_lock;
Heiko J Schickfab97222006-09-22 15:22:22 -0700318extern struct idr ehca_qp_idr;
319extern struct idr ehca_cq_idr;
320
321extern int ehca_static_rate;
322extern int ehca_port_act_time;
323extern int ehca_use_hp_mr;
Hoang-Nam Nguyen4fd30062007-02-15 17:08:33 +0100324extern int ehca_scaling_code;
Hoang-Nam Nguyen1655fc22007-07-28 21:47:53 -0700325extern int ehca_mr_largepage;
Heiko J Schickfab97222006-09-22 15:22:22 -0700326
327struct ipzu_queue_resp {
Heiko J Schickfab97222006-09-22 15:22:22 -0700328 u32 qe_size; /* queue entry size */
329 u32 act_nr_of_sg;
330 u32 queue_length; /* queue length allocated in bytes */
331 u32 pagesize;
332 u32 toggle_state;
Stefan Roschere2f81da2007-07-20 16:04:17 +0200333 u32 offset; /* save offset within a page for small_qp */
Heiko J Schickfab97222006-09-22 15:22:22 -0700334};
335
336struct ehca_create_cq_resp {
337 u32 cq_number;
338 u32 token;
339 struct ipzu_queue_resp ipz_queue;
Heiko J Schickfab97222006-09-22 15:22:22 -0700340};
341
342struct ehca_create_qp_resp {
343 u32 qp_num;
344 u32 token;
345 u32 qp_type;
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200346 u32 ext_type;
Heiko J Schickfab97222006-09-22 15:22:22 -0700347 u32 qkey;
348 /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
349 u32 real_qp_num;
350 u32 dummy; /* padding for 8 byte alignment */
351 struct ipzu_queue_resp ipz_squeue;
352 struct ipzu_queue_resp ipz_rqueue;
Heiko J Schickfab97222006-09-22 15:22:22 -0700353};
354
355struct ehca_alloc_cq_parms {
356 u32 nr_cqe;
357 u32 act_nr_of_entries;
358 u32 act_pages;
359 struct ipz_eq_handle eq_handle;
360};
361
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200362enum ehca_service_type {
363 ST_RC = 0,
364 ST_UC = 1,
365 ST_RD = 2,
366 ST_UD = 3,
367};
368
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200369enum ehca_ll_comp_flags {
370 LLQP_SEND_COMP = 0x20,
371 LLQP_RECV_COMP = 0x40,
372 LLQP_COMP_MASK = 0x60,
373};
374
Stefan Roschere2f81da2007-07-20 16:04:17 +0200375struct ehca_alloc_queue_parms {
376 /* input parameters */
377 int max_wr;
378 int max_sge;
379 int page_size;
380 int is_small;
381
382 /* output parameters */
383 u16 act_nr_wqes;
384 u8 act_nr_sges;
385 u32 queue_size; /* bytes for small queues, pages otherwise */
386};
387
Heiko J Schickfab97222006-09-22 15:22:22 -0700388struct ehca_alloc_qp_parms {
Stefan Roschere2f81da2007-07-20 16:04:17 +0200389 struct ehca_alloc_queue_parms squeue;
390 struct ehca_alloc_queue_parms rqueue;
391
392 /* input parameters */
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200393 enum ehca_service_type servicetype;
Stefan Roschere2f81da2007-07-20 16:04:17 +0200394 int qp_storage;
Heiko J Schickfab97222006-09-22 15:22:22 -0700395 int sigtype;
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200396 enum ehca_ext_qp_type ext_type;
397 enum ehca_ll_comp_flags ll_comp_flags;
Heiko J Schickfab97222006-09-22 15:22:22 -0700398 int ud_av_l_key_ctl;
399
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200400 u32 token;
401 struct ipz_eq_handle eq_handle;
402 struct ipz_pd pd;
403 struct ipz_cq_handle send_cq_handle, recv_cq_handle;
404
405 u32 srq_qpn, srq_token, srq_limit;
406
Stefan Roschere2f81da2007-07-20 16:04:17 +0200407 /* output parameters */
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200408 u32 real_qp_num;
409 struct ipz_qp_handle qp_handle;
410 struct h_galpas galpas;
Heiko J Schickfab97222006-09-22 15:22:22 -0700411};
412
413int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
414int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200415struct ehca_qp *ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);
Heiko J Schickfab97222006-09-22 15:22:22 -0700416
417#endif