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