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