| .. | .. |
|---|
| 58 | 58 | module_param(fastreg_support, int, 0644); |
|---|
| 59 | 59 | MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)"); |
|---|
| 60 | 60 | |
|---|
| 61 | | -void _c4iw_free_ucontext(struct kref *kref) |
|---|
| 61 | +static void c4iw_dealloc_ucontext(struct ib_ucontext *context) |
|---|
| 62 | 62 | { |
|---|
| 63 | | - struct c4iw_ucontext *ucontext; |
|---|
| 63 | + struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context); |
|---|
| 64 | 64 | struct c4iw_dev *rhp; |
|---|
| 65 | 65 | struct c4iw_mm_entry *mm, *tmp; |
|---|
| 66 | 66 | |
|---|
| 67 | | - ucontext = container_of(kref, struct c4iw_ucontext, kref); |
|---|
| 67 | + pr_debug("context %p\n", context); |
|---|
| 68 | 68 | rhp = to_c4iw_dev(ucontext->ibucontext.device); |
|---|
| 69 | 69 | |
|---|
| 70 | | - pr_debug("ucontext %p\n", ucontext); |
|---|
| 71 | 70 | list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry) |
|---|
| 72 | 71 | kfree(mm); |
|---|
| 73 | 72 | c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx); |
|---|
| 74 | | - kfree(ucontext); |
|---|
| 75 | 73 | } |
|---|
| 76 | 74 | |
|---|
| 77 | | -static int c4iw_dealloc_ucontext(struct ib_ucontext *context) |
|---|
| 75 | +static int c4iw_alloc_ucontext(struct ib_ucontext *ucontext, |
|---|
| 76 | + struct ib_udata *udata) |
|---|
| 78 | 77 | { |
|---|
| 79 | | - struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context); |
|---|
| 80 | | - |
|---|
| 81 | | - pr_debug("context %p\n", context); |
|---|
| 82 | | - c4iw_put_ucontext(ucontext); |
|---|
| 83 | | - return 0; |
|---|
| 84 | | -} |
|---|
| 85 | | - |
|---|
| 86 | | -static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev, |
|---|
| 87 | | - struct ib_udata *udata) |
|---|
| 88 | | -{ |
|---|
| 89 | | - struct c4iw_ucontext *context; |
|---|
| 78 | + struct ib_device *ibdev = ucontext->device; |
|---|
| 79 | + struct c4iw_ucontext *context = to_c4iw_ucontext(ucontext); |
|---|
| 90 | 80 | struct c4iw_dev *rhp = to_c4iw_dev(ibdev); |
|---|
| 91 | 81 | struct c4iw_alloc_ucontext_resp uresp; |
|---|
| 92 | 82 | int ret = 0; |
|---|
| 93 | 83 | struct c4iw_mm_entry *mm = NULL; |
|---|
| 94 | 84 | |
|---|
| 95 | 85 | pr_debug("ibdev %p\n", ibdev); |
|---|
| 96 | | - context = kzalloc(sizeof(*context), GFP_KERNEL); |
|---|
| 97 | | - if (!context) { |
|---|
| 98 | | - ret = -ENOMEM; |
|---|
| 99 | | - goto err; |
|---|
| 100 | | - } |
|---|
| 101 | | - |
|---|
| 102 | 86 | c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx); |
|---|
| 103 | 87 | INIT_LIST_HEAD(&context->mmaps); |
|---|
| 104 | 88 | spin_lock_init(&context->mmap_lock); |
|---|
| 105 | | - kref_init(&context->kref); |
|---|
| 106 | 89 | |
|---|
| 107 | 90 | if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) { |
|---|
| 108 | 91 | pr_err_once("Warning - downlevel libcxgb4 (non-fatal), device status page disabled\n"); |
|---|
| .. | .. |
|---|
| 111 | 94 | mm = kmalloc(sizeof(*mm), GFP_KERNEL); |
|---|
| 112 | 95 | if (!mm) { |
|---|
| 113 | 96 | ret = -ENOMEM; |
|---|
| 114 | | - goto err_free; |
|---|
| 97 | + goto err; |
|---|
| 115 | 98 | } |
|---|
| 116 | 99 | |
|---|
| 117 | 100 | uresp.status_page_size = PAGE_SIZE; |
|---|
| .. | .. |
|---|
| 131 | 114 | mm->len = PAGE_SIZE; |
|---|
| 132 | 115 | insert_mmap(context, mm); |
|---|
| 133 | 116 | } |
|---|
| 134 | | - return &context->ibucontext; |
|---|
| 117 | + return 0; |
|---|
| 135 | 118 | err_mm: |
|---|
| 136 | 119 | kfree(mm); |
|---|
| 137 | | -err_free: |
|---|
| 138 | | - kfree(context); |
|---|
| 139 | 120 | err: |
|---|
| 140 | | - return ERR_PTR(ret); |
|---|
| 121 | + return ret; |
|---|
| 141 | 122 | } |
|---|
| 142 | 123 | |
|---|
| 143 | 124 | static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
|---|
| .. | .. |
|---|
| 209 | 190 | return ret; |
|---|
| 210 | 191 | } |
|---|
| 211 | 192 | |
|---|
| 212 | | -static int c4iw_deallocate_pd(struct ib_pd *pd) |
|---|
| 193 | +static int c4iw_deallocate_pd(struct ib_pd *pd, struct ib_udata *udata) |
|---|
| 213 | 194 | { |
|---|
| 214 | 195 | struct c4iw_dev *rhp; |
|---|
| 215 | 196 | struct c4iw_pd *php; |
|---|
| .. | .. |
|---|
| 221 | 202 | mutex_lock(&rhp->rdev.stats.lock); |
|---|
| 222 | 203 | rhp->rdev.stats.pd.cur--; |
|---|
| 223 | 204 | mutex_unlock(&rhp->rdev.stats.lock); |
|---|
| 224 | | - kfree(php); |
|---|
| 225 | 205 | return 0; |
|---|
| 226 | 206 | } |
|---|
| 227 | 207 | |
|---|
| 228 | | -static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev, |
|---|
| 229 | | - struct ib_ucontext *context, |
|---|
| 230 | | - struct ib_udata *udata) |
|---|
| 208 | +static int c4iw_allocate_pd(struct ib_pd *pd, struct ib_udata *udata) |
|---|
| 231 | 209 | { |
|---|
| 232 | | - struct c4iw_pd *php; |
|---|
| 210 | + struct c4iw_pd *php = to_c4iw_pd(pd); |
|---|
| 211 | + struct ib_device *ibdev = pd->device; |
|---|
| 233 | 212 | u32 pdid; |
|---|
| 234 | 213 | struct c4iw_dev *rhp; |
|---|
| 235 | 214 | |
|---|
| .. | .. |
|---|
| 237 | 216 | rhp = (struct c4iw_dev *) ibdev; |
|---|
| 238 | 217 | pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table); |
|---|
| 239 | 218 | if (!pdid) |
|---|
| 240 | | - return ERR_PTR(-EINVAL); |
|---|
| 241 | | - php = kzalloc(sizeof(*php), GFP_KERNEL); |
|---|
| 242 | | - if (!php) { |
|---|
| 243 | | - c4iw_put_resource(&rhp->rdev.resource.pdid_table, pdid); |
|---|
| 244 | | - return ERR_PTR(-ENOMEM); |
|---|
| 245 | | - } |
|---|
| 219 | + return -EINVAL; |
|---|
| 220 | + |
|---|
| 246 | 221 | php->pdid = pdid; |
|---|
| 247 | 222 | php->rhp = rhp; |
|---|
| 248 | | - if (context) { |
|---|
| 223 | + if (udata) { |
|---|
| 249 | 224 | struct c4iw_alloc_pd_resp uresp = {.pdid = php->pdid}; |
|---|
| 250 | 225 | |
|---|
| 251 | 226 | if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) { |
|---|
| 252 | | - c4iw_deallocate_pd(&php->ibpd); |
|---|
| 253 | | - return ERR_PTR(-EFAULT); |
|---|
| 227 | + c4iw_deallocate_pd(&php->ibpd, udata); |
|---|
| 228 | + return -EFAULT; |
|---|
| 254 | 229 | } |
|---|
| 255 | 230 | } |
|---|
| 256 | 231 | mutex_lock(&rhp->rdev.stats.lock); |
|---|
| .. | .. |
|---|
| 259 | 234 | rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur; |
|---|
| 260 | 235 | mutex_unlock(&rhp->rdev.stats.lock); |
|---|
| 261 | 236 | pr_debug("pdid 0x%0x ptr 0x%p\n", pdid, php); |
|---|
| 262 | | - return &php->ibpd; |
|---|
| 263 | | -} |
|---|
| 264 | | - |
|---|
| 265 | | -static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
|---|
| 266 | | - u16 *pkey) |
|---|
| 267 | | -{ |
|---|
| 268 | | - pr_debug("ibdev %p\n", ibdev); |
|---|
| 269 | | - *pkey = 0; |
|---|
| 270 | 237 | return 0; |
|---|
| 271 | 238 | } |
|---|
| 272 | 239 | |
|---|
| .. | .. |
|---|
| 297 | 264 | return -EINVAL; |
|---|
| 298 | 265 | |
|---|
| 299 | 266 | dev = to_c4iw_dev(ibdev); |
|---|
| 300 | | - memset(props, 0, sizeof *props); |
|---|
| 301 | 267 | memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6); |
|---|
| 302 | 268 | props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type); |
|---|
| 303 | 269 | props->fw_ver = dev->rdev.lldi.fw_vers; |
|---|
| .. | .. |
|---|
| 332 | 298 | static int c4iw_query_port(struct ib_device *ibdev, u8 port, |
|---|
| 333 | 299 | struct ib_port_attr *props) |
|---|
| 334 | 300 | { |
|---|
| 335 | | - struct c4iw_dev *dev; |
|---|
| 336 | | - struct net_device *netdev; |
|---|
| 337 | | - struct in_device *inetdev; |
|---|
| 338 | | - |
|---|
| 301 | + int ret = 0; |
|---|
| 339 | 302 | pr_debug("ibdev %p\n", ibdev); |
|---|
| 340 | | - |
|---|
| 341 | | - dev = to_c4iw_dev(ibdev); |
|---|
| 342 | | - netdev = dev->rdev.lldi.ports[port-1]; |
|---|
| 343 | | - /* props being zeroed by the caller, avoid zeroing it here */ |
|---|
| 344 | | - props->max_mtu = IB_MTU_4096; |
|---|
| 345 | | - props->active_mtu = ib_mtu_int_to_enum(netdev->mtu); |
|---|
| 346 | | - |
|---|
| 347 | | - if (!netif_carrier_ok(netdev)) |
|---|
| 348 | | - props->state = IB_PORT_DOWN; |
|---|
| 349 | | - else { |
|---|
| 350 | | - inetdev = in_dev_get(netdev); |
|---|
| 351 | | - if (inetdev) { |
|---|
| 352 | | - if (inetdev->ifa_list) |
|---|
| 353 | | - props->state = IB_PORT_ACTIVE; |
|---|
| 354 | | - else |
|---|
| 355 | | - props->state = IB_PORT_INIT; |
|---|
| 356 | | - in_dev_put(inetdev); |
|---|
| 357 | | - } else |
|---|
| 358 | | - props->state = IB_PORT_INIT; |
|---|
| 359 | | - } |
|---|
| 303 | + ret = ib_get_eth_speed(ibdev, port, &props->active_speed, |
|---|
| 304 | + &props->active_width); |
|---|
| 360 | 305 | |
|---|
| 361 | 306 | props->port_cap_flags = |
|---|
| 362 | 307 | IB_PORT_CM_SUP | |
|---|
| .. | .. |
|---|
| 365 | 310 | IB_PORT_DEVICE_MGMT_SUP | |
|---|
| 366 | 311 | IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP; |
|---|
| 367 | 312 | props->gid_tbl_len = 1; |
|---|
| 368 | | - props->pkey_tbl_len = 1; |
|---|
| 369 | | - props->active_width = 2; |
|---|
| 370 | | - props->active_speed = IB_SPEED_DDR; |
|---|
| 371 | 313 | props->max_msg_sz = -1; |
|---|
| 372 | 314 | |
|---|
| 373 | | - return 0; |
|---|
| 315 | + return ret; |
|---|
| 374 | 316 | } |
|---|
| 375 | 317 | |
|---|
| 376 | | -static ssize_t show_rev(struct device *dev, struct device_attribute *attr, |
|---|
| 377 | | - char *buf) |
|---|
| 318 | +static ssize_t hw_rev_show(struct device *dev, |
|---|
| 319 | + struct device_attribute *attr, char *buf) |
|---|
| 378 | 320 | { |
|---|
| 379 | | - struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
|---|
| 380 | | - ibdev.dev); |
|---|
| 321 | + struct c4iw_dev *c4iw_dev = |
|---|
| 322 | + rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev); |
|---|
| 323 | + |
|---|
| 381 | 324 | pr_debug("dev 0x%p\n", dev); |
|---|
| 382 | 325 | return sprintf(buf, "%d\n", |
|---|
| 383 | 326 | CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type)); |
|---|
| 384 | 327 | } |
|---|
| 328 | +static DEVICE_ATTR_RO(hw_rev); |
|---|
| 385 | 329 | |
|---|
| 386 | | -static ssize_t show_hca(struct device *dev, struct device_attribute *attr, |
|---|
| 387 | | - char *buf) |
|---|
| 330 | +static ssize_t hca_type_show(struct device *dev, |
|---|
| 331 | + struct device_attribute *attr, char *buf) |
|---|
| 388 | 332 | { |
|---|
| 389 | | - struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
|---|
| 390 | | - ibdev.dev); |
|---|
| 333 | + struct c4iw_dev *c4iw_dev = |
|---|
| 334 | + rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev); |
|---|
| 391 | 335 | struct ethtool_drvinfo info; |
|---|
| 392 | 336 | struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0]; |
|---|
| 393 | 337 | |
|---|
| .. | .. |
|---|
| 395 | 339 | lldev->ethtool_ops->get_drvinfo(lldev, &info); |
|---|
| 396 | 340 | return sprintf(buf, "%s\n", info.driver); |
|---|
| 397 | 341 | } |
|---|
| 342 | +static DEVICE_ATTR_RO(hca_type); |
|---|
| 398 | 343 | |
|---|
| 399 | | -static ssize_t show_board(struct device *dev, struct device_attribute *attr, |
|---|
| 400 | | - char *buf) |
|---|
| 344 | +static ssize_t board_id_show(struct device *dev, struct device_attribute *attr, |
|---|
| 345 | + char *buf) |
|---|
| 401 | 346 | { |
|---|
| 402 | | - struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
|---|
| 403 | | - ibdev.dev); |
|---|
| 347 | + struct c4iw_dev *c4iw_dev = |
|---|
| 348 | + rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev); |
|---|
| 349 | + |
|---|
| 404 | 350 | pr_debug("dev 0x%p\n", dev); |
|---|
| 405 | 351 | return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor, |
|---|
| 406 | 352 | c4iw_dev->rdev.lldi.pdev->device); |
|---|
| 407 | 353 | } |
|---|
| 354 | +static DEVICE_ATTR_RO(board_id); |
|---|
| 408 | 355 | |
|---|
| 409 | 356 | enum counters { |
|---|
| 410 | 357 | IP4INSEGS, |
|---|
| .. | .. |
|---|
| 461 | 408 | return stats->num_counters; |
|---|
| 462 | 409 | } |
|---|
| 463 | 410 | |
|---|
| 464 | | -static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
|---|
| 465 | | -static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
|---|
| 466 | | -static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
|---|
| 411 | +static struct attribute *c4iw_class_attributes[] = { |
|---|
| 412 | + &dev_attr_hw_rev.attr, |
|---|
| 413 | + &dev_attr_hca_type.attr, |
|---|
| 414 | + &dev_attr_board_id.attr, |
|---|
| 415 | + NULL |
|---|
| 416 | +}; |
|---|
| 467 | 417 | |
|---|
| 468 | | -static struct device_attribute *c4iw_class_attributes[] = { |
|---|
| 469 | | - &dev_attr_hw_rev, |
|---|
| 470 | | - &dev_attr_hca_type, |
|---|
| 471 | | - &dev_attr_board_id, |
|---|
| 418 | +static const struct attribute_group c4iw_attr_group = { |
|---|
| 419 | + .attrs = c4iw_class_attributes, |
|---|
| 472 | 420 | }; |
|---|
| 473 | 421 | |
|---|
| 474 | 422 | static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num, |
|---|
| .. | .. |
|---|
| 483 | 431 | if (err) |
|---|
| 484 | 432 | return err; |
|---|
| 485 | 433 | |
|---|
| 486 | | - immutable->pkey_tbl_len = attr.pkey_tbl_len; |
|---|
| 487 | 434 | immutable->gid_tbl_len = attr.gid_tbl_len; |
|---|
| 488 | 435 | |
|---|
| 489 | 436 | return 0; |
|---|
| .. | .. |
|---|
| 502 | 449 | FW_HDR_FW_VER_BUILD_G(c4iw_dev->rdev.lldi.fw_vers)); |
|---|
| 503 | 450 | } |
|---|
| 504 | 451 | |
|---|
| 505 | | -static struct net_device *get_netdev(struct ib_device *dev, u8 port) |
|---|
| 452 | +static const struct ib_device_ops c4iw_dev_ops = { |
|---|
| 453 | + .owner = THIS_MODULE, |
|---|
| 454 | + .driver_id = RDMA_DRIVER_CXGB4, |
|---|
| 455 | + .uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION, |
|---|
| 456 | + |
|---|
| 457 | + .alloc_hw_stats = c4iw_alloc_stats, |
|---|
| 458 | + .alloc_mr = c4iw_alloc_mr, |
|---|
| 459 | + .alloc_mw = c4iw_alloc_mw, |
|---|
| 460 | + .alloc_pd = c4iw_allocate_pd, |
|---|
| 461 | + .alloc_ucontext = c4iw_alloc_ucontext, |
|---|
| 462 | + .create_cq = c4iw_create_cq, |
|---|
| 463 | + .create_qp = c4iw_create_qp, |
|---|
| 464 | + .create_srq = c4iw_create_srq, |
|---|
| 465 | + .dealloc_mw = c4iw_dealloc_mw, |
|---|
| 466 | + .dealloc_pd = c4iw_deallocate_pd, |
|---|
| 467 | + .dealloc_ucontext = c4iw_dealloc_ucontext, |
|---|
| 468 | + .dereg_mr = c4iw_dereg_mr, |
|---|
| 469 | + .destroy_cq = c4iw_destroy_cq, |
|---|
| 470 | + .destroy_qp = c4iw_destroy_qp, |
|---|
| 471 | + .destroy_srq = c4iw_destroy_srq, |
|---|
| 472 | + .fill_res_cq_entry = c4iw_fill_res_cq_entry, |
|---|
| 473 | + .fill_res_cm_id_entry = c4iw_fill_res_cm_id_entry, |
|---|
| 474 | + .fill_res_mr_entry = c4iw_fill_res_mr_entry, |
|---|
| 475 | + .get_dev_fw_str = get_dev_fw_str, |
|---|
| 476 | + .get_dma_mr = c4iw_get_dma_mr, |
|---|
| 477 | + .get_hw_stats = c4iw_get_mib, |
|---|
| 478 | + .get_port_immutable = c4iw_port_immutable, |
|---|
| 479 | + .iw_accept = c4iw_accept_cr, |
|---|
| 480 | + .iw_add_ref = c4iw_qp_add_ref, |
|---|
| 481 | + .iw_connect = c4iw_connect, |
|---|
| 482 | + .iw_create_listen = c4iw_create_listen, |
|---|
| 483 | + .iw_destroy_listen = c4iw_destroy_listen, |
|---|
| 484 | + .iw_get_qp = c4iw_get_qp, |
|---|
| 485 | + .iw_reject = c4iw_reject_cr, |
|---|
| 486 | + .iw_rem_ref = c4iw_qp_rem_ref, |
|---|
| 487 | + .map_mr_sg = c4iw_map_mr_sg, |
|---|
| 488 | + .mmap = c4iw_mmap, |
|---|
| 489 | + .modify_qp = c4iw_ib_modify_qp, |
|---|
| 490 | + .modify_srq = c4iw_modify_srq, |
|---|
| 491 | + .poll_cq = c4iw_poll_cq, |
|---|
| 492 | + .post_recv = c4iw_post_receive, |
|---|
| 493 | + .post_send = c4iw_post_send, |
|---|
| 494 | + .post_srq_recv = c4iw_post_srq_recv, |
|---|
| 495 | + .query_device = c4iw_query_device, |
|---|
| 496 | + .query_gid = c4iw_query_gid, |
|---|
| 497 | + .query_port = c4iw_query_port, |
|---|
| 498 | + .query_qp = c4iw_ib_query_qp, |
|---|
| 499 | + .reg_user_mr = c4iw_reg_user_mr, |
|---|
| 500 | + .req_notify_cq = c4iw_arm_cq, |
|---|
| 501 | + |
|---|
| 502 | + INIT_RDMA_OBJ_SIZE(ib_cq, c4iw_cq, ibcq), |
|---|
| 503 | + INIT_RDMA_OBJ_SIZE(ib_mw, c4iw_mw, ibmw), |
|---|
| 504 | + INIT_RDMA_OBJ_SIZE(ib_pd, c4iw_pd, ibpd), |
|---|
| 505 | + INIT_RDMA_OBJ_SIZE(ib_srq, c4iw_srq, ibsrq), |
|---|
| 506 | + INIT_RDMA_OBJ_SIZE(ib_ucontext, c4iw_ucontext, ibucontext), |
|---|
| 507 | +}; |
|---|
| 508 | + |
|---|
| 509 | +static int set_netdevs(struct ib_device *ib_dev, struct c4iw_rdev *rdev) |
|---|
| 506 | 510 | { |
|---|
| 507 | | - struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, ibdev); |
|---|
| 508 | | - struct c4iw_rdev *rdev = &c4iw_dev->rdev; |
|---|
| 509 | | - struct net_device *ndev; |
|---|
| 511 | + int ret; |
|---|
| 512 | + int i; |
|---|
| 510 | 513 | |
|---|
| 511 | | - if (!port || port > rdev->lldi.nports) |
|---|
| 512 | | - return NULL; |
|---|
| 513 | | - |
|---|
| 514 | | - rcu_read_lock(); |
|---|
| 515 | | - ndev = rdev->lldi.ports[port - 1]; |
|---|
| 516 | | - if (ndev) |
|---|
| 517 | | - dev_hold(ndev); |
|---|
| 518 | | - rcu_read_unlock(); |
|---|
| 519 | | - |
|---|
| 520 | | - return ndev; |
|---|
| 521 | | -} |
|---|
| 522 | | - |
|---|
| 523 | | -static int fill_res_entry(struct sk_buff *msg, struct rdma_restrack_entry *res) |
|---|
| 524 | | -{ |
|---|
| 525 | | - return (res->type < ARRAY_SIZE(c4iw_restrack_funcs) && |
|---|
| 526 | | - c4iw_restrack_funcs[res->type]) ? |
|---|
| 527 | | - c4iw_restrack_funcs[res->type](msg, res) : 0; |
|---|
| 514 | + for (i = 0; i < rdev->lldi.nports; i++) { |
|---|
| 515 | + ret = ib_device_set_netdev(ib_dev, rdev->lldi.ports[i], |
|---|
| 516 | + i + 1); |
|---|
| 517 | + if (ret) |
|---|
| 518 | + return ret; |
|---|
| 519 | + } |
|---|
| 520 | + return 0; |
|---|
| 528 | 521 | } |
|---|
| 529 | 522 | |
|---|
| 530 | 523 | void c4iw_register_device(struct work_struct *work) |
|---|
| 531 | 524 | { |
|---|
| 532 | 525 | int ret; |
|---|
| 533 | | - int i; |
|---|
| 534 | 526 | struct uld_ctx *ctx = container_of(work, struct uld_ctx, reg_work); |
|---|
| 535 | 527 | struct c4iw_dev *dev = ctx->dev; |
|---|
| 536 | 528 | |
|---|
| 537 | 529 | pr_debug("c4iw_dev %p\n", dev); |
|---|
| 538 | | - strlcpy(dev->ibdev.name, "cxgb4_%d", IB_DEVICE_NAME_MAX); |
|---|
| 539 | 530 | memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid)); |
|---|
| 540 | 531 | memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6); |
|---|
| 541 | | - dev->ibdev.owner = THIS_MODULE; |
|---|
| 542 | 532 | dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW; |
|---|
| 543 | 533 | if (fastreg_support) |
|---|
| 544 | 534 | dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
|---|
| .. | .. |
|---|
| 571 | 561 | dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports; |
|---|
| 572 | 562 | dev->ibdev.num_comp_vectors = dev->rdev.lldi.nciq; |
|---|
| 573 | 563 | dev->ibdev.dev.parent = &dev->rdev.lldi.pdev->dev; |
|---|
| 574 | | - dev->ibdev.query_device = c4iw_query_device; |
|---|
| 575 | | - dev->ibdev.query_port = c4iw_query_port; |
|---|
| 576 | | - dev->ibdev.query_pkey = c4iw_query_pkey; |
|---|
| 577 | | - dev->ibdev.query_gid = c4iw_query_gid; |
|---|
| 578 | | - dev->ibdev.alloc_ucontext = c4iw_alloc_ucontext; |
|---|
| 579 | | - dev->ibdev.dealloc_ucontext = c4iw_dealloc_ucontext; |
|---|
| 580 | | - dev->ibdev.mmap = c4iw_mmap; |
|---|
| 581 | | - dev->ibdev.alloc_pd = c4iw_allocate_pd; |
|---|
| 582 | | - dev->ibdev.dealloc_pd = c4iw_deallocate_pd; |
|---|
| 583 | | - dev->ibdev.create_qp = c4iw_create_qp; |
|---|
| 584 | | - dev->ibdev.modify_qp = c4iw_ib_modify_qp; |
|---|
| 585 | | - dev->ibdev.query_qp = c4iw_ib_query_qp; |
|---|
| 586 | | - dev->ibdev.destroy_qp = c4iw_destroy_qp; |
|---|
| 587 | | - dev->ibdev.create_srq = c4iw_create_srq; |
|---|
| 588 | | - dev->ibdev.modify_srq = c4iw_modify_srq; |
|---|
| 589 | | - dev->ibdev.destroy_srq = c4iw_destroy_srq; |
|---|
| 590 | | - dev->ibdev.create_cq = c4iw_create_cq; |
|---|
| 591 | | - dev->ibdev.destroy_cq = c4iw_destroy_cq; |
|---|
| 592 | | - dev->ibdev.poll_cq = c4iw_poll_cq; |
|---|
| 593 | | - dev->ibdev.get_dma_mr = c4iw_get_dma_mr; |
|---|
| 594 | | - dev->ibdev.reg_user_mr = c4iw_reg_user_mr; |
|---|
| 595 | | - dev->ibdev.dereg_mr = c4iw_dereg_mr; |
|---|
| 596 | | - dev->ibdev.alloc_mw = c4iw_alloc_mw; |
|---|
| 597 | | - dev->ibdev.dealloc_mw = c4iw_dealloc_mw; |
|---|
| 598 | | - dev->ibdev.alloc_mr = c4iw_alloc_mr; |
|---|
| 599 | | - dev->ibdev.map_mr_sg = c4iw_map_mr_sg; |
|---|
| 600 | | - dev->ibdev.req_notify_cq = c4iw_arm_cq; |
|---|
| 601 | | - dev->ibdev.post_send = c4iw_post_send; |
|---|
| 602 | | - dev->ibdev.post_recv = c4iw_post_receive; |
|---|
| 603 | | - dev->ibdev.post_srq_recv = c4iw_post_srq_recv; |
|---|
| 604 | | - dev->ibdev.alloc_hw_stats = c4iw_alloc_stats; |
|---|
| 605 | | - dev->ibdev.get_hw_stats = c4iw_get_mib; |
|---|
| 606 | | - dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION; |
|---|
| 607 | | - dev->ibdev.get_port_immutable = c4iw_port_immutable; |
|---|
| 608 | | - dev->ibdev.get_dev_fw_str = get_dev_fw_str; |
|---|
| 609 | | - dev->ibdev.get_netdev = get_netdev; |
|---|
| 610 | 564 | |
|---|
| 611 | | - dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL); |
|---|
| 612 | | - if (!dev->ibdev.iwcm) { |
|---|
| 613 | | - ret = -ENOMEM; |
|---|
| 614 | | - goto err_dealloc_ctx; |
|---|
| 615 | | - } |
|---|
| 565 | + memcpy(dev->ibdev.iw_ifname, dev->rdev.lldi.ports[0]->name, |
|---|
| 566 | + sizeof(dev->ibdev.iw_ifname)); |
|---|
| 616 | 567 | |
|---|
| 617 | | - dev->ibdev.iwcm->connect = c4iw_connect; |
|---|
| 618 | | - dev->ibdev.iwcm->accept = c4iw_accept_cr; |
|---|
| 619 | | - dev->ibdev.iwcm->reject = c4iw_reject_cr; |
|---|
| 620 | | - dev->ibdev.iwcm->create_listen = c4iw_create_listen; |
|---|
| 621 | | - dev->ibdev.iwcm->destroy_listen = c4iw_destroy_listen; |
|---|
| 622 | | - dev->ibdev.iwcm->add_ref = c4iw_qp_add_ref; |
|---|
| 623 | | - dev->ibdev.iwcm->rem_ref = c4iw_qp_rem_ref; |
|---|
| 624 | | - dev->ibdev.iwcm->get_qp = c4iw_get_qp; |
|---|
| 625 | | - dev->ibdev.res.fill_res_entry = fill_res_entry; |
|---|
| 626 | | - memcpy(dev->ibdev.iwcm->ifname, dev->rdev.lldi.ports[0]->name, |
|---|
| 627 | | - sizeof(dev->ibdev.iwcm->ifname)); |
|---|
| 628 | | - |
|---|
| 629 | | - dev->ibdev.driver_id = RDMA_DRIVER_CXGB4; |
|---|
| 630 | | - ret = ib_register_device(&dev->ibdev, NULL); |
|---|
| 568 | + rdma_set_device_sysfs_group(&dev->ibdev, &c4iw_attr_group); |
|---|
| 569 | + ib_set_device_ops(&dev->ibdev, &c4iw_dev_ops); |
|---|
| 570 | + ret = set_netdevs(&dev->ibdev, &dev->rdev); |
|---|
| 631 | 571 | if (ret) |
|---|
| 632 | | - goto err_kfree_iwcm; |
|---|
| 633 | | - |
|---|
| 634 | | - for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) { |
|---|
| 635 | | - ret = device_create_file(&dev->ibdev.dev, |
|---|
| 636 | | - c4iw_class_attributes[i]); |
|---|
| 637 | | - if (ret) |
|---|
| 638 | | - goto err_unregister_device; |
|---|
| 639 | | - } |
|---|
| 572 | + goto err_dealloc_ctx; |
|---|
| 573 | + dma_set_max_seg_size(&dev->rdev.lldi.pdev->dev, UINT_MAX); |
|---|
| 574 | + ret = ib_register_device(&dev->ibdev, "cxgb4_%d", |
|---|
| 575 | + &dev->rdev.lldi.pdev->dev); |
|---|
| 576 | + if (ret) |
|---|
| 577 | + goto err_dealloc_ctx; |
|---|
| 640 | 578 | return; |
|---|
| 641 | | -err_unregister_device: |
|---|
| 642 | | - ib_unregister_device(&dev->ibdev); |
|---|
| 643 | | -err_kfree_iwcm: |
|---|
| 644 | | - kfree(dev->ibdev.iwcm); |
|---|
| 579 | + |
|---|
| 645 | 580 | err_dealloc_ctx: |
|---|
| 646 | 581 | pr_err("%s - Failed registering iwarp device: %d\n", |
|---|
| 647 | 582 | pci_name(ctx->lldi.pdev), ret); |
|---|
| .. | .. |
|---|
| 651 | 586 | |
|---|
| 652 | 587 | void c4iw_unregister_device(struct c4iw_dev *dev) |
|---|
| 653 | 588 | { |
|---|
| 654 | | - int i; |
|---|
| 655 | | - |
|---|
| 656 | 589 | pr_debug("c4iw_dev %p\n", dev); |
|---|
| 657 | | - for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) |
|---|
| 658 | | - device_remove_file(&dev->ibdev.dev, |
|---|
| 659 | | - c4iw_class_attributes[i]); |
|---|
| 660 | 590 | ib_unregister_device(&dev->ibdev); |
|---|
| 661 | | - kfree(dev->ibdev.iwcm); |
|---|
| 662 | 591 | return; |
|---|
| 663 | 592 | } |
|---|