provider.c 18.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
/*
 * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/device.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/ethtool.h>
#include <linux/rtnetlink.h>
#include <linux/inetdevice.h>
#include <linux/io.h>

#include <asm/irq.h>
#include <asm/byteorder.h>

#include <rdma/iw_cm.h>
#include <rdma/ib_verbs.h>
#include <rdma/ib_smi.h>
#include <rdma/ib_umem.h>
#include <rdma/ib_user_verbs.h>

#include "iw_cxgb4.h"

S
Steve Wise 已提交
57
static int fastreg_support = 1;
58
module_param(fastreg_support, int, 0644);
S
Steve Wise 已提交
59
MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)");
60 61

static struct ib_ah *c4iw_ah_create(struct ib_pd *pd,
62
				    struct rdma_ah_attr *ah_attr,
63 64
				    struct ib_udata *udata)

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
{
	return ERR_PTR(-ENOSYS);
}

static int c4iw_ah_destroy(struct ib_ah *ah)
{
	return -ENOSYS;
}

static int c4iw_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
{
	return -ENOSYS;
}

static int c4iw_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
{
	return -ENOSYS;
}

static int c4iw_process_mad(struct ib_device *ibdev, int mad_flags,
85 86
			    u8 port_num, const struct ib_wc *in_wc,
			    const struct ib_grh *in_grh,
87 88 89 90 91
			    const struct ib_mad_hdr *in_mad,
			    size_t in_mad_size,
			    struct ib_mad_hdr *out_mad,
			    size_t *out_mad_size,
			    u16 *out_mad_pkey_index)
92 93 94 95
{
	return -ENOSYS;
}

96
void _c4iw_free_ucontext(struct kref *kref)
97
{
98 99
	struct c4iw_ucontext *ucontext;
	struct c4iw_dev *rhp;
100 101
	struct c4iw_mm_entry *mm, *tmp;

102 103 104
	ucontext = container_of(kref, struct c4iw_ucontext, kref);
	rhp = to_c4iw_dev(ucontext->ibucontext.device);

105
	pr_debug("ucontext %p\n", ucontext);
106 107 108 109
	list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
		kfree(mm);
	c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx);
	kfree(ucontext);
110 111 112 113 114 115
}

static int c4iw_dealloc_ucontext(struct ib_ucontext *context)
{
	struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context);

116
	pr_debug("context %p\n", context);
117
	c4iw_put_ucontext(ucontext);
118 119 120 121 122 123 124 125
	return 0;
}

static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev,
					       struct ib_udata *udata)
{
	struct c4iw_ucontext *context;
	struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
126 127 128
	struct c4iw_alloc_ucontext_resp uresp;
	int ret = 0;
	struct c4iw_mm_entry *mm = NULL;
129

130
	pr_debug("ibdev %p\n", ibdev);
131
	context = kzalloc(sizeof(*context), GFP_KERNEL);
132 133 134 135 136
	if (!context) {
		ret = -ENOMEM;
		goto err;
	}

137 138 139
	c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx);
	INIT_LIST_HEAD(&context->mmaps);
	spin_lock_init(&context->mmap_lock);
140
	kref_init(&context->kref);
141

142
	if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) {
143
		pr_err_once("Warning - downlevel libcxgb4 (non-fatal), device status page disabled\n");
144 145 146
		rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED;
	} else {
		mm = kmalloc(sizeof(*mm), GFP_KERNEL);
147 148
		if (!mm) {
			ret = -ENOMEM;
149
			goto err_free;
150
		}
151 152 153 154 155 156 157 158

		uresp.status_page_size = PAGE_SIZE;

		spin_lock(&context->mmap_lock);
		uresp.status_page_key = context->key;
		context->key += PAGE_SIZE;
		spin_unlock(&context->mmap_lock);

159 160
		ret = ib_copy_to_udata(udata, &uresp,
				       sizeof(uresp) - sizeof(uresp.reserved));
161 162 163 164 165 166 167 168
		if (ret)
			goto err_mm;

		mm->key = uresp.status_page_key;
		mm->addr = virt_to_phys(rhp->rdev.status_page);
		mm->len = PAGE_SIZE;
		insert_mmap(context, mm);
	}
169
	return &context->ibucontext;
170 171 172 173 174 175
err_mm:
	kfree(mm);
err_free:
	kfree(context);
err:
	return ERR_PTR(ret);
176 177 178 179 180 181 182 183 184 185 186 187
}

static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
{
	int len = vma->vm_end - vma->vm_start;
	u32 key = vma->vm_pgoff << PAGE_SHIFT;
	struct c4iw_rdev *rdev;
	int ret = 0;
	struct c4iw_mm_entry *mm;
	struct c4iw_ucontext *ucontext;
	u64 addr;

188
	pr_debug("pgoff 0x%lx key 0x%x len %d\n", vma->vm_pgoff,
J
Joe Perches 已提交
189
		 key, len);
190 191 192 193 194 195 196 197 198 199 200 201 202

	if (vma->vm_start & (PAGE_SIZE-1))
		return -EINVAL;

	rdev = &(to_c4iw_dev(context->device)->rdev);
	ucontext = to_c4iw_ucontext(context);

	mm = remove_mmap(ucontext, key, len);
	if (!mm)
		return -EINVAL;
	addr = mm->addr;
	kfree(mm);

S
Steve Wise 已提交
203 204 205
	if ((addr >= pci_resource_start(rdev->lldi.pdev, 0)) &&
	    (addr < (pci_resource_start(rdev->lldi.pdev, 0) +
		    pci_resource_len(rdev->lldi.pdev, 0)))) {
206 207

		/*
S
Steve Wise 已提交
208
		 * MA_SYNC register...
209 210
		 */
		vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
