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