RDMA/core: Fix a WARN() message
[linux-2.6-block.git] / drivers / infiniband / hw / cxgb4 / provider.c
CommitLineData
cfdda9d7
SW
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
40dbf6ee 57static int fastreg_support = 1;
cfdda9d7 58module_param(fastreg_support, int, 0644);
40dbf6ee 59MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)");
cfdda9d7 60
cfe876d8 61static int c4iw_dealloc_ucontext(struct ib_ucontext *context)
cfdda9d7 62{
cfe876d8 63 struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context);
c12a67fe 64 struct c4iw_dev *rhp;
cfdda9d7
SW
65 struct c4iw_mm_entry *mm, *tmp;
66
cfe876d8 67 pr_debug("context %p\n", context);
c12a67fe
SW
68 rhp = to_c4iw_dev(ucontext->ibucontext.device);
69
cfdda9d7
SW
70 list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
71 kfree(mm);
72 c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx);
73 kfree(ucontext);
74 return 0;
75}
76
77static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev,
78 struct ib_udata *udata)
79{
80 struct c4iw_ucontext *context;
81 struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
05eb2389
SW
82 struct c4iw_alloc_ucontext_resp uresp;
83 int ret = 0;
84 struct c4iw_mm_entry *mm = NULL;
cfdda9d7 85
548ddb19 86 pr_debug("ibdev %p\n", ibdev);
cfdda9d7 87 context = kzalloc(sizeof(*context), GFP_KERNEL);
05eb2389
SW
88 if (!context) {
89 ret = -ENOMEM;
90 goto err;
91 }
92
cfdda9d7
SW
93 c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx);
94 INIT_LIST_HEAD(&context->mmaps);
95 spin_lock_init(&context->mmap_lock);
05eb2389 96
b7dfa889 97 if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) {
700456bd 98 pr_err_once("Warning - downlevel libcxgb4 (non-fatal), device status page disabled\n");
05eb2389
SW
99 rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED;
100 } else {
101 mm = kmalloc(sizeof(*mm), GFP_KERNEL);
bfd2793c
YD
102 if (!mm) {
103 ret = -ENOMEM;
05eb2389 104 goto err_free;
bfd2793c 105 }
05eb2389
SW
106
107 uresp.status_page_size = PAGE_SIZE;
108
109 spin_lock(&context->mmap_lock);
110 uresp.status_page_key = context->key;
111 context->key += PAGE_SIZE;
112 spin_unlock(&context->mmap_lock);
113
b7dfa889
YD
114 ret = ib_copy_to_udata(udata, &uresp,
115 sizeof(uresp) - sizeof(uresp.reserved));
05eb2389
SW
116 if (ret)
117 goto err_mm;
118
119 mm->key = uresp.status_page_key;
120 mm->addr = virt_to_phys(rhp->rdev.status_page);
121 mm->len = PAGE_SIZE;
122 insert_mmap(context, mm);
123 }
cfdda9d7 124 return &context->ibucontext;
05eb2389
SW
125err_mm:
126 kfree(mm);
127err_free:
128 kfree(context);
129err:
130 return ERR_PTR(ret);
cfdda9d7
SW
131}
132
133static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
134{
135 int len = vma->vm_end - vma->vm_start;
136 u32 key = vma->vm_pgoff << PAGE_SHIFT;
137 struct c4iw_rdev *rdev;
138 int ret = 0;
139 struct c4iw_mm_entry *mm;
140 struct c4iw_ucontext *ucontext;
141 u64 addr;
142
548ddb19 143 pr_debug("pgoff 0x%lx key 0x%x len %d\n", vma->vm_pgoff,
a9a42886 144 key, len);
cfdda9d7
SW
145
146 if (vma->vm_start & (PAGE_SIZE-1))
147 return -EINVAL;
148
149 rdev = &(to_c4iw_dev(context->device)->rdev);
150 ucontext = to_c4iw_ucontext(context);
151
152 mm = remove_mmap(ucontext, key, len);
153 if (!mm)
154 return -EINVAL;
155 addr = mm->addr;
156 kfree(mm);
157
c6d7b267
SW
158 if ((addr >= pci_resource_start(rdev->lldi.pdev, 0)) &&
159 (addr < (pci_resource_start(rdev->lldi.pdev, 0) +
160 pci_resource_len(rdev->lldi.pdev, 0)))) {
cfdda9d7
SW
161
162 /*
c6d7b267 163 * MA_SYNC register...
cfdda9d7 164 */
cfdda9d7 165 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
c6d7b267
SW
166 ret = io_remap_pfn_range(vma, vma->vm_start,
167 addr >> PAGE_SHIFT,
168 len, vma->vm_page_prot);
169 } else if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) &&
170 (addr < (pci_resource_start(rdev->lldi.pdev, 2) +
171 pci_resource_len(rdev->lldi.pdev, 2)))) {
172
173 /*
174 * Map user DB or OCQP memory...
175 */
176 if (addr >= rdev->oc_mw_pa)
177 vma->vm_page_prot = t4_pgprot_wc(vma->vm_page_prot);
f079af7a 178 else {
963cab50 179 if (!is_t4(rdev->lldi.adapter_type))
f079af7a
VP
180 vma->vm_page_prot =
181 t4_pgprot_wc(vma->vm_page_prot);
182 else
183 vma->vm_page_prot =
184 pgprot_noncached(vma->vm_page_prot);
185 }
cfdda9d7
SW
186 ret = io_remap_pfn_range(vma, vma->vm_start,
187 addr >> PAGE_SHIFT,
188 len, vma->vm_page_prot);
189 } else {
190
191 /*
192 * Map WQ or CQ contig dma memory...
193 */
194 ret = remap_pfn_range(vma, vma->vm_start,
195 addr >> PAGE_SHIFT,
196 len, vma->vm_page_prot);
197 }
198
199 return ret;
200}
201
21a428a0 202static void c4iw_deallocate_pd(struct ib_pd *pd)
cfdda9d7
SW
203{
204 struct c4iw_dev *rhp;
205 struct c4iw_pd *php;
206
207 php = to_c4iw_pd(pd);
208 rhp = php->rhp;
548ddb19 209 pr_debug("ibpd %p pdid 0x%x\n", pd, php->pdid);
ec3eead2 210 c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid);
8d81ef34
VP
211 mutex_lock(&rhp->rdev.stats.lock);
212 rhp->rdev.stats.pd.cur--;
213 mutex_unlock(&rhp->rdev.stats.lock);
cfdda9d7
SW
214}
215
21a428a0
LR
216static int c4iw_allocate_pd(struct ib_pd *pd, struct ib_ucontext *context,
217 struct ib_udata *udata)
cfdda9d7 218{
21a428a0
LR
219 struct c4iw_pd *php = to_c4iw_pd(pd);
220 struct ib_device *ibdev = pd->device;
cfdda9d7
SW
221 u32 pdid;
222 struct c4iw_dev *rhp;
223
548ddb19 224 pr_debug("ibdev %p\n", ibdev);
cfdda9d7 225 rhp = (struct c4iw_dev *) ibdev;
ec3eead2 226 pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table);
cfdda9d7 227 if (!pdid)
21a428a0
LR
228 return -EINVAL;
229
cfdda9d7
SW
230 php->pdid = pdid;
231 php->rhp = rhp;
232 if (context) {
7f86260b
JG
233 struct c4iw_alloc_pd_resp uresp = {.pdid = php->pdid};
234
235 if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) {
cfdda9d7 236 c4iw_deallocate_pd(&php->ibpd);
21a428a0 237 return -EFAULT;
cfdda9d7
SW
238 }
239 }
8d81ef34
VP
240 mutex_lock(&rhp->rdev.stats.lock);
241 rhp->rdev.stats.pd.cur++;
242 if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max)
243 rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur;
244 mutex_unlock(&rhp->rdev.stats.lock);
548ddb19 245 pr_debug("pdid 0x%0x ptr 0x%p\n", pdid, php);
21a428a0 246 return 0;
cfdda9d7
SW
247}
248
249static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
250 u16 *pkey)
251{
548ddb19 252 pr_debug("ibdev %p\n", ibdev);
cfdda9d7
SW
253 *pkey = 0;
254 return 0;
255}
256
257static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index,
258 union ib_gid *gid)
259{
260 struct c4iw_dev *dev;
261
548ddb19
BP
262 pr_debug("ibdev %p, port %d, index %d, gid %p\n",
263 ibdev, port, index, gid);
ba97b749
SW
264 if (!port)
265 return -EINVAL;
cfdda9d7 266 dev = to_c4iw_dev(ibdev);
cfdda9d7
SW
267 memset(&(gid->raw[0]), 0, sizeof(gid->raw));
268 memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6);
269 return 0;
270}
271
2528e33e
MB
272static int c4iw_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
273 struct ib_udata *uhw)
cfdda9d7
SW
274{
275
276 struct c4iw_dev *dev;
2528e33e 277
548ddb19 278 pr_debug("ibdev %p\n", ibdev);
cfdda9d7 279
2528e33e
MB
280 if (uhw->inlen || uhw->outlen)
281 return -EINVAL;
282
cfdda9d7
SW
283 dev = to_c4iw_dev(ibdev);
284 memset(props, 0, sizeof *props);
285 memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
f079af7a 286 props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type);
cfdda9d7
SW
287 props->fw_ver = dev->rdev.lldi.fw_vers;
288 props->device_cap_flags = dev->device_cap_flags;
289 props->page_size_cap = T4_PAGESIZE_MASK;
290 props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor;
291 props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device;
292 props->max_mr_size = T4_MAX_MR_SIZE;
66eb19af 293 props->max_qp = dev->rdev.lldi.vr->qp.size / 2;
6a0b6174 294 props->max_srq = dev->rdev.lldi.vr->srq.size;
04e10e21 295 props->max_qp_wr = dev->rdev.hw_queue.t4_max_qp_depth;
6a0b6174 296 props->max_srq_wr = dev->rdev.hw_queue.t4_max_qp_depth;
33023fb8
SW
297 props->max_send_sge = min(T4_MAX_SEND_SGE, T4_MAX_WRITE_SGE);
298 props->max_recv_sge = T4_MAX_RECV_SGE;
6a0b6174 299 props->max_srq_sge = T4_MAX_RECV_SGE;
cfdda9d7 300 props->max_sge_rd = 1;
4c2c5763
HS
301 props->max_res_rd_atom = dev->rdev.lldi.max_ird_adapter;
302 props->max_qp_rd_atom = min(dev->rdev.lldi.max_ordird_qp,
303 c4iw_max_read_depth);
304 props->max_qp_init_rd_atom = props->max_qp_rd_atom;
66eb19af 305 props->max_cq = dev->rdev.lldi.vr->qp.size;
04e10e21 306 props->max_cqe = dev->rdev.hw_queue.t4_max_cq_depth;
cfdda9d7
SW
307 props->max_mr = c4iw_num_stags(&dev->rdev);
308 props->max_pd = T4_MAX_NUM_PD;
309 props->local_ca_ack_delay = 0;
ee30f7d5
H
310 props->max_fast_reg_page_list_len =
311 t4_max_fr_depth(dev->rdev.lldi.ulptx_memwrite_dsgl && use_dsgl);
cfdda9d7
SW
312
313 return 0;
314}
315
316static int c4iw_query_port(struct ib_device *ibdev, u8 port,
317 struct ib_port_attr *props)
318{
319 struct c4iw_dev *dev;
320 struct net_device *netdev;
321 struct in_device *inetdev;
322
548ddb19 323 pr_debug("ibdev %p\n", ibdev);
cfdda9d7
SW
324
325 dev = to_c4iw_dev(ibdev);
326 netdev = dev->rdev.lldi.ports[port-1];
c4550c63 327 /* props being zeroed by the caller, avoid zeroing it here */
cfdda9d7 328 props->max_mtu = IB_MTU_4096;
d3f4aadd 329 props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
cfdda9d7
SW
330
331 if (!netif_carrier_ok(netdev))
332 props->state = IB_PORT_DOWN;
333 else {
334 inetdev = in_dev_get(netdev);
335 if (inetdev) {
336 if (inetdev->ifa_list)
337 props->state = IB_PORT_ACTIVE;
338 else
339 props->state = IB_PORT_INIT;
340 in_dev_put(inetdev);
341 } else
342 props->state = IB_PORT_INIT;
343 }
344
345 props->port_cap_flags =
346 IB_PORT_CM_SUP |
347 IB_PORT_SNMP_TUNNEL_SUP |
348 IB_PORT_REINIT_SUP |
349 IB_PORT_DEVICE_MGMT_SUP |
350 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
351 props->gid_tbl_len = 1;
352 props->pkey_tbl_len = 1;
353 props->active_width = 2;
2e96691c 354 props->active_speed = IB_SPEED_DDR;
cfdda9d7
SW
355 props->max_msg_sz = -1;
356
357 return 0;
358}
359
508a523f
PP
360static ssize_t hw_rev_show(struct device *dev,
361 struct device_attribute *attr, char *buf)
cfdda9d7 362{
54747231
PP
363 struct c4iw_dev *c4iw_dev =
364 rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
365
548ddb19 366 pr_debug("dev 0x%p\n", dev);
f079af7a
VP
367 return sprintf(buf, "%d\n",
368 CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type));
cfdda9d7 369}
508a523f 370static DEVICE_ATTR_RO(hw_rev);
cfdda9d7 371
508a523f
PP
372static ssize_t hca_type_show(struct device *dev,
373 struct device_attribute *attr, char *buf)
cfdda9d7 374{
54747231
PP
375 struct c4iw_dev *c4iw_dev =
376 rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
cfdda9d7
SW
377 struct ethtool_drvinfo info;
378 struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0];
379
548ddb19 380 pr_debug("dev 0x%p\n", dev);
cfdda9d7
SW
381 lldev->ethtool_ops->get_drvinfo(lldev, &info);
382 return sprintf(buf, "%s\n", info.driver);
383}
508a523f 384static DEVICE_ATTR_RO(hca_type);
cfdda9d7 385
508a523f
PP
386static ssize_t board_id_show(struct device *dev, struct device_attribute *attr,
387 char *buf)
cfdda9d7 388{
54747231
PP
389 struct c4iw_dev *c4iw_dev =
390 rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
391
548ddb19 392 pr_debug("dev 0x%p\n", dev);
cfdda9d7
SW
393 return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor,
394 c4iw_dev->rdev.lldi.pdev->device);
395}
508a523f 396static DEVICE_ATTR_RO(board_id);
cfdda9d7 397
b40f4757
CL
398enum counters {
399 IP4INSEGS,
400 IP4OUTSEGS,
401 IP4RETRANSSEGS,
402 IP4OUTRSTS,
403 IP6INSEGS,
404 IP6OUTSEGS,
405 IP6RETRANSSEGS,
406 IP6OUTRSTS,
407 NR_COUNTERS
408};
409
410static const char * const names[] = {
411 [IP4INSEGS] = "ip4InSegs",
412 [IP4OUTSEGS] = "ip4OutSegs",
413 [IP4RETRANSSEGS] = "ip4RetransSegs",
414 [IP4OUTRSTS] = "ip4OutRsts",
415 [IP6INSEGS] = "ip6InSegs",
416 [IP6OUTSEGS] = "ip6OutSegs",
417 [IP6RETRANSSEGS] = "ip6RetransSegs",
418 [IP6OUTRSTS] = "ip6OutRsts"
419};
420
421static struct rdma_hw_stats *c4iw_alloc_stats(struct ib_device *ibdev,
422 u8 port_num)
423{
424 BUILD_BUG_ON(ARRAY_SIZE(names) != NR_COUNTERS);
425
426 if (port_num != 0)
427 return NULL;
428
429 return rdma_alloc_hw_stats_struct(names, NR_COUNTERS,
430 RDMA_HW_STATS_DEFAULT_LIFESPAN);
431}
432
cfdda9d7 433static int c4iw_get_mib(struct ib_device *ibdev,
b40f4757
CL
434 struct rdma_hw_stats *stats,
435 u8 port, int index)
cfdda9d7 436{
de5dd81b
SW
437 struct tp_tcp_stats v4, v6;
438 struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev);
439
440 cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6);
b40f4757
CL
441 stats->value[IP4INSEGS] = v4.tcp_in_segs;
442 stats->value[IP4OUTSEGS] = v4.tcp_out_segs;
443 stats->value[IP4RETRANSSEGS] = v4.tcp_retrans_segs;
444 stats->value[IP4OUTRSTS] = v4.tcp_out_rsts;
445 stats->value[IP6INSEGS] = v6.tcp_in_segs;
446 stats->value[IP6OUTSEGS] = v6.tcp_out_segs;
447 stats->value[IP6RETRANSSEGS] = v6.tcp_retrans_segs;
448 stats->value[IP6OUTRSTS] = v6.tcp_out_rsts;
449
450 return stats->num_counters;
cfdda9d7
SW
451}
452
508a523f
PP
453static struct attribute *c4iw_class_attributes[] = {
454 &dev_attr_hw_rev.attr,
455 &dev_attr_hca_type.attr,
456 &dev_attr_board_id.attr,
457 NULL
458};
cfdda9d7 459
508a523f
PP
460static const struct attribute_group c4iw_attr_group = {
461 .attrs = c4iw_class_attributes,
cfdda9d7
SW
462};
463
7738613e
IW
464static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num,
465 struct ib_port_immutable *immutable)
466{
467 struct ib_port_attr attr;
468 int err;
469
c4550c63
OG
470 immutable->core_cap_flags = RDMA_CORE_PORT_IWARP;
471
472 err = ib_query_port(ibdev, port_num, &attr);
7738613e
IW
473 if (err)
474 return err;
475
476 immutable->pkey_tbl_len = attr.pkey_tbl_len;
477 immutable->gid_tbl_len = attr.gid_tbl_len;
478
479 return 0;
480}
481
9abb0d1b 482static void get_dev_fw_str(struct ib_device *dev, char *str)
ce192243
IW
483{
484 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
485 ibdev);
548ddb19 486 pr_debug("dev 0x%p\n", dev);
ce192243 487
9abb0d1b 488 snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u.%u",
ce192243
IW
489 FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers),
490 FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers),
491 FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers),
492 FW_HDR_FW_VER_BUILD_G(c4iw_dev->rdev.lldi.fw_vers));
493}
494
f215a3d2
SW
495static struct net_device *get_netdev(struct ib_device *dev, u8 port)
496{
497 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, ibdev);
498 struct c4iw_rdev *rdev = &c4iw_dev->rdev;
499 struct net_device *ndev;
500
501 if (!port || port > rdev->lldi.nports)
502 return NULL;
503
504 rcu_read_lock();
505 ndev = rdev->lldi.ports[port - 1];
506 if (ndev)
507 dev_hold(ndev);
508 rcu_read_unlock();
509
510 return ndev;
511}
512
056f9c7f
SW
513static int fill_res_entry(struct sk_buff *msg, struct rdma_restrack_entry *res)
514{
515 return (res->type < ARRAY_SIZE(c4iw_restrack_funcs) &&
516 c4iw_restrack_funcs[res->type]) ?
517 c4iw_restrack_funcs[res->type](msg, res) : 0;
518}
519
dad3b05d
KH
520static const struct ib_device_ops c4iw_dev_ops = {
521 .alloc_hw_stats = c4iw_alloc_stats,
522 .alloc_mr = c4iw_alloc_mr,
523 .alloc_mw = c4iw_alloc_mw,
524 .alloc_pd = c4iw_allocate_pd,
525 .alloc_ucontext = c4iw_alloc_ucontext,
526 .create_cq = c4iw_create_cq,
527 .create_qp = c4iw_create_qp,
528 .create_srq = c4iw_create_srq,
529 .dealloc_mw = c4iw_dealloc_mw,
530 .dealloc_pd = c4iw_deallocate_pd,
531 .dealloc_ucontext = c4iw_dealloc_ucontext,
532 .dereg_mr = c4iw_dereg_mr,
533 .destroy_cq = c4iw_destroy_cq,
534 .destroy_qp = c4iw_destroy_qp,
535 .destroy_srq = c4iw_destroy_srq,
02da3750 536 .fill_res_entry = fill_res_entry,
dad3b05d
KH
537 .get_dev_fw_str = get_dev_fw_str,
538 .get_dma_mr = c4iw_get_dma_mr,
539 .get_hw_stats = c4iw_get_mib,
540 .get_netdev = get_netdev,
541 .get_port_immutable = c4iw_port_immutable,
542 .map_mr_sg = c4iw_map_mr_sg,
543 .mmap = c4iw_mmap,
544 .modify_qp = c4iw_ib_modify_qp,
545 .modify_srq = c4iw_modify_srq,
546 .poll_cq = c4iw_poll_cq,
547 .post_recv = c4iw_post_receive,
548 .post_send = c4iw_post_send,
549 .post_srq_recv = c4iw_post_srq_recv,
550 .query_device = c4iw_query_device,
551 .query_gid = c4iw_query_gid,
552 .query_pkey = c4iw_query_pkey,
553 .query_port = c4iw_query_port,
554 .query_qp = c4iw_ib_query_qp,
555 .reg_user_mr = c4iw_reg_user_mr,
556 .req_notify_cq = c4iw_arm_cq,
21a428a0 557 INIT_RDMA_OBJ_SIZE(ib_pd, c4iw_pd, ibpd),
dad3b05d
KH
558};
559
1c8f1da5 560void c4iw_register_device(struct work_struct *work)
cfdda9d7
SW
561{
562 int ret;
1c8f1da5
BP
563 struct uld_ctx *ctx = container_of(work, struct uld_ctx, reg_work);
564 struct c4iw_dev *dev = ctx->dev;
cfdda9d7 565
548ddb19 566 pr_debug("c4iw_dev %p\n", dev);
cfdda9d7
SW
567 memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
568 memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
569 dev->ibdev.owner = THIS_MODULE;
570 dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW;
571 if (fastreg_support)
572 dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
573 dev->ibdev.local_dma_lkey = 0;
574 dev->ibdev.uverbs_cmd_mask =
575 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
576 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
577 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
578 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
579 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
580 (1ull << IB_USER_VERBS_CMD_REG_MR) |
581 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
582 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
583 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
584 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
585 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
586 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
587 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
67bbc055 588 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
cfdda9d7
SW
589 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
590 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
591 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
6a0b6174
RR
592 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
593 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
594 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
595 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
cfdda9d7 596 dev->ibdev.node_type = RDMA_NODE_RNIC;
bd99fdea 597 BUILD_BUG_ON(sizeof(C4IW_NODE_DESC) > IB_DEVICE_NODE_DESC_MAX);
cfdda9d7
SW
598 memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC));
599 dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports;
cf38be6d 600 dev->ibdev.num_comp_vectors = dev->rdev.lldi.nciq;
d08868a1 601 dev->ibdev.dev.parent = &dev->rdev.lldi.pdev->dev;
c6d7b267 602 dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION;
cfdda9d7 603
95b8e384 604 dev->ibdev.iwcm = kzalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
1c8f1da5
BP
605 if (!dev->ibdev.iwcm) {
606 ret = -ENOMEM;
607 goto err_dealloc_ctx;
608 }
cfdda9d7
SW
609
610 dev->ibdev.iwcm->connect = c4iw_connect;
611 dev->ibdev.iwcm->accept = c4iw_accept_cr;
612 dev->ibdev.iwcm->reject = c4iw_reject_cr;
613 dev->ibdev.iwcm->create_listen = c4iw_create_listen;
614 dev->ibdev.iwcm->destroy_listen = c4iw_destroy_listen;
615 dev->ibdev.iwcm->add_ref = c4iw_qp_add_ref;
616 dev->ibdev.iwcm->rem_ref = c4iw_qp_rem_ref;
617 dev->ibdev.iwcm->get_qp = c4iw_get_qp;
851d7b6b
SW
618 memcpy(dev->ibdev.iwcm->ifname, dev->rdev.lldi.ports[0]->name,
619 sizeof(dev->ibdev.iwcm->ifname));
cfdda9d7 620
508a523f 621 rdma_set_device_sysfs_group(&dev->ibdev, &c4iw_attr_group);
0ede73bc 622 dev->ibdev.driver_id = RDMA_DRIVER_CXGB4;
dad3b05d 623 ib_set_device_ops(&dev->ibdev, &c4iw_dev_ops);
ea4baf7f 624 ret = ib_register_device(&dev->ibdev, "cxgb4_%d");
cfdda9d7 625 if (ret)
1c8f1da5 626 goto err_kfree_iwcm;
1c8f1da5 627 return;
508a523f 628
1c8f1da5 629err_kfree_iwcm:
cfdda9d7 630 kfree(dev->ibdev.iwcm);
1c8f1da5
BP
631err_dealloc_ctx:
632 pr_err("%s - Failed registering iwarp device: %d\n",
633 pci_name(ctx->lldi.pdev), ret);
634 c4iw_dealloc(ctx);
635 return;
cfdda9d7
SW
636}
637
638void c4iw_unregister_device(struct c4iw_dev *dev)
639{
548ddb19 640 pr_debug("c4iw_dev %p\n", dev);
cfdda9d7
SW
641 ib_unregister_device(&dev->ibdev);
642 kfree(dev->ibdev.iwcm);
643 return;
644}