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> |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 40 | #if defined(CONFIG_X86) |
| 41 | #include <asm/pat.h> |
| 42 | #endif |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 43 | #include <linux/sched.h> |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 44 | #include <linux/delay.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 45 | #include <rdma/ib_user_verbs.h> |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 46 | #include <rdma/ib_addr.h> |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 47 | #include <rdma/ib_cache.h> |
Achiad Shochat | ada68c3 | 2016-02-22 18:17:23 +0200 | [diff] [blame] | 48 | #include <linux/mlx5/port.h> |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 49 | #include <linux/mlx5/vport.h> |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 50 | #include <linux/list.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 51 | #include <rdma/ib_smi.h> |
| 52 | #include <rdma/ib_umem.h> |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 53 | #include <linux/in.h> |
| 54 | #include <linux/etherdevice.h> |
| 55 | #include <linux/mlx5/fs.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 56 | #include "mlx5_ib.h" |
| 57 | |
| 58 | #define DRIVER_NAME "mlx5_ib" |
Amir Vadai | 169a1d8 | 2014-02-19 17:47:31 +0200 | [diff] [blame] | 59 | #define DRIVER_VERSION "2.2-1" |
| 60 | #define DRIVER_RELDATE "Feb 2014" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 61 | |
| 62 | MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); |
| 63 | MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); |
| 64 | MODULE_LICENSE("Dual BSD/GPL"); |
| 65 | MODULE_VERSION(DRIVER_VERSION); |
| 66 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 67 | static int deprecated_prof_sel = 2; |
| 68 | module_param_named(prof_sel, deprecated_prof_sel, int, 0444); |
| 69 | 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] | 70 | |
| 71 | static char mlx5_version[] = |
| 72 | DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
| 73 | DRIVER_VERSION " (" DRIVER_RELDATE ")\n"; |
| 74 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 75 | enum { |
| 76 | MLX5_ATOMIC_SIZE_QP_8BYTES = 1 << 3, |
| 77 | }; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 78 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 79 | static enum rdma_link_layer |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 80 | mlx5_port_type_cap_to_rdma_ll(int port_type_cap) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 81 | { |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 82 | switch (port_type_cap) { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 83 | case MLX5_CAP_PORT_TYPE_IB: |
| 84 | return IB_LINK_LAYER_INFINIBAND; |
| 85 | case MLX5_CAP_PORT_TYPE_ETH: |
| 86 | return IB_LINK_LAYER_ETHERNET; |
| 87 | default: |
| 88 | return IB_LINK_LAYER_UNSPECIFIED; |
| 89 | } |
| 90 | } |
| 91 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 92 | static enum rdma_link_layer |
| 93 | mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num) |
| 94 | { |
| 95 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 96 | int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type); |
| 97 | |
| 98 | return mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 99 | } |
| 100 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 101 | static int mlx5_netdev_event(struct notifier_block *this, |
| 102 | unsigned long event, void *ptr) |
| 103 | { |
| 104 | struct net_device *ndev = netdev_notifier_info_to_dev(ptr); |
| 105 | struct mlx5_ib_dev *ibdev = container_of(this, struct mlx5_ib_dev, |
| 106 | roce.nb); |
| 107 | |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 108 | switch (event) { |
| 109 | case NETDEV_REGISTER: |
| 110 | case NETDEV_UNREGISTER: |
| 111 | write_lock(&ibdev->roce.netdev_lock); |
| 112 | if (ndev->dev.parent == &ibdev->mdev->pdev->dev) |
| 113 | ibdev->roce.netdev = (event == NETDEV_UNREGISTER) ? |
| 114 | NULL : ndev; |
| 115 | write_unlock(&ibdev->roce.netdev_lock); |
| 116 | break; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 117 | |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 118 | case NETDEV_UP: |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 119 | case NETDEV_DOWN: { |
| 120 | struct net_device *lag_ndev = mlx5_lag_get_roce_netdev(ibdev->mdev); |
| 121 | struct net_device *upper = NULL; |
| 122 | |
| 123 | if (lag_ndev) { |
| 124 | upper = netdev_master_upper_dev_get(lag_ndev); |
| 125 | dev_put(lag_ndev); |
| 126 | } |
| 127 | |
| 128 | if ((upper == ndev || (!upper && ndev == ibdev->roce.netdev)) |
| 129 | && ibdev->ib_active) { |
Bart Van Assche | 626bc02 | 2016-12-05 17:18:08 -0800 | [diff] [blame] | 130 | struct ib_event ibev = { }; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 131 | |
| 132 | ibev.device = &ibdev->ib_dev; |
| 133 | ibev.event = (event == NETDEV_UP) ? |
| 134 | IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
| 135 | ibev.element.port_num = 1; |
| 136 | ib_dispatch_event(&ibev); |
| 137 | } |
| 138 | break; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 139 | } |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 140 | |
| 141 | default: |
| 142 | break; |
| 143 | } |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 144 | |
| 145 | return NOTIFY_DONE; |
| 146 | } |
| 147 | |
| 148 | static struct net_device *mlx5_ib_get_netdev(struct ib_device *device, |
| 149 | u8 port_num) |
| 150 | { |
| 151 | struct mlx5_ib_dev *ibdev = to_mdev(device); |
| 152 | struct net_device *ndev; |
| 153 | |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 154 | ndev = mlx5_lag_get_roce_netdev(ibdev->mdev); |
| 155 | if (ndev) |
| 156 | return ndev; |
| 157 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 158 | /* Ensure ndev does not disappear before we invoke dev_hold() |
| 159 | */ |
| 160 | read_lock(&ibdev->roce.netdev_lock); |
| 161 | ndev = ibdev->roce.netdev; |
| 162 | if (ndev) |
| 163 | dev_hold(ndev); |
| 164 | read_unlock(&ibdev->roce.netdev_lock); |
| 165 | |
| 166 | return ndev; |
| 167 | } |
| 168 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 169 | static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, |
| 170 | struct ib_port_attr *props) |
| 171 | { |
| 172 | struct mlx5_ib_dev *dev = to_mdev(device); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 173 | struct net_device *ndev, *upper; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 174 | enum ib_mtu ndev_ib_mtu; |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 175 | u16 qkey_viol_cntr; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 176 | |
| 177 | memset(props, 0, sizeof(*props)); |
| 178 | |
| 179 | props->port_cap_flags |= IB_PORT_CM_SUP; |
| 180 | props->port_cap_flags |= IB_PORT_IP_BASED_GIDS; |
| 181 | |
| 182 | props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev, |
| 183 | roce_address_table_size); |
| 184 | props->max_mtu = IB_MTU_4096; |
| 185 | props->max_msg_sz = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg); |
| 186 | props->pkey_tbl_len = 1; |
| 187 | props->state = IB_PORT_DOWN; |
| 188 | props->phys_state = 3; |
| 189 | |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 190 | mlx5_query_nic_vport_qkey_viol_cntr(dev->mdev, &qkey_viol_cntr); |
| 191 | props->qkey_viol_cntr = qkey_viol_cntr; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 192 | |
| 193 | ndev = mlx5_ib_get_netdev(device, port_num); |
| 194 | if (!ndev) |
| 195 | return 0; |
| 196 | |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 197 | if (mlx5_lag_is_active(dev->mdev)) { |
| 198 | rcu_read_lock(); |
| 199 | upper = netdev_master_upper_dev_get_rcu(ndev); |
| 200 | if (upper) { |
| 201 | dev_put(ndev); |
| 202 | ndev = upper; |
| 203 | dev_hold(ndev); |
| 204 | } |
| 205 | rcu_read_unlock(); |
| 206 | } |
| 207 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 208 | if (netif_running(ndev) && netif_carrier_ok(ndev)) { |
| 209 | props->state = IB_PORT_ACTIVE; |
| 210 | props->phys_state = 5; |
| 211 | } |
| 212 | |
| 213 | ndev_ib_mtu = iboe_get_mtu(ndev->mtu); |
| 214 | |
| 215 | dev_put(ndev); |
| 216 | |
| 217 | props->active_mtu = min(props->max_mtu, ndev_ib_mtu); |
| 218 | |
| 219 | props->active_width = IB_WIDTH_4X; /* TODO */ |
| 220 | props->active_speed = IB_SPEED_QDR; /* TODO */ |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 225 | static void ib_gid_to_mlx5_roce_addr(const union ib_gid *gid, |
| 226 | const struct ib_gid_attr *attr, |
| 227 | void *mlx5_addr) |
| 228 | { |
| 229 | #define MLX5_SET_RA(p, f, v) MLX5_SET(roce_addr_layout, p, f, v) |
| 230 | char *mlx5_addr_l3_addr = MLX5_ADDR_OF(roce_addr_layout, mlx5_addr, |
| 231 | source_l3_address); |
| 232 | void *mlx5_addr_mac = MLX5_ADDR_OF(roce_addr_layout, mlx5_addr, |
| 233 | source_mac_47_32); |
| 234 | |
| 235 | if (!gid) |
| 236 | return; |
| 237 | |
| 238 | ether_addr_copy(mlx5_addr_mac, attr->ndev->dev_addr); |
| 239 | |
| 240 | if (is_vlan_dev(attr->ndev)) { |
| 241 | MLX5_SET_RA(mlx5_addr, vlan_valid, 1); |
| 242 | MLX5_SET_RA(mlx5_addr, vlan_id, vlan_dev_vlan_id(attr->ndev)); |
| 243 | } |
| 244 | |
| 245 | switch (attr->gid_type) { |
| 246 | case IB_GID_TYPE_IB: |
| 247 | MLX5_SET_RA(mlx5_addr, roce_version, MLX5_ROCE_VERSION_1); |
| 248 | break; |
| 249 | case IB_GID_TYPE_ROCE_UDP_ENCAP: |
| 250 | MLX5_SET_RA(mlx5_addr, roce_version, MLX5_ROCE_VERSION_2); |
| 251 | break; |
| 252 | |
| 253 | default: |
| 254 | WARN_ON(true); |
| 255 | } |
| 256 | |
| 257 | if (attr->gid_type != IB_GID_TYPE_IB) { |
| 258 | if (ipv6_addr_v4mapped((void *)gid)) |
| 259 | MLX5_SET_RA(mlx5_addr, roce_l3_type, |
| 260 | MLX5_ROCE_L3_TYPE_IPV4); |
| 261 | else |
| 262 | MLX5_SET_RA(mlx5_addr, roce_l3_type, |
| 263 | MLX5_ROCE_L3_TYPE_IPV6); |
| 264 | } |
| 265 | |
| 266 | if ((attr->gid_type == IB_GID_TYPE_IB) || |
| 267 | !ipv6_addr_v4mapped((void *)gid)) |
| 268 | memcpy(mlx5_addr_l3_addr, gid, sizeof(*gid)); |
| 269 | else |
| 270 | memcpy(&mlx5_addr_l3_addr[12], &gid->raw[12], 4); |
| 271 | } |
| 272 | |
| 273 | static int set_roce_addr(struct ib_device *device, u8 port_num, |
| 274 | unsigned int index, |
| 275 | const union ib_gid *gid, |
| 276 | const struct ib_gid_attr *attr) |
| 277 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 278 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 279 | u32 in[MLX5_ST_SZ_DW(set_roce_address_in)] = {0}; |
| 280 | u32 out[MLX5_ST_SZ_DW(set_roce_address_out)] = {0}; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 281 | void *in_addr = MLX5_ADDR_OF(set_roce_address_in, in, roce_address); |
| 282 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(device, port_num); |
| 283 | |
| 284 | if (ll != IB_LINK_LAYER_ETHERNET) |
| 285 | return -EINVAL; |
| 286 | |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 287 | ib_gid_to_mlx5_roce_addr(gid, attr, in_addr); |
| 288 | |
| 289 | MLX5_SET(set_roce_address_in, in, roce_address_index, index); |
| 290 | MLX5_SET(set_roce_address_in, in, opcode, MLX5_CMD_OP_SET_ROCE_ADDRESS); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 291 | return mlx5_cmd_exec(dev->mdev, in, sizeof(in), out, sizeof(out)); |
| 292 | } |
| 293 | |
| 294 | static int mlx5_ib_add_gid(struct ib_device *device, u8 port_num, |
| 295 | unsigned int index, const union ib_gid *gid, |
| 296 | const struct ib_gid_attr *attr, |
| 297 | __always_unused void **context) |
| 298 | { |
| 299 | return set_roce_addr(device, port_num, index, gid, attr); |
| 300 | } |
| 301 | |
| 302 | static int mlx5_ib_del_gid(struct ib_device *device, u8 port_num, |
| 303 | unsigned int index, __always_unused void **context) |
| 304 | { |
| 305 | return set_roce_addr(device, port_num, index, NULL, NULL); |
| 306 | } |
| 307 | |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 308 | __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num, |
| 309 | int index) |
| 310 | { |
| 311 | struct ib_gid_attr attr; |
| 312 | union ib_gid gid; |
| 313 | |
| 314 | if (ib_get_cached_gid(&dev->ib_dev, port_num, index, &gid, &attr)) |
| 315 | return 0; |
| 316 | |
| 317 | if (!attr.ndev) |
| 318 | return 0; |
| 319 | |
| 320 | dev_put(attr.ndev); |
| 321 | |
| 322 | if (attr.gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP) |
| 323 | return 0; |
| 324 | |
| 325 | return cpu_to_be16(MLX5_CAP_ROCE(dev->mdev, r_roce_min_src_udp_port)); |
| 326 | } |
| 327 | |
Majd Dibbiny | ed88451 | 2017-01-18 14:10:35 +0200 | [diff] [blame^] | 328 | int mlx5_get_roce_gid_type(struct mlx5_ib_dev *dev, u8 port_num, |
| 329 | int index, enum ib_gid_type *gid_type) |
| 330 | { |
| 331 | struct ib_gid_attr attr; |
| 332 | union ib_gid gid; |
| 333 | int ret; |
| 334 | |
| 335 | ret = ib_get_cached_gid(&dev->ib_dev, port_num, index, &gid, &attr); |
| 336 | if (ret) |
| 337 | return ret; |
| 338 | |
| 339 | if (!attr.ndev) |
| 340 | return -ENODEV; |
| 341 | |
| 342 | dev_put(attr.ndev); |
| 343 | |
| 344 | *gid_type = attr.gid_type; |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 349 | static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) |
| 350 | { |
Noa Osherovich | 7fae665 | 2016-09-12 19:16:23 +0300 | [diff] [blame] | 351 | if (MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_IB) |
| 352 | return !MLX5_CAP_GEN(dev->mdev, ib_virt); |
| 353 | return 0; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | enum { |
| 357 | MLX5_VPORT_ACCESS_METHOD_MAD, |
| 358 | MLX5_VPORT_ACCESS_METHOD_HCA, |
| 359 | MLX5_VPORT_ACCESS_METHOD_NIC, |
| 360 | }; |
| 361 | |
| 362 | static int mlx5_get_vport_access_method(struct ib_device *ibdev) |
| 363 | { |
| 364 | if (mlx5_use_mad_ifc(to_mdev(ibdev))) |
| 365 | return MLX5_VPORT_ACCESS_METHOD_MAD; |
| 366 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 367 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 368 | IB_LINK_LAYER_ETHERNET) |
| 369 | return MLX5_VPORT_ACCESS_METHOD_NIC; |
| 370 | |
| 371 | return MLX5_VPORT_ACCESS_METHOD_HCA; |
| 372 | } |
| 373 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 374 | static void get_atomic_caps(struct mlx5_ib_dev *dev, |
| 375 | struct ib_device_attr *props) |
| 376 | { |
| 377 | u8 tmp; |
| 378 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
| 379 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 380 | u8 atomic_req_8B_endianness_mode = |
| 381 | MLX5_CAP_ATOMIC(dev->mdev, atomic_req_8B_endianess_mode); |
| 382 | |
| 383 | /* Check if HW supports 8 bytes standard atomic operations and capable |
| 384 | * of host endianness respond |
| 385 | */ |
| 386 | tmp = MLX5_ATOMIC_OPS_CMP_SWAP | MLX5_ATOMIC_OPS_FETCH_ADD; |
| 387 | if (((atomic_operations & tmp) == tmp) && |
| 388 | (atomic_size_qp & MLX5_ATOMIC_SIZE_QP_8BYTES) && |
| 389 | (atomic_req_8B_endianness_mode)) { |
| 390 | props->atomic_cap = IB_ATOMIC_HCA; |
| 391 | } else { |
| 392 | props->atomic_cap = IB_ATOMIC_NONE; |
| 393 | } |
| 394 | } |
| 395 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 396 | static int mlx5_query_system_image_guid(struct ib_device *ibdev, |
| 397 | __be64 *sys_image_guid) |
| 398 | { |
| 399 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 400 | struct mlx5_core_dev *mdev = dev->mdev; |
| 401 | u64 tmp; |
| 402 | int err; |
| 403 | |
| 404 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 405 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 406 | return mlx5_query_mad_ifc_system_image_guid(ibdev, |
| 407 | sys_image_guid); |
| 408 | |
| 409 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 410 | err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 411 | break; |
| 412 | |
| 413 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 414 | err = mlx5_query_nic_vport_system_image_guid(mdev, &tmp); |
| 415 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 416 | |
| 417 | default: |
| 418 | return -EINVAL; |
| 419 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 420 | |
| 421 | if (!err) |
| 422 | *sys_image_guid = cpu_to_be64(tmp); |
| 423 | |
| 424 | return err; |
| 425 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static int mlx5_query_max_pkeys(struct ib_device *ibdev, |
| 429 | u16 *max_pkeys) |
| 430 | { |
| 431 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 432 | struct mlx5_core_dev *mdev = dev->mdev; |
| 433 | |
| 434 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 435 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 436 | return mlx5_query_mad_ifc_max_pkeys(ibdev, max_pkeys); |
| 437 | |
| 438 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 439 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 440 | *max_pkeys = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, |
| 441 | pkey_table_size)); |
| 442 | return 0; |
| 443 | |
| 444 | default: |
| 445 | return -EINVAL; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | static int mlx5_query_vendor_id(struct ib_device *ibdev, |
| 450 | u32 *vendor_id) |
| 451 | { |
| 452 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 453 | |
| 454 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 455 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 456 | return mlx5_query_mad_ifc_vendor_id(ibdev, vendor_id); |
| 457 | |
| 458 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 459 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 460 | return mlx5_core_query_vendor_id(dev->mdev, vendor_id); |
| 461 | |
| 462 | default: |
| 463 | return -EINVAL; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | static int mlx5_query_node_guid(struct mlx5_ib_dev *dev, |
| 468 | __be64 *node_guid) |
| 469 | { |
| 470 | u64 tmp; |
| 471 | int err; |
| 472 | |
| 473 | switch (mlx5_get_vport_access_method(&dev->ib_dev)) { |
| 474 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 475 | return mlx5_query_mad_ifc_node_guid(dev, node_guid); |
| 476 | |
| 477 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 478 | err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 479 | break; |
| 480 | |
| 481 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 482 | err = mlx5_query_nic_vport_node_guid(dev->mdev, &tmp); |
| 483 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 484 | |
| 485 | default: |
| 486 | return -EINVAL; |
| 487 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 488 | |
| 489 | if (!err) |
| 490 | *node_guid = cpu_to_be64(tmp); |
| 491 | |
| 492 | return err; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | struct mlx5_reg_node_desc { |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 496 | u8 desc[IB_DEVICE_NODE_DESC_MAX]; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 497 | }; |
| 498 | |
| 499 | static int mlx5_query_node_desc(struct mlx5_ib_dev *dev, char *node_desc) |
| 500 | { |
| 501 | struct mlx5_reg_node_desc in; |
| 502 | |
| 503 | if (mlx5_use_mad_ifc(dev)) |
| 504 | return mlx5_query_mad_ifc_node_desc(dev, node_desc); |
| 505 | |
| 506 | memset(&in, 0, sizeof(in)); |
| 507 | |
| 508 | return mlx5_core_access_reg(dev->mdev, &in, sizeof(in), node_desc, |
| 509 | sizeof(struct mlx5_reg_node_desc), |
| 510 | MLX5_REG_NODE_DESC, 0, 0); |
| 511 | } |
| 512 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 513 | static int mlx5_ib_query_device(struct ib_device *ibdev, |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 514 | struct ib_device_attr *props, |
| 515 | struct ib_udata *uhw) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 516 | { |
| 517 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 518 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 519 | int err = -ENOMEM; |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 520 | int max_sq_desc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 521 | int max_rq_sg; |
| 522 | int max_sq_sg; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 523 | u64 min_page_size = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 524 | struct mlx5_ib_query_device_resp resp = {}; |
| 525 | size_t resp_len; |
| 526 | u64 max_tso; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 527 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 528 | resp_len = sizeof(resp.comp_mask) + sizeof(resp.response_length); |
| 529 | if (uhw->outlen && uhw->outlen < resp_len) |
| 530 | return -EINVAL; |
| 531 | else |
| 532 | resp.response_length = resp_len; |
| 533 | |
| 534 | if (uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen)) |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 535 | return -EINVAL; |
| 536 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 537 | memset(props, 0, sizeof(*props)); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 538 | err = mlx5_query_system_image_guid(ibdev, |
| 539 | &props->sys_image_guid); |
| 540 | if (err) |
| 541 | return err; |
| 542 | |
| 543 | err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys); |
| 544 | if (err) |
| 545 | return err; |
| 546 | |
| 547 | err = mlx5_query_vendor_id(ibdev, &props->vendor_id); |
| 548 | if (err) |
| 549 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 550 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 551 | props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) | |
| 552 | (fw_rev_min(dev->mdev) << 16) | |
| 553 | fw_rev_sub(dev->mdev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 554 | props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | |
| 555 | IB_DEVICE_PORT_ACTIVE_EVENT | |
| 556 | IB_DEVICE_SYS_IMAGE_GUID | |
Eli Cohen | 1a4c3a3 | 2014-02-06 17:41:25 +0200 | [diff] [blame] | 557 | IB_DEVICE_RC_RNR_NAK_GEN; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 558 | |
| 559 | if (MLX5_CAP_GEN(mdev, pkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 560 | props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 561 | if (MLX5_CAP_GEN(mdev, qkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 562 | props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 563 | if (MLX5_CAP_GEN(mdev, apm)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 564 | props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 565 | if (MLX5_CAP_GEN(mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 566 | props->device_cap_flags |= IB_DEVICE_XRC; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 567 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
| 568 | props->device_cap_flags |= IB_DEVICE_MEM_WINDOW | |
| 569 | IB_DEVICE_MEM_WINDOW_TYPE_2B; |
| 570 | props->max_mw = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 571 | /* We support 'Gappy' memory registration too */ |
| 572 | props->device_cap_flags |= IB_DEVICE_SG_GAPS_REG; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 573 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 574 | props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 575 | if (MLX5_CAP_GEN(mdev, sho)) { |
Sagi Grimberg | 2dea909 | 2014-02-23 14:19:13 +0200 | [diff] [blame] | 576 | props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER; |
| 577 | /* At this stage no support for signature handover */ |
| 578 | props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 | |
| 579 | IB_PROT_T10DIF_TYPE_2 | |
| 580 | IB_PROT_T10DIF_TYPE_3; |
| 581 | props->sig_guard_cap = IB_GUARD_T10DIF_CRC | |
| 582 | IB_GUARD_T10DIF_CSUM; |
| 583 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 584 | if (MLX5_CAP_GEN(mdev, block_lb_mc)) |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 585 | props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 586 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 587 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads)) { |
| 588 | if (MLX5_CAP_ETH(mdev, csum_cap)) |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 589 | props->device_cap_flags |= IB_DEVICE_RAW_IP_CSUM; |
| 590 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 591 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) { |
| 592 | max_tso = MLX5_CAP_ETH(mdev, max_lso_cap); |
| 593 | if (max_tso) { |
| 594 | resp.tso_caps.max_tso = 1 << max_tso; |
| 595 | resp.tso_caps.supported_qpts |= |
| 596 | 1 << IB_QPT_RAW_PACKET; |
| 597 | resp.response_length += sizeof(resp.tso_caps); |
| 598 | } |
| 599 | } |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 600 | |
| 601 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) { |
| 602 | resp.rss_caps.rx_hash_function = |
| 603 | MLX5_RX_HASH_FUNC_TOEPLITZ; |
| 604 | resp.rss_caps.rx_hash_fields_mask = |
| 605 | MLX5_RX_HASH_SRC_IPV4 | |
| 606 | MLX5_RX_HASH_DST_IPV4 | |
| 607 | MLX5_RX_HASH_SRC_IPV6 | |
| 608 | MLX5_RX_HASH_DST_IPV6 | |
| 609 | MLX5_RX_HASH_SRC_PORT_TCP | |
| 610 | MLX5_RX_HASH_DST_PORT_TCP | |
| 611 | MLX5_RX_HASH_SRC_PORT_UDP | |
| 612 | MLX5_RX_HASH_DST_PORT_UDP; |
| 613 | resp.response_length += sizeof(resp.rss_caps); |
| 614 | } |
| 615 | } else { |
| 616 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) |
| 617 | resp.response_length += sizeof(resp.tso_caps); |
| 618 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) |
| 619 | resp.response_length += sizeof(resp.rss_caps); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 620 | } |
| 621 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 622 | if (MLX5_CAP_GEN(mdev, ipoib_basic_offloads)) { |
| 623 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 624 | props->device_cap_flags |= IB_DEVICE_UD_TSO; |
| 625 | } |
| 626 | |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 627 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
| 628 | MLX5_CAP_ETH(dev->mdev, scatter_fcs)) |
| 629 | props->device_cap_flags |= IB_DEVICE_RAW_SCATTER_FCS; |
| 630 | |
Maor Gottlieb | da6d6ba3 | 2016-06-04 15:15:28 +0300 | [diff] [blame] | 631 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_BYPASS)) |
| 632 | props->device_cap_flags |= IB_DEVICE_MANAGED_FLOW_STEERING; |
| 633 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 634 | props->vendor_part_id = mdev->pdev->device; |
| 635 | props->hw_ver = mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 636 | |
| 637 | props->max_mr_size = ~0ull; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 638 | props->page_size_cap = ~(min_page_size - 1); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 639 | props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp); |
| 640 | props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
| 641 | max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) / |
| 642 | sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 643 | max_sq_desc = min_t(int, MLX5_CAP_GEN(mdev, max_wqe_sz_sq), 512); |
| 644 | max_sq_sg = (max_sq_desc - sizeof(struct mlx5_wqe_ctrl_seg) - |
| 645 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 646 | sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 647 | props->max_sge = min(max_rq_sg, max_sq_sg); |
Sagi Grimberg | 986ef95 | 2016-03-31 19:03:25 +0300 | [diff] [blame] | 648 | props->max_sge_rd = MLX5_MAX_SGE_RD; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 649 | props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq); |
Leon Romanovsky | 9f17768 | 2016-01-14 08:11:40 +0200 | [diff] [blame] | 650 | 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] | 651 | props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
| 652 | props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd); |
| 653 | props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp); |
| 654 | props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp); |
| 655 | props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq); |
| 656 | props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1; |
| 657 | 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] | 658 | 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] | 659 | props->max_srq_sge = max_rq_sg - 1; |
Sagi Grimberg | 911f433 | 2016-03-03 13:37:51 +0200 | [diff] [blame] | 660 | props->max_fast_reg_page_list_len = |
| 661 | 1 << MLX5_CAP_GEN(mdev, log_max_klm_list_size); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 662 | get_atomic_caps(dev, props); |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 663 | props->masked_atomic_cap = IB_ATOMIC_NONE; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 664 | props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg); |
| 665 | props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 666 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 667 | props->max_mcast_grp; |
| 668 | props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */ |
Maor Gottlieb | 86695a6 | 2016-10-27 16:36:38 +0300 | [diff] [blame] | 669 | props->max_ah = INT_MAX; |
Matan Barak | 7c60bcb | 2015-12-15 20:30:11 +0200 | [diff] [blame] | 670 | props->hca_core_clock = MLX5_CAP_GEN(mdev, device_frequency_khz); |
| 671 | props->timestamp_mask = 0x7FFFFFFFFFFFFFFFULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 672 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 673 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 674 | if (MLX5_CAP_GEN(mdev, pg)) |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 675 | props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
| 676 | props->odp_caps = dev->odp_caps; |
| 677 | #endif |
| 678 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 679 | if (MLX5_CAP_GEN(mdev, cd)) |
| 680 | props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL; |
| 681 | |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 682 | if (!mlx5_core_is_pf(mdev)) |
| 683 | props->device_cap_flags |= IB_DEVICE_VIRTUAL_FUNCTION; |
| 684 | |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 685 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
| 686 | IB_LINK_LAYER_ETHERNET) { |
| 687 | props->rss_caps.max_rwq_indirection_tables = |
| 688 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt); |
| 689 | props->rss_caps.max_rwq_indirection_table_size = |
| 690 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt_size); |
| 691 | props->rss_caps.supported_qpts = 1 << IB_QPT_RAW_PACKET; |
| 692 | props->max_wq_type_rq = |
| 693 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rq); |
| 694 | } |
| 695 | |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 696 | if (field_avail(typeof(resp), cqe_comp_caps, uhw->outlen)) { |
| 697 | resp.cqe_comp_caps.max_num = |
| 698 | MLX5_CAP_GEN(dev->mdev, cqe_compression) ? |
| 699 | MLX5_CAP_GEN(dev->mdev, cqe_compression_max_num) : 0; |
| 700 | resp.cqe_comp_caps.supported_format = |
| 701 | MLX5_IB_CQE_RES_FORMAT_HASH | |
| 702 | MLX5_IB_CQE_RES_FORMAT_CSUM; |
| 703 | resp.response_length += sizeof(resp.cqe_comp_caps); |
| 704 | } |
| 705 | |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 706 | if (field_avail(typeof(resp), packet_pacing_caps, uhw->outlen)) { |
| 707 | if (MLX5_CAP_QOS(mdev, packet_pacing) && |
| 708 | MLX5_CAP_GEN(mdev, qos)) { |
| 709 | resp.packet_pacing_caps.qp_rate_limit_max = |
| 710 | MLX5_CAP_QOS(mdev, packet_pacing_max_rate); |
| 711 | resp.packet_pacing_caps.qp_rate_limit_min = |
| 712 | MLX5_CAP_QOS(mdev, packet_pacing_min_rate); |
| 713 | resp.packet_pacing_caps.supported_qpts |= |
| 714 | 1 << IB_QPT_RAW_PACKET; |
| 715 | } |
| 716 | resp.response_length += sizeof(resp.packet_pacing_caps); |
| 717 | } |
| 718 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 719 | if (field_avail(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes, |
| 720 | uhw->outlen)) { |
| 721 | resp.mlx5_ib_support_multi_pkt_send_wqes = |
| 722 | MLX5_CAP_ETH(mdev, multi_pkt_send_wqe); |
| 723 | resp.response_length += |
| 724 | sizeof(resp.mlx5_ib_support_multi_pkt_send_wqes); |
| 725 | } |
| 726 | |
| 727 | if (field_avail(typeof(resp), reserved, uhw->outlen)) |
| 728 | resp.response_length += sizeof(resp.reserved); |
| 729 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 730 | if (uhw->outlen) { |
| 731 | err = ib_copy_to_udata(uhw, &resp, resp.response_length); |
| 732 | |
| 733 | if (err) |
| 734 | return err; |
| 735 | } |
| 736 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 737 | return 0; |
| 738 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 739 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 740 | enum mlx5_ib_width { |
| 741 | MLX5_IB_WIDTH_1X = 1 << 0, |
| 742 | MLX5_IB_WIDTH_2X = 1 << 1, |
| 743 | MLX5_IB_WIDTH_4X = 1 << 2, |
| 744 | MLX5_IB_WIDTH_8X = 1 << 3, |
| 745 | MLX5_IB_WIDTH_12X = 1 << 4 |
| 746 | }; |
| 747 | |
| 748 | static int translate_active_width(struct ib_device *ibdev, u8 active_width, |
| 749 | u8 *ib_width) |
| 750 | { |
| 751 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 752 | int err = 0; |
| 753 | |
| 754 | if (active_width & MLX5_IB_WIDTH_1X) { |
| 755 | *ib_width = IB_WIDTH_1X; |
| 756 | } else if (active_width & MLX5_IB_WIDTH_2X) { |
| 757 | mlx5_ib_dbg(dev, "active_width %d is not supported by IB spec\n", |
| 758 | (int)active_width); |
| 759 | err = -EINVAL; |
| 760 | } else if (active_width & MLX5_IB_WIDTH_4X) { |
| 761 | *ib_width = IB_WIDTH_4X; |
| 762 | } else if (active_width & MLX5_IB_WIDTH_8X) { |
| 763 | *ib_width = IB_WIDTH_8X; |
| 764 | } else if (active_width & MLX5_IB_WIDTH_12X) { |
| 765 | *ib_width = IB_WIDTH_12X; |
| 766 | } else { |
| 767 | mlx5_ib_dbg(dev, "Invalid active_width %d\n", |
| 768 | (int)active_width); |
| 769 | err = -EINVAL; |
| 770 | } |
| 771 | |
| 772 | return err; |
| 773 | } |
| 774 | |
| 775 | static int mlx5_mtu_to_ib_mtu(int mtu) |
| 776 | { |
| 777 | switch (mtu) { |
| 778 | case 256: return 1; |
| 779 | case 512: return 2; |
| 780 | case 1024: return 3; |
| 781 | case 2048: return 4; |
| 782 | case 4096: return 5; |
| 783 | default: |
| 784 | pr_warn("invalid mtu\n"); |
| 785 | return -1; |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | enum ib_max_vl_num { |
| 790 | __IB_MAX_VL_0 = 1, |
| 791 | __IB_MAX_VL_0_1 = 2, |
| 792 | __IB_MAX_VL_0_3 = 3, |
| 793 | __IB_MAX_VL_0_7 = 4, |
| 794 | __IB_MAX_VL_0_14 = 5, |
| 795 | }; |
| 796 | |
| 797 | enum mlx5_vl_hw_cap { |
| 798 | MLX5_VL_HW_0 = 1, |
| 799 | MLX5_VL_HW_0_1 = 2, |
| 800 | MLX5_VL_HW_0_2 = 3, |
| 801 | MLX5_VL_HW_0_3 = 4, |
| 802 | MLX5_VL_HW_0_4 = 5, |
| 803 | MLX5_VL_HW_0_5 = 6, |
| 804 | MLX5_VL_HW_0_6 = 7, |
| 805 | MLX5_VL_HW_0_7 = 8, |
| 806 | MLX5_VL_HW_0_14 = 15 |
| 807 | }; |
| 808 | |
| 809 | static int translate_max_vl_num(struct ib_device *ibdev, u8 vl_hw_cap, |
| 810 | u8 *max_vl_num) |
| 811 | { |
| 812 | switch (vl_hw_cap) { |
| 813 | case MLX5_VL_HW_0: |
| 814 | *max_vl_num = __IB_MAX_VL_0; |
| 815 | break; |
| 816 | case MLX5_VL_HW_0_1: |
| 817 | *max_vl_num = __IB_MAX_VL_0_1; |
| 818 | break; |
| 819 | case MLX5_VL_HW_0_3: |
| 820 | *max_vl_num = __IB_MAX_VL_0_3; |
| 821 | break; |
| 822 | case MLX5_VL_HW_0_7: |
| 823 | *max_vl_num = __IB_MAX_VL_0_7; |
| 824 | break; |
| 825 | case MLX5_VL_HW_0_14: |
| 826 | *max_vl_num = __IB_MAX_VL_0_14; |
| 827 | break; |
| 828 | |
| 829 | default: |
| 830 | return -EINVAL; |
| 831 | } |
| 832 | |
| 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port, |
| 837 | struct ib_port_attr *props) |
| 838 | { |
| 839 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 840 | struct mlx5_core_dev *mdev = dev->mdev; |
| 841 | struct mlx5_hca_vport_context *rep; |
Saeed Mahameed | 046339e | 2016-04-22 00:33:03 +0300 | [diff] [blame] | 842 | u16 max_mtu; |
| 843 | u16 oper_mtu; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 844 | int err; |
| 845 | u8 ib_link_width_oper; |
| 846 | u8 vl_hw_cap; |
| 847 | |
| 848 | rep = kzalloc(sizeof(*rep), GFP_KERNEL); |
| 849 | if (!rep) { |
| 850 | err = -ENOMEM; |
| 851 | goto out; |
| 852 | } |
| 853 | |
| 854 | memset(props, 0, sizeof(*props)); |
| 855 | |
| 856 | err = mlx5_query_hca_vport_context(mdev, 0, port, 0, rep); |
| 857 | if (err) |
| 858 | goto out; |
| 859 | |
| 860 | props->lid = rep->lid; |
| 861 | props->lmc = rep->lmc; |
| 862 | props->sm_lid = rep->sm_lid; |
| 863 | props->sm_sl = rep->sm_sl; |
| 864 | props->state = rep->vport_state; |
| 865 | props->phys_state = rep->port_physical_state; |
| 866 | props->port_cap_flags = rep->cap_mask1; |
| 867 | props->gid_tbl_len = mlx5_get_gid_table_len(MLX5_CAP_GEN(mdev, gid_table_size)); |
| 868 | props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg); |
| 869 | props->pkey_tbl_len = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, pkey_table_size)); |
| 870 | props->bad_pkey_cntr = rep->pkey_violation_counter; |
| 871 | props->qkey_viol_cntr = rep->qkey_violation_counter; |
| 872 | props->subnet_timeout = rep->subnet_timeout; |
| 873 | props->init_type_reply = rep->init_type_reply; |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 874 | props->grh_required = rep->grh_required; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 875 | |
| 876 | err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); |
| 877 | if (err) |
| 878 | goto out; |
| 879 | |
| 880 | err = translate_active_width(ibdev, ib_link_width_oper, |
| 881 | &props->active_width); |
| 882 | if (err) |
| 883 | goto out; |
Noa Osherovich | d5beb7f | 2016-06-02 10:47:53 +0300 | [diff] [blame] | 884 | err = mlx5_query_port_ib_proto_oper(mdev, &props->active_speed, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 885 | if (err) |
| 886 | goto out; |
| 887 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 888 | mlx5_query_port_max_mtu(mdev, &max_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 889 | |
| 890 | props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu); |
| 891 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 892 | mlx5_query_port_oper_mtu(mdev, &oper_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 893 | |
| 894 | props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu); |
| 895 | |
| 896 | err = mlx5_query_port_vl_hw_cap(mdev, &vl_hw_cap, port); |
| 897 | if (err) |
| 898 | goto out; |
| 899 | |
| 900 | err = translate_max_vl_num(ibdev, vl_hw_cap, |
| 901 | &props->max_vl_num); |
| 902 | out: |
| 903 | kfree(rep); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 904 | return err; |
| 905 | } |
| 906 | |
| 907 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 908 | struct ib_port_attr *props) |
| 909 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 910 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 911 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 912 | return mlx5_query_mad_ifc_port(ibdev, port, props); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 913 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 914 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 915 | return mlx5_query_hca_port(ibdev, port, props); |
| 916 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 917 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 918 | return mlx5_query_port_roce(ibdev, port, props); |
| 919 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 920 | default: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 921 | return -EINVAL; |
| 922 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 926 | union ib_gid *gid) |
| 927 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 928 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 929 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 930 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 931 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 932 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 933 | return mlx5_query_mad_ifc_gids(ibdev, port, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 934 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 935 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 936 | return mlx5_query_hca_vport_gid(mdev, 0, port, 0, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 937 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 938 | default: |
| 939 | return -EINVAL; |
| 940 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 941 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 945 | u16 *pkey) |
| 946 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 947 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 948 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 949 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 950 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 951 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 952 | return mlx5_query_mad_ifc_pkey(ibdev, port, index, pkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 953 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 954 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 955 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 956 | return mlx5_query_hca_vport_pkey(mdev, 0, port, 0, index, |
| 957 | pkey); |
| 958 | default: |
| 959 | return -EINVAL; |
| 960 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 961 | } |
| 962 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 963 | static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask, |
| 964 | struct ib_device_modify *props) |
| 965 | { |
| 966 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 967 | struct mlx5_reg_node_desc in; |
| 968 | struct mlx5_reg_node_desc out; |
| 969 | int err; |
| 970 | |
| 971 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 972 | return -EOPNOTSUPP; |
| 973 | |
| 974 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 975 | return 0; |
| 976 | |
| 977 | /* |
| 978 | * If possible, pass node desc to FW, so it can generate |
| 979 | * a 144 trap. If cmd fails, just ignore. |
| 980 | */ |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 981 | memcpy(&in, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 982 | err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 983 | sizeof(out), MLX5_REG_NODE_DESC, 0, 1); |
| 984 | if (err) |
| 985 | return err; |
| 986 | |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 987 | memcpy(ibdev->node_desc, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 988 | |
| 989 | return err; |
| 990 | } |
| 991 | |
| 992 | static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 993 | struct ib_port_modify *props) |
| 994 | { |
| 995 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 996 | struct ib_port_attr attr; |
| 997 | u32 tmp; |
| 998 | int err; |
| 999 | |
| 1000 | mutex_lock(&dev->cap_mask_mutex); |
| 1001 | |
| 1002 | err = mlx5_ib_query_port(ibdev, port, &attr); |
| 1003 | if (err) |
| 1004 | goto out; |
| 1005 | |
| 1006 | tmp = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 1007 | ~props->clr_port_cap_mask; |
| 1008 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1009 | err = mlx5_set_port_caps(dev->mdev, port, tmp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1010 | |
| 1011 | out: |
| 1012 | mutex_unlock(&dev->cap_mask_mutex); |
| 1013 | return err; |
| 1014 | } |
| 1015 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1016 | static void print_lib_caps(struct mlx5_ib_dev *dev, u64 caps) |
| 1017 | { |
| 1018 | mlx5_ib_dbg(dev, "MLX5_LIB_CAP_4K_UAR = %s\n", |
| 1019 | caps & MLX5_LIB_CAP_4K_UAR ? "y" : "n"); |
| 1020 | } |
| 1021 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1022 | static int calc_total_bfregs(struct mlx5_ib_dev *dev, bool lib_uar_4k, |
| 1023 | struct mlx5_ib_alloc_ucontext_req_v2 *req, |
| 1024 | u32 *num_sys_pages) |
| 1025 | { |
| 1026 | int uars_per_sys_page; |
| 1027 | int bfregs_per_sys_page; |
| 1028 | int ref_bfregs = req->total_num_bfregs; |
| 1029 | |
| 1030 | if (req->total_num_bfregs == 0) |
| 1031 | return -EINVAL; |
| 1032 | |
| 1033 | BUILD_BUG_ON(MLX5_MAX_BFREGS % MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1034 | BUILD_BUG_ON(MLX5_MAX_BFREGS < MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1035 | |
| 1036 | if (req->total_num_bfregs > MLX5_MAX_BFREGS) |
| 1037 | return -ENOMEM; |
| 1038 | |
| 1039 | uars_per_sys_page = get_uars_per_sys_page(dev, lib_uar_4k); |
| 1040 | bfregs_per_sys_page = uars_per_sys_page * MLX5_NON_FP_BFREGS_PER_UAR; |
| 1041 | req->total_num_bfregs = ALIGN(req->total_num_bfregs, bfregs_per_sys_page); |
| 1042 | *num_sys_pages = req->total_num_bfregs / bfregs_per_sys_page; |
| 1043 | |
| 1044 | if (req->num_low_latency_bfregs > req->total_num_bfregs - 1) |
| 1045 | return -EINVAL; |
| 1046 | |
| 1047 | mlx5_ib_dbg(dev, "uar_4k: fw support %s, lib support %s, user requested %d bfregs, alloated %d, using %d sys pages\n", |
| 1048 | MLX5_CAP_GEN(dev->mdev, uar_4k) ? "yes" : "no", |
| 1049 | lib_uar_4k ? "yes" : "no", ref_bfregs, |
| 1050 | req->total_num_bfregs, *num_sys_pages); |
| 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | static int allocate_uars(struct mlx5_ib_dev *dev, struct mlx5_ib_ucontext *context) |
| 1056 | { |
| 1057 | struct mlx5_bfreg_info *bfregi; |
| 1058 | int err; |
| 1059 | int i; |
| 1060 | |
| 1061 | bfregi = &context->bfregi; |
| 1062 | for (i = 0; i < bfregi->num_sys_pages; i++) { |
| 1063 | err = mlx5_cmd_alloc_uar(dev->mdev, &bfregi->sys_pages[i]); |
| 1064 | if (err) |
| 1065 | goto error; |
| 1066 | |
| 1067 | mlx5_ib_dbg(dev, "allocated uar %d\n", bfregi->sys_pages[i]); |
| 1068 | } |
| 1069 | return 0; |
| 1070 | |
| 1071 | error: |
| 1072 | for (--i; i >= 0; i--) |
| 1073 | if (mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i])) |
| 1074 | mlx5_ib_warn(dev, "failed to free uar %d\n", i); |
| 1075 | |
| 1076 | return err; |
| 1077 | } |
| 1078 | |
| 1079 | static int deallocate_uars(struct mlx5_ib_dev *dev, struct mlx5_ib_ucontext *context) |
| 1080 | { |
| 1081 | struct mlx5_bfreg_info *bfregi; |
| 1082 | int err; |
| 1083 | int i; |
| 1084 | |
| 1085 | bfregi = &context->bfregi; |
| 1086 | for (i = 0; i < bfregi->num_sys_pages; i++) { |
| 1087 | err = mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i]); |
| 1088 | if (err) { |
| 1089 | mlx5_ib_warn(dev, "failed to free uar %d\n", i); |
| 1090 | return err; |
| 1091 | } |
| 1092 | } |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1096 | static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev, |
| 1097 | struct ib_udata *udata) |
| 1098 | { |
| 1099 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1100 | struct mlx5_ib_alloc_ucontext_req_v2 req = {}; |
| 1101 | struct mlx5_ib_alloc_ucontext_resp resp = {}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1102 | struct mlx5_ib_ucontext *context; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1103 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1104 | int ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1105 | int err; |
Jack Morgenstein | f241e74 | 2014-07-28 23:30:23 +0300 | [diff] [blame] | 1106 | size_t reqlen; |
Majd Dibbiny | a168a41c | 2016-01-28 17:51:47 +0200 | [diff] [blame] | 1107 | size_t min_req_v2 = offsetof(struct mlx5_ib_alloc_ucontext_req_v2, |
| 1108 | max_cqe_version); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1109 | bool lib_uar_4k; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1110 | |
| 1111 | if (!dev->ib_active) |
| 1112 | return ERR_PTR(-EAGAIN); |
| 1113 | |
Haggai Abramovsky | dfbee85 | 2016-01-14 19:12:56 +0200 | [diff] [blame] | 1114 | if (udata->inlen < sizeof(struct ib_uverbs_cmd_hdr)) |
| 1115 | return ERR_PTR(-EINVAL); |
| 1116 | |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1117 | reqlen = udata->inlen - sizeof(struct ib_uverbs_cmd_hdr); |
| 1118 | if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
| 1119 | ver = 0; |
Majd Dibbiny | a168a41c | 2016-01-28 17:51:47 +0200 | [diff] [blame] | 1120 | else if (reqlen >= min_req_v2) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1121 | ver = 2; |
| 1122 | else |
| 1123 | return ERR_PTR(-EINVAL); |
| 1124 | |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1125 | err = ib_copy_from_udata(&req, udata, min(reqlen, sizeof(req))); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1126 | if (err) |
| 1127 | return ERR_PTR(err); |
| 1128 | |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1129 | if (req.flags) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1130 | return ERR_PTR(-EINVAL); |
| 1131 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1132 | if (req.comp_mask || req.reserved0 || req.reserved1 || req.reserved2) |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1133 | return ERR_PTR(-EOPNOTSUPP); |
| 1134 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1135 | req.total_num_bfregs = ALIGN(req.total_num_bfregs, |
| 1136 | MLX5_NON_FP_BFREGS_PER_UAR); |
| 1137 | if (req.num_low_latency_bfregs > req.total_num_bfregs - 1) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1138 | return ERR_PTR(-EINVAL); |
| 1139 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1140 | resp.qp_tab_size = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp); |
Noa Osherovich | 2cc6ad5 | 2016-06-04 15:15:33 +0300 | [diff] [blame] | 1141 | if (mlx5_core_is_pf(dev->mdev) && MLX5_CAP_GEN(dev->mdev, bf)) |
| 1142 | resp.bf_reg_size = 1 << MLX5_CAP_GEN(dev->mdev, log_bf_reg_size); |
Daniel Jurgens | b47bd6e | 2016-10-25 18:36:24 +0300 | [diff] [blame] | 1143 | resp.cache_line_size = cache_line_size(); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1144 | resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); |
| 1145 | resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); |
| 1146 | resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1147 | resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1148 | 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] | 1149 | resp.cqe_version = min_t(__u8, |
| 1150 | (__u8)MLX5_CAP_GEN(dev->mdev, cqe_version), |
| 1151 | req.max_cqe_version); |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1152 | resp.log_uar_size = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1153 | MLX5_ADAPTER_PAGE_SHIFT : PAGE_SHIFT; |
| 1154 | resp.num_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1155 | MLX5_CAP_GEN(dev->mdev, num_of_uars_per_page) : 1; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1156 | resp.response_length = min(offsetof(typeof(resp), response_length) + |
| 1157 | sizeof(resp.response_length), udata->outlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1158 | |
| 1159 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 1160 | if (!context) |
| 1161 | return ERR_PTR(-ENOMEM); |
| 1162 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1163 | lib_uar_4k = req.lib_caps & MLX5_LIB_CAP_4K_UAR; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1164 | bfregi = &context->bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1165 | |
| 1166 | /* updates req->total_num_bfregs */ |
| 1167 | err = calc_total_bfregs(dev, lib_uar_4k, &req, &bfregi->num_sys_pages); |
| 1168 | if (err) |
| 1169 | goto out_ctx; |
| 1170 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1171 | mutex_init(&bfregi->lock); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1172 | bfregi->lib_uar_4k = lib_uar_4k; |
| 1173 | bfregi->count = kcalloc(req.total_num_bfregs, sizeof(*bfregi->count), |
| 1174 | GFP_KERNEL); |
| 1175 | if (!bfregi->count) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1176 | err = -ENOMEM; |
| 1177 | goto out_ctx; |
| 1178 | } |
| 1179 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1180 | bfregi->sys_pages = kcalloc(bfregi->num_sys_pages, |
| 1181 | sizeof(*bfregi->sys_pages), |
| 1182 | GFP_KERNEL); |
| 1183 | if (!bfregi->sys_pages) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1184 | err = -ENOMEM; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1185 | goto out_count; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1186 | } |
| 1187 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1188 | err = allocate_uars(dev, context); |
| 1189 | if (err) |
| 1190 | goto out_sys_pages; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1191 | |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 1192 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 1193 | context->ibucontext.invalidate_range = &mlx5_ib_invalidate_range; |
| 1194 | #endif |
| 1195 | |
Artemy Kovalyov | 7d0cc6e | 2017-01-02 11:37:44 +0200 | [diff] [blame] | 1196 | context->upd_xlt_page = __get_free_page(GFP_KERNEL); |
| 1197 | if (!context->upd_xlt_page) { |
| 1198 | err = -ENOMEM; |
| 1199 | goto out_uars; |
| 1200 | } |
| 1201 | mutex_init(&context->upd_xlt_page_mutex); |
| 1202 | |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1203 | if (MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) { |
| 1204 | err = mlx5_core_alloc_transport_domain(dev->mdev, |
| 1205 | &context->tdn); |
| 1206 | if (err) |
Artemy Kovalyov | 7d0cc6e | 2017-01-02 11:37:44 +0200 | [diff] [blame] | 1207 | goto out_page; |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1208 | } |
| 1209 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1210 | INIT_LIST_HEAD(&context->vma_private_list); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1211 | INIT_LIST_HEAD(&context->db_page_list); |
| 1212 | mutex_init(&context->db_page_mutex); |
| 1213 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1214 | resp.tot_bfregs = req.total_num_bfregs; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1215 | resp.num_ports = MLX5_CAP_GEN(dev->mdev, num_ports); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1216 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1217 | if (field_avail(typeof(resp), cqe_version, udata->outlen)) |
| 1218 | resp.response_length += sizeof(resp.cqe_version); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1219 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1220 | if (field_avail(typeof(resp), cmds_supp_uhw, udata->outlen)) { |
Moni Shoua | 6ad279c5 | 2016-11-23 08:23:23 +0200 | [diff] [blame] | 1221 | resp.cmds_supp_uhw |= MLX5_USER_CMDS_SUPP_UHW_QUERY_DEVICE | |
| 1222 | MLX5_USER_CMDS_SUPP_UHW_CREATE_AH; |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1223 | resp.response_length += sizeof(resp.cmds_supp_uhw); |
| 1224 | } |
| 1225 | |
Noa Osherovich | bc5c6ee | 2016-06-04 15:15:31 +0300 | [diff] [blame] | 1226 | /* |
| 1227 | * We don't want to expose information from the PCI bar that is located |
| 1228 | * after 4096 bytes, so if the arch only supports larger pages, let's |
| 1229 | * pretend we don't support reading the HCA's core clock. This is also |
| 1230 | * forced by mmap function. |
| 1231 | */ |
Eli Cohen | de8d6e0 | 2017-01-03 23:55:19 +0200 | [diff] [blame] | 1232 | if (field_avail(typeof(resp), hca_core_clock_offset, udata->outlen)) { |
| 1233 | if (PAGE_SIZE <= 4096) { |
| 1234 | resp.comp_mask |= |
| 1235 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET; |
| 1236 | resp.hca_core_clock_offset = |
| 1237 | offsetof(struct mlx5_init_seg, internal_timer_h) % PAGE_SIZE; |
| 1238 | } |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1239 | resp.response_length += sizeof(resp.hca_core_clock_offset) + |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1240 | sizeof(resp.reserved2); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1241 | } |
| 1242 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1243 | if (field_avail(typeof(resp), log_uar_size, udata->outlen)) |
| 1244 | resp.response_length += sizeof(resp.log_uar_size); |
| 1245 | |
| 1246 | if (field_avail(typeof(resp), num_uars_per_page, udata->outlen)) |
| 1247 | resp.response_length += sizeof(resp.num_uars_per_page); |
| 1248 | |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1249 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1250 | if (err) |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1251 | goto out_td; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1252 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1253 | bfregi->ver = ver; |
| 1254 | bfregi->num_low_latency_bfregs = req.num_low_latency_bfregs; |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1255 | context->cqe_version = resp.cqe_version; |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1256 | context->lib_caps = req.lib_caps; |
| 1257 | print_lib_caps(dev, context->lib_caps); |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1258 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1259 | return &context->ibucontext; |
| 1260 | |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1261 | out_td: |
| 1262 | if (MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1263 | mlx5_core_dealloc_transport_domain(dev->mdev, context->tdn); |
| 1264 | |
Artemy Kovalyov | 7d0cc6e | 2017-01-02 11:37:44 +0200 | [diff] [blame] | 1265 | out_page: |
| 1266 | free_page(context->upd_xlt_page); |
| 1267 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1268 | out_uars: |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1269 | deallocate_uars(dev, context); |
| 1270 | |
| 1271 | out_sys_pages: |
| 1272 | kfree(bfregi->sys_pages); |
| 1273 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1274 | out_count: |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1275 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1276 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1277 | out_ctx: |
| 1278 | kfree(context); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1279 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1280 | return ERR_PTR(err); |
| 1281 | } |
| 1282 | |
| 1283 | static int mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
| 1284 | { |
| 1285 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 1286 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1287 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1288 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1289 | bfregi = &context->bfregi; |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1290 | if (MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1291 | mlx5_core_dealloc_transport_domain(dev->mdev, context->tdn); |
| 1292 | |
Artemy Kovalyov | 7d0cc6e | 2017-01-02 11:37:44 +0200 | [diff] [blame] | 1293 | free_page(context->upd_xlt_page); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1294 | deallocate_uars(dev, context); |
| 1295 | kfree(bfregi->sys_pages); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1296 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1297 | kfree(context); |
| 1298 | |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1302 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, |
| 1303 | struct mlx5_bfreg_info *bfregi, |
| 1304 | int idx) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1305 | { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1306 | int fw_uars_per_page; |
| 1307 | |
| 1308 | fw_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? MLX5_UARS_IN_PAGE : 1; |
| 1309 | |
| 1310 | return (pci_resource_start(dev->mdev->pdev, 0) >> PAGE_SHIFT) + |
| 1311 | bfregi->sys_pages[idx] / fw_uars_per_page; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | static int get_command(unsigned long offset) |
| 1315 | { |
| 1316 | return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK; |
| 1317 | } |
| 1318 | |
| 1319 | static int get_arg(unsigned long offset) |
| 1320 | { |
| 1321 | return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1); |
| 1322 | } |
| 1323 | |
| 1324 | static int get_index(unsigned long offset) |
| 1325 | { |
| 1326 | return get_arg(offset); |
| 1327 | } |
| 1328 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1329 | static void mlx5_ib_vma_open(struct vm_area_struct *area) |
| 1330 | { |
| 1331 | /* vma_open is called when a new VMA is created on top of our VMA. This |
| 1332 | * is done through either mremap flow or split_vma (usually due to |
| 1333 | * mlock, madvise, munmap, etc.) We do not support a clone of the VMA, |
| 1334 | * as this VMA is strongly hardware related. Therefore we set the |
| 1335 | * vm_ops of the newly created/cloned VMA to NULL, to prevent it from |
| 1336 | * calling us again and trying to do incorrect actions. We assume that |
| 1337 | * the original VMA size is exactly a single page, and therefore all |
| 1338 | * "splitting" operation will not happen to it. |
| 1339 | */ |
| 1340 | area->vm_ops = NULL; |
| 1341 | } |
| 1342 | |
| 1343 | static void mlx5_ib_vma_close(struct vm_area_struct *area) |
| 1344 | { |
| 1345 | struct mlx5_ib_vma_private_data *mlx5_ib_vma_priv_data; |
| 1346 | |
| 1347 | /* It's guaranteed that all VMAs opened on a FD are closed before the |
| 1348 | * file itself is closed, therefore no sync is needed with the regular |
| 1349 | * closing flow. (e.g. mlx5 ib_dealloc_ucontext) |
| 1350 | * However need a sync with accessing the vma as part of |
| 1351 | * mlx5_ib_disassociate_ucontext. |
| 1352 | * The close operation is usually called under mm->mmap_sem except when |
| 1353 | * process is exiting. |
| 1354 | * The exiting case is handled explicitly as part of |
| 1355 | * mlx5_ib_disassociate_ucontext. |
| 1356 | */ |
| 1357 | mlx5_ib_vma_priv_data = (struct mlx5_ib_vma_private_data *)area->vm_private_data; |
| 1358 | |
| 1359 | /* setting the vma context pointer to null in the mlx5_ib driver's |
| 1360 | * private data, to protect a race condition in |
| 1361 | * mlx5_ib_disassociate_ucontext(). |
| 1362 | */ |
| 1363 | mlx5_ib_vma_priv_data->vma = NULL; |
| 1364 | list_del(&mlx5_ib_vma_priv_data->list); |
| 1365 | kfree(mlx5_ib_vma_priv_data); |
| 1366 | } |
| 1367 | |
| 1368 | static const struct vm_operations_struct mlx5_ib_vm_ops = { |
| 1369 | .open = mlx5_ib_vma_open, |
| 1370 | .close = mlx5_ib_vma_close |
| 1371 | }; |
| 1372 | |
| 1373 | static int mlx5_ib_set_vma_data(struct vm_area_struct *vma, |
| 1374 | struct mlx5_ib_ucontext *ctx) |
| 1375 | { |
| 1376 | struct mlx5_ib_vma_private_data *vma_prv; |
| 1377 | struct list_head *vma_head = &ctx->vma_private_list; |
| 1378 | |
| 1379 | vma_prv = kzalloc(sizeof(*vma_prv), GFP_KERNEL); |
| 1380 | if (!vma_prv) |
| 1381 | return -ENOMEM; |
| 1382 | |
| 1383 | vma_prv->vma = vma; |
| 1384 | vma->vm_private_data = vma_prv; |
| 1385 | vma->vm_ops = &mlx5_ib_vm_ops; |
| 1386 | |
| 1387 | list_add(&vma_prv->list, vma_head); |
| 1388 | |
| 1389 | return 0; |
| 1390 | } |
| 1391 | |
| 1392 | static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) |
| 1393 | { |
| 1394 | int ret; |
| 1395 | struct vm_area_struct *vma; |
| 1396 | struct mlx5_ib_vma_private_data *vma_private, *n; |
| 1397 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 1398 | struct task_struct *owning_process = NULL; |
| 1399 | struct mm_struct *owning_mm = NULL; |
| 1400 | |
| 1401 | owning_process = get_pid_task(ibcontext->tgid, PIDTYPE_PID); |
| 1402 | if (!owning_process) |
| 1403 | return; |
| 1404 | |
| 1405 | owning_mm = get_task_mm(owning_process); |
| 1406 | if (!owning_mm) { |
| 1407 | pr_info("no mm, disassociate ucontext is pending task termination\n"); |
| 1408 | while (1) { |
| 1409 | put_task_struct(owning_process); |
| 1410 | usleep_range(1000, 2000); |
| 1411 | owning_process = get_pid_task(ibcontext->tgid, |
| 1412 | PIDTYPE_PID); |
| 1413 | if (!owning_process || |
| 1414 | owning_process->state == TASK_DEAD) { |
| 1415 | pr_info("disassociate ucontext done, task was terminated\n"); |
| 1416 | /* in case task was dead need to release the |
| 1417 | * task struct. |
| 1418 | */ |
| 1419 | if (owning_process) |
| 1420 | put_task_struct(owning_process); |
| 1421 | return; |
| 1422 | } |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | /* need to protect from a race on closing the vma as part of |
| 1427 | * mlx5_ib_vma_close. |
| 1428 | */ |
| 1429 | down_read(&owning_mm->mmap_sem); |
| 1430 | list_for_each_entry_safe(vma_private, n, &context->vma_private_list, |
| 1431 | list) { |
| 1432 | vma = vma_private->vma; |
| 1433 | ret = zap_vma_ptes(vma, vma->vm_start, |
| 1434 | PAGE_SIZE); |
| 1435 | WARN_ONCE(ret, "%s: zap_vma_ptes failed", __func__); |
| 1436 | /* context going to be destroyed, should |
| 1437 | * not access ops any more. |
| 1438 | */ |
| 1439 | vma->vm_ops = NULL; |
| 1440 | list_del(&vma_private->list); |
| 1441 | kfree(vma_private); |
| 1442 | } |
| 1443 | up_read(&owning_mm->mmap_sem); |
| 1444 | mmput(owning_mm); |
| 1445 | put_task_struct(owning_process); |
| 1446 | } |
| 1447 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 1448 | static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd) |
| 1449 | { |
| 1450 | switch (cmd) { |
| 1451 | case MLX5_IB_MMAP_WC_PAGE: |
| 1452 | return "WC"; |
| 1453 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 1454 | return "best effort WC"; |
| 1455 | case MLX5_IB_MMAP_NC_PAGE: |
| 1456 | return "NC"; |
| 1457 | default: |
| 1458 | return NULL; |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | static int uar_mmap(struct mlx5_ib_dev *dev, enum mlx5_ib_mmap_cmd cmd, |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1463 | struct vm_area_struct *vma, |
| 1464 | struct mlx5_ib_ucontext *context) |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 1465 | { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1466 | struct mlx5_bfreg_info *bfregi = &context->bfregi; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 1467 | int err; |
| 1468 | unsigned long idx; |
| 1469 | phys_addr_t pfn, pa; |
| 1470 | pgprot_t prot; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1471 | int uars_per_page; |
| 1472 | |
| 1473 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 1474 | return -EINVAL; |
| 1475 | |
| 1476 | uars_per_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k); |
| 1477 | idx = get_index(vma->vm_pgoff); |
| 1478 | if (idx % uars_per_page || |
| 1479 | idx * uars_per_page >= bfregi->num_sys_pages) { |
| 1480 | mlx5_ib_warn(dev, "invalid uar index %lu\n", idx); |
| 1481 | return -EINVAL; |
| 1482 | } |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 1483 | |
| 1484 | switch (cmd) { |
| 1485 | case MLX5_IB_MMAP_WC_PAGE: |
| 1486 | /* Some architectures don't support WC memory */ |
| 1487 | #if defined(CONFIG_X86) |
| 1488 | if (!pat_enabled()) |
| 1489 | return -EPERM; |
| 1490 | #elif !(defined(CONFIG_PPC) || (defined(CONFIG_ARM) && defined(CONFIG_MMU))) |
| 1491 | return -EPERM; |
| 1492 | #endif |
| 1493 | /* fall through */ |
| 1494 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 1495 | /* For MLX5_IB_MMAP_REGULAR_PAGE do the best effort to get WC */ |
| 1496 | prot = pgprot_writecombine(vma->vm_page_prot); |
| 1497 | break; |
| 1498 | case MLX5_IB_MMAP_NC_PAGE: |
| 1499 | prot = pgprot_noncached(vma->vm_page_prot); |
| 1500 | break; |
| 1501 | default: |
| 1502 | return -EINVAL; |
| 1503 | } |
| 1504 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1505 | pfn = uar_index2pfn(dev, bfregi, idx); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 1506 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn %pa\n", idx, &pfn); |
| 1507 | |
| 1508 | vma->vm_page_prot = prot; |
| 1509 | err = io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 1510 | PAGE_SIZE, vma->vm_page_prot); |
| 1511 | if (err) { |
| 1512 | mlx5_ib_err(dev, "io_remap_pfn_range failed with error=%d, vm_start=0x%lx, pfn=%pa, mmap_cmd=%s\n", |
| 1513 | err, vma->vm_start, &pfn, mmap_cmd2str(cmd)); |
| 1514 | return -EAGAIN; |
| 1515 | } |
| 1516 | |
| 1517 | pa = pfn << PAGE_SHIFT; |
| 1518 | mlx5_ib_dbg(dev, "mapped %s at 0x%lx, PA %pa\n", mmap_cmd2str(cmd), |
| 1519 | vma->vm_start, &pa); |
| 1520 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1521 | return mlx5_ib_set_vma_data(vma, context); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 1522 | } |
| 1523 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1524 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
| 1525 | { |
| 1526 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 1527 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1528 | unsigned long command; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1529 | phys_addr_t pfn; |
| 1530 | |
| 1531 | command = get_command(vma->vm_pgoff); |
| 1532 | switch (command) { |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 1533 | case MLX5_IB_MMAP_WC_PAGE: |
| 1534 | case MLX5_IB_MMAP_NC_PAGE: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1535 | case MLX5_IB_MMAP_REGULAR_PAGE: |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1536 | return uar_mmap(dev, command, vma, context); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1537 | |
| 1538 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
| 1539 | return -ENOSYS; |
| 1540 | |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 1541 | case MLX5_IB_MMAP_CORE_CLOCK: |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 1542 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 1543 | return -EINVAL; |
| 1544 | |
Matan Barak | 6cbac1e | 2016-04-14 16:52:10 +0300 | [diff] [blame] | 1545 | if (vma->vm_flags & VM_WRITE) |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 1546 | return -EPERM; |
| 1547 | |
| 1548 | /* Don't expose to user-space information it shouldn't have */ |
| 1549 | if (PAGE_SIZE > 4096) |
| 1550 | return -EOPNOTSUPP; |
| 1551 | |
| 1552 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 1553 | pfn = (dev->mdev->iseg_base + |
| 1554 | offsetof(struct mlx5_init_seg, internal_timer_h)) >> |
| 1555 | PAGE_SHIFT; |
| 1556 | if (io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 1557 | PAGE_SIZE, vma->vm_page_prot)) |
| 1558 | return -EAGAIN; |
| 1559 | |
| 1560 | mlx5_ib_dbg(dev, "mapped internal timer at 0x%lx, PA 0x%llx\n", |
| 1561 | vma->vm_start, |
| 1562 | (unsigned long long)pfn << PAGE_SHIFT); |
| 1563 | break; |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 1564 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1565 | default: |
| 1566 | return -EINVAL; |
| 1567 | } |
| 1568 | |
| 1569 | return 0; |
| 1570 | } |
| 1571 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1572 | static struct ib_pd *mlx5_ib_alloc_pd(struct ib_device *ibdev, |
| 1573 | struct ib_ucontext *context, |
| 1574 | struct ib_udata *udata) |
| 1575 | { |
| 1576 | struct mlx5_ib_alloc_pd_resp resp; |
| 1577 | struct mlx5_ib_pd *pd; |
| 1578 | int err; |
| 1579 | |
| 1580 | pd = kmalloc(sizeof(*pd), GFP_KERNEL); |
| 1581 | if (!pd) |
| 1582 | return ERR_PTR(-ENOMEM); |
| 1583 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1584 | err = mlx5_core_alloc_pd(to_mdev(ibdev)->mdev, &pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1585 | if (err) { |
| 1586 | kfree(pd); |
| 1587 | return ERR_PTR(err); |
| 1588 | } |
| 1589 | |
| 1590 | if (context) { |
| 1591 | resp.pdn = pd->pdn; |
| 1592 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1593 | mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1594 | kfree(pd); |
| 1595 | return ERR_PTR(-EFAULT); |
| 1596 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | return &pd->ibpd; |
| 1600 | } |
| 1601 | |
| 1602 | static int mlx5_ib_dealloc_pd(struct ib_pd *pd) |
| 1603 | { |
| 1604 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 1605 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
| 1606 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1607 | mlx5_core_dealloc_pd(mdev->mdev, mpd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1608 | kfree(mpd); |
| 1609 | |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 1613 | enum { |
| 1614 | MATCH_CRITERIA_ENABLE_OUTER_BIT, |
| 1615 | MATCH_CRITERIA_ENABLE_MISC_BIT, |
| 1616 | MATCH_CRITERIA_ENABLE_INNER_BIT |
| 1617 | }; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1618 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 1619 | #define HEADER_IS_ZERO(match_criteria, headers) \ |
| 1620 | !(memchr_inv(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \ |
| 1621 | 0, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \ |
| 1622 | |
| 1623 | static u8 get_match_criteria_enable(u32 *match_criteria) |
| 1624 | { |
| 1625 | u8 match_criteria_enable; |
| 1626 | |
| 1627 | match_criteria_enable = |
| 1628 | (!HEADER_IS_ZERO(match_criteria, outer_headers)) << |
| 1629 | MATCH_CRITERIA_ENABLE_OUTER_BIT; |
| 1630 | match_criteria_enable |= |
| 1631 | (!HEADER_IS_ZERO(match_criteria, misc_parameters)) << |
| 1632 | MATCH_CRITERIA_ENABLE_MISC_BIT; |
| 1633 | match_criteria_enable |= |
| 1634 | (!HEADER_IS_ZERO(match_criteria, inner_headers)) << |
| 1635 | MATCH_CRITERIA_ENABLE_INNER_BIT; |
| 1636 | |
| 1637 | return match_criteria_enable; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1638 | } |
| 1639 | |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 1640 | static void set_proto(void *outer_c, void *outer_v, u8 mask, u8 val) |
| 1641 | { |
| 1642 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_protocol, mask); |
| 1643 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_protocol, val); |
| 1644 | } |
| 1645 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1646 | static void set_flow_label(void *misc_c, void *misc_v, u8 mask, u8 val, |
| 1647 | bool inner) |
| 1648 | { |
| 1649 | if (inner) { |
| 1650 | MLX5_SET(fte_match_set_misc, |
| 1651 | misc_c, inner_ipv6_flow_label, mask); |
| 1652 | MLX5_SET(fte_match_set_misc, |
| 1653 | misc_v, inner_ipv6_flow_label, val); |
| 1654 | } else { |
| 1655 | MLX5_SET(fte_match_set_misc, |
| 1656 | misc_c, outer_ipv6_flow_label, mask); |
| 1657 | MLX5_SET(fte_match_set_misc, |
| 1658 | misc_v, outer_ipv6_flow_label, val); |
| 1659 | } |
| 1660 | } |
| 1661 | |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 1662 | static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val) |
| 1663 | { |
| 1664 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_ecn, mask); |
| 1665 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_ecn, val); |
| 1666 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_dscp, mask >> 2); |
| 1667 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_dscp, val >> 2); |
| 1668 | } |
| 1669 | |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 1670 | #define LAST_ETH_FIELD vlan_tag |
| 1671 | #define LAST_IB_FIELD sl |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 1672 | #define LAST_IPV4_FIELD tos |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 1673 | #define LAST_IPV6_FIELD traffic_class |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 1674 | #define LAST_TCP_UDP_FIELD src_port |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 1675 | #define LAST_TUNNEL_FIELD tunnel_id |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 1676 | |
| 1677 | /* Field is the last supported field */ |
| 1678 | #define FIELDS_NOT_SUPPORTED(filter, field)\ |
| 1679 | memchr_inv((void *)&filter.field +\ |
| 1680 | sizeof(filter.field), 0,\ |
| 1681 | sizeof(filter) -\ |
| 1682 | offsetof(typeof(filter), field) -\ |
| 1683 | sizeof(filter.field)) |
| 1684 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1685 | static int parse_flow_attr(u32 *match_c, u32 *match_v, |
Maor Gottlieb | dd063d0 | 2016-08-28 14:16:32 +0300 | [diff] [blame] | 1686 | const union ib_flow_spec *ib_spec) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1687 | { |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 1688 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 1689 | misc_parameters); |
| 1690 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 1691 | misc_parameters); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1692 | void *headers_c; |
| 1693 | void *headers_v; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 1694 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1695 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 1696 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 1697 | inner_headers); |
| 1698 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 1699 | inner_headers); |
| 1700 | } else { |
| 1701 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 1702 | outer_headers); |
| 1703 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 1704 | outer_headers); |
| 1705 | } |
| 1706 | |
| 1707 | switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1708 | case IB_FLOW_SPEC_ETH: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 1709 | if (FIELDS_NOT_SUPPORTED(ib_spec->eth.mask, LAST_ETH_FIELD)) |
| 1710 | return -ENOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1711 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1712 | ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1713 | dmac_47_16), |
| 1714 | ib_spec->eth.mask.dst_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1715 | ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1716 | dmac_47_16), |
| 1717 | ib_spec->eth.val.dst_mac); |
| 1718 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1719 | ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | ee3da80 | 2016-09-12 19:16:24 +0300 | [diff] [blame] | 1720 | smac_47_16), |
| 1721 | ib_spec->eth.mask.src_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1722 | ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | ee3da80 | 2016-09-12 19:16:24 +0300 | [diff] [blame] | 1723 | smac_47_16), |
| 1724 | ib_spec->eth.val.src_mac); |
| 1725 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1726 | if (ib_spec->eth.mask.vlan_tag) { |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1727 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1728 | vlan_tag, 1); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1729 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1730 | vlan_tag, 1); |
| 1731 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1732 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1733 | first_vid, ntohs(ib_spec->eth.mask.vlan_tag)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1734 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1735 | first_vid, ntohs(ib_spec->eth.val.vlan_tag)); |
| 1736 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1737 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1738 | first_cfi, |
| 1739 | ntohs(ib_spec->eth.mask.vlan_tag) >> 12); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1740 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1741 | first_cfi, |
| 1742 | ntohs(ib_spec->eth.val.vlan_tag) >> 12); |
| 1743 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1744 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1745 | first_prio, |
| 1746 | ntohs(ib_spec->eth.mask.vlan_tag) >> 13); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1747 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1748 | first_prio, |
| 1749 | ntohs(ib_spec->eth.val.vlan_tag) >> 13); |
| 1750 | } |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1751 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1752 | ethertype, ntohs(ib_spec->eth.mask.ether_type)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1753 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1754 | ethertype, ntohs(ib_spec->eth.val.ether_type)); |
| 1755 | break; |
| 1756 | case IB_FLOW_SPEC_IPV4: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 1757 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv4.mask, LAST_IPV4_FIELD)) |
| 1758 | return -ENOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1759 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1760 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1761 | ethertype, 0xffff); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1762 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1763 | ethertype, ETH_P_IP); |
| 1764 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1765 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1766 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 1767 | &ib_spec->ipv4.mask.src_ip, |
| 1768 | sizeof(ib_spec->ipv4.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1769 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1770 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 1771 | &ib_spec->ipv4.val.src_ip, |
| 1772 | sizeof(ib_spec->ipv4.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1773 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1774 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 1775 | &ib_spec->ipv4.mask.dst_ip, |
| 1776 | sizeof(ib_spec->ipv4.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1777 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1778 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 1779 | &ib_spec->ipv4.val.dst_ip, |
| 1780 | sizeof(ib_spec->ipv4.val.dst_ip)); |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 1781 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1782 | set_tos(headers_c, headers_v, |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 1783 | ib_spec->ipv4.mask.tos, ib_spec->ipv4.val.tos); |
| 1784 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1785 | set_proto(headers_c, headers_v, |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 1786 | ib_spec->ipv4.mask.proto, ib_spec->ipv4.val.proto); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1787 | break; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 1788 | case IB_FLOW_SPEC_IPV6: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 1789 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv6.mask, LAST_IPV6_FIELD)) |
| 1790 | return -ENOTSUPP; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 1791 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1792 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 1793 | ethertype, 0xffff); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1794 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 1795 | ethertype, ETH_P_IPV6); |
| 1796 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1797 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 1798 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 1799 | &ib_spec->ipv6.mask.src_ip, |
| 1800 | sizeof(ib_spec->ipv6.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1801 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 1802 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 1803 | &ib_spec->ipv6.val.src_ip, |
| 1804 | sizeof(ib_spec->ipv6.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1805 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 1806 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 1807 | &ib_spec->ipv6.mask.dst_ip, |
| 1808 | sizeof(ib_spec->ipv6.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1809 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 1810 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 1811 | &ib_spec->ipv6.val.dst_ip, |
| 1812 | sizeof(ib_spec->ipv6.val.dst_ip)); |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 1813 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1814 | set_tos(headers_c, headers_v, |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 1815 | ib_spec->ipv6.mask.traffic_class, |
| 1816 | ib_spec->ipv6.val.traffic_class); |
| 1817 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1818 | set_proto(headers_c, headers_v, |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 1819 | ib_spec->ipv6.mask.next_hdr, |
| 1820 | ib_spec->ipv6.val.next_hdr); |
| 1821 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1822 | set_flow_label(misc_params_c, misc_params_v, |
| 1823 | ntohl(ib_spec->ipv6.mask.flow_label), |
| 1824 | ntohl(ib_spec->ipv6.val.flow_label), |
| 1825 | ib_spec->type & IB_FLOW_SPEC_INNER); |
| 1826 | |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 1827 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1828 | case IB_FLOW_SPEC_TCP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 1829 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 1830 | LAST_TCP_UDP_FIELD)) |
| 1831 | return -ENOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1832 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1833 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1834 | 0xff); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1835 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1836 | IPPROTO_TCP); |
| 1837 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1838 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1839 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1840 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1841 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 1842 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1843 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1844 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1845 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1846 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 1847 | break; |
| 1848 | case IB_FLOW_SPEC_UDP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 1849 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 1850 | LAST_TCP_UDP_FIELD)) |
| 1851 | return -ENOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1852 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1853 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1854 | 0xff); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1855 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1856 | IPPROTO_UDP); |
| 1857 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1858 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1859 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1860 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1861 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 1862 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1863 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1864 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 1865 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1866 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 1867 | break; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 1868 | case IB_FLOW_SPEC_VXLAN_TUNNEL: |
| 1869 | if (FIELDS_NOT_SUPPORTED(ib_spec->tunnel.mask, |
| 1870 | LAST_TUNNEL_FIELD)) |
| 1871 | return -ENOTSUPP; |
| 1872 | |
| 1873 | MLX5_SET(fte_match_set_misc, misc_params_c, vxlan_vni, |
| 1874 | ntohl(ib_spec->tunnel.mask.tunnel_id)); |
| 1875 | MLX5_SET(fte_match_set_misc, misc_params_v, vxlan_vni, |
| 1876 | ntohl(ib_spec->tunnel.val.tunnel_id)); |
| 1877 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1878 | default: |
| 1879 | return -EINVAL; |
| 1880 | } |
| 1881 | |
| 1882 | return 0; |
| 1883 | } |
| 1884 | |
| 1885 | /* If a flow could catch both multicast and unicast packets, |
| 1886 | * it won't fall into the multicast flow steering table and this rule |
| 1887 | * could steal other multicast packets. |
| 1888 | */ |
| 1889 | static bool flow_is_multicast_only(struct ib_flow_attr *ib_attr) |
| 1890 | { |
| 1891 | struct ib_flow_spec_eth *eth_spec; |
| 1892 | |
| 1893 | if (ib_attr->type != IB_FLOW_ATTR_NORMAL || |
| 1894 | ib_attr->size < sizeof(struct ib_flow_attr) + |
| 1895 | sizeof(struct ib_flow_spec_eth) || |
| 1896 | ib_attr->num_of_specs < 1) |
| 1897 | return false; |
| 1898 | |
| 1899 | eth_spec = (struct ib_flow_spec_eth *)(ib_attr + 1); |
| 1900 | if (eth_spec->type != IB_FLOW_SPEC_ETH || |
| 1901 | eth_spec->size != sizeof(*eth_spec)) |
| 1902 | return false; |
| 1903 | |
| 1904 | return is_multicast_ether_addr(eth_spec->mask.dst_mac) && |
| 1905 | is_multicast_ether_addr(eth_spec->val.dst_mac); |
| 1906 | } |
| 1907 | |
Maor Gottlieb | dd063d0 | 2016-08-28 14:16:32 +0300 | [diff] [blame] | 1908 | static bool is_valid_attr(const struct ib_flow_attr *flow_attr) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1909 | { |
| 1910 | union ib_flow_spec *ib_spec = (union ib_flow_spec *)(flow_attr + 1); |
| 1911 | bool has_ipv4_spec = false; |
| 1912 | bool eth_type_ipv4 = true; |
| 1913 | unsigned int spec_index; |
| 1914 | |
| 1915 | /* Validate that ethertype is correct */ |
| 1916 | for (spec_index = 0; spec_index < flow_attr->num_of_specs; spec_index++) { |
| 1917 | if (ib_spec->type == IB_FLOW_SPEC_ETH && |
| 1918 | ib_spec->eth.mask.ether_type) { |
| 1919 | if (!((ib_spec->eth.mask.ether_type == htons(0xffff)) && |
| 1920 | ib_spec->eth.val.ether_type == htons(ETH_P_IP))) |
| 1921 | eth_type_ipv4 = false; |
| 1922 | } else if (ib_spec->type == IB_FLOW_SPEC_IPV4) { |
| 1923 | has_ipv4_spec = true; |
| 1924 | } |
| 1925 | ib_spec = (void *)ib_spec + ib_spec->size; |
| 1926 | } |
| 1927 | return !has_ipv4_spec || eth_type_ipv4; |
| 1928 | } |
| 1929 | |
| 1930 | static void put_flow_table(struct mlx5_ib_dev *dev, |
| 1931 | struct mlx5_ib_flow_prio *prio, bool ft_added) |
| 1932 | { |
| 1933 | prio->refcount -= !!ft_added; |
| 1934 | if (!prio->refcount) { |
| 1935 | mlx5_destroy_flow_table(prio->flow_table); |
| 1936 | prio->flow_table = NULL; |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | static int mlx5_ib_destroy_flow(struct ib_flow *flow_id) |
| 1941 | { |
| 1942 | struct mlx5_ib_dev *dev = to_mdev(flow_id->qp->device); |
| 1943 | struct mlx5_ib_flow_handler *handler = container_of(flow_id, |
| 1944 | struct mlx5_ib_flow_handler, |
| 1945 | ibflow); |
| 1946 | struct mlx5_ib_flow_handler *iter, *tmp; |
| 1947 | |
| 1948 | mutex_lock(&dev->flow_db.lock); |
| 1949 | |
| 1950 | list_for_each_entry_safe(iter, tmp, &handler->list, list) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 1951 | mlx5_del_flow_rules(iter->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 1952 | put_flow_table(dev, iter->prio, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1953 | list_del(&iter->list); |
| 1954 | kfree(iter); |
| 1955 | } |
| 1956 | |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 1957 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 1958 | put_flow_table(dev, handler->prio, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1959 | mutex_unlock(&dev->flow_db.lock); |
| 1960 | |
| 1961 | kfree(handler); |
| 1962 | |
| 1963 | return 0; |
| 1964 | } |
| 1965 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 1966 | static int ib_prio_to_core_prio(unsigned int priority, bool dont_trap) |
| 1967 | { |
| 1968 | priority *= 2; |
| 1969 | if (!dont_trap) |
| 1970 | priority++; |
| 1971 | return priority; |
| 1972 | } |
| 1973 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 1974 | enum flow_table_type { |
| 1975 | MLX5_IB_FT_RX, |
| 1976 | MLX5_IB_FT_TX |
| 1977 | }; |
| 1978 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1979 | #define MLX5_FS_MAX_TYPES 10 |
| 1980 | #define MLX5_FS_MAX_ENTRIES 32000UL |
| 1981 | static struct mlx5_ib_flow_prio *get_flow_table(struct mlx5_ib_dev *dev, |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 1982 | struct ib_flow_attr *flow_attr, |
| 1983 | enum flow_table_type ft_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1984 | { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 1985 | bool dont_trap = flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1986 | struct mlx5_flow_namespace *ns = NULL; |
| 1987 | struct mlx5_ib_flow_prio *prio; |
| 1988 | struct mlx5_flow_table *ft; |
| 1989 | int num_entries; |
| 1990 | int num_groups; |
| 1991 | int priority; |
| 1992 | int err = 0; |
| 1993 | |
| 1994 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 1995 | if (flow_is_multicast_only(flow_attr) && |
| 1996 | !dont_trap) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 1997 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 1998 | else |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 1999 | priority = ib_prio_to_core_prio(flow_attr->priority, |
| 2000 | dont_trap); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2001 | ns = mlx5_get_flow_namespace(dev->mdev, |
| 2002 | MLX5_FLOW_NAMESPACE_BYPASS); |
| 2003 | num_entries = MLX5_FS_MAX_ENTRIES; |
| 2004 | num_groups = MLX5_FS_MAX_TYPES; |
| 2005 | prio = &dev->flow_db.prios[priority]; |
| 2006 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 2007 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 2008 | ns = mlx5_get_flow_namespace(dev->mdev, |
| 2009 | MLX5_FLOW_NAMESPACE_LEFTOVERS); |
| 2010 | build_leftovers_ft_param(&priority, |
| 2011 | &num_entries, |
| 2012 | &num_groups); |
| 2013 | prio = &dev->flow_db.prios[MLX5_IB_FLOW_LEFTOVERS_PRIO]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 2014 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 2015 | if (!MLX5_CAP_FLOWTABLE(dev->mdev, |
| 2016 | allow_sniffer_and_nic_rx_shared_tir)) |
| 2017 | return ERR_PTR(-ENOTSUPP); |
| 2018 | |
| 2019 | ns = mlx5_get_flow_namespace(dev->mdev, ft_type == MLX5_IB_FT_RX ? |
| 2020 | MLX5_FLOW_NAMESPACE_SNIFFER_RX : |
| 2021 | MLX5_FLOW_NAMESPACE_SNIFFER_TX); |
| 2022 | |
| 2023 | prio = &dev->flow_db.sniffer[ft_type]; |
| 2024 | priority = 0; |
| 2025 | num_entries = 1; |
| 2026 | num_groups = 1; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | if (!ns) |
| 2030 | return ERR_PTR(-ENOTSUPP); |
| 2031 | |
| 2032 | ft = prio->flow_table; |
| 2033 | if (!ft) { |
| 2034 | ft = mlx5_create_auto_grouped_flow_table(ns, priority, |
| 2035 | num_entries, |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 2036 | num_groups, |
Hadar Hen Zion | c9f1b07 | 2016-11-07 15:14:44 +0200 | [diff] [blame] | 2037 | 0, 0); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2038 | |
| 2039 | if (!IS_ERR(ft)) { |
| 2040 | prio->refcount = 0; |
| 2041 | prio->flow_table = ft; |
| 2042 | } else { |
| 2043 | err = PTR_ERR(ft); |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | return err ? ERR_PTR(err) : prio; |
| 2048 | } |
| 2049 | |
| 2050 | static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev, |
| 2051 | struct mlx5_ib_flow_prio *ft_prio, |
Maor Gottlieb | dd063d0 | 2016-08-28 14:16:32 +0300 | [diff] [blame] | 2052 | const struct ib_flow_attr *flow_attr, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2053 | struct mlx5_flow_destination *dst) |
| 2054 | { |
| 2055 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 2056 | struct mlx5_ib_flow_handler *handler; |
Hadar Hen Zion | 66958ed | 2016-11-07 15:14:45 +0200 | [diff] [blame] | 2057 | struct mlx5_flow_act flow_act = {0}; |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 2058 | struct mlx5_flow_spec *spec; |
Maor Gottlieb | dd063d0 | 2016-08-28 14:16:32 +0300 | [diff] [blame] | 2059 | const void *ib_flow = (const void *)flow_attr + sizeof(*flow_attr); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2060 | unsigned int spec_index; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2061 | int err = 0; |
| 2062 | |
| 2063 | if (!is_valid_attr(flow_attr)) |
| 2064 | return ERR_PTR(-EINVAL); |
| 2065 | |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 2066 | spec = mlx5_vzalloc(sizeof(*spec)); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2067 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 2068 | if (!handler || !spec) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2069 | err = -ENOMEM; |
| 2070 | goto free; |
| 2071 | } |
| 2072 | |
| 2073 | INIT_LIST_HEAD(&handler->list); |
| 2074 | |
| 2075 | for (spec_index = 0; spec_index < flow_attr->num_of_specs; spec_index++) { |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 2076 | err = parse_flow_attr(spec->match_criteria, |
| 2077 | spec->match_value, ib_flow); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2078 | if (err < 0) |
| 2079 | goto free; |
| 2080 | |
| 2081 | ib_flow += ((union ib_flow_spec *)ib_flow)->size; |
| 2082 | } |
| 2083 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2084 | spec->match_criteria_enable = get_match_criteria_enable(spec->match_criteria); |
Hadar Hen Zion | 66958ed | 2016-11-07 15:14:45 +0200 | [diff] [blame] | 2085 | flow_act.action = dst ? MLX5_FLOW_CONTEXT_ACTION_FWD_DEST : |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 2086 | MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO; |
Hadar Hen Zion | 66958ed | 2016-11-07 15:14:45 +0200 | [diff] [blame] | 2087 | flow_act.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG; |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 2088 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Hadar Hen Zion | 66958ed | 2016-11-07 15:14:45 +0200 | [diff] [blame] | 2089 | &flow_act, |
| 2090 | dst, 1); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2091 | |
| 2092 | if (IS_ERR(handler->rule)) { |
| 2093 | err = PTR_ERR(handler->rule); |
| 2094 | goto free; |
| 2095 | } |
| 2096 | |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 2097 | ft_prio->refcount++; |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 2098 | handler->prio = ft_prio; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2099 | |
| 2100 | ft_prio->flow_table = ft; |
| 2101 | free: |
| 2102 | if (err) |
| 2103 | kfree(handler); |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 2104 | kvfree(spec); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2105 | return err ? ERR_PTR(err) : handler; |
| 2106 | } |
| 2107 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 2108 | static struct mlx5_ib_flow_handler *create_dont_trap_rule(struct mlx5_ib_dev *dev, |
| 2109 | struct mlx5_ib_flow_prio *ft_prio, |
| 2110 | struct ib_flow_attr *flow_attr, |
| 2111 | struct mlx5_flow_destination *dst) |
| 2112 | { |
| 2113 | struct mlx5_ib_flow_handler *handler_dst = NULL; |
| 2114 | struct mlx5_ib_flow_handler *handler = NULL; |
| 2115 | |
| 2116 | handler = create_flow_rule(dev, ft_prio, flow_attr, NULL); |
| 2117 | if (!IS_ERR(handler)) { |
| 2118 | handler_dst = create_flow_rule(dev, ft_prio, |
| 2119 | flow_attr, dst); |
| 2120 | if (IS_ERR(handler_dst)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 2121 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 2122 | ft_prio->refcount--; |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 2123 | kfree(handler); |
| 2124 | handler = handler_dst; |
| 2125 | } else { |
| 2126 | list_add(&handler_dst->list, &handler->list); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | return handler; |
| 2131 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2132 | enum { |
| 2133 | LEFTOVERS_MC, |
| 2134 | LEFTOVERS_UC, |
| 2135 | }; |
| 2136 | |
| 2137 | static struct mlx5_ib_flow_handler *create_leftovers_rule(struct mlx5_ib_dev *dev, |
| 2138 | struct mlx5_ib_flow_prio *ft_prio, |
| 2139 | struct ib_flow_attr *flow_attr, |
| 2140 | struct mlx5_flow_destination *dst) |
| 2141 | { |
| 2142 | struct mlx5_ib_flow_handler *handler_ucast = NULL; |
| 2143 | struct mlx5_ib_flow_handler *handler = NULL; |
| 2144 | |
| 2145 | static struct { |
| 2146 | struct ib_flow_attr flow_attr; |
| 2147 | struct ib_flow_spec_eth eth_flow; |
| 2148 | } leftovers_specs[] = { |
| 2149 | [LEFTOVERS_MC] = { |
| 2150 | .flow_attr = { |
| 2151 | .num_of_specs = 1, |
| 2152 | .size = sizeof(leftovers_specs[0]) |
| 2153 | }, |
| 2154 | .eth_flow = { |
| 2155 | .type = IB_FLOW_SPEC_ETH, |
| 2156 | .size = sizeof(struct ib_flow_spec_eth), |
| 2157 | .mask = {.dst_mac = {0x1} }, |
| 2158 | .val = {.dst_mac = {0x1} } |
| 2159 | } |
| 2160 | }, |
| 2161 | [LEFTOVERS_UC] = { |
| 2162 | .flow_attr = { |
| 2163 | .num_of_specs = 1, |
| 2164 | .size = sizeof(leftovers_specs[0]) |
| 2165 | }, |
| 2166 | .eth_flow = { |
| 2167 | .type = IB_FLOW_SPEC_ETH, |
| 2168 | .size = sizeof(struct ib_flow_spec_eth), |
| 2169 | .mask = {.dst_mac = {0x1} }, |
| 2170 | .val = {.dst_mac = {} } |
| 2171 | } |
| 2172 | } |
| 2173 | }; |
| 2174 | |
| 2175 | handler = create_flow_rule(dev, ft_prio, |
| 2176 | &leftovers_specs[LEFTOVERS_MC].flow_attr, |
| 2177 | dst); |
| 2178 | if (!IS_ERR(handler) && |
| 2179 | flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT) { |
| 2180 | handler_ucast = create_flow_rule(dev, ft_prio, |
| 2181 | &leftovers_specs[LEFTOVERS_UC].flow_attr, |
| 2182 | dst); |
| 2183 | if (IS_ERR(handler_ucast)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 2184 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 2185 | ft_prio->refcount--; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2186 | kfree(handler); |
| 2187 | handler = handler_ucast; |
| 2188 | } else { |
| 2189 | list_add(&handler_ucast->list, &handler->list); |
| 2190 | } |
| 2191 | } |
| 2192 | |
| 2193 | return handler; |
| 2194 | } |
| 2195 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 2196 | static struct mlx5_ib_flow_handler *create_sniffer_rule(struct mlx5_ib_dev *dev, |
| 2197 | struct mlx5_ib_flow_prio *ft_rx, |
| 2198 | struct mlx5_ib_flow_prio *ft_tx, |
| 2199 | struct mlx5_flow_destination *dst) |
| 2200 | { |
| 2201 | struct mlx5_ib_flow_handler *handler_rx; |
| 2202 | struct mlx5_ib_flow_handler *handler_tx; |
| 2203 | int err; |
| 2204 | static const struct ib_flow_attr flow_attr = { |
| 2205 | .num_of_specs = 0, |
| 2206 | .size = sizeof(flow_attr) |
| 2207 | }; |
| 2208 | |
| 2209 | handler_rx = create_flow_rule(dev, ft_rx, &flow_attr, dst); |
| 2210 | if (IS_ERR(handler_rx)) { |
| 2211 | err = PTR_ERR(handler_rx); |
| 2212 | goto err; |
| 2213 | } |
| 2214 | |
| 2215 | handler_tx = create_flow_rule(dev, ft_tx, &flow_attr, dst); |
| 2216 | if (IS_ERR(handler_tx)) { |
| 2217 | err = PTR_ERR(handler_tx); |
| 2218 | goto err_tx; |
| 2219 | } |
| 2220 | |
| 2221 | list_add(&handler_tx->list, &handler_rx->list); |
| 2222 | |
| 2223 | return handler_rx; |
| 2224 | |
| 2225 | err_tx: |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 2226 | mlx5_del_flow_rules(handler_rx->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 2227 | ft_rx->refcount--; |
| 2228 | kfree(handler_rx); |
| 2229 | err: |
| 2230 | return ERR_PTR(err); |
| 2231 | } |
| 2232 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2233 | static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, |
| 2234 | struct ib_flow_attr *flow_attr, |
| 2235 | int domain) |
| 2236 | { |
| 2237 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Yishai Hadas | d9f88e5 | 2016-08-28 10:58:37 +0300 | [diff] [blame] | 2238 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2239 | struct mlx5_ib_flow_handler *handler = NULL; |
| 2240 | struct mlx5_flow_destination *dst = NULL; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 2241 | struct mlx5_ib_flow_prio *ft_prio_tx = NULL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2242 | struct mlx5_ib_flow_prio *ft_prio; |
| 2243 | int err; |
| 2244 | |
| 2245 | if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) |
| 2246 | return ERR_PTR(-ENOSPC); |
| 2247 | |
| 2248 | if (domain != IB_FLOW_DOMAIN_USER || |
| 2249 | flow_attr->port > MLX5_CAP_GEN(dev->mdev, num_ports) || |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 2250 | (flow_attr->flags & ~IB_FLOW_ATTR_FLAGS_DONT_TRAP)) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2251 | return ERR_PTR(-EINVAL); |
| 2252 | |
| 2253 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
| 2254 | if (!dst) |
| 2255 | return ERR_PTR(-ENOMEM); |
| 2256 | |
| 2257 | mutex_lock(&dev->flow_db.lock); |
| 2258 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 2259 | ft_prio = get_flow_table(dev, flow_attr, MLX5_IB_FT_RX); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2260 | if (IS_ERR(ft_prio)) { |
| 2261 | err = PTR_ERR(ft_prio); |
| 2262 | goto unlock; |
| 2263 | } |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 2264 | if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 2265 | ft_prio_tx = get_flow_table(dev, flow_attr, MLX5_IB_FT_TX); |
| 2266 | if (IS_ERR(ft_prio_tx)) { |
| 2267 | err = PTR_ERR(ft_prio_tx); |
| 2268 | ft_prio_tx = NULL; |
| 2269 | goto destroy_ft; |
| 2270 | } |
| 2271 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2272 | |
| 2273 | dst->type = MLX5_FLOW_DESTINATION_TYPE_TIR; |
Yishai Hadas | d9f88e5 | 2016-08-28 10:58:37 +0300 | [diff] [blame] | 2274 | if (mqp->flags & MLX5_IB_QP_RSS) |
| 2275 | dst->tir_num = mqp->rss_qp.tirn; |
| 2276 | else |
| 2277 | dst->tir_num = mqp->raw_packet_qp.rq.tirn; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2278 | |
| 2279 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 2280 | if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) { |
| 2281 | handler = create_dont_trap_rule(dev, ft_prio, |
| 2282 | flow_attr, dst); |
| 2283 | } else { |
| 2284 | handler = create_flow_rule(dev, ft_prio, flow_attr, |
| 2285 | dst); |
| 2286 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2287 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 2288 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 2289 | handler = create_leftovers_rule(dev, ft_prio, flow_attr, |
| 2290 | dst); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 2291 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 2292 | handler = create_sniffer_rule(dev, ft_prio, ft_prio_tx, dst); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2293 | } else { |
| 2294 | err = -EINVAL; |
| 2295 | goto destroy_ft; |
| 2296 | } |
| 2297 | |
| 2298 | if (IS_ERR(handler)) { |
| 2299 | err = PTR_ERR(handler); |
| 2300 | handler = NULL; |
| 2301 | goto destroy_ft; |
| 2302 | } |
| 2303 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2304 | mutex_unlock(&dev->flow_db.lock); |
| 2305 | kfree(dst); |
| 2306 | |
| 2307 | return &handler->ibflow; |
| 2308 | |
| 2309 | destroy_ft: |
| 2310 | put_flow_table(dev, ft_prio, false); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 2311 | if (ft_prio_tx) |
| 2312 | put_flow_table(dev, ft_prio_tx, false); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2313 | unlock: |
| 2314 | mutex_unlock(&dev->flow_db.lock); |
| 2315 | kfree(dst); |
| 2316 | kfree(handler); |
| 2317 | return ERR_PTR(err); |
| 2318 | } |
| 2319 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2320 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 2321 | { |
| 2322 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 2323 | int err; |
| 2324 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2325 | err = mlx5_core_attach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2326 | if (err) |
| 2327 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
| 2328 | ibqp->qp_num, gid->raw); |
| 2329 | |
| 2330 | return err; |
| 2331 | } |
| 2332 | |
| 2333 | static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 2334 | { |
| 2335 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 2336 | int err; |
| 2337 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2338 | err = mlx5_core_detach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2339 | if (err) |
| 2340 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
| 2341 | ibqp->qp_num, gid->raw); |
| 2342 | |
| 2343 | return err; |
| 2344 | } |
| 2345 | |
| 2346 | static int init_node_data(struct mlx5_ib_dev *dev) |
| 2347 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 2348 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2349 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 2350 | err = mlx5_query_node_desc(dev, dev->ib_dev.node_desc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2351 | if (err) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 2352 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2353 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 2354 | dev->mdev->rev_id = dev->mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2355 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 2356 | return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | static ssize_t show_fw_pages(struct device *device, struct device_attribute *attr, |
| 2360 | char *buf) |
| 2361 | { |
| 2362 | struct mlx5_ib_dev *dev = |
| 2363 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 2364 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2365 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | static ssize_t show_reg_pages(struct device *device, |
| 2369 | struct device_attribute *attr, char *buf) |
| 2370 | { |
| 2371 | struct mlx5_ib_dev *dev = |
| 2372 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 2373 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 2374 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | static ssize_t show_hca(struct device *device, struct device_attribute *attr, |
| 2378 | char *buf) |
| 2379 | { |
| 2380 | struct mlx5_ib_dev *dev = |
| 2381 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2382 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2383 | } |
| 2384 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2385 | static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
| 2386 | char *buf) |
| 2387 | { |
| 2388 | struct mlx5_ib_dev *dev = |
| 2389 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2390 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | static ssize_t show_board(struct device *device, struct device_attribute *attr, |
| 2394 | char *buf) |
| 2395 | { |
| 2396 | struct mlx5_ib_dev *dev = |
| 2397 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 2398 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2399 | dev->mdev->board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2403 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 2404 | static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
| 2405 | static DEVICE_ATTR(fw_pages, S_IRUGO, show_fw_pages, NULL); |
| 2406 | static DEVICE_ATTR(reg_pages, S_IRUGO, show_reg_pages, NULL); |
| 2407 | |
| 2408 | static struct device_attribute *mlx5_class_attributes[] = { |
| 2409 | &dev_attr_hw_rev, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2410 | &dev_attr_hca_type, |
| 2411 | &dev_attr_board_id, |
| 2412 | &dev_attr_fw_pages, |
| 2413 | &dev_attr_reg_pages, |
| 2414 | }; |
| 2415 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 2416 | static void pkey_change_handler(struct work_struct *work) |
| 2417 | { |
| 2418 | struct mlx5_ib_port_resources *ports = |
| 2419 | container_of(work, struct mlx5_ib_port_resources, |
| 2420 | pkey_change_work); |
| 2421 | |
| 2422 | mutex_lock(&ports->devr->mutex); |
| 2423 | mlx5_ib_gsi_pkey_change(ports->gsi); |
| 2424 | mutex_unlock(&ports->devr->mutex); |
| 2425 | } |
| 2426 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2427 | static void mlx5_ib_handle_internal_error(struct mlx5_ib_dev *ibdev) |
| 2428 | { |
| 2429 | struct mlx5_ib_qp *mqp; |
| 2430 | struct mlx5_ib_cq *send_mcq, *recv_mcq; |
| 2431 | struct mlx5_core_cq *mcq; |
| 2432 | struct list_head cq_armed_list; |
| 2433 | unsigned long flags_qp; |
| 2434 | unsigned long flags_cq; |
| 2435 | unsigned long flags; |
| 2436 | |
| 2437 | INIT_LIST_HEAD(&cq_armed_list); |
| 2438 | |
| 2439 | /* Go over qp list reside on that ibdev, sync with create/destroy qp.*/ |
| 2440 | spin_lock_irqsave(&ibdev->reset_flow_resource_lock, flags); |
| 2441 | list_for_each_entry(mqp, &ibdev->qp_list, qps_list) { |
| 2442 | spin_lock_irqsave(&mqp->sq.lock, flags_qp); |
| 2443 | if (mqp->sq.tail != mqp->sq.head) { |
| 2444 | send_mcq = to_mcq(mqp->ibqp.send_cq); |
| 2445 | spin_lock_irqsave(&send_mcq->lock, flags_cq); |
| 2446 | if (send_mcq->mcq.comp && |
| 2447 | mqp->ibqp.send_cq->comp_handler) { |
| 2448 | if (!send_mcq->mcq.reset_notify_added) { |
| 2449 | send_mcq->mcq.reset_notify_added = 1; |
| 2450 | list_add_tail(&send_mcq->mcq.reset_notify, |
| 2451 | &cq_armed_list); |
| 2452 | } |
| 2453 | } |
| 2454 | spin_unlock_irqrestore(&send_mcq->lock, flags_cq); |
| 2455 | } |
| 2456 | spin_unlock_irqrestore(&mqp->sq.lock, flags_qp); |
| 2457 | spin_lock_irqsave(&mqp->rq.lock, flags_qp); |
| 2458 | /* no handling is needed for SRQ */ |
| 2459 | if (!mqp->ibqp.srq) { |
| 2460 | if (mqp->rq.tail != mqp->rq.head) { |
| 2461 | recv_mcq = to_mcq(mqp->ibqp.recv_cq); |
| 2462 | spin_lock_irqsave(&recv_mcq->lock, flags_cq); |
| 2463 | if (recv_mcq->mcq.comp && |
| 2464 | mqp->ibqp.recv_cq->comp_handler) { |
| 2465 | if (!recv_mcq->mcq.reset_notify_added) { |
| 2466 | recv_mcq->mcq.reset_notify_added = 1; |
| 2467 | list_add_tail(&recv_mcq->mcq.reset_notify, |
| 2468 | &cq_armed_list); |
| 2469 | } |
| 2470 | } |
| 2471 | spin_unlock_irqrestore(&recv_mcq->lock, |
| 2472 | flags_cq); |
| 2473 | } |
| 2474 | } |
| 2475 | spin_unlock_irqrestore(&mqp->rq.lock, flags_qp); |
| 2476 | } |
| 2477 | /*At that point all inflight post send were put to be executed as of we |
| 2478 | * lock/unlock above locks Now need to arm all involved CQs. |
| 2479 | */ |
| 2480 | list_for_each_entry(mcq, &cq_armed_list, reset_notify) { |
| 2481 | mcq->comp(mcq); |
| 2482 | } |
| 2483 | spin_unlock_irqrestore(&ibdev->reset_flow_resource_lock, flags); |
| 2484 | } |
| 2485 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2486 | static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context, |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 2487 | enum mlx5_dev_event event, unsigned long param) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2488 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2489 | struct mlx5_ib_dev *ibdev = (struct mlx5_ib_dev *)context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2490 | struct ib_event ibev; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 2491 | bool fatal = false; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2492 | u8 port = 0; |
| 2493 | |
| 2494 | switch (event) { |
| 2495 | case MLX5_DEV_EVENT_SYS_ERROR: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2496 | ibev.event = IB_EVENT_DEVICE_FATAL; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2497 | mlx5_ib_handle_internal_error(ibdev); |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 2498 | fatal = true; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2499 | break; |
| 2500 | |
| 2501 | case MLX5_DEV_EVENT_PORT_UP: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2502 | case MLX5_DEV_EVENT_PORT_DOWN: |
Noa Osherovich | 2788cf3 | 2016-06-04 15:15:29 +0300 | [diff] [blame] | 2503 | case MLX5_DEV_EVENT_PORT_INITIALIZED: |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 2504 | port = (u8)param; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 2505 | |
| 2506 | /* In RoCE, port up/down events are handled in |
| 2507 | * mlx5_netdev_event(). |
| 2508 | */ |
| 2509 | if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
| 2510 | IB_LINK_LAYER_ETHERNET) |
| 2511 | return; |
| 2512 | |
| 2513 | ibev.event = (event == MLX5_DEV_EVENT_PORT_UP) ? |
| 2514 | IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2515 | break; |
| 2516 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2517 | case MLX5_DEV_EVENT_LID_CHANGE: |
| 2518 | ibev.event = IB_EVENT_LID_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 2519 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2520 | break; |
| 2521 | |
| 2522 | case MLX5_DEV_EVENT_PKEY_CHANGE: |
| 2523 | ibev.event = IB_EVENT_PKEY_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 2524 | port = (u8)param; |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 2525 | |
| 2526 | schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2527 | break; |
| 2528 | |
| 2529 | case MLX5_DEV_EVENT_GUID_CHANGE: |
| 2530 | ibev.event = IB_EVENT_GID_CHANGE; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 2531 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2532 | break; |
| 2533 | |
| 2534 | case MLX5_DEV_EVENT_CLIENT_REREG: |
| 2535 | ibev.event = IB_EVENT_CLIENT_REREGISTER; |
Jack Morgenstein | 4d2f9bb | 2014-07-28 23:30:24 +0300 | [diff] [blame] | 2536 | port = (u8)param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2537 | break; |
Saeed Mahameed | bdc3792 | 2016-09-29 19:35:38 +0300 | [diff] [blame] | 2538 | default: |
| 2539 | return; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | ibev.device = &ibdev->ib_dev; |
| 2543 | ibev.element.port_num = port; |
| 2544 | |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 2545 | if (port < 1 || port > ibdev->num_ports) { |
| 2546 | mlx5_ib_warn(ibdev, "warning: event on port %d\n", port); |
| 2547 | return; |
| 2548 | } |
| 2549 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2550 | if (ibdev->ib_active) |
| 2551 | ib_dispatch_event(&ibev); |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 2552 | |
| 2553 | if (fatal) |
| 2554 | ibdev->ib_active = false; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2555 | } |
| 2556 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 2557 | static int set_has_smi_cap(struct mlx5_ib_dev *dev) |
| 2558 | { |
| 2559 | struct mlx5_hca_vport_context vport_ctx; |
| 2560 | int err; |
| 2561 | int port; |
| 2562 | |
| 2563 | for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++) { |
| 2564 | dev->mdev->port_caps[port - 1].has_smi = false; |
| 2565 | if (MLX5_CAP_GEN(dev->mdev, port_type) == |
| 2566 | MLX5_CAP_PORT_TYPE_IB) { |
| 2567 | if (MLX5_CAP_GEN(dev->mdev, ib_virt)) { |
| 2568 | err = mlx5_query_hca_vport_context(dev->mdev, 0, |
| 2569 | port, 0, |
| 2570 | &vport_ctx); |
| 2571 | if (err) { |
| 2572 | mlx5_ib_err(dev, "query_hca_vport_context for port=%d failed %d\n", |
| 2573 | port, err); |
| 2574 | return err; |
| 2575 | } |
| 2576 | dev->mdev->port_caps[port - 1].has_smi = |
| 2577 | vport_ctx.has_smi; |
| 2578 | } else { |
| 2579 | dev->mdev->port_caps[port - 1].has_smi = true; |
| 2580 | } |
| 2581 | } |
| 2582 | } |
| 2583 | return 0; |
| 2584 | } |
| 2585 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2586 | static void get_ext_port_caps(struct mlx5_ib_dev *dev) |
| 2587 | { |
| 2588 | int port; |
| 2589 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2590 | for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2591 | mlx5_query_ext_port_caps(dev, port); |
| 2592 | } |
| 2593 | |
| 2594 | static int get_port_caps(struct mlx5_ib_dev *dev) |
| 2595 | { |
| 2596 | struct ib_device_attr *dprops = NULL; |
| 2597 | struct ib_port_attr *pprops = NULL; |
Dan Carpenter | f614fc1 | 2015-01-12 11:56:58 +0300 | [diff] [blame] | 2598 | int err = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2599 | int port; |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 2600 | struct ib_udata uhw = {.inlen = 0, .outlen = 0}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2601 | |
| 2602 | pprops = kmalloc(sizeof(*pprops), GFP_KERNEL); |
| 2603 | if (!pprops) |
| 2604 | goto out; |
| 2605 | |
| 2606 | dprops = kmalloc(sizeof(*dprops), GFP_KERNEL); |
| 2607 | if (!dprops) |
| 2608 | goto out; |
| 2609 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 2610 | err = set_has_smi_cap(dev); |
| 2611 | if (err) |
| 2612 | goto out; |
| 2613 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 2614 | err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2615 | if (err) { |
| 2616 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
| 2617 | goto out; |
| 2618 | } |
| 2619 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2620 | for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2621 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
| 2622 | if (err) { |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2623 | mlx5_ib_warn(dev, "query_port %d failed %d\n", |
| 2624 | port, err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2625 | break; |
| 2626 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2627 | dev->mdev->port_caps[port - 1].pkey_table_len = |
| 2628 | dprops->max_pkeys; |
| 2629 | dev->mdev->port_caps[port - 1].gid_table_len = |
| 2630 | pprops->gid_tbl_len; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2631 | mlx5_ib_dbg(dev, "pkey_table_len %d, gid_table_len %d\n", |
| 2632 | dprops->max_pkeys, pprops->gid_tbl_len); |
| 2633 | } |
| 2634 | |
| 2635 | out: |
| 2636 | kfree(pprops); |
| 2637 | kfree(dprops); |
| 2638 | |
| 2639 | return err; |
| 2640 | } |
| 2641 | |
| 2642 | static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
| 2643 | { |
| 2644 | int err; |
| 2645 | |
| 2646 | err = mlx5_mr_cache_cleanup(dev); |
| 2647 | if (err) |
| 2648 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
| 2649 | |
| 2650 | mlx5_ib_destroy_qp(dev->umrc.qp); |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 2651 | ib_free_cq(dev->umrc.cq); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2652 | ib_dealloc_pd(dev->umrc.pd); |
| 2653 | } |
| 2654 | |
| 2655 | enum { |
| 2656 | MAX_UMR_WR = 128, |
| 2657 | }; |
| 2658 | |
| 2659 | static int create_umr_res(struct mlx5_ib_dev *dev) |
| 2660 | { |
| 2661 | struct ib_qp_init_attr *init_attr = NULL; |
| 2662 | struct ib_qp_attr *attr = NULL; |
| 2663 | struct ib_pd *pd; |
| 2664 | struct ib_cq *cq; |
| 2665 | struct ib_qp *qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2666 | int ret; |
| 2667 | |
| 2668 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| 2669 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 2670 | if (!attr || !init_attr) { |
| 2671 | ret = -ENOMEM; |
| 2672 | goto error_0; |
| 2673 | } |
| 2674 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 2675 | pd = ib_alloc_pd(&dev->ib_dev, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2676 | if (IS_ERR(pd)) { |
| 2677 | mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); |
| 2678 | ret = PTR_ERR(pd); |
| 2679 | goto error_0; |
| 2680 | } |
| 2681 | |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 2682 | cq = ib_alloc_cq(&dev->ib_dev, NULL, 128, 0, IB_POLL_SOFTIRQ); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2683 | if (IS_ERR(cq)) { |
| 2684 | mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); |
| 2685 | ret = PTR_ERR(cq); |
| 2686 | goto error_2; |
| 2687 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2688 | |
| 2689 | init_attr->send_cq = cq; |
| 2690 | init_attr->recv_cq = cq; |
| 2691 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
| 2692 | init_attr->cap.max_send_wr = MAX_UMR_WR; |
| 2693 | init_attr->cap.max_send_sge = 1; |
| 2694 | init_attr->qp_type = MLX5_IB_QPT_REG_UMR; |
| 2695 | init_attr->port_num = 1; |
| 2696 | qp = mlx5_ib_create_qp(pd, init_attr, NULL); |
| 2697 | if (IS_ERR(qp)) { |
| 2698 | mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); |
| 2699 | ret = PTR_ERR(qp); |
| 2700 | goto error_3; |
| 2701 | } |
| 2702 | qp->device = &dev->ib_dev; |
| 2703 | qp->real_qp = qp; |
| 2704 | qp->uobject = NULL; |
| 2705 | qp->qp_type = MLX5_IB_QPT_REG_UMR; |
| 2706 | |
| 2707 | attr->qp_state = IB_QPS_INIT; |
| 2708 | attr->port_num = 1; |
| 2709 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX | |
| 2710 | IB_QP_PORT, NULL); |
| 2711 | if (ret) { |
| 2712 | mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); |
| 2713 | goto error_4; |
| 2714 | } |
| 2715 | |
| 2716 | memset(attr, 0, sizeof(*attr)); |
| 2717 | attr->qp_state = IB_QPS_RTR; |
| 2718 | attr->path_mtu = IB_MTU_256; |
| 2719 | |
| 2720 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 2721 | if (ret) { |
| 2722 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); |
| 2723 | goto error_4; |
| 2724 | } |
| 2725 | |
| 2726 | memset(attr, 0, sizeof(*attr)); |
| 2727 | attr->qp_state = IB_QPS_RTS; |
| 2728 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 2729 | if (ret) { |
| 2730 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); |
| 2731 | goto error_4; |
| 2732 | } |
| 2733 | |
| 2734 | dev->umrc.qp = qp; |
| 2735 | dev->umrc.cq = cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2736 | dev->umrc.pd = pd; |
| 2737 | |
| 2738 | sema_init(&dev->umrc.sem, MAX_UMR_WR); |
| 2739 | ret = mlx5_mr_cache_init(dev); |
| 2740 | if (ret) { |
| 2741 | mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); |
| 2742 | goto error_4; |
| 2743 | } |
| 2744 | |
| 2745 | kfree(attr); |
| 2746 | kfree(init_attr); |
| 2747 | |
| 2748 | return 0; |
| 2749 | |
| 2750 | error_4: |
| 2751 | mlx5_ib_destroy_qp(qp); |
| 2752 | |
| 2753 | error_3: |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 2754 | ib_free_cq(cq); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2755 | |
| 2756 | error_2: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2757 | ib_dealloc_pd(pd); |
| 2758 | |
| 2759 | error_0: |
| 2760 | kfree(attr); |
| 2761 | kfree(init_attr); |
| 2762 | return ret; |
| 2763 | } |
| 2764 | |
| 2765 | static int create_dev_resources(struct mlx5_ib_resources *devr) |
| 2766 | { |
| 2767 | struct ib_srq_init_attr attr; |
| 2768 | struct mlx5_ib_dev *dev; |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 2769 | struct ib_cq_init_attr cq_attr = {.cqe = 1}; |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 2770 | int port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2771 | int ret = 0; |
| 2772 | |
| 2773 | dev = container_of(devr, struct mlx5_ib_dev, devr); |
| 2774 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 2775 | mutex_init(&devr->mutex); |
| 2776 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2777 | devr->p0 = mlx5_ib_alloc_pd(&dev->ib_dev, NULL, NULL); |
| 2778 | if (IS_ERR(devr->p0)) { |
| 2779 | ret = PTR_ERR(devr->p0); |
| 2780 | goto error0; |
| 2781 | } |
| 2782 | devr->p0->device = &dev->ib_dev; |
| 2783 | devr->p0->uobject = NULL; |
| 2784 | atomic_set(&devr->p0->usecnt, 0); |
| 2785 | |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 2786 | 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] | 2787 | if (IS_ERR(devr->c0)) { |
| 2788 | ret = PTR_ERR(devr->c0); |
| 2789 | goto error1; |
| 2790 | } |
| 2791 | devr->c0->device = &dev->ib_dev; |
| 2792 | devr->c0->uobject = NULL; |
| 2793 | devr->c0->comp_handler = NULL; |
| 2794 | devr->c0->event_handler = NULL; |
| 2795 | devr->c0->cq_context = NULL; |
| 2796 | atomic_set(&devr->c0->usecnt, 0); |
| 2797 | |
| 2798 | devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 2799 | if (IS_ERR(devr->x0)) { |
| 2800 | ret = PTR_ERR(devr->x0); |
| 2801 | goto error2; |
| 2802 | } |
| 2803 | devr->x0->device = &dev->ib_dev; |
| 2804 | devr->x0->inode = NULL; |
| 2805 | atomic_set(&devr->x0->usecnt, 0); |
| 2806 | mutex_init(&devr->x0->tgt_qp_mutex); |
| 2807 | INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
| 2808 | |
| 2809 | devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 2810 | if (IS_ERR(devr->x1)) { |
| 2811 | ret = PTR_ERR(devr->x1); |
| 2812 | goto error3; |
| 2813 | } |
| 2814 | devr->x1->device = &dev->ib_dev; |
| 2815 | devr->x1->inode = NULL; |
| 2816 | atomic_set(&devr->x1->usecnt, 0); |
| 2817 | mutex_init(&devr->x1->tgt_qp_mutex); |
| 2818 | INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
| 2819 | |
| 2820 | memset(&attr, 0, sizeof(attr)); |
| 2821 | attr.attr.max_sge = 1; |
| 2822 | attr.attr.max_wr = 1; |
| 2823 | attr.srq_type = IB_SRQT_XRC; |
| 2824 | attr.ext.xrc.cq = devr->c0; |
| 2825 | attr.ext.xrc.xrcd = devr->x0; |
| 2826 | |
| 2827 | devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 2828 | if (IS_ERR(devr->s0)) { |
| 2829 | ret = PTR_ERR(devr->s0); |
| 2830 | goto error4; |
| 2831 | } |
| 2832 | devr->s0->device = &dev->ib_dev; |
| 2833 | devr->s0->pd = devr->p0; |
| 2834 | devr->s0->uobject = NULL; |
| 2835 | devr->s0->event_handler = NULL; |
| 2836 | devr->s0->srq_context = NULL; |
| 2837 | devr->s0->srq_type = IB_SRQT_XRC; |
| 2838 | devr->s0->ext.xrc.xrcd = devr->x0; |
| 2839 | devr->s0->ext.xrc.cq = devr->c0; |
| 2840 | atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
| 2841 | atomic_inc(&devr->s0->ext.xrc.cq->usecnt); |
| 2842 | atomic_inc(&devr->p0->usecnt); |
| 2843 | atomic_set(&devr->s0->usecnt, 0); |
| 2844 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 2845 | memset(&attr, 0, sizeof(attr)); |
| 2846 | attr.attr.max_sge = 1; |
| 2847 | attr.attr.max_wr = 1; |
| 2848 | attr.srq_type = IB_SRQT_BASIC; |
| 2849 | devr->s1 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 2850 | if (IS_ERR(devr->s1)) { |
| 2851 | ret = PTR_ERR(devr->s1); |
| 2852 | goto error5; |
| 2853 | } |
| 2854 | devr->s1->device = &dev->ib_dev; |
| 2855 | devr->s1->pd = devr->p0; |
| 2856 | devr->s1->uobject = NULL; |
| 2857 | devr->s1->event_handler = NULL; |
| 2858 | devr->s1->srq_context = NULL; |
| 2859 | devr->s1->srq_type = IB_SRQT_BASIC; |
| 2860 | devr->s1->ext.xrc.cq = devr->c0; |
| 2861 | atomic_inc(&devr->p0->usecnt); |
| 2862 | atomic_set(&devr->s0->usecnt, 0); |
| 2863 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 2864 | for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) { |
| 2865 | INIT_WORK(&devr->ports[port].pkey_change_work, |
| 2866 | pkey_change_handler); |
| 2867 | devr->ports[port].devr = devr; |
| 2868 | } |
| 2869 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2870 | return 0; |
| 2871 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 2872 | error5: |
| 2873 | mlx5_ib_destroy_srq(devr->s0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2874 | error4: |
| 2875 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 2876 | error3: |
| 2877 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 2878 | error2: |
| 2879 | mlx5_ib_destroy_cq(devr->c0); |
| 2880 | error1: |
| 2881 | mlx5_ib_dealloc_pd(devr->p0); |
| 2882 | error0: |
| 2883 | return ret; |
| 2884 | } |
| 2885 | |
| 2886 | static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
| 2887 | { |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 2888 | struct mlx5_ib_dev *dev = |
| 2889 | container_of(devr, struct mlx5_ib_dev, devr); |
| 2890 | int port; |
| 2891 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 2892 | mlx5_ib_destroy_srq(devr->s1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2893 | mlx5_ib_destroy_srq(devr->s0); |
| 2894 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 2895 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 2896 | mlx5_ib_destroy_cq(devr->c0); |
| 2897 | mlx5_ib_dealloc_pd(devr->p0); |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 2898 | |
| 2899 | /* Make sure no change P_Key work items are still executing */ |
| 2900 | for (port = 0; port < dev->num_ports; ++port) |
| 2901 | cancel_work_sync(&devr->ports[port].pkey_change_work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2902 | } |
| 2903 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 2904 | static u32 get_core_cap_flags(struct ib_device *ibdev) |
| 2905 | { |
| 2906 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 2907 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, 1); |
| 2908 | u8 l3_type_cap = MLX5_CAP_ROCE(dev->mdev, l3_type); |
| 2909 | u8 roce_version_cap = MLX5_CAP_ROCE(dev->mdev, roce_version); |
| 2910 | u32 ret = 0; |
| 2911 | |
| 2912 | if (ll == IB_LINK_LAYER_INFINIBAND) |
| 2913 | return RDMA_CORE_PORT_IBA_IB; |
| 2914 | |
| 2915 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV4_CAP)) |
| 2916 | return 0; |
| 2917 | |
| 2918 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV6_CAP)) |
| 2919 | return 0; |
| 2920 | |
| 2921 | if (roce_version_cap & MLX5_ROCE_VERSION_1_CAP) |
| 2922 | ret |= RDMA_CORE_PORT_IBA_ROCE; |
| 2923 | |
| 2924 | if (roce_version_cap & MLX5_ROCE_VERSION_2_CAP) |
| 2925 | ret |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; |
| 2926 | |
| 2927 | return ret; |
| 2928 | } |
| 2929 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2930 | static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 2931 | struct ib_port_immutable *immutable) |
| 2932 | { |
| 2933 | struct ib_port_attr attr; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 2934 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 2935 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, port_num); |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2936 | int err; |
| 2937 | |
| 2938 | err = mlx5_ib_query_port(ibdev, port_num, &attr); |
| 2939 | if (err) |
| 2940 | return err; |
| 2941 | |
| 2942 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 2943 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 2944 | immutable->core_cap_flags = get_core_cap_flags(ibdev); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 2945 | if ((ll == IB_LINK_LAYER_INFINIBAND) || MLX5_CAP_GEN(dev->mdev, roce)) |
| 2946 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2947 | |
| 2948 | return 0; |
| 2949 | } |
| 2950 | |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 2951 | static void get_dev_fw_str(struct ib_device *ibdev, char *str, |
| 2952 | size_t str_len) |
| 2953 | { |
| 2954 | struct mlx5_ib_dev *dev = |
| 2955 | container_of(ibdev, struct mlx5_ib_dev, ib_dev); |
| 2956 | snprintf(str, str_len, "%d.%d.%04d", fw_rev_maj(dev->mdev), |
| 2957 | fw_rev_min(dev->mdev), fw_rev_sub(dev->mdev)); |
| 2958 | } |
| 2959 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 2960 | static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 2961 | { |
| 2962 | struct mlx5_core_dev *mdev = dev->mdev; |
| 2963 | struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(mdev, |
| 2964 | MLX5_FLOW_NAMESPACE_LAG); |
| 2965 | struct mlx5_flow_table *ft; |
| 2966 | int err; |
| 2967 | |
| 2968 | if (!ns || !mlx5_lag_is_active(mdev)) |
| 2969 | return 0; |
| 2970 | |
| 2971 | err = mlx5_cmd_create_vport_lag(mdev); |
| 2972 | if (err) |
| 2973 | return err; |
| 2974 | |
| 2975 | ft = mlx5_create_lag_demux_flow_table(ns, 0, 0); |
| 2976 | if (IS_ERR(ft)) { |
| 2977 | err = PTR_ERR(ft); |
| 2978 | goto err_destroy_vport_lag; |
| 2979 | } |
| 2980 | |
| 2981 | dev->flow_db.lag_demux_ft = ft; |
| 2982 | return 0; |
| 2983 | |
| 2984 | err_destroy_vport_lag: |
| 2985 | mlx5_cmd_destroy_vport_lag(mdev); |
| 2986 | return err; |
| 2987 | } |
| 2988 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 2989 | static void mlx5_eth_lag_cleanup(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 2990 | { |
| 2991 | struct mlx5_core_dev *mdev = dev->mdev; |
| 2992 | |
| 2993 | if (dev->flow_db.lag_demux_ft) { |
| 2994 | mlx5_destroy_flow_table(dev->flow_db.lag_demux_ft); |
| 2995 | dev->flow_db.lag_demux_ft = NULL; |
| 2996 | |
| 2997 | mlx5_cmd_destroy_vport_lag(mdev); |
| 2998 | } |
| 2999 | } |
| 3000 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 3001 | static int mlx5_add_netdev_notifier(struct mlx5_ib_dev *dev) |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3002 | { |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3003 | int err; |
| 3004 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3005 | dev->roce.nb.notifier_call = mlx5_netdev_event; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3006 | err = register_netdevice_notifier(&dev->roce.nb); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 3007 | if (err) { |
| 3008 | dev->roce.nb.notifier_call = NULL; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3009 | return err; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 3010 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3011 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 3012 | return 0; |
| 3013 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3014 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 3015 | static void mlx5_remove_netdev_notifier(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3016 | { |
| 3017 | if (dev->roce.nb.notifier_call) { |
| 3018 | unregister_netdevice_notifier(&dev->roce.nb); |
| 3019 | dev->roce.nb.notifier_call = NULL; |
| 3020 | } |
| 3021 | } |
| 3022 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 3023 | static int mlx5_enable_eth(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3024 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3025 | int err; |
| 3026 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 3027 | err = mlx5_add_netdev_notifier(dev); |
| 3028 | if (err) |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3029 | return err; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3030 | |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 3031 | if (MLX5_CAP_GEN(dev->mdev, roce)) { |
| 3032 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 3033 | if (err) |
| 3034 | goto err_unregister_netdevice_notifier; |
| 3035 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3036 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 3037 | err = mlx5_eth_lag_init(dev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 3038 | if (err) |
| 3039 | goto err_disable_roce; |
| 3040 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3041 | return 0; |
| 3042 | |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 3043 | err_disable_roce: |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 3044 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 3045 | mlx5_nic_vport_disable_roce(dev->mdev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 3046 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3047 | err_unregister_netdevice_notifier: |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 3048 | mlx5_remove_netdev_notifier(dev); |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 3049 | return err; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3050 | } |
| 3051 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 3052 | static void mlx5_disable_eth(struct mlx5_ib_dev *dev) |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3053 | { |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 3054 | mlx5_eth_lag_cleanup(dev); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 3055 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 3056 | mlx5_nic_vport_disable_roce(dev->mdev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3057 | } |
| 3058 | |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3059 | static void mlx5_ib_dealloc_q_counters(struct mlx5_ib_dev *dev) |
| 3060 | { |
| 3061 | unsigned int i; |
| 3062 | |
| 3063 | for (i = 0; i < dev->num_ports; i++) |
| 3064 | mlx5_core_dealloc_q_counter(dev->mdev, |
| 3065 | dev->port[i].q_cnt_id); |
| 3066 | } |
| 3067 | |
| 3068 | static int mlx5_ib_alloc_q_counters(struct mlx5_ib_dev *dev) |
| 3069 | { |
| 3070 | int i; |
| 3071 | int ret; |
| 3072 | |
| 3073 | for (i = 0; i < dev->num_ports; i++) { |
| 3074 | ret = mlx5_core_alloc_q_counter(dev->mdev, |
| 3075 | &dev->port[i].q_cnt_id); |
| 3076 | if (ret) { |
| 3077 | mlx5_ib_warn(dev, |
| 3078 | "couldn't allocate queue counter for port %d, err %d\n", |
| 3079 | i + 1, ret); |
| 3080 | goto dealloc_counters; |
| 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | return 0; |
| 3085 | |
| 3086 | dealloc_counters: |
| 3087 | while (--i >= 0) |
| 3088 | mlx5_core_dealloc_q_counter(dev->mdev, |
| 3089 | dev->port[i].q_cnt_id); |
| 3090 | |
| 3091 | return ret; |
| 3092 | } |
| 3093 | |
Wei Yongjun | 6196150 | 2016-07-12 11:32:47 +0000 | [diff] [blame] | 3094 | static const char * const names[] = { |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 3095 | "rx_write_requests", |
| 3096 | "rx_read_requests", |
| 3097 | "rx_atomic_requests", |
| 3098 | "out_of_buffer", |
| 3099 | "out_of_sequence", |
| 3100 | "duplicate_request", |
| 3101 | "rnr_nak_retry_err", |
| 3102 | "packet_seq_err", |
| 3103 | "implied_nak_seq_err", |
| 3104 | "local_ack_timeout_err", |
| 3105 | }; |
| 3106 | |
| 3107 | static const size_t stats_offsets[] = { |
| 3108 | MLX5_BYTE_OFF(query_q_counter_out, rx_write_requests), |
| 3109 | MLX5_BYTE_OFF(query_q_counter_out, rx_read_requests), |
| 3110 | MLX5_BYTE_OFF(query_q_counter_out, rx_atomic_requests), |
| 3111 | MLX5_BYTE_OFF(query_q_counter_out, out_of_buffer), |
| 3112 | MLX5_BYTE_OFF(query_q_counter_out, out_of_sequence), |
| 3113 | MLX5_BYTE_OFF(query_q_counter_out, duplicate_request), |
| 3114 | MLX5_BYTE_OFF(query_q_counter_out, rnr_nak_retry_err), |
| 3115 | MLX5_BYTE_OFF(query_q_counter_out, packet_seq_err), |
| 3116 | MLX5_BYTE_OFF(query_q_counter_out, implied_nak_seq_err), |
| 3117 | MLX5_BYTE_OFF(query_q_counter_out, local_ack_timeout_err), |
| 3118 | }; |
| 3119 | |
| 3120 | static struct rdma_hw_stats *mlx5_ib_alloc_hw_stats(struct ib_device *ibdev, |
| 3121 | u8 port_num) |
| 3122 | { |
| 3123 | BUILD_BUG_ON(ARRAY_SIZE(names) != ARRAY_SIZE(stats_offsets)); |
| 3124 | |
| 3125 | /* We support only per port stats */ |
| 3126 | if (port_num == 0) |
| 3127 | return NULL; |
| 3128 | |
| 3129 | return rdma_alloc_hw_stats_struct(names, ARRAY_SIZE(names), |
| 3130 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 3131 | } |
| 3132 | |
| 3133 | static int mlx5_ib_get_hw_stats(struct ib_device *ibdev, |
| 3134 | struct rdma_hw_stats *stats, |
| 3135 | u8 port, int index) |
| 3136 | { |
| 3137 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 3138 | int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); |
| 3139 | void *out; |
| 3140 | __be32 val; |
| 3141 | int ret; |
| 3142 | int i; |
| 3143 | |
| 3144 | if (!port || !stats) |
| 3145 | return -ENOSYS; |
| 3146 | |
| 3147 | out = mlx5_vzalloc(outlen); |
| 3148 | if (!out) |
| 3149 | return -ENOMEM; |
| 3150 | |
| 3151 | ret = mlx5_core_query_q_counter(dev->mdev, |
| 3152 | dev->port[port - 1].q_cnt_id, 0, |
| 3153 | out, outlen); |
| 3154 | if (ret) |
| 3155 | goto free; |
| 3156 | |
| 3157 | for (i = 0; i < ARRAY_SIZE(names); i++) { |
| 3158 | val = *(__be32 *)(out + stats_offsets[i]); |
| 3159 | stats->value[i] = (u64)be32_to_cpu(val); |
| 3160 | } |
| 3161 | free: |
| 3162 | kvfree(out); |
| 3163 | return ARRAY_SIZE(names); |
| 3164 | } |
| 3165 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3166 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3167 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3168 | struct mlx5_ib_dev *dev; |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 3169 | enum rdma_link_layer ll; |
| 3170 | int port_type_cap; |
Aviv Heller | 4babcf9 | 2016-09-18 20:48:03 +0300 | [diff] [blame] | 3171 | const char *name; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3172 | int err; |
| 3173 | int i; |
| 3174 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 3175 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 3176 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 3177 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3178 | printk_once(KERN_INFO "%s", mlx5_version); |
| 3179 | |
| 3180 | dev = (struct mlx5_ib_dev *)ib_alloc_device(sizeof(*dev)); |
| 3181 | if (!dev) |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3182 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3183 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3184 | dev->mdev = mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3185 | |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3186 | dev->port = kcalloc(MLX5_CAP_GEN(mdev, num_ports), sizeof(*dev->port), |
| 3187 | GFP_KERNEL); |
| 3188 | if (!dev->port) |
| 3189 | goto err_dealloc; |
| 3190 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3191 | rwlock_init(&dev->roce.netdev_lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3192 | err = get_port_caps(dev); |
| 3193 | if (err) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3194 | goto err_free_port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3195 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 3196 | if (mlx5_use_mad_ifc(dev)) |
| 3197 | get_ext_port_caps(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3198 | |
Aviv Heller | 4babcf9 | 2016-09-18 20:48:03 +0300 | [diff] [blame] | 3199 | if (!mlx5_lag_is_active(mdev)) |
| 3200 | name = "mlx5_%d"; |
| 3201 | else |
| 3202 | name = "mlx5_bond_%d"; |
| 3203 | |
| 3204 | strlcpy(dev->ib_dev.name, name, IB_DEVICE_NAME_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3205 | dev->ib_dev.owner = THIS_MODULE; |
| 3206 | dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Sagi Grimberg | c6790aa | 2015-09-24 10:34:23 +0300 | [diff] [blame] | 3207 | dev->ib_dev.local_dma_lkey = 0 /* not supported for now */; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3208 | dev->num_ports = MLX5_CAP_GEN(mdev, num_ports); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3209 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 3210 | dev->ib_dev.num_comp_vectors = |
| 3211 | dev->mdev->priv.eq_table.num_comp_vectors; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3212 | dev->ib_dev.dma_device = &mdev->pdev->dev; |
| 3213 | |
| 3214 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
| 3215 | dev->ib_dev.uverbs_cmd_mask = |
| 3216 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 3217 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 3218 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 3219 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 3220 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
Moni Shoua | 41c450f | 2016-11-23 08:23:26 +0200 | [diff] [blame] | 3221 | (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
| 3222 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3223 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 3224 | (1ull << IB_USER_VERBS_CMD_REREG_MR) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3225 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 3226 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 3227 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 3228 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 3229 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 3230 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 3231 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 3232 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 3233 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 3234 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 3235 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 3236 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 3237 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 3238 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 3239 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 3240 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 3241 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Haggai Eran | 1707cb4 | 2015-02-08 13:28:52 +0200 | [diff] [blame] | 3242 | dev->ib_dev.uverbs_ex_cmd_mask = |
Matan Barak | d4584dd | 2016-01-28 17:51:46 +0200 | [diff] [blame] | 3243 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE) | |
| 3244 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3245 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) | |
| 3246 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_QP); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3247 | |
| 3248 | dev->ib_dev.query_device = mlx5_ib_query_device; |
| 3249 | dev->ib_dev.query_port = mlx5_ib_query_port; |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 3250 | dev->ib_dev.get_link_layer = mlx5_ib_port_link_layer; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3251 | if (ll == IB_LINK_LAYER_ETHERNET) |
| 3252 | dev->ib_dev.get_netdev = mlx5_ib_get_netdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3253 | dev->ib_dev.query_gid = mlx5_ib_query_gid; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 3254 | dev->ib_dev.add_gid = mlx5_ib_add_gid; |
| 3255 | dev->ib_dev.del_gid = mlx5_ib_del_gid; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3256 | dev->ib_dev.query_pkey = mlx5_ib_query_pkey; |
| 3257 | dev->ib_dev.modify_device = mlx5_ib_modify_device; |
| 3258 | dev->ib_dev.modify_port = mlx5_ib_modify_port; |
| 3259 | dev->ib_dev.alloc_ucontext = mlx5_ib_alloc_ucontext; |
| 3260 | dev->ib_dev.dealloc_ucontext = mlx5_ib_dealloc_ucontext; |
| 3261 | dev->ib_dev.mmap = mlx5_ib_mmap; |
| 3262 | dev->ib_dev.alloc_pd = mlx5_ib_alloc_pd; |
| 3263 | dev->ib_dev.dealloc_pd = mlx5_ib_dealloc_pd; |
| 3264 | dev->ib_dev.create_ah = mlx5_ib_create_ah; |
| 3265 | dev->ib_dev.query_ah = mlx5_ib_query_ah; |
| 3266 | dev->ib_dev.destroy_ah = mlx5_ib_destroy_ah; |
| 3267 | dev->ib_dev.create_srq = mlx5_ib_create_srq; |
| 3268 | dev->ib_dev.modify_srq = mlx5_ib_modify_srq; |
| 3269 | dev->ib_dev.query_srq = mlx5_ib_query_srq; |
| 3270 | dev->ib_dev.destroy_srq = mlx5_ib_destroy_srq; |
| 3271 | dev->ib_dev.post_srq_recv = mlx5_ib_post_srq_recv; |
| 3272 | dev->ib_dev.create_qp = mlx5_ib_create_qp; |
| 3273 | dev->ib_dev.modify_qp = mlx5_ib_modify_qp; |
| 3274 | dev->ib_dev.query_qp = mlx5_ib_query_qp; |
| 3275 | dev->ib_dev.destroy_qp = mlx5_ib_destroy_qp; |
| 3276 | dev->ib_dev.post_send = mlx5_ib_post_send; |
| 3277 | dev->ib_dev.post_recv = mlx5_ib_post_recv; |
| 3278 | dev->ib_dev.create_cq = mlx5_ib_create_cq; |
| 3279 | dev->ib_dev.modify_cq = mlx5_ib_modify_cq; |
| 3280 | dev->ib_dev.resize_cq = mlx5_ib_resize_cq; |
| 3281 | dev->ib_dev.destroy_cq = mlx5_ib_destroy_cq; |
| 3282 | dev->ib_dev.poll_cq = mlx5_ib_poll_cq; |
| 3283 | dev->ib_dev.req_notify_cq = mlx5_ib_arm_cq; |
| 3284 | dev->ib_dev.get_dma_mr = mlx5_ib_get_dma_mr; |
| 3285 | dev->ib_dev.reg_user_mr = mlx5_ib_reg_user_mr; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 3286 | dev->ib_dev.rereg_user_mr = mlx5_ib_rereg_user_mr; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3287 | dev->ib_dev.dereg_mr = mlx5_ib_dereg_mr; |
| 3288 | dev->ib_dev.attach_mcast = mlx5_ib_mcg_attach; |
| 3289 | dev->ib_dev.detach_mcast = mlx5_ib_mcg_detach; |
| 3290 | dev->ib_dev.process_mad = mlx5_ib_process_mad; |
Sagi Grimberg | 9bee178 | 2015-07-30 10:32:35 +0300 | [diff] [blame] | 3291 | dev->ib_dev.alloc_mr = mlx5_ib_alloc_mr; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 3292 | dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg; |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 3293 | dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 3294 | dev->ib_dev.get_port_immutable = mlx5_port_immutable; |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 3295 | dev->ib_dev.get_dev_fw_str = get_dev_fw_str; |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 3296 | if (mlx5_core_is_pf(mdev)) { |
| 3297 | dev->ib_dev.get_vf_config = mlx5_ib_get_vf_config; |
| 3298 | dev->ib_dev.set_vf_link_state = mlx5_ib_set_vf_link_state; |
| 3299 | dev->ib_dev.get_vf_stats = mlx5_ib_get_vf_stats; |
| 3300 | dev->ib_dev.set_vf_guid = mlx5_ib_set_vf_guid; |
| 3301 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3302 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 3303 | dev->ib_dev.disassociate_ucontext = mlx5_ib_disassociate_ucontext; |
| 3304 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3305 | mlx5_ib_internal_fill_odp_caps(dev); |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 3306 | |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 3307 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
| 3308 | dev->ib_dev.alloc_mw = mlx5_ib_alloc_mw; |
| 3309 | dev->ib_dev.dealloc_mw = mlx5_ib_dealloc_mw; |
| 3310 | dev->ib_dev.uverbs_cmd_mask |= |
| 3311 | (1ull << IB_USER_VERBS_CMD_ALLOC_MW) | |
| 3312 | (1ull << IB_USER_VERBS_CMD_DEALLOC_MW); |
| 3313 | } |
| 3314 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 3315 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt) && |
| 3316 | MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) { |
| 3317 | dev->ib_dev.get_hw_stats = mlx5_ib_get_hw_stats; |
| 3318 | dev->ib_dev.alloc_hw_stats = mlx5_ib_alloc_hw_stats; |
| 3319 | } |
| 3320 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3321 | if (MLX5_CAP_GEN(mdev, xrc)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3322 | dev->ib_dev.alloc_xrcd = mlx5_ib_alloc_xrcd; |
| 3323 | dev->ib_dev.dealloc_xrcd = mlx5_ib_dealloc_xrcd; |
| 3324 | dev->ib_dev.uverbs_cmd_mask |= |
| 3325 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 3326 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
| 3327 | } |
| 3328 | |
Linus Torvalds | 048ccca | 2016-01-23 18:45:06 -0800 | [diff] [blame] | 3329 | if (mlx5_ib_port_link_layer(&dev->ib_dev, 1) == |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3330 | IB_LINK_LAYER_ETHERNET) { |
| 3331 | dev->ib_dev.create_flow = mlx5_ib_create_flow; |
| 3332 | dev->ib_dev.destroy_flow = mlx5_ib_destroy_flow; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 3333 | dev->ib_dev.create_wq = mlx5_ib_create_wq; |
| 3334 | dev->ib_dev.modify_wq = mlx5_ib_modify_wq; |
| 3335 | dev->ib_dev.destroy_wq = mlx5_ib_destroy_wq; |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 3336 | dev->ib_dev.create_rwq_ind_table = mlx5_ib_create_rwq_ind_table; |
| 3337 | dev->ib_dev.destroy_rwq_ind_table = mlx5_ib_destroy_rwq_ind_table; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3338 | dev->ib_dev.uverbs_ex_cmd_mask |= |
| 3339 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 3340 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW) | |
| 3341 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_WQ) | |
| 3342 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_WQ) | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 3343 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_WQ) | |
| 3344 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) | |
| 3345 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3346 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3347 | err = init_node_data(dev); |
| 3348 | if (err) |
Majd Dibbiny | 90be7c8 | 2016-10-27 16:36:39 +0300 | [diff] [blame] | 3349 | goto err_free_port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3350 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3351 | mutex_init(&dev->flow_db.lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3352 | mutex_init(&dev->cap_mask_mutex); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 3353 | INIT_LIST_HEAD(&dev->qp_list); |
| 3354 | spin_lock_init(&dev->reset_flow_resource_lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3355 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3356 | if (ll == IB_LINK_LAYER_ETHERNET) { |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 3357 | err = mlx5_enable_eth(dev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3358 | if (err) |
Majd Dibbiny | 90be7c8 | 2016-10-27 16:36:39 +0300 | [diff] [blame] | 3359 | goto err_free_port; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3360 | } |
| 3361 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3362 | err = create_dev_resources(&dev->devr); |
| 3363 | if (err) |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 3364 | goto err_disable_eth; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3365 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 3366 | err = mlx5_ib_odp_init_one(dev); |
Wei Yongjun | 281d1a9 | 2013-07-30 07:54:26 +0800 | [diff] [blame] | 3367 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3368 | goto err_rsrc; |
| 3369 | |
Kamal Heib | 45bded2 | 2017-01-18 14:10:32 +0200 | [diff] [blame] | 3370 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) { |
| 3371 | err = mlx5_ib_alloc_q_counters(dev); |
| 3372 | if (err) |
| 3373 | goto err_odp; |
| 3374 | } |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 3375 | |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 3376 | dev->mdev->priv.uar = mlx5_get_uars_page(dev->mdev); |
| 3377 | if (!dev->mdev->priv.uar) |
| 3378 | goto err_q_cnt; |
| 3379 | |
| 3380 | err = mlx5_alloc_bfreg(dev->mdev, &dev->bfreg, false, false); |
| 3381 | if (err) |
| 3382 | goto err_uar_page; |
| 3383 | |
| 3384 | err = mlx5_alloc_bfreg(dev->mdev, &dev->fp_bfreg, false, true); |
| 3385 | if (err) |
| 3386 | goto err_bfreg; |
| 3387 | |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3388 | err = ib_register_device(&dev->ib_dev, NULL); |
| 3389 | if (err) |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 3390 | goto err_fp_bfreg; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3391 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3392 | err = create_umr_res(dev); |
| 3393 | if (err) |
| 3394 | goto err_dev; |
| 3395 | |
| 3396 | for (i = 0; i < ARRAY_SIZE(mlx5_class_attributes); i++) { |
Wei Yongjun | 281d1a9 | 2013-07-30 07:54:26 +0800 | [diff] [blame] | 3397 | err = device_create_file(&dev->ib_dev.dev, |
| 3398 | mlx5_class_attributes[i]); |
| 3399 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3400 | goto err_umrc; |
| 3401 | } |
| 3402 | |
| 3403 | dev->ib_active = true; |
| 3404 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3405 | return dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3406 | |
| 3407 | err_umrc: |
| 3408 | destroy_umrc_res(dev); |
| 3409 | |
| 3410 | err_dev: |
| 3411 | ib_unregister_device(&dev->ib_dev); |
| 3412 | |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 3413 | err_fp_bfreg: |
| 3414 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
| 3415 | |
| 3416 | err_bfreg: |
| 3417 | mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
| 3418 | |
| 3419 | err_uar_page: |
| 3420 | mlx5_put_uars_page(dev->mdev, dev->mdev->priv.uar); |
| 3421 | |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3422 | err_q_cnt: |
Kamal Heib | 45bded2 | 2017-01-18 14:10:32 +0200 | [diff] [blame] | 3423 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) |
| 3424 | mlx5_ib_dealloc_q_counters(dev); |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3425 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 3426 | err_odp: |
| 3427 | mlx5_ib_odp_remove_one(dev); |
| 3428 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3429 | err_rsrc: |
| 3430 | destroy_dev_resources(&dev->devr); |
| 3431 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 3432 | err_disable_eth: |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 3433 | if (ll == IB_LINK_LAYER_ETHERNET) { |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 3434 | mlx5_disable_eth(dev); |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 3435 | mlx5_remove_netdev_notifier(dev); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 3436 | } |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3437 | |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3438 | err_free_port: |
| 3439 | kfree(dev->port); |
| 3440 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3441 | err_dealloc: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3442 | ib_dealloc_device((struct ib_device *)dev); |
| 3443 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3444 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3445 | } |
| 3446 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3447 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3448 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3449 | struct mlx5_ib_dev *dev = context; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3450 | 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] | 3451 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 3452 | mlx5_remove_netdev_notifier(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3453 | ib_unregister_device(&dev->ib_dev); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 3454 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
| 3455 | mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
| 3456 | mlx5_put_uars_page(dev->mdev, mdev->priv.uar); |
Kamal Heib | 45bded2 | 2017-01-18 14:10:32 +0200 | [diff] [blame] | 3457 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) |
| 3458 | mlx5_ib_dealloc_q_counters(dev); |
Eli Cohen | eefd56e | 2014-09-14 16:47:50 +0300 | [diff] [blame] | 3459 | destroy_umrc_res(dev); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 3460 | mlx5_ib_odp_remove_one(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3461 | destroy_dev_resources(&dev->devr); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 3462 | if (ll == IB_LINK_LAYER_ETHERNET) |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 3463 | mlx5_disable_eth(dev); |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3464 | kfree(dev->port); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3465 | ib_dealloc_device(&dev->ib_dev); |
| 3466 | } |
| 3467 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3468 | static struct mlx5_interface mlx5_ib_interface = { |
| 3469 | .add = mlx5_ib_add, |
| 3470 | .remove = mlx5_ib_remove, |
| 3471 | .event = mlx5_ib_event, |
Artemy Kovalyov | d9aaed8 | 2017-01-02 11:37:46 +0200 | [diff] [blame] | 3472 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 3473 | .pfault = mlx5_ib_pfault, |
| 3474 | #endif |
Saeed Mahameed | 64613d94 | 2015-04-02 17:07:34 +0300 | [diff] [blame] | 3475 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3476 | }; |
| 3477 | |
| 3478 | static int __init mlx5_ib_init(void) |
| 3479 | { |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 3480 | int err; |
| 3481 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3482 | if (deprecated_prof_sel != 2) |
| 3483 | pr_warn("prof_sel is deprecated for mlx5_ib, set it for mlx5_core\n"); |
| 3484 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 3485 | err = mlx5_register_interface(&mlx5_ib_interface); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 3486 | |
| 3487 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | static void __exit mlx5_ib_cleanup(void) |
| 3491 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 3492 | mlx5_unregister_interface(&mlx5_ib_interface); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | module_init(mlx5_ib_init); |
| 3496 | module_exit(mlx5_ib_cleanup); |