blob: 79429256023a7e2e7be7f83e7f1b305233f5348a [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
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
Steve Wise40dbf6e2010-09-17 15:40:15 -050057static int fastreg_support = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -070058module_param(fastreg_support, int, 0644);
Steve Wise40dbf6e2010-09-17 15:40:15 -050059MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -070060
Steve Wisecfdda9d2010-04-21 15:30:06 -070061static 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
67static int c4iw_ah_destroy(struct ib_ah *ah)
68{
69 return -ENOSYS;
70}
71
72static int c4iw_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
73{
74 return -ENOSYS;
75}
76
77static int c4iw_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
78{
79 return -ENOSYS;
80}
81
82static int c4iw_process_mad(struct ib_device *ibdev, int mad_flags,
83 u8 port_num, struct ib_wc *in_wc,
84 struct ib_grh *in_grh, struct ib_mad *in_mad,
85 struct ib_mad *out_mad)
86{
87 return -ENOSYS;
88}
89
90static int c4iw_dealloc_ucontext(struct ib_ucontext *context)
91{
92 struct c4iw_dev *rhp = to_c4iw_dev(context->device);
93 struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context);
94 struct c4iw_mm_entry *mm, *tmp;
95
96 PDBG("%s context %p\n", __func__, context);
97 list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
98 kfree(mm);
99 c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx);
100 kfree(ucontext);
101 return 0;
102}
103
104static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev,
105 struct ib_udata *udata)
106{
107 struct c4iw_ucontext *context;
108 struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
Steve Wise05eb2382014-03-14 21:52:08 +0530109 static int warned;
110 struct c4iw_alloc_ucontext_resp uresp;
111 int ret = 0;
112 struct c4iw_mm_entry *mm = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700113
114 PDBG("%s ibdev %p\n", __func__, ibdev);
115 context = kzalloc(sizeof(*context), GFP_KERNEL);
Steve Wise05eb2382014-03-14 21:52:08 +0530116 if (!context) {
117 ret = -ENOMEM;
118 goto err;
119 }
120
Steve Wisecfdda9d2010-04-21 15:30:06 -0700121 c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx);
122 INIT_LIST_HEAD(&context->mmaps);
123 spin_lock_init(&context->mmap_lock);
Steve Wise05eb2382014-03-14 21:52:08 +0530124
125 if (udata->outlen < sizeof(uresp)) {
126 if (!warned++)
127 pr_err(MOD "Warning - downlevel libcxgb4 (non-fatal), device status page disabled.");
128 rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED;
129 } else {
130 mm = kmalloc(sizeof(*mm), GFP_KERNEL);
Yann Droneaudbfd27932014-03-28 14:55:21 -0400131 if (!mm) {
132 ret = -ENOMEM;
Steve Wise05eb2382014-03-14 21:52:08 +0530133 goto err_free;
Yann Droneaudbfd27932014-03-28 14:55:21 -0400134 }
Steve Wise05eb2382014-03-14 21:52:08 +0530135
136 uresp.status_page_size = PAGE_SIZE;
137
138 spin_lock(&context->mmap_lock);
139 uresp.status_page_key = context->key;
140 context->key += PAGE_SIZE;
141 spin_unlock(&context->mmap_lock);
142
143 ret = ib_copy_to_udata(udata, &uresp, sizeof(uresp));
144 if (ret)
145 goto err_mm;
146
147 mm->key = uresp.status_page_key;
148 mm->addr = virt_to_phys(rhp->rdev.status_page);
149 mm->len = PAGE_SIZE;
150 insert_mmap(context, mm);
151 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700152 return &context->ibucontext;
Steve Wise05eb2382014-03-14 21:52:08 +0530153err_mm:
154 kfree(mm);
155err_free:
156 kfree(context);
157err:
158 return ERR_PTR(ret);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700159}
160
161static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
162{
163 int len = vma->vm_end - vma->vm_start;
164 u32 key = vma->vm_pgoff << PAGE_SHIFT;
165 struct c4iw_rdev *rdev;
166 int ret = 0;
167 struct c4iw_mm_entry *mm;
168 struct c4iw_ucontext *ucontext;
169 u64 addr;
170
171 PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __func__, vma->vm_pgoff,
172 key, len);
173
174 if (vma->vm_start & (PAGE_SIZE-1))
175 return -EINVAL;
176
177 rdev = &(to_c4iw_dev(context->device)->rdev);
178 ucontext = to_c4iw_ucontext(context);
179
180 mm = remove_mmap(ucontext, key, len);
181 if (!mm)
182 return -EINVAL;
183 addr = mm->addr;
184 kfree(mm);
185
Steve Wisec6d7b262010-09-13 11:23:57 -0500186 if ((addr >= pci_resource_start(rdev->lldi.pdev, 0)) &&
187 (addr < (pci_resource_start(rdev->lldi.pdev, 0) +
188 pci_resource_len(rdev->lldi.pdev, 0)))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -0700189
190 /*
Steve Wisec6d7b262010-09-13 11:23:57 -0500191 * MA_SYNC register...
Steve Wisecfdda9d2010-04-21 15:30:06 -0700192 */
Steve Wisecfdda9d2010-04-21 15:30:06 -0700193 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
Steve Wisec6d7b262010-09-13 11:23:57 -0500194 ret = io_remap_pfn_range(vma, vma->vm_start,
195 addr >> PAGE_SHIFT,
196 len, vma->vm_page_prot);
197 } else if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) &&
198 (addr < (pci_resource_start(rdev->lldi.pdev, 2) +
199 pci_resource_len(rdev->lldi.pdev, 2)))) {
200
201 /*
202 * Map user DB or OCQP memory...
203 */
204 if (addr >= rdev->oc_mw_pa)
205 vma->vm_page_prot = t4_pgprot_wc(vma->vm_page_prot);
Vipul Pandyaf079af72013-03-14 05:08:58 +0000206 else {
207 if (is_t5(rdev->lldi.adapter_type))
208 vma->vm_page_prot =
209 t4_pgprot_wc(vma->vm_page_prot);
210 else
211 vma->vm_page_prot =
212 pgprot_noncached(vma->vm_page_prot);
213 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700214 ret = io_remap_pfn_range(vma, vma->vm_start,
215 addr >> PAGE_SHIFT,
216 len, vma->vm_page_prot);
217 } else {
218
219 /*
220 * Map WQ or CQ contig dma memory...
221 */
222 ret = remap_pfn_range(vma, vma->vm_start,
223 addr >> PAGE_SHIFT,
224 len, vma->vm_page_prot);
225 }
226
227 return ret;
228}
229
230static int c4iw_deallocate_pd(struct ib_pd *pd)
231{
232 struct c4iw_dev *rhp;
233 struct c4iw_pd *php;
234
235 php = to_c4iw_pd(pd);
236 rhp = php->rhp;
237 PDBG("%s ibpd %p pdid 0x%x\n", __func__, pd, php->pdid);
Vipul Pandyaec3eead2012-05-18 15:29:32 +0530238 c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid);
Vipul Pandya8d81ef32012-05-18 15:29:27 +0530239 mutex_lock(&rhp->rdev.stats.lock);
240 rhp->rdev.stats.pd.cur--;
241 mutex_unlock(&rhp->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700242 kfree(php);
243 return 0;
244}
245
246static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev,
247 struct ib_ucontext *context,
248 struct ib_udata *udata)
249{
250 struct c4iw_pd *php;
251 u32 pdid;
252 struct c4iw_dev *rhp;
253
254 PDBG("%s ibdev %p\n", __func__, ibdev);
255 rhp = (struct c4iw_dev *) ibdev;
Vipul Pandyaec3eead2012-05-18 15:29:32 +0530256 pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700257 if (!pdid)
258 return ERR_PTR(-EINVAL);
259 php = kzalloc(sizeof(*php), GFP_KERNEL);
260 if (!php) {
Vipul Pandyaec3eead2012-05-18 15:29:32 +0530261 c4iw_put_resource(&rhp->rdev.resource.pdid_table, pdid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700262 return ERR_PTR(-ENOMEM);
263 }
264 php->pdid = pdid;
265 php->rhp = rhp;
266 if (context) {
267 if (ib_copy_to_udata(udata, &php->pdid, sizeof(u32))) {
268 c4iw_deallocate_pd(&php->ibpd);
269 return ERR_PTR(-EFAULT);
270 }
271 }
Vipul Pandya8d81ef32012-05-18 15:29:27 +0530272 mutex_lock(&rhp->rdev.stats.lock);
273 rhp->rdev.stats.pd.cur++;
274 if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max)
275 rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur;
276 mutex_unlock(&rhp->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700277 PDBG("%s pdid 0x%0x ptr 0x%p\n", __func__, pdid, php);
278 return &php->ibpd;
279}
280
281static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
282 u16 *pkey)
283{
284 PDBG("%s ibdev %p\n", __func__, ibdev);
285 *pkey = 0;
286 return 0;
287}
288
289static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index,
290 union ib_gid *gid)
291{
292 struct c4iw_dev *dev;
293
294 PDBG("%s ibdev %p, port %d, index %d, gid %p\n",
295 __func__, ibdev, port, index, gid);
296 dev = to_c4iw_dev(ibdev);
297 BUG_ON(port == 0);
298 memset(&(gid->raw[0]), 0, sizeof(gid->raw));
299 memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6);
300 return 0;
301}
302
303static int c4iw_query_device(struct ib_device *ibdev,
304 struct ib_device_attr *props)
305{
306
307 struct c4iw_dev *dev;
308 PDBG("%s ibdev %p\n", __func__, ibdev);
309
310 dev = to_c4iw_dev(ibdev);
311 memset(props, 0, sizeof *props);
312 memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
Vipul Pandyaf079af72013-03-14 05:08:58 +0000313 props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700314 props->fw_ver = dev->rdev.lldi.fw_vers;
315 props->device_cap_flags = dev->device_cap_flags;
316 props->page_size_cap = T4_PAGESIZE_MASK;
317 props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor;
318 props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device;
319 props->max_mr_size = T4_MAX_MR_SIZE;
320 props->max_qp = T4_MAX_NUM_QP;
321 props->max_qp_wr = T4_MAX_QP_DEPTH;
322 props->max_sge = T4_MAX_RECV_SGE;
323 props->max_sge_rd = 1;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700324 props->max_qp_rd_atom = c4iw_max_read_depth;
325 props->max_qp_init_rd_atom = c4iw_max_read_depth;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700326 props->max_cq = T4_MAX_NUM_CQ;
327 props->max_cqe = T4_MAX_CQ_DEPTH;
328 props->max_mr = c4iw_num_stags(&dev->rdev);
329 props->max_pd = T4_MAX_NUM_PD;
330 props->local_ca_ack_delay = 0;
331 props->max_fast_reg_page_list_len = T4_MAX_FR_DEPTH;
332
333 return 0;
334}
335
336static int c4iw_query_port(struct ib_device *ibdev, u8 port,
337 struct ib_port_attr *props)
338{
339 struct c4iw_dev *dev;
340 struct net_device *netdev;
341 struct in_device *inetdev;
342
343 PDBG("%s ibdev %p\n", __func__, ibdev);
344
345 dev = to_c4iw_dev(ibdev);
346 netdev = dev->rdev.lldi.ports[port-1];
347
348 memset(props, 0, sizeof(struct ib_port_attr));
349 props->max_mtu = IB_MTU_4096;
350 if (netdev->mtu >= 4096)
351 props->active_mtu = IB_MTU_4096;
352 else if (netdev->mtu >= 2048)
353 props->active_mtu = IB_MTU_2048;
354 else if (netdev->mtu >= 1024)
355 props->active_mtu = IB_MTU_1024;
356 else if (netdev->mtu >= 512)
357 props->active_mtu = IB_MTU_512;
358 else
359 props->active_mtu = IB_MTU_256;
360
361 if (!netif_carrier_ok(netdev))
362 props->state = IB_PORT_DOWN;
363 else {
364 inetdev = in_dev_get(netdev);
365 if (inetdev) {
366 if (inetdev->ifa_list)
367 props->state = IB_PORT_ACTIVE;
368 else
369 props->state = IB_PORT_INIT;
370 in_dev_put(inetdev);
371 } else
372 props->state = IB_PORT_INIT;
373 }
374
375 props->port_cap_flags =
376 IB_PORT_CM_SUP |
377 IB_PORT_SNMP_TUNNEL_SUP |
378 IB_PORT_REINIT_SUP |
379 IB_PORT_DEVICE_MGMT_SUP |
380 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
381 props->gid_tbl_len = 1;
382 props->pkey_tbl_len = 1;
383 props->active_width = 2;
Or Gerlitz2e966912012-02-28 18:49:50 +0200384 props->active_speed = IB_SPEED_DDR;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700385 props->max_msg_sz = -1;
386
387 return 0;
388}
389
390static ssize_t show_rev(struct device *dev, struct device_attribute *attr,
391 char *buf)
392{
393 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
394 ibdev.dev);
395 PDBG("%s dev 0x%p\n", __func__, dev);
Vipul Pandyaf079af72013-03-14 05:08:58 +0000396 return sprintf(buf, "%d\n",
397 CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700398}
399
400static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,
401 char *buf)
402{
403 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
404 ibdev.dev);
405 PDBG("%s dev 0x%p\n", __func__, dev);
406
407 return sprintf(buf, "%u.%u.%u.%u\n",
408 FW_HDR_FW_VER_MAJOR_GET(c4iw_dev->rdev.lldi.fw_vers),
409 FW_HDR_FW_VER_MINOR_GET(c4iw_dev->rdev.lldi.fw_vers),
410 FW_HDR_FW_VER_MICRO_GET(c4iw_dev->rdev.lldi.fw_vers),
411 FW_HDR_FW_VER_BUILD_GET(c4iw_dev->rdev.lldi.fw_vers));
412}
413
414static ssize_t show_hca(struct device *dev, struct device_attribute *attr,
415 char *buf)
416{
417 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
418 ibdev.dev);
419 struct ethtool_drvinfo info;
420 struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0];
421
422 PDBG("%s dev 0x%p\n", __func__, dev);
423 lldev->ethtool_ops->get_drvinfo(lldev, &info);
424 return sprintf(buf, "%s\n", info.driver);
425}
426
427static ssize_t show_board(struct device *dev, struct device_attribute *attr,
428 char *buf)
429{
430 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
431 ibdev.dev);
432 PDBG("%s dev 0x%p\n", __func__, dev);
433 return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor,
434 c4iw_dev->rdev.lldi.pdev->device);
435}
436
437static int c4iw_get_mib(struct ib_device *ibdev,
438 union rdma_protocol_stats *stats)
439{
Steve Wisede5dd812010-10-18 15:16:40 +0000440 struct tp_tcp_stats v4, v6;
441 struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev);
442
443 cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6);
444 memset(stats, 0, sizeof *stats);
445 stats->iw.tcpInSegs = v4.tcpInSegs + v6.tcpInSegs;
446 stats->iw.tcpOutSegs = v4.tcpOutSegs + v6.tcpOutSegs;
447 stats->iw.tcpRetransSegs = v4.tcpRetransSegs + v6.tcpRetransSegs;
448 stats->iw.tcpOutRsts = v4.tcpOutRsts + v6.tcpOutSegs;
449
450 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700451}
452
453static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
454static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
455static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
456static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
457
458static struct device_attribute *c4iw_class_attributes[] = {
459 &dev_attr_hw_rev,
460 &dev_attr_fw_ver,
461 &dev_attr_hca_type,
462 &dev_attr_board_id,
463};
464
465int c4iw_register_device(struct c4iw_dev *dev)
466{
467 int ret;
468 int i;
469
470 PDBG("%s c4iw_dev %p\n", __func__, dev);
471 BUG_ON(!dev->rdev.lldi.ports[0]);
472 strlcpy(dev->ibdev.name, "cxgb4_%d", IB_DEVICE_NAME_MAX);
473 memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
474 memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
475 dev->ibdev.owner = THIS_MODULE;
476 dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW;
477 if (fastreg_support)
478 dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
479 dev->ibdev.local_dma_lkey = 0;
480 dev->ibdev.uverbs_cmd_mask =
481 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
482 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
483 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
484 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
485 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
486 (1ull << IB_USER_VERBS_CMD_REG_MR) |
487 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
488 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
489 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
490 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
491 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
492 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
493 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
Vipul Pandya67bbc052012-05-18 15:29:33 +0530494 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700495 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
496 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
497 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
498 (1ull << IB_USER_VERBS_CMD_POST_RECV);
499 dev->ibdev.node_type = RDMA_NODE_RNIC;
500 memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC));
501 dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports;
502 dev->ibdev.num_comp_vectors = 1;
503 dev->ibdev.dma_device = &(dev->rdev.lldi.pdev->dev);
504 dev->ibdev.query_device = c4iw_query_device;
505 dev->ibdev.query_port = c4iw_query_port;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700506 dev->ibdev.query_pkey = c4iw_query_pkey;
507 dev->ibdev.query_gid = c4iw_query_gid;
508 dev->ibdev.alloc_ucontext = c4iw_alloc_ucontext;
509 dev->ibdev.dealloc_ucontext = c4iw_dealloc_ucontext;
510 dev->ibdev.mmap = c4iw_mmap;
511 dev->ibdev.alloc_pd = c4iw_allocate_pd;
512 dev->ibdev.dealloc_pd = c4iw_deallocate_pd;
513 dev->ibdev.create_ah = c4iw_ah_create;
514 dev->ibdev.destroy_ah = c4iw_ah_destroy;
515 dev->ibdev.create_qp = c4iw_create_qp;
516 dev->ibdev.modify_qp = c4iw_ib_modify_qp;
Vipul Pandya67bbc052012-05-18 15:29:33 +0530517 dev->ibdev.query_qp = c4iw_ib_query_qp;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700518 dev->ibdev.destroy_qp = c4iw_destroy_qp;
519 dev->ibdev.create_cq = c4iw_create_cq;
520 dev->ibdev.destroy_cq = c4iw_destroy_cq;
521 dev->ibdev.resize_cq = c4iw_resize_cq;
522 dev->ibdev.poll_cq = c4iw_poll_cq;
523 dev->ibdev.get_dma_mr = c4iw_get_dma_mr;
524 dev->ibdev.reg_phys_mr = c4iw_register_phys_mem;
525 dev->ibdev.rereg_phys_mr = c4iw_reregister_phys_mem;
526 dev->ibdev.reg_user_mr = c4iw_reg_user_mr;
527 dev->ibdev.dereg_mr = c4iw_dereg_mr;
528 dev->ibdev.alloc_mw = c4iw_alloc_mw;
529 dev->ibdev.bind_mw = c4iw_bind_mw;
530 dev->ibdev.dealloc_mw = c4iw_dealloc_mw;
531 dev->ibdev.alloc_fast_reg_mr = c4iw_alloc_fast_reg_mr;
532 dev->ibdev.alloc_fast_reg_page_list = c4iw_alloc_fastreg_pbl;
533 dev->ibdev.free_fast_reg_page_list = c4iw_free_fastreg_pbl;
534 dev->ibdev.attach_mcast = c4iw_multicast_attach;
535 dev->ibdev.detach_mcast = c4iw_multicast_detach;
536 dev->ibdev.process_mad = c4iw_process_mad;
537 dev->ibdev.req_notify_cq = c4iw_arm_cq;
538 dev->ibdev.post_send = c4iw_post_send;
539 dev->ibdev.post_recv = c4iw_post_receive;
540 dev->ibdev.get_protocol_stats = c4iw_get_mib;
Steve Wisec6d7b262010-09-13 11:23:57 -0500541 dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700542
543 dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
544 if (!dev->ibdev.iwcm)
545 return -ENOMEM;
546
547 dev->ibdev.iwcm->connect = c4iw_connect;
548 dev->ibdev.iwcm->accept = c4iw_accept_cr;
549 dev->ibdev.iwcm->reject = c4iw_reject_cr;
550 dev->ibdev.iwcm->create_listen = c4iw_create_listen;
551 dev->ibdev.iwcm->destroy_listen = c4iw_destroy_listen;
552 dev->ibdev.iwcm->add_ref = c4iw_qp_add_ref;
553 dev->ibdev.iwcm->rem_ref = c4iw_qp_rem_ref;
554 dev->ibdev.iwcm->get_qp = c4iw_get_qp;
555
Ralph Campbell9a6edb62010-05-06 17:03:25 -0700556 ret = ib_register_device(&dev->ibdev, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700557 if (ret)
558 goto bail1;
559
560 for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) {
561 ret = device_create_file(&dev->ibdev.dev,
562 c4iw_class_attributes[i]);
563 if (ret)
564 goto bail2;
565 }
566 return 0;
567bail2:
568 ib_unregister_device(&dev->ibdev);
569bail1:
570 kfree(dev->ibdev.iwcm);
571 return ret;
572}
573
574void c4iw_unregister_device(struct c4iw_dev *dev)
575{
576 int i;
577
578 PDBG("%s c4iw_dev %p\n", __func__, dev);
579 for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i)
580 device_remove_file(&dev->ibdev.dev,
581 c4iw_class_attributes[i]);
582 ib_unregister_device(&dev->ibdev);
583 kfree(dev->ibdev.iwcm);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700584 return;
585}