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_0016");
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_register_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;
320 ret = ib_register_device(&shca->ib_device);
322 ehca_err(&shca->ib_device,
323 "ib_register_device() failed ret=%x", ret);
328 static int ehca_create_aqp1(struct ehca_shca *shca, u32 port)
330 struct ehca_sport *sport = &shca->sport[port - 1];
333 struct ib_qp_init_attr qp_init_attr;
336 if (sport->ibcq_aqp1) {
337 ehca_err(&shca->ib_device, "AQP1 CQ is already created.");
341 ibcq = ib_create_cq(&shca->ib_device, NULL, NULL, (void*)(-1), 10);
343 ehca_err(&shca->ib_device, "Cannot create AQP1 CQ.");
344 return PTR_ERR(ibcq);
346 sport->ibcq_aqp1 = ibcq;
348 if (sport->ibqp_aqp1) {
349 ehca_err(&shca->ib_device, "AQP1 QP is already created.");
354 memset(&qp_init_attr, 0, sizeof(struct ib_qp_init_attr));
355 qp_init_attr.send_cq = ibcq;
356 qp_init_attr.recv_cq = ibcq;
357 qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR;
358 qp_init_attr.cap.max_send_wr = 100;
359 qp_init_attr.cap.max_recv_wr = 100;
360 qp_init_attr.cap.max_send_sge = 2;
361 qp_init_attr.cap.max_recv_sge = 1;
362 qp_init_attr.qp_type = IB_QPT_GSI;
363 qp_init_attr.port_num = port;
364 qp_init_attr.qp_context = NULL;
365 qp_init_attr.event_handler = NULL;
366 qp_init_attr.srq = NULL;
368 ibqp = ib_create_qp(&shca->pd->ib_pd, &qp_init_attr);
370 ehca_err(&shca->ib_device, "Cannot create AQP1 QP.");
374 sport->ibqp_aqp1 = ibqp;
379 ib_destroy_cq(sport->ibcq_aqp1);
383 static int ehca_destroy_aqp1(struct ehca_sport *sport)
387 ret = ib_destroy_qp(sport->ibqp_aqp1);
389 ehca_gen_err("Cannot destroy AQP1 QP. ret=%x", ret);
393 ret = ib_destroy_cq(sport->ibcq_aqp1);
395 ehca_gen_err("Cannot destroy AQP1 CQ. ret=%x", ret);
400 static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf)
402 return snprintf(buf, PAGE_SIZE, "%d\n",
406 static ssize_t ehca_store_debug_level(struct device_driver *ddp,
407 const char *buf, size_t count)
409 int value = (*buf) - '0';
410 if (value >= 0 && value <= 9)
411 ehca_debug_level = value;
415 DRIVER_ATTR(debug_level, S_IRUSR | S_IWUSR,
416 ehca_show_debug_level, ehca_store_debug_level);
418 void ehca_create_driver_sysfs(struct ibmebus_driver *drv)
420 driver_create_file(&drv->driver, &driver_attr_debug_level);
423 void ehca_remove_driver_sysfs(struct ibmebus_driver *drv)
425 driver_remove_file(&drv->driver, &driver_attr_debug_level);
428 #define EHCA_RESOURCE_ATTR(name) \
429 static ssize_t ehca_show_##name(struct device *dev, \
430 struct device_attribute *attr, \
433 struct ehca_shca *shca; \
434 struct hipz_query_hca *rblock; \
437 shca = dev->driver_data; \
439 rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL); \
441 dev_err(dev, "Can't allocate rblock memory."); \
445 if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { \
446 dev_err(dev, "Can't query device properties"); \
451 data = rblock->name; \
454 if ((strcmp(#name, "num_ports") == 0) && (ehca_nr_ports == 1)) \
455 return snprintf(buf, 256, "1\n"); \
457 return snprintf(buf, 256, "%d\n", data); \
460 static DEVICE_ATTR(name, S_IRUGO, ehca_show_##name, NULL);
462 EHCA_RESOURCE_ATTR(num_ports);
463 EHCA_RESOURCE_ATTR(hw_ver);
464 EHCA_RESOURCE_ATTR(max_eq);
465 EHCA_RESOURCE_ATTR(cur_eq);
466 EHCA_RESOURCE_ATTR(max_cq);
467 EHCA_RESOURCE_ATTR(cur_cq);
468 EHCA_RESOURCE_ATTR(max_qp);
469 EHCA_RESOURCE_ATTR(cur_qp);
470 EHCA_RESOURCE_ATTR(max_mr);
471 EHCA_RESOURCE_ATTR(cur_mr);
472 EHCA_RESOURCE_ATTR(max_mw);
473 EHCA_RESOURCE_ATTR(cur_mw);
474 EHCA_RESOURCE_ATTR(max_pd);
475 EHCA_RESOURCE_ATTR(max_ah);
477 static ssize_t ehca_show_adapter_handle(struct device *dev,
478 struct device_attribute *attr,
481 struct ehca_shca *shca = dev->driver_data;
483 return sprintf(buf, "%lx\n", shca->ipz_hca_handle.handle);
486 static DEVICE_ATTR(adapter_handle, S_IRUGO, ehca_show_adapter_handle, NULL);
489 void ehca_create_device_sysfs(struct ibmebus_dev *dev)
491 device_create_file(&dev->ofdev.dev, &dev_attr_adapter_handle);
492 device_create_file(&dev->ofdev.dev, &dev_attr_num_ports);
493 device_create_file(&dev->ofdev.dev, &dev_attr_hw_ver);
494 device_create_file(&dev->ofdev.dev, &dev_attr_max_eq);
495 device_create_file(&dev->ofdev.dev, &dev_attr_cur_eq);
496 device_create_file(&dev->ofdev.dev, &dev_attr_max_cq);
497 device_create_file(&dev->ofdev.dev, &dev_attr_cur_cq);
498 device_create_file(&dev->ofdev.dev, &dev_attr_max_qp);
499 device_create_file(&dev->ofdev.dev, &dev_attr_cur_qp);
500 device_create_file(&dev->ofdev.dev, &dev_attr_max_mr);
501 device_create_file(&dev->ofdev.dev, &dev_attr_cur_mr);
502 device_create_file(&dev->ofdev.dev, &dev_attr_max_mw);
503 device_create_file(&dev->ofdev.dev, &dev_attr_cur_mw);
504 device_create_file(&dev->ofdev.dev, &dev_attr_max_pd);
505 device_create_file(&dev->ofdev.dev, &dev_attr_max_ah);
508 void ehca_remove_device_sysfs(struct ibmebus_dev *dev)
510 device_remove_file(&dev->ofdev.dev, &dev_attr_adapter_handle);
511 device_remove_file(&dev->ofdev.dev, &dev_attr_num_ports);
512 device_remove_file(&dev->ofdev.dev, &dev_attr_hw_ver);
513 device_remove_file(&dev->ofdev.dev, &dev_attr_max_eq);
514 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_eq);
515 device_remove_file(&dev->ofdev.dev, &dev_attr_max_cq);
516 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_cq);
517 device_remove_file(&dev->ofdev.dev, &dev_attr_max_qp);
518 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_qp);
519 device_remove_file(&dev->ofdev.dev, &dev_attr_max_mr);
520 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_mr);
521 device_remove_file(&dev->ofdev.dev, &dev_attr_max_mw);
522 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_mw);
523 device_remove_file(&dev->ofdev.dev, &dev_attr_max_pd);
524 device_remove_file(&dev->ofdev.dev, &dev_attr_max_ah);
527 static int __devinit ehca_probe(struct ibmebus_dev *dev,
528 const struct of_device_id *id)
530 struct ehca_shca *shca;
535 handle = (u64 *)get_property(dev->ofdev.node, "ibm,hca-handle", NULL);
537 ehca_gen_err("Cannot get eHCA handle for adapter: %s.",
538 dev->ofdev.node->full_name);
543 ehca_gen_err("Wrong eHCA handle for adapter: %s.",
544 dev->ofdev.node->full_name);
548 shca = (struct ehca_shca *)ib_alloc_device(sizeof(*shca));
550 ehca_gen_err("Cannot allocate shca memory.");
554 shca->ibmebus_dev = dev;
555 shca->ipz_hca_handle.handle = *handle;
556 dev->ofdev.dev.driver_data = shca;
558 ret = ehca_sense_attributes(shca);
560 ehca_gen_err("Cannot sense eHCA attributes.");
564 ret = ehca_register_device(shca);
566 ehca_gen_err("Cannot register Infiniband device");
570 /* create event queues */
571 ret = ehca_create_eq(shca, &shca->eq, EHCA_EQ, 2048);
573 ehca_err(&shca->ib_device, "Cannot create EQ.");
577 ret = ehca_create_eq(shca, &shca->neq, EHCA_NEQ, 513);
579 ehca_err(&shca->ib_device, "Cannot create NEQ.");
583 /* create internal protection domain */
584 ibpd = ehca_alloc_pd(&shca->ib_device, (void*)(-1), NULL);
586 ehca_err(&shca->ib_device, "Cannot create internal PD.");
591 shca->pd = container_of(ibpd, struct ehca_pd, ib_pd);
592 shca->pd->ib_pd.device = &shca->ib_device;
594 /* create internal max MR */
595 ret = ehca_reg_internal_maxmr(shca, shca->pd, &shca->maxmr);
598 ehca_err(&shca->ib_device, "Cannot create internal MR ret=%x",
603 /* create AQP1 for port 1 */
604 if (ehca_open_aqp1 == 1) {
605 shca->sport[0].port_state = IB_PORT_DOWN;
606 ret = ehca_create_aqp1(shca, 1);
608 ehca_err(&shca->ib_device,
609 "Cannot create AQP1 for port 1.");
614 /* create AQP1 for port 2 */
615 if ((ehca_open_aqp1 == 1) && (shca->num_ports == 2)) {
616 shca->sport[1].port_state = IB_PORT_DOWN;
617 ret = ehca_create_aqp1(shca, 2);
619 ehca_err(&shca->ib_device,
620 "Cannot create AQP1 for port 2.");
625 ehca_create_device_sysfs(dev);
627 spin_lock(&shca_list_lock);
628 list_add(&shca->shca_list, &shca_list);
629 spin_unlock(&shca_list_lock);
634 ret = ehca_destroy_aqp1(&shca->sport[0]);
636 ehca_err(&shca->ib_device,
637 "Cannot destroy AQP1 for port 1. ret=%x", ret);
640 ret = ehca_dereg_internal_maxmr(shca);
642 ehca_err(&shca->ib_device,
643 "Cannot destroy internal MR. ret=%x", ret);
646 ret = ehca_dealloc_pd(&shca->pd->ib_pd);
648 ehca_err(&shca->ib_device,
649 "Cannot destroy internal PD. ret=%x", ret);
652 ret = ehca_destroy_eq(shca, &shca->neq);
654 ehca_err(&shca->ib_device,
655 "Cannot destroy NEQ. ret=%x", ret);
658 ret = ehca_destroy_eq(shca, &shca->eq);
660 ehca_err(&shca->ib_device,
661 "Cannot destroy EQ. ret=%x", ret);
664 ib_unregister_device(&shca->ib_device);
667 ib_dealloc_device(&shca->ib_device);
672 static int __devexit ehca_remove(struct ibmebus_dev *dev)
674 struct ehca_shca *shca = dev->ofdev.dev.driver_data;
677 ehca_remove_device_sysfs(dev);
679 if (ehca_open_aqp1 == 1) {
681 for (i = 0; i < shca->num_ports; i++) {
682 ret = ehca_destroy_aqp1(&shca->sport[i]);
684 ehca_err(&shca->ib_device,
685 "Cannot destroy AQP1 for port %x "
690 ib_unregister_device(&shca->ib_device);
692 ret = ehca_dereg_internal_maxmr(shca);
694 ehca_err(&shca->ib_device,
695 "Cannot destroy internal MR. ret=%x", ret);
697 ret = ehca_dealloc_pd(&shca->pd->ib_pd);
699 ehca_err(&shca->ib_device,
700 "Cannot destroy internal PD. ret=%x", ret);
702 ret = ehca_destroy_eq(shca, &shca->eq);
704 ehca_err(&shca->ib_device, "Cannot destroy EQ. ret=%x", ret);
706 ret = ehca_destroy_eq(shca, &shca->neq);
708 ehca_err(&shca->ib_device, "Canot destroy NEQ. ret=%x", ret);
710 ib_dealloc_device(&shca->ib_device);
712 spin_lock(&shca_list_lock);
713 list_del(&shca->shca_list);
714 spin_unlock(&shca_list_lock);
719 static struct of_device_id ehca_device_table[] =
723 .compatible = "IBM,lhca",
728 static struct ibmebus_driver ehca_driver = {
730 .id_table = ehca_device_table,
732 .remove = ehca_remove,
735 void ehca_poll_eqs(unsigned long data)
737 struct ehca_shca *shca;
739 spin_lock(&shca_list_lock);
740 list_for_each_entry(shca, &shca_list, shca_list) {
741 if (shca->eq.is_initialized)
742 ehca_tasklet_eq((unsigned long)(void*)shca);
744 mod_timer(&poll_eqs_timer, jiffies + HZ);
745 spin_unlock(&shca_list_lock);
748 int __init ehca_module_init(void)
752 printk(KERN_INFO "eHCA Infiniband Device Driver "
753 "(Rel.: SVNEHCA_0016)\n");
754 idr_init(&ehca_qp_idr);
755 idr_init(&ehca_cq_idr);
756 spin_lock_init(&ehca_qp_idr_lock);
757 spin_lock_init(&ehca_cq_idr_lock);
759 INIT_LIST_HEAD(&shca_list);
760 spin_lock_init(&shca_list_lock);
762 if ((ret = ehca_create_comp_pool())) {
763 ehca_gen_err("Cannot create comp pool.");
767 if ((ret = ehca_create_slab_caches())) {
768 ehca_gen_err("Cannot create SLAB caches");
773 if ((ret = ibmebus_register_driver(&ehca_driver))) {
774 ehca_gen_err("Cannot register eHCA device driver");
779 ehca_create_driver_sysfs(&ehca_driver);
781 if (ehca_poll_all_eqs != 1) {
782 ehca_gen_err("WARNING!!!");
783 ehca_gen_err("It is possible to lose interrupts.");
785 init_timer(&poll_eqs_timer);
786 poll_eqs_timer.function = ehca_poll_eqs;
787 poll_eqs_timer.expires = jiffies + HZ;
788 add_timer(&poll_eqs_timer);
794 ehca_destroy_slab_caches();
797 ehca_destroy_comp_pool();
801 void __exit ehca_module_exit(void)
803 if (ehca_poll_all_eqs == 1)
804 del_timer_sync(&poll_eqs_timer);
806 ehca_remove_driver_sysfs(&ehca_driver);
807 ibmebus_unregister_driver(&ehca_driver);
809 ehca_destroy_slab_caches();
811 ehca_destroy_comp_pool();
813 idr_destroy(&ehca_cq_idr);
814 idr_destroy(&ehca_qp_idr);
817 module_init(ehca_module_init);
818 module_exit(ehca_module_exit);