]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/infiniband/hw/mlx4/main.c
IB/ib_mthca: Pre-link receive WQEs in Tavor mode
[net-next-2.6.git] / drivers / infiniband / hw / mlx4 / main.c
CommitLineData
225c7b1f
RD
1/*
2 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
3 *
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:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
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.
22 *
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.
31 */
32
33#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/errno.h>
36
37#include <rdma/ib_smi.h>
38#include <rdma/ib_user_verbs.h>
39
40#include <linux/mlx4/driver.h>
41#include <linux/mlx4/cmd.h>
42
43#include "mlx4_ib.h"
44#include "user.h"
45
46#define DRV_NAME "mlx4_ib"
47#define DRV_VERSION "0.01"
48#define DRV_RELDATE "May 1, 2006"
49
50MODULE_AUTHOR("Roland Dreier");
51MODULE_DESCRIPTION("Mellanox ConnectX HCA InfiniBand driver");
52MODULE_LICENSE("Dual BSD/GPL");
53MODULE_VERSION(DRV_VERSION);
54
55static const char mlx4_ib_version[] __devinitdata =
56 DRV_NAME ": Mellanox ConnectX InfiniBand driver v"
57 DRV_VERSION " (" DRV_RELDATE ")\n";
58
59static void init_query_mad(struct ib_smp *mad)
60{
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;
65}
66
67static int mlx4_ib_query_device(struct ib_device *ibdev,
68 struct ib_device_attr *props)
69{
70 struct mlx4_ib_dev *dev = to_mdev(ibdev);
71 struct ib_smp *in_mad = NULL;
72 struct ib_smp *out_mad = NULL;
73 int err = -ENOMEM;
74
75 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
76 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
77 if (!in_mad || !out_mad)
78 goto out;
79
80 init_query_mad(in_mad);
81 in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
82
83 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, 1, NULL, NULL, in_mad, out_mad);
84 if (err)
85 goto out;
86
87 memset(props, 0, sizeof *props);
88
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;
102
103 props->vendor_id = be32_to_cpup((__be32 *) (out_mad->data + 36)) &
104 0xffffff;
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);
108
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;
c8681f14 123 props->max_srq_wr = dev->dev->caps.max_srq_wqes - 1;
225c7b1f
RD
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;
5ae2a7a8 128 props->max_pkeys = dev->dev->caps.pkey_table_len[1];
225c7b1f
RD
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;
134
135out:
136 kfree(in_mad);
137 kfree(out_mad);
138
139 return err;
140}
141
142static int mlx4_ib_query_port(struct ib_device *ibdev, u8 port,
143 struct ib_port_attr *props)
144{
145 struct ib_smp *in_mad = NULL;
146 struct ib_smp *out_mad = NULL;
147 int err = -ENOMEM;
148
149 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
150 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
151 if (!in_mad || !out_mad)
152 goto out;
153
154 memset(props, 0, sizeof *props);
155
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);
159
160 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
161 if (err)
162 goto out;
163
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));
5ae2a7a8 171 props->gid_tbl_len = to_mdev(ibdev)->dev->caps.gid_table_len[port];
149983af 172 props->max_msg_sz = to_mdev(ibdev)->dev->caps.max_msg_sz;
5ae2a7a8 173 props->pkey_tbl_len = to_mdev(ibdev)->dev->caps.pkey_table_len[port];
225c7b1f
RD
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;
183
184out:
185 kfree(in_mad);
186 kfree(out_mad);
187
188 return err;
189}
190
191static int mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
192 union ib_gid *gid)
193{
194 struct ib_smp *in_mad = NULL;
195 struct ib_smp *out_mad = NULL;
196 int err = -ENOMEM;
197
198 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
199 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
200 if (!in_mad || !out_mad)
201 goto out;
202
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);
206
207 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
208 if (err)
209 goto out;
210
211 memcpy(gid->raw, out_mad->data + 8, 8);
212
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);
216
217 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
218 if (err)
219 goto out;
220
221 memcpy(gid->raw + 8, out_mad->data + (index % 8) * 8, 8);
222
223out:
224 kfree(in_mad);
225 kfree(out_mad);
226 return err;
227}
228
229static int mlx4_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
230 u16 *pkey)
231{
232 struct ib_smp *in_mad = NULL;
233 struct ib_smp *out_mad = NULL;
234 int err = -ENOMEM;
235
236 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
237 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
238 if (!in_mad || !out_mad)
239 goto out;
240
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);
244
245 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
246 if (err)
247 goto out;
248
249 *pkey = be16_to_cpu(((__be16 *) out_mad->data)[index % 32]);
250
251out:
252 kfree(in_mad);
253 kfree(out_mad);
254 return err;
255}
256
257static int mlx4_ib_modify_device(struct ib_device *ibdev, int mask,
258 struct ib_device_modify *props)
259{
260 if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
261 return -EOPNOTSUPP;
262
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);
267 }
268
269 return 0;
270}
271
272static int mlx4_SET_PORT(struct mlx4_ib_dev *dev, u8 port, int reset_qkey_viols,
273 u32 cap_mask)
274{
275 struct mlx4_cmd_mailbox *mailbox;
276 int err;
277
278 mailbox = mlx4_alloc_cmd_mailbox(dev->dev);
279 if (IS_ERR(mailbox))
280 return PTR_ERR(mailbox);
281
282 memset(mailbox->buf, 0, 256);
5ae2a7a8
RD
283
284 if (dev->dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
285 *(u8 *) mailbox->buf = !!reset_qkey_viols << 6;
286 ((__be32 *) mailbox->buf)[2] = cpu_to_be32(cap_mask);
287 } else {
288 ((u8 *) mailbox->buf)[3] = !!reset_qkey_viols;
289 ((__be32 *) mailbox->buf)[1] = cpu_to_be32(cap_mask);
290 }
225c7b1f
RD
291
292 err = mlx4_cmd(dev->dev, mailbox->dma, port, 0, MLX4_CMD_SET_PORT,
293 MLX4_CMD_TIME_CLASS_B);
294
295 mlx4_free_cmd_mailbox(dev->dev, mailbox);
296 return err;
297}
298
299static int mlx4_ib_modify_port(struct ib_device *ibdev, u8 port, int mask,
300 struct ib_port_modify *props)
301{
302 struct ib_port_attr attr;
303 u32 cap_mask;
304 int err;
305
306 mutex_lock(&to_mdev(ibdev)->cap_mask_mutex);
307
308 err = mlx4_ib_query_port(ibdev, port, &attr);
309 if (err)
310 goto out;
311
312 cap_mask = (attr.port_cap_flags | props->set_port_cap_mask) &
313 ~props->clr_port_cap_mask;
314
315 err = mlx4_SET_PORT(to_mdev(ibdev), port,
316 !!(mask & IB_PORT_RESET_QKEY_CNTR),
317 cap_mask);
318
319out:
320 mutex_unlock(&to_mdev(ibdev)->cap_mask_mutex);
321 return err;
322}
323
324static struct ib_ucontext *mlx4_ib_alloc_ucontext(struct ib_device *ibdev,
325 struct ib_udata *udata)
326{
327 struct mlx4_ib_dev *dev = to_mdev(ibdev);
328 struct mlx4_ib_ucontext *context;
329 struct mlx4_ib_alloc_ucontext_resp resp;
330 int err;
331
332 resp.qp_tab_size = dev->dev->caps.num_qps;
333 resp.bf_reg_size = dev->dev->caps.bf_reg_size;
334 resp.bf_regs_per_page = dev->dev->caps.bf_regs_per_page;
335
336 context = kmalloc(sizeof *context, GFP_KERNEL);
337 if (!context)
338 return ERR_PTR(-ENOMEM);
339
340 err = mlx4_uar_alloc(to_mdev(ibdev)->dev, &context->uar);
341 if (err) {
342 kfree(context);
343 return ERR_PTR(err);
344 }
345
346 INIT_LIST_HEAD(&context->db_page_list);
347 mutex_init(&context->db_page_mutex);
348
349 err = ib_copy_to_udata(udata, &resp, sizeof resp);
350 if (err) {
351 mlx4_uar_free(to_mdev(ibdev)->dev, &context->uar);
352 kfree(context);
353 return ERR_PTR(-EFAULT);
354 }
355
356 return &context->ibucontext;
357}
358
359static int mlx4_ib_dealloc_ucontext(struct ib_ucontext *ibcontext)
360{
361 struct mlx4_ib_ucontext *context = to_mucontext(ibcontext);
362
363 mlx4_uar_free(to_mdev(ibcontext->device)->dev, &context->uar);
364 kfree(context);
365
366 return 0;
367}
368
369static int mlx4_ib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
370{
371 struct mlx4_ib_dev *dev = to_mdev(context->device);
372
373 if (vma->vm_end - vma->vm_start != PAGE_SIZE)
374 return -EINVAL;
375
376 if (vma->vm_pgoff == 0) {
377 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
378
379 if (io_remap_pfn_range(vma, vma->vm_start,
380 to_mucontext(context)->uar.pfn,
381 PAGE_SIZE, vma->vm_page_prot))
382 return -EAGAIN;
383 } else if (vma->vm_pgoff == 1 && dev->dev->caps.bf_reg_size != 0) {
384 /* FIXME want pgprot_writecombine() for BlueFlame pages */
385 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
386
387 if (io_remap_pfn_range(vma, vma->vm_start,
388 to_mucontext(context)->uar.pfn +
389 dev->dev->caps.num_uars,
390 PAGE_SIZE, vma->vm_page_prot))
391 return -EAGAIN;
392 } else
393 return -EINVAL;
394
395 return 0;
396}
397
398static struct ib_pd *mlx4_ib_alloc_pd(struct ib_device *ibdev,
399 struct ib_ucontext *context,
400 struct ib_udata *udata)
401{
402 struct mlx4_ib_pd *pd;
403 int err;
404
405 pd = kmalloc(sizeof *pd, GFP_KERNEL);
406 if (!pd)
407 return ERR_PTR(-ENOMEM);
408
409 err = mlx4_pd_alloc(to_mdev(ibdev)->dev, &pd->pdn);
410 if (err) {
411 kfree(pd);
412 return ERR_PTR(err);
413 }
414
415 if (context)
416 if (ib_copy_to_udata(udata, &pd->pdn, sizeof (__u32))) {
417 mlx4_pd_free(to_mdev(ibdev)->dev, pd->pdn);
418 kfree(pd);
419 return ERR_PTR(-EFAULT);
420 }
421
422 return &pd->ibpd;
423}
424
425static int mlx4_ib_dealloc_pd(struct ib_pd *pd)
426{
427 mlx4_pd_free(to_mdev(pd->device)->dev, to_mpd(pd)->pdn);
428 kfree(pd);
429
430 return 0;
431}
432
433static int mlx4_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
434{
435 return mlx4_multicast_attach(to_mdev(ibqp->device)->dev,
436 &to_mqp(ibqp)->mqp, gid->raw);
437}
438
439static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
440{
441 return mlx4_multicast_detach(to_mdev(ibqp->device)->dev,
442 &to_mqp(ibqp)->mqp, gid->raw);
443}
444
445static int init_node_data(struct mlx4_ib_dev *dev)
446{
447 struct ib_smp *in_mad = NULL;
448 struct ib_smp *out_mad = NULL;
449 int err = -ENOMEM;
450
451 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
452 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
453 if (!in_mad || !out_mad)
454 goto out;
455
456 init_query_mad(in_mad);
457 in_mad->attr_id = IB_SMP_ATTR_NODE_DESC;
458
459 err = mlx4_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad);
460 if (err)
461 goto out;
462
463 memcpy(dev->ib_dev.node_desc, out_mad->data, 64);
464
465 in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
466
467 err = mlx4_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad);
468 if (err)
469 goto out;
470
893da759 471 dev->dev->rev_id = be32_to_cpup((__be32 *) (out_mad->data + 32));
225c7b1f
RD
472 memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8);
473
474out:
475 kfree(in_mad);
476 kfree(out_mad);
477 return err;
478}
479
cd9281d8
JM
480static ssize_t show_hca(struct class_device *cdev, char *buf)
481{
482 struct mlx4_ib_dev *dev = container_of(cdev, struct mlx4_ib_dev, ib_dev.class_dev);
483 return sprintf(buf, "MT%d\n", dev->dev->pdev->device);
484}
485
486static ssize_t show_fw_ver(struct class_device *cdev, char *buf)
487{
488 struct mlx4_ib_dev *dev = container_of(cdev, struct mlx4_ib_dev, ib_dev.class_dev);
489 return sprintf(buf, "%d.%d.%d\n", (int) (dev->dev->caps.fw_ver >> 32),
490 (int) (dev->dev->caps.fw_ver >> 16) & 0xffff,
491 (int) dev->dev->caps.fw_ver & 0xffff);
492}
493
494static ssize_t show_rev(struct class_device *cdev, char *buf)
495{
496 struct mlx4_ib_dev *dev = container_of(cdev, struct mlx4_ib_dev, ib_dev.class_dev);
497 return sprintf(buf, "%x\n", dev->dev->rev_id);
498}
499
500static ssize_t show_board(struct class_device *cdev, char *buf)
501{
502 struct mlx4_ib_dev *dev = container_of(cdev, struct mlx4_ib_dev, ib_dev.class_dev);
503 return sprintf(buf, "%.*s\n", MLX4_BOARD_ID_LEN, dev->dev->board_id);
504}
505
506static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
507static CLASS_DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
508static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
509static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
510
511static struct class_device_attribute *mlx4_class_attributes[] = {
512 &class_device_attr_hw_rev,
513 &class_device_attr_fw_ver,
514 &class_device_attr_hca_type,
515 &class_device_attr_board_id
516};
517
225c7b1f
RD
518static void *mlx4_ib_add(struct mlx4_dev *dev)
519{
520 struct mlx4_ib_dev *ibdev;
cd9281d8 521 int i;
225c7b1f
RD
522
523 ibdev = (struct mlx4_ib_dev *) ib_alloc_device(sizeof *ibdev);
524 if (!ibdev) {
525 dev_err(&dev->pdev->dev, "Device struct alloc failed\n");
526 return NULL;
527 }
528
529 if (mlx4_pd_alloc(dev, &ibdev->priv_pdn))
530 goto err_dealloc;
531
532 if (mlx4_uar_alloc(dev, &ibdev->priv_uar))
533 goto err_pd;
534
535 ibdev->uar_map = ioremap(ibdev->priv_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
536 if (!ibdev->uar_map)
537 goto err_uar;
26c6bc7b 538 MLX4_INIT_DOORBELL_LOCK(&ibdev->uar_lock);
225c7b1f
RD
539
540 INIT_LIST_HEAD(&ibdev->pgdir_list);
541 mutex_init(&ibdev->pgdir_mutex);
542
543 ibdev->dev = dev;
544
545 strlcpy(ibdev->ib_dev.name, "mlx4_%d", IB_DEVICE_NAME_MAX);
546 ibdev->ib_dev.owner = THIS_MODULE;
547 ibdev->ib_dev.node_type = RDMA_NODE_IB_CA;
548 ibdev->ib_dev.phys_port_cnt = dev->caps.num_ports;
549 ibdev->ib_dev.num_comp_vectors = 1;
550 ibdev->ib_dev.dma_device = &dev->pdev->dev;
551
552 ibdev->ib_dev.uverbs_abi_ver = MLX4_IB_UVERBS_ABI_VERSION;
553 ibdev->ib_dev.uverbs_cmd_mask =
554 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
555 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
556 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
557 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
558 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
559 (1ull << IB_USER_VERBS_CMD_REG_MR) |
560 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
561 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
562 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
563 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
564 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
565 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
6a775e2b 566 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
225c7b1f
RD
567 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
568 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
569 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
570 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
571 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
65541cb7 572 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
225c7b1f
RD
573 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
574
575 ibdev->ib_dev.query_device = mlx4_ib_query_device;
576 ibdev->ib_dev.query_port = mlx4_ib_query_port;
577 ibdev->ib_dev.query_gid = mlx4_ib_query_gid;
578 ibdev->ib_dev.query_pkey = mlx4_ib_query_pkey;
579 ibdev->ib_dev.modify_device = mlx4_ib_modify_device;
580 ibdev->ib_dev.modify_port = mlx4_ib_modify_port;
581 ibdev->ib_dev.alloc_ucontext = mlx4_ib_alloc_ucontext;
582 ibdev->ib_dev.dealloc_ucontext = mlx4_ib_dealloc_ucontext;
583 ibdev->ib_dev.mmap = mlx4_ib_mmap;
584 ibdev->ib_dev.alloc_pd = mlx4_ib_alloc_pd;
585 ibdev->ib_dev.dealloc_pd = mlx4_ib_dealloc_pd;
586 ibdev->ib_dev.create_ah = mlx4_ib_create_ah;
587 ibdev->ib_dev.query_ah = mlx4_ib_query_ah;
588 ibdev->ib_dev.destroy_ah = mlx4_ib_destroy_ah;
589 ibdev->ib_dev.create_srq = mlx4_ib_create_srq;
590 ibdev->ib_dev.modify_srq = mlx4_ib_modify_srq;
65541cb7 591 ibdev->ib_dev.query_srq = mlx4_ib_query_srq;
225c7b1f
RD
592 ibdev->ib_dev.destroy_srq = mlx4_ib_destroy_srq;
593 ibdev->ib_dev.post_srq_recv = mlx4_ib_post_srq_recv;
594 ibdev->ib_dev.create_qp = mlx4_ib_create_qp;
595 ibdev->ib_dev.modify_qp = mlx4_ib_modify_qp;
6a775e2b 596 ibdev->ib_dev.query_qp = mlx4_ib_query_qp;
225c7b1f
RD
597 ibdev->ib_dev.destroy_qp = mlx4_ib_destroy_qp;
598 ibdev->ib_dev.post_send = mlx4_ib_post_send;
599 ibdev->ib_dev.post_recv = mlx4_ib_post_recv;
600 ibdev->ib_dev.create_cq = mlx4_ib_create_cq;
601 ibdev->ib_dev.destroy_cq = mlx4_ib_destroy_cq;
602 ibdev->ib_dev.poll_cq = mlx4_ib_poll_cq;
603 ibdev->ib_dev.req_notify_cq = mlx4_ib_arm_cq;
604 ibdev->ib_dev.get_dma_mr = mlx4_ib_get_dma_mr;
605 ibdev->ib_dev.reg_user_mr = mlx4_ib_reg_user_mr;
606 ibdev->ib_dev.dereg_mr = mlx4_ib_dereg_mr;
607 ibdev->ib_dev.attach_mcast = mlx4_ib_mcg_attach;
608 ibdev->ib_dev.detach_mcast = mlx4_ib_mcg_detach;
609 ibdev->ib_dev.process_mad = mlx4_ib_process_mad;
610
8ad11fb6
JM
611 ibdev->ib_dev.alloc_fmr = mlx4_ib_fmr_alloc;
612 ibdev->ib_dev.map_phys_fmr = mlx4_ib_map_phys_fmr;
613 ibdev->ib_dev.unmap_fmr = mlx4_ib_unmap_fmr;
614 ibdev->ib_dev.dealloc_fmr = mlx4_ib_fmr_dealloc;
615
225c7b1f
RD
616 if (init_node_data(ibdev))
617 goto err_map;
618
619 spin_lock_init(&ibdev->sm_lock);
620 mutex_init(&ibdev->cap_mask_mutex);
621
622 if (ib_register_device(&ibdev->ib_dev))
623 goto err_map;
624
625 if (mlx4_ib_mad_init(ibdev))
626 goto err_reg;
627
cd9281d8
JM
628 for (i = 0; i < ARRAY_SIZE(mlx4_class_attributes); ++i) {
629 if (class_device_create_file(&ibdev->ib_dev.class_dev,
630 mlx4_class_attributes[i]))
631 goto err_reg;
632 }
633
225c7b1f
RD
634 return ibdev;
635
636err_reg:
637 ib_unregister_device(&ibdev->ib_dev);
638
639err_map:
640 iounmap(ibdev->uar_map);
641
642err_uar:
643 mlx4_uar_free(dev, &ibdev->priv_uar);
644
645err_pd:
646 mlx4_pd_free(dev, ibdev->priv_pdn);
647
648err_dealloc:
649 ib_dealloc_device(&ibdev->ib_dev);
650
651 return NULL;
652}
653
654static void mlx4_ib_remove(struct mlx4_dev *dev, void *ibdev_ptr)
655{
656 struct mlx4_ib_dev *ibdev = ibdev_ptr;
657 int p;
658
659 for (p = 1; p <= dev->caps.num_ports; ++p)
660 mlx4_CLOSE_PORT(dev, p);
661
662 mlx4_ib_mad_cleanup(ibdev);
663 ib_unregister_device(&ibdev->ib_dev);
664 iounmap(ibdev->uar_map);
665 mlx4_uar_free(dev, &ibdev->priv_uar);
666 mlx4_pd_free(dev, ibdev->priv_pdn);
667 ib_dealloc_device(&ibdev->ib_dev);
668}
669
670static void mlx4_ib_event(struct mlx4_dev *dev, void *ibdev_ptr,
671 enum mlx4_dev_event event, int subtype,
672 int port)
673{
674 struct ib_event ibev;
675
676 switch (event) {
677 case MLX4_EVENT_TYPE_PORT_CHANGE:
678 ibev.event = subtype == MLX4_PORT_CHANGE_SUBTYPE_ACTIVE ?
679 IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR;
680 break;
681
682 case MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR:
683 ibev.event = IB_EVENT_DEVICE_FATAL;
684 break;
685
686 default:
687 return;
688 }
689
690 ibev.device = ibdev_ptr;
691 ibev.element.port_num = port;
692
693 ib_dispatch_event(&ibev);
694}
695
696static struct mlx4_interface mlx4_ib_interface = {
697 .add = mlx4_ib_add,
698 .remove = mlx4_ib_remove,
699 .event = mlx4_ib_event
700};
701
702static int __init mlx4_ib_init(void)
703{
704 return mlx4_register_interface(&mlx4_ib_interface);
705}
706
707static void __exit mlx4_ib_cleanup(void)
708{
709 mlx4_unregister_interface(&mlx4_ib_interface);
710}
711
712module_init(mlx4_ib_init);
713module_exit(mlx4_ib_cleanup);