blob: 6e75db68996ed10a20edead0f6467d6871277221 [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>
8 *
9 * Copyright (c) 2005 IBM Corporation
10 *
11 * All rights reserved.
12 *
13 * This source code is distributed under a dual license of GPL v2.0 and OpenIB
14 * BSD.
15 *
16 * OpenIB BSD License
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are met:
20 *
21 * Redistributions of source code must retain the above copyright notice, this
22 * list of conditions and the following disclaimer.
23 *
24 * Redistributions in binary form must reproduce the above copyright notice,
25 * this list of conditions and the following disclaimer in the documentation
26 * and/or other materials
27 * provided with the distribution.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
36 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
37 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#ifndef __EHCA_CLASSES_H__
43#define __EHCA_CLASSES_H__
44
Heiko J Schickfab97222006-09-22 15:22:22 -070045
46struct 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
89struct ehca_sport {
90 struct ib_cq *ibcq_aqp1;
91 struct ib_qp *ibqp_aqp1;
92 enum ib_rate rate;
93 enum ib_port_state port_state;
94};
95
96struct ehca_shca {
97 struct ib_device ib_device;
98 struct ibmebus_dev *ibmebus_dev;
99 u8 num_ports;
100 int hw_level;
101 struct list_head shca_list;
102 struct ipz_adapter_handle ipz_hca_handle;
103 struct ehca_sport sport[2];
104 struct ehca_eq eq;
105 struct ehca_eq neq;
106 struct ehca_mr *maxmr;
107 struct ehca_pd *pd;
108 struct h_galpas galpas;
Joachim Fenkesc4ed7902007-04-24 17:44:31 +0200109 struct mutex modify_mutex;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200110 u64 hca_cap;
111 int max_mtu;
Heiko J Schickfab97222006-09-22 15:22:22 -0700112};
113
114struct ehca_pd {
115 struct ib_pd ib_pd;
116 struct ipz_pd fw_pd;
117 u32 ownpid;
118};
119
120struct ehca_qp {
121 struct ib_qp ib_qp;
122 u32 qp_type;
123 struct ipz_queue ipz_squeue;
124 struct ipz_queue ipz_rqueue;
125 struct h_galpas galpas;
126 u32 qkey;
127 u32 real_qp_num;
128 u32 token;
129 spinlock_t spinlock_s;
130 spinlock_t spinlock_r;
131 u32 sq_max_inline_data_size;
132 struct ipz_qp_handle ipz_qp_handle;
133 struct ehca_pfqp pf;
134 struct ib_qp_init_attr init_attr;
Heiko J Schickfab97222006-09-22 15:22:22 -0700135 struct ehca_cq *send_cq;
136 struct ehca_cq *recv_cq;
137 unsigned int sqerr_purgeflag;
138 struct hlist_node list_entries;
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100139 /* mmap counter for resources mapped into user space */
140 u32 mm_count_squeue;
141 u32 mm_count_rqueue;
142 u32 mm_count_galpa;
Heiko J Schickfab97222006-09-22 15:22:22 -0700143};
144
145/* must be power of 2 */
146#define QP_HASHTAB_LEN 8
147
148struct ehca_cq {
149 struct ib_cq ib_cq;
150 struct ipz_queue ipz_queue;
151 struct h_galpas galpas;
152 spinlock_t spinlock;
153 u32 cq_number;
154 u32 token;
155 u32 nr_of_entries;
156 struct ipz_cq_handle ipz_cq_handle;
157 struct ehca_pfcq pf;
158 spinlock_t cb_lock;
Heiko J Schickfab97222006-09-22 15:22:22 -0700159 struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
160 struct list_head entry;
Hoang-Nam Nguyen31726792007-02-28 18:01:02 +0100161 u32 nr_callbacks; /* #events assigned to cpu by scaling code */
162 u32 nr_events; /* #events seen */
163 wait_queue_head_t wait_completion;
Heiko J Schickfab97222006-09-22 15:22:22 -0700164 spinlock_t task_lock;
165 u32 ownpid;
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100166 /* mmap counter for resources mapped into user space */
167 u32 mm_count_queue;
168 u32 mm_count_galpa;
Heiko J Schickfab97222006-09-22 15:22:22 -0700169};
170
171enum ehca_mr_flag {
172 EHCA_MR_FLAG_FMR = 0x80000000, /* FMR, created with ehca_alloc_fmr */
173 EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR */
174};
175
176struct ehca_mr {
177 union {
178 struct ib_mr ib_mr; /* must always be first in ehca_mr */
179 struct ib_fmr ib_fmr; /* must always be first in ehca_mr */
180 } ib;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -0800181 struct ib_umem *umem;
Heiko J Schickfab97222006-09-22 15:22:22 -0700182 spinlock_t mrlock;
183
184 enum ehca_mr_flag flags;
185 u32 num_pages; /* number of MR pages */
186 u32 num_4k; /* number of 4k "page" portions to form MR */
187 int acl; /* ACL (stored here for usage in reregister) */
188 u64 *start; /* virtual start address (stored here for */
189 /* usage in reregister) */
190 u64 size; /* size (stored here for usage in reregister) */
191 u32 fmr_page_size; /* page size for FMR */
192 u32 fmr_max_pages; /* max pages for FMR */
193 u32 fmr_max_maps; /* max outstanding maps for FMR */
194 u32 fmr_map_cnt; /* map counter for FMR */
195 /* fw specific data */
196 struct ipz_mrmw_handle ipz_mr_handle; /* MR handle for h-calls */
197 struct h_galpas galpas;
198 /* data for userspace bridge */
199 u32 nr_of_pages;
200 void *pagearray;
201};
202
203struct ehca_mw {
204 struct ib_mw ib_mw; /* gen2 mw, must always be first in ehca_mw */
205 spinlock_t mwlock;
206
207 u8 never_bound; /* indication MW was never bound */
208 struct ipz_mrmw_handle ipz_mw_handle; /* MW handle for h-calls */
209 struct h_galpas galpas;
210};
211
212enum ehca_mr_pgi_type {
213 EHCA_MR_PGI_PHYS = 1, /* type of ehca_reg_phys_mr,
214 * ehca_rereg_phys_mr,
215 * ehca_reg_internal_maxmr */
216 EHCA_MR_PGI_USER = 2, /* type of ehca_reg_user_mr */
217 EHCA_MR_PGI_FMR = 3 /* type of ehca_map_phys_fmr */
218};
219
220struct ehca_mr_pginfo {
221 enum ehca_mr_pgi_type type;
222 u64 num_pages;
223 u64 page_cnt;
224 u64 num_4k; /* number of 4k "page" portions */
225 u64 page_4k_cnt; /* counter for 4k "page" portions */
226 u64 next_4k; /* next 4k "page" portion in buffer/chunk/listelem */
227
228 /* type EHCA_MR_PGI_PHYS section */
229 int num_phys_buf;
230 struct ib_phys_buf *phys_buf_array;
231 u64 next_buf;
232
233 /* type EHCA_MR_PGI_USER section */
234 struct ib_umem *region;
235 struct ib_umem_chunk *next_chunk;
236 u64 next_nmap;
237
238 /* type EHCA_MR_PGI_FMR section */
239 u64 *page_list;
240 u64 next_listelem;
241 /* next_4k also used within EHCA_MR_PGI_FMR */
242};
243
244/* output parameters for MR/FMR hipz calls */
245struct ehca_mr_hipzout_parms {
246 struct ipz_mrmw_handle handle;
247 u32 lkey;
248 u32 rkey;
249 u64 len;
250 u64 vaddr;
251 u32 acl;
252};
253
254/* output parameters for MW hipz calls */
255struct ehca_mw_hipzout_parms {
256 struct ipz_mrmw_handle handle;
257 u32 rkey;
258};
259
260struct ehca_av {
261 struct ib_ah ib_ah;
262 struct ehca_ud_av av;
263};
264
265struct ehca_ucontext {
266 struct ib_ucontext ib_ucontext;
267};
268
Heiko J Schickfab97222006-09-22 15:22:22 -0700269int ehca_init_pd_cache(void);
270void ehca_cleanup_pd_cache(void);
271int ehca_init_cq_cache(void);
272void ehca_cleanup_cq_cache(void);
273int ehca_init_qp_cache(void);
274void ehca_cleanup_qp_cache(void);
275int ehca_init_av_cache(void);
276void ehca_cleanup_av_cache(void);
277int ehca_init_mrmw_cache(void);
278void ehca_cleanup_mrmw_cache(void);
279
280extern spinlock_t ehca_qp_idr_lock;
281extern spinlock_t ehca_cq_idr_lock;
Stefan Roscher5d882782007-05-09 13:47:56 +0200282extern spinlock_t hcall_lock;
Heiko J Schickfab97222006-09-22 15:22:22 -0700283extern struct idr ehca_qp_idr;
284extern struct idr ehca_cq_idr;
285
286extern int ehca_static_rate;
287extern int ehca_port_act_time;
288extern int ehca_use_hp_mr;
Hoang-Nam Nguyen4fd30062007-02-15 17:08:33 +0100289extern int ehca_scaling_code;
Heiko J Schickfab97222006-09-22 15:22:22 -0700290
291struct ipzu_queue_resp {
Heiko J Schickfab97222006-09-22 15:22:22 -0700292 u32 qe_size; /* queue entry size */
293 u32 act_nr_of_sg;
294 u32 queue_length; /* queue length allocated in bytes */
295 u32 pagesize;
296 u32 toggle_state;
297 u32 dummy; /* padding for 8 byte alignment */
298};
299
300struct ehca_create_cq_resp {
301 u32 cq_number;
302 u32 token;
303 struct ipzu_queue_resp ipz_queue;
Heiko J Schickfab97222006-09-22 15:22:22 -0700304};
305
306struct ehca_create_qp_resp {
307 u32 qp_num;
308 u32 token;
309 u32 qp_type;
310 u32 qkey;
311 /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
312 u32 real_qp_num;
313 u32 dummy; /* padding for 8 byte alignment */
314 struct ipzu_queue_resp ipz_squeue;
315 struct ipzu_queue_resp ipz_rqueue;
Heiko J Schickfab97222006-09-22 15:22:22 -0700316};
317
318struct ehca_alloc_cq_parms {
319 u32 nr_cqe;
320 u32 act_nr_of_entries;
321 u32 act_pages;
322 struct ipz_eq_handle eq_handle;
323};
324
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200325enum ehca_service_type {
326 ST_RC = 0,
327 ST_UC = 1,
328 ST_RD = 2,
329 ST_UD = 3,
330};
331
332enum ehca_ext_qp_type {
333 EQPT_NORMAL = 0,
334 EQPT_LLQP = 1,
335 EQPT_SRQBASE = 2,
336 EQPT_SRQ = 3,
337};
338
339enum ehca_ll_comp_flags {
340 LLQP_SEND_COMP = 0x20,
341 LLQP_RECV_COMP = 0x40,
342 LLQP_COMP_MASK = 0x60,
343};
344
Heiko J Schickfab97222006-09-22 15:22:22 -0700345struct ehca_alloc_qp_parms {
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200346/* input parameters */
347 enum ehca_service_type servicetype;
Heiko J Schickfab97222006-09-22 15:22:22 -0700348 int sigtype;
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200349 enum ehca_ext_qp_type ext_type;
350 enum ehca_ll_comp_flags ll_comp_flags;
351
352 int max_send_wr, max_recv_wr;
353 int max_send_sge, max_recv_sge;
Heiko J Schickfab97222006-09-22 15:22:22 -0700354 int ud_av_l_key_ctl;
355
Joachim Fenkes9a79fc02007-07-09 15:23:15 +0200356 u32 token;
357 struct ipz_eq_handle eq_handle;
358 struct ipz_pd pd;
359 struct ipz_cq_handle send_cq_handle, recv_cq_handle;
360
361 u32 srq_qpn, srq_token, srq_limit;
362
363/* output parameters */
364 u32 real_qp_num;
365 struct ipz_qp_handle qp_handle;
366 struct h_galpas galpas;
367
Heiko J Schickfab97222006-09-22 15:22:22 -0700368 u16 act_nr_send_wqes;
369 u16 act_nr_recv_wqes;
370 u8 act_nr_recv_sges;
371 u8 act_nr_send_sges;
372
373 u32 nr_rq_pages;
374 u32 nr_sq_pages;
Heiko J Schickfab97222006-09-22 15:22:22 -0700375};
376
377int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
378int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
379struct ehca_qp* ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);
380
381#endif