blob: 9d689aeb928a4030a8033ec8d8e9e1b64812e7cf [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 -070046
47struct ehca_module;
48struct ehca_qp;
49struct ehca_cq;
50struct ehca_eq;
51struct ehca_mr;
52struct ehca_mw;
53struct ehca_pd;
54struct ehca_av;
55
Hoang-Nam Nguyen31726792007-02-28 18:01:02 +010056#include <linux/wait.h>
57
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
90struct ehca_sport {
91 struct ib_cq *ibcq_aqp1;
92 struct ib_qp *ibqp_aqp1;
93 enum ib_rate rate;
94 enum ib_port_state port_state;
95};
96
97struct ehca_shca {
98 struct ib_device ib_device;
99 struct ibmebus_dev *ibmebus_dev;
100 u8 num_ports;
101 int hw_level;
102 struct list_head shca_list;
103 struct ipz_adapter_handle ipz_hca_handle;
104 struct ehca_sport sport[2];
105 struct ehca_eq eq;
106 struct ehca_eq neq;
107 struct ehca_mr *maxmr;
108 struct ehca_pd *pd;
109 struct h_galpas galpas;
Joachim Fenkesc4ed7902007-04-24 17:44:31 +0200110 struct mutex modify_mutex;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200111 u64 hca_cap;
112 int max_mtu;
Heiko J Schickfab97222006-09-22 15:22:22 -0700113};
114
115struct ehca_pd {
116 struct ib_pd ib_pd;
117 struct ipz_pd fw_pd;
118 u32 ownpid;
119};
120
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200121enum ehca_ext_qp_type {
122 EQPT_NORMAL = 0,
123 EQPT_LLQP = 1,
124 EQPT_SRQBASE = 2,
125 EQPT_SRQ = 3,
126};
127
Heiko J Schickfab97222006-09-22 15:22:22 -0700128struct ehca_qp {
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200129 union {
130 struct ib_qp ib_qp;
131 struct ib_srq ib_srq;
132 };
Heiko J Schickfab97222006-09-22 15:22:22 -0700133 u32 qp_type;
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200134 enum ehca_ext_qp_type ext_type;
Heiko J Schickfab97222006-09-22 15:22:22 -0700135 struct ipz_queue ipz_squeue;
136 struct ipz_queue ipz_rqueue;
137 struct h_galpas galpas;
138 u32 qkey;
139 u32 real_qp_num;
140 u32 token;
141 spinlock_t spinlock_s;
142 spinlock_t spinlock_r;
143 u32 sq_max_inline_data_size;
144 struct ipz_qp_handle ipz_qp_handle;
145 struct ehca_pfqp pf;
146 struct ib_qp_init_attr init_attr;
Heiko J Schickfab97222006-09-22 15:22:22 -0700147 struct ehca_cq *send_cq;
148 struct ehca_cq *recv_cq;
149 unsigned int sqerr_purgeflag;
150 struct hlist_node list_entries;
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100151 /* mmap counter for resources mapped into user space */
152 u32 mm_count_squeue;
153 u32 mm_count_rqueue;
154 u32 mm_count_galpa;
Heiko J Schickfab97222006-09-22 15:22:22 -0700155};
156
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200157#define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
158#define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)
159#define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)
160
Heiko J Schickfab97222006-09-22 15:22:22 -0700161/* must be power of 2 */
162#define QP_HASHTAB_LEN 8
163
164struct ehca_cq {
165 struct ib_cq ib_cq;
166 struct ipz_queue ipz_queue;
167 struct h_galpas galpas;
168 spinlock_t spinlock;
169 u32 cq_number;
170 u32 token;
171 u32 nr_of_entries;
172 struct ipz_cq_handle ipz_cq_handle;
173 struct ehca_pfcq pf;
174 spinlock_t cb_lock;
Heiko J Schickfab97222006-09-22 15:22:22 -0700175 struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
176 struct list_head entry;
Hoang-Nam Nguyen31726792007-02-28 18:01:02 +0100177 u32 nr_callbacks; /* #events assigned to cpu by scaling code */
178 u32 nr_events; /* #events seen */
179 wait_queue_head_t wait_completion;
Heiko J Schickfab97222006-09-22 15:22:22 -0700180 spinlock_t task_lock;
181 u32 ownpid;
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100182 /* mmap counter for resources mapped into user space */
183 u32 mm_count_queue;
184 u32 mm_count_galpa;
Heiko J Schickfab97222006-09-22 15:22:22 -0700185};
186
187enum ehca_mr_flag {
188 EHCA_MR_FLAG_FMR = 0x80000000, /* FMR, created with ehca_alloc_fmr */
189 EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR */
190};
191
192struct ehca_mr {
193 union {
194 struct ib_mr ib_mr; /* must always be first in ehca_mr */
195 struct ib_fmr ib_fmr; /* must always be first in ehca_mr */
196 } ib;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -0800197 struct ib_umem *umem;
Heiko J Schickfab97222006-09-22 15:22:22 -0700198 spinlock_t mrlock;
199
200 enum ehca_mr_flag flags;
201 u32 num_pages; /* number of MR pages */
202 u32 num_4k; /* number of 4k "page" portions to form MR */
203 int acl; /* ACL (stored here for usage in reregister) */
204 u64 *start; /* virtual start address (stored here for */
205 /* usage in reregister) */
206 u64 size; /* size (stored here for usage in reregister) */
207 u32 fmr_page_size; /* page size for FMR */
208 u32 fmr_max_pages; /* max pages for FMR */
209 u32 fmr_max_maps; /* max outstanding maps for FMR */
210 u32 fmr_map_cnt; /* map counter for FMR */
211 /* fw specific data */
212 struct ipz_mrmw_handle ipz_mr_handle; /* MR handle for h-calls */
213 struct h_galpas galpas;
214 /* data for userspace bridge */
215 u32 nr_of_pages;
216 void *pagearray;
217};
218
219struct ehca_mw {
220 struct ib_mw ib_mw; /* gen2 mw, must always be first in ehca_mw */
221 spinlock_t mwlock;
222
223 u8 never_bound; /* indication MW was never bound */
224 struct ipz_mrmw_handle ipz_mw_handle; /* MW handle for h-calls */
225 struct h_galpas galpas;
226};
227
228enum ehca_mr_pgi_type {
229 EHCA_MR_PGI_PHYS = 1, /* type of ehca_reg_phys_mr,
230 * ehca_rereg_phys_mr,
231 * ehca_reg_internal_maxmr */
232 EHCA_MR_PGI_USER = 2, /* type of ehca_reg_user_mr */
233 EHCA_MR_PGI_FMR = 3 /* type of ehca_map_phys_fmr */
234};
235
236struct ehca_mr_pginfo {
237 enum ehca_mr_pgi_type type;
238 u64 num_pages;
239 u64 page_cnt;
240 u64 num_4k; /* number of 4k "page" portions */
241 u64 page_4k_cnt; /* counter for 4k "page" portions */
242 u64 next_4k; /* next 4k "page" portion in buffer/chunk/listelem */
243
244 /* type EHCA_MR_PGI_PHYS section */
245 int num_phys_buf;
246 struct ib_phys_buf *phys_buf_array;
247 u64 next_buf;
248
249 /* type EHCA_MR_PGI_USER section */
250 struct ib_umem *region;
251 struct ib_umem_chunk *next_chunk;
252 u64 next_nmap;
253
254 /* type EHCA_MR_PGI_FMR section */
255 u64 *page_list;
256 u64 next_listelem;
257 /* next_4k also used within EHCA_MR_PGI_FMR */
258};
259
260/* output parameters for MR/FMR hipz calls */
261struct ehca_mr_hipzout_parms {
262 struct ipz_mrmw_handle handle;
263 u32 lkey;
264 u32 rkey;
265 u64 len;
266 u64 vaddr;
267 u32 acl;
268};
269
270/* output parameters for MW hipz calls */
271struct ehca_mw_hipzout_parms {
272 struct ipz_mrmw_handle handle;
273 u32 rkey;
274};
275
276struct ehca_av {
277 struct ib_ah ib_ah;
278 struct ehca_ud_av av;
279};
280
281struct ehca_ucontext {
282 struct ib_ucontext ib_ucontext;
283};
284
Heiko J Schickfab97222006-09-22 15:22:22 -0700285int ehca_init_pd_cache(void);
286void ehca_cleanup_pd_cache(void);
287int ehca_init_cq_cache(void);
288void ehca_cleanup_cq_cache(void);
289int ehca_init_qp_cache(void);
290void ehca_cleanup_qp_cache(void);
291int ehca_init_av_cache(void);
292void ehca_cleanup_av_cache(void);
293int ehca_init_mrmw_cache(void);
294void ehca_cleanup_mrmw_cache(void);
295
296extern spinlock_t ehca_qp_idr_lock;
297extern spinlock_t ehca_cq_idr_lock;
Stefan Roscher5d882782007-05-09 13:47:56 +0200298extern spinlock_t hcall_lock;
Heiko J Schickfab97222006-09-22 15:22:22 -0700299extern struct idr ehca_qp_idr;
300extern struct idr ehca_cq_idr;
301
302extern int ehca_static_rate;
303extern int ehca_port_act_time;
304extern int ehca_use_hp_mr;
Hoang-Nam Nguyen4fd30062007-02-15 17:08:33 +0100305extern int ehca_scaling_code;
Heiko J Schickfab97222006-09-22 15:22:22 -0700306
307struct ipzu_queue_resp {
Heiko J Schickfab97222006-09-22 15:22:22 -0700308 u32 qe_size; /* queue entry size */
309 u32 act_nr_of_sg;
310 u32 queue_length; /* queue length allocated in bytes */
311 u32 pagesize;
312 u32 toggle_state;
313 u32 dummy; /* padding for 8 byte alignment */
314};
315
316struct ehca_create_cq_resp {
317 u32 cq_number;
318 u32 token;
319 struct ipzu_queue_resp ipz_queue;
Heiko J Schickfab97222006-09-22 15:22:22 -0700320};
321
322struct ehca_create_qp_resp {
323 u32 qp_num;
324 u32 token;
325 u32 qp_type;
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200326 u32 ext_type;
Heiko J Schickfab97222006-09-22 15:22:22 -0700327 u32 qkey;
328 /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
329 u32 real_qp_num;
330 u32 dummy; /* padding for 8 byte alignment */
331 struct ipzu_queue_resp ipz_squeue;
332 struct ipzu_queue_resp ipz_rqueue;
Heiko J Schickfab97222006-09-22 15:22:22 -0700333};
334
335struct ehca_alloc_cq_parms {
336 u32 nr_cqe;
337 u32 act_nr_of_entries;
338 u32 act_pages;
339 struct ipz_eq_handle eq_handle;
340};
341
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200342enum ehca_service_type {
343 ST_RC = 0,
344 ST_UC = 1,
345 ST_RD = 2,
346 ST_UD = 3,
347};
348
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200349enum ehca_ll_comp_flags {
350 LLQP_SEND_COMP = 0x20,
351 LLQP_RECV_COMP = 0x40,
352 LLQP_COMP_MASK = 0x60,
353};
354
Heiko J Schickfab97222006-09-22 15:22:22 -0700355struct ehca_alloc_qp_parms {
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200356/* input parameters */
357 enum ehca_service_type servicetype;
Heiko J Schickfab97222006-09-22 15:22:22 -0700358 int sigtype;
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200359 enum ehca_ext_qp_type ext_type;
360 enum ehca_ll_comp_flags ll_comp_flags;
361
362 int max_send_wr, max_recv_wr;
363 int max_send_sge, max_recv_sge;
Heiko J Schickfab97222006-09-22 15:22:22 -0700364 int ud_av_l_key_ctl;
365
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200366 u32 token;
367 struct ipz_eq_handle eq_handle;
368 struct ipz_pd pd;
369 struct ipz_cq_handle send_cq_handle, recv_cq_handle;
370
371 u32 srq_qpn, srq_token, srq_limit;
372
373/* output parameters */
374 u32 real_qp_num;
375 struct ipz_qp_handle qp_handle;
376 struct h_galpas galpas;
377
Heiko J Schickfab97222006-09-22 15:22:22 -0700378 u16 act_nr_send_wqes;
379 u16 act_nr_recv_wqes;
380 u8 act_nr_recv_sges;
381 u8 act_nr_send_sges;
382
383 u32 nr_rq_pages;
384 u32 nr_sq_pages;
Heiko J Schickfab97222006-09-22 15:22:22 -0700385};
386
387int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
388int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
389struct ehca_qp* ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);
390
391#endif