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