2 * Copyright (c) 2006, 2007 Cisco Systems, 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
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/errno.h>
37 #include <rdma/ib_smi.h>
38 #include <rdma/ib_user_verbs.h>
40 #include <linux/mlx4/driver.h>
41 #include <linux/mlx4/cmd.h>
46 #define DRV_NAME "mlx4_ib"
47 #define DRV_VERSION "0.01"
48 #define DRV_RELDATE "May 1, 2006"
50 MODULE_AUTHOR("Roland Dreier");
51 MODULE_DESCRIPTION("Mellanox ConnectX HCA InfiniBand driver");
52 MODULE_LICENSE("Dual BSD/GPL");
53 MODULE_VERSION(DRV_VERSION
);
55 static const char mlx4_ib_version
[] __devinitdata
=
56 DRV_NAME
": Mellanox ConnectX InfiniBand driver v"
57 DRV_VERSION
" (" DRV_RELDATE
")\n";
59 static void init_query_mad(struct ib_smp
*mad
)
61 mad
->base_version
= 1;
62 mad
->mgmt_class
= IB_MGMT_CLASS_SUBN_LID_ROUTED
;
63 mad
->class_version
= 1;
64 mad
->method
= IB_MGMT_METHOD_GET
;
67 static int mlx4_ib_query_device(struct ib_device
*ibdev
,
68 struct ib_device_attr
*props
)
70 struct mlx4_ib_dev
*dev
= to_mdev(ibdev
);
71 struct ib_smp
*in_mad
= NULL
;
72 struct ib_smp
*out_mad
= NULL
;
75 in_mad
= kzalloc(sizeof *in_mad
, GFP_KERNEL
);
76 out_mad
= kmalloc(sizeof *out_mad
, GFP_KERNEL
);
77 if (!in_mad
|| !out_mad
)
80 init_query_mad(in_mad
);
81 in_mad
->attr_id
= IB_SMP_ATTR_NODE_INFO
;
83 err
= mlx4_MAD_IFC(to_mdev(ibdev
), 1, 1, 1, NULL
, NULL
, in_mad
, out_mad
);
87 memset(props
, 0, sizeof *props
);
89 props
->fw_ver
= dev
->dev
->caps
.fw_ver
;
90 props
->device_cap_flags
= IB_DEVICE_CHANGE_PHY_PORT
|
91 IB_DEVICE_PORT_ACTIVE_EVENT
|
92 IB_DEVICE_SYS_IMAGE_GUID
|
93 IB_DEVICE_RC_RNR_NAK_GEN
;
94 if (dev
->dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_BAD_PKEY_CNTR
)
95 props
->device_cap_flags
|= IB_DEVICE_BAD_PKEY_CNTR
;
96 if (dev
->dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_BAD_QKEY_CNTR
)
97 props
->device_cap_flags
|= IB_DEVICE_BAD_QKEY_CNTR
;
98 if (dev
->dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_APM
)
99 props
->device_cap_flags
|= IB_DEVICE_AUTO_PATH_MIG
;
100 if (dev
->dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_UD_AV_PORT
)
101 props
->device_cap_flags
|= IB_DEVICE_UD_AV_PORT_ENFORCE
;
103 props
->vendor_id
= be32_to_cpup((__be32
*) (out_mad
->data
+ 36)) &
105 props
->vendor_part_id
= be16_to_cpup((__be16
*) (out_mad
->data
+ 30));
106 props
->hw_ver
= be32_to_cpup((__be32
*) (out_mad
->data
+ 32));
107 memcpy(&props
->sys_image_guid
, out_mad
->data
+ 4, 8);
109 props
->max_mr_size
= ~0ull;
110 props
->page_size_cap
= dev
->dev
->caps
.page_size_cap
;
111 props
->max_qp
= dev
->dev
->caps
.num_qps
- dev
->dev
->caps
.reserved_qps
;
112 props
->max_qp_wr
= dev
->dev
->caps
.max_wqes
;
113 props
->max_sge
= min(dev
->dev
->caps
.max_sq_sg
,
114 dev
->dev
->caps
.max_rq_sg
);
115 props
->max_cq
= dev
->dev
->caps
.num_cqs
- dev
->dev
->caps
.reserved_cqs
;
116 props
->max_cqe
= dev
->dev
->caps
.max_cqes
;
117 props
->max_mr
= dev
->dev
->caps
.num_mpts
- dev
->dev
->caps
.reserved_mrws
;
118 props
->max_pd
= dev
->dev
->caps
.num_pds
- dev
->dev
->caps
.reserved_pds
;
119 props
->max_qp_rd_atom
= dev
->dev
->caps
.max_qp_dest_rdma
;
120 props
->max_qp_init_rd_atom
= dev
->dev
->caps
.max_qp_init_rdma
;
121 props
->max_res_rd_atom
= props
->max_qp_rd_atom
* props
->max_qp
;
122 props
->max_srq
= dev
->dev
->caps
.num_srqs
- dev
->dev
->caps
.reserved_srqs
;
123 props
->max_srq_wr
= dev
->dev
->caps
.max_srq_wqes
;
124 props
->max_srq_sge
= dev
->dev
->caps
.max_srq_sge
;
125 props
->local_ca_ack_delay
= dev
->dev
->caps
.local_ca_ack_delay
;
126 props
->atomic_cap
= dev
->dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_ATOMIC
?
127 IB_ATOMIC_HCA
: IB_ATOMIC_NONE
;
128 props
->max_pkeys
= dev
->dev
->caps
.pkey_table_len
;
129 props
->max_mcast_grp
= dev
->dev
->caps
.num_mgms
+ dev
->dev
->caps
.num_amgms
;
130 props
->max_mcast_qp_attach
= dev
->dev
->caps
.num_qp_per_mgm
;
131 props
->max_total_mcast_qp_attach
= props
->max_mcast_qp_attach
*
132 props
->max_mcast_grp
;
133 props
->max_map_per_fmr
= (1 << (32 - ilog2(dev
->dev
->caps
.num_mpts
))) - 1;
142 static int mlx4_ib_query_port(struct ib_device
*ibdev
, u8 port
,
143 struct ib_port_attr
*props
)
145 struct ib_smp
*in_mad
= NULL
;
146 struct ib_smp
*out_mad
= NULL
;
149 in_mad
= kzalloc(sizeof *in_mad
, GFP_KERNEL
);
150 out_mad
= kmalloc(sizeof *out_mad
, GFP_KERNEL
);
151 if (!in_mad
|| !out_mad
)
154 memset(props
, 0, sizeof *props
);
156 init_query_mad(in_mad
);
157 in_mad
->attr_id
= IB_SMP_ATTR_PORT_INFO
;
158 in_mad
->attr_mod
= cpu_to_be32(port
);
160 err
= mlx4_MAD_IFC(to_mdev(ibdev
), 1, 1, port
, NULL
, NULL
, in_mad
, out_mad
);
164 props
->lid
= be16_to_cpup((__be16
*) (out_mad
->data
+ 16));
165 props
->lmc
= out_mad
->data
[34] & 0x7;
166 props
->sm_lid
= be16_to_cpup((__be16
*) (out_mad
->data
+ 18));
167 props
->sm_sl
= out_mad
->data
[36] & 0xf;
168 props
->state
= out_mad
->data
[32] & 0xf;
169 props
->phys_state
= out_mad
->data
[33] >> 4;
170 props
->port_cap_flags
= be32_to_cpup((__be32
*) (out_mad
->data
+ 20));
171 props
->gid_tbl_len
= to_mdev(ibdev
)->dev
->caps
.gid_table_len
;
172 props
->max_msg_sz
= 0x80000000;
173 props
->pkey_tbl_len
= to_mdev(ibdev
)->dev
->caps
.pkey_table_len
;
174 props
->bad_pkey_cntr
= be16_to_cpup((__be16
*) (out_mad
->data
+ 46));
175 props
->qkey_viol_cntr
= be16_to_cpup((__be16
*) (out_mad
->data
+ 48));
176 props
->active_width
= out_mad
->data
[31] & 0xf;
177 props
->active_speed
= out_mad
->data
[35] >> 4;
178 props
->max_mtu
= out_mad
->data
[41] & 0xf;
179 props
->active_mtu
= out_mad
->data
[36] >> 4;
180 props
->subnet_timeout
= out_mad
->data
[51] & 0x1f;
181 props
->max_vl_num
= out_mad
->data
[37] >> 4;
182 props
->init_type_reply
= out_mad
->data
[41] >> 4;
191 static int mlx4_ib_query_gid(struct ib_device
*ibdev
, u8 port
, int index
,
194 struct ib_smp
*in_mad
= NULL
;
195 struct ib_smp
*out_mad
= NULL
;
198 in_mad
= kzalloc(sizeof *in_mad
, GFP_KERNEL
);
199 out_mad
= kmalloc(sizeof *out_mad
, GFP_KERNEL
);
200 if (!in_mad
|| !out_mad
)
203 init_query_mad(in_mad
);
204 in_mad
->attr_id
= IB_SMP_ATTR_PORT_INFO
;
205 in_mad
->attr_mod
= cpu_to_be32(port
);
207 err
= mlx4_MAD_IFC(to_mdev(ibdev
), 1, 1, port
, NULL
, NULL
, in_mad
, out_mad
);
211 memcpy(gid
->raw
, out_mad
->data
+ 8, 8);
213 init_query_mad(in_mad
);
214 in_mad
->attr_id
= IB_SMP_ATTR_GUID_INFO
;
215 in_mad
->attr_mod
= cpu_to_be32(index
/ 8);
217 err
= mlx4_MAD_IFC(to_mdev(ibdev
), 1, 1, port
, NULL
, NULL
, in_mad
, out_mad
);
221 memcpy(gid
->raw
+ 8, out_mad
->data
+ (index
% 8) * 8, 8);
229 static int mlx4_ib_query_pkey(struct ib_device
*ibdev
, u8 port
, u16 index
,
232 struct ib_smp
*in_mad
= NULL
;
233 struct ib_smp
*out_mad
= NULL
;
236 in_mad
= kzalloc(sizeof *in_mad
, GFP_KERNEL
);
237 out_mad
= kmalloc(sizeof *out_mad
, GFP_KERNEL
);
238 if (!in_mad
|| !out_mad
)
241 init_query_mad(in_mad
);
242 in_mad
->attr_id
= IB_SMP_ATTR_PKEY_TABLE
;
243 in_mad
->attr_mod
= cpu_to_be32(index
/ 32);
245 err
= mlx4_MAD_IFC(to_mdev(ibdev
), 1, 1, port
, NULL
, NULL
, in_mad
, out_mad
);
249 *pkey
= be16_to_cpu(((__be16
*) out_mad
->data
)[index
% 32]);
257 static int mlx4_ib_modify_device(struct ib_device
*ibdev
, int mask
,
258 struct ib_device_modify
*props
)
260 if (mask
& ~IB_DEVICE_MODIFY_NODE_DESC
)
263 if (mask
& IB_DEVICE_MODIFY_NODE_DESC
) {
264 spin_lock(&to_mdev(ibdev
)->sm_lock
);
265 memcpy(ibdev
->node_desc
, props
->node_desc
, 64);
266 spin_unlock(&to_mdev(ibdev
)->sm_lock
);
272 static int mlx4_SET_PORT(struct mlx4_ib_dev
*dev
, u8 port
, int reset_qkey_viols
,
275 struct mlx4_cmd_mailbox
*mailbox
;
278 mailbox
= mlx4_alloc_cmd_mailbox(dev
->dev
);
280 return PTR_ERR(mailbox
);
282 memset(mailbox
->buf
, 0, 256);
283 *(u8
*) mailbox
->buf
= !!reset_qkey_viols
<< 6;
284 ((__be32
*) mailbox
->buf
)[2] = cpu_to_be32(cap_mask
);
286 err
= mlx4_cmd(dev
->dev
, mailbox
->dma
, port
, 0, MLX4_CMD_SET_PORT
,
287 MLX4_CMD_TIME_CLASS_B
);
289 mlx4_free_cmd_mailbox(dev
->dev
, mailbox
);
293 static int mlx4_ib_modify_port(struct ib_device
*ibdev
, u8 port
, int mask
,
294 struct ib_port_modify
*props
)
296 struct ib_port_attr attr
;
300 mutex_lock(&to_mdev(ibdev
)->cap_mask_mutex
);
302 err
= mlx4_ib_query_port(ibdev
, port
, &attr
);
306 cap_mask
= (attr
.port_cap_flags
| props
->set_port_cap_mask
) &
307 ~props
->clr_port_cap_mask
;
309 err
= mlx4_SET_PORT(to_mdev(ibdev
), port
,
310 !!(mask
& IB_PORT_RESET_QKEY_CNTR
),
314 mutex_unlock(&to_mdev(ibdev
)->cap_mask_mutex
);
318 static struct ib_ucontext
*mlx4_ib_alloc_ucontext(struct ib_device
*ibdev
,
319 struct ib_udata
*udata
)
321 struct mlx4_ib_dev
*dev
= to_mdev(ibdev
);
322 struct mlx4_ib_ucontext
*context
;
323 struct mlx4_ib_alloc_ucontext_resp resp
;
326 resp
.qp_tab_size
= dev
->dev
->caps
.num_qps
;
327 resp
.bf_reg_size
= dev
->dev
->caps
.bf_reg_size
;
328 resp
.bf_regs_per_page
= dev
->dev
->caps
.bf_regs_per_page
;
330 context
= kmalloc(sizeof *context
, GFP_KERNEL
);
332 return ERR_PTR(-ENOMEM
);
334 err
= mlx4_uar_alloc(to_mdev(ibdev
)->dev
, &context
->uar
);
340 INIT_LIST_HEAD(&context
->db_page_list
);
341 mutex_init(&context
->db_page_mutex
);
343 err
= ib_copy_to_udata(udata
, &resp
, sizeof resp
);
345 mlx4_uar_free(to_mdev(ibdev
)->dev
, &context
->uar
);
347 return ERR_PTR(-EFAULT
);
350 return &context
->ibucontext
;
353 static int mlx4_ib_dealloc_ucontext(struct ib_ucontext
*ibcontext
)
355 struct mlx4_ib_ucontext
*context
= to_mucontext(ibcontext
);
357 mlx4_uar_free(to_mdev(ibcontext
->device
)->dev
, &context
->uar
);
363 static int mlx4_ib_mmap(struct ib_ucontext
*context
, struct vm_area_struct
*vma
)
365 struct mlx4_ib_dev
*dev
= to_mdev(context
->device
);
367 if (vma
->vm_end
- vma
->vm_start
!= PAGE_SIZE
)
370 if (vma
->vm_pgoff
== 0) {
371 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
373 if (io_remap_pfn_range(vma
, vma
->vm_start
,
374 to_mucontext(context
)->uar
.pfn
,
375 PAGE_SIZE
, vma
->vm_page_prot
))
377 } else if (vma
->vm_pgoff
== 1 && dev
->dev
->caps
.bf_reg_size
!= 0) {
378 /* FIXME want pgprot_writecombine() for BlueFlame pages */
379 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
381 if (io_remap_pfn_range(vma
, vma
->vm_start
,
382 to_mucontext(context
)->uar
.pfn
+
383 dev
->dev
->caps
.num_uars
,
384 PAGE_SIZE
, vma
->vm_page_prot
))
392 static struct ib_pd
*mlx4_ib_alloc_pd(struct ib_device
*ibdev
,
393 struct ib_ucontext
*context
,
394 struct ib_udata
*udata
)
396 struct mlx4_ib_pd
*pd
;
399 pd
= kmalloc(sizeof *pd
, GFP_KERNEL
);
401 return ERR_PTR(-ENOMEM
);
403 err
= mlx4_pd_alloc(to_mdev(ibdev
)->dev
, &pd
->pdn
);
410 if (ib_copy_to_udata(udata
, &pd
->pdn
, sizeof (__u32
))) {
411 mlx4_pd_free(to_mdev(ibdev
)->dev
, pd
->pdn
);
413 return ERR_PTR(-EFAULT
);
419 static int mlx4_ib_dealloc_pd(struct ib_pd
*pd
)
421 mlx4_pd_free(to_mdev(pd
->device
)->dev
, to_mpd(pd
)->pdn
);
427 static int mlx4_ib_mcg_attach(struct ib_qp
*ibqp
, union ib_gid
*gid
, u16 lid
)
429 return mlx4_multicast_attach(to_mdev(ibqp
->device
)->dev
,
430 &to_mqp(ibqp
)->mqp
, gid
->raw
);
433 static int mlx4_ib_mcg_detach(struct ib_qp
*ibqp
, union ib_gid
*gid
, u16 lid
)
435 return mlx4_multicast_detach(to_mdev(ibqp
->device
)->dev
,
436 &to_mqp(ibqp
)->mqp
, gid
->raw
);
439 static int init_node_data(struct mlx4_ib_dev
*dev
)
441 struct ib_smp
*in_mad
= NULL
;
442 struct ib_smp
*out_mad
= NULL
;
445 in_mad
= kzalloc(sizeof *in_mad
, GFP_KERNEL
);
446 out_mad
= kmalloc(sizeof *out_mad
, GFP_KERNEL
);
447 if (!in_mad
|| !out_mad
)
450 init_query_mad(in_mad
);
451 in_mad
->attr_id
= IB_SMP_ATTR_NODE_DESC
;
453 err
= mlx4_MAD_IFC(dev
, 1, 1, 1, NULL
, NULL
, in_mad
, out_mad
);
457 memcpy(dev
->ib_dev
.node_desc
, out_mad
->data
, 64);
459 in_mad
->attr_id
= IB_SMP_ATTR_NODE_INFO
;
461 err
= mlx4_MAD_IFC(dev
, 1, 1, 1, NULL
, NULL
, in_mad
, out_mad
);
465 memcpy(&dev
->ib_dev
.node_guid
, out_mad
->data
+ 12, 8);
473 static void *mlx4_ib_add(struct mlx4_dev
*dev
)
475 struct mlx4_ib_dev
*ibdev
;
477 ibdev
= (struct mlx4_ib_dev
*) ib_alloc_device(sizeof *ibdev
);
479 dev_err(&dev
->pdev
->dev
, "Device struct alloc failed\n");
483 if (mlx4_pd_alloc(dev
, &ibdev
->priv_pdn
))
486 if (mlx4_uar_alloc(dev
, &ibdev
->priv_uar
))
489 ibdev
->uar_map
= ioremap(ibdev
->priv_uar
.pfn
<< PAGE_SHIFT
, PAGE_SIZE
);
493 INIT_LIST_HEAD(&ibdev
->pgdir_list
);
494 mutex_init(&ibdev
->pgdir_mutex
);
498 strlcpy(ibdev
->ib_dev
.name
, "mlx4_%d", IB_DEVICE_NAME_MAX
);
499 ibdev
->ib_dev
.owner
= THIS_MODULE
;
500 ibdev
->ib_dev
.node_type
= RDMA_NODE_IB_CA
;
501 ibdev
->ib_dev
.phys_port_cnt
= dev
->caps
.num_ports
;
502 ibdev
->ib_dev
.num_comp_vectors
= 1;
503 ibdev
->ib_dev
.dma_device
= &dev
->pdev
->dev
;
505 ibdev
->ib_dev
.uverbs_abi_ver
= MLX4_IB_UVERBS_ABI_VERSION
;
506 ibdev
->ib_dev
.uverbs_cmd_mask
=
507 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT
) |
508 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE
) |
509 (1ull << IB_USER_VERBS_CMD_QUERY_PORT
) |
510 (1ull << IB_USER_VERBS_CMD_ALLOC_PD
) |
511 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD
) |
512 (1ull << IB_USER_VERBS_CMD_REG_MR
) |
513 (1ull << IB_USER_VERBS_CMD_DEREG_MR
) |
514 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL
) |
515 (1ull << IB_USER_VERBS_CMD_CREATE_CQ
) |
516 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ
) |
517 (1ull << IB_USER_VERBS_CMD_CREATE_QP
) |
518 (1ull << IB_USER_VERBS_CMD_MODIFY_QP
) |
519 (1ull << IB_USER_VERBS_CMD_DESTROY_QP
) |
520 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST
) |
521 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST
) |
522 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ
) |
523 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ
) |
524 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ
);
526 ibdev
->ib_dev
.query_device
= mlx4_ib_query_device
;
527 ibdev
->ib_dev
.query_port
= mlx4_ib_query_port
;
528 ibdev
->ib_dev
.query_gid
= mlx4_ib_query_gid
;
529 ibdev
->ib_dev
.query_pkey
= mlx4_ib_query_pkey
;
530 ibdev
->ib_dev
.modify_device
= mlx4_ib_modify_device
;
531 ibdev
->ib_dev
.modify_port
= mlx4_ib_modify_port
;
532 ibdev
->ib_dev
.alloc_ucontext
= mlx4_ib_alloc_ucontext
;
533 ibdev
->ib_dev
.dealloc_ucontext
= mlx4_ib_dealloc_ucontext
;
534 ibdev
->ib_dev
.mmap
= mlx4_ib_mmap
;
535 ibdev
->ib_dev
.alloc_pd
= mlx4_ib_alloc_pd
;
536 ibdev
->ib_dev
.dealloc_pd
= mlx4_ib_dealloc_pd
;
537 ibdev
->ib_dev
.create_ah
= mlx4_ib_create_ah
;
538 ibdev
->ib_dev
.query_ah
= mlx4_ib_query_ah
;
539 ibdev
->ib_dev
.destroy_ah
= mlx4_ib_destroy_ah
;
540 ibdev
->ib_dev
.create_srq
= mlx4_ib_create_srq
;
541 ibdev
->ib_dev
.modify_srq
= mlx4_ib_modify_srq
;
542 ibdev
->ib_dev
.destroy_srq
= mlx4_ib_destroy_srq
;
543 ibdev
->ib_dev
.post_srq_recv
= mlx4_ib_post_srq_recv
;
544 ibdev
->ib_dev
.create_qp
= mlx4_ib_create_qp
;
545 ibdev
->ib_dev
.modify_qp
= mlx4_ib_modify_qp
;
546 ibdev
->ib_dev
.destroy_qp
= mlx4_ib_destroy_qp
;
547 ibdev
->ib_dev
.post_send
= mlx4_ib_post_send
;
548 ibdev
->ib_dev
.post_recv
= mlx4_ib_post_recv
;
549 ibdev
->ib_dev
.create_cq
= mlx4_ib_create_cq
;
550 ibdev
->ib_dev
.destroy_cq
= mlx4_ib_destroy_cq
;
551 ibdev
->ib_dev
.poll_cq
= mlx4_ib_poll_cq
;
552 ibdev
->ib_dev
.req_notify_cq
= mlx4_ib_arm_cq
;
553 ibdev
->ib_dev
.get_dma_mr
= mlx4_ib_get_dma_mr
;
554 ibdev
->ib_dev
.reg_user_mr
= mlx4_ib_reg_user_mr
;
555 ibdev
->ib_dev
.dereg_mr
= mlx4_ib_dereg_mr
;
556 ibdev
->ib_dev
.attach_mcast
= mlx4_ib_mcg_attach
;
557 ibdev
->ib_dev
.detach_mcast
= mlx4_ib_mcg_detach
;
558 ibdev
->ib_dev
.process_mad
= mlx4_ib_process_mad
;
560 if (init_node_data(ibdev
))
563 spin_lock_init(&ibdev
->sm_lock
);
564 mutex_init(&ibdev
->cap_mask_mutex
);
566 if (ib_register_device(&ibdev
->ib_dev
))
569 if (mlx4_ib_mad_init(ibdev
))
575 ib_unregister_device(&ibdev
->ib_dev
);
578 iounmap(ibdev
->uar_map
);
581 mlx4_uar_free(dev
, &ibdev
->priv_uar
);
584 mlx4_pd_free(dev
, ibdev
->priv_pdn
);
587 ib_dealloc_device(&ibdev
->ib_dev
);
592 static void mlx4_ib_remove(struct mlx4_dev
*dev
, void *ibdev_ptr
)
594 struct mlx4_ib_dev
*ibdev
= ibdev_ptr
;
597 for (p
= 1; p
<= dev
->caps
.num_ports
; ++p
)
598 mlx4_CLOSE_PORT(dev
, p
);
600 mlx4_ib_mad_cleanup(ibdev
);
601 ib_unregister_device(&ibdev
->ib_dev
);
602 iounmap(ibdev
->uar_map
);
603 mlx4_uar_free(dev
, &ibdev
->priv_uar
);
604 mlx4_pd_free(dev
, ibdev
->priv_pdn
);
605 ib_dealloc_device(&ibdev
->ib_dev
);
608 static void mlx4_ib_event(struct mlx4_dev
*dev
, void *ibdev_ptr
,
609 enum mlx4_dev_event event
, int subtype
,
612 struct ib_event ibev
;
615 case MLX4_EVENT_TYPE_PORT_CHANGE
:
616 ibev
.event
= subtype
== MLX4_PORT_CHANGE_SUBTYPE_ACTIVE
?
617 IB_EVENT_PORT_ACTIVE
: IB_EVENT_PORT_ERR
;
620 case MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR
:
621 ibev
.event
= IB_EVENT_DEVICE_FATAL
;
628 ibev
.device
= ibdev_ptr
;
629 ibev
.element
.port_num
= port
;
631 ib_dispatch_event(&ibev
);
634 static struct mlx4_interface mlx4_ib_interface
= {
636 .remove
= mlx4_ib_remove
,
637 .event
= mlx4_ib_event
640 static int __init
mlx4_ib_init(void)
642 return mlx4_register_interface(&mlx4_ib_interface
);
645 static void __exit
mlx4_ib_cleanup(void)
647 mlx4_unregister_interface(&mlx4_ib_interface
);
650 module_init(mlx4_ib_init
);
651 module_exit(mlx4_ib_cleanup
);