blob: ec0145192228fdcb56de58a865f60af90b897fd7 [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 * 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 Nguyen7e28db52006-11-07 00:56:39 +010043#ifdef CONFIG_PPC_64K_PAGES
44#include <linux/slab.h>
45#endif
Heiko J Schickfab97222006-09-22 15:22:22 -070046#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
52MODULE_LICENSE("Dual BSD/GPL");
53MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
54MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver");
Joachim Fenkes4e430dc2007-05-09 13:48:31 +020055MODULE_VERSION("SVNEHCA_0023");
Heiko J Schickfab97222006-09-22 15:22:22 -070056
57int ehca_open_aqp1 = 0;
58int ehca_debug_level = 0;
59int ehca_hw_level = 0;
60int ehca_nr_ports = 2;
61int ehca_use_hp_mr = 0;
62int ehca_port_act_time = 30;
63int ehca_poll_all_eqs = 1;
64int ehca_static_rate = -1;
Joachim Fenkes4e430dc2007-05-09 13:48:31 +020065int ehca_scaling_code = 0;
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +020066int ehca_mr_largepage = 0;
Heiko J Schickfab97222006-09-22 15:22:22 -070067
68module_param_named(open_aqp1, ehca_open_aqp1, int, 0);
69module_param_named(debug_level, ehca_debug_level, int, 0);
70module_param_named(hw_level, ehca_hw_level, int, 0);
71module_param_named(nr_ports, ehca_nr_ports, int, 0);
72module_param_named(use_hp_mr, ehca_use_hp_mr, int, 0);
73module_param_named(port_act_time, ehca_port_act_time, int, 0);
74module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, 0);
75module_param_named(static_rate, ehca_static_rate, int, 0);
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +020076module_param_named(scaling_code, ehca_scaling_code, int, 0);
77module_param_named(mr_largepage, ehca_mr_largepage, int, 0);
Heiko J Schickfab97222006-09-22 15:22:22 -070078
79MODULE_PARM_DESC(open_aqp1,
80 "AQP1 on startup (0: no (default), 1: yes)");
81MODULE_PARM_DESC(debug_level,
82 "debug level"
83 " (0: no debug traces (default), 1: with debug traces)");
84MODULE_PARM_DESC(hw_level,
85 "hardware level"
86 " (0: autosensing (default), 1: v. 0.20, 2: v. 0.21)");
87MODULE_PARM_DESC(nr_ports,
88 "number of connected ports (default: 2)");
89MODULE_PARM_DESC(use_hp_mr,
90 "high performance MRs (0: no (default), 1: yes)");
91MODULE_PARM_DESC(port_act_time,
92 "time to wait for port activation (default: 30 sec)");
93MODULE_PARM_DESC(poll_all_eqs,
94 "polls all event queues periodically"
95 " (0: no, 1: yes (default))");
96MODULE_PARM_DESC(static_rate,
97 "set permanent static rate (default: disabled)");
Hoang-Nam Nguyen4fd30062007-02-15 17:08:33 +010098MODULE_PARM_DESC(scaling_code,
Hoang-Nam Nguyenb8a3ba52007-07-09 15:20:55 +020099 "set scaling code (0: disabled/default, 1: enabled)");
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200100MODULE_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 Schickfab97222006-09-22 15:22:22 -0700103
Joachim Fenkes26ed6872007-07-09 15:31:10 +0200104DEFINE_RWLOCK(ehca_qp_idr_lock);
105DEFINE_RWLOCK(ehca_cq_idr_lock);
Heiko J Schickfab97222006-09-22 15:22:22 -0700106DEFINE_IDR(ehca_qp_idr);
107DEFINE_IDR(ehca_cq_idr);
108
Joachim Fenkes9844b712007-07-09 15:29:03 +0200109static LIST_HEAD(shca_list); /* list of all registered ehcas */
110static DEFINE_SPINLOCK(shca_list_lock);
Heiko J Schickfab97222006-09-22 15:22:22 -0700111
112static struct timer_list poll_eqs_timer;
113
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100114#ifdef CONFIG_PPC_64K_PAGES
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200115static struct kmem_cache *ctblk_cache;
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100116
Hoang-Nam Nguyenf2d91362007-01-09 18:04:14 +0100117void *ehca_alloc_fw_ctrlblock(gfp_t flags)
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100118{
Hoang-Nam Nguyenf2d91362007-01-09 18:04:14 +0100119 void *ret = kmem_cache_zalloc(ctblk_cache, flags);
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100120 if (!ret)
121 ehca_gen_err("Out of memory for ctblk");
122 return ret;
123}
124
125void ehca_free_fw_ctrlblock(void *ptr)
126{
127 if (ptr)
128 kmem_cache_free(ctblk_cache, ptr);
129
130}
131#endif
132
Heiko J Schickfab97222006-09-22 15:22:22 -0700133static int ehca_create_slab_caches(void)
134{
135 int ret;
136
137 ret = ehca_init_pd_cache();
138 if (ret) {
139 ehca_gen_err("Cannot create PD SLAB cache.");
140 return ret;
141 }
142
143 ret = ehca_init_cq_cache();
144 if (ret) {
145 ehca_gen_err("Cannot create CQ SLAB cache.");
146 goto create_slab_caches2;
147 }
148
149 ret = ehca_init_qp_cache();
150 if (ret) {
151 ehca_gen_err("Cannot create QP SLAB cache.");
152 goto create_slab_caches3;
153 }
154
155 ret = ehca_init_av_cache();
156 if (ret) {
157 ehca_gen_err("Cannot create AV SLAB cache.");
158 goto create_slab_caches4;
159 }
160
161 ret = ehca_init_mrmw_cache();
162 if (ret) {
163 ehca_gen_err("Cannot create MR&MW SLAB cache.");
164 goto create_slab_caches5;
165 }
166
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100167#ifdef CONFIG_PPC_64K_PAGES
168 ctblk_cache = kmem_cache_create("ehca_cache_ctblk",
169 EHCA_PAGESIZE, H_CB_ALIGNMENT,
170 SLAB_HWCACHE_ALIGN,
Paul Mundt20c2df82007-07-20 10:11:58 +0900171 NULL);
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100172 if (!ctblk_cache) {
173 ehca_gen_err("Cannot create ctblk SLAB cache.");
174 ehca_cleanup_mrmw_cache();
175 goto create_slab_caches5;
176 }
177#endif
Heiko J Schickfab97222006-09-22 15:22:22 -0700178 return 0;
179
180create_slab_caches5:
181 ehca_cleanup_av_cache();
182
183create_slab_caches4:
184 ehca_cleanup_qp_cache();
185
186create_slab_caches3:
187 ehca_cleanup_cq_cache();
188
189create_slab_caches2:
190 ehca_cleanup_pd_cache();
191
192 return ret;
193}
194
195static void ehca_destroy_slab_caches(void)
196{
197 ehca_cleanup_mrmw_cache();
198 ehca_cleanup_av_cache();
199 ehca_cleanup_qp_cache();
200 ehca_cleanup_cq_cache();
201 ehca_cleanup_pd_cache();
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100202#ifdef CONFIG_PPC_64K_PAGES
203 if (ctblk_cache)
204 kmem_cache_destroy(ctblk_cache);
205#endif
Heiko J Schickfab97222006-09-22 15:22:22 -0700206}
207
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200208#define EHCA_HCAAVER EHCA_BMASK_IBM(32, 39)
209#define EHCA_REVID EHCA_BMASK_IBM(40, 63)
Heiko J Schickfab97222006-09-22 15:22:22 -0700210
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200211static struct cap_descr {
212 u64 mask;
213 char *descr;
214} hca_cap_descr[] = {
215 { HCA_CAP_AH_PORT_NR_CHECK, "HCA_CAP_AH_PORT_NR_CHECK" },
216 { HCA_CAP_ATOMIC, "HCA_CAP_ATOMIC" },
217 { HCA_CAP_AUTO_PATH_MIG, "HCA_CAP_AUTO_PATH_MIG" },
218 { HCA_CAP_BAD_P_KEY_CTR, "HCA_CAP_BAD_P_KEY_CTR" },
219 { HCA_CAP_SQD_RTS_PORT_CHANGE, "HCA_CAP_SQD_RTS_PORT_CHANGE" },
220 { HCA_CAP_CUR_QP_STATE_MOD, "HCA_CAP_CUR_QP_STATE_MOD" },
221 { HCA_CAP_INIT_TYPE, "HCA_CAP_INIT_TYPE" },
222 { HCA_CAP_PORT_ACTIVE_EVENT, "HCA_CAP_PORT_ACTIVE_EVENT" },
223 { HCA_CAP_Q_KEY_VIOL_CTR, "HCA_CAP_Q_KEY_VIOL_CTR" },
224 { HCA_CAP_WQE_RESIZE, "HCA_CAP_WQE_RESIZE" },
225 { HCA_CAP_RAW_PACKET_MCAST, "HCA_CAP_RAW_PACKET_MCAST" },
226 { HCA_CAP_SHUTDOWN_PORT, "HCA_CAP_SHUTDOWN_PORT" },
227 { HCA_CAP_RC_LL_QP, "HCA_CAP_RC_LL_QP" },
228 { HCA_CAP_SRQ, "HCA_CAP_SRQ" },
229 { HCA_CAP_UD_LL_QP, "HCA_CAP_UD_LL_QP" },
230 { HCA_CAP_RESIZE_MR, "HCA_CAP_RESIZE_MR" },
231 { HCA_CAP_MINI_QP, "HCA_CAP_MINI_QP" },
232};
233
Heiko J Schickfab97222006-09-22 15:22:22 -0700234int ehca_sense_attributes(struct ehca_shca *shca)
235{
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200236 int i, ret = 0;
Heiko J Schickfab97222006-09-22 15:22:22 -0700237 u64 h_ret;
238 struct hipz_query_hca *rblock;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200239 struct hipz_query_port *port;
Heiko J Schickfab97222006-09-22 15:22:22 -0700240
Hoang-Nam Nguyenf2d91362007-01-09 18:04:14 +0100241 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
Heiko J Schickfab97222006-09-22 15:22:22 -0700242 if (!rblock) {
243 ehca_gen_err("Cannot allocate rblock memory.");
244 return -ENOMEM;
245 }
246
247 h_ret = hipz_h_query_hca(shca->ipz_hca_handle, rblock);
248 if (h_ret != H_SUCCESS) {
249 ehca_gen_err("Cannot query device properties. h_ret=%lx",
250 h_ret);
251 ret = -EPERM;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200252 goto sense_attributes1;
Heiko J Schickfab97222006-09-22 15:22:22 -0700253 }
254
255 if (ehca_nr_ports == 1)
256 shca->num_ports = 1;
257 else
258 shca->num_ports = (u8)rblock->num_ports;
259
260 ehca_gen_dbg(" ... found %x ports", rblock->num_ports);
261
262 if (ehca_hw_level == 0) {
263 u32 hcaaver;
264 u32 revid;
265
266 hcaaver = EHCA_BMASK_GET(EHCA_HCAAVER, rblock->hw_ver);
267 revid = EHCA_BMASK_GET(EHCA_REVID, rblock->hw_ver);
268
269 ehca_gen_dbg(" ... hardware version=%x:%x", hcaaver, revid);
270
Joachim Fenkesfbb93182007-07-12 17:47:45 +0200271 if (hcaaver == 1) {
272 if (revid <= 3)
273 shca->hw_level = 0x10 | (revid + 1);
274 else
275 shca->hw_level = 0x14;
276 } else if (hcaaver == 2) {
277 if (revid == 0)
278 shca->hw_level = 0x21;
279 else if (revid == 0x10)
280 shca->hw_level = 0x22;
281 else if (revid == 0x20 || revid == 0x21)
282 shca->hw_level = 0x23;
283 }
284
285 if (!shca->hw_level) {
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200286 ehca_gen_warn("unknown hardware version"
287 " - assuming default level");
288 shca->hw_level = 0x22;
289 }
Joachim Fenkesfbb93182007-07-12 17:47:45 +0200290 } else
291 shca->hw_level = ehca_hw_level;
Heiko J Schickfab97222006-09-22 15:22:22 -0700292 ehca_gen_dbg(" ... hardware level=%x", shca->hw_level);
293
294 shca->sport[0].rate = IB_RATE_30_GBPS;
295 shca->sport[1].rate = IB_RATE_30_GBPS;
296
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200297 shca->hca_cap = rblock->hca_cap_indicators;
298 ehca_gen_dbg(" ... HCA capabilities:");
299 for (i = 0; i < ARRAY_SIZE(hca_cap_descr); i++)
300 if (EHCA_BMASK_GET(hca_cap_descr[i].mask, shca->hca_cap))
301 ehca_gen_dbg(" %s", hca_cap_descr[i].descr);
302
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200303 shca->hca_cap_mr_pgsize = rblock->memory_page_size_supported;
304
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200305 port = (struct hipz_query_port *)rblock;
Joachim Fenkes91f13aa2007-07-09 15:21:45 +0200306 h_ret = hipz_h_query_port(shca->ipz_hca_handle, 1, port);
307 if (h_ret != H_SUCCESS) {
308 ehca_gen_err("Cannot query port properties. h_ret=%lx",
309 h_ret);
310 ret = -EPERM;
311 goto sense_attributes1;
312 }
313
314 shca->max_mtu = port->max_mtu;
315
316sense_attributes1:
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100317 ehca_free_fw_ctrlblock(rblock);
Heiko J Schickfab97222006-09-22 15:22:22 -0700318 return ret;
319}
320
321static int init_node_guid(struct ehca_shca *shca)
322{
323 int ret = 0;
324 struct hipz_query_hca *rblock;
325
Hoang-Nam Nguyenf2d91362007-01-09 18:04:14 +0100326 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
Heiko J Schickfab97222006-09-22 15:22:22 -0700327 if (!rblock) {
328 ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
329 return -ENOMEM;
330 }
331
332 if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) {
333 ehca_err(&shca->ib_device, "Can't query device properties");
334 ret = -EINVAL;
335 goto init_node_guid1;
336 }
337
338 memcpy(&shca->ib_device.node_guid, &rblock->node_guid, sizeof(u64));
339
340init_node_guid1:
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100341 ehca_free_fw_ctrlblock(rblock);
Heiko J Schickfab97222006-09-22 15:22:22 -0700342 return ret;
343}
344
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700345int ehca_init_device(struct ehca_shca *shca)
Heiko J Schickfab97222006-09-22 15:22:22 -0700346{
347 int ret;
348
349 ret = init_node_guid(shca);
350 if (ret)
351 return ret;
352
353 strlcpy(shca->ib_device.name, "ehca%d", IB_DEVICE_NAME_MAX);
354 shca->ib_device.owner = THIS_MODULE;
355
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200356 shca->ib_device.uverbs_abi_ver = 7;
Heiko J Schickfab97222006-09-22 15:22:22 -0700357 shca->ib_device.uverbs_cmd_mask =
358 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
359 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
360 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
361 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
362 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
363 (1ull << IB_USER_VERBS_CMD_REG_MR) |
364 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
365 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
366 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
367 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
368 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
369 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
370 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
371 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
372 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
373 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST);
374
Tom Tucker07ebafb2006-08-03 16:02:42 -0500375 shca->ib_device.node_type = RDMA_NODE_IB_CA;
Heiko J Schickfab97222006-09-22 15:22:22 -0700376 shca->ib_device.phys_port_cnt = shca->num_ports;
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +0300377 shca->ib_device.num_comp_vectors = 1;
Heiko J Schickfab97222006-09-22 15:22:22 -0700378 shca->ib_device.dma_device = &shca->ibmebus_dev->ofdev.dev;
379 shca->ib_device.query_device = ehca_query_device;
380 shca->ib_device.query_port = ehca_query_port;
381 shca->ib_device.query_gid = ehca_query_gid;
382 shca->ib_device.query_pkey = ehca_query_pkey;
383 /* shca->in_device.modify_device = ehca_modify_device */
384 shca->ib_device.modify_port = ehca_modify_port;
385 shca->ib_device.alloc_ucontext = ehca_alloc_ucontext;
386 shca->ib_device.dealloc_ucontext = ehca_dealloc_ucontext;
387 shca->ib_device.alloc_pd = ehca_alloc_pd;
388 shca->ib_device.dealloc_pd = ehca_dealloc_pd;
389 shca->ib_device.create_ah = ehca_create_ah;
390 /* shca->ib_device.modify_ah = ehca_modify_ah; */
391 shca->ib_device.query_ah = ehca_query_ah;
392 shca->ib_device.destroy_ah = ehca_destroy_ah;
393 shca->ib_device.create_qp = ehca_create_qp;
394 shca->ib_device.modify_qp = ehca_modify_qp;
395 shca->ib_device.query_qp = ehca_query_qp;
396 shca->ib_device.destroy_qp = ehca_destroy_qp;
397 shca->ib_device.post_send = ehca_post_send;
398 shca->ib_device.post_recv = ehca_post_recv;
399 shca->ib_device.create_cq = ehca_create_cq;
400 shca->ib_device.destroy_cq = ehca_destroy_cq;
401 shca->ib_device.resize_cq = ehca_resize_cq;
402 shca->ib_device.poll_cq = ehca_poll_cq;
403 /* shca->ib_device.peek_cq = ehca_peek_cq; */
404 shca->ib_device.req_notify_cq = ehca_req_notify_cq;
405 /* shca->ib_device.req_ncomp_notif = ehca_req_ncomp_notif; */
406 shca->ib_device.get_dma_mr = ehca_get_dma_mr;
407 shca->ib_device.reg_phys_mr = ehca_reg_phys_mr;
408 shca->ib_device.reg_user_mr = ehca_reg_user_mr;
409 shca->ib_device.query_mr = ehca_query_mr;
410 shca->ib_device.dereg_mr = ehca_dereg_mr;
411 shca->ib_device.rereg_phys_mr = ehca_rereg_phys_mr;
412 shca->ib_device.alloc_mw = ehca_alloc_mw;
413 shca->ib_device.bind_mw = ehca_bind_mw;
414 shca->ib_device.dealloc_mw = ehca_dealloc_mw;
415 shca->ib_device.alloc_fmr = ehca_alloc_fmr;
416 shca->ib_device.map_phys_fmr = ehca_map_phys_fmr;
417 shca->ib_device.unmap_fmr = ehca_unmap_fmr;
418 shca->ib_device.dealloc_fmr = ehca_dealloc_fmr;
419 shca->ib_device.attach_mcast = ehca_attach_mcast;
420 shca->ib_device.detach_mcast = ehca_detach_mcast;
421 /* shca->ib_device.process_mad = ehca_process_mad; */
422 shca->ib_device.mmap = ehca_mmap;
423
Joachim Fenkesa6a12942007-07-09 15:25:10 +0200424 if (EHCA_BMASK_GET(HCA_CAP_SRQ, shca->hca_cap)) {
425 shca->ib_device.uverbs_cmd_mask |=
426 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
427 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
428 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
429 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
430
431 shca->ib_device.create_srq = ehca_create_srq;
432 shca->ib_device.modify_srq = ehca_modify_srq;
433 shca->ib_device.query_srq = ehca_query_srq;
434 shca->ib_device.destroy_srq = ehca_destroy_srq;
435 shca->ib_device.post_srq_recv = ehca_post_srq_recv;
436 }
437
Heiko J Schickfab97222006-09-22 15:22:22 -0700438 return ret;
439}
440
441static int ehca_create_aqp1(struct ehca_shca *shca, u32 port)
442{
443 struct ehca_sport *sport = &shca->sport[port - 1];
444 struct ib_cq *ibcq;
445 struct ib_qp *ibqp;
446 struct ib_qp_init_attr qp_init_attr;
447 int ret;
448
449 if (sport->ibcq_aqp1) {
450 ehca_err(&shca->ib_device, "AQP1 CQ is already created.");
451 return -EPERM;
452 }
453
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200454 ibcq = ib_create_cq(&shca->ib_device, NULL, NULL, (void *)(-1), 10, 0);
Heiko J Schickfab97222006-09-22 15:22:22 -0700455 if (IS_ERR(ibcq)) {
456 ehca_err(&shca->ib_device, "Cannot create AQP1 CQ.");
457 return PTR_ERR(ibcq);
458 }
459 sport->ibcq_aqp1 = ibcq;
460
461 if (sport->ibqp_aqp1) {
462 ehca_err(&shca->ib_device, "AQP1 QP is already created.");
463 ret = -EPERM;
464 goto create_aqp1;
465 }
466
467 memset(&qp_init_attr, 0, sizeof(struct ib_qp_init_attr));
468 qp_init_attr.send_cq = ibcq;
469 qp_init_attr.recv_cq = ibcq;
470 qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR;
471 qp_init_attr.cap.max_send_wr = 100;
472 qp_init_attr.cap.max_recv_wr = 100;
473 qp_init_attr.cap.max_send_sge = 2;
474 qp_init_attr.cap.max_recv_sge = 1;
475 qp_init_attr.qp_type = IB_QPT_GSI;
476 qp_init_attr.port_num = port;
477 qp_init_attr.qp_context = NULL;
478 qp_init_attr.event_handler = NULL;
479 qp_init_attr.srq = NULL;
480
481 ibqp = ib_create_qp(&shca->pd->ib_pd, &qp_init_attr);
482 if (IS_ERR(ibqp)) {
483 ehca_err(&shca->ib_device, "Cannot create AQP1 QP.");
484 ret = PTR_ERR(ibqp);
485 goto create_aqp1;
486 }
487 sport->ibqp_aqp1 = ibqp;
488
489 return 0;
490
491create_aqp1:
492 ib_destroy_cq(sport->ibcq_aqp1);
493 return ret;
494}
495
496static int ehca_destroy_aqp1(struct ehca_sport *sport)
497{
498 int ret;
499
500 ret = ib_destroy_qp(sport->ibqp_aqp1);
501 if (ret) {
502 ehca_gen_err("Cannot destroy AQP1 QP. ret=%x", ret);
503 return ret;
504 }
505
506 ret = ib_destroy_cq(sport->ibcq_aqp1);
507 if (ret)
508 ehca_gen_err("Cannot destroy AQP1 CQ. ret=%x", ret);
509
510 return ret;
511}
512
513static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf)
514{
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +0100515 return snprintf(buf, PAGE_SIZE, "%d\n",
516 ehca_debug_level);
Heiko J Schickfab97222006-09-22 15:22:22 -0700517}
518
519static ssize_t ehca_store_debug_level(struct device_driver *ddp,
520 const char *buf, size_t count)
521{
522 int value = (*buf) - '0';
523 if (value >= 0 && value <= 9)
524 ehca_debug_level = value;
525 return 1;
526}
527
528DRIVER_ATTR(debug_level, S_IRUSR | S_IWUSR,
529 ehca_show_debug_level, ehca_store_debug_level);
530
Joachim Fenkesbba9b602007-05-09 13:48:25 +0200531static struct attribute *ehca_drv_attrs[] = {
532 &driver_attr_debug_level.attr,
533 NULL
534};
Heiko J Schickfab97222006-09-22 15:22:22 -0700535
Joachim Fenkesbba9b602007-05-09 13:48:25 +0200536static struct attribute_group ehca_drv_attr_grp = {
537 .attrs = ehca_drv_attrs
538};
Heiko J Schickfab97222006-09-22 15:22:22 -0700539
540#define EHCA_RESOURCE_ATTR(name) \
541static ssize_t ehca_show_##name(struct device *dev, \
542 struct device_attribute *attr, \
543 char *buf) \
544{ \
545 struct ehca_shca *shca; \
546 struct hipz_query_hca *rblock; \
547 int data; \
548 \
549 shca = dev->driver_data; \
550 \
Hoang-Nam Nguyenf2d91362007-01-09 18:04:14 +0100551 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); \
Heiko J Schickfab97222006-09-22 15:22:22 -0700552 if (!rblock) { \
553 dev_err(dev, "Can't allocate rblock memory."); \
554 return 0; \
555 } \
556 \
557 if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { \
558 dev_err(dev, "Can't query device properties"); \
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100559 ehca_free_fw_ctrlblock(rblock); \
Heiko J Schickfab97222006-09-22 15:22:22 -0700560 return 0; \
561 } \
562 \
563 data = rblock->name; \
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100564 ehca_free_fw_ctrlblock(rblock); \
Heiko J Schickfab97222006-09-22 15:22:22 -0700565 \
566 if ((strcmp(#name, "num_ports") == 0) && (ehca_nr_ports == 1)) \
567 return snprintf(buf, 256, "1\n"); \
568 else \
569 return snprintf(buf, 256, "%d\n", data); \
570 \
571} \
572static DEVICE_ATTR(name, S_IRUGO, ehca_show_##name, NULL);
573
574EHCA_RESOURCE_ATTR(num_ports);
575EHCA_RESOURCE_ATTR(hw_ver);
576EHCA_RESOURCE_ATTR(max_eq);
577EHCA_RESOURCE_ATTR(cur_eq);
578EHCA_RESOURCE_ATTR(max_cq);
579EHCA_RESOURCE_ATTR(cur_cq);
580EHCA_RESOURCE_ATTR(max_qp);
581EHCA_RESOURCE_ATTR(cur_qp);
582EHCA_RESOURCE_ATTR(max_mr);
583EHCA_RESOURCE_ATTR(cur_mr);
584EHCA_RESOURCE_ATTR(max_mw);
585EHCA_RESOURCE_ATTR(cur_mw);
586EHCA_RESOURCE_ATTR(max_pd);
587EHCA_RESOURCE_ATTR(max_ah);
588
589static ssize_t ehca_show_adapter_handle(struct device *dev,
590 struct device_attribute *attr,
591 char *buf)
592{
593 struct ehca_shca *shca = dev->driver_data;
594
595 return sprintf(buf, "%lx\n", shca->ipz_hca_handle.handle);
596
597}
598static DEVICE_ATTR(adapter_handle, S_IRUGO, ehca_show_adapter_handle, NULL);
599
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200600static ssize_t ehca_show_mr_largepage(struct device *dev,
601 struct device_attribute *attr,
602 char *buf)
603{
604 return sprintf(buf, "%d\n", ehca_mr_largepage);
605}
606static DEVICE_ATTR(mr_largepage, S_IRUGO, ehca_show_mr_largepage, NULL);
607
Joachim Fenkesbba9b602007-05-09 13:48:25 +0200608static struct attribute *ehca_dev_attrs[] = {
609 &dev_attr_adapter_handle.attr,
610 &dev_attr_num_ports.attr,
611 &dev_attr_hw_ver.attr,
612 &dev_attr_max_eq.attr,
613 &dev_attr_cur_eq.attr,
614 &dev_attr_max_cq.attr,
615 &dev_attr_cur_cq.attr,
616 &dev_attr_max_qp.attr,
617 &dev_attr_cur_qp.attr,
618 &dev_attr_max_mr.attr,
619 &dev_attr_cur_mr.attr,
620 &dev_attr_max_mw.attr,
621 &dev_attr_cur_mw.attr,
622 &dev_attr_max_pd.attr,
623 &dev_attr_max_ah.attr,
Hoang-Nam Nguyen5bb7d922007-07-20 16:01:51 +0200624 &dev_attr_mr_largepage.attr,
Joachim Fenkesbba9b602007-05-09 13:48:25 +0200625 NULL
626};
Heiko J Schickfab97222006-09-22 15:22:22 -0700627
Joachim Fenkesbba9b602007-05-09 13:48:25 +0200628static struct attribute_group ehca_dev_attr_grp = {
629 .attrs = ehca_dev_attrs
630};
Heiko J Schickfab97222006-09-22 15:22:22 -0700631
632static int __devinit ehca_probe(struct ibmebus_dev *dev,
633 const struct of_device_id *id)
634{
635 struct ehca_shca *shca;
Stephen Rothwella7edd0e2007-04-03 10:52:17 +1000636 const u64 *handle;
Heiko J Schickfab97222006-09-22 15:22:22 -0700637 struct ib_pd *ibpd;
638 int ret;
639
Stephen Rothwell40cd3a42007-05-01 13:54:02 +1000640 handle = of_get_property(dev->ofdev.node, "ibm,hca-handle", NULL);
Heiko J Schickfab97222006-09-22 15:22:22 -0700641 if (!handle) {
642 ehca_gen_err("Cannot get eHCA handle for adapter: %s.",
643 dev->ofdev.node->full_name);
644 return -ENODEV;
645 }
646
647 if (!(*handle)) {
648 ehca_gen_err("Wrong eHCA handle for adapter: %s.",
649 dev->ofdev.node->full_name);
650 return -ENODEV;
651 }
652
653 shca = (struct ehca_shca *)ib_alloc_device(sizeof(*shca));
654 if (!shca) {
655 ehca_gen_err("Cannot allocate shca memory.");
656 return -ENOMEM;
657 }
Joachim Fenkesc4ed7902007-04-24 17:44:31 +0200658 mutex_init(&shca->modify_mutex);
Heiko J Schickfab97222006-09-22 15:22:22 -0700659
660 shca->ibmebus_dev = dev;
661 shca->ipz_hca_handle.handle = *handle;
662 dev->ofdev.dev.driver_data = shca;
663
664 ret = ehca_sense_attributes(shca);
665 if (ret < 0) {
666 ehca_gen_err("Cannot sense eHCA attributes.");
667 goto probe1;
668 }
669
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700670 ret = ehca_init_device(shca);
Heiko J Schickfab97222006-09-22 15:22:22 -0700671 if (ret) {
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700672 ehca_gen_err("Cannot init ehca device struct");
Heiko J Schickfab97222006-09-22 15:22:22 -0700673 goto probe1;
674 }
675
676 /* create event queues */
677 ret = ehca_create_eq(shca, &shca->eq, EHCA_EQ, 2048);
678 if (ret) {
679 ehca_err(&shca->ib_device, "Cannot create EQ.");
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700680 goto probe1;
Heiko J Schickfab97222006-09-22 15:22:22 -0700681 }
682
683 ret = ehca_create_eq(shca, &shca->neq, EHCA_NEQ, 513);
684 if (ret) {
685 ehca_err(&shca->ib_device, "Cannot create NEQ.");
686 goto probe3;
687 }
688
689 /* create internal protection domain */
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200690 ibpd = ehca_alloc_pd(&shca->ib_device, (void *)(-1), NULL);
Heiko J Schickfab97222006-09-22 15:22:22 -0700691 if (IS_ERR(ibpd)) {
692 ehca_err(&shca->ib_device, "Cannot create internal PD.");
693 ret = PTR_ERR(ibpd);
694 goto probe4;
695 }
696
697 shca->pd = container_of(ibpd, struct ehca_pd, ib_pd);
698 shca->pd->ib_pd.device = &shca->ib_device;
699
700 /* create internal max MR */
701 ret = ehca_reg_internal_maxmr(shca, shca->pd, &shca->maxmr);
702
703 if (ret) {
704 ehca_err(&shca->ib_device, "Cannot create internal MR ret=%x",
705 ret);
706 goto probe5;
707 }
708
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700709 ret = ib_register_device(&shca->ib_device);
710 if (ret) {
711 ehca_err(&shca->ib_device,
712 "ib_register_device() failed ret=%x", ret);
713 goto probe6;
714 }
715
Heiko J Schickfab97222006-09-22 15:22:22 -0700716 /* create AQP1 for port 1 */
717 if (ehca_open_aqp1 == 1) {
718 shca->sport[0].port_state = IB_PORT_DOWN;
719 ret = ehca_create_aqp1(shca, 1);
720 if (ret) {
721 ehca_err(&shca->ib_device,
722 "Cannot create AQP1 for port 1.");
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700723 goto probe7;
Heiko J Schickfab97222006-09-22 15:22:22 -0700724 }
725 }
726
727 /* create AQP1 for port 2 */
728 if ((ehca_open_aqp1 == 1) && (shca->num_ports == 2)) {
729 shca->sport[1].port_state = IB_PORT_DOWN;
730 ret = ehca_create_aqp1(shca, 2);
731 if (ret) {
732 ehca_err(&shca->ib_device,
733 "Cannot create AQP1 for port 2.");
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700734 goto probe8;
Heiko J Schickfab97222006-09-22 15:22:22 -0700735 }
736 }
737
Joachim Fenkesbba9b602007-05-09 13:48:25 +0200738 ret = sysfs_create_group(&dev->ofdev.dev.kobj, &ehca_dev_attr_grp);
739 if (ret) /* only complain; we can live without attributes */
740 ehca_err(&shca->ib_device,
741 "Cannot create device attributes ret=%d", ret);
Heiko J Schickfab97222006-09-22 15:22:22 -0700742
743 spin_lock(&shca_list_lock);
744 list_add(&shca->shca_list, &shca_list);
745 spin_unlock(&shca_list_lock);
746
747 return 0;
748
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700749probe8:
Heiko J Schickfab97222006-09-22 15:22:22 -0700750 ret = ehca_destroy_aqp1(&shca->sport[0]);
751 if (ret)
752 ehca_err(&shca->ib_device,
753 "Cannot destroy AQP1 for port 1. ret=%x", ret);
754
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700755probe7:
756 ib_unregister_device(&shca->ib_device);
757
Heiko J Schickfab97222006-09-22 15:22:22 -0700758probe6:
759 ret = ehca_dereg_internal_maxmr(shca);
760 if (ret)
761 ehca_err(&shca->ib_device,
762 "Cannot destroy internal MR. ret=%x", ret);
763
764probe5:
765 ret = ehca_dealloc_pd(&shca->pd->ib_pd);
766 if (ret)
767 ehca_err(&shca->ib_device,
768 "Cannot destroy internal PD. ret=%x", ret);
769
770probe4:
771 ret = ehca_destroy_eq(shca, &shca->neq);
772 if (ret)
773 ehca_err(&shca->ib_device,
774 "Cannot destroy NEQ. ret=%x", ret);
775
776probe3:
777 ret = ehca_destroy_eq(shca, &shca->eq);
778 if (ret)
779 ehca_err(&shca->ib_device,
780 "Cannot destroy EQ. ret=%x", ret);
781
Heiko J Schickfab97222006-09-22 15:22:22 -0700782probe1:
783 ib_dealloc_device(&shca->ib_device);
784
785 return -EINVAL;
786}
787
788static int __devexit ehca_remove(struct ibmebus_dev *dev)
789{
790 struct ehca_shca *shca = dev->ofdev.dev.driver_data;
791 int ret;
792
Joachim Fenkesbba9b602007-05-09 13:48:25 +0200793 sysfs_remove_group(&dev->ofdev.dev.kobj, &ehca_dev_attr_grp);
Heiko J Schickfab97222006-09-22 15:22:22 -0700794
795 if (ehca_open_aqp1 == 1) {
796 int i;
797 for (i = 0; i < shca->num_ports; i++) {
798 ret = ehca_destroy_aqp1(&shca->sport[i]);
799 if (ret)
800 ehca_err(&shca->ib_device,
801 "Cannot destroy AQP1 for port %x "
802 "ret=%x", ret, i);
803 }
804 }
805
806 ib_unregister_device(&shca->ib_device);
807
808 ret = ehca_dereg_internal_maxmr(shca);
809 if (ret)
810 ehca_err(&shca->ib_device,
811 "Cannot destroy internal MR. ret=%x", ret);
812
813 ret = ehca_dealloc_pd(&shca->pd->ib_pd);
814 if (ret)
815 ehca_err(&shca->ib_device,
816 "Cannot destroy internal PD. ret=%x", ret);
817
818 ret = ehca_destroy_eq(shca, &shca->eq);
819 if (ret)
820 ehca_err(&shca->ib_device, "Cannot destroy EQ. ret=%x", ret);
821
822 ret = ehca_destroy_eq(shca, &shca->neq);
823 if (ret)
824 ehca_err(&shca->ib_device, "Canot destroy NEQ. ret=%x", ret);
825
826 ib_dealloc_device(&shca->ib_device);
827
828 spin_lock(&shca_list_lock);
829 list_del(&shca->shca_list);
830 spin_unlock(&shca_list_lock);
831
832 return ret;
833}
834
835static struct of_device_id ehca_device_table[] =
836{
837 {
838 .name = "lhca",
839 .compatible = "IBM,lhca",
840 },
841 {},
842};
843
844static struct ibmebus_driver ehca_driver = {
845 .name = "ehca",
846 .id_table = ehca_device_table,
847 .probe = ehca_probe,
848 .remove = ehca_remove,
849};
850
851void ehca_poll_eqs(unsigned long data)
852{
853 struct ehca_shca *shca;
854
855 spin_lock(&shca_list_lock);
856 list_for_each_entry(shca, &shca_list, shca_list) {
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +0100857 if (shca->eq.is_initialized) {
858 /* call deadman proc only if eq ptr does not change */
859 struct ehca_eq *eq = &shca->eq;
860 int max = 3;
861 volatile u64 q_ofs, q_ofs2;
862 u64 flags;
863 spin_lock_irqsave(&eq->spinlock, flags);
864 q_ofs = eq->ipz_queue.current_q_offset;
865 spin_unlock_irqrestore(&eq->spinlock, flags);
866 do {
867 spin_lock_irqsave(&eq->spinlock, flags);
868 q_ofs2 = eq->ipz_queue.current_q_offset;
869 spin_unlock_irqrestore(&eq->spinlock, flags);
870 max--;
871 } while (q_ofs == q_ofs2 && max > 0);
872 if (q_ofs == q_ofs2)
873 ehca_process_eq(shca, 0);
874 }
Heiko J Schickfab97222006-09-22 15:22:22 -0700875 }
876 mod_timer(&poll_eqs_timer, jiffies + HZ);
877 spin_unlock(&shca_list_lock);
878}
879
880int __init ehca_module_init(void)
881{
882 int ret;
883
884 printk(KERN_INFO "eHCA Infiniband Device Driver "
Joachim Fenkes4e430dc2007-05-09 13:48:31 +0200885 "(Rel.: SVNEHCA_0023)\n");
Heiko J Schickfab97222006-09-22 15:22:22 -0700886
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200887 ret = ehca_create_comp_pool();
888 if (ret) {
Heiko J Schickfab97222006-09-22 15:22:22 -0700889 ehca_gen_err("Cannot create comp pool.");
890 return ret;
891 }
892
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200893 ret = ehca_create_slab_caches();
894 if (ret) {
Heiko J Schickfab97222006-09-22 15:22:22 -0700895 ehca_gen_err("Cannot create SLAB caches");
896 ret = -ENOMEM;
897 goto module_init1;
898 }
899
Hoang-Nam Nguyen2b943972007-07-12 17:53:47 +0200900 ret = ibmebus_register_driver(&ehca_driver);
901 if (ret) {
Heiko J Schickfab97222006-09-22 15:22:22 -0700902 ehca_gen_err("Cannot register eHCA device driver");
903 ret = -EINVAL;
904 goto module_init2;
905 }
906
Joachim Fenkesbba9b602007-05-09 13:48:25 +0200907 ret = sysfs_create_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
908 if (ret) /* only complain; we can live without attributes */
909 ehca_gen_err("Cannot create driver attributes ret=%d", ret);
Heiko J Schickfab97222006-09-22 15:22:22 -0700910
911 if (ehca_poll_all_eqs != 1) {
912 ehca_gen_err("WARNING!!!");
913 ehca_gen_err("It is possible to lose interrupts.");
914 } else {
915 init_timer(&poll_eqs_timer);
916 poll_eqs_timer.function = ehca_poll_eqs;
917 poll_eqs_timer.expires = jiffies + HZ;
918 add_timer(&poll_eqs_timer);
919 }
920
921 return 0;
922
923module_init2:
924 ehca_destroy_slab_caches();
925
926module_init1:
927 ehca_destroy_comp_pool();
928 return ret;
929};
930
931void __exit ehca_module_exit(void)
932{
933 if (ehca_poll_all_eqs == 1)
934 del_timer_sync(&poll_eqs_timer);
935
Joachim Fenkesbba9b602007-05-09 13:48:25 +0200936 sysfs_remove_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
Heiko J Schickfab97222006-09-22 15:22:22 -0700937 ibmebus_unregister_driver(&ehca_driver);
938
939 ehca_destroy_slab_caches();
940
941 ehca_destroy_comp_pool();
942
943 idr_destroy(&ehca_cq_idr);
944 idr_destroy(&ehca_qp_idr);
945};
946
947module_init(ehca_module_init);
948module_exit(ehca_module_exit);