IB/core cleanup: Add const on args - device->process_mad
[deliverable/linux.git] / drivers / infiniband / hw / cxgb4 / provider.c
1 /*
2 * Copyright (c) 2009-2010 Chelsio, 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 #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>
43 #include <linux/inetdevice.h>
44 #include <linux/io.h>
45
46 #include <asm/irq.h>
47 #include <asm/byteorder.h>
48
49 #include <rdma/iw_cm.h>
50 #include <rdma/ib_verbs.h>
51 #include <rdma/ib_smi.h>
52 #include <rdma/ib_umem.h>
53 #include <rdma/ib_user_verbs.h>
54
55 #include "iw_cxgb4.h"
56
57 static int fastreg_support = 1;
58 module_param(fastreg_support, int, 0644);
59 MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)");
60
61 static struct ib_ah *c4iw_ah_create(struct ib_pd *pd,
62 struct ib_ah_attr *ah_attr)
63 {
64 return ERR_PTR(-ENOSYS);
65 }
66
67 static int c4iw_ah_destroy(struct ib_ah *ah)
68 {
69 return -ENOSYS;
70 }
71
72 static int c4iw_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
73 {
74 return -ENOSYS;
75 }
76
77 static int c4iw_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
78 {
79 return -ENOSYS;
80 }
81
82 static int c4iw_process_mad(struct ib_device *ibdev, int mad_flags,
83 u8 port_num, const struct ib_wc *in_wc,
84 const struct ib_grh *in_grh,
85 const struct ib_mad *in_mad,
86 struct ib_mad *out_mad)
87 {
88 return -ENOSYS;
89 }
90
91 static int c4iw_dealloc_ucontext(struct ib_ucontext *context)
92 {
93 struct c4iw_dev *rhp = to_c4iw_dev(context->device);
94 struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context);
95 struct c4iw_mm_entry *mm, *tmp;
96
97 PDBG("%s context %p\n", __func__, context);
98 list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
99 kfree(mm);
100 c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx);
101 kfree(ucontext);
102 return 0;
103 }
104
105 static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev,
106 struct ib_udata *udata)
107 {
108 struct c4iw_ucontext *context;
109 struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
110 static int warned;
111 struct c4iw_alloc_ucontext_resp uresp;
112 int ret = 0;
113 struct c4iw_mm_entry *mm = NULL;
114
115 PDBG("%s ibdev %p\n", __func__, ibdev);
116 context = kzalloc(sizeof(*context), GFP_KERNEL);
117 if (!context) {
118 ret = -ENOMEM;
119 goto err;
120 }
121
122 c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx);
123 INIT_LIST_HEAD(&context->mmaps);
124 spin_lock_init(&context->mmap_lock);
125
126 if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) {
127 if (!warned++)
128 pr_err(MOD "Warning - downlevel libcxgb4 (non-fatal), device status page disabled.");
129 rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED;
130 } else {
131 mm = kmalloc(sizeof(*mm), GFP_KERNEL);
132 if (!mm) {
133 ret = -ENOMEM;
134 goto err_free;
135 }
136
137 uresp.status_page_size = PAGE_SIZE;
138
139 spin_lock(&context->mmap_lock);
140 uresp.status_page_key = context->key;
141 context->key += PAGE_SIZE;
142 spin_unlock(&context->mmap_lock);
143
144 ret = ib_copy_to_udata(udata, &uresp,
145 sizeof(uresp) - sizeof(uresp.reserved));
146 if (ret)
147 goto err_mm;
148
149 mm->key = uresp.status_page_key;
150 mm->addr = virt_to_phys(rhp->rdev.status_page);
151 mm->len = PAGE_SIZE;
152 insert_mmap(context, mm);
153 }
154 return &context->ibucontext;
155 err_mm:
156 kfree(mm);
157 err_free:
158 kfree(context);
159 err:
160 return ERR_PTR(ret);
161 }
162
163 static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
164 {
165 int len = vma->vm_end - vma->vm_start;
166 u32 key = vma->vm_pgoff << PAGE_SHIFT;
167 struct c4iw_rdev *rdev;
168 int ret = 0;
169 struct c4iw_mm_entry *mm;
170 struct c4iw_ucontext *ucontext;
171 u64 addr;
172
173 PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __func__, vma->vm_pgoff,
174 key, len);
175
176 if (vma->vm_start & (PAGE_SIZE-1))
177 return -EINVAL;
178
179 rdev = &(to_c4iw_dev(context->device)->rdev);
180 ucontext = to_c4iw_ucontext(context);
181
182 mm = remove_mmap(ucontext, key, len);
183 if (!mm)
184 return -EINVAL;
185 addr = mm->addr;
186 kfree(mm);
187
188 if ((addr >= pci_resource_start(rdev->lldi.pdev, 0)) &&
189 (addr < (pci_resource_start(rdev->lldi.pdev, 0) +
190 pci_resource_len(rdev->lldi.pdev, 0)))) {
191
192 /*
193 * MA_SYNC register...
194 */
195 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
196 ret = io_remap_pfn_range(vma, vma->vm_start,
197 addr >> PAGE_SHIFT,
198 len, vma->vm_page_prot);
199 } else if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) &&
200 (addr < (pci_resource_start(rdev->lldi.pdev, 2) +
201 pci_resource_len(rdev->lldi.pdev, 2)))) {
202
203 /*
204 * Map user DB or OCQP memory...
205 */
206 if (addr >= rdev->oc_mw_pa)
207 vma->vm_page_prot = t4_pgprot_wc(vma->vm_page_prot);
208 else {
209 if (is_t5(rdev->lldi.adapter_type))
210 vma->vm_page_prot =
211 t4_pgprot_wc(vma->vm_page_prot);
212 else
213 vma->vm_page_prot =
214 pgprot_noncached(vma->vm_page_prot);
215 }
216 ret = io_remap_pfn_range(vma, vma->vm_start,
217 addr >> PAGE_SHIFT,
218 len, vma->vm_page_prot);
219 } else {
220
221 /*
222 * Map WQ or CQ contig dma memory...
223 */
224 ret = remap_pfn_range(vma, vma->vm_start,
225 addr >> PAGE_SHIFT,
226 len, vma->vm_page_prot);
227 }
228
229 return ret;
230 }
231
232 static int c4iw_deallocate_pd(struct ib_pd *pd)
233 {
234 struct c4iw_dev *rhp;
235 struct c4iw_pd *php;
236
237 php = to_c4iw_pd(pd);
238 rhp = php->rhp;
239 PDBG("%s ibpd %p pdid 0x%x\n", __func__, pd, php->pdid);
240 c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid);
241 mutex_lock(&rhp->rdev.stats.lock);
242 rhp->rdev.stats.pd.cur--;
243 mutex_unlock(&rhp->rdev.stats.lock);
244 kfree(php);
245 return 0;
246 }
247
248 static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev,
249 struct ib_ucontext *context,
250 struct ib_udata *udata)
251 {
252 struct c4iw_pd *php;
253 u32 pdid;
254 struct c4iw_dev *rhp;
255
256 PDBG("%s ibdev %p\n", __func__, ibdev);
257 rhp = (struct c4iw_dev *) ibdev;
258 pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table);
259 if (!pdid)
260 return ERR_PTR(-EINVAL);
261 php = kzalloc(sizeof(*php), GFP_KERNEL);
262 if (!php) {
263 c4iw_put_resource(&rhp->rdev.resource.pdid_table, pdid);
264 return ERR_PTR(-ENOMEM);
265 }
266 php->pdid = pdid;
267 php->rhp = rhp;
268 if (context) {
269 if (ib_copy_to_udata(udata, &php->pdid, sizeof(u32))) {
270 c4iw_deallocate_pd(&php->ibpd);
271 return ERR_PTR(-EFAULT);
272 }
273 }
274 mutex_lock(&rhp->rdev.stats.lock);
275 rhp->rdev.stats.pd.cur++;
276 if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max)
277 rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur;
278 mutex_unlock(&rhp->rdev.stats.lock);
279 PDBG("%s pdid 0x%0x ptr 0x%p\n", __func__, pdid, php);
280 return &php->ibpd;
281 }
282
283 static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
284 u16 *pkey)
285 {
286 PDBG("%s ibdev %p\n", __func__, ibdev);
287 *pkey = 0;
288 return 0;
289 }
290
291 static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index,
292 union ib_gid *gid)
293 {
294 struct c4iw_dev *dev;
295
296 PDBG("%s ibdev %p, port %d, index %d, gid %p\n",
297 __func__, ibdev, port, index, gid);
298 dev = to_c4iw_dev(ibdev);
299 BUG_ON(port == 0);
300 memset(&(gid->raw[0]), 0, sizeof(gid->raw));
301 memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6);
302 return 0;
303 }
304
305 static int c4iw_query_device(struct ib_device *ibdev,
306 struct ib_device_attr *props)
307 {
308
309 struct c4iw_dev *dev;
310 PDBG("%s ibdev %p\n", __func__, ibdev);
311
312 dev = to_c4iw_dev(ibdev);
313 memset(props, 0, sizeof *props);
314 memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
315 props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type);
316 props->fw_ver = dev->rdev.lldi.fw_vers;
317 props->device_cap_flags = dev->device_cap_flags;
318 props->page_size_cap = T4_PAGESIZE_MASK;
319 props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor;
320 props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device;
321 props->max_mr_size = T4_MAX_MR_SIZE;
322 props->max_qp = dev->rdev.lldi.vr->qp.size / 2;
323 props->max_qp_wr = dev->rdev.hw_queue.t4_max_qp_depth;
324 props->max_sge = T4_MAX_RECV_SGE;
325 props->max_sge_rd = 1;
326 props->max_res_rd_atom = dev->rdev.lldi.max_ird_adapter;
327 props->max_qp_rd_atom = min(dev->rdev.lldi.max_ordird_qp,
328 c4iw_max_read_depth);
329 props->max_qp_init_rd_atom = props->max_qp_rd_atom;
330 props->max_cq = dev->rdev.lldi.vr->qp.size;
331 props->max_cqe = dev->rdev.hw_queue.t4_max_cq_depth;
332 props->max_mr = c4iw_num_stags(&dev->rdev);
333 props->max_pd = T4_MAX_NUM_PD;
334 props->local_ca_ack_delay = 0;
335 props->max_fast_reg_page_list_len = t4_max_fr_depth(use_dsgl);
336
337 return 0;
338 }
339
340 static int c4iw_query_port(struct ib_device *ibdev, u8 port,
341 struct ib_port_attr *props)
342 {
343 struct c4iw_dev *dev;
344 struct net_device *netdev;
345 struct in_device *inetdev;
346
347 PDBG("%s ibdev %p\n", __func__, ibdev);
348
349 dev = to_c4iw_dev(ibdev);
350 netdev = dev->rdev.lldi.ports[port-1];
351
352 memset(props, 0, sizeof(struct ib_port_attr));
353 props->max_mtu = IB_MTU_4096;
354 if (netdev->mtu >= 4096)
355 props->active_mtu = IB_MTU_4096;
356 else if (netdev->mtu >= 2048)
357 props->active_mtu = IB_MTU_2048;
358 else if (netdev->mtu >= 1024)
359 props->active_mtu = IB_MTU_1024;
360 else if (netdev->mtu >= 512)
361 props->active_mtu = IB_MTU_512;
362 else
363 props->active_mtu = IB_MTU_256;
364
365 if (!netif_carrier_ok(netdev))
366 props->state = IB_PORT_DOWN;
367 else {
368 inetdev = in_dev_get(netdev);
369 if (inetdev) {
370 if (inetdev->ifa_list)
371 props->state = IB_PORT_ACTIVE;
372 else
373 props->state = IB_PORT_INIT;
374 in_dev_put(inetdev);
375 } else
376 props->state = IB_PORT_INIT;
377 }
378
379 props->port_cap_flags =
380 IB_PORT_CM_SUP |
381 IB_PORT_SNMP_TUNNEL_SUP |
382 IB_PORT_REINIT_SUP |
383 IB_PORT_DEVICE_MGMT_SUP |
384 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
385 props->gid_tbl_len = 1;
386 props->pkey_tbl_len = 1;
387 props->active_width = 2;
388 props->active_speed = IB_SPEED_DDR;
389 props->max_msg_sz = -1;
390
391 return 0;
392 }
393
394 static ssize_t show_rev(struct device *dev, struct device_attribute *attr,
395 char *buf)
396 {
397 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
398 ibdev.dev);
399 PDBG("%s dev 0x%p\n", __func__, dev);
400 return sprintf(buf, "%d\n",
401 CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type));
402 }
403
404 static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,
405 char *buf)
406 {
407 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
408 ibdev.dev);
409 PDBG("%s dev 0x%p\n", __func__, dev);
410
411 return sprintf(buf, "%u.%u.%u.%u\n",
412 FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers),
413 FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers),
414 FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers),
415 FW_HDR_FW_VER_BUILD_G(c4iw_dev->rdev.lldi.fw_vers));
416 }
417
418 static ssize_t show_hca(struct device *dev, struct device_attribute *attr,
419 char *buf)
420 {
421 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
422 ibdev.dev);
423 struct ethtool_drvinfo info;
424 struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0];
425
426 PDBG("%s dev 0x%p\n", __func__, dev);
427 lldev->ethtool_ops->get_drvinfo(lldev, &info);
428 return sprintf(buf, "%s\n", info.driver);
429 }
430
431 static ssize_t show_board(struct device *dev, struct device_attribute *attr,
432 char *buf)
433 {
434 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
435 ibdev.dev);
436 PDBG("%s dev 0x%p\n", __func__, dev);
437 return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor,
438 c4iw_dev->rdev.lldi.pdev->device);
439 }
440
441 static int c4iw_get_mib(struct ib_device *ibdev,
442 union rdma_protocol_stats *stats)
443 {
444 struct tp_tcp_stats v4, v6;
445 struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev);
446
447 cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6);
448 memset(stats, 0, sizeof *stats);
449 stats->iw.tcpInSegs = v4.tcpInSegs + v6.tcpInSegs;
450 stats->iw.tcpOutSegs = v4.tcpOutSegs + v6.tcpOutSegs;
451 stats->iw.tcpRetransSegs = v4.tcpRetransSegs + v6.tcpRetransSegs;
452 stats->iw.tcpOutRsts = v4.tcpOutRsts + v6.tcpOutSegs;
453
454 return 0;
455 }
456
457 static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
458 static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
459 static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
460 static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
461
462 static struct device_attribute *c4iw_class_attributes[] = {
463 &dev_attr_hw_rev,
464 &dev_attr_fw_ver,
465 &dev_attr_hca_type,
466 &dev_attr_board_id,
467 };
468
469 static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num,
470 struct ib_port_immutable *immutable)
471 {
472 struct ib_port_attr attr;
473 int err;
474
475 err = c4iw_query_port(ibdev, port_num, &attr);
476 if (err)
477 return err;
478
479 immutable->pkey_tbl_len = attr.pkey_tbl_len;
480 immutable->gid_tbl_len = attr.gid_tbl_len;
481 immutable->core_cap_flags = RDMA_CORE_PORT_IWARP;
482
483 return 0;
484 }
485
486 int c4iw_register_device(struct c4iw_dev *dev)
487 {
488 int ret;
489 int i;
490
491 PDBG("%s c4iw_dev %p\n", __func__, dev);
492 BUG_ON(!dev->rdev.lldi.ports[0]);
493 strlcpy(dev->ibdev.name, "cxgb4_%d", IB_DEVICE_NAME_MAX);
494 memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
495 memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
496 dev->ibdev.owner = THIS_MODULE;
497 dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW;
498 if (fastreg_support)
499 dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
500 dev->ibdev.local_dma_lkey = 0;
501 dev->ibdev.uverbs_cmd_mask =
502 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
503 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
504 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
505 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
506 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
507 (1ull << IB_USER_VERBS_CMD_REG_MR) |
508 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
509 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
510 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
511 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
512 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
513 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
514 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
515 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
516 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
517 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
518 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
519 (1ull << IB_USER_VERBS_CMD_POST_RECV);
520 dev->ibdev.node_type = RDMA_NODE_RNIC;
521 memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC));
522 dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports;
523 dev->ibdev.num_comp_vectors = dev->rdev.lldi.nciq;
524 dev->ibdev.dma_device = &(dev->rdev.lldi.pdev->dev);
525 dev->ibdev.query_device = c4iw_query_device;
526 dev->ibdev.query_port = c4iw_query_port;
527 dev->ibdev.query_pkey = c4iw_query_pkey;
528 dev->ibdev.query_gid = c4iw_query_gid;
529 dev->ibdev.alloc_ucontext = c4iw_alloc_ucontext;
530 dev->ibdev.dealloc_ucontext = c4iw_dealloc_ucontext;
531 dev->ibdev.mmap = c4iw_mmap;
532 dev->ibdev.alloc_pd = c4iw_allocate_pd;
533 dev->ibdev.dealloc_pd = c4iw_deallocate_pd;
534 dev->ibdev.create_ah = c4iw_ah_create;
535 dev->ibdev.destroy_ah = c4iw_ah_destroy;
536 dev->ibdev.create_qp = c4iw_create_qp;
537 dev->ibdev.modify_qp = c4iw_ib_modify_qp;
538 dev->ibdev.query_qp = c4iw_ib_query_qp;
539 dev->ibdev.destroy_qp = c4iw_destroy_qp;
540 dev->ibdev.create_cq = c4iw_create_cq;
541 dev->ibdev.destroy_cq = c4iw_destroy_cq;
542 dev->ibdev.resize_cq = c4iw_resize_cq;
543 dev->ibdev.poll_cq = c4iw_poll_cq;
544 dev->ibdev.get_dma_mr = c4iw_get_dma_mr;
545 dev->ibdev.reg_phys_mr = c4iw_register_phys_mem;
546 dev->ibdev.rereg_phys_mr = c4iw_reregister_phys_mem;
547 dev->ibdev.reg_user_mr = c4iw_reg_user_mr;
548 dev->ibdev.dereg_mr = c4iw_dereg_mr;
549 dev->ibdev.alloc_mw = c4iw_alloc_mw;
550 dev->ibdev.bind_mw = c4iw_bind_mw;
551 dev->ibdev.dealloc_mw = c4iw_dealloc_mw;
552 dev->ibdev.alloc_fast_reg_mr = c4iw_alloc_fast_reg_mr;
553 dev->ibdev.alloc_fast_reg_page_list = c4iw_alloc_fastreg_pbl;
554 dev->ibdev.free_fast_reg_page_list = c4iw_free_fastreg_pbl;
555 dev->ibdev.attach_mcast = c4iw_multicast_attach;
556 dev->ibdev.detach_mcast = c4iw_multicast_detach;
557 dev->ibdev.process_mad = c4iw_process_mad;
558 dev->ibdev.req_notify_cq = c4iw_arm_cq;
559 dev->ibdev.post_send = c4iw_post_send;
560 dev->ibdev.post_recv = c4iw_post_receive;
561 dev->ibdev.get_protocol_stats = c4iw_get_mib;
562 dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION;
563 dev->ibdev.get_port_immutable = c4iw_port_immutable;
564
565 dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
566 if (!dev->ibdev.iwcm)
567 return -ENOMEM;
568
569 dev->ibdev.iwcm->connect = c4iw_connect;
570 dev->ibdev.iwcm->accept = c4iw_accept_cr;
571 dev->ibdev.iwcm->reject = c4iw_reject_cr;
572 dev->ibdev.iwcm->create_listen = c4iw_create_listen;
573 dev->ibdev.iwcm->destroy_listen = c4iw_destroy_listen;
574 dev->ibdev.iwcm->add_ref = c4iw_qp_add_ref;
575 dev->ibdev.iwcm->rem_ref = c4iw_qp_rem_ref;
576 dev->ibdev.iwcm->get_qp = c4iw_get_qp;
577
578 ret = ib_register_device(&dev->ibdev, NULL);
579 if (ret)
580 goto bail1;
581
582 for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) {
583 ret = device_create_file(&dev->ibdev.dev,
584 c4iw_class_attributes[i]);
585 if (ret)
586 goto bail2;
587 }
588 return 0;
589 bail2:
590 ib_unregister_device(&dev->ibdev);
591 bail1:
592 kfree(dev->ibdev.iwcm);
593 return ret;
594 }
595
596 void c4iw_unregister_device(struct c4iw_dev *dev)
597 {
598 int i;
599
600 PDBG("%s c4iw_dev %p\n", __func__, dev);
601 for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i)
602 device_remove_file(&dev->ibdev.dev,
603 c4iw_class_attributes[i]);
604 ib_unregister_device(&dev->ibdev);
605 kfree(dev->ibdev.iwcm);
606 return;
607 }
This page took 0.045976 seconds and 5 git commands to generate.