blob: c1835121a82223612195fce09369ba0b58173e4a [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");
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +010055MODULE_VERSION("SVNEHCA_0021");
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;
Hoang-Nam Nguyen4fd30062007-02-15 17:08:33 +010065int ehca_scaling_code = 1;
Heiko J Schickfab97222006-09-22 15:22:22 -070066
67module_param_named(open_aqp1, ehca_open_aqp1, int, 0);
68module_param_named(debug_level, ehca_debug_level, int, 0);
69module_param_named(hw_level, ehca_hw_level, int, 0);
70module_param_named(nr_ports, ehca_nr_ports, int, 0);
71module_param_named(use_hp_mr, ehca_use_hp_mr, int, 0);
72module_param_named(port_act_time, ehca_port_act_time, int, 0);
73module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, 0);
74module_param_named(static_rate, ehca_static_rate, int, 0);
Hoang-Nam Nguyen4fd30062007-02-15 17:08:33 +010075module_param_named(scaling_code, ehca_scaling_code, int, 0);
Heiko J Schickfab97222006-09-22 15:22:22 -070076
77MODULE_PARM_DESC(open_aqp1,
78 "AQP1 on startup (0: no (default), 1: yes)");
79MODULE_PARM_DESC(debug_level,
80 "debug level"
81 " (0: no debug traces (default), 1: with debug traces)");
82MODULE_PARM_DESC(hw_level,
83 "hardware level"
84 " (0: autosensing (default), 1: v. 0.20, 2: v. 0.21)");
85MODULE_PARM_DESC(nr_ports,
86 "number of connected ports (default: 2)");
87MODULE_PARM_DESC(use_hp_mr,
88 "high performance MRs (0: no (default), 1: yes)");
89MODULE_PARM_DESC(port_act_time,
90 "time to wait for port activation (default: 30 sec)");
91MODULE_PARM_DESC(poll_all_eqs,
92 "polls all event queues periodically"
93 " (0: no, 1: yes (default))");
94MODULE_PARM_DESC(static_rate,
95 "set permanent static rate (default: disabled)");
Hoang-Nam Nguyen4fd30062007-02-15 17:08:33 +010096MODULE_PARM_DESC(scaling_code,
97 "set scaling code (0: disabled, 1: enabled/default)");
Heiko J Schickfab97222006-09-22 15:22:22 -070098
99spinlock_t ehca_qp_idr_lock;
100spinlock_t ehca_cq_idr_lock;
101DEFINE_IDR(ehca_qp_idr);
102DEFINE_IDR(ehca_cq_idr);
103
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100104
Heiko J Schickfab97222006-09-22 15:22:22 -0700105static struct list_head shca_list; /* list of all registered ehcas */
106static spinlock_t shca_list_lock;
107
108static struct timer_list poll_eqs_timer;
109
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100110#ifdef CONFIG_PPC_64K_PAGES
111static struct kmem_cache *ctblk_cache = NULL;
112
Hoang-Nam Nguyenf2d91362007-01-09 18:04:14 +0100113void *ehca_alloc_fw_ctrlblock(gfp_t flags)
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100114{
Hoang-Nam Nguyenf2d91362007-01-09 18:04:14 +0100115 void *ret = kmem_cache_zalloc(ctblk_cache, flags);
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100116 if (!ret)
117 ehca_gen_err("Out of memory for ctblk");
118 return ret;
119}
120
121void ehca_free_fw_ctrlblock(void *ptr)
122{
123 if (ptr)
124 kmem_cache_free(ctblk_cache, ptr);
125
126}
127#endif
128
Heiko J Schickfab97222006-09-22 15:22:22 -0700129static int ehca_create_slab_caches(void)
130{
131 int ret;
132
133 ret = ehca_init_pd_cache();
134 if (ret) {
135 ehca_gen_err("Cannot create PD SLAB cache.");
136 return ret;
137 }
138
139 ret = ehca_init_cq_cache();
140 if (ret) {
141 ehca_gen_err("Cannot create CQ SLAB cache.");
142 goto create_slab_caches2;
143 }
144
145 ret = ehca_init_qp_cache();
146 if (ret) {
147 ehca_gen_err("Cannot create QP SLAB cache.");
148 goto create_slab_caches3;
149 }
150
151 ret = ehca_init_av_cache();
152 if (ret) {
153 ehca_gen_err("Cannot create AV SLAB cache.");
154 goto create_slab_caches4;
155 }
156
157 ret = ehca_init_mrmw_cache();
158 if (ret) {
159 ehca_gen_err("Cannot create MR&MW SLAB cache.");
160 goto create_slab_caches5;
161 }
162
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100163#ifdef CONFIG_PPC_64K_PAGES
164 ctblk_cache = kmem_cache_create("ehca_cache_ctblk",
165 EHCA_PAGESIZE, H_CB_ALIGNMENT,
166 SLAB_HWCACHE_ALIGN,
167 NULL, NULL);
168 if (!ctblk_cache) {
169 ehca_gen_err("Cannot create ctblk SLAB cache.");
170 ehca_cleanup_mrmw_cache();
171 goto create_slab_caches5;
172 }
173#endif
Heiko J Schickfab97222006-09-22 15:22:22 -0700174 return 0;
175
176create_slab_caches5:
177 ehca_cleanup_av_cache();
178
179create_slab_caches4:
180 ehca_cleanup_qp_cache();
181
182create_slab_caches3:
183 ehca_cleanup_cq_cache();
184
185create_slab_caches2:
186 ehca_cleanup_pd_cache();
187
188 return ret;
189}
190
191static void ehca_destroy_slab_caches(void)
192{
193 ehca_cleanup_mrmw_cache();
194 ehca_cleanup_av_cache();
195 ehca_cleanup_qp_cache();
196 ehca_cleanup_cq_cache();
197 ehca_cleanup_pd_cache();
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100198#ifdef CONFIG_PPC_64K_PAGES
199 if (ctblk_cache)
200 kmem_cache_destroy(ctblk_cache);
201#endif
Heiko J Schickfab97222006-09-22 15:22:22 -0700202}
203
204#define EHCA_HCAAVER EHCA_BMASK_IBM(32,39)
205#define EHCA_REVID EHCA_BMASK_IBM(40,63)
206
207int ehca_sense_attributes(struct ehca_shca *shca)
208{
209 int ret = 0;
210 u64 h_ret;
211 struct hipz_query_hca *rblock;
212
Hoang-Nam Nguyenf2d91362007-01-09 18:04:14 +0100213 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
Heiko J Schickfab97222006-09-22 15:22:22 -0700214 if (!rblock) {
215 ehca_gen_err("Cannot allocate rblock memory.");
216 return -ENOMEM;
217 }
218
219 h_ret = hipz_h_query_hca(shca->ipz_hca_handle, rblock);
220 if (h_ret != H_SUCCESS) {
221 ehca_gen_err("Cannot query device properties. h_ret=%lx",
222 h_ret);
223 ret = -EPERM;
224 goto num_ports1;
225 }
226
227 if (ehca_nr_ports == 1)
228 shca->num_ports = 1;
229 else
230 shca->num_ports = (u8)rblock->num_ports;
231
232 ehca_gen_dbg(" ... found %x ports", rblock->num_ports);
233
234 if (ehca_hw_level == 0) {
235 u32 hcaaver;
236 u32 revid;
237
238 hcaaver = EHCA_BMASK_GET(EHCA_HCAAVER, rblock->hw_ver);
239 revid = EHCA_BMASK_GET(EHCA_REVID, rblock->hw_ver);
240
241 ehca_gen_dbg(" ... hardware version=%x:%x", hcaaver, revid);
242
243 if ((hcaaver == 1) && (revid == 0))
244 shca->hw_level = 0;
245 else if ((hcaaver == 1) && (revid == 1))
246 shca->hw_level = 1;
247 else if ((hcaaver == 1) && (revid == 2))
248 shca->hw_level = 2;
249 }
250 ehca_gen_dbg(" ... hardware level=%x", shca->hw_level);
251
252 shca->sport[0].rate = IB_RATE_30_GBPS;
253 shca->sport[1].rate = IB_RATE_30_GBPS;
254
255num_ports1:
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100256 ehca_free_fw_ctrlblock(rblock);
Heiko J Schickfab97222006-09-22 15:22:22 -0700257 return ret;
258}
259
260static int init_node_guid(struct ehca_shca *shca)
261{
262 int ret = 0;
263 struct hipz_query_hca *rblock;
264
Hoang-Nam Nguyenf2d91362007-01-09 18:04:14 +0100265 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
Heiko J Schickfab97222006-09-22 15:22:22 -0700266 if (!rblock) {
267 ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
268 return -ENOMEM;
269 }
270
271 if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) {
272 ehca_err(&shca->ib_device, "Can't query device properties");
273 ret = -EINVAL;
274 goto init_node_guid1;
275 }
276
277 memcpy(&shca->ib_device.node_guid, &rblock->node_guid, sizeof(u64));
278
279init_node_guid1:
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100280 ehca_free_fw_ctrlblock(rblock);
Heiko J Schickfab97222006-09-22 15:22:22 -0700281 return ret;
282}
283
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700284int ehca_init_device(struct ehca_shca *shca)
Heiko J Schickfab97222006-09-22 15:22:22 -0700285{
286 int ret;
287
288 ret = init_node_guid(shca);
289 if (ret)
290 return ret;
291
292 strlcpy(shca->ib_device.name, "ehca%d", IB_DEVICE_NAME_MAX);
293 shca->ib_device.owner = THIS_MODULE;
294
Hoang-Nam Nguyen4c34bdf2007-01-24 00:13:35 +0100295 shca->ib_device.uverbs_abi_ver = 6;
Heiko J Schickfab97222006-09-22 15:22:22 -0700296 shca->ib_device.uverbs_cmd_mask =
297 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
298 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
299 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
300 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
301 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
302 (1ull << IB_USER_VERBS_CMD_REG_MR) |
303 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
304 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
305 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
306 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
307 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
308 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
309 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
310 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
311 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
312 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST);
313
Tom Tucker07ebafb2006-08-03 16:02:42 -0500314 shca->ib_device.node_type = RDMA_NODE_IB_CA;
Heiko J Schickfab97222006-09-22 15:22:22 -0700315 shca->ib_device.phys_port_cnt = shca->num_ports;
316 shca->ib_device.dma_device = &shca->ibmebus_dev->ofdev.dev;
317 shca->ib_device.query_device = ehca_query_device;
318 shca->ib_device.query_port = ehca_query_port;
319 shca->ib_device.query_gid = ehca_query_gid;
320 shca->ib_device.query_pkey = ehca_query_pkey;
321 /* shca->in_device.modify_device = ehca_modify_device */
322 shca->ib_device.modify_port = ehca_modify_port;
323 shca->ib_device.alloc_ucontext = ehca_alloc_ucontext;
324 shca->ib_device.dealloc_ucontext = ehca_dealloc_ucontext;
325 shca->ib_device.alloc_pd = ehca_alloc_pd;
326 shca->ib_device.dealloc_pd = ehca_dealloc_pd;
327 shca->ib_device.create_ah = ehca_create_ah;
328 /* shca->ib_device.modify_ah = ehca_modify_ah; */
329 shca->ib_device.query_ah = ehca_query_ah;
330 shca->ib_device.destroy_ah = ehca_destroy_ah;
331 shca->ib_device.create_qp = ehca_create_qp;
332 shca->ib_device.modify_qp = ehca_modify_qp;
333 shca->ib_device.query_qp = ehca_query_qp;
334 shca->ib_device.destroy_qp = ehca_destroy_qp;
335 shca->ib_device.post_send = ehca_post_send;
336 shca->ib_device.post_recv = ehca_post_recv;
337 shca->ib_device.create_cq = ehca_create_cq;
338 shca->ib_device.destroy_cq = ehca_destroy_cq;
339 shca->ib_device.resize_cq = ehca_resize_cq;
340 shca->ib_device.poll_cq = ehca_poll_cq;
341 /* shca->ib_device.peek_cq = ehca_peek_cq; */
342 shca->ib_device.req_notify_cq = ehca_req_notify_cq;
343 /* shca->ib_device.req_ncomp_notif = ehca_req_ncomp_notif; */
344 shca->ib_device.get_dma_mr = ehca_get_dma_mr;
345 shca->ib_device.reg_phys_mr = ehca_reg_phys_mr;
346 shca->ib_device.reg_user_mr = ehca_reg_user_mr;
347 shca->ib_device.query_mr = ehca_query_mr;
348 shca->ib_device.dereg_mr = ehca_dereg_mr;
349 shca->ib_device.rereg_phys_mr = ehca_rereg_phys_mr;
350 shca->ib_device.alloc_mw = ehca_alloc_mw;
351 shca->ib_device.bind_mw = ehca_bind_mw;
352 shca->ib_device.dealloc_mw = ehca_dealloc_mw;
353 shca->ib_device.alloc_fmr = ehca_alloc_fmr;
354 shca->ib_device.map_phys_fmr = ehca_map_phys_fmr;
355 shca->ib_device.unmap_fmr = ehca_unmap_fmr;
356 shca->ib_device.dealloc_fmr = ehca_dealloc_fmr;
357 shca->ib_device.attach_mcast = ehca_attach_mcast;
358 shca->ib_device.detach_mcast = ehca_detach_mcast;
359 /* shca->ib_device.process_mad = ehca_process_mad; */
360 shca->ib_device.mmap = ehca_mmap;
361
Heiko J Schickfab97222006-09-22 15:22:22 -0700362 return ret;
363}
364
365static int ehca_create_aqp1(struct ehca_shca *shca, u32 port)
366{
367 struct ehca_sport *sport = &shca->sport[port - 1];
368 struct ib_cq *ibcq;
369 struct ib_qp *ibqp;
370 struct ib_qp_init_attr qp_init_attr;
371 int ret;
372
373 if (sport->ibcq_aqp1) {
374 ehca_err(&shca->ib_device, "AQP1 CQ is already created.");
375 return -EPERM;
376 }
377
378 ibcq = ib_create_cq(&shca->ib_device, NULL, NULL, (void*)(-1), 10);
379 if (IS_ERR(ibcq)) {
380 ehca_err(&shca->ib_device, "Cannot create AQP1 CQ.");
381 return PTR_ERR(ibcq);
382 }
383 sport->ibcq_aqp1 = ibcq;
384
385 if (sport->ibqp_aqp1) {
386 ehca_err(&shca->ib_device, "AQP1 QP is already created.");
387 ret = -EPERM;
388 goto create_aqp1;
389 }
390
391 memset(&qp_init_attr, 0, sizeof(struct ib_qp_init_attr));
392 qp_init_attr.send_cq = ibcq;
393 qp_init_attr.recv_cq = ibcq;
394 qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR;
395 qp_init_attr.cap.max_send_wr = 100;
396 qp_init_attr.cap.max_recv_wr = 100;
397 qp_init_attr.cap.max_send_sge = 2;
398 qp_init_attr.cap.max_recv_sge = 1;
399 qp_init_attr.qp_type = IB_QPT_GSI;
400 qp_init_attr.port_num = port;
401 qp_init_attr.qp_context = NULL;
402 qp_init_attr.event_handler = NULL;
403 qp_init_attr.srq = NULL;
404
405 ibqp = ib_create_qp(&shca->pd->ib_pd, &qp_init_attr);
406 if (IS_ERR(ibqp)) {
407 ehca_err(&shca->ib_device, "Cannot create AQP1 QP.");
408 ret = PTR_ERR(ibqp);
409 goto create_aqp1;
410 }
411 sport->ibqp_aqp1 = ibqp;
412
413 return 0;
414
415create_aqp1:
416 ib_destroy_cq(sport->ibcq_aqp1);
417 return ret;
418}
419
420static int ehca_destroy_aqp1(struct ehca_sport *sport)
421{
422 int ret;
423
424 ret = ib_destroy_qp(sport->ibqp_aqp1);
425 if (ret) {
426 ehca_gen_err("Cannot destroy AQP1 QP. ret=%x", ret);
427 return ret;
428 }
429
430 ret = ib_destroy_cq(sport->ibcq_aqp1);
431 if (ret)
432 ehca_gen_err("Cannot destroy AQP1 CQ. ret=%x", ret);
433
434 return ret;
435}
436
437static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf)
438{
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +0100439 return snprintf(buf, PAGE_SIZE, "%d\n",
440 ehca_debug_level);
Heiko J Schickfab97222006-09-22 15:22:22 -0700441}
442
443static ssize_t ehca_store_debug_level(struct device_driver *ddp,
444 const char *buf, size_t count)
445{
446 int value = (*buf) - '0';
447 if (value >= 0 && value <= 9)
448 ehca_debug_level = value;
449 return 1;
450}
451
452DRIVER_ATTR(debug_level, S_IRUSR | S_IWUSR,
453 ehca_show_debug_level, ehca_store_debug_level);
454
455void ehca_create_driver_sysfs(struct ibmebus_driver *drv)
456{
457 driver_create_file(&drv->driver, &driver_attr_debug_level);
458}
459
460void ehca_remove_driver_sysfs(struct ibmebus_driver *drv)
461{
462 driver_remove_file(&drv->driver, &driver_attr_debug_level);
463}
464
465#define EHCA_RESOURCE_ATTR(name) \
466static ssize_t ehca_show_##name(struct device *dev, \
467 struct device_attribute *attr, \
468 char *buf) \
469{ \
470 struct ehca_shca *shca; \
471 struct hipz_query_hca *rblock; \
472 int data; \
473 \
474 shca = dev->driver_data; \
475 \
Hoang-Nam Nguyenf2d91362007-01-09 18:04:14 +0100476 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); \
Heiko J Schickfab97222006-09-22 15:22:22 -0700477 if (!rblock) { \
478 dev_err(dev, "Can't allocate rblock memory."); \
479 return 0; \
480 } \
481 \
482 if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { \
483 dev_err(dev, "Can't query device properties"); \
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100484 ehca_free_fw_ctrlblock(rblock); \
Heiko J Schickfab97222006-09-22 15:22:22 -0700485 return 0; \
486 } \
487 \
488 data = rblock->name; \
Hoang-Nam Nguyen7e28db52006-11-07 00:56:39 +0100489 ehca_free_fw_ctrlblock(rblock); \
Heiko J Schickfab97222006-09-22 15:22:22 -0700490 \
491 if ((strcmp(#name, "num_ports") == 0) && (ehca_nr_ports == 1)) \
492 return snprintf(buf, 256, "1\n"); \
493 else \
494 return snprintf(buf, 256, "%d\n", data); \
495 \
496} \
497static DEVICE_ATTR(name, S_IRUGO, ehca_show_##name, NULL);
498
499EHCA_RESOURCE_ATTR(num_ports);
500EHCA_RESOURCE_ATTR(hw_ver);
501EHCA_RESOURCE_ATTR(max_eq);
502EHCA_RESOURCE_ATTR(cur_eq);
503EHCA_RESOURCE_ATTR(max_cq);
504EHCA_RESOURCE_ATTR(cur_cq);
505EHCA_RESOURCE_ATTR(max_qp);
506EHCA_RESOURCE_ATTR(cur_qp);
507EHCA_RESOURCE_ATTR(max_mr);
508EHCA_RESOURCE_ATTR(cur_mr);
509EHCA_RESOURCE_ATTR(max_mw);
510EHCA_RESOURCE_ATTR(cur_mw);
511EHCA_RESOURCE_ATTR(max_pd);
512EHCA_RESOURCE_ATTR(max_ah);
513
514static ssize_t ehca_show_adapter_handle(struct device *dev,
515 struct device_attribute *attr,
516 char *buf)
517{
518 struct ehca_shca *shca = dev->driver_data;
519
520 return sprintf(buf, "%lx\n", shca->ipz_hca_handle.handle);
521
522}
523static DEVICE_ATTR(adapter_handle, S_IRUGO, ehca_show_adapter_handle, NULL);
524
525
526void ehca_create_device_sysfs(struct ibmebus_dev *dev)
527{
528 device_create_file(&dev->ofdev.dev, &dev_attr_adapter_handle);
529 device_create_file(&dev->ofdev.dev, &dev_attr_num_ports);
530 device_create_file(&dev->ofdev.dev, &dev_attr_hw_ver);
531 device_create_file(&dev->ofdev.dev, &dev_attr_max_eq);
532 device_create_file(&dev->ofdev.dev, &dev_attr_cur_eq);
533 device_create_file(&dev->ofdev.dev, &dev_attr_max_cq);
534 device_create_file(&dev->ofdev.dev, &dev_attr_cur_cq);
535 device_create_file(&dev->ofdev.dev, &dev_attr_max_qp);
536 device_create_file(&dev->ofdev.dev, &dev_attr_cur_qp);
537 device_create_file(&dev->ofdev.dev, &dev_attr_max_mr);
538 device_create_file(&dev->ofdev.dev, &dev_attr_cur_mr);
539 device_create_file(&dev->ofdev.dev, &dev_attr_max_mw);
540 device_create_file(&dev->ofdev.dev, &dev_attr_cur_mw);
541 device_create_file(&dev->ofdev.dev, &dev_attr_max_pd);
542 device_create_file(&dev->ofdev.dev, &dev_attr_max_ah);
543}
544
545void ehca_remove_device_sysfs(struct ibmebus_dev *dev)
546{
547 device_remove_file(&dev->ofdev.dev, &dev_attr_adapter_handle);
548 device_remove_file(&dev->ofdev.dev, &dev_attr_num_ports);
549 device_remove_file(&dev->ofdev.dev, &dev_attr_hw_ver);
550 device_remove_file(&dev->ofdev.dev, &dev_attr_max_eq);
551 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_eq);
552 device_remove_file(&dev->ofdev.dev, &dev_attr_max_cq);
553 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_cq);
554 device_remove_file(&dev->ofdev.dev, &dev_attr_max_qp);
555 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_qp);
556 device_remove_file(&dev->ofdev.dev, &dev_attr_max_mr);
557 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_mr);
558 device_remove_file(&dev->ofdev.dev, &dev_attr_max_mw);
559 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_mw);
560 device_remove_file(&dev->ofdev.dev, &dev_attr_max_pd);
561 device_remove_file(&dev->ofdev.dev, &dev_attr_max_ah);
562}
563
564static int __devinit ehca_probe(struct ibmebus_dev *dev,
565 const struct of_device_id *id)
566{
567 struct ehca_shca *shca;
568 u64 *handle;
569 struct ib_pd *ibpd;
570 int ret;
571
572 handle = (u64 *)get_property(dev->ofdev.node, "ibm,hca-handle", NULL);
573 if (!handle) {
574 ehca_gen_err("Cannot get eHCA handle for adapter: %s.",
575 dev->ofdev.node->full_name);
576 return -ENODEV;
577 }
578
579 if (!(*handle)) {
580 ehca_gen_err("Wrong eHCA handle for adapter: %s.",
581 dev->ofdev.node->full_name);
582 return -ENODEV;
583 }
584
585 shca = (struct ehca_shca *)ib_alloc_device(sizeof(*shca));
586 if (!shca) {
587 ehca_gen_err("Cannot allocate shca memory.");
588 return -ENOMEM;
589 }
590
591 shca->ibmebus_dev = dev;
592 shca->ipz_hca_handle.handle = *handle;
593 dev->ofdev.dev.driver_data = shca;
594
595 ret = ehca_sense_attributes(shca);
596 if (ret < 0) {
597 ehca_gen_err("Cannot sense eHCA attributes.");
598 goto probe1;
599 }
600
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700601 ret = ehca_init_device(shca);
Heiko J Schickfab97222006-09-22 15:22:22 -0700602 if (ret) {
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700603 ehca_gen_err("Cannot init ehca device struct");
Heiko J Schickfab97222006-09-22 15:22:22 -0700604 goto probe1;
605 }
606
607 /* create event queues */
608 ret = ehca_create_eq(shca, &shca->eq, EHCA_EQ, 2048);
609 if (ret) {
610 ehca_err(&shca->ib_device, "Cannot create EQ.");
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700611 goto probe1;
Heiko J Schickfab97222006-09-22 15:22:22 -0700612 }
613
614 ret = ehca_create_eq(shca, &shca->neq, EHCA_NEQ, 513);
615 if (ret) {
616 ehca_err(&shca->ib_device, "Cannot create NEQ.");
617 goto probe3;
618 }
619
620 /* create internal protection domain */
621 ibpd = ehca_alloc_pd(&shca->ib_device, (void*)(-1), NULL);
622 if (IS_ERR(ibpd)) {
623 ehca_err(&shca->ib_device, "Cannot create internal PD.");
624 ret = PTR_ERR(ibpd);
625 goto probe4;
626 }
627
628 shca->pd = container_of(ibpd, struct ehca_pd, ib_pd);
629 shca->pd->ib_pd.device = &shca->ib_device;
630
631 /* create internal max MR */
632 ret = ehca_reg_internal_maxmr(shca, shca->pd, &shca->maxmr);
633
634 if (ret) {
635 ehca_err(&shca->ib_device, "Cannot create internal MR ret=%x",
636 ret);
637 goto probe5;
638 }
639
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700640 ret = ib_register_device(&shca->ib_device);
641 if (ret) {
642 ehca_err(&shca->ib_device,
643 "ib_register_device() failed ret=%x", ret);
644 goto probe6;
645 }
646
Heiko J Schickfab97222006-09-22 15:22:22 -0700647 /* create AQP1 for port 1 */
648 if (ehca_open_aqp1 == 1) {
649 shca->sport[0].port_state = IB_PORT_DOWN;
650 ret = ehca_create_aqp1(shca, 1);
651 if (ret) {
652 ehca_err(&shca->ib_device,
653 "Cannot create AQP1 for port 1.");
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700654 goto probe7;
Heiko J Schickfab97222006-09-22 15:22:22 -0700655 }
656 }
657
658 /* create AQP1 for port 2 */
659 if ((ehca_open_aqp1 == 1) && (shca->num_ports == 2)) {
660 shca->sport[1].port_state = IB_PORT_DOWN;
661 ret = ehca_create_aqp1(shca, 2);
662 if (ret) {
663 ehca_err(&shca->ib_device,
664 "Cannot create AQP1 for port 2.");
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700665 goto probe8;
Heiko J Schickfab97222006-09-22 15:22:22 -0700666 }
667 }
668
669 ehca_create_device_sysfs(dev);
670
671 spin_lock(&shca_list_lock);
672 list_add(&shca->shca_list, &shca_list);
673 spin_unlock(&shca_list_lock);
674
675 return 0;
676
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700677probe8:
Heiko J Schickfab97222006-09-22 15:22:22 -0700678 ret = ehca_destroy_aqp1(&shca->sport[0]);
679 if (ret)
680 ehca_err(&shca->ib_device,
681 "Cannot destroy AQP1 for port 1. ret=%x", ret);
682
Hoang-Nam Nguyen0f248d92006-10-02 14:52:17 -0700683probe7:
684 ib_unregister_device(&shca->ib_device);
685
Heiko J Schickfab97222006-09-22 15:22:22 -0700686probe6:
687 ret = ehca_dereg_internal_maxmr(shca);
688 if (ret)
689 ehca_err(&shca->ib_device,
690 "Cannot destroy internal MR. ret=%x", ret);
691
692probe5:
693 ret = ehca_dealloc_pd(&shca->pd->ib_pd);
694 if (ret)
695 ehca_err(&shca->ib_device,
696 "Cannot destroy internal PD. ret=%x", ret);
697
698probe4:
699 ret = ehca_destroy_eq(shca, &shca->neq);
700 if (ret)
701 ehca_err(&shca->ib_device,
702 "Cannot destroy NEQ. ret=%x", ret);
703
704probe3:
705 ret = ehca_destroy_eq(shca, &shca->eq);
706 if (ret)
707 ehca_err(&shca->ib_device,
708 "Cannot destroy EQ. ret=%x", ret);
709
Heiko J Schickfab97222006-09-22 15:22:22 -0700710probe1:
711 ib_dealloc_device(&shca->ib_device);
712
713 return -EINVAL;
714}
715
716static int __devexit ehca_remove(struct ibmebus_dev *dev)
717{
718 struct ehca_shca *shca = dev->ofdev.dev.driver_data;
719 int ret;
720
721 ehca_remove_device_sysfs(dev);
722
723 if (ehca_open_aqp1 == 1) {
724 int i;
725 for (i = 0; i < shca->num_ports; i++) {
726 ret = ehca_destroy_aqp1(&shca->sport[i]);
727 if (ret)
728 ehca_err(&shca->ib_device,
729 "Cannot destroy AQP1 for port %x "
730 "ret=%x", ret, i);
731 }
732 }
733
734 ib_unregister_device(&shca->ib_device);
735
736 ret = ehca_dereg_internal_maxmr(shca);
737 if (ret)
738 ehca_err(&shca->ib_device,
739 "Cannot destroy internal MR. ret=%x", ret);
740
741 ret = ehca_dealloc_pd(&shca->pd->ib_pd);
742 if (ret)
743 ehca_err(&shca->ib_device,
744 "Cannot destroy internal PD. ret=%x", ret);
745
746 ret = ehca_destroy_eq(shca, &shca->eq);
747 if (ret)
748 ehca_err(&shca->ib_device, "Cannot destroy EQ. ret=%x", ret);
749
750 ret = ehca_destroy_eq(shca, &shca->neq);
751 if (ret)
752 ehca_err(&shca->ib_device, "Canot destroy NEQ. ret=%x", ret);
753
754 ib_dealloc_device(&shca->ib_device);
755
756 spin_lock(&shca_list_lock);
757 list_del(&shca->shca_list);
758 spin_unlock(&shca_list_lock);
759
760 return ret;
761}
762
763static struct of_device_id ehca_device_table[] =
764{
765 {
766 .name = "lhca",
767 .compatible = "IBM,lhca",
768 },
769 {},
770};
771
772static struct ibmebus_driver ehca_driver = {
773 .name = "ehca",
774 .id_table = ehca_device_table,
775 .probe = ehca_probe,
776 .remove = ehca_remove,
777};
778
779void ehca_poll_eqs(unsigned long data)
780{
781 struct ehca_shca *shca;
782
783 spin_lock(&shca_list_lock);
784 list_for_each_entry(shca, &shca_list, shca_list) {
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +0100785 if (shca->eq.is_initialized) {
786 /* call deadman proc only if eq ptr does not change */
787 struct ehca_eq *eq = &shca->eq;
788 int max = 3;
789 volatile u64 q_ofs, q_ofs2;
790 u64 flags;
791 spin_lock_irqsave(&eq->spinlock, flags);
792 q_ofs = eq->ipz_queue.current_q_offset;
793 spin_unlock_irqrestore(&eq->spinlock, flags);
794 do {
795 spin_lock_irqsave(&eq->spinlock, flags);
796 q_ofs2 = eq->ipz_queue.current_q_offset;
797 spin_unlock_irqrestore(&eq->spinlock, flags);
798 max--;
799 } while (q_ofs == q_ofs2 && max > 0);
800 if (q_ofs == q_ofs2)
801 ehca_process_eq(shca, 0);
802 }
Heiko J Schickfab97222006-09-22 15:22:22 -0700803 }
804 mod_timer(&poll_eqs_timer, jiffies + HZ);
805 spin_unlock(&shca_list_lock);
806}
807
808int __init ehca_module_init(void)
809{
810 int ret;
811
812 printk(KERN_INFO "eHCA Infiniband Device Driver "
Hoang-Nam Nguyen78d8d5f2007-02-15 17:06:33 +0100813 "(Rel.: SVNEHCA_0021)\n");
Heiko J Schickfab97222006-09-22 15:22:22 -0700814 idr_init(&ehca_qp_idr);
815 idr_init(&ehca_cq_idr);
816 spin_lock_init(&ehca_qp_idr_lock);
817 spin_lock_init(&ehca_cq_idr_lock);
818
819 INIT_LIST_HEAD(&shca_list);
820 spin_lock_init(&shca_list_lock);
821
822 if ((ret = ehca_create_comp_pool())) {
823 ehca_gen_err("Cannot create comp pool.");
824 return ret;
825 }
826
827 if ((ret = ehca_create_slab_caches())) {
828 ehca_gen_err("Cannot create SLAB caches");
829 ret = -ENOMEM;
830 goto module_init1;
831 }
832
833 if ((ret = ibmebus_register_driver(&ehca_driver))) {
834 ehca_gen_err("Cannot register eHCA device driver");
835 ret = -EINVAL;
836 goto module_init2;
837 }
838
839 ehca_create_driver_sysfs(&ehca_driver);
840
841 if (ehca_poll_all_eqs != 1) {
842 ehca_gen_err("WARNING!!!");
843 ehca_gen_err("It is possible to lose interrupts.");
844 } else {
845 init_timer(&poll_eqs_timer);
846 poll_eqs_timer.function = ehca_poll_eqs;
847 poll_eqs_timer.expires = jiffies + HZ;
848 add_timer(&poll_eqs_timer);
849 }
850
851 return 0;
852
853module_init2:
854 ehca_destroy_slab_caches();
855
856module_init1:
857 ehca_destroy_comp_pool();
858 return ret;
859};
860
861void __exit ehca_module_exit(void)
862{
863 if (ehca_poll_all_eqs == 1)
864 del_timer_sync(&poll_eqs_timer);
865
866 ehca_remove_driver_sysfs(&ehca_driver);
867 ibmebus_unregister_driver(&ehca_driver);
868
869 ehca_destroy_slab_caches();
870
871 ehca_destroy_comp_pool();
872
873 idr_destroy(&ehca_cq_idr);
874 idr_destroy(&ehca_qp_idr);
875};
876
877module_init(ehca_module_init);
878module_exit(ehca_module_exit);