S
Steve Wise 已提交
211 212 213 214 215 216 217 218 219 220 221 222
		ret = io_remap_pfn_range(vma, vma->vm_start,
					 addr >> PAGE_SHIFT,
					 len, vma->vm_page_prot);
	} else if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) &&
		   (addr < (pci_resource_start(rdev->lldi.pdev, 2) +
		    pci_resource_len(rdev->lldi.pdev, 2)))) {

		/*
		 * Map user DB or OCQP memory...
		 */
		if (addr >= rdev->oc_mw_pa)
			vma->vm_page_prot = t4_pgprot_wc(vma->vm_page_prot);
223
		else {
224
			if (!is_t4(rdev->lldi.adapter_type))
225 226 227 228 229 230
				vma->vm_page_prot =
					t4_pgprot_wc(vma->vm_page_prot);
			else
				vma->vm_page_prot =
					pgprot_noncached(vma->vm_page_prot);
		}
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
		ret = io_remap_pfn_range(vma, vma->vm_start,
					 addr >> PAGE_SHIFT,
					 len, vma->vm_page_prot);
	} else {

		/*
		 * Map WQ or CQ contig dma memory...
		 */
		ret = remap_pfn_range(vma, vma->vm_start,
				      addr >> PAGE_SHIFT,
				      len, vma->vm_page_prot);
	}

	return ret;
}

static int c4iw_deallocate_pd(struct ib_pd *pd)
{
	struct c4iw_dev *rhp;
	struct c4iw_pd *php;

	php = to_c4iw_pd(pd);
	rhp = php->rhp;
254
	pr_debug("ibpd %p pdid 0x%x\n", pd, php->pdid);
V
Vipul Pandya 已提交
255
	c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid);
256 257 258
	mutex_lock(&rhp->rdev.stats.lock);
	rhp->rdev.stats.pd.cur--;
	mutex_unlock(&rhp->rdev.stats.lock);
259 260 261 262 263 264 265 266 267 268 269 270
	kfree(php);
	return 0;
}

