Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved. |
Jack Morgenstein | 51a379d | 2008-07-25 10:32:52 -0700 | [diff] [blame] | 3 | * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved. |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 4 | * |
| 5 | * This software is available to you under a choice of one of two |
| 6 | * licenses. You may choose to be licensed under the terms of the GNU |
| 7 | * General Public License (GPL) Version 2, available from the file |
| 8 | * COPYING in the main directory of this source tree, or the |
| 9 | * OpenIB.org BSD license below: |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or |
| 12 | * without modification, are permitted provided that the following |
| 13 | * conditions are met: |
| 14 | * |
| 15 | * - Redistributions of source code must retain the above |
| 16 | * copyright notice, this list of conditions and the following |
| 17 | * disclaimer. |
| 18 | * |
| 19 | * - Redistributions in binary form must reproduce the above |
| 20 | * copyright notice, this list of conditions and the following |
| 21 | * disclaimer in the documentation and/or other materials |
| 22 | * provided with the distribution. |
| 23 | * |
| 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 25 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 26 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 27 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 28 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 29 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 30 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 | * SOFTWARE. |
| 32 | */ |
| 33 | |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 37 | #include <linux/errno.h> |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/inetdevice.h> |
| 40 | #include <linux/rtnetlink.h> |
Eli Cohen | 4c3eb3c | 2010-08-26 17:19:22 +0300 | [diff] [blame] | 41 | #include <linux/if_vlan.h> |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 42 | #include <net/ipv6.h> |
| 43 | #include <net/addrconf.h> |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 44 | |
| 45 | #include <rdma/ib_smi.h> |
| 46 | #include <rdma/ib_user_verbs.h> |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 47 | #include <rdma/ib_addr.h> |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 48 | #include <rdma/ib_cache.h> |
| 49 | |
| 50 | #include <net/bonding.h> |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 51 | |
| 52 | #include <linux/mlx4/driver.h> |
| 53 | #include <linux/mlx4/cmd.h> |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 54 | #include <linux/mlx4/qp.h> |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 55 | |
| 56 | #include "mlx4_ib.h" |
| 57 | #include "user.h" |
| 58 | |
Jack Morgenstein | b1d8eb5 | 2012-06-19 11:21:35 +0300 | [diff] [blame] | 59 | #define DRV_NAME MLX4_IB_DRV_NAME |
Amir Vadai | 169a1d8 | 2014-02-19 17:47:31 +0200 | [diff] [blame] | 60 | #define DRV_VERSION "2.2-1" |
| 61 | #define DRV_RELDATE "Feb 2014" |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 62 | |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 63 | #define MLX4_IB_FLOW_MAX_PRIO 0xFFF |
Matan Barak | a37a1a4 | 2013-11-07 15:25:16 +0200 | [diff] [blame] | 64 | #define MLX4_IB_FLOW_QPN_MASK 0xFFFFFF |
Markus Stockhausen | 50e2ec9 | 2014-08-13 14:07:30 +0000 | [diff] [blame] | 65 | #define MLX4_IB_CARD_REV_A0 0xA0 |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 66 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 67 | MODULE_AUTHOR("Roland Dreier"); |
| 68 | MODULE_DESCRIPTION("Mellanox ConnectX HCA InfiniBand driver"); |
| 69 | MODULE_LICENSE("Dual BSD/GPL"); |
| 70 | MODULE_VERSION(DRV_VERSION); |
| 71 | |
Yishai Hadas | 56c1d23 | 2015-02-12 09:49:43 +0200 | [diff] [blame] | 72 | int mlx4_ib_sm_guid_assign = 0; |
Jack Morgenstein | a0c64a1 | 2012-08-03 08:40:49 +0000 | [diff] [blame] | 73 | module_param_named(sm_guid_assign, mlx4_ib_sm_guid_assign, int, 0444); |
Yishai Hadas | 56c1d23 | 2015-02-12 09:49:43 +0200 | [diff] [blame] | 74 | MODULE_PARM_DESC(sm_guid_assign, "Enable SM alias_GUID assignment if sm_guid_assign > 0 (Default: 0)"); |
Jack Morgenstein | a0c64a1 | 2012-08-03 08:40:49 +0000 | [diff] [blame] | 75 | |
Roland Dreier | 68f3948 | 2008-02-04 20:20:44 -0800 | [diff] [blame] | 76 | static const char mlx4_ib_version[] = |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 77 | DRV_NAME ": Mellanox ConnectX InfiniBand driver v" |
| 78 | DRV_VERSION " (" DRV_RELDATE ")\n"; |
| 79 | |
Jack Morgenstein | 3806d08 | 2012-08-03 08:40:58 +0000 | [diff] [blame] | 80 | static void do_slave_init(struct mlx4_ib_dev *ibdev, int slave, int do_init); |
| 81 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 82 | static struct workqueue_struct *wq; |
| 83 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 84 | static void init_query_mad(struct ib_smp *mad) |
| 85 | { |
| 86 | mad->base_version = 1; |
| 87 | mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; |
| 88 | mad->class_version = 1; |
| 89 | mad->method = IB_MGMT_METHOD_GET; |
| 90 | } |
| 91 | |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 92 | static int check_flow_steering_support(struct mlx4_dev *dev) |
| 93 | { |
Matan Barak | 0a9b7d5 | 2013-11-07 15:25:15 +0200 | [diff] [blame] | 94 | int eth_num_ports = 0; |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 95 | int ib_num_ports = 0; |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 96 | |
Matan Barak | 0a9b7d5 | 2013-11-07 15:25:15 +0200 | [diff] [blame] | 97 | int dmfs = dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED; |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 98 | |
Matan Barak | 0a9b7d5 | 2013-11-07 15:25:15 +0200 | [diff] [blame] | 99 | if (dmfs) { |
| 100 | int i; |
| 101 | mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) |
| 102 | eth_num_ports++; |
| 103 | mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB) |
| 104 | ib_num_ports++; |
| 105 | dmfs &= (!ib_num_ports || |
| 106 | (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_DMFS_IPOIB)) && |
| 107 | (!eth_num_ports || |
| 108 | (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FS_EN)); |
| 109 | if (ib_num_ports && mlx4_is_mfunc(dev)) { |
| 110 | pr_warn("Device managed flow steering is unavailable for IB port in multifunction env.\n"); |
| 111 | dmfs = 0; |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 112 | } |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 113 | } |
Matan Barak | 0a9b7d5 | 2013-11-07 15:25:15 +0200 | [diff] [blame] | 114 | return dmfs; |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 115 | } |
| 116 | |
Jack Morgenstein | 3dec487 | 2014-09-11 14:11:19 +0300 | [diff] [blame] | 117 | static int num_ib_ports(struct mlx4_dev *dev) |
| 118 | { |
| 119 | int ib_ports = 0; |
| 120 | int i; |
| 121 | |
| 122 | mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB) |
| 123 | ib_ports++; |
| 124 | |
| 125 | return ib_ports; |
| 126 | } |
| 127 | |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 128 | static struct net_device *mlx4_ib_get_netdev(struct ib_device *device, u8 port_num) |
| 129 | { |
| 130 | struct mlx4_ib_dev *ibdev = to_mdev(device); |
| 131 | struct net_device *dev; |
| 132 | |
| 133 | rcu_read_lock(); |
| 134 | dev = mlx4_get_protocol_dev(ibdev->dev, MLX4_PROT_ETH, port_num); |
| 135 | |
| 136 | if (dev) { |
| 137 | if (mlx4_is_bonded(ibdev->dev)) { |
| 138 | struct net_device *upper = NULL; |
| 139 | |
| 140 | upper = netdev_master_upper_dev_get_rcu(dev); |
| 141 | if (upper) { |
| 142 | struct net_device *active; |
| 143 | |
| 144 | active = bond_option_active_slave_get_rcu(netdev_priv(upper)); |
| 145 | if (active) |
| 146 | dev = active; |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | if (dev) |
| 151 | dev_hold(dev); |
| 152 | |
| 153 | rcu_read_unlock(); |
| 154 | return dev; |
| 155 | } |
| 156 | |
| 157 | static int mlx4_ib_update_gids(struct gid_entry *gids, |
| 158 | struct mlx4_ib_dev *ibdev, |
| 159 | u8 port_num) |
| 160 | { |
| 161 | struct mlx4_cmd_mailbox *mailbox; |
| 162 | int err; |
| 163 | struct mlx4_dev *dev = ibdev->dev; |
| 164 | int i; |
| 165 | union ib_gid *gid_tbl; |
| 166 | |
| 167 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
| 168 | if (IS_ERR(mailbox)) |
| 169 | return -ENOMEM; |
| 170 | |
| 171 | gid_tbl = mailbox->buf; |
| 172 | |
| 173 | for (i = 0; i < MLX4_MAX_PORT_GIDS; ++i) |
| 174 | memcpy(&gid_tbl[i], &gids[i].gid, sizeof(union ib_gid)); |
| 175 | |
| 176 | err = mlx4_cmd(dev, mailbox->dma, |
| 177 | MLX4_SET_PORT_GID_TABLE << 8 | port_num, |
| 178 | 1, MLX4_CMD_SET_PORT, MLX4_CMD_TIME_CLASS_B, |
| 179 | MLX4_CMD_WRAPPED); |
| 180 | if (mlx4_is_bonded(dev)) |
| 181 | err += mlx4_cmd(dev, mailbox->dma, |
| 182 | MLX4_SET_PORT_GID_TABLE << 8 | 2, |
| 183 | 1, MLX4_CMD_SET_PORT, MLX4_CMD_TIME_CLASS_B, |
| 184 | MLX4_CMD_WRAPPED); |
| 185 | |
| 186 | mlx4_free_cmd_mailbox(dev, mailbox); |
| 187 | return err; |
| 188 | } |
| 189 | |
| 190 | static int mlx4_ib_add_gid(struct ib_device *device, |
| 191 | u8 port_num, |
| 192 | unsigned int index, |
| 193 | const union ib_gid *gid, |
| 194 | const struct ib_gid_attr *attr, |
| 195 | void **context) |
| 196 | { |
| 197 | struct mlx4_ib_dev *ibdev = to_mdev(device); |
| 198 | struct mlx4_ib_iboe *iboe = &ibdev->iboe; |
| 199 | struct mlx4_port_gid_table *port_gid_table; |
| 200 | int free = -1, found = -1; |
| 201 | int ret = 0; |
| 202 | int hw_update = 0; |
| 203 | int i; |
| 204 | struct gid_entry *gids = NULL; |
| 205 | |
| 206 | if (!rdma_cap_roce_gid_table(device, port_num)) |
| 207 | return -EINVAL; |
| 208 | |
| 209 | if (port_num > MLX4_MAX_PORTS) |
| 210 | return -EINVAL; |
| 211 | |
| 212 | if (!context) |
| 213 | return -EINVAL; |
| 214 | |
| 215 | port_gid_table = &iboe->gids[port_num - 1]; |
| 216 | spin_lock_bh(&iboe->lock); |
| 217 | for (i = 0; i < MLX4_MAX_PORT_GIDS; ++i) { |
Moni Shoua | b699a85 | 2016-01-14 17:50:33 +0200 | [diff] [blame^] | 218 | if (!memcmp(&port_gid_table->gids[i].gid, gid, sizeof(*gid)) && |
| 219 | (port_gid_table->gids[i].gid_type == attr->gid_type)) { |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 220 | found = i; |
| 221 | break; |
| 222 | } |
| 223 | if (free < 0 && !memcmp(&port_gid_table->gids[i].gid, &zgid, sizeof(*gid))) |
| 224 | free = i; /* HW has space */ |
| 225 | } |
| 226 | |
| 227 | if (found < 0) { |
| 228 | if (free < 0) { |
| 229 | ret = -ENOSPC; |
| 230 | } else { |
| 231 | port_gid_table->gids[free].ctx = kmalloc(sizeof(*port_gid_table->gids[free].ctx), GFP_ATOMIC); |
| 232 | if (!port_gid_table->gids[free].ctx) { |
| 233 | ret = -ENOMEM; |
| 234 | } else { |
| 235 | *context = port_gid_table->gids[free].ctx; |
| 236 | memcpy(&port_gid_table->gids[free].gid, gid, sizeof(*gid)); |
Moni Shoua | b699a85 | 2016-01-14 17:50:33 +0200 | [diff] [blame^] | 237 | port_gid_table->gids[free].gid_type = attr->gid_type; |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 238 | port_gid_table->gids[free].ctx->real_index = free; |
| 239 | port_gid_table->gids[free].ctx->refcount = 1; |
| 240 | hw_update = 1; |
| 241 | } |
| 242 | } |
| 243 | } else { |
| 244 | struct gid_cache_context *ctx = port_gid_table->gids[found].ctx; |
| 245 | *context = ctx; |
| 246 | ctx->refcount++; |
| 247 | } |
| 248 | if (!ret && hw_update) { |
| 249 | gids = kmalloc(sizeof(*gids) * MLX4_MAX_PORT_GIDS, GFP_ATOMIC); |
| 250 | if (!gids) { |
| 251 | ret = -ENOMEM; |
| 252 | } else { |
Moni Shoua | b699a85 | 2016-01-14 17:50:33 +0200 | [diff] [blame^] | 253 | for (i = 0; i < MLX4_MAX_PORT_GIDS; i++) { |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 254 | memcpy(&gids[i].gid, &port_gid_table->gids[i].gid, sizeof(union ib_gid)); |
Moni Shoua | b699a85 | 2016-01-14 17:50:33 +0200 | [diff] [blame^] | 255 | gids[i].gid_type = port_gid_table->gids[i].gid_type; |
| 256 | } |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | spin_unlock_bh(&iboe->lock); |
| 260 | |
| 261 | if (!ret && hw_update) { |
| 262 | ret = mlx4_ib_update_gids(gids, ibdev, port_num); |
| 263 | kfree(gids); |
| 264 | } |
| 265 | |
| 266 | return ret; |
| 267 | } |
| 268 | |
| 269 | static int mlx4_ib_del_gid(struct ib_device *device, |
| 270 | u8 port_num, |
| 271 | unsigned int index, |
| 272 | void **context) |
| 273 | { |
| 274 | struct gid_cache_context *ctx = *context; |
| 275 | struct mlx4_ib_dev *ibdev = to_mdev(device); |
| 276 | struct mlx4_ib_iboe *iboe = &ibdev->iboe; |
| 277 | struct mlx4_port_gid_table *port_gid_table; |
| 278 | int ret = 0; |
| 279 | int hw_update = 0; |
| 280 | struct gid_entry *gids = NULL; |
| 281 | |
| 282 | if (!rdma_cap_roce_gid_table(device, port_num)) |
| 283 | return -EINVAL; |
| 284 | |
| 285 | if (port_num > MLX4_MAX_PORTS) |
| 286 | return -EINVAL; |
| 287 | |
| 288 | port_gid_table = &iboe->gids[port_num - 1]; |
| 289 | spin_lock_bh(&iboe->lock); |
| 290 | if (ctx) { |
| 291 | ctx->refcount--; |
| 292 | if (!ctx->refcount) { |
| 293 | unsigned int real_index = ctx->real_index; |
| 294 | |
| 295 | memcpy(&port_gid_table->gids[real_index].gid, &zgid, sizeof(zgid)); |
| 296 | kfree(port_gid_table->gids[real_index].ctx); |
| 297 | port_gid_table->gids[real_index].ctx = NULL; |
| 298 | hw_update = 1; |
| 299 | } |
| 300 | } |
| 301 | if (!ret && hw_update) { |
| 302 | int i; |
| 303 | |
| 304 | gids = kmalloc(sizeof(*gids) * MLX4_MAX_PORT_GIDS, GFP_ATOMIC); |
| 305 | if (!gids) { |
| 306 | ret = -ENOMEM; |
| 307 | } else { |
| 308 | for (i = 0; i < MLX4_MAX_PORT_GIDS; i++) |
| 309 | memcpy(&gids[i].gid, &port_gid_table->gids[i].gid, sizeof(union ib_gid)); |
| 310 | } |
| 311 | } |
| 312 | spin_unlock_bh(&iboe->lock); |
| 313 | |
| 314 | if (!ret && hw_update) { |
| 315 | ret = mlx4_ib_update_gids(gids, ibdev, port_num); |
| 316 | kfree(gids); |
| 317 | } |
| 318 | return ret; |
| 319 | } |
| 320 | |
| 321 | int mlx4_ib_gid_index_to_real_index(struct mlx4_ib_dev *ibdev, |
| 322 | u8 port_num, int index) |
| 323 | { |
| 324 | struct mlx4_ib_iboe *iboe = &ibdev->iboe; |
| 325 | struct gid_cache_context *ctx = NULL; |
| 326 | union ib_gid gid; |
| 327 | struct mlx4_port_gid_table *port_gid_table; |
| 328 | int real_index = -EINVAL; |
| 329 | int i; |
| 330 | int ret; |
| 331 | unsigned long flags; |
Moni Shoua | b699a85 | 2016-01-14 17:50:33 +0200 | [diff] [blame^] | 332 | struct ib_gid_attr attr; |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 333 | |
| 334 | if (port_num > MLX4_MAX_PORTS) |
| 335 | return -EINVAL; |
| 336 | |
| 337 | if (mlx4_is_bonded(ibdev->dev)) |
| 338 | port_num = 1; |
| 339 | |
| 340 | if (!rdma_cap_roce_gid_table(&ibdev->ib_dev, port_num)) |
| 341 | return index; |
| 342 | |
Moni Shoua | b699a85 | 2016-01-14 17:50:33 +0200 | [diff] [blame^] | 343 | ret = ib_get_cached_gid(&ibdev->ib_dev, port_num, index, &gid, &attr); |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 344 | if (ret) |
| 345 | return ret; |
| 346 | |
Moni Shoua | b699a85 | 2016-01-14 17:50:33 +0200 | [diff] [blame^] | 347 | if (attr.ndev) |
| 348 | dev_put(attr.ndev); |
| 349 | |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 350 | if (!memcmp(&gid, &zgid, sizeof(gid))) |
| 351 | return -EINVAL; |
| 352 | |
| 353 | spin_lock_irqsave(&iboe->lock, flags); |
| 354 | port_gid_table = &iboe->gids[port_num - 1]; |
| 355 | |
| 356 | for (i = 0; i < MLX4_MAX_PORT_GIDS; ++i) |
Moni Shoua | b699a85 | 2016-01-14 17:50:33 +0200 | [diff] [blame^] | 357 | if (!memcmp(&port_gid_table->gids[i].gid, &gid, sizeof(gid)) && |
| 358 | attr.gid_type == port_gid_table->gids[i].gid_type) { |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 359 | ctx = port_gid_table->gids[i].ctx; |
| 360 | break; |
| 361 | } |
| 362 | if (ctx) |
| 363 | real_index = ctx->real_index; |
| 364 | spin_unlock_irqrestore(&iboe->lock, flags); |
| 365 | return real_index; |
| 366 | } |
| 367 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 368 | static int mlx4_ib_query_device(struct ib_device *ibdev, |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 369 | struct ib_device_attr *props, |
| 370 | struct ib_udata *uhw) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 371 | { |
| 372 | struct mlx4_ib_dev *dev = to_mdev(ibdev); |
| 373 | struct ib_smp *in_mad = NULL; |
| 374 | struct ib_smp *out_mad = NULL; |
| 375 | int err = -ENOMEM; |
Jack Morgenstein | 3dec487 | 2014-09-11 14:11:19 +0300 | [diff] [blame] | 376 | int have_ib_ports; |
Matan Barak | 4b664c4 | 2015-06-11 16:35:27 +0300 | [diff] [blame] | 377 | struct mlx4_uverbs_ex_query_device cmd; |
| 378 | struct mlx4_uverbs_ex_query_device_resp resp = {.comp_mask = 0}; |
| 379 | struct mlx4_clock_params clock_params; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 380 | |
Matan Barak | 4b664c4 | 2015-06-11 16:35:27 +0300 | [diff] [blame] | 381 | if (uhw->inlen) { |
| 382 | if (uhw->inlen < sizeof(cmd)) |
| 383 | return -EINVAL; |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 384 | |
Matan Barak | 4b664c4 | 2015-06-11 16:35:27 +0300 | [diff] [blame] | 385 | err = ib_copy_from_udata(&cmd, uhw, sizeof(cmd)); |
| 386 | if (err) |
| 387 | return err; |
| 388 | |
| 389 | if (cmd.comp_mask) |
| 390 | return -EINVAL; |
| 391 | |
| 392 | if (cmd.reserved) |
| 393 | return -EINVAL; |
| 394 | } |
| 395 | |
| 396 | resp.response_length = offsetof(typeof(resp), response_length) + |
| 397 | sizeof(resp.response_length); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 398 | in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); |
| 399 | out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); |
| 400 | if (!in_mad || !out_mad) |
| 401 | goto out; |
| 402 | |
| 403 | init_query_mad(in_mad); |
| 404 | in_mad->attr_id = IB_SMP_ATTR_NODE_INFO; |
| 405 | |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 406 | err = mlx4_MAD_IFC(to_mdev(ibdev), MLX4_MAD_IFC_IGNORE_KEYS, |
| 407 | 1, NULL, NULL, in_mad, out_mad); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 408 | if (err) |
| 409 | goto out; |
| 410 | |
| 411 | memset(props, 0, sizeof *props); |
| 412 | |
Jack Morgenstein | 3dec487 | 2014-09-11 14:11:19 +0300 | [diff] [blame] | 413 | have_ib_ports = num_ib_ports(dev->dev); |
| 414 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 415 | props->fw_ver = dev->dev->caps.fw_ver; |
| 416 | props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | |
| 417 | IB_DEVICE_PORT_ACTIVE_EVENT | |
| 418 | IB_DEVICE_SYS_IMAGE_GUID | |
Ron Livne | 521e575 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 419 | IB_DEVICE_RC_RNR_NAK_GEN | |
| 420 | IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 421 | if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_BAD_PKEY_CNTR) |
| 422 | props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; |
| 423 | if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_BAD_QKEY_CNTR) |
| 424 | props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR; |
Jack Morgenstein | 3dec487 | 2014-09-11 14:11:19 +0300 | [diff] [blame] | 425 | if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_APM && have_ib_ports) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 426 | props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG; |
| 427 | if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UD_AV_PORT) |
| 428 | props->device_cap_flags |= IB_DEVICE_UD_AV_PORT_ENFORCE; |
Eli Cohen | 8ff095e | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 429 | if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_IPOIB_CSUM) |
| 430 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
Markus Stockhausen | 50e2ec9 | 2014-08-13 14:07:30 +0000 | [diff] [blame] | 431 | if (dev->dev->caps.max_gso_sz && |
| 432 | (dev->dev->rev_id != MLX4_IB_CARD_REV_A0) && |
| 433 | (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_BLH)) |
Eli Cohen | b832be1 | 2008-04-16 21:09:27 -0700 | [diff] [blame] | 434 | props->device_cap_flags |= IB_DEVICE_UD_TSO; |
Roland Dreier | 95d04f0 | 2008-07-23 08:12:26 -0700 | [diff] [blame] | 435 | if (dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_RESERVED_LKEY) |
| 436 | props->device_cap_flags |= IB_DEVICE_LOCAL_DMA_LKEY; |
| 437 | if ((dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_LOCAL_INV) && |
| 438 | (dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_REMOTE_INV) && |
| 439 | (dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_FAST_REG_WR)) |
| 440 | props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
Sean Hefty | 0a1405d | 2011-06-02 11:32:15 -0700 | [diff] [blame] | 441 | if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) |
| 442 | props->device_cap_flags |= IB_DEVICE_XRC; |
Shani Michaeli | b425388 | 2013-02-06 16:19:16 +0000 | [diff] [blame] | 443 | if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_MEM_WINDOW) |
| 444 | props->device_cap_flags |= IB_DEVICE_MEM_WINDOW; |
| 445 | if (dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_TYPE_2_WIN) { |
| 446 | if (dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_WIN_TYPE_2B) |
| 447 | props->device_cap_flags |= IB_DEVICE_MEM_WINDOW_TYPE_2B; |
| 448 | else |
| 449 | props->device_cap_flags |= IB_DEVICE_MEM_WINDOW_TYPE_2A; |
Matan Barak | 0a9b7d5 | 2013-11-07 15:25:15 +0200 | [diff] [blame] | 450 | if (dev->steering_support == MLX4_STEERING_MODE_DEVICE_MANAGED) |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 451 | props->device_cap_flags |= IB_DEVICE_MANAGED_FLOW_STEERING; |
Shani Michaeli | b425388 | 2013-02-06 16:19:16 +0000 | [diff] [blame] | 452 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 453 | |
Bodong Wang | 070b399 | 2015-09-22 23:18:11 +0300 | [diff] [blame] | 454 | props->device_cap_flags |= IB_DEVICE_RAW_IP_CSUM; |
| 455 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 456 | props->vendor_id = be32_to_cpup((__be32 *) (out_mad->data + 36)) & |
| 457 | 0xffffff; |
Yishai Hadas | 872bf2f | 2015-01-25 16:59:35 +0200 | [diff] [blame] | 458 | props->vendor_part_id = dev->dev->persist->pdev->device; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 459 | props->hw_ver = be32_to_cpup((__be32 *) (out_mad->data + 32)); |
| 460 | memcpy(&props->sys_image_guid, out_mad->data + 4, 8); |
| 461 | |
| 462 | props->max_mr_size = ~0ull; |
| 463 | props->page_size_cap = dev->dev->caps.page_size_cap; |
Jack Morgenstein | 5a0d0a6 | 2013-11-03 10:03:23 +0200 | [diff] [blame] | 464 | props->max_qp = dev->dev->quotas.qp; |
Sagi Grimberg | fc2d004 | 2012-05-24 16:08:08 +0300 | [diff] [blame] | 465 | props->max_qp_wr = dev->dev->caps.max_wqes - MLX4_IB_SQ_MAX_SPARE; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 466 | props->max_sge = min(dev->dev->caps.max_sq_sg, |
| 467 | dev->dev->caps.max_rq_sg); |
Sagi Grimberg | a5e14ba | 2015-10-28 13:28:15 +0200 | [diff] [blame] | 468 | props->max_sge_rd = MLX4_MAX_SGE_RD; |
Jack Morgenstein | 5a0d0a6 | 2013-11-03 10:03:23 +0200 | [diff] [blame] | 469 | props->max_cq = dev->dev->quotas.cq; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 470 | props->max_cqe = dev->dev->caps.max_cqes; |
Jack Morgenstein | 5a0d0a6 | 2013-11-03 10:03:23 +0200 | [diff] [blame] | 471 | props->max_mr = dev->dev->quotas.mpt; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 472 | props->max_pd = dev->dev->caps.num_pds - dev->dev->caps.reserved_pds; |
| 473 | props->max_qp_rd_atom = dev->dev->caps.max_qp_dest_rdma; |
| 474 | props->max_qp_init_rd_atom = dev->dev->caps.max_qp_init_rdma; |
| 475 | props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp; |
Jack Morgenstein | 5a0d0a6 | 2013-11-03 10:03:23 +0200 | [diff] [blame] | 476 | props->max_srq = dev->dev->quotas.srq; |
Jack Morgenstein | c8681f1 | 2007-06-21 13:39:10 -0700 | [diff] [blame] | 477 | props->max_srq_wr = dev->dev->caps.max_srq_wqes - 1; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 478 | props->max_srq_sge = dev->dev->caps.max_srq_sge; |
Eli Cohen | 5a0fd09 | 2010-10-07 16:24:16 +0200 | [diff] [blame] | 479 | props->max_fast_reg_page_list_len = MLX4_MAX_FAST_REG_PAGES; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 480 | props->local_ca_ack_delay = dev->dev->caps.local_ca_ack_delay; |
| 481 | props->atomic_cap = dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_ATOMIC ? |
| 482 | IB_ATOMIC_HCA : IB_ATOMIC_NONE; |
Dotan Barak | 47e956b | 2012-07-11 15:39:29 +0000 | [diff] [blame] | 483 | props->masked_atomic_cap = props->atomic_cap; |
Roland Dreier | 5ae2a7a | 2007-06-18 08:15:02 -0700 | [diff] [blame] | 484 | props->max_pkeys = dev->dev->caps.pkey_table_len[1]; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 485 | props->max_mcast_grp = dev->dev->caps.num_mgms + dev->dev->caps.num_amgms; |
| 486 | props->max_mcast_qp_attach = dev->dev->caps.num_qp_per_mgm; |
| 487 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 488 | props->max_mcast_grp; |
Eli Cohen | a5bbe89 | 2012-02-09 18:10:06 +0200 | [diff] [blame] | 489 | props->max_map_per_fmr = dev->dev->caps.max_fmr_maps; |
Matan Barak | 4b664c4 | 2015-06-11 16:35:27 +0300 | [diff] [blame] | 490 | props->hca_core_clock = dev->dev->caps.hca_core_clock * 1000UL; |
| 491 | props->timestamp_mask = 0xFFFFFFFFFFFFULL; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 492 | |
Matan Barak | 8a7ff14 | 2015-07-01 14:31:02 +0300 | [diff] [blame] | 493 | if (!mlx4_is_slave(dev->dev)) |
| 494 | err = mlx4_get_internal_clock_params(dev->dev, &clock_params); |
Matan Barak | 4b664c4 | 2015-06-11 16:35:27 +0300 | [diff] [blame] | 495 | |
| 496 | if (uhw->outlen >= resp.response_length + sizeof(resp.hca_core_clock_offset)) { |
Matan Barak | 4b664c4 | 2015-06-11 16:35:27 +0300 | [diff] [blame] | 497 | resp.response_length += sizeof(resp.hca_core_clock_offset); |
Matan Barak | 8a7ff14 | 2015-07-01 14:31:02 +0300 | [diff] [blame] | 498 | if (!err && !mlx4_is_slave(dev->dev)) { |
| 499 | resp.comp_mask |= QUERY_DEVICE_RESP_MASK_TIMESTAMP; |
| 500 | resp.hca_core_clock_offset = clock_params.offset % PAGE_SIZE; |
| 501 | } |
Matan Barak | 4b664c4 | 2015-06-11 16:35:27 +0300 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | if (uhw->outlen) { |
| 505 | err = ib_copy_to_udata(uhw, &resp, resp.response_length); |
| 506 | if (err) |
| 507 | goto out; |
| 508 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 509 | out: |
| 510 | kfree(in_mad); |
| 511 | kfree(out_mad); |
| 512 | |
| 513 | return err; |
| 514 | } |
| 515 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 516 | static enum rdma_link_layer |
| 517 | mlx4_ib_port_link_layer(struct ib_device *device, u8 port_num) |
| 518 | { |
| 519 | struct mlx4_dev *dev = to_mdev(device)->dev; |
| 520 | |
Jack Morgenstein | 65dab25 | 2011-12-13 04:10:41 +0000 | [diff] [blame] | 521 | return dev->caps.port_mask[port_num] == MLX4_PORT_TYPE_IB ? |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 522 | IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET; |
| 523 | } |
| 524 | |
| 525 | static int ib_link_query_port(struct ib_device *ibdev, u8 port, |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 526 | struct ib_port_attr *props, int netw_view) |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 527 | { |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 528 | struct ib_smp *in_mad = NULL; |
| 529 | struct ib_smp *out_mad = NULL; |
Marcel Apfelbaum | a5e12df | 2011-10-03 19:04:20 +0300 | [diff] [blame] | 530 | int ext_active_speed; |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 531 | int mad_ifc_flags = MLX4_MAD_IFC_IGNORE_KEYS; |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 532 | int err = -ENOMEM; |
| 533 | |
| 534 | in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); |
| 535 | out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); |
| 536 | if (!in_mad || !out_mad) |
| 537 | goto out; |
| 538 | |
| 539 | init_query_mad(in_mad); |
| 540 | in_mad->attr_id = IB_SMP_ATTR_PORT_INFO; |
| 541 | in_mad->attr_mod = cpu_to_be32(port); |
| 542 | |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 543 | if (mlx4_is_mfunc(to_mdev(ibdev)->dev) && netw_view) |
| 544 | mad_ifc_flags |= MLX4_MAD_IFC_NET_VIEW; |
| 545 | |
| 546 | err = mlx4_MAD_IFC(to_mdev(ibdev), mad_ifc_flags, port, NULL, NULL, |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 547 | in_mad, out_mad); |
| 548 | if (err) |
| 549 | goto out; |
| 550 | |
Marcel Apfelbaum | a5e12df | 2011-10-03 19:04:20 +0300 | [diff] [blame] | 551 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 552 | props->lid = be16_to_cpup((__be16 *) (out_mad->data + 16)); |
| 553 | props->lmc = out_mad->data[34] & 0x7; |
| 554 | props->sm_lid = be16_to_cpup((__be16 *) (out_mad->data + 18)); |
| 555 | props->sm_sl = out_mad->data[36] & 0xf; |
| 556 | props->state = out_mad->data[32] & 0xf; |
| 557 | props->phys_state = out_mad->data[33] >> 4; |
| 558 | props->port_cap_flags = be32_to_cpup((__be32 *) (out_mad->data + 20)); |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 559 | if (netw_view) |
| 560 | props->gid_tbl_len = out_mad->data[50]; |
| 561 | else |
| 562 | props->gid_tbl_len = to_mdev(ibdev)->dev->caps.gid_table_len[port]; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 563 | props->max_msg_sz = to_mdev(ibdev)->dev->caps.max_msg_sz; |
| 564 | props->pkey_tbl_len = to_mdev(ibdev)->dev->caps.pkey_table_len[port]; |
| 565 | props->bad_pkey_cntr = be16_to_cpup((__be16 *) (out_mad->data + 46)); |
| 566 | props->qkey_viol_cntr = be16_to_cpup((__be16 *) (out_mad->data + 48)); |
| 567 | props->active_width = out_mad->data[31] & 0xf; |
| 568 | props->active_speed = out_mad->data[35] >> 4; |
| 569 | props->max_mtu = out_mad->data[41] & 0xf; |
| 570 | props->active_mtu = out_mad->data[36] >> 4; |
| 571 | props->subnet_timeout = out_mad->data[51] & 0x1f; |
| 572 | props->max_vl_num = out_mad->data[37] >> 4; |
| 573 | props->init_type_reply = out_mad->data[41] >> 4; |
| 574 | |
Marcel Apfelbaum | a5e12df | 2011-10-03 19:04:20 +0300 | [diff] [blame] | 575 | /* Check if extended speeds (EDR/FDR/...) are supported */ |
| 576 | if (props->port_cap_flags & IB_PORT_EXTENDED_SPEEDS_SUP) { |
| 577 | ext_active_speed = out_mad->data[62] >> 4; |
| 578 | |
| 579 | switch (ext_active_speed) { |
| 580 | case 1: |
Or Gerlitz | 2e96691 | 2012-02-28 18:49:50 +0200 | [diff] [blame] | 581 | props->active_speed = IB_SPEED_FDR; |
Marcel Apfelbaum | a5e12df | 2011-10-03 19:04:20 +0300 | [diff] [blame] | 582 | break; |
| 583 | case 2: |
Or Gerlitz | 2e96691 | 2012-02-28 18:49:50 +0200 | [diff] [blame] | 584 | props->active_speed = IB_SPEED_EDR; |
Marcel Apfelbaum | a5e12df | 2011-10-03 19:04:20 +0300 | [diff] [blame] | 585 | break; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /* If reported active speed is QDR, check if is FDR-10 */ |
Or Gerlitz | 2e96691 | 2012-02-28 18:49:50 +0200 | [diff] [blame] | 590 | if (props->active_speed == IB_SPEED_QDR) { |
Or Gerlitz | 8154c07 | 2012-03-06 15:50:50 +0200 | [diff] [blame] | 591 | init_query_mad(in_mad); |
| 592 | in_mad->attr_id = MLX4_ATTR_EXTENDED_PORT_INFO; |
| 593 | in_mad->attr_mod = cpu_to_be32(port); |
Marcel Apfelbaum | a5e12df | 2011-10-03 19:04:20 +0300 | [diff] [blame] | 594 | |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 595 | err = mlx4_MAD_IFC(to_mdev(ibdev), mad_ifc_flags, port, |
Or Gerlitz | 8154c07 | 2012-03-06 15:50:50 +0200 | [diff] [blame] | 596 | NULL, NULL, in_mad, out_mad); |
| 597 | if (err) |
Jesper Juhl | bf6b47d | 2012-04-11 23:43:29 +0200 | [diff] [blame] | 598 | goto out; |
Marcel Apfelbaum | a5e12df | 2011-10-03 19:04:20 +0300 | [diff] [blame] | 599 | |
Or Gerlitz | 8154c07 | 2012-03-06 15:50:50 +0200 | [diff] [blame] | 600 | /* Checking LinkSpeedActive for FDR-10 */ |
| 601 | if (out_mad->data[15] & 0x1) |
| 602 | props->active_speed = IB_SPEED_FDR10; |
Marcel Apfelbaum | a5e12df | 2011-10-03 19:04:20 +0300 | [diff] [blame] | 603 | } |
Or Gerlitz | d2ef406 | 2012-04-02 17:45:20 +0300 | [diff] [blame] | 604 | |
| 605 | /* Avoid wrong speed value returned by FW if the IB link is down. */ |
| 606 | if (props->state == IB_PORT_DOWN) |
| 607 | props->active_speed = IB_SPEED_SDR; |
| 608 | |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 609 | out: |
| 610 | kfree(in_mad); |
| 611 | kfree(out_mad); |
| 612 | return err; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | static u8 state_to_phys_state(enum ib_port_state state) |
| 616 | { |
| 617 | return state == IB_PORT_ACTIVE ? 5 : 3; |
| 618 | } |
| 619 | |
| 620 | static int eth_link_query_port(struct ib_device *ibdev, u8 port, |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 621 | struct ib_port_attr *props, int netw_view) |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 622 | { |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 623 | |
| 624 | struct mlx4_ib_dev *mdev = to_mdev(ibdev); |
| 625 | struct mlx4_ib_iboe *iboe = &mdev->iboe; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 626 | struct net_device *ndev; |
| 627 | enum ib_mtu tmp; |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 628 | struct mlx4_cmd_mailbox *mailbox; |
| 629 | int err = 0; |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 630 | int is_bonded = mlx4_is_bonded(mdev->dev); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 631 | |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 632 | mailbox = mlx4_alloc_cmd_mailbox(mdev->dev); |
| 633 | if (IS_ERR(mailbox)) |
| 634 | return PTR_ERR(mailbox); |
| 635 | |
| 636 | err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, port, 0, |
| 637 | MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B, |
| 638 | MLX4_CMD_WRAPPED); |
| 639 | if (err) |
| 640 | goto out; |
| 641 | |
| 642 | props->active_width = (((u8 *)mailbox->buf)[5] == 0x40) ? |
| 643 | IB_WIDTH_4X : IB_WIDTH_1X; |
Or Gerlitz | 2e96691 | 2012-02-28 18:49:50 +0200 | [diff] [blame] | 644 | props->active_speed = IB_SPEED_QDR; |
Moni Shoua | b4a26a2 | 2014-02-09 11:54:34 +0200 | [diff] [blame] | 645 | props->port_cap_flags = IB_PORT_CM_SUP | IB_PORT_IP_BASED_GIDS; |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 646 | props->gid_tbl_len = mdev->dev->caps.gid_table_len[port]; |
| 647 | props->max_msg_sz = mdev->dev->caps.max_msg_sz; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 648 | props->pkey_tbl_len = 1; |
Or Gerlitz | bcacb89 | 2011-10-10 10:53:41 +0200 | [diff] [blame] | 649 | props->max_mtu = IB_MTU_4096; |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 650 | props->max_vl_num = 2; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 651 | props->state = IB_PORT_DOWN; |
| 652 | props->phys_state = state_to_phys_state(props->state); |
| 653 | props->active_mtu = IB_MTU_256; |
Jack Morgenstein | dba3ad2 | 2014-08-21 14:28:41 +0300 | [diff] [blame] | 654 | spin_lock_bh(&iboe->lock); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 655 | ndev = iboe->netdevs[port - 1]; |
Moni Shoua | 5070cd2 | 2015-07-30 18:33:30 +0300 | [diff] [blame] | 656 | if (ndev && is_bonded) { |
| 657 | rcu_read_lock(); /* required to get upper dev */ |
| 658 | ndev = netdev_master_upper_dev_get_rcu(ndev); |
| 659 | rcu_read_unlock(); |
| 660 | } |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 661 | if (!ndev) |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 662 | goto out_unlock; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 663 | |
| 664 | tmp = iboe_get_mtu(ndev->mtu); |
| 665 | props->active_mtu = tmp ? min(props->max_mtu, tmp) : IB_MTU_256; |
| 666 | |
Eli Cohen | 21d60609 | 2010-11-11 21:05:58 +0000 | [diff] [blame] | 667 | props->state = (netif_running(ndev) && netif_carrier_ok(ndev)) ? |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 668 | IB_PORT_ACTIVE : IB_PORT_DOWN; |
| 669 | props->phys_state = state_to_phys_state(props->state); |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 670 | out_unlock: |
Jack Morgenstein | dba3ad2 | 2014-08-21 14:28:41 +0300 | [diff] [blame] | 671 | spin_unlock_bh(&iboe->lock); |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 672 | out: |
| 673 | mlx4_free_cmd_mailbox(mdev->dev, mailbox); |
| 674 | return err; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 677 | int __mlx4_ib_query_port(struct ib_device *ibdev, u8 port, |
| 678 | struct ib_port_attr *props, int netw_view) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 679 | { |
Or Gerlitz | a9c766b | 2012-01-11 19:00:29 +0200 | [diff] [blame] | 680 | int err; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 681 | |
| 682 | memset(props, 0, sizeof *props); |
| 683 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 684 | err = mlx4_ib_port_link_layer(ibdev, port) == IB_LINK_LAYER_INFINIBAND ? |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 685 | ib_link_query_port(ibdev, port, props, netw_view) : |
| 686 | eth_link_query_port(ibdev, port, props, netw_view); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 687 | |
| 688 | return err; |
| 689 | } |
| 690 | |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 691 | static int mlx4_ib_query_port(struct ib_device *ibdev, u8 port, |
| 692 | struct ib_port_attr *props) |
| 693 | { |
| 694 | /* returns host view */ |
| 695 | return __mlx4_ib_query_port(ibdev, port, props, 0); |
| 696 | } |
| 697 | |
Jack Morgenstein | a0c64a1 | 2012-08-03 08:40:49 +0000 | [diff] [blame] | 698 | int __mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 699 | union ib_gid *gid, int netw_view) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 700 | { |
| 701 | struct ib_smp *in_mad = NULL; |
| 702 | struct ib_smp *out_mad = NULL; |
| 703 | int err = -ENOMEM; |
Jack Morgenstein | a0c64a1 | 2012-08-03 08:40:49 +0000 | [diff] [blame] | 704 | struct mlx4_ib_dev *dev = to_mdev(ibdev); |
| 705 | int clear = 0; |
| 706 | int mad_ifc_flags = MLX4_MAD_IFC_IGNORE_KEYS; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 707 | |
| 708 | in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); |
| 709 | out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); |
| 710 | if (!in_mad || !out_mad) |
| 711 | goto out; |
| 712 | |
| 713 | init_query_mad(in_mad); |
| 714 | in_mad->attr_id = IB_SMP_ATTR_PORT_INFO; |
| 715 | in_mad->attr_mod = cpu_to_be32(port); |
| 716 | |
Jack Morgenstein | a0c64a1 | 2012-08-03 08:40:49 +0000 | [diff] [blame] | 717 | if (mlx4_is_mfunc(dev->dev) && netw_view) |
| 718 | mad_ifc_flags |= MLX4_MAD_IFC_NET_VIEW; |
| 719 | |
| 720 | err = mlx4_MAD_IFC(dev, mad_ifc_flags, port, NULL, NULL, in_mad, out_mad); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 721 | if (err) |
| 722 | goto out; |
| 723 | |
| 724 | memcpy(gid->raw, out_mad->data + 8, 8); |
| 725 | |
Jack Morgenstein | a0c64a1 | 2012-08-03 08:40:49 +0000 | [diff] [blame] | 726 | if (mlx4_is_mfunc(dev->dev) && !netw_view) { |
| 727 | if (index) { |
| 728 | /* For any index > 0, return the null guid */ |
| 729 | err = 0; |
| 730 | clear = 1; |
| 731 | goto out; |
| 732 | } |
| 733 | } |
| 734 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 735 | init_query_mad(in_mad); |
| 736 | in_mad->attr_id = IB_SMP_ATTR_GUID_INFO; |
| 737 | in_mad->attr_mod = cpu_to_be32(index / 8); |
| 738 | |
Jack Morgenstein | a0c64a1 | 2012-08-03 08:40:49 +0000 | [diff] [blame] | 739 | err = mlx4_MAD_IFC(dev, mad_ifc_flags, port, |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 740 | NULL, NULL, in_mad, out_mad); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 741 | if (err) |
| 742 | goto out; |
| 743 | |
| 744 | memcpy(gid->raw + 8, out_mad->data + (index % 8) * 8, 8); |
| 745 | |
| 746 | out: |
Jack Morgenstein | a0c64a1 | 2012-08-03 08:40:49 +0000 | [diff] [blame] | 747 | if (clear) |
| 748 | memset(gid->raw + 8, 0, 8); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 749 | kfree(in_mad); |
| 750 | kfree(out_mad); |
| 751 | return err; |
| 752 | } |
| 753 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 754 | static int mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 755 | union ib_gid *gid) |
| 756 | { |
Moni Shoua | 5070cd2 | 2015-07-30 18:33:30 +0300 | [diff] [blame] | 757 | int ret; |
| 758 | |
| 759 | if (rdma_protocol_ib(ibdev, port)) |
Jack Morgenstein | a0c64a1 | 2012-08-03 08:40:49 +0000 | [diff] [blame] | 760 | return __mlx4_ib_query_gid(ibdev, port, index, gid, 0); |
Moni Shoua | 5070cd2 | 2015-07-30 18:33:30 +0300 | [diff] [blame] | 761 | |
| 762 | if (!rdma_protocol_roce(ibdev, port)) |
| 763 | return -ENODEV; |
| 764 | |
| 765 | if (!rdma_cap_roce_gid_table(ibdev, port)) |
| 766 | return -ENODEV; |
| 767 | |
Matan Barak | 55ee3ab | 2015-10-15 18:38:45 +0300 | [diff] [blame] | 768 | ret = ib_get_cached_gid(ibdev, port, index, gid, NULL); |
Moni Shoua | 5070cd2 | 2015-07-30 18:33:30 +0300 | [diff] [blame] | 769 | if (ret == -EAGAIN) { |
| 770 | memcpy(gid, &zgid, sizeof(*gid)); |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | return ret; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 777 | int __mlx4_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 778 | u16 *pkey, int netw_view) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 779 | { |
| 780 | struct ib_smp *in_mad = NULL; |
| 781 | struct ib_smp *out_mad = NULL; |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 782 | int mad_ifc_flags = MLX4_MAD_IFC_IGNORE_KEYS; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 783 | int err = -ENOMEM; |
| 784 | |
| 785 | in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); |
| 786 | out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); |
| 787 | if (!in_mad || !out_mad) |
| 788 | goto out; |
| 789 | |
| 790 | init_query_mad(in_mad); |
| 791 | in_mad->attr_id = IB_SMP_ATTR_PKEY_TABLE; |
| 792 | in_mad->attr_mod = cpu_to_be32(index / 32); |
| 793 | |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 794 | if (mlx4_is_mfunc(to_mdev(ibdev)->dev) && netw_view) |
| 795 | mad_ifc_flags |= MLX4_MAD_IFC_NET_VIEW; |
| 796 | |
| 797 | err = mlx4_MAD_IFC(to_mdev(ibdev), mad_ifc_flags, port, NULL, NULL, |
| 798 | in_mad, out_mad); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 799 | if (err) |
| 800 | goto out; |
| 801 | |
| 802 | *pkey = be16_to_cpu(((__be16 *) out_mad->data)[index % 32]); |
| 803 | |
| 804 | out: |
| 805 | kfree(in_mad); |
| 806 | kfree(out_mad); |
| 807 | return err; |
| 808 | } |
| 809 | |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 810 | static int mlx4_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, u16 *pkey) |
| 811 | { |
| 812 | return __mlx4_ib_query_pkey(ibdev, port, index, pkey, 0); |
| 813 | } |
| 814 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 815 | static int mlx4_ib_modify_device(struct ib_device *ibdev, int mask, |
| 816 | struct ib_device_modify *props) |
| 817 | { |
Jack Morgenstein | d0d68b8 | 2010-10-04 12:11:34 +0000 | [diff] [blame] | 818 | struct mlx4_cmd_mailbox *mailbox; |
Jack Morgenstein | df7fba6 | 2012-08-03 08:26:45 +0000 | [diff] [blame] | 819 | unsigned long flags; |
Jack Morgenstein | d0d68b8 | 2010-10-04 12:11:34 +0000 | [diff] [blame] | 820 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 821 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 822 | return -EOPNOTSUPP; |
| 823 | |
Jack Morgenstein | d0d68b8 | 2010-10-04 12:11:34 +0000 | [diff] [blame] | 824 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 825 | return 0; |
| 826 | |
Jack Morgenstein | 992e8e6e | 2012-08-03 08:40:54 +0000 | [diff] [blame] | 827 | if (mlx4_is_slave(to_mdev(ibdev)->dev)) |
| 828 | return -EOPNOTSUPP; |
| 829 | |
Jack Morgenstein | df7fba6 | 2012-08-03 08:26:45 +0000 | [diff] [blame] | 830 | spin_lock_irqsave(&to_mdev(ibdev)->sm_lock, flags); |
Jack Morgenstein | d0d68b8 | 2010-10-04 12:11:34 +0000 | [diff] [blame] | 831 | memcpy(ibdev->node_desc, props->node_desc, 64); |
Jack Morgenstein | df7fba6 | 2012-08-03 08:26:45 +0000 | [diff] [blame] | 832 | spin_unlock_irqrestore(&to_mdev(ibdev)->sm_lock, flags); |
Jack Morgenstein | d0d68b8 | 2010-10-04 12:11:34 +0000 | [diff] [blame] | 833 | |
| 834 | /* |
| 835 | * If possible, pass node desc to FW, so it can generate |
| 836 | * a 144 trap. If cmd fails, just ignore. |
| 837 | */ |
| 838 | mailbox = mlx4_alloc_cmd_mailbox(to_mdev(ibdev)->dev); |
| 839 | if (IS_ERR(mailbox)) |
| 840 | return 0; |
| 841 | |
Jack Morgenstein | d0d68b8 | 2010-10-04 12:11:34 +0000 | [diff] [blame] | 842 | memcpy(mailbox->buf, props->node_desc, 64); |
| 843 | mlx4_cmd(to_mdev(ibdev)->dev, mailbox->dma, 1, 0, |
Jack Morgenstein | 992e8e6e | 2012-08-03 08:40:54 +0000 | [diff] [blame] | 844 | MLX4_CMD_SET_NODE, MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); |
Jack Morgenstein | d0d68b8 | 2010-10-04 12:11:34 +0000 | [diff] [blame] | 845 | |
| 846 | mlx4_free_cmd_mailbox(to_mdev(ibdev)->dev, mailbox); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 847 | |
| 848 | return 0; |
| 849 | } |
| 850 | |
Jack Morgenstein | 6156501 | 2014-05-29 16:31:01 +0300 | [diff] [blame] | 851 | static int mlx4_ib_SET_PORT(struct mlx4_ib_dev *dev, u8 port, int reset_qkey_viols, |
| 852 | u32 cap_mask) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 853 | { |
| 854 | struct mlx4_cmd_mailbox *mailbox; |
| 855 | int err; |
| 856 | |
| 857 | mailbox = mlx4_alloc_cmd_mailbox(dev->dev); |
| 858 | if (IS_ERR(mailbox)) |
| 859 | return PTR_ERR(mailbox); |
| 860 | |
Roland Dreier | 5ae2a7a | 2007-06-18 08:15:02 -0700 | [diff] [blame] | 861 | if (dev->dev->flags & MLX4_FLAG_OLD_PORT_CMDS) { |
| 862 | *(u8 *) mailbox->buf = !!reset_qkey_viols << 6; |
| 863 | ((__be32 *) mailbox->buf)[2] = cpu_to_be32(cap_mask); |
| 864 | } else { |
| 865 | ((u8 *) mailbox->buf)[3] = !!reset_qkey_viols; |
| 866 | ((__be32 *) mailbox->buf)[1] = cpu_to_be32(cap_mask); |
| 867 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 868 | |
Ido Shamay | a130b59 | 2015-04-02 16:31:19 +0300 | [diff] [blame] | 869 | err = mlx4_cmd(dev->dev, mailbox->dma, port, MLX4_SET_PORT_IB_OPCODE, |
| 870 | MLX4_CMD_SET_PORT, MLX4_CMD_TIME_CLASS_B, |
| 871 | MLX4_CMD_WRAPPED); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 872 | |
| 873 | mlx4_free_cmd_mailbox(dev->dev, mailbox); |
| 874 | return err; |
| 875 | } |
| 876 | |
| 877 | static int mlx4_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 878 | struct ib_port_modify *props) |
| 879 | { |
Jack Morgenstein | 6156501 | 2014-05-29 16:31:01 +0300 | [diff] [blame] | 880 | struct mlx4_ib_dev *mdev = to_mdev(ibdev); |
| 881 | u8 is_eth = mdev->dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 882 | struct ib_port_attr attr; |
| 883 | u32 cap_mask; |
| 884 | int err; |
| 885 | |
Jack Morgenstein | 6156501 | 2014-05-29 16:31:01 +0300 | [diff] [blame] | 886 | /* return OK if this is RoCE. CM calls ib_modify_port() regardless |
| 887 | * of whether port link layer is ETH or IB. For ETH ports, qkey |
| 888 | * violations and port capabilities are not meaningful. |
| 889 | */ |
| 890 | if (is_eth) |
| 891 | return 0; |
| 892 | |
| 893 | mutex_lock(&mdev->cap_mask_mutex); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 894 | |
| 895 | err = mlx4_ib_query_port(ibdev, port, &attr); |
| 896 | if (err) |
| 897 | goto out; |
| 898 | |
| 899 | cap_mask = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 900 | ~props->clr_port_cap_mask; |
| 901 | |
Jack Morgenstein | 6156501 | 2014-05-29 16:31:01 +0300 | [diff] [blame] | 902 | err = mlx4_ib_SET_PORT(mdev, port, |
| 903 | !!(mask & IB_PORT_RESET_QKEY_CNTR), |
| 904 | cap_mask); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 905 | |
| 906 | out: |
| 907 | mutex_unlock(&to_mdev(ibdev)->cap_mask_mutex); |
| 908 | return err; |
| 909 | } |
| 910 | |
| 911 | static struct ib_ucontext *mlx4_ib_alloc_ucontext(struct ib_device *ibdev, |
| 912 | struct ib_udata *udata) |
| 913 | { |
| 914 | struct mlx4_ib_dev *dev = to_mdev(ibdev); |
| 915 | struct mlx4_ib_ucontext *context; |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 916 | struct mlx4_ib_alloc_ucontext_resp_v3 resp_v3; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 917 | struct mlx4_ib_alloc_ucontext_resp resp; |
| 918 | int err; |
| 919 | |
Jack Morgenstein | 3b4a8cd | 2009-09-05 20:24:50 -0700 | [diff] [blame] | 920 | if (!dev->ib_active) |
| 921 | return ERR_PTR(-EAGAIN); |
| 922 | |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 923 | if (ibdev->uverbs_abi_ver == MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION) { |
| 924 | resp_v3.qp_tab_size = dev->dev->caps.num_qps; |
| 925 | resp_v3.bf_reg_size = dev->dev->caps.bf_reg_size; |
| 926 | resp_v3.bf_regs_per_page = dev->dev->caps.bf_regs_per_page; |
| 927 | } else { |
| 928 | resp.dev_caps = dev->dev->caps.userspace_caps; |
| 929 | resp.qp_tab_size = dev->dev->caps.num_qps; |
| 930 | resp.bf_reg_size = dev->dev->caps.bf_reg_size; |
| 931 | resp.bf_regs_per_page = dev->dev->caps.bf_regs_per_page; |
| 932 | resp.cqe_size = dev->dev->caps.cqe_size; |
| 933 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 934 | |
Yishai Hadas | ae184dd | 2015-08-13 18:32:06 +0300 | [diff] [blame] | 935 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 936 | if (!context) |
| 937 | return ERR_PTR(-ENOMEM); |
| 938 | |
| 939 | err = mlx4_uar_alloc(to_mdev(ibdev)->dev, &context->uar); |
| 940 | if (err) { |
| 941 | kfree(context); |
| 942 | return ERR_PTR(err); |
| 943 | } |
| 944 | |
| 945 | INIT_LIST_HEAD(&context->db_page_list); |
| 946 | mutex_init(&context->db_page_mutex); |
| 947 | |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 948 | if (ibdev->uverbs_abi_ver == MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION) |
| 949 | err = ib_copy_to_udata(udata, &resp_v3, sizeof(resp_v3)); |
| 950 | else |
| 951 | err = ib_copy_to_udata(udata, &resp, sizeof(resp)); |
| 952 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 953 | if (err) { |
| 954 | mlx4_uar_free(to_mdev(ibdev)->dev, &context->uar); |
| 955 | kfree(context); |
| 956 | return ERR_PTR(-EFAULT); |
| 957 | } |
| 958 | |
| 959 | return &context->ibucontext; |
| 960 | } |
| 961 | |
| 962 | static int mlx4_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
| 963 | { |
| 964 | struct mlx4_ib_ucontext *context = to_mucontext(ibcontext); |
| 965 | |
| 966 | mlx4_uar_free(to_mdev(ibcontext->device)->dev, &context->uar); |
| 967 | kfree(context); |
| 968 | |
| 969 | return 0; |
| 970 | } |
| 971 | |
Yishai Hadas | ae184dd | 2015-08-13 18:32:06 +0300 | [diff] [blame] | 972 | static void mlx4_ib_vma_open(struct vm_area_struct *area) |
| 973 | { |
| 974 | /* vma_open is called when a new VMA is created on top of our VMA. |
| 975 | * This is done through either mremap flow or split_vma (usually due |
| 976 | * to mlock, madvise, munmap, etc.). We do not support a clone of the |
| 977 | * vma, as this VMA is strongly hardware related. Therefore we set the |
| 978 | * vm_ops of the newly created/cloned VMA to NULL, to prevent it from |
| 979 | * calling us again and trying to do incorrect actions. We assume that |
| 980 | * the original vma size is exactly a single page that there will be no |
| 981 | * "splitting" operations on. |
| 982 | */ |
| 983 | area->vm_ops = NULL; |
| 984 | } |
| 985 | |
| 986 | static void mlx4_ib_vma_close(struct vm_area_struct *area) |
| 987 | { |
| 988 | struct mlx4_ib_vma_private_data *mlx4_ib_vma_priv_data; |
| 989 | |
| 990 | /* It's guaranteed that all VMAs opened on a FD are closed before the |
| 991 | * file itself is closed, therefore no sync is needed with the regular |
| 992 | * closing flow. (e.g. mlx4_ib_dealloc_ucontext) However need a sync |
| 993 | * with accessing the vma as part of mlx4_ib_disassociate_ucontext. |
| 994 | * The close operation is usually called under mm->mmap_sem except when |
| 995 | * process is exiting. The exiting case is handled explicitly as part |
| 996 | * of mlx4_ib_disassociate_ucontext. |
| 997 | */ |
| 998 | mlx4_ib_vma_priv_data = (struct mlx4_ib_vma_private_data *) |
| 999 | area->vm_private_data; |
| 1000 | |
| 1001 | /* set the vma context pointer to null in the mlx4_ib driver's private |
| 1002 | * data to protect against a race condition in mlx4_ib_dissassociate_ucontext(). |
| 1003 | */ |
| 1004 | mlx4_ib_vma_priv_data->vma = NULL; |
| 1005 | } |
| 1006 | |
| 1007 | static const struct vm_operations_struct mlx4_ib_vm_ops = { |
| 1008 | .open = mlx4_ib_vma_open, |
| 1009 | .close = mlx4_ib_vma_close |
| 1010 | }; |
| 1011 | |
| 1012 | static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) |
| 1013 | { |
| 1014 | int i; |
| 1015 | int ret = 0; |
| 1016 | struct vm_area_struct *vma; |
| 1017 | struct mlx4_ib_ucontext *context = to_mucontext(ibcontext); |
| 1018 | struct task_struct *owning_process = NULL; |
| 1019 | struct mm_struct *owning_mm = NULL; |
| 1020 | |
| 1021 | owning_process = get_pid_task(ibcontext->tgid, PIDTYPE_PID); |
| 1022 | if (!owning_process) |
| 1023 | return; |
| 1024 | |
| 1025 | owning_mm = get_task_mm(owning_process); |
| 1026 | if (!owning_mm) { |
| 1027 | pr_info("no mm, disassociate ucontext is pending task termination\n"); |
| 1028 | while (1) { |
| 1029 | /* make sure that task is dead before returning, it may |
| 1030 | * prevent a rare case of module down in parallel to a |
| 1031 | * call to mlx4_ib_vma_close. |
| 1032 | */ |
| 1033 | put_task_struct(owning_process); |
| 1034 | msleep(1); |
| 1035 | owning_process = get_pid_task(ibcontext->tgid, |
| 1036 | PIDTYPE_PID); |
| 1037 | if (!owning_process || |
| 1038 | owning_process->state == TASK_DEAD) { |
| 1039 | pr_info("disassociate ucontext done, task was terminated\n"); |
| 1040 | /* in case task was dead need to release the task struct */ |
| 1041 | if (owning_process) |
| 1042 | put_task_struct(owning_process); |
| 1043 | return; |
| 1044 | } |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | /* need to protect from a race on closing the vma as part of |
| 1049 | * mlx4_ib_vma_close(). |
| 1050 | */ |
| 1051 | down_read(&owning_mm->mmap_sem); |
| 1052 | for (i = 0; i < HW_BAR_COUNT; i++) { |
| 1053 | vma = context->hw_bar_info[i].vma; |
| 1054 | if (!vma) |
| 1055 | continue; |
| 1056 | |
| 1057 | ret = zap_vma_ptes(context->hw_bar_info[i].vma, |
| 1058 | context->hw_bar_info[i].vma->vm_start, |
| 1059 | PAGE_SIZE); |
| 1060 | if (ret) { |
| 1061 | pr_err("Error: zap_vma_ptes failed for index=%d, ret=%d\n", i, ret); |
| 1062 | BUG_ON(1); |
| 1063 | } |
| 1064 | |
| 1065 | /* context going to be destroyed, should not access ops any more */ |
| 1066 | context->hw_bar_info[i].vma->vm_ops = NULL; |
| 1067 | } |
| 1068 | |
| 1069 | up_read(&owning_mm->mmap_sem); |
| 1070 | mmput(owning_mm); |
| 1071 | put_task_struct(owning_process); |
| 1072 | } |
| 1073 | |
| 1074 | static void mlx4_ib_set_vma_data(struct vm_area_struct *vma, |
| 1075 | struct mlx4_ib_vma_private_data *vma_private_data) |
| 1076 | { |
| 1077 | vma_private_data->vma = vma; |
| 1078 | vma->vm_private_data = vma_private_data; |
| 1079 | vma->vm_ops = &mlx4_ib_vm_ops; |
| 1080 | } |
| 1081 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1082 | static int mlx4_ib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
| 1083 | { |
| 1084 | struct mlx4_ib_dev *dev = to_mdev(context->device); |
Yishai Hadas | ae184dd | 2015-08-13 18:32:06 +0300 | [diff] [blame] | 1085 | struct mlx4_ib_ucontext *mucontext = to_mucontext(context); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1086 | |
| 1087 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 1088 | return -EINVAL; |
| 1089 | |
| 1090 | if (vma->vm_pgoff == 0) { |
Yishai Hadas | ae184dd | 2015-08-13 18:32:06 +0300 | [diff] [blame] | 1091 | /* We prevent double mmaping on same context */ |
| 1092 | if (mucontext->hw_bar_info[HW_BAR_DB].vma) |
| 1093 | return -EINVAL; |
| 1094 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1095 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 1096 | |
| 1097 | if (io_remap_pfn_range(vma, vma->vm_start, |
| 1098 | to_mucontext(context)->uar.pfn, |
| 1099 | PAGE_SIZE, vma->vm_page_prot)) |
| 1100 | return -EAGAIN; |
Yishai Hadas | ae184dd | 2015-08-13 18:32:06 +0300 | [diff] [blame] | 1101 | |
| 1102 | mlx4_ib_set_vma_data(vma, &mucontext->hw_bar_info[HW_BAR_DB]); |
| 1103 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1104 | } else if (vma->vm_pgoff == 1 && dev->dev->caps.bf_reg_size != 0) { |
Yishai Hadas | ae184dd | 2015-08-13 18:32:06 +0300 | [diff] [blame] | 1105 | /* We prevent double mmaping on same context */ |
| 1106 | if (mucontext->hw_bar_info[HW_BAR_BF].vma) |
| 1107 | return -EINVAL; |
| 1108 | |
Roland Dreier | e1d60ec | 2009-03-30 08:31:05 -0700 | [diff] [blame] | 1109 | vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1110 | |
| 1111 | if (io_remap_pfn_range(vma, vma->vm_start, |
| 1112 | to_mucontext(context)->uar.pfn + |
| 1113 | dev->dev->caps.num_uars, |
| 1114 | PAGE_SIZE, vma->vm_page_prot)) |
| 1115 | return -EAGAIN; |
Yishai Hadas | ae184dd | 2015-08-13 18:32:06 +0300 | [diff] [blame] | 1116 | |
| 1117 | mlx4_ib_set_vma_data(vma, &mucontext->hw_bar_info[HW_BAR_BF]); |
| 1118 | |
Matan Barak | 52033cf | 2015-06-11 16:35:26 +0300 | [diff] [blame] | 1119 | } else if (vma->vm_pgoff == 3) { |
| 1120 | struct mlx4_clock_params params; |
Yishai Hadas | ae184dd | 2015-08-13 18:32:06 +0300 | [diff] [blame] | 1121 | int ret; |
| 1122 | |
| 1123 | /* We prevent double mmaping on same context */ |
| 1124 | if (mucontext->hw_bar_info[HW_BAR_CLOCK].vma) |
| 1125 | return -EINVAL; |
| 1126 | |
| 1127 | ret = mlx4_get_internal_clock_params(dev->dev, ¶ms); |
Matan Barak | 52033cf | 2015-06-11 16:35:26 +0300 | [diff] [blame] | 1128 | |
| 1129 | if (ret) |
| 1130 | return ret; |
| 1131 | |
| 1132 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 1133 | if (io_remap_pfn_range(vma, vma->vm_start, |
| 1134 | (pci_resource_start(dev->dev->persist->pdev, |
| 1135 | params.bar) + |
| 1136 | params.offset) |
| 1137 | >> PAGE_SHIFT, |
| 1138 | PAGE_SIZE, vma->vm_page_prot)) |
| 1139 | return -EAGAIN; |
Yishai Hadas | ae184dd | 2015-08-13 18:32:06 +0300 | [diff] [blame] | 1140 | |
| 1141 | mlx4_ib_set_vma_data(vma, |
| 1142 | &mucontext->hw_bar_info[HW_BAR_CLOCK]); |
Matan Barak | 52033cf | 2015-06-11 16:35:26 +0300 | [diff] [blame] | 1143 | } else { |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1144 | return -EINVAL; |
Matan Barak | 52033cf | 2015-06-11 16:35:26 +0300 | [diff] [blame] | 1145 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1146 | |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
| 1150 | static struct ib_pd *mlx4_ib_alloc_pd(struct ib_device *ibdev, |
| 1151 | struct ib_ucontext *context, |
| 1152 | struct ib_udata *udata) |
| 1153 | { |
| 1154 | struct mlx4_ib_pd *pd; |
| 1155 | int err; |
| 1156 | |
| 1157 | pd = kmalloc(sizeof *pd, GFP_KERNEL); |
| 1158 | if (!pd) |
| 1159 | return ERR_PTR(-ENOMEM); |
| 1160 | |
| 1161 | err = mlx4_pd_alloc(to_mdev(ibdev)->dev, &pd->pdn); |
| 1162 | if (err) { |
| 1163 | kfree(pd); |
| 1164 | return ERR_PTR(err); |
| 1165 | } |
| 1166 | |
| 1167 | if (context) |
| 1168 | if (ib_copy_to_udata(udata, &pd->pdn, sizeof (__u32))) { |
| 1169 | mlx4_pd_free(to_mdev(ibdev)->dev, pd->pdn); |
| 1170 | kfree(pd); |
| 1171 | return ERR_PTR(-EFAULT); |
| 1172 | } |
| 1173 | |
| 1174 | return &pd->ibpd; |
| 1175 | } |
| 1176 | |
| 1177 | static int mlx4_ib_dealloc_pd(struct ib_pd *pd) |
| 1178 | { |
| 1179 | mlx4_pd_free(to_mdev(pd->device)->dev, to_mpd(pd)->pdn); |
| 1180 | kfree(pd); |
| 1181 | |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
Sean Hefty | 012a8ff | 2011-06-02 09:01:33 -0700 | [diff] [blame] | 1185 | static struct ib_xrcd *mlx4_ib_alloc_xrcd(struct ib_device *ibdev, |
| 1186 | struct ib_ucontext *context, |
| 1187 | struct ib_udata *udata) |
| 1188 | { |
| 1189 | struct mlx4_ib_xrcd *xrcd; |
Matan Barak | 8e37210 | 2015-06-11 16:35:21 +0300 | [diff] [blame] | 1190 | struct ib_cq_init_attr cq_attr = {}; |
Sean Hefty | 012a8ff | 2011-06-02 09:01:33 -0700 | [diff] [blame] | 1191 | int err; |
| 1192 | |
| 1193 | if (!(to_mdev(ibdev)->dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC)) |
| 1194 | return ERR_PTR(-ENOSYS); |
| 1195 | |
| 1196 | xrcd = kmalloc(sizeof *xrcd, GFP_KERNEL); |
| 1197 | if (!xrcd) |
| 1198 | return ERR_PTR(-ENOMEM); |
| 1199 | |
| 1200 | err = mlx4_xrcd_alloc(to_mdev(ibdev)->dev, &xrcd->xrcdn); |
| 1201 | if (err) |
| 1202 | goto err1; |
| 1203 | |
| 1204 | xrcd->pd = ib_alloc_pd(ibdev); |
| 1205 | if (IS_ERR(xrcd->pd)) { |
| 1206 | err = PTR_ERR(xrcd->pd); |
| 1207 | goto err2; |
| 1208 | } |
| 1209 | |
Matan Barak | 8e37210 | 2015-06-11 16:35:21 +0300 | [diff] [blame] | 1210 | cq_attr.cqe = 1; |
| 1211 | xrcd->cq = ib_create_cq(ibdev, NULL, NULL, xrcd, &cq_attr); |
Sean Hefty | 012a8ff | 2011-06-02 09:01:33 -0700 | [diff] [blame] | 1212 | if (IS_ERR(xrcd->cq)) { |
| 1213 | err = PTR_ERR(xrcd->cq); |
| 1214 | goto err3; |
| 1215 | } |
| 1216 | |
| 1217 | return &xrcd->ibxrcd; |
| 1218 | |
| 1219 | err3: |
| 1220 | ib_dealloc_pd(xrcd->pd); |
| 1221 | err2: |
| 1222 | mlx4_xrcd_free(to_mdev(ibdev)->dev, xrcd->xrcdn); |
| 1223 | err1: |
| 1224 | kfree(xrcd); |
| 1225 | return ERR_PTR(err); |
| 1226 | } |
| 1227 | |
| 1228 | static int mlx4_ib_dealloc_xrcd(struct ib_xrcd *xrcd) |
| 1229 | { |
| 1230 | ib_destroy_cq(to_mxrcd(xrcd)->cq); |
| 1231 | ib_dealloc_pd(to_mxrcd(xrcd)->pd); |
| 1232 | mlx4_xrcd_free(to_mdev(xrcd->device)->dev, to_mxrcd(xrcd)->xrcdn); |
| 1233 | kfree(xrcd); |
| 1234 | |
| 1235 | return 0; |
| 1236 | } |
| 1237 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1238 | static int add_gid_entry(struct ib_qp *ibqp, union ib_gid *gid) |
| 1239 | { |
| 1240 | struct mlx4_ib_qp *mqp = to_mqp(ibqp); |
| 1241 | struct mlx4_ib_dev *mdev = to_mdev(ibqp->device); |
| 1242 | struct mlx4_ib_gid_entry *ge; |
| 1243 | |
| 1244 | ge = kzalloc(sizeof *ge, GFP_KERNEL); |
| 1245 | if (!ge) |
| 1246 | return -ENOMEM; |
| 1247 | |
| 1248 | ge->gid = *gid; |
| 1249 | if (mlx4_ib_add_mc(mdev, mqp, gid)) { |
| 1250 | ge->port = mqp->port; |
| 1251 | ge->added = 1; |
| 1252 | } |
| 1253 | |
| 1254 | mutex_lock(&mqp->mutex); |
| 1255 | list_add_tail(&ge->list, &mqp->gid_list); |
| 1256 | mutex_unlock(&mqp->mutex); |
| 1257 | |
| 1258 | return 0; |
| 1259 | } |
| 1260 | |
Eran Ben Elisha | 3ba8e31 | 2015-10-15 14:44:40 +0300 | [diff] [blame] | 1261 | static void mlx4_ib_delete_counters_table(struct mlx4_ib_dev *ibdev, |
| 1262 | struct mlx4_ib_counters *ctr_table) |
| 1263 | { |
| 1264 | struct counter_index *counter, *tmp_count; |
| 1265 | |
| 1266 | mutex_lock(&ctr_table->mutex); |
| 1267 | list_for_each_entry_safe(counter, tmp_count, &ctr_table->counters_list, |
| 1268 | list) { |
| 1269 | if (counter->allocated) |
| 1270 | mlx4_counter_free(ibdev->dev, counter->index); |
| 1271 | list_del(&counter->list); |
| 1272 | kfree(counter); |
| 1273 | } |
| 1274 | mutex_unlock(&ctr_table->mutex); |
| 1275 | } |
| 1276 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1277 | int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp, |
| 1278 | union ib_gid *gid) |
| 1279 | { |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1280 | struct net_device *ndev; |
| 1281 | int ret = 0; |
| 1282 | |
| 1283 | if (!mqp->port) |
| 1284 | return 0; |
| 1285 | |
Jack Morgenstein | dba3ad2 | 2014-08-21 14:28:41 +0300 | [diff] [blame] | 1286 | spin_lock_bh(&mdev->iboe.lock); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1287 | ndev = mdev->iboe.netdevs[mqp->port - 1]; |
| 1288 | if (ndev) |
| 1289 | dev_hold(ndev); |
Jack Morgenstein | dba3ad2 | 2014-08-21 14:28:41 +0300 | [diff] [blame] | 1290 | spin_unlock_bh(&mdev->iboe.lock); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1291 | |
| 1292 | if (ndev) { |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1293 | ret = 1; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1294 | dev_put(ndev); |
| 1295 | } |
| 1296 | |
| 1297 | return ret; |
| 1298 | } |
| 1299 | |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1300 | struct mlx4_ib_steering { |
| 1301 | struct list_head list; |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1302 | struct mlx4_flow_reg_id reg_id; |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1303 | union ib_gid gid; |
| 1304 | }; |
| 1305 | |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1306 | static int parse_flow_attr(struct mlx4_dev *dev, |
Matan Barak | a37a1a4 | 2013-11-07 15:25:16 +0200 | [diff] [blame] | 1307 | u32 qp_num, |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1308 | union ib_flow_spec *ib_spec, |
| 1309 | struct _rule_hw *mlx4_spec) |
| 1310 | { |
| 1311 | enum mlx4_net_trans_rule_id type; |
| 1312 | |
| 1313 | switch (ib_spec->type) { |
| 1314 | case IB_FLOW_SPEC_ETH: |
| 1315 | type = MLX4_NET_TRANS_RULE_ID_ETH; |
| 1316 | memcpy(mlx4_spec->eth.dst_mac, ib_spec->eth.val.dst_mac, |
| 1317 | ETH_ALEN); |
| 1318 | memcpy(mlx4_spec->eth.dst_mac_msk, ib_spec->eth.mask.dst_mac, |
| 1319 | ETH_ALEN); |
| 1320 | mlx4_spec->eth.vlan_tag = ib_spec->eth.val.vlan_tag; |
| 1321 | mlx4_spec->eth.vlan_tag_msk = ib_spec->eth.mask.vlan_tag; |
| 1322 | break; |
Matan Barak | a37a1a4 | 2013-11-07 15:25:16 +0200 | [diff] [blame] | 1323 | case IB_FLOW_SPEC_IB: |
| 1324 | type = MLX4_NET_TRANS_RULE_ID_IB; |
| 1325 | mlx4_spec->ib.l3_qpn = |
| 1326 | cpu_to_be32(qp_num); |
| 1327 | mlx4_spec->ib.qpn_mask = |
| 1328 | cpu_to_be32(MLX4_IB_FLOW_QPN_MASK); |
| 1329 | break; |
| 1330 | |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1331 | |
| 1332 | case IB_FLOW_SPEC_IPV4: |
| 1333 | type = MLX4_NET_TRANS_RULE_ID_IPV4; |
| 1334 | mlx4_spec->ipv4.src_ip = ib_spec->ipv4.val.src_ip; |
| 1335 | mlx4_spec->ipv4.src_ip_msk = ib_spec->ipv4.mask.src_ip; |
| 1336 | mlx4_spec->ipv4.dst_ip = ib_spec->ipv4.val.dst_ip; |
| 1337 | mlx4_spec->ipv4.dst_ip_msk = ib_spec->ipv4.mask.dst_ip; |
| 1338 | break; |
| 1339 | |
| 1340 | case IB_FLOW_SPEC_TCP: |
| 1341 | case IB_FLOW_SPEC_UDP: |
| 1342 | type = ib_spec->type == IB_FLOW_SPEC_TCP ? |
| 1343 | MLX4_NET_TRANS_RULE_ID_TCP : |
| 1344 | MLX4_NET_TRANS_RULE_ID_UDP; |
| 1345 | mlx4_spec->tcp_udp.dst_port = ib_spec->tcp_udp.val.dst_port; |
| 1346 | mlx4_spec->tcp_udp.dst_port_msk = ib_spec->tcp_udp.mask.dst_port; |
| 1347 | mlx4_spec->tcp_udp.src_port = ib_spec->tcp_udp.val.src_port; |
| 1348 | mlx4_spec->tcp_udp.src_port_msk = ib_spec->tcp_udp.mask.src_port; |
| 1349 | break; |
| 1350 | |
| 1351 | default: |
| 1352 | return -EINVAL; |
| 1353 | } |
| 1354 | if (mlx4_map_sw_to_hw_steering_id(dev, type) < 0 || |
| 1355 | mlx4_hw_rule_sz(dev, type) < 0) |
| 1356 | return -EINVAL; |
| 1357 | mlx4_spec->id = cpu_to_be16(mlx4_map_sw_to_hw_steering_id(dev, type)); |
| 1358 | mlx4_spec->size = mlx4_hw_rule_sz(dev, type) >> 2; |
| 1359 | return mlx4_hw_rule_sz(dev, type); |
| 1360 | } |
| 1361 | |
Matan Barak | a37a1a4 | 2013-11-07 15:25:16 +0200 | [diff] [blame] | 1362 | struct default_rules { |
| 1363 | __u32 mandatory_fields[IB_FLOW_SPEC_SUPPORT_LAYERS]; |
| 1364 | __u32 mandatory_not_fields[IB_FLOW_SPEC_SUPPORT_LAYERS]; |
| 1365 | __u32 rules_create_list[IB_FLOW_SPEC_SUPPORT_LAYERS]; |
| 1366 | __u8 link_layer; |
| 1367 | }; |
| 1368 | static const struct default_rules default_table[] = { |
| 1369 | { |
| 1370 | .mandatory_fields = {IB_FLOW_SPEC_IPV4}, |
| 1371 | .mandatory_not_fields = {IB_FLOW_SPEC_ETH}, |
| 1372 | .rules_create_list = {IB_FLOW_SPEC_IB}, |
| 1373 | .link_layer = IB_LINK_LAYER_INFINIBAND |
| 1374 | } |
| 1375 | }; |
| 1376 | |
| 1377 | static int __mlx4_ib_default_rules_match(struct ib_qp *qp, |
| 1378 | struct ib_flow_attr *flow_attr) |
| 1379 | { |
| 1380 | int i, j, k; |
| 1381 | void *ib_flow; |
| 1382 | const struct default_rules *pdefault_rules = default_table; |
| 1383 | u8 link_layer = rdma_port_get_link_layer(qp->device, flow_attr->port); |
| 1384 | |
Fabian Frederick | a57f23f | 2014-08-12 19:20:07 -0400 | [diff] [blame] | 1385 | for (i = 0; i < ARRAY_SIZE(default_table); i++, pdefault_rules++) { |
Matan Barak | a37a1a4 | 2013-11-07 15:25:16 +0200 | [diff] [blame] | 1386 | __u32 field_types[IB_FLOW_SPEC_SUPPORT_LAYERS]; |
| 1387 | memset(&field_types, 0, sizeof(field_types)); |
| 1388 | |
| 1389 | if (link_layer != pdefault_rules->link_layer) |
| 1390 | continue; |
| 1391 | |
| 1392 | ib_flow = flow_attr + 1; |
| 1393 | /* we assume the specs are sorted */ |
| 1394 | for (j = 0, k = 0; k < IB_FLOW_SPEC_SUPPORT_LAYERS && |
| 1395 | j < flow_attr->num_of_specs; k++) { |
| 1396 | union ib_flow_spec *current_flow = |
| 1397 | (union ib_flow_spec *)ib_flow; |
| 1398 | |
| 1399 | /* same layer but different type */ |
| 1400 | if (((current_flow->type & IB_FLOW_SPEC_LAYER_MASK) == |
| 1401 | (pdefault_rules->mandatory_fields[k] & |
| 1402 | IB_FLOW_SPEC_LAYER_MASK)) && |
| 1403 | (current_flow->type != |
| 1404 | pdefault_rules->mandatory_fields[k])) |
| 1405 | goto out; |
| 1406 | |
| 1407 | /* same layer, try match next one */ |
| 1408 | if (current_flow->type == |
| 1409 | pdefault_rules->mandatory_fields[k]) { |
| 1410 | j++; |
| 1411 | ib_flow += |
| 1412 | ((union ib_flow_spec *)ib_flow)->size; |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | ib_flow = flow_attr + 1; |
| 1417 | for (j = 0; j < flow_attr->num_of_specs; |
| 1418 | j++, ib_flow += ((union ib_flow_spec *)ib_flow)->size) |
| 1419 | for (k = 0; k < IB_FLOW_SPEC_SUPPORT_LAYERS; k++) |
| 1420 | /* same layer and same type */ |
| 1421 | if (((union ib_flow_spec *)ib_flow)->type == |
| 1422 | pdefault_rules->mandatory_not_fields[k]) |
| 1423 | goto out; |
| 1424 | |
| 1425 | return i; |
| 1426 | } |
| 1427 | out: |
| 1428 | return -1; |
| 1429 | } |
| 1430 | |
| 1431 | static int __mlx4_ib_create_default_rules( |
| 1432 | struct mlx4_ib_dev *mdev, |
| 1433 | struct ib_qp *qp, |
| 1434 | const struct default_rules *pdefault_rules, |
| 1435 | struct _rule_hw *mlx4_spec) { |
| 1436 | int size = 0; |
| 1437 | int i; |
| 1438 | |
Fabian Frederick | a57f23f | 2014-08-12 19:20:07 -0400 | [diff] [blame] | 1439 | for (i = 0; i < ARRAY_SIZE(pdefault_rules->rules_create_list); i++) { |
Matan Barak | a37a1a4 | 2013-11-07 15:25:16 +0200 | [diff] [blame] | 1440 | int ret; |
| 1441 | union ib_flow_spec ib_spec; |
| 1442 | switch (pdefault_rules->rules_create_list[i]) { |
| 1443 | case 0: |
| 1444 | /* no rule */ |
| 1445 | continue; |
| 1446 | case IB_FLOW_SPEC_IB: |
| 1447 | ib_spec.type = IB_FLOW_SPEC_IB; |
| 1448 | ib_spec.size = sizeof(struct ib_flow_spec_ib); |
| 1449 | |
| 1450 | break; |
| 1451 | default: |
| 1452 | /* invalid rule */ |
| 1453 | return -EINVAL; |
| 1454 | } |
| 1455 | /* We must put empty rule, qpn is being ignored */ |
| 1456 | ret = parse_flow_attr(mdev->dev, 0, &ib_spec, |
| 1457 | mlx4_spec); |
| 1458 | if (ret < 0) { |
| 1459 | pr_info("invalid parsing\n"); |
| 1460 | return -EINVAL; |
| 1461 | } |
| 1462 | |
| 1463 | mlx4_spec = (void *)mlx4_spec + ret; |
| 1464 | size += ret; |
| 1465 | } |
| 1466 | return size; |
| 1467 | } |
| 1468 | |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1469 | static int __mlx4_ib_create_flow(struct ib_qp *qp, struct ib_flow_attr *flow_attr, |
| 1470 | int domain, |
| 1471 | enum mlx4_net_trans_promisc_mode flow_type, |
| 1472 | u64 *reg_id) |
| 1473 | { |
| 1474 | int ret, i; |
| 1475 | int size = 0; |
| 1476 | void *ib_flow; |
| 1477 | struct mlx4_ib_dev *mdev = to_mdev(qp->device); |
| 1478 | struct mlx4_cmd_mailbox *mailbox; |
| 1479 | struct mlx4_net_trans_rule_hw_ctrl *ctrl; |
Matan Barak | a37a1a4 | 2013-11-07 15:25:16 +0200 | [diff] [blame] | 1480 | int default_flow; |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1481 | |
| 1482 | static const u16 __mlx4_domain[] = { |
| 1483 | [IB_FLOW_DOMAIN_USER] = MLX4_DOMAIN_UVERBS, |
| 1484 | [IB_FLOW_DOMAIN_ETHTOOL] = MLX4_DOMAIN_ETHTOOL, |
| 1485 | [IB_FLOW_DOMAIN_RFS] = MLX4_DOMAIN_RFS, |
| 1486 | [IB_FLOW_DOMAIN_NIC] = MLX4_DOMAIN_NIC, |
| 1487 | }; |
| 1488 | |
| 1489 | if (flow_attr->priority > MLX4_IB_FLOW_MAX_PRIO) { |
| 1490 | pr_err("Invalid priority value %d\n", flow_attr->priority); |
| 1491 | return -EINVAL; |
| 1492 | } |
| 1493 | |
| 1494 | if (domain >= IB_FLOW_DOMAIN_NUM) { |
| 1495 | pr_err("Invalid domain value %d\n", domain); |
| 1496 | return -EINVAL; |
| 1497 | } |
| 1498 | |
| 1499 | if (mlx4_map_sw_to_hw_steering_mode(mdev->dev, flow_type) < 0) |
| 1500 | return -EINVAL; |
| 1501 | |
| 1502 | mailbox = mlx4_alloc_cmd_mailbox(mdev->dev); |
| 1503 | if (IS_ERR(mailbox)) |
| 1504 | return PTR_ERR(mailbox); |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1505 | ctrl = mailbox->buf; |
| 1506 | |
| 1507 | ctrl->prio = cpu_to_be16(__mlx4_domain[domain] | |
| 1508 | flow_attr->priority); |
| 1509 | ctrl->type = mlx4_map_sw_to_hw_steering_mode(mdev->dev, flow_type); |
| 1510 | ctrl->port = flow_attr->port; |
| 1511 | ctrl->qpn = cpu_to_be32(qp->qp_num); |
| 1512 | |
| 1513 | ib_flow = flow_attr + 1; |
| 1514 | size += sizeof(struct mlx4_net_trans_rule_hw_ctrl); |
Matan Barak | a37a1a4 | 2013-11-07 15:25:16 +0200 | [diff] [blame] | 1515 | /* Add default flows */ |
| 1516 | default_flow = __mlx4_ib_default_rules_match(qp, flow_attr); |
| 1517 | if (default_flow >= 0) { |
| 1518 | ret = __mlx4_ib_create_default_rules( |
| 1519 | mdev, qp, default_table + default_flow, |
| 1520 | mailbox->buf + size); |
| 1521 | if (ret < 0) { |
| 1522 | mlx4_free_cmd_mailbox(mdev->dev, mailbox); |
| 1523 | return -EINVAL; |
| 1524 | } |
| 1525 | size += ret; |
| 1526 | } |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1527 | for (i = 0; i < flow_attr->num_of_specs; i++) { |
Matan Barak | a37a1a4 | 2013-11-07 15:25:16 +0200 | [diff] [blame] | 1528 | ret = parse_flow_attr(mdev->dev, qp->qp_num, ib_flow, |
| 1529 | mailbox->buf + size); |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1530 | if (ret < 0) { |
| 1531 | mlx4_free_cmd_mailbox(mdev->dev, mailbox); |
| 1532 | return -EINVAL; |
| 1533 | } |
| 1534 | ib_flow += ((union ib_flow_spec *) ib_flow)->size; |
| 1535 | size += ret; |
| 1536 | } |
| 1537 | |
| 1538 | ret = mlx4_cmd_imm(mdev->dev, mailbox->dma, reg_id, size >> 2, 0, |
| 1539 | MLX4_QP_FLOW_STEERING_ATTACH, MLX4_CMD_TIME_CLASS_A, |
Matan Barak | 4856413 | 2015-05-31 09:30:15 +0300 | [diff] [blame] | 1540 | MLX4_CMD_WRAPPED); |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1541 | if (ret == -ENOMEM) |
| 1542 | pr_err("mcg table is full. Fail to register network rule.\n"); |
| 1543 | else if (ret == -ENXIO) |
| 1544 | pr_err("Device managed flow steering is disabled. Fail to register network rule.\n"); |
| 1545 | else if (ret) |
| 1546 | pr_err("Invalid argumant. Fail to register network rule.\n"); |
| 1547 | |
| 1548 | mlx4_free_cmd_mailbox(mdev->dev, mailbox); |
| 1549 | return ret; |
| 1550 | } |
| 1551 | |
| 1552 | static int __mlx4_ib_destroy_flow(struct mlx4_dev *dev, u64 reg_id) |
| 1553 | { |
| 1554 | int err; |
| 1555 | err = mlx4_cmd(dev, reg_id, 0, 0, |
| 1556 | MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A, |
Matan Barak | 4856413 | 2015-05-31 09:30:15 +0300 | [diff] [blame] | 1557 | MLX4_CMD_WRAPPED); |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1558 | if (err) |
| 1559 | pr_err("Fail to detach network rule. registration id = 0x%llx\n", |
| 1560 | reg_id); |
| 1561 | return err; |
| 1562 | } |
| 1563 | |
Or Gerlitz | d2fce8a | 2014-08-27 16:47:49 +0300 | [diff] [blame] | 1564 | static int mlx4_ib_tunnel_steer_add(struct ib_qp *qp, struct ib_flow_attr *flow_attr, |
| 1565 | u64 *reg_id) |
| 1566 | { |
| 1567 | void *ib_flow; |
| 1568 | union ib_flow_spec *ib_spec; |
| 1569 | struct mlx4_dev *dev = to_mdev(qp->device)->dev; |
| 1570 | int err = 0; |
| 1571 | |
Or Gerlitz | 5eff6da | 2015-01-15 15:28:54 +0200 | [diff] [blame] | 1572 | if (dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN || |
| 1573 | dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_STATIC) |
Or Gerlitz | d2fce8a | 2014-08-27 16:47:49 +0300 | [diff] [blame] | 1574 | return 0; /* do nothing */ |
| 1575 | |
| 1576 | ib_flow = flow_attr + 1; |
| 1577 | ib_spec = (union ib_flow_spec *)ib_flow; |
| 1578 | |
| 1579 | if (ib_spec->type != IB_FLOW_SPEC_ETH || flow_attr->num_of_specs != 1) |
| 1580 | return 0; /* do nothing */ |
| 1581 | |
| 1582 | err = mlx4_tunnel_steer_add(to_mdev(qp->device)->dev, ib_spec->eth.val.dst_mac, |
| 1583 | flow_attr->port, qp->qp_num, |
| 1584 | MLX4_DOMAIN_UVERBS | (flow_attr->priority & 0xff), |
| 1585 | reg_id); |
| 1586 | return err; |
| 1587 | } |
| 1588 | |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1589 | static struct ib_flow *mlx4_ib_create_flow(struct ib_qp *qp, |
| 1590 | struct ib_flow_attr *flow_attr, |
| 1591 | int domain) |
| 1592 | { |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1593 | int err = 0, i = 0, j = 0; |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1594 | struct mlx4_ib_flow *mflow; |
| 1595 | enum mlx4_net_trans_promisc_mode type[2]; |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1596 | struct mlx4_dev *dev = (to_mdev(qp->device))->dev; |
| 1597 | int is_bonded = mlx4_is_bonded(dev); |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1598 | |
| 1599 | memset(type, 0, sizeof(type)); |
| 1600 | |
| 1601 | mflow = kzalloc(sizeof(*mflow), GFP_KERNEL); |
| 1602 | if (!mflow) { |
| 1603 | err = -ENOMEM; |
| 1604 | goto err_free; |
| 1605 | } |
| 1606 | |
| 1607 | switch (flow_attr->type) { |
| 1608 | case IB_FLOW_ATTR_NORMAL: |
| 1609 | type[0] = MLX4_FS_REGULAR; |
| 1610 | break; |
| 1611 | |
| 1612 | case IB_FLOW_ATTR_ALL_DEFAULT: |
| 1613 | type[0] = MLX4_FS_ALL_DEFAULT; |
| 1614 | break; |
| 1615 | |
| 1616 | case IB_FLOW_ATTR_MC_DEFAULT: |
| 1617 | type[0] = MLX4_FS_MC_DEFAULT; |
| 1618 | break; |
| 1619 | |
| 1620 | case IB_FLOW_ATTR_SNIFFER: |
| 1621 | type[0] = MLX4_FS_UC_SNIFFER; |
| 1622 | type[1] = MLX4_FS_MC_SNIFFER; |
| 1623 | break; |
| 1624 | |
| 1625 | default: |
| 1626 | err = -EINVAL; |
| 1627 | goto err_free; |
| 1628 | } |
| 1629 | |
| 1630 | while (i < ARRAY_SIZE(type) && type[i]) { |
| 1631 | err = __mlx4_ib_create_flow(qp, flow_attr, domain, type[i], |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1632 | &mflow->reg_id[i].id); |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1633 | if (err) |
Or Gerlitz | 571e1b2 | 2014-10-30 15:59:28 +0200 | [diff] [blame] | 1634 | goto err_create_flow; |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1635 | if (is_bonded) { |
Moni Shoua | 824c25c | 2015-02-08 11:49:33 +0200 | [diff] [blame] | 1636 | /* Application always sees one port so the mirror rule |
| 1637 | * must be on port #2 |
| 1638 | */ |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1639 | flow_attr->port = 2; |
| 1640 | err = __mlx4_ib_create_flow(qp, flow_attr, |
| 1641 | domain, type[j], |
| 1642 | &mflow->reg_id[j].mirror); |
| 1643 | flow_attr->port = 1; |
| 1644 | if (err) |
| 1645 | goto err_create_flow; |
| 1646 | j++; |
| 1647 | } |
| 1648 | |
Roland Dreier | 1156256 | 2015-05-29 23:11:27 -0700 | [diff] [blame] | 1649 | i++; |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1650 | } |
| 1651 | |
Or Gerlitz | d2fce8a | 2014-08-27 16:47:49 +0300 | [diff] [blame] | 1652 | if (i < ARRAY_SIZE(type) && flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1653 | err = mlx4_ib_tunnel_steer_add(qp, flow_attr, |
| 1654 | &mflow->reg_id[i].id); |
Or Gerlitz | d2fce8a | 2014-08-27 16:47:49 +0300 | [diff] [blame] | 1655 | if (err) |
Or Gerlitz | 571e1b2 | 2014-10-30 15:59:28 +0200 | [diff] [blame] | 1656 | goto err_create_flow; |
Roland Dreier | 1156256 | 2015-05-29 23:11:27 -0700 | [diff] [blame] | 1657 | |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1658 | if (is_bonded) { |
| 1659 | flow_attr->port = 2; |
| 1660 | err = mlx4_ib_tunnel_steer_add(qp, flow_attr, |
| 1661 | &mflow->reg_id[j].mirror); |
| 1662 | flow_attr->port = 1; |
| 1663 | if (err) |
| 1664 | goto err_create_flow; |
| 1665 | j++; |
| 1666 | } |
| 1667 | /* function to create mirror rule */ |
Roland Dreier | 1156256 | 2015-05-29 23:11:27 -0700 | [diff] [blame] | 1668 | i++; |
Or Gerlitz | d2fce8a | 2014-08-27 16:47:49 +0300 | [diff] [blame] | 1669 | } |
| 1670 | |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1671 | return &mflow->ibflow; |
| 1672 | |
Or Gerlitz | 571e1b2 | 2014-10-30 15:59:28 +0200 | [diff] [blame] | 1673 | err_create_flow: |
| 1674 | while (i) { |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1675 | (void)__mlx4_ib_destroy_flow(to_mdev(qp->device)->dev, |
| 1676 | mflow->reg_id[i].id); |
Or Gerlitz | 571e1b2 | 2014-10-30 15:59:28 +0200 | [diff] [blame] | 1677 | i--; |
| 1678 | } |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1679 | |
| 1680 | while (j) { |
| 1681 | (void)__mlx4_ib_destroy_flow(to_mdev(qp->device)->dev, |
| 1682 | mflow->reg_id[j].mirror); |
| 1683 | j--; |
| 1684 | } |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1685 | err_free: |
| 1686 | kfree(mflow); |
| 1687 | return ERR_PTR(err); |
| 1688 | } |
| 1689 | |
| 1690 | static int mlx4_ib_destroy_flow(struct ib_flow *flow_id) |
| 1691 | { |
| 1692 | int err, ret = 0; |
| 1693 | int i = 0; |
| 1694 | struct mlx4_ib_dev *mdev = to_mdev(flow_id->qp->device); |
| 1695 | struct mlx4_ib_flow *mflow = to_mflow(flow_id); |
| 1696 | |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1697 | while (i < ARRAY_SIZE(mflow->reg_id) && mflow->reg_id[i].id) { |
| 1698 | err = __mlx4_ib_destroy_flow(mdev->dev, mflow->reg_id[i].id); |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1699 | if (err) |
| 1700 | ret = err; |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1701 | if (mflow->reg_id[i].mirror) { |
| 1702 | err = __mlx4_ib_destroy_flow(mdev->dev, |
| 1703 | mflow->reg_id[i].mirror); |
| 1704 | if (err) |
| 1705 | ret = err; |
| 1706 | } |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 1707 | i++; |
| 1708 | } |
| 1709 | |
| 1710 | kfree(mflow); |
| 1711 | return ret; |
| 1712 | } |
| 1713 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1714 | static int mlx4_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 1715 | { |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1716 | int err; |
| 1717 | struct mlx4_ib_dev *mdev = to_mdev(ibqp->device); |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1718 | struct mlx4_dev *dev = mdev->dev; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1719 | struct mlx4_ib_qp *mqp = to_mqp(ibqp); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1720 | struct mlx4_ib_steering *ib_steering = NULL; |
Or Gerlitz | e9a7faf | 2014-12-17 16:17:34 +0200 | [diff] [blame] | 1721 | enum mlx4_protocol prot = MLX4_PROT_IB_IPV6; |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1722 | struct mlx4_flow_reg_id reg_id; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1723 | |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1724 | if (mdev->dev->caps.steering_mode == |
| 1725 | MLX4_STEERING_MODE_DEVICE_MANAGED) { |
| 1726 | ib_steering = kmalloc(sizeof(*ib_steering), GFP_KERNEL); |
| 1727 | if (!ib_steering) |
| 1728 | return -ENOMEM; |
| 1729 | } |
| 1730 | |
| 1731 | err = mlx4_multicast_attach(mdev->dev, &mqp->mqp, gid->raw, mqp->port, |
| 1732 | !!(mqp->flags & |
| 1733 | MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK), |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1734 | prot, ®_id.id); |
Or Gerlitz | e9a7faf | 2014-12-17 16:17:34 +0200 | [diff] [blame] | 1735 | if (err) { |
| 1736 | pr_err("multicast attach op failed, err %d\n", err); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1737 | goto err_malloc; |
Or Gerlitz | e9a7faf | 2014-12-17 16:17:34 +0200 | [diff] [blame] | 1738 | } |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1739 | |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1740 | reg_id.mirror = 0; |
| 1741 | if (mlx4_is_bonded(dev)) { |
Moni Shoua | 824c25c | 2015-02-08 11:49:33 +0200 | [diff] [blame] | 1742 | err = mlx4_multicast_attach(mdev->dev, &mqp->mqp, gid->raw, |
| 1743 | (mqp->port == 1) ? 2 : 1, |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1744 | !!(mqp->flags & |
| 1745 | MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK), |
| 1746 | prot, ®_id.mirror); |
| 1747 | if (err) |
| 1748 | goto err_add; |
| 1749 | } |
| 1750 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1751 | err = add_gid_entry(ibqp, gid); |
| 1752 | if (err) |
| 1753 | goto err_add; |
| 1754 | |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1755 | if (ib_steering) { |
| 1756 | memcpy(ib_steering->gid.raw, gid->raw, 16); |
| 1757 | ib_steering->reg_id = reg_id; |
| 1758 | mutex_lock(&mqp->mutex); |
| 1759 | list_add(&ib_steering->list, &mqp->steering_rules); |
| 1760 | mutex_unlock(&mqp->mutex); |
| 1761 | } |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1762 | return 0; |
| 1763 | |
| 1764 | err_add: |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1765 | mlx4_multicast_detach(mdev->dev, &mqp->mqp, gid->raw, |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1766 | prot, reg_id.id); |
| 1767 | if (reg_id.mirror) |
| 1768 | mlx4_multicast_detach(mdev->dev, &mqp->mqp, gid->raw, |
| 1769 | prot, reg_id.mirror); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1770 | err_malloc: |
| 1771 | kfree(ib_steering); |
| 1772 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1773 | return err; |
| 1774 | } |
| 1775 | |
| 1776 | static struct mlx4_ib_gid_entry *find_gid_entry(struct mlx4_ib_qp *qp, u8 *raw) |
| 1777 | { |
| 1778 | struct mlx4_ib_gid_entry *ge; |
| 1779 | struct mlx4_ib_gid_entry *tmp; |
| 1780 | struct mlx4_ib_gid_entry *ret = NULL; |
| 1781 | |
| 1782 | list_for_each_entry_safe(ge, tmp, &qp->gid_list, list) { |
| 1783 | if (!memcmp(raw, ge->gid.raw, 16)) { |
| 1784 | ret = ge; |
| 1785 | break; |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | return ret; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 1793 | { |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1794 | int err; |
| 1795 | struct mlx4_ib_dev *mdev = to_mdev(ibqp->device); |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1796 | struct mlx4_dev *dev = mdev->dev; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1797 | struct mlx4_ib_qp *mqp = to_mqp(ibqp); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1798 | struct net_device *ndev; |
| 1799 | struct mlx4_ib_gid_entry *ge; |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1800 | struct mlx4_flow_reg_id reg_id = {0, 0}; |
Or Gerlitz | e9a7faf | 2014-12-17 16:17:34 +0200 | [diff] [blame] | 1801 | enum mlx4_protocol prot = MLX4_PROT_IB_IPV6; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1802 | |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1803 | if (mdev->dev->caps.steering_mode == |
| 1804 | MLX4_STEERING_MODE_DEVICE_MANAGED) { |
| 1805 | struct mlx4_ib_steering *ib_steering; |
| 1806 | |
| 1807 | mutex_lock(&mqp->mutex); |
| 1808 | list_for_each_entry(ib_steering, &mqp->steering_rules, list) { |
| 1809 | if (!memcmp(ib_steering->gid.raw, gid->raw, 16)) { |
| 1810 | list_del(&ib_steering->list); |
| 1811 | break; |
| 1812 | } |
| 1813 | } |
| 1814 | mutex_unlock(&mqp->mutex); |
| 1815 | if (&ib_steering->list == &mqp->steering_rules) { |
| 1816 | pr_err("Couldn't find reg_id for mgid. Steering rule is left attached\n"); |
| 1817 | return -EINVAL; |
| 1818 | } |
| 1819 | reg_id = ib_steering->reg_id; |
| 1820 | kfree(ib_steering); |
| 1821 | } |
| 1822 | |
| 1823 | err = mlx4_multicast_detach(mdev->dev, &mqp->mqp, gid->raw, |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1824 | prot, reg_id.id); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1825 | if (err) |
| 1826 | return err; |
| 1827 | |
Moni Shoua | 146d6e1 | 2015-02-03 16:48:38 +0200 | [diff] [blame] | 1828 | if (mlx4_is_bonded(dev)) { |
| 1829 | err = mlx4_multicast_detach(mdev->dev, &mqp->mqp, gid->raw, |
| 1830 | prot, reg_id.mirror); |
| 1831 | if (err) |
| 1832 | return err; |
| 1833 | } |
| 1834 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1835 | mutex_lock(&mqp->mutex); |
| 1836 | ge = find_gid_entry(mqp, gid->raw); |
| 1837 | if (ge) { |
Jack Morgenstein | dba3ad2 | 2014-08-21 14:28:41 +0300 | [diff] [blame] | 1838 | spin_lock_bh(&mdev->iboe.lock); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1839 | ndev = ge->added ? mdev->iboe.netdevs[ge->port - 1] : NULL; |
| 1840 | if (ndev) |
| 1841 | dev_hold(ndev); |
Jack Morgenstein | dba3ad2 | 2014-08-21 14:28:41 +0300 | [diff] [blame] | 1842 | spin_unlock_bh(&mdev->iboe.lock); |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 1843 | if (ndev) |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1844 | dev_put(ndev); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1845 | list_del(&ge->list); |
| 1846 | kfree(ge); |
| 1847 | } else |
Shlomo Pongratz | 987c8f8 | 2012-04-29 17:04:26 +0300 | [diff] [blame] | 1848 | pr_warn("could not find mgid entry\n"); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 1849 | |
| 1850 | mutex_unlock(&mqp->mutex); |
| 1851 | |
| 1852 | return 0; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | static int init_node_data(struct mlx4_ib_dev *dev) |
| 1856 | { |
| 1857 | struct ib_smp *in_mad = NULL; |
| 1858 | struct ib_smp *out_mad = NULL; |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 1859 | int mad_ifc_flags = MLX4_MAD_IFC_IGNORE_KEYS; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1860 | int err = -ENOMEM; |
| 1861 | |
| 1862 | in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); |
| 1863 | out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); |
| 1864 | if (!in_mad || !out_mad) |
| 1865 | goto out; |
| 1866 | |
| 1867 | init_query_mad(in_mad); |
| 1868 | in_mad->attr_id = IB_SMP_ATTR_NODE_DESC; |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 1869 | if (mlx4_is_master(dev->dev)) |
| 1870 | mad_ifc_flags |= MLX4_MAD_IFC_NET_VIEW; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1871 | |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 1872 | err = mlx4_MAD_IFC(dev, mad_ifc_flags, 1, NULL, NULL, in_mad, out_mad); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1873 | if (err) |
| 1874 | goto out; |
| 1875 | |
| 1876 | memcpy(dev->ib_dev.node_desc, out_mad->data, 64); |
| 1877 | |
| 1878 | in_mad->attr_id = IB_SMP_ATTR_NODE_INFO; |
| 1879 | |
Jack Morgenstein | 0a9a018 | 2012-08-03 08:40:45 +0000 | [diff] [blame] | 1880 | err = mlx4_MAD_IFC(dev, mad_ifc_flags, 1, NULL, NULL, in_mad, out_mad); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1881 | if (err) |
| 1882 | goto out; |
| 1883 | |
Jack Morgenstein | 992e8e6e | 2012-08-03 08:40:54 +0000 | [diff] [blame] | 1884 | dev->dev->rev_id = be32_to_cpup((__be32 *) (out_mad->data + 32)); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1885 | memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8); |
| 1886 | |
| 1887 | out: |
| 1888 | kfree(in_mad); |
| 1889 | kfree(out_mad); |
| 1890 | return err; |
| 1891 | } |
| 1892 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1893 | static ssize_t show_hca(struct device *device, struct device_attribute *attr, |
| 1894 | char *buf) |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1895 | { |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1896 | struct mlx4_ib_dev *dev = |
| 1897 | container_of(device, struct mlx4_ib_dev, ib_dev.dev); |
Yishai Hadas | 872bf2f | 2015-01-25 16:59:35 +0200 | [diff] [blame] | 1898 | return sprintf(buf, "MT%d\n", dev->dev->persist->pdev->device); |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1899 | } |
| 1900 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1901 | static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr, |
| 1902 | char *buf) |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1903 | { |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1904 | struct mlx4_ib_dev *dev = |
| 1905 | container_of(device, struct mlx4_ib_dev, ib_dev.dev); |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1906 | return sprintf(buf, "%d.%d.%d\n", (int) (dev->dev->caps.fw_ver >> 32), |
| 1907 | (int) (dev->dev->caps.fw_ver >> 16) & 0xffff, |
| 1908 | (int) dev->dev->caps.fw_ver & 0xffff); |
| 1909 | } |
| 1910 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1911 | static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
| 1912 | char *buf) |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1913 | { |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1914 | struct mlx4_ib_dev *dev = |
| 1915 | container_of(device, struct mlx4_ib_dev, ib_dev.dev); |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1916 | return sprintf(buf, "%x\n", dev->dev->rev_id); |
| 1917 | } |
| 1918 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1919 | static ssize_t show_board(struct device *device, struct device_attribute *attr, |
| 1920 | char *buf) |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1921 | { |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1922 | struct mlx4_ib_dev *dev = |
| 1923 | container_of(device, struct mlx4_ib_dev, ib_dev.dev); |
| 1924 | return sprintf(buf, "%.*s\n", MLX4_BOARD_ID_LEN, |
| 1925 | dev->dev->board_id); |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1926 | } |
| 1927 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1928 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
| 1929 | static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL); |
| 1930 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 1931 | static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1932 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1933 | static struct device_attribute *mlx4_class_attributes[] = { |
| 1934 | &dev_attr_hw_rev, |
| 1935 | &dev_attr_fw_ver, |
| 1936 | &dev_attr_hca_type, |
| 1937 | &dev_attr_board_id |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1938 | }; |
| 1939 | |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1940 | #define MLX4_IB_INVALID_MAC ((u64)-1) |
| 1941 | static void mlx4_ib_update_qps(struct mlx4_ib_dev *ibdev, |
| 1942 | struct net_device *dev, |
| 1943 | int port) |
| 1944 | { |
| 1945 | u64 new_smac = 0; |
| 1946 | u64 release_mac = MLX4_IB_INVALID_MAC; |
| 1947 | struct mlx4_ib_qp *qp; |
| 1948 | |
| 1949 | read_lock(&dev_base_lock); |
| 1950 | new_smac = mlx4_mac_to_u64(dev->dev_addr); |
| 1951 | read_unlock(&dev_base_lock); |
| 1952 | |
Jack Morgenstein | 3e0629c | 2014-09-11 14:11:17 +0300 | [diff] [blame] | 1953 | atomic64_set(&ibdev->iboe.mac[port - 1], new_smac); |
| 1954 | |
Jack Morgenstein | d24d9f4 | 2014-09-11 14:11:18 +0300 | [diff] [blame] | 1955 | /* no need for update QP1 and mac registration in non-SRIOV */ |
| 1956 | if (!mlx4_is_mfunc(ibdev->dev)) |
| 1957 | return; |
| 1958 | |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1959 | mutex_lock(&ibdev->qp1_proxy_lock[port - 1]); |
| 1960 | qp = ibdev->qp1_proxy[port - 1]; |
| 1961 | if (qp) { |
| 1962 | int new_smac_index; |
Jack Morgenstein | 25476b0 | 2014-09-11 14:11:20 +0300 | [diff] [blame] | 1963 | u64 old_smac; |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1964 | struct mlx4_update_qp_params update_params; |
| 1965 | |
Jack Morgenstein | 25476b0 | 2014-09-11 14:11:20 +0300 | [diff] [blame] | 1966 | mutex_lock(&qp->mutex); |
| 1967 | old_smac = qp->pri.smac; |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1968 | if (new_smac == old_smac) |
| 1969 | goto unlock; |
| 1970 | |
| 1971 | new_smac_index = mlx4_register_mac(ibdev->dev, port, new_smac); |
| 1972 | |
| 1973 | if (new_smac_index < 0) |
| 1974 | goto unlock; |
| 1975 | |
| 1976 | update_params.smac_index = new_smac_index; |
Matan Barak | 09e05c3 | 2014-09-10 16:41:56 +0300 | [diff] [blame] | 1977 | if (mlx4_update_qp(ibdev->dev, qp->mqp.qpn, MLX4_UPDATE_QP_SMAC, |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1978 | &update_params)) { |
| 1979 | release_mac = new_smac; |
| 1980 | goto unlock; |
| 1981 | } |
Jack Morgenstein | 25476b0 | 2014-09-11 14:11:20 +0300 | [diff] [blame] | 1982 | /* if old port was zero, no mac was yet registered for this QP */ |
| 1983 | if (qp->pri.smac_port) |
| 1984 | release_mac = old_smac; |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1985 | qp->pri.smac = new_smac; |
Jack Morgenstein | 25476b0 | 2014-09-11 14:11:20 +0300 | [diff] [blame] | 1986 | qp->pri.smac_port = port; |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1987 | qp->pri.smac_index = new_smac_index; |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | unlock: |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1991 | if (release_mac != MLX4_IB_INVALID_MAC) |
| 1992 | mlx4_unregister_mac(ibdev->dev, port, release_mac); |
Jack Morgenstein | 25476b0 | 2014-09-11 14:11:20 +0300 | [diff] [blame] | 1993 | if (qp) |
| 1994 | mutex_unlock(&qp->mutex); |
| 1995 | mutex_unlock(&ibdev->qp1_proxy_lock[port - 1]); |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1996 | } |
| 1997 | |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 1998 | static void mlx4_ib_scan_netdevs(struct mlx4_ib_dev *ibdev, |
| 1999 | struct net_device *dev, |
| 2000 | unsigned long event) |
| 2001 | |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 2002 | { |
| 2003 | struct mlx4_ib_iboe *iboe; |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 2004 | int update_qps_port = -1; |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 2005 | int port; |
| 2006 | |
Moni Shoua | 5070cd2 | 2015-07-30 18:33:30 +0300 | [diff] [blame] | 2007 | ASSERT_RTNL(); |
| 2008 | |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 2009 | iboe = &ibdev->iboe; |
| 2010 | |
Jack Morgenstein | dba3ad2 | 2014-08-21 14:28:41 +0300 | [diff] [blame] | 2011 | spin_lock_bh(&iboe->lock); |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 2012 | mlx4_foreach_ib_transport_port(port, ibdev->dev) { |
Moni Shoua | ad4885d2 | 2014-02-05 15:13:02 +0200 | [diff] [blame] | 2013 | |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 2014 | iboe->netdevs[port - 1] = |
| 2015 | mlx4_get_protocol_dev(ibdev->dev, MLX4_PROT_ETH, port); |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 2016 | |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 2017 | if (dev == iboe->netdevs[port - 1] && |
| 2018 | (event == NETDEV_CHANGEADDR || event == NETDEV_REGISTER || |
| 2019 | event == NETDEV_UP || event == NETDEV_CHANGE)) |
| 2020 | update_qps_port = port; |
| 2021 | |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 2022 | } |
Jack Morgenstein | dba3ad2 | 2014-08-21 14:28:41 +0300 | [diff] [blame] | 2023 | spin_unlock_bh(&iboe->lock); |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 2024 | |
| 2025 | if (update_qps_port > 0) |
| 2026 | mlx4_ib_update_qps(ibdev, dev, update_qps_port); |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | static int mlx4_ib_netdev_event(struct notifier_block *this, |
| 2030 | unsigned long event, void *ptr) |
| 2031 | { |
Jiri Pirko | 351638e | 2013-05-28 01:30:21 +0000 | [diff] [blame] | 2032 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2033 | struct mlx4_ib_dev *ibdev; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2034 | |
| 2035 | if (!net_eq(dev_net(dev), &init_net)) |
| 2036 | return NOTIFY_DONE; |
| 2037 | |
| 2038 | ibdev = container_of(this, struct mlx4_ib_dev, iboe.nb); |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 2039 | mlx4_ib_scan_netdevs(ibdev, dev, event); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2040 | |
| 2041 | return NOTIFY_DONE; |
| 2042 | } |
| 2043 | |
Jack Morgenstein | 54679e1 | 2012-08-03 08:40:43 +0000 | [diff] [blame] | 2044 | static void init_pkeys(struct mlx4_ib_dev *ibdev) |
| 2045 | { |
| 2046 | int port; |
| 2047 | int slave; |
| 2048 | int i; |
| 2049 | |
| 2050 | if (mlx4_is_master(ibdev->dev)) { |
Yishai Hadas | 872bf2f | 2015-01-25 16:59:35 +0200 | [diff] [blame] | 2051 | for (slave = 0; slave <= ibdev->dev->persist->num_vfs; |
| 2052 | ++slave) { |
Jack Morgenstein | 54679e1 | 2012-08-03 08:40:43 +0000 | [diff] [blame] | 2053 | for (port = 1; port <= ibdev->dev->caps.num_ports; ++port) { |
| 2054 | for (i = 0; |
| 2055 | i < ibdev->dev->phys_caps.pkey_phys_table_len[port]; |
| 2056 | ++i) { |
| 2057 | ibdev->pkeys.virt2phys_pkey[slave][port - 1][i] = |
| 2058 | /* master has the identity virt2phys pkey mapping */ |
| 2059 | (slave == mlx4_master_func_num(ibdev->dev) || !i) ? i : |
| 2060 | ibdev->dev->phys_caps.pkey_phys_table_len[port] - 1; |
| 2061 | mlx4_sync_pkey_table(ibdev->dev, slave, port, i, |
| 2062 | ibdev->pkeys.virt2phys_pkey[slave][port - 1][i]); |
| 2063 | } |
| 2064 | } |
| 2065 | } |
| 2066 | /* initialize pkey cache */ |
| 2067 | for (port = 1; port <= ibdev->dev->caps.num_ports; ++port) { |
| 2068 | for (i = 0; |
| 2069 | i < ibdev->dev->phys_caps.pkey_phys_table_len[port]; |
| 2070 | ++i) |
| 2071 | ibdev->pkeys.phys_pkey_cache[port-1][i] = |
| 2072 | (i) ? 0 : 0xFFFF; |
| 2073 | } |
| 2074 | } |
| 2075 | } |
| 2076 | |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2077 | static void mlx4_ib_alloc_eqs(struct mlx4_dev *dev, struct mlx4_ib_dev *ibdev) |
| 2078 | { |
Matan Barak | c66fa19 | 2015-05-31 09:30:16 +0300 | [diff] [blame] | 2079 | int i, j, eq = 0, total_eqs = 0; |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2080 | |
Matan Barak | c66fa19 | 2015-05-31 09:30:16 +0300 | [diff] [blame] | 2081 | ibdev->eq_table = kcalloc(dev->caps.num_comp_vectors, |
| 2082 | sizeof(ibdev->eq_table[0]), GFP_KERNEL); |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2083 | if (!ibdev->eq_table) |
| 2084 | return; |
| 2085 | |
Matan Barak | c66fa19 | 2015-05-31 09:30:16 +0300 | [diff] [blame] | 2086 | for (i = 1; i <= dev->caps.num_ports; i++) { |
| 2087 | for (j = 0; j < mlx4_get_eqs_per_port(dev, i); |
| 2088 | j++, total_eqs++) { |
| 2089 | if (i > 1 && mlx4_is_eq_shared(dev, total_eqs)) |
| 2090 | continue; |
| 2091 | ibdev->eq_table[eq] = total_eqs; |
| 2092 | if (!mlx4_assign_eq(dev, i, |
| 2093 | &ibdev->eq_table[eq])) |
| 2094 | eq++; |
| 2095 | else |
| 2096 | ibdev->eq_table[eq] = -1; |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2097 | } |
| 2098 | } |
| 2099 | |
Matan Barak | c66fa19 | 2015-05-31 09:30:16 +0300 | [diff] [blame] | 2100 | for (i = eq; i < dev->caps.num_comp_vectors; |
| 2101 | ibdev->eq_table[i++] = -1) |
| 2102 | ; |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2103 | |
| 2104 | /* Advertise the new number of EQs to clients */ |
Matan Barak | c66fa19 | 2015-05-31 09:30:16 +0300 | [diff] [blame] | 2105 | ibdev->ib_dev.num_comp_vectors = eq; |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | static void mlx4_ib_free_eqs(struct mlx4_dev *dev, struct mlx4_ib_dev *ibdev) |
| 2109 | { |
| 2110 | int i; |
Matan Barak | c66fa19 | 2015-05-31 09:30:16 +0300 | [diff] [blame] | 2111 | int total_eqs = ibdev->ib_dev.num_comp_vectors; |
Shlomo Pongratz | 3aac6ff | 2012-05-24 16:08:07 +0300 | [diff] [blame] | 2112 | |
Matan Barak | c66fa19 | 2015-05-31 09:30:16 +0300 | [diff] [blame] | 2113 | /* no eqs were allocated */ |
Shlomo Pongratz | 3aac6ff | 2012-05-24 16:08:07 +0300 | [diff] [blame] | 2114 | if (!ibdev->eq_table) |
| 2115 | return; |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2116 | |
| 2117 | /* Reset the advertised EQ number */ |
Matan Barak | c66fa19 | 2015-05-31 09:30:16 +0300 | [diff] [blame] | 2118 | ibdev->ib_dev.num_comp_vectors = 0; |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2119 | |
Matan Barak | c66fa19 | 2015-05-31 09:30:16 +0300 | [diff] [blame] | 2120 | for (i = 0; i < total_eqs; i++) |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2121 | mlx4_release_eq(dev, ibdev->eq_table[i]); |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2122 | |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2123 | kfree(ibdev->eq_table); |
Matan Barak | c66fa19 | 2015-05-31 09:30:16 +0300 | [diff] [blame] | 2124 | ibdev->eq_table = NULL; |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2125 | } |
| 2126 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2127 | static int mlx4_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 2128 | struct ib_port_immutable *immutable) |
| 2129 | { |
| 2130 | struct ib_port_attr attr; |
| 2131 | int err; |
| 2132 | |
| 2133 | err = mlx4_ib_query_port(ibdev, port_num, &attr); |
| 2134 | if (err) |
| 2135 | return err; |
| 2136 | |
| 2137 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 2138 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 2139 | |
Ira Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 2140 | if (mlx4_ib_port_link_layer(ibdev, port_num) == IB_LINK_LAYER_INFINIBAND) |
| 2141 | immutable->core_cap_flags = RDMA_CORE_PORT_IBA_IB; |
| 2142 | else |
| 2143 | immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE; |
| 2144 | |
Ira Weiny | 337877a | 2015-06-06 14:38:29 -0400 | [diff] [blame] | 2145 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
| 2146 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2147 | return 0; |
| 2148 | } |
| 2149 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2150 | static void *mlx4_ib_add(struct mlx4_dev *dev) |
| 2151 | { |
| 2152 | struct mlx4_ib_dev *ibdev; |
Roland Dreier | 22e7ef9 | 2009-01-09 13:22:29 -0800 | [diff] [blame] | 2153 | int num_ports = 0; |
Jack Morgenstein | 035b103 | 2012-05-10 23:28:09 +0300 | [diff] [blame] | 2154 | int i, j; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2155 | int err; |
| 2156 | struct mlx4_ib_iboe *iboe; |
Matan Barak | 4196670 | 2014-02-02 17:06:47 +0200 | [diff] [blame] | 2157 | int ib_num_ports = 0; |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 2158 | int num_req_counters; |
Eran Ben Elisha | c3abb51 | 2015-06-15 17:59:03 +0300 | [diff] [blame] | 2159 | int allocated; |
| 2160 | u32 counter_index; |
Eran Ben Elisha | 3ba8e31 | 2015-10-15 14:44:40 +0300 | [diff] [blame] | 2161 | struct counter_index *new_counter_index = NULL; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2162 | |
Shlomo Pongratz | 987c8f8 | 2012-04-29 17:04:26 +0300 | [diff] [blame] | 2163 | pr_info_once("%s", mlx4_ib_version); |
Roland Dreier | 68f3948 | 2008-02-04 20:20:44 -0800 | [diff] [blame] | 2164 | |
Jack Morgenstein | 026149c | 2012-08-03 08:40:55 +0000 | [diff] [blame] | 2165 | num_ports = 0; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2166 | mlx4_foreach_ib_transport_port(i, dev) |
Roland Dreier | 22e7ef9 | 2009-01-09 13:22:29 -0800 | [diff] [blame] | 2167 | num_ports++; |
| 2168 | |
| 2169 | /* No point in registering a device with no ports... */ |
| 2170 | if (num_ports == 0) |
| 2171 | return NULL; |
| 2172 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2173 | ibdev = (struct mlx4_ib_dev *) ib_alloc_device(sizeof *ibdev); |
| 2174 | if (!ibdev) { |
Yishai Hadas | 872bf2f | 2015-01-25 16:59:35 +0200 | [diff] [blame] | 2175 | dev_err(&dev->persist->pdev->dev, |
| 2176 | "Device struct alloc failed\n"); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2177 | return NULL; |
| 2178 | } |
| 2179 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2180 | iboe = &ibdev->iboe; |
| 2181 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2182 | if (mlx4_pd_alloc(dev, &ibdev->priv_pdn)) |
| 2183 | goto err_dealloc; |
| 2184 | |
| 2185 | if (mlx4_uar_alloc(dev, &ibdev->priv_uar)) |
| 2186 | goto err_pd; |
| 2187 | |
Roland Dreier | 4979d18 | 2011-01-12 09:50:36 -0800 | [diff] [blame] | 2188 | ibdev->uar_map = ioremap((phys_addr_t) ibdev->priv_uar.pfn << PAGE_SHIFT, |
| 2189 | PAGE_SIZE); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2190 | if (!ibdev->uar_map) |
| 2191 | goto err_uar; |
Jack Morgenstein | 26c6bc7 | 2007-05-13 17:18:23 +0300 | [diff] [blame] | 2192 | MLX4_INIT_DOORBELL_LOCK(&ibdev->uar_lock); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2193 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2194 | ibdev->dev = dev; |
Moni Shoua | c621574 | 2015-02-03 16:48:39 +0200 | [diff] [blame] | 2195 | ibdev->bond_next_port = 0; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2196 | |
| 2197 | strlcpy(ibdev->ib_dev.name, "mlx4_%d", IB_DEVICE_NAME_MAX); |
| 2198 | ibdev->ib_dev.owner = THIS_MODULE; |
| 2199 | ibdev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Roland Dreier | 95d04f0 | 2008-07-23 08:12:26 -0700 | [diff] [blame] | 2200 | ibdev->ib_dev.local_dma_lkey = dev->caps.reserved_lkey; |
Roland Dreier | 22e7ef9 | 2009-01-09 13:22:29 -0800 | [diff] [blame] | 2201 | ibdev->num_ports = num_ports; |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 2202 | ibdev->ib_dev.phys_port_cnt = mlx4_is_bonded(dev) ? |
| 2203 | 1 : ibdev->num_ports; |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 2204 | ibdev->ib_dev.num_comp_vectors = dev->caps.num_comp_vectors; |
Yishai Hadas | 872bf2f | 2015-01-25 16:59:35 +0200 | [diff] [blame] | 2205 | ibdev->ib_dev.dma_device = &dev->persist->pdev->dev; |
Moni Shoua | 5070cd2 | 2015-07-30 18:33:30 +0300 | [diff] [blame] | 2206 | ibdev->ib_dev.get_netdev = mlx4_ib_get_netdev; |
| 2207 | ibdev->ib_dev.add_gid = mlx4_ib_add_gid; |
| 2208 | ibdev->ib_dev.del_gid = mlx4_ib_del_gid; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2209 | |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 2210 | if (dev->caps.userspace_caps) |
| 2211 | ibdev->ib_dev.uverbs_abi_ver = MLX4_IB_UVERBS_ABI_VERSION; |
| 2212 | else |
| 2213 | ibdev->ib_dev.uverbs_abi_ver = MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION; |
| 2214 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2215 | ibdev->ib_dev.uverbs_cmd_mask = |
| 2216 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 2217 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 2218 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 2219 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 2220 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
| 2221 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
Matan Barak | 9376932 | 2014-07-31 11:01:30 +0300 | [diff] [blame] | 2222 | (1ull << IB_USER_VERBS_CMD_REREG_MR) | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2223 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 2224 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 2225 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
Vladimir Sokolovsky | bbf8eed1 | 2008-04-16 21:09:33 -0700 | [diff] [blame] | 2226 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2227 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 2228 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 2229 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
Jack Morgenstein | 6a775e2 | 2007-06-21 12:27:47 +0300 | [diff] [blame] | 2230 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2231 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 2232 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 2233 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 2234 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 2235 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
Jack Morgenstein | 65541cb | 2007-06-21 13:03:11 +0300 | [diff] [blame] | 2236 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
Sean Hefty | 18abd5e | 2011-06-02 10:43:26 -0700 | [diff] [blame] | 2237 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
Sean Hefty | 42849b2 | 2011-08-11 13:57:43 -0700 | [diff] [blame] | 2238 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 2239 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2240 | |
| 2241 | ibdev->ib_dev.query_device = mlx4_ib_query_device; |
| 2242 | ibdev->ib_dev.query_port = mlx4_ib_query_port; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2243 | ibdev->ib_dev.get_link_layer = mlx4_ib_port_link_layer; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2244 | ibdev->ib_dev.query_gid = mlx4_ib_query_gid; |
| 2245 | ibdev->ib_dev.query_pkey = mlx4_ib_query_pkey; |
| 2246 | ibdev->ib_dev.modify_device = mlx4_ib_modify_device; |
| 2247 | ibdev->ib_dev.modify_port = mlx4_ib_modify_port; |
| 2248 | ibdev->ib_dev.alloc_ucontext = mlx4_ib_alloc_ucontext; |
| 2249 | ibdev->ib_dev.dealloc_ucontext = mlx4_ib_dealloc_ucontext; |
| 2250 | ibdev->ib_dev.mmap = mlx4_ib_mmap; |
| 2251 | ibdev->ib_dev.alloc_pd = mlx4_ib_alloc_pd; |
| 2252 | ibdev->ib_dev.dealloc_pd = mlx4_ib_dealloc_pd; |
| 2253 | ibdev->ib_dev.create_ah = mlx4_ib_create_ah; |
| 2254 | ibdev->ib_dev.query_ah = mlx4_ib_query_ah; |
| 2255 | ibdev->ib_dev.destroy_ah = mlx4_ib_destroy_ah; |
| 2256 | ibdev->ib_dev.create_srq = mlx4_ib_create_srq; |
| 2257 | ibdev->ib_dev.modify_srq = mlx4_ib_modify_srq; |
Jack Morgenstein | 65541cb | 2007-06-21 13:03:11 +0300 | [diff] [blame] | 2258 | ibdev->ib_dev.query_srq = mlx4_ib_query_srq; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2259 | ibdev->ib_dev.destroy_srq = mlx4_ib_destroy_srq; |
| 2260 | ibdev->ib_dev.post_srq_recv = mlx4_ib_post_srq_recv; |
| 2261 | ibdev->ib_dev.create_qp = mlx4_ib_create_qp; |
| 2262 | ibdev->ib_dev.modify_qp = mlx4_ib_modify_qp; |
Jack Morgenstein | 6a775e2 | 2007-06-21 12:27:47 +0300 | [diff] [blame] | 2263 | ibdev->ib_dev.query_qp = mlx4_ib_query_qp; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2264 | ibdev->ib_dev.destroy_qp = mlx4_ib_destroy_qp; |
| 2265 | ibdev->ib_dev.post_send = mlx4_ib_post_send; |
| 2266 | ibdev->ib_dev.post_recv = mlx4_ib_post_recv; |
| 2267 | ibdev->ib_dev.create_cq = mlx4_ib_create_cq; |
Eli Cohen | 3fdcb97 | 2008-04-16 21:09:33 -0700 | [diff] [blame] | 2268 | ibdev->ib_dev.modify_cq = mlx4_ib_modify_cq; |
Vladimir Sokolovsky | bbf8eed1 | 2008-04-16 21:09:33 -0700 | [diff] [blame] | 2269 | ibdev->ib_dev.resize_cq = mlx4_ib_resize_cq; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2270 | ibdev->ib_dev.destroy_cq = mlx4_ib_destroy_cq; |
| 2271 | ibdev->ib_dev.poll_cq = mlx4_ib_poll_cq; |
| 2272 | ibdev->ib_dev.req_notify_cq = mlx4_ib_arm_cq; |
| 2273 | ibdev->ib_dev.get_dma_mr = mlx4_ib_get_dma_mr; |
| 2274 | ibdev->ib_dev.reg_user_mr = mlx4_ib_reg_user_mr; |
Matan Barak | 9376932 | 2014-07-31 11:01:30 +0300 | [diff] [blame] | 2275 | ibdev->ib_dev.rereg_user_mr = mlx4_ib_rereg_user_mr; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2276 | ibdev->ib_dev.dereg_mr = mlx4_ib_dereg_mr; |
Sagi Grimberg | 679e34d | 2015-07-30 10:32:42 +0300 | [diff] [blame] | 2277 | ibdev->ib_dev.alloc_mr = mlx4_ib_alloc_mr; |
Sagi Grimberg | 1b2cd0f | 2015-10-13 19:11:27 +0300 | [diff] [blame] | 2278 | ibdev->ib_dev.map_mr_sg = mlx4_ib_map_mr_sg; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2279 | ibdev->ib_dev.attach_mcast = mlx4_ib_mcg_attach; |
| 2280 | ibdev->ib_dev.detach_mcast = mlx4_ib_mcg_detach; |
| 2281 | ibdev->ib_dev.process_mad = mlx4_ib_process_mad; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2282 | ibdev->ib_dev.get_port_immutable = mlx4_port_immutable; |
Yishai Hadas | ae184dd | 2015-08-13 18:32:06 +0300 | [diff] [blame] | 2283 | ibdev->ib_dev.disassociate_ucontext = mlx4_ib_disassociate_ucontext; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2284 | |
Jack Morgenstein | 992e8e6e | 2012-08-03 08:40:54 +0000 | [diff] [blame] | 2285 | if (!mlx4_is_slave(ibdev->dev)) { |
| 2286 | ibdev->ib_dev.alloc_fmr = mlx4_ib_fmr_alloc; |
| 2287 | ibdev->ib_dev.map_phys_fmr = mlx4_ib_map_phys_fmr; |
| 2288 | ibdev->ib_dev.unmap_fmr = mlx4_ib_unmap_fmr; |
| 2289 | ibdev->ib_dev.dealloc_fmr = mlx4_ib_fmr_dealloc; |
| 2290 | } |
Jack Morgenstein | 8ad11fb | 2007-08-01 12:29:05 +0300 | [diff] [blame] | 2291 | |
Shani Michaeli | b425388 | 2013-02-06 16:19:16 +0000 | [diff] [blame] | 2292 | if (dev->caps.flags & MLX4_DEV_CAP_FLAG_MEM_WINDOW || |
| 2293 | dev->caps.bmme_flags & MLX4_BMME_FLAG_TYPE_2_WIN) { |
| 2294 | ibdev->ib_dev.alloc_mw = mlx4_ib_alloc_mw; |
Shani Michaeli | b425388 | 2013-02-06 16:19:16 +0000 | [diff] [blame] | 2295 | ibdev->ib_dev.dealloc_mw = mlx4_ib_dealloc_mw; |
| 2296 | |
| 2297 | ibdev->ib_dev.uverbs_cmd_mask |= |
| 2298 | (1ull << IB_USER_VERBS_CMD_ALLOC_MW) | |
| 2299 | (1ull << IB_USER_VERBS_CMD_DEALLOC_MW); |
| 2300 | } |
| 2301 | |
Sean Hefty | 012a8ff | 2011-06-02 09:01:33 -0700 | [diff] [blame] | 2302 | if (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) { |
| 2303 | ibdev->ib_dev.alloc_xrcd = mlx4_ib_alloc_xrcd; |
| 2304 | ibdev->ib_dev.dealloc_xrcd = mlx4_ib_dealloc_xrcd; |
| 2305 | ibdev->ib_dev.uverbs_cmd_mask |= |
| 2306 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 2307 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
| 2308 | } |
| 2309 | |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 2310 | if (check_flow_steering_support(dev)) { |
Matan Barak | 0a9b7d5 | 2013-11-07 15:25:15 +0200 | [diff] [blame] | 2311 | ibdev->steering_support = MLX4_STEERING_MODE_DEVICE_MANAGED; |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 2312 | ibdev->ib_dev.create_flow = mlx4_ib_create_flow; |
| 2313 | ibdev->ib_dev.destroy_flow = mlx4_ib_destroy_flow; |
| 2314 | |
Yann Droneaud | f21519b | 2013-11-06 23:21:49 +0100 | [diff] [blame] | 2315 | ibdev->ib_dev.uverbs_ex_cmd_mask |= |
| 2316 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) | |
| 2317 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW); |
Hadar Hen Zion | f77c016 | 2013-08-14 13:58:31 +0300 | [diff] [blame] | 2318 | } |
| 2319 | |
Matan Barak | 4b664c4 | 2015-06-11 16:35:27 +0300 | [diff] [blame] | 2320 | ibdev->ib_dev.uverbs_ex_cmd_mask |= |
| 2321 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE) | |
Eran Ben Elisha | fbfb662 | 2015-10-15 14:44:42 +0300 | [diff] [blame] | 2322 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | |
| 2323 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP); |
Matan Barak | 4b664c4 | 2015-06-11 16:35:27 +0300 | [diff] [blame] | 2324 | |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2325 | mlx4_ib_alloc_eqs(dev, ibdev); |
| 2326 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2327 | spin_lock_init(&iboe->lock); |
| 2328 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2329 | if (init_node_data(ibdev)) |
| 2330 | goto err_map; |
| 2331 | |
Eran Ben Elisha | 3ba8e31 | 2015-10-15 14:44:40 +0300 | [diff] [blame] | 2332 | for (i = 0; i < ibdev->num_ports; ++i) { |
| 2333 | mutex_init(&ibdev->counters_table[i].mutex); |
| 2334 | INIT_LIST_HEAD(&ibdev->counters_table[i].counters_list); |
| 2335 | } |
| 2336 | |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 2337 | num_req_counters = mlx4_is_bonded(dev) ? 1 : ibdev->num_ports; |
| 2338 | for (i = 0; i < num_req_counters; ++i) { |
Matan Barak | 9433c18 | 2014-05-15 15:29:28 +0300 | [diff] [blame] | 2339 | mutex_init(&ibdev->qp1_proxy_lock[i]); |
Eran Ben Elisha | c3abb51 | 2015-06-15 17:59:03 +0300 | [diff] [blame] | 2340 | allocated = 0; |
Or Gerlitz | cfcde11 | 2011-06-15 14:49:57 +0000 | [diff] [blame] | 2341 | if (mlx4_ib_port_link_layer(&ibdev->ib_dev, i + 1) == |
| 2342 | IB_LINK_LAYER_ETHERNET) { |
Eran Ben Elisha | c3abb51 | 2015-06-15 17:59:03 +0300 | [diff] [blame] | 2343 | err = mlx4_counter_alloc(ibdev->dev, &counter_index); |
| 2344 | /* if failed to allocate a new counter, use default */ |
Or Gerlitz | cfcde11 | 2011-06-15 14:49:57 +0000 | [diff] [blame] | 2345 | if (err) |
Eran Ben Elisha | c3abb51 | 2015-06-15 17:59:03 +0300 | [diff] [blame] | 2346 | counter_index = |
| 2347 | mlx4_get_default_counter_index(dev, |
| 2348 | i + 1); |
| 2349 | else |
| 2350 | allocated = 1; |
| 2351 | } else { /* IB_LINK_LAYER_INFINIBAND use the default counter */ |
| 2352 | counter_index = mlx4_get_default_counter_index(dev, |
| 2353 | i + 1); |
Dan Carpenter | 3839d8a | 2014-03-28 11:21:39 +0300 | [diff] [blame] | 2354 | } |
Eran Ben Elisha | 3ba8e31 | 2015-10-15 14:44:40 +0300 | [diff] [blame] | 2355 | new_counter_index = kmalloc(sizeof(*new_counter_index), |
| 2356 | GFP_KERNEL); |
| 2357 | if (!new_counter_index) { |
| 2358 | if (allocated) |
| 2359 | mlx4_counter_free(ibdev->dev, counter_index); |
| 2360 | goto err_counter; |
| 2361 | } |
| 2362 | new_counter_index->index = counter_index; |
| 2363 | new_counter_index->allocated = allocated; |
| 2364 | list_add_tail(&new_counter_index->list, |
| 2365 | &ibdev->counters_table[i].counters_list); |
| 2366 | ibdev->counters_table[i].default_counter = counter_index; |
Eran Ben Elisha | c3abb51 | 2015-06-15 17:59:03 +0300 | [diff] [blame] | 2367 | pr_info("counter index %d for port %d allocated %d\n", |
| 2368 | counter_index, i + 1, allocated); |
Or Gerlitz | cfcde11 | 2011-06-15 14:49:57 +0000 | [diff] [blame] | 2369 | } |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 2370 | if (mlx4_is_bonded(dev)) |
Eran Ben Elisha | c3abb51 | 2015-06-15 17:59:03 +0300 | [diff] [blame] | 2371 | for (i = 1; i < ibdev->num_ports ; ++i) { |
Eran Ben Elisha | 3ba8e31 | 2015-10-15 14:44:40 +0300 | [diff] [blame] | 2372 | new_counter_index = |
| 2373 | kmalloc(sizeof(struct counter_index), |
| 2374 | GFP_KERNEL); |
| 2375 | if (!new_counter_index) |
| 2376 | goto err_counter; |
| 2377 | new_counter_index->index = counter_index; |
| 2378 | new_counter_index->allocated = 0; |
| 2379 | list_add_tail(&new_counter_index->list, |
| 2380 | &ibdev->counters_table[i].counters_list); |
| 2381 | ibdev->counters_table[i].default_counter = |
| 2382 | counter_index; |
Eran Ben Elisha | c3abb51 | 2015-06-15 17:59:03 +0300 | [diff] [blame] | 2383 | } |
Or Gerlitz | cfcde11 | 2011-06-15 14:49:57 +0000 | [diff] [blame] | 2384 | |
Matan Barak | 4196670 | 2014-02-02 17:06:47 +0200 | [diff] [blame] | 2385 | mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB) |
| 2386 | ib_num_ports++; |
| 2387 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2388 | spin_lock_init(&ibdev->sm_lock); |
| 2389 | mutex_init(&ibdev->cap_mask_mutex); |
Yishai Hadas | 35f05da | 2015-02-08 11:49:34 +0200 | [diff] [blame] | 2390 | INIT_LIST_HEAD(&ibdev->qp_list); |
| 2391 | spin_lock_init(&ibdev->reset_flow_resource_lock); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2392 | |
Matan Barak | 4196670 | 2014-02-02 17:06:47 +0200 | [diff] [blame] | 2393 | if (ibdev->steering_support == MLX4_STEERING_MODE_DEVICE_MANAGED && |
| 2394 | ib_num_ports) { |
Matan Barak | c1c9850 | 2013-11-07 15:25:17 +0200 | [diff] [blame] | 2395 | ibdev->steer_qpn_count = MLX4_IB_UC_MAX_NUM_QPS; |
| 2396 | err = mlx4_qp_reserve_range(dev, ibdev->steer_qpn_count, |
| 2397 | MLX4_IB_UC_STEER_QPN_ALIGN, |
Eugenia Emantayev | ddae034 | 2014-12-11 10:57:54 +0200 | [diff] [blame] | 2398 | &ibdev->steer_qpn_base, 0); |
Matan Barak | c1c9850 | 2013-11-07 15:25:17 +0200 | [diff] [blame] | 2399 | if (err) |
| 2400 | goto err_counter; |
| 2401 | |
| 2402 | ibdev->ib_uc_qpns_bitmap = |
| 2403 | kmalloc(BITS_TO_LONGS(ibdev->steer_qpn_count) * |
| 2404 | sizeof(long), |
| 2405 | GFP_KERNEL); |
| 2406 | if (!ibdev->ib_uc_qpns_bitmap) { |
Yishai Hadas | 872bf2f | 2015-01-25 16:59:35 +0200 | [diff] [blame] | 2407 | dev_err(&dev->persist->pdev->dev, |
| 2408 | "bit map alloc failed\n"); |
Matan Barak | c1c9850 | 2013-11-07 15:25:17 +0200 | [diff] [blame] | 2409 | goto err_steer_qp_release; |
| 2410 | } |
| 2411 | |
| 2412 | bitmap_zero(ibdev->ib_uc_qpns_bitmap, ibdev->steer_qpn_count); |
| 2413 | |
| 2414 | err = mlx4_FLOW_STEERING_IB_UC_QP_RANGE( |
| 2415 | dev, ibdev->steer_qpn_base, |
| 2416 | ibdev->steer_qpn_base + |
| 2417 | ibdev->steer_qpn_count - 1); |
| 2418 | if (err) |
| 2419 | goto err_steer_free_bitmap; |
| 2420 | } |
| 2421 | |
Jack Morgenstein | 3e0629c | 2014-09-11 14:11:17 +0300 | [diff] [blame] | 2422 | for (j = 1; j <= ibdev->dev->caps.num_ports; j++) |
| 2423 | atomic64_set(&iboe->mac[j - 1], ibdev->dev->caps.def_mac[j]); |
| 2424 | |
Ralph Campbell | 9a6edb6 | 2010-05-06 17:03:25 -0700 | [diff] [blame] | 2425 | if (ib_register_device(&ibdev->ib_dev, NULL)) |
Matan Barak | c1c9850 | 2013-11-07 15:25:17 +0200 | [diff] [blame] | 2426 | goto err_steer_free_bitmap; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2427 | |
| 2428 | if (mlx4_ib_mad_init(ibdev)) |
| 2429 | goto err_reg; |
| 2430 | |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2431 | if (mlx4_ib_init_sriov(ibdev)) |
| 2432 | goto err_mad; |
| 2433 | |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 2434 | if (dev->caps.flags & MLX4_DEV_CAP_FLAG_IBOE) { |
| 2435 | if (!iboe->nb.notifier_call) { |
| 2436 | iboe->nb.notifier_call = mlx4_ib_netdev_event; |
| 2437 | err = register_netdevice_notifier(&iboe->nb); |
| 2438 | if (err) { |
| 2439 | iboe->nb.notifier_call = NULL; |
| 2440 | goto err_notif; |
| 2441 | } |
| 2442 | } |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2443 | } |
| 2444 | |
Jack Morgenstein | 035b103 | 2012-05-10 23:28:09 +0300 | [diff] [blame] | 2445 | for (j = 0; j < ARRAY_SIZE(mlx4_class_attributes); ++j) { |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2446 | if (device_create_file(&ibdev->ib_dev.dev, |
Jack Morgenstein | 035b103 | 2012-05-10 23:28:09 +0300 | [diff] [blame] | 2447 | mlx4_class_attributes[j])) |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2448 | goto err_notif; |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 2449 | } |
| 2450 | |
Jack Morgenstein | 3b4a8cd | 2009-09-05 20:24:50 -0700 | [diff] [blame] | 2451 | ibdev->ib_active = true; |
| 2452 | |
Jack Morgenstein | 54679e1 | 2012-08-03 08:40:43 +0000 | [diff] [blame] | 2453 | if (mlx4_is_mfunc(ibdev->dev)) |
| 2454 | init_pkeys(ibdev); |
| 2455 | |
Jack Morgenstein | 3806d08 | 2012-08-03 08:40:58 +0000 | [diff] [blame] | 2456 | /* create paravirt contexts for any VFs which are active */ |
| 2457 | if (mlx4_is_master(ibdev->dev)) { |
| 2458 | for (j = 0; j < MLX4_MFUNC_MAX; j++) { |
| 2459 | if (j == mlx4_master_func_num(ibdev->dev)) |
| 2460 | continue; |
| 2461 | if (mlx4_is_slave_active(ibdev->dev, j)) |
| 2462 | do_slave_init(ibdev, j, 1); |
| 2463 | } |
| 2464 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2465 | return ibdev; |
| 2466 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2467 | err_notif: |
Moni Shoua | d487ee7 | 2013-12-12 18:03:13 +0200 | [diff] [blame] | 2468 | if (ibdev->iboe.nb.notifier_call) { |
| 2469 | if (unregister_netdevice_notifier(&ibdev->iboe.nb)) |
| 2470 | pr_warn("failure unregistering notifier\n"); |
| 2471 | ibdev->iboe.nb.notifier_call = NULL; |
| 2472 | } |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2473 | flush_workqueue(wq); |
| 2474 | |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2475 | mlx4_ib_close_sriov(ibdev); |
| 2476 | |
| 2477 | err_mad: |
| 2478 | mlx4_ib_mad_cleanup(ibdev); |
| 2479 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2480 | err_reg: |
| 2481 | ib_unregister_device(&ibdev->ib_dev); |
| 2482 | |
Matan Barak | c1c9850 | 2013-11-07 15:25:17 +0200 | [diff] [blame] | 2483 | err_steer_free_bitmap: |
| 2484 | kfree(ibdev->ib_uc_qpns_bitmap); |
| 2485 | |
| 2486 | err_steer_qp_release: |
| 2487 | if (ibdev->steering_support == MLX4_STEERING_MODE_DEVICE_MANAGED) |
| 2488 | mlx4_qp_release_range(dev, ibdev->steer_qpn_base, |
| 2489 | ibdev->steer_qpn_count); |
Or Gerlitz | cfcde11 | 2011-06-15 14:49:57 +0000 | [diff] [blame] | 2490 | err_counter: |
Eran Ben Elisha | 3ba8e31 | 2015-10-15 14:44:40 +0300 | [diff] [blame] | 2491 | for (i = 0; i < ibdev->num_ports; ++i) |
| 2492 | mlx4_ib_delete_counters_table(ibdev, &ibdev->counters_table[i]); |
| 2493 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2494 | err_map: |
| 2495 | iounmap(ibdev->uar_map); |
| 2496 | |
| 2497 | err_uar: |
| 2498 | mlx4_uar_free(dev, &ibdev->priv_uar); |
| 2499 | |
| 2500 | err_pd: |
| 2501 | mlx4_pd_free(dev, ibdev->priv_pdn); |
| 2502 | |
| 2503 | err_dealloc: |
| 2504 | ib_dealloc_device(&ibdev->ib_dev); |
| 2505 | |
| 2506 | return NULL; |
| 2507 | } |
| 2508 | |
Matan Barak | c1c9850 | 2013-11-07 15:25:17 +0200 | [diff] [blame] | 2509 | int mlx4_ib_steer_qp_alloc(struct mlx4_ib_dev *dev, int count, int *qpn) |
| 2510 | { |
| 2511 | int offset; |
| 2512 | |
| 2513 | WARN_ON(!dev->ib_uc_qpns_bitmap); |
| 2514 | |
| 2515 | offset = bitmap_find_free_region(dev->ib_uc_qpns_bitmap, |
| 2516 | dev->steer_qpn_count, |
| 2517 | get_count_order(count)); |
| 2518 | if (offset < 0) |
| 2519 | return offset; |
| 2520 | |
| 2521 | *qpn = dev->steer_qpn_base + offset; |
| 2522 | return 0; |
| 2523 | } |
| 2524 | |
| 2525 | void mlx4_ib_steer_qp_free(struct mlx4_ib_dev *dev, u32 qpn, int count) |
| 2526 | { |
| 2527 | if (!qpn || |
| 2528 | dev->steering_support != MLX4_STEERING_MODE_DEVICE_MANAGED) |
| 2529 | return; |
| 2530 | |
| 2531 | BUG_ON(qpn < dev->steer_qpn_base); |
| 2532 | |
| 2533 | bitmap_release_region(dev->ib_uc_qpns_bitmap, |
| 2534 | qpn - dev->steer_qpn_base, |
| 2535 | get_count_order(count)); |
| 2536 | } |
| 2537 | |
| 2538 | int mlx4_ib_steer_qp_reg(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp, |
| 2539 | int is_attach) |
| 2540 | { |
| 2541 | int err; |
| 2542 | size_t flow_size; |
| 2543 | struct ib_flow_attr *flow = NULL; |
| 2544 | struct ib_flow_spec_ib *ib_spec; |
| 2545 | |
| 2546 | if (is_attach) { |
| 2547 | flow_size = sizeof(struct ib_flow_attr) + |
| 2548 | sizeof(struct ib_flow_spec_ib); |
| 2549 | flow = kzalloc(flow_size, GFP_KERNEL); |
| 2550 | if (!flow) |
| 2551 | return -ENOMEM; |
| 2552 | flow->port = mqp->port; |
| 2553 | flow->num_of_specs = 1; |
| 2554 | flow->size = flow_size; |
| 2555 | ib_spec = (struct ib_flow_spec_ib *)(flow + 1); |
| 2556 | ib_spec->type = IB_FLOW_SPEC_IB; |
| 2557 | ib_spec->size = sizeof(struct ib_flow_spec_ib); |
| 2558 | /* Add an empty rule for IB L2 */ |
| 2559 | memset(&ib_spec->mask, 0, sizeof(ib_spec->mask)); |
| 2560 | |
| 2561 | err = __mlx4_ib_create_flow(&mqp->ibqp, flow, |
| 2562 | IB_FLOW_DOMAIN_NIC, |
| 2563 | MLX4_FS_REGULAR, |
| 2564 | &mqp->reg_id); |
| 2565 | } else { |
| 2566 | err = __mlx4_ib_destroy_flow(mdev->dev, mqp->reg_id); |
| 2567 | } |
| 2568 | kfree(flow); |
| 2569 | return err; |
| 2570 | } |
| 2571 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2572 | static void mlx4_ib_remove(struct mlx4_dev *dev, void *ibdev_ptr) |
| 2573 | { |
| 2574 | struct mlx4_ib_dev *ibdev = ibdev_ptr; |
| 2575 | int p; |
| 2576 | |
Moni Shoua | 4bf9715 | 2014-08-21 14:28:42 +0300 | [diff] [blame] | 2577 | ibdev->ib_active = false; |
| 2578 | flush_workqueue(wq); |
| 2579 | |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2580 | mlx4_ib_close_sriov(ibdev); |
Yevgeny Petrilin | a6a4777 | 2009-03-18 19:49:54 -0700 | [diff] [blame] | 2581 | mlx4_ib_mad_cleanup(ibdev); |
| 2582 | ib_unregister_device(&ibdev->ib_dev); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2583 | if (ibdev->iboe.nb.notifier_call) { |
| 2584 | if (unregister_netdevice_notifier(&ibdev->iboe.nb)) |
Shlomo Pongratz | 987c8f8 | 2012-04-29 17:04:26 +0300 | [diff] [blame] | 2585 | pr_warn("failure unregistering notifier\n"); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2586 | ibdev->iboe.nb.notifier_call = NULL; |
| 2587 | } |
Matan Barak | c1c9850 | 2013-11-07 15:25:17 +0200 | [diff] [blame] | 2588 | |
| 2589 | if (ibdev->steering_support == MLX4_STEERING_MODE_DEVICE_MANAGED) { |
| 2590 | mlx4_qp_release_range(dev, ibdev->steer_qpn_base, |
| 2591 | ibdev->steer_qpn_count); |
| 2592 | kfree(ibdev->ib_uc_qpns_bitmap); |
| 2593 | } |
| 2594 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2595 | iounmap(ibdev->uar_map); |
Or Gerlitz | cfcde11 | 2011-06-15 14:49:57 +0000 | [diff] [blame] | 2596 | for (p = 0; p < ibdev->num_ports; ++p) |
Eran Ben Elisha | 3ba8e31 | 2015-10-15 14:44:40 +0300 | [diff] [blame] | 2597 | mlx4_ib_delete_counters_table(ibdev, &ibdev->counters_table[p]); |
| 2598 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2599 | mlx4_foreach_port(p, dev, MLX4_PORT_TYPE_IB) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2600 | mlx4_CLOSE_PORT(dev, p); |
| 2601 | |
Shlomo Pongratz | e605b74 | 2012-04-29 17:04:27 +0300 | [diff] [blame] | 2602 | mlx4_ib_free_eqs(dev, ibdev); |
| 2603 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2604 | mlx4_uar_free(dev, &ibdev->priv_uar); |
| 2605 | mlx4_pd_free(dev, ibdev->priv_pdn); |
| 2606 | ib_dealloc_device(&ibdev->ib_dev); |
| 2607 | } |
| 2608 | |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2609 | static void do_slave_init(struct mlx4_ib_dev *ibdev, int slave, int do_init) |
| 2610 | { |
| 2611 | struct mlx4_ib_demux_work **dm = NULL; |
| 2612 | struct mlx4_dev *dev = ibdev->dev; |
| 2613 | int i; |
| 2614 | unsigned long flags; |
Matan Barak | 449fc48 | 2014-03-19 18:11:52 +0200 | [diff] [blame] | 2615 | struct mlx4_active_ports actv_ports; |
| 2616 | unsigned int ports; |
| 2617 | unsigned int first_port; |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2618 | |
| 2619 | if (!mlx4_is_master(dev)) |
| 2620 | return; |
| 2621 | |
Matan Barak | 449fc48 | 2014-03-19 18:11:52 +0200 | [diff] [blame] | 2622 | actv_ports = mlx4_get_active_ports(dev, slave); |
| 2623 | ports = bitmap_weight(actv_ports.ports, dev->caps.num_ports); |
| 2624 | first_port = find_first_bit(actv_ports.ports, dev->caps.num_ports); |
| 2625 | |
| 2626 | dm = kcalloc(ports, sizeof(*dm), GFP_ATOMIC); |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2627 | if (!dm) { |
| 2628 | pr_err("failed to allocate memory for tunneling qp update\n"); |
Maninder Singh | a39a98f | 2015-07-08 09:43:35 +0530 | [diff] [blame] | 2629 | return; |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2630 | } |
| 2631 | |
Matan Barak | 449fc48 | 2014-03-19 18:11:52 +0200 | [diff] [blame] | 2632 | for (i = 0; i < ports; i++) { |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2633 | dm[i] = kmalloc(sizeof (struct mlx4_ib_demux_work), GFP_ATOMIC); |
| 2634 | if (!dm[i]) { |
| 2635 | pr_err("failed to allocate memory for tunneling qp update work struct\n"); |
Maninder Singh | a39a98f | 2015-07-08 09:43:35 +0530 | [diff] [blame] | 2636 | while (--i >= 0) |
| 2637 | kfree(dm[i]); |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2638 | goto out; |
| 2639 | } |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2640 | INIT_WORK(&dm[i]->work, mlx4_ib_tunnels_update_work); |
Matan Barak | 449fc48 | 2014-03-19 18:11:52 +0200 | [diff] [blame] | 2641 | dm[i]->port = first_port + i + 1; |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2642 | dm[i]->slave = slave; |
| 2643 | dm[i]->do_init = do_init; |
| 2644 | dm[i]->dev = ibdev; |
Doug Ledford | d9a047a | 2015-07-09 10:21:08 -0400 | [diff] [blame] | 2645 | } |
| 2646 | /* initialize or tear down tunnel QPs for the slave */ |
| 2647 | spin_lock_irqsave(&ibdev->sriov.going_down_lock, flags); |
| 2648 | if (!ibdev->sriov.is_going_down) { |
| 2649 | for (i = 0; i < ports; i++) |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2650 | queue_work(ibdev->sriov.demux[i].ud_wq, &dm[i]->work); |
| 2651 | spin_unlock_irqrestore(&ibdev->sriov.going_down_lock, flags); |
Doug Ledford | d9a047a | 2015-07-09 10:21:08 -0400 | [diff] [blame] | 2652 | } else { |
| 2653 | spin_unlock_irqrestore(&ibdev->sriov.going_down_lock, flags); |
| 2654 | for (i = 0; i < ports; i++) |
| 2655 | kfree(dm[i]); |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2656 | } |
| 2657 | out: |
Syam Sidhardhan | c89d127 | 2013-02-24 23:20:05 +0000 | [diff] [blame] | 2658 | kfree(dm); |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2659 | return; |
| 2660 | } |
| 2661 | |
Yishai Hadas | 35f05da | 2015-02-08 11:49:34 +0200 | [diff] [blame] | 2662 | static void mlx4_ib_handle_catas_error(struct mlx4_ib_dev *ibdev) |
| 2663 | { |
| 2664 | struct mlx4_ib_qp *mqp; |
| 2665 | unsigned long flags_qp; |
| 2666 | unsigned long flags_cq; |
| 2667 | struct mlx4_ib_cq *send_mcq, *recv_mcq; |
| 2668 | struct list_head cq_notify_list; |
| 2669 | struct mlx4_cq *mcq; |
| 2670 | unsigned long flags; |
| 2671 | |
| 2672 | pr_warn("mlx4_ib_handle_catas_error was started\n"); |
| 2673 | INIT_LIST_HEAD(&cq_notify_list); |
| 2674 | |
| 2675 | /* Go over qp list reside on that ibdev, sync with create/destroy qp.*/ |
| 2676 | spin_lock_irqsave(&ibdev->reset_flow_resource_lock, flags); |
| 2677 | |
| 2678 | list_for_each_entry(mqp, &ibdev->qp_list, qps_list) { |
| 2679 | spin_lock_irqsave(&mqp->sq.lock, flags_qp); |
| 2680 | if (mqp->sq.tail != mqp->sq.head) { |
| 2681 | send_mcq = to_mcq(mqp->ibqp.send_cq); |
| 2682 | spin_lock_irqsave(&send_mcq->lock, flags_cq); |
| 2683 | if (send_mcq->mcq.comp && |
| 2684 | mqp->ibqp.send_cq->comp_handler) { |
| 2685 | if (!send_mcq->mcq.reset_notify_added) { |
| 2686 | send_mcq->mcq.reset_notify_added = 1; |
| 2687 | list_add_tail(&send_mcq->mcq.reset_notify, |
| 2688 | &cq_notify_list); |
| 2689 | } |
| 2690 | } |
| 2691 | spin_unlock_irqrestore(&send_mcq->lock, flags_cq); |
| 2692 | } |
| 2693 | spin_unlock_irqrestore(&mqp->sq.lock, flags_qp); |
| 2694 | /* Now, handle the QP's receive queue */ |
| 2695 | spin_lock_irqsave(&mqp->rq.lock, flags_qp); |
| 2696 | /* no handling is needed for SRQ */ |
| 2697 | if (!mqp->ibqp.srq) { |
| 2698 | if (mqp->rq.tail != mqp->rq.head) { |
| 2699 | recv_mcq = to_mcq(mqp->ibqp.recv_cq); |
| 2700 | spin_lock_irqsave(&recv_mcq->lock, flags_cq); |
| 2701 | if (recv_mcq->mcq.comp && |
| 2702 | mqp->ibqp.recv_cq->comp_handler) { |
| 2703 | if (!recv_mcq->mcq.reset_notify_added) { |
| 2704 | recv_mcq->mcq.reset_notify_added = 1; |
| 2705 | list_add_tail(&recv_mcq->mcq.reset_notify, |
| 2706 | &cq_notify_list); |
| 2707 | } |
| 2708 | } |
| 2709 | spin_unlock_irqrestore(&recv_mcq->lock, |
| 2710 | flags_cq); |
| 2711 | } |
| 2712 | } |
| 2713 | spin_unlock_irqrestore(&mqp->rq.lock, flags_qp); |
| 2714 | } |
| 2715 | |
| 2716 | list_for_each_entry(mcq, &cq_notify_list, reset_notify) { |
| 2717 | mcq->comp(mcq); |
| 2718 | } |
| 2719 | spin_unlock_irqrestore(&ibdev->reset_flow_resource_lock, flags); |
| 2720 | pr_warn("mlx4_ib_handle_catas_error ended\n"); |
| 2721 | } |
| 2722 | |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 2723 | static void handle_bonded_port_state_event(struct work_struct *work) |
| 2724 | { |
| 2725 | struct ib_event_work *ew = |
| 2726 | container_of(work, struct ib_event_work, work); |
| 2727 | struct mlx4_ib_dev *ibdev = ew->ib_dev; |
| 2728 | enum ib_port_state bonded_port_state = IB_PORT_NOP; |
| 2729 | int i; |
| 2730 | struct ib_event ibev; |
| 2731 | |
| 2732 | kfree(ew); |
| 2733 | spin_lock_bh(&ibdev->iboe.lock); |
| 2734 | for (i = 0; i < MLX4_MAX_PORTS; ++i) { |
| 2735 | struct net_device *curr_netdev = ibdev->iboe.netdevs[i]; |
Moni Shoua | 217e8b1 | 2015-03-18 16:51:35 +0200 | [diff] [blame] | 2736 | enum ib_port_state curr_port_state; |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 2737 | |
Moni Shoua | 217e8b1 | 2015-03-18 16:51:35 +0200 | [diff] [blame] | 2738 | if (!curr_netdev) |
| 2739 | continue; |
| 2740 | |
| 2741 | curr_port_state = |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 2742 | (netif_running(curr_netdev) && |
| 2743 | netif_carrier_ok(curr_netdev)) ? |
| 2744 | IB_PORT_ACTIVE : IB_PORT_DOWN; |
| 2745 | |
| 2746 | bonded_port_state = (bonded_port_state != IB_PORT_ACTIVE) ? |
| 2747 | curr_port_state : IB_PORT_ACTIVE; |
| 2748 | } |
| 2749 | spin_unlock_bh(&ibdev->iboe.lock); |
| 2750 | |
| 2751 | ibev.device = &ibdev->ib_dev; |
| 2752 | ibev.element.port_num = 1; |
| 2753 | ibev.event = (bonded_port_state == IB_PORT_ACTIVE) ? |
| 2754 | IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
| 2755 | |
| 2756 | ib_dispatch_event(&ibev); |
| 2757 | } |
| 2758 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2759 | static void mlx4_ib_event(struct mlx4_dev *dev, void *ibdev_ptr, |
Jack Morgenstein | 00f5ce9 | 2012-06-19 11:21:40 +0300 | [diff] [blame] | 2760 | enum mlx4_dev_event event, unsigned long param) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2761 | { |
| 2762 | struct ib_event ibev; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2763 | struct mlx4_ib_dev *ibdev = to_mdev((struct ib_device *) ibdev_ptr); |
Jack Morgenstein | 00f5ce9 | 2012-06-19 11:21:40 +0300 | [diff] [blame] | 2764 | struct mlx4_eqe *eqe = NULL; |
| 2765 | struct ib_event_work *ew; |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2766 | int p = 0; |
Jack Morgenstein | 00f5ce9 | 2012-06-19 11:21:40 +0300 | [diff] [blame] | 2767 | |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 2768 | if (mlx4_is_bonded(dev) && |
| 2769 | ((event == MLX4_DEV_EVENT_PORT_UP) || |
| 2770 | (event == MLX4_DEV_EVENT_PORT_DOWN))) { |
| 2771 | ew = kmalloc(sizeof(*ew), GFP_ATOMIC); |
| 2772 | if (!ew) |
| 2773 | return; |
| 2774 | INIT_WORK(&ew->work, handle_bonded_port_state_event); |
| 2775 | ew->ib_dev = ibdev; |
| 2776 | queue_work(wq, &ew->work); |
| 2777 | return; |
| 2778 | } |
| 2779 | |
Jack Morgenstein | 00f5ce9 | 2012-06-19 11:21:40 +0300 | [diff] [blame] | 2780 | if (event == MLX4_DEV_EVENT_PORT_MGMT_CHANGE) |
| 2781 | eqe = (struct mlx4_eqe *)param; |
| 2782 | else |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2783 | p = (int) param; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2784 | |
| 2785 | switch (event) { |
Roland Dreier | 37608ee | 2008-04-16 21:01:08 -0700 | [diff] [blame] | 2786 | case MLX4_DEV_EVENT_PORT_UP: |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2787 | if (p > ibdev->num_ports) |
| 2788 | return; |
Jack Morgenstein | a0c64a1 | 2012-08-03 08:40:49 +0000 | [diff] [blame] | 2789 | if (mlx4_is_master(dev) && |
| 2790 | rdma_port_get_link_layer(&ibdev->ib_dev, p) == |
| 2791 | IB_LINK_LAYER_INFINIBAND) { |
| 2792 | mlx4_ib_invalidate_all_guid_record(ibdev, p); |
| 2793 | } |
Roland Dreier | 37608ee | 2008-04-16 21:01:08 -0700 | [diff] [blame] | 2794 | ibev.event = IB_EVENT_PORT_ACTIVE; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2795 | break; |
| 2796 | |
Roland Dreier | 37608ee | 2008-04-16 21:01:08 -0700 | [diff] [blame] | 2797 | case MLX4_DEV_EVENT_PORT_DOWN: |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2798 | if (p > ibdev->num_ports) |
| 2799 | return; |
Roland Dreier | 37608ee | 2008-04-16 21:01:08 -0700 | [diff] [blame] | 2800 | ibev.event = IB_EVENT_PORT_ERR; |
| 2801 | break; |
| 2802 | |
| 2803 | case MLX4_DEV_EVENT_CATASTROPHIC_ERROR: |
Jack Morgenstein | 3b4a8cd | 2009-09-05 20:24:50 -0700 | [diff] [blame] | 2804 | ibdev->ib_active = false; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2805 | ibev.event = IB_EVENT_DEVICE_FATAL; |
Yishai Hadas | 35f05da | 2015-02-08 11:49:34 +0200 | [diff] [blame] | 2806 | mlx4_ib_handle_catas_error(ibdev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2807 | break; |
| 2808 | |
Jack Morgenstein | 00f5ce9 | 2012-06-19 11:21:40 +0300 | [diff] [blame] | 2809 | case MLX4_DEV_EVENT_PORT_MGMT_CHANGE: |
| 2810 | ew = kmalloc(sizeof *ew, GFP_ATOMIC); |
| 2811 | if (!ew) { |
| 2812 | pr_err("failed to allocate memory for events work\n"); |
| 2813 | break; |
| 2814 | } |
| 2815 | |
| 2816 | INIT_WORK(&ew->work, handle_port_mgmt_change_event); |
| 2817 | memcpy(&ew->ib_eqe, eqe, sizeof *eqe); |
| 2818 | ew->ib_dev = ibdev; |
Jack Morgenstein | 992e8e6e | 2012-08-03 08:40:54 +0000 | [diff] [blame] | 2819 | /* need to queue only for port owner, which uses GEN_EQE */ |
| 2820 | if (mlx4_is_master(dev)) |
| 2821 | queue_work(wq, &ew->work); |
| 2822 | else |
| 2823 | handle_port_mgmt_change_event(&ew->work); |
Jack Morgenstein | 00f5ce9 | 2012-06-19 11:21:40 +0300 | [diff] [blame] | 2824 | return; |
| 2825 | |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2826 | case MLX4_DEV_EVENT_SLAVE_INIT: |
| 2827 | /* here, p is the slave id */ |
| 2828 | do_slave_init(ibdev, p, 1); |
Yishai Hadas | ee59fa0 | 2015-03-03 17:28:49 +0200 | [diff] [blame] | 2829 | if (mlx4_is_master(dev)) { |
| 2830 | int i; |
| 2831 | |
| 2832 | for (i = 1; i <= ibdev->num_ports; i++) { |
| 2833 | if (rdma_port_get_link_layer(&ibdev->ib_dev, i) |
| 2834 | == IB_LINK_LAYER_INFINIBAND) |
| 2835 | mlx4_ib_slave_alias_guid_event(ibdev, |
| 2836 | p, i, |
| 2837 | 1); |
| 2838 | } |
| 2839 | } |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2840 | return; |
| 2841 | |
| 2842 | case MLX4_DEV_EVENT_SLAVE_SHUTDOWN: |
Yishai Hadas | ee59fa0 | 2015-03-03 17:28:49 +0200 | [diff] [blame] | 2843 | if (mlx4_is_master(dev)) { |
| 2844 | int i; |
| 2845 | |
| 2846 | for (i = 1; i <= ibdev->num_ports; i++) { |
| 2847 | if (rdma_port_get_link_layer(&ibdev->ib_dev, i) |
| 2848 | == IB_LINK_LAYER_INFINIBAND) |
| 2849 | mlx4_ib_slave_alias_guid_event(ibdev, |
| 2850 | p, i, |
| 2851 | 0); |
| 2852 | } |
| 2853 | } |
Jack Morgenstein | fc06573 | 2012-08-03 08:40:42 +0000 | [diff] [blame] | 2854 | /* here, p is the slave id */ |
| 2855 | do_slave_init(ibdev, p, 0); |
| 2856 | return; |
| 2857 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2858 | default: |
| 2859 | return; |
| 2860 | } |
| 2861 | |
| 2862 | ibev.device = ibdev_ptr; |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 2863 | ibev.element.port_num = mlx4_is_bonded(ibdev->dev) ? 1 : (u8)p; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2864 | |
| 2865 | ib_dispatch_event(&ibev); |
| 2866 | } |
| 2867 | |
| 2868 | static struct mlx4_interface mlx4_ib_interface = { |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2869 | .add = mlx4_ib_add, |
| 2870 | .remove = mlx4_ib_remove, |
| 2871 | .event = mlx4_ib_event, |
Moni Shoua | a575009 | 2015-02-03 16:48:37 +0200 | [diff] [blame] | 2872 | .protocol = MLX4_PROT_IB_IPV6, |
| 2873 | .flags = MLX4_INTFF_BONDING |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2874 | }; |
| 2875 | |
| 2876 | static int __init mlx4_ib_init(void) |
| 2877 | { |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2878 | int err; |
| 2879 | |
| 2880 | wq = create_singlethread_workqueue("mlx4_ib"); |
| 2881 | if (!wq) |
| 2882 | return -ENOMEM; |
| 2883 | |
Oren Duer | b9c5d6a | 2012-08-03 08:40:46 +0000 | [diff] [blame] | 2884 | err = mlx4_ib_mcg_init(); |
| 2885 | if (err) |
| 2886 | goto clean_wq; |
| 2887 | |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2888 | err = mlx4_register_interface(&mlx4_ib_interface); |
Oren Duer | b9c5d6a | 2012-08-03 08:40:46 +0000 | [diff] [blame] | 2889 | if (err) |
| 2890 | goto clean_mcg; |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2891 | |
| 2892 | return 0; |
Oren Duer | b9c5d6a | 2012-08-03 08:40:46 +0000 | [diff] [blame] | 2893 | |
| 2894 | clean_mcg: |
| 2895 | mlx4_ib_mcg_destroy(); |
| 2896 | |
| 2897 | clean_wq: |
| 2898 | destroy_workqueue(wq); |
| 2899 | return err; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | static void __exit mlx4_ib_cleanup(void) |
| 2903 | { |
| 2904 | mlx4_unregister_interface(&mlx4_ib_interface); |
Oren Duer | b9c5d6a | 2012-08-03 08:40:46 +0000 | [diff] [blame] | 2905 | mlx4_ib_mcg_destroy(); |
Eli Cohen | fa417f7 | 2010-10-24 21:08:52 -0700 | [diff] [blame] | 2906 | destroy_workqueue(wq); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | module_init(mlx4_ib_init); |
| 2910 | module_exit(mlx4_ib_cleanup); |