Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
0002 /*
0003  * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
0004  * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
0005  */
0006 
0007 #include <rdma/rdma_netlink.h>
0008 #include <net/addrconf.h>
0009 #include "rxe.h"
0010 #include "rxe_loc.h"
0011 
0012 MODULE_AUTHOR("Bob Pearson, Frank Zago, John Groves, Kamal Heib");
0013 MODULE_DESCRIPTION("Soft RDMA transport");
0014 MODULE_LICENSE("Dual BSD/GPL");
0015 
0016 /* free resources for a rxe device all objects created for this device must
0017  * have been destroyed
0018  */
0019 void rxe_dealloc(struct ib_device *ib_dev)
0020 {
0021     struct rxe_dev *rxe = container_of(ib_dev, struct rxe_dev, ib_dev);
0022 
0023     rxe_pool_cleanup(&rxe->uc_pool);
0024     rxe_pool_cleanup(&rxe->pd_pool);
0025     rxe_pool_cleanup(&rxe->ah_pool);
0026     rxe_pool_cleanup(&rxe->srq_pool);
0027     rxe_pool_cleanup(&rxe->qp_pool);
0028     rxe_pool_cleanup(&rxe->cq_pool);
0029     rxe_pool_cleanup(&rxe->mr_pool);
0030     rxe_pool_cleanup(&rxe->mw_pool);
0031 
0032     WARN_ON(!RB_EMPTY_ROOT(&rxe->mcg_tree));
0033 
0034     if (rxe->tfm)
0035         crypto_free_shash(rxe->tfm);
0036 }
0037 
0038 /* initialize rxe device parameters */
0039 static void rxe_init_device_param(struct rxe_dev *rxe)
0040 {
0041     rxe->max_inline_data            = RXE_MAX_INLINE_DATA;
0042 
0043     rxe->attr.vendor_id         = RXE_VENDOR_ID;
0044     rxe->attr.max_mr_size           = RXE_MAX_MR_SIZE;
0045     rxe->attr.page_size_cap         = RXE_PAGE_SIZE_CAP;
0046     rxe->attr.max_qp            = RXE_MAX_QP;
0047     rxe->attr.max_qp_wr         = RXE_MAX_QP_WR;
0048     rxe->attr.device_cap_flags      = RXE_DEVICE_CAP_FLAGS;
0049     rxe->attr.kernel_cap_flags      = IBK_ALLOW_USER_UNREG;
0050     rxe->attr.max_send_sge          = RXE_MAX_SGE;
0051     rxe->attr.max_recv_sge          = RXE_MAX_SGE;
0052     rxe->attr.max_sge_rd            = RXE_MAX_SGE_RD;
0053     rxe->attr.max_cq            = RXE_MAX_CQ;
0054     rxe->attr.max_cqe           = (1 << RXE_MAX_LOG_CQE) - 1;
0055     rxe->attr.max_mr            = RXE_MAX_MR;
0056     rxe->attr.max_mw            = RXE_MAX_MW;
0057     rxe->attr.max_pd            = RXE_MAX_PD;
0058     rxe->attr.max_qp_rd_atom        = RXE_MAX_QP_RD_ATOM;
0059     rxe->attr.max_res_rd_atom       = RXE_MAX_RES_RD_ATOM;
0060     rxe->attr.max_qp_init_rd_atom       = RXE_MAX_QP_INIT_RD_ATOM;
0061     rxe->attr.atomic_cap            = IB_ATOMIC_HCA;
0062     rxe->attr.max_mcast_grp         = RXE_MAX_MCAST_GRP;
0063     rxe->attr.max_mcast_qp_attach       = RXE_MAX_MCAST_QP_ATTACH;
0064     rxe->attr.max_total_mcast_qp_attach = RXE_MAX_TOT_MCAST_QP_ATTACH;
0065     rxe->attr.max_ah            = RXE_MAX_AH;
0066     rxe->attr.max_srq           = RXE_MAX_SRQ;
0067     rxe->attr.max_srq_wr            = RXE_MAX_SRQ_WR;
0068     rxe->attr.max_srq_sge           = RXE_MAX_SRQ_SGE;
0069     rxe->attr.max_fast_reg_page_list_len    = RXE_MAX_FMR_PAGE_LIST_LEN;
0070     rxe->attr.max_pkeys         = RXE_MAX_PKEYS;
0071     rxe->attr.local_ca_ack_delay        = RXE_LOCAL_CA_ACK_DELAY;
0072     addrconf_addr_eui48((unsigned char *)&rxe->attr.sys_image_guid,
0073             rxe->ndev->dev_addr);
0074 
0075     rxe->max_ucontext           = RXE_MAX_UCONTEXT;
0076 }
0077 
0078 /* initialize port attributes */
0079 static void rxe_init_port_param(struct rxe_port *port)
0080 {
0081     port->attr.state        = IB_PORT_DOWN;
0082     port->attr.max_mtu      = IB_MTU_4096;
0083     port->attr.active_mtu       = IB_MTU_256;
0084     port->attr.gid_tbl_len      = RXE_PORT_GID_TBL_LEN;
0085     port->attr.port_cap_flags   = RXE_PORT_PORT_CAP_FLAGS;
0086     port->attr.max_msg_sz       = RXE_PORT_MAX_MSG_SZ;
0087     port->attr.bad_pkey_cntr    = RXE_PORT_BAD_PKEY_CNTR;
0088     port->attr.qkey_viol_cntr   = RXE_PORT_QKEY_VIOL_CNTR;
0089     port->attr.pkey_tbl_len     = RXE_PORT_PKEY_TBL_LEN;
0090     port->attr.lid          = RXE_PORT_LID;
0091     port->attr.sm_lid       = RXE_PORT_SM_LID;
0092     port->attr.lmc          = RXE_PORT_LMC;
0093     port->attr.max_vl_num       = RXE_PORT_MAX_VL_NUM;
0094     port->attr.sm_sl        = RXE_PORT_SM_SL;
0095     port->attr.subnet_timeout   = RXE_PORT_SUBNET_TIMEOUT;
0096     port->attr.init_type_reply  = RXE_PORT_INIT_TYPE_REPLY;
0097     port->attr.active_width     = RXE_PORT_ACTIVE_WIDTH;
0098     port->attr.active_speed     = RXE_PORT_ACTIVE_SPEED;
0099     port->attr.phys_state       = RXE_PORT_PHYS_STATE;
0100     port->mtu_cap           = ib_mtu_enum_to_int(IB_MTU_256);
0101     port->subnet_prefix     = cpu_to_be64(RXE_PORT_SUBNET_PREFIX);
0102 }
0103 
0104 /* initialize port state, note IB convention that HCA ports are always
0105  * numbered from 1
0106  */
0107 static void rxe_init_ports(struct rxe_dev *rxe)
0108 {
0109     struct rxe_port *port = &rxe->port;
0110 
0111     rxe_init_port_param(port);
0112     addrconf_addr_eui48((unsigned char *)&port->port_guid,
0113                 rxe->ndev->dev_addr);
0114     spin_lock_init(&port->port_lock);
0115 }
0116 
0117 /* init pools of managed objects */
0118 static void rxe_init_pools(struct rxe_dev *rxe)
0119 {
0120     rxe_pool_init(rxe, &rxe->uc_pool, RXE_TYPE_UC);
0121     rxe_pool_init(rxe, &rxe->pd_pool, RXE_TYPE_PD);
0122     rxe_pool_init(rxe, &rxe->ah_pool, RXE_TYPE_AH);
0123     rxe_pool_init(rxe, &rxe->srq_pool, RXE_TYPE_SRQ);
0124     rxe_pool_init(rxe, &rxe->qp_pool, RXE_TYPE_QP);
0125     rxe_pool_init(rxe, &rxe->cq_pool, RXE_TYPE_CQ);
0126     rxe_pool_init(rxe, &rxe->mr_pool, RXE_TYPE_MR);
0127     rxe_pool_init(rxe, &rxe->mw_pool, RXE_TYPE_MW);
0128 }
0129 
0130 /* initialize rxe device state */
0131 static void rxe_init(struct rxe_dev *rxe)
0132 {
0133     /* init default device parameters */
0134     rxe_init_device_param(rxe);
0135 
0136     rxe_init_ports(rxe);
0137     rxe_init_pools(rxe);
0138 
0139     /* init pending mmap list */
0140     spin_lock_init(&rxe->mmap_offset_lock);
0141     spin_lock_init(&rxe->pending_lock);
0142     INIT_LIST_HEAD(&rxe->pending_mmaps);
0143 
0144     /* init multicast support */
0145     spin_lock_init(&rxe->mcg_lock);
0146     rxe->mcg_tree = RB_ROOT;
0147 
0148     mutex_init(&rxe->usdev_lock);
0149 }
0150 
0151 void rxe_set_mtu(struct rxe_dev *rxe, unsigned int ndev_mtu)
0152 {
0153     struct rxe_port *port = &rxe->port;
0154     enum ib_mtu mtu;
0155 
0156     mtu = eth_mtu_int_to_enum(ndev_mtu);
0157 
0158     /* Make sure that new MTU in range */
0159     mtu = mtu ? min_t(enum ib_mtu, mtu, IB_MTU_4096) : IB_MTU_256;
0160 
0161     port->attr.active_mtu = mtu;
0162     port->mtu_cap = ib_mtu_enum_to_int(mtu);
0163 }
0164 
0165 /* called by ifc layer to create new rxe device.
0166  * The caller should allocate memory for rxe by calling ib_alloc_device.
0167  */
0168 int rxe_add(struct rxe_dev *rxe, unsigned int mtu, const char *ibdev_name)
0169 {
0170     rxe_init(rxe);
0171     rxe_set_mtu(rxe, mtu);
0172 
0173     return rxe_register_device(rxe, ibdev_name);
0174 }
0175 
0176 static int rxe_newlink(const char *ibdev_name, struct net_device *ndev)
0177 {
0178     struct rxe_dev *exists;
0179     int err = 0;
0180 
0181     if (is_vlan_dev(ndev)) {
0182         pr_err("rxe creation allowed on top of a real device only\n");
0183         err = -EPERM;
0184         goto err;
0185     }
0186 
0187     exists = rxe_get_dev_from_net(ndev);
0188     if (exists) {
0189         ib_device_put(&exists->ib_dev);
0190         pr_err("already configured on %s\n", ndev->name);
0191         err = -EEXIST;
0192         goto err;
0193     }
0194 
0195     err = rxe_net_add(ibdev_name, ndev);
0196     if (err) {
0197         pr_err("failed to add %s\n", ndev->name);
0198         goto err;
0199     }
0200 err:
0201     return err;
0202 }
0203 
0204 static struct rdma_link_ops rxe_link_ops = {
0205     .type = "rxe",
0206     .newlink = rxe_newlink,
0207 };
0208 
0209 static int __init rxe_module_init(void)
0210 {
0211     int err;
0212 
0213     err = rxe_net_init();
0214     if (err)
0215         return err;
0216 
0217     rdma_link_register(&rxe_link_ops);
0218     pr_info("loaded\n");
0219     return 0;
0220 }
0221 
0222 static void __exit rxe_module_exit(void)
0223 {
0224     rdma_link_unregister(&rxe_link_ops);
0225     ib_unregister_driver(RDMA_DRIVER_RXE);
0226     rxe_net_exit();
0227 
0228     pr_info("unloaded\n");
0229 }
0230 
0231 late_initcall(rxe_module_init);
0232 module_exit(rxe_module_exit);
0233 
0234 MODULE_ALIAS_RDMA_LINK("rxe");