static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev,
				      struct ib_ucontext *context,
				      struct ib_udata *udata)
{
	struct c4iw_pd *php;
	u32 pdid;
	struct c4iw_dev *rhp;

271
	pr_debug("ibdev %p\n", ibdev);
272
	rhp = (struct c4iw_dev *) ibdev;
V
Vipul Pandya 已提交
273
	pdid =  c4iw_get_resource(&rhp->rdev.resource.pdid_table);
274 275 276 277
	if (!pdid)
		return ERR_PTR(-EINVAL);
	php = kzalloc(sizeof(*php), GFP_KERNEL);
	if (!php) {
V
Vipul Pandya 已提交
278
		c4iw_put_resource(&rhp->rdev.resource.pdid_table, pdid);
279 280 281 282 283 284 285 286 287 288
		return ERR_PTR(-ENOMEM);
	}
	php->pdid = pdid;
	php->rhp = rhp;
	if (context) {
		if (ib_copy_to_udata(udata, &php->pdid, sizeof(u32))) {
			c4iw_deallocate_pd(&php->ibpd);
			return ERR_PTR(-EFAULT);
		}
	}
289 290 291 292 293
	mutex_lock(&rhp->rdev.stats.lock);
	rhp->rdev.stats.pd.cur++;
	if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max)
		rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur;
	mutex_unlock(&rhp->rdev.stats.lock);
294
	pr_debug("pdid 0x%0x ptr 0x%p\n", pdid, php);
295 296 297 298 299 300
	return &php->ibpd;
}

static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
			   u16 *pkey)
{
301
	pr_debug("ibdev %p\n", ibdev);
302 303 304 305 306 307 308 309 310
	*pkey = 0;
	return 0;
}

static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index,
			  union ib_gid *gid)
{
	struct c4iw_dev *dev;

311 312
	pr_debug("ibdev %p, port %d, index %d, gid %p\n",
		 ibdev, port, index, gid);
S
Steve Wise 已提交
313 314
	if (!port)
		return -EINVAL;
315 316 317 318 319 320
	dev = to_c4iw_dev(ibdev);
	memset(&(gid->raw[0]), 0, sizeof(gid->raw));
	memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6);
	return 0;
}

321 322
static int c4iw_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
			     struct ib_udata *uhw)
323 324 325
{

	struct c4iw_dev *dev;
326

327
	pr_debug("ibdev %p\n", ibdev);
328

329 330 331
	if (uhw->inlen || uhw->outlen)
		return -EINVAL;

332 333 334
	dev = to_c4iw_dev(ibdev);
	memset(props, 0, sizeof *props);
	memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
335
	props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type);
336 337 338 339 340 341
	props->fw_ver = dev->rdev.lldi.fw_vers;
	props->device_cap_flags = dev->device_cap_flags;
	props->page_size_cap = T4_PAGESIZE_MASK;
	props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor;
	props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device;
	props->max_mr_size = T4_MAX_MR_SIZE;
342
	props->max_qp = dev->rdev.lldi.vr->qp.size / 2;
343
	props->max_qp_wr = dev->rdev.hw_queue.t4_max_qp_depth;
344 345
	props->max_sge = T4_MAX_RECV_SGE;
	props->max_sge_rd = 1;
346 347 348 349
	props->max_res_rd_atom = dev->rdev.lldi.max_ird_adapter;
	props->max_qp_rd_atom = min(dev->rdev.lldi.max_ordird_qp,
				    c4iw_max_read_depth);
	props->max_qp_init_rd_atom = props->max_qp_rd_atom;
350
	props->max_cq = dev->rdev.lldi.vr->qp.size;
351
	props->max_cqe = dev->rdev.hw_queue.t4_max_cq_depth;
352 353 354
	props->max_mr = c4iw_num_stags(&dev->rdev);
	props->max_pd = T4_MAX_NUM_PD;
	props->local_ca_ack_delay = 0;
355 356
	props->max_fast_reg_page_list_len =
		t4_max_fr_depth(dev->rdev.lldi.ulptx_memwrite_dsgl && use_dsgl);
357 358 359 360 361 362 363 364 365 366 367

	return 0;
}

static int c4iw_query_port(struct ib_device *ibdev, u8 port,
			   struct ib_port_attr *props)
{
	struct c4iw_dev *dev;
	struct net_device *netdev;
	struct in_device *inetdev;

368
	pr_debug("ibdev %p\n", ibdev);
369 370 371

