Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / infiniband / hw / cxgb3 / iwch_provider.c
blob11d103d3eac0c2c568e7b25011f268d342d8c51d
1 /*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
32 #include <linux/module.h>
33 #include <linux/moduleparam.h>
34 #include <linux/device.h>
35 #include <linux/netdevice.h>
36 #include <linux/etherdevice.h>
37 #include <linux/delay.h>
38 #include <linux/errno.h>
39 #include <linux/list.h>
40 #include <linux/spinlock.h>
41 #include <linux/ethtool.h>
42 #include <linux/rtnetlink.h>
44 #include <asm/io.h>
45 #include <asm/irq.h>
46 #include <asm/byteorder.h>
48 #include <rdma/iw_cm.h>
49 #include <rdma/ib_verbs.h>
50 #include <rdma/ib_smi.h>
51 #include <rdma/ib_umem.h>
52 #include <rdma/ib_user_verbs.h>
54 #include "cxio_hal.h"
55 #include "iwch.h"
56 #include "iwch_provider.h"
57 #include "iwch_cm.h"
58 #include "iwch_user.h"
60 static int iwch_modify_port(struct ib_device *ibdev,
61 u8 port, int port_modify_mask,
62 struct ib_port_modify *props)
64 return -ENOSYS;
67 static struct ib_ah *iwch_ah_create(struct ib_pd *pd,
68 struct ib_ah_attr *ah_attr)
70 return ERR_PTR(-ENOSYS);
73 static int iwch_ah_destroy(struct ib_ah *ah)
75 return -ENOSYS;
78 static int iwch_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
80 return -ENOSYS;
83 static int iwch_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
85 return -ENOSYS;
88 static int iwch_process_mad(struct ib_device *ibdev,
89 int mad_flags,
90 u8 port_num,
91 struct ib_wc *in_wc,
92 struct ib_grh *in_grh,
93 struct ib_mad *in_mad, struct ib_mad *out_mad)
95 return -ENOSYS;
98 static int iwch_dealloc_ucontext(struct ib_ucontext *context)
100 struct iwch_dev *rhp = to_iwch_dev(context->device);
101 struct iwch_ucontext *ucontext = to_iwch_ucontext(context);
102 struct iwch_mm_entry *mm, *tmp;
104 PDBG("%s context %p\n", __FUNCTION__, context);
105 list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
106 kfree(mm);
107 cxio_release_ucontext(&rhp->rdev, &ucontext->uctx);
108 kfree(ucontext);
109 return 0;
112 static struct ib_ucontext *iwch_alloc_ucontext(struct ib_device *ibdev,
113 struct ib_udata *udata)
115 struct iwch_ucontext *context;
116 struct iwch_dev *rhp = to_iwch_dev(ibdev);
118 PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
119 context = kzalloc(sizeof(*context), GFP_KERNEL);
120 if (!context)
121 return ERR_PTR(-ENOMEM);
122 cxio_init_ucontext(&rhp->rdev, &context->uctx);
123 INIT_LIST_HEAD(&context->mmaps);
124 spin_lock_init(&context->mmap_lock);
125 return &context->ibucontext;
128 static int iwch_destroy_cq(struct ib_cq *ib_cq)
130 struct iwch_cq *chp;
132 PDBG("%s ib_cq %p\n", __FUNCTION__, ib_cq);
133 chp = to_iwch_cq(ib_cq);
135 remove_handle(chp->rhp, &chp->rhp->cqidr, chp->cq.cqid);
136 atomic_dec(&chp->refcnt);
137 wait_event(chp->wait, !atomic_read(&chp->refcnt));
139 cxio_destroy_cq(&chp->rhp->rdev, &chp->cq);
140 kfree(chp);
141 return 0;
144 static struct ib_cq *iwch_create_cq(struct ib_device *ibdev, int entries, int vector,
145 struct ib_ucontext *ib_context,
146 struct ib_udata *udata)
148 struct iwch_dev *rhp;
149 struct iwch_cq *chp;
150 struct iwch_create_cq_resp uresp;
151 struct iwch_create_cq_req ureq;
152 struct iwch_ucontext *ucontext = NULL;
154 PDBG("%s ib_dev %p entries %d\n", __FUNCTION__, ibdev, entries);
155 rhp = to_iwch_dev(ibdev);
156 chp = kzalloc(sizeof(*chp), GFP_KERNEL);
157 if (!chp)
158 return ERR_PTR(-ENOMEM);
160 if (ib_context) {
161 ucontext = to_iwch_ucontext(ib_context);
162 if (!t3a_device(rhp)) {
163 if (ib_copy_from_udata(&ureq, udata, sizeof (ureq))) {
164 kfree(chp);
165 return ERR_PTR(-EFAULT);
167 chp->user_rptr_addr = (u32 __user *)(unsigned long)ureq.user_rptr_addr;
171 if (t3a_device(rhp)) {
174 * T3A: Add some fluff to handle extra CQEs inserted
175 * for various errors.
176 * Additional CQE possibilities:
177 * TERMINATE,
178 * incoming RDMA WRITE Failures
179 * incoming RDMA READ REQUEST FAILUREs
180 * NOTE: We cannot ensure the CQ won't overflow.
182 entries += 16;
184 entries = roundup_pow_of_two(entries);
185 chp->cq.size_log2 = ilog2(entries);
187 if (cxio_create_cq(&rhp->rdev, &chp->cq)) {
188 kfree(chp);
189 return ERR_PTR(-ENOMEM);
191 chp->rhp = rhp;
192 <<<<<<< HEAD:drivers/infiniband/hw/cxgb3/iwch_provider.c
193 chp->ibcq.cqe = (1 << chp->cq.size_log2) - 1;
194 =======
195 chp->ibcq.cqe = 1 << chp->cq.size_log2;
196 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/infiniband/hw/cxgb3/iwch_provider.c
197 spin_lock_init(&chp->lock);
198 atomic_set(&chp->refcnt, 1);
199 init_waitqueue_head(&chp->wait);
200 insert_handle(rhp, &rhp->cqidr, chp, chp->cq.cqid);
202 if (ucontext) {
203 struct iwch_mm_entry *mm;
205 mm = kmalloc(sizeof *mm, GFP_KERNEL);
206 if (!mm) {
207 iwch_destroy_cq(&chp->ibcq);
208 return ERR_PTR(-ENOMEM);
210 uresp.cqid = chp->cq.cqid;
211 uresp.size_log2 = chp->cq.size_log2;
212 spin_lock(&ucontext->mmap_lock);
213 uresp.key = ucontext->key;
214 ucontext->key += PAGE_SIZE;
215 spin_unlock(&ucontext->mmap_lock);
216 if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) {
217 kfree(mm);
218 iwch_destroy_cq(&chp->ibcq);
219 return ERR_PTR(-EFAULT);
221 mm->key = uresp.key;
222 mm->addr = virt_to_phys(chp->cq.queue);
223 mm->len = PAGE_ALIGN((1UL << uresp.size_log2) *
224 sizeof (struct t3_cqe));
225 insert_mmap(ucontext, mm);
227 PDBG("created cqid 0x%0x chp %p size 0x%0x, dma_addr 0x%0llx\n",
228 chp->cq.cqid, chp, (1 << chp->cq.size_log2),
229 (unsigned long long) chp->cq.dma_addr);
230 return &chp->ibcq;
233 static int iwch_resize_cq(struct ib_cq *cq, int cqe, struct ib_udata *udata)
235 #ifdef notyet
236 struct iwch_cq *chp = to_iwch_cq(cq);
237 struct t3_cq oldcq, newcq;
238 int ret;
240 PDBG("%s ib_cq %p cqe %d\n", __FUNCTION__, cq, cqe);
242 /* We don't downsize... */
243 if (cqe <= cq->cqe)
244 return 0;
246 /* create new t3_cq with new size */
247 cqe = roundup_pow_of_two(cqe+1);
248 newcq.size_log2 = ilog2(cqe);
250 /* Dont allow resize to less than the current wce count */
251 if (cqe < Q_COUNT(chp->cq.rptr, chp->cq.wptr)) {
252 return -ENOMEM;
255 /* Quiesce all QPs using this CQ */
256 ret = iwch_quiesce_qps(chp);
257 if (ret) {
258 return ret;
261 ret = cxio_create_cq(&chp->rhp->rdev, &newcq);
262 if (ret) {
263 return ret;
266 /* copy CQEs */
267 memcpy(newcq.queue, chp->cq.queue, (1 << chp->cq.size_log2) *
268 sizeof(struct t3_cqe));
270 /* old iwch_qp gets new t3_cq but keeps old cqid */
271 oldcq = chp->cq;
272 chp->cq = newcq;
273 chp->cq.cqid = oldcq.cqid;
275 /* resize new t3_cq to update the HW context */
276 ret = cxio_resize_cq(&chp->rhp->rdev, &chp->cq);
277 if (ret) {
278 chp->cq = oldcq;
279 return ret;
281 chp->ibcq.cqe = (1<<chp->cq.size_log2) - 1;
283 /* destroy old t3_cq */
284 oldcq.cqid = newcq.cqid;
285 ret = cxio_destroy_cq(&chp->rhp->rdev, &oldcq);
286 if (ret) {
287 printk(KERN_ERR MOD "%s - cxio_destroy_cq failed %d\n",
288 __FUNCTION__, ret);
291 /* add user hooks here */
293 /* resume qps */
294 ret = iwch_resume_qps(chp);
295 return ret;
296 #else
297 return -ENOSYS;
298 #endif
301 static int iwch_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags)
303 struct iwch_dev *rhp;
304 struct iwch_cq *chp;
305 enum t3_cq_opcode cq_op;
306 int err;
307 unsigned long flag;
308 u32 rptr;
310 chp = to_iwch_cq(ibcq);
311 rhp = chp->rhp;
312 if ((flags & IB_CQ_SOLICITED_MASK) == IB_CQ_SOLICITED)
313 cq_op = CQ_ARM_SE;
314 else
315 cq_op = CQ_ARM_AN;
316 if (chp->user_rptr_addr) {
317 if (get_user(rptr, chp->user_rptr_addr))
318 return -EFAULT;
319 spin_lock_irqsave(&chp->lock, flag);
320 chp->cq.rptr = rptr;
321 } else
322 spin_lock_irqsave(&chp->lock, flag);
323 PDBG("%s rptr 0x%x\n", __FUNCTION__, chp->cq.rptr);
324 err = cxio_hal_cq_op(&rhp->rdev, &chp->cq, cq_op, 0);
325 spin_unlock_irqrestore(&chp->lock, flag);
326 if (err < 0)
327 printk(KERN_ERR MOD "Error %d rearming CQID 0x%x\n", err,
328 chp->cq.cqid);
329 if (err > 0 && !(flags & IB_CQ_REPORT_MISSED_EVENTS))
330 err = 0;
331 return err;
334 static int iwch_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
336 int len = vma->vm_end - vma->vm_start;
337 u32 key = vma->vm_pgoff << PAGE_SHIFT;
338 struct cxio_rdev *rdev_p;
339 int ret = 0;
340 struct iwch_mm_entry *mm;
341 struct iwch_ucontext *ucontext;
342 u64 addr;
344 PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __FUNCTION__, vma->vm_pgoff,
345 key, len);
347 if (vma->vm_start & (PAGE_SIZE-1)) {
348 return -EINVAL;
351 rdev_p = &(to_iwch_dev(context->device)->rdev);
352 ucontext = to_iwch_ucontext(context);
354 mm = remove_mmap(ucontext, key, len);
355 if (!mm)
356 return -EINVAL;
357 addr = mm->addr;
358 kfree(mm);
360 if ((addr >= rdev_p->rnic_info.udbell_physbase) &&
361 (addr < (rdev_p->rnic_info.udbell_physbase +
362 rdev_p->rnic_info.udbell_len))) {
365 * Map T3 DB register.
367 if (vma->vm_flags & VM_READ) {
368 return -EPERM;
371 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
372 vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND;
373 vma->vm_flags &= ~VM_MAYREAD;
374 ret = io_remap_pfn_range(vma, vma->vm_start,
375 addr >> PAGE_SHIFT,
376 len, vma->vm_page_prot);
377 } else {
380 * Map WQ or CQ contig dma memory...
382 ret = remap_pfn_range(vma, vma->vm_start,
383 addr >> PAGE_SHIFT,
384 len, vma->vm_page_prot);
387 return ret;
390 static int iwch_deallocate_pd(struct ib_pd *pd)
392 struct iwch_dev *rhp;
393 struct iwch_pd *php;
395 php = to_iwch_pd(pd);
396 rhp = php->rhp;
397 PDBG("%s ibpd %p pdid 0x%x\n", __FUNCTION__, pd, php->pdid);
398 cxio_hal_put_pdid(rhp->rdev.rscp, php->pdid);
399 kfree(php);
400 return 0;
403 static struct ib_pd *iwch_allocate_pd(struct ib_device *ibdev,
404 struct ib_ucontext *context,
405 struct ib_udata *udata)
407 struct iwch_pd *php;
408 u32 pdid;
409 struct iwch_dev *rhp;
411 PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
412 rhp = (struct iwch_dev *) ibdev;
413 pdid = cxio_hal_get_pdid(rhp->rdev.rscp);
414 if (!pdid)
415 return ERR_PTR(-EINVAL);
416 php = kzalloc(sizeof(*php), GFP_KERNEL);
417 if (!php) {
418 cxio_hal_put_pdid(rhp->rdev.rscp, pdid);
419 return ERR_PTR(-ENOMEM);
421 php->pdid = pdid;
422 php->rhp = rhp;
423 if (context) {
424 if (ib_copy_to_udata(udata, &php->pdid, sizeof (__u32))) {
425 iwch_deallocate_pd(&php->ibpd);
426 return ERR_PTR(-EFAULT);
429 PDBG("%s pdid 0x%0x ptr 0x%p\n", __FUNCTION__, pdid, php);
430 return &php->ibpd;
433 static int iwch_dereg_mr(struct ib_mr *ib_mr)
435 struct iwch_dev *rhp;
436 struct iwch_mr *mhp;
437 u32 mmid;
439 PDBG("%s ib_mr %p\n", __FUNCTION__, ib_mr);
440 /* There can be no memory windows */
441 if (atomic_read(&ib_mr->usecnt))
442 return -EINVAL;
444 mhp = to_iwch_mr(ib_mr);
445 rhp = mhp->rhp;
446 mmid = mhp->attr.stag >> 8;
447 cxio_dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size,
448 mhp->attr.pbl_addr);
449 remove_handle(rhp, &rhp->mmidr, mmid);
450 if (mhp->kva)
451 kfree((void *) (unsigned long) mhp->kva);
452 if (mhp->umem)
453 ib_umem_release(mhp->umem);
454 PDBG("%s mmid 0x%x ptr %p\n", __FUNCTION__, mmid, mhp);
455 kfree(mhp);
456 return 0;
459 static struct ib_mr *iwch_register_phys_mem(struct ib_pd *pd,
460 struct ib_phys_buf *buffer_list,
461 int num_phys_buf,
462 int acc,
463 u64 *iova_start)
465 __be64 *page_list;
466 int shift;
467 u64 total_size;
468 int npages;
469 struct iwch_dev *rhp;
470 struct iwch_pd *php;
471 struct iwch_mr *mhp;
472 int ret;
474 PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
475 php = to_iwch_pd(pd);
476 rhp = php->rhp;
478 mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
479 if (!mhp)
480 return ERR_PTR(-ENOMEM);
482 /* First check that we have enough alignment */
483 if ((*iova_start & ~PAGE_MASK) != (buffer_list[0].addr & ~PAGE_MASK)) {
484 ret = -EINVAL;
485 goto err;
488 if (num_phys_buf > 1 &&
489 ((buffer_list[0].addr + buffer_list[0].size) & ~PAGE_MASK)) {
490 ret = -EINVAL;
491 goto err;
494 ret = build_phys_page_list(buffer_list, num_phys_buf, iova_start,
495 &total_size, &npages, &shift, &page_list);
496 if (ret)
497 goto err;
499 mhp->rhp = rhp;
500 mhp->attr.pdid = php->pdid;
501 mhp->attr.zbva = 0;
503 mhp->attr.perms = iwch_ib_to_tpt_access(acc);
504 mhp->attr.va_fbo = *iova_start;
505 mhp->attr.page_size = shift - 12;
507 mhp->attr.len = (u32) total_size;
508 mhp->attr.pbl_size = npages;
509 ret = iwch_register_mem(rhp, php, mhp, shift, page_list);
510 kfree(page_list);
511 if (ret) {
512 goto err;
514 return &mhp->ibmr;
515 err:
516 kfree(mhp);
517 return ERR_PTR(ret);
521 static int iwch_reregister_phys_mem(struct ib_mr *mr,
522 int mr_rereg_mask,
523 struct ib_pd *pd,
524 struct ib_phys_buf *buffer_list,
525 int num_phys_buf,
526 int acc, u64 * iova_start)
529 struct iwch_mr mh, *mhp;
530 struct iwch_pd *php;
531 struct iwch_dev *rhp;
532 __be64 *page_list = NULL;
533 int shift = 0;
534 u64 total_size;
535 int npages;
536 int ret;
538 PDBG("%s ib_mr %p ib_pd %p\n", __FUNCTION__, mr, pd);
540 /* There can be no memory windows */
541 if (atomic_read(&mr->usecnt))
542 return -EINVAL;
544 mhp = to_iwch_mr(mr);
545 rhp = mhp->rhp;
546 php = to_iwch_pd(mr->pd);
548 /* make sure we are on the same adapter */
549 if (rhp != php->rhp)
550 return -EINVAL;
552 memcpy(&mh, mhp, sizeof *mhp);
554 if (mr_rereg_mask & IB_MR_REREG_PD)
555 php = to_iwch_pd(pd);
556 if (mr_rereg_mask & IB_MR_REREG_ACCESS)
557 mh.attr.perms = iwch_ib_to_tpt_access(acc);
558 if (mr_rereg_mask & IB_MR_REREG_TRANS) {
559 ret = build_phys_page_list(buffer_list, num_phys_buf,
560 iova_start,
561 &total_size, &npages,
562 &shift, &page_list);
563 if (ret)
564 return ret;
567 ret = iwch_reregister_mem(rhp, php, &mh, shift, page_list, npages);
568 kfree(page_list);
569 if (ret) {
570 return ret;
572 if (mr_rereg_mask & IB_MR_REREG_PD)
573 mhp->attr.pdid = php->pdid;
574 if (mr_rereg_mask & IB_MR_REREG_ACCESS)
575 mhp->attr.perms = iwch_ib_to_tpt_access(acc);
576 if (mr_rereg_mask & IB_MR_REREG_TRANS) {
577 mhp->attr.zbva = 0;
578 mhp->attr.va_fbo = *iova_start;
579 mhp->attr.page_size = shift - 12;
580 mhp->attr.len = (u32) total_size;
581 mhp->attr.pbl_size = npages;
584 return 0;
588 static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
589 u64 virt, int acc, struct ib_udata *udata)
591 __be64 *pages;
592 int shift, n, len;
593 int i, j, k;
594 int err = 0;
595 struct ib_umem_chunk *chunk;
596 struct iwch_dev *rhp;
597 struct iwch_pd *php;
598 struct iwch_mr *mhp;
599 struct iwch_reg_user_mr_resp uresp;
601 PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
603 php = to_iwch_pd(pd);
604 rhp = php->rhp;
605 mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
606 if (!mhp)
607 return ERR_PTR(-ENOMEM);
609 mhp->umem = ib_umem_get(pd->uobject->context, start, length, acc);
610 if (IS_ERR(mhp->umem)) {
611 err = PTR_ERR(mhp->umem);
612 kfree(mhp);
613 return ERR_PTR(err);
616 shift = ffs(mhp->umem->page_size) - 1;
618 n = 0;
619 list_for_each_entry(chunk, &mhp->umem->chunk_list, list)
620 n += chunk->nents;
622 pages = kmalloc(n * sizeof(u64), GFP_KERNEL);
623 if (!pages) {
624 err = -ENOMEM;
625 goto err;
628 i = n = 0;
630 list_for_each_entry(chunk, &mhp->umem->chunk_list, list)
631 for (j = 0; j < chunk->nmap; ++j) {
632 len = sg_dma_len(&chunk->page_list[j]) >> shift;
633 for (k = 0; k < len; ++k) {
634 pages[i++] = cpu_to_be64(sg_dma_address(
635 &chunk->page_list[j]) +
636 mhp->umem->page_size * k);
640 mhp->rhp = rhp;
641 mhp->attr.pdid = php->pdid;
642 mhp->attr.zbva = 0;
643 mhp->attr.perms = iwch_ib_to_tpt_access(acc);
644 mhp->attr.va_fbo = virt;
645 mhp->attr.page_size = shift - 12;
646 mhp->attr.len = (u32) length;
647 mhp->attr.pbl_size = i;
648 err = iwch_register_mem(rhp, php, mhp, shift, pages);
649 kfree(pages);
650 if (err)
651 goto err;
653 if (udata && !t3a_device(rhp)) {
654 uresp.pbl_addr = (mhp->attr.pbl_addr -
655 rhp->rdev.rnic_info.pbl_base) >> 3;
656 PDBG("%s user resp pbl_addr 0x%x\n", __FUNCTION__,
657 uresp.pbl_addr);
659 if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) {
660 iwch_dereg_mr(&mhp->ibmr);
661 err = -EFAULT;
662 goto err;
666 return &mhp->ibmr;
668 err:
669 ib_umem_release(mhp->umem);
670 kfree(mhp);
671 return ERR_PTR(err);
674 static struct ib_mr *iwch_get_dma_mr(struct ib_pd *pd, int acc)
676 struct ib_phys_buf bl;
677 u64 kva;
678 struct ib_mr *ibmr;
680 PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
683 * T3 only supports 32 bits of size.
685 bl.size = 0xffffffff;
686 bl.addr = 0;
687 kva = 0;
688 ibmr = iwch_register_phys_mem(pd, &bl, 1, acc, &kva);
689 return ibmr;
692 static struct ib_mw *iwch_alloc_mw(struct ib_pd *pd)
694 struct iwch_dev *rhp;
695 struct iwch_pd *php;
696 struct iwch_mw *mhp;
697 u32 mmid;
698 u32 stag = 0;
699 int ret;
701 php = to_iwch_pd(pd);
702 rhp = php->rhp;
703 mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
704 if (!mhp)
705 return ERR_PTR(-ENOMEM);
706 ret = cxio_allocate_window(&rhp->rdev, &stag, php->pdid);
707 if (ret) {
708 kfree(mhp);
709 return ERR_PTR(ret);
711 mhp->rhp = rhp;
712 mhp->attr.pdid = php->pdid;
713 mhp->attr.type = TPT_MW;
714 mhp->attr.stag = stag;
715 mmid = (stag) >> 8;
716 insert_handle(rhp, &rhp->mmidr, mhp, mmid);
717 PDBG("%s mmid 0x%x mhp %p stag 0x%x\n", __FUNCTION__, mmid, mhp, stag);
718 return &(mhp->ibmw);
721 static int iwch_dealloc_mw(struct ib_mw *mw)
723 struct iwch_dev *rhp;
724 struct iwch_mw *mhp;
725 u32 mmid;
727 mhp = to_iwch_mw(mw);
728 rhp = mhp->rhp;
729 mmid = (mw->rkey) >> 8;
730 cxio_deallocate_window(&rhp->rdev, mhp->attr.stag);
731 remove_handle(rhp, &rhp->mmidr, mmid);
732 kfree(mhp);
733 PDBG("%s ib_mw %p mmid 0x%x ptr %p\n", __FUNCTION__, mw, mmid, mhp);
734 return 0;
737 static int iwch_destroy_qp(struct ib_qp *ib_qp)
739 struct iwch_dev *rhp;
740 struct iwch_qp *qhp;
741 struct iwch_qp_attributes attrs;
742 struct iwch_ucontext *ucontext;
744 qhp = to_iwch_qp(ib_qp);
745 rhp = qhp->rhp;
747 attrs.next_state = IWCH_QP_STATE_ERROR;
748 iwch_modify_qp(rhp, qhp, IWCH_QP_ATTR_NEXT_STATE, &attrs, 0);
749 wait_event(qhp->wait, !qhp->ep);
751 remove_handle(rhp, &rhp->qpidr, qhp->wq.qpid);
753 atomic_dec(&qhp->refcnt);
754 wait_event(qhp->wait, !atomic_read(&qhp->refcnt));
756 ucontext = ib_qp->uobject ? to_iwch_ucontext(ib_qp->uobject->context)
757 : NULL;
758 cxio_destroy_qp(&rhp->rdev, &qhp->wq,
759 ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
761 PDBG("%s ib_qp %p qpid 0x%0x qhp %p\n", __FUNCTION__,
762 ib_qp, qhp->wq.qpid, qhp);
763 kfree(qhp);
764 return 0;
767 static struct ib_qp *iwch_create_qp(struct ib_pd *pd,
768 struct ib_qp_init_attr *attrs,
769 struct ib_udata *udata)
771 struct iwch_dev *rhp;
772 struct iwch_qp *qhp;
773 struct iwch_pd *php;
774 struct iwch_cq *schp;
775 struct iwch_cq *rchp;
776 struct iwch_create_qp_resp uresp;
777 int wqsize, sqsize, rqsize;
778 struct iwch_ucontext *ucontext;
780 PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
781 if (attrs->qp_type != IB_QPT_RC)
782 return ERR_PTR(-EINVAL);
783 php = to_iwch_pd(pd);
784 rhp = php->rhp;
785 schp = get_chp(rhp, ((struct iwch_cq *) attrs->send_cq)->cq.cqid);
786 rchp = get_chp(rhp, ((struct iwch_cq *) attrs->recv_cq)->cq.cqid);
787 if (!schp || !rchp)
788 return ERR_PTR(-EINVAL);
790 /* The RQT size must be # of entries + 1 rounded up to a power of two */
791 rqsize = roundup_pow_of_two(attrs->cap.max_recv_wr);
792 if (rqsize == attrs->cap.max_recv_wr)
793 rqsize = roundup_pow_of_two(attrs->cap.max_recv_wr+1);
795 /* T3 doesn't support RQT depth < 16 */
796 if (rqsize < 16)
797 rqsize = 16;
799 if (rqsize > T3_MAX_RQ_SIZE)
800 return ERR_PTR(-EINVAL);
802 if (attrs->cap.max_inline_data > T3_MAX_INLINE)
803 return ERR_PTR(-EINVAL);
806 * NOTE: The SQ and total WQ sizes don't need to be
807 * a power of two. However, all the code assumes
808 * they are. EG: Q_FREECNT() and friends.
810 sqsize = roundup_pow_of_two(attrs->cap.max_send_wr);
811 wqsize = roundup_pow_of_two(rqsize + sqsize);
812 PDBG("%s wqsize %d sqsize %d rqsize %d\n", __FUNCTION__,
813 wqsize, sqsize, rqsize);
814 qhp = kzalloc(sizeof(*qhp), GFP_KERNEL);
815 if (!qhp)
816 return ERR_PTR(-ENOMEM);
817 qhp->wq.size_log2 = ilog2(wqsize);
818 qhp->wq.rq_size_log2 = ilog2(rqsize);
819 qhp->wq.sq_size_log2 = ilog2(sqsize);
820 ucontext = pd->uobject ? to_iwch_ucontext(pd->uobject->context) : NULL;
821 if (cxio_create_qp(&rhp->rdev, !udata, &qhp->wq,
822 ucontext ? &ucontext->uctx : &rhp->rdev.uctx)) {
823 kfree(qhp);
824 return ERR_PTR(-ENOMEM);
826 <<<<<<< HEAD:drivers/infiniband/hw/cxgb3/iwch_provider.c
827 =======
829 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/infiniband/hw/cxgb3/iwch_provider.c
830 attrs->cap.max_recv_wr = rqsize - 1;
831 attrs->cap.max_send_wr = sqsize;
832 <<<<<<< HEAD:drivers/infiniband/hw/cxgb3/iwch_provider.c
833 =======
834 attrs->cap.max_inline_data = T3_MAX_INLINE;
836 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/infiniband/hw/cxgb3/iwch_provider.c
837 qhp->rhp = rhp;
838 qhp->attr.pd = php->pdid;
839 qhp->attr.scq = ((struct iwch_cq *) attrs->send_cq)->cq.cqid;
840 qhp->attr.rcq = ((struct iwch_cq *) attrs->recv_cq)->cq.cqid;
841 qhp->attr.sq_num_entries = attrs->cap.max_send_wr;
842 qhp->attr.rq_num_entries = attrs->cap.max_recv_wr;
843 qhp->attr.sq_max_sges = attrs->cap.max_send_sge;
844 qhp->attr.sq_max_sges_rdma_write = attrs->cap.max_send_sge;
845 qhp->attr.rq_max_sges = attrs->cap.max_recv_sge;
846 qhp->attr.state = IWCH_QP_STATE_IDLE;
847 qhp->attr.next_state = IWCH_QP_STATE_IDLE;
850 * XXX - These don't get passed in from the openib user
851 * at create time. The CM sets them via a QP modify.
852 * Need to fix... I think the CM should
854 qhp->attr.enable_rdma_read = 1;
855 qhp->attr.enable_rdma_write = 1;
856 qhp->attr.enable_bind = 1;
857 qhp->attr.max_ord = 1;
858 qhp->attr.max_ird = 1;
860 spin_lock_init(&qhp->lock);
861 init_waitqueue_head(&qhp->wait);
862 atomic_set(&qhp->refcnt, 1);
863 insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.qpid);
865 if (udata) {
867 struct iwch_mm_entry *mm1, *mm2;
869 mm1 = kmalloc(sizeof *mm1, GFP_KERNEL);
870 if (!mm1) {
871 iwch_destroy_qp(&qhp->ibqp);
872 return ERR_PTR(-ENOMEM);
875 mm2 = kmalloc(sizeof *mm2, GFP_KERNEL);
876 if (!mm2) {
877 kfree(mm1);
878 iwch_destroy_qp(&qhp->ibqp);
879 return ERR_PTR(-ENOMEM);
882 uresp.qpid = qhp->wq.qpid;
883 uresp.size_log2 = qhp->wq.size_log2;
884 uresp.sq_size_log2 = qhp->wq.sq_size_log2;
885 uresp.rq_size_log2 = qhp->wq.rq_size_log2;
886 spin_lock(&ucontext->mmap_lock);
887 uresp.key = ucontext->key;
888 ucontext->key += PAGE_SIZE;
889 uresp.db_key = ucontext->key;
890 ucontext->key += PAGE_SIZE;
891 spin_unlock(&ucontext->mmap_lock);
892 if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) {
893 kfree(mm1);
894 kfree(mm2);
895 iwch_destroy_qp(&qhp->ibqp);
896 return ERR_PTR(-EFAULT);
898 mm1->key = uresp.key;
899 mm1->addr = virt_to_phys(qhp->wq.queue);
900 mm1->len = PAGE_ALIGN(wqsize * sizeof (union t3_wr));
901 insert_mmap(ucontext, mm1);
902 mm2->key = uresp.db_key;
903 mm2->addr = qhp->wq.udb & PAGE_MASK;
904 mm2->len = PAGE_SIZE;
905 insert_mmap(ucontext, mm2);
907 qhp->ibqp.qp_num = qhp->wq.qpid;
908 init_timer(&(qhp->timer));
909 PDBG("%s sq_num_entries %d, rq_num_entries %d "
910 "qpid 0x%0x qhp %p dma_addr 0x%llx size %d\n",
911 __FUNCTION__, qhp->attr.sq_num_entries, qhp->attr.rq_num_entries,
912 qhp->wq.qpid, qhp, (unsigned long long) qhp->wq.dma_addr,
913 1 << qhp->wq.size_log2);
914 return &qhp->ibqp;
917 static int iwch_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
918 int attr_mask, struct ib_udata *udata)
920 struct iwch_dev *rhp;
921 struct iwch_qp *qhp;
922 enum iwch_qp_attr_mask mask = 0;
923 struct iwch_qp_attributes attrs;
925 PDBG("%s ib_qp %p\n", __FUNCTION__, ibqp);
927 /* iwarp does not support the RTR state */
928 if ((attr_mask & IB_QP_STATE) && (attr->qp_state == IB_QPS_RTR))
929 attr_mask &= ~IB_QP_STATE;
931 /* Make sure we still have something left to do */
932 if (!attr_mask)
933 return 0;
935 memset(&attrs, 0, sizeof attrs);
936 qhp = to_iwch_qp(ibqp);
937 rhp = qhp->rhp;
939 attrs.next_state = iwch_convert_state(attr->qp_state);
940 attrs.enable_rdma_read = (attr->qp_access_flags &
941 IB_ACCESS_REMOTE_READ) ? 1 : 0;
942 attrs.enable_rdma_write = (attr->qp_access_flags &
943 IB_ACCESS_REMOTE_WRITE) ? 1 : 0;
944 attrs.enable_bind = (attr->qp_access_flags & IB_ACCESS_MW_BIND) ? 1 : 0;
947 mask |= (attr_mask & IB_QP_STATE) ? IWCH_QP_ATTR_NEXT_STATE : 0;
948 mask |= (attr_mask & IB_QP_ACCESS_FLAGS) ?
949 (IWCH_QP_ATTR_ENABLE_RDMA_READ |
950 IWCH_QP_ATTR_ENABLE_RDMA_WRITE |
951 IWCH_QP_ATTR_ENABLE_RDMA_BIND) : 0;
953 return iwch_modify_qp(rhp, qhp, mask, &attrs, 0);
956 void iwch_qp_add_ref(struct ib_qp *qp)
958 PDBG("%s ib_qp %p\n", __FUNCTION__, qp);
959 atomic_inc(&(to_iwch_qp(qp)->refcnt));
962 void iwch_qp_rem_ref(struct ib_qp *qp)
964 PDBG("%s ib_qp %p\n", __FUNCTION__, qp);
965 if (atomic_dec_and_test(&(to_iwch_qp(qp)->refcnt)))
966 wake_up(&(to_iwch_qp(qp)->wait));
969 static struct ib_qp *iwch_get_qp(struct ib_device *dev, int qpn)
971 PDBG("%s ib_dev %p qpn 0x%x\n", __FUNCTION__, dev, qpn);
972 return (struct ib_qp *)get_qhp(to_iwch_dev(dev), qpn);
976 static int iwch_query_pkey(struct ib_device *ibdev,
977 u8 port, u16 index, u16 * pkey)
979 PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
980 *pkey = 0;
981 return 0;
984 static int iwch_query_gid(struct ib_device *ibdev, u8 port,
985 int index, union ib_gid *gid)
987 struct iwch_dev *dev;
989 PDBG("%s ibdev %p, port %d, index %d, gid %p\n",
990 __FUNCTION__, ibdev, port, index, gid);
991 dev = to_iwch_dev(ibdev);
992 BUG_ON(port == 0 || port > 2);
993 memset(&(gid->raw[0]), 0, sizeof(gid->raw));
994 memcpy(&(gid->raw[0]), dev->rdev.port_info.lldevs[port-1]->dev_addr, 6);
995 return 0;
998 static int iwch_query_device(struct ib_device *ibdev,
999 struct ib_device_attr *props)
1002 struct iwch_dev *dev;
1003 PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
1005 dev = to_iwch_dev(ibdev);
1006 memset(props, 0, sizeof *props);
1007 memcpy(&props->sys_image_guid, dev->rdev.t3cdev_p->lldev->dev_addr, 6);
1008 props->device_cap_flags = dev->device_cap_flags;
1009 props->vendor_id = (u32)dev->rdev.rnic_info.pdev->vendor;
1010 props->vendor_part_id = (u32)dev->rdev.rnic_info.pdev->device;
1011 props->max_mr_size = ~0ull;
1012 props->max_qp = dev->attr.max_qps;
1013 props->max_qp_wr = dev->attr.max_wrs;
1014 props->max_sge = dev->attr.max_sge_per_wr;
1015 props->max_sge_rd = 1;
1016 props->max_qp_rd_atom = dev->attr.max_rdma_reads_per_qp;
1017 props->max_qp_init_rd_atom = dev->attr.max_rdma_reads_per_qp;
1018 props->max_cq = dev->attr.max_cqs;
1019 props->max_cqe = dev->attr.max_cqes_per_cq;
1020 props->max_mr = dev->attr.max_mem_regs;
1021 props->max_pd = dev->attr.max_pds;
1022 props->local_ca_ack_delay = 0;
1024 return 0;
1027 static int iwch_query_port(struct ib_device *ibdev,
1028 u8 port, struct ib_port_attr *props)
1030 PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
1031 props->max_mtu = IB_MTU_4096;
1032 props->lid = 0;
1033 props->lmc = 0;
1034 props->sm_lid = 0;
1035 props->sm_sl = 0;
1036 props->state = IB_PORT_ACTIVE;
1037 props->phys_state = 0;
1038 props->port_cap_flags =
1039 IB_PORT_CM_SUP |
1040 IB_PORT_SNMP_TUNNEL_SUP |
1041 IB_PORT_REINIT_SUP |
1042 IB_PORT_DEVICE_MGMT_SUP |
1043 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
1044 props->gid_tbl_len = 1;
1045 props->pkey_tbl_len = 1;
1046 props->qkey_viol_cntr = 0;
1047 props->active_width = 2;
1048 props->active_speed = 2;
1049 props->max_msg_sz = -1;
1051 return 0;
1054 static ssize_t show_rev(struct class_device *cdev, char *buf)
1056 struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
1057 ibdev.class_dev);
1058 PDBG("%s class dev 0x%p\n", __FUNCTION__, cdev);
1059 return sprintf(buf, "%d\n", dev->rdev.t3cdev_p->type);
1062 static ssize_t show_fw_ver(struct class_device *cdev, char *buf)
1064 struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
1065 ibdev.class_dev);
1066 struct ethtool_drvinfo info;
1067 struct net_device *lldev = dev->rdev.t3cdev_p->lldev;
1069 PDBG("%s class dev 0x%p\n", __FUNCTION__, cdev);
1070 rtnl_lock();
1071 lldev->ethtool_ops->get_drvinfo(lldev, &info);
1072 rtnl_unlock();
1073 return sprintf(buf, "%s\n", info.fw_version);
1076 static ssize_t show_hca(struct class_device *cdev, char *buf)
1078 struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
1079 ibdev.class_dev);
1080 struct ethtool_drvinfo info;
1081 struct net_device *lldev = dev->rdev.t3cdev_p->lldev;
1083 PDBG("%s class dev 0x%p\n", __FUNCTION__, cdev);
1084 rtnl_lock();
1085 lldev->ethtool_ops->get_drvinfo(lldev, &info);
1086 rtnl_unlock();
1087 return sprintf(buf, "%s\n", info.driver);
1090 static ssize_t show_board(struct class_device *cdev, char *buf)
1092 struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
1093 ibdev.class_dev);
1094 PDBG("%s class dev 0x%p\n", __FUNCTION__, dev);
1095 return sprintf(buf, "%x.%x\n", dev->rdev.rnic_info.pdev->vendor,
1096 dev->rdev.rnic_info.pdev->device);
1099 static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
1100 static CLASS_DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
1101 static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
1102 static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
1104 static struct class_device_attribute *iwch_class_attributes[] = {
1105 &class_device_attr_hw_rev,
1106 &class_device_attr_fw_ver,
1107 &class_device_attr_hca_type,
1108 &class_device_attr_board_id
1111 int iwch_register_device(struct iwch_dev *dev)
1113 int ret;
1114 int i;
1116 PDBG("%s iwch_dev %p\n", __FUNCTION__, dev);
1117 strlcpy(dev->ibdev.name, "cxgb3_%d", IB_DEVICE_NAME_MAX);
1118 memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
1119 memcpy(&dev->ibdev.node_guid, dev->rdev.t3cdev_p->lldev->dev_addr, 6);
1120 dev->ibdev.owner = THIS_MODULE;
1121 dev->device_cap_flags =
1122 (IB_DEVICE_ZERO_STAG |
1123 IB_DEVICE_SEND_W_INV | IB_DEVICE_MEM_WINDOW);
1125 dev->ibdev.uverbs_cmd_mask =
1126 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
1127 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
1128 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
1129 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
1130 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
1131 (1ull << IB_USER_VERBS_CMD_REG_MR) |
1132 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
1133 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
1134 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
1135 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
1136 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
1137 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
1138 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
1139 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
1140 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
1141 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
1142 (1ull << IB_USER_VERBS_CMD_POST_RECV);
1143 dev->ibdev.node_type = RDMA_NODE_RNIC;
1144 memcpy(dev->ibdev.node_desc, IWCH_NODE_DESC, sizeof(IWCH_NODE_DESC));
1145 dev->ibdev.phys_port_cnt = dev->rdev.port_info.nports;
1146 dev->ibdev.num_comp_vectors = 1;
1147 dev->ibdev.dma_device = &(dev->rdev.rnic_info.pdev->dev);
1148 dev->ibdev.query_device = iwch_query_device;
1149 dev->ibdev.query_port = iwch_query_port;
1150 dev->ibdev.modify_port = iwch_modify_port;
1151 dev->ibdev.query_pkey = iwch_query_pkey;
1152 dev->ibdev.query_gid = iwch_query_gid;
1153 dev->ibdev.alloc_ucontext = iwch_alloc_ucontext;
1154 dev->ibdev.dealloc_ucontext = iwch_dealloc_ucontext;
1155 dev->ibdev.mmap = iwch_mmap;
1156 dev->ibdev.alloc_pd = iwch_allocate_pd;
1157 dev->ibdev.dealloc_pd = iwch_deallocate_pd;
1158 dev->ibdev.create_ah = iwch_ah_create;
1159 dev->ibdev.destroy_ah = iwch_ah_destroy;
1160 dev->ibdev.create_qp = iwch_create_qp;
1161 dev->ibdev.modify_qp = iwch_ib_modify_qp;
1162 dev->ibdev.destroy_qp = iwch_destroy_qp;
1163 dev->ibdev.create_cq = iwch_create_cq;
1164 dev->ibdev.destroy_cq = iwch_destroy_cq;
1165 dev->ibdev.resize_cq = iwch_resize_cq;
1166 dev->ibdev.poll_cq = iwch_poll_cq;
1167 dev->ibdev.get_dma_mr = iwch_get_dma_mr;
1168 dev->ibdev.reg_phys_mr = iwch_register_phys_mem;
1169 dev->ibdev.rereg_phys_mr = iwch_reregister_phys_mem;
1170 dev->ibdev.reg_user_mr = iwch_reg_user_mr;
1171 dev->ibdev.dereg_mr = iwch_dereg_mr;
1172 dev->ibdev.alloc_mw = iwch_alloc_mw;
1173 dev->ibdev.bind_mw = iwch_bind_mw;
1174 dev->ibdev.dealloc_mw = iwch_dealloc_mw;
1176 dev->ibdev.attach_mcast = iwch_multicast_attach;
1177 dev->ibdev.detach_mcast = iwch_multicast_detach;
1178 dev->ibdev.process_mad = iwch_process_mad;
1180 dev->ibdev.req_notify_cq = iwch_arm_cq;
1181 dev->ibdev.post_send = iwch_post_send;
1182 dev->ibdev.post_recv = iwch_post_receive;
1185 dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
1186 if (!dev->ibdev.iwcm)
1187 return -ENOMEM;
1189 dev->ibdev.iwcm->connect = iwch_connect;
1190 dev->ibdev.iwcm->accept = iwch_accept_cr;
1191 dev->ibdev.iwcm->reject = iwch_reject_cr;
1192 dev->ibdev.iwcm->create_listen = iwch_create_listen;
1193 dev->ibdev.iwcm->destroy_listen = iwch_destroy_listen;
1194 dev->ibdev.iwcm->add_ref = iwch_qp_add_ref;
1195 dev->ibdev.iwcm->rem_ref = iwch_qp_rem_ref;
1196 dev->ibdev.iwcm->get_qp = iwch_get_qp;
1198 ret = ib_register_device(&dev->ibdev);
1199 if (ret)
1200 goto bail1;
1202 for (i = 0; i < ARRAY_SIZE(iwch_class_attributes); ++i) {
1203 ret = class_device_create_file(&dev->ibdev.class_dev,
1204 iwch_class_attributes[i]);
1205 if (ret) {
1206 goto bail2;
1209 return 0;
1210 bail2:
1211 ib_unregister_device(&dev->ibdev);
1212 bail1:
1213 return ret;
1216 void iwch_unregister_device(struct iwch_dev *dev)
1218 int i;
1220 PDBG("%s iwch_dev %p\n", __FUNCTION__, dev);
1221 for (i = 0; i < ARRAY_SIZE(iwch_class_attributes); ++i)
1222 class_device_remove_file(&dev->ibdev.class_dev,
1223 iwch_class_attributes[i]);
1224 ib_unregister_device(&dev->ibdev);
1225 return;