Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 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> |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame^] | 8 | * Joachim Fenkes <fenkes@de.ibm.com> |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 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 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 46 | |
| 47 | struct ehca_module; |
| 48 | struct ehca_qp; |
| 49 | struct ehca_cq; |
| 50 | struct ehca_eq; |
| 51 | struct ehca_mr; |
| 52 | struct ehca_mw; |
| 53 | struct ehca_pd; |
| 54 | struct ehca_av; |
| 55 | |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 56 | #include <linux/wait.h> |
| 57 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 58 | #include <rdma/ib_verbs.h> |
| 59 | #include <rdma/ib_user_verbs.h> |
| 60 | |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 61 | #ifdef CONFIG_PPC64 |
| 62 | #include "ehca_classes_pSeries.h" |
| 63 | #endif |
| 64 | #include "ipz_pt_fn.h" |
| 65 | #include "ehca_qes.h" |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 66 | #include "ehca_irq.h" |
| 67 | |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 68 | #define EHCA_EQE_CACHE_SIZE 20 |
| 69 | |
| 70 | struct ehca_eqe_cache_entry { |
| 71 | struct ehca_eqe *eqe; |
| 72 | struct ehca_cq *cq; |
| 73 | }; |
| 74 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 75 | struct 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 Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 86 | spinlock_t irq_spinlock; |
| 87 | struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE]; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | struct 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 | |
| 97 | struct 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 Fenkes | c4ed790 | 2007-04-24 17:44:31 +0200 | [diff] [blame] | 110 | struct mutex modify_mutex; |
Joachim Fenkes | 91f13aa | 2007-07-09 15:21:45 +0200 | [diff] [blame] | 111 | u64 hca_cap; |
| 112 | int max_mtu; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | struct ehca_pd { |
| 116 | struct ib_pd ib_pd; |
| 117 | struct ipz_pd fw_pd; |
| 118 | u32 ownpid; |
| 119 | }; |
| 120 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame^] | 121 | enum ehca_ext_qp_type { |
| 122 | EQPT_NORMAL = 0, |
| 123 | EQPT_LLQP = 1, |
| 124 | EQPT_SRQBASE = 2, |
| 125 | EQPT_SRQ = 3, |
| 126 | }; |
| 127 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 128 | struct ehca_qp { |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame^] | 129 | union { |
| 130 | struct ib_qp ib_qp; |
| 131 | struct ib_srq ib_srq; |
| 132 | }; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 133 | u32 qp_type; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame^] | 134 | enum ehca_ext_qp_type ext_type; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 135 | 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 Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 147 | struct ehca_cq *send_cq; |
| 148 | struct ehca_cq *recv_cq; |
| 149 | unsigned int sqerr_purgeflag; |
| 150 | struct hlist_node list_entries; |
Hoang-Nam Nguyen | 4c34bdf | 2007-01-24 00:13:35 +0100 | [diff] [blame] | 151 | /* 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 Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 155 | }; |
| 156 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame^] | 157 | #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 Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 161 | /* must be power of 2 */ |
| 162 | #define QP_HASHTAB_LEN 8 |
| 163 | |
| 164 | struct 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 Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 175 | struct hlist_head qp_hashtab[QP_HASHTAB_LEN]; |
| 176 | struct list_head entry; |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 177 | 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 Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 180 | spinlock_t task_lock; |
| 181 | u32 ownpid; |
Hoang-Nam Nguyen | 4c34bdf | 2007-01-24 00:13:35 +0100 | [diff] [blame] | 182 | /* mmap counter for resources mapped into user space */ |
| 183 | u32 mm_count_queue; |
| 184 | u32 mm_count_galpa; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | enum 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 | |
| 192 | struct 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 Dreier | f7c6a7b | 2007-03-04 16:15:11 -0800 | [diff] [blame] | 197 | struct ib_umem *umem; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 198 | 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 | |
| 219 | struct 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 | |
| 228 | enum 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 | |
| 236 | struct 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 */ |
| 261 | struct 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 */ |
| 271 | struct ehca_mw_hipzout_parms { |
| 272 | struct ipz_mrmw_handle handle; |
| 273 | u32 rkey; |
| 274 | }; |
| 275 | |
| 276 | struct ehca_av { |
| 277 | struct ib_ah ib_ah; |
| 278 | struct ehca_ud_av av; |
| 279 | }; |
| 280 | |
| 281 | struct ehca_ucontext { |
| 282 | struct ib_ucontext ib_ucontext; |
| 283 | }; |
| 284 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 285 | int ehca_init_pd_cache(void); |
| 286 | void ehca_cleanup_pd_cache(void); |
| 287 | int ehca_init_cq_cache(void); |
| 288 | void ehca_cleanup_cq_cache(void); |
| 289 | int ehca_init_qp_cache(void); |
| 290 | void ehca_cleanup_qp_cache(void); |
| 291 | int ehca_init_av_cache(void); |
| 292 | void ehca_cleanup_av_cache(void); |
| 293 | int ehca_init_mrmw_cache(void); |
| 294 | void ehca_cleanup_mrmw_cache(void); |
| 295 | |
| 296 | extern spinlock_t ehca_qp_idr_lock; |
| 297 | extern spinlock_t ehca_cq_idr_lock; |
Stefan Roscher | 5d88278 | 2007-05-09 13:47:56 +0200 | [diff] [blame] | 298 | extern spinlock_t hcall_lock; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 299 | extern struct idr ehca_qp_idr; |
| 300 | extern struct idr ehca_cq_idr; |
| 301 | |
| 302 | extern int ehca_static_rate; |
| 303 | extern int ehca_port_act_time; |
| 304 | extern int ehca_use_hp_mr; |
Hoang-Nam Nguyen | 4fd3006 | 2007-02-15 17:08:33 +0100 | [diff] [blame] | 305 | extern int ehca_scaling_code; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 306 | |
| 307 | struct ipzu_queue_resp { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 308 | 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 | |
| 316 | struct ehca_create_cq_resp { |
| 317 | u32 cq_number; |
| 318 | u32 token; |
| 319 | struct ipzu_queue_resp ipz_queue; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 320 | }; |
| 321 | |
| 322 | struct ehca_create_qp_resp { |
| 323 | u32 qp_num; |
| 324 | u32 token; |
| 325 | u32 qp_type; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame^] | 326 | u32 ext_type; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 327 | 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 Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | struct 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 Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 342 | enum ehca_service_type { |
| 343 | ST_RC = 0, |
| 344 | ST_UC = 1, |
| 345 | ST_RD = 2, |
| 346 | ST_UD = 3, |
| 347 | }; |
| 348 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 349 | enum ehca_ll_comp_flags { |
| 350 | LLQP_SEND_COMP = 0x20, |
| 351 | LLQP_RECV_COMP = 0x40, |
| 352 | LLQP_COMP_MASK = 0x60, |
| 353 | }; |
| 354 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 355 | struct ehca_alloc_qp_parms { |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 356 | /* input parameters */ |
| 357 | enum ehca_service_type servicetype; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 358 | int sigtype; |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 359 | 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 Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 364 | int ud_av_l_key_ctl; |
| 365 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 366 | 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 Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 378 | 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 Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 385 | }; |
| 386 | |
| 387 | int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp); |
| 388 | int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num); |
| 389 | struct ehca_qp* ehca_cq_get_qp(struct ehca_cq *cq, int qp_num); |
| 390 | |
| 391 | #endif |