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