2 * IBM eServer eHCA Infiniband device driver for Linux on POWER
4 * module start stop, hca detection
6 * Authors: Heiko J Schick <schickhj@de.ibm.com>
7 * Hoang-Nam Nguyen <hnguyen@de.ibm.com>
8 * Joachim Fenkes <fenkes@de.ibm.com>
10 * Copyright (c) 2005 IBM Corporation
12 * All rights reserved.
14 * This source code is distributed under a dual license of GPL v2.0 and OpenIB
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are met:
22 * Redistributions of source code must retain the above copyright notice, this
23 * list of conditions and the following disclaimer.
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.
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.
43 #include "ehca_classes.h"
44 #include "ehca_iverbs.h"
45 #include "ehca_mrmw.h"
46 #include "ehca_tools.h"
49 MODULE_LICENSE("Dual BSD/GPL");
50 MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
51 MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver");
52 MODULE_VERSION("SVNEHCA_0017");
54 int ehca_open_aqp1
= 0;
55 int ehca_debug_level
= 0;
56 int ehca_hw_level
= 0;
57 int ehca_nr_ports
= 2;
58 int ehca_use_hp_mr
= 0;
59 int ehca_port_act_time
= 30;
60 int ehca_poll_all_eqs
= 1;
61 int ehca_static_rate
= -1;
63 module_param_named(open_aqp1
, ehca_open_aqp1
, int, 0);
64 module_param_named(debug_level
, ehca_debug_level
, int, 0);
65 module_param_named(hw_level
, ehca_hw_level
, int, 0);
66 module_param_named(nr_ports
, ehca_nr_ports
, int, 0);
67 module_param_named(use_hp_mr
, ehca_use_hp_mr
, int, 0);
68 module_param_named(port_act_time
, ehca_port_act_time
, int, 0);
69 module_param_named(poll_all_eqs
, ehca_poll_all_eqs
, int, 0);
70 module_param_named(static_rate
, ehca_static_rate
, int, 0);
72 MODULE_PARM_DESC(open_aqp1
,
73 "AQP1 on startup (0: no (default), 1: yes)");
74 MODULE_PARM_DESC(debug_level
,
76 " (0: no debug traces (default), 1: with debug traces)");
77 MODULE_PARM_DESC(hw_level
,
79 " (0: autosensing (default), 1: v. 0.20, 2: v. 0.21)");
80 MODULE_PARM_DESC(nr_ports
,
81 "number of connected ports (default: 2)");
82 MODULE_PARM_DESC(use_hp_mr
,
83 "high performance MRs (0: no (default), 1: yes)");
84 MODULE_PARM_DESC(port_act_time
,
85 "time to wait for port activation (default: 30 sec)");
86 MODULE_PARM_DESC(poll_all_eqs
,
87 "polls all event queues periodically"
88 " (0: no, 1: yes (default))");
89 MODULE_PARM_DESC(static_rate
,
90 "set permanent static rate (default: disabled)");
92 spinlock_t ehca_qp_idr_lock
;
93 spinlock_t ehca_cq_idr_lock
;
94 DEFINE_IDR(ehca_qp_idr
);
95 DEFINE_IDR(ehca_cq_idr
);
97 static struct list_head shca_list
; /* list of all registered ehcas */
98 static spinlock_t shca_list_lock
;
100 static struct timer_list poll_eqs_timer
;
102 static int ehca_create_slab_caches(void)
106 ret
= ehca_init_pd_cache();
108 ehca_gen_err("Cannot create PD SLAB cache.");
112 ret
= ehca_init_cq_cache();
114 ehca_gen_err("Cannot create CQ SLAB cache.");
115 goto create_slab_caches2
;
118 ret
= ehca_init_qp_cache();
120 ehca_gen_err("Cannot create QP SLAB cache.");
121 goto create_slab_caches3
;
124 ret
= ehca_init_av_cache();
126 ehca_gen_err("Cannot create AV SLAB cache.");
127 goto create_slab_caches4
;
130 ret
= ehca_init_mrmw_cache();
132 ehca_gen_err("Cannot create MR&MW SLAB cache.");
133 goto create_slab_caches5
;
139 ehca_cleanup_av_cache();
142 ehca_cleanup_qp_cache();
145 ehca_cleanup_cq_cache();
148 ehca_cleanup_pd_cache();
153 static void ehca_destroy_slab_caches(void)
155 ehca_cleanup_mrmw_cache();
156 ehca_cleanup_av_cache();
157 ehca_cleanup_qp_cache();
158 ehca_cleanup_cq_cache();
159 ehca_cleanup_pd_cache();
162 #define EHCA_HCAAVER EHCA_BMASK_IBM(32,39)
163 #define EHCA_REVID EHCA_BMASK_IBM(40,63)
165 int ehca_sense_attributes(struct ehca_shca
*shca
)
169 struct hipz_query_hca
*rblock
;
171 rblock
= kzalloc(H_CB_ALIGNMENT
, GFP_KERNEL
);
173 ehca_gen_err("Cannot allocate rblock memory.");
177 h_ret
= hipz_h_query_hca(shca
->ipz_hca_handle
, rblock
);
178 if (h_ret
!= H_SUCCESS
) {
179 ehca_gen_err("Cannot query device properties. h_ret=%lx",
185 if (ehca_nr_ports
== 1)
188 shca
->num_ports
= (u8
)rblock
->num_ports
;
190 ehca_gen_dbg(" ... found %x ports", rblock
->num_ports
);
192 if (ehca_hw_level
== 0) {
196 hcaaver
= EHCA_BMASK_GET(EHCA_HCAAVER
, rblock
->hw_ver
);
197 revid
= EHCA_BMASK_GET(EHCA_REVID
, rblock
->hw_ver
);
199 ehca_gen_dbg(" ... hardware version=%x:%x", hcaaver
, revid
);
201 if ((hcaaver
== 1) && (revid
== 0))
203 else if ((hcaaver
== 1) && (revid
== 1))
205 else if ((hcaaver
== 1) && (revid
== 2))
208 ehca_gen_dbg(" ... hardware level=%x", shca
->hw_level
);
210 shca
->sport
[0].rate
= IB_RATE_30_GBPS
;
211 shca
->sport
[1].rate
= IB_RATE_30_GBPS
;
218 static int init_node_guid(struct ehca_shca
*shca
)
221 struct hipz_query_hca
*rblock
;
223 rblock
= kzalloc(H_CB_ALIGNMENT
, GFP_KERNEL
);
225 ehca_err(&shca
->ib_device
, "Can't allocate rblock memory.");
229 if (hipz_h_query_hca(shca
->ipz_hca_handle
, rblock
) != H_SUCCESS
) {
230 ehca_err(&shca
->ib_device
, "Can't query device properties");
232 goto init_node_guid1
;
235 memcpy(&shca
->ib_device
.node_guid
, &rblock
->node_guid
, sizeof(u64
));
242 int ehca_init_device(struct ehca_shca
*shca
)
246 ret
= init_node_guid(shca
);
250 strlcpy(shca
->ib_device
.name
, "ehca%d", IB_DEVICE_NAME_MAX
);
251 shca
->ib_device
.owner
= THIS_MODULE
;
253 shca
->ib_device
.uverbs_abi_ver
= 5;
254 shca
->ib_device
.uverbs_cmd_mask
=
255 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT
) |
256 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE
) |
257 (1ull << IB_USER_VERBS_CMD_QUERY_PORT
) |
258 (1ull << IB_USER_VERBS_CMD_ALLOC_PD
) |
259 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD
) |
260 (1ull << IB_USER_VERBS_CMD_REG_MR
) |
261 (1ull << IB_USER_VERBS_CMD_DEREG_MR
) |
262 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL
) |
263 (1ull << IB_USER_VERBS_CMD_CREATE_CQ
) |
264 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ
) |
265 (1ull << IB_USER_VERBS_CMD_CREATE_QP
) |
266 (1ull << IB_USER_VERBS_CMD_MODIFY_QP
) |
267 (1ull << IB_USER_VERBS_CMD_QUERY_QP
) |
268 (1ull << IB_USER_VERBS_CMD_DESTROY_QP
) |
269 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST
) |
270 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST
);
272 shca
->ib_device
.node_type
= RDMA_NODE_IB_CA
;
273 shca
->ib_device
.phys_port_cnt
= shca
->num_ports
;
274 shca
->ib_device
.dma_device
= &shca
->ibmebus_dev
->ofdev
.dev
;
275 shca
->ib_device
.query_device
= ehca_query_device
;
276 shca
->ib_device
.query_port
= ehca_query_port
;
277 shca
->ib_device
.query_gid
= ehca_query_gid
;
278 shca
->ib_device
.query_pkey
= ehca_query_pkey
;
279 /* shca->in_device.modify_device = ehca_modify_device */
280 shca
->ib_device
.modify_port
= ehca_modify_port
;
281 shca
->ib_device
.alloc_ucontext
= ehca_alloc_ucontext
;
282 shca
->ib_device
.dealloc_ucontext
= ehca_dealloc_ucontext
;
283 shca
->ib_device
.alloc_pd
= ehca_alloc_pd
;
284 shca
->ib_device
.dealloc_pd
= ehca_dealloc_pd
;
285 shca
->ib_device
.create_ah
= ehca_create_ah
;
286 /* shca->ib_device.modify_ah = ehca_modify_ah; */
287 shca
->ib_device
.query_ah
= ehca_query_ah
;
288 shca
->ib_device
.destroy_ah
= ehca_destroy_ah
;
289 shca
->ib_device
.create_qp
= ehca_create_qp
;
290 shca
->ib_device
.modify_qp
= ehca_modify_qp
;
291 shca
->ib_device
.query_qp
= ehca_query_qp
;
292 shca
->ib_device
.destroy_qp
= ehca_destroy_qp
;
293 shca
->ib_device
.post_send
= ehca_post_send
;
294 shca
->ib_device
.post_recv
= ehca_post_recv
;
295 shca
->ib_device
.create_cq
= ehca_create_cq
;
296 shca
->ib_device
.destroy_cq
= ehca_destroy_cq
;
297 shca
->ib_device
.resize_cq
= ehca_resize_cq
;
298 shca
->ib_device
.poll_cq
= ehca_poll_cq
;
299 /* shca->ib_device.peek_cq = ehca_peek_cq; */
300 shca
->ib_device
.req_notify_cq
= ehca_req_notify_cq
;
301 /* shca->ib_device.req_ncomp_notif = ehca_req_ncomp_notif; */
302 shca
->ib_device
.get_dma_mr
= ehca_get_dma_mr
;
303 shca
->ib_device
.reg_phys_mr
= ehca_reg_phys_mr
;
304 shca
->ib_device
.reg_user_mr
= ehca_reg_user_mr
;
305 shca
->ib_device
.query_mr
= ehca_query_mr
;
306 shca
->ib_device
.dereg_mr
= ehca_dereg_mr
;
307 shca
->ib_device
.rereg_phys_mr
= ehca_rereg_phys_mr
;
308 shca
->ib_device
.alloc_mw
= ehca_alloc_mw
;
309 shca
->ib_device
.bind_mw
= ehca_bind_mw
;
310 shca
->ib_device
.dealloc_mw
= ehca_dealloc_mw
;
311 shca
->ib_device
.alloc_fmr
= ehca_alloc_fmr
;
312 shca
->ib_device
.map_phys_fmr
= ehca_map_phys_fmr
;
313 shca
->ib_device
.unmap_fmr
= ehca_unmap_fmr
;
314 shca
->ib_device
.dealloc_fmr
= ehca_dealloc_fmr
;
315 shca
->ib_device
.attach_mcast
= ehca_attach_mcast
;
316 shca
->ib_device
.detach_mcast
= ehca_detach_mcast
;
317 /* shca->ib_device.process_mad = ehca_process_mad; */
318 shca
->ib_device
.mmap
= ehca_mmap
;
323 static int ehca_create_aqp1(struct ehca_shca
*shca
, u32 port
)
325 struct ehca_sport
*sport
= &shca
->sport
[port
- 1];
328 struct ib_qp_init_attr qp_init_attr
;
331 if (sport
->ibcq_aqp1
) {
332 ehca_err(&shca
->ib_device
, "AQP1 CQ is already created.");
336 ibcq
= ib_create_cq(&shca
->ib_device
, NULL
, NULL
, (void*)(-1), 10);
338 ehca_err(&shca
->ib_device
, "Cannot create AQP1 CQ.");
339 return PTR_ERR(ibcq
);
341 sport
->ibcq_aqp1
= ibcq
;
343 if (sport
->ibqp_aqp1
) {
344 ehca_err(&shca
->ib_device
, "AQP1 QP is already created.");
349 memset(&qp_init_attr
, 0, sizeof(struct ib_qp_init_attr
));
350 qp_init_attr
.send_cq
= ibcq
;
351 qp_init_attr
.recv_cq
= ibcq
;
352 qp_init_attr
.sq_sig_type
= IB_SIGNAL_ALL_WR
;
353 qp_init_attr
.cap
.max_send_wr
= 100;
354 qp_init_attr
.cap
.max_recv_wr
= 100;
355 qp_init_attr
.cap
.max_send_sge
= 2;
356 qp_init_attr
.cap
.max_recv_sge
= 1;
357 qp_init_attr
.qp_type
= IB_QPT_GSI
;
358 qp_init_attr
.port_num
= port
;
359 qp_init_attr
.qp_context
= NULL
;
360 qp_init_attr
.event_handler
= NULL
;
361 qp_init_attr
.srq
= NULL
;
363 ibqp
= ib_create_qp(&shca
->pd
->ib_pd
, &qp_init_attr
);
365 ehca_err(&shca
->ib_device
, "Cannot create AQP1 QP.");
369 sport
->ibqp_aqp1
= ibqp
;
374 ib_destroy_cq(sport
->ibcq_aqp1
);
378 static int ehca_destroy_aqp1(struct ehca_sport
*sport
)
382 ret
= ib_destroy_qp(sport
->ibqp_aqp1
);
384 ehca_gen_err("Cannot destroy AQP1 QP. ret=%x", ret
);
388 ret
= ib_destroy_cq(sport
->ibcq_aqp1
);
390 ehca_gen_err("Cannot destroy AQP1 CQ. ret=%x", ret
);
395 static ssize_t
ehca_show_debug_level(struct device_driver
*ddp
, char *buf
)
397 return snprintf(buf
, PAGE_SIZE
, "%d\n",
401 static ssize_t
ehca_store_debug_level(struct device_driver
*ddp
,
402 const char *buf
, size_t count
)
404 int value
= (*buf
) - '0';
405 if (value
>= 0 && value
<= 9)
406 ehca_debug_level
= value
;
410 DRIVER_ATTR(debug_level
, S_IRUSR
| S_IWUSR
,
411 ehca_show_debug_level
, ehca_store_debug_level
);
413 void ehca_create_driver_sysfs(struct ibmebus_driver
*drv
)
415 driver_create_file(&drv
->driver
, &driver_attr_debug_level
);
418 void ehca_remove_driver_sysfs(struct ibmebus_driver
*drv
)
420 driver_remove_file(&drv
->driver
, &driver_attr_debug_level
);
423 #define EHCA_RESOURCE_ATTR(name) \
424 static ssize_t ehca_show_##name(struct device *dev, \
425 struct device_attribute *attr, \
428 struct ehca_shca *shca; \
429 struct hipz_query_hca *rblock; \
432 shca = dev->driver_data; \
434 rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL); \
436 dev_err(dev, "Can't allocate rblock memory."); \
440 if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { \
441 dev_err(dev, "Can't query device properties"); \
446 data = rblock->name; \
449 if ((strcmp(#name, "num_ports") == 0) && (ehca_nr_ports == 1)) \
450 return snprintf(buf, 256, "1\n"); \
452 return snprintf(buf, 256, "%d\n", data); \
455 static DEVICE_ATTR(name, S_IRUGO, ehca_show_##name, NULL);
457 EHCA_RESOURCE_ATTR(num_ports
);
458 EHCA_RESOURCE_ATTR(hw_ver
);
459 EHCA_RESOURCE_ATTR(max_eq
);
460 EHCA_RESOURCE_ATTR(cur_eq
);
461 EHCA_RESOURCE_ATTR(max_cq
);
462 EHCA_RESOURCE_ATTR(cur_cq
);
463 EHCA_RESOURCE_ATTR(max_qp
);
464 EHCA_RESOURCE_ATTR(cur_qp
);
465 EHCA_RESOURCE_ATTR(max_mr
);
466 EHCA_RESOURCE_ATTR(cur_mr
);
467 EHCA_RESOURCE_ATTR(max_mw
);
468 EHCA_RESOURCE_ATTR(cur_mw
);
469 EHCA_RESOURCE_ATTR(max_pd
);
470 EHCA_RESOURCE_ATTR(max_ah
);
472 static ssize_t
ehca_show_adapter_handle(struct device
*dev
,
473 struct device_attribute
*attr
,
476 struct ehca_shca
*shca
= dev
->driver_data
;
478 return sprintf(buf
, "%lx\n", shca
->ipz_hca_handle
.handle
);
481 static DEVICE_ATTR(adapter_handle
, S_IRUGO
, ehca_show_adapter_handle
, NULL
);
484 void ehca_create_device_sysfs(struct ibmebus_dev
*dev
)
486 device_create_file(&dev
->ofdev
.dev
, &dev_attr_adapter_handle
);
487 device_create_file(&dev
->ofdev
.dev
, &dev_attr_num_ports
);
488 device_create_file(&dev
->ofdev
.dev
, &dev_attr_hw_ver
);
489 device_create_file(&dev
->ofdev
.dev
, &dev_attr_max_eq
);
490 device_create_file(&dev
->ofdev
.dev
, &dev_attr_cur_eq
);
491 device_create_file(&dev
->ofdev
.dev
, &dev_attr_max_cq
);
492 device_create_file(&dev
->ofdev
.dev
, &dev_attr_cur_cq
);
493 device_create_file(&dev
->ofdev
.dev
, &dev_attr_max_qp
);
494 device_create_file(&dev
->ofdev
.dev
, &dev_attr_cur_qp
);
495 device_create_file(&dev
->ofdev
.dev
, &dev_attr_max_mr
);
496 device_create_file(&dev
->ofdev
.dev
, &dev_attr_cur_mr
);
497 device_create_file(&dev
->ofdev
.dev
, &dev_attr_max_mw
);
498 device_create_file(&dev
->ofdev
.dev
, &dev_attr_cur_mw
);
499 device_create_file(&dev
->ofdev
.dev
, &dev_attr_max_pd
);
500 device_create_file(&dev
->ofdev
.dev
, &dev_attr_max_ah
);
503 void ehca_remove_device_sysfs(struct ibmebus_dev
*dev
)
505 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_adapter_handle
);
506 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_num_ports
);
507 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_hw_ver
);
508 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_max_eq
);
509 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_cur_eq
);
510 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_max_cq
);
511 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_cur_cq
);
512 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_max_qp
);
513 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_cur_qp
);
514 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_max_mr
);
515 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_cur_mr
);
516 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_max_mw
);
517 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_cur_mw
);
518 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_max_pd
);
519 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_max_ah
);
522 static int __devinit
ehca_probe(struct ibmebus_dev
*dev
,
523 const struct of_device_id
*id
)
525 struct ehca_shca
*shca
;
530 handle
= (u64
*)get_property(dev
->ofdev
.node
, "ibm,hca-handle", NULL
);
532 ehca_gen_err("Cannot get eHCA handle for adapter: %s.",
533 dev
->ofdev
.node
->full_name
);
538 ehca_gen_err("Wrong eHCA handle for adapter: %s.",
539 dev
->ofdev
.node
->full_name
);
543 shca
= (struct ehca_shca
*)ib_alloc_device(sizeof(*shca
));
545 ehca_gen_err("Cannot allocate shca memory.");
549 shca
->ibmebus_dev
= dev
;
550 shca
->ipz_hca_handle
.handle
= *handle
;
551 dev
->ofdev
.dev
.driver_data
= shca
;
553 ret
= ehca_sense_attributes(shca
);
555 ehca_gen_err("Cannot sense eHCA attributes.");
559 ret
= ehca_init_device(shca
);
561 ehca_gen_err("Cannot init ehca device struct");
565 /* create event queues */
566 ret
= ehca_create_eq(shca
, &shca
->eq
, EHCA_EQ
, 2048);
568 ehca_err(&shca
->ib_device
, "Cannot create EQ.");
572 ret
= ehca_create_eq(shca
, &shca
->neq
, EHCA_NEQ
, 513);
574 ehca_err(&shca
->ib_device
, "Cannot create NEQ.");
578 /* create internal protection domain */
579 ibpd
= ehca_alloc_pd(&shca
->ib_device
, (void*)(-1), NULL
);
581 ehca_err(&shca
->ib_device
, "Cannot create internal PD.");
586 shca
->pd
= container_of(ibpd
, struct ehca_pd
, ib_pd
);
587 shca
->pd
->ib_pd
.device
= &shca
->ib_device
;
589 /* create internal max MR */
590 ret
= ehca_reg_internal_maxmr(shca
, shca
->pd
, &shca
->maxmr
);
593 ehca_err(&shca
->ib_device
, "Cannot create internal MR ret=%x",
598 ret
= ib_register_device(&shca
->ib_device
);
600 ehca_err(&shca
->ib_device
,
601 "ib_register_device() failed ret=%x", ret
);
605 /* create AQP1 for port 1 */
606 if (ehca_open_aqp1
== 1) {
607 shca
->sport
[0].port_state
= IB_PORT_DOWN
;
608 ret
= ehca_create_aqp1(shca
, 1);
610 ehca_err(&shca
->ib_device
,
611 "Cannot create AQP1 for port 1.");
616 /* create AQP1 for port 2 */
617 if ((ehca_open_aqp1
== 1) && (shca
->num_ports
== 2)) {
618 shca
->sport
[1].port_state
= IB_PORT_DOWN
;
619 ret
= ehca_create_aqp1(shca
, 2);
621 ehca_err(&shca
->ib_device
,
622 "Cannot create AQP1 for port 2.");
627 ehca_create_device_sysfs(dev
);
629 spin_lock(&shca_list_lock
);
630 list_add(&shca
->shca_list
, &shca_list
);
631 spin_unlock(&shca_list_lock
);
636 ret
= ehca_destroy_aqp1(&shca
->sport
[0]);
638 ehca_err(&shca
->ib_device
,
639 "Cannot destroy AQP1 for port 1. ret=%x", ret
);
642 ib_unregister_device(&shca
->ib_device
);
645 ret
= ehca_dereg_internal_maxmr(shca
);
647 ehca_err(&shca
->ib_device
,
648 "Cannot destroy internal MR. ret=%x", ret
);
651 ret
= ehca_dealloc_pd(&shca
->pd
->ib_pd
);
653 ehca_err(&shca
->ib_device
,
654 "Cannot destroy internal PD. ret=%x", ret
);
657 ret
= ehca_destroy_eq(shca
, &shca
->neq
);
659 ehca_err(&shca
->ib_device
,
660 "Cannot destroy NEQ. ret=%x", ret
);
663 ret
= ehca_destroy_eq(shca
, &shca
->eq
);
665 ehca_err(&shca
->ib_device
,
666 "Cannot destroy EQ. ret=%x", ret
);
669 ib_dealloc_device(&shca
->ib_device
);
674 static int __devexit
ehca_remove(struct ibmebus_dev
*dev
)
676 struct ehca_shca
*shca
= dev
->ofdev
.dev
.driver_data
;
679 ehca_remove_device_sysfs(dev
);
681 if (ehca_open_aqp1
== 1) {
683 for (i
= 0; i
< shca
->num_ports
; i
++) {
684 ret
= ehca_destroy_aqp1(&shca
->sport
[i
]);
686 ehca_err(&shca
->ib_device
,
687 "Cannot destroy AQP1 for port %x "
692 ib_unregister_device(&shca
->ib_device
);
694 ret
= ehca_dereg_internal_maxmr(shca
);
696 ehca_err(&shca
->ib_device
,
697 "Cannot destroy internal MR. ret=%x", ret
);
699 ret
= ehca_dealloc_pd(&shca
->pd
->ib_pd
);
701 ehca_err(&shca
->ib_device
,
702 "Cannot destroy internal PD. ret=%x", ret
);
704 ret
= ehca_destroy_eq(shca
, &shca
->eq
);
706 ehca_err(&shca
->ib_device
, "Cannot destroy EQ. ret=%x", ret
);
708 ret
= ehca_destroy_eq(shca
, &shca
->neq
);
710 ehca_err(&shca
->ib_device
, "Canot destroy NEQ. ret=%x", ret
);
712 ib_dealloc_device(&shca
->ib_device
);
714 spin_lock(&shca_list_lock
);
715 list_del(&shca
->shca_list
);
716 spin_unlock(&shca_list_lock
);
721 static struct of_device_id ehca_device_table
[] =
725 .compatible
= "IBM,lhca",
730 static struct ibmebus_driver ehca_driver
= {
732 .id_table
= ehca_device_table
,
734 .remove
= ehca_remove
,
737 void ehca_poll_eqs(unsigned long data
)
739 struct ehca_shca
*shca
;
741 spin_lock(&shca_list_lock
);
742 list_for_each_entry(shca
, &shca_list
, shca_list
) {
743 if (shca
->eq
.is_initialized
)
744 ehca_tasklet_eq((unsigned long)(void*)shca
);
746 mod_timer(&poll_eqs_timer
, jiffies
+ HZ
);
747 spin_unlock(&shca_list_lock
);
750 int __init
ehca_module_init(void)
754 printk(KERN_INFO
"eHCA Infiniband Device Driver "
755 "(Rel.: SVNEHCA_0017)\n");
756 idr_init(&ehca_qp_idr
);
757 idr_init(&ehca_cq_idr
);
758 spin_lock_init(&ehca_qp_idr_lock
);
759 spin_lock_init(&ehca_cq_idr_lock
);
761 INIT_LIST_HEAD(&shca_list
);
762 spin_lock_init(&shca_list_lock
);
764 if ((ret
= ehca_create_comp_pool())) {
765 ehca_gen_err("Cannot create comp pool.");
769 if ((ret
= ehca_create_slab_caches())) {
770 ehca_gen_err("Cannot create SLAB caches");
775 if ((ret
= ibmebus_register_driver(&ehca_driver
))) {
776 ehca_gen_err("Cannot register eHCA device driver");
781 ehca_create_driver_sysfs(&ehca_driver
);
783 if (ehca_poll_all_eqs
!= 1) {
784 ehca_gen_err("WARNING!!!");
785 ehca_gen_err("It is possible to lose interrupts.");
787 init_timer(&poll_eqs_timer
);
788 poll_eqs_timer
.function
= ehca_poll_eqs
;
789 poll_eqs_timer
.expires
= jiffies
+ HZ
;
790 add_timer(&poll_eqs_timer
);
796 ehca_destroy_slab_caches();
799 ehca_destroy_comp_pool();
803 void __exit
ehca_module_exit(void)
805 if (ehca_poll_all_eqs
== 1)
806 del_timer_sync(&poll_eqs_timer
);
808 ehca_remove_driver_sysfs(&ehca_driver
);
809 ibmebus_unregister_driver(&ehca_driver
);
811 ehca_destroy_slab_caches();
813 ehca_destroy_comp_pool();
815 idr_destroy(&ehca_cq_idr
);
816 idr_destroy(&ehca_qp_idr
);
819 module_init(ehca_module_init
);
820 module_exit(ehca_module_exit
);