	dev = to_c4iw_dev(ibdev);
	netdev = dev->rdev.lldi.ports[port-1];
372
	/* props being zeroed by the caller, avoid zeroing it here */
373
	props->max_mtu = IB_MTU_4096;
374
	props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398

	if (!netif_carrier_ok(netdev))
		props->state = IB_PORT_DOWN;
	else {
		inetdev = in_dev_get(netdev);
		if (inetdev) {
			if (inetdev->ifa_list)
				props->state = IB_PORT_ACTIVE;
			else
				props->state = IB_PORT_INIT;
			in_dev_put(inetdev);
		} else
			props->state = IB_PORT_INIT;
	}

	props->port_cap_flags =
	    IB_PORT_CM_SUP |
	    IB_PORT_SNMP_TUNNEL_SUP |
	    IB_PORT_REINIT_SUP |
	    IB_PORT_DEVICE_MGMT_SUP |
	    IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
	props->gid_tbl_len = 1;
	props->pkey_tbl_len = 1;
	props->active_width = 2;
399
	props->active_speed = IB_SPEED_DDR;
400 401 402 403 404 405 406 407 408 409
	props->max_msg_sz = -1;

	return 0;
}

static ssize_t show_rev(struct device *dev, struct device_attribute *attr,
			char *buf)
{
	struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
						 ibdev.dev);
410
	pr_debug("dev 0x%p\n", dev);
411 412
	return sprintf(buf, "%d\n",
		       CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type));
413 414 415 416 417 418 419 420 421 422
}

static ssize_t show_hca(struct device *dev, struct device_attribute *attr,
			char *buf)
{
	struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
						 ibdev.dev);
	struct ethtool_drvinfo info;
	struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0];

423
	pr_debug("dev 0x%p\n", dev);
424 425 426 427 428 429 430 431 432
	lldev->ethtool_ops->get_drvinfo(lldev, &info);
	return sprintf(buf, "%s\n", info.driver);
}

static ssize_t show_board(struct device *dev, struct device_attribute *attr,
			  char *buf)
{
	struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
						 ibdev.dev);
433
	pr_debug("dev 0x%p\n", dev);
434 435 436 437
	return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor,
		       c4iw_dev->rdev.lldi.pdev->device);
}

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
enum counters {
	IP4INSEGS,
	IP4OUTSEGS,
	IP4RETRANSSEGS,
	IP4OUTRSTS,
	IP6INSEGS,
	IP6OUTSEGS,
	IP6RETRANSSEGS,
	IP6OUTRSTS,
	NR_COUNTERS
};

static const char * const names[] = {
	[IP4INSEGS] = "ip4InSegs",
	[IP4OUTSEGS] = "ip4OutSegs",
	[IP4RETRANSSEGS] = "ip4RetransSegs",
	[IP4OUTRSTS] = "ip4OutRsts",
	[IP6INSEGS] = "ip6InSegs",
	[IP6OUTSEGS] = "ip6OutSegs",
	[IP6RETRANSSEGS] = "ip6RetransSegs",
	[IP6OUTRSTS] = "ip6OutRsts"
};

static struct rdma_hw_stats *c4iw_alloc_stats(struct ib_device *ibdev,
					      u8 port_num)
{
	BUILD_BUG_ON(ARRAY_SIZE(names) != NR_COUNTERS);

	if (port_num != 0)
		return NULL;

	return rdma_alloc_hw_stats_struct(names, NR_COUNTERS,
					  RDMA_HW_STATS_DEFAULT_LIFESPAN);
}

473
static int c4iw_get_mib(struct ib_device *ibdev,
474 475
			struct rdma_hw_stats *stats,
			u8 port, int index)
476
{
S
Steve Wise 已提交
477 478 479 480
	struct tp_tcp_stats v4, v6;
	struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev);

	cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6);
481 482 483 484 485 486 487 488 489 490
	stats->value[IP4INSEGS] = v4.tcp_in_segs;
	stats->value[IP4OUTSEGS] = v4.tcp_out_segs;
	stats->value[IP4RETRANSSEGS] = v4.tcp_retrans_segs;
	stats->value[IP4OUTRSTS] = v4.tcp_out_rsts;
	stats->value[IP6INSEGS] = v6.tcp_in_segs;
	stats->value[IP6OUTSEGS] = v6.tcp_out_segs;
	stats->value[IP6RETRANSSEGS] = v6.tcp_retrans_segs;
	stats->value[IP6OUTRSTS] = v6.tcp_out_rsts;

	return stats->num_counters;
