1 /* 2 * Copyright(c) 2016 - 2018 Intel Corporation. 3 * 4 * This file is provided under a dual BSD/GPLv2 license. When using or 5 * redistributing this file, you may do so under either license. 6 * 7 * GPL LICENSE SUMMARY 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of version 2 of the GNU General Public License as 11 * published by the Free Software Foundation. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * BSD LICENSE 19 * 20 * Redistribution and use in source and binary forms, with or without 21 * modification, are permitted provided that the following conditions 22 * are met: 23 * 24 * - Redistributions of source code must retain the above copyright 25 * notice, this list of conditions and the following disclaimer. 26 * - Redistributions in binary form must reproduce the above copyright 27 * notice, this list of conditions and the following disclaimer in 28 * the documentation and/or other materials provided with the 29 * distribution. 30 * - Neither the name of Intel Corporation nor the names of its 31 * contributors may be used to endorse or promote products derived 32 * from this software without specific prior written permission. 33 * 34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 * 46 */ 47 48 #include <linux/module.h> 49 #include <linux/kernel.h> 50 #include <linux/dma-mapping.h> 51 #include "vt.h" 52 #include "cq.h" 53 #include "trace.h" 54 55 #define RVT_UVERBS_ABI_VERSION 2 56 57 MODULE_LICENSE("Dual BSD/GPL"); 58 MODULE_DESCRIPTION("RDMA Verbs Transport Library"); 59 60 static int rvt_init(void) 61 { 62 int ret = rvt_driver_cq_init(); 63 64 if (ret) 65 pr_err("Error in driver CQ init.\n"); 66 67 return ret; 68 } 69 module_init(rvt_init); 70 71 static void rvt_cleanup(void) 72 { 73 rvt_cq_exit(); 74 } 75 module_exit(rvt_cleanup); 76 77 /** 78 * rvt_alloc_device - allocate rdi 79 * @size: how big of a structure to allocate 80 * @nports: number of ports to allocate array slots for 81 * 82 * Use IB core device alloc to allocate space for the rdi which is assumed to be 83 * inside of the ib_device. Any extra space that drivers require should be 84 * included in size. 85 * 86 * We also allocate a port array based on the number of ports. 87 * 88 * Return: pointer to allocated rdi 89 */ 90 struct rvt_dev_info *rvt_alloc_device(size_t size, int nports) 91 { 92 struct rvt_dev_info *rdi; 93 94 rdi = container_of(_ib_alloc_device(size), struct rvt_dev_info, ibdev); 95 if (!rdi) 96 return rdi; 97 98 rdi->ports = kcalloc(nports, sizeof(*rdi->ports), GFP_KERNEL); 99 if (!rdi->ports) 100 ib_dealloc_device(&rdi->ibdev); 101 102 return rdi; 103 } 104 EXPORT_SYMBOL(rvt_alloc_device); 105 106 /** 107 * rvt_dealloc_device - deallocate rdi 108 * @rdi: structure to free 109 * 110 * Free a structure allocated with rvt_alloc_device() 111 */ 112 void rvt_dealloc_device(struct rvt_dev_info *rdi) 113 { 114 kfree(rdi->ports); 115 ib_dealloc_device(&rdi->ibdev); 116 } 117 EXPORT_SYMBOL(rvt_dealloc_device); 118 119 static int rvt_query_device(struct ib_device *ibdev, 120 struct ib_device_attr *props, 121 struct ib_udata *uhw) 122 { 123 struct rvt_dev_info *rdi = ib_to_rvt(ibdev); 124 125 if (uhw->inlen || uhw->outlen) 126 return -EINVAL; 127 /* 128 * Return rvt_dev_info.dparms.props contents 129 */ 130 *props = rdi->dparms.props; 131 return 0; 132 } 133 134 static int rvt_modify_device(struct ib_device *device, 135 int device_modify_mask, 136 struct ib_device_modify *device_modify) 137 { 138 /* 139 * There is currently no need to supply this based on qib and hfi1. 140 * Future drivers may need to implement this though. 141 */ 142 143 return -EOPNOTSUPP; 144 } 145 146 /** 147 * rvt_query_port: Passes the query port call to the driver 148 * @ibdev: Verbs IB dev 149 * @port_num: port number, 1 based from ib core 150 * @props: structure to hold returned properties 151 * 152 * Return: 0 on success 153 */ 154 static int rvt_query_port(struct ib_device *ibdev, u8 port_num, 155 struct ib_port_attr *props) 156 { 157 struct rvt_dev_info *rdi = ib_to_rvt(ibdev); 158 struct rvt_ibport *rvp; 159 int port_index = ibport_num_to_idx(ibdev, port_num); 160 161 if (port_index < 0) 162 return -EINVAL; 163 164 rvp = rdi->ports[port_index]; 165 /* props being zeroed by the caller, avoid zeroing it here */ 166 props->sm_lid = rvp->sm_lid; 167 props->sm_sl = rvp->sm_sl; 168 props->port_cap_flags = rvp->port_cap_flags; 169 props->max_msg_sz = 0x80000000; 170 props->pkey_tbl_len = rvt_get_npkeys(rdi); 171 props->bad_pkey_cntr = rvp->pkey_violations; 172 props->qkey_viol_cntr = rvp->qkey_violations; 173 props->subnet_timeout = rvp->subnet_timeout; 174 props->init_type_reply = 0; 175 176 /* Populate the remaining ib_port_attr elements */ 177 return rdi->driver_f.query_port_state(rdi, port_num, props); 178 } 179 180 /** 181 * rvt_modify_port 182 * @ibdev: Verbs IB dev 183 * @port_num: Port number, 1 based from ib core 184 * @port_modify_mask: How to change the port 185 * @props: Structure to fill in 186 * 187 * Return: 0 on success 188 */ 189 static int rvt_modify_port(struct ib_device *ibdev, u8 port_num, 190 int port_modify_mask, struct ib_port_modify *props) 191 { 192 struct rvt_dev_info *rdi = ib_to_rvt(ibdev); 193 struct rvt_ibport *rvp; 194 int ret = 0; 195 int port_index = ibport_num_to_idx(ibdev, port_num); 196 197 if (port_index < 0) 198 return -EINVAL; 199 200 rvp = rdi->ports[port_index]; 201 if (port_modify_mask & IB_PORT_OPA_MASK_CHG) { 202 rvp->port_cap3_flags |= props->set_port_cap_mask; 203 rvp->port_cap3_flags &= ~props->clr_port_cap_mask; 204 } else { 205 rvp->port_cap_flags |= props->set_port_cap_mask; 206 rvp->port_cap_flags &= ~props->clr_port_cap_mask; 207 } 208 209 if (props->set_port_cap_mask || props->clr_port_cap_mask) 210 rdi->driver_f.cap_mask_chg(rdi, port_num); 211 if (port_modify_mask & IB_PORT_SHUTDOWN) 212 ret = rdi->driver_f.shut_down_port(rdi, port_num); 213 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR) 214 rvp->qkey_violations = 0; 215 216 return ret; 217 } 218 219 /** 220 * rvt_query_pkey - Return a pkey from the table at a given index 221 * @ibdev: Verbs IB dev 222 * @port_num: Port number, 1 based from ib core 223 * @index: Index into pkey table 224 * @pkey: returned pkey from the port pkey table 225 * 226 * Return: 0 on failure pkey otherwise 227 */ 228 static int rvt_query_pkey(struct ib_device *ibdev, u8 port_num, u16 index, 229 u16 *pkey) 230 { 231 /* 232 * Driver will be responsible for keeping rvt_dev_info.pkey_table up to 233 * date. This function will just return that value. There is no need to 234 * lock, if a stale value is read and sent to the user so be it there is 235 * no way to protect against that anyway. 236 */ 237 struct rvt_dev_info *rdi = ib_to_rvt(ibdev); 238 int port_index; 239 240 port_index = ibport_num_to_idx(ibdev, port_num); 241 if (port_index < 0) 242 return -EINVAL; 243 244 if (index >= rvt_get_npkeys(rdi)) 245 return -EINVAL; 246 247 *pkey = rvt_get_pkey(rdi, port_index, index); 248 return 0; 249 } 250 251 /** 252 * rvt_query_gid - Return a gid from the table 253 * @ibdev: Verbs IB dev 254 * @port_num: Port number, 1 based from ib core 255 * @guid_index: Index in table 256 * @gid: Gid to return 257 * 258 * Return: 0 on success 259 */ 260 static int rvt_query_gid(struct ib_device *ibdev, u8 port_num, 261 int guid_index, union ib_gid *gid) 262 { 263 struct rvt_dev_info *rdi; 264 struct rvt_ibport *rvp; 265 int port_index; 266 267 /* 268 * Driver is responsible for updating the guid table. Which will be used 269 * to craft the return value. This will work similar to how query_pkey() 270 * is being done. 271 */ 272 port_index = ibport_num_to_idx(ibdev, port_num); 273 if (port_index < 0) 274 return -EINVAL; 275 276 rdi = ib_to_rvt(ibdev); 277 rvp = rdi->ports[port_index]; 278 279 gid->global.subnet_prefix = rvp->gid_prefix; 280 281 return rdi->driver_f.get_guid_be(rdi, rvp, guid_index, 282 &gid->global.interface_id); 283 } 284 285 /** 286 * rvt_alloc_ucontext - Allocate a user context 287 * @uctx: Verbs context 288 * @udata: User data allocated 289 */ 290 static int rvt_alloc_ucontext(struct ib_ucontext *uctx, struct ib_udata *udata) 291 { 292 return 0; 293 } 294 295 /** 296 * rvt_dealloc_ucontext - Free a user context 297 * @context - Free this 298 */ 299 static void rvt_dealloc_ucontext(struct ib_ucontext *context) 300 { 301 return; 302 } 303 304 static int rvt_get_port_immutable(struct ib_device *ibdev, u8 port_num, 305 struct ib_port_immutable *immutable) 306 { 307 struct rvt_dev_info *rdi = ib_to_rvt(ibdev); 308 struct ib_port_attr attr; 309 int err, port_index; 310 311 port_index = ibport_num_to_idx(ibdev, port_num); 312 if (port_index < 0) 313 return -EINVAL; 314 315 immutable->core_cap_flags = rdi->dparms.core_cap_flags; 316 317 err = ib_query_port(ibdev, port_num, &attr); 318 if (err) 319 return err; 320 321 immutable->pkey_tbl_len = attr.pkey_tbl_len; 322 immutable->gid_tbl_len = attr.gid_tbl_len; 323 immutable->max_mad_size = rdi->dparms.max_mad_size; 324 325 return 0; 326 } 327 328 enum { 329 MISC, 330 QUERY_DEVICE, 331 MODIFY_DEVICE, 332 QUERY_PORT, 333 MODIFY_PORT, 334 QUERY_PKEY, 335 QUERY_GID, 336 ALLOC_UCONTEXT, 337 DEALLOC_UCONTEXT, 338 GET_PORT_IMMUTABLE, 339 CREATE_QP, 340 MODIFY_QP, 341 DESTROY_QP, 342 QUERY_QP, 343 POST_SEND, 344 POST_RECV, 345 POST_SRQ_RECV, 346 CREATE_AH, 347 DESTROY_AH, 348 MODIFY_AH, 349 QUERY_AH, 350 CREATE_SRQ, 351 MODIFY_SRQ, 352 DESTROY_SRQ, 353 QUERY_SRQ, 354 ATTACH_MCAST, 355 DETACH_MCAST, 356 GET_DMA_MR, 357 REG_USER_MR, 358 DEREG_MR, 359 ALLOC_MR, 360 MAP_MR_SG, 361 ALLOC_FMR, 362 MAP_PHYS_FMR, 363 UNMAP_FMR, 364 DEALLOC_FMR, 365 MMAP, 366 CREATE_CQ, 367 DESTROY_CQ, 368 POLL_CQ, 369 REQ_NOTFIY_CQ, 370 RESIZE_CQ, 371 ALLOC_PD, 372 DEALLOC_PD, 373 _VERB_IDX_MAX /* Must always be last! */ 374 }; 375 376 static const struct ib_device_ops rvt_dev_ops = { 377 .uverbs_abi_ver = RVT_UVERBS_ABI_VERSION, 378 379 .alloc_mr = rvt_alloc_mr, 380 .alloc_pd = rvt_alloc_pd, 381 .alloc_ucontext = rvt_alloc_ucontext, 382 .attach_mcast = rvt_attach_mcast, 383 .create_ah = rvt_create_ah, 384 .create_cq = rvt_create_cq, 385 .create_qp = rvt_create_qp, 386 .create_srq = rvt_create_srq, 387 .dealloc_pd = rvt_dealloc_pd, 388 .dealloc_ucontext = rvt_dealloc_ucontext, 389 .dereg_mr = rvt_dereg_mr, 390 .destroy_ah = rvt_destroy_ah, 391 .destroy_cq = rvt_destroy_cq, 392 .destroy_qp = rvt_destroy_qp, 393 .destroy_srq = rvt_destroy_srq, 394 .detach_mcast = rvt_detach_mcast, 395 .get_dma_mr = rvt_get_dma_mr, 396 .get_port_immutable = rvt_get_port_immutable, 397 .map_mr_sg = rvt_map_mr_sg, 398 .mmap = rvt_mmap, 399 .modify_ah = rvt_modify_ah, 400 .modify_device = rvt_modify_device, 401 .modify_port = rvt_modify_port, 402 .modify_qp = rvt_modify_qp, 403 .modify_srq = rvt_modify_srq, 404 .poll_cq = rvt_poll_cq, 405 .post_recv = rvt_post_recv, 406 .post_send = rvt_post_send, 407 .post_srq_recv = rvt_post_srq_recv, 408 .query_ah = rvt_query_ah, 409 .query_device = rvt_query_device, 410 .query_gid = rvt_query_gid, 411 .query_pkey = rvt_query_pkey, 412 .query_port = rvt_query_port, 413 .query_qp = rvt_query_qp, 414 .query_srq = rvt_query_srq, 415 .reg_user_mr = rvt_reg_user_mr, 416 .req_notify_cq = rvt_req_notify_cq, 417 .resize_cq = rvt_resize_cq, 418 419 INIT_RDMA_OBJ_SIZE(ib_ah, rvt_ah, ibah), 420 INIT_RDMA_OBJ_SIZE(ib_cq, rvt_cq, ibcq), 421 INIT_RDMA_OBJ_SIZE(ib_pd, rvt_pd, ibpd), 422 INIT_RDMA_OBJ_SIZE(ib_srq, rvt_srq, ibsrq), 423 INIT_RDMA_OBJ_SIZE(ib_ucontext, rvt_ucontext, ibucontext), 424 }; 425 426 static noinline int check_support(struct rvt_dev_info *rdi, int verb) 427 { 428 switch (verb) { 429 case MISC: 430 /* 431 * These functions are not part of verbs specifically but are 432 * required for rdmavt to function. 433 */ 434 if ((!rdi->ibdev.ops.init_port) || 435 (!rdi->driver_f.get_pci_dev)) 436 return -EINVAL; 437 break; 438 439 case MODIFY_DEVICE: 440 /* 441 * rdmavt does not support modify device currently drivers must 442 * provide. 443 */ 444 if (!rdi->ibdev.ops.modify_device) 445 return -EOPNOTSUPP; 446 break; 447 448 case QUERY_PORT: 449 if (!rdi->ibdev.ops.query_port) 450 if (!rdi->driver_f.query_port_state) 451 return -EINVAL; 452 break; 453 454 case MODIFY_PORT: 455 if (!rdi->ibdev.ops.modify_port) 456 if (!rdi->driver_f.cap_mask_chg || 457 !rdi->driver_f.shut_down_port) 458 return -EINVAL; 459 break; 460 461 case QUERY_GID: 462 if (!rdi->ibdev.ops.query_gid) 463 if (!rdi->driver_f.get_guid_be) 464 return -EINVAL; 465 break; 466 467 case CREATE_QP: 468 if (!rdi->ibdev.ops.create_qp) 469 if (!rdi->driver_f.qp_priv_alloc || 470 !rdi->driver_f.qp_priv_free || 471 !rdi->driver_f.notify_qp_reset || 472 !rdi->driver_f.flush_qp_waiters || 473 !rdi->driver_f.stop_send_queue || 474 !rdi->driver_f.quiesce_qp) 475 return -EINVAL; 476 break; 477 478 case MODIFY_QP: 479 if (!rdi->ibdev.ops.modify_qp) 480 if (!rdi->driver_f.notify_qp_reset || 481 !rdi->driver_f.schedule_send || 482 !rdi->driver_f.get_pmtu_from_attr || 483 !rdi->driver_f.flush_qp_waiters || 484 !rdi->driver_f.stop_send_queue || 485 !rdi->driver_f.quiesce_qp || 486 !rdi->driver_f.notify_error_qp || 487 !rdi->driver_f.mtu_from_qp || 488 !rdi->driver_f.mtu_to_path_mtu) 489 return -EINVAL; 490 break; 491 492 case DESTROY_QP: 493 if (!rdi->ibdev.ops.destroy_qp) 494 if (!rdi->driver_f.qp_priv_free || 495 !rdi->driver_f.notify_qp_reset || 496 !rdi->driver_f.flush_qp_waiters || 497 !rdi->driver_f.stop_send_queue || 498 !rdi->driver_f.quiesce_qp) 499 return -EINVAL; 500 break; 501 502 case POST_SEND: 503 if (!rdi->ibdev.ops.post_send) 504 if (!rdi->driver_f.schedule_send || 505 !rdi->driver_f.do_send || 506 !rdi->post_parms) 507 return -EINVAL; 508 break; 509 510 } 511 512 return 0; 513 } 514 515 /** 516 * rvt_register_device - register a driver 517 * @rdi: main dev structure for all of rdmavt operations 518 * 519 * It is up to drivers to allocate the rdi and fill in the appropriate 520 * information. 521 * 522 * Return: 0 on success otherwise an errno. 523 */ 524 int rvt_register_device(struct rvt_dev_info *rdi) 525 { 526 int ret = 0, i; 527 528 if (!rdi) 529 return -EINVAL; 530 531 /* 532 * Check to ensure drivers have setup the required helpers for the verbs 533 * they want rdmavt to handle 534 */ 535 for (i = 0; i < _VERB_IDX_MAX; i++) 536 if (check_support(rdi, i)) { 537 pr_err("Driver support req not met at %d\n", i); 538 return -EINVAL; 539 } 540 541 ib_set_device_ops(&rdi->ibdev, &rvt_dev_ops); 542 543 /* Once we get past here we can use rvt_pr macros and tracepoints */ 544 trace_rvt_dbg(rdi, "Driver attempting registration"); 545 rvt_mmap_init(rdi); 546 547 /* Queue Pairs */ 548 ret = rvt_driver_qp_init(rdi); 549 if (ret) { 550 pr_err("Error in driver QP init.\n"); 551 return -EINVAL; 552 } 553 554 /* Address Handle */ 555 spin_lock_init(&rdi->n_ahs_lock); 556 rdi->n_ahs_allocated = 0; 557 558 /* Shared Receive Queue */ 559 rvt_driver_srq_init(rdi); 560 561 /* Multicast */ 562 rvt_driver_mcast_init(rdi); 563 564 /* Mem Region */ 565 ret = rvt_driver_mr_init(rdi); 566 if (ret) { 567 pr_err("Error in driver MR init.\n"); 568 goto bail_no_mr; 569 } 570 571 /* Memory Working Set Size */ 572 ret = rvt_wss_init(rdi); 573 if (ret) { 574 rvt_pr_err(rdi, "Error in WSS init.\n"); 575 goto bail_mr; 576 } 577 578 /* Completion queues */ 579 spin_lock_init(&rdi->n_cqs_lock); 580 581 /* DMA Operations */ 582 rdi->ibdev.dev.dma_parms = rdi->ibdev.dev.parent->dma_parms; 583 dma_set_coherent_mask(&rdi->ibdev.dev, 584 rdi->ibdev.dev.parent->coherent_dma_mask); 585 586 /* Protection Domain */ 587 spin_lock_init(&rdi->n_pds_lock); 588 rdi->n_pds_allocated = 0; 589 590 /* 591 * There are some things which could be set by underlying drivers but 592 * really should be up to rdmavt to set. For instance drivers can't know 593 * exactly which functions rdmavt supports, nor do they know the ABI 594 * version, so we do all of this sort of stuff here. 595 */ 596 rdi->ibdev.uverbs_cmd_mask = 597 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | 598 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | 599 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | 600 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | 601 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | 602 (1ull << IB_USER_VERBS_CMD_CREATE_AH) | 603 (1ull << IB_USER_VERBS_CMD_MODIFY_AH) | 604 (1ull << IB_USER_VERBS_CMD_QUERY_AH) | 605 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | 606 (1ull << IB_USER_VERBS_CMD_REG_MR) | 607 (1ull << IB_USER_VERBS_CMD_DEREG_MR) | 608 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | 609 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | 610 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | 611 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | 612 (1ull << IB_USER_VERBS_CMD_POLL_CQ) | 613 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) | 614 (1ull << IB_USER_VERBS_CMD_CREATE_QP) | 615 (1ull << IB_USER_VERBS_CMD_QUERY_QP) | 616 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | 617 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | 618 (1ull << IB_USER_VERBS_CMD_POST_SEND) | 619 (1ull << IB_USER_VERBS_CMD_POST_RECV) | 620 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | 621 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | 622 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | 623 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | 624 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | 625 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | 626 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV); 627 rdi->ibdev.node_type = RDMA_NODE_IB_CA; 628 if (!rdi->ibdev.num_comp_vectors) 629 rdi->ibdev.num_comp_vectors = 1; 630 631 /* We are now good to announce we exist */ 632 ret = ib_register_device(&rdi->ibdev, dev_name(&rdi->ibdev.dev), NULL); 633 if (ret) { 634 rvt_pr_err(rdi, "Failed to register driver with ib core.\n"); 635 goto bail_wss; 636 } 637 638 rvt_create_mad_agents(rdi); 639 640 rvt_pr_info(rdi, "Registration with rdmavt done.\n"); 641 return ret; 642 643 bail_wss: 644 rvt_wss_exit(rdi); 645 bail_mr: 646 rvt_mr_exit(rdi); 647 648 bail_no_mr: 649 rvt_qp_exit(rdi); 650 651 return ret; 652 } 653 EXPORT_SYMBOL(rvt_register_device); 654 655 /** 656 * rvt_unregister_device - remove a driver 657 * @rdi: rvt dev struct 658 */ 659 void rvt_unregister_device(struct rvt_dev_info *rdi) 660 { 661 trace_rvt_dbg(rdi, "Driver is unregistering."); 662 if (!rdi) 663 return; 664 665 rvt_free_mad_agents(rdi); 666 667 ib_unregister_device(&rdi->ibdev); 668 rvt_wss_exit(rdi); 669 rvt_mr_exit(rdi); 670 rvt_qp_exit(rdi); 671 } 672 EXPORT_SYMBOL(rvt_unregister_device); 673 674 /** 675 * rvt_init_port - init internal data for driver port 676 * @rdi: rvt_dev_info struct 677 * @port: rvt port 678 * @port_index: 0 based index of ports, different from IB core port num 679 * @pkey_table: pkey_table for @port 680 * 681 * Keep track of a list of ports. No need to have a detach port. 682 * They persist until the driver goes away. 683 * 684 * Return: always 0 685 */ 686 int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port, 687 int port_index, u16 *pkey_table) 688 { 689 690 rdi->ports[port_index] = port; 691 rdi->ports[port_index]->pkey_table = pkey_table; 692 693 return 0; 694 } 695 EXPORT_SYMBOL(rvt_init_port); 696