Loading...
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 <net/addrconf.h>
45#include <linux/io.h>
46
47#include <asm/irq.h>
48#include <asm/byteorder.h>
49
50#include <rdma/iw_cm.h>
51#include <rdma/ib_verbs.h>
52#include <rdma/ib_smi.h>
53#include <rdma/ib_umem.h>
54#include <rdma/ib_user_verbs.h>
55
56#include "iw_cxgb4.h"
57
58static int fastreg_support = 1;
59module_param(fastreg_support, int, 0644);
60MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)");
61
62static void c4iw_dealloc_ucontext(struct ib_ucontext *context)
63{
64 struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context);
65 struct c4iw_dev *rhp;
66 struct c4iw_mm_entry *mm, *tmp;
67
68 pr_debug("context %p\n", context);
69 rhp = to_c4iw_dev(ucontext->ibucontext.device);
70
71 list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
72 kfree(mm);
73 c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx);
74}
75
76static int c4iw_alloc_ucontext(struct ib_ucontext *ucontext,
77 struct ib_udata *udata)
78{
79 struct ib_device *ibdev = ucontext->device;
80 struct c4iw_ucontext *context = to_c4iw_ucontext(ucontext);
81 struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
82 struct c4iw_alloc_ucontext_resp uresp;
83 int ret = 0;
84 struct c4iw_mm_entry *mm = NULL;
85
86 pr_debug("ibdev %p\n", ibdev);
87 c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx);
88 INIT_LIST_HEAD(&context->mmaps);
89 spin_lock_init(&context->mmap_lock);
90
91 if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) {
92 pr_err_once("Warning - downlevel libcxgb4 (non-fatal), device status page disabled\n");
93 rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED;
94 } else {
95 mm = kmalloc(sizeof(*mm), GFP_KERNEL);
96 if (!mm) {
97 ret = -ENOMEM;
98 goto err;
99 }
100
101 uresp.status_page_size = PAGE_SIZE;
102
103 spin_lock(&context->mmap_lock);
104 uresp.status_page_key = context->key;
105 context->key += PAGE_SIZE;
106 spin_unlock(&context->mmap_lock);
107
108 ret = ib_copy_to_udata(udata, &uresp,
109 sizeof(uresp) - sizeof(uresp.reserved));
110 if (ret)
111 goto err_mm;
112
113 mm->key = uresp.status_page_key;
114 mm->addr = virt_to_phys(rhp->rdev.status_page);
115 mm->len = PAGE_SIZE;
116 insert_mmap(context, mm);
117 }
118 return 0;
119err_mm:
120 kfree(mm);
121err:
122 return ret;
123}
124
125static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
126{
127 int len = vma->vm_end - vma->vm_start;
128 u32 key = vma->vm_pgoff << PAGE_SHIFT;
129 struct c4iw_rdev *rdev;
130 int ret = 0;
131 struct c4iw_mm_entry *mm;
132 struct c4iw_ucontext *ucontext;
133 u64 addr;
134
135 pr_debug("pgoff 0x%lx key 0x%x len %d\n", vma->vm_pgoff,
136 key, len);
137
138 if (vma->vm_start & (PAGE_SIZE-1))
139 return -EINVAL;
140
141 rdev = &(to_c4iw_dev(context->device)->rdev);
142 ucontext = to_c4iw_ucontext(context);
143
144 mm = remove_mmap(ucontext, key, len);
145 if (!mm)
146 return -EINVAL;
147 addr = mm->addr;
148 kfree(mm);
149
150 if ((addr >= pci_resource_start(rdev->lldi.pdev, 0)) &&
151 (addr < (pci_resource_start(rdev->lldi.pdev, 0) +
152 pci_resource_len(rdev->lldi.pdev, 0)))) {
153
154 /*
155 * MA_SYNC register...
156 */
157 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
158 ret = io_remap_pfn_range(vma, vma->vm_start,
159 addr >> PAGE_SHIFT,
160 len, vma->vm_page_prot);
161 } else if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) &&
162 (addr < (pci_resource_start(rdev->lldi.pdev, 2) +
163 pci_resource_len(rdev->lldi.pdev, 2)))) {
164
165 /*
166 * Map user DB or OCQP memory...
167 */
168 if (addr >= rdev->oc_mw_pa)
169 vma->vm_page_prot = t4_pgprot_wc(vma->vm_page_prot);
170 else {
171 if (!is_t4(rdev->lldi.adapter_type))
172 vma->vm_page_prot =
173 t4_pgprot_wc(vma->vm_page_prot);
174 else
175 vma->vm_page_prot =
176 pgprot_noncached(vma->vm_page_prot);
177 }
178 ret = io_remap_pfn_range(vma, vma->vm_start,
179 addr >> PAGE_SHIFT,
180 len, vma->vm_page_prot);
181 } else {
182
183 /*
184 * Map WQ or CQ contig dma memory...
185 */
186 ret = remap_pfn_range(vma, vma->vm_start,
187 addr >> PAGE_SHIFT,
188 len, vma->vm_page_prot);
189 }
190
191 return ret;
192}
193
194static int c4iw_deallocate_pd(struct ib_pd *pd, struct ib_udata *udata)
195{
196 struct c4iw_dev *rhp;
197 struct c4iw_pd *php;
198
199 php = to_c4iw_pd(pd);
200 rhp = php->rhp;
201 pr_debug("ibpd %p pdid 0x%x\n", pd, php->pdid);
202 c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid);
203 mutex_lock(&rhp->rdev.stats.lock);
204 rhp->rdev.stats.pd.cur--;
205 mutex_unlock(&rhp->rdev.stats.lock);
206 return 0;
207}
208
209static int c4iw_allocate_pd(struct ib_pd *pd, struct ib_udata *udata)
210{
211 struct c4iw_pd *php = to_c4iw_pd(pd);
212 struct ib_device *ibdev = pd->device;
213 u32 pdid;
214 struct c4iw_dev *rhp;
215
216 pr_debug("ibdev %p\n", ibdev);
217 rhp = (struct c4iw_dev *) ibdev;
218 pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table);
219 if (!pdid)
220 return -EINVAL;
221
222 php->pdid = pdid;
223 php->rhp = rhp;
224 if (udata) {
225 struct c4iw_alloc_pd_resp uresp = {.pdid = php->pdid};
226
227 if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) {
228 c4iw_deallocate_pd(&php->ibpd, udata);
229 return -EFAULT;
230 }
231 }
232 mutex_lock(&rhp->rdev.stats.lock);
233 rhp->rdev.stats.pd.cur++;
234 if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max)
235 rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur;
236 mutex_unlock(&rhp->rdev.stats.lock);
237 pr_debug("pdid 0x%0x ptr 0x%p\n", pdid, php);
238 return 0;
239}
240
241static int c4iw_query_gid(struct ib_device *ibdev, u32 port, int index,
242 union ib_gid *gid)
243{
244 struct c4iw_dev *dev;
245
246 pr_debug("ibdev %p, port %u, index %d, gid %p\n",
247 ibdev, port, index, gid);
248 if (!port)
249 return -EINVAL;
250 dev = to_c4iw_dev(ibdev);
251 memset(&(gid->raw[0]), 0, sizeof(gid->raw));
252 memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6);
253 return 0;
254}
255
256static int c4iw_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
257 struct ib_udata *uhw)
258{
259
260 struct c4iw_dev *dev;
261
262 pr_debug("ibdev %p\n", ibdev);
263
264 if (uhw->inlen || uhw->outlen)
265 return -EINVAL;
266
267 dev = to_c4iw_dev(ibdev);
268 addrconf_addr_eui48((u8 *)&props->sys_image_guid,
269 dev->rdev.lldi.ports[0]->dev_addr);
270 props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type);
271 props->fw_ver = dev->rdev.lldi.fw_vers;
272 props->device_cap_flags = IB_DEVICE_MEM_WINDOW;
273 props->kernel_cap_flags = IBK_LOCAL_DMA_LKEY;
274 if (fastreg_support)
275 props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
276 props->page_size_cap = T4_PAGESIZE_MASK;
277 props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor;
278 props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device;
279 props->max_mr_size = T4_MAX_MR_SIZE;
280 props->max_qp = dev->rdev.lldi.vr->qp.size / 2;
281 props->max_srq = dev->rdev.lldi.vr->srq.size;
282 props->max_qp_wr = dev->rdev.hw_queue.t4_max_qp_depth;
283 props->max_srq_wr = dev->rdev.hw_queue.t4_max_qp_depth;
284 props->max_send_sge = min(T4_MAX_SEND_SGE, T4_MAX_WRITE_SGE);
285 props->max_recv_sge = T4_MAX_RECV_SGE;
286 props->max_srq_sge = T4_MAX_RECV_SGE;
287 props->max_sge_rd = 1;
288 props->max_res_rd_atom = dev->rdev.lldi.max_ird_adapter;
289 props->max_qp_rd_atom = min(dev->rdev.lldi.max_ordird_qp,
290 c4iw_max_read_depth);
291 props->max_qp_init_rd_atom = props->max_qp_rd_atom;
292 props->max_cq = dev->rdev.lldi.vr->qp.size;
293 props->max_cqe = dev->rdev.hw_queue.t4_max_cq_depth;
294 props->max_mr = c4iw_num_stags(&dev->rdev);
295 props->max_pd = T4_MAX_NUM_PD;
296 props->local_ca_ack_delay = 0;
297 props->max_fast_reg_page_list_len =
298 t4_max_fr_depth(dev->rdev.lldi.ulptx_memwrite_dsgl && use_dsgl);
299
300 return 0;
301}
302
303static int c4iw_query_port(struct ib_device *ibdev, u32 port,
304 struct ib_port_attr *props)
305{
306 int ret = 0;
307 pr_debug("ibdev %p\n", ibdev);
308 ret = ib_get_eth_speed(ibdev, port, &props->active_speed,
309 &props->active_width);
310
311 props->port_cap_flags =
312 IB_PORT_CM_SUP |
313 IB_PORT_SNMP_TUNNEL_SUP |
314 IB_PORT_REINIT_SUP |
315 IB_PORT_DEVICE_MGMT_SUP |
316 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
317 props->gid_tbl_len = 1;
318 props->max_msg_sz = -1;
319
320 return ret;
321}
322
323static ssize_t hw_rev_show(struct device *dev,
324 struct device_attribute *attr, char *buf)
325{
326 struct c4iw_dev *c4iw_dev =
327 rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
328
329 pr_debug("dev 0x%p\n", dev);
330 return sysfs_emit(
331 buf, "%d\n",
332 CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type));
333}
334static DEVICE_ATTR_RO(hw_rev);
335
336static ssize_t hca_type_show(struct device *dev,
337 struct device_attribute *attr, char *buf)
338{
339 struct c4iw_dev *c4iw_dev =
340 rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
341 struct ethtool_drvinfo info;
342 struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0];
343
344 pr_debug("dev 0x%p\n", dev);
345 lldev->ethtool_ops->get_drvinfo(lldev, &info);
346 return sysfs_emit(buf, "%s\n", info.driver);
347}
348static DEVICE_ATTR_RO(hca_type);
349
350static ssize_t board_id_show(struct device *dev, struct device_attribute *attr,
351 char *buf)
352{
353 struct c4iw_dev *c4iw_dev =
354 rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
355
356 pr_debug("dev 0x%p\n", dev);
357 return sysfs_emit(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor,
358 c4iw_dev->rdev.lldi.pdev->device);
359}
360static DEVICE_ATTR_RO(board_id);
361
362enum counters {
363 IP4INSEGS,
364 IP4OUTSEGS,
365 IP4RETRANSSEGS,
366 IP4OUTRSTS,
367 IP6INSEGS,
368 IP6OUTSEGS,
369 IP6RETRANSSEGS,
370 IP6OUTRSTS,
371 NR_COUNTERS
372};
373
374static const struct rdma_stat_desc cxgb4_descs[] = {
375 [IP4INSEGS].name = "ip4InSegs",
376 [IP4OUTSEGS].name = "ip4OutSegs",
377 [IP4RETRANSSEGS].name = "ip4RetransSegs",
378 [IP4OUTRSTS].name = "ip4OutRsts",
379 [IP6INSEGS].name = "ip6InSegs",
380 [IP6OUTSEGS].name = "ip6OutSegs",
381 [IP6RETRANSSEGS].name = "ip6RetransSegs",
382 [IP6OUTRSTS].name = "ip6OutRsts"
383};
384
385static struct rdma_hw_stats *c4iw_alloc_device_stats(struct ib_device *ibdev)
386{
387 BUILD_BUG_ON(ARRAY_SIZE(cxgb4_descs) != NR_COUNTERS);
388
389 /* FIXME: these look like port stats */
390 return rdma_alloc_hw_stats_struct(cxgb4_descs, NR_COUNTERS,
391 RDMA_HW_STATS_DEFAULT_LIFESPAN);
392}
393
394static int c4iw_get_mib(struct ib_device *ibdev,
395 struct rdma_hw_stats *stats,
396 u32 port, int index)
397{
398 struct tp_tcp_stats v4, v6;
399 struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev);
400
401 cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6);
402 stats->value[IP4INSEGS] = v4.tcp_in_segs;
403 stats->value[IP4OUTSEGS] = v4.tcp_out_segs;
404 stats->value[IP4RETRANSSEGS] = v4.tcp_retrans_segs;
405 stats->value[IP4OUTRSTS] = v4.tcp_out_rsts;
406 stats->value[IP6INSEGS] = v6.tcp_in_segs;
407 stats->value[IP6OUTSEGS] = v6.tcp_out_segs;
408 stats->value[IP6RETRANSSEGS] = v6.tcp_retrans_segs;
409 stats->value[IP6OUTRSTS] = v6.tcp_out_rsts;
410
411 return stats->num_counters;
412}
413
414static struct attribute *c4iw_class_attributes[] = {
415 &dev_attr_hw_rev.attr,
416 &dev_attr_hca_type.attr,
417 &dev_attr_board_id.attr,
418 NULL
419};
420
421static const struct attribute_group c4iw_attr_group = {
422 .attrs = c4iw_class_attributes,
423};
424
425static int c4iw_port_immutable(struct ib_device *ibdev, u32 port_num,
426 struct ib_port_immutable *immutable)
427{
428 struct ib_port_attr attr;
429 int err;
430
431 immutable->core_cap_flags = RDMA_CORE_PORT_IWARP;
432
433 err = ib_query_port(ibdev, port_num, &attr);
434 if (err)
435 return err;
436
437 immutable->gid_tbl_len = attr.gid_tbl_len;
438
439 return 0;
440}
441
442static void get_dev_fw_str(struct ib_device *dev, char *str)
443{
444 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
445 ibdev);
446 pr_debug("dev 0x%p\n", dev);
447
448 snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u.%u",
449 FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers),
450 FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers),
451 FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers),
452 FW_HDR_FW_VER_BUILD_G(c4iw_dev->rdev.lldi.fw_vers));
453}
454
455static const struct ib_device_ops c4iw_dev_ops = {
456 .owner = THIS_MODULE,
457 .driver_id = RDMA_DRIVER_CXGB4,
458 .uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION,
459
460 .alloc_hw_device_stats = c4iw_alloc_device_stats,
461 .alloc_mr = c4iw_alloc_mr,
462 .alloc_pd = c4iw_allocate_pd,
463 .alloc_ucontext = c4iw_alloc_ucontext,
464 .create_cq = c4iw_create_cq,
465 .create_qp = c4iw_create_qp,
466 .create_srq = c4iw_create_srq,
467 .dealloc_pd = c4iw_deallocate_pd,
468 .dealloc_ucontext = c4iw_dealloc_ucontext,
469 .dereg_mr = c4iw_dereg_mr,
470 .destroy_cq = c4iw_destroy_cq,
471 .destroy_qp = c4iw_destroy_qp,
472 .destroy_srq = c4iw_destroy_srq,
473 .device_group = &c4iw_attr_group,
474 .fill_res_cq_entry = c4iw_fill_res_cq_entry,
475 .fill_res_cm_id_entry = c4iw_fill_res_cm_id_entry,
476 .fill_res_mr_entry = c4iw_fill_res_mr_entry,
477 .get_dev_fw_str = get_dev_fw_str,
478 .get_dma_mr = c4iw_get_dma_mr,
479 .get_hw_stats = c4iw_get_mib,
480 .get_port_immutable = c4iw_port_immutable,
481 .iw_accept = c4iw_accept_cr,
482 .iw_add_ref = c4iw_qp_add_ref,
483 .iw_connect = c4iw_connect,
484 .iw_create_listen = c4iw_create_listen,
485 .iw_destroy_listen = c4iw_destroy_listen,
486 .iw_get_qp = c4iw_get_qp,
487 .iw_reject = c4iw_reject_cr,
488 .iw_rem_ref = c4iw_qp_rem_ref,
489 .map_mr_sg = c4iw_map_mr_sg,
490 .mmap = c4iw_mmap,
491 .modify_qp = c4iw_ib_modify_qp,
492 .modify_srq = c4iw_modify_srq,
493 .poll_cq = c4iw_poll_cq,
494 .post_recv = c4iw_post_receive,
495 .post_send = c4iw_post_send,
496 .post_srq_recv = c4iw_post_srq_recv,
497 .query_device = c4iw_query_device,
498 .query_gid = c4iw_query_gid,
499 .query_port = c4iw_query_port,
500 .query_qp = c4iw_ib_query_qp,
501 .reg_user_mr = c4iw_reg_user_mr,
502 .req_notify_cq = c4iw_arm_cq,
503
504 INIT_RDMA_OBJ_SIZE(ib_cq, c4iw_cq, ibcq),
505 INIT_RDMA_OBJ_SIZE(ib_mw, c4iw_mw, ibmw),
506 INIT_RDMA_OBJ_SIZE(ib_pd, c4iw_pd, ibpd),
507 INIT_RDMA_OBJ_SIZE(ib_qp, c4iw_qp, ibqp),
508 INIT_RDMA_OBJ_SIZE(ib_srq, c4iw_srq, ibsrq),
509 INIT_RDMA_OBJ_SIZE(ib_ucontext, c4iw_ucontext, ibucontext),
510};
511
512static int set_netdevs(struct ib_device *ib_dev, struct c4iw_rdev *rdev)
513{
514 int ret;
515 int i;
516
517 for (i = 0; i < rdev->lldi.nports; i++) {
518 ret = ib_device_set_netdev(ib_dev, rdev->lldi.ports[i],
519 i + 1);
520 if (ret)
521 return ret;
522 }
523 return 0;
524}
525
526void c4iw_register_device(struct work_struct *work)
527{
528 int ret;
529 struct uld_ctx *ctx = container_of(work, struct uld_ctx, reg_work);
530 struct c4iw_dev *dev = ctx->dev;
531
532 pr_debug("c4iw_dev %p\n", dev);
533 addrconf_addr_eui48((u8 *)&dev->ibdev.node_guid,
534 dev->rdev.lldi.ports[0]->dev_addr);
535 dev->ibdev.local_dma_lkey = 0;
536 dev->ibdev.node_type = RDMA_NODE_RNIC;
537 BUILD_BUG_ON(sizeof(C4IW_NODE_DESC) > IB_DEVICE_NODE_DESC_MAX);
538 memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC));
539 dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports;
540 dev->ibdev.num_comp_vectors = dev->rdev.lldi.nciq;
541 dev->ibdev.dev.parent = &dev->rdev.lldi.pdev->dev;
542
543 memcpy(dev->ibdev.iw_ifname, dev->rdev.lldi.ports[0]->name,
544 sizeof(dev->ibdev.iw_ifname));
545
546 ib_set_device_ops(&dev->ibdev, &c4iw_dev_ops);
547 ret = set_netdevs(&dev->ibdev, &dev->rdev);
548 if (ret)
549 goto err_dealloc_ctx;
550 dma_set_max_seg_size(&dev->rdev.lldi.pdev->dev, UINT_MAX);
551 ret = ib_register_device(&dev->ibdev, "cxgb4_%d",
552 &dev->rdev.lldi.pdev->dev);
553 if (ret)
554 goto err_dealloc_ctx;
555 return;
556
557err_dealloc_ctx:
558 pr_err("%s - Failed registering iwarp device: %d\n",
559 pci_name(ctx->lldi.pdev), ret);
560 c4iw_dealloc(ctx);
561 return;
562}
563
564void c4iw_unregister_device(struct c4iw_dev *dev)
565{
566 pr_debug("c4iw_dev %p\n", dev);
567 ib_unregister_device(&dev->ibdev);
568 return;
569}
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
57static int fastreg_support = 1;
58module_param(fastreg_support, int, 0644);
59MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)");
60
61static void c4iw_dealloc_ucontext(struct ib_ucontext *context)
62{
63 struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context);
64 struct c4iw_dev *rhp;
65 struct c4iw_mm_entry *mm, *tmp;
66
67 pr_debug("context %p\n", context);
68 rhp = to_c4iw_dev(ucontext->ibucontext.device);
69
70 list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
71 kfree(mm);
72 c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx);
73}
74
75static int c4iw_alloc_ucontext(struct ib_ucontext *ucontext,
76 struct ib_udata *udata)
77{
78 struct ib_device *ibdev = ucontext->device;
79 struct c4iw_ucontext *context = to_c4iw_ucontext(ucontext);
80 struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
81 struct c4iw_alloc_ucontext_resp uresp;
82 int ret = 0;
83 struct c4iw_mm_entry *mm = NULL;
84
85 pr_debug("ibdev %p\n", ibdev);
86 c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx);
87 INIT_LIST_HEAD(&context->mmaps);
88 spin_lock_init(&context->mmap_lock);
89
90 if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) {
91 pr_err_once("Warning - downlevel libcxgb4 (non-fatal), device status page disabled\n");
92 rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED;
93 } else {
94 mm = kmalloc(sizeof(*mm), GFP_KERNEL);
95 if (!mm) {
96 ret = -ENOMEM;
97 goto err;
98 }
99
100 uresp.status_page_size = PAGE_SIZE;
101
102 spin_lock(&context->mmap_lock);
103 uresp.status_page_key = context->key;
104 context->key += PAGE_SIZE;
105 spin_unlock(&context->mmap_lock);
106
107 ret = ib_copy_to_udata(udata, &uresp,
108 sizeof(uresp) - sizeof(uresp.reserved));
109 if (ret)
110 goto err_mm;
111
112 mm->key = uresp.status_page_key;
113 mm->addr = virt_to_phys(rhp->rdev.status_page);
114 mm->len = PAGE_SIZE;
115 insert_mmap(context, mm);
116 }
117 return 0;
118err_mm:
119 kfree(mm);
120err:
121 return ret;
122}
123
124static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
125{
126 int len = vma->vm_end - vma->vm_start;
127 u32 key = vma->vm_pgoff << PAGE_SHIFT;
128 struct c4iw_rdev *rdev;
129 int ret = 0;
130 struct c4iw_mm_entry *mm;
131 struct c4iw_ucontext *ucontext;
132 u64 addr;
133
134 pr_debug("pgoff 0x%lx key 0x%x len %d\n", vma->vm_pgoff,
135 key, len);
136
137 if (vma->vm_start & (PAGE_SIZE-1))
138 return -EINVAL;
139
140 rdev = &(to_c4iw_dev(context->device)->rdev);
141 ucontext = to_c4iw_ucontext(context);
142
143 mm = remove_mmap(ucontext, key, len);
144 if (!mm)
145 return -EINVAL;
146 addr = mm->addr;
147 kfree(mm);
148
149 if ((addr >= pci_resource_start(rdev->lldi.pdev, 0)) &&
150 (addr < (pci_resource_start(rdev->lldi.pdev, 0) +
151 pci_resource_len(rdev->lldi.pdev, 0)))) {
152
153 /*
154 * MA_SYNC register...
155 */
156 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
157 ret = io_remap_pfn_range(vma, vma->vm_start,
158 addr >> PAGE_SHIFT,
159 len, vma->vm_page_prot);
160 } else if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) &&
161 (addr < (pci_resource_start(rdev->lldi.pdev, 2) +
162 pci_resource_len(rdev->lldi.pdev, 2)))) {
163
164 /*
165 * Map user DB or OCQP memory...
166 */
167 if (addr >= rdev->oc_mw_pa)
168 vma->vm_page_prot = t4_pgprot_wc(vma->vm_page_prot);
169 else {
170 if (!is_t4(rdev->lldi.adapter_type))
171 vma->vm_page_prot =
172 t4_pgprot_wc(vma->vm_page_prot);
173 else
174 vma->vm_page_prot =
175 pgprot_noncached(vma->vm_page_prot);
176 }
177 ret = io_remap_pfn_range(vma, vma->vm_start,
178 addr >> PAGE_SHIFT,
179 len, vma->vm_page_prot);
180 } else {
181
182 /*
183 * Map WQ or CQ contig dma memory...
184 */
185 ret = remap_pfn_range(vma, vma->vm_start,
186 addr >> PAGE_SHIFT,
187 len, vma->vm_page_prot);
188 }
189
190 return ret;
191}
192
193static void c4iw_deallocate_pd(struct ib_pd *pd, struct ib_udata *udata)
194{
195 struct c4iw_dev *rhp;
196 struct c4iw_pd *php;
197
198 php = to_c4iw_pd(pd);
199 rhp = php->rhp;
200 pr_debug("ibpd %p pdid 0x%x\n", pd, php->pdid);
201 c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid);
202 mutex_lock(&rhp->rdev.stats.lock);
203 rhp->rdev.stats.pd.cur--;
204 mutex_unlock(&rhp->rdev.stats.lock);
205}
206
207static int c4iw_allocate_pd(struct ib_pd *pd, struct ib_udata *udata)
208{
209 struct c4iw_pd *php = to_c4iw_pd(pd);
210 struct ib_device *ibdev = pd->device;
211 u32 pdid;
212 struct c4iw_dev *rhp;
213
214 pr_debug("ibdev %p\n", ibdev);
215 rhp = (struct c4iw_dev *) ibdev;
216 pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table);
217 if (!pdid)
218 return -EINVAL;
219
220 php->pdid = pdid;
221 php->rhp = rhp;
222 if (udata) {
223 struct c4iw_alloc_pd_resp uresp = {.pdid = php->pdid};
224
225 if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) {
226 c4iw_deallocate_pd(&php->ibpd, udata);
227 return -EFAULT;
228 }
229 }
230 mutex_lock(&rhp->rdev.stats.lock);
231 rhp->rdev.stats.pd.cur++;
232 if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max)
233 rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur;
234 mutex_unlock(&rhp->rdev.stats.lock);
235 pr_debug("pdid 0x%0x ptr 0x%p\n", pdid, php);
236 return 0;
237}
238
239static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
240 u16 *pkey)
241{
242 pr_debug("ibdev %p\n", ibdev);
243 *pkey = 0;
244 return 0;
245}
246
247static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index,
248 union ib_gid *gid)
249{
250 struct c4iw_dev *dev;
251
252 pr_debug("ibdev %p, port %d, index %d, gid %p\n",
253 ibdev, port, index, gid);
254 if (!port)
255 return -EINVAL;
256 dev = to_c4iw_dev(ibdev);
257 memset(&(gid->raw[0]), 0, sizeof(gid->raw));
258 memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6);
259 return 0;
260}
261
262static int c4iw_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
263 struct ib_udata *uhw)
264{
265
266 struct c4iw_dev *dev;
267
268 pr_debug("ibdev %p\n", ibdev);
269
270 if (uhw->inlen || uhw->outlen)
271 return -EINVAL;
272
273 dev = to_c4iw_dev(ibdev);
274 memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
275 props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type);
276 props->fw_ver = dev->rdev.lldi.fw_vers;
277 props->device_cap_flags = dev->device_cap_flags;
278 props->page_size_cap = T4_PAGESIZE_MASK;
279 props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor;
280 props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device;
281 props->max_mr_size = T4_MAX_MR_SIZE;
282 props->max_qp = dev->rdev.lldi.vr->qp.size / 2;
283 props->max_srq = dev->rdev.lldi.vr->srq.size;
284 props->max_qp_wr = dev->rdev.hw_queue.t4_max_qp_depth;
285 props->max_srq_wr = dev->rdev.hw_queue.t4_max_qp_depth;
286 props->max_send_sge = min(T4_MAX_SEND_SGE, T4_MAX_WRITE_SGE);
287 props->max_recv_sge = T4_MAX_RECV_SGE;
288 props->max_srq_sge = T4_MAX_RECV_SGE;
289 props->max_sge_rd = 1;
290 props->max_res_rd_atom = dev->rdev.lldi.max_ird_adapter;
291 props->max_qp_rd_atom = min(dev->rdev.lldi.max_ordird_qp,
292 c4iw_max_read_depth);
293 props->max_qp_init_rd_atom = props->max_qp_rd_atom;
294 props->max_cq = dev->rdev.lldi.vr->qp.size;
295 props->max_cqe = dev->rdev.hw_queue.t4_max_cq_depth;
296 props->max_mr = c4iw_num_stags(&dev->rdev);
297 props->max_pd = T4_MAX_NUM_PD;
298 props->local_ca_ack_delay = 0;
299 props->max_fast_reg_page_list_len =
300 t4_max_fr_depth(dev->rdev.lldi.ulptx_memwrite_dsgl && use_dsgl);
301
302 return 0;
303}
304
305static int c4iw_query_port(struct ib_device *ibdev, u8 port,
306 struct ib_port_attr *props)
307{
308 pr_debug("ibdev %p\n", ibdev);
309
310 props->port_cap_flags =
311 IB_PORT_CM_SUP |
312 IB_PORT_SNMP_TUNNEL_SUP |
313 IB_PORT_REINIT_SUP |
314 IB_PORT_DEVICE_MGMT_SUP |
315 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
316 props->gid_tbl_len = 1;
317 props->pkey_tbl_len = 1;
318 props->active_width = 2;
319 props->active_speed = IB_SPEED_DDR;
320 props->max_msg_sz = -1;
321
322 return 0;
323}
324
325static ssize_t hw_rev_show(struct device *dev,
326 struct device_attribute *attr, char *buf)
327{
328 struct c4iw_dev *c4iw_dev =
329 rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
330
331 pr_debug("dev 0x%p\n", dev);
332 return sprintf(buf, "%d\n",
333 CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type));
334}
335static DEVICE_ATTR_RO(hw_rev);
336
337static ssize_t hca_type_show(struct device *dev,
338 struct device_attribute *attr, char *buf)
339{
340 struct c4iw_dev *c4iw_dev =
341 rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
342 struct ethtool_drvinfo info;
343 struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0];
344
345 pr_debug("dev 0x%p\n", dev);
346 lldev->ethtool_ops->get_drvinfo(lldev, &info);
347 return sprintf(buf, "%s\n", info.driver);
348}
349static DEVICE_ATTR_RO(hca_type);
350
351static ssize_t board_id_show(struct device *dev, struct device_attribute *attr,
352 char *buf)
353{
354 struct c4iw_dev *c4iw_dev =
355 rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
356
357 pr_debug("dev 0x%p\n", dev);
358 return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor,
359 c4iw_dev->rdev.lldi.pdev->device);
360}
361static DEVICE_ATTR_RO(board_id);
362
363enum counters {
364 IP4INSEGS,
365 IP4OUTSEGS,
366 IP4RETRANSSEGS,
367 IP4OUTRSTS,
368 IP6INSEGS,
369 IP6OUTSEGS,
370 IP6RETRANSSEGS,
371 IP6OUTRSTS,
372 NR_COUNTERS
373};
374
375static const char * const names[] = {
376 [IP4INSEGS] = "ip4InSegs",
377 [IP4OUTSEGS] = "ip4OutSegs",
378 [IP4RETRANSSEGS] = "ip4RetransSegs",
379 [IP4OUTRSTS] = "ip4OutRsts",
380 [IP6INSEGS] = "ip6InSegs",
381 [IP6OUTSEGS] = "ip6OutSegs",
382 [IP6RETRANSSEGS] = "ip6RetransSegs",
383 [IP6OUTRSTS] = "ip6OutRsts"
384};
385
386static struct rdma_hw_stats *c4iw_alloc_stats(struct ib_device *ibdev,
387 u8 port_num)
388{
389 BUILD_BUG_ON(ARRAY_SIZE(names) != NR_COUNTERS);
390
391 if (port_num != 0)
392 return NULL;
393
394 return rdma_alloc_hw_stats_struct(names, NR_COUNTERS,
395 RDMA_HW_STATS_DEFAULT_LIFESPAN);
396}
397
398static int c4iw_get_mib(struct ib_device *ibdev,
399 struct rdma_hw_stats *stats,
400 u8 port, int index)
401{
402 struct tp_tcp_stats v4, v6;
403 struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev);
404
405 cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6);
406 stats->value[IP4INSEGS] = v4.tcp_in_segs;
407 stats->value[IP4OUTSEGS] = v4.tcp_out_segs;
408 stats->value[IP4RETRANSSEGS] = v4.tcp_retrans_segs;
409 stats->value[IP4OUTRSTS] = v4.tcp_out_rsts;
410 stats->value[IP6INSEGS] = v6.tcp_in_segs;
411 stats->value[IP6OUTSEGS] = v6.tcp_out_segs;
412 stats->value[IP6RETRANSSEGS] = v6.tcp_retrans_segs;
413 stats->value[IP6OUTRSTS] = v6.tcp_out_rsts;
414
415 return stats->num_counters;
416}
417
418static struct attribute *c4iw_class_attributes[] = {
419 &dev_attr_hw_rev.attr,
420 &dev_attr_hca_type.attr,
421 &dev_attr_board_id.attr,
422 NULL
423};
424
425static const struct attribute_group c4iw_attr_group = {
426 .attrs = c4iw_class_attributes,
427};
428
429static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num,
430 struct ib_port_immutable *immutable)
431{
432 struct ib_port_attr attr;
433 int err;
434
435 immutable->core_cap_flags = RDMA_CORE_PORT_IWARP;
436
437 err = ib_query_port(ibdev, port_num, &attr);
438 if (err)
439 return err;
440
441 immutable->pkey_tbl_len = attr.pkey_tbl_len;
442 immutable->gid_tbl_len = attr.gid_tbl_len;
443
444 return 0;
445}
446
447static void get_dev_fw_str(struct ib_device *dev, char *str)
448{
449 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
450 ibdev);
451 pr_debug("dev 0x%p\n", dev);
452
453 snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u.%u",
454 FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers),
455 FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers),
456 FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers),
457 FW_HDR_FW_VER_BUILD_G(c4iw_dev->rdev.lldi.fw_vers));
458}
459
460static int fill_res_entry(struct sk_buff *msg, struct rdma_restrack_entry *res)
461{
462 return (res->type < ARRAY_SIZE(c4iw_restrack_funcs) &&
463 c4iw_restrack_funcs[res->type]) ?
464 c4iw_restrack_funcs[res->type](msg, res) : 0;
465}
466
467static const struct ib_device_ops c4iw_dev_ops = {
468 .owner = THIS_MODULE,
469 .driver_id = RDMA_DRIVER_CXGB4,
470 .uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION,
471
472 .alloc_hw_stats = c4iw_alloc_stats,
473 .alloc_mr = c4iw_alloc_mr,
474 .alloc_mw = c4iw_alloc_mw,
475 .alloc_pd = c4iw_allocate_pd,
476 .alloc_ucontext = c4iw_alloc_ucontext,
477 .create_cq = c4iw_create_cq,
478 .create_qp = c4iw_create_qp,
479 .create_srq = c4iw_create_srq,
480 .dealloc_mw = c4iw_dealloc_mw,
481 .dealloc_pd = c4iw_deallocate_pd,
482 .dealloc_ucontext = c4iw_dealloc_ucontext,
483 .dereg_mr = c4iw_dereg_mr,
484 .destroy_cq = c4iw_destroy_cq,
485 .destroy_qp = c4iw_destroy_qp,
486 .destroy_srq = c4iw_destroy_srq,
487 .fill_res_entry = fill_res_entry,
488 .get_dev_fw_str = get_dev_fw_str,
489 .get_dma_mr = c4iw_get_dma_mr,
490 .get_hw_stats = c4iw_get_mib,
491 .get_port_immutable = c4iw_port_immutable,
492 .iw_accept = c4iw_accept_cr,
493 .iw_add_ref = c4iw_qp_add_ref,
494 .iw_connect = c4iw_connect,
495 .iw_create_listen = c4iw_create_listen,
496 .iw_destroy_listen = c4iw_destroy_listen,
497 .iw_get_qp = c4iw_get_qp,
498 .iw_reject = c4iw_reject_cr,
499 .iw_rem_ref = c4iw_qp_rem_ref,
500 .map_mr_sg = c4iw_map_mr_sg,
501 .mmap = c4iw_mmap,
502 .modify_qp = c4iw_ib_modify_qp,
503 .modify_srq = c4iw_modify_srq,
504 .poll_cq = c4iw_poll_cq,
505 .post_recv = c4iw_post_receive,
506 .post_send = c4iw_post_send,
507 .post_srq_recv = c4iw_post_srq_recv,
508 .query_device = c4iw_query_device,
509 .query_gid = c4iw_query_gid,
510 .query_pkey = c4iw_query_pkey,
511 .query_port = c4iw_query_port,
512 .query_qp = c4iw_ib_query_qp,
513 .reg_user_mr = c4iw_reg_user_mr,
514 .req_notify_cq = c4iw_arm_cq,
515 INIT_RDMA_OBJ_SIZE(ib_pd, c4iw_pd, ibpd),
516 INIT_RDMA_OBJ_SIZE(ib_cq, c4iw_cq, ibcq),
517 INIT_RDMA_OBJ_SIZE(ib_srq, c4iw_srq, ibsrq),
518 INIT_RDMA_OBJ_SIZE(ib_ucontext, c4iw_ucontext, ibucontext),
519};
520
521static int set_netdevs(struct ib_device *ib_dev, struct c4iw_rdev *rdev)
522{
523 int ret;
524 int i;
525
526 for (i = 0; i < rdev->lldi.nports; i++) {
527 ret = ib_device_set_netdev(ib_dev, rdev->lldi.ports[i],
528 i + 1);
529 if (ret)
530 return ret;
531 }
532 return 0;
533}
534
535void c4iw_register_device(struct work_struct *work)
536{
537 int ret;
538 struct uld_ctx *ctx = container_of(work, struct uld_ctx, reg_work);
539 struct c4iw_dev *dev = ctx->dev;
540
541 pr_debug("c4iw_dev %p\n", dev);
542 memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
543 memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
544 dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW;
545 if (fastreg_support)
546 dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
547 dev->ibdev.local_dma_lkey = 0;
548 dev->ibdev.uverbs_cmd_mask =
549 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
550 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
551 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
552 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
553 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
554 (1ull << IB_USER_VERBS_CMD_REG_MR) |
555 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
556 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
557 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
558 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
559 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
560 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
561 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
562 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
563 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
564 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
565 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
566 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
567 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
568 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
569 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
570 dev->ibdev.node_type = RDMA_NODE_RNIC;
571 BUILD_BUG_ON(sizeof(C4IW_NODE_DESC) > IB_DEVICE_NODE_DESC_MAX);
572 memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC));
573 dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports;
574 dev->ibdev.num_comp_vectors = dev->rdev.lldi.nciq;
575 dev->ibdev.dev.parent = &dev->rdev.lldi.pdev->dev;
576
577 memcpy(dev->ibdev.iw_ifname, dev->rdev.lldi.ports[0]->name,
578 sizeof(dev->ibdev.iw_ifname));
579
580 rdma_set_device_sysfs_group(&dev->ibdev, &c4iw_attr_group);
581 ib_set_device_ops(&dev->ibdev, &c4iw_dev_ops);
582 ret = set_netdevs(&dev->ibdev, &dev->rdev);
583 if (ret)
584 goto err_dealloc_ctx;
585 ret = ib_register_device(&dev->ibdev, "cxgb4_%d");
586 if (ret)
587 goto err_dealloc_ctx;
588 return;
589
590err_dealloc_ctx:
591 pr_err("%s - Failed registering iwarp device: %d\n",
592 pci_name(ctx->lldi.pdev), ret);
593 c4iw_dealloc(ctx);
594 return;
595}
596
597void c4iw_unregister_device(struct c4iw_dev *dev)
598{
599 pr_debug("c4iw_dev %p\n", dev);
600 ib_unregister_device(&dev->ibdev);
601 return;
602}