2 * Copyright (c) 2005 Ammasso, Inc. All rights reserved.
3 * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include <linux/module.h>
36 #include <linux/moduleparam.h>
37 #include <linux/pci.h>
38 #include <linux/netdevice.h>
39 #include <linux/etherdevice.h>
40 #include <linux/inetdevice.h>
41 #include <linux/delay.h>
42 #include <linux/ethtool.h>
43 #include <linux/mii.h>
44 #include <linux/if_vlan.h>
45 #include <linux/crc32.h>
48 #include <linux/tcp.h>
49 #include <linux/init.h>
50 #include <linux/dma-mapping.h>
51 #include <linux/if_arp.h>
52 #include <linux/vmalloc.h>
56 #include <asm/byteorder.h>
58 #include <rdma/ib_smi.h>
59 #include <rdma/ib_umem.h>
60 #include <rdma/ib_user_verbs.h>
62 #include "c2_provider.h"
65 static int c2_query_device(struct ib_device *ibdev,
66 struct ib_device_attr *props)
68 struct c2_dev *c2dev = to_c2dev(ibdev);
70 pr_debug("%s:%u\n", __func__, __LINE__);
72 *props = c2dev->props;
76 static int c2_query_port(struct ib_device *ibdev,
77 u8 port, struct ib_port_attr *props)
79 pr_debug("%s:%u\n", __func__, __LINE__);
81 props->max_mtu = IB_MTU_4096;
86 props->state = IB_PORT_ACTIVE;
87 props->phys_state = 0;
88 props->port_cap_flags =
91 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
92 props->gid_tbl_len = 1;
93 props->pkey_tbl_len = 1;
94 props->qkey_viol_cntr = 0;
95 props->active_width = 1;
96 props->active_speed = 1;
101 static int c2_modify_port(struct ib_device *ibdev,
102 u8 port, int port_modify_mask,
103 struct ib_port_modify *props)
105 pr_debug("%s:%u\n", __func__, __LINE__);
109 static int c2_query_pkey(struct ib_device *ibdev,
110 u8 port, u16 index, u16 * pkey)
112 pr_debug("%s:%u\n", __func__, __LINE__);
117 static int c2_query_gid(struct ib_device *ibdev, u8 port,
118 int index, union ib_gid *gid)
120 struct c2_dev *c2dev = to_c2dev(ibdev);
122 pr_debug("%s:%u\n", __func__, __LINE__);
123 memset(&(gid->raw[0]), 0, sizeof(gid->raw));
124 memcpy(&(gid->raw[0]), c2dev->pseudo_netdev->dev_addr, 6);
129 /* Allocate the user context data structure. This keeps track
130 * of all objects associated with a particular user-mode client.
132 static struct ib_ucontext *c2_alloc_ucontext(struct ib_device *ibdev,
133 struct ib_udata *udata)
135 struct c2_ucontext *context;
137 pr_debug("%s:%u\n", __func__, __LINE__);
138 context = kmalloc(sizeof(*context), GFP_KERNEL);
140 return ERR_PTR(-ENOMEM);
142 return &context->ibucontext;
145 static int c2_dealloc_ucontext(struct ib_ucontext *context)
147 pr_debug("%s:%u\n", __func__, __LINE__);
152 static int c2_mmap_uar(struct ib_ucontext *context, struct vm_area_struct *vma)
154 pr_debug("%s:%u\n", __func__, __LINE__);
158 static struct ib_pd *c2_alloc_pd(struct ib_device *ibdev,
159 struct ib_ucontext *context,
160 struct ib_udata *udata)
165 pr_debug("%s:%u\n", __func__, __LINE__);
167 pd = kmalloc(sizeof(*pd), GFP_KERNEL);
169 return ERR_PTR(-ENOMEM);
171 err = c2_pd_alloc(to_c2dev(ibdev), !context, pd);
178 if (ib_copy_to_udata(udata, &pd->pd_id, sizeof(__u32))) {
179 c2_pd_free(to_c2dev(ibdev), pd);
181 return ERR_PTR(-EFAULT);
188 static int c2_dealloc_pd(struct ib_pd *pd)
190 pr_debug("%s:%u\n", __func__, __LINE__);
191 c2_pd_free(to_c2dev(pd->device), to_c2pd(pd));
197 static struct ib_ah *c2_ah_create(struct ib_pd *pd, struct ib_ah_attr *ah_attr)
199 pr_debug("%s:%u\n", __func__, __LINE__);
200 return ERR_PTR(-ENOSYS);
203 static int c2_ah_destroy(struct ib_ah *ah)
205 pr_debug("%s:%u\n", __func__, __LINE__);
209 static void c2_add_ref(struct ib_qp *ibqp)
214 atomic_inc(&qp->refcount);
217 static void c2_rem_ref(struct ib_qp *ibqp)
222 if (atomic_dec_and_test(&qp->refcount))
226 struct ib_qp *c2_get_qp(struct ib_device *device, int qpn)
228 struct c2_dev* c2dev = to_c2dev(device);
231 qp = c2_find_qpn(c2dev, qpn);
232 pr_debug("%s Returning QP=%p for QPN=%d, device=%p, refcount=%d\n",
233 __func__, qp, qpn, device,
234 (qp?atomic_read(&qp->refcount):0));
236 return (qp?&qp->ibqp:NULL);
239 static struct ib_qp *c2_create_qp(struct ib_pd *pd,
240 struct ib_qp_init_attr *init_attr,
241 struct ib_udata *udata)
246 pr_debug("%s:%u\n", __func__, __LINE__);
248 if (init_attr->create_flags)
249 return ERR_PTR(-EINVAL);
251 switch (init_attr->qp_type) {
253 qp = kzalloc(sizeof(*qp), GFP_KERNEL);
255 pr_debug("%s: Unable to allocate QP\n", __func__);
256 return ERR_PTR(-ENOMEM);
258 spin_lock_init(&qp->lock);
260 /* userspace specific */
263 err = c2_alloc_qp(to_c2dev(pd->device),
264 to_c2pd(pd), init_attr, qp);
266 if (err && pd->uobject) {
267 /* userspace specific */
272 pr_debug("%s: Invalid QP type: %d\n", __func__,
274 return ERR_PTR(-EINVAL);
286 static int c2_destroy_qp(struct ib_qp *ib_qp)
288 struct c2_qp *qp = to_c2qp(ib_qp);
290 pr_debug("%s:%u qp=%p,qp->state=%d\n",
291 __func__, __LINE__, ib_qp, qp->state);
292 c2_free_qp(to_c2dev(ib_qp->device), qp);
297 static struct ib_cq *c2_create_cq(struct ib_device *ibdev, int entries, int vector,
298 struct ib_ucontext *context,
299 struct ib_udata *udata)
304 cq = kmalloc(sizeof(*cq), GFP_KERNEL);
306 pr_debug("%s: Unable to allocate CQ\n", __func__);
307 return ERR_PTR(-ENOMEM);
310 err = c2_init_cq(to_c2dev(ibdev), entries, NULL, cq);
312 pr_debug("%s: error initializing CQ\n", __func__);
320 static int c2_destroy_cq(struct ib_cq *ib_cq)
322 struct c2_cq *cq = to_c2cq(ib_cq);
324 pr_debug("%s:%u\n", __func__, __LINE__);
326 c2_free_cq(to_c2dev(ib_cq->device), cq);
332 static inline u32 c2_convert_access(int acc)
334 return (acc & IB_ACCESS_REMOTE_WRITE ? C2_ACF_REMOTE_WRITE : 0) |
335 (acc & IB_ACCESS_REMOTE_READ ? C2_ACF_REMOTE_READ : 0) |
336 (acc & IB_ACCESS_LOCAL_WRITE ? C2_ACF_LOCAL_WRITE : 0) |
337 C2_ACF_LOCAL_READ | C2_ACF_WINDOW_BIND;
340 static struct ib_mr *c2_reg_phys_mr(struct ib_pd *ib_pd,
341 struct ib_phys_buf *buffer_list,
342 int num_phys_buf, int acc, u64 * iova_start)
347 int err, i, j, k, page_shift, pbl_depth;
352 page_shift = PAGE_SHIFT;
354 * If there is only 1 buffer we assume this could
355 * be a map of all phy mem...use a 32k page_shift.
357 if (num_phys_buf == 1)
360 for (i = 0; i < num_phys_buf; i++) {
362 if (buffer_list[i].addr & ~PAGE_MASK) {
363 pr_debug("Unaligned Memory Buffer: 0x%x\n",
364 (unsigned int) buffer_list[i].addr);
365 return ERR_PTR(-EINVAL);
368 if (!buffer_list[i].size) {
369 pr_debug("Invalid Buffer Size\n");
370 return ERR_PTR(-EINVAL);
373 total_len += buffer_list[i].size;
374 pbl_depth += ALIGN(buffer_list[i].size,
375 (1 << page_shift)) >> page_shift;
378 page_list = vmalloc(sizeof(u64) * pbl_depth);
380 pr_debug("couldn't vmalloc page_list of size %zd\n",
381 (sizeof(u64) * pbl_depth));
382 return ERR_PTR(-ENOMEM);
385 for (i = 0, j = 0; i < num_phys_buf; i++) {
389 naddrs = ALIGN(buffer_list[i].size,
390 (1 << page_shift)) >> page_shift;
391 for (k = 0; k < naddrs; k++)
392 page_list[j++] = (buffer_list[i].addr +
396 mr = kmalloc(sizeof(*mr), GFP_KERNEL);
399 return ERR_PTR(-ENOMEM);
402 mr->pd = to_c2pd(ib_pd);
404 pr_debug("%s - page shift %d, pbl_depth %d, total_len %u, "
405 "*iova_start %llx, first pa %llx, last pa %llx\n",
406 __func__, page_shift, pbl_depth, total_len,
407 (unsigned long long) *iova_start,
408 (unsigned long long) page_list[0],
409 (unsigned long long) page_list[pbl_depth-1]);
410 err = c2_nsmr_register_phys_kern(to_c2dev(ib_pd->device), page_list,
411 (1 << page_shift), pbl_depth,
412 total_len, 0, iova_start,
413 c2_convert_access(acc), mr);
423 static struct ib_mr *c2_get_dma_mr(struct ib_pd *pd, int acc)
425 struct ib_phys_buf bl;
428 pr_debug("%s:%u\n", __func__, __LINE__);
431 bl.size = 0xffffffff;
433 return c2_reg_phys_mr(pd, &bl, 1, acc, &kva);
436 static struct ib_mr *c2_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
437 u64 virt, int acc, struct ib_udata *udata)
444 struct ib_umem_chunk *chunk;
445 struct c2_pd *c2pd = to_c2pd(pd);
448 pr_debug("%s:%u\n", __func__, __LINE__);
450 c2mr = kmalloc(sizeof(*c2mr), GFP_KERNEL);
452 return ERR_PTR(-ENOMEM);
455 c2mr->umem = ib_umem_get(pd->uobject->context, start, length, acc);
456 if (IS_ERR(c2mr->umem)) {
457 err = PTR_ERR(c2mr->umem);
462 shift = ffs(c2mr->umem->page_size) - 1;
465 list_for_each_entry(chunk, &c2mr->umem->chunk_list, list)
468 pages = kmalloc(n * sizeof(u64), GFP_KERNEL);
475 list_for_each_entry(chunk, &c2mr->umem->chunk_list, list) {
476 for (j = 0; j < chunk->nmap; ++j) {
477 len = sg_dma_len(&chunk->page_list[j]) >> shift;
478 for (k = 0; k < len; ++k) {
480 sg_dma_address(&chunk->page_list[j]) +
481 (c2mr->umem->page_size * k);
487 err = c2_nsmr_register_phys_kern(to_c2dev(pd->device),
489 c2mr->umem->page_size,
494 c2_convert_access(acc),
502 ib_umem_release(c2mr->umem);
507 static int c2_dereg_mr(struct ib_mr *ib_mr)
509 struct c2_mr *mr = to_c2mr(ib_mr);
512 pr_debug("%s:%u\n", __func__, __LINE__);
514 err = c2_stag_dealloc(to_c2dev(ib_mr->device), ib_mr->lkey);
516 pr_debug("c2_stag_dealloc failed: %d\n", err);
519 ib_umem_release(mr->umem);
526 static ssize_t show_rev(struct class_device *cdev, char *buf)
528 struct c2_dev *dev = container_of(cdev, struct c2_dev, ibdev.class_dev);
529 pr_debug("%s:%u\n", __func__, __LINE__);
530 return sprintf(buf, "%x\n", dev->props.hw_ver);
533 static ssize_t show_fw_ver(struct class_device *cdev, char *buf)
535 struct c2_dev *dev = container_of(cdev, struct c2_dev, ibdev.class_dev);
536 pr_debug("%s:%u\n", __func__, __LINE__);
537 return sprintf(buf, "%x.%x.%x\n",
538 (int) (dev->props.fw_ver >> 32),
539 (int) (dev->props.fw_ver >> 16) & 0xffff,
540 (int) (dev->props.fw_ver & 0xffff));
543 static ssize_t show_hca(struct class_device *cdev, char *buf)
545 pr_debug("%s:%u\n", __func__, __LINE__);
546 return sprintf(buf, "AMSO1100\n");
549 static ssize_t show_board(struct class_device *cdev, char *buf)
551 pr_debug("%s:%u\n", __func__, __LINE__);
552 return sprintf(buf, "%.*s\n", 32, "AMSO1100 Board ID");
555 static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
556 static CLASS_DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
557 static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
558 static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
560 static struct class_device_attribute *c2_class_attributes[] = {
561 &class_device_attr_hw_rev,
562 &class_device_attr_fw_ver,
563 &class_device_attr_hca_type,
564 &class_device_attr_board_id
567 static int c2_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
568 int attr_mask, struct ib_udata *udata)
573 c2_qp_modify(to_c2dev(ibqp->device), to_c2qp(ibqp), attr,
579 static int c2_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
581 pr_debug("%s:%u\n", __func__, __LINE__);
585 static int c2_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
587 pr_debug("%s:%u\n", __func__, __LINE__);
591 static int c2_process_mad(struct ib_device *ibdev,
595 struct ib_grh *in_grh,
596 struct ib_mad *in_mad, struct ib_mad *out_mad)
598 pr_debug("%s:%u\n", __func__, __LINE__);
602 static int c2_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
604 pr_debug("%s:%u\n", __func__, __LINE__);
606 /* Request a connection */
607 return c2_llp_connect(cm_id, iw_param);
610 static int c2_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
612 pr_debug("%s:%u\n", __func__, __LINE__);
614 /* Accept the new connection */
615 return c2_llp_accept(cm_id, iw_param);
618 static int c2_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
622 pr_debug("%s:%u\n", __func__, __LINE__);
624 err = c2_llp_reject(cm_id, pdata, pdata_len);
628 static int c2_service_create(struct iw_cm_id *cm_id, int backlog)
632 pr_debug("%s:%u\n", __func__, __LINE__);
633 err = c2_llp_service_create(cm_id, backlog);
634 pr_debug("%s:%u err=%d\n",
640 static int c2_service_destroy(struct iw_cm_id *cm_id)
643 pr_debug("%s:%u\n", __func__, __LINE__);
645 err = c2_llp_service_destroy(cm_id);
650 static int c2_pseudo_up(struct net_device *netdev)
652 struct in_device *ind;
653 struct c2_dev *c2dev = netdev->priv;
655 ind = in_dev_get(netdev);
659 pr_debug("adding...\n");
662 u8 *ip = (u8 *) & ifa->ifa_address;
664 pr_debug("%s: %d.%d.%d.%d\n",
665 ifa->ifa_label, ip[0], ip[1], ip[2], ip[3]);
667 c2_add_addr(c2dev, ifa->ifa_address, ifa->ifa_mask);
675 static int c2_pseudo_down(struct net_device *netdev)
677 struct in_device *ind;
678 struct c2_dev *c2dev = netdev->priv;
680 ind = in_dev_get(netdev);
684 pr_debug("deleting...\n");
687 u8 *ip = (u8 *) & ifa->ifa_address;
689 pr_debug("%s: %d.%d.%d.%d\n",
690 ifa->ifa_label, ip[0], ip[1], ip[2], ip[3]);
692 c2_del_addr(c2dev, ifa->ifa_address, ifa->ifa_mask);
700 static int c2_pseudo_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
706 static int c2_pseudo_change_mtu(struct net_device *netdev, int new_mtu)
710 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
713 netdev->mtu = new_mtu;
715 /* TODO: Tell rnic about new rmda interface mtu */
719 static void setup(struct net_device *netdev)
721 netdev->open = c2_pseudo_up;
722 netdev->stop = c2_pseudo_down;
723 netdev->hard_start_xmit = c2_pseudo_xmit_frame;
724 netdev->get_stats = NULL;
725 netdev->tx_timeout = NULL;
726 netdev->set_mac_address = NULL;
727 netdev->change_mtu = c2_pseudo_change_mtu;
728 netdev->watchdog_timeo = 0;
729 netdev->type = ARPHRD_ETHER;
731 netdev->hard_header_len = ETH_HLEN;
732 netdev->addr_len = ETH_ALEN;
733 netdev->tx_queue_len = 0;
734 netdev->flags |= IFF_NOARP;
738 static struct net_device *c2_pseudo_netdev_init(struct c2_dev *c2dev)
741 struct net_device *netdev;
743 /* change ethxxx to iwxxx */
745 strcat(name, &c2dev->netdev->name[3]);
746 netdev = alloc_netdev(sizeof(*netdev), name, setup);
748 printk(KERN_ERR PFX "%s - etherdev alloc failed",
753 netdev->priv = c2dev;
755 SET_NETDEV_DEV(netdev, &c2dev->pcidev->dev);
757 memcpy_fromio(netdev->dev_addr, c2dev->kva + C2_REGS_RDMA_ENADDR, 6);
759 /* Print out the MAC address */
760 pr_debug("%s: MAC %02X:%02X:%02X:%02X:%02X:%02X\n",
762 netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
763 netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
766 /* Disable network packets */
767 netif_stop_queue(netdev);
772 int c2_register_device(struct c2_dev *dev)
777 /* Register pseudo network device */
778 dev->pseudo_netdev = c2_pseudo_netdev_init(dev);
779 if (!dev->pseudo_netdev)
782 ret = register_netdev(dev->pseudo_netdev);
786 pr_debug("%s:%u\n", __func__, __LINE__);
787 strlcpy(dev->ibdev.name, "amso%d", IB_DEVICE_NAME_MAX);
788 dev->ibdev.owner = THIS_MODULE;
789 dev->ibdev.uverbs_cmd_mask =
790 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
791 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
792 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
793 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
794 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
795 (1ull << IB_USER_VERBS_CMD_REG_MR) |
796 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
797 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
798 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
799 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
800 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
801 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
802 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
803 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
804 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
805 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
806 (1ull << IB_USER_VERBS_CMD_POST_RECV);
808 dev->ibdev.node_type = RDMA_NODE_RNIC;
809 memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
810 memcpy(&dev->ibdev.node_guid, dev->pseudo_netdev->dev_addr, 6);
811 dev->ibdev.phys_port_cnt = 1;
812 dev->ibdev.num_comp_vectors = 1;
813 dev->ibdev.dma_device = &dev->pcidev->dev;
814 dev->ibdev.query_device = c2_query_device;
815 dev->ibdev.query_port = c2_query_port;
816 dev->ibdev.modify_port = c2_modify_port;
817 dev->ibdev.query_pkey = c2_query_pkey;
818 dev->ibdev.query_gid = c2_query_gid;
819 dev->ibdev.alloc_ucontext = c2_alloc_ucontext;
820 dev->ibdev.dealloc_ucontext = c2_dealloc_ucontext;
821 dev->ibdev.mmap = c2_mmap_uar;
822 dev->ibdev.alloc_pd = c2_alloc_pd;
823 dev->ibdev.dealloc_pd = c2_dealloc_pd;
824 dev->ibdev.create_ah = c2_ah_create;
825 dev->ibdev.destroy_ah = c2_ah_destroy;
826 dev->ibdev.create_qp = c2_create_qp;
827 dev->ibdev.modify_qp = c2_modify_qp;
828 dev->ibdev.destroy_qp = c2_destroy_qp;
829 dev->ibdev.create_cq = c2_create_cq;
830 dev->ibdev.destroy_cq = c2_destroy_cq;
831 dev->ibdev.poll_cq = c2_poll_cq;
832 dev->ibdev.get_dma_mr = c2_get_dma_mr;
833 dev->ibdev.reg_phys_mr = c2_reg_phys_mr;
834 dev->ibdev.reg_user_mr = c2_reg_user_mr;
835 dev->ibdev.dereg_mr = c2_dereg_mr;
837 dev->ibdev.alloc_fmr = NULL;
838 dev->ibdev.unmap_fmr = NULL;
839 dev->ibdev.dealloc_fmr = NULL;
840 dev->ibdev.map_phys_fmr = NULL;
842 dev->ibdev.attach_mcast = c2_multicast_attach;
843 dev->ibdev.detach_mcast = c2_multicast_detach;
844 dev->ibdev.process_mad = c2_process_mad;
846 dev->ibdev.req_notify_cq = c2_arm_cq;
847 dev->ibdev.post_send = c2_post_send;
848 dev->ibdev.post_recv = c2_post_receive;
850 dev->ibdev.iwcm = kmalloc(sizeof(*dev->ibdev.iwcm), GFP_KERNEL);
851 dev->ibdev.iwcm->add_ref = c2_add_ref;
852 dev->ibdev.iwcm->rem_ref = c2_rem_ref;
853 dev->ibdev.iwcm->get_qp = c2_get_qp;
854 dev->ibdev.iwcm->connect = c2_connect;
855 dev->ibdev.iwcm->accept = c2_accept;
856 dev->ibdev.iwcm->reject = c2_reject;
857 dev->ibdev.iwcm->create_listen = c2_service_create;
858 dev->ibdev.iwcm->destroy_listen = c2_service_destroy;
860 ret = ib_register_device(&dev->ibdev);
864 for (i = 0; i < ARRAY_SIZE(c2_class_attributes); ++i) {
865 ret = class_device_create_file(&dev->ibdev.class_dev,
866 c2_class_attributes[i]);
873 ib_unregister_device(&dev->ibdev);
875 unregister_netdev(dev->pseudo_netdev);
877 free_netdev(dev->pseudo_netdev);
879 pr_debug("%s:%u ret=%d\n", __func__, __LINE__, ret);
883 void c2_unregister_device(struct c2_dev *dev)
885 pr_debug("%s:%u\n", __func__, __LINE__);
886 unregister_netdev(dev->pseudo_netdev);
887 free_netdev(dev->pseudo_netdev);
888 ib_unregister_device(&dev->ibdev);