IB/ehca: Use macro to calculate number of chunks in a mem block
[deliverable/linux.git] / drivers / infiniband / hw / ehca / ehca_classes.h
CommitLineData
fab97220
HS
1/*
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>
a6a12947 8 * Joachim Fenkes <fenkes@de.ibm.com>
fab97220
HS
9 *
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
fab97220
HS
46
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
31726798
HNN
56#include <linux/wait.h>
57
78d8d5f9
HNN
58#include <rdma/ib_verbs.h>
59#include <rdma/ib_user_verbs.h>
60
fab97220
HS
61#ifdef CONFIG_PPC64
62#include "ehca_classes_pSeries.h"
63#endif
78d8d5f9
HNN
64#include "ipz_pt_fn.h"
65#include "ehca_qes.h"
66#include "ehca_irq.h"
fab97220 67
78d8d5f9 68#define EHCA_EQE_CACHE_SIZE 20
fab97220 69
78d8d5f9
HNN
70struct ehca_eqe_cache_entry {
71 struct ehca_eqe *eqe;
72 struct ehca_cq *cq;
73};
fab97220
HS
74
75struct 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;
78d8d5f9
HNN
86 spinlock_t irq_spinlock;
87 struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
fab97220
HS
88};
89
8705ce5b
JF
90struct ehca_sma_attr {
91 u16 lid, lmc, sm_sl, sm_lid;
92 u16 pkey_tbl_len, pkeys[16];
93};
94
fab97220
HS
95struct 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;
8705ce5b 100 struct ehca_sma_attr saved_attr;
fab97220
HS
101};
102
103struct ehca_shca {
104 struct ib_device ib_device;
105 struct ibmebus_dev *ibmebus_dev;
106 u8 num_ports;
107 int hw_level;
108 struct list_head shca_list;
109 struct ipz_adapter_handle ipz_hca_handle;
110 struct ehca_sport sport[2];
111 struct ehca_eq eq;
112 struct ehca_eq neq;
113 struct ehca_mr *maxmr;
114 struct ehca_pd *pd;
115 struct h_galpas galpas;
c4ed790d 116 struct mutex modify_mutex;
91f13aa3
JF
117 u64 hca_cap;
118 int max_mtu;
fab97220
HS
119};
120
121struct ehca_pd {
122 struct ib_pd ib_pd;
123 struct ipz_pd fw_pd;
124 u32 ownpid;
125};
126
a6a12947
JF
127enum ehca_ext_qp_type {
128 EQPT_NORMAL = 0,
129 EQPT_LLQP = 1,
130 EQPT_SRQBASE = 2,
131 EQPT_SRQ = 3,
132};
133
fab97220 134struct ehca_qp {
a6a12947
JF
135 union {
136 struct ib_qp ib_qp;
137 struct ib_srq ib_srq;
138 };
fab97220 139 u32 qp_type;
a6a12947 140 enum ehca_ext_qp_type ext_type;
fab97220
HS
141 struct ipz_queue ipz_squeue;
142 struct ipz_queue ipz_rqueue;
143 struct h_galpas galpas;
144 u32 qkey;
145 u32 real_qp_num;
146 u32 token;
147 spinlock_t spinlock_s;
148 spinlock_t spinlock_r;
149 u32 sq_max_inline_data_size;
150 struct ipz_qp_handle ipz_qp_handle;
151 struct ehca_pfqp pf;
152 struct ib_qp_init_attr init_attr;
fab97220
HS
153 struct ehca_cq *send_cq;
154 struct ehca_cq *recv_cq;
155 unsigned int sqerr_purgeflag;
156 struct hlist_node list_entries;
4c34bdf5
HNN
157 /* mmap counter for resources mapped into user space */
158 u32 mm_count_squeue;
159 u32 mm_count_rqueue;
160 u32 mm_count_galpa;
fab97220
HS
161};
162
a6a12947
JF
163#define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
164#define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)
165#define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)
166
fab97220
HS
167/* must be power of 2 */
168#define QP_HASHTAB_LEN 8
169
170struct ehca_cq {
171 struct ib_cq ib_cq;
172 struct ipz_queue ipz_queue;
173 struct h_galpas galpas;
174 spinlock_t spinlock;
175 u32 cq_number;
176 u32 token;
177 u32 nr_of_entries;
178 struct ipz_cq_handle ipz_cq_handle;
179 struct ehca_pfcq pf;
180 spinlock_t cb_lock;
fab97220
HS
181 struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
182 struct list_head entry;
28db6beb
JF
183 u32 nr_callbacks; /* #events assigned to cpu by scaling code */
184 atomic_t nr_events; /* #events seen */
31726798 185 wait_queue_head_t wait_completion;
fab97220
HS
186 spinlock_t task_lock;
187 u32 ownpid;
4c34bdf5
HNN
188 /* mmap counter for resources mapped into user space */
189 u32 mm_count_queue;
190 u32 mm_count_galpa;
fab97220
HS
191};
192
193enum ehca_mr_flag {
194 EHCA_MR_FLAG_FMR = 0x80000000, /* FMR, created with ehca_alloc_fmr */
195 EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR */
196};
197
198struct ehca_mr {
199 union {
200 struct ib_mr ib_mr; /* must always be first in ehca_mr */
201 struct ib_fmr ib_fmr; /* must always be first in ehca_mr */
202 } ib;
f7c6a7b5 203 struct ib_umem *umem;
fab97220
HS
204 spinlock_t mrlock;
205
206 enum ehca_mr_flag flags;
207 u32 num_pages; /* number of MR pages */
208 u32 num_4k; /* number of 4k "page" portions to form MR */
209 int acl; /* ACL (stored here for usage in reregister) */
210 u64 *start; /* virtual start address (stored here for */
211 /* usage in reregister) */
212 u64 size; /* size (stored here for usage in reregister) */
213 u32 fmr_page_size; /* page size for FMR */
214 u32 fmr_max_pages; /* max pages for FMR */
215 u32 fmr_max_maps; /* max outstanding maps for FMR */
216 u32 fmr_map_cnt; /* map counter for FMR */
217 /* fw specific data */
218 struct ipz_mrmw_handle ipz_mr_handle; /* MR handle for h-calls */
219 struct h_galpas galpas;
220 /* data for userspace bridge */
221 u32 nr_of_pages;
222 void *pagearray;
223};
224
225struct ehca_mw {
226 struct ib_mw ib_mw; /* gen2 mw, must always be first in ehca_mw */
227 spinlock_t mwlock;
228
229 u8 never_bound; /* indication MW was never bound */
230 struct ipz_mrmw_handle ipz_mw_handle; /* MW handle for h-calls */
231 struct h_galpas galpas;
232};
233
234enum ehca_mr_pgi_type {
235 EHCA_MR_PGI_PHYS = 1, /* type of ehca_reg_phys_mr,
236 * ehca_rereg_phys_mr,
237 * ehca_reg_internal_maxmr */
238 EHCA_MR_PGI_USER = 2, /* type of ehca_reg_user_mr */
239 EHCA_MR_PGI_FMR = 3 /* type of ehca_map_phys_fmr */
240};
241
242struct ehca_mr_pginfo {
243 enum ehca_mr_pgi_type type;
244 u64 num_pages;
245 u64 page_cnt;
246 u64 num_4k; /* number of 4k "page" portions */
247 u64 page_4k_cnt; /* counter for 4k "page" portions */
248 u64 next_4k; /* next 4k "page" portion in buffer/chunk/listelem */
249
250 /* type EHCA_MR_PGI_PHYS section */
251 int num_phys_buf;
252 struct ib_phys_buf *phys_buf_array;
253 u64 next_buf;
254
255 /* type EHCA_MR_PGI_USER section */
256 struct ib_umem *region;
257 struct ib_umem_chunk *next_chunk;
258 u64 next_nmap;
259
260 /* type EHCA_MR_PGI_FMR section */
261 u64 *page_list;
262 u64 next_listelem;
263 /* next_4k also used within EHCA_MR_PGI_FMR */
264};
265
266/* output parameters for MR/FMR hipz calls */
267struct ehca_mr_hipzout_parms {
268 struct ipz_mrmw_handle handle;
269 u32 lkey;
270 u32 rkey;
271 u64 len;
272 u64 vaddr;
273 u32 acl;
274};
275
276/* output parameters for MW hipz calls */
277struct ehca_mw_hipzout_parms {
278 struct ipz_mrmw_handle handle;
279 u32 rkey;
280};
281
282struct ehca_av {
283 struct ib_ah ib_ah;
284 struct ehca_ud_av av;
285};
286
287struct ehca_ucontext {
288 struct ib_ucontext ib_ucontext;
289};
290
fab97220
HS
291int ehca_init_pd_cache(void);
292void ehca_cleanup_pd_cache(void);
293int ehca_init_cq_cache(void);
294void ehca_cleanup_cq_cache(void);
295int ehca_init_qp_cache(void);
296void ehca_cleanup_qp_cache(void);
297int ehca_init_av_cache(void);
298void ehca_cleanup_av_cache(void);
299int ehca_init_mrmw_cache(void);
300void ehca_cleanup_mrmw_cache(void);
301
26ed687f
JF
302extern rwlock_t ehca_qp_idr_lock;
303extern rwlock_t ehca_cq_idr_lock;
fab97220
HS
304extern struct idr ehca_qp_idr;
305extern struct idr ehca_cq_idr;
306
307extern int ehca_static_rate;
308extern int ehca_port_act_time;
309extern int ehca_use_hp_mr;
4fd30060 310extern int ehca_scaling_code;
fab97220
HS
311
312struct ipzu_queue_resp {
fab97220
HS
313 u32 qe_size; /* queue entry size */
314 u32 act_nr_of_sg;
315 u32 queue_length; /* queue length allocated in bytes */
316 u32 pagesize;
317 u32 toggle_state;
318 u32 dummy; /* padding for 8 byte alignment */
319};
320
321struct ehca_create_cq_resp {
322 u32 cq_number;
323 u32 token;
324 struct ipzu_queue_resp ipz_queue;
fab97220
HS
325};
326
327struct ehca_create_qp_resp {
328 u32 qp_num;
329 u32 token;
330 u32 qp_type;
a6a12947 331 u32 ext_type;
fab97220
HS
332 u32 qkey;
333 /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
334 u32 real_qp_num;
335 u32 dummy; /* padding for 8 byte alignment */
336 struct ipzu_queue_resp ipz_squeue;
337 struct ipzu_queue_resp ipz_rqueue;
fab97220
HS
338};
339
340struct ehca_alloc_cq_parms {
341 u32 nr_cqe;
342 u32 act_nr_of_entries;
343 u32 act_pages;
344 struct ipz_eq_handle eq_handle;
345};
346
9a79fc0a
JF
347enum ehca_service_type {
348 ST_RC = 0,
349 ST_UC = 1,
350 ST_RD = 2,
351 ST_UD = 3,
352};
353
9a79fc0a
JF
354enum ehca_ll_comp_flags {
355 LLQP_SEND_COMP = 0x20,
356 LLQP_RECV_COMP = 0x40,
357 LLQP_COMP_MASK = 0x60,
358};
359
fab97220 360struct ehca_alloc_qp_parms {
9a79fc0a
JF
361/* input parameters */
362 enum ehca_service_type servicetype;
fab97220 363 int sigtype;
9a79fc0a
JF
364 enum ehca_ext_qp_type ext_type;
365 enum ehca_ll_comp_flags ll_comp_flags;
366
367 int max_send_wr, max_recv_wr;
368 int max_send_sge, max_recv_sge;
fab97220
HS
369 int ud_av_l_key_ctl;
370
9a79fc0a
JF
371 u32 token;
372 struct ipz_eq_handle eq_handle;
373 struct ipz_pd pd;
374 struct ipz_cq_handle send_cq_handle, recv_cq_handle;
375
376 u32 srq_qpn, srq_token, srq_limit;
377
378/* output parameters */
379 u32 real_qp_num;
380 struct ipz_qp_handle qp_handle;
381 struct h_galpas galpas;
382
fab97220
HS
383 u16 act_nr_send_wqes;
384 u16 act_nr_recv_wqes;
385 u8 act_nr_recv_sges;
386 u8 act_nr_send_sges;
387
388 u32 nr_rq_pages;
389 u32 nr_sq_pages;
fab97220
HS
390};
391
392int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
393int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
394struct ehca_qp* ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);
395
396#endif
This page took 0.170731 seconds and 5 git commands to generate.