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