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