Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1 | /* |
Saeed Mahameed | 6cf0a15 | 2015-04-02 17:07:30 +0300 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | |
| 33 | #include <asm-generic/kmap_types.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/errno.h> |
| 37 | #include <linux/pci.h> |
| 38 | #include <linux/dma-mapping.h> |
| 39 | #include <linux/slab.h> |
| 40 | #include <linux/io-mapping.h> |
| 41 | #include <linux/sched.h> |
| 42 | #include <rdma/ib_user_verbs.h> |
| 43 | #include <rdma/ib_smi.h> |
| 44 | #include <rdma/ib_umem.h> |
| 45 | #include "user.h" |
| 46 | #include "mlx5_ib.h" |
| 47 | |
| 48 | #define DRIVER_NAME "mlx5_ib" |
Amir Vadai | 169a1d8 | 2014-02-19 17:47:31 +0200 | [diff] [blame] | 49 | #define DRIVER_VERSION "2.2-1" |
| 50 | #define DRIVER_RELDATE "Feb 2014" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 51 | |
| 52 | MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); |
| 53 | MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); |
| 54 | MODULE_LICENSE("Dual BSD/GPL"); |
| 55 | MODULE_VERSION(DRIVER_VERSION); |
| 56 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 57 | static int deprecated_prof_sel = 2; |
| 58 | module_param_named(prof_sel, deprecated_prof_sel, int, 0444); |
| 59 | MODULE_PARM_DESC(prof_sel, "profile selector. Deprecated here. Moved to module mlx5_core"); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 60 | |
| 61 | static char mlx5_version[] = |
| 62 | DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
| 63 | DRIVER_VERSION " (" DRIVER_RELDATE ")\n"; |
| 64 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 65 | static int mlx5_ib_query_device(struct ib_device *ibdev, |
| 66 | struct ib_device_attr *props) |
| 67 | { |
| 68 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 69 | struct ib_smp *in_mad = NULL; |
| 70 | struct ib_smp *out_mad = NULL; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 71 | struct mlx5_general_caps *gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 72 | int err = -ENOMEM; |
| 73 | int max_rq_sg; |
| 74 | int max_sq_sg; |
| 75 | u64 flags; |
| 76 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 77 | gen = &dev->mdev->caps.gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 78 | in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL); |
| 79 | out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL); |
| 80 | if (!in_mad || !out_mad) |
| 81 | goto out; |
| 82 | |
| 83 | init_query_mad(in_mad); |
| 84 | in_mad->attr_id = IB_SMP_ATTR_NODE_INFO; |
| 85 | |
| 86 | err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, 1, NULL, NULL, in_mad, out_mad); |
| 87 | if (err) |
| 88 | goto out; |
| 89 | |
| 90 | memset(props, 0, sizeof(*props)); |
| 91 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 92 | props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) | |
| 93 | (fw_rev_min(dev->mdev) << 16) | |
| 94 | fw_rev_sub(dev->mdev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 95 | props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | |
| 96 | IB_DEVICE_PORT_ACTIVE_EVENT | |
| 97 | IB_DEVICE_SYS_IMAGE_GUID | |
Eli Cohen | 1a4c3a3 | 2014-02-06 17:41:25 +0200 | [diff] [blame] | 98 | IB_DEVICE_RC_RNR_NAK_GEN; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 99 | flags = gen->flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 100 | if (flags & MLX5_DEV_CAP_FLAG_BAD_PKEY_CNTR) |
| 101 | props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; |
| 102 | if (flags & MLX5_DEV_CAP_FLAG_BAD_QKEY_CNTR) |
| 103 | props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR; |
| 104 | if (flags & MLX5_DEV_CAP_FLAG_APM) |
| 105 | props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG; |
| 106 | props->device_cap_flags |= IB_DEVICE_LOCAL_DMA_LKEY; |
| 107 | if (flags & MLX5_DEV_CAP_FLAG_XRC) |
| 108 | props->device_cap_flags |= IB_DEVICE_XRC; |
| 109 | props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
Sagi Grimberg | 2dea909 | 2014-02-23 14:19:13 +0200 | [diff] [blame] | 110 | if (flags & MLX5_DEV_CAP_FLAG_SIG_HAND_OVER) { |
| 111 | props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER; |
| 112 | /* At this stage no support for signature handover */ |
| 113 | props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 | |
| 114 | IB_PROT_T10DIF_TYPE_2 | |
| 115 | IB_PROT_T10DIF_TYPE_3; |
| 116 | props->sig_guard_cap = IB_GUARD_T10DIF_CRC | |
| 117 | IB_GUARD_T10DIF_CSUM; |
| 118 | } |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 119 | if (flags & MLX5_DEV_CAP_FLAG_BLOCK_MCAST) |
| 120 | props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 121 | |
| 122 | props->vendor_id = be32_to_cpup((__be32 *)(out_mad->data + 36)) & |
| 123 | 0xffffff; |
| 124 | props->vendor_part_id = be16_to_cpup((__be16 *)(out_mad->data + 30)); |
| 125 | props->hw_ver = be32_to_cpup((__be32 *)(out_mad->data + 32)); |
| 126 | memcpy(&props->sys_image_guid, out_mad->data + 4, 8); |
| 127 | |
| 128 | props->max_mr_size = ~0ull; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 129 | props->page_size_cap = gen->min_page_sz; |
| 130 | props->max_qp = 1 << gen->log_max_qp; |
| 131 | props->max_qp_wr = gen->max_wqes; |
| 132 | max_rq_sg = gen->max_rq_desc_sz / sizeof(struct mlx5_wqe_data_seg); |
| 133 | max_sq_sg = (gen->max_sq_desc_sz - sizeof(struct mlx5_wqe_ctrl_seg)) / |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 134 | sizeof(struct mlx5_wqe_data_seg); |
| 135 | props->max_sge = min(max_rq_sg, max_sq_sg); |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 136 | props->max_cq = 1 << gen->log_max_cq; |
| 137 | props->max_cqe = gen->max_cqes - 1; |
| 138 | props->max_mr = 1 << gen->log_max_mkey; |
| 139 | props->max_pd = 1 << gen->log_max_pd; |
| 140 | props->max_qp_rd_atom = 1 << gen->log_max_ra_req_qp; |
| 141 | props->max_qp_init_rd_atom = 1 << gen->log_max_ra_res_qp; |
| 142 | props->max_srq = 1 << gen->log_max_srq; |
| 143 | props->max_srq_wr = gen->max_srq_wqes - 1; |
| 144 | props->local_ca_ack_delay = gen->local_ca_ack_delay; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 145 | props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 146 | props->max_srq_sge = max_rq_sg - 1; |
| 147 | props->max_fast_reg_page_list_len = (unsigned int)-1; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 148 | props->local_ca_ack_delay = gen->local_ca_ack_delay; |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 149 | props->atomic_cap = IB_ATOMIC_NONE; |
| 150 | props->masked_atomic_cap = IB_ATOMIC_NONE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 151 | props->max_pkeys = be16_to_cpup((__be16 *)(out_mad->data + 28)); |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 152 | props->max_mcast_grp = 1 << gen->log_max_mcg; |
| 153 | props->max_mcast_qp_attach = gen->max_qp_mcg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 154 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 155 | props->max_mcast_grp; |
| 156 | props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */ |
| 157 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 158 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 159 | if (dev->mdev->caps.gen.flags & MLX5_DEV_CAP_FLAG_ON_DMND_PG) |
| 160 | props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
| 161 | props->odp_caps = dev->odp_caps; |
| 162 | #endif |
| 163 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 164 | out: |
| 165 | kfree(in_mad); |
| 166 | kfree(out_mad); |
| 167 | |
| 168 | return err; |
| 169 | } |
| 170 | |
| 171 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 172 | struct ib_port_attr *props) |
| 173 | { |
| 174 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 175 | struct ib_smp *in_mad = NULL; |
| 176 | struct ib_smp *out_mad = NULL; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 177 | struct mlx5_general_caps *gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 178 | int ext_active_speed; |
| 179 | int err = -ENOMEM; |
| 180 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 181 | gen = &dev->mdev->caps.gen; |
| 182 | if (port < 1 || port > gen->num_ports) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 183 | mlx5_ib_warn(dev, "invalid port number %d\n", port); |
| 184 | return -EINVAL; |
| 185 | } |
| 186 | |
| 187 | in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL); |
| 188 | out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL); |
| 189 | if (!in_mad || !out_mad) |
| 190 | goto out; |
| 191 | |
| 192 | memset(props, 0, sizeof(*props)); |
| 193 | |
| 194 | init_query_mad(in_mad); |
| 195 | in_mad->attr_id = IB_SMP_ATTR_PORT_INFO; |
| 196 | in_mad->attr_mod = cpu_to_be32(port); |
| 197 | |
| 198 | err = mlx5_MAD_IFC(dev, 1, 1, port, NULL, NULL, in_mad, out_mad); |
| 199 | if (err) { |
| 200 | mlx5_ib_warn(dev, "err %d\n", err); |
| 201 | goto out; |
| 202 | } |
| 203 | |
| 204 | |
| 205 | props->lid = be16_to_cpup((__be16 *)(out_mad->data + 16)); |
| 206 | props->lmc = out_mad->data[34] & 0x7; |
| 207 | props->sm_lid = be16_to_cpup((__be16 *)(out_mad->data + 18)); |
| 208 | props->sm_sl = out_mad->data[36] & 0xf; |
| 209 | props->state = out_mad->data[32] & 0xf; |
| 210 | props->phys_state = out_mad->data[33] >> 4; |
| 211 | props->port_cap_flags = be32_to_cpup((__be32 *)(out_mad->data + 20)); |
| 212 | props->gid_tbl_len = out_mad->data[50]; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 213 | props->max_msg_sz = 1 << gen->log_max_msg; |
| 214 | props->pkey_tbl_len = gen->port[port - 1].pkey_table_len; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 215 | props->bad_pkey_cntr = be16_to_cpup((__be16 *)(out_mad->data + 46)); |
| 216 | props->qkey_viol_cntr = be16_to_cpup((__be16 *)(out_mad->data + 48)); |
| 217 | props->active_width = out_mad->data[31] & 0xf; |
| 218 | props->active_speed = out_mad->data[35] >> 4; |
| 219 | props->max_mtu = out_mad->data[41] & 0xf; |
| 220 | props->active_mtu = out_mad->data[36] >> 4; |
| 221 | props->subnet_timeout = out_mad->data[51] & 0x1f; |
| 222 | props->max_vl_num = out_mad->data[37] >> 4; |
| 223 | props->init_type_reply = out_mad->data[41] >> 4; |
| 224 | |
| 225 | /* Check if extended speeds (EDR/FDR/...) are supported */ |
| 226 | if (props->port_cap_flags & IB_PORT_EXTENDED_SPEEDS_SUP) { |
| 227 | ext_active_speed = out_mad->data[62] >> 4; |
| 228 | |
| 229 | switch (ext_active_speed) { |
| 230 | case 1: |
| 231 | props->active_speed = 16; /* FDR */ |
| 232 | break; |
| 233 | case 2: |
| 234 | props->active_speed = 32; /* EDR */ |
| 235 | break; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /* If reported active speed is QDR, check if is FDR-10 */ |
| 240 | if (props->active_speed == 4) { |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 241 | if (gen->ext_port_cap[port - 1] & |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 242 | MLX_EXT_PORT_CAP_FLAG_EXTENDED_PORT_INFO) { |
| 243 | init_query_mad(in_mad); |
| 244 | in_mad->attr_id = MLX5_ATTR_EXTENDED_PORT_INFO; |
| 245 | in_mad->attr_mod = cpu_to_be32(port); |
| 246 | |
| 247 | err = mlx5_MAD_IFC(dev, 1, 1, port, |
| 248 | NULL, NULL, in_mad, out_mad); |
| 249 | if (err) |
| 250 | goto out; |
| 251 | |
| 252 | /* Checking LinkSpeedActive for FDR-10 */ |
| 253 | if (out_mad->data[15] & 0x1) |
| 254 | props->active_speed = 8; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | out: |
| 259 | kfree(in_mad); |
| 260 | kfree(out_mad); |
| 261 | |
| 262 | return err; |
| 263 | } |
| 264 | |
Michael Wang | 6b90a6d | 2015-05-05 14:50:18 +0200 | [diff] [blame] | 265 | static enum rdma_protocol_type |
| 266 | mlx5_ib_query_protocol(struct ib_device *device, u8 port_num) |
| 267 | { |
| 268 | return RDMA_PROTOCOL_IB; |
| 269 | } |
| 270 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 271 | static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 272 | union ib_gid *gid) |
| 273 | { |
| 274 | struct ib_smp *in_mad = NULL; |
| 275 | struct ib_smp *out_mad = NULL; |
| 276 | int err = -ENOMEM; |
| 277 | |
| 278 | in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL); |
| 279 | out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL); |
| 280 | if (!in_mad || !out_mad) |
| 281 | goto out; |
| 282 | |
| 283 | init_query_mad(in_mad); |
| 284 | in_mad->attr_id = IB_SMP_ATTR_PORT_INFO; |
| 285 | in_mad->attr_mod = cpu_to_be32(port); |
| 286 | |
| 287 | err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad); |
| 288 | if (err) |
| 289 | goto out; |
| 290 | |
| 291 | memcpy(gid->raw, out_mad->data + 8, 8); |
| 292 | |
| 293 | init_query_mad(in_mad); |
| 294 | in_mad->attr_id = IB_SMP_ATTR_GUID_INFO; |
| 295 | in_mad->attr_mod = cpu_to_be32(index / 8); |
| 296 | |
| 297 | err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad); |
| 298 | if (err) |
| 299 | goto out; |
| 300 | |
| 301 | memcpy(gid->raw + 8, out_mad->data + (index % 8) * 8, 8); |
| 302 | |
| 303 | out: |
| 304 | kfree(in_mad); |
| 305 | kfree(out_mad); |
| 306 | return err; |
| 307 | } |
| 308 | |
| 309 | static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 310 | u16 *pkey) |
| 311 | { |
| 312 | struct ib_smp *in_mad = NULL; |
| 313 | struct ib_smp *out_mad = NULL; |
| 314 | int err = -ENOMEM; |
| 315 | |
| 316 | in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL); |
| 317 | out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL); |
| 318 | if (!in_mad || !out_mad) |
| 319 | goto out; |
| 320 | |
| 321 | init_query_mad(in_mad); |
| 322 | in_mad->attr_id = IB_SMP_ATTR_PKEY_TABLE; |
| 323 | in_mad->attr_mod = cpu_to_be32(index / 32); |
| 324 | |
| 325 | err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad); |
| 326 | if (err) |
| 327 | goto out; |
| 328 | |
| 329 | *pkey = be16_to_cpu(((__be16 *)out_mad->data)[index % 32]); |
| 330 | |
| 331 | out: |
| 332 | kfree(in_mad); |
| 333 | kfree(out_mad); |
| 334 | return err; |
| 335 | } |
| 336 | |
| 337 | struct mlx5_reg_node_desc { |
| 338 | u8 desc[64]; |
| 339 | }; |
| 340 | |
| 341 | static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask, |
| 342 | struct ib_device_modify *props) |
| 343 | { |
| 344 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 345 | struct mlx5_reg_node_desc in; |
| 346 | struct mlx5_reg_node_desc out; |
| 347 | int err; |
| 348 | |
| 349 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 350 | return -EOPNOTSUPP; |
| 351 | |
| 352 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 353 | return 0; |
| 354 | |
| 355 | /* |
| 356 | * If possible, pass node desc to FW, so it can generate |
| 357 | * a 144 trap. If cmd fails, just ignore. |
| 358 | */ |
| 359 | memcpy(&in, props->node_desc, 64); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 360 | err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 361 | sizeof(out), MLX5_REG_NODE_DESC, 0, 1); |
| 362 | if (err) |
| 363 | return err; |
| 364 | |
| 365 | memcpy(ibdev->node_desc, props->node_desc, 64); |
| 366 | |
| 367 | return err; |
| 368 | } |
| 369 | |
| 370 | static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 371 | struct ib_port_modify *props) |
| 372 | { |
| 373 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 374 | struct ib_port_attr attr; |
| 375 | u32 tmp; |
| 376 | int err; |
| 377 | |
| 378 | mutex_lock(&dev->cap_mask_mutex); |
| 379 | |
| 380 | err = mlx5_ib_query_port(ibdev, port, &attr); |
| 381 | if (err) |
| 382 | goto out; |
| 383 | |
| 384 | tmp = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 385 | ~props->clr_port_cap_mask; |
| 386 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 387 | err = mlx5_set_port_caps(dev->mdev, port, tmp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 388 | |
| 389 | out: |
| 390 | mutex_unlock(&dev->cap_mask_mutex); |
| 391 | return err; |
| 392 | } |
| 393 | |
| 394 | static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev, |
| 395 | struct ib_udata *udata) |
| 396 | { |
| 397 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 398 | struct mlx5_ib_alloc_ucontext_req_v2 req; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 399 | struct mlx5_ib_alloc_ucontext_resp resp; |
| 400 | struct mlx5_ib_ucontext *context; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 401 | struct mlx5_general_caps *gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 402 | struct mlx5_uuar_info *uuari; |
| 403 | struct mlx5_uar *uars; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 404 | int gross_uuars; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 405 | int num_uars; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 406 | int ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 407 | int uuarn; |
| 408 | int err; |
| 409 | int i; |
Jack Morgenstein | f241e74 | 2014-07-28 23:30:23 +0300 | [diff] [blame] | 410 | size_t reqlen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 411 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 412 | gen = &dev->mdev->caps.gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 413 | if (!dev->ib_active) |
| 414 | return ERR_PTR(-EAGAIN); |
| 415 | |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 416 | memset(&req, 0, sizeof(req)); |
| 417 | reqlen = udata->inlen - sizeof(struct ib_uverbs_cmd_hdr); |
| 418 | if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
| 419 | ver = 0; |
| 420 | else if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req_v2)) |
| 421 | ver = 2; |
| 422 | else |
| 423 | return ERR_PTR(-EINVAL); |
| 424 | |
| 425 | err = ib_copy_from_udata(&req, udata, reqlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 426 | if (err) |
| 427 | return ERR_PTR(err); |
| 428 | |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 429 | if (req.flags || req.reserved) |
| 430 | return ERR_PTR(-EINVAL); |
| 431 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 432 | if (req.total_num_uuars > MLX5_MAX_UUARS) |
| 433 | return ERR_PTR(-ENOMEM); |
| 434 | |
| 435 | if (req.total_num_uuars == 0) |
| 436 | return ERR_PTR(-EINVAL); |
| 437 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 438 | req.total_num_uuars = ALIGN(req.total_num_uuars, |
| 439 | MLX5_NON_FP_BF_REGS_PER_PAGE); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 440 | if (req.num_low_latency_uuars > req.total_num_uuars - 1) |
| 441 | return ERR_PTR(-EINVAL); |
| 442 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 443 | num_uars = req.total_num_uuars / MLX5_NON_FP_BF_REGS_PER_PAGE; |
| 444 | gross_uuars = num_uars * MLX5_BF_REGS_PER_PAGE; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 445 | resp.qp_tab_size = 1 << gen->log_max_qp; |
| 446 | resp.bf_reg_size = gen->bf_reg_size; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 447 | resp.cache_line_size = L1_CACHE_BYTES; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 448 | resp.max_sq_desc_sz = gen->max_sq_desc_sz; |
| 449 | resp.max_rq_desc_sz = gen->max_rq_desc_sz; |
| 450 | resp.max_send_wqebb = gen->max_wqes; |
| 451 | resp.max_recv_wr = gen->max_wqes; |
| 452 | resp.max_srq_recv_wr = gen->max_srq_wqes; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 453 | |
| 454 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 455 | if (!context) |
| 456 | return ERR_PTR(-ENOMEM); |
| 457 | |
| 458 | uuari = &context->uuari; |
| 459 | mutex_init(&uuari->lock); |
| 460 | uars = kcalloc(num_uars, sizeof(*uars), GFP_KERNEL); |
| 461 | if (!uars) { |
| 462 | err = -ENOMEM; |
| 463 | goto out_ctx; |
| 464 | } |
| 465 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 466 | uuari->bitmap = kcalloc(BITS_TO_LONGS(gross_uuars), |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 467 | sizeof(*uuari->bitmap), |
| 468 | GFP_KERNEL); |
| 469 | if (!uuari->bitmap) { |
| 470 | err = -ENOMEM; |
| 471 | goto out_uar_ctx; |
| 472 | } |
| 473 | /* |
| 474 | * clear all fast path uuars |
| 475 | */ |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 476 | for (i = 0; i < gross_uuars; i++) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 477 | uuarn = i & 3; |
| 478 | if (uuarn == 2 || uuarn == 3) |
| 479 | set_bit(i, uuari->bitmap); |
| 480 | } |
| 481 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 482 | uuari->count = kcalloc(gross_uuars, sizeof(*uuari->count), GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 483 | if (!uuari->count) { |
| 484 | err = -ENOMEM; |
| 485 | goto out_bitmap; |
| 486 | } |
| 487 | |
| 488 | for (i = 0; i < num_uars; i++) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 489 | err = mlx5_cmd_alloc_uar(dev->mdev, &uars[i].index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 490 | if (err) |
| 491 | goto out_count; |
| 492 | } |
| 493 | |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 494 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 495 | context->ibucontext.invalidate_range = &mlx5_ib_invalidate_range; |
| 496 | #endif |
| 497 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 498 | INIT_LIST_HEAD(&context->db_page_list); |
| 499 | mutex_init(&context->db_page_mutex); |
| 500 | |
| 501 | resp.tot_uuars = req.total_num_uuars; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 502 | resp.num_ports = gen->num_ports; |
Dan Carpenter | 92b0ca7 | 2013-07-25 20:04:36 +0300 | [diff] [blame] | 503 | err = ib_copy_to_udata(udata, &resp, |
| 504 | sizeof(resp) - sizeof(resp.reserved)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 505 | if (err) |
| 506 | goto out_uars; |
| 507 | |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 508 | uuari->ver = ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 509 | uuari->num_low_latency_uuars = req.num_low_latency_uuars; |
| 510 | uuari->uars = uars; |
| 511 | uuari->num_uars = num_uars; |
| 512 | return &context->ibucontext; |
| 513 | |
| 514 | out_uars: |
| 515 | for (i--; i >= 0; i--) |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 516 | mlx5_cmd_free_uar(dev->mdev, uars[i].index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 517 | out_count: |
| 518 | kfree(uuari->count); |
| 519 | |
| 520 | out_bitmap: |
| 521 | kfree(uuari->bitmap); |
| 522 | |
| 523 | out_uar_ctx: |
| 524 | kfree(uars); |
| 525 | |
| 526 | out_ctx: |
| 527 | kfree(context); |
| 528 | return ERR_PTR(err); |
| 529 | } |
| 530 | |
| 531 | static int mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
| 532 | { |
| 533 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 534 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
| 535 | struct mlx5_uuar_info *uuari = &context->uuari; |
| 536 | int i; |
| 537 | |
| 538 | for (i = 0; i < uuari->num_uars; i++) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 539 | if (mlx5_cmd_free_uar(dev->mdev, uuari->uars[i].index)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 540 | mlx5_ib_warn(dev, "failed to free UAR 0x%x\n", uuari->uars[i].index); |
| 541 | } |
| 542 | |
| 543 | kfree(uuari->count); |
| 544 | kfree(uuari->bitmap); |
| 545 | kfree(uuari->uars); |
| 546 | kfree(context); |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, int index) |
| 552 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 553 | return (pci_resource_start(dev->mdev->pdev, 0) >> PAGE_SHIFT) + index; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static int get_command(unsigned long offset) |
| 557 | { |
| 558 | return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK; |
| 559 | } |
| 560 | |
| 561 | static int get_arg(unsigned long offset) |
| 562 | { |
| 563 | return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1); |
| 564 | } |
| 565 | |
| 566 | static int get_index(unsigned long offset) |
| 567 | { |
| 568 | return get_arg(offset); |
| 569 | } |
| 570 | |
| 571 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
| 572 | { |
| 573 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 574 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
| 575 | struct mlx5_uuar_info *uuari = &context->uuari; |
| 576 | unsigned long command; |
| 577 | unsigned long idx; |
| 578 | phys_addr_t pfn; |
| 579 | |
| 580 | command = get_command(vma->vm_pgoff); |
| 581 | switch (command) { |
| 582 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 583 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 584 | return -EINVAL; |
| 585 | |
| 586 | idx = get_index(vma->vm_pgoff); |
Eli Cohen | 1c3ce90 | 2014-09-14 16:47:53 +0300 | [diff] [blame] | 587 | if (idx >= uuari->num_uars) |
| 588 | return -EINVAL; |
| 589 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 590 | pfn = uar_index2pfn(dev, uuari->uars[idx].index); |
| 591 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn 0x%llx\n", idx, |
| 592 | (unsigned long long)pfn); |
| 593 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 594 | vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); |
| 595 | if (io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 596 | PAGE_SIZE, vma->vm_page_prot)) |
| 597 | return -EAGAIN; |
| 598 | |
| 599 | mlx5_ib_dbg(dev, "mapped WC at 0x%lx, PA 0x%llx\n", |
| 600 | vma->vm_start, |
| 601 | (unsigned long long)pfn << PAGE_SHIFT); |
| 602 | break; |
| 603 | |
| 604 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
| 605 | return -ENOSYS; |
| 606 | |
| 607 | default: |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | static int alloc_pa_mkey(struct mlx5_ib_dev *dev, u32 *key, u32 pdn) |
| 615 | { |
| 616 | struct mlx5_create_mkey_mbox_in *in; |
| 617 | struct mlx5_mkey_seg *seg; |
| 618 | struct mlx5_core_mr mr; |
| 619 | int err; |
| 620 | |
| 621 | in = kzalloc(sizeof(*in), GFP_KERNEL); |
| 622 | if (!in) |
| 623 | return -ENOMEM; |
| 624 | |
| 625 | seg = &in->seg; |
| 626 | seg->flags = MLX5_PERM_LOCAL_READ | MLX5_ACCESS_MODE_PA; |
| 627 | seg->flags_pd = cpu_to_be32(pdn | MLX5_MKEY_LEN64); |
| 628 | seg->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8); |
| 629 | seg->start_addr = 0; |
| 630 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 631 | err = mlx5_core_create_mkey(dev->mdev, &mr, in, sizeof(*in), |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 632 | NULL, NULL, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 633 | if (err) { |
| 634 | mlx5_ib_warn(dev, "failed to create mkey, %d\n", err); |
| 635 | goto err_in; |
| 636 | } |
| 637 | |
| 638 | kfree(in); |
| 639 | *key = mr.key; |
| 640 | |
| 641 | return 0; |
| 642 | |
| 643 | err_in: |
| 644 | kfree(in); |
| 645 | |
| 646 | return err; |
| 647 | } |
| 648 | |
| 649 | static void free_pa_mkey(struct mlx5_ib_dev *dev, u32 key) |
| 650 | { |
| 651 | struct mlx5_core_mr mr; |
| 652 | int err; |
| 653 | |
| 654 | memset(&mr, 0, sizeof(mr)); |
| 655 | mr.key = key; |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 656 | err = mlx5_core_destroy_mkey(dev->mdev, &mr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 657 | if (err) |
| 658 | mlx5_ib_warn(dev, "failed to destroy mkey 0x%x\n", key); |
| 659 | } |
| 660 | |
| 661 | static struct ib_pd *mlx5_ib_alloc_pd(struct ib_device *ibdev, |
| 662 | struct ib_ucontext *context, |
| 663 | struct ib_udata *udata) |
| 664 | { |
| 665 | struct mlx5_ib_alloc_pd_resp resp; |
| 666 | struct mlx5_ib_pd *pd; |
| 667 | int err; |
| 668 | |
| 669 | pd = kmalloc(sizeof(*pd), GFP_KERNEL); |
| 670 | if (!pd) |
| 671 | return ERR_PTR(-ENOMEM); |
| 672 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 673 | err = mlx5_core_alloc_pd(to_mdev(ibdev)->mdev, &pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 674 | if (err) { |
| 675 | kfree(pd); |
| 676 | return ERR_PTR(err); |
| 677 | } |
| 678 | |
| 679 | if (context) { |
| 680 | resp.pdn = pd->pdn; |
| 681 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 682 | mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 683 | kfree(pd); |
| 684 | return ERR_PTR(-EFAULT); |
| 685 | } |
| 686 | } else { |
| 687 | err = alloc_pa_mkey(to_mdev(ibdev), &pd->pa_lkey, pd->pdn); |
| 688 | if (err) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 689 | mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 690 | kfree(pd); |
| 691 | return ERR_PTR(err); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | return &pd->ibpd; |
| 696 | } |
| 697 | |
| 698 | static int mlx5_ib_dealloc_pd(struct ib_pd *pd) |
| 699 | { |
| 700 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 701 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
| 702 | |
| 703 | if (!pd->uobject) |
| 704 | free_pa_mkey(mdev, mpd->pa_lkey); |
| 705 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 706 | mlx5_core_dealloc_pd(mdev->mdev, mpd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 707 | kfree(mpd); |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 713 | { |
| 714 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 715 | int err; |
| 716 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 717 | err = mlx5_core_attach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 718 | if (err) |
| 719 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
| 720 | ibqp->qp_num, gid->raw); |
| 721 | |
| 722 | return err; |
| 723 | } |
| 724 | |
| 725 | static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 726 | { |
| 727 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 728 | int err; |
| 729 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 730 | err = mlx5_core_detach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 731 | if (err) |
| 732 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
| 733 | ibqp->qp_num, gid->raw); |
| 734 | |
| 735 | return err; |
| 736 | } |
| 737 | |
| 738 | static int init_node_data(struct mlx5_ib_dev *dev) |
| 739 | { |
| 740 | struct ib_smp *in_mad = NULL; |
| 741 | struct ib_smp *out_mad = NULL; |
| 742 | int err = -ENOMEM; |
| 743 | |
| 744 | in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL); |
| 745 | out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL); |
| 746 | if (!in_mad || !out_mad) |
| 747 | goto out; |
| 748 | |
| 749 | init_query_mad(in_mad); |
| 750 | in_mad->attr_id = IB_SMP_ATTR_NODE_DESC; |
| 751 | |
| 752 | err = mlx5_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad); |
| 753 | if (err) |
| 754 | goto out; |
| 755 | |
| 756 | memcpy(dev->ib_dev.node_desc, out_mad->data, 64); |
| 757 | |
| 758 | in_mad->attr_id = IB_SMP_ATTR_NODE_INFO; |
| 759 | |
| 760 | err = mlx5_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad); |
| 761 | if (err) |
| 762 | goto out; |
| 763 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 764 | dev->mdev->rev_id = be32_to_cpup((__be32 *)(out_mad->data + 32)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 765 | memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8); |
| 766 | |
| 767 | out: |
| 768 | kfree(in_mad); |
| 769 | kfree(out_mad); |
| 770 | return err; |
| 771 | } |
| 772 | |
| 773 | static ssize_t show_fw_pages(struct device *device, struct device_attribute *attr, |
| 774 | char *buf) |
| 775 | { |
| 776 | struct mlx5_ib_dev *dev = |
| 777 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 778 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 779 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | static ssize_t show_reg_pages(struct device *device, |
| 783 | struct device_attribute *attr, char *buf) |
| 784 | { |
| 785 | struct mlx5_ib_dev *dev = |
| 786 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 787 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 788 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | static ssize_t show_hca(struct device *device, struct device_attribute *attr, |
| 792 | char *buf) |
| 793 | { |
| 794 | struct mlx5_ib_dev *dev = |
| 795 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 796 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr, |
| 800 | char *buf) |
| 801 | { |
| 802 | struct mlx5_ib_dev *dev = |
| 803 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 804 | return sprintf(buf, "%d.%d.%d\n", fw_rev_maj(dev->mdev), |
| 805 | fw_rev_min(dev->mdev), fw_rev_sub(dev->mdev)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
| 809 | char *buf) |
| 810 | { |
| 811 | struct mlx5_ib_dev *dev = |
| 812 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 813 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static ssize_t show_board(struct device *device, struct device_attribute *attr, |
| 817 | char *buf) |
| 818 | { |
| 819 | struct mlx5_ib_dev *dev = |
| 820 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 821 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 822 | dev->mdev->board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
| 826 | static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL); |
| 827 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 828 | static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
| 829 | static DEVICE_ATTR(fw_pages, S_IRUGO, show_fw_pages, NULL); |
| 830 | static DEVICE_ATTR(reg_pages, S_IRUGO, show_reg_pages, NULL); |
| 831 | |
| 832 | static struct device_attribute *mlx5_class_attributes[] = { |
| 833 | &dev_attr_hw_rev, |
| 834 | &dev_attr_fw_ver, |
| 835 | &dev_attr_hca_type, |
| 836 | &dev_attr_board_id, |
| 837 | &dev_attr_fw_pages, |
| 838 | &dev_attr_reg_pages, |
| 839 | }; |
| 840 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 841 | static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context, |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 842 | enum mlx5_dev_event event, unsigned long param) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 843 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 844 | struct mlx5_ib_dev *ibdev = (struct mlx5_ib_dev *)context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 845 | struct ib_event ibev; |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 846 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 847 | u8 port = 0; |
| 848 | |
| 849 | switch (event) { |
| 850 | case MLX5_DEV_EVENT_SYS_ERROR: |
| 851 | ibdev->ib_active = false; |
| 852 | ibev.event = IB_EVENT_DEVICE_FATAL; |
| 853 | break; |
| 854 | |
| 855 | case MLX5_DEV_EVENT_PORT_UP: |
| 856 | ibev.event = IB_EVENT_PORT_ACTIVE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 857 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 858 | break; |
| 859 | |
| 860 | case MLX5_DEV_EVENT_PORT_DOWN: |
| 861 | ibev.event = IB_EVENT_PORT_ERR; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 862 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 863 | break; |
| 864 | |
| 865 | case MLX5_DEV_EVENT_PORT_INITIALIZED: |
| 866 | /* not used by ULPs */ |
| 867 | return; |
| 868 | |
| 869 | case MLX5_DEV_EVENT_LID_CHANGE: |
| 870 | ibev.event = IB_EVENT_LID_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 871 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 872 | break; |
| 873 | |
| 874 | case MLX5_DEV_EVENT_PKEY_CHANGE: |
| 875 | ibev.event = IB_EVENT_PKEY_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 876 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 877 | break; |
| 878 | |
| 879 | case MLX5_DEV_EVENT_GUID_CHANGE: |
| 880 | ibev.event = IB_EVENT_GID_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 881 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 882 | break; |
| 883 | |
| 884 | case MLX5_DEV_EVENT_CLIENT_REREG: |
| 885 | ibev.event = IB_EVENT_CLIENT_REREGISTER; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 886 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 887 | break; |
| 888 | } |
| 889 | |
| 890 | ibev.device = &ibdev->ib_dev; |
| 891 | ibev.element.port_num = port; |
| 892 | |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 893 | if (port < 1 || port > ibdev->num_ports) { |
| 894 | mlx5_ib_warn(ibdev, "warning: event on port %d\n", port); |
| 895 | return; |
| 896 | } |
| 897 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 898 | if (ibdev->ib_active) |
| 899 | ib_dispatch_event(&ibev); |
| 900 | } |
| 901 | |
| 902 | static void get_ext_port_caps(struct mlx5_ib_dev *dev) |
| 903 | { |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 904 | struct mlx5_general_caps *gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 905 | int port; |
| 906 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 907 | gen = &dev->mdev->caps.gen; |
| 908 | for (port = 1; port <= gen->num_ports; port++) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 909 | mlx5_query_ext_port_caps(dev, port); |
| 910 | } |
| 911 | |
| 912 | static int get_port_caps(struct mlx5_ib_dev *dev) |
| 913 | { |
| 914 | struct ib_device_attr *dprops = NULL; |
| 915 | struct ib_port_attr *pprops = NULL; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 916 | struct mlx5_general_caps *gen; |
Dan Carpenter | f614fc1 | 2015-01-12 11:56:58 +0300 | [diff] [blame] | 917 | int err = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 918 | int port; |
| 919 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 920 | gen = &dev->mdev->caps.gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 921 | pprops = kmalloc(sizeof(*pprops), GFP_KERNEL); |
| 922 | if (!pprops) |
| 923 | goto out; |
| 924 | |
| 925 | dprops = kmalloc(sizeof(*dprops), GFP_KERNEL); |
| 926 | if (!dprops) |
| 927 | goto out; |
| 928 | |
| 929 | err = mlx5_ib_query_device(&dev->ib_dev, dprops); |
| 930 | if (err) { |
| 931 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
| 932 | goto out; |
| 933 | } |
| 934 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 935 | for (port = 1; port <= gen->num_ports; port++) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 936 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
| 937 | if (err) { |
| 938 | mlx5_ib_warn(dev, "query_port %d failed %d\n", port, err); |
| 939 | break; |
| 940 | } |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 941 | gen->port[port - 1].pkey_table_len = dprops->max_pkeys; |
| 942 | gen->port[port - 1].gid_table_len = pprops->gid_tbl_len; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 943 | mlx5_ib_dbg(dev, "pkey_table_len %d, gid_table_len %d\n", |
| 944 | dprops->max_pkeys, pprops->gid_tbl_len); |
| 945 | } |
| 946 | |
| 947 | out: |
| 948 | kfree(pprops); |
| 949 | kfree(dprops); |
| 950 | |
| 951 | return err; |
| 952 | } |
| 953 | |
| 954 | static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
| 955 | { |
| 956 | int err; |
| 957 | |
| 958 | err = mlx5_mr_cache_cleanup(dev); |
| 959 | if (err) |
| 960 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
| 961 | |
| 962 | mlx5_ib_destroy_qp(dev->umrc.qp); |
| 963 | ib_destroy_cq(dev->umrc.cq); |
| 964 | ib_dereg_mr(dev->umrc.mr); |
| 965 | ib_dealloc_pd(dev->umrc.pd); |
| 966 | } |
| 967 | |
| 968 | enum { |
| 969 | MAX_UMR_WR = 128, |
| 970 | }; |
| 971 | |
| 972 | static int create_umr_res(struct mlx5_ib_dev *dev) |
| 973 | { |
| 974 | struct ib_qp_init_attr *init_attr = NULL; |
| 975 | struct ib_qp_attr *attr = NULL; |
| 976 | struct ib_pd *pd; |
| 977 | struct ib_cq *cq; |
| 978 | struct ib_qp *qp; |
| 979 | struct ib_mr *mr; |
| 980 | int ret; |
| 981 | |
| 982 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| 983 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 984 | if (!attr || !init_attr) { |
| 985 | ret = -ENOMEM; |
| 986 | goto error_0; |
| 987 | } |
| 988 | |
| 989 | pd = ib_alloc_pd(&dev->ib_dev); |
| 990 | if (IS_ERR(pd)) { |
| 991 | mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); |
| 992 | ret = PTR_ERR(pd); |
| 993 | goto error_0; |
| 994 | } |
| 995 | |
| 996 | mr = ib_get_dma_mr(pd, IB_ACCESS_LOCAL_WRITE); |
| 997 | if (IS_ERR(mr)) { |
| 998 | mlx5_ib_dbg(dev, "Couldn't create DMA MR for sync UMR QP\n"); |
| 999 | ret = PTR_ERR(mr); |
| 1000 | goto error_1; |
| 1001 | } |
| 1002 | |
| 1003 | cq = ib_create_cq(&dev->ib_dev, mlx5_umr_cq_handler, NULL, NULL, 128, |
| 1004 | 0); |
| 1005 | if (IS_ERR(cq)) { |
| 1006 | mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); |
| 1007 | ret = PTR_ERR(cq); |
| 1008 | goto error_2; |
| 1009 | } |
| 1010 | ib_req_notify_cq(cq, IB_CQ_NEXT_COMP); |
| 1011 | |
| 1012 | init_attr->send_cq = cq; |
| 1013 | init_attr->recv_cq = cq; |
| 1014 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
| 1015 | init_attr->cap.max_send_wr = MAX_UMR_WR; |
| 1016 | init_attr->cap.max_send_sge = 1; |
| 1017 | init_attr->qp_type = MLX5_IB_QPT_REG_UMR; |
| 1018 | init_attr->port_num = 1; |
| 1019 | qp = mlx5_ib_create_qp(pd, init_attr, NULL); |
| 1020 | if (IS_ERR(qp)) { |
| 1021 | mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); |
| 1022 | ret = PTR_ERR(qp); |
| 1023 | goto error_3; |
| 1024 | } |
| 1025 | qp->device = &dev->ib_dev; |
| 1026 | qp->real_qp = qp; |
| 1027 | qp->uobject = NULL; |
| 1028 | qp->qp_type = MLX5_IB_QPT_REG_UMR; |
| 1029 | |
| 1030 | attr->qp_state = IB_QPS_INIT; |
| 1031 | attr->port_num = 1; |
| 1032 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX | |
| 1033 | IB_QP_PORT, NULL); |
| 1034 | if (ret) { |
| 1035 | mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); |
| 1036 | goto error_4; |
| 1037 | } |
| 1038 | |
| 1039 | memset(attr, 0, sizeof(*attr)); |
| 1040 | attr->qp_state = IB_QPS_RTR; |
| 1041 | attr->path_mtu = IB_MTU_256; |
| 1042 | |
| 1043 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 1044 | if (ret) { |
| 1045 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); |
| 1046 | goto error_4; |
| 1047 | } |
| 1048 | |
| 1049 | memset(attr, 0, sizeof(*attr)); |
| 1050 | attr->qp_state = IB_QPS_RTS; |
| 1051 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 1052 | if (ret) { |
| 1053 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); |
| 1054 | goto error_4; |
| 1055 | } |
| 1056 | |
| 1057 | dev->umrc.qp = qp; |
| 1058 | dev->umrc.cq = cq; |
| 1059 | dev->umrc.mr = mr; |
| 1060 | dev->umrc.pd = pd; |
| 1061 | |
| 1062 | sema_init(&dev->umrc.sem, MAX_UMR_WR); |
| 1063 | ret = mlx5_mr_cache_init(dev); |
| 1064 | if (ret) { |
| 1065 | mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); |
| 1066 | goto error_4; |
| 1067 | } |
| 1068 | |
| 1069 | kfree(attr); |
| 1070 | kfree(init_attr); |
| 1071 | |
| 1072 | return 0; |
| 1073 | |
| 1074 | error_4: |
| 1075 | mlx5_ib_destroy_qp(qp); |
| 1076 | |
| 1077 | error_3: |
| 1078 | ib_destroy_cq(cq); |
| 1079 | |
| 1080 | error_2: |
| 1081 | ib_dereg_mr(mr); |
| 1082 | |
| 1083 | error_1: |
| 1084 | ib_dealloc_pd(pd); |
| 1085 | |
| 1086 | error_0: |
| 1087 | kfree(attr); |
| 1088 | kfree(init_attr); |
| 1089 | return ret; |
| 1090 | } |
| 1091 | |
| 1092 | static int create_dev_resources(struct mlx5_ib_resources *devr) |
| 1093 | { |
| 1094 | struct ib_srq_init_attr attr; |
| 1095 | struct mlx5_ib_dev *dev; |
| 1096 | int ret = 0; |
| 1097 | |
| 1098 | dev = container_of(devr, struct mlx5_ib_dev, devr); |
| 1099 | |
| 1100 | devr->p0 = mlx5_ib_alloc_pd(&dev->ib_dev, NULL, NULL); |
| 1101 | if (IS_ERR(devr->p0)) { |
| 1102 | ret = PTR_ERR(devr->p0); |
| 1103 | goto error0; |
| 1104 | } |
| 1105 | devr->p0->device = &dev->ib_dev; |
| 1106 | devr->p0->uobject = NULL; |
| 1107 | atomic_set(&devr->p0->usecnt, 0); |
| 1108 | |
| 1109 | devr->c0 = mlx5_ib_create_cq(&dev->ib_dev, 1, 0, NULL, NULL); |
| 1110 | if (IS_ERR(devr->c0)) { |
| 1111 | ret = PTR_ERR(devr->c0); |
| 1112 | goto error1; |
| 1113 | } |
| 1114 | devr->c0->device = &dev->ib_dev; |
| 1115 | devr->c0->uobject = NULL; |
| 1116 | devr->c0->comp_handler = NULL; |
| 1117 | devr->c0->event_handler = NULL; |
| 1118 | devr->c0->cq_context = NULL; |
| 1119 | atomic_set(&devr->c0->usecnt, 0); |
| 1120 | |
| 1121 | devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 1122 | if (IS_ERR(devr->x0)) { |
| 1123 | ret = PTR_ERR(devr->x0); |
| 1124 | goto error2; |
| 1125 | } |
| 1126 | devr->x0->device = &dev->ib_dev; |
| 1127 | devr->x0->inode = NULL; |
| 1128 | atomic_set(&devr->x0->usecnt, 0); |
| 1129 | mutex_init(&devr->x0->tgt_qp_mutex); |
| 1130 | INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
| 1131 | |
| 1132 | devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 1133 | if (IS_ERR(devr->x1)) { |
| 1134 | ret = PTR_ERR(devr->x1); |
| 1135 | goto error3; |
| 1136 | } |
| 1137 | devr->x1->device = &dev->ib_dev; |
| 1138 | devr->x1->inode = NULL; |
| 1139 | atomic_set(&devr->x1->usecnt, 0); |
| 1140 | mutex_init(&devr->x1->tgt_qp_mutex); |
| 1141 | INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
| 1142 | |
| 1143 | memset(&attr, 0, sizeof(attr)); |
| 1144 | attr.attr.max_sge = 1; |
| 1145 | attr.attr.max_wr = 1; |
| 1146 | attr.srq_type = IB_SRQT_XRC; |
| 1147 | attr.ext.xrc.cq = devr->c0; |
| 1148 | attr.ext.xrc.xrcd = devr->x0; |
| 1149 | |
| 1150 | devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 1151 | if (IS_ERR(devr->s0)) { |
| 1152 | ret = PTR_ERR(devr->s0); |
| 1153 | goto error4; |
| 1154 | } |
| 1155 | devr->s0->device = &dev->ib_dev; |
| 1156 | devr->s0->pd = devr->p0; |
| 1157 | devr->s0->uobject = NULL; |
| 1158 | devr->s0->event_handler = NULL; |
| 1159 | devr->s0->srq_context = NULL; |
| 1160 | devr->s0->srq_type = IB_SRQT_XRC; |
| 1161 | devr->s0->ext.xrc.xrcd = devr->x0; |
| 1162 | devr->s0->ext.xrc.cq = devr->c0; |
| 1163 | atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
| 1164 | atomic_inc(&devr->s0->ext.xrc.cq->usecnt); |
| 1165 | atomic_inc(&devr->p0->usecnt); |
| 1166 | atomic_set(&devr->s0->usecnt, 0); |
| 1167 | |
| 1168 | return 0; |
| 1169 | |
| 1170 | error4: |
| 1171 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 1172 | error3: |
| 1173 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 1174 | error2: |
| 1175 | mlx5_ib_destroy_cq(devr->c0); |
| 1176 | error1: |
| 1177 | mlx5_ib_dealloc_pd(devr->p0); |
| 1178 | error0: |
| 1179 | return ret; |
| 1180 | } |
| 1181 | |
| 1182 | static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
| 1183 | { |
| 1184 | mlx5_ib_destroy_srq(devr->s0); |
| 1185 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 1186 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 1187 | mlx5_ib_destroy_cq(devr->c0); |
| 1188 | mlx5_ib_dealloc_pd(devr->p0); |
| 1189 | } |
| 1190 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame^] | 1191 | static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 1192 | struct ib_port_immutable *immutable) |
| 1193 | { |
| 1194 | struct ib_port_attr attr; |
| 1195 | int err; |
| 1196 | |
| 1197 | err = mlx5_ib_query_port(ibdev, port_num, &attr); |
| 1198 | if (err) |
| 1199 | return err; |
| 1200 | |
| 1201 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 1202 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 1203 | |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1207 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1208 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1209 | struct mlx5_ib_dev *dev; |
| 1210 | int err; |
| 1211 | int i; |
| 1212 | |
| 1213 | printk_once(KERN_INFO "%s", mlx5_version); |
| 1214 | |
| 1215 | dev = (struct mlx5_ib_dev *)ib_alloc_device(sizeof(*dev)); |
| 1216 | if (!dev) |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1217 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1218 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1219 | dev->mdev = mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1220 | |
| 1221 | err = get_port_caps(dev); |
| 1222 | if (err) |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1223 | goto err_dealloc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1224 | |
| 1225 | get_ext_port_caps(dev); |
| 1226 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1227 | MLX5_INIT_DOORBELL_LOCK(&dev->uar_lock); |
| 1228 | |
| 1229 | strlcpy(dev->ib_dev.name, "mlx5_%d", IB_DEVICE_NAME_MAX); |
| 1230 | dev->ib_dev.owner = THIS_MODULE; |
| 1231 | dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 1232 | dev->ib_dev.local_dma_lkey = mdev->caps.gen.reserved_lkey; |
| 1233 | dev->num_ports = mdev->caps.gen.num_ports; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1234 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 1235 | dev->ib_dev.num_comp_vectors = |
| 1236 | dev->mdev->priv.eq_table.num_comp_vectors; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1237 | dev->ib_dev.dma_device = &mdev->pdev->dev; |
| 1238 | |
| 1239 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
| 1240 | dev->ib_dev.uverbs_cmd_mask = |
| 1241 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 1242 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 1243 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 1244 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 1245 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
| 1246 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
| 1247 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 1248 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 1249 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 1250 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 1251 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 1252 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 1253 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 1254 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 1255 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 1256 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 1257 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 1258 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 1259 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 1260 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 1261 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 1262 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 1263 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Haggai Eran | 1707cb4 | 2015-02-08 13:28:52 +0200 | [diff] [blame] | 1264 | dev->ib_dev.uverbs_ex_cmd_mask = |
| 1265 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1266 | |
| 1267 | dev->ib_dev.query_device = mlx5_ib_query_device; |
| 1268 | dev->ib_dev.query_port = mlx5_ib_query_port; |
Michael Wang | 6b90a6d | 2015-05-05 14:50:18 +0200 | [diff] [blame] | 1269 | dev->ib_dev.query_protocol = mlx5_ib_query_protocol; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1270 | dev->ib_dev.query_gid = mlx5_ib_query_gid; |
| 1271 | dev->ib_dev.query_pkey = mlx5_ib_query_pkey; |
| 1272 | dev->ib_dev.modify_device = mlx5_ib_modify_device; |
| 1273 | dev->ib_dev.modify_port = mlx5_ib_modify_port; |
| 1274 | dev->ib_dev.alloc_ucontext = mlx5_ib_alloc_ucontext; |
| 1275 | dev->ib_dev.dealloc_ucontext = mlx5_ib_dealloc_ucontext; |
| 1276 | dev->ib_dev.mmap = mlx5_ib_mmap; |
| 1277 | dev->ib_dev.alloc_pd = mlx5_ib_alloc_pd; |
| 1278 | dev->ib_dev.dealloc_pd = mlx5_ib_dealloc_pd; |
| 1279 | dev->ib_dev.create_ah = mlx5_ib_create_ah; |
| 1280 | dev->ib_dev.query_ah = mlx5_ib_query_ah; |
| 1281 | dev->ib_dev.destroy_ah = mlx5_ib_destroy_ah; |
| 1282 | dev->ib_dev.create_srq = mlx5_ib_create_srq; |
| 1283 | dev->ib_dev.modify_srq = mlx5_ib_modify_srq; |
| 1284 | dev->ib_dev.query_srq = mlx5_ib_query_srq; |
| 1285 | dev->ib_dev.destroy_srq = mlx5_ib_destroy_srq; |
| 1286 | dev->ib_dev.post_srq_recv = mlx5_ib_post_srq_recv; |
| 1287 | dev->ib_dev.create_qp = mlx5_ib_create_qp; |
| 1288 | dev->ib_dev.modify_qp = mlx5_ib_modify_qp; |
| 1289 | dev->ib_dev.query_qp = mlx5_ib_query_qp; |
| 1290 | dev->ib_dev.destroy_qp = mlx5_ib_destroy_qp; |
| 1291 | dev->ib_dev.post_send = mlx5_ib_post_send; |
| 1292 | dev->ib_dev.post_recv = mlx5_ib_post_recv; |
| 1293 | dev->ib_dev.create_cq = mlx5_ib_create_cq; |
| 1294 | dev->ib_dev.modify_cq = mlx5_ib_modify_cq; |
| 1295 | dev->ib_dev.resize_cq = mlx5_ib_resize_cq; |
| 1296 | dev->ib_dev.destroy_cq = mlx5_ib_destroy_cq; |
| 1297 | dev->ib_dev.poll_cq = mlx5_ib_poll_cq; |
| 1298 | dev->ib_dev.req_notify_cq = mlx5_ib_arm_cq; |
| 1299 | dev->ib_dev.get_dma_mr = mlx5_ib_get_dma_mr; |
| 1300 | dev->ib_dev.reg_user_mr = mlx5_ib_reg_user_mr; |
| 1301 | dev->ib_dev.dereg_mr = mlx5_ib_dereg_mr; |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 1302 | dev->ib_dev.destroy_mr = mlx5_ib_destroy_mr; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1303 | dev->ib_dev.attach_mcast = mlx5_ib_mcg_attach; |
| 1304 | dev->ib_dev.detach_mcast = mlx5_ib_mcg_detach; |
| 1305 | dev->ib_dev.process_mad = mlx5_ib_process_mad; |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 1306 | dev->ib_dev.create_mr = mlx5_ib_create_mr; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1307 | dev->ib_dev.alloc_fast_reg_mr = mlx5_ib_alloc_fast_reg_mr; |
| 1308 | dev->ib_dev.alloc_fast_reg_page_list = mlx5_ib_alloc_fast_reg_page_list; |
| 1309 | dev->ib_dev.free_fast_reg_page_list = mlx5_ib_free_fast_reg_page_list; |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 1310 | dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame^] | 1311 | dev->ib_dev.get_port_immutable = mlx5_port_immutable; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1312 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 1313 | mlx5_ib_internal_query_odp_caps(dev); |
| 1314 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 1315 | if (mdev->caps.gen.flags & MLX5_DEV_CAP_FLAG_XRC) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1316 | dev->ib_dev.alloc_xrcd = mlx5_ib_alloc_xrcd; |
| 1317 | dev->ib_dev.dealloc_xrcd = mlx5_ib_dealloc_xrcd; |
| 1318 | dev->ib_dev.uverbs_cmd_mask |= |
| 1319 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 1320 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
| 1321 | } |
| 1322 | |
| 1323 | err = init_node_data(dev); |
| 1324 | if (err) |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 1325 | goto err_dealloc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1326 | |
| 1327 | mutex_init(&dev->cap_mask_mutex); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1328 | |
| 1329 | err = create_dev_resources(&dev->devr); |
| 1330 | if (err) |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 1331 | goto err_dealloc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1332 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1333 | err = mlx5_ib_odp_init_one(dev); |
Wei Yongjun | 281d1a9 | 2013-07-30 07:54:26 +0800 | [diff] [blame] | 1334 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1335 | goto err_rsrc; |
| 1336 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1337 | err = ib_register_device(&dev->ib_dev, NULL); |
| 1338 | if (err) |
| 1339 | goto err_odp; |
| 1340 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1341 | err = create_umr_res(dev); |
| 1342 | if (err) |
| 1343 | goto err_dev; |
| 1344 | |
| 1345 | for (i = 0; i < ARRAY_SIZE(mlx5_class_attributes); i++) { |
Wei Yongjun | 281d1a9 | 2013-07-30 07:54:26 +0800 | [diff] [blame] | 1346 | err = device_create_file(&dev->ib_dev.dev, |
| 1347 | mlx5_class_attributes[i]); |
| 1348 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1349 | goto err_umrc; |
| 1350 | } |
| 1351 | |
| 1352 | dev->ib_active = true; |
| 1353 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1354 | return dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1355 | |
| 1356 | err_umrc: |
| 1357 | destroy_umrc_res(dev); |
| 1358 | |
| 1359 | err_dev: |
| 1360 | ib_unregister_device(&dev->ib_dev); |
| 1361 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1362 | err_odp: |
| 1363 | mlx5_ib_odp_remove_one(dev); |
| 1364 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1365 | err_rsrc: |
| 1366 | destroy_dev_resources(&dev->devr); |
| 1367 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1368 | err_dealloc: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1369 | ib_dealloc_device((struct ib_device *)dev); |
| 1370 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1371 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1372 | } |
| 1373 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1374 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1375 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1376 | struct mlx5_ib_dev *dev = context; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1377 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1378 | ib_unregister_device(&dev->ib_dev); |
Eli Cohen | eefd56e | 2014-09-14 16:47:50 +0300 | [diff] [blame] | 1379 | destroy_umrc_res(dev); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1380 | mlx5_ib_odp_remove_one(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1381 | destroy_dev_resources(&dev->devr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1382 | ib_dealloc_device(&dev->ib_dev); |
| 1383 | } |
| 1384 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1385 | static struct mlx5_interface mlx5_ib_interface = { |
| 1386 | .add = mlx5_ib_add, |
| 1387 | .remove = mlx5_ib_remove, |
| 1388 | .event = mlx5_ib_event, |
Saeed Mahameed | 64613d94 | 2015-04-02 17:07:34 +0300 | [diff] [blame] | 1389 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1390 | }; |
| 1391 | |
| 1392 | static int __init mlx5_ib_init(void) |
| 1393 | { |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1394 | int err; |
| 1395 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1396 | if (deprecated_prof_sel != 2) |
| 1397 | pr_warn("prof_sel is deprecated for mlx5_ib, set it for mlx5_core\n"); |
| 1398 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1399 | err = mlx5_ib_odp_init(); |
| 1400 | if (err) |
| 1401 | return err; |
| 1402 | |
| 1403 | err = mlx5_register_interface(&mlx5_ib_interface); |
| 1404 | if (err) |
| 1405 | goto clean_odp; |
| 1406 | |
| 1407 | return err; |
| 1408 | |
| 1409 | clean_odp: |
| 1410 | mlx5_ib_odp_cleanup(); |
| 1411 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | static void __exit mlx5_ib_cleanup(void) |
| 1415 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1416 | mlx5_unregister_interface(&mlx5_ib_interface); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1417 | mlx5_ib_odp_cleanup(); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | module_init(mlx5_ib_init); |
| 1421 | module_exit(mlx5_ib_cleanup); |