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 | * module start stop, hca detection |
| 5 | * |
| 6 | * Authors: Heiko J Schick <schickhj@de.ibm.com> |
| 7 | * Hoang-Nam Nguyen <hnguyen@de.ibm.com> |
| 8 | * Joachim Fenkes <fenkes@de.ibm.com> |
| 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 | |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 43 | #ifdef CONFIG_PPC_64K_PAGES |
| 44 | #include <linux/slab.h> |
| 45 | #endif |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 46 | #include "ehca_classes.h" |
| 47 | #include "ehca_iverbs.h" |
| 48 | #include "ehca_mrmw.h" |
| 49 | #include "ehca_tools.h" |
| 50 | #include "hcp_if.h" |
| 51 | |
| 52 | MODULE_LICENSE("Dual BSD/GPL"); |
| 53 | MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); |
| 54 | MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver"); |
Joachim Fenkes | 4e430dc | 2007-05-09 13:48:31 +0200 | [diff] [blame] | 55 | MODULE_VERSION("SVNEHCA_0023"); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 56 | |
| 57 | int ehca_open_aqp1 = 0; |
| 58 | int ehca_debug_level = 0; |
| 59 | int ehca_hw_level = 0; |
| 60 | int ehca_nr_ports = 2; |
| 61 | int ehca_use_hp_mr = 0; |
| 62 | int ehca_port_act_time = 30; |
| 63 | int ehca_poll_all_eqs = 1; |
| 64 | int ehca_static_rate = -1; |
Joachim Fenkes | 4e430dc | 2007-05-09 13:48:31 +0200 | [diff] [blame] | 65 | int ehca_scaling_code = 0; |
Hoang-Nam Nguyen | 5bb7d92 | 2007-07-20 16:01:51 +0200 | [diff] [blame] | 66 | int ehca_mr_largepage = 0; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 67 | |
| 68 | module_param_named(open_aqp1, ehca_open_aqp1, int, 0); |
| 69 | module_param_named(debug_level, ehca_debug_level, int, 0); |
| 70 | module_param_named(hw_level, ehca_hw_level, int, 0); |
| 71 | module_param_named(nr_ports, ehca_nr_ports, int, 0); |
| 72 | module_param_named(use_hp_mr, ehca_use_hp_mr, int, 0); |
| 73 | module_param_named(port_act_time, ehca_port_act_time, int, 0); |
| 74 | module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, 0); |
| 75 | module_param_named(static_rate, ehca_static_rate, int, 0); |
Hoang-Nam Nguyen | 5bb7d92 | 2007-07-20 16:01:51 +0200 | [diff] [blame] | 76 | module_param_named(scaling_code, ehca_scaling_code, int, 0); |
| 77 | module_param_named(mr_largepage, ehca_mr_largepage, int, 0); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 78 | |
| 79 | MODULE_PARM_DESC(open_aqp1, |
| 80 | "AQP1 on startup (0: no (default), 1: yes)"); |
| 81 | MODULE_PARM_DESC(debug_level, |
| 82 | "debug level" |
| 83 | " (0: no debug traces (default), 1: with debug traces)"); |
| 84 | MODULE_PARM_DESC(hw_level, |
| 85 | "hardware level" |
| 86 | " (0: autosensing (default), 1: v. 0.20, 2: v. 0.21)"); |
| 87 | MODULE_PARM_DESC(nr_ports, |
| 88 | "number of connected ports (default: 2)"); |
| 89 | MODULE_PARM_DESC(use_hp_mr, |
| 90 | "high performance MRs (0: no (default), 1: yes)"); |
| 91 | MODULE_PARM_DESC(port_act_time, |
| 92 | "time to wait for port activation (default: 30 sec)"); |
| 93 | MODULE_PARM_DESC(poll_all_eqs, |
| 94 | "polls all event queues periodically" |
| 95 | " (0: no, 1: yes (default))"); |
| 96 | MODULE_PARM_DESC(static_rate, |
| 97 | "set permanent static rate (default: disabled)"); |
Hoang-Nam Nguyen | 4fd3006 | 2007-02-15 17:08:33 +0100 | [diff] [blame] | 98 | MODULE_PARM_DESC(scaling_code, |
Hoang-Nam Nguyen | b8a3ba5 | 2007-07-09 15:20:55 +0200 | [diff] [blame] | 99 | "set scaling code (0: disabled/default, 1: enabled)"); |
Hoang-Nam Nguyen | 5bb7d92 | 2007-07-20 16:01:51 +0200 | [diff] [blame] | 100 | MODULE_PARM_DESC(mr_largepage, |
| 101 | "use large page for MR (0: use PAGE_SIZE (default), " |
| 102 | "1: use large page depending on MR size"); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 103 | |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 104 | DEFINE_RWLOCK(ehca_qp_idr_lock); |
| 105 | DEFINE_RWLOCK(ehca_cq_idr_lock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 106 | DEFINE_IDR(ehca_qp_idr); |
| 107 | DEFINE_IDR(ehca_cq_idr); |
| 108 | |
Joachim Fenkes | 9844b71 | 2007-07-09 15:29:03 +0200 | [diff] [blame] | 109 | static LIST_HEAD(shca_list); /* list of all registered ehcas */ |
| 110 | static DEFINE_SPINLOCK(shca_list_lock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 111 | |
| 112 | static struct timer_list poll_eqs_timer; |
| 113 | |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 114 | #ifdef CONFIG_PPC_64K_PAGES |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 115 | static struct kmem_cache *ctblk_cache; |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 116 | |
Hoang-Nam Nguyen | f2d9136 | 2007-01-09 18:04:14 +0100 | [diff] [blame] | 117 | void *ehca_alloc_fw_ctrlblock(gfp_t flags) |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 118 | { |
Hoang-Nam Nguyen | f2d9136 | 2007-01-09 18:04:14 +0100 | [diff] [blame] | 119 | void *ret = kmem_cache_zalloc(ctblk_cache, flags); |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 120 | if (!ret) |
| 121 | ehca_gen_err("Out of memory for ctblk"); |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | void ehca_free_fw_ctrlblock(void *ptr) |
| 126 | { |
| 127 | if (ptr) |
| 128 | kmem_cache_free(ctblk_cache, ptr); |
| 129 | |
| 130 | } |
| 131 | #endif |
| 132 | |
Hoang-Nam Nguyen | 51d2bfb | 2007-07-20 16:02:46 +0200 | [diff] [blame] | 133 | int ehca2ib_return_code(u64 ehca_rc) |
| 134 | { |
| 135 | switch (ehca_rc) { |
| 136 | case H_SUCCESS: |
| 137 | return 0; |
| 138 | case H_RESOURCE: /* Resource in use */ |
| 139 | case H_BUSY: |
| 140 | return -EBUSY; |
| 141 | case H_NOT_ENOUGH_RESOURCES: /* insufficient resources */ |
| 142 | case H_CONSTRAINED: /* resource constraint */ |
| 143 | case H_NO_MEM: |
| 144 | return -ENOMEM; |
| 145 | default: |
| 146 | return -EINVAL; |
| 147 | } |
| 148 | } |
| 149 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 150 | static int ehca_create_slab_caches(void) |
| 151 | { |
| 152 | int ret; |
| 153 | |
| 154 | ret = ehca_init_pd_cache(); |
| 155 | if (ret) { |
| 156 | ehca_gen_err("Cannot create PD SLAB cache."); |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | ret = ehca_init_cq_cache(); |
| 161 | if (ret) { |
| 162 | ehca_gen_err("Cannot create CQ SLAB cache."); |
| 163 | goto create_slab_caches2; |
| 164 | } |
| 165 | |
| 166 | ret = ehca_init_qp_cache(); |
| 167 | if (ret) { |
| 168 | ehca_gen_err("Cannot create QP SLAB cache."); |
| 169 | goto create_slab_caches3; |
| 170 | } |
| 171 | |
| 172 | ret = ehca_init_av_cache(); |
| 173 | if (ret) { |
| 174 | ehca_gen_err("Cannot create AV SLAB cache."); |
| 175 | goto create_slab_caches4; |
| 176 | } |
| 177 | |
| 178 | ret = ehca_init_mrmw_cache(); |
| 179 | if (ret) { |
| 180 | ehca_gen_err("Cannot create MR&MW SLAB cache."); |
| 181 | goto create_slab_caches5; |
| 182 | } |
| 183 | |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 184 | #ifdef CONFIG_PPC_64K_PAGES |
| 185 | ctblk_cache = kmem_cache_create("ehca_cache_ctblk", |
| 186 | EHCA_PAGESIZE, H_CB_ALIGNMENT, |
| 187 | SLAB_HWCACHE_ALIGN, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 188 | NULL); |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 189 | if (!ctblk_cache) { |
| 190 | ehca_gen_err("Cannot create ctblk SLAB cache."); |
| 191 | ehca_cleanup_mrmw_cache(); |
| 192 | goto create_slab_caches5; |
| 193 | } |
| 194 | #endif |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 195 | return 0; |
| 196 | |
| 197 | create_slab_caches5: |
| 198 | ehca_cleanup_av_cache(); |
| 199 | |
| 200 | create_slab_caches4: |
| 201 | ehca_cleanup_qp_cache(); |
| 202 | |
| 203 | create_slab_caches3: |
| 204 | ehca_cleanup_cq_cache(); |
| 205 | |
| 206 | create_slab_caches2: |
| 207 | ehca_cleanup_pd_cache(); |
| 208 | |
| 209 | return ret; |
| 210 | } |
| 211 | |
| 212 | static void ehca_destroy_slab_caches(void) |
| 213 | { |
| 214 | ehca_cleanup_mrmw_cache(); |
| 215 | ehca_cleanup_av_cache(); |
| 216 | ehca_cleanup_qp_cache(); |
| 217 | ehca_cleanup_cq_cache(); |
| 218 | ehca_cleanup_pd_cache(); |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 219 | #ifdef CONFIG_PPC_64K_PAGES |
| 220 | if (ctblk_cache) |
| 221 | kmem_cache_destroy(ctblk_cache); |
| 222 | #endif |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 225 | #define EHCA_HCAAVER EHCA_BMASK_IBM(32, 39) |
| 226 | #define EHCA_REVID EHCA_BMASK_IBM(40, 63) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 227 | |
Joachim Fenkes | 91f13aa | 2007-07-09 15:21:45 +0200 | [diff] [blame] | 228 | static struct cap_descr { |
| 229 | u64 mask; |
| 230 | char *descr; |
| 231 | } hca_cap_descr[] = { |
| 232 | { HCA_CAP_AH_PORT_NR_CHECK, "HCA_CAP_AH_PORT_NR_CHECK" }, |
| 233 | { HCA_CAP_ATOMIC, "HCA_CAP_ATOMIC" }, |
| 234 | { HCA_CAP_AUTO_PATH_MIG, "HCA_CAP_AUTO_PATH_MIG" }, |
| 235 | { HCA_CAP_BAD_P_KEY_CTR, "HCA_CAP_BAD_P_KEY_CTR" }, |
| 236 | { HCA_CAP_SQD_RTS_PORT_CHANGE, "HCA_CAP_SQD_RTS_PORT_CHANGE" }, |
| 237 | { HCA_CAP_CUR_QP_STATE_MOD, "HCA_CAP_CUR_QP_STATE_MOD" }, |
| 238 | { HCA_CAP_INIT_TYPE, "HCA_CAP_INIT_TYPE" }, |
| 239 | { HCA_CAP_PORT_ACTIVE_EVENT, "HCA_CAP_PORT_ACTIVE_EVENT" }, |
| 240 | { HCA_CAP_Q_KEY_VIOL_CTR, "HCA_CAP_Q_KEY_VIOL_CTR" }, |
| 241 | { HCA_CAP_WQE_RESIZE, "HCA_CAP_WQE_RESIZE" }, |
| 242 | { HCA_CAP_RAW_PACKET_MCAST, "HCA_CAP_RAW_PACKET_MCAST" }, |
| 243 | { HCA_CAP_SHUTDOWN_PORT, "HCA_CAP_SHUTDOWN_PORT" }, |
| 244 | { HCA_CAP_RC_LL_QP, "HCA_CAP_RC_LL_QP" }, |
| 245 | { HCA_CAP_SRQ, "HCA_CAP_SRQ" }, |
| 246 | { HCA_CAP_UD_LL_QP, "HCA_CAP_UD_LL_QP" }, |
| 247 | { HCA_CAP_RESIZE_MR, "HCA_CAP_RESIZE_MR" }, |
| 248 | { HCA_CAP_MINI_QP, "HCA_CAP_MINI_QP" }, |
| 249 | }; |
| 250 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 251 | int ehca_sense_attributes(struct ehca_shca *shca) |
| 252 | { |
Joachim Fenkes | 91f13aa | 2007-07-09 15:21:45 +0200 | [diff] [blame] | 253 | int i, ret = 0; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 254 | u64 h_ret; |
| 255 | struct hipz_query_hca *rblock; |
Joachim Fenkes | 91f13aa | 2007-07-09 15:21:45 +0200 | [diff] [blame] | 256 | struct hipz_query_port *port; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 257 | |
Hoang-Nam Nguyen | f2d9136 | 2007-01-09 18:04:14 +0100 | [diff] [blame] | 258 | rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 259 | if (!rblock) { |
| 260 | ehca_gen_err("Cannot allocate rblock memory."); |
| 261 | return -ENOMEM; |
| 262 | } |
| 263 | |
| 264 | h_ret = hipz_h_query_hca(shca->ipz_hca_handle, rblock); |
| 265 | if (h_ret != H_SUCCESS) { |
| 266 | ehca_gen_err("Cannot query device properties. h_ret=%lx", |
| 267 | h_ret); |
| 268 | ret = -EPERM; |
Joachim Fenkes | 91f13aa | 2007-07-09 15:21:45 +0200 | [diff] [blame] | 269 | goto sense_attributes1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | if (ehca_nr_ports == 1) |
| 273 | shca->num_ports = 1; |
| 274 | else |
| 275 | shca->num_ports = (u8)rblock->num_ports; |
| 276 | |
| 277 | ehca_gen_dbg(" ... found %x ports", rblock->num_ports); |
| 278 | |
| 279 | if (ehca_hw_level == 0) { |
| 280 | u32 hcaaver; |
| 281 | u32 revid; |
| 282 | |
| 283 | hcaaver = EHCA_BMASK_GET(EHCA_HCAAVER, rblock->hw_ver); |
| 284 | revid = EHCA_BMASK_GET(EHCA_REVID, rblock->hw_ver); |
| 285 | |
| 286 | ehca_gen_dbg(" ... hardware version=%x:%x", hcaaver, revid); |
| 287 | |
Joachim Fenkes | fbb9318 | 2007-07-12 17:47:45 +0200 | [diff] [blame] | 288 | if (hcaaver == 1) { |
| 289 | if (revid <= 3) |
| 290 | shca->hw_level = 0x10 | (revid + 1); |
| 291 | else |
| 292 | shca->hw_level = 0x14; |
| 293 | } else if (hcaaver == 2) { |
| 294 | if (revid == 0) |
| 295 | shca->hw_level = 0x21; |
| 296 | else if (revid == 0x10) |
| 297 | shca->hw_level = 0x22; |
| 298 | else if (revid == 0x20 || revid == 0x21) |
| 299 | shca->hw_level = 0x23; |
| 300 | } |
| 301 | |
| 302 | if (!shca->hw_level) { |
Joachim Fenkes | 91f13aa | 2007-07-09 15:21:45 +0200 | [diff] [blame] | 303 | ehca_gen_warn("unknown hardware version" |
| 304 | " - assuming default level"); |
| 305 | shca->hw_level = 0x22; |
| 306 | } |
Joachim Fenkes | fbb9318 | 2007-07-12 17:47:45 +0200 | [diff] [blame] | 307 | } else |
| 308 | shca->hw_level = ehca_hw_level; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 309 | ehca_gen_dbg(" ... hardware level=%x", shca->hw_level); |
| 310 | |
| 311 | shca->sport[0].rate = IB_RATE_30_GBPS; |
| 312 | shca->sport[1].rate = IB_RATE_30_GBPS; |
| 313 | |
Joachim Fenkes | 91f13aa | 2007-07-09 15:21:45 +0200 | [diff] [blame] | 314 | shca->hca_cap = rblock->hca_cap_indicators; |
| 315 | ehca_gen_dbg(" ... HCA capabilities:"); |
| 316 | for (i = 0; i < ARRAY_SIZE(hca_cap_descr); i++) |
| 317 | if (EHCA_BMASK_GET(hca_cap_descr[i].mask, shca->hca_cap)) |
| 318 | ehca_gen_dbg(" %s", hca_cap_descr[i].descr); |
| 319 | |
Hoang-Nam Nguyen | 5bb7d92 | 2007-07-20 16:01:51 +0200 | [diff] [blame] | 320 | shca->hca_cap_mr_pgsize = rblock->memory_page_size_supported; |
| 321 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 322 | port = (struct hipz_query_port *)rblock; |
Joachim Fenkes | 91f13aa | 2007-07-09 15:21:45 +0200 | [diff] [blame] | 323 | h_ret = hipz_h_query_port(shca->ipz_hca_handle, 1, port); |
| 324 | if (h_ret != H_SUCCESS) { |
| 325 | ehca_gen_err("Cannot query port properties. h_ret=%lx", |
| 326 | h_ret); |
| 327 | ret = -EPERM; |
| 328 | goto sense_attributes1; |
| 329 | } |
| 330 | |
| 331 | shca->max_mtu = port->max_mtu; |
| 332 | |
| 333 | sense_attributes1: |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 334 | ehca_free_fw_ctrlblock(rblock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 335 | return ret; |
| 336 | } |
| 337 | |
| 338 | static int init_node_guid(struct ehca_shca *shca) |
| 339 | { |
| 340 | int ret = 0; |
| 341 | struct hipz_query_hca *rblock; |
| 342 | |
Hoang-Nam Nguyen | f2d9136 | 2007-01-09 18:04:14 +0100 | [diff] [blame] | 343 | rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 344 | if (!rblock) { |
| 345 | ehca_err(&shca->ib_device, "Can't allocate rblock memory."); |
| 346 | return -ENOMEM; |
| 347 | } |
| 348 | |
| 349 | if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { |
| 350 | ehca_err(&shca->ib_device, "Can't query device properties"); |
| 351 | ret = -EINVAL; |
| 352 | goto init_node_guid1; |
| 353 | } |
| 354 | |
| 355 | memcpy(&shca->ib_device.node_guid, &rblock->node_guid, sizeof(u64)); |
| 356 | |
| 357 | init_node_guid1: |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 358 | ehca_free_fw_ctrlblock(rblock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 359 | return ret; |
| 360 | } |
| 361 | |
Hoang-Nam Nguyen | 0f248d9 | 2006-10-02 14:52:17 -0700 | [diff] [blame] | 362 | int ehca_init_device(struct ehca_shca *shca) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 363 | { |
| 364 | int ret; |
| 365 | |
| 366 | ret = init_node_guid(shca); |
| 367 | if (ret) |
| 368 | return ret; |
| 369 | |
| 370 | strlcpy(shca->ib_device.name, "ehca%d", IB_DEVICE_NAME_MAX); |
| 371 | shca->ib_device.owner = THIS_MODULE; |
| 372 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 373 | shca->ib_device.uverbs_abi_ver = 7; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 374 | shca->ib_device.uverbs_cmd_mask = |
| 375 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 376 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 377 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 378 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 379 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
| 380 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
| 381 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 382 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 383 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 384 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 385 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 386 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 387 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 388 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 389 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 390 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST); |
| 391 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 392 | shca->ib_device.node_type = RDMA_NODE_IB_CA; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 393 | shca->ib_device.phys_port_cnt = shca->num_ports; |
Michael S. Tsirkin | f4fd0b2 | 2007-05-03 13:48:47 +0300 | [diff] [blame] | 394 | shca->ib_device.num_comp_vectors = 1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 395 | shca->ib_device.dma_device = &shca->ibmebus_dev->ofdev.dev; |
| 396 | shca->ib_device.query_device = ehca_query_device; |
| 397 | shca->ib_device.query_port = ehca_query_port; |
| 398 | shca->ib_device.query_gid = ehca_query_gid; |
| 399 | shca->ib_device.query_pkey = ehca_query_pkey; |
| 400 | /* shca->in_device.modify_device = ehca_modify_device */ |
| 401 | shca->ib_device.modify_port = ehca_modify_port; |
| 402 | shca->ib_device.alloc_ucontext = ehca_alloc_ucontext; |
| 403 | shca->ib_device.dealloc_ucontext = ehca_dealloc_ucontext; |
| 404 | shca->ib_device.alloc_pd = ehca_alloc_pd; |
| 405 | shca->ib_device.dealloc_pd = ehca_dealloc_pd; |
| 406 | shca->ib_device.create_ah = ehca_create_ah; |
| 407 | /* shca->ib_device.modify_ah = ehca_modify_ah; */ |
| 408 | shca->ib_device.query_ah = ehca_query_ah; |
| 409 | shca->ib_device.destroy_ah = ehca_destroy_ah; |
| 410 | shca->ib_device.create_qp = ehca_create_qp; |
| 411 | shca->ib_device.modify_qp = ehca_modify_qp; |
| 412 | shca->ib_device.query_qp = ehca_query_qp; |
| 413 | shca->ib_device.destroy_qp = ehca_destroy_qp; |
| 414 | shca->ib_device.post_send = ehca_post_send; |
| 415 | shca->ib_device.post_recv = ehca_post_recv; |
| 416 | shca->ib_device.create_cq = ehca_create_cq; |
| 417 | shca->ib_device.destroy_cq = ehca_destroy_cq; |
| 418 | shca->ib_device.resize_cq = ehca_resize_cq; |
| 419 | shca->ib_device.poll_cq = ehca_poll_cq; |
| 420 | /* shca->ib_device.peek_cq = ehca_peek_cq; */ |
| 421 | shca->ib_device.req_notify_cq = ehca_req_notify_cq; |
| 422 | /* shca->ib_device.req_ncomp_notif = ehca_req_ncomp_notif; */ |
| 423 | shca->ib_device.get_dma_mr = ehca_get_dma_mr; |
| 424 | shca->ib_device.reg_phys_mr = ehca_reg_phys_mr; |
| 425 | shca->ib_device.reg_user_mr = ehca_reg_user_mr; |
| 426 | shca->ib_device.query_mr = ehca_query_mr; |
| 427 | shca->ib_device.dereg_mr = ehca_dereg_mr; |
| 428 | shca->ib_device.rereg_phys_mr = ehca_rereg_phys_mr; |
| 429 | shca->ib_device.alloc_mw = ehca_alloc_mw; |
| 430 | shca->ib_device.bind_mw = ehca_bind_mw; |
| 431 | shca->ib_device.dealloc_mw = ehca_dealloc_mw; |
| 432 | shca->ib_device.alloc_fmr = ehca_alloc_fmr; |
| 433 | shca->ib_device.map_phys_fmr = ehca_map_phys_fmr; |
| 434 | shca->ib_device.unmap_fmr = ehca_unmap_fmr; |
| 435 | shca->ib_device.dealloc_fmr = ehca_dealloc_fmr; |
| 436 | shca->ib_device.attach_mcast = ehca_attach_mcast; |
| 437 | shca->ib_device.detach_mcast = ehca_detach_mcast; |
| 438 | /* shca->ib_device.process_mad = ehca_process_mad; */ |
| 439 | shca->ib_device.mmap = ehca_mmap; |
| 440 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 441 | if (EHCA_BMASK_GET(HCA_CAP_SRQ, shca->hca_cap)) { |
| 442 | shca->ib_device.uverbs_cmd_mask |= |
| 443 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 444 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 445 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 446 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ); |
| 447 | |
| 448 | shca->ib_device.create_srq = ehca_create_srq; |
| 449 | shca->ib_device.modify_srq = ehca_modify_srq; |
| 450 | shca->ib_device.query_srq = ehca_query_srq; |
| 451 | shca->ib_device.destroy_srq = ehca_destroy_srq; |
| 452 | shca->ib_device.post_srq_recv = ehca_post_srq_recv; |
| 453 | } |
| 454 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 455 | return ret; |
| 456 | } |
| 457 | |
| 458 | static int ehca_create_aqp1(struct ehca_shca *shca, u32 port) |
| 459 | { |
| 460 | struct ehca_sport *sport = &shca->sport[port - 1]; |
| 461 | struct ib_cq *ibcq; |
| 462 | struct ib_qp *ibqp; |
| 463 | struct ib_qp_init_attr qp_init_attr; |
| 464 | int ret; |
| 465 | |
| 466 | if (sport->ibcq_aqp1) { |
| 467 | ehca_err(&shca->ib_device, "AQP1 CQ is already created."); |
| 468 | return -EPERM; |
| 469 | } |
| 470 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 471 | ibcq = ib_create_cq(&shca->ib_device, NULL, NULL, (void *)(-1), 10, 0); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 472 | if (IS_ERR(ibcq)) { |
| 473 | ehca_err(&shca->ib_device, "Cannot create AQP1 CQ."); |
| 474 | return PTR_ERR(ibcq); |
| 475 | } |
| 476 | sport->ibcq_aqp1 = ibcq; |
| 477 | |
| 478 | if (sport->ibqp_aqp1) { |
| 479 | ehca_err(&shca->ib_device, "AQP1 QP is already created."); |
| 480 | ret = -EPERM; |
| 481 | goto create_aqp1; |
| 482 | } |
| 483 | |
| 484 | memset(&qp_init_attr, 0, sizeof(struct ib_qp_init_attr)); |
| 485 | qp_init_attr.send_cq = ibcq; |
| 486 | qp_init_attr.recv_cq = ibcq; |
| 487 | qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR; |
| 488 | qp_init_attr.cap.max_send_wr = 100; |
| 489 | qp_init_attr.cap.max_recv_wr = 100; |
| 490 | qp_init_attr.cap.max_send_sge = 2; |
| 491 | qp_init_attr.cap.max_recv_sge = 1; |
| 492 | qp_init_attr.qp_type = IB_QPT_GSI; |
| 493 | qp_init_attr.port_num = port; |
| 494 | qp_init_attr.qp_context = NULL; |
| 495 | qp_init_attr.event_handler = NULL; |
| 496 | qp_init_attr.srq = NULL; |
| 497 | |
| 498 | ibqp = ib_create_qp(&shca->pd->ib_pd, &qp_init_attr); |
| 499 | if (IS_ERR(ibqp)) { |
| 500 | ehca_err(&shca->ib_device, "Cannot create AQP1 QP."); |
| 501 | ret = PTR_ERR(ibqp); |
| 502 | goto create_aqp1; |
| 503 | } |
| 504 | sport->ibqp_aqp1 = ibqp; |
| 505 | |
| 506 | return 0; |
| 507 | |
| 508 | create_aqp1: |
| 509 | ib_destroy_cq(sport->ibcq_aqp1); |
| 510 | return ret; |
| 511 | } |
| 512 | |
| 513 | static int ehca_destroy_aqp1(struct ehca_sport *sport) |
| 514 | { |
| 515 | int ret; |
| 516 | |
| 517 | ret = ib_destroy_qp(sport->ibqp_aqp1); |
| 518 | if (ret) { |
| 519 | ehca_gen_err("Cannot destroy AQP1 QP. ret=%x", ret); |
| 520 | return ret; |
| 521 | } |
| 522 | |
| 523 | ret = ib_destroy_cq(sport->ibcq_aqp1); |
| 524 | if (ret) |
| 525 | ehca_gen_err("Cannot destroy AQP1 CQ. ret=%x", ret); |
| 526 | |
| 527 | return ret; |
| 528 | } |
| 529 | |
| 530 | static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf) |
| 531 | { |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 532 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 533 | ehca_debug_level); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static ssize_t ehca_store_debug_level(struct device_driver *ddp, |
| 537 | const char *buf, size_t count) |
| 538 | { |
| 539 | int value = (*buf) - '0'; |
| 540 | if (value >= 0 && value <= 9) |
| 541 | ehca_debug_level = value; |
| 542 | return 1; |
| 543 | } |
| 544 | |
| 545 | DRIVER_ATTR(debug_level, S_IRUSR | S_IWUSR, |
| 546 | ehca_show_debug_level, ehca_store_debug_level); |
| 547 | |
Joachim Fenkes | bba9b60 | 2007-05-09 13:48:25 +0200 | [diff] [blame] | 548 | static struct attribute *ehca_drv_attrs[] = { |
| 549 | &driver_attr_debug_level.attr, |
| 550 | NULL |
| 551 | }; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 552 | |
Joachim Fenkes | bba9b60 | 2007-05-09 13:48:25 +0200 | [diff] [blame] | 553 | static struct attribute_group ehca_drv_attr_grp = { |
| 554 | .attrs = ehca_drv_attrs |
| 555 | }; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 556 | |
| 557 | #define EHCA_RESOURCE_ATTR(name) \ |
| 558 | static ssize_t ehca_show_##name(struct device *dev, \ |
| 559 | struct device_attribute *attr, \ |
| 560 | char *buf) \ |
| 561 | { \ |
| 562 | struct ehca_shca *shca; \ |
| 563 | struct hipz_query_hca *rblock; \ |
| 564 | int data; \ |
| 565 | \ |
| 566 | shca = dev->driver_data; \ |
| 567 | \ |
Hoang-Nam Nguyen | f2d9136 | 2007-01-09 18:04:14 +0100 | [diff] [blame] | 568 | rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); \ |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 569 | if (!rblock) { \ |
| 570 | dev_err(dev, "Can't allocate rblock memory."); \ |
| 571 | return 0; \ |
| 572 | } \ |
| 573 | \ |
| 574 | if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { \ |
| 575 | dev_err(dev, "Can't query device properties"); \ |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 576 | ehca_free_fw_ctrlblock(rblock); \ |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 577 | return 0; \ |
| 578 | } \ |
| 579 | \ |
| 580 | data = rblock->name; \ |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 581 | ehca_free_fw_ctrlblock(rblock); \ |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 582 | \ |
| 583 | if ((strcmp(#name, "num_ports") == 0) && (ehca_nr_ports == 1)) \ |
| 584 | return snprintf(buf, 256, "1\n"); \ |
| 585 | else \ |
| 586 | return snprintf(buf, 256, "%d\n", data); \ |
| 587 | \ |
| 588 | } \ |
| 589 | static DEVICE_ATTR(name, S_IRUGO, ehca_show_##name, NULL); |
| 590 | |
| 591 | EHCA_RESOURCE_ATTR(num_ports); |
| 592 | EHCA_RESOURCE_ATTR(hw_ver); |
| 593 | EHCA_RESOURCE_ATTR(max_eq); |
| 594 | EHCA_RESOURCE_ATTR(cur_eq); |
| 595 | EHCA_RESOURCE_ATTR(max_cq); |
| 596 | EHCA_RESOURCE_ATTR(cur_cq); |
| 597 | EHCA_RESOURCE_ATTR(max_qp); |
| 598 | EHCA_RESOURCE_ATTR(cur_qp); |
| 599 | EHCA_RESOURCE_ATTR(max_mr); |
| 600 | EHCA_RESOURCE_ATTR(cur_mr); |
| 601 | EHCA_RESOURCE_ATTR(max_mw); |
| 602 | EHCA_RESOURCE_ATTR(cur_mw); |
| 603 | EHCA_RESOURCE_ATTR(max_pd); |
| 604 | EHCA_RESOURCE_ATTR(max_ah); |
| 605 | |
| 606 | static ssize_t ehca_show_adapter_handle(struct device *dev, |
| 607 | struct device_attribute *attr, |
| 608 | char *buf) |
| 609 | { |
| 610 | struct ehca_shca *shca = dev->driver_data; |
| 611 | |
| 612 | return sprintf(buf, "%lx\n", shca->ipz_hca_handle.handle); |
| 613 | |
| 614 | } |
| 615 | static DEVICE_ATTR(adapter_handle, S_IRUGO, ehca_show_adapter_handle, NULL); |
| 616 | |
Hoang-Nam Nguyen | 5bb7d92 | 2007-07-20 16:01:51 +0200 | [diff] [blame] | 617 | static ssize_t ehca_show_mr_largepage(struct device *dev, |
| 618 | struct device_attribute *attr, |
| 619 | char *buf) |
| 620 | { |
| 621 | return sprintf(buf, "%d\n", ehca_mr_largepage); |
| 622 | } |
| 623 | static DEVICE_ATTR(mr_largepage, S_IRUGO, ehca_show_mr_largepage, NULL); |
| 624 | |
Joachim Fenkes | bba9b60 | 2007-05-09 13:48:25 +0200 | [diff] [blame] | 625 | static struct attribute *ehca_dev_attrs[] = { |
| 626 | &dev_attr_adapter_handle.attr, |
| 627 | &dev_attr_num_ports.attr, |
| 628 | &dev_attr_hw_ver.attr, |
| 629 | &dev_attr_max_eq.attr, |
| 630 | &dev_attr_cur_eq.attr, |
| 631 | &dev_attr_max_cq.attr, |
| 632 | &dev_attr_cur_cq.attr, |
| 633 | &dev_attr_max_qp.attr, |
| 634 | &dev_attr_cur_qp.attr, |
| 635 | &dev_attr_max_mr.attr, |
| 636 | &dev_attr_cur_mr.attr, |
| 637 | &dev_attr_max_mw.attr, |
| 638 | &dev_attr_cur_mw.attr, |
| 639 | &dev_attr_max_pd.attr, |
| 640 | &dev_attr_max_ah.attr, |
Hoang-Nam Nguyen | 5bb7d92 | 2007-07-20 16:01:51 +0200 | [diff] [blame] | 641 | &dev_attr_mr_largepage.attr, |
Joachim Fenkes | bba9b60 | 2007-05-09 13:48:25 +0200 | [diff] [blame] | 642 | NULL |
| 643 | }; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 644 | |
Joachim Fenkes | bba9b60 | 2007-05-09 13:48:25 +0200 | [diff] [blame] | 645 | static struct attribute_group ehca_dev_attr_grp = { |
| 646 | .attrs = ehca_dev_attrs |
| 647 | }; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 648 | |
| 649 | static int __devinit ehca_probe(struct ibmebus_dev *dev, |
| 650 | const struct of_device_id *id) |
| 651 | { |
| 652 | struct ehca_shca *shca; |
Stephen Rothwell | a7edd0e | 2007-04-03 10:52:17 +1000 | [diff] [blame] | 653 | const u64 *handle; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 654 | struct ib_pd *ibpd; |
| 655 | int ret; |
| 656 | |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 657 | handle = of_get_property(dev->ofdev.node, "ibm,hca-handle", NULL); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 658 | if (!handle) { |
| 659 | ehca_gen_err("Cannot get eHCA handle for adapter: %s.", |
| 660 | dev->ofdev.node->full_name); |
| 661 | return -ENODEV; |
| 662 | } |
| 663 | |
| 664 | if (!(*handle)) { |
| 665 | ehca_gen_err("Wrong eHCA handle for adapter: %s.", |
| 666 | dev->ofdev.node->full_name); |
| 667 | return -ENODEV; |
| 668 | } |
| 669 | |
| 670 | shca = (struct ehca_shca *)ib_alloc_device(sizeof(*shca)); |
| 671 | if (!shca) { |
| 672 | ehca_gen_err("Cannot allocate shca memory."); |
| 673 | return -ENOMEM; |
| 674 | } |
Joachim Fenkes | c4ed790 | 2007-04-24 17:44:31 +0200 | [diff] [blame] | 675 | mutex_init(&shca->modify_mutex); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 676 | |
| 677 | shca->ibmebus_dev = dev; |
| 678 | shca->ipz_hca_handle.handle = *handle; |
| 679 | dev->ofdev.dev.driver_data = shca; |
| 680 | |
| 681 | ret = ehca_sense_attributes(shca); |
| 682 | if (ret < 0) { |
| 683 | ehca_gen_err("Cannot sense eHCA attributes."); |
| 684 | goto probe1; |
| 685 | } |
| 686 | |
Hoang-Nam Nguyen | 0f248d9 | 2006-10-02 14:52:17 -0700 | [diff] [blame] | 687 | ret = ehca_init_device(shca); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 688 | if (ret) { |
Hoang-Nam Nguyen | 0f248d9 | 2006-10-02 14:52:17 -0700 | [diff] [blame] | 689 | ehca_gen_err("Cannot init ehca device struct"); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 690 | goto probe1; |
| 691 | } |
| 692 | |
| 693 | /* create event queues */ |
| 694 | ret = ehca_create_eq(shca, &shca->eq, EHCA_EQ, 2048); |
| 695 | if (ret) { |
| 696 | ehca_err(&shca->ib_device, "Cannot create EQ."); |
Hoang-Nam Nguyen | 0f248d9 | 2006-10-02 14:52:17 -0700 | [diff] [blame] | 697 | goto probe1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | ret = ehca_create_eq(shca, &shca->neq, EHCA_NEQ, 513); |
| 701 | if (ret) { |
| 702 | ehca_err(&shca->ib_device, "Cannot create NEQ."); |
| 703 | goto probe3; |
| 704 | } |
| 705 | |
| 706 | /* create internal protection domain */ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 707 | ibpd = ehca_alloc_pd(&shca->ib_device, (void *)(-1), NULL); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 708 | if (IS_ERR(ibpd)) { |
| 709 | ehca_err(&shca->ib_device, "Cannot create internal PD."); |
| 710 | ret = PTR_ERR(ibpd); |
| 711 | goto probe4; |
| 712 | } |
| 713 | |
| 714 | shca->pd = container_of(ibpd, struct ehca_pd, ib_pd); |
| 715 | shca->pd->ib_pd.device = &shca->ib_device; |
| 716 | |
| 717 | /* create internal max MR */ |
| 718 | ret = ehca_reg_internal_maxmr(shca, shca->pd, &shca->maxmr); |
| 719 | |
| 720 | if (ret) { |
| 721 | ehca_err(&shca->ib_device, "Cannot create internal MR ret=%x", |
| 722 | ret); |
| 723 | goto probe5; |
| 724 | } |
| 725 | |
Hoang-Nam Nguyen | 0f248d9 | 2006-10-02 14:52:17 -0700 | [diff] [blame] | 726 | ret = ib_register_device(&shca->ib_device); |
| 727 | if (ret) { |
| 728 | ehca_err(&shca->ib_device, |
| 729 | "ib_register_device() failed ret=%x", ret); |
| 730 | goto probe6; |
| 731 | } |
| 732 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 733 | /* create AQP1 for port 1 */ |
| 734 | if (ehca_open_aqp1 == 1) { |
| 735 | shca->sport[0].port_state = IB_PORT_DOWN; |
| 736 | ret = ehca_create_aqp1(shca, 1); |
| 737 | if (ret) { |
| 738 | ehca_err(&shca->ib_device, |
| 739 | "Cannot create AQP1 for port 1."); |
Hoang-Nam Nguyen | 0f248d9 | 2006-10-02 14:52:17 -0700 | [diff] [blame] | 740 | goto probe7; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | |
| 744 | /* create AQP1 for port 2 */ |
| 745 | if ((ehca_open_aqp1 == 1) && (shca->num_ports == 2)) { |
| 746 | shca->sport[1].port_state = IB_PORT_DOWN; |
| 747 | ret = ehca_create_aqp1(shca, 2); |
| 748 | if (ret) { |
| 749 | ehca_err(&shca->ib_device, |
| 750 | "Cannot create AQP1 for port 2."); |
Hoang-Nam Nguyen | 0f248d9 | 2006-10-02 14:52:17 -0700 | [diff] [blame] | 751 | goto probe8; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | |
Joachim Fenkes | bba9b60 | 2007-05-09 13:48:25 +0200 | [diff] [blame] | 755 | ret = sysfs_create_group(&dev->ofdev.dev.kobj, &ehca_dev_attr_grp); |
| 756 | if (ret) /* only complain; we can live without attributes */ |
| 757 | ehca_err(&shca->ib_device, |
| 758 | "Cannot create device attributes ret=%d", ret); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 759 | |
| 760 | spin_lock(&shca_list_lock); |
| 761 | list_add(&shca->shca_list, &shca_list); |
| 762 | spin_unlock(&shca_list_lock); |
| 763 | |
| 764 | return 0; |
| 765 | |
Hoang-Nam Nguyen | 0f248d9 | 2006-10-02 14:52:17 -0700 | [diff] [blame] | 766 | probe8: |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 767 | ret = ehca_destroy_aqp1(&shca->sport[0]); |
| 768 | if (ret) |
| 769 | ehca_err(&shca->ib_device, |
| 770 | "Cannot destroy AQP1 for port 1. ret=%x", ret); |
| 771 | |
Hoang-Nam Nguyen | 0f248d9 | 2006-10-02 14:52:17 -0700 | [diff] [blame] | 772 | probe7: |
| 773 | ib_unregister_device(&shca->ib_device); |
| 774 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 775 | probe6: |
| 776 | ret = ehca_dereg_internal_maxmr(shca); |
| 777 | if (ret) |
| 778 | ehca_err(&shca->ib_device, |
| 779 | "Cannot destroy internal MR. ret=%x", ret); |
| 780 | |
| 781 | probe5: |
| 782 | ret = ehca_dealloc_pd(&shca->pd->ib_pd); |
| 783 | if (ret) |
| 784 | ehca_err(&shca->ib_device, |
| 785 | "Cannot destroy internal PD. ret=%x", ret); |
| 786 | |
| 787 | probe4: |
| 788 | ret = ehca_destroy_eq(shca, &shca->neq); |
| 789 | if (ret) |
| 790 | ehca_err(&shca->ib_device, |
| 791 | "Cannot destroy NEQ. ret=%x", ret); |
| 792 | |
| 793 | probe3: |
| 794 | ret = ehca_destroy_eq(shca, &shca->eq); |
| 795 | if (ret) |
| 796 | ehca_err(&shca->ib_device, |
| 797 | "Cannot destroy EQ. ret=%x", ret); |
| 798 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 799 | probe1: |
| 800 | ib_dealloc_device(&shca->ib_device); |
| 801 | |
| 802 | return -EINVAL; |
| 803 | } |
| 804 | |
| 805 | static int __devexit ehca_remove(struct ibmebus_dev *dev) |
| 806 | { |
| 807 | struct ehca_shca *shca = dev->ofdev.dev.driver_data; |
| 808 | int ret; |
| 809 | |
Joachim Fenkes | bba9b60 | 2007-05-09 13:48:25 +0200 | [diff] [blame] | 810 | sysfs_remove_group(&dev->ofdev.dev.kobj, &ehca_dev_attr_grp); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 811 | |
| 812 | if (ehca_open_aqp1 == 1) { |
| 813 | int i; |
| 814 | for (i = 0; i < shca->num_ports; i++) { |
| 815 | ret = ehca_destroy_aqp1(&shca->sport[i]); |
| 816 | if (ret) |
| 817 | ehca_err(&shca->ib_device, |
| 818 | "Cannot destroy AQP1 for port %x " |
| 819 | "ret=%x", ret, i); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | ib_unregister_device(&shca->ib_device); |
| 824 | |
| 825 | ret = ehca_dereg_internal_maxmr(shca); |
| 826 | if (ret) |
| 827 | ehca_err(&shca->ib_device, |
| 828 | "Cannot destroy internal MR. ret=%x", ret); |
| 829 | |
| 830 | ret = ehca_dealloc_pd(&shca->pd->ib_pd); |
| 831 | if (ret) |
| 832 | ehca_err(&shca->ib_device, |
| 833 | "Cannot destroy internal PD. ret=%x", ret); |
| 834 | |
| 835 | ret = ehca_destroy_eq(shca, &shca->eq); |
| 836 | if (ret) |
| 837 | ehca_err(&shca->ib_device, "Cannot destroy EQ. ret=%x", ret); |
| 838 | |
| 839 | ret = ehca_destroy_eq(shca, &shca->neq); |
| 840 | if (ret) |
| 841 | ehca_err(&shca->ib_device, "Canot destroy NEQ. ret=%x", ret); |
| 842 | |
| 843 | ib_dealloc_device(&shca->ib_device); |
| 844 | |
| 845 | spin_lock(&shca_list_lock); |
| 846 | list_del(&shca->shca_list); |
| 847 | spin_unlock(&shca_list_lock); |
| 848 | |
| 849 | return ret; |
| 850 | } |
| 851 | |
| 852 | static struct of_device_id ehca_device_table[] = |
| 853 | { |
| 854 | { |
| 855 | .name = "lhca", |
| 856 | .compatible = "IBM,lhca", |
| 857 | }, |
| 858 | {}, |
| 859 | }; |
| 860 | |
| 861 | static struct ibmebus_driver ehca_driver = { |
| 862 | .name = "ehca", |
| 863 | .id_table = ehca_device_table, |
| 864 | .probe = ehca_probe, |
| 865 | .remove = ehca_remove, |
| 866 | }; |
| 867 | |
| 868 | void ehca_poll_eqs(unsigned long data) |
| 869 | { |
| 870 | struct ehca_shca *shca; |
| 871 | |
| 872 | spin_lock(&shca_list_lock); |
| 873 | list_for_each_entry(shca, &shca_list, shca_list) { |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 874 | if (shca->eq.is_initialized) { |
| 875 | /* call deadman proc only if eq ptr does not change */ |
| 876 | struct ehca_eq *eq = &shca->eq; |
| 877 | int max = 3; |
| 878 | volatile u64 q_ofs, q_ofs2; |
| 879 | u64 flags; |
| 880 | spin_lock_irqsave(&eq->spinlock, flags); |
| 881 | q_ofs = eq->ipz_queue.current_q_offset; |
| 882 | spin_unlock_irqrestore(&eq->spinlock, flags); |
| 883 | do { |
| 884 | spin_lock_irqsave(&eq->spinlock, flags); |
| 885 | q_ofs2 = eq->ipz_queue.current_q_offset; |
| 886 | spin_unlock_irqrestore(&eq->spinlock, flags); |
| 887 | max--; |
| 888 | } while (q_ofs == q_ofs2 && max > 0); |
| 889 | if (q_ofs == q_ofs2) |
| 890 | ehca_process_eq(shca, 0); |
| 891 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 892 | } |
| 893 | mod_timer(&poll_eqs_timer, jiffies + HZ); |
| 894 | spin_unlock(&shca_list_lock); |
| 895 | } |
| 896 | |
| 897 | int __init ehca_module_init(void) |
| 898 | { |
| 899 | int ret; |
| 900 | |
| 901 | printk(KERN_INFO "eHCA Infiniband Device Driver " |
Joachim Fenkes | 4e430dc | 2007-05-09 13:48:31 +0200 | [diff] [blame] | 902 | "(Rel.: SVNEHCA_0023)\n"); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 903 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 904 | ret = ehca_create_comp_pool(); |
| 905 | if (ret) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 906 | ehca_gen_err("Cannot create comp pool."); |
| 907 | return ret; |
| 908 | } |
| 909 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 910 | ret = ehca_create_slab_caches(); |
| 911 | if (ret) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 912 | ehca_gen_err("Cannot create SLAB caches"); |
| 913 | ret = -ENOMEM; |
| 914 | goto module_init1; |
| 915 | } |
| 916 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 917 | ret = ibmebus_register_driver(&ehca_driver); |
| 918 | if (ret) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 919 | ehca_gen_err("Cannot register eHCA device driver"); |
| 920 | ret = -EINVAL; |
| 921 | goto module_init2; |
| 922 | } |
| 923 | |
Joachim Fenkes | bba9b60 | 2007-05-09 13:48:25 +0200 | [diff] [blame] | 924 | ret = sysfs_create_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp); |
| 925 | if (ret) /* only complain; we can live without attributes */ |
| 926 | ehca_gen_err("Cannot create driver attributes ret=%d", ret); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 927 | |
| 928 | if (ehca_poll_all_eqs != 1) { |
| 929 | ehca_gen_err("WARNING!!!"); |
| 930 | ehca_gen_err("It is possible to lose interrupts."); |
| 931 | } else { |
| 932 | init_timer(&poll_eqs_timer); |
| 933 | poll_eqs_timer.function = ehca_poll_eqs; |
| 934 | poll_eqs_timer.expires = jiffies + HZ; |
| 935 | add_timer(&poll_eqs_timer); |
| 936 | } |
| 937 | |
| 938 | return 0; |
| 939 | |
| 940 | module_init2: |
| 941 | ehca_destroy_slab_caches(); |
| 942 | |
| 943 | module_init1: |
| 944 | ehca_destroy_comp_pool(); |
| 945 | return ret; |
| 946 | }; |
| 947 | |
| 948 | void __exit ehca_module_exit(void) |
| 949 | { |
| 950 | if (ehca_poll_all_eqs == 1) |
| 951 | del_timer_sync(&poll_eqs_timer); |
| 952 | |
Joachim Fenkes | bba9b60 | 2007-05-09 13:48:25 +0200 | [diff] [blame] | 953 | sysfs_remove_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 954 | ibmebus_unregister_driver(&ehca_driver); |
| 955 | |
| 956 | ehca_destroy_slab_caches(); |
| 957 | |
| 958 | ehca_destroy_comp_pool(); |
| 959 | |
| 960 | idr_destroy(&ehca_cq_idr); |
| 961 | idr_destroy(&ehca_qp_idr); |
| 962 | }; |
| 963 | |
| 964 | module_init(ehca_module_init); |
| 965 | module_exit(ehca_module_exit); |