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