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 | |
Christoph Hellwig | adec640 | 2015-08-28 09:27:19 +0200 | [diff] [blame] | 33 | #include <linux/highmem.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 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> |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 43 | #include <linux/mlx5/vport.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 44 | #include <rdma/ib_smi.h> |
| 45 | #include <rdma/ib_umem.h> |
| 46 | #include "user.h" |
| 47 | #include "mlx5_ib.h" |
| 48 | |
| 49 | #define DRIVER_NAME "mlx5_ib" |
Amir Vadai | 169a1d8 | 2014-02-19 17:47:31 +0200 | [diff] [blame] | 50 | #define DRIVER_VERSION "2.2-1" |
| 51 | #define DRIVER_RELDATE "Feb 2014" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 52 | |
| 53 | MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); |
| 54 | MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); |
| 55 | MODULE_LICENSE("Dual BSD/GPL"); |
| 56 | MODULE_VERSION(DRIVER_VERSION); |
| 57 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 58 | static int deprecated_prof_sel = 2; |
| 59 | module_param_named(prof_sel, deprecated_prof_sel, int, 0444); |
| 60 | 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] | 61 | |
| 62 | static char mlx5_version[] = |
| 63 | DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
| 64 | DRIVER_VERSION " (" DRIVER_RELDATE ")\n"; |
| 65 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 66 | static enum rdma_link_layer |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame^] | 67 | mlx5_port_type_cap_to_rdma_ll(int port_type_cap) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 68 | { |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame^] | 69 | switch (port_type_cap) { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 70 | case MLX5_CAP_PORT_TYPE_IB: |
| 71 | return IB_LINK_LAYER_INFINIBAND; |
| 72 | case MLX5_CAP_PORT_TYPE_ETH: |
| 73 | return IB_LINK_LAYER_ETHERNET; |
| 74 | default: |
| 75 | return IB_LINK_LAYER_UNSPECIFIED; |
| 76 | } |
| 77 | } |
| 78 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame^] | 79 | static enum rdma_link_layer |
| 80 | mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num) |
| 81 | { |
| 82 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 83 | int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type); |
| 84 | |
| 85 | return mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 86 | } |
| 87 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 88 | static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) |
| 89 | { |
| 90 | return !dev->mdev->issi; |
| 91 | } |
| 92 | |
| 93 | enum { |
| 94 | MLX5_VPORT_ACCESS_METHOD_MAD, |
| 95 | MLX5_VPORT_ACCESS_METHOD_HCA, |
| 96 | MLX5_VPORT_ACCESS_METHOD_NIC, |
| 97 | }; |
| 98 | |
| 99 | static int mlx5_get_vport_access_method(struct ib_device *ibdev) |
| 100 | { |
| 101 | if (mlx5_use_mad_ifc(to_mdev(ibdev))) |
| 102 | return MLX5_VPORT_ACCESS_METHOD_MAD; |
| 103 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame^] | 104 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 105 | IB_LINK_LAYER_ETHERNET) |
| 106 | return MLX5_VPORT_ACCESS_METHOD_NIC; |
| 107 | |
| 108 | return MLX5_VPORT_ACCESS_METHOD_HCA; |
| 109 | } |
| 110 | |
| 111 | static int mlx5_query_system_image_guid(struct ib_device *ibdev, |
| 112 | __be64 *sys_image_guid) |
| 113 | { |
| 114 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 115 | struct mlx5_core_dev *mdev = dev->mdev; |
| 116 | u64 tmp; |
| 117 | int err; |
| 118 | |
| 119 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 120 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 121 | return mlx5_query_mad_ifc_system_image_guid(ibdev, |
| 122 | sys_image_guid); |
| 123 | |
| 124 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 125 | err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp); |
| 126 | if (!err) |
| 127 | *sys_image_guid = cpu_to_be64(tmp); |
| 128 | return err; |
| 129 | |
| 130 | default: |
| 131 | return -EINVAL; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | static int mlx5_query_max_pkeys(struct ib_device *ibdev, |
| 136 | u16 *max_pkeys) |
| 137 | { |
| 138 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 139 | struct mlx5_core_dev *mdev = dev->mdev; |
| 140 | |
| 141 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 142 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 143 | return mlx5_query_mad_ifc_max_pkeys(ibdev, max_pkeys); |
| 144 | |
| 145 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 146 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 147 | *max_pkeys = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, |
| 148 | pkey_table_size)); |
| 149 | return 0; |
| 150 | |
| 151 | default: |
| 152 | return -EINVAL; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | static int mlx5_query_vendor_id(struct ib_device *ibdev, |
| 157 | u32 *vendor_id) |
| 158 | { |
| 159 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 160 | |
| 161 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 162 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 163 | return mlx5_query_mad_ifc_vendor_id(ibdev, vendor_id); |
| 164 | |
| 165 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 166 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 167 | return mlx5_core_query_vendor_id(dev->mdev, vendor_id); |
| 168 | |
| 169 | default: |
| 170 | return -EINVAL; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | static int mlx5_query_node_guid(struct mlx5_ib_dev *dev, |
| 175 | __be64 *node_guid) |
| 176 | { |
| 177 | u64 tmp; |
| 178 | int err; |
| 179 | |
| 180 | switch (mlx5_get_vport_access_method(&dev->ib_dev)) { |
| 181 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 182 | return mlx5_query_mad_ifc_node_guid(dev, node_guid); |
| 183 | |
| 184 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 185 | err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp); |
| 186 | if (!err) |
| 187 | *node_guid = cpu_to_be64(tmp); |
| 188 | return err; |
| 189 | |
| 190 | default: |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | struct mlx5_reg_node_desc { |
| 196 | u8 desc[64]; |
| 197 | }; |
| 198 | |
| 199 | static int mlx5_query_node_desc(struct mlx5_ib_dev *dev, char *node_desc) |
| 200 | { |
| 201 | struct mlx5_reg_node_desc in; |
| 202 | |
| 203 | if (mlx5_use_mad_ifc(dev)) |
| 204 | return mlx5_query_mad_ifc_node_desc(dev, node_desc); |
| 205 | |
| 206 | memset(&in, 0, sizeof(in)); |
| 207 | |
| 208 | return mlx5_core_access_reg(dev->mdev, &in, sizeof(in), node_desc, |
| 209 | sizeof(struct mlx5_reg_node_desc), |
| 210 | MLX5_REG_NODE_DESC, 0, 0); |
| 211 | } |
| 212 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 213 | static int mlx5_ib_query_device(struct ib_device *ibdev, |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 214 | struct ib_device_attr *props, |
| 215 | struct ib_udata *uhw) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 216 | { |
| 217 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 218 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 219 | int err = -ENOMEM; |
| 220 | int max_rq_sg; |
| 221 | int max_sq_sg; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 222 | u64 min_page_size = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 223 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 224 | if (uhw->inlen || uhw->outlen) |
| 225 | return -EINVAL; |
| 226 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 227 | memset(props, 0, sizeof(*props)); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 228 | err = mlx5_query_system_image_guid(ibdev, |
| 229 | &props->sys_image_guid); |
| 230 | if (err) |
| 231 | return err; |
| 232 | |
| 233 | err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys); |
| 234 | if (err) |
| 235 | return err; |
| 236 | |
| 237 | err = mlx5_query_vendor_id(ibdev, &props->vendor_id); |
| 238 | if (err) |
| 239 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 240 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 241 | props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) | |
| 242 | (fw_rev_min(dev->mdev) << 16) | |
| 243 | fw_rev_sub(dev->mdev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 244 | props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | |
| 245 | IB_DEVICE_PORT_ACTIVE_EVENT | |
| 246 | IB_DEVICE_SYS_IMAGE_GUID | |
Eli Cohen | 1a4c3a3 | 2014-02-06 17:41:25 +0200 | [diff] [blame] | 247 | IB_DEVICE_RC_RNR_NAK_GEN; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 248 | |
| 249 | if (MLX5_CAP_GEN(mdev, pkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 250 | props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 251 | if (MLX5_CAP_GEN(mdev, qkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 252 | props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 253 | if (MLX5_CAP_GEN(mdev, apm)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 254 | props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 255 | if (MLX5_CAP_GEN(mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 256 | props->device_cap_flags |= IB_DEVICE_XRC; |
| 257 | props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 258 | if (MLX5_CAP_GEN(mdev, sho)) { |
Sagi Grimberg | 2dea909 | 2014-02-23 14:19:13 +0200 | [diff] [blame] | 259 | props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER; |
| 260 | /* At this stage no support for signature handover */ |
| 261 | props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 | |
| 262 | IB_PROT_T10DIF_TYPE_2 | |
| 263 | IB_PROT_T10DIF_TYPE_3; |
| 264 | props->sig_guard_cap = IB_GUARD_T10DIF_CRC | |
| 265 | IB_GUARD_T10DIF_CSUM; |
| 266 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 267 | if (MLX5_CAP_GEN(mdev, block_lb_mc)) |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 268 | props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 269 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 270 | props->vendor_part_id = mdev->pdev->device; |
| 271 | props->hw_ver = mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 272 | |
| 273 | props->max_mr_size = ~0ull; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 274 | props->page_size_cap = ~(min_page_size - 1); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 275 | props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp); |
| 276 | props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
| 277 | max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) / |
| 278 | sizeof(struct mlx5_wqe_data_seg); |
| 279 | max_sq_sg = (MLX5_CAP_GEN(mdev, max_wqe_sz_sq) - |
| 280 | sizeof(struct mlx5_wqe_ctrl_seg)) / |
| 281 | sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 282 | props->max_sge = min(max_rq_sg, max_sq_sg); |
Sagi Grimberg | 18ebd40 | 2015-07-27 18:10:01 -0500 | [diff] [blame] | 283 | props->max_sge_rd = props->max_sge; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 284 | props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq); |
| 285 | props->max_cqe = (1 << MLX5_CAP_GEN(mdev, log_max_eq_sz)) - 1; |
| 286 | props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
| 287 | props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd); |
| 288 | props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp); |
| 289 | props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp); |
| 290 | props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq); |
| 291 | props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1; |
| 292 | props->local_ca_ack_delay = MLX5_CAP_GEN(mdev, local_ca_ack_delay); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 293 | 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] | 294 | props->max_srq_sge = max_rq_sg - 1; |
| 295 | props->max_fast_reg_page_list_len = (unsigned int)-1; |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 296 | props->atomic_cap = IB_ATOMIC_NONE; |
| 297 | props->masked_atomic_cap = IB_ATOMIC_NONE; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 298 | props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg); |
| 299 | props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 300 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 301 | props->max_mcast_grp; |
| 302 | props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */ |
| 303 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 304 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 305 | if (MLX5_CAP_GEN(mdev, pg)) |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 306 | props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
| 307 | props->odp_caps = dev->odp_caps; |
| 308 | #endif |
| 309 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 310 | return 0; |
| 311 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 312 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 313 | enum mlx5_ib_width { |
| 314 | MLX5_IB_WIDTH_1X = 1 << 0, |
| 315 | MLX5_IB_WIDTH_2X = 1 << 1, |
| 316 | MLX5_IB_WIDTH_4X = 1 << 2, |
| 317 | MLX5_IB_WIDTH_8X = 1 << 3, |
| 318 | MLX5_IB_WIDTH_12X = 1 << 4 |
| 319 | }; |
| 320 | |
| 321 | static int translate_active_width(struct ib_device *ibdev, u8 active_width, |
| 322 | u8 *ib_width) |
| 323 | { |
| 324 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 325 | int err = 0; |
| 326 | |
| 327 | if (active_width & MLX5_IB_WIDTH_1X) { |
| 328 | *ib_width = IB_WIDTH_1X; |
| 329 | } else if (active_width & MLX5_IB_WIDTH_2X) { |
| 330 | mlx5_ib_dbg(dev, "active_width %d is not supported by IB spec\n", |
| 331 | (int)active_width); |
| 332 | err = -EINVAL; |
| 333 | } else if (active_width & MLX5_IB_WIDTH_4X) { |
| 334 | *ib_width = IB_WIDTH_4X; |
| 335 | } else if (active_width & MLX5_IB_WIDTH_8X) { |
| 336 | *ib_width = IB_WIDTH_8X; |
| 337 | } else if (active_width & MLX5_IB_WIDTH_12X) { |
| 338 | *ib_width = IB_WIDTH_12X; |
| 339 | } else { |
| 340 | mlx5_ib_dbg(dev, "Invalid active_width %d\n", |
| 341 | (int)active_width); |
| 342 | err = -EINVAL; |
| 343 | } |
| 344 | |
| 345 | return err; |
| 346 | } |
| 347 | |
| 348 | static int mlx5_mtu_to_ib_mtu(int mtu) |
| 349 | { |
| 350 | switch (mtu) { |
| 351 | case 256: return 1; |
| 352 | case 512: return 2; |
| 353 | case 1024: return 3; |
| 354 | case 2048: return 4; |
| 355 | case 4096: return 5; |
| 356 | default: |
| 357 | pr_warn("invalid mtu\n"); |
| 358 | return -1; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | enum ib_max_vl_num { |
| 363 | __IB_MAX_VL_0 = 1, |
| 364 | __IB_MAX_VL_0_1 = 2, |
| 365 | __IB_MAX_VL_0_3 = 3, |
| 366 | __IB_MAX_VL_0_7 = 4, |
| 367 | __IB_MAX_VL_0_14 = 5, |
| 368 | }; |
| 369 | |
| 370 | enum mlx5_vl_hw_cap { |
| 371 | MLX5_VL_HW_0 = 1, |
| 372 | MLX5_VL_HW_0_1 = 2, |
| 373 | MLX5_VL_HW_0_2 = 3, |
| 374 | MLX5_VL_HW_0_3 = 4, |
| 375 | MLX5_VL_HW_0_4 = 5, |
| 376 | MLX5_VL_HW_0_5 = 6, |
| 377 | MLX5_VL_HW_0_6 = 7, |
| 378 | MLX5_VL_HW_0_7 = 8, |
| 379 | MLX5_VL_HW_0_14 = 15 |
| 380 | }; |
| 381 | |
| 382 | static int translate_max_vl_num(struct ib_device *ibdev, u8 vl_hw_cap, |
| 383 | u8 *max_vl_num) |
| 384 | { |
| 385 | switch (vl_hw_cap) { |
| 386 | case MLX5_VL_HW_0: |
| 387 | *max_vl_num = __IB_MAX_VL_0; |
| 388 | break; |
| 389 | case MLX5_VL_HW_0_1: |
| 390 | *max_vl_num = __IB_MAX_VL_0_1; |
| 391 | break; |
| 392 | case MLX5_VL_HW_0_3: |
| 393 | *max_vl_num = __IB_MAX_VL_0_3; |
| 394 | break; |
| 395 | case MLX5_VL_HW_0_7: |
| 396 | *max_vl_num = __IB_MAX_VL_0_7; |
| 397 | break; |
| 398 | case MLX5_VL_HW_0_14: |
| 399 | *max_vl_num = __IB_MAX_VL_0_14; |
| 400 | break; |
| 401 | |
| 402 | default: |
| 403 | return -EINVAL; |
| 404 | } |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port, |
| 410 | struct ib_port_attr *props) |
| 411 | { |
| 412 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 413 | struct mlx5_core_dev *mdev = dev->mdev; |
| 414 | struct mlx5_hca_vport_context *rep; |
| 415 | int max_mtu; |
| 416 | int oper_mtu; |
| 417 | int err; |
| 418 | u8 ib_link_width_oper; |
| 419 | u8 vl_hw_cap; |
| 420 | |
| 421 | rep = kzalloc(sizeof(*rep), GFP_KERNEL); |
| 422 | if (!rep) { |
| 423 | err = -ENOMEM; |
| 424 | goto out; |
| 425 | } |
| 426 | |
| 427 | memset(props, 0, sizeof(*props)); |
| 428 | |
| 429 | err = mlx5_query_hca_vport_context(mdev, 0, port, 0, rep); |
| 430 | if (err) |
| 431 | goto out; |
| 432 | |
| 433 | props->lid = rep->lid; |
| 434 | props->lmc = rep->lmc; |
| 435 | props->sm_lid = rep->sm_lid; |
| 436 | props->sm_sl = rep->sm_sl; |
| 437 | props->state = rep->vport_state; |
| 438 | props->phys_state = rep->port_physical_state; |
| 439 | props->port_cap_flags = rep->cap_mask1; |
| 440 | props->gid_tbl_len = mlx5_get_gid_table_len(MLX5_CAP_GEN(mdev, gid_table_size)); |
| 441 | props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg); |
| 442 | props->pkey_tbl_len = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, pkey_table_size)); |
| 443 | props->bad_pkey_cntr = rep->pkey_violation_counter; |
| 444 | props->qkey_viol_cntr = rep->qkey_violation_counter; |
| 445 | props->subnet_timeout = rep->subnet_timeout; |
| 446 | props->init_type_reply = rep->init_type_reply; |
| 447 | |
| 448 | err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); |
| 449 | if (err) |
| 450 | goto out; |
| 451 | |
| 452 | err = translate_active_width(ibdev, ib_link_width_oper, |
| 453 | &props->active_width); |
| 454 | if (err) |
| 455 | goto out; |
| 456 | err = mlx5_query_port_proto_oper(mdev, &props->active_speed, MLX5_PTYS_IB, |
| 457 | port); |
| 458 | if (err) |
| 459 | goto out; |
| 460 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 461 | mlx5_query_port_max_mtu(mdev, &max_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 462 | |
| 463 | props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu); |
| 464 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 465 | mlx5_query_port_oper_mtu(mdev, &oper_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 466 | |
| 467 | props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu); |
| 468 | |
| 469 | err = mlx5_query_port_vl_hw_cap(mdev, &vl_hw_cap, port); |
| 470 | if (err) |
| 471 | goto out; |
| 472 | |
| 473 | err = translate_max_vl_num(ibdev, vl_hw_cap, |
| 474 | &props->max_vl_num); |
| 475 | out: |
| 476 | kfree(rep); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 477 | return err; |
| 478 | } |
| 479 | |
| 480 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 481 | struct ib_port_attr *props) |
| 482 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 483 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 484 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 485 | return mlx5_query_mad_ifc_port(ibdev, port, props); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 486 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 487 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 488 | return mlx5_query_hca_port(ibdev, port, props); |
| 489 | |
| 490 | default: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 491 | return -EINVAL; |
| 492 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 496 | union ib_gid *gid) |
| 497 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 498 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 499 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 500 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 501 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 502 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 503 | return mlx5_query_mad_ifc_gids(ibdev, port, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 504 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 505 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 506 | return mlx5_query_hca_vport_gid(mdev, 0, port, 0, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 507 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 508 | default: |
| 509 | return -EINVAL; |
| 510 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 511 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 515 | u16 *pkey) |
| 516 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 517 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 518 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 519 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 520 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 521 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 522 | return mlx5_query_mad_ifc_pkey(ibdev, port, index, pkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 523 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 524 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 525 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 526 | return mlx5_query_hca_vport_pkey(mdev, 0, port, 0, index, |
| 527 | pkey); |
| 528 | default: |
| 529 | return -EINVAL; |
| 530 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 531 | } |
| 532 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 533 | static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask, |
| 534 | struct ib_device_modify *props) |
| 535 | { |
| 536 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 537 | struct mlx5_reg_node_desc in; |
| 538 | struct mlx5_reg_node_desc out; |
| 539 | int err; |
| 540 | |
| 541 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 542 | return -EOPNOTSUPP; |
| 543 | |
| 544 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 545 | return 0; |
| 546 | |
| 547 | /* |
| 548 | * If possible, pass node desc to FW, so it can generate |
| 549 | * a 144 trap. If cmd fails, just ignore. |
| 550 | */ |
| 551 | memcpy(&in, props->node_desc, 64); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 552 | err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 553 | sizeof(out), MLX5_REG_NODE_DESC, 0, 1); |
| 554 | if (err) |
| 555 | return err; |
| 556 | |
| 557 | memcpy(ibdev->node_desc, props->node_desc, 64); |
| 558 | |
| 559 | return err; |
| 560 | } |
| 561 | |
| 562 | static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 563 | struct ib_port_modify *props) |
| 564 | { |
| 565 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 566 | struct ib_port_attr attr; |
| 567 | u32 tmp; |
| 568 | int err; |
| 569 | |
| 570 | mutex_lock(&dev->cap_mask_mutex); |
| 571 | |
| 572 | err = mlx5_ib_query_port(ibdev, port, &attr); |
| 573 | if (err) |
| 574 | goto out; |
| 575 | |
| 576 | tmp = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 577 | ~props->clr_port_cap_mask; |
| 578 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 579 | err = mlx5_set_port_caps(dev->mdev, port, tmp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 580 | |
| 581 | out: |
| 582 | mutex_unlock(&dev->cap_mask_mutex); |
| 583 | return err; |
| 584 | } |
| 585 | |
| 586 | static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev, |
| 587 | struct ib_udata *udata) |
| 588 | { |
| 589 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 590 | struct mlx5_ib_alloc_ucontext_req_v2 req; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 591 | struct mlx5_ib_alloc_ucontext_resp resp; |
| 592 | struct mlx5_ib_ucontext *context; |
| 593 | struct mlx5_uuar_info *uuari; |
| 594 | struct mlx5_uar *uars; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 595 | int gross_uuars; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 596 | int num_uars; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 597 | int ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 598 | int uuarn; |
| 599 | int err; |
| 600 | int i; |
Jack Morgenstein | f241e74 | 2014-07-28 23:30:23 +0300 | [diff] [blame] | 601 | size_t reqlen; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 602 | |
| 603 | if (!dev->ib_active) |
| 604 | return ERR_PTR(-EAGAIN); |
| 605 | |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 606 | memset(&req, 0, sizeof(req)); |
| 607 | reqlen = udata->inlen - sizeof(struct ib_uverbs_cmd_hdr); |
| 608 | if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
| 609 | ver = 0; |
| 610 | else if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req_v2)) |
| 611 | ver = 2; |
| 612 | else |
| 613 | return ERR_PTR(-EINVAL); |
| 614 | |
| 615 | err = ib_copy_from_udata(&req, udata, reqlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 616 | if (err) |
| 617 | return ERR_PTR(err); |
| 618 | |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 619 | if (req.flags || req.reserved) |
| 620 | return ERR_PTR(-EINVAL); |
| 621 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 622 | if (req.total_num_uuars > MLX5_MAX_UUARS) |
| 623 | return ERR_PTR(-ENOMEM); |
| 624 | |
| 625 | if (req.total_num_uuars == 0) |
| 626 | return ERR_PTR(-EINVAL); |
| 627 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 628 | req.total_num_uuars = ALIGN(req.total_num_uuars, |
| 629 | MLX5_NON_FP_BF_REGS_PER_PAGE); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 630 | if (req.num_low_latency_uuars > req.total_num_uuars - 1) |
| 631 | return ERR_PTR(-EINVAL); |
| 632 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 633 | num_uars = req.total_num_uuars / MLX5_NON_FP_BF_REGS_PER_PAGE; |
| 634 | gross_uuars = num_uars * MLX5_BF_REGS_PER_PAGE; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 635 | resp.qp_tab_size = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp); |
| 636 | resp.bf_reg_size = 1 << MLX5_CAP_GEN(dev->mdev, log_bf_reg_size); |
| 637 | resp.cache_line_size = L1_CACHE_BYTES; |
| 638 | resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); |
| 639 | resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); |
| 640 | resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 641 | resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 642 | resp.max_srq_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 643 | |
| 644 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 645 | if (!context) |
| 646 | return ERR_PTR(-ENOMEM); |
| 647 | |
| 648 | uuari = &context->uuari; |
| 649 | mutex_init(&uuari->lock); |
| 650 | uars = kcalloc(num_uars, sizeof(*uars), GFP_KERNEL); |
| 651 | if (!uars) { |
| 652 | err = -ENOMEM; |
| 653 | goto out_ctx; |
| 654 | } |
| 655 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 656 | uuari->bitmap = kcalloc(BITS_TO_LONGS(gross_uuars), |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 657 | sizeof(*uuari->bitmap), |
| 658 | GFP_KERNEL); |
| 659 | if (!uuari->bitmap) { |
| 660 | err = -ENOMEM; |
| 661 | goto out_uar_ctx; |
| 662 | } |
| 663 | /* |
| 664 | * clear all fast path uuars |
| 665 | */ |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 666 | for (i = 0; i < gross_uuars; i++) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 667 | uuarn = i & 3; |
| 668 | if (uuarn == 2 || uuarn == 3) |
| 669 | set_bit(i, uuari->bitmap); |
| 670 | } |
| 671 | |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 672 | uuari->count = kcalloc(gross_uuars, sizeof(*uuari->count), GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 673 | if (!uuari->count) { |
| 674 | err = -ENOMEM; |
| 675 | goto out_bitmap; |
| 676 | } |
| 677 | |
| 678 | for (i = 0; i < num_uars; i++) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 679 | err = mlx5_cmd_alloc_uar(dev->mdev, &uars[i].index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 680 | if (err) |
| 681 | goto out_count; |
| 682 | } |
| 683 | |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 684 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 685 | context->ibucontext.invalidate_range = &mlx5_ib_invalidate_range; |
| 686 | #endif |
| 687 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 688 | INIT_LIST_HEAD(&context->db_page_list); |
| 689 | mutex_init(&context->db_page_mutex); |
| 690 | |
| 691 | resp.tot_uuars = req.total_num_uuars; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 692 | resp.num_ports = MLX5_CAP_GEN(dev->mdev, num_ports); |
Dan Carpenter | 92b0ca7 | 2013-07-25 20:04:36 +0300 | [diff] [blame] | 693 | err = ib_copy_to_udata(udata, &resp, |
| 694 | sizeof(resp) - sizeof(resp.reserved)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 695 | if (err) |
| 696 | goto out_uars; |
| 697 | |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 698 | uuari->ver = ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 699 | uuari->num_low_latency_uuars = req.num_low_latency_uuars; |
| 700 | uuari->uars = uars; |
| 701 | uuari->num_uars = num_uars; |
| 702 | return &context->ibucontext; |
| 703 | |
| 704 | out_uars: |
| 705 | for (i--; i >= 0; i--) |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 706 | mlx5_cmd_free_uar(dev->mdev, uars[i].index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 707 | out_count: |
| 708 | kfree(uuari->count); |
| 709 | |
| 710 | out_bitmap: |
| 711 | kfree(uuari->bitmap); |
| 712 | |
| 713 | out_uar_ctx: |
| 714 | kfree(uars); |
| 715 | |
| 716 | out_ctx: |
| 717 | kfree(context); |
| 718 | return ERR_PTR(err); |
| 719 | } |
| 720 | |
| 721 | static int mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
| 722 | { |
| 723 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 724 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
| 725 | struct mlx5_uuar_info *uuari = &context->uuari; |
| 726 | int i; |
| 727 | |
| 728 | for (i = 0; i < uuari->num_uars; i++) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 729 | if (mlx5_cmd_free_uar(dev->mdev, uuari->uars[i].index)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 730 | mlx5_ib_warn(dev, "failed to free UAR 0x%x\n", uuari->uars[i].index); |
| 731 | } |
| 732 | |
| 733 | kfree(uuari->count); |
| 734 | kfree(uuari->bitmap); |
| 735 | kfree(uuari->uars); |
| 736 | kfree(context); |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, int index) |
| 742 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 743 | return (pci_resource_start(dev->mdev->pdev, 0) >> PAGE_SHIFT) + index; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static int get_command(unsigned long offset) |
| 747 | { |
| 748 | return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK; |
| 749 | } |
| 750 | |
| 751 | static int get_arg(unsigned long offset) |
| 752 | { |
| 753 | return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1); |
| 754 | } |
| 755 | |
| 756 | static int get_index(unsigned long offset) |
| 757 | { |
| 758 | return get_arg(offset); |
| 759 | } |
| 760 | |
| 761 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
| 762 | { |
| 763 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 764 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
| 765 | struct mlx5_uuar_info *uuari = &context->uuari; |
| 766 | unsigned long command; |
| 767 | unsigned long idx; |
| 768 | phys_addr_t pfn; |
| 769 | |
| 770 | command = get_command(vma->vm_pgoff); |
| 771 | switch (command) { |
| 772 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 773 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 774 | return -EINVAL; |
| 775 | |
| 776 | idx = get_index(vma->vm_pgoff); |
Eli Cohen | 1c3ce90 | 2014-09-14 16:47:53 +0300 | [diff] [blame] | 777 | if (idx >= uuari->num_uars) |
| 778 | return -EINVAL; |
| 779 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 780 | pfn = uar_index2pfn(dev, uuari->uars[idx].index); |
| 781 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn 0x%llx\n", idx, |
| 782 | (unsigned long long)pfn); |
| 783 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 784 | vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); |
| 785 | if (io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 786 | PAGE_SIZE, vma->vm_page_prot)) |
| 787 | return -EAGAIN; |
| 788 | |
| 789 | mlx5_ib_dbg(dev, "mapped WC at 0x%lx, PA 0x%llx\n", |
| 790 | vma->vm_start, |
| 791 | (unsigned long long)pfn << PAGE_SHIFT); |
| 792 | break; |
| 793 | |
| 794 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
| 795 | return -ENOSYS; |
| 796 | |
| 797 | default: |
| 798 | return -EINVAL; |
| 799 | } |
| 800 | |
| 801 | return 0; |
| 802 | } |
| 803 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 804 | static struct ib_pd *mlx5_ib_alloc_pd(struct ib_device *ibdev, |
| 805 | struct ib_ucontext *context, |
| 806 | struct ib_udata *udata) |
| 807 | { |
| 808 | struct mlx5_ib_alloc_pd_resp resp; |
| 809 | struct mlx5_ib_pd *pd; |
| 810 | int err; |
| 811 | |
| 812 | pd = kmalloc(sizeof(*pd), GFP_KERNEL); |
| 813 | if (!pd) |
| 814 | return ERR_PTR(-ENOMEM); |
| 815 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 816 | err = mlx5_core_alloc_pd(to_mdev(ibdev)->mdev, &pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 817 | if (err) { |
| 818 | kfree(pd); |
| 819 | return ERR_PTR(err); |
| 820 | } |
| 821 | |
| 822 | if (context) { |
| 823 | resp.pdn = pd->pdn; |
| 824 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 825 | mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 826 | kfree(pd); |
| 827 | return ERR_PTR(-EFAULT); |
| 828 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | return &pd->ibpd; |
| 832 | } |
| 833 | |
| 834 | static int mlx5_ib_dealloc_pd(struct ib_pd *pd) |
| 835 | { |
| 836 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 837 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
| 838 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 839 | mlx5_core_dealloc_pd(mdev->mdev, mpd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 840 | kfree(mpd); |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 846 | { |
| 847 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 848 | int err; |
| 849 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 850 | err = mlx5_core_attach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 851 | if (err) |
| 852 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
| 853 | ibqp->qp_num, gid->raw); |
| 854 | |
| 855 | return err; |
| 856 | } |
| 857 | |
| 858 | static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 859 | { |
| 860 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 861 | int err; |
| 862 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 863 | err = mlx5_core_detach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 864 | if (err) |
| 865 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
| 866 | ibqp->qp_num, gid->raw); |
| 867 | |
| 868 | return err; |
| 869 | } |
| 870 | |
| 871 | static int init_node_data(struct mlx5_ib_dev *dev) |
| 872 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 873 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 874 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 875 | err = mlx5_query_node_desc(dev, dev->ib_dev.node_desc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 876 | if (err) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 877 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 878 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 879 | dev->mdev->rev_id = dev->mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 880 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 881 | return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | static ssize_t show_fw_pages(struct device *device, struct device_attribute *attr, |
| 885 | char *buf) |
| 886 | { |
| 887 | struct mlx5_ib_dev *dev = |
| 888 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 889 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 890 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | static ssize_t show_reg_pages(struct device *device, |
| 894 | struct device_attribute *attr, char *buf) |
| 895 | { |
| 896 | struct mlx5_ib_dev *dev = |
| 897 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 898 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 899 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | static ssize_t show_hca(struct device *device, struct device_attribute *attr, |
| 903 | char *buf) |
| 904 | { |
| 905 | struct mlx5_ib_dev *dev = |
| 906 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 907 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr, |
| 911 | char *buf) |
| 912 | { |
| 913 | struct mlx5_ib_dev *dev = |
| 914 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 915 | return sprintf(buf, "%d.%d.%d\n", fw_rev_maj(dev->mdev), |
| 916 | fw_rev_min(dev->mdev), fw_rev_sub(dev->mdev)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
| 920 | char *buf) |
| 921 | { |
| 922 | struct mlx5_ib_dev *dev = |
| 923 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 924 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | static ssize_t show_board(struct device *device, struct device_attribute *attr, |
| 928 | char *buf) |
| 929 | { |
| 930 | struct mlx5_ib_dev *dev = |
| 931 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 932 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 933 | dev->mdev->board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
| 937 | static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL); |
| 938 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 939 | static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
| 940 | static DEVICE_ATTR(fw_pages, S_IRUGO, show_fw_pages, NULL); |
| 941 | static DEVICE_ATTR(reg_pages, S_IRUGO, show_reg_pages, NULL); |
| 942 | |
| 943 | static struct device_attribute *mlx5_class_attributes[] = { |
| 944 | &dev_attr_hw_rev, |
| 945 | &dev_attr_fw_ver, |
| 946 | &dev_attr_hca_type, |
| 947 | &dev_attr_board_id, |
| 948 | &dev_attr_fw_pages, |
| 949 | &dev_attr_reg_pages, |
| 950 | }; |
| 951 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 952 | static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context, |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 953 | enum mlx5_dev_event event, unsigned long param) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 954 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 955 | struct mlx5_ib_dev *ibdev = (struct mlx5_ib_dev *)context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 956 | struct ib_event ibev; |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 957 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 958 | u8 port = 0; |
| 959 | |
| 960 | switch (event) { |
| 961 | case MLX5_DEV_EVENT_SYS_ERROR: |
| 962 | ibdev->ib_active = false; |
| 963 | ibev.event = IB_EVENT_DEVICE_FATAL; |
| 964 | break; |
| 965 | |
| 966 | case MLX5_DEV_EVENT_PORT_UP: |
| 967 | ibev.event = IB_EVENT_PORT_ACTIVE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 968 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 969 | break; |
| 970 | |
| 971 | case MLX5_DEV_EVENT_PORT_DOWN: |
| 972 | ibev.event = IB_EVENT_PORT_ERR; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 973 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 974 | break; |
| 975 | |
| 976 | case MLX5_DEV_EVENT_PORT_INITIALIZED: |
| 977 | /* not used by ULPs */ |
| 978 | return; |
| 979 | |
| 980 | case MLX5_DEV_EVENT_LID_CHANGE: |
| 981 | ibev.event = IB_EVENT_LID_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 982 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 983 | break; |
| 984 | |
| 985 | case MLX5_DEV_EVENT_PKEY_CHANGE: |
| 986 | ibev.event = IB_EVENT_PKEY_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 987 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 988 | break; |
| 989 | |
| 990 | case MLX5_DEV_EVENT_GUID_CHANGE: |
| 991 | ibev.event = IB_EVENT_GID_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 992 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 993 | break; |
| 994 | |
| 995 | case MLX5_DEV_EVENT_CLIENT_REREG: |
| 996 | ibev.event = IB_EVENT_CLIENT_REREGISTER; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 997 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 998 | break; |
| 999 | } |
| 1000 | |
| 1001 | ibev.device = &ibdev->ib_dev; |
| 1002 | ibev.element.port_num = port; |
| 1003 | |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 1004 | if (port < 1 || port > ibdev->num_ports) { |
| 1005 | mlx5_ib_warn(ibdev, "warning: event on port %d\n", port); |
| 1006 | return; |
| 1007 | } |
| 1008 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1009 | if (ibdev->ib_active) |
| 1010 | ib_dispatch_event(&ibev); |
| 1011 | } |
| 1012 | |
| 1013 | static void get_ext_port_caps(struct mlx5_ib_dev *dev) |
| 1014 | { |
| 1015 | int port; |
| 1016 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1017 | for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1018 | mlx5_query_ext_port_caps(dev, port); |
| 1019 | } |
| 1020 | |
| 1021 | static int get_port_caps(struct mlx5_ib_dev *dev) |
| 1022 | { |
| 1023 | struct ib_device_attr *dprops = NULL; |
| 1024 | struct ib_port_attr *pprops = NULL; |
Dan Carpenter | f614fc1 | 2015-01-12 11:56:58 +0300 | [diff] [blame] | 1025 | int err = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1026 | int port; |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 1027 | struct ib_udata uhw = {.inlen = 0, .outlen = 0}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1028 | |
| 1029 | pprops = kmalloc(sizeof(*pprops), GFP_KERNEL); |
| 1030 | if (!pprops) |
| 1031 | goto out; |
| 1032 | |
| 1033 | dprops = kmalloc(sizeof(*dprops), GFP_KERNEL); |
| 1034 | if (!dprops) |
| 1035 | goto out; |
| 1036 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 1037 | err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1038 | if (err) { |
| 1039 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
| 1040 | goto out; |
| 1041 | } |
| 1042 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1043 | for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1044 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
| 1045 | if (err) { |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1046 | mlx5_ib_warn(dev, "query_port %d failed %d\n", |
| 1047 | port, err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1048 | break; |
| 1049 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1050 | dev->mdev->port_caps[port - 1].pkey_table_len = |
| 1051 | dprops->max_pkeys; |
| 1052 | dev->mdev->port_caps[port - 1].gid_table_len = |
| 1053 | pprops->gid_tbl_len; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1054 | mlx5_ib_dbg(dev, "pkey_table_len %d, gid_table_len %d\n", |
| 1055 | dprops->max_pkeys, pprops->gid_tbl_len); |
| 1056 | } |
| 1057 | |
| 1058 | out: |
| 1059 | kfree(pprops); |
| 1060 | kfree(dprops); |
| 1061 | |
| 1062 | return err; |
| 1063 | } |
| 1064 | |
| 1065 | static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
| 1066 | { |
| 1067 | int err; |
| 1068 | |
| 1069 | err = mlx5_mr_cache_cleanup(dev); |
| 1070 | if (err) |
| 1071 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
| 1072 | |
| 1073 | mlx5_ib_destroy_qp(dev->umrc.qp); |
| 1074 | ib_destroy_cq(dev->umrc.cq); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1075 | ib_dealloc_pd(dev->umrc.pd); |
| 1076 | } |
| 1077 | |
| 1078 | enum { |
| 1079 | MAX_UMR_WR = 128, |
| 1080 | }; |
| 1081 | |
| 1082 | static int create_umr_res(struct mlx5_ib_dev *dev) |
| 1083 | { |
| 1084 | struct ib_qp_init_attr *init_attr = NULL; |
| 1085 | struct ib_qp_attr *attr = NULL; |
| 1086 | struct ib_pd *pd; |
| 1087 | struct ib_cq *cq; |
| 1088 | struct ib_qp *qp; |
Matan Barak | 8e37210 | 2015-06-11 16:35:21 +0300 | [diff] [blame] | 1089 | struct ib_cq_init_attr cq_attr = {}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1090 | int ret; |
| 1091 | |
| 1092 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| 1093 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 1094 | if (!attr || !init_attr) { |
| 1095 | ret = -ENOMEM; |
| 1096 | goto error_0; |
| 1097 | } |
| 1098 | |
| 1099 | pd = ib_alloc_pd(&dev->ib_dev); |
| 1100 | if (IS_ERR(pd)) { |
| 1101 | mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); |
| 1102 | ret = PTR_ERR(pd); |
| 1103 | goto error_0; |
| 1104 | } |
| 1105 | |
Matan Barak | 8e37210 | 2015-06-11 16:35:21 +0300 | [diff] [blame] | 1106 | cq_attr.cqe = 128; |
| 1107 | cq = ib_create_cq(&dev->ib_dev, mlx5_umr_cq_handler, NULL, NULL, |
| 1108 | &cq_attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1109 | if (IS_ERR(cq)) { |
| 1110 | mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); |
| 1111 | ret = PTR_ERR(cq); |
| 1112 | goto error_2; |
| 1113 | } |
| 1114 | ib_req_notify_cq(cq, IB_CQ_NEXT_COMP); |
| 1115 | |
| 1116 | init_attr->send_cq = cq; |
| 1117 | init_attr->recv_cq = cq; |
| 1118 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
| 1119 | init_attr->cap.max_send_wr = MAX_UMR_WR; |
| 1120 | init_attr->cap.max_send_sge = 1; |
| 1121 | init_attr->qp_type = MLX5_IB_QPT_REG_UMR; |
| 1122 | init_attr->port_num = 1; |
| 1123 | qp = mlx5_ib_create_qp(pd, init_attr, NULL); |
| 1124 | if (IS_ERR(qp)) { |
| 1125 | mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); |
| 1126 | ret = PTR_ERR(qp); |
| 1127 | goto error_3; |
| 1128 | } |
| 1129 | qp->device = &dev->ib_dev; |
| 1130 | qp->real_qp = qp; |
| 1131 | qp->uobject = NULL; |
| 1132 | qp->qp_type = MLX5_IB_QPT_REG_UMR; |
| 1133 | |
| 1134 | attr->qp_state = IB_QPS_INIT; |
| 1135 | attr->port_num = 1; |
| 1136 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX | |
| 1137 | IB_QP_PORT, NULL); |
| 1138 | if (ret) { |
| 1139 | mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); |
| 1140 | goto error_4; |
| 1141 | } |
| 1142 | |
| 1143 | memset(attr, 0, sizeof(*attr)); |
| 1144 | attr->qp_state = IB_QPS_RTR; |
| 1145 | attr->path_mtu = IB_MTU_256; |
| 1146 | |
| 1147 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 1148 | if (ret) { |
| 1149 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); |
| 1150 | goto error_4; |
| 1151 | } |
| 1152 | |
| 1153 | memset(attr, 0, sizeof(*attr)); |
| 1154 | attr->qp_state = IB_QPS_RTS; |
| 1155 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 1156 | if (ret) { |
| 1157 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); |
| 1158 | goto error_4; |
| 1159 | } |
| 1160 | |
| 1161 | dev->umrc.qp = qp; |
| 1162 | dev->umrc.cq = cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1163 | dev->umrc.pd = pd; |
| 1164 | |
| 1165 | sema_init(&dev->umrc.sem, MAX_UMR_WR); |
| 1166 | ret = mlx5_mr_cache_init(dev); |
| 1167 | if (ret) { |
| 1168 | mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); |
| 1169 | goto error_4; |
| 1170 | } |
| 1171 | |
| 1172 | kfree(attr); |
| 1173 | kfree(init_attr); |
| 1174 | |
| 1175 | return 0; |
| 1176 | |
| 1177 | error_4: |
| 1178 | mlx5_ib_destroy_qp(qp); |
| 1179 | |
| 1180 | error_3: |
| 1181 | ib_destroy_cq(cq); |
| 1182 | |
| 1183 | error_2: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1184 | ib_dealloc_pd(pd); |
| 1185 | |
| 1186 | error_0: |
| 1187 | kfree(attr); |
| 1188 | kfree(init_attr); |
| 1189 | return ret; |
| 1190 | } |
| 1191 | |
| 1192 | static int create_dev_resources(struct mlx5_ib_resources *devr) |
| 1193 | { |
| 1194 | struct ib_srq_init_attr attr; |
| 1195 | struct mlx5_ib_dev *dev; |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 1196 | struct ib_cq_init_attr cq_attr = {.cqe = 1}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1197 | int ret = 0; |
| 1198 | |
| 1199 | dev = container_of(devr, struct mlx5_ib_dev, devr); |
| 1200 | |
| 1201 | devr->p0 = mlx5_ib_alloc_pd(&dev->ib_dev, NULL, NULL); |
| 1202 | if (IS_ERR(devr->p0)) { |
| 1203 | ret = PTR_ERR(devr->p0); |
| 1204 | goto error0; |
| 1205 | } |
| 1206 | devr->p0->device = &dev->ib_dev; |
| 1207 | devr->p0->uobject = NULL; |
| 1208 | atomic_set(&devr->p0->usecnt, 0); |
| 1209 | |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 1210 | devr->c0 = mlx5_ib_create_cq(&dev->ib_dev, &cq_attr, NULL, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1211 | if (IS_ERR(devr->c0)) { |
| 1212 | ret = PTR_ERR(devr->c0); |
| 1213 | goto error1; |
| 1214 | } |
| 1215 | devr->c0->device = &dev->ib_dev; |
| 1216 | devr->c0->uobject = NULL; |
| 1217 | devr->c0->comp_handler = NULL; |
| 1218 | devr->c0->event_handler = NULL; |
| 1219 | devr->c0->cq_context = NULL; |
| 1220 | atomic_set(&devr->c0->usecnt, 0); |
| 1221 | |
| 1222 | devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 1223 | if (IS_ERR(devr->x0)) { |
| 1224 | ret = PTR_ERR(devr->x0); |
| 1225 | goto error2; |
| 1226 | } |
| 1227 | devr->x0->device = &dev->ib_dev; |
| 1228 | devr->x0->inode = NULL; |
| 1229 | atomic_set(&devr->x0->usecnt, 0); |
| 1230 | mutex_init(&devr->x0->tgt_qp_mutex); |
| 1231 | INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
| 1232 | |
| 1233 | devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 1234 | if (IS_ERR(devr->x1)) { |
| 1235 | ret = PTR_ERR(devr->x1); |
| 1236 | goto error3; |
| 1237 | } |
| 1238 | devr->x1->device = &dev->ib_dev; |
| 1239 | devr->x1->inode = NULL; |
| 1240 | atomic_set(&devr->x1->usecnt, 0); |
| 1241 | mutex_init(&devr->x1->tgt_qp_mutex); |
| 1242 | INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
| 1243 | |
| 1244 | memset(&attr, 0, sizeof(attr)); |
| 1245 | attr.attr.max_sge = 1; |
| 1246 | attr.attr.max_wr = 1; |
| 1247 | attr.srq_type = IB_SRQT_XRC; |
| 1248 | attr.ext.xrc.cq = devr->c0; |
| 1249 | attr.ext.xrc.xrcd = devr->x0; |
| 1250 | |
| 1251 | devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 1252 | if (IS_ERR(devr->s0)) { |
| 1253 | ret = PTR_ERR(devr->s0); |
| 1254 | goto error4; |
| 1255 | } |
| 1256 | devr->s0->device = &dev->ib_dev; |
| 1257 | devr->s0->pd = devr->p0; |
| 1258 | devr->s0->uobject = NULL; |
| 1259 | devr->s0->event_handler = NULL; |
| 1260 | devr->s0->srq_context = NULL; |
| 1261 | devr->s0->srq_type = IB_SRQT_XRC; |
| 1262 | devr->s0->ext.xrc.xrcd = devr->x0; |
| 1263 | devr->s0->ext.xrc.cq = devr->c0; |
| 1264 | atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
| 1265 | atomic_inc(&devr->s0->ext.xrc.cq->usecnt); |
| 1266 | atomic_inc(&devr->p0->usecnt); |
| 1267 | atomic_set(&devr->s0->usecnt, 0); |
| 1268 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 1269 | memset(&attr, 0, sizeof(attr)); |
| 1270 | attr.attr.max_sge = 1; |
| 1271 | attr.attr.max_wr = 1; |
| 1272 | attr.srq_type = IB_SRQT_BASIC; |
| 1273 | devr->s1 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 1274 | if (IS_ERR(devr->s1)) { |
| 1275 | ret = PTR_ERR(devr->s1); |
| 1276 | goto error5; |
| 1277 | } |
| 1278 | devr->s1->device = &dev->ib_dev; |
| 1279 | devr->s1->pd = devr->p0; |
| 1280 | devr->s1->uobject = NULL; |
| 1281 | devr->s1->event_handler = NULL; |
| 1282 | devr->s1->srq_context = NULL; |
| 1283 | devr->s1->srq_type = IB_SRQT_BASIC; |
| 1284 | devr->s1->ext.xrc.cq = devr->c0; |
| 1285 | atomic_inc(&devr->p0->usecnt); |
| 1286 | atomic_set(&devr->s0->usecnt, 0); |
| 1287 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1288 | return 0; |
| 1289 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 1290 | error5: |
| 1291 | mlx5_ib_destroy_srq(devr->s0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1292 | error4: |
| 1293 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 1294 | error3: |
| 1295 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 1296 | error2: |
| 1297 | mlx5_ib_destroy_cq(devr->c0); |
| 1298 | error1: |
| 1299 | mlx5_ib_dealloc_pd(devr->p0); |
| 1300 | error0: |
| 1301 | return ret; |
| 1302 | } |
| 1303 | |
| 1304 | static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
| 1305 | { |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 1306 | mlx5_ib_destroy_srq(devr->s1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1307 | mlx5_ib_destroy_srq(devr->s0); |
| 1308 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 1309 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 1310 | mlx5_ib_destroy_cq(devr->c0); |
| 1311 | mlx5_ib_dealloc_pd(devr->p0); |
| 1312 | } |
| 1313 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 1314 | static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 1315 | struct ib_port_immutable *immutable) |
| 1316 | { |
| 1317 | struct ib_port_attr attr; |
| 1318 | int err; |
| 1319 | |
| 1320 | err = mlx5_ib_query_port(ibdev, port_num, &attr); |
| 1321 | if (err) |
| 1322 | return err; |
| 1323 | |
| 1324 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 1325 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Ira Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 1326 | immutable->core_cap_flags = RDMA_CORE_PORT_IBA_IB; |
Ira Weiny | 337877a | 2015-06-06 14:38:29 -0400 | [diff] [blame] | 1327 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 1328 | |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1332 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1333 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1334 | struct mlx5_ib_dev *dev; |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame^] | 1335 | enum rdma_link_layer ll; |
| 1336 | int port_type_cap; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1337 | int err; |
| 1338 | int i; |
| 1339 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame^] | 1340 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 1341 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 1342 | |
Majd Dibbiny | 647241e | 2015-06-04 19:30:47 +0300 | [diff] [blame] | 1343 | /* don't create IB instance over Eth ports, no RoCE yet! */ |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame^] | 1344 | if (ll == IB_LINK_LAYER_ETHERNET) |
Majd Dibbiny | 647241e | 2015-06-04 19:30:47 +0300 | [diff] [blame] | 1345 | return NULL; |
| 1346 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1347 | printk_once(KERN_INFO "%s", mlx5_version); |
| 1348 | |
| 1349 | dev = (struct mlx5_ib_dev *)ib_alloc_device(sizeof(*dev)); |
| 1350 | if (!dev) |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1351 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1352 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1353 | dev->mdev = mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1354 | |
| 1355 | err = get_port_caps(dev); |
| 1356 | if (err) |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1357 | goto err_dealloc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1358 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1359 | if (mlx5_use_mad_ifc(dev)) |
| 1360 | get_ext_port_caps(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1361 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1362 | MLX5_INIT_DOORBELL_LOCK(&dev->uar_lock); |
| 1363 | |
| 1364 | strlcpy(dev->ib_dev.name, "mlx5_%d", IB_DEVICE_NAME_MAX); |
| 1365 | dev->ib_dev.owner = THIS_MODULE; |
| 1366 | dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Sagi Grimberg | c6790aa | 2015-09-24 10:34:23 +0300 | [diff] [blame] | 1367 | dev->ib_dev.local_dma_lkey = 0 /* not supported for now */; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1368 | dev->num_ports = MLX5_CAP_GEN(mdev, num_ports); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1369 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 1370 | dev->ib_dev.num_comp_vectors = |
| 1371 | dev->mdev->priv.eq_table.num_comp_vectors; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1372 | dev->ib_dev.dma_device = &mdev->pdev->dev; |
| 1373 | |
| 1374 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
| 1375 | dev->ib_dev.uverbs_cmd_mask = |
| 1376 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 1377 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 1378 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 1379 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 1380 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
| 1381 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
| 1382 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 1383 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 1384 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 1385 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 1386 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 1387 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 1388 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 1389 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 1390 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 1391 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 1392 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 1393 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 1394 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 1395 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 1396 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 1397 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 1398 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Haggai Eran | 1707cb4 | 2015-02-08 13:28:52 +0200 | [diff] [blame] | 1399 | dev->ib_dev.uverbs_ex_cmd_mask = |
| 1400 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1401 | |
| 1402 | dev->ib_dev.query_device = mlx5_ib_query_device; |
| 1403 | dev->ib_dev.query_port = mlx5_ib_query_port; |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame^] | 1404 | dev->ib_dev.get_link_layer = mlx5_ib_port_link_layer; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1405 | dev->ib_dev.query_gid = mlx5_ib_query_gid; |
| 1406 | dev->ib_dev.query_pkey = mlx5_ib_query_pkey; |
| 1407 | dev->ib_dev.modify_device = mlx5_ib_modify_device; |
| 1408 | dev->ib_dev.modify_port = mlx5_ib_modify_port; |
| 1409 | dev->ib_dev.alloc_ucontext = mlx5_ib_alloc_ucontext; |
| 1410 | dev->ib_dev.dealloc_ucontext = mlx5_ib_dealloc_ucontext; |
| 1411 | dev->ib_dev.mmap = mlx5_ib_mmap; |
| 1412 | dev->ib_dev.alloc_pd = mlx5_ib_alloc_pd; |
| 1413 | dev->ib_dev.dealloc_pd = mlx5_ib_dealloc_pd; |
| 1414 | dev->ib_dev.create_ah = mlx5_ib_create_ah; |
| 1415 | dev->ib_dev.query_ah = mlx5_ib_query_ah; |
| 1416 | dev->ib_dev.destroy_ah = mlx5_ib_destroy_ah; |
| 1417 | dev->ib_dev.create_srq = mlx5_ib_create_srq; |
| 1418 | dev->ib_dev.modify_srq = mlx5_ib_modify_srq; |
| 1419 | dev->ib_dev.query_srq = mlx5_ib_query_srq; |
| 1420 | dev->ib_dev.destroy_srq = mlx5_ib_destroy_srq; |
| 1421 | dev->ib_dev.post_srq_recv = mlx5_ib_post_srq_recv; |
| 1422 | dev->ib_dev.create_qp = mlx5_ib_create_qp; |
| 1423 | dev->ib_dev.modify_qp = mlx5_ib_modify_qp; |
| 1424 | dev->ib_dev.query_qp = mlx5_ib_query_qp; |
| 1425 | dev->ib_dev.destroy_qp = mlx5_ib_destroy_qp; |
| 1426 | dev->ib_dev.post_send = mlx5_ib_post_send; |
| 1427 | dev->ib_dev.post_recv = mlx5_ib_post_recv; |
| 1428 | dev->ib_dev.create_cq = mlx5_ib_create_cq; |
| 1429 | dev->ib_dev.modify_cq = mlx5_ib_modify_cq; |
| 1430 | dev->ib_dev.resize_cq = mlx5_ib_resize_cq; |
| 1431 | dev->ib_dev.destroy_cq = mlx5_ib_destroy_cq; |
| 1432 | dev->ib_dev.poll_cq = mlx5_ib_poll_cq; |
| 1433 | dev->ib_dev.req_notify_cq = mlx5_ib_arm_cq; |
| 1434 | dev->ib_dev.get_dma_mr = mlx5_ib_get_dma_mr; |
| 1435 | dev->ib_dev.reg_user_mr = mlx5_ib_reg_user_mr; |
| 1436 | dev->ib_dev.dereg_mr = mlx5_ib_dereg_mr; |
| 1437 | dev->ib_dev.attach_mcast = mlx5_ib_mcg_attach; |
| 1438 | dev->ib_dev.detach_mcast = mlx5_ib_mcg_detach; |
| 1439 | dev->ib_dev.process_mad = mlx5_ib_process_mad; |
Sagi Grimberg | 9bee178 | 2015-07-30 10:32:35 +0300 | [diff] [blame] | 1440 | dev->ib_dev.alloc_mr = mlx5_ib_alloc_mr; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 1441 | dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg; |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 1442 | dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 1443 | dev->ib_dev.get_port_immutable = mlx5_port_immutable; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1444 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1445 | mlx5_ib_internal_fill_odp_caps(dev); |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 1446 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1447 | if (MLX5_CAP_GEN(mdev, xrc)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1448 | dev->ib_dev.alloc_xrcd = mlx5_ib_alloc_xrcd; |
| 1449 | dev->ib_dev.dealloc_xrcd = mlx5_ib_dealloc_xrcd; |
| 1450 | dev->ib_dev.uverbs_cmd_mask |= |
| 1451 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 1452 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
| 1453 | } |
| 1454 | |
| 1455 | err = init_node_data(dev); |
| 1456 | if (err) |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 1457 | goto err_dealloc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1458 | |
| 1459 | mutex_init(&dev->cap_mask_mutex); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1460 | |
| 1461 | err = create_dev_resources(&dev->devr); |
| 1462 | if (err) |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 1463 | goto err_dealloc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1464 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1465 | err = mlx5_ib_odp_init_one(dev); |
Wei Yongjun | 281d1a9 | 2013-07-30 07:54:26 +0800 | [diff] [blame] | 1466 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1467 | goto err_rsrc; |
| 1468 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1469 | err = ib_register_device(&dev->ib_dev, NULL); |
| 1470 | if (err) |
| 1471 | goto err_odp; |
| 1472 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1473 | err = create_umr_res(dev); |
| 1474 | if (err) |
| 1475 | goto err_dev; |
| 1476 | |
| 1477 | for (i = 0; i < ARRAY_SIZE(mlx5_class_attributes); i++) { |
Wei Yongjun | 281d1a9 | 2013-07-30 07:54:26 +0800 | [diff] [blame] | 1478 | err = device_create_file(&dev->ib_dev.dev, |
| 1479 | mlx5_class_attributes[i]); |
| 1480 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1481 | goto err_umrc; |
| 1482 | } |
| 1483 | |
| 1484 | dev->ib_active = true; |
| 1485 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1486 | return dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1487 | |
| 1488 | err_umrc: |
| 1489 | destroy_umrc_res(dev); |
| 1490 | |
| 1491 | err_dev: |
| 1492 | ib_unregister_device(&dev->ib_dev); |
| 1493 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1494 | err_odp: |
| 1495 | mlx5_ib_odp_remove_one(dev); |
| 1496 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1497 | err_rsrc: |
| 1498 | destroy_dev_resources(&dev->devr); |
| 1499 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1500 | err_dealloc: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1501 | ib_dealloc_device((struct ib_device *)dev); |
| 1502 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1503 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1504 | } |
| 1505 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1506 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1507 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1508 | struct mlx5_ib_dev *dev = context; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1509 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1510 | ib_unregister_device(&dev->ib_dev); |
Eli Cohen | eefd56e | 2014-09-14 16:47:50 +0300 | [diff] [blame] | 1511 | destroy_umrc_res(dev); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1512 | mlx5_ib_odp_remove_one(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1513 | destroy_dev_resources(&dev->devr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1514 | ib_dealloc_device(&dev->ib_dev); |
| 1515 | } |
| 1516 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1517 | static struct mlx5_interface mlx5_ib_interface = { |
| 1518 | .add = mlx5_ib_add, |
| 1519 | .remove = mlx5_ib_remove, |
| 1520 | .event = mlx5_ib_event, |
Saeed Mahameed | 64613d94 | 2015-04-02 17:07:34 +0300 | [diff] [blame] | 1521 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1522 | }; |
| 1523 | |
| 1524 | static int __init mlx5_ib_init(void) |
| 1525 | { |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1526 | int err; |
| 1527 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1528 | if (deprecated_prof_sel != 2) |
| 1529 | pr_warn("prof_sel is deprecated for mlx5_ib, set it for mlx5_core\n"); |
| 1530 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1531 | err = mlx5_ib_odp_init(); |
| 1532 | if (err) |
| 1533 | return err; |
| 1534 | |
| 1535 | err = mlx5_register_interface(&mlx5_ib_interface); |
| 1536 | if (err) |
| 1537 | goto clean_odp; |
| 1538 | |
| 1539 | return err; |
| 1540 | |
| 1541 | clean_odp: |
| 1542 | mlx5_ib_odp_cleanup(); |
| 1543 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | static void __exit mlx5_ib_cleanup(void) |
| 1547 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1548 | mlx5_unregister_interface(&mlx5_ib_interface); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 1549 | mlx5_ib_odp_cleanup(); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | module_init(mlx5_ib_init); |
| 1553 | module_exit(mlx5_ib_cleanup); |