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>
53 #include <linux/slab.h>
57 #include <asm/byteorder.h>
59 #include <rdma/ib_smi.h>
60 #include <rdma/ib_umem.h>
61 #include <rdma/ib_user_verbs.h>
63 #include "c2_provider.h"
66 static int c2_query_device(struct ib_device
*ibdev
,
67 struct ib_device_attr
*props
)
69 struct c2_dev
*c2dev
= to_c2dev(ibdev
);
71 pr_debug("%s:%u\n", __func__
, __LINE__
);
73 *props
= c2dev
->props
;
77 static int c2_query_port(struct ib_device
*ibdev
,
78 u8 port
, struct ib_port_attr
*props
)
80 pr_debug("%s:%u\n", __func__
, __LINE__
);
82 props
->max_mtu
= IB_MTU_4096
;
87 props
->state
= IB_PORT_ACTIVE
;
88 props
->phys_state
= 0;
89 props
->port_cap_flags
=
92 IB_PORT_VENDOR_CLASS_SUP
| IB_PORT_BOOT_MGMT_SUP
;
93 props
->gid_tbl_len
= 1;
94 props
->pkey_tbl_len
= 1;
95 props
->qkey_viol_cntr
= 0;
96 props
->active_width
= 1;
97 props
->active_speed
= 1;
102 static int c2_modify_port(struct ib_device
*ibdev
,
103 u8 port
, int port_modify_mask
,
104 struct ib_port_modify
*props
)
106 pr_debug("%s:%u\n", __func__
, __LINE__
);
110 static int c2_query_pkey(struct ib_device
*ibdev
,
111 u8 port
, u16 index
, u16
* pkey
)
113 pr_debug("%s:%u\n", __func__
, __LINE__
);
118 static int c2_query_gid(struct ib_device
*ibdev
, u8 port
,
119 int index
, union ib_gid
*gid
)
121 struct c2_dev
*c2dev
= to_c2dev(ibdev
);
123 pr_debug("%s:%u\n", __func__
, __LINE__
);
124 memset(&(gid
->raw
[0]), 0, sizeof(gid
->raw
));
125 memcpy(&(gid
->raw
[0]), c2dev
->pseudo_netdev
->dev_addr
, 6);
130 /* Allocate the user context data structure. This keeps track
131 * of all objects associated with a particular user-mode client.
133 static struct ib_ucontext
*c2_alloc_ucontext(struct ib_device
*ibdev
,
134 struct ib_udata
*udata
)
136 struct c2_ucontext
*context
;
138 pr_debug("%s:%u\n", __func__
, __LINE__
);
139 context
= kmalloc(sizeof(*context
), GFP_KERNEL
);
141 return ERR_PTR(-ENOMEM
);
143 return &context
->ibucontext
;
146 static int c2_dealloc_ucontext(struct ib_ucontext
*context
)
148 pr_debug("%s:%u\n", __func__
, __LINE__
);
153 static int c2_mmap_uar(struct ib_ucontext
*context
, struct vm_area_struct
*vma
)
155 pr_debug("%s:%u\n", __func__
, __LINE__
);
159 static struct ib_pd
*c2_alloc_pd(struct ib_device
*ibdev
,
160 struct ib_ucontext
*context
,
161 struct ib_udata
*udata
)
166 pr_debug("%s:%u\n", __func__
, __LINE__
);
168 pd
= kmalloc(sizeof(*pd
), GFP_KERNEL
);
170 return ERR_PTR(-ENOMEM
);
172 err
= c2_pd_alloc(to_c2dev(ibdev
), !context
, pd
);
179 if (ib_copy_to_udata(udata
, &pd
->pd_id
, sizeof(__u32
))) {
180 c2_pd_free(to_c2dev(ibdev
), pd
);
182 return ERR_PTR(-EFAULT
);
189 static int c2_dealloc_pd(struct ib_pd
*pd
)
191 pr_debug("%s:%u\n", __func__
, __LINE__
);
192 c2_pd_free(to_c2dev(pd
->device
), to_c2pd(pd
));
198 static struct ib_ah
*c2_ah_create(struct ib_pd
*pd
, struct ib_ah_attr
*ah_attr
)
200 pr_debug("%s:%u\n", __func__
, __LINE__
);
201 return ERR_PTR(-ENOSYS
);
204 static int c2_ah_destroy(struct ib_ah
*ah
)
206 pr_debug("%s:%u\n", __func__
, __LINE__
);
210 static void c2_add_ref(struct ib_qp
*ibqp
)
215 atomic_inc(&qp
->refcount
);
218 static void c2_rem_ref(struct ib_qp
*ibqp
)
223 if (atomic_dec_and_test(&qp
->refcount
))
227 struct ib_qp
*c2_get_qp(struct ib_device
*device
, int qpn
)
229 struct c2_dev
* c2dev
= to_c2dev(device
);
232 qp
= c2_find_qpn(c2dev
, qpn
);
233 pr_debug("%s Returning QP=%p for QPN=%d, device=%p, refcount=%d\n",
234 __func__
, qp
, qpn
, device
,
235 (qp
?atomic_read(&qp
->refcount
):0));
237 return (qp
?&qp
->ibqp
:NULL
);
240 static struct ib_qp
*c2_create_qp(struct ib_pd
*pd
,
241 struct ib_qp_init_attr
*init_attr
,
242 struct ib_udata
*udata
)
247 pr_debug("%s:%u\n", __func__
, __LINE__
);
249 if (init_attr
->create_flags
)
250 return ERR_PTR(-EINVAL
);
252 switch (init_attr
->qp_type
) {
254 qp
= kzalloc(sizeof(*qp
), GFP_KERNEL
);
256 pr_debug("%s: Unable to allocate QP\n", __func__
);
257 return ERR_PTR(-ENOMEM
);
259 spin_lock_init(&qp
->lock
);
261 /* userspace specific */
264 err
= c2_alloc_qp(to_c2dev(pd
->device
),
265 to_c2pd(pd
), init_attr
, qp
);
267 if (err
&& pd
->uobject
) {
268 /* userspace specific */
273 pr_debug("%s: Invalid QP type: %d\n", __func__
,
275 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
, 0);
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 device
*dev
, struct device_attribute
*attr
,
529 struct c2_dev
*c2dev
= container_of(dev
, struct c2_dev
, ibdev
.dev
);
530 pr_debug("%s:%u\n", __func__
, __LINE__
);
531 return sprintf(buf
, "%x\n", c2dev
->props
.hw_ver
);
534 static ssize_t
show_fw_ver(struct device
*dev
, struct device_attribute
*attr
,
537 struct c2_dev
*c2dev
= container_of(dev
, struct c2_dev
, ibdev
.dev
);
538 pr_debug("%s:%u\n", __func__
, __LINE__
);
539 return sprintf(buf
, "%x.%x.%x\n",
540 (int) (c2dev
->props
.fw_ver
>> 32),
541 (int) (c2dev
->props
.fw_ver
>> 16) & 0xffff,
542 (int) (c2dev
->props
.fw_ver
& 0xffff));
545 static ssize_t
show_hca(struct device
*dev
, struct device_attribute
*attr
,
548 pr_debug("%s:%u\n", __func__
, __LINE__
);
549 return sprintf(buf
, "AMSO1100\n");
552 static ssize_t
show_board(struct device
*dev
, struct device_attribute
*attr
,
555 pr_debug("%s:%u\n", __func__
, __LINE__
);
556 return sprintf(buf
, "%.*s\n", 32, "AMSO1100 Board ID");
559 static DEVICE_ATTR(hw_rev
, S_IRUGO
, show_rev
, NULL
);
560 static DEVICE_ATTR(fw_ver
, S_IRUGO
, show_fw_ver
, NULL
);
561 static DEVICE_ATTR(hca_type
, S_IRUGO
, show_hca
, NULL
);
562 static DEVICE_ATTR(board_id
, S_IRUGO
, show_board
, NULL
);
564 static struct device_attribute
*c2_dev_attributes
[] = {
571 static int c2_modify_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
572 int attr_mask
, struct ib_udata
*udata
)
577 c2_qp_modify(to_c2dev(ibqp
->device
), to_c2qp(ibqp
), attr
,
583 static int c2_multicast_attach(struct ib_qp
*ibqp
, union ib_gid
*gid
, u16 lid
)
585 pr_debug("%s:%u\n", __func__
, __LINE__
);
589 static int c2_multicast_detach(struct ib_qp
*ibqp
, union ib_gid
*gid
, u16 lid
)
591 pr_debug("%s:%u\n", __func__
, __LINE__
);
595 static int c2_process_mad(struct ib_device
*ibdev
,
599 struct ib_grh
*in_grh
,
600 struct ib_mad
*in_mad
, struct ib_mad
*out_mad
)
602 pr_debug("%s:%u\n", __func__
, __LINE__
);
606 static int c2_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*iw_param
)
608 pr_debug("%s:%u\n", __func__
, __LINE__
);
610 /* Request a connection */
611 return c2_llp_connect(cm_id
, iw_param
);
614 static int c2_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*iw_param
)
616 pr_debug("%s:%u\n", __func__
, __LINE__
);
618 /* Accept the new connection */
619 return c2_llp_accept(cm_id
, iw_param
);
622 static int c2_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
626 pr_debug("%s:%u\n", __func__
, __LINE__
);
628 err
= c2_llp_reject(cm_id
, pdata
, pdata_len
);
632 static int c2_service_create(struct iw_cm_id
*cm_id
, int backlog
)
636 pr_debug("%s:%u\n", __func__
, __LINE__
);
637 err
= c2_llp_service_create(cm_id
, backlog
);
638 pr_debug("%s:%u err=%d\n",
644 static int c2_service_destroy(struct iw_cm_id
*cm_id
)
647 pr_debug("%s:%u\n", __func__
, __LINE__
);
649 err
= c2_llp_service_destroy(cm_id
);
654 static int c2_pseudo_up(struct net_device
*netdev
)
656 struct in_device
*ind
;
657 struct c2_dev
*c2dev
= netdev
->ml_priv
;
659 ind
= in_dev_get(netdev
);
663 pr_debug("adding...\n");
666 u8
*ip
= (u8
*) & ifa
->ifa_address
;
668 pr_debug("%s: %d.%d.%d.%d\n",
669 ifa
->ifa_label
, ip
[0], ip
[1], ip
[2], ip
[3]);
671 c2_add_addr(c2dev
, ifa
->ifa_address
, ifa
->ifa_mask
);
679 static int c2_pseudo_down(struct net_device
*netdev
)
681 struct in_device
*ind
;
682 struct c2_dev
*c2dev
= netdev
->ml_priv
;
684 ind
= in_dev_get(netdev
);
688 pr_debug("deleting...\n");
691 u8
*ip
= (u8
*) & ifa
->ifa_address
;
693 pr_debug("%s: %d.%d.%d.%d\n",
694 ifa
->ifa_label
, ip
[0], ip
[1], ip
[2], ip
[3]);
696 c2_del_addr(c2dev
, ifa
->ifa_address
, ifa
->ifa_mask
);
704 static int c2_pseudo_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
710 static int c2_pseudo_change_mtu(struct net_device
*netdev
, int new_mtu
)
712 if (new_mtu
< ETH_ZLEN
|| new_mtu
> ETH_JUMBO_MTU
)
715 netdev
->mtu
= new_mtu
;
717 /* TODO: Tell rnic about new rmda interface mtu */
721 static const struct net_device_ops c2_pseudo_netdev_ops
= {
722 .ndo_open
= c2_pseudo_up
,
723 .ndo_stop
= c2_pseudo_down
,
724 .ndo_start_xmit
= c2_pseudo_xmit_frame
,
725 .ndo_change_mtu
= c2_pseudo_change_mtu
,
726 .ndo_validate_addr
= eth_validate_addr
,
729 static void setup(struct net_device
*netdev
)
731 netdev
->netdev_ops
= &c2_pseudo_netdev_ops
;
733 netdev
->watchdog_timeo
= 0;
734 netdev
->type
= ARPHRD_ETHER
;
736 netdev
->hard_header_len
= ETH_HLEN
;
737 netdev
->addr_len
= ETH_ALEN
;
738 netdev
->tx_queue_len
= 0;
739 netdev
->flags
|= IFF_NOARP
;
742 static struct net_device
*c2_pseudo_netdev_init(struct c2_dev
*c2dev
)
745 struct net_device
*netdev
;
747 /* change ethxxx to iwxxx */
749 strcat(name
, &c2dev
->netdev
->name
[3]);
750 netdev
= alloc_netdev(0, name
, setup
);
752 printk(KERN_ERR PFX
"%s - etherdev alloc failed",
757 netdev
->ml_priv
= c2dev
;
759 SET_NETDEV_DEV(netdev
, &c2dev
->pcidev
->dev
);
761 memcpy_fromio(netdev
->dev_addr
, c2dev
->kva
+ C2_REGS_RDMA_ENADDR
, 6);
763 /* Print out the MAC address */
764 pr_debug("%s: MAC %02X:%02X:%02X:%02X:%02X:%02X\n",
766 netdev
->dev_addr
[0], netdev
->dev_addr
[1], netdev
->dev_addr
[2],
767 netdev
->dev_addr
[3], netdev
->dev_addr
[4], netdev
->dev_addr
[5]);
770 /* Disable network packets */
771 netif_stop_queue(netdev
);
776 int c2_register_device(struct c2_dev
*dev
)
781 /* Register pseudo network device */
782 dev
->pseudo_netdev
= c2_pseudo_netdev_init(dev
);
783 if (!dev
->pseudo_netdev
)
786 ret
= register_netdev(dev
->pseudo_netdev
);
788 goto out_free_netdev
;
790 pr_debug("%s:%u\n", __func__
, __LINE__
);
791 strlcpy(dev
->ibdev
.name
, "amso%d", IB_DEVICE_NAME_MAX
);
792 dev
->ibdev
.owner
= THIS_MODULE
;
793 dev
->ibdev
.uverbs_cmd_mask
=
794 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT
) |
795 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE
) |
796 (1ull << IB_USER_VERBS_CMD_QUERY_PORT
) |
797 (1ull << IB_USER_VERBS_CMD_ALLOC_PD
) |
798 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD
) |
799 (1ull << IB_USER_VERBS_CMD_REG_MR
) |
800 (1ull << IB_USER_VERBS_CMD_DEREG_MR
) |
801 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL
) |
802 (1ull << IB_USER_VERBS_CMD_CREATE_CQ
) |
803 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ
) |
804 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ
) |
805 (1ull << IB_USER_VERBS_CMD_CREATE_QP
) |
806 (1ull << IB_USER_VERBS_CMD_MODIFY_QP
) |
807 (1ull << IB_USER_VERBS_CMD_POLL_CQ
) |
808 (1ull << IB_USER_VERBS_CMD_DESTROY_QP
) |
809 (1ull << IB_USER_VERBS_CMD_POST_SEND
) |
810 (1ull << IB_USER_VERBS_CMD_POST_RECV
);
812 dev
->ibdev
.node_type
= RDMA_NODE_RNIC
;
813 memset(&dev
->ibdev
.node_guid
, 0, sizeof(dev
->ibdev
.node_guid
));
814 memcpy(&dev
->ibdev
.node_guid
, dev
->pseudo_netdev
->dev_addr
, 6);
815 dev
->ibdev
.phys_port_cnt
= 1;
816 dev
->ibdev
.num_comp_vectors
= 1;
817 dev
->ibdev
.dma_device
= &dev
->pcidev
->dev
;
818 dev
->ibdev
.query_device
= c2_query_device
;
819 dev
->ibdev
.query_port
= c2_query_port
;
820 dev
->ibdev
.modify_port
= c2_modify_port
;
821 dev
->ibdev
.query_pkey
= c2_query_pkey
;
822 dev
->ibdev
.query_gid
= c2_query_gid
;
823 dev
->ibdev
.alloc_ucontext
= c2_alloc_ucontext
;
824 dev
->ibdev
.dealloc_ucontext
= c2_dealloc_ucontext
;
825 dev
->ibdev
.mmap
= c2_mmap_uar
;
826 dev
->ibdev
.alloc_pd
= c2_alloc_pd
;
827 dev
->ibdev
.dealloc_pd
= c2_dealloc_pd
;
828 dev
->ibdev
.create_ah
= c2_ah_create
;
829 dev
->ibdev
.destroy_ah
= c2_ah_destroy
;
830 dev
->ibdev
.create_qp
= c2_create_qp
;
831 dev
->ibdev
.modify_qp
= c2_modify_qp
;
832 dev
->ibdev
.destroy_qp
= c2_destroy_qp
;
833 dev
->ibdev
.create_cq
= c2_create_cq
;
834 dev
->ibdev
.destroy_cq
= c2_destroy_cq
;
835 dev
->ibdev
.poll_cq
= c2_poll_cq
;
836 dev
->ibdev
.get_dma_mr
= c2_get_dma_mr
;
837 dev
->ibdev
.reg_phys_mr
= c2_reg_phys_mr
;
838 dev
->ibdev
.reg_user_mr
= c2_reg_user_mr
;
839 dev
->ibdev
.dereg_mr
= c2_dereg_mr
;
841 dev
->ibdev
.alloc_fmr
= NULL
;
842 dev
->ibdev
.unmap_fmr
= NULL
;
843 dev
->ibdev
.dealloc_fmr
= NULL
;
844 dev
->ibdev
.map_phys_fmr
= NULL
;
846 dev
->ibdev
.attach_mcast
= c2_multicast_attach
;
847 dev
->ibdev
.detach_mcast
= c2_multicast_detach
;
848 dev
->ibdev
.process_mad
= c2_process_mad
;
850 dev
->ibdev
.req_notify_cq
= c2_arm_cq
;
851 dev
->ibdev
.post_send
= c2_post_send
;
852 dev
->ibdev
.post_recv
= c2_post_receive
;
854 dev
->ibdev
.iwcm
= kmalloc(sizeof(*dev
->ibdev
.iwcm
), GFP_KERNEL
);
855 if (dev
->ibdev
.iwcm
== NULL
) {
857 goto out_unregister_netdev
;
859 dev
->ibdev
.iwcm
->add_ref
= c2_add_ref
;
860 dev
->ibdev
.iwcm
->rem_ref
= c2_rem_ref
;
861 dev
->ibdev
.iwcm
->get_qp
= c2_get_qp
;
862 dev
->ibdev
.iwcm
->connect
= c2_connect
;
863 dev
->ibdev
.iwcm
->accept
= c2_accept
;
864 dev
->ibdev
.iwcm
->reject
= c2_reject
;
865 dev
->ibdev
.iwcm
->create_listen
= c2_service_create
;
866 dev
->ibdev
.iwcm
->destroy_listen
= c2_service_destroy
;
868 ret
= ib_register_device(&dev
->ibdev
, NULL
);
872 for (i
= 0; i
< ARRAY_SIZE(c2_dev_attributes
); ++i
) {
873 ret
= device_create_file(&dev
->ibdev
.dev
,
874 c2_dev_attributes
[i
]);
876 goto out_unregister_ibdev
;
880 out_unregister_ibdev
:
881 ib_unregister_device(&dev
->ibdev
);
883 kfree(dev
->ibdev
.iwcm
);
884 out_unregister_netdev
:
885 unregister_netdev(dev
->pseudo_netdev
);
887 free_netdev(dev
->pseudo_netdev
);
889 pr_debug("%s:%u ret=%d\n", __func__
, __LINE__
, ret
);
893 void c2_unregister_device(struct c2_dev
*dev
)
895 pr_debug("%s:%u\n", __func__
, __LINE__
);
896 unregister_netdev(dev
->pseudo_netdev
);
897 free_netdev(dev
->pseudo_netdev
);
898 ib_unregister_device(&dev
->ibdev
);