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 | |
| 265 | static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 266 | union ib_gid *gid) |
| 267 | { |
| 268 | struct ib_smp *in_mad = NULL; |
| 269 | struct ib_smp *out_mad = NULL; |
| 270 | int err = -ENOMEM; |
| 271 | |
| 272 | in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL); |
| 273 | out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL); |
| 274 | if (!in_mad || !out_mad) |
| 275 | goto out; |
| 276 | |
| 277 | init_query_mad(in_mad); |
| 278 | in_mad->attr_id = IB_SMP_ATTR_PORT_INFO; |
| 279 | in_mad->attr_mod = cpu_to_be32(port); |
| 280 | |
| 281 | err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad); |
| 282 | if (err) |
| 283 | goto out; |
| 284 | |
| 285 | memcpy(gid->raw, out_mad->data + 8, 8); |
| 286 | |
| 287 | init_query_mad(in_mad); |
| 288 | in_mad->attr_id = IB_SMP_ATTR_GUID_INFO; |
| 289 | in_mad->attr_mod = cpu_to_be32(index / 8); |
| 290 | |
| 291 | err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad); |
| 292 | if (err) |
| 293 | goto out; |
| 294 | |
| 295 | memcpy(gid->raw + 8, out_mad->data + (index % 8) * 8, 8); |
| 296 | |
| 297 | out: |
| 298 | kfree(in_mad); |
| 299 | kfree(out_mad); |
| 300 | return err; |
| 301 | } |
| 302 | |
| 303 | static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 304 | u16 *pkey) |
| 305 | { |
| 306 | struct ib_smp *in_mad = NULL; |
| 307 | struct ib_smp *out_mad = NULL; |
| 308 | int err = -ENOMEM; |
| 309 | |
| 310 | in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL); |
| 311 | out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL); |
| 312 | if (!in_mad || !out_mad) |
| 313 | goto out; |
| 314 | |
| 315 | init_query_mad(in_mad); |
| 316 | in_mad->attr_id = IB_SMP_ATTR_PKEY_TABLE; |
| 317 | in_mad->attr_mod = cpu_to_be32(index / 32); |
| 318 | |
| 319 | err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad); |
| 320 | if (err) |
| 321 | goto out; |
| 322 | |
| 323 | *pkey = be16_to_cpu(((__be16 *)out_mad->data)[index % 32]); |
| 324 | |
| 325 | out: |
| 326 | kfree(in_mad); |
| 327 | kfree(out_mad); |
| 328 | return err; |
| 329 | } |
| 330 | |
| 331 | struct mlx5_reg_node_desc { |
| 332 | u8 desc[64]; |
| 333 | }; |
| 334 | |
| 335 | static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask, |
| 336 | struct ib_device_modify *props) |
| 337 | { |
| 338 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 339 | struct mlx5_reg_node_desc in; |
| 340 | struct mlx5_reg_node_desc out; |
| 341 | int err; |
| 342 | |
| 343 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 344 | return -EOPNOTSUPP; |
| 345 | |
| 346 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 347 | return 0; |
| 348 | |
| 349 | /* |
| 350 | * If possible, pass node desc to FW, so it can generate |
| 351 | * a 144 trap. If cmd fails, just ignore. |
| 352 | */ |
| 353 | memcpy(&in, props->node_desc, 64); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 354 | err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 355 | sizeof(out), MLX5_REG_NODE_DESC, 0, 1); |
| 356 | if (err) |
| 357 | return err; |
| 358 | |
| 359 | memcpy(ibdev->node_desc, props->node_desc, 64); |
| 360 | |
| 361 | return err; |
| 362 | } |
| 363 | |
| 364 | static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 365 | struct ib_port_modify *props) |
| 366 | { |
| 367 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 368 | struct ib_port_attr attr; |
| 369 | u32 tmp; |
| 370 | int err; |
| 371 | |
| 372 | mutex_lock(&dev->cap_mask_mutex); |
| 373 | |
| 374 | err = mlx5_ib_query_port(ibdev, port, &attr); |
| 375 | if (err) |
| 376 | goto out; |
| 377 | |
| 378 | tmp = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 379 | ~props->clr_port_cap_mask; |
| 380 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 381 | err = mlx5_set_port_caps(dev->mdev, port, tmp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 382 | |
| 383 | out: |
| 384 | mutex_unlock(&dev->cap_mask_mutex); |
| 385 | return err; |
| 386 | } |
| 387 | |
| 388 | static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev, |
| 389 | struct ib_udata *udata) |
| 390 | { |
| 391 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 392 | struct mlx5_ib_alloc_ucontext_req_v2 req; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 393 | struct mlx5_ib_alloc_ucontext_resp resp; |
| 394 | struct mlx5_ib_ucontext *context; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 395 | struct mlx5_general_caps *gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 396 | struct mlx5_uuar_info *uuari; |
| 397 | struct mlx5_uar *uars; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 398 | int gross_uuars; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 399 | int num_uars; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 400 | int ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 401 | int uuarn; |
| 402 | int err; |
| 403 | int i; |
Jack Morgenstein | f241e74 | 2014-07-28 23:30:23 +0300 | [diff] [blame] | 404 | size_t reqlen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 405 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 406 | gen = &dev->mdev->caps.gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 407 | if (!dev->ib_active) |
| 408 | return ERR_PTR(-EAGAIN); |
| 409 | |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 410 | memset(&req, 0, sizeof(req)); |
| 411 | reqlen = udata->inlen - sizeof(struct ib_uverbs_cmd_hdr); |
| 412 | if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
| 413 | ver = 0; |
| 414 | else if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req_v2)) |
| 415 | ver = 2; |
| 416 | else |
| 417 | return ERR_PTR(-EINVAL); |
| 418 | |
| 419 | err = ib_copy_from_udata(&req, udata, reqlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 420 | if (err) |
| 421 | return ERR_PTR(err); |
| 422 | |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 423 | if (req.flags || req.reserved) |
| 424 | return ERR_PTR(-EINVAL); |
| 425 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 426 | if (req.total_num_uuars > MLX5_MAX_UUARS) |
| 427 | return ERR_PTR(-ENOMEM); |
| 428 | |
| 429 | if (req.total_num_uuars == 0) |
| 430 | return ERR_PTR(-EINVAL); |
| 431 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 432 | req.total_num_uuars = ALIGN(req.total_num_uuars, |
| 433 | MLX5_NON_FP_BF_REGS_PER_PAGE); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 434 | if (req.num_low_latency_uuars > req.total_num_uuars - 1) |
| 435 | return ERR_PTR(-EINVAL); |
| 436 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 437 | num_uars = req.total_num_uuars / MLX5_NON_FP_BF_REGS_PER_PAGE; |
| 438 | gross_uuars = num_uars * MLX5_BF_REGS_PER_PAGE; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 439 | resp.qp_tab_size = 1 << gen->log_max_qp; |
| 440 | resp.bf_reg_size = gen->bf_reg_size; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 441 | resp.cache_line_size = L1_CACHE_BYTES; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 442 | resp.max_sq_desc_sz = gen->max_sq_desc_sz; |
| 443 | resp.max_rq_desc_sz = gen->max_rq_desc_sz; |
| 444 | resp.max_send_wqebb = gen->max_wqes; |
| 445 | resp.max_recv_wr = gen->max_wqes; |
| 446 | resp.max_srq_recv_wr = gen->max_srq_wqes; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 447 | |
| 448 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 449 | if (!context) |
| 450 | return ERR_PTR(-ENOMEM); |
| 451 | |
| 452 | uuari = &context->uuari; |
| 453 | mutex_init(&uuari->lock); |
| 454 | uars = kcalloc(num_uars, sizeof(*uars), GFP_KERNEL); |
| 455 | if (!uars) { |
| 456 | err = -ENOMEM; |
| 457 | goto out_ctx; |
| 458 | } |
| 459 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 460 | uuari->bitmap = kcalloc(BITS_TO_LONGS(gross_uuars), |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 461 | sizeof(*uuari->bitmap), |
| 462 | GFP_KERNEL); |
| 463 | if (!uuari->bitmap) { |
| 464 | err = -ENOMEM; |
| 465 | goto out_uar_ctx; |
| 466 | } |
| 467 | /* |
| 468 | * clear all fast path uuars |
| 469 | */ |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 470 | for (i = 0; i < gross_uuars; i++) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 471 | uuarn = i & 3; |
| 472 | if (uuarn == 2 || uuarn == 3) |
| 473 | set_bit(i, uuari->bitmap); |
| 474 | } |
| 475 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 476 | uuari->count = kcalloc(gross_uuars, sizeof(*uuari->count), GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 477 | if (!uuari->count) { |
| 478 | err = -ENOMEM; |
| 479 | goto out_bitmap; |
| 480 | } |
| 481 | |
| 482 | for (i = 0; i < num_uars; i++) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 483 | err = mlx5_cmd_alloc_uar(dev->mdev, &uars[i].index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 484 | if (err) |
| 485 | goto out_count; |
| 486 | } |
| 487 | |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 488 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 489 | context->ibucontext.invalidate_range = &mlx5_ib_invalidate_range; |
| 490 | #endif |
| 491 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 492 | INIT_LIST_HEAD(&context->db_page_list); |
| 493 | mutex_init(&context->db_page_mutex); |
| 494 | |
| 495 | resp.tot_uuars = req.total_num_uuars; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 496 | resp.num_ports = gen->num_ports; |
Dan Carpenter | 92b0ca7 | 2013-07-25 20:04:36 +0300 | [diff] [blame] | 497 | err = ib_copy_to_udata(udata, &resp, |
| 498 | sizeof(resp) - sizeof(resp.reserved)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 499 | if (err) |
| 500 | goto out_uars; |
| 501 | |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 502 | uuari->ver = ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 503 | uuari->num_low_latency_uuars = req.num_low_latency_uuars; |
| 504 | uuari->uars = uars; |
| 505 | uuari->num_uars = num_uars; |
| 506 | return &context->ibucontext; |
| 507 | |
| 508 | out_uars: |
| 509 | for (i--; i >= 0; i--) |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 510 | mlx5_cmd_free_uar(dev->mdev, uars[i].index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 511 | out_count: |
| 512 | kfree(uuari->count); |
| 513 | |
| 514 | out_bitmap: |
| 515 | kfree(uuari->bitmap); |
| 516 | |
| 517 | out_uar_ctx: |
| 518 | kfree(uars); |
| 519 | |
| 520 | out_ctx: |
| 521 | kfree(context); |
| 522 | return ERR_PTR(err); |
| 523 | } |
| 524 | |
| 525 | static int mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
| 526 | { |
| 527 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 528 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
| 529 | struct mlx5_uuar_info *uuari = &context->uuari; |
| 530 | int i; |
| 531 | |
| 532 | for (i = 0; i < uuari->num_uars; i++) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 533 | if (mlx5_cmd_free_uar(dev->mdev, uuari->uars[i].index)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 534 | mlx5_ib_warn(dev, "failed to free UAR 0x%x\n", uuari->uars[i].index); |
| 535 | } |
| 536 | |
| 537 | kfree(uuari->count); |
| 538 | kfree(uuari->bitmap); |
| 539 | kfree(uuari->uars); |
| 540 | kfree(context); |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, int index) |
| 546 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 547 | return (pci_resource_start(dev->mdev->pdev, 0) >> PAGE_SHIFT) + index; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static int get_command(unsigned long offset) |
| 551 | { |
| 552 | return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK; |
| 553 | } |
| 554 | |
| 555 | static int get_arg(unsigned long offset) |
| 556 | { |
| 557 | return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1); |
| 558 | } |
| 559 | |
| 560 | static int get_index(unsigned long offset) |
| 561 | { |
| 562 | return get_arg(offset); |
| 563 | } |
| 564 | |
| 565 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
| 566 | { |
| 567 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 568 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
| 569 | struct mlx5_uuar_info *uuari = &context->uuari; |
| 570 | unsigned long command; |
| 571 | unsigned long idx; |
| 572 | phys_addr_t pfn; |
| 573 | |
| 574 | command = get_command(vma->vm_pgoff); |
| 575 | switch (command) { |
| 576 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 577 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 578 | return -EINVAL; |
| 579 | |
| 580 | idx = get_index(vma->vm_pgoff); |
Eli Cohen | 1c3ce90 | 2014-09-14 16:47:53 +0300 | [diff] [blame] | 581 | if (idx >= uuari->num_uars) |
| 582 | return -EINVAL; |
| 583 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 584 | pfn = uar_index2pfn(dev, uuari->uars[idx].index); |
| 585 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn 0x%llx\n", idx, |
| 586 | (unsigned long long)pfn); |
| 587 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 588 | vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); |
| 589 | if (io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 590 | PAGE_SIZE, vma->vm_page_prot)) |
| 591 | return -EAGAIN; |
| 592 | |
| 593 | mlx5_ib_dbg(dev, "mapped WC at 0x%lx, PA 0x%llx\n", |
| 594 | vma->vm_start, |
| 595 | (unsigned long long)pfn << PAGE_SHIFT); |
| 596 | break; |
| 597 | |
| 598 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
| 599 | return -ENOSYS; |
| 600 | |
| 601 | default: |
| 602 | return -EINVAL; |
| 603 | } |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | static int alloc_pa_mkey(struct mlx5_ib_dev *dev, u32 *key, u32 pdn) |
| 609 | { |
| 610 | struct mlx5_create_mkey_mbox_in *in; |
| 611 | struct mlx5_mkey_seg *seg; |
| 612 | struct mlx5_core_mr mr; |
| 613 | int err; |
| 614 | |
| 615 | in = kzalloc(sizeof(*in), GFP_KERNEL); |
| 616 | if (!in) |
| 617 | return -ENOMEM; |
| 618 | |
| 619 | seg = &in->seg; |
| 620 | seg->flags = MLX5_PERM_LOCAL_READ | MLX5_ACCESS_MODE_PA; |
| 621 | seg->flags_pd = cpu_to_be32(pdn | MLX5_MKEY_LEN64); |
| 622 | seg->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8); |
| 623 | seg->start_addr = 0; |
| 624 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 625 | err = mlx5_core_create_mkey(dev->mdev, &mr, in, sizeof(*in), |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 626 | NULL, NULL, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 627 | if (err) { |
| 628 | mlx5_ib_warn(dev, "failed to create mkey, %d\n", err); |
| 629 | goto err_in; |
| 630 | } |
| 631 | |
| 632 | kfree(in); |
| 633 | *key = mr.key; |
| 634 | |
| 635 | return 0; |
| 636 | |
| 637 | err_in: |
| 638 | kfree(in); |
| 639 | |
| 640 | return err; |
| 641 | } |
| 642 | |
| 643 | static void free_pa_mkey(struct mlx5_ib_dev *dev, u32 key) |
| 644 | { |
| 645 | struct mlx5_core_mr mr; |
| 646 | int err; |
| 647 | |
| 648 | memset(&mr, 0, sizeof(mr)); |
| 649 | mr.key = key; |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 650 | err = mlx5_core_destroy_mkey(dev->mdev, &mr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 651 | if (err) |
| 652 | mlx5_ib_warn(dev, "failed to destroy mkey 0x%x\n", key); |
| 653 | } |
| 654 | |
| 655 | static struct ib_pd *mlx5_ib_alloc_pd(struct ib_device *ibdev, |
| 656 | struct ib_ucontext *context, |
| 657 | struct ib_udata *udata) |
| 658 | { |
| 659 | struct mlx5_ib_alloc_pd_resp resp; |
| 660 | struct mlx5_ib_pd *pd; |
| 661 | int err; |
| 662 | |
| 663 | pd = kmalloc(sizeof(*pd), GFP_KERNEL); |
| 664 | if (!pd) |
| 665 | return ERR_PTR(-ENOMEM); |
| 666 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 667 | err = mlx5_core_alloc_pd(to_mdev(ibdev)->mdev, &pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 668 | if (err) { |
| 669 | kfree(pd); |
| 670 | return ERR_PTR(err); |
| 671 | } |
| 672 | |
| 673 | if (context) { |
| 674 | resp.pdn = pd->pdn; |
| 675 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 676 | mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 677 | kfree(pd); |
| 678 | return ERR_PTR(-EFAULT); |
| 679 | } |
| 680 | } else { |
| 681 | err = alloc_pa_mkey(to_mdev(ibdev), &pd->pa_lkey, pd->pdn); |
| 682 | if (err) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 683 | mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 684 | kfree(pd); |
| 685 | return ERR_PTR(err); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | return &pd->ibpd; |
| 690 | } |
| 691 | |
| 692 | static int mlx5_ib_dealloc_pd(struct ib_pd *pd) |
| 693 | { |
| 694 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 695 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
| 696 | |
| 697 | if (!pd->uobject) |
| 698 | free_pa_mkey(mdev, mpd->pa_lkey); |
| 699 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 700 | mlx5_core_dealloc_pd(mdev->mdev, mpd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 701 | kfree(mpd); |
| 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 707 | { |
| 708 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 709 | int err; |
| 710 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 711 | err = mlx5_core_attach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 712 | if (err) |
| 713 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
| 714 | ibqp->qp_num, gid->raw); |
| 715 | |
| 716 | return err; |
| 717 | } |
| 718 | |
| 719 | static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 720 | { |
| 721 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 722 | int err; |
| 723 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 724 | err = mlx5_core_detach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 725 | if (err) |
| 726 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
| 727 | ibqp->qp_num, gid->raw); |
| 728 | |
| 729 | return err; |
| 730 | } |
| 731 | |
| 732 | static int init_node_data(struct mlx5_ib_dev *dev) |
| 733 | { |
| 734 | struct ib_smp *in_mad = NULL; |
| 735 | struct ib_smp *out_mad = NULL; |
| 736 | int err = -ENOMEM; |
| 737 | |
| 738 | in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL); |
| 739 | out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL); |
| 740 | if (!in_mad || !out_mad) |
| 741 | goto out; |
| 742 | |
| 743 | init_query_mad(in_mad); |
| 744 | in_mad->attr_id = IB_SMP_ATTR_NODE_DESC; |
| 745 | |
| 746 | err = mlx5_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad); |
| 747 | if (err) |
| 748 | goto out; |
| 749 | |
| 750 | memcpy(dev->ib_dev.node_desc, out_mad->data, 64); |
| 751 | |
| 752 | in_mad->attr_id = IB_SMP_ATTR_NODE_INFO; |
| 753 | |
| 754 | err = mlx5_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad); |
| 755 | if (err) |
| 756 | goto out; |
| 757 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 758 | dev->mdev->rev_id = be32_to_cpup((__be32 *)(out_mad->data + 32)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 759 | memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8); |
| 760 | |
| 761 | out: |
| 762 | kfree(in_mad); |
| 763 | kfree(out_mad); |
| 764 | return err; |
| 765 | } |
| 766 | |
| 767 | static ssize_t show_fw_pages(struct device *device, struct device_attribute *attr, |
| 768 | char *buf) |
| 769 | { |
| 770 | struct mlx5_ib_dev *dev = |
| 771 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 772 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 773 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | static ssize_t show_reg_pages(struct device *device, |
| 777 | struct device_attribute *attr, char *buf) |
| 778 | { |
| 779 | struct mlx5_ib_dev *dev = |
| 780 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 781 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 782 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | static ssize_t show_hca(struct device *device, struct device_attribute *attr, |
| 786 | char *buf) |
| 787 | { |
| 788 | struct mlx5_ib_dev *dev = |
| 789 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 790 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr, |
| 794 | char *buf) |
| 795 | { |
| 796 | struct mlx5_ib_dev *dev = |
| 797 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 798 | return sprintf(buf, "%d.%d.%d\n", fw_rev_maj(dev->mdev), |
| 799 | fw_rev_min(dev->mdev), fw_rev_sub(dev->mdev)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
| 803 | char *buf) |
| 804 | { |
| 805 | struct mlx5_ib_dev *dev = |
| 806 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 807 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | static ssize_t show_board(struct device *device, struct device_attribute *attr, |
| 811 | char *buf) |
| 812 | { |
| 813 | struct mlx5_ib_dev *dev = |
| 814 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 815 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 816 | dev->mdev->board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
| 820 | static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL); |
| 821 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 822 | static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
| 823 | static DEVICE_ATTR(fw_pages, S_IRUGO, show_fw_pages, NULL); |
| 824 | static DEVICE_ATTR(reg_pages, S_IRUGO, show_reg_pages, NULL); |
| 825 | |
| 826 | static struct device_attribute *mlx5_class_attributes[] = { |
| 827 | &dev_attr_hw_rev, |
| 828 | &dev_attr_fw_ver, |
| 829 | &dev_attr_hca_type, |
| 830 | &dev_attr_board_id, |
| 831 | &dev_attr_fw_pages, |
| 832 | &dev_attr_reg_pages, |
| 833 | }; |
| 834 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 835 | static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context, |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 836 | enum mlx5_dev_event event, unsigned long param) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 837 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 838 | struct mlx5_ib_dev *ibdev = (struct mlx5_ib_dev *)context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 839 | struct ib_event ibev; |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 840 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 841 | u8 port = 0; |
| 842 | |
| 843 | switch (event) { |
| 844 | case MLX5_DEV_EVENT_SYS_ERROR: |
| 845 | ibdev->ib_active = false; |
| 846 | ibev.event = IB_EVENT_DEVICE_FATAL; |
| 847 | break; |
| 848 | |
| 849 | case MLX5_DEV_EVENT_PORT_UP: |
| 850 | ibev.event = IB_EVENT_PORT_ACTIVE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 851 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 852 | break; |
| 853 | |
| 854 | case MLX5_DEV_EVENT_PORT_DOWN: |
| 855 | ibev.event = IB_EVENT_PORT_ERR; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 856 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 857 | break; |
| 858 | |
| 859 | case MLX5_DEV_EVENT_PORT_INITIALIZED: |
| 860 | /* not used by ULPs */ |
| 861 | return; |
| 862 | |
| 863 | case MLX5_DEV_EVENT_LID_CHANGE: |
| 864 | ibev.event = IB_EVENT_LID_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 865 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 866 | break; |
| 867 | |
| 868 | case MLX5_DEV_EVENT_PKEY_CHANGE: |
| 869 | ibev.event = IB_EVENT_PKEY_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 870 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case MLX5_DEV_EVENT_GUID_CHANGE: |
| 874 | ibev.event = IB_EVENT_GID_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 875 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 876 | break; |
| 877 | |
| 878 | case MLX5_DEV_EVENT_CLIENT_REREG: |
| 879 | ibev.event = IB_EVENT_CLIENT_REREGISTER; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 880 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 881 | break; |
| 882 | } |
| 883 | |
| 884 | ibev.device = &ibdev->ib_dev; |
| 885 | ibev.element.port_num = port; |
| 886 | |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 887 | if (port < 1 || port > ibdev->num_ports) { |
| 888 | mlx5_ib_warn(ibdev, "warning: event on port %d\n", port); |
| 889 | return; |
| 890 | } |
| 891 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 892 | if (ibdev->ib_active) |
| 893 | ib_dispatch_event(&ibev); |
| 894 | } |
| 895 | |
| 896 | static void get_ext_port_caps(struct mlx5_ib_dev *dev) |
| 897 | { |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 898 | struct mlx5_general_caps *gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 899 | int port; |
| 900 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 901 | gen = &dev->mdev->caps.gen; |
| 902 | for (port = 1; port <= gen->num_ports; port++) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 903 | mlx5_query_ext_port_caps(dev, port); |
| 904 | } |
| 905 | |
| 906 | static int get_port_caps(struct mlx5_ib_dev *dev) |
| 907 | { |
| 908 | struct ib_device_attr *dprops = NULL; |
| 909 | struct ib_port_attr *pprops = NULL; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 910 | struct mlx5_general_caps *gen; |
Dan Carpenter | f614fc1 | 2015-01-12 11:56:58 +0300 | [diff] [blame] | 911 | int err = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 912 | int port; |
| 913 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 914 | gen = &dev->mdev->caps.gen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 915 | pprops = kmalloc(sizeof(*pprops), GFP_KERNEL); |
| 916 | if (!pprops) |
| 917 | goto out; |
| 918 | |
| 919 | dprops = kmalloc(sizeof(*dprops), GFP_KERNEL); |
| 920 | if (!dprops) |
| 921 | goto out; |
| 922 | |
| 923 | err = mlx5_ib_query_device(&dev->ib_dev, dprops); |
| 924 | if (err) { |
| 925 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
| 926 | goto out; |
| 927 | } |
| 928 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 929 | for (port = 1; port <= gen->num_ports; port++) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 930 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
| 931 | if (err) { |
| 932 | mlx5_ib_warn(dev, "query_port %d failed %d\n", port, err); |
| 933 | break; |
| 934 | } |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 935 | gen->port[port - 1].pkey_table_len = dprops->max_pkeys; |
| 936 | gen->port[port - 1].gid_table_len = pprops->gid_tbl_len; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 937 | mlx5_ib_dbg(dev, "pkey_table_len %d, gid_table_len %d\n", |
| 938 | dprops->max_pkeys, pprops->gid_tbl_len); |
| 939 | } |
| 940 | |
| 941 | out: |
| 942 | kfree(pprops); |
| 943 | kfree(dprops); |
| 944 | |
| 945 | return err; |
| 946 | } |
| 947 | |
| 948 | static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
| 949 | { |
| 950 | int err; |
| 951 | |
| 952 | err = mlx5_mr_cache_cleanup(dev); |
| 953 | if (err) |
| 954 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
| 955 | |
| 956 | mlx5_ib_destroy_qp(dev->umrc.qp); |
| 957 | ib_destroy_cq(dev->umrc.cq); |
| 958 | ib_dereg_mr(dev->umrc.mr); |
| 959 | ib_dealloc_pd(dev->umrc.pd); |
| 960 | } |
| 961 | |
| 962 | enum { |
| 963 | MAX_UMR_WR = 128, |
| 964 | }; |
| 965 | |
| 966 | static int create_umr_res(struct mlx5_ib_dev *dev) |
| 967 | { |
| 968 | struct ib_qp_init_attr *init_attr = NULL; |
| 969 | struct ib_qp_attr *attr = NULL; |
| 970 | struct ib_pd *pd; |
| 971 | struct ib_cq *cq; |
| 972 | struct ib_qp *qp; |
| 973 | struct ib_mr *mr; |
| 974 | int ret; |
| 975 | |
| 976 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| 977 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 978 | if (!attr || !init_attr) { |
| 979 | ret = -ENOMEM; |
| 980 | goto error_0; |
| 981 | } |
| 982 | |
| 983 | pd = ib_alloc_pd(&dev->ib_dev); |
| 984 | if (IS_ERR(pd)) { |
| 985 | mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); |
| 986 | ret = PTR_ERR(pd); |
| 987 | goto error_0; |
| 988 | } |
| 989 | |
| 990 | mr = ib_get_dma_mr(pd, IB_ACCESS_LOCAL_WRITE); |
| 991 | if (IS_ERR(mr)) { |
| 992 | mlx5_ib_dbg(dev, "Couldn't create DMA MR for sync UMR QP\n"); |
| 993 | ret = PTR_ERR(mr); |
| 994 | goto error_1; |
| 995 | } |
| 996 | |
| 997 | cq = ib_create_cq(&dev->ib_dev, mlx5_umr_cq_handler, NULL, NULL, 128, |
| 998 | 0); |
| 999 | if (IS_ERR(cq)) { |
| 1000 | mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); |
| 1001 | ret = PTR_ERR(cq); |
| 1002 | goto error_2; |
| 1003 | } |
| 1004 | ib_req_notify_cq(cq, IB_CQ_NEXT_COMP); |
| 1005 | |
| 1006 | init_attr->send_cq = cq; |
| 1007 | init_attr->recv_cq = cq; |
| 1008 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
| 1009 | init_attr->cap.max_send_wr = MAX_UMR_WR; |
| 1010 | init_attr->cap.max_send_sge = 1; |
| 1011 | init_attr->qp_type = MLX5_IB_QPT_REG_UMR; |
| 1012 | init_attr->port_num = 1; |
| 1013 | qp = mlx5_ib_create_qp(pd, init_attr, NULL); |
| 1014 | if (IS_ERR(qp)) { |
| 1015 | mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); |
| 1016 | ret = PTR_ERR(qp); |
| 1017 | goto error_3; |
| 1018 | } |
| 1019 | qp->device = &dev->ib_dev; |
| 1020 | qp->real_qp = qp; |
| 1021 | qp->uobject = NULL; |
| 1022 | qp->qp_type = MLX5_IB_QPT_REG_UMR; |
| 1023 | |
| 1024 | attr->qp_state = IB_QPS_INIT; |
| 1025 | attr->port_num = 1; |
| 1026 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX | |
| 1027 | IB_QP_PORT, NULL); |
| 1028 | if (ret) { |
| 1029 | mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); |
| 1030 | goto error_4; |
| 1031 | } |
| 1032 | |
| 1033 | memset(attr, 0, sizeof(*attr)); |
| 1034 | attr->qp_state = IB_QPS_RTR; |
| 1035 | attr->path_mtu = IB_MTU_256; |
| 1036 | |
| 1037 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 1038 | if (ret) { |
| 1039 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); |
| 1040 | goto error_4; |
| 1041 | } |
| 1042 | |
| 1043 | memset(attr, 0, sizeof(*attr)); |
| 1044 | attr->qp_state = IB_QPS_RTS; |
| 1045 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 1046 | if (ret) { |
| 1047 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); |
| 1048 | goto error_4; |
| 1049 | } |
| 1050 | |
| 1051 | dev->umrc.qp = qp; |
| 1052 | dev->umrc.cq = cq; |
| 1053 | dev->umrc.mr = mr; |
| 1054 | dev->umrc.pd = pd; |
| 1055 | |
| 1056 | sema_init(&dev->umrc.sem, MAX_UMR_WR); |
| 1057 | ret = mlx5_mr_cache_init(dev); |
| 1058 | if (ret) { |
| 1059 | mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); |
| 1060 | goto error_4; |
| 1061 | } |
| 1062 | |
| 1063 | kfree(attr); |
| 1064 | kfree(init_attr); |
| 1065 | |
| 1066 | return 0; |
| 1067 | |
| 1068 | error_4: |
| 1069 | mlx5_ib_destroy_qp(qp); |
| 1070 | |
| 1071 | error_3: |
| 1072 | ib_destroy_cq(cq); |
| 1073 | |
| 1074 | error_2: |
| 1075 | ib_dereg_mr(mr); |
| 1076 | |
| 1077 | error_1: |
| 1078 | ib_dealloc_pd(pd); |
| 1079 | |
| 1080 | error_0: |
| 1081 | kfree(attr); |
| 1082 | kfree(init_attr); |
| 1083 | return ret; |
| 1084 | } |
| 1085 | |
| 1086 | static int create_dev_resources(struct mlx5_ib_resources *devr) |
| 1087 | { |
| 1088 | struct ib_srq_init_attr attr; |
| 1089 | struct mlx5_ib_dev *dev; |
| 1090 | int ret = 0; |
| 1091 | |
| 1092 | dev = container_of(devr, struct mlx5_ib_dev, devr); |
| 1093 | |
| 1094 | devr->p0 = mlx5_ib_alloc_pd(&dev->ib_dev, NULL, NULL); |
| 1095 | if (IS_ERR(devr->p0)) { |
| 1096 | ret = PTR_ERR(devr->p0); |
| 1097 | goto error0; |
| 1098 | } |
| 1099 | devr->p0->device = &dev->ib_dev; |
| 1100 | devr->p0->uobject = NULL; |
| 1101 | atomic_set(&devr->p0->usecnt, 0); |
| 1102 | |
| 1103 | devr->c0 = mlx5_ib_create_cq(&dev->ib_dev, 1, 0, NULL, NULL); |
| 1104 | if (IS_ERR(devr->c0)) { |
| 1105 | ret = PTR_ERR(devr->c0); |
| 1106 | goto error1; |
| 1107 | } |
| 1108 | devr->c0->device = &dev->ib_dev; |
| 1109 | devr->c0->uobject = NULL; |
| 1110 | devr->c0->comp_handler = NULL; |
| 1111 | devr->c0->event_handler = NULL; |
| 1112 | devr->c0->cq_context = NULL; |
| 1113 | atomic_set(&devr->c0->usecnt, 0); |
| 1114 | |
| 1115 | devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 1116 | if (IS_ERR(devr->x0)) { |
| 1117 | ret = PTR_ERR(devr->x0); |
| 1118 | goto error2; |
| 1119 | } |
| 1120 | devr->x0->device = &dev->ib_dev; |
| 1121 | devr->x0->inode = NULL; |
| 1122 | atomic_set(&devr->x0->usecnt, 0); |
| 1123 | mutex_init(&devr->x0->tgt_qp_mutex); |
| 1124 | INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
| 1125 | |
| 1126 | devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 1127 | if (IS_ERR(devr->x1)) { |
| 1128 | ret = PTR_ERR(devr->x1); |
| 1129 | goto error3; |
| 1130 | } |
| 1131 | devr->x1->device = &dev->ib_dev; |
| 1132 | devr->x1->inode = NULL; |
| 1133 | atomic_set(&devr->x1->usecnt, 0); |
| 1134 | mutex_init(&devr->x1->tgt_qp_mutex); |
| 1135 | INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
| 1136 | |
| 1137 | memset(&attr, 0, sizeof(attr)); |
| 1138 | attr.attr.max_sge = 1; |
| 1139 | attr.attr.max_wr = 1; |
| 1140 | attr.srq_type = IB_SRQT_XRC; |
| 1141 | attr.ext.xrc.cq = devr->c0; |
| 1142 | attr.ext.xrc.xrcd = devr->x0; |
| 1143 | |
| 1144 | devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 1145 | if (IS_ERR(devr->s0)) { |
| 1146 | ret = PTR_ERR(devr->s0); |
| 1147 | goto error4; |
| 1148 | } |
| 1149 | devr->s0->device = &dev->ib_dev; |
| 1150 | devr->s0->pd = devr->p0; |
| 1151 | devr->s0->uobject = NULL; |
| 1152 | devr->s0->event_handler = NULL; |
| 1153 | devr->s0->srq_context = NULL; |
| 1154 | devr->s0->srq_type = IB_SRQT_XRC; |
| 1155 | devr->s0->ext.xrc.xrcd = devr->x0; |
| 1156 | devr->s0->ext.xrc.cq = devr->c0; |
| 1157 | atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
| 1158 | atomic_inc(&devr->s0->ext.xrc.cq->usecnt); |
| 1159 | atomic_inc(&devr->p0->usecnt); |
| 1160 | atomic_set(&devr->s0->usecnt, 0); |
| 1161 | |
| 1162 | return 0; |
| 1163 | |
| 1164 | error4: |
| 1165 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 1166 | error3: |
| 1167 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 1168 | error2: |
| 1169 | mlx5_ib_destroy_cq(devr->c0); |
| 1170 | error1: |
| 1171 | mlx5_ib_dealloc_pd(devr->p0); |
| 1172 | error0: |
| 1173 | return ret; |
| 1174 | } |
| 1175 | |
| 1176 | static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
| 1177 | { |
| 1178 | mlx5_ib_destroy_srq(devr->s0); |
| 1179 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 1180 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 1181 | mlx5_ib_destroy_cq(devr->c0); |
| 1182 | mlx5_ib_dealloc_pd(devr->p0); |
| 1183 | } |
| 1184 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 1185 | static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 1186 | struct ib_port_immutable *immutable) |
| 1187 | { |
| 1188 | struct ib_port_attr attr; |
| 1189 | int err; |
| 1190 | |
| 1191 | err = mlx5_ib_query_port(ibdev, port_num, &attr); |
| 1192 | if (err) |
| 1193 | return err; |
| 1194 | |
| 1195 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 1196 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Ira Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame^] | 1197 | immutable->core_cap_flags = RDMA_CORE_PORT_IBA_IB; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 1198 | |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1202 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1203 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1204 | struct mlx5_ib_dev *dev; |
| 1205 | int err; |
| 1206 | int i; |
| 1207 | |
| 1208 | printk_once(KERN_INFO "%s", mlx5_version); |
| 1209 | |
| 1210 | dev = (struct mlx5_ib_dev *)ib_alloc_device(sizeof(*dev)); |
| 1211 | if (!dev) |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1212 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1213 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1214 | dev->mdev = mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1215 | |
| 1216 | err = get_port_caps(dev); |
| 1217 | if (err) |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1218 | goto err_dealloc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1219 | |
| 1220 | get_ext_port_caps(dev); |
| 1221 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1222 | MLX5_INIT_DOORBELL_LOCK(&dev->uar_lock); |
| 1223 | |
| 1224 | strlcpy(dev->ib_dev.name, "mlx5_%d", IB_DEVICE_NAME_MAX); |
| 1225 | dev->ib_dev.owner = THIS_MODULE; |
| 1226 | dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 1227 | dev->ib_dev.local_dma_lkey = mdev->caps.gen.reserved_lkey; |
| 1228 | dev->num_ports = mdev->caps.gen.num_ports; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1229 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 1230 | dev->ib_dev.num_comp_vectors = |
| 1231 | dev->mdev->priv.eq_table.num_comp_vectors; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1232 | dev->ib_dev.dma_device = &mdev->pdev->dev; |
| 1233 | |
| 1234 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
| 1235 | dev->ib_dev.uverbs_cmd_mask = |
| 1236 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 1237 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 1238 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 1239 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 1240 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
| 1241 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
| 1242 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 1243 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 1244 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 1245 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 1246 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 1247 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 1248 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 1249 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 1250 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 1251 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 1252 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 1253 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 1254 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 1255 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 1256 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 1257 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 1258 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Haggai Eran | 1707cb4 | 2015-02-08 13:28:52 +0200 | [diff] [blame] | 1259 | dev->ib_dev.uverbs_ex_cmd_mask = |
| 1260 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1261 | |
| 1262 | dev->ib_dev.query_device = mlx5_ib_query_device; |
| 1263 | dev->ib_dev.query_port = mlx5_ib_query_port; |
| 1264 | dev->ib_dev.query_gid = mlx5_ib_query_gid; |
| 1265 | dev->ib_dev.query_pkey = mlx5_ib_query_pkey; |
| 1266 | dev->ib_dev.modify_device = mlx5_ib_modify_device; |
| 1267 | dev->ib_dev.modify_port = mlx5_ib_modify_port; |
| 1268 | dev->ib_dev.alloc_ucontext = mlx5_ib_alloc_ucontext; |
| 1269 | dev->ib_dev.dealloc_ucontext = mlx5_ib_dealloc_ucontext; |
| 1270 | dev->ib_dev.mmap = mlx5_ib_mmap; |
| 1271 | dev->ib_dev.alloc_pd = mlx5_ib_alloc_pd; |
| 1272 | dev->ib_dev.dealloc_pd = mlx5_ib_dealloc_pd; |
| 1273 | dev->ib_dev.create_ah = mlx5_ib_create_ah; |
| 1274 | dev->ib_dev.query_ah = mlx5_ib_query_ah; |
| 1275 | dev->ib_dev.destroy_ah = mlx5_ib_destroy_ah; |
| 1276 | dev->ib_dev.create_srq = mlx5_ib_create_srq; |
| 1277 | dev->ib_dev.modify_srq = mlx5_ib_modify_srq; |
| 1278 | dev->ib_dev.query_srq = mlx5_ib_query_srq; |
| 1279 | dev->ib_dev.destroy_srq = mlx5_ib_destroy_srq; |
| 1280 | dev->ib_dev.post_srq_recv = mlx5_ib_post_srq_recv; |
| 1281 | dev->ib_dev.create_qp = mlx5_ib_create_qp; |
| 1282 | dev->ib_dev.modify_qp = mlx5_ib_modify_qp; |
| 1283 | dev->ib_dev.query_qp = mlx5_ib_query_qp; |
| 1284 | dev->ib_dev.destroy_qp = mlx5_ib_destroy_qp; |
| 1285 | dev->ib_dev.post_send = mlx5_ib_post_send; |
| 1286 | dev->ib_dev.post_recv = mlx5_ib_post_recv; |
| 1287 | dev->ib_dev.create_cq = mlx5_ib_create_cq; |
| 1288 | dev->ib_dev.modify_cq = mlx5_ib_modify_cq; |
| 1289 | dev->ib_dev.resize_cq = mlx5_ib_resize_cq; |
| 1290 | dev->ib_dev.destroy_cq = mlx5_ib_destroy_cq; |
| 1291 | dev->ib_dev.poll_cq = mlx5_ib_poll_cq; |
| 1292 | dev->ib_dev.req_notify_cq = mlx5_ib_arm_cq; |
| 1293 | dev->ib_dev.get_dma_mr = mlx5_ib_get_dma_mr; |
| 1294 | dev->ib_dev.reg_user_mr = mlx5_ib_reg_user_mr; |
| 1295 | dev->ib_dev.dereg_mr = mlx5_ib_dereg_mr; |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 1296 | dev->ib_dev.destroy_mr = mlx5_ib_destroy_mr; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1297 | dev->ib_dev.attach_mcast = mlx5_ib_mcg_attach; |
| 1298 | dev->ib_dev.detach_mcast = mlx5_ib_mcg_detach; |
| 1299 | dev->ib_dev.process_mad = mlx5_ib_process_mad; |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 1300 | dev->ib_dev.create_mr = mlx5_ib_create_mr; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1301 | dev->ib_dev.alloc_fast_reg_mr = mlx5_ib_alloc_fast_reg_mr; |
| 1302 | dev->ib_dev.alloc_fast_reg_page_list = mlx5_ib_alloc_fast_reg_page_list; |
| 1303 | 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] | 1304 | dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 1305 | dev->ib_dev.get_port_immutable = mlx5_port_immutable; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1306 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 1307 | mlx5_ib_internal_query_odp_caps(dev); |
| 1308 | |
Eli Cohen | c7a08ac | 2014-10-02 12:19:42 +0300 | [diff] [blame] | 1309 | if (mdev->caps.gen.flags & MLX5_DEV_CAP_FLAG_XRC) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1310 | dev->ib_dev.alloc_xrcd = mlx5_ib_alloc_xrcd; |
| 1311 | dev->ib_dev.dealloc_xrcd = mlx5_ib_dealloc_xrcd; |
| 1312 | dev->ib_dev.uverbs_cmd_mask |= |
| 1313 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 1314 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
| 1315 | } |
| 1316 | |
| 1317 | err = init_node_data(dev); |
| 1318 | if (err) |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 1319 | goto err_dealloc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1320 | |
| 1321 | mutex_init(&dev->cap_mask_mutex); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1322 | |
| 1323 | err = create_dev_resources(&dev->devr); |
| 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 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1327 | err = mlx5_ib_odp_init_one(dev); |
Wei Yongjun | 281d1a9 | 2013-07-30 07:54:26 +0800 | [diff] [blame] | 1328 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1329 | goto err_rsrc; |
| 1330 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1331 | err = ib_register_device(&dev->ib_dev, NULL); |
| 1332 | if (err) |
| 1333 | goto err_odp; |
| 1334 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1335 | err = create_umr_res(dev); |
| 1336 | if (err) |
| 1337 | goto err_dev; |
| 1338 | |
| 1339 | for (i = 0; i < ARRAY_SIZE(mlx5_class_attributes); i++) { |
Wei Yongjun | 281d1a9 | 2013-07-30 07:54:26 +0800 | [diff] [blame] | 1340 | err = device_create_file(&dev->ib_dev.dev, |
| 1341 | mlx5_class_attributes[i]); |
| 1342 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1343 | goto err_umrc; |
| 1344 | } |
| 1345 | |
| 1346 | dev->ib_active = true; |
| 1347 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1348 | return dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1349 | |
| 1350 | err_umrc: |
| 1351 | destroy_umrc_res(dev); |
| 1352 | |
| 1353 | err_dev: |
| 1354 | ib_unregister_device(&dev->ib_dev); |
| 1355 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1356 | err_odp: |
| 1357 | mlx5_ib_odp_remove_one(dev); |
| 1358 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1359 | err_rsrc: |
| 1360 | destroy_dev_resources(&dev->devr); |
| 1361 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1362 | err_dealloc: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1363 | ib_dealloc_device((struct ib_device *)dev); |
| 1364 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1365 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1366 | } |
| 1367 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1368 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1369 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1370 | struct mlx5_ib_dev *dev = context; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1371 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1372 | ib_unregister_device(&dev->ib_dev); |
Eli Cohen | eefd56e | 2014-09-14 16:47:50 +0300 | [diff] [blame] | 1373 | destroy_umrc_res(dev); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1374 | mlx5_ib_odp_remove_one(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1375 | destroy_dev_resources(&dev->devr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1376 | ib_dealloc_device(&dev->ib_dev); |
| 1377 | } |
| 1378 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1379 | static struct mlx5_interface mlx5_ib_interface = { |
| 1380 | .add = mlx5_ib_add, |
| 1381 | .remove = mlx5_ib_remove, |
| 1382 | .event = mlx5_ib_event, |
Saeed Mahameed | 64613d94 | 2015-04-02 17:07:34 +0300 | [diff] [blame] | 1383 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1384 | }; |
| 1385 | |
| 1386 | static int __init mlx5_ib_init(void) |
| 1387 | { |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1388 | int err; |
| 1389 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1390 | if (deprecated_prof_sel != 2) |
| 1391 | pr_warn("prof_sel is deprecated for mlx5_ib, set it for mlx5_core\n"); |
| 1392 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1393 | err = mlx5_ib_odp_init(); |
| 1394 | if (err) |
| 1395 | return err; |
| 1396 | |
| 1397 | err = mlx5_register_interface(&mlx5_ib_interface); |
| 1398 | if (err) |
| 1399 | goto clean_odp; |
| 1400 | |
| 1401 | return err; |
| 1402 | |
| 1403 | clean_odp: |
| 1404 | mlx5_ib_odp_cleanup(); |
| 1405 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | static void __exit mlx5_ib_cleanup(void) |
| 1409 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1410 | mlx5_unregister_interface(&mlx5_ib_interface); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1411 | mlx5_ib_odp_cleanup(); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | module_init(mlx5_ib_init); |
| 1415 | module_exit(mlx5_ib_cleanup); |