| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. |
|---|
| 3 | 4 | * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved. |
|---|
| 4 | | - * |
|---|
| 5 | | - * This software is available to you under a choice of one of two |
|---|
| 6 | | - * licenses. You may choose to be licensed under the terms of the GNU |
|---|
| 7 | | - * General Public License (GPL) Version 2, available from the file |
|---|
| 8 | | - * COPYING in the main directory of this source tree, or the |
|---|
| 9 | | - * OpenIB.org BSD license below: |
|---|
| 10 | | - * |
|---|
| 11 | | - * Redistribution and use in source and binary forms, with or |
|---|
| 12 | | - * without modification, are permitted provided that the following |
|---|
| 13 | | - * conditions are met: |
|---|
| 14 | | - * |
|---|
| 15 | | - * - Redistributions of source code must retain the above |
|---|
| 16 | | - * copyright notice, this list of conditions and the following |
|---|
| 17 | | - * disclaimer. |
|---|
| 18 | | - * |
|---|
| 19 | | - * - Redistributions in binary form must reproduce the above |
|---|
| 20 | | - * copyright notice, this list of conditions and the following |
|---|
| 21 | | - * disclaimer in the documentation and/or other materials |
|---|
| 22 | | - * provided with the distribution. |
|---|
| 23 | | - * |
|---|
| 24 | | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|---|
| 25 | | - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|---|
| 26 | | - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|---|
| 27 | | - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
|---|
| 28 | | - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
|---|
| 29 | | - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|---|
| 30 | | - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|---|
| 31 | | - * SOFTWARE. |
|---|
| 32 | 5 | */ |
|---|
| 33 | 6 | |
|---|
| 7 | +#include <rdma/rdma_netlink.h> |
|---|
| 34 | 8 | #include <net/addrconf.h> |
|---|
| 35 | 9 | #include "rxe.h" |
|---|
| 36 | 10 | #include "rxe_loc.h" |
|---|
| .. | .. |
|---|
| 39 | 13 | MODULE_DESCRIPTION("Soft RDMA transport"); |
|---|
| 40 | 14 | MODULE_LICENSE("Dual BSD/GPL"); |
|---|
| 41 | 15 | |
|---|
| 42 | | -/* free resources for all ports on a device */ |
|---|
| 43 | | -static void rxe_cleanup_ports(struct rxe_dev *rxe) |
|---|
| 44 | | -{ |
|---|
| 45 | | - kfree(rxe->port.pkey_tbl); |
|---|
| 46 | | - rxe->port.pkey_tbl = NULL; |
|---|
| 47 | | - |
|---|
| 48 | | -} |
|---|
| 16 | +bool rxe_initialized; |
|---|
| 49 | 17 | |
|---|
| 50 | 18 | /* free resources for a rxe device all objects created for this device must |
|---|
| 51 | 19 | * have been destroyed |
|---|
| 52 | 20 | */ |
|---|
| 53 | | -static void rxe_cleanup(struct rxe_dev *rxe) |
|---|
| 21 | +void rxe_dealloc(struct ib_device *ib_dev) |
|---|
| 54 | 22 | { |
|---|
| 23 | + struct rxe_dev *rxe = container_of(ib_dev, struct rxe_dev, ib_dev); |
|---|
| 24 | + |
|---|
| 55 | 25 | rxe_pool_cleanup(&rxe->uc_pool); |
|---|
| 56 | 26 | rxe_pool_cleanup(&rxe->pd_pool); |
|---|
| 57 | 27 | rxe_pool_cleanup(&rxe->ah_pool); |
|---|
| .. | .. |
|---|
| 63 | 33 | rxe_pool_cleanup(&rxe->mc_grp_pool); |
|---|
| 64 | 34 | rxe_pool_cleanup(&rxe->mc_elem_pool); |
|---|
| 65 | 35 | |
|---|
| 66 | | - rxe_cleanup_ports(rxe); |
|---|
| 67 | | - |
|---|
| 68 | | - crypto_free_shash(rxe->tfm); |
|---|
| 69 | | -} |
|---|
| 70 | | - |
|---|
| 71 | | -/* called when all references have been dropped */ |
|---|
| 72 | | -void rxe_release(struct kref *kref) |
|---|
| 73 | | -{ |
|---|
| 74 | | - struct rxe_dev *rxe = container_of(kref, struct rxe_dev, ref_cnt); |
|---|
| 75 | | - |
|---|
| 76 | | - rxe_cleanup(rxe); |
|---|
| 77 | | - ib_dealloc_device(&rxe->ib_dev); |
|---|
| 36 | + if (rxe->tfm) |
|---|
| 37 | + crypto_free_shash(rxe->tfm); |
|---|
| 78 | 38 | } |
|---|
| 79 | 39 | |
|---|
| 80 | 40 | /* initialize rxe device parameters */ |
|---|
| .. | .. |
|---|
| 82 | 42 | { |
|---|
| 83 | 43 | rxe->max_inline_data = RXE_MAX_INLINE_DATA; |
|---|
| 84 | 44 | |
|---|
| 85 | | - rxe->attr.fw_ver = RXE_FW_VER; |
|---|
| 45 | + rxe->attr.vendor_id = RXE_VENDOR_ID; |
|---|
| 86 | 46 | rxe->attr.max_mr_size = RXE_MAX_MR_SIZE; |
|---|
| 87 | 47 | rxe->attr.page_size_cap = RXE_PAGE_SIZE_CAP; |
|---|
| 88 | | - rxe->attr.vendor_id = RXE_VENDOR_ID; |
|---|
| 89 | | - rxe->attr.vendor_part_id = RXE_VENDOR_PART_ID; |
|---|
| 90 | | - rxe->attr.hw_ver = RXE_HW_VER; |
|---|
| 91 | 48 | rxe->attr.max_qp = RXE_MAX_QP; |
|---|
| 92 | 49 | rxe->attr.max_qp_wr = RXE_MAX_QP_WR; |
|---|
| 93 | 50 | rxe->attr.device_cap_flags = RXE_DEVICE_CAP_FLAGS; |
|---|
| .. | .. |
|---|
| 99 | 56 | rxe->attr.max_mr = RXE_MAX_MR; |
|---|
| 100 | 57 | rxe->attr.max_pd = RXE_MAX_PD; |
|---|
| 101 | 58 | rxe->attr.max_qp_rd_atom = RXE_MAX_QP_RD_ATOM; |
|---|
| 102 | | - rxe->attr.max_ee_rd_atom = RXE_MAX_EE_RD_ATOM; |
|---|
| 103 | 59 | rxe->attr.max_res_rd_atom = RXE_MAX_RES_RD_ATOM; |
|---|
| 104 | 60 | rxe->attr.max_qp_init_rd_atom = RXE_MAX_QP_INIT_RD_ATOM; |
|---|
| 105 | | - rxe->attr.max_ee_init_rd_atom = RXE_MAX_EE_INIT_RD_ATOM; |
|---|
| 106 | | - rxe->attr.atomic_cap = RXE_ATOMIC_CAP; |
|---|
| 107 | | - rxe->attr.max_ee = RXE_MAX_EE; |
|---|
| 108 | | - rxe->attr.max_rdd = RXE_MAX_RDD; |
|---|
| 109 | | - rxe->attr.max_mw = RXE_MAX_MW; |
|---|
| 110 | | - rxe->attr.max_raw_ipv6_qp = RXE_MAX_RAW_IPV6_QP; |
|---|
| 111 | | - rxe->attr.max_raw_ethy_qp = RXE_MAX_RAW_ETHY_QP; |
|---|
| 61 | + rxe->attr.atomic_cap = IB_ATOMIC_HCA; |
|---|
| 112 | 62 | rxe->attr.max_mcast_grp = RXE_MAX_MCAST_GRP; |
|---|
| 113 | 63 | rxe->attr.max_mcast_qp_attach = RXE_MAX_MCAST_QP_ATTACH; |
|---|
| 114 | 64 | rxe->attr.max_total_mcast_qp_attach = RXE_MAX_TOT_MCAST_QP_ATTACH; |
|---|
| 115 | 65 | rxe->attr.max_ah = RXE_MAX_AH; |
|---|
| 116 | | - rxe->attr.max_fmr = RXE_MAX_FMR; |
|---|
| 117 | | - rxe->attr.max_map_per_fmr = RXE_MAX_MAP_PER_FMR; |
|---|
| 118 | 66 | rxe->attr.max_srq = RXE_MAX_SRQ; |
|---|
| 119 | 67 | rxe->attr.max_srq_wr = RXE_MAX_SRQ_WR; |
|---|
| 120 | 68 | rxe->attr.max_srq_sge = RXE_MAX_SRQ_SGE; |
|---|
| .. | .. |
|---|
| 128 | 76 | } |
|---|
| 129 | 77 | |
|---|
| 130 | 78 | /* initialize port attributes */ |
|---|
| 131 | | -static int rxe_init_port_param(struct rxe_port *port) |
|---|
| 79 | +static void rxe_init_port_param(struct rxe_port *port) |
|---|
| 132 | 80 | { |
|---|
| 133 | | - port->attr.state = RXE_PORT_STATE; |
|---|
| 134 | | - port->attr.max_mtu = RXE_PORT_MAX_MTU; |
|---|
| 135 | | - port->attr.active_mtu = RXE_PORT_ACTIVE_MTU; |
|---|
| 81 | + port->attr.state = IB_PORT_DOWN; |
|---|
| 82 | + port->attr.max_mtu = IB_MTU_4096; |
|---|
| 83 | + port->attr.active_mtu = IB_MTU_256; |
|---|
| 136 | 84 | port->attr.gid_tbl_len = RXE_PORT_GID_TBL_LEN; |
|---|
| 137 | 85 | port->attr.port_cap_flags = RXE_PORT_PORT_CAP_FLAGS; |
|---|
| 138 | 86 | port->attr.max_msg_sz = RXE_PORT_MAX_MSG_SZ; |
|---|
| .. | .. |
|---|
| 149 | 97 | port->attr.active_width = RXE_PORT_ACTIVE_WIDTH; |
|---|
| 150 | 98 | port->attr.active_speed = RXE_PORT_ACTIVE_SPEED; |
|---|
| 151 | 99 | port->attr.phys_state = RXE_PORT_PHYS_STATE; |
|---|
| 152 | | - port->mtu_cap = |
|---|
| 153 | | - ib_mtu_enum_to_int(RXE_PORT_ACTIVE_MTU); |
|---|
| 100 | + port->mtu_cap = ib_mtu_enum_to_int(IB_MTU_256); |
|---|
| 154 | 101 | port->subnet_prefix = cpu_to_be64(RXE_PORT_SUBNET_PREFIX); |
|---|
| 155 | | - |
|---|
| 156 | | - return 0; |
|---|
| 157 | 102 | } |
|---|
| 158 | 103 | |
|---|
| 159 | 104 | /* initialize port state, note IB convention that HCA ports are always |
|---|
| 160 | 105 | * numbered from 1 |
|---|
| 161 | 106 | */ |
|---|
| 162 | | -static int rxe_init_ports(struct rxe_dev *rxe) |
|---|
| 107 | +static void rxe_init_ports(struct rxe_dev *rxe) |
|---|
| 163 | 108 | { |
|---|
| 164 | 109 | struct rxe_port *port = &rxe->port; |
|---|
| 165 | 110 | |
|---|
| 166 | 111 | rxe_init_port_param(port); |
|---|
| 167 | | - |
|---|
| 168 | | - port->pkey_tbl = kcalloc(port->attr.pkey_tbl_len, |
|---|
| 169 | | - sizeof(*port->pkey_tbl), GFP_KERNEL); |
|---|
| 170 | | - |
|---|
| 171 | | - if (!port->pkey_tbl) |
|---|
| 172 | | - return -ENOMEM; |
|---|
| 173 | | - |
|---|
| 174 | | - port->pkey_tbl[0] = 0xffff; |
|---|
| 175 | 112 | addrconf_addr_eui48((unsigned char *)&port->port_guid, |
|---|
| 176 | 113 | rxe->ndev->dev_addr); |
|---|
| 177 | | - |
|---|
| 178 | 114 | spin_lock_init(&port->port_lock); |
|---|
| 179 | | - |
|---|
| 180 | | - return 0; |
|---|
| 181 | 115 | } |
|---|
| 182 | 116 | |
|---|
| 183 | 117 | /* init pools of managed objects */ |
|---|
| .. | .. |
|---|
| 267 | 201 | /* init default device parameters */ |
|---|
| 268 | 202 | rxe_init_device_param(rxe); |
|---|
| 269 | 203 | |
|---|
| 270 | | - err = rxe_init_ports(rxe); |
|---|
| 271 | | - if (err) |
|---|
| 272 | | - goto err1; |
|---|
| 204 | + rxe_init_ports(rxe); |
|---|
| 273 | 205 | |
|---|
| 274 | 206 | err = rxe_init_pools(rxe); |
|---|
| 275 | 207 | if (err) |
|---|
| 276 | | - goto err2; |
|---|
| 208 | + return err; |
|---|
| 277 | 209 | |
|---|
| 278 | 210 | /* init pending mmap list */ |
|---|
| 279 | 211 | spin_lock_init(&rxe->mmap_offset_lock); |
|---|
| 280 | 212 | spin_lock_init(&rxe->pending_lock); |
|---|
| 281 | 213 | INIT_LIST_HEAD(&rxe->pending_mmaps); |
|---|
| 282 | | - INIT_LIST_HEAD(&rxe->list); |
|---|
| 283 | 214 | |
|---|
| 284 | 215 | mutex_init(&rxe->usdev_lock); |
|---|
| 285 | 216 | |
|---|
| 286 | 217 | return 0; |
|---|
| 287 | | - |
|---|
| 288 | | -err2: |
|---|
| 289 | | - rxe_cleanup_ports(rxe); |
|---|
| 290 | | -err1: |
|---|
| 291 | | - return err; |
|---|
| 292 | 218 | } |
|---|
| 293 | 219 | |
|---|
| 294 | 220 | void rxe_set_mtu(struct rxe_dev *rxe, unsigned int ndev_mtu) |
|---|
| .. | .. |
|---|
| 299 | 225 | mtu = eth_mtu_int_to_enum(ndev_mtu); |
|---|
| 300 | 226 | |
|---|
| 301 | 227 | /* Make sure that new MTU in range */ |
|---|
| 302 | | - mtu = mtu ? min_t(enum ib_mtu, mtu, RXE_PORT_MAX_MTU) : IB_MTU_256; |
|---|
| 228 | + mtu = mtu ? min_t(enum ib_mtu, mtu, IB_MTU_4096) : IB_MTU_256; |
|---|
| 303 | 229 | |
|---|
| 304 | 230 | port->attr.active_mtu = mtu; |
|---|
| 305 | 231 | port->mtu_cap = ib_mtu_enum_to_int(mtu); |
|---|
| .. | .. |
|---|
| 308 | 234 | /* called by ifc layer to create new rxe device. |
|---|
| 309 | 235 | * The caller should allocate memory for rxe by calling ib_alloc_device. |
|---|
| 310 | 236 | */ |
|---|
| 311 | | -int rxe_add(struct rxe_dev *rxe, unsigned int mtu) |
|---|
| 237 | +int rxe_add(struct rxe_dev *rxe, unsigned int mtu, const char *ibdev_name) |
|---|
| 312 | 238 | { |
|---|
| 313 | 239 | int err; |
|---|
| 314 | 240 | |
|---|
| 315 | | - kref_init(&rxe->ref_cnt); |
|---|
| 316 | | - |
|---|
| 317 | 241 | err = rxe_init(rxe); |
|---|
| 318 | 242 | if (err) |
|---|
| 319 | | - goto err1; |
|---|
| 243 | + return err; |
|---|
| 320 | 244 | |
|---|
| 321 | 245 | rxe_set_mtu(rxe, mtu); |
|---|
| 322 | 246 | |
|---|
| 323 | | - err = rxe_register_device(rxe); |
|---|
| 324 | | - if (err) |
|---|
| 325 | | - goto err1; |
|---|
| 247 | + return rxe_register_device(rxe, ibdev_name); |
|---|
| 248 | +} |
|---|
| 326 | 249 | |
|---|
| 327 | | - return 0; |
|---|
| 250 | +static int rxe_newlink(const char *ibdev_name, struct net_device *ndev) |
|---|
| 251 | +{ |
|---|
| 252 | + struct rxe_dev *exists; |
|---|
| 253 | + int err = 0; |
|---|
| 328 | 254 | |
|---|
| 329 | | -err1: |
|---|
| 330 | | - rxe_dev_put(rxe); |
|---|
| 255 | + if (is_vlan_dev(ndev)) { |
|---|
| 256 | + pr_err("rxe creation allowed on top of a real device only\n"); |
|---|
| 257 | + err = -EPERM; |
|---|
| 258 | + goto err; |
|---|
| 259 | + } |
|---|
| 260 | + |
|---|
| 261 | + exists = rxe_get_dev_from_net(ndev); |
|---|
| 262 | + if (exists) { |
|---|
| 263 | + ib_device_put(&exists->ib_dev); |
|---|
| 264 | + pr_err("already configured on %s\n", ndev->name); |
|---|
| 265 | + err = -EEXIST; |
|---|
| 266 | + goto err; |
|---|
| 267 | + } |
|---|
| 268 | + |
|---|
| 269 | + err = rxe_net_add(ibdev_name, ndev); |
|---|
| 270 | + if (err) { |
|---|
| 271 | + pr_err("failed to add %s\n", ndev->name); |
|---|
| 272 | + goto err; |
|---|
| 273 | + } |
|---|
| 274 | +err: |
|---|
| 331 | 275 | return err; |
|---|
| 332 | 276 | } |
|---|
| 333 | 277 | |
|---|
| 334 | | -/* called by the ifc layer to remove a device */ |
|---|
| 335 | | -void rxe_remove(struct rxe_dev *rxe) |
|---|
| 336 | | -{ |
|---|
| 337 | | - rxe_unregister_device(rxe); |
|---|
| 338 | | - |
|---|
| 339 | | - rxe_dev_put(rxe); |
|---|
| 340 | | -} |
|---|
| 278 | +static struct rdma_link_ops rxe_link_ops = { |
|---|
| 279 | + .type = "rxe", |
|---|
| 280 | + .newlink = rxe_newlink, |
|---|
| 281 | +}; |
|---|
| 341 | 282 | |
|---|
| 342 | 283 | static int __init rxe_module_init(void) |
|---|
| 343 | 284 | { |
|---|
| 344 | 285 | int err; |
|---|
| 345 | 286 | |
|---|
| 346 | | - /* initialize slab caches for managed objects */ |
|---|
| 347 | | - err = rxe_cache_init(); |
|---|
| 348 | | - if (err) { |
|---|
| 349 | | - pr_err("unable to init object pools\n"); |
|---|
| 350 | | - return err; |
|---|
| 351 | | - } |
|---|
| 352 | | - |
|---|
| 353 | 287 | err = rxe_net_init(); |
|---|
| 354 | 288 | if (err) |
|---|
| 355 | 289 | return err; |
|---|
| 356 | 290 | |
|---|
| 291 | + rdma_link_register(&rxe_link_ops); |
|---|
| 292 | + rxe_initialized = true; |
|---|
| 357 | 293 | pr_info("loaded\n"); |
|---|
| 358 | 294 | return 0; |
|---|
| 359 | 295 | } |
|---|
| 360 | 296 | |
|---|
| 361 | 297 | static void __exit rxe_module_exit(void) |
|---|
| 362 | 298 | { |
|---|
| 363 | | - rxe_remove_all(); |
|---|
| 299 | + rdma_link_unregister(&rxe_link_ops); |
|---|
| 300 | + ib_unregister_driver(RDMA_DRIVER_RXE); |
|---|
| 364 | 301 | rxe_net_exit(); |
|---|
| 365 | | - rxe_cache_exit(); |
|---|
| 366 | 302 | |
|---|
| 303 | + rxe_initialized = false; |
|---|
| 367 | 304 | pr_info("unloaded\n"); |
|---|
| 368 | 305 | } |
|---|
| 369 | 306 | |
|---|
| 370 | 307 | late_initcall(rxe_module_init); |
|---|
| 371 | 308 | module_exit(rxe_module_exit); |
|---|
| 309 | + |
|---|
| 310 | +MODULE_ALIAS_RDMA_LINK("rxe"); |
|---|