491 492 493 494 495 496 497 498 499 500 501 502
}

static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);

static struct device_attribute *c4iw_class_attributes[] = {
	&dev_attr_hw_rev,
	&dev_attr_hca_type,
	&dev_attr_board_id,
};

503 504 505 506 507 508
static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num,
			       struct ib_port_immutable *immutable)
{
	struct ib_port_attr attr;
	int err;

509 510 511
	immutable->core_cap_flags = RDMA_CORE_PORT_IWARP;

	err = ib_query_port(ibdev, port_num, &attr);
512 513 514 515 516 517 518 519 520
	if (err)
		return err;

	immutable->pkey_tbl_len = attr.pkey_tbl_len;
	immutable->gid_tbl_len = attr.gid_tbl_len;

	return 0;
}

521
static void get_dev_fw_str(struct ib_device *dev, char *str)
522 523 524
{
	struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
						 ibdev);
525
	pr_debug("dev 0x%p\n", dev);
526

527
	snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u.%u",
528 529 530 531 532 533
		 FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers),
		 FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers),
		 FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers),
		 FW_HDR_FW_VER_BUILD_G(c4iw_dev->rdev.lldi.fw_vers));
}

534
void c4iw_register_device(struct work_struct *work)
535 536 537
{
	int ret;
	int i;
538 539
	struct uld_ctx *ctx = container_of(work, struct uld_ctx, reg_work);
	struct c4iw_dev *dev = ctx->dev;
540

541
	pr_debug("c4iw_dev %p\n", dev);
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
	strlcpy(dev->ibdev.name, "cxgb4_%d", IB_DEVICE_NAME_MAX);
	memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
	memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
	dev->ibdev.owner = THIS_MODULE;
	dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW;
	if (fastreg_support)
		dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
	dev->ibdev.local_dma_lkey = 0;
	dev->ibdev.uverbs_cmd_mask =
	    (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
	    (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
	    (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
	    (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
	    (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
	    (1ull << IB_USER_VERBS_CMD_REG_MR) |
	    (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
	    (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
	    (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
	    (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
	    (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
	    (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
	    (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
V
Vipul Pandya 已提交
564
	    (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
565 566 567 568 569
	    (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
	    (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
	    (1ull << IB_USER_VERBS_CMD_POST_SEND) |
	    (1ull << IB_USER_VERBS_CMD_POST_RECV);
	dev->ibdev.node_type = RDMA_NODE_RNIC;
570
	BUILD_BUG_ON(sizeof(C4IW_NODE_DESC) > IB_DEVICE_NODE_DESC_MAX);
571 572
	memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC));
	dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports;
573
	dev->ibdev.num_comp_vectors =  dev->rdev.lldi.nciq;
574
	dev->ibdev.dev.parent = &dev->rdev.lldi.pdev->dev;
575 576 577 578 579 580 581 582 583 584 585 586 587
	dev->ibdev.query_device = c4iw_query_device;
	dev->ibdev.query_port = c4iw_query_port;
	dev->ibdev.query_pkey = c4iw_query_pkey;
	dev->ibdev.query_gid = c4iw_query_gid;
	dev->ibdev.alloc_ucontext = c4iw_alloc_ucontext;
	dev->ibdev.dealloc_ucontext = c4iw_dealloc_ucontext;
	dev->ibdev.mmap = c4iw_mmap;
	dev->ibdev.alloc_pd = c4iw_allocate_pd;
	dev->ibdev.dealloc_pd = c4iw_deallocate_pd;
	dev->ibdev.create_ah = c4iw_ah_create;
	dev->ibdev.destroy_ah = c4iw_ah_destroy;
	dev->ibdev.create_qp = c4iw_create_qp;
	dev->ibdev.modify_qp = c4iw_ib_modify_qp;
V
Vipul Pandya 已提交
588
	dev->ibdev.query_qp = c4iw_ib_query_qp;
589 590 591 592 593 594 595 596 597 598
	dev->ibdev.destroy_qp = c4iw_destroy_qp;
	dev->ibdev.create_cq = c4iw_create_cq;
	dev->ibdev.destroy_cq = c4iw_destroy_cq;
	dev->ibdev.resize_cq = c4iw_resize_cq;
	dev->ibdev.poll_cq = c4iw_poll_cq;
	dev->ibdev.get_dma_mr = c4iw_get_dma_mr;
	dev->ibdev.reg_user_mr = c4iw_reg_user_mr;
	dev->ibdev.dereg_mr = c4iw_dereg_mr;
	dev->ibdev.alloc_mw = c4iw_alloc_mw;
	dev->ibdev.dealloc_mw = c4iw_dealloc_mw;
599
	dev->ibdev.alloc_mr = c4iw_alloc_mr;
600
	dev->ibdev.map_mr_sg = c4iw_map_mr_sg;
601 602 603 604 605 606
	dev->ibdev.attach_mcast = c4iw_multicast_attach;
	dev->ibdev.detach_mcast = c4iw_multicast_detach;
	dev->ibdev.process_mad = c4iw_process_mad;
	dev->ibdev.req_notify_cq = c4iw_arm_cq;
	dev->ibdev.post_send = c4iw_post_send;
	dev->ibdev.post_recv = c4iw_post_receive;
607 608
	dev->ibdev.alloc_hw_stats = c4iw_alloc_stats;
	dev->ibdev.get_hw_stats = c4iw_get_mib;
S
Steve Wise 已提交
609
	dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION;
610
	dev->ibdev.get_port_immutable = c4iw_port_immutable;
611
	dev->ibdev.get_dev_fw_str = get_dev_fw_str;
612 613

	dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
614 615 616 617
	if (!dev->ibdev.iwcm) {
		ret = -ENOMEM;
		goto err_dealloc_ctx;
	}
618 619 620 621 622 623 624 625 626

	dev->ibdev.iwcm->connect = c4iw_connect;
	dev->ibdev.iwcm->accept = c4iw_accept_cr;
	dev->ibdev.iwcm->reject = c4iw_reject_cr;
	dev->ibdev.iwcm->create_listen = c4iw_create_listen;
	dev->ibdev.iwcm->destroy_listen = c4iw_destroy_listen;
	dev->ibdev.iwcm->add_ref = c4iw_qp_add_ref;
	dev->ibdev.iwcm->rem_ref = c4iw_qp_rem_ref;
	dev->ibdev.iwcm->get_qp = c4iw_get_qp;
627 628
	memcpy(dev->ibdev.iwcm->ifname, dev->rdev.lldi.ports[0]->name,
	       sizeof(dev->ibdev.iwcm->ifname));
629

630
	ret = ib_register_device(&dev->ibdev, NULL);
631
	if (ret)
632
		goto err_kfree_iwcm;
633 634 635 636 637

	for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) {
		ret = device_create_file(&dev->ibdev.dev,
					 c4iw_class_attributes[i]);
		if (ret)
638
			goto err_unregister_device;
639
	}
640 641
	return;
err_unregister_device:
642
	ib_unregister_device(&dev->ibdev);
643
err_kfree_iwcm:
644
	kfree(dev->ibdev.iwcm);
645 646 647 648 649
err_dealloc_ctx:
	pr_err("%s - Failed registering iwarp device: %d\n",
	       pci_name(ctx->lldi.pdev), ret);
	c4iw_dealloc(ctx);
	return;
650 651 652 653 654 655
}

void c4iw_unregister_device(struct c4iw_dev *dev)
{
	int i;

656
	pr_debug("c4iw_dev %p\n", dev);
657 658 659 660 661 662 663
	for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i)
		device_remove_file(&dev->ibdev.dev,
				   c4iw_class_attributes[i]);
	ib_unregister_device(&dev->ibdev);
	kfree(dev->ibdev.iwcm);
	return;
}