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> |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 41 | #include <linux/bitmap.h> |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 42 | #if defined(CONFIG_X86) |
| 43 | #include <asm/pat.h> |
| 44 | #endif |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 45 | #include <linux/sched.h> |
Ingo Molnar | 6e84f31 | 2017-02-08 18:51:29 +0100 | [diff] [blame] | 46 | #include <linux/sched/mm.h> |
Ingo Molnar | 0881e7b | 2017-02-05 15:30:50 +0100 | [diff] [blame] | 47 | #include <linux/sched/task.h> |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 48 | #include <linux/delay.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 49 | #include <rdma/ib_user_verbs.h> |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 50 | #include <rdma/ib_addr.h> |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 51 | #include <rdma/ib_cache.h> |
Achiad Shochat | ada68c3 | 2016-02-22 18:17:23 +0200 | [diff] [blame] | 52 | #include <linux/mlx5/port.h> |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 53 | #include <linux/mlx5/vport.h> |
Pravin Shedge | 72c7fe9 | 2017-12-06 22:19:39 +0530 | [diff] [blame] | 54 | #include <linux/mlx5/fs.h> |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 55 | #include <linux/list.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 56 | #include <rdma/ib_smi.h> |
| 57 | #include <rdma/ib_umem.h> |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 58 | #include <linux/in.h> |
| 59 | #include <linux/etherdevice.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 60 | #include "mlx5_ib.h" |
Mark Bloch | fc385b7 | 2018-01-16 14:34:48 +0000 | [diff] [blame] | 61 | #include "ib_rep.h" |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 62 | #include "cmd.h" |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 63 | #include "srq.h" |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 64 | #include <linux/mlx5/fs_helpers.h> |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 65 | #include <linux/mlx5/accel.h> |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 66 | #include <rdma/uverbs_std_types.h> |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 67 | #include <rdma/mlx5_user_ioctl_verbs.h> |
| 68 | #include <rdma/mlx5_user_ioctl_cmds.h> |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 69 | |
| 70 | #define UVERBS_MODULE_NAME mlx5_ib |
| 71 | #include <rdma/uverbs_named_ioctl.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 72 | |
| 73 | #define DRIVER_NAME "mlx5_ib" |
Tariq Toukan | b359911 | 2017-02-22 17:45:46 +0200 | [diff] [blame] | 74 | #define DRIVER_VERSION "5.0-0" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 75 | |
| 76 | MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); |
| 77 | MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); |
| 78 | MODULE_LICENSE("Dual BSD/GPL"); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 79 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 80 | static char mlx5_version[] = |
| 81 | DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
Tariq Toukan | b359911 | 2017-02-22 17:45:46 +0200 | [diff] [blame] | 82 | DRIVER_VERSION "\n"; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 83 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 84 | struct mlx5_ib_event_work { |
| 85 | struct work_struct work; |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 86 | union { |
| 87 | struct mlx5_ib_dev *dev; |
| 88 | struct mlx5_ib_multiport_info *mpi; |
| 89 | }; |
| 90 | bool is_slave; |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 91 | unsigned int event; |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 92 | void *param; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 93 | }; |
| 94 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 95 | enum { |
| 96 | MLX5_ATOMIC_SIZE_QP_8BYTES = 1 << 3, |
| 97 | }; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 98 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 99 | static struct workqueue_struct *mlx5_ib_event_wq; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 100 | static LIST_HEAD(mlx5_ib_unaffiliated_port_list); |
| 101 | static LIST_HEAD(mlx5_ib_dev_list); |
| 102 | /* |
| 103 | * This mutex should be held when accessing either of the above lists |
| 104 | */ |
| 105 | static DEFINE_MUTEX(mlx5_ib_multiport_mutex); |
| 106 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 107 | /* We can't use an array for xlt_emergency_page because dma_map_single |
| 108 | * doesn't work on kernel modules memory |
| 109 | */ |
| 110 | static unsigned long xlt_emergency_page; |
| 111 | static struct mutex xlt_emergency_page_mutex; |
| 112 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 113 | struct mlx5_ib_dev *mlx5_ib_get_ibdev_from_mpi(struct mlx5_ib_multiport_info *mpi) |
| 114 | { |
| 115 | struct mlx5_ib_dev *dev; |
| 116 | |
| 117 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 118 | dev = mpi->ibdev; |
| 119 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 120 | return dev; |
| 121 | } |
| 122 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 123 | static enum rdma_link_layer |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 124 | mlx5_port_type_cap_to_rdma_ll(int port_type_cap) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 125 | { |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 126 | switch (port_type_cap) { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 127 | case MLX5_CAP_PORT_TYPE_IB: |
| 128 | return IB_LINK_LAYER_INFINIBAND; |
| 129 | case MLX5_CAP_PORT_TYPE_ETH: |
| 130 | return IB_LINK_LAYER_ETHERNET; |
| 131 | default: |
| 132 | return IB_LINK_LAYER_UNSPECIFIED; |
| 133 | } |
| 134 | } |
| 135 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 136 | static enum rdma_link_layer |
| 137 | mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num) |
| 138 | { |
| 139 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 140 | int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type); |
| 141 | |
| 142 | return mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 143 | } |
| 144 | |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 145 | static int get_port_state(struct ib_device *ibdev, |
| 146 | u8 port_num, |
| 147 | enum ib_port_state *state) |
| 148 | { |
| 149 | struct ib_port_attr attr; |
| 150 | int ret; |
| 151 | |
| 152 | memset(&attr, 0, sizeof(attr)); |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 153 | ret = ibdev->ops.query_port(ibdev, port_num, &attr); |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 154 | if (!ret) |
| 155 | *state = attr.state; |
| 156 | return ret; |
| 157 | } |
| 158 | |
Mark Bloch | 35b0aa6 | 2019-03-28 15:27:39 +0200 | [diff] [blame] | 159 | static struct mlx5_roce *mlx5_get_rep_roce(struct mlx5_ib_dev *dev, |
| 160 | struct net_device *ndev, |
| 161 | u8 *port_num) |
| 162 | { |
| 163 | struct mlx5_eswitch *esw = dev->mdev->priv.eswitch; |
| 164 | struct net_device *rep_ndev; |
| 165 | struct mlx5_ib_port *port; |
| 166 | int i; |
| 167 | |
| 168 | for (i = 0; i < dev->num_ports; i++) { |
| 169 | port = &dev->port[i]; |
| 170 | if (!port->rep) |
| 171 | continue; |
| 172 | |
| 173 | read_lock(&port->roce.netdev_lock); |
| 174 | rep_ndev = mlx5_ib_get_rep_netdev(esw, |
| 175 | port->rep->vport); |
| 176 | if (rep_ndev == ndev) { |
| 177 | read_unlock(&port->roce.netdev_lock); |
| 178 | *port_num = i + 1; |
| 179 | return &port->roce; |
| 180 | } |
| 181 | read_unlock(&port->roce.netdev_lock); |
| 182 | } |
| 183 | |
| 184 | return NULL; |
| 185 | } |
| 186 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 187 | static int mlx5_netdev_event(struct notifier_block *this, |
| 188 | unsigned long event, void *ptr) |
| 189 | { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 190 | struct mlx5_roce *roce = container_of(this, struct mlx5_roce, nb); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 191 | struct net_device *ndev = netdev_notifier_info_to_dev(ptr); |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 192 | u8 port_num = roce->native_port_num; |
| 193 | struct mlx5_core_dev *mdev; |
| 194 | struct mlx5_ib_dev *ibdev; |
| 195 | |
| 196 | ibdev = roce->dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 197 | mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL); |
| 198 | if (!mdev) |
| 199 | return NOTIFY_DONE; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 200 | |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 201 | switch (event) { |
| 202 | case NETDEV_REGISTER: |
Mark Bloch | 35b0aa6 | 2019-03-28 15:27:39 +0200 | [diff] [blame] | 203 | /* Should already be registered during the load */ |
| 204 | if (ibdev->is_rep) |
| 205 | break; |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 206 | write_lock(&roce->netdev_lock); |
Mark Bloch | 35b0aa6 | 2019-03-28 15:27:39 +0200 | [diff] [blame] | 207 | if (ndev->dev.parent == &mdev->pdev->dev) |
Or Gerlitz | 842a9c8 | 2018-12-11 18:10:43 +0200 | [diff] [blame] | 208 | roce->netdev = ndev; |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 209 | write_unlock(&roce->netdev_lock); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 210 | break; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 211 | |
Or Gerlitz | 842a9c8 | 2018-12-11 18:10:43 +0200 | [diff] [blame] | 212 | case NETDEV_UNREGISTER: |
Mark Bloch | 35b0aa6 | 2019-03-28 15:27:39 +0200 | [diff] [blame] | 213 | /* In case of reps, ib device goes away before the netdevs */ |
Or Gerlitz | 842a9c8 | 2018-12-11 18:10:43 +0200 | [diff] [blame] | 214 | write_lock(&roce->netdev_lock); |
| 215 | if (roce->netdev == ndev) |
| 216 | roce->netdev = NULL; |
| 217 | write_unlock(&roce->netdev_lock); |
| 218 | break; |
| 219 | |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 220 | case NETDEV_CHANGE: |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 221 | case NETDEV_UP: |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 222 | case NETDEV_DOWN: { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 223 | struct net_device *lag_ndev = mlx5_lag_get_roce_netdev(mdev); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 224 | struct net_device *upper = NULL; |
| 225 | |
| 226 | if (lag_ndev) { |
| 227 | upper = netdev_master_upper_dev_get(lag_ndev); |
| 228 | dev_put(lag_ndev); |
| 229 | } |
| 230 | |
Mark Bloch | 35b0aa6 | 2019-03-28 15:27:39 +0200 | [diff] [blame] | 231 | if (ibdev->is_rep) |
| 232 | roce = mlx5_get_rep_roce(ibdev, ndev, &port_num); |
| 233 | if (!roce) |
| 234 | return NOTIFY_DONE; |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 235 | if ((upper == ndev || (!upper && ndev == roce->netdev)) |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 236 | && ibdev->ib_active) { |
Bart Van Assche | 626bc02 | 2016-12-05 17:18:08 -0800 | [diff] [blame] | 237 | struct ib_event ibev = { }; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 238 | enum ib_port_state port_state; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 239 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 240 | if (get_port_state(&ibdev->ib_dev, port_num, |
| 241 | &port_state)) |
| 242 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 243 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 244 | if (roce->last_port_state == port_state) |
| 245 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 246 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 247 | roce->last_port_state = port_state; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 248 | ibev.device = &ibdev->ib_dev; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 249 | if (port_state == IB_PORT_DOWN) |
| 250 | ibev.event = IB_EVENT_PORT_ERR; |
| 251 | else if (port_state == IB_PORT_ACTIVE) |
| 252 | ibev.event = IB_EVENT_PORT_ACTIVE; |
| 253 | else |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 254 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 255 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 256 | ibev.element.port_num = port_num; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 257 | ib_dispatch_event(&ibev); |
| 258 | } |
| 259 | break; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 260 | } |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 261 | |
| 262 | default: |
| 263 | break; |
| 264 | } |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 265 | done: |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 266 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 267 | return NOTIFY_DONE; |
| 268 | } |
| 269 | |
| 270 | static struct net_device *mlx5_ib_get_netdev(struct ib_device *device, |
| 271 | u8 port_num) |
| 272 | { |
| 273 | struct mlx5_ib_dev *ibdev = to_mdev(device); |
| 274 | struct net_device *ndev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 275 | struct mlx5_core_dev *mdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 276 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 277 | mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL); |
| 278 | if (!mdev) |
| 279 | return NULL; |
| 280 | |
| 281 | ndev = mlx5_lag_get_roce_netdev(mdev); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 282 | if (ndev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 283 | goto out; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 284 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 285 | /* Ensure ndev does not disappear before we invoke dev_hold() |
| 286 | */ |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 287 | read_lock(&ibdev->port[port_num - 1].roce.netdev_lock); |
| 288 | ndev = ibdev->port[port_num - 1].roce.netdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 289 | if (ndev) |
| 290 | dev_hold(ndev); |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 291 | read_unlock(&ibdev->port[port_num - 1].roce.netdev_lock); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 292 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 293 | out: |
| 294 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 295 | return ndev; |
| 296 | } |
| 297 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 298 | struct mlx5_core_dev *mlx5_ib_get_native_port_mdev(struct mlx5_ib_dev *ibdev, |
| 299 | u8 ib_port_num, |
| 300 | u8 *native_port_num) |
| 301 | { |
| 302 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&ibdev->ib_dev, |
| 303 | ib_port_num); |
| 304 | struct mlx5_core_dev *mdev = NULL; |
| 305 | struct mlx5_ib_multiport_info *mpi; |
| 306 | struct mlx5_ib_port *port; |
| 307 | |
Mark Bloch | 210b1f7 | 2018-03-05 20:09:47 +0200 | [diff] [blame] | 308 | if (!mlx5_core_mp_enabled(ibdev->mdev) || |
| 309 | ll != IB_LINK_LAYER_ETHERNET) { |
| 310 | if (native_port_num) |
| 311 | *native_port_num = ib_port_num; |
| 312 | return ibdev->mdev; |
| 313 | } |
| 314 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 315 | if (native_port_num) |
| 316 | *native_port_num = 1; |
| 317 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 318 | port = &ibdev->port[ib_port_num - 1]; |
| 319 | if (!port) |
| 320 | return NULL; |
| 321 | |
| 322 | spin_lock(&port->mp.mpi_lock); |
| 323 | mpi = ibdev->port[ib_port_num - 1].mp.mpi; |
| 324 | if (mpi && !mpi->unaffiliate) { |
| 325 | mdev = mpi->mdev; |
| 326 | /* If it's the master no need to refcount, it'll exist |
| 327 | * as long as the ib_dev exists. |
| 328 | */ |
| 329 | if (!mpi->is_master) |
| 330 | mpi->mdev_refcnt++; |
| 331 | } |
| 332 | spin_unlock(&port->mp.mpi_lock); |
| 333 | |
| 334 | return mdev; |
| 335 | } |
| 336 | |
| 337 | void mlx5_ib_put_native_port_mdev(struct mlx5_ib_dev *ibdev, u8 port_num) |
| 338 | { |
| 339 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&ibdev->ib_dev, |
| 340 | port_num); |
| 341 | struct mlx5_ib_multiport_info *mpi; |
| 342 | struct mlx5_ib_port *port; |
| 343 | |
| 344 | if (!mlx5_core_mp_enabled(ibdev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 345 | return; |
| 346 | |
| 347 | port = &ibdev->port[port_num - 1]; |
| 348 | |
| 349 | spin_lock(&port->mp.mpi_lock); |
| 350 | mpi = ibdev->port[port_num - 1].mp.mpi; |
| 351 | if (mpi->is_master) |
| 352 | goto out; |
| 353 | |
| 354 | mpi->mdev_refcnt--; |
| 355 | if (mpi->unaffiliate) |
| 356 | complete(&mpi->unref_comp); |
| 357 | out: |
| 358 | spin_unlock(&port->mp.mpi_lock); |
| 359 | } |
| 360 | |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 361 | static int translate_eth_legacy_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 362 | u8 *active_width) |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 363 | { |
| 364 | switch (eth_proto_oper) { |
| 365 | case MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII): |
| 366 | case MLX5E_PROT_MASK(MLX5E_1000BASE_KX): |
| 367 | case MLX5E_PROT_MASK(MLX5E_100BASE_TX): |
| 368 | case MLX5E_PROT_MASK(MLX5E_1000BASE_T): |
| 369 | *active_width = IB_WIDTH_1X; |
| 370 | *active_speed = IB_SPEED_SDR; |
| 371 | break; |
| 372 | case MLX5E_PROT_MASK(MLX5E_10GBASE_T): |
| 373 | case MLX5E_PROT_MASK(MLX5E_10GBASE_CX4): |
| 374 | case MLX5E_PROT_MASK(MLX5E_10GBASE_KX4): |
| 375 | case MLX5E_PROT_MASK(MLX5E_10GBASE_KR): |
| 376 | case MLX5E_PROT_MASK(MLX5E_10GBASE_CR): |
| 377 | case MLX5E_PROT_MASK(MLX5E_10GBASE_SR): |
| 378 | case MLX5E_PROT_MASK(MLX5E_10GBASE_ER): |
| 379 | *active_width = IB_WIDTH_1X; |
| 380 | *active_speed = IB_SPEED_QDR; |
| 381 | break; |
| 382 | case MLX5E_PROT_MASK(MLX5E_25GBASE_CR): |
| 383 | case MLX5E_PROT_MASK(MLX5E_25GBASE_KR): |
| 384 | case MLX5E_PROT_MASK(MLX5E_25GBASE_SR): |
| 385 | *active_width = IB_WIDTH_1X; |
| 386 | *active_speed = IB_SPEED_EDR; |
| 387 | break; |
| 388 | case MLX5E_PROT_MASK(MLX5E_40GBASE_CR4): |
| 389 | case MLX5E_PROT_MASK(MLX5E_40GBASE_KR4): |
| 390 | case MLX5E_PROT_MASK(MLX5E_40GBASE_SR4): |
| 391 | case MLX5E_PROT_MASK(MLX5E_40GBASE_LR4): |
| 392 | *active_width = IB_WIDTH_4X; |
| 393 | *active_speed = IB_SPEED_QDR; |
| 394 | break; |
| 395 | case MLX5E_PROT_MASK(MLX5E_50GBASE_CR2): |
| 396 | case MLX5E_PROT_MASK(MLX5E_50GBASE_KR2): |
| 397 | case MLX5E_PROT_MASK(MLX5E_50GBASE_SR2): |
| 398 | *active_width = IB_WIDTH_1X; |
| 399 | *active_speed = IB_SPEED_HDR; |
| 400 | break; |
| 401 | case MLX5E_PROT_MASK(MLX5E_56GBASE_R4): |
| 402 | *active_width = IB_WIDTH_4X; |
| 403 | *active_speed = IB_SPEED_FDR; |
| 404 | break; |
| 405 | case MLX5E_PROT_MASK(MLX5E_100GBASE_CR4): |
| 406 | case MLX5E_PROT_MASK(MLX5E_100GBASE_SR4): |
| 407 | case MLX5E_PROT_MASK(MLX5E_100GBASE_KR4): |
| 408 | case MLX5E_PROT_MASK(MLX5E_100GBASE_LR4): |
| 409 | *active_width = IB_WIDTH_4X; |
| 410 | *active_speed = IB_SPEED_EDR; |
| 411 | break; |
| 412 | default: |
| 413 | return -EINVAL; |
| 414 | } |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 419 | static int translate_eth_ext_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 420 | u8 *active_width) |
| 421 | { |
| 422 | switch (eth_proto_oper) { |
| 423 | case MLX5E_PROT_MASK(MLX5E_SGMII_100M): |
| 424 | case MLX5E_PROT_MASK(MLX5E_1000BASE_X_SGMII): |
| 425 | *active_width = IB_WIDTH_1X; |
| 426 | *active_speed = IB_SPEED_SDR; |
| 427 | break; |
| 428 | case MLX5E_PROT_MASK(MLX5E_5GBASE_R): |
| 429 | *active_width = IB_WIDTH_1X; |
| 430 | *active_speed = IB_SPEED_DDR; |
| 431 | break; |
| 432 | case MLX5E_PROT_MASK(MLX5E_10GBASE_XFI_XAUI_1): |
| 433 | *active_width = IB_WIDTH_1X; |
| 434 | *active_speed = IB_SPEED_QDR; |
| 435 | break; |
| 436 | case MLX5E_PROT_MASK(MLX5E_40GBASE_XLAUI_4_XLPPI_4): |
| 437 | *active_width = IB_WIDTH_4X; |
| 438 | *active_speed = IB_SPEED_QDR; |
| 439 | break; |
| 440 | case MLX5E_PROT_MASK(MLX5E_25GAUI_1_25GBASE_CR_KR): |
| 441 | *active_width = IB_WIDTH_1X; |
| 442 | *active_speed = IB_SPEED_EDR; |
| 443 | break; |
| 444 | case MLX5E_PROT_MASK(MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2): |
Aya Levin | cd27287 | 2019-03-11 14:35:58 +0200 | [diff] [blame] | 445 | *active_width = IB_WIDTH_2X; |
| 446 | *active_speed = IB_SPEED_EDR; |
| 447 | break; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 448 | case MLX5E_PROT_MASK(MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR): |
| 449 | *active_width = IB_WIDTH_1X; |
| 450 | *active_speed = IB_SPEED_HDR; |
| 451 | break; |
Aya Levin | cd27287 | 2019-03-11 14:35:58 +0200 | [diff] [blame] | 452 | case MLX5E_PROT_MASK(MLX5E_CAUI_4_100GBASE_CR4_KR4): |
| 453 | *active_width = IB_WIDTH_4X; |
| 454 | *active_speed = IB_SPEED_EDR; |
| 455 | break; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 456 | case MLX5E_PROT_MASK(MLX5E_100GAUI_2_100GBASE_CR2_KR2): |
| 457 | *active_width = IB_WIDTH_2X; |
| 458 | *active_speed = IB_SPEED_HDR; |
| 459 | break; |
| 460 | case MLX5E_PROT_MASK(MLX5E_200GAUI_4_200GBASE_CR4_KR4): |
| 461 | *active_width = IB_WIDTH_4X; |
| 462 | *active_speed = IB_SPEED_HDR; |
| 463 | break; |
| 464 | default: |
| 465 | return -EINVAL; |
| 466 | } |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static int translate_eth_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 472 | u8 *active_width, bool ext) |
| 473 | { |
| 474 | return ext ? |
| 475 | translate_eth_ext_proto_oper(eth_proto_oper, active_speed, |
| 476 | active_width) : |
| 477 | translate_eth_legacy_proto_oper(eth_proto_oper, active_speed, |
| 478 | active_width); |
| 479 | } |
| 480 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 481 | static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, |
| 482 | struct ib_port_attr *props) |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 483 | { |
| 484 | struct mlx5_ib_dev *dev = to_mdev(device); |
Aya Levin | bc4e12f | 2019-02-12 22:55:43 -0800 | [diff] [blame] | 485 | u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {0}; |
Colin Ian King | da005f9 | 2018-01-09 15:55:43 +0000 | [diff] [blame] | 486 | struct mlx5_core_dev *mdev; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 487 | struct net_device *ndev, *upper; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 488 | enum ib_mtu ndev_ib_mtu; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 489 | bool put_mdev = true; |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 490 | u16 qkey_viol_cntr; |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 491 | u32 eth_prot_oper; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 492 | u8 mdev_port_num; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 493 | bool ext; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 494 | int err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 495 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 496 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 497 | if (!mdev) { |
| 498 | /* This means the port isn't affiliated yet. Get the |
| 499 | * info for the master port instead. |
| 500 | */ |
| 501 | put_mdev = false; |
| 502 | mdev = dev->mdev; |
| 503 | mdev_port_num = 1; |
| 504 | port_num = 1; |
| 505 | } |
| 506 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 507 | /* Possible bad flows are checked before filling out props so in case |
| 508 | * of an error it will still be zeroed out. |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 509 | * Use native port in case of reps |
Noa Osherovich | 50f22fd | 2017-04-20 20:53:32 +0300 | [diff] [blame] | 510 | */ |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 511 | if (dev->is_rep) |
| 512 | err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, |
| 513 | 1); |
| 514 | else |
| 515 | err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, |
| 516 | mdev_port_num); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 517 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 518 | goto out; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 519 | ext = MLX5_CAP_PCAM_FEATURE(dev->mdev, ptys_extended_ethernet); |
| 520 | eth_prot_oper = MLX5_GET_ETH_PROTO(ptys_reg, out, ext, eth_proto_oper); |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 521 | |
Honggang Li | 7672ed3 | 2018-03-16 10:37:13 +0800 | [diff] [blame] | 522 | props->active_width = IB_WIDTH_4X; |
| 523 | props->active_speed = IB_SPEED_QDR; |
| 524 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 525 | translate_eth_proto_oper(eth_prot_oper, &props->active_speed, |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 526 | &props->active_width, ext); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 527 | |
Jason Gunthorpe | 2f944c0 | 2018-07-04 15:57:48 +0300 | [diff] [blame] | 528 | props->port_cap_flags |= IB_PORT_CM_SUP; |
| 529 | props->ip_gids = true; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 530 | |
| 531 | props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev, |
| 532 | roce_address_table_size); |
| 533 | props->max_mtu = IB_MTU_4096; |
| 534 | props->max_msg_sz = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg); |
| 535 | props->pkey_tbl_len = 1; |
| 536 | props->state = IB_PORT_DOWN; |
| 537 | props->phys_state = 3; |
| 538 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 539 | mlx5_query_nic_vport_qkey_viol_cntr(mdev, &qkey_viol_cntr); |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 540 | props->qkey_viol_cntr = qkey_viol_cntr; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 541 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 542 | /* If this is a stub query for an unaffiliated port stop here */ |
| 543 | if (!put_mdev) |
| 544 | goto out; |
| 545 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 546 | ndev = mlx5_ib_get_netdev(device, port_num); |
| 547 | if (!ndev) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 548 | goto out; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 549 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 550 | if (dev->lag_active) { |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 551 | rcu_read_lock(); |
| 552 | upper = netdev_master_upper_dev_get_rcu(ndev); |
| 553 | if (upper) { |
| 554 | dev_put(ndev); |
| 555 | ndev = upper; |
| 556 | dev_hold(ndev); |
| 557 | } |
| 558 | rcu_read_unlock(); |
| 559 | } |
| 560 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 561 | if (netif_running(ndev) && netif_carrier_ok(ndev)) { |
| 562 | props->state = IB_PORT_ACTIVE; |
| 563 | props->phys_state = 5; |
| 564 | } |
| 565 | |
| 566 | ndev_ib_mtu = iboe_get_mtu(ndev->mtu); |
| 567 | |
| 568 | dev_put(ndev); |
| 569 | |
| 570 | props->active_mtu = min(props->max_mtu, ndev_ib_mtu); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 571 | out: |
| 572 | if (put_mdev) |
| 573 | mlx5_ib_put_native_port_mdev(dev, port_num); |
| 574 | return err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 575 | } |
| 576 | |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 577 | struct mlx5_ib_vlan_info { |
| 578 | u16 vlan_id; |
| 579 | bool vlan; |
| 580 | }; |
| 581 | |
| 582 | static int get_lower_dev_vlan(struct net_device *lower_dev, void *data) |
| 583 | { |
| 584 | struct mlx5_ib_vlan_info *vlan_info = data; |
| 585 | |
| 586 | if (is_vlan_dev(lower_dev)) { |
| 587 | vlan_info->vlan = true; |
| 588 | vlan_info->vlan_id = vlan_dev_vlan_id(lower_dev); |
| 589 | } |
| 590 | /* We are interested only in first level vlan device, so |
| 591 | * always return 1 to stop iterating over next level devices. |
| 592 | */ |
| 593 | return 1; |
| 594 | } |
| 595 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 596 | static int set_roce_addr(struct mlx5_ib_dev *dev, u8 port_num, |
| 597 | unsigned int index, const union ib_gid *gid, |
| 598 | const struct ib_gid_attr *attr) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 599 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 600 | enum ib_gid_type gid_type = IB_GID_TYPE_IB; |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 601 | struct mlx5_ib_vlan_info vlan_info = { }; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 602 | u8 roce_version = 0; |
| 603 | u8 roce_l3_type = 0; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 604 | u8 mac[ETH_ALEN]; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 605 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 606 | if (gid) { |
| 607 | gid_type = attr->gid_type; |
| 608 | ether_addr_copy(mac, attr->ndev->dev_addr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 609 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 610 | if (is_vlan_dev(attr->ndev)) { |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 611 | vlan_info.vlan = true; |
| 612 | vlan_info.vlan_id = vlan_dev_vlan_id(attr->ndev); |
| 613 | } else { |
| 614 | /* If the netdev is upper device and if it's lower |
| 615 | * lower device is vlan device, consider vlan id of |
| 616 | * the lower vlan device for this gid entry. |
| 617 | */ |
| 618 | rcu_read_lock(); |
| 619 | netdev_walk_all_lower_dev_rcu(attr->ndev, |
| 620 | get_lower_dev_vlan, &vlan_info); |
| 621 | rcu_read_unlock(); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 622 | } |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 623 | } |
| 624 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 625 | switch (gid_type) { |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 626 | case IB_GID_TYPE_IB: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 627 | roce_version = MLX5_ROCE_VERSION_1; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 628 | break; |
| 629 | case IB_GID_TYPE_ROCE_UDP_ENCAP: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 630 | roce_version = MLX5_ROCE_VERSION_2; |
| 631 | if (ipv6_addr_v4mapped((void *)gid)) |
| 632 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV4; |
| 633 | else |
| 634 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV6; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 635 | break; |
| 636 | |
| 637 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 638 | mlx5_ib_warn(dev, "Unexpected GID type %u\n", gid_type); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 639 | } |
| 640 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 641 | return mlx5_core_roce_gid_set(dev->mdev, index, roce_version, |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 642 | roce_l3_type, gid->raw, mac, |
| 643 | vlan_info.vlan, vlan_info.vlan_id, |
| 644 | port_num); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 645 | } |
| 646 | |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 647 | static int mlx5_ib_add_gid(const struct ib_gid_attr *attr, |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 648 | __always_unused void **context) |
| 649 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 650 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 651 | attr->index, &attr->gid, attr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 652 | } |
| 653 | |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 654 | static int mlx5_ib_del_gid(const struct ib_gid_attr *attr, |
| 655 | __always_unused void **context) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 656 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 657 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
| 658 | attr->index, NULL, NULL); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 659 | } |
| 660 | |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 661 | __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, |
| 662 | const struct ib_gid_attr *attr) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 663 | { |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 664 | if (attr->gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 665 | return 0; |
| 666 | |
| 667 | return cpu_to_be16(MLX5_CAP_ROCE(dev->mdev, r_roce_min_src_udp_port)); |
| 668 | } |
| 669 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 670 | static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) |
| 671 | { |
Noa Osherovich | 7fae665 | 2016-09-12 19:16:23 +0300 | [diff] [blame] | 672 | if (MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_IB) |
| 673 | return !MLX5_CAP_GEN(dev->mdev, ib_virt); |
| 674 | return 0; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | enum { |
| 678 | MLX5_VPORT_ACCESS_METHOD_MAD, |
| 679 | MLX5_VPORT_ACCESS_METHOD_HCA, |
| 680 | MLX5_VPORT_ACCESS_METHOD_NIC, |
| 681 | }; |
| 682 | |
| 683 | static int mlx5_get_vport_access_method(struct ib_device *ibdev) |
| 684 | { |
| 685 | if (mlx5_use_mad_ifc(to_mdev(ibdev))) |
| 686 | return MLX5_VPORT_ACCESS_METHOD_MAD; |
| 687 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 688 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 689 | IB_LINK_LAYER_ETHERNET) |
| 690 | return MLX5_VPORT_ACCESS_METHOD_NIC; |
| 691 | |
| 692 | return MLX5_VPORT_ACCESS_METHOD_HCA; |
| 693 | } |
| 694 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 695 | static void get_atomic_caps(struct mlx5_ib_dev *dev, |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 696 | u8 atomic_size_qp, |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 697 | struct ib_device_attr *props) |
| 698 | { |
| 699 | u8 tmp; |
| 700 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 701 | u8 atomic_req_8B_endianness_mode = |
Or Gerlitz | bd10838 | 2017-05-28 15:24:17 +0300 | [diff] [blame] | 702 | MLX5_CAP_ATOMIC(dev->mdev, atomic_req_8B_endianness_mode); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 703 | |
| 704 | /* Check if HW supports 8 bytes standard atomic operations and capable |
| 705 | * of host endianness respond |
| 706 | */ |
| 707 | tmp = MLX5_ATOMIC_OPS_CMP_SWAP | MLX5_ATOMIC_OPS_FETCH_ADD; |
| 708 | if (((atomic_operations & tmp) == tmp) && |
| 709 | (atomic_size_qp & MLX5_ATOMIC_SIZE_QP_8BYTES) && |
| 710 | (atomic_req_8B_endianness_mode)) { |
| 711 | props->atomic_cap = IB_ATOMIC_HCA; |
| 712 | } else { |
| 713 | props->atomic_cap = IB_ATOMIC_NONE; |
| 714 | } |
| 715 | } |
| 716 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 717 | static void get_atomic_caps_qp(struct mlx5_ib_dev *dev, |
| 718 | struct ib_device_attr *props) |
| 719 | { |
| 720 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 721 | |
| 722 | get_atomic_caps(dev, atomic_size_qp, props); |
| 723 | } |
| 724 | |
| 725 | static void get_atomic_caps_dc(struct mlx5_ib_dev *dev, |
| 726 | struct ib_device_attr *props) |
| 727 | { |
| 728 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc); |
| 729 | |
| 730 | get_atomic_caps(dev, atomic_size_qp, props); |
| 731 | } |
| 732 | |
| 733 | bool mlx5_ib_dc_atomic_is_supported(struct mlx5_ib_dev *dev) |
| 734 | { |
| 735 | struct ib_device_attr props = {}; |
| 736 | |
| 737 | get_atomic_caps_dc(dev, &props); |
| 738 | return (props.atomic_cap == IB_ATOMIC_HCA) ? true : false; |
| 739 | } |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 740 | static int mlx5_query_system_image_guid(struct ib_device *ibdev, |
| 741 | __be64 *sys_image_guid) |
| 742 | { |
| 743 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 744 | struct mlx5_core_dev *mdev = dev->mdev; |
| 745 | u64 tmp; |
| 746 | int err; |
| 747 | |
| 748 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 749 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 750 | return mlx5_query_mad_ifc_system_image_guid(ibdev, |
| 751 | sys_image_guid); |
| 752 | |
| 753 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 754 | err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 755 | break; |
| 756 | |
| 757 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 758 | err = mlx5_query_nic_vport_system_image_guid(mdev, &tmp); |
| 759 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 760 | |
| 761 | default: |
| 762 | return -EINVAL; |
| 763 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 764 | |
| 765 | if (!err) |
| 766 | *sys_image_guid = cpu_to_be64(tmp); |
| 767 | |
| 768 | return err; |
| 769 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | static int mlx5_query_max_pkeys(struct ib_device *ibdev, |
| 773 | u16 *max_pkeys) |
| 774 | { |
| 775 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 776 | struct mlx5_core_dev *mdev = dev->mdev; |
| 777 | |
| 778 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 779 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 780 | return mlx5_query_mad_ifc_max_pkeys(ibdev, max_pkeys); |
| 781 | |
| 782 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 783 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 784 | *max_pkeys = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, |
| 785 | pkey_table_size)); |
| 786 | return 0; |
| 787 | |
| 788 | default: |
| 789 | return -EINVAL; |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | static int mlx5_query_vendor_id(struct ib_device *ibdev, |
| 794 | u32 *vendor_id) |
| 795 | { |
| 796 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 797 | |
| 798 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 799 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 800 | return mlx5_query_mad_ifc_vendor_id(ibdev, vendor_id); |
| 801 | |
| 802 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 803 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 804 | return mlx5_core_query_vendor_id(dev->mdev, vendor_id); |
| 805 | |
| 806 | default: |
| 807 | return -EINVAL; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | static int mlx5_query_node_guid(struct mlx5_ib_dev *dev, |
| 812 | __be64 *node_guid) |
| 813 | { |
| 814 | u64 tmp; |
| 815 | int err; |
| 816 | |
| 817 | switch (mlx5_get_vport_access_method(&dev->ib_dev)) { |
| 818 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 819 | return mlx5_query_mad_ifc_node_guid(dev, node_guid); |
| 820 | |
| 821 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 822 | err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 823 | break; |
| 824 | |
| 825 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 826 | err = mlx5_query_nic_vport_node_guid(dev->mdev, &tmp); |
| 827 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 828 | |
| 829 | default: |
| 830 | return -EINVAL; |
| 831 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 832 | |
| 833 | if (!err) |
| 834 | *node_guid = cpu_to_be64(tmp); |
| 835 | |
| 836 | return err; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | struct mlx5_reg_node_desc { |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 840 | u8 desc[IB_DEVICE_NODE_DESC_MAX]; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 841 | }; |
| 842 | |
| 843 | static int mlx5_query_node_desc(struct mlx5_ib_dev *dev, char *node_desc) |
| 844 | { |
| 845 | struct mlx5_reg_node_desc in; |
| 846 | |
| 847 | if (mlx5_use_mad_ifc(dev)) |
| 848 | return mlx5_query_mad_ifc_node_desc(dev, node_desc); |
| 849 | |
| 850 | memset(&in, 0, sizeof(in)); |
| 851 | |
| 852 | return mlx5_core_access_reg(dev->mdev, &in, sizeof(in), node_desc, |
| 853 | sizeof(struct mlx5_reg_node_desc), |
| 854 | MLX5_REG_NODE_DESC, 0, 0); |
| 855 | } |
| 856 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 857 | static int mlx5_ib_query_device(struct ib_device *ibdev, |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 858 | struct ib_device_attr *props, |
| 859 | struct ib_udata *uhw) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 860 | { |
| 861 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 862 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 863 | int err = -ENOMEM; |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 864 | int max_sq_desc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 865 | int max_rq_sg; |
| 866 | int max_sq_sg; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 867 | u64 min_page_size = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 868 | bool raw_support = !mlx5_core_mp_enabled(mdev); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 869 | struct mlx5_ib_query_device_resp resp = {}; |
| 870 | size_t resp_len; |
| 871 | u64 max_tso; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 872 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 873 | resp_len = sizeof(resp.comp_mask) + sizeof(resp.response_length); |
| 874 | if (uhw->outlen && uhw->outlen < resp_len) |
| 875 | return -EINVAL; |
| 876 | else |
| 877 | resp.response_length = resp_len; |
| 878 | |
| 879 | if (uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen)) |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 880 | return -EINVAL; |
| 881 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 882 | memset(props, 0, sizeof(*props)); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 883 | err = mlx5_query_system_image_guid(ibdev, |
| 884 | &props->sys_image_guid); |
| 885 | if (err) |
| 886 | return err; |
| 887 | |
| 888 | err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys); |
| 889 | if (err) |
| 890 | return err; |
| 891 | |
| 892 | err = mlx5_query_vendor_id(ibdev, &props->vendor_id); |
| 893 | if (err) |
| 894 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 895 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 896 | props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) | |
| 897 | (fw_rev_min(dev->mdev) << 16) | |
| 898 | fw_rev_sub(dev->mdev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 899 | props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | |
| 900 | IB_DEVICE_PORT_ACTIVE_EVENT | |
| 901 | IB_DEVICE_SYS_IMAGE_GUID | |
Eli Cohen | 1a4c3a3 | 2014-02-06 17:41:25 +0200 | [diff] [blame] | 902 | IB_DEVICE_RC_RNR_NAK_GEN; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 903 | |
| 904 | if (MLX5_CAP_GEN(mdev, pkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 905 | props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 906 | if (MLX5_CAP_GEN(mdev, qkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 907 | props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 908 | if (MLX5_CAP_GEN(mdev, apm)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 909 | props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 910 | if (MLX5_CAP_GEN(mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 911 | props->device_cap_flags |= IB_DEVICE_XRC; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 912 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
| 913 | props->device_cap_flags |= IB_DEVICE_MEM_WINDOW | |
| 914 | IB_DEVICE_MEM_WINDOW_TYPE_2B; |
| 915 | props->max_mw = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 916 | /* We support 'Gappy' memory registration too */ |
| 917 | props->device_cap_flags |= IB_DEVICE_SG_GAPS_REG; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 918 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 919 | props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 920 | if (MLX5_CAP_GEN(mdev, sho)) { |
Sagi Grimberg | 2dea909 | 2014-02-23 14:19:13 +0200 | [diff] [blame] | 921 | props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER; |
| 922 | /* At this stage no support for signature handover */ |
| 923 | props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 | |
| 924 | IB_PROT_T10DIF_TYPE_2 | |
| 925 | IB_PROT_T10DIF_TYPE_3; |
| 926 | props->sig_guard_cap = IB_GUARD_T10DIF_CRC | |
| 927 | IB_GUARD_T10DIF_CSUM; |
| 928 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 929 | if (MLX5_CAP_GEN(mdev, block_lb_mc)) |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 930 | props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 931 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 932 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 933 | if (MLX5_CAP_ETH(mdev, csum_cap)) { |
| 934 | /* Legacy bit to support old userspace libraries */ |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 935 | props->device_cap_flags |= IB_DEVICE_RAW_IP_CSUM; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 936 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_IP_CSUM; |
| 937 | } |
| 938 | |
| 939 | if (MLX5_CAP_ETH(dev->mdev, vlan_cap)) |
| 940 | props->raw_packet_caps |= |
| 941 | IB_RAW_PACKET_CAP_CVLAN_STRIPPING; |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 942 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 943 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) { |
| 944 | max_tso = MLX5_CAP_ETH(mdev, max_lso_cap); |
| 945 | if (max_tso) { |
| 946 | resp.tso_caps.max_tso = 1 << max_tso; |
| 947 | resp.tso_caps.supported_qpts |= |
| 948 | 1 << IB_QPT_RAW_PACKET; |
| 949 | resp.response_length += sizeof(resp.tso_caps); |
| 950 | } |
| 951 | } |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 952 | |
| 953 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) { |
| 954 | resp.rss_caps.rx_hash_function = |
| 955 | MLX5_RX_HASH_FUNC_TOEPLITZ; |
| 956 | resp.rss_caps.rx_hash_fields_mask = |
| 957 | MLX5_RX_HASH_SRC_IPV4 | |
| 958 | MLX5_RX_HASH_DST_IPV4 | |
| 959 | MLX5_RX_HASH_SRC_IPV6 | |
| 960 | MLX5_RX_HASH_DST_IPV6 | |
| 961 | MLX5_RX_HASH_SRC_PORT_TCP | |
| 962 | MLX5_RX_HASH_DST_PORT_TCP | |
| 963 | MLX5_RX_HASH_SRC_PORT_UDP | |
Maor Gottlieb | 4e2b53a | 2017-12-24 14:51:25 +0200 | [diff] [blame] | 964 | MLX5_RX_HASH_DST_PORT_UDP | |
| 965 | MLX5_RX_HASH_INNER; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 966 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
| 967 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 968 | resp.rss_caps.rx_hash_fields_mask |= |
| 969 | MLX5_RX_HASH_IPSEC_SPI; |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 970 | resp.response_length += sizeof(resp.rss_caps); |
| 971 | } |
| 972 | } else { |
| 973 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) |
| 974 | resp.response_length += sizeof(resp.tso_caps); |
| 975 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) |
| 976 | resp.response_length += sizeof(resp.rss_caps); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 977 | } |
| 978 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 979 | if (MLX5_CAP_GEN(mdev, ipoib_basic_offloads)) { |
| 980 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 981 | props->device_cap_flags |= IB_DEVICE_UD_TSO; |
| 982 | } |
| 983 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 984 | if (MLX5_CAP_GEN(dev->mdev, rq_delay_drop) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 985 | MLX5_CAP_GEN(dev->mdev, general_notification_event) && |
| 986 | raw_support) |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 987 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_DELAY_DROP; |
| 988 | |
Yishai Hadas | 1d54f89 | 2017-06-08 16:15:11 +0300 | [diff] [blame] | 989 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
| 990 | MLX5_CAP_IPOIB_ENHANCED(mdev, csum_cap)) |
| 991 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 992 | |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 993 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 994 | MLX5_CAP_ETH(dev->mdev, scatter_fcs) && |
| 995 | raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 996 | /* Legacy bit to support old userspace libraries */ |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 997 | props->device_cap_flags |= IB_DEVICE_RAW_SCATTER_FCS; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 998 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_SCATTER_FCS; |
| 999 | } |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 1000 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 1001 | if (MLX5_CAP_DEV_MEM(mdev, memic)) { |
| 1002 | props->max_dm_size = |
| 1003 | MLX5_CAP_DEV_MEM(mdev, max_memic_size); |
| 1004 | } |
| 1005 | |
Maor Gottlieb | da6d6ba3 | 2016-06-04 15:15:28 +0300 | [diff] [blame] | 1006 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_BYPASS)) |
| 1007 | props->device_cap_flags |= IB_DEVICE_MANAGED_FLOW_STEERING; |
| 1008 | |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 1009 | if (MLX5_CAP_GEN(mdev, end_pad)) |
| 1010 | props->device_cap_flags |= IB_DEVICE_PCI_WRITE_END_PADDING; |
| 1011 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1012 | props->vendor_part_id = mdev->pdev->device; |
| 1013 | props->hw_ver = mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1014 | |
| 1015 | props->max_mr_size = ~0ull; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 1016 | props->page_size_cap = ~(min_page_size - 1); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1017 | props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp); |
| 1018 | props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
| 1019 | max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) / |
| 1020 | sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 1021 | max_sq_desc = min_t(int, MLX5_CAP_GEN(mdev, max_wqe_sz_sq), 512); |
| 1022 | max_sq_sg = (max_sq_desc - sizeof(struct mlx5_wqe_ctrl_seg) - |
| 1023 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 1024 | sizeof(struct mlx5_wqe_data_seg); |
Steve Wise | 33023fb | 2018-06-18 08:05:26 -0700 | [diff] [blame] | 1025 | props->max_send_sge = max_sq_sg; |
| 1026 | props->max_recv_sge = max_rq_sg; |
Sagi Grimberg | 986ef95 | 2016-03-31 19:03:25 +0300 | [diff] [blame] | 1027 | props->max_sge_rd = MLX5_MAX_SGE_RD; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1028 | props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq); |
Leon Romanovsky | 9f17768 | 2016-01-14 08:11:40 +0200 | [diff] [blame] | 1029 | 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] | 1030 | props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
| 1031 | props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd); |
| 1032 | props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp); |
| 1033 | props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp); |
| 1034 | props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq); |
| 1035 | props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1; |
| 1036 | 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] | 1037 | 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] | 1038 | props->max_srq_sge = max_rq_sg - 1; |
Sagi Grimberg | 911f433 | 2016-03-03 13:37:51 +0200 | [diff] [blame] | 1039 | props->max_fast_reg_page_list_len = |
| 1040 | 1 << MLX5_CAP_GEN(mdev, log_max_klm_list_size); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 1041 | get_atomic_caps_qp(dev, props); |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 1042 | props->masked_atomic_cap = IB_ATOMIC_NONE; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1043 | props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg); |
| 1044 | props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1045 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 1046 | props->max_mcast_grp; |
| 1047 | props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */ |
Maor Gottlieb | 86695a6 | 2016-10-27 16:36:38 +0300 | [diff] [blame] | 1048 | props->max_ah = INT_MAX; |
Matan Barak | 7c60bcb | 2015-12-15 20:30:11 +0200 | [diff] [blame] | 1049 | props->hca_core_clock = MLX5_CAP_GEN(mdev, device_frequency_khz); |
| 1050 | props->timestamp_mask = 0x7FFFFFFFFFFFFFFFULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1051 | |
Leon Romanovsky | e502b8b | 2019-01-08 16:07:24 +0200 | [diff] [blame] | 1052 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
| 1053 | if (MLX5_CAP_GEN(mdev, pg)) |
| 1054 | props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
| 1055 | props->odp_caps = dev->odp_caps; |
| 1056 | } |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 1057 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 1058 | if (MLX5_CAP_GEN(mdev, cd)) |
| 1059 | props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL; |
| 1060 | |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 1061 | if (!mlx5_core_is_pf(mdev)) |
| 1062 | props->device_cap_flags |= IB_DEVICE_VIRTUAL_FUNCTION; |
| 1063 | |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 1064 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1065 | IB_LINK_LAYER_ETHERNET && raw_support) { |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 1066 | props->rss_caps.max_rwq_indirection_tables = |
| 1067 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt); |
| 1068 | props->rss_caps.max_rwq_indirection_table_size = |
| 1069 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt_size); |
| 1070 | props->rss_caps.supported_qpts = 1 << IB_QPT_RAW_PACKET; |
| 1071 | props->max_wq_type_rq = |
| 1072 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rq); |
| 1073 | } |
| 1074 | |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1075 | if (MLX5_CAP_GEN(mdev, tag_matching)) { |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1076 | props->tm_caps.max_rndv_hdr_size = MLX5_TM_MAX_RNDV_MSG_SIZE; |
| 1077 | props->tm_caps.max_num_tags = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1078 | (1 << MLX5_CAP_GEN(mdev, log_tag_matching_list_sz)) - 1; |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1079 | props->tm_caps.flags = IB_TM_CAP_RC; |
| 1080 | props->tm_caps.max_ops = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1081 | 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1082 | props->tm_caps.max_sge = MLX5_TM_MAX_SGE; |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1083 | } |
| 1084 | |
Yonatan Cohen | 87ab3f5 | 2017-11-13 10:51:18 +0200 | [diff] [blame] | 1085 | if (MLX5_CAP_GEN(dev->mdev, cq_moderation)) { |
| 1086 | props->cq_caps.max_cq_moderation_count = |
| 1087 | MLX5_MAX_CQ_COUNT; |
| 1088 | props->cq_caps.max_cq_moderation_period = |
| 1089 | MLX5_MAX_CQ_PERIOD; |
| 1090 | } |
| 1091 | |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1092 | if (field_avail(typeof(resp), cqe_comp_caps, uhw->outlen)) { |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1093 | resp.response_length += sizeof(resp.cqe_comp_caps); |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 1094 | |
| 1095 | if (MLX5_CAP_GEN(dev->mdev, cqe_compression)) { |
| 1096 | resp.cqe_comp_caps.max_num = |
| 1097 | MLX5_CAP_GEN(dev->mdev, |
| 1098 | cqe_compression_max_num); |
| 1099 | |
| 1100 | resp.cqe_comp_caps.supported_format = |
| 1101 | MLX5_IB_CQE_RES_FORMAT_HASH | |
| 1102 | MLX5_IB_CQE_RES_FORMAT_CSUM; |
Yonatan Cohen | 6f1006a | 2018-05-27 13:42:34 +0300 | [diff] [blame] | 1103 | |
| 1104 | if (MLX5_CAP_GEN(dev->mdev, mini_cqe_resp_stride_index)) |
| 1105 | resp.cqe_comp_caps.supported_format |= |
| 1106 | MLX5_IB_CQE_RES_FORMAT_CSUM_STRIDX; |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 1107 | } |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1108 | } |
| 1109 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1110 | if (field_avail(typeof(resp), packet_pacing_caps, uhw->outlen) && |
| 1111 | raw_support) { |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 1112 | if (MLX5_CAP_QOS(mdev, packet_pacing) && |
| 1113 | MLX5_CAP_GEN(mdev, qos)) { |
| 1114 | resp.packet_pacing_caps.qp_rate_limit_max = |
| 1115 | MLX5_CAP_QOS(mdev, packet_pacing_max_rate); |
| 1116 | resp.packet_pacing_caps.qp_rate_limit_min = |
| 1117 | MLX5_CAP_QOS(mdev, packet_pacing_min_rate); |
| 1118 | resp.packet_pacing_caps.supported_qpts |= |
| 1119 | 1 << IB_QPT_RAW_PACKET; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 1120 | if (MLX5_CAP_QOS(mdev, packet_pacing_burst_bound) && |
| 1121 | MLX5_CAP_QOS(mdev, packet_pacing_typical_size)) |
| 1122 | resp.packet_pacing_caps.cap_flags |= |
| 1123 | MLX5_IB_PP_SUPPORT_BURST; |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 1124 | } |
| 1125 | resp.response_length += sizeof(resp.packet_pacing_caps); |
| 1126 | } |
| 1127 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1128 | if (field_avail(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes, |
| 1129 | uhw->outlen)) { |
Bodong Wang | 795b609 | 2017-08-17 15:52:34 +0300 | [diff] [blame] | 1130 | if (MLX5_CAP_ETH(mdev, multi_pkt_send_wqe)) |
| 1131 | resp.mlx5_ib_support_multi_pkt_send_wqes = |
| 1132 | MLX5_IB_ALLOW_MPW; |
Bodong Wang | 050da90 | 2017-08-17 15:52:35 +0300 | [diff] [blame] | 1133 | |
| 1134 | if (MLX5_CAP_ETH(mdev, enhanced_multi_pkt_send_wqe)) |
| 1135 | resp.mlx5_ib_support_multi_pkt_send_wqes |= |
| 1136 | MLX5_IB_SUPPORT_EMPW; |
| 1137 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1138 | resp.response_length += |
| 1139 | sizeof(resp.mlx5_ib_support_multi_pkt_send_wqes); |
| 1140 | } |
| 1141 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1142 | if (field_avail(typeof(resp), flags, uhw->outlen)) { |
| 1143 | resp.response_length += sizeof(resp.flags); |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1144 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1145 | if (MLX5_CAP_GEN(mdev, cqe_compression_128)) |
| 1146 | resp.flags |= |
| 1147 | MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_COMP; |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1148 | |
| 1149 | if (MLX5_CAP_GEN(mdev, cqe_128_always)) |
| 1150 | resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_PAD; |
Danit Goldberg | 7e11b91 | 2018-11-30 13:22:06 +0200 | [diff] [blame] | 1151 | if (MLX5_CAP_GEN(mdev, qp_packet_based)) |
| 1152 | resp.flags |= |
| 1153 | MLX5_IB_QUERY_DEV_RESP_PACKET_BASED_CREDIT_MODE; |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1154 | } |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1155 | |
Noa Osherovich | 96dc3fc | 2017-08-17 15:52:28 +0300 | [diff] [blame] | 1156 | if (field_avail(typeof(resp), sw_parsing_caps, |
| 1157 | uhw->outlen)) { |
| 1158 | resp.response_length += sizeof(resp.sw_parsing_caps); |
| 1159 | if (MLX5_CAP_ETH(mdev, swp)) { |
| 1160 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1161 | MLX5_IB_SW_PARSING; |
| 1162 | |
| 1163 | if (MLX5_CAP_ETH(mdev, swp_csum)) |
| 1164 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1165 | MLX5_IB_SW_PARSING_CSUM; |
| 1166 | |
| 1167 | if (MLX5_CAP_ETH(mdev, swp_lso)) |
| 1168 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1169 | MLX5_IB_SW_PARSING_LSO; |
| 1170 | |
| 1171 | if (resp.sw_parsing_caps.sw_parsing_offloads) |
| 1172 | resp.sw_parsing_caps.supported_qpts = |
| 1173 | BIT(IB_QPT_RAW_PACKET); |
| 1174 | } |
| 1175 | } |
| 1176 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1177 | if (field_avail(typeof(resp), striding_rq_caps, uhw->outlen) && |
| 1178 | raw_support) { |
Noa Osherovich | b4f3459 | 2017-10-17 18:01:12 +0300 | [diff] [blame] | 1179 | resp.response_length += sizeof(resp.striding_rq_caps); |
| 1180 | if (MLX5_CAP_GEN(mdev, striding_rq)) { |
| 1181 | resp.striding_rq_caps.min_single_stride_log_num_of_bytes = |
| 1182 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1183 | resp.striding_rq_caps.max_single_stride_log_num_of_bytes = |
| 1184 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1185 | resp.striding_rq_caps.min_single_wqe_log_num_of_strides = |
| 1186 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1187 | resp.striding_rq_caps.max_single_wqe_log_num_of_strides = |
| 1188 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1189 | resp.striding_rq_caps.supported_qpts = |
| 1190 | BIT(IB_QPT_RAW_PACKET); |
| 1191 | } |
| 1192 | } |
| 1193 | |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1194 | if (field_avail(typeof(resp), tunnel_offloads_caps, |
| 1195 | uhw->outlen)) { |
| 1196 | resp.response_length += sizeof(resp.tunnel_offloads_caps); |
| 1197 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan)) |
| 1198 | resp.tunnel_offloads_caps |= |
| 1199 | MLX5_IB_TUNNELED_OFFLOADS_VXLAN; |
| 1200 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_geneve_rx)) |
| 1201 | resp.tunnel_offloads_caps |= |
| 1202 | MLX5_IB_TUNNELED_OFFLOADS_GENEVE; |
| 1203 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_gre)) |
| 1204 | resp.tunnel_offloads_caps |= |
| 1205 | MLX5_IB_TUNNELED_OFFLOADS_GRE; |
Ariel Levkovich | e818e25 | 2018-05-13 14:33:35 +0300 | [diff] [blame] | 1206 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1207 | MLX5_FLEX_PROTO_CW_MPLS_GRE) |
| 1208 | resp.tunnel_offloads_caps |= |
| 1209 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_GRE; |
| 1210 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1211 | MLX5_FLEX_PROTO_CW_MPLS_UDP) |
| 1212 | resp.tunnel_offloads_caps |= |
| 1213 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_UDP; |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1214 | } |
| 1215 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1216 | if (uhw->outlen) { |
| 1217 | err = ib_copy_to_udata(uhw, &resp, resp.response_length); |
| 1218 | |
| 1219 | if (err) |
| 1220 | return err; |
| 1221 | } |
| 1222 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1223 | return 0; |
| 1224 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1225 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1226 | enum mlx5_ib_width { |
| 1227 | MLX5_IB_WIDTH_1X = 1 << 0, |
| 1228 | MLX5_IB_WIDTH_2X = 1 << 1, |
| 1229 | MLX5_IB_WIDTH_4X = 1 << 2, |
| 1230 | MLX5_IB_WIDTH_8X = 1 << 3, |
| 1231 | MLX5_IB_WIDTH_12X = 1 << 4 |
| 1232 | }; |
| 1233 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1234 | static void translate_active_width(struct ib_device *ibdev, u8 active_width, |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1235 | u8 *ib_width) |
| 1236 | { |
| 1237 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1238 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1239 | if (active_width & MLX5_IB_WIDTH_1X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1240 | *ib_width = IB_WIDTH_1X; |
Michael Guralnik | d764970 | 2018-12-09 11:49:54 +0200 | [diff] [blame] | 1241 | else if (active_width & MLX5_IB_WIDTH_2X) |
| 1242 | *ib_width = IB_WIDTH_2X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1243 | else if (active_width & MLX5_IB_WIDTH_4X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1244 | *ib_width = IB_WIDTH_4X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1245 | else if (active_width & MLX5_IB_WIDTH_8X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1246 | *ib_width = IB_WIDTH_8X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1247 | else if (active_width & MLX5_IB_WIDTH_12X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1248 | *ib_width = IB_WIDTH_12X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1249 | else { |
| 1250 | mlx5_ib_dbg(dev, "Invalid active_width %d, setting width to default value: 4x\n", |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1251 | (int)active_width); |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1252 | *ib_width = IB_WIDTH_4X; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1253 | } |
| 1254 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1255 | return; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | static int mlx5_mtu_to_ib_mtu(int mtu) |
| 1259 | { |
| 1260 | switch (mtu) { |
| 1261 | case 256: return 1; |
| 1262 | case 512: return 2; |
| 1263 | case 1024: return 3; |
| 1264 | case 2048: return 4; |
| 1265 | case 4096: return 5; |
| 1266 | default: |
| 1267 | pr_warn("invalid mtu\n"); |
| 1268 | return -1; |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | enum ib_max_vl_num { |
| 1273 | __IB_MAX_VL_0 = 1, |
| 1274 | __IB_MAX_VL_0_1 = 2, |
| 1275 | __IB_MAX_VL_0_3 = 3, |
| 1276 | __IB_MAX_VL_0_7 = 4, |
| 1277 | __IB_MAX_VL_0_14 = 5, |
| 1278 | }; |
| 1279 | |
| 1280 | enum mlx5_vl_hw_cap { |
| 1281 | MLX5_VL_HW_0 = 1, |
| 1282 | MLX5_VL_HW_0_1 = 2, |
| 1283 | MLX5_VL_HW_0_2 = 3, |
| 1284 | MLX5_VL_HW_0_3 = 4, |
| 1285 | MLX5_VL_HW_0_4 = 5, |
| 1286 | MLX5_VL_HW_0_5 = 6, |
| 1287 | MLX5_VL_HW_0_6 = 7, |
| 1288 | MLX5_VL_HW_0_7 = 8, |
| 1289 | MLX5_VL_HW_0_14 = 15 |
| 1290 | }; |
| 1291 | |
| 1292 | static int translate_max_vl_num(struct ib_device *ibdev, u8 vl_hw_cap, |
| 1293 | u8 *max_vl_num) |
| 1294 | { |
| 1295 | switch (vl_hw_cap) { |
| 1296 | case MLX5_VL_HW_0: |
| 1297 | *max_vl_num = __IB_MAX_VL_0; |
| 1298 | break; |
| 1299 | case MLX5_VL_HW_0_1: |
| 1300 | *max_vl_num = __IB_MAX_VL_0_1; |
| 1301 | break; |
| 1302 | case MLX5_VL_HW_0_3: |
| 1303 | *max_vl_num = __IB_MAX_VL_0_3; |
| 1304 | break; |
| 1305 | case MLX5_VL_HW_0_7: |
| 1306 | *max_vl_num = __IB_MAX_VL_0_7; |
| 1307 | break; |
| 1308 | case MLX5_VL_HW_0_14: |
| 1309 | *max_vl_num = __IB_MAX_VL_0_14; |
| 1310 | break; |
| 1311 | |
| 1312 | default: |
| 1313 | return -EINVAL; |
| 1314 | } |
| 1315 | |
| 1316 | return 0; |
| 1317 | } |
| 1318 | |
| 1319 | static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port, |
| 1320 | struct ib_port_attr *props) |
| 1321 | { |
| 1322 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1323 | struct mlx5_core_dev *mdev = dev->mdev; |
| 1324 | struct mlx5_hca_vport_context *rep; |
Saeed Mahameed | 046339e | 2016-04-22 00:33:03 +0300 | [diff] [blame] | 1325 | u16 max_mtu; |
| 1326 | u16 oper_mtu; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1327 | int err; |
| 1328 | u8 ib_link_width_oper; |
| 1329 | u8 vl_hw_cap; |
| 1330 | |
| 1331 | rep = kzalloc(sizeof(*rep), GFP_KERNEL); |
| 1332 | if (!rep) { |
| 1333 | err = -ENOMEM; |
| 1334 | goto out; |
| 1335 | } |
| 1336 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1337 | /* props being zeroed by the caller, avoid zeroing it here */ |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1338 | |
| 1339 | err = mlx5_query_hca_vport_context(mdev, 0, port, 0, rep); |
| 1340 | if (err) |
| 1341 | goto out; |
| 1342 | |
| 1343 | props->lid = rep->lid; |
| 1344 | props->lmc = rep->lmc; |
| 1345 | props->sm_lid = rep->sm_lid; |
| 1346 | props->sm_sl = rep->sm_sl; |
| 1347 | props->state = rep->vport_state; |
| 1348 | props->phys_state = rep->port_physical_state; |
| 1349 | props->port_cap_flags = rep->cap_mask1; |
| 1350 | props->gid_tbl_len = mlx5_get_gid_table_len(MLX5_CAP_GEN(mdev, gid_table_size)); |
| 1351 | props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg); |
| 1352 | props->pkey_tbl_len = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, pkey_table_size)); |
| 1353 | props->bad_pkey_cntr = rep->pkey_violation_counter; |
| 1354 | props->qkey_viol_cntr = rep->qkey_violation_counter; |
| 1355 | props->subnet_timeout = rep->subnet_timeout; |
| 1356 | props->init_type_reply = rep->init_type_reply; |
| 1357 | |
Michael Guralnik | 4106a75 | 2018-12-09 11:49:51 +0200 | [diff] [blame] | 1358 | if (props->port_cap_flags & IB_PORT_CAP_MASK2_SUP) |
| 1359 | props->port_cap_flags2 = rep->cap_mask2; |
| 1360 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1361 | err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); |
| 1362 | if (err) |
| 1363 | goto out; |
| 1364 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1365 | translate_active_width(ibdev, ib_link_width_oper, &props->active_width); |
| 1366 | |
Noa Osherovich | d5beb7f | 2016-06-02 10:47:53 +0300 | [diff] [blame] | 1367 | err = mlx5_query_port_ib_proto_oper(mdev, &props->active_speed, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1368 | if (err) |
| 1369 | goto out; |
| 1370 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1371 | mlx5_query_port_max_mtu(mdev, &max_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1372 | |
| 1373 | props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu); |
| 1374 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1375 | mlx5_query_port_oper_mtu(mdev, &oper_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1376 | |
| 1377 | props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu); |
| 1378 | |
| 1379 | err = mlx5_query_port_vl_hw_cap(mdev, &vl_hw_cap, port); |
| 1380 | if (err) |
| 1381 | goto out; |
| 1382 | |
| 1383 | err = translate_max_vl_num(ibdev, vl_hw_cap, |
| 1384 | &props->max_vl_num); |
| 1385 | out: |
| 1386 | kfree(rep); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1387 | return err; |
| 1388 | } |
| 1389 | |
| 1390 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 1391 | struct ib_port_attr *props) |
| 1392 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1393 | unsigned int count; |
| 1394 | int ret; |
| 1395 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1396 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1397 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1398 | ret = mlx5_query_mad_ifc_port(ibdev, port, props); |
| 1399 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1400 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1401 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1402 | ret = mlx5_query_hca_port(ibdev, port, props); |
| 1403 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1404 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1405 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1406 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1407 | break; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1408 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1409 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1410 | ret = -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1411 | } |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1412 | |
| 1413 | if (!ret && props) { |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1414 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1415 | struct mlx5_core_dev *mdev; |
| 1416 | bool put_mdev = true; |
| 1417 | |
| 1418 | mdev = mlx5_ib_get_native_port_mdev(dev, port, NULL); |
| 1419 | if (!mdev) { |
| 1420 | /* If the port isn't affiliated yet query the master. |
| 1421 | * The master and slave will have the same values. |
| 1422 | */ |
| 1423 | mdev = dev->mdev; |
| 1424 | port = 1; |
| 1425 | put_mdev = false; |
| 1426 | } |
| 1427 | count = mlx5_core_reserved_gids_count(mdev); |
| 1428 | if (put_mdev) |
| 1429 | mlx5_ib_put_native_port_mdev(dev, port); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1430 | props->gid_tbl_len -= count; |
| 1431 | } |
| 1432 | return ret; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1433 | } |
| 1434 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 1435 | static int mlx5_ib_rep_query_port(struct ib_device *ibdev, u8 port, |
| 1436 | struct ib_port_attr *props) |
| 1437 | { |
| 1438 | int ret; |
| 1439 | |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 1440 | /* Only link layer == ethernet is valid for representors |
| 1441 | * and we always use port 1 |
| 1442 | */ |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 1443 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1444 | if (ret || !props) |
| 1445 | return ret; |
| 1446 | |
| 1447 | /* We don't support GIDS */ |
| 1448 | props->gid_tbl_len = 0; |
| 1449 | |
| 1450 | return ret; |
| 1451 | } |
| 1452 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1453 | static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 1454 | union ib_gid *gid) |
| 1455 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1456 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1457 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1458 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1459 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1460 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1461 | return mlx5_query_mad_ifc_gids(ibdev, port, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1462 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1463 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1464 | return mlx5_query_hca_vport_gid(mdev, 0, port, 0, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1465 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1466 | default: |
| 1467 | return -EINVAL; |
| 1468 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1469 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1470 | } |
| 1471 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1472 | static int mlx5_query_hca_nic_pkey(struct ib_device *ibdev, u8 port, |
| 1473 | u16 index, u16 *pkey) |
| 1474 | { |
| 1475 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1476 | struct mlx5_core_dev *mdev; |
| 1477 | bool put_mdev = true; |
| 1478 | u8 mdev_port_num; |
| 1479 | int err; |
| 1480 | |
| 1481 | mdev = mlx5_ib_get_native_port_mdev(dev, port, &mdev_port_num); |
| 1482 | if (!mdev) { |
| 1483 | /* The port isn't affiliated yet, get the PKey from the master |
| 1484 | * port. For RoCE the PKey tables will be the same. |
| 1485 | */ |
| 1486 | put_mdev = false; |
| 1487 | mdev = dev->mdev; |
| 1488 | mdev_port_num = 1; |
| 1489 | } |
| 1490 | |
| 1491 | err = mlx5_query_hca_vport_pkey(mdev, 0, mdev_port_num, 0, |
| 1492 | index, pkey); |
| 1493 | if (put_mdev) |
| 1494 | mlx5_ib_put_native_port_mdev(dev, port); |
| 1495 | |
| 1496 | return err; |
| 1497 | } |
| 1498 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1499 | static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 1500 | u16 *pkey) |
| 1501 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1502 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1503 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1504 | return mlx5_query_mad_ifc_pkey(ibdev, port, index, pkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1505 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1506 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1507 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1508 | return mlx5_query_hca_nic_pkey(ibdev, port, index, pkey); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1509 | default: |
| 1510 | return -EINVAL; |
| 1511 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1512 | } |
| 1513 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1514 | static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask, |
| 1515 | struct ib_device_modify *props) |
| 1516 | { |
| 1517 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1518 | struct mlx5_reg_node_desc in; |
| 1519 | struct mlx5_reg_node_desc out; |
| 1520 | int err; |
| 1521 | |
| 1522 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 1523 | return -EOPNOTSUPP; |
| 1524 | |
| 1525 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 1526 | return 0; |
| 1527 | |
| 1528 | /* |
| 1529 | * If possible, pass node desc to FW, so it can generate |
| 1530 | * a 144 trap. If cmd fails, just ignore. |
| 1531 | */ |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1532 | memcpy(&in, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1533 | err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1534 | sizeof(out), MLX5_REG_NODE_DESC, 0, 1); |
| 1535 | if (err) |
| 1536 | return err; |
| 1537 | |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1538 | memcpy(ibdev->node_desc, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1539 | |
| 1540 | return err; |
| 1541 | } |
| 1542 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1543 | static int set_port_caps_atomic(struct mlx5_ib_dev *dev, u8 port_num, u32 mask, |
| 1544 | u32 value) |
| 1545 | { |
| 1546 | struct mlx5_hca_vport_context ctx = {}; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1547 | struct mlx5_core_dev *mdev; |
| 1548 | u8 mdev_port_num; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1549 | int err; |
| 1550 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1551 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 1552 | if (!mdev) |
| 1553 | return -ENODEV; |
| 1554 | |
| 1555 | 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] | 1556 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1557 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1558 | |
| 1559 | if (~ctx.cap_mask1_perm & mask) { |
| 1560 | mlx5_ib_warn(dev, "trying to change bitmask 0x%X but change supported 0x%X\n", |
| 1561 | mask, ctx.cap_mask1_perm); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1562 | err = -EINVAL; |
| 1563 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | ctx.cap_mask1 = value; |
| 1567 | ctx.cap_mask1_perm = mask; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1568 | err = mlx5_core_modify_hca_vport_context(mdev, 0, mdev_port_num, |
| 1569 | 0, &ctx); |
| 1570 | |
| 1571 | out: |
| 1572 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1573 | |
| 1574 | return err; |
| 1575 | } |
| 1576 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1577 | static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 1578 | struct ib_port_modify *props) |
| 1579 | { |
| 1580 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1581 | struct ib_port_attr attr; |
| 1582 | u32 tmp; |
| 1583 | int err; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1584 | u32 change_mask; |
| 1585 | u32 value; |
| 1586 | bool is_ib = (mlx5_ib_port_link_layer(ibdev, port) == |
| 1587 | IB_LINK_LAYER_INFINIBAND); |
| 1588 | |
Majd Dibbiny | ec25587 | 2017-08-23 08:35:42 +0300 | [diff] [blame] | 1589 | /* CM layer calls ib_modify_port() regardless of the link layer. For |
| 1590 | * Ethernet ports, qkey violation and Port capabilities are meaningless. |
| 1591 | */ |
| 1592 | if (!is_ib) |
| 1593 | return 0; |
| 1594 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1595 | if (MLX5_CAP_GEN(dev->mdev, ib_virt) && is_ib) { |
| 1596 | change_mask = props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1597 | value = ~props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1598 | return set_port_caps_atomic(dev, port, change_mask, value); |
| 1599 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1600 | |
| 1601 | mutex_lock(&dev->cap_mask_mutex); |
| 1602 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1603 | err = ib_query_port(ibdev, port, &attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1604 | if (err) |
| 1605 | goto out; |
| 1606 | |
| 1607 | tmp = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 1608 | ~props->clr_port_cap_mask; |
| 1609 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1610 | err = mlx5_set_port_caps(dev->mdev, port, tmp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1611 | |
| 1612 | out: |
| 1613 | mutex_unlock(&dev->cap_mask_mutex); |
| 1614 | return err; |
| 1615 | } |
| 1616 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1617 | static void print_lib_caps(struct mlx5_ib_dev *dev, u64 caps) |
| 1618 | { |
| 1619 | mlx5_ib_dbg(dev, "MLX5_LIB_CAP_4K_UAR = %s\n", |
| 1620 | caps & MLX5_LIB_CAP_4K_UAR ? "y" : "n"); |
| 1621 | } |
| 1622 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1623 | static u16 calc_dynamic_bfregs(int uars_per_sys_page) |
| 1624 | { |
| 1625 | /* Large page with non 4k uar support might limit the dynamic size */ |
| 1626 | if (uars_per_sys_page == 1 && PAGE_SIZE > 4096) |
| 1627 | return MLX5_MIN_DYN_BFREGS; |
| 1628 | |
| 1629 | return MLX5_MAX_DYN_BFREGS; |
| 1630 | } |
| 1631 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1632 | static int calc_total_bfregs(struct mlx5_ib_dev *dev, bool lib_uar_4k, |
| 1633 | struct mlx5_ib_alloc_ucontext_req_v2 *req, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1634 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1635 | { |
| 1636 | int uars_per_sys_page; |
| 1637 | int bfregs_per_sys_page; |
| 1638 | int ref_bfregs = req->total_num_bfregs; |
| 1639 | |
| 1640 | if (req->total_num_bfregs == 0) |
| 1641 | return -EINVAL; |
| 1642 | |
| 1643 | BUILD_BUG_ON(MLX5_MAX_BFREGS % MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1644 | BUILD_BUG_ON(MLX5_MAX_BFREGS < MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1645 | |
| 1646 | if (req->total_num_bfregs > MLX5_MAX_BFREGS) |
| 1647 | return -ENOMEM; |
| 1648 | |
| 1649 | uars_per_sys_page = get_uars_per_sys_page(dev, lib_uar_4k); |
| 1650 | 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] | 1651 | /* This holds the required static allocation asked by the user */ |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1652 | 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] | 1653 | if (req->num_low_latency_bfregs > req->total_num_bfregs - 1) |
| 1654 | return -EINVAL; |
| 1655 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1656 | bfregi->num_static_sys_pages = req->total_num_bfregs / bfregs_per_sys_page; |
| 1657 | bfregi->num_dyn_bfregs = ALIGN(calc_dynamic_bfregs(uars_per_sys_page), bfregs_per_sys_page); |
| 1658 | bfregi->total_num_bfregs = req->total_num_bfregs + bfregi->num_dyn_bfregs; |
| 1659 | bfregi->num_sys_pages = bfregi->total_num_bfregs / bfregs_per_sys_page; |
| 1660 | |
| 1661 | 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] | 1662 | MLX5_CAP_GEN(dev->mdev, uar_4k) ? "yes" : "no", |
| 1663 | lib_uar_4k ? "yes" : "no", ref_bfregs, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1664 | req->total_num_bfregs, bfregi->total_num_bfregs, |
| 1665 | bfregi->num_sys_pages); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1666 | |
| 1667 | return 0; |
| 1668 | } |
| 1669 | |
| 1670 | static int allocate_uars(struct mlx5_ib_dev *dev, struct mlx5_ib_ucontext *context) |
| 1671 | { |
| 1672 | struct mlx5_bfreg_info *bfregi; |
| 1673 | int err; |
| 1674 | int i; |
| 1675 | |
| 1676 | bfregi = &context->bfregi; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1677 | for (i = 0; i < bfregi->num_static_sys_pages; i++) { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1678 | err = mlx5_cmd_alloc_uar(dev->mdev, &bfregi->sys_pages[i]); |
| 1679 | if (err) |
| 1680 | goto error; |
| 1681 | |
| 1682 | mlx5_ib_dbg(dev, "allocated uar %d\n", bfregi->sys_pages[i]); |
| 1683 | } |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1684 | |
| 1685 | for (i = bfregi->num_static_sys_pages; i < bfregi->num_sys_pages; i++) |
| 1686 | bfregi->sys_pages[i] = MLX5_IB_INVALID_UAR_INDEX; |
| 1687 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1688 | return 0; |
| 1689 | |
| 1690 | error: |
| 1691 | for (--i; i >= 0; i--) |
| 1692 | if (mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i])) |
| 1693 | mlx5_ib_warn(dev, "failed to free uar %d\n", i); |
| 1694 | |
| 1695 | return err; |
| 1696 | } |
| 1697 | |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1698 | static void deallocate_uars(struct mlx5_ib_dev *dev, |
| 1699 | struct mlx5_ib_ucontext *context) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1700 | { |
| 1701 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1702 | int i; |
| 1703 | |
| 1704 | bfregi = &context->bfregi; |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1705 | for (i = 0; i < bfregi->num_sys_pages; i++) |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1706 | if (i < bfregi->num_static_sys_pages || |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1707 | bfregi->sys_pages[i] != MLX5_IB_INVALID_UAR_INDEX) |
| 1708 | mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i]); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1709 | } |
| 1710 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1711 | int mlx5_ib_enable_lb(struct mlx5_ib_dev *dev, bool td, bool qp) |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1712 | { |
| 1713 | int err = 0; |
| 1714 | |
| 1715 | mutex_lock(&dev->lb.mutex); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1716 | if (td) |
| 1717 | dev->lb.user_td++; |
| 1718 | if (qp) |
| 1719 | dev->lb.qps++; |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1720 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1721 | if (dev->lb.user_td == 2 || |
| 1722 | dev->lb.qps == 1) { |
| 1723 | if (!dev->lb.enabled) { |
| 1724 | err = mlx5_nic_vport_update_local_lb(dev->mdev, true); |
| 1725 | dev->lb.enabled = true; |
| 1726 | } |
| 1727 | } |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1728 | |
| 1729 | mutex_unlock(&dev->lb.mutex); |
| 1730 | |
| 1731 | return err; |
| 1732 | } |
| 1733 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1734 | void mlx5_ib_disable_lb(struct mlx5_ib_dev *dev, bool td, bool qp) |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1735 | { |
| 1736 | mutex_lock(&dev->lb.mutex); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1737 | if (td) |
| 1738 | dev->lb.user_td--; |
| 1739 | if (qp) |
| 1740 | dev->lb.qps--; |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1741 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1742 | if (dev->lb.user_td == 1 && |
| 1743 | dev->lb.qps == 0) { |
| 1744 | if (dev->lb.enabled) { |
| 1745 | mlx5_nic_vport_update_local_lb(dev->mdev, false); |
| 1746 | dev->lb.enabled = false; |
| 1747 | } |
| 1748 | } |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1749 | |
| 1750 | mutex_unlock(&dev->lb.mutex); |
| 1751 | } |
| 1752 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1753 | static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn, |
| 1754 | u16 uid) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1755 | { |
| 1756 | int err; |
| 1757 | |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1758 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1759 | return 0; |
| 1760 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1761 | err = mlx5_cmd_alloc_transport_domain(dev->mdev, tdn, uid); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1762 | if (err) |
| 1763 | return err; |
| 1764 | |
| 1765 | if ((MLX5_CAP_GEN(dev->mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH) || |
Eran Ben Elisha | 8978cc9 | 2018-01-09 11:41:10 +0200 | [diff] [blame] | 1766 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1767 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1768 | return err; |
| 1769 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1770 | return mlx5_ib_enable_lb(dev, true, false); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1771 | } |
| 1772 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1773 | static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn, |
| 1774 | u16 uid) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1775 | { |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1776 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1777 | return; |
| 1778 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1779 | mlx5_cmd_dealloc_transport_domain(dev->mdev, tdn, uid); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1780 | |
| 1781 | if ((MLX5_CAP_GEN(dev->mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH) || |
Eran Ben Elisha | 8978cc9 | 2018-01-09 11:41:10 +0200 | [diff] [blame] | 1782 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1783 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1784 | return; |
| 1785 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1786 | mlx5_ib_disable_lb(dev, true, false); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1787 | } |
| 1788 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1789 | static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx, |
| 1790 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1791 | { |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1792 | struct ib_device *ibdev = uctx->device; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1793 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1794 | struct mlx5_ib_alloc_ucontext_req_v2 req = {}; |
| 1795 | struct mlx5_ib_alloc_ucontext_resp resp = {}; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1796 | struct mlx5_core_dev *mdev = dev->mdev; |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1797 | struct mlx5_ib_ucontext *context = to_mucontext(uctx); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1798 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1799 | int ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1800 | int err; |
Majd Dibbiny | a168a41c | 2016-01-28 17:51:47 +0200 | [diff] [blame] | 1801 | size_t min_req_v2 = offsetof(struct mlx5_ib_alloc_ucontext_req_v2, |
| 1802 | max_cqe_version); |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1803 | u32 dump_fill_mkey; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1804 | bool lib_uar_4k; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1805 | |
| 1806 | if (!dev->ib_active) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1807 | return -EAGAIN; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1808 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1809 | if (udata->inlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1810 | ver = 0; |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1811 | else if (udata->inlen >= min_req_v2) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1812 | ver = 2; |
| 1813 | else |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1814 | return -EINVAL; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1815 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1816 | err = ib_copy_from_udata(&req, udata, min(udata->inlen, sizeof(req))); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1817 | if (err) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1818 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1819 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1820 | if (req.flags & ~MLX5_IB_ALLOC_UCTX_DEVX) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1821 | return -EOPNOTSUPP; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1822 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1823 | if (req.comp_mask || req.reserved0 || req.reserved1 || req.reserved2) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1824 | return -EOPNOTSUPP; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1825 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1826 | req.total_num_bfregs = ALIGN(req.total_num_bfregs, |
| 1827 | MLX5_NON_FP_BFREGS_PER_UAR); |
| 1828 | if (req.num_low_latency_bfregs > req.total_num_bfregs - 1) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1829 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1830 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1831 | 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] | 1832 | if (mlx5_core_is_pf(dev->mdev) && MLX5_CAP_GEN(dev->mdev, bf)) |
| 1833 | 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] | 1834 | resp.cache_line_size = cache_line_size(); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1835 | resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); |
| 1836 | resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); |
| 1837 | resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1838 | resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1839 | 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] | 1840 | resp.cqe_version = min_t(__u8, |
| 1841 | (__u8)MLX5_CAP_GEN(dev->mdev, cqe_version), |
| 1842 | req.max_cqe_version); |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1843 | resp.log_uar_size = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1844 | MLX5_ADAPTER_PAGE_SHIFT : PAGE_SHIFT; |
| 1845 | resp.num_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1846 | MLX5_CAP_GEN(dev->mdev, num_of_uars_per_page) : 1; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1847 | resp.response_length = min(offsetof(typeof(resp), response_length) + |
| 1848 | sizeof(resp.response_length), udata->outlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1849 | |
Matan Barak | c03faa5 | 2018-03-28 09:27:54 +0300 | [diff] [blame] | 1850 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_DEVICE) { |
| 1851 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_EGRESS)) |
| 1852 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM; |
| 1853 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_REQUIRED_METADATA) |
| 1854 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_REQ_METADATA; |
| 1855 | if (MLX5_CAP_FLOWTABLE(dev->mdev, flow_table_properties_nic_receive.ft_field_support.outer_esp_spi)) |
| 1856 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_SPI_STEERING; |
| 1857 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_TX_IV_IS_ESN) |
| 1858 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_TX_IV_IS_ESN; |
| 1859 | /* MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_FULL_OFFLOAD is currently always 0 */ |
| 1860 | } |
| 1861 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1862 | lib_uar_4k = req.lib_caps & MLX5_LIB_CAP_4K_UAR; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1863 | bfregi = &context->bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1864 | |
| 1865 | /* updates req->total_num_bfregs */ |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1866 | err = calc_total_bfregs(dev, lib_uar_4k, &req, bfregi); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1867 | if (err) |
| 1868 | goto out_ctx; |
| 1869 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1870 | mutex_init(&bfregi->lock); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1871 | bfregi->lib_uar_4k = lib_uar_4k; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1872 | bfregi->count = kcalloc(bfregi->total_num_bfregs, sizeof(*bfregi->count), |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1873 | GFP_KERNEL); |
| 1874 | if (!bfregi->count) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1875 | err = -ENOMEM; |
| 1876 | goto out_ctx; |
| 1877 | } |
| 1878 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1879 | bfregi->sys_pages = kcalloc(bfregi->num_sys_pages, |
| 1880 | sizeof(*bfregi->sys_pages), |
| 1881 | GFP_KERNEL); |
| 1882 | if (!bfregi->sys_pages) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1883 | err = -ENOMEM; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1884 | goto out_count; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1885 | } |
| 1886 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1887 | err = allocate_uars(dev, context); |
| 1888 | if (err) |
| 1889 | goto out_sys_pages; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1890 | |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 1891 | if (ibdev->attrs.device_cap_flags & IB_DEVICE_ON_DEMAND_PAGING) |
| 1892 | context->ibucontext.invalidate_range = |
| 1893 | &mlx5_ib_invalidate_range; |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 1894 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1895 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) { |
Yishai Hadas | fb98153 | 2018-11-26 08:28:36 +0200 | [diff] [blame] | 1896 | err = mlx5_ib_devx_create(dev, true); |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1897 | if (err < 0) |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1898 | goto out_uars; |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1899 | context->devx_uid = err; |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1900 | } |
| 1901 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1902 | err = mlx5_ib_alloc_transport_domain(dev, &context->tdn, |
| 1903 | context->devx_uid); |
| 1904 | if (err) |
| 1905 | goto out_devx; |
| 1906 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1907 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1908 | err = mlx5_cmd_dump_fill_mkey(dev->mdev, &dump_fill_mkey); |
| 1909 | if (err) |
Jason Gunthorpe | 8193abb | 2018-07-04 13:19:46 -0600 | [diff] [blame] | 1910 | goto out_mdev; |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1911 | } |
| 1912 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1913 | INIT_LIST_HEAD(&context->db_page_list); |
| 1914 | mutex_init(&context->db_page_mutex); |
| 1915 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1916 | resp.tot_bfregs = req.total_num_bfregs; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 1917 | resp.num_ports = dev->num_ports; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1918 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1919 | if (field_avail(typeof(resp), cqe_version, udata->outlen)) |
| 1920 | resp.response_length += sizeof(resp.cqe_version); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1921 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1922 | if (field_avail(typeof(resp), cmds_supp_uhw, udata->outlen)) { |
Moni Shoua | 6ad279c5 | 2016-11-23 08:23:23 +0200 | [diff] [blame] | 1923 | resp.cmds_supp_uhw |= MLX5_USER_CMDS_SUPP_UHW_QUERY_DEVICE | |
| 1924 | MLX5_USER_CMDS_SUPP_UHW_CREATE_AH; |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1925 | resp.response_length += sizeof(resp.cmds_supp_uhw); |
| 1926 | } |
| 1927 | |
Or Gerlitz | 7898489 | 2016-11-30 20:33:33 +0200 | [diff] [blame] | 1928 | if (field_avail(typeof(resp), eth_min_inline, udata->outlen)) { |
| 1929 | if (mlx5_ib_port_link_layer(ibdev, 1) == IB_LINK_LAYER_ETHERNET) { |
| 1930 | mlx5_query_min_inline(dev->mdev, &resp.eth_min_inline); |
| 1931 | resp.eth_min_inline++; |
| 1932 | } |
| 1933 | resp.response_length += sizeof(resp.eth_min_inline); |
| 1934 | } |
| 1935 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1936 | if (field_avail(typeof(resp), clock_info_versions, udata->outlen)) { |
| 1937 | if (mdev->clock_info) |
| 1938 | resp.clock_info_versions = BIT(MLX5_IB_CLOCK_INFO_V1); |
| 1939 | resp.response_length += sizeof(resp.clock_info_versions); |
| 1940 | } |
| 1941 | |
Noa Osherovich | bc5c6ee | 2016-06-04 15:15:31 +0300 | [diff] [blame] | 1942 | /* |
| 1943 | * We don't want to expose information from the PCI bar that is located |
| 1944 | * after 4096 bytes, so if the arch only supports larger pages, let's |
| 1945 | * pretend we don't support reading the HCA's core clock. This is also |
| 1946 | * forced by mmap function. |
| 1947 | */ |
Eli Cohen | de8d6e0 | 2017-01-03 23:55:19 +0200 | [diff] [blame] | 1948 | if (field_avail(typeof(resp), hca_core_clock_offset, udata->outlen)) { |
| 1949 | if (PAGE_SIZE <= 4096) { |
| 1950 | resp.comp_mask |= |
| 1951 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET; |
| 1952 | resp.hca_core_clock_offset = |
| 1953 | offsetof(struct mlx5_init_seg, internal_timer_h) % PAGE_SIZE; |
| 1954 | } |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1955 | resp.response_length += sizeof(resp.hca_core_clock_offset); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1956 | } |
| 1957 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1958 | if (field_avail(typeof(resp), log_uar_size, udata->outlen)) |
| 1959 | resp.response_length += sizeof(resp.log_uar_size); |
| 1960 | |
| 1961 | if (field_avail(typeof(resp), num_uars_per_page, udata->outlen)) |
| 1962 | resp.response_length += sizeof(resp.num_uars_per_page); |
| 1963 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1964 | if (field_avail(typeof(resp), num_dyn_bfregs, udata->outlen)) { |
| 1965 | resp.num_dyn_bfregs = bfregi->num_dyn_bfregs; |
| 1966 | resp.response_length += sizeof(resp.num_dyn_bfregs); |
| 1967 | } |
| 1968 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1969 | if (field_avail(typeof(resp), dump_fill_mkey, udata->outlen)) { |
| 1970 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1971 | resp.dump_fill_mkey = dump_fill_mkey; |
| 1972 | resp.comp_mask |= |
| 1973 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_DUMP_FILL_MKEY; |
| 1974 | } |
| 1975 | resp.response_length += sizeof(resp.dump_fill_mkey); |
| 1976 | } |
| 1977 | |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1978 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1979 | if (err) |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1980 | goto out_mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1981 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1982 | bfregi->ver = ver; |
| 1983 | bfregi->num_low_latency_bfregs = req.num_low_latency_bfregs; |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1984 | context->cqe_version = resp.cqe_version; |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1985 | context->lib_caps = req.lib_caps; |
| 1986 | print_lib_caps(dev, context->lib_caps); |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1987 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 1988 | if (dev->lag_active) { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 1989 | u8 port = mlx5_core_native_port_num(dev->mdev) - 1; |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 1990 | |
| 1991 | atomic_set(&context->tx_port_affinity, |
| 1992 | atomic_add_return( |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 1993 | 1, &dev->port[port].roce.tx_port_affinity)); |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 1994 | } |
| 1995 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1996 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1997 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1998 | out_mdev: |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1999 | mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid); |
| 2000 | out_devx: |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 2001 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 2002 | mlx5_ib_devx_destroy(dev, context->devx_uid); |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 2003 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2004 | out_uars: |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2005 | deallocate_uars(dev, context); |
| 2006 | |
| 2007 | out_sys_pages: |
| 2008 | kfree(bfregi->sys_pages); |
| 2009 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2010 | out_count: |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2011 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2012 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2013 | out_ctx: |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 2014 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2015 | } |
| 2016 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 2017 | static void mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2018 | { |
| 2019 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 2020 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2021 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2022 | |
Jason Gunthorpe | f27a0d5 | 2018-09-16 20:48:08 +0300 | [diff] [blame] | 2023 | /* All umem's must be destroyed before destroying the ucontext. */ |
| 2024 | mutex_lock(&ibcontext->per_mm_list_lock); |
| 2025 | WARN_ON(!list_empty(&ibcontext->per_mm_list)); |
| 2026 | mutex_unlock(&ibcontext->per_mm_list_lock); |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 2027 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2028 | bfregi = &context->bfregi; |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 2029 | mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid); |
| 2030 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2031 | if (context->devx_uid) |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 2032 | mlx5_ib_devx_destroy(dev, context->devx_uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2033 | |
| 2034 | deallocate_uars(dev, context); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2035 | kfree(bfregi->sys_pages); |
| 2036 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, |
| 2040 | int uar_idx) |
| 2041 | { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2042 | int fw_uars_per_page; |
| 2043 | |
| 2044 | fw_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? MLX5_UARS_IN_PAGE : 1; |
| 2045 | |
Huy Nguyen | aa8106f | 2019-03-29 15:38:01 -0700 | [diff] [blame] | 2046 | return (dev->mdev->bar_addr >> PAGE_SHIFT) + uar_idx / fw_uars_per_page; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | static int get_command(unsigned long offset) |
| 2050 | { |
| 2051 | return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK; |
| 2052 | } |
| 2053 | |
| 2054 | static int get_arg(unsigned long offset) |
| 2055 | { |
| 2056 | return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1); |
| 2057 | } |
| 2058 | |
| 2059 | static int get_index(unsigned long offset) |
| 2060 | { |
| 2061 | return get_arg(offset); |
| 2062 | } |
| 2063 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2064 | /* Index resides in an extra byte to enable larger values than 255 */ |
| 2065 | static int get_extended_index(unsigned long offset) |
| 2066 | { |
| 2067 | return get_arg(offset) | ((offset >> 16) & 0xff) << 8; |
| 2068 | } |
| 2069 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2070 | |
| 2071 | static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) |
| 2072 | { |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2073 | } |
| 2074 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2075 | static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd) |
| 2076 | { |
| 2077 | switch (cmd) { |
| 2078 | case MLX5_IB_MMAP_WC_PAGE: |
| 2079 | return "WC"; |
| 2080 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2081 | return "best effort WC"; |
| 2082 | case MLX5_IB_MMAP_NC_PAGE: |
| 2083 | return "NC"; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2084 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2085 | return "Device Memory"; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2086 | default: |
| 2087 | return NULL; |
| 2088 | } |
| 2089 | } |
| 2090 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2091 | static int mlx5_ib_mmap_clock_info_page(struct mlx5_ib_dev *dev, |
| 2092 | struct vm_area_struct *vma, |
| 2093 | struct mlx5_ib_ucontext *context) |
| 2094 | { |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2095 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2096 | return -EINVAL; |
| 2097 | |
| 2098 | if (get_index(vma->vm_pgoff) != MLX5_IB_CLOCK_INFO_V1) |
| 2099 | return -EOPNOTSUPP; |
| 2100 | |
| 2101 | if (vma->vm_flags & VM_WRITE) |
| 2102 | return -EPERM; |
| 2103 | |
| 2104 | if (!dev->mdev->clock_info_page) |
| 2105 | return -EOPNOTSUPP; |
| 2106 | |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2107 | return rdma_user_mmap_page(&context->ibucontext, vma, |
| 2108 | dev->mdev->clock_info_page, PAGE_SIZE); |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2109 | } |
| 2110 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2111 | 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] | 2112 | struct vm_area_struct *vma, |
| 2113 | struct mlx5_ib_ucontext *context) |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2114 | { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2115 | struct mlx5_bfreg_info *bfregi = &context->bfregi; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2116 | int err; |
| 2117 | unsigned long idx; |
Kamal Heib | aa09ea6 | 2018-07-19 00:05:32 +0300 | [diff] [blame] | 2118 | phys_addr_t pfn; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2119 | pgprot_t prot; |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2120 | u32 bfreg_dyn_idx = 0; |
| 2121 | u32 uar_index; |
| 2122 | int dyn_uar = (cmd == MLX5_IB_MMAP_ALLOC_WC); |
| 2123 | int max_valid_idx = dyn_uar ? bfregi->num_sys_pages : |
| 2124 | bfregi->num_static_sys_pages; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2125 | |
| 2126 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2127 | return -EINVAL; |
| 2128 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2129 | if (dyn_uar) |
| 2130 | idx = get_extended_index(vma->vm_pgoff) + bfregi->num_static_sys_pages; |
| 2131 | else |
| 2132 | idx = get_index(vma->vm_pgoff); |
| 2133 | |
| 2134 | if (idx >= max_valid_idx) { |
| 2135 | mlx5_ib_warn(dev, "invalid uar index %lu, max=%d\n", |
| 2136 | idx, max_valid_idx); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2137 | return -EINVAL; |
| 2138 | } |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2139 | |
| 2140 | switch (cmd) { |
| 2141 | case MLX5_IB_MMAP_WC_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2142 | case MLX5_IB_MMAP_ALLOC_WC: |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2143 | /* Some architectures don't support WC memory */ |
| 2144 | #if defined(CONFIG_X86) |
| 2145 | if (!pat_enabled()) |
| 2146 | return -EPERM; |
| 2147 | #elif !(defined(CONFIG_PPC) || (defined(CONFIG_ARM) && defined(CONFIG_MMU))) |
| 2148 | return -EPERM; |
| 2149 | #endif |
| 2150 | /* fall through */ |
| 2151 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2152 | /* For MLX5_IB_MMAP_REGULAR_PAGE do the best effort to get WC */ |
| 2153 | prot = pgprot_writecombine(vma->vm_page_prot); |
| 2154 | break; |
| 2155 | case MLX5_IB_MMAP_NC_PAGE: |
| 2156 | prot = pgprot_noncached(vma->vm_page_prot); |
| 2157 | break; |
| 2158 | default: |
| 2159 | return -EINVAL; |
| 2160 | } |
| 2161 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2162 | if (dyn_uar) { |
| 2163 | int uars_per_page; |
| 2164 | |
| 2165 | uars_per_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k); |
| 2166 | bfreg_dyn_idx = idx * (uars_per_page * MLX5_NON_FP_BFREGS_PER_UAR); |
| 2167 | if (bfreg_dyn_idx >= bfregi->total_num_bfregs) { |
| 2168 | mlx5_ib_warn(dev, "invalid bfreg_dyn_idx %u, max=%u\n", |
| 2169 | bfreg_dyn_idx, bfregi->total_num_bfregs); |
| 2170 | return -EINVAL; |
| 2171 | } |
| 2172 | |
| 2173 | mutex_lock(&bfregi->lock); |
| 2174 | /* Fail if uar already allocated, first bfreg index of each |
| 2175 | * page holds its count. |
| 2176 | */ |
| 2177 | if (bfregi->count[bfreg_dyn_idx]) { |
| 2178 | mlx5_ib_warn(dev, "wrong offset, idx %lu is busy, bfregn=%u\n", idx, bfreg_dyn_idx); |
| 2179 | mutex_unlock(&bfregi->lock); |
| 2180 | return -EINVAL; |
| 2181 | } |
| 2182 | |
| 2183 | bfregi->count[bfreg_dyn_idx]++; |
| 2184 | mutex_unlock(&bfregi->lock); |
| 2185 | |
| 2186 | err = mlx5_cmd_alloc_uar(dev->mdev, &uar_index); |
| 2187 | if (err) { |
| 2188 | mlx5_ib_warn(dev, "UAR alloc failed\n"); |
| 2189 | goto free_bfreg; |
| 2190 | } |
| 2191 | } else { |
| 2192 | uar_index = bfregi->sys_pages[idx]; |
| 2193 | } |
| 2194 | |
| 2195 | pfn = uar_index2pfn(dev, uar_index); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2196 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn %pa\n", idx, &pfn); |
| 2197 | |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2198 | err = rdma_user_mmap_io(&context->ibucontext, vma, pfn, PAGE_SIZE, |
| 2199 | prot); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2200 | if (err) { |
Leon Romanovsky | 8f06228 | 2018-05-22 08:31:03 +0300 | [diff] [blame] | 2201 | mlx5_ib_err(dev, |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2202 | "rdma_user_mmap_io failed with error=%d, mmap_cmd=%s\n", |
Leon Romanovsky | 8f06228 | 2018-05-22 08:31:03 +0300 | [diff] [blame] | 2203 | err, mmap_cmd2str(cmd)); |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2204 | goto err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2205 | } |
| 2206 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2207 | if (dyn_uar) |
| 2208 | bfregi->sys_pages[idx] = uar_index; |
| 2209 | return 0; |
| 2210 | |
| 2211 | err: |
| 2212 | if (!dyn_uar) |
| 2213 | return err; |
| 2214 | |
| 2215 | mlx5_cmd_free_uar(dev->mdev, idx); |
| 2216 | |
| 2217 | free_bfreg: |
| 2218 | mlx5_ib_free_bfreg(dev, bfregi, bfreg_dyn_idx); |
| 2219 | |
| 2220 | return err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2221 | } |
| 2222 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2223 | static int dm_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
| 2224 | { |
| 2225 | struct mlx5_ib_ucontext *mctx = to_mucontext(context); |
| 2226 | struct mlx5_ib_dev *dev = to_mdev(context->device); |
| 2227 | u16 page_idx = get_extended_index(vma->vm_pgoff); |
| 2228 | size_t map_size = vma->vm_end - vma->vm_start; |
| 2229 | u32 npages = map_size >> PAGE_SHIFT; |
| 2230 | phys_addr_t pfn; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2231 | |
| 2232 | if (find_next_zero_bit(mctx->dm_pages, page_idx + npages, page_idx) != |
| 2233 | page_idx + npages) |
| 2234 | return -EINVAL; |
| 2235 | |
Huy Nguyen | aa8106f | 2019-03-29 15:38:01 -0700 | [diff] [blame] | 2236 | pfn = ((dev->mdev->bar_addr + |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2237 | MLX5_CAP64_DEV_MEM(dev->mdev, memic_bar_start_addr)) >> |
| 2238 | PAGE_SHIFT) + |
| 2239 | page_idx; |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2240 | return rdma_user_mmap_io(context, vma, pfn, map_size, |
| 2241 | pgprot_writecombine(vma->vm_page_prot)); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2242 | } |
| 2243 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2244 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
| 2245 | { |
| 2246 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 2247 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2248 | unsigned long command; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2249 | phys_addr_t pfn; |
| 2250 | |
| 2251 | command = get_command(vma->vm_pgoff); |
| 2252 | switch (command) { |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2253 | case MLX5_IB_MMAP_WC_PAGE: |
| 2254 | case MLX5_IB_MMAP_NC_PAGE: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2255 | case MLX5_IB_MMAP_REGULAR_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2256 | case MLX5_IB_MMAP_ALLOC_WC: |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2257 | return uar_mmap(dev, command, vma, context); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2258 | |
| 2259 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
| 2260 | return -ENOSYS; |
| 2261 | |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2262 | case MLX5_IB_MMAP_CORE_CLOCK: |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2263 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2264 | return -EINVAL; |
| 2265 | |
Matan Barak | 6cbac1e | 2016-04-14 16:52:10 +0300 | [diff] [blame] | 2266 | if (vma->vm_flags & VM_WRITE) |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2267 | return -EPERM; |
| 2268 | |
| 2269 | /* Don't expose to user-space information it shouldn't have */ |
| 2270 | if (PAGE_SIZE > 4096) |
| 2271 | return -EOPNOTSUPP; |
| 2272 | |
| 2273 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 2274 | pfn = (dev->mdev->iseg_base + |
| 2275 | offsetof(struct mlx5_init_seg, internal_timer_h)) >> |
| 2276 | PAGE_SHIFT; |
| 2277 | if (io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 2278 | PAGE_SIZE, vma->vm_page_prot)) |
| 2279 | return -EAGAIN; |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2280 | break; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2281 | case MLX5_IB_MMAP_CLOCK_INFO: |
| 2282 | return mlx5_ib_mmap_clock_info_page(dev, vma, context); |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2283 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2284 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2285 | return dm_mmap(ibcontext, vma); |
| 2286 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2287 | default: |
| 2288 | return -EINVAL; |
| 2289 | } |
| 2290 | |
| 2291 | return 0; |
| 2292 | } |
| 2293 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2294 | struct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev, |
| 2295 | struct ib_ucontext *context, |
| 2296 | struct ib_dm_alloc_attr *attr, |
| 2297 | struct uverbs_attr_bundle *attrs) |
| 2298 | { |
| 2299 | u64 act_size = roundup(attr->length, MLX5_MEMIC_BASE_SIZE); |
| 2300 | struct mlx5_memic *memic = &to_mdev(ibdev)->memic; |
| 2301 | phys_addr_t memic_addr; |
| 2302 | struct mlx5_ib_dm *dm; |
| 2303 | u64 start_offset; |
| 2304 | u32 page_idx; |
| 2305 | int err; |
| 2306 | |
| 2307 | dm = kzalloc(sizeof(*dm), GFP_KERNEL); |
| 2308 | if (!dm) |
| 2309 | return ERR_PTR(-ENOMEM); |
| 2310 | |
| 2311 | mlx5_ib_dbg(to_mdev(ibdev), "alloc_memic req: user_length=0x%llx act_length=0x%llx log_alignment=%d\n", |
| 2312 | attr->length, act_size, attr->alignment); |
| 2313 | |
| 2314 | err = mlx5_cmd_alloc_memic(memic, &memic_addr, |
| 2315 | act_size, attr->alignment); |
| 2316 | if (err) |
| 2317 | goto err_free; |
| 2318 | |
| 2319 | start_offset = memic_addr & ~PAGE_MASK; |
Huy Nguyen | aa8106f | 2019-03-29 15:38:01 -0700 | [diff] [blame] | 2320 | page_idx = (memic_addr - memic->dev->bar_addr - |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2321 | MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
| 2322 | PAGE_SHIFT; |
| 2323 | |
| 2324 | err = uverbs_copy_to(attrs, |
| 2325 | MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 2326 | &start_offset, sizeof(start_offset)); |
| 2327 | if (err) |
| 2328 | goto err_dealloc; |
| 2329 | |
| 2330 | err = uverbs_copy_to(attrs, |
| 2331 | MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 2332 | &page_idx, sizeof(page_idx)); |
| 2333 | if (err) |
| 2334 | goto err_dealloc; |
| 2335 | |
| 2336 | bitmap_set(to_mucontext(context)->dm_pages, page_idx, |
| 2337 | DIV_ROUND_UP(act_size, PAGE_SIZE)); |
| 2338 | |
| 2339 | dm->dev_addr = memic_addr; |
| 2340 | |
| 2341 | return &dm->ibdm; |
| 2342 | |
| 2343 | err_dealloc: |
| 2344 | mlx5_cmd_dealloc_memic(memic, memic_addr, |
| 2345 | act_size); |
| 2346 | err_free: |
| 2347 | kfree(dm); |
| 2348 | return ERR_PTR(err); |
| 2349 | } |
| 2350 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2351 | int mlx5_ib_dealloc_dm(struct ib_dm *ibdm, struct uverbs_attr_bundle *attrs) |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2352 | { |
| 2353 | struct mlx5_memic *memic = &to_mdev(ibdm->device)->memic; |
| 2354 | struct mlx5_ib_dm *dm = to_mdm(ibdm); |
| 2355 | u64 act_size = roundup(dm->ibdm.length, MLX5_MEMIC_BASE_SIZE); |
| 2356 | u32 page_idx; |
| 2357 | int ret; |
| 2358 | |
| 2359 | ret = mlx5_cmd_dealloc_memic(memic, dm->dev_addr, act_size); |
| 2360 | if (ret) |
| 2361 | return ret; |
| 2362 | |
Huy Nguyen | aa8106f | 2019-03-29 15:38:01 -0700 | [diff] [blame] | 2363 | page_idx = (dm->dev_addr - memic->dev->bar_addr - |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2364 | MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
| 2365 | PAGE_SHIFT; |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2366 | bitmap_clear(rdma_udata_to_drv_context( |
| 2367 | &attrs->driver_udata, |
| 2368 | struct mlx5_ib_ucontext, |
| 2369 | ibucontext)->dm_pages, |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2370 | page_idx, |
| 2371 | DIV_ROUND_UP(act_size, PAGE_SIZE)); |
| 2372 | |
| 2373 | kfree(dm); |
| 2374 | |
| 2375 | return 0; |
| 2376 | } |
| 2377 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2378 | static int mlx5_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2379 | { |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2380 | struct mlx5_ib_pd *pd = to_mpd(ibpd); |
| 2381 | struct ib_device *ibdev = ibpd->device; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2382 | struct mlx5_ib_alloc_pd_resp resp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2383 | int err; |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2384 | u32 out[MLX5_ST_SZ_DW(alloc_pd_out)] = {}; |
| 2385 | u32 in[MLX5_ST_SZ_DW(alloc_pd_in)] = {}; |
| 2386 | u16 uid = 0; |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2387 | struct mlx5_ib_ucontext *context = rdma_udata_to_drv_context( |
| 2388 | udata, struct mlx5_ib_ucontext, ibucontext); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2389 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2390 | uid = context ? context->devx_uid : 0; |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2391 | MLX5_SET(alloc_pd_in, in, opcode, MLX5_CMD_OP_ALLOC_PD); |
| 2392 | MLX5_SET(alloc_pd_in, in, uid, uid); |
| 2393 | err = mlx5_cmd_exec(to_mdev(ibdev)->mdev, in, sizeof(in), |
| 2394 | out, sizeof(out)); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2395 | if (err) |
| 2396 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2397 | |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2398 | pd->pdn = MLX5_GET(alloc_pd_out, out, pd); |
| 2399 | pd->uid = uid; |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2400 | if (udata) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2401 | resp.pdn = pd->pdn; |
| 2402 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2403 | mlx5_cmd_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn, uid); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2404 | return -EFAULT; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2405 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2406 | } |
| 2407 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2408 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2409 | } |
| 2410 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2411 | static void mlx5_ib_dealloc_pd(struct ib_pd *pd, struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2412 | { |
| 2413 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 2414 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
| 2415 | |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2416 | mlx5_cmd_dealloc_pd(mdev->mdev, mpd->pdn, mpd->uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2417 | } |
| 2418 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2419 | enum { |
| 2420 | MATCH_CRITERIA_ENABLE_OUTER_BIT, |
| 2421 | MATCH_CRITERIA_ENABLE_MISC_BIT, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2422 | MATCH_CRITERIA_ENABLE_INNER_BIT, |
| 2423 | MATCH_CRITERIA_ENABLE_MISC2_BIT |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2424 | }; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2425 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2426 | #define HEADER_IS_ZERO(match_criteria, headers) \ |
| 2427 | !(memchr_inv(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \ |
| 2428 | 0, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \ |
| 2429 | |
| 2430 | static u8 get_match_criteria_enable(u32 *match_criteria) |
| 2431 | { |
| 2432 | u8 match_criteria_enable; |
| 2433 | |
| 2434 | match_criteria_enable = |
| 2435 | (!HEADER_IS_ZERO(match_criteria, outer_headers)) << |
| 2436 | MATCH_CRITERIA_ENABLE_OUTER_BIT; |
| 2437 | match_criteria_enable |= |
| 2438 | (!HEADER_IS_ZERO(match_criteria, misc_parameters)) << |
| 2439 | MATCH_CRITERIA_ENABLE_MISC_BIT; |
| 2440 | match_criteria_enable |= |
| 2441 | (!HEADER_IS_ZERO(match_criteria, inner_headers)) << |
| 2442 | MATCH_CRITERIA_ENABLE_INNER_BIT; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2443 | match_criteria_enable |= |
| 2444 | (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) << |
| 2445 | MATCH_CRITERIA_ENABLE_MISC2_BIT; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2446 | |
| 2447 | return match_criteria_enable; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2448 | } |
| 2449 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2450 | static int set_proto(void *outer_c, void *outer_v, u8 mask, u8 val) |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2451 | { |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2452 | u8 entry_mask; |
| 2453 | u8 entry_val; |
| 2454 | int err = 0; |
| 2455 | |
| 2456 | if (!mask) |
| 2457 | goto out; |
| 2458 | |
| 2459 | entry_mask = MLX5_GET(fte_match_set_lyr_2_4, outer_c, |
| 2460 | ip_protocol); |
| 2461 | entry_val = MLX5_GET(fte_match_set_lyr_2_4, outer_v, |
| 2462 | ip_protocol); |
| 2463 | if (!entry_mask) { |
| 2464 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_protocol, mask); |
| 2465 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_protocol, val); |
| 2466 | goto out; |
| 2467 | } |
| 2468 | /* Don't override existing ip protocol */ |
| 2469 | if (mask != entry_mask || val != entry_val) |
| 2470 | err = -EINVAL; |
| 2471 | out: |
| 2472 | return err; |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2473 | } |
| 2474 | |
Daria Velikovsky | 37da2a0 | 2018-05-07 10:20:02 +0300 | [diff] [blame] | 2475 | static void set_flow_label(void *misc_c, void *misc_v, u32 mask, u32 val, |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2476 | bool inner) |
| 2477 | { |
| 2478 | if (inner) { |
| 2479 | MLX5_SET(fte_match_set_misc, |
| 2480 | misc_c, inner_ipv6_flow_label, mask); |
| 2481 | MLX5_SET(fte_match_set_misc, |
| 2482 | misc_v, inner_ipv6_flow_label, val); |
| 2483 | } else { |
| 2484 | MLX5_SET(fte_match_set_misc, |
| 2485 | misc_c, outer_ipv6_flow_label, mask); |
| 2486 | MLX5_SET(fte_match_set_misc, |
| 2487 | misc_v, outer_ipv6_flow_label, val); |
| 2488 | } |
| 2489 | } |
| 2490 | |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2491 | static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val) |
| 2492 | { |
| 2493 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_ecn, mask); |
| 2494 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_ecn, val); |
| 2495 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_dscp, mask >> 2); |
| 2496 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_dscp, val >> 2); |
| 2497 | } |
| 2498 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2499 | static int check_mpls_supp_fields(u32 field_support, const __be32 *set_mask) |
| 2500 | { |
| 2501 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_label) && |
| 2502 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_LABEL)) |
| 2503 | return -EOPNOTSUPP; |
| 2504 | |
| 2505 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_exp) && |
| 2506 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_EXP)) |
| 2507 | return -EOPNOTSUPP; |
| 2508 | |
| 2509 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_s_bos) && |
| 2510 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_S_BOS)) |
| 2511 | return -EOPNOTSUPP; |
| 2512 | |
| 2513 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_ttl) && |
| 2514 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_TTL)) |
| 2515 | return -EOPNOTSUPP; |
| 2516 | |
| 2517 | return 0; |
| 2518 | } |
| 2519 | |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2520 | #define LAST_ETH_FIELD vlan_tag |
| 2521 | #define LAST_IB_FIELD sl |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2522 | #define LAST_IPV4_FIELD tos |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2523 | #define LAST_IPV6_FIELD traffic_class |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2524 | #define LAST_TCP_UDP_FIELD src_port |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2525 | #define LAST_TUNNEL_FIELD tunnel_id |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2526 | #define LAST_FLOW_TAG_FIELD tag_id |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2527 | #define LAST_DROP_FIELD size |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2528 | #define LAST_COUNTERS_FIELD counters |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2529 | |
| 2530 | /* Field is the last supported field */ |
| 2531 | #define FIELDS_NOT_SUPPORTED(filter, field)\ |
| 2532 | memchr_inv((void *)&filter.field +\ |
| 2533 | sizeof(filter.field), 0,\ |
| 2534 | sizeof(filter) -\ |
| 2535 | offsetof(typeof(filter), field) -\ |
| 2536 | sizeof(filter.field)) |
| 2537 | |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2538 | int parse_flow_flow_action(struct mlx5_ib_flow_action *maction, |
| 2539 | bool is_egress, |
| 2540 | struct mlx5_flow_act *action) |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2541 | { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2542 | |
| 2543 | switch (maction->ib_action.type) { |
| 2544 | case IB_FLOW_ACTION_ESP: |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2545 | if (action->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 2546 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)) |
| 2547 | return -EINVAL; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2548 | /* Currently only AES_GCM keymat is supported by the driver */ |
| 2549 | action->esp_id = (uintptr_t)maction->esp_aes_gcm.ctx; |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2550 | action->action |= is_egress ? |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2551 | MLX5_FLOW_CONTEXT_ACTION_ENCRYPT : |
| 2552 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT; |
| 2553 | return 0; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2554 | case IB_FLOW_ACTION_UNSPECIFIED: |
| 2555 | if (maction->flow_action_raw.sub_type == |
| 2556 | MLX5_IB_FLOW_ACTION_MODIFY_HEADER) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2557 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) |
| 2558 | return -EINVAL; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2559 | action->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; |
| 2560 | action->modify_id = maction->flow_action_raw.action_id; |
| 2561 | return 0; |
| 2562 | } |
Mark Bloch | 10a3089 | 2018-09-02 12:51:34 +0300 | [diff] [blame] | 2563 | if (maction->flow_action_raw.sub_type == |
| 2564 | MLX5_IB_FLOW_ACTION_DECAP) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2565 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_DECAP) |
| 2566 | return -EINVAL; |
Mark Bloch | 10a3089 | 2018-09-02 12:51:34 +0300 | [diff] [blame] | 2567 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DECAP; |
| 2568 | return 0; |
| 2569 | } |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2570 | if (maction->flow_action_raw.sub_type == |
| 2571 | MLX5_IB_FLOW_ACTION_PACKET_REFORMAT) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2572 | if (action->action & |
| 2573 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT) |
| 2574 | return -EINVAL; |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2575 | action->action |= |
| 2576 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT; |
| 2577 | action->reformat_id = |
| 2578 | maction->flow_action_raw.action_id; |
| 2579 | return 0; |
| 2580 | } |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2581 | /* fall through */ |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2582 | default: |
| 2583 | return -EOPNOTSUPP; |
| 2584 | } |
| 2585 | } |
| 2586 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2587 | static int parse_flow_attr(struct mlx5_core_dev *mdev, u32 *match_c, |
| 2588 | u32 *match_v, const union ib_flow_spec *ib_spec, |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2589 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2590 | struct mlx5_flow_act *action, u32 prev_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2591 | { |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2592 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2593 | misc_parameters); |
| 2594 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2595 | misc_parameters); |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2596 | void *misc_params2_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2597 | misc_parameters_2); |
| 2598 | void *misc_params2_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2599 | misc_parameters_2); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2600 | void *headers_c; |
| 2601 | void *headers_v; |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2602 | int match_ipv; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2603 | int ret; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2604 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2605 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2606 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2607 | inner_headers); |
| 2608 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2609 | inner_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2610 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2611 | ft_field_support.inner_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2612 | } else { |
| 2613 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2614 | outer_headers); |
| 2615 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2616 | outer_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2617 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2618 | ft_field_support.outer_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2622 | case IB_FLOW_SPEC_ETH: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2623 | if (FIELDS_NOT_SUPPORTED(ib_spec->eth.mask, LAST_ETH_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2624 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2625 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2626 | 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] | 2627 | dmac_47_16), |
| 2628 | ib_spec->eth.mask.dst_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2629 | 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] | 2630 | dmac_47_16), |
| 2631 | ib_spec->eth.val.dst_mac); |
| 2632 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2633 | 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] | 2634 | smac_47_16), |
| 2635 | ib_spec->eth.mask.src_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2636 | 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] | 2637 | smac_47_16), |
| 2638 | ib_spec->eth.val.src_mac); |
| 2639 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2640 | if (ib_spec->eth.mask.vlan_tag) { |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2641 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2642 | cvlan_tag, 1); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2643 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2644 | cvlan_tag, 1); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2645 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2646 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2647 | first_vid, ntohs(ib_spec->eth.mask.vlan_tag)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2648 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2649 | first_vid, ntohs(ib_spec->eth.val.vlan_tag)); |
| 2650 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2651 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2652 | first_cfi, |
| 2653 | ntohs(ib_spec->eth.mask.vlan_tag) >> 12); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2654 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2655 | first_cfi, |
| 2656 | ntohs(ib_spec->eth.val.vlan_tag) >> 12); |
| 2657 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2658 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2659 | first_prio, |
| 2660 | ntohs(ib_spec->eth.mask.vlan_tag) >> 13); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2661 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2662 | first_prio, |
| 2663 | ntohs(ib_spec->eth.val.vlan_tag) >> 13); |
| 2664 | } |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2665 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2666 | ethertype, ntohs(ib_spec->eth.mask.ether_type)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2667 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2668 | ethertype, ntohs(ib_spec->eth.val.ether_type)); |
| 2669 | break; |
| 2670 | case IB_FLOW_SPEC_IPV4: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2671 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv4.mask, LAST_IPV4_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2672 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2673 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2674 | if (match_ipv) { |
| 2675 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2676 | ip_version, 0xf); |
| 2677 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2678 | ip_version, MLX5_FS_IPV4_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2679 | } else { |
| 2680 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2681 | ethertype, 0xffff); |
| 2682 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2683 | ethertype, ETH_P_IP); |
| 2684 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2685 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2686 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2687 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2688 | &ib_spec->ipv4.mask.src_ip, |
| 2689 | sizeof(ib_spec->ipv4.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2690 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2691 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2692 | &ib_spec->ipv4.val.src_ip, |
| 2693 | sizeof(ib_spec->ipv4.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2694 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2695 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2696 | &ib_spec->ipv4.mask.dst_ip, |
| 2697 | sizeof(ib_spec->ipv4.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2698 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2699 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2700 | &ib_spec->ipv4.val.dst_ip, |
| 2701 | sizeof(ib_spec->ipv4.val.dst_ip)); |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2702 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2703 | set_tos(headers_c, headers_v, |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2704 | ib_spec->ipv4.mask.tos, ib_spec->ipv4.val.tos); |
| 2705 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2706 | if (set_proto(headers_c, headers_v, |
| 2707 | ib_spec->ipv4.mask.proto, |
| 2708 | ib_spec->ipv4.val.proto)) |
| 2709 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2710 | break; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2711 | case IB_FLOW_SPEC_IPV6: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2712 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv6.mask, LAST_IPV6_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2713 | return -EOPNOTSUPP; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2714 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2715 | if (match_ipv) { |
| 2716 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2717 | ip_version, 0xf); |
| 2718 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2719 | ip_version, MLX5_FS_IPV6_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2720 | } else { |
| 2721 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2722 | ethertype, 0xffff); |
| 2723 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2724 | ethertype, ETH_P_IPV6); |
| 2725 | } |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2726 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2727 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2728 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2729 | &ib_spec->ipv6.mask.src_ip, |
| 2730 | sizeof(ib_spec->ipv6.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2731 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2732 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2733 | &ib_spec->ipv6.val.src_ip, |
| 2734 | sizeof(ib_spec->ipv6.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2735 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2736 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2737 | &ib_spec->ipv6.mask.dst_ip, |
| 2738 | sizeof(ib_spec->ipv6.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2739 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2740 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2741 | &ib_spec->ipv6.val.dst_ip, |
| 2742 | sizeof(ib_spec->ipv6.val.dst_ip)); |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2743 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2744 | set_tos(headers_c, headers_v, |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2745 | ib_spec->ipv6.mask.traffic_class, |
| 2746 | ib_spec->ipv6.val.traffic_class); |
| 2747 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2748 | if (set_proto(headers_c, headers_v, |
| 2749 | ib_spec->ipv6.mask.next_hdr, |
| 2750 | ib_spec->ipv6.val.next_hdr)) |
| 2751 | return -EINVAL; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2752 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2753 | set_flow_label(misc_params_c, misc_params_v, |
| 2754 | ntohl(ib_spec->ipv6.mask.flow_label), |
| 2755 | ntohl(ib_spec->ipv6.val.flow_label), |
| 2756 | ib_spec->type & IB_FLOW_SPEC_INNER); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2757 | break; |
| 2758 | case IB_FLOW_SPEC_ESP: |
| 2759 | if (ib_spec->esp.mask.seq) |
| 2760 | return -EOPNOTSUPP; |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2761 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2762 | MLX5_SET(fte_match_set_misc, misc_params_c, outer_esp_spi, |
| 2763 | ntohl(ib_spec->esp.mask.spi)); |
| 2764 | MLX5_SET(fte_match_set_misc, misc_params_v, outer_esp_spi, |
| 2765 | ntohl(ib_spec->esp.val.spi)); |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2766 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2767 | case IB_FLOW_SPEC_TCP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2768 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2769 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2770 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2771 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2772 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_TCP)) |
| 2773 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2774 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2775 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2776 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2777 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2778 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2779 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2780 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2781 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2782 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2783 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2784 | break; |
| 2785 | case IB_FLOW_SPEC_UDP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2786 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2787 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2788 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2789 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2790 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_UDP)) |
| 2791 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2792 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2793 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2794 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2795 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2796 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2797 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2798 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2799 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2800 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2801 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2802 | break; |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2803 | case IB_FLOW_SPEC_GRE: |
| 2804 | if (ib_spec->gre.mask.c_ks_res0_ver) |
| 2805 | return -EOPNOTSUPP; |
| 2806 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2807 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_GRE)) |
| 2808 | return -EINVAL; |
| 2809 | |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2810 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
| 2811 | 0xff); |
| 2812 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
| 2813 | IPPROTO_GRE); |
| 2814 | |
| 2815 | MLX5_SET(fte_match_set_misc, misc_params_c, gre_protocol, |
Maor Gottlieb | a93b632 | 2018-07-01 15:50:17 +0300 | [diff] [blame] | 2816 | ntohs(ib_spec->gre.mask.protocol)); |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2817 | MLX5_SET(fte_match_set_misc, misc_params_v, gre_protocol, |
| 2818 | ntohs(ib_spec->gre.val.protocol)); |
| 2819 | |
| 2820 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_c, |
Oz Shlomo | 5886a96 | 2018-12-10 13:15:13 -0800 | [diff] [blame] | 2821 | gre_key.nvgre.hi), |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2822 | &ib_spec->gre.mask.key, |
| 2823 | sizeof(ib_spec->gre.mask.key)); |
| 2824 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_v, |
Oz Shlomo | 5886a96 | 2018-12-10 13:15:13 -0800 | [diff] [blame] | 2825 | gre_key.nvgre.hi), |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2826 | &ib_spec->gre.val.key, |
| 2827 | sizeof(ib_spec->gre.val.key)); |
| 2828 | break; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2829 | case IB_FLOW_SPEC_MPLS: |
| 2830 | switch (prev_type) { |
| 2831 | case IB_FLOW_SPEC_UDP: |
| 2832 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2833 | ft_field_support.outer_first_mpls_over_udp), |
| 2834 | &ib_spec->mpls.mask.tag)) |
| 2835 | return -EOPNOTSUPP; |
| 2836 | |
| 2837 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2838 | outer_first_mpls_over_udp), |
| 2839 | &ib_spec->mpls.val.tag, |
| 2840 | sizeof(ib_spec->mpls.val.tag)); |
| 2841 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2842 | outer_first_mpls_over_udp), |
| 2843 | &ib_spec->mpls.mask.tag, |
| 2844 | sizeof(ib_spec->mpls.mask.tag)); |
| 2845 | break; |
| 2846 | case IB_FLOW_SPEC_GRE: |
| 2847 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2848 | ft_field_support.outer_first_mpls_over_gre), |
| 2849 | &ib_spec->mpls.mask.tag)) |
| 2850 | return -EOPNOTSUPP; |
| 2851 | |
| 2852 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2853 | outer_first_mpls_over_gre), |
| 2854 | &ib_spec->mpls.val.tag, |
| 2855 | sizeof(ib_spec->mpls.val.tag)); |
| 2856 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2857 | outer_first_mpls_over_gre), |
| 2858 | &ib_spec->mpls.mask.tag, |
| 2859 | sizeof(ib_spec->mpls.mask.tag)); |
| 2860 | break; |
| 2861 | default: |
| 2862 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2863 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2864 | ft_field_support.inner_first_mpls), |
| 2865 | &ib_spec->mpls.mask.tag)) |
| 2866 | return -EOPNOTSUPP; |
| 2867 | |
| 2868 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2869 | inner_first_mpls), |
| 2870 | &ib_spec->mpls.val.tag, |
| 2871 | sizeof(ib_spec->mpls.val.tag)); |
| 2872 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2873 | inner_first_mpls), |
| 2874 | &ib_spec->mpls.mask.tag, |
| 2875 | sizeof(ib_spec->mpls.mask.tag)); |
| 2876 | } else { |
| 2877 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2878 | ft_field_support.outer_first_mpls), |
| 2879 | &ib_spec->mpls.mask.tag)) |
| 2880 | return -EOPNOTSUPP; |
| 2881 | |
| 2882 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2883 | outer_first_mpls), |
| 2884 | &ib_spec->mpls.val.tag, |
| 2885 | sizeof(ib_spec->mpls.val.tag)); |
| 2886 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2887 | outer_first_mpls), |
| 2888 | &ib_spec->mpls.mask.tag, |
| 2889 | sizeof(ib_spec->mpls.mask.tag)); |
| 2890 | } |
| 2891 | } |
| 2892 | break; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2893 | case IB_FLOW_SPEC_VXLAN_TUNNEL: |
| 2894 | if (FIELDS_NOT_SUPPORTED(ib_spec->tunnel.mask, |
| 2895 | LAST_TUNNEL_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2896 | return -EOPNOTSUPP; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2897 | |
| 2898 | MLX5_SET(fte_match_set_misc, misc_params_c, vxlan_vni, |
| 2899 | ntohl(ib_spec->tunnel.mask.tunnel_id)); |
| 2900 | MLX5_SET(fte_match_set_misc, misc_params_v, vxlan_vni, |
| 2901 | ntohl(ib_spec->tunnel.val.tunnel_id)); |
| 2902 | break; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2903 | case IB_FLOW_SPEC_ACTION_TAG: |
| 2904 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_tag, |
| 2905 | LAST_FLOW_TAG_FIELD)) |
| 2906 | return -EOPNOTSUPP; |
| 2907 | if (ib_spec->flow_tag.tag_id >= BIT(24)) |
| 2908 | return -EINVAL; |
| 2909 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 2910 | action->flow_tag = ib_spec->flow_tag.tag_id; |
Paul Blakey | d5634fe | 2018-09-20 12:17:48 +0200 | [diff] [blame] | 2911 | action->flags |= FLOW_ACT_HAS_TAG; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2912 | break; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2913 | case IB_FLOW_SPEC_ACTION_DROP: |
| 2914 | if (FIELDS_NOT_SUPPORTED(ib_spec->drop, |
| 2915 | LAST_DROP_FIELD)) |
| 2916 | return -EOPNOTSUPP; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 2917 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DROP; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2918 | break; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2919 | case IB_FLOW_SPEC_ACTION_HANDLE: |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2920 | ret = parse_flow_flow_action(to_mflow_act(ib_spec->action.act), |
| 2921 | flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS, action); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2922 | if (ret) |
| 2923 | return ret; |
| 2924 | break; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2925 | case IB_FLOW_SPEC_ACTION_COUNT: |
| 2926 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_count, |
| 2927 | LAST_COUNTERS_FIELD)) |
| 2928 | return -EOPNOTSUPP; |
| 2929 | |
| 2930 | /* for now support only one counters spec per flow */ |
| 2931 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) |
| 2932 | return -EINVAL; |
| 2933 | |
| 2934 | action->counters = ib_spec->flow_count.counters; |
| 2935 | action->action |= MLX5_FLOW_CONTEXT_ACTION_COUNT; |
| 2936 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2937 | default: |
| 2938 | return -EINVAL; |
| 2939 | } |
| 2940 | |
| 2941 | return 0; |
| 2942 | } |
| 2943 | |
| 2944 | /* If a flow could catch both multicast and unicast packets, |
| 2945 | * it won't fall into the multicast flow steering table and this rule |
| 2946 | * could steal other multicast packets. |
| 2947 | */ |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 2948 | 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] | 2949 | { |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2950 | union ib_flow_spec *flow_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2951 | |
| 2952 | if (ib_attr->type != IB_FLOW_ATTR_NORMAL || |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2953 | ib_attr->num_of_specs < 1) |
| 2954 | return false; |
| 2955 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2956 | flow_spec = (union ib_flow_spec *)(ib_attr + 1); |
| 2957 | if (flow_spec->type == IB_FLOW_SPEC_IPV4) { |
| 2958 | struct ib_flow_spec_ipv4 *ipv4_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2959 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2960 | ipv4_spec = (struct ib_flow_spec_ipv4 *)flow_spec; |
| 2961 | if (ipv4_is_multicast(ipv4_spec->val.dst_ip)) |
| 2962 | return true; |
| 2963 | |
| 2964 | return false; |
| 2965 | } |
| 2966 | |
| 2967 | if (flow_spec->type == IB_FLOW_SPEC_ETH) { |
| 2968 | struct ib_flow_spec_eth *eth_spec; |
| 2969 | |
| 2970 | eth_spec = (struct ib_flow_spec_eth *)flow_spec; |
| 2971 | return is_multicast_ether_addr(eth_spec->mask.dst_mac) && |
| 2972 | is_multicast_ether_addr(eth_spec->val.dst_mac); |
| 2973 | } |
| 2974 | |
| 2975 | return false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2976 | } |
| 2977 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2978 | enum valid_spec { |
| 2979 | VALID_SPEC_INVALID, |
| 2980 | VALID_SPEC_VALID, |
| 2981 | VALID_SPEC_NA, |
| 2982 | }; |
| 2983 | |
| 2984 | static enum valid_spec |
| 2985 | is_valid_esp_aes_gcm(struct mlx5_core_dev *mdev, |
| 2986 | const struct mlx5_flow_spec *spec, |
| 2987 | const struct mlx5_flow_act *flow_act, |
| 2988 | bool egress) |
| 2989 | { |
| 2990 | const u32 *match_c = spec->match_criteria; |
| 2991 | bool is_crypto = |
| 2992 | (flow_act->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 2993 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)); |
| 2994 | bool is_ipsec = mlx5_fs_is_ipsec_flow(match_c); |
| 2995 | bool is_drop = flow_act->action & MLX5_FLOW_CONTEXT_ACTION_DROP; |
| 2996 | |
| 2997 | /* |
| 2998 | * Currently only crypto is supported in egress, when regular egress |
| 2999 | * rules would be supported, always return VALID_SPEC_NA. |
| 3000 | */ |
| 3001 | if (!is_crypto) |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3002 | return VALID_SPEC_NA; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3003 | |
| 3004 | return is_crypto && is_ipsec && |
Paul Blakey | d5634fe | 2018-09-20 12:17:48 +0200 | [diff] [blame] | 3005 | (!egress || (!is_drop && !(flow_act->flags & FLOW_ACT_HAS_TAG))) ? |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3006 | VALID_SPEC_VALID : VALID_SPEC_INVALID; |
| 3007 | } |
| 3008 | |
| 3009 | static bool is_valid_spec(struct mlx5_core_dev *mdev, |
| 3010 | const struct mlx5_flow_spec *spec, |
| 3011 | const struct mlx5_flow_act *flow_act, |
| 3012 | bool egress) |
| 3013 | { |
| 3014 | /* We curretly only support ipsec egress flow */ |
| 3015 | return is_valid_esp_aes_gcm(mdev, spec, flow_act, egress) != VALID_SPEC_INVALID; |
| 3016 | } |
| 3017 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3018 | static bool is_valid_ethertype(struct mlx5_core_dev *mdev, |
| 3019 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3020 | bool check_inner) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3021 | { |
| 3022 | 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] | 3023 | int match_ipv = check_inner ? |
| 3024 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 3025 | ft_field_support.inner_ip_version) : |
| 3026 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 3027 | ft_field_support.outer_ip_version); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3028 | int inner_bit = check_inner ? IB_FLOW_SPEC_INNER : 0; |
| 3029 | bool ipv4_spec_valid, ipv6_spec_valid; |
| 3030 | unsigned int ip_spec_type = 0; |
| 3031 | bool has_ethertype = false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3032 | unsigned int spec_index; |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3033 | bool mask_valid = true; |
| 3034 | u16 eth_type = 0; |
| 3035 | bool type_valid; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3036 | |
| 3037 | /* Validate that ethertype is correct */ |
| 3038 | 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] | 3039 | if ((ib_spec->type == (IB_FLOW_SPEC_ETH | inner_bit)) && |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3040 | ib_spec->eth.mask.ether_type) { |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3041 | mask_valid = (ib_spec->eth.mask.ether_type == |
| 3042 | htons(0xffff)); |
| 3043 | has_ethertype = true; |
| 3044 | eth_type = ntohs(ib_spec->eth.val.ether_type); |
| 3045 | } else if ((ib_spec->type == (IB_FLOW_SPEC_IPV4 | inner_bit)) || |
| 3046 | (ib_spec->type == (IB_FLOW_SPEC_IPV6 | inner_bit))) { |
| 3047 | ip_spec_type = ib_spec->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3048 | } |
| 3049 | ib_spec = (void *)ib_spec + ib_spec->size; |
| 3050 | } |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3051 | |
| 3052 | type_valid = (!has_ethertype) || (!ip_spec_type); |
| 3053 | if (!type_valid && mask_valid) { |
| 3054 | ipv4_spec_valid = (eth_type == ETH_P_IP) && |
| 3055 | (ip_spec_type == (IB_FLOW_SPEC_IPV4 | inner_bit)); |
| 3056 | ipv6_spec_valid = (eth_type == ETH_P_IPV6) && |
| 3057 | (ip_spec_type == (IB_FLOW_SPEC_IPV6 | inner_bit)); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3058 | |
| 3059 | type_valid = (ipv4_spec_valid) || (ipv6_spec_valid) || |
| 3060 | (((eth_type == ETH_P_MPLS_UC) || |
| 3061 | (eth_type == ETH_P_MPLS_MC)) && match_ipv); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | return type_valid; |
| 3065 | } |
| 3066 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3067 | static bool is_valid_attr(struct mlx5_core_dev *mdev, |
| 3068 | const struct ib_flow_attr *flow_attr) |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3069 | { |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3070 | return is_valid_ethertype(mdev, flow_attr, false) && |
| 3071 | is_valid_ethertype(mdev, flow_attr, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | static void put_flow_table(struct mlx5_ib_dev *dev, |
| 3075 | struct mlx5_ib_flow_prio *prio, bool ft_added) |
| 3076 | { |
| 3077 | prio->refcount -= !!ft_added; |
| 3078 | if (!prio->refcount) { |
| 3079 | mlx5_destroy_flow_table(prio->flow_table); |
| 3080 | prio->flow_table = NULL; |
| 3081 | } |
| 3082 | } |
| 3083 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3084 | static void counters_clear_description(struct ib_counters *counters) |
| 3085 | { |
| 3086 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3087 | |
| 3088 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3089 | kfree(mcounters->counters_data); |
| 3090 | mcounters->counters_data = NULL; |
| 3091 | mcounters->cntrs_max_index = 0; |
| 3092 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3093 | } |
| 3094 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3095 | static int mlx5_ib_destroy_flow(struct ib_flow *flow_id) |
| 3096 | { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3097 | struct mlx5_ib_flow_handler *handler = container_of(flow_id, |
| 3098 | struct mlx5_ib_flow_handler, |
| 3099 | ibflow); |
| 3100 | struct mlx5_ib_flow_handler *iter, *tmp; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3101 | struct mlx5_ib_dev *dev = handler->dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3102 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3103 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3104 | |
| 3105 | list_for_each_entry_safe(iter, tmp, &handler->list, list) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3106 | mlx5_del_flow_rules(iter->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3107 | put_flow_table(dev, iter->prio, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3108 | list_del(&iter->list); |
| 3109 | kfree(iter); |
| 3110 | } |
| 3111 | |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3112 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3113 | put_flow_table(dev, handler->prio, true); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3114 | if (handler->ibcounters && |
| 3115 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3116 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3117 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3118 | mutex_unlock(&dev->flow_db->lock); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3119 | if (handler->flow_matcher) |
| 3120 | atomic_dec(&handler->flow_matcher->usecnt); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3121 | kfree(handler); |
| 3122 | |
| 3123 | return 0; |
| 3124 | } |
| 3125 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3126 | static int ib_prio_to_core_prio(unsigned int priority, bool dont_trap) |
| 3127 | { |
| 3128 | priority *= 2; |
| 3129 | if (!dont_trap) |
| 3130 | priority++; |
| 3131 | return priority; |
| 3132 | } |
| 3133 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3134 | enum flow_table_type { |
| 3135 | MLX5_IB_FT_RX, |
| 3136 | MLX5_IB_FT_TX |
| 3137 | }; |
| 3138 | |
Maor Gottlieb | 00b7c2a | 2017-03-29 06:09:01 +0300 | [diff] [blame] | 3139 | #define MLX5_FS_MAX_TYPES 6 |
| 3140 | #define MLX5_FS_MAX_ENTRIES BIT(16) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3141 | |
| 3142 | static struct mlx5_ib_flow_prio *_get_prio(struct mlx5_flow_namespace *ns, |
| 3143 | struct mlx5_ib_flow_prio *prio, |
| 3144 | int priority, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3145 | int num_entries, int num_groups, |
| 3146 | u32 flags) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3147 | { |
| 3148 | struct mlx5_flow_table *ft; |
| 3149 | |
| 3150 | ft = mlx5_create_auto_grouped_flow_table(ns, priority, |
| 3151 | num_entries, |
| 3152 | num_groups, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3153 | 0, flags); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3154 | if (IS_ERR(ft)) |
| 3155 | return ERR_CAST(ft); |
| 3156 | |
| 3157 | prio->flow_table = ft; |
| 3158 | prio->refcount = 0; |
| 3159 | return prio; |
| 3160 | } |
| 3161 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3162 | 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] | 3163 | struct ib_flow_attr *flow_attr, |
| 3164 | enum flow_table_type ft_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3165 | { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3166 | bool dont_trap = flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3167 | struct mlx5_flow_namespace *ns = NULL; |
| 3168 | struct mlx5_ib_flow_prio *prio; |
| 3169 | struct mlx5_flow_table *ft; |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3170 | int max_table_size; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3171 | int num_entries; |
| 3172 | int num_groups; |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3173 | u32 flags = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3174 | int priority; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3175 | |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3176 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3177 | log_max_ft_size)); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3178 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3179 | enum mlx5_flow_namespace_type fn_type; |
| 3180 | |
| 3181 | if (flow_is_multicast_only(flow_attr) && |
| 3182 | !dont_trap) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3183 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3184 | else |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3185 | priority = ib_prio_to_core_prio(flow_attr->priority, |
| 3186 | dont_trap); |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3187 | if (ft_type == MLX5_IB_FT_RX) { |
| 3188 | fn_type = MLX5_FLOW_NAMESPACE_BYPASS; |
| 3189 | prio = &dev->flow_db->prios[priority]; |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3190 | if (!dev->is_rep && |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3191 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, decap)) |
| 3192 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3193 | if (!dev->is_rep && |
Mark Bloch | 5c2db53 | 2018-09-02 12:51:35 +0300 | [diff] [blame] | 3194 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3195 | reformat_l3_tunnel_to_l2)) |
| 3196 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3197 | } else { |
| 3198 | max_table_size = |
| 3199 | BIT(MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, |
| 3200 | log_max_ft_size)); |
| 3201 | fn_type = MLX5_FLOW_NAMESPACE_EGRESS; |
| 3202 | prio = &dev->flow_db->egress_prios[priority]; |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3203 | if (!dev->is_rep && |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3204 | MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, reformat)) |
| 3205 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3206 | } |
| 3207 | ns = mlx5_get_flow_namespace(dev->mdev, fn_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3208 | num_entries = MLX5_FS_MAX_ENTRIES; |
| 3209 | num_groups = MLX5_FS_MAX_TYPES; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3210 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3211 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3212 | ns = mlx5_get_flow_namespace(dev->mdev, |
| 3213 | MLX5_FLOW_NAMESPACE_LEFTOVERS); |
| 3214 | build_leftovers_ft_param(&priority, |
| 3215 | &num_entries, |
| 3216 | &num_groups); |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3217 | prio = &dev->flow_db->prios[MLX5_IB_FLOW_LEFTOVERS_PRIO]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3218 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3219 | if (!MLX5_CAP_FLOWTABLE(dev->mdev, |
| 3220 | allow_sniffer_and_nic_rx_shared_tir)) |
| 3221 | return ERR_PTR(-ENOTSUPP); |
| 3222 | |
| 3223 | ns = mlx5_get_flow_namespace(dev->mdev, ft_type == MLX5_IB_FT_RX ? |
| 3224 | MLX5_FLOW_NAMESPACE_SNIFFER_RX : |
| 3225 | MLX5_FLOW_NAMESPACE_SNIFFER_TX); |
| 3226 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3227 | prio = &dev->flow_db->sniffer[ft_type]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3228 | priority = 0; |
| 3229 | num_entries = 1; |
| 3230 | num_groups = 1; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | if (!ns) |
| 3234 | return ERR_PTR(-ENOTSUPP); |
| 3235 | |
Mark Bloch | 3b70508 | 2019-03-28 15:46:22 +0200 | [diff] [blame] | 3236 | max_table_size = min_t(int, num_entries, max_table_size); |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3237 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3238 | ft = prio->flow_table; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3239 | if (!ft) |
Mark Bloch | 3b70508 | 2019-03-28 15:46:22 +0200 | [diff] [blame] | 3240 | return _get_prio(ns, prio, priority, max_table_size, num_groups, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3241 | flags); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3242 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3243 | return prio; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3244 | } |
| 3245 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3246 | static void set_underlay_qp(struct mlx5_ib_dev *dev, |
| 3247 | struct mlx5_flow_spec *spec, |
| 3248 | u32 underlay_qpn) |
| 3249 | { |
| 3250 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, |
| 3251 | spec->match_criteria, |
| 3252 | misc_parameters); |
| 3253 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3254 | misc_parameters); |
| 3255 | |
| 3256 | if (underlay_qpn && |
| 3257 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3258 | ft_field_support.bth_dst_qp)) { |
| 3259 | MLX5_SET(fte_match_set_misc, |
| 3260 | misc_params_v, bth_dst_qp, underlay_qpn); |
| 3261 | MLX5_SET(fte_match_set_misc, |
| 3262 | misc_params_c, bth_dst_qp, 0xffffff); |
| 3263 | } |
| 3264 | } |
| 3265 | |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3266 | static int read_flow_counters(struct ib_device *ibdev, |
| 3267 | struct mlx5_read_counters_attr *read_attr) |
| 3268 | { |
| 3269 | struct mlx5_fc *fc = read_attr->hw_cntrs_hndl; |
| 3270 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 3271 | |
| 3272 | return mlx5_fc_query(dev->mdev, fc, |
| 3273 | &read_attr->out[IB_COUNTER_PACKETS], |
| 3274 | &read_attr->out[IB_COUNTER_BYTES]); |
| 3275 | } |
| 3276 | |
| 3277 | /* flow counters currently expose two counters packets and bytes */ |
| 3278 | #define FLOW_COUNTERS_NUM 2 |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3279 | static int counters_set_description(struct ib_counters *counters, |
| 3280 | enum mlx5_ib_counters_type counters_type, |
| 3281 | struct mlx5_ib_flow_counters_desc *desc_data, |
| 3282 | u32 ncounters) |
| 3283 | { |
| 3284 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3285 | u32 cntrs_max_index = 0; |
| 3286 | int i; |
| 3287 | |
| 3288 | if (counters_type != MLX5_IB_COUNTERS_FLOW) |
| 3289 | return -EINVAL; |
| 3290 | |
| 3291 | /* init the fields for the object */ |
| 3292 | mcounters->type = counters_type; |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3293 | mcounters->read_counters = read_flow_counters; |
| 3294 | mcounters->counters_num = FLOW_COUNTERS_NUM; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3295 | mcounters->ncounters = ncounters; |
| 3296 | /* each counter entry have both description and index pair */ |
| 3297 | for (i = 0; i < ncounters; i++) { |
| 3298 | if (desc_data[i].description > IB_COUNTER_BYTES) |
| 3299 | return -EINVAL; |
| 3300 | |
| 3301 | if (cntrs_max_index <= desc_data[i].index) |
| 3302 | cntrs_max_index = desc_data[i].index + 1; |
| 3303 | } |
| 3304 | |
| 3305 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3306 | mcounters->counters_data = desc_data; |
| 3307 | mcounters->cntrs_max_index = cntrs_max_index; |
| 3308 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3309 | |
| 3310 | return 0; |
| 3311 | } |
| 3312 | |
| 3313 | #define MAX_COUNTERS_NUM (USHRT_MAX / (sizeof(u32) * 2)) |
| 3314 | static int flow_counters_set_data(struct ib_counters *ibcounters, |
| 3315 | struct mlx5_ib_create_flow *ucmd) |
| 3316 | { |
| 3317 | struct mlx5_ib_mcounters *mcounters = to_mcounters(ibcounters); |
| 3318 | struct mlx5_ib_flow_counters_data *cntrs_data = NULL; |
| 3319 | struct mlx5_ib_flow_counters_desc *desc_data = NULL; |
| 3320 | bool hw_hndl = false; |
| 3321 | int ret = 0; |
| 3322 | |
| 3323 | if (ucmd && ucmd->ncounters_data != 0) { |
| 3324 | cntrs_data = ucmd->data; |
| 3325 | if (cntrs_data->ncounters > MAX_COUNTERS_NUM) |
| 3326 | return -EINVAL; |
| 3327 | |
| 3328 | desc_data = kcalloc(cntrs_data->ncounters, |
| 3329 | sizeof(*desc_data), |
| 3330 | GFP_KERNEL); |
| 3331 | if (!desc_data) |
| 3332 | return -ENOMEM; |
| 3333 | |
| 3334 | if (copy_from_user(desc_data, |
| 3335 | u64_to_user_ptr(cntrs_data->counters_data), |
| 3336 | sizeof(*desc_data) * cntrs_data->ncounters)) { |
| 3337 | ret = -EFAULT; |
| 3338 | goto free; |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | if (!mcounters->hw_cntrs_hndl) { |
| 3343 | mcounters->hw_cntrs_hndl = mlx5_fc_create( |
| 3344 | to_mdev(ibcounters->device)->mdev, false); |
weiyongjun (A) | e31abf7 | 2018-06-07 01:47:41 +0000 | [diff] [blame] | 3345 | if (IS_ERR(mcounters->hw_cntrs_hndl)) { |
| 3346 | ret = PTR_ERR(mcounters->hw_cntrs_hndl); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3347 | goto free; |
| 3348 | } |
| 3349 | hw_hndl = true; |
| 3350 | } |
| 3351 | |
| 3352 | if (desc_data) { |
| 3353 | /* counters already bound to at least one flow */ |
| 3354 | if (mcounters->cntrs_max_index) { |
| 3355 | ret = -EINVAL; |
| 3356 | goto free_hndl; |
| 3357 | } |
| 3358 | |
| 3359 | ret = counters_set_description(ibcounters, |
| 3360 | MLX5_IB_COUNTERS_FLOW, |
| 3361 | desc_data, |
| 3362 | cntrs_data->ncounters); |
| 3363 | if (ret) |
| 3364 | goto free_hndl; |
| 3365 | |
| 3366 | } else if (!mcounters->cntrs_max_index) { |
| 3367 | /* counters not bound yet, must have udata passed */ |
| 3368 | ret = -EINVAL; |
| 3369 | goto free_hndl; |
| 3370 | } |
| 3371 | |
| 3372 | return 0; |
| 3373 | |
| 3374 | free_hndl: |
| 3375 | if (hw_hndl) { |
| 3376 | mlx5_fc_destroy(to_mdev(ibcounters->device)->mdev, |
| 3377 | mcounters->hw_cntrs_hndl); |
| 3378 | mcounters->hw_cntrs_hndl = NULL; |
| 3379 | } |
| 3380 | free: |
| 3381 | kfree(desc_data); |
| 3382 | return ret; |
| 3383 | } |
| 3384 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3385 | static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev, |
| 3386 | struct mlx5_ib_flow_prio *ft_prio, |
| 3387 | const struct ib_flow_attr *flow_attr, |
| 3388 | struct mlx5_flow_destination *dst, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3389 | u32 underlay_qpn, |
| 3390 | struct mlx5_ib_create_flow *ucmd) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3391 | { |
| 3392 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3393 | struct mlx5_ib_flow_handler *handler; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3394 | struct mlx5_flow_act flow_act = {.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG}; |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3395 | struct mlx5_flow_spec *spec; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3396 | struct mlx5_flow_destination dest_arr[2] = {}; |
| 3397 | struct mlx5_flow_destination *rule_dst = dest_arr; |
Maor Gottlieb | dd063d0 | 2016-08-28 14:16:32 +0300 | [diff] [blame] | 3398 | const void *ib_flow = (const void *)flow_attr + sizeof(*flow_attr); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3399 | unsigned int spec_index; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3400 | u32 prev_type = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3401 | int err = 0; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3402 | int dest_num = 0; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3403 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3404 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3405 | if (!is_valid_attr(dev->mdev, flow_attr)) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3406 | return ERR_PTR(-EINVAL); |
| 3407 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3408 | if (dev->is_rep && is_egress) |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3409 | return ERR_PTR(-EINVAL); |
| 3410 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3411 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3412 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3413 | if (!handler || !spec) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3414 | err = -ENOMEM; |
| 3415 | goto free; |
| 3416 | } |
| 3417 | |
| 3418 | INIT_LIST_HEAD(&handler->list); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3419 | if (dst) { |
| 3420 | memcpy(&dest_arr[0], dst, sizeof(*dst)); |
| 3421 | dest_num++; |
| 3422 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3423 | |
| 3424 | 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] | 3425 | err = parse_flow_attr(dev->mdev, spec->match_criteria, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3426 | spec->match_value, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3427 | ib_flow, flow_attr, &flow_act, |
| 3428 | prev_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3429 | if (err < 0) |
| 3430 | goto free; |
| 3431 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3432 | prev_type = ((union ib_flow_spec *)ib_flow)->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3433 | ib_flow += ((union ib_flow_spec *)ib_flow)->size; |
| 3434 | } |
| 3435 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3436 | if (!flow_is_multicast_only(flow_attr)) |
| 3437 | set_underlay_qp(dev, spec, underlay_qpn); |
| 3438 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3439 | if (dev->is_rep) { |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3440 | void *misc; |
| 3441 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3442 | if (!dev->port[flow_attr->port - 1].rep) { |
| 3443 | err = -EINVAL; |
| 3444 | goto free; |
| 3445 | } |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3446 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3447 | misc_parameters); |
| 3448 | MLX5_SET(fte_match_set_misc, misc, source_port, |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3449 | dev->port[flow_attr->port - 1].rep->vport); |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3450 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
| 3451 | misc_parameters); |
| 3452 | MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port); |
| 3453 | } |
| 3454 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 3455 | spec->match_criteria_enable = get_match_criteria_enable(spec->match_criteria); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3456 | |
| 3457 | if (is_egress && |
| 3458 | !is_valid_spec(dev->mdev, spec, &flow_act, is_egress)) { |
| 3459 | err = -EINVAL; |
| 3460 | goto free; |
| 3461 | } |
| 3462 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3463 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3464 | struct mlx5_ib_mcounters *mcounters; |
| 3465 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3466 | err = flow_counters_set_data(flow_act.counters, ucmd); |
| 3467 | if (err) |
| 3468 | goto free; |
| 3469 | |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3470 | mcounters = to_mcounters(flow_act.counters); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3471 | handler->ibcounters = flow_act.counters; |
| 3472 | dest_arr[dest_num].type = |
| 3473 | MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3474 | dest_arr[dest_num].counter_id = |
| 3475 | mlx5_fc_id(mcounters->hw_cntrs_hndl); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3476 | dest_num++; |
| 3477 | } |
| 3478 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3479 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DROP) { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3480 | if (!(flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT)) { |
| 3481 | rule_dst = NULL; |
| 3482 | dest_num = 0; |
| 3483 | } |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3484 | } else { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3485 | if (is_egress) |
| 3486 | flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
| 3487 | else |
| 3488 | flow_act.action |= |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3489 | dest_num ? MLX5_FLOW_CONTEXT_ACTION_FWD_DEST : |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3490 | MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3491 | } |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3492 | |
Paul Blakey | d5634fe | 2018-09-20 12:17:48 +0200 | [diff] [blame] | 3493 | if ((flow_act.flags & FLOW_ACT_HAS_TAG) && |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3494 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3495 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3496 | mlx5_ib_warn(dev, "Flow tag %u and attribute type %x isn't allowed in leftovers\n", |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3497 | flow_act.flow_tag, flow_attr->type); |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3498 | err = -EINVAL; |
| 3499 | goto free; |
| 3500 | } |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3501 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Hadar Hen Zion | 66958ed | 2016-11-07 15:14:45 +0200 | [diff] [blame] | 3502 | &flow_act, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3503 | rule_dst, dest_num); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3504 | |
| 3505 | if (IS_ERR(handler->rule)) { |
| 3506 | err = PTR_ERR(handler->rule); |
| 3507 | goto free; |
| 3508 | } |
| 3509 | |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3510 | ft_prio->refcount++; |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3511 | handler->prio = ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3512 | handler->dev = dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3513 | |
| 3514 | ft_prio->flow_table = ft; |
| 3515 | free: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3516 | if (err && handler) { |
| 3517 | if (handler->ibcounters && |
| 3518 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3519 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3520 | kfree(handler); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3521 | } |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3522 | kvfree(spec); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3523 | return err ? ERR_PTR(err) : handler; |
| 3524 | } |
| 3525 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3526 | static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev, |
| 3527 | struct mlx5_ib_flow_prio *ft_prio, |
| 3528 | const struct ib_flow_attr *flow_attr, |
| 3529 | struct mlx5_flow_destination *dst) |
| 3530 | { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3531 | return _create_flow_rule(dev, ft_prio, flow_attr, dst, 0, NULL); |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3532 | } |
| 3533 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3534 | static struct mlx5_ib_flow_handler *create_dont_trap_rule(struct mlx5_ib_dev *dev, |
| 3535 | struct mlx5_ib_flow_prio *ft_prio, |
| 3536 | struct ib_flow_attr *flow_attr, |
| 3537 | struct mlx5_flow_destination *dst) |
| 3538 | { |
| 3539 | struct mlx5_ib_flow_handler *handler_dst = NULL; |
| 3540 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3541 | |
| 3542 | handler = create_flow_rule(dev, ft_prio, flow_attr, NULL); |
| 3543 | if (!IS_ERR(handler)) { |
| 3544 | handler_dst = create_flow_rule(dev, ft_prio, |
| 3545 | flow_attr, dst); |
| 3546 | if (IS_ERR(handler_dst)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3547 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3548 | ft_prio->refcount--; |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3549 | kfree(handler); |
| 3550 | handler = handler_dst; |
| 3551 | } else { |
| 3552 | list_add(&handler_dst->list, &handler->list); |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | return handler; |
| 3557 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3558 | enum { |
| 3559 | LEFTOVERS_MC, |
| 3560 | LEFTOVERS_UC, |
| 3561 | }; |
| 3562 | |
| 3563 | static struct mlx5_ib_flow_handler *create_leftovers_rule(struct mlx5_ib_dev *dev, |
| 3564 | struct mlx5_ib_flow_prio *ft_prio, |
| 3565 | struct ib_flow_attr *flow_attr, |
| 3566 | struct mlx5_flow_destination *dst) |
| 3567 | { |
| 3568 | struct mlx5_ib_flow_handler *handler_ucast = NULL; |
| 3569 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3570 | |
| 3571 | static struct { |
| 3572 | struct ib_flow_attr flow_attr; |
| 3573 | struct ib_flow_spec_eth eth_flow; |
| 3574 | } leftovers_specs[] = { |
| 3575 | [LEFTOVERS_MC] = { |
| 3576 | .flow_attr = { |
| 3577 | .num_of_specs = 1, |
| 3578 | .size = sizeof(leftovers_specs[0]) |
| 3579 | }, |
| 3580 | .eth_flow = { |
| 3581 | .type = IB_FLOW_SPEC_ETH, |
| 3582 | .size = sizeof(struct ib_flow_spec_eth), |
| 3583 | .mask = {.dst_mac = {0x1} }, |
| 3584 | .val = {.dst_mac = {0x1} } |
| 3585 | } |
| 3586 | }, |
| 3587 | [LEFTOVERS_UC] = { |
| 3588 | .flow_attr = { |
| 3589 | .num_of_specs = 1, |
| 3590 | .size = sizeof(leftovers_specs[0]) |
| 3591 | }, |
| 3592 | .eth_flow = { |
| 3593 | .type = IB_FLOW_SPEC_ETH, |
| 3594 | .size = sizeof(struct ib_flow_spec_eth), |
| 3595 | .mask = {.dst_mac = {0x1} }, |
| 3596 | .val = {.dst_mac = {} } |
| 3597 | } |
| 3598 | } |
| 3599 | }; |
| 3600 | |
| 3601 | handler = create_flow_rule(dev, ft_prio, |
| 3602 | &leftovers_specs[LEFTOVERS_MC].flow_attr, |
| 3603 | dst); |
| 3604 | if (!IS_ERR(handler) && |
| 3605 | flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT) { |
| 3606 | handler_ucast = create_flow_rule(dev, ft_prio, |
| 3607 | &leftovers_specs[LEFTOVERS_UC].flow_attr, |
| 3608 | dst); |
| 3609 | if (IS_ERR(handler_ucast)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3610 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3611 | ft_prio->refcount--; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3612 | kfree(handler); |
| 3613 | handler = handler_ucast; |
| 3614 | } else { |
| 3615 | list_add(&handler_ucast->list, &handler->list); |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | return handler; |
| 3620 | } |
| 3621 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3622 | static struct mlx5_ib_flow_handler *create_sniffer_rule(struct mlx5_ib_dev *dev, |
| 3623 | struct mlx5_ib_flow_prio *ft_rx, |
| 3624 | struct mlx5_ib_flow_prio *ft_tx, |
| 3625 | struct mlx5_flow_destination *dst) |
| 3626 | { |
| 3627 | struct mlx5_ib_flow_handler *handler_rx; |
| 3628 | struct mlx5_ib_flow_handler *handler_tx; |
| 3629 | int err; |
| 3630 | static const struct ib_flow_attr flow_attr = { |
| 3631 | .num_of_specs = 0, |
| 3632 | .size = sizeof(flow_attr) |
| 3633 | }; |
| 3634 | |
| 3635 | handler_rx = create_flow_rule(dev, ft_rx, &flow_attr, dst); |
| 3636 | if (IS_ERR(handler_rx)) { |
| 3637 | err = PTR_ERR(handler_rx); |
| 3638 | goto err; |
| 3639 | } |
| 3640 | |
| 3641 | handler_tx = create_flow_rule(dev, ft_tx, &flow_attr, dst); |
| 3642 | if (IS_ERR(handler_tx)) { |
| 3643 | err = PTR_ERR(handler_tx); |
| 3644 | goto err_tx; |
| 3645 | } |
| 3646 | |
| 3647 | list_add(&handler_tx->list, &handler_rx->list); |
| 3648 | |
| 3649 | return handler_rx; |
| 3650 | |
| 3651 | err_tx: |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3652 | mlx5_del_flow_rules(handler_rx->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3653 | ft_rx->refcount--; |
| 3654 | kfree(handler_rx); |
| 3655 | err: |
| 3656 | return ERR_PTR(err); |
| 3657 | } |
| 3658 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3659 | static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, |
| 3660 | struct ib_flow_attr *flow_attr, |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3661 | int domain, |
| 3662 | struct ib_udata *udata) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3663 | { |
| 3664 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Yishai Hadas | d9f88e5 | 2016-08-28 10:58:37 +0300 | [diff] [blame] | 3665 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3666 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3667 | struct mlx5_flow_destination *dst = NULL; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3668 | struct mlx5_ib_flow_prio *ft_prio_tx = NULL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3669 | struct mlx5_ib_flow_prio *ft_prio; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3670 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3671 | struct mlx5_ib_create_flow *ucmd = NULL, ucmd_hdr; |
| 3672 | size_t min_ucmd_sz, required_ucmd_sz; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3673 | int err; |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3674 | int underlay_qpn; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3675 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3676 | if (udata && udata->inlen) { |
| 3677 | min_ucmd_sz = offsetof(typeof(ucmd_hdr), reserved) + |
| 3678 | sizeof(ucmd_hdr.reserved); |
| 3679 | if (udata->inlen < min_ucmd_sz) |
| 3680 | return ERR_PTR(-EOPNOTSUPP); |
| 3681 | |
| 3682 | err = ib_copy_from_udata(&ucmd_hdr, udata, min_ucmd_sz); |
| 3683 | if (err) |
| 3684 | return ERR_PTR(err); |
| 3685 | |
| 3686 | /* currently supports only one counters data */ |
| 3687 | if (ucmd_hdr.ncounters_data > 1) |
| 3688 | return ERR_PTR(-EINVAL); |
| 3689 | |
| 3690 | required_ucmd_sz = min_ucmd_sz + |
| 3691 | sizeof(struct mlx5_ib_flow_counters_data) * |
| 3692 | ucmd_hdr.ncounters_data; |
| 3693 | if (udata->inlen > required_ucmd_sz && |
| 3694 | !ib_is_udata_cleared(udata, required_ucmd_sz, |
| 3695 | udata->inlen - required_ucmd_sz)) |
| 3696 | return ERR_PTR(-EOPNOTSUPP); |
| 3697 | |
| 3698 | ucmd = kzalloc(required_ucmd_sz, GFP_KERNEL); |
| 3699 | if (!ucmd) |
| 3700 | return ERR_PTR(-ENOMEM); |
| 3701 | |
| 3702 | err = ib_copy_from_udata(ucmd, udata, required_ucmd_sz); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3703 | if (err) |
| 3704 | goto free_ucmd; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3705 | } |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3706 | |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3707 | if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) { |
| 3708 | err = -ENOMEM; |
| 3709 | goto free_ucmd; |
| 3710 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3711 | |
| 3712 | if (domain != IB_FLOW_DOMAIN_USER || |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 3713 | flow_attr->port > dev->num_ports || |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3714 | (flow_attr->flags & ~(IB_FLOW_ATTR_FLAGS_DONT_TRAP | |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3715 | IB_FLOW_ATTR_FLAGS_EGRESS))) { |
| 3716 | err = -EINVAL; |
| 3717 | goto free_ucmd; |
| 3718 | } |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3719 | |
| 3720 | if (is_egress && |
| 3721 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3722 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3723 | err = -EINVAL; |
| 3724 | goto free_ucmd; |
| 3725 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3726 | |
| 3727 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3728 | if (!dst) { |
| 3729 | err = -ENOMEM; |
| 3730 | goto free_ucmd; |
| 3731 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3732 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3733 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3734 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3735 | ft_prio = get_flow_table(dev, flow_attr, |
| 3736 | is_egress ? MLX5_IB_FT_TX : MLX5_IB_FT_RX); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3737 | if (IS_ERR(ft_prio)) { |
| 3738 | err = PTR_ERR(ft_prio); |
| 3739 | goto unlock; |
| 3740 | } |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3741 | if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3742 | ft_prio_tx = get_flow_table(dev, flow_attr, MLX5_IB_FT_TX); |
| 3743 | if (IS_ERR(ft_prio_tx)) { |
| 3744 | err = PTR_ERR(ft_prio_tx); |
| 3745 | ft_prio_tx = NULL; |
| 3746 | goto destroy_ft; |
| 3747 | } |
| 3748 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3749 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3750 | if (is_egress) { |
| 3751 | dst->type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
| 3752 | } else { |
| 3753 | dst->type = MLX5_FLOW_DESTINATION_TYPE_TIR; |
| 3754 | if (mqp->flags & MLX5_IB_QP_RSS) |
| 3755 | dst->tir_num = mqp->rss_qp.tirn; |
| 3756 | else |
| 3757 | dst->tir_num = mqp->raw_packet_qp.rq.tirn; |
| 3758 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3759 | |
| 3760 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3761 | if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) { |
| 3762 | handler = create_dont_trap_rule(dev, ft_prio, |
| 3763 | flow_attr, dst); |
| 3764 | } else { |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3765 | underlay_qpn = (mqp->flags & MLX5_IB_QP_UNDERLAY) ? |
| 3766 | mqp->underlay_qpn : 0; |
| 3767 | handler = _create_flow_rule(dev, ft_prio, flow_attr, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3768 | dst, underlay_qpn, ucmd); |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3769 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3770 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3771 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3772 | handler = create_leftovers_rule(dev, ft_prio, flow_attr, |
| 3773 | dst); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3774 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3775 | handler = create_sniffer_rule(dev, ft_prio, ft_prio_tx, dst); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3776 | } else { |
| 3777 | err = -EINVAL; |
| 3778 | goto destroy_ft; |
| 3779 | } |
| 3780 | |
| 3781 | if (IS_ERR(handler)) { |
| 3782 | err = PTR_ERR(handler); |
| 3783 | handler = NULL; |
| 3784 | goto destroy_ft; |
| 3785 | } |
| 3786 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3787 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3788 | kfree(dst); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3789 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3790 | |
| 3791 | return &handler->ibflow; |
| 3792 | |
| 3793 | destroy_ft: |
| 3794 | put_flow_table(dev, ft_prio, false); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3795 | if (ft_prio_tx) |
| 3796 | put_flow_table(dev, ft_prio_tx, false); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3797 | unlock: |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3798 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3799 | kfree(dst); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3800 | free_ucmd: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3801 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3802 | return ERR_PTR(err); |
| 3803 | } |
| 3804 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3805 | static struct mlx5_ib_flow_prio * |
| 3806 | _get_flow_table(struct mlx5_ib_dev *dev, |
| 3807 | struct mlx5_ib_flow_matcher *fs_matcher, |
| 3808 | bool mcast) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3809 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3810 | struct mlx5_flow_namespace *ns = NULL; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3811 | struct mlx5_ib_flow_prio *prio = NULL; |
| 3812 | int max_table_size = 0; |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3813 | u32 flags = 0; |
| 3814 | int priority; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3815 | |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3816 | if (mcast) |
| 3817 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3818 | else |
| 3819 | priority = ib_prio_to_core_prio(fs_matcher->priority, false); |
| 3820 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3821 | if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS) { |
| 3822 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3823 | log_max_ft_size)); |
| 3824 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, decap)) |
| 3825 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
| 3826 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3827 | reformat_l3_tunnel_to_l2)) |
| 3828 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3829 | } else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_EGRESS) { |
| 3830 | max_table_size = BIT( |
| 3831 | MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, log_max_ft_size)); |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3832 | if (MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, reformat)) |
| 3833 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3834 | } else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_FDB) { |
| 3835 | max_table_size = BIT( |
| 3836 | MLX5_CAP_ESW_FLOWTABLE_FDB(dev->mdev, log_max_ft_size)); |
| 3837 | priority = FDB_BYPASS_PATH; |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3838 | } |
| 3839 | |
Mark Bloch | 3b70508 | 2019-03-28 15:46:22 +0200 | [diff] [blame] | 3840 | max_table_size = min_t(int, max_table_size, MLX5_FS_MAX_ENTRIES); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3841 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3842 | ns = mlx5_get_flow_namespace(dev->mdev, fs_matcher->ns_type); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3843 | if (!ns) |
| 3844 | return ERR_PTR(-ENOTSUPP); |
| 3845 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3846 | if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS) |
| 3847 | prio = &dev->flow_db->prios[priority]; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3848 | else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_EGRESS) |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3849 | prio = &dev->flow_db->egress_prios[priority]; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3850 | else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_FDB) |
| 3851 | prio = &dev->flow_db->fdb; |
| 3852 | |
| 3853 | if (!prio) |
| 3854 | return ERR_PTR(-EINVAL); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3855 | |
| 3856 | if (prio->flow_table) |
| 3857 | return prio; |
| 3858 | |
Mark Bloch | 3b70508 | 2019-03-28 15:46:22 +0200 | [diff] [blame] | 3859 | return _get_prio(ns, prio, priority, max_table_size, |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3860 | MLX5_FS_MAX_TYPES, flags); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | static struct mlx5_ib_flow_handler * |
| 3864 | _create_raw_flow_rule(struct mlx5_ib_dev *dev, |
| 3865 | struct mlx5_ib_flow_prio *ft_prio, |
| 3866 | struct mlx5_flow_destination *dst, |
| 3867 | struct mlx5_ib_flow_matcher *fs_matcher, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3868 | struct mlx5_flow_act *flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3869 | void *cmd_in, int inlen, |
| 3870 | int dst_num) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3871 | { |
| 3872 | struct mlx5_ib_flow_handler *handler; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3873 | struct mlx5_flow_spec *spec; |
| 3874 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3875 | int err = 0; |
| 3876 | |
| 3877 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
| 3878 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
| 3879 | if (!handler || !spec) { |
| 3880 | err = -ENOMEM; |
| 3881 | goto free; |
| 3882 | } |
| 3883 | |
| 3884 | INIT_LIST_HEAD(&handler->list); |
| 3885 | |
| 3886 | memcpy(spec->match_value, cmd_in, inlen); |
| 3887 | memcpy(spec->match_criteria, fs_matcher->matcher_mask.match_params, |
| 3888 | fs_matcher->mask_len); |
| 3889 | spec->match_criteria_enable = fs_matcher->match_criteria_enable; |
| 3890 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3891 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3892 | flow_act, dst, dst_num); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3893 | |
| 3894 | if (IS_ERR(handler->rule)) { |
| 3895 | err = PTR_ERR(handler->rule); |
| 3896 | goto free; |
| 3897 | } |
| 3898 | |
| 3899 | ft_prio->refcount++; |
| 3900 | handler->prio = ft_prio; |
| 3901 | handler->dev = dev; |
| 3902 | ft_prio->flow_table = ft; |
| 3903 | |
| 3904 | free: |
| 3905 | if (err) |
| 3906 | kfree(handler); |
| 3907 | kvfree(spec); |
| 3908 | return err ? ERR_PTR(err) : handler; |
| 3909 | } |
| 3910 | |
| 3911 | static bool raw_fs_is_multicast(struct mlx5_ib_flow_matcher *fs_matcher, |
| 3912 | void *match_v) |
| 3913 | { |
| 3914 | void *match_c; |
| 3915 | void *match_v_set_lyr_2_4, *match_c_set_lyr_2_4; |
| 3916 | void *dmac, *dmac_mask; |
| 3917 | void *ipv4, *ipv4_mask; |
| 3918 | |
| 3919 | if (!(fs_matcher->match_criteria_enable & |
| 3920 | (1 << MATCH_CRITERIA_ENABLE_OUTER_BIT))) |
| 3921 | return false; |
| 3922 | |
| 3923 | match_c = fs_matcher->matcher_mask.match_params; |
| 3924 | match_v_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_v, |
| 3925 | outer_headers); |
| 3926 | match_c_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_c, |
| 3927 | outer_headers); |
| 3928 | |
| 3929 | dmac = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 3930 | dmac_47_16); |
| 3931 | dmac_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 3932 | dmac_47_16); |
| 3933 | |
| 3934 | if (is_multicast_ether_addr(dmac) && |
| 3935 | is_multicast_ether_addr(dmac_mask)) |
| 3936 | return true; |
| 3937 | |
| 3938 | ipv4 = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 3939 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 3940 | |
| 3941 | ipv4_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 3942 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 3943 | |
| 3944 | if (ipv4_is_multicast(*(__be32 *)(ipv4)) && |
| 3945 | ipv4_is_multicast(*(__be32 *)(ipv4_mask))) |
| 3946 | return true; |
| 3947 | |
| 3948 | return false; |
| 3949 | } |
| 3950 | |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3951 | struct mlx5_ib_flow_handler * |
| 3952 | mlx5_ib_raw_fs_rule_add(struct mlx5_ib_dev *dev, |
| 3953 | struct mlx5_ib_flow_matcher *fs_matcher, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3954 | struct mlx5_flow_act *flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3955 | u32 counter_id, |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3956 | void *cmd_in, int inlen, int dest_id, |
| 3957 | int dest_type) |
| 3958 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3959 | struct mlx5_flow_destination *dst; |
| 3960 | struct mlx5_ib_flow_prio *ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3961 | struct mlx5_ib_flow_handler *handler; |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3962 | int dst_num = 0; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3963 | bool mcast; |
| 3964 | int err; |
| 3965 | |
| 3966 | if (fs_matcher->flow_type != MLX5_IB_FLOW_TYPE_NORMAL) |
| 3967 | return ERR_PTR(-EOPNOTSUPP); |
| 3968 | |
| 3969 | if (fs_matcher->priority > MLX5_IB_FLOW_LAST_PRIO) |
| 3970 | return ERR_PTR(-ENOMEM); |
| 3971 | |
Gustavo A. R. Silva | 8e8aa14 | 2019-01-15 00:00:48 -0600 | [diff] [blame] | 3972 | dst = kcalloc(2, sizeof(*dst), GFP_KERNEL); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3973 | if (!dst) |
| 3974 | return ERR_PTR(-ENOMEM); |
| 3975 | |
| 3976 | mcast = raw_fs_is_multicast(fs_matcher, cmd_in); |
| 3977 | mutex_lock(&dev->flow_db->lock); |
| 3978 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3979 | ft_prio = _get_flow_table(dev, fs_matcher, mcast); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3980 | if (IS_ERR(ft_prio)) { |
| 3981 | err = PTR_ERR(ft_prio); |
| 3982 | goto unlock; |
| 3983 | } |
| 3984 | |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 3985 | if (dest_type == MLX5_FLOW_DESTINATION_TYPE_TIR) { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3986 | dst[dst_num].type = dest_type; |
| 3987 | dst[dst_num].tir_num = dest_id; |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3988 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 3989 | } else if (dest_type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3990 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM; |
| 3991 | dst[dst_num].ft_num = dest_id; |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3992 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 3993 | } else { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3994 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 3995 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 3996 | } |
| 3997 | |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3998 | dst_num++; |
| 3999 | |
| 4000 | if (flow_act->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
| 4001 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
| 4002 | dst[dst_num].counter_id = counter_id; |
| 4003 | dst_num++; |
| 4004 | } |
| 4005 | |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 4006 | handler = _create_raw_flow_rule(dev, ft_prio, dst, fs_matcher, flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 4007 | cmd_in, inlen, dst_num); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4008 | |
| 4009 | if (IS_ERR(handler)) { |
| 4010 | err = PTR_ERR(handler); |
| 4011 | goto destroy_ft; |
| 4012 | } |
| 4013 | |
| 4014 | mutex_unlock(&dev->flow_db->lock); |
| 4015 | atomic_inc(&fs_matcher->usecnt); |
| 4016 | handler->flow_matcher = fs_matcher; |
| 4017 | |
| 4018 | kfree(dst); |
| 4019 | |
| 4020 | return handler; |
| 4021 | |
| 4022 | destroy_ft: |
| 4023 | put_flow_table(dev, ft_prio, false); |
| 4024 | unlock: |
| 4025 | mutex_unlock(&dev->flow_db->lock); |
| 4026 | kfree(dst); |
| 4027 | |
| 4028 | return ERR_PTR(err); |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 4029 | } |
| 4030 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4031 | static u32 mlx5_ib_flow_action_flags_to_accel_xfrm_flags(u32 mlx5_flags) |
| 4032 | { |
| 4033 | u32 flags = 0; |
| 4034 | |
| 4035 | if (mlx5_flags & MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA) |
| 4036 | flags |= MLX5_ACCEL_XFRM_FLAG_REQUIRE_METADATA; |
| 4037 | |
| 4038 | return flags; |
| 4039 | } |
| 4040 | |
| 4041 | #define MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA |
| 4042 | static struct ib_flow_action * |
| 4043 | mlx5_ib_create_flow_action_esp(struct ib_device *device, |
| 4044 | const struct ib_flow_action_attrs_esp *attr, |
| 4045 | struct uverbs_attr_bundle *attrs) |
| 4046 | { |
| 4047 | struct mlx5_ib_dev *mdev = to_mdev(device); |
| 4048 | struct ib_uverbs_flow_action_esp_keymat_aes_gcm *aes_gcm; |
| 4049 | struct mlx5_accel_esp_xfrm_attrs accel_attrs = {}; |
| 4050 | struct mlx5_ib_flow_action *action; |
| 4051 | u64 action_flags; |
| 4052 | u64 flags; |
| 4053 | int err = 0; |
| 4054 | |
Jason Gunthorpe | bccd062 | 2018-07-26 16:37:14 -0600 | [diff] [blame] | 4055 | err = uverbs_get_flags64( |
| 4056 | &action_flags, attrs, MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 4057 | ((MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED << 1) - 1)); |
| 4058 | if (err) |
| 4059 | return ERR_PTR(err); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4060 | |
| 4061 | flags = mlx5_ib_flow_action_flags_to_accel_xfrm_flags(action_flags); |
| 4062 | |
| 4063 | /* We current only support a subset of the standard features. Only a |
| 4064 | * keymat of type AES_GCM, with icv_len == 16, iv_algo == SEQ and esn |
| 4065 | * (with overlap). Full offload mode isn't supported. |
| 4066 | */ |
| 4067 | if (!attr->keymat || attr->replay || attr->encap || |
| 4068 | attr->spi || attr->seq || attr->tfc_pad || |
| 4069 | attr->hard_limit_pkts || |
| 4070 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4071 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT))) |
| 4072 | return ERR_PTR(-EOPNOTSUPP); |
| 4073 | |
| 4074 | if (attr->keymat->protocol != |
| 4075 | IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM) |
| 4076 | return ERR_PTR(-EOPNOTSUPP); |
| 4077 | |
| 4078 | aes_gcm = &attr->keymat->keymat.aes_gcm; |
| 4079 | |
| 4080 | if (aes_gcm->icv_len != 16 || |
| 4081 | aes_gcm->iv_algo != IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ) |
| 4082 | return ERR_PTR(-EOPNOTSUPP); |
| 4083 | |
| 4084 | action = kmalloc(sizeof(*action), GFP_KERNEL); |
| 4085 | if (!action) |
| 4086 | return ERR_PTR(-ENOMEM); |
| 4087 | |
| 4088 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 4089 | memcpy(&accel_attrs.keymat.aes_gcm.aes_key, &aes_gcm->aes_key, |
| 4090 | sizeof(accel_attrs.keymat.aes_gcm.aes_key)); |
| 4091 | accel_attrs.keymat.aes_gcm.key_len = aes_gcm->key_len * 8; |
| 4092 | memcpy(&accel_attrs.keymat.aes_gcm.salt, &aes_gcm->salt, |
| 4093 | sizeof(accel_attrs.keymat.aes_gcm.salt)); |
| 4094 | memcpy(&accel_attrs.keymat.aes_gcm.seq_iv, &aes_gcm->iv, |
| 4095 | sizeof(accel_attrs.keymat.aes_gcm.seq_iv)); |
| 4096 | accel_attrs.keymat.aes_gcm.icv_len = aes_gcm->icv_len * 8; |
| 4097 | accel_attrs.keymat.aes_gcm.iv_algo = MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ; |
| 4098 | accel_attrs.keymat_type = MLX5_ACCEL_ESP_KEYMAT_AES_GCM; |
| 4099 | |
| 4100 | accel_attrs.esn = attr->esn; |
| 4101 | if (attr->flags & IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) |
| 4102 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED; |
| 4103 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 4104 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4105 | |
| 4106 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT) |
| 4107 | accel_attrs.action |= MLX5_ACCEL_ESP_ACTION_ENCRYPT; |
| 4108 | |
| 4109 | action->esp_aes_gcm.ctx = |
| 4110 | mlx5_accel_esp_create_xfrm(mdev->mdev, &accel_attrs, flags); |
| 4111 | if (IS_ERR(action->esp_aes_gcm.ctx)) { |
| 4112 | err = PTR_ERR(action->esp_aes_gcm.ctx); |
| 4113 | goto err_parse; |
| 4114 | } |
| 4115 | |
| 4116 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 4117 | |
| 4118 | return &action->ib_action; |
| 4119 | |
| 4120 | err_parse: |
| 4121 | kfree(action); |
| 4122 | return ERR_PTR(err); |
| 4123 | } |
| 4124 | |
Matan Barak | 349705c | 2018-03-28 09:27:51 +0300 | [diff] [blame] | 4125 | static int |
| 4126 | mlx5_ib_modify_flow_action_esp(struct ib_flow_action *action, |
| 4127 | const struct ib_flow_action_attrs_esp *attr, |
| 4128 | struct uverbs_attr_bundle *attrs) |
| 4129 | { |
| 4130 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 4131 | struct mlx5_accel_esp_xfrm_attrs accel_attrs; |
| 4132 | int err = 0; |
| 4133 | |
| 4134 | if (attr->keymat || attr->replay || attr->encap || |
| 4135 | attr->spi || attr->seq || attr->tfc_pad || |
| 4136 | attr->hard_limit_pkts || |
| 4137 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4138 | IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS | |
| 4139 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW))) |
| 4140 | return -EOPNOTSUPP; |
| 4141 | |
| 4142 | /* Only the ESN value or the MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP can |
| 4143 | * be modified. |
| 4144 | */ |
| 4145 | if (!(maction->esp_aes_gcm.ib_flags & |
| 4146 | IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) && |
| 4147 | attr->flags & (IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4148 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW)) |
| 4149 | return -EINVAL; |
| 4150 | |
| 4151 | memcpy(&accel_attrs, &maction->esp_aes_gcm.ctx->attrs, |
| 4152 | sizeof(accel_attrs)); |
| 4153 | |
| 4154 | accel_attrs.esn = attr->esn; |
| 4155 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 4156 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4157 | else |
| 4158 | accel_attrs.flags &= ~MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4159 | |
| 4160 | err = mlx5_accel_esp_modify_xfrm(maction->esp_aes_gcm.ctx, |
| 4161 | &accel_attrs); |
| 4162 | if (err) |
| 4163 | return err; |
| 4164 | |
| 4165 | maction->esp_aes_gcm.ib_flags &= |
| 4166 | ~IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 4167 | maction->esp_aes_gcm.ib_flags |= |
| 4168 | attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 4169 | |
| 4170 | return 0; |
| 4171 | } |
| 4172 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4173 | static int mlx5_ib_destroy_flow_action(struct ib_flow_action *action) |
| 4174 | { |
| 4175 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 4176 | |
| 4177 | switch (action->type) { |
| 4178 | case IB_FLOW_ACTION_ESP: |
| 4179 | /* |
| 4180 | * We only support aes_gcm by now, so we implicitly know this is |
| 4181 | * the underline crypto. |
| 4182 | */ |
| 4183 | mlx5_accel_esp_destroy_xfrm(maction->esp_aes_gcm.ctx); |
| 4184 | break; |
Mark Bloch | b4749bf | 2018-08-28 14:18:51 +0300 | [diff] [blame] | 4185 | case IB_FLOW_ACTION_UNSPECIFIED: |
| 4186 | mlx5_ib_destroy_flow_action_raw(maction); |
| 4187 | break; |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4188 | default: |
| 4189 | WARN_ON(true); |
| 4190 | break; |
| 4191 | } |
| 4192 | |
| 4193 | kfree(maction); |
| 4194 | return 0; |
| 4195 | } |
| 4196 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4197 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4198 | { |
| 4199 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4200 | struct mlx5_ib_qp *mqp = to_mqp(ibqp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4201 | int err; |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4202 | u16 uid; |
| 4203 | |
| 4204 | uid = ibqp->pd ? |
| 4205 | to_mpd(ibqp->pd)->uid : 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4206 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4207 | if (mqp->flags & MLX5_IB_QP_UNDERLAY) { |
| 4208 | mlx5_ib_dbg(dev, "Attaching a multi cast group to underlay QP is not supported\n"); |
| 4209 | return -EOPNOTSUPP; |
| 4210 | } |
| 4211 | |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4212 | err = mlx5_cmd_attach_mcg(dev->mdev, gid, ibqp->qp_num, uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4213 | if (err) |
| 4214 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
| 4215 | ibqp->qp_num, gid->raw); |
| 4216 | |
| 4217 | return err; |
| 4218 | } |
| 4219 | |
| 4220 | static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4221 | { |
| 4222 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 4223 | int err; |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4224 | u16 uid; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4225 | |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4226 | uid = ibqp->pd ? |
| 4227 | to_mpd(ibqp->pd)->uid : 0; |
| 4228 | err = mlx5_cmd_detach_mcg(dev->mdev, gid, ibqp->qp_num, uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4229 | if (err) |
| 4230 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
| 4231 | ibqp->qp_num, gid->raw); |
| 4232 | |
| 4233 | return err; |
| 4234 | } |
| 4235 | |
| 4236 | static int init_node_data(struct mlx5_ib_dev *dev) |
| 4237 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4238 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4239 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4240 | err = mlx5_query_node_desc(dev, dev->ib_dev.node_desc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4241 | if (err) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4242 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4243 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4244 | dev->mdev->rev_id = dev->mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4245 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4246 | return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4247 | } |
| 4248 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4249 | static ssize_t fw_pages_show(struct device *device, |
| 4250 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4251 | { |
| 4252 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4253 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4254 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4255 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4256 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4257 | static DEVICE_ATTR_RO(fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4258 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4259 | static ssize_t reg_pages_show(struct device *device, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4260 | struct device_attribute *attr, char *buf) |
| 4261 | { |
| 4262 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4263 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4264 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 4265 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4266 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4267 | static DEVICE_ATTR_RO(reg_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4268 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4269 | static ssize_t hca_type_show(struct device *device, |
| 4270 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4271 | { |
| 4272 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4273 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4274 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4275 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4276 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4277 | static DEVICE_ATTR_RO(hca_type); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4278 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4279 | static ssize_t hw_rev_show(struct device *device, |
| 4280 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4281 | { |
| 4282 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4283 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4284 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4285 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4286 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4287 | static DEVICE_ATTR_RO(hw_rev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4288 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4289 | static ssize_t board_id_show(struct device *device, |
| 4290 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4291 | { |
| 4292 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4293 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4294 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4295 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4296 | dev->mdev->board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4297 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4298 | static DEVICE_ATTR_RO(board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4299 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4300 | static struct attribute *mlx5_class_attributes[] = { |
| 4301 | &dev_attr_hw_rev.attr, |
| 4302 | &dev_attr_hca_type.attr, |
| 4303 | &dev_attr_board_id.attr, |
| 4304 | &dev_attr_fw_pages.attr, |
| 4305 | &dev_attr_reg_pages.attr, |
| 4306 | NULL, |
| 4307 | }; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4308 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4309 | static const struct attribute_group mlx5_attr_group = { |
| 4310 | .attrs = mlx5_class_attributes, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4311 | }; |
| 4312 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4313 | static void pkey_change_handler(struct work_struct *work) |
| 4314 | { |
| 4315 | struct mlx5_ib_port_resources *ports = |
| 4316 | container_of(work, struct mlx5_ib_port_resources, |
| 4317 | pkey_change_work); |
| 4318 | |
| 4319 | mutex_lock(&ports->devr->mutex); |
| 4320 | mlx5_ib_gsi_pkey_change(ports->gsi); |
| 4321 | mutex_unlock(&ports->devr->mutex); |
| 4322 | } |
| 4323 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4324 | static void mlx5_ib_handle_internal_error(struct mlx5_ib_dev *ibdev) |
| 4325 | { |
| 4326 | struct mlx5_ib_qp *mqp; |
| 4327 | struct mlx5_ib_cq *send_mcq, *recv_mcq; |
| 4328 | struct mlx5_core_cq *mcq; |
| 4329 | struct list_head cq_armed_list; |
| 4330 | unsigned long flags_qp; |
| 4331 | unsigned long flags_cq; |
| 4332 | unsigned long flags; |
| 4333 | |
| 4334 | INIT_LIST_HEAD(&cq_armed_list); |
| 4335 | |
| 4336 | /* Go over qp list reside on that ibdev, sync with create/destroy qp.*/ |
| 4337 | spin_lock_irqsave(&ibdev->reset_flow_resource_lock, flags); |
| 4338 | list_for_each_entry(mqp, &ibdev->qp_list, qps_list) { |
| 4339 | spin_lock_irqsave(&mqp->sq.lock, flags_qp); |
| 4340 | if (mqp->sq.tail != mqp->sq.head) { |
| 4341 | send_mcq = to_mcq(mqp->ibqp.send_cq); |
| 4342 | spin_lock_irqsave(&send_mcq->lock, flags_cq); |
| 4343 | if (send_mcq->mcq.comp && |
| 4344 | mqp->ibqp.send_cq->comp_handler) { |
| 4345 | if (!send_mcq->mcq.reset_notify_added) { |
| 4346 | send_mcq->mcq.reset_notify_added = 1; |
| 4347 | list_add_tail(&send_mcq->mcq.reset_notify, |
| 4348 | &cq_armed_list); |
| 4349 | } |
| 4350 | } |
| 4351 | spin_unlock_irqrestore(&send_mcq->lock, flags_cq); |
| 4352 | } |
| 4353 | spin_unlock_irqrestore(&mqp->sq.lock, flags_qp); |
| 4354 | spin_lock_irqsave(&mqp->rq.lock, flags_qp); |
| 4355 | /* no handling is needed for SRQ */ |
| 4356 | if (!mqp->ibqp.srq) { |
| 4357 | if (mqp->rq.tail != mqp->rq.head) { |
| 4358 | recv_mcq = to_mcq(mqp->ibqp.recv_cq); |
| 4359 | spin_lock_irqsave(&recv_mcq->lock, flags_cq); |
| 4360 | if (recv_mcq->mcq.comp && |
| 4361 | mqp->ibqp.recv_cq->comp_handler) { |
| 4362 | if (!recv_mcq->mcq.reset_notify_added) { |
| 4363 | recv_mcq->mcq.reset_notify_added = 1; |
| 4364 | list_add_tail(&recv_mcq->mcq.reset_notify, |
| 4365 | &cq_armed_list); |
| 4366 | } |
| 4367 | } |
| 4368 | spin_unlock_irqrestore(&recv_mcq->lock, |
| 4369 | flags_cq); |
| 4370 | } |
| 4371 | } |
| 4372 | spin_unlock_irqrestore(&mqp->rq.lock, flags_qp); |
| 4373 | } |
| 4374 | /*At that point all inflight post send were put to be executed as of we |
| 4375 | * lock/unlock above locks Now need to arm all involved CQs. |
| 4376 | */ |
| 4377 | list_for_each_entry(mcq, &cq_armed_list, reset_notify) { |
| 4378 | mcq->comp(mcq); |
| 4379 | } |
| 4380 | spin_unlock_irqrestore(&ibdev->reset_flow_resource_lock, flags); |
| 4381 | } |
| 4382 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4383 | static void delay_drop_handler(struct work_struct *work) |
| 4384 | { |
| 4385 | int err; |
| 4386 | struct mlx5_ib_delay_drop *delay_drop = |
| 4387 | container_of(work, struct mlx5_ib_delay_drop, |
| 4388 | delay_drop_work); |
| 4389 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 4390 | atomic_inc(&delay_drop->events_cnt); |
| 4391 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4392 | mutex_lock(&delay_drop->lock); |
| 4393 | err = mlx5_core_set_delay_drop(delay_drop->dev->mdev, |
| 4394 | delay_drop->timeout); |
| 4395 | if (err) { |
| 4396 | mlx5_ib_warn(delay_drop->dev, "Failed to set delay drop, timeout=%u\n", |
| 4397 | delay_drop->timeout); |
| 4398 | delay_drop->activate = false; |
| 4399 | } |
| 4400 | mutex_unlock(&delay_drop->lock); |
| 4401 | } |
| 4402 | |
Saeed Mahameed | 09e574f | 2018-11-26 14:39:04 -0800 | [diff] [blame] | 4403 | static void handle_general_event(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, |
| 4404 | struct ib_event *ibev) |
| 4405 | { |
| 4406 | switch (eqe->sub_type) { |
| 4407 | case MLX5_GENERAL_SUBTYPE_DELAY_DROP_TIMEOUT: |
| 4408 | schedule_work(&ibdev->delay_drop.delay_drop_work); |
| 4409 | break; |
| 4410 | default: /* do nothing */ |
| 4411 | return; |
| 4412 | } |
| 4413 | } |
| 4414 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4415 | static int handle_port_change(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, |
| 4416 | struct ib_event *ibev) |
| 4417 | { |
| 4418 | u8 port = (eqe->data.port.port >> 4) & 0xf; |
| 4419 | |
| 4420 | ibev->element.port_num = port; |
| 4421 | |
| 4422 | switch (eqe->sub_type) { |
| 4423 | case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE: |
| 4424 | case MLX5_PORT_CHANGE_SUBTYPE_DOWN: |
| 4425 | case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED: |
| 4426 | /* In RoCE, port up/down events are handled in |
| 4427 | * mlx5_netdev_event(). |
| 4428 | */ |
| 4429 | if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
| 4430 | IB_LINK_LAYER_ETHERNET) |
| 4431 | return -EINVAL; |
| 4432 | |
| 4433 | ibev->event = (eqe->sub_type == MLX5_PORT_CHANGE_SUBTYPE_ACTIVE) ? |
| 4434 | IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
| 4435 | break; |
| 4436 | |
| 4437 | case MLX5_PORT_CHANGE_SUBTYPE_LID: |
| 4438 | ibev->event = IB_EVENT_LID_CHANGE; |
| 4439 | break; |
| 4440 | |
| 4441 | case MLX5_PORT_CHANGE_SUBTYPE_PKEY: |
| 4442 | ibev->event = IB_EVENT_PKEY_CHANGE; |
| 4443 | schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work); |
| 4444 | break; |
| 4445 | |
| 4446 | case MLX5_PORT_CHANGE_SUBTYPE_GUID: |
| 4447 | ibev->event = IB_EVENT_GID_CHANGE; |
| 4448 | break; |
| 4449 | |
| 4450 | case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG: |
| 4451 | ibev->event = IB_EVENT_CLIENT_REREGISTER; |
| 4452 | break; |
| 4453 | default: |
| 4454 | return -EINVAL; |
| 4455 | } |
| 4456 | |
| 4457 | return 0; |
| 4458 | } |
| 4459 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4460 | static void mlx5_ib_handle_event(struct work_struct *_work) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4461 | { |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4462 | struct mlx5_ib_event_work *work = |
| 4463 | container_of(_work, struct mlx5_ib_event_work, work); |
| 4464 | struct mlx5_ib_dev *ibdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4465 | struct ib_event ibev; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4466 | bool fatal = false; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4467 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4468 | if (work->is_slave) { |
| 4469 | ibdev = mlx5_ib_get_ibdev_from_mpi(work->mpi); |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4470 | if (!ibdev) |
| 4471 | goto out; |
| 4472 | } else { |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4473 | ibdev = work->dev; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4474 | } |
| 4475 | |
| 4476 | switch (work->event) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4477 | case MLX5_DEV_EVENT_SYS_ERROR: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4478 | ibev.event = IB_EVENT_DEVICE_FATAL; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4479 | mlx5_ib_handle_internal_error(ibdev); |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4480 | ibev.element.port_num = (u8)(unsigned long)work->param; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4481 | fatal = true; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4482 | break; |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4483 | case MLX5_EVENT_TYPE_PORT_CHANGE: |
| 4484 | if (handle_port_change(ibdev, work->param, &ibev)) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4485 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4486 | break; |
Saeed Mahameed | 09e574f | 2018-11-26 14:39:04 -0800 | [diff] [blame] | 4487 | case MLX5_EVENT_TYPE_GENERAL_EVENT: |
| 4488 | handle_general_event(ibdev, work->param, &ibev); |
| 4489 | /* fall through */ |
Saeed Mahameed | bdc3792 | 2016-09-29 19:35:38 +0300 | [diff] [blame] | 4490 | default: |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4491 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4492 | } |
| 4493 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4494 | ibev.device = &ibdev->ib_dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4495 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4496 | if (!rdma_is_port_valid(&ibdev->ib_dev, ibev.element.port_num)) { |
| 4497 | mlx5_ib_warn(ibdev, "warning: event on port %d\n", ibev.element.port_num); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4498 | goto out; |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 4499 | } |
| 4500 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4501 | if (ibdev->ib_active) |
| 4502 | ib_dispatch_event(&ibev); |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4503 | |
| 4504 | if (fatal) |
| 4505 | ibdev->ib_active = false; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4506 | out: |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4507 | kfree(work); |
| 4508 | } |
| 4509 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4510 | static int mlx5_ib_event(struct notifier_block *nb, |
| 4511 | unsigned long event, void *param) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4512 | { |
| 4513 | struct mlx5_ib_event_work *work; |
| 4514 | |
| 4515 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4516 | if (!work) |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4517 | return NOTIFY_DONE; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4518 | |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4519 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4520 | work->dev = container_of(nb, struct mlx5_ib_dev, mdev_events); |
| 4521 | work->is_slave = false; |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4522 | work->param = param; |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4523 | work->event = event; |
| 4524 | |
| 4525 | queue_work(mlx5_ib_event_wq, &work->work); |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4526 | |
| 4527 | return NOTIFY_OK; |
| 4528 | } |
| 4529 | |
| 4530 | static int mlx5_ib_event_slave_port(struct notifier_block *nb, |
| 4531 | unsigned long event, void *param) |
| 4532 | { |
| 4533 | struct mlx5_ib_event_work *work; |
| 4534 | |
| 4535 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
| 4536 | if (!work) |
| 4537 | return NOTIFY_DONE; |
| 4538 | |
| 4539 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
| 4540 | work->mpi = container_of(nb, struct mlx5_ib_multiport_info, mdev_events); |
| 4541 | work->is_slave = true; |
| 4542 | work->param = param; |
| 4543 | work->event = event; |
| 4544 | queue_work(mlx5_ib_event_wq, &work->work); |
| 4545 | |
| 4546 | return NOTIFY_OK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4547 | } |
| 4548 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4549 | static int set_has_smi_cap(struct mlx5_ib_dev *dev) |
| 4550 | { |
| 4551 | struct mlx5_hca_vport_context vport_ctx; |
| 4552 | int err; |
| 4553 | int port; |
| 4554 | |
Mark Bloch | a989ea0 | 2019-03-28 15:27:40 +0200 | [diff] [blame] | 4555 | for (port = 1; port <= ARRAY_SIZE(dev->mdev->port_caps); port++) { |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4556 | dev->mdev->port_caps[port - 1].has_smi = false; |
| 4557 | if (MLX5_CAP_GEN(dev->mdev, port_type) == |
| 4558 | MLX5_CAP_PORT_TYPE_IB) { |
| 4559 | if (MLX5_CAP_GEN(dev->mdev, ib_virt)) { |
| 4560 | err = mlx5_query_hca_vport_context(dev->mdev, 0, |
| 4561 | port, 0, |
| 4562 | &vport_ctx); |
| 4563 | if (err) { |
| 4564 | mlx5_ib_err(dev, "query_hca_vport_context for port=%d failed %d\n", |
| 4565 | port, err); |
| 4566 | return err; |
| 4567 | } |
| 4568 | dev->mdev->port_caps[port - 1].has_smi = |
| 4569 | vport_ctx.has_smi; |
| 4570 | } else { |
| 4571 | dev->mdev->port_caps[port - 1].has_smi = true; |
| 4572 | } |
| 4573 | } |
| 4574 | } |
| 4575 | return 0; |
| 4576 | } |
| 4577 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4578 | static void get_ext_port_caps(struct mlx5_ib_dev *dev) |
| 4579 | { |
| 4580 | int port; |
| 4581 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4582 | for (port = 1; port <= dev->num_ports; port++) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4583 | mlx5_query_ext_port_caps(dev, port); |
| 4584 | } |
| 4585 | |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 4586 | static int __get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4587 | { |
| 4588 | struct ib_device_attr *dprops = NULL; |
| 4589 | struct ib_port_attr *pprops = NULL; |
Dan Carpenter | f614fc1 | 2015-01-12 11:56:58 +0300 | [diff] [blame] | 4590 | int err = -ENOMEM; |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4591 | struct ib_udata uhw = {.inlen = 0, .outlen = 0}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4592 | |
| 4593 | pprops = kmalloc(sizeof(*pprops), GFP_KERNEL); |
| 4594 | if (!pprops) |
| 4595 | goto out; |
| 4596 | |
| 4597 | dprops = kmalloc(sizeof(*dprops), GFP_KERNEL); |
| 4598 | if (!dprops) |
| 4599 | goto out; |
| 4600 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4601 | err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4602 | if (err) { |
| 4603 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
| 4604 | goto out; |
| 4605 | } |
| 4606 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4607 | memset(pprops, 0, sizeof(*pprops)); |
| 4608 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
| 4609 | if (err) { |
| 4610 | mlx5_ib_warn(dev, "query_port %d failed %d\n", |
| 4611 | port, err); |
| 4612 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4613 | } |
| 4614 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4615 | dev->mdev->port_caps[port - 1].pkey_table_len = |
| 4616 | dprops->max_pkeys; |
| 4617 | dev->mdev->port_caps[port - 1].gid_table_len = |
| 4618 | pprops->gid_tbl_len; |
| 4619 | mlx5_ib_dbg(dev, "port %d: pkey_table_len %d, gid_table_len %d\n", |
| 4620 | port, dprops->max_pkeys, pprops->gid_tbl_len); |
| 4621 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4622 | out: |
| 4623 | kfree(pprops); |
| 4624 | kfree(dprops); |
| 4625 | |
| 4626 | return err; |
| 4627 | } |
| 4628 | |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 4629 | static int get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
| 4630 | { |
| 4631 | /* For representors use port 1, is this is the only native |
| 4632 | * port |
| 4633 | */ |
| 4634 | if (dev->is_rep) |
| 4635 | return __get_port_caps(dev, 1); |
| 4636 | return __get_port_caps(dev, port); |
| 4637 | } |
| 4638 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4639 | static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
| 4640 | { |
| 4641 | int err; |
| 4642 | |
| 4643 | err = mlx5_mr_cache_cleanup(dev); |
| 4644 | if (err) |
| 4645 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
| 4646 | |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4647 | if (dev->umrc.qp) |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4648 | mlx5_ib_destroy_qp(dev->umrc.qp, NULL); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4649 | if (dev->umrc.cq) |
| 4650 | ib_free_cq(dev->umrc.cq); |
| 4651 | if (dev->umrc.pd) |
| 4652 | ib_dealloc_pd(dev->umrc.pd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | enum { |
| 4656 | MAX_UMR_WR = 128, |
| 4657 | }; |
| 4658 | |
| 4659 | static int create_umr_res(struct mlx5_ib_dev *dev) |
| 4660 | { |
| 4661 | struct ib_qp_init_attr *init_attr = NULL; |
| 4662 | struct ib_qp_attr *attr = NULL; |
| 4663 | struct ib_pd *pd; |
| 4664 | struct ib_cq *cq; |
| 4665 | struct ib_qp *qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4666 | int ret; |
| 4667 | |
| 4668 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| 4669 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 4670 | if (!attr || !init_attr) { |
| 4671 | ret = -ENOMEM; |
| 4672 | goto error_0; |
| 4673 | } |
| 4674 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 4675 | pd = ib_alloc_pd(&dev->ib_dev, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4676 | if (IS_ERR(pd)) { |
| 4677 | mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); |
| 4678 | ret = PTR_ERR(pd); |
| 4679 | goto error_0; |
| 4680 | } |
| 4681 | |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4682 | 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] | 4683 | if (IS_ERR(cq)) { |
| 4684 | mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); |
| 4685 | ret = PTR_ERR(cq); |
| 4686 | goto error_2; |
| 4687 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4688 | |
| 4689 | init_attr->send_cq = cq; |
| 4690 | init_attr->recv_cq = cq; |
| 4691 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
| 4692 | init_attr->cap.max_send_wr = MAX_UMR_WR; |
| 4693 | init_attr->cap.max_send_sge = 1; |
| 4694 | init_attr->qp_type = MLX5_IB_QPT_REG_UMR; |
| 4695 | init_attr->port_num = 1; |
| 4696 | qp = mlx5_ib_create_qp(pd, init_attr, NULL); |
| 4697 | if (IS_ERR(qp)) { |
| 4698 | mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); |
| 4699 | ret = PTR_ERR(qp); |
| 4700 | goto error_3; |
| 4701 | } |
| 4702 | qp->device = &dev->ib_dev; |
| 4703 | qp->real_qp = qp; |
| 4704 | qp->uobject = NULL; |
| 4705 | qp->qp_type = MLX5_IB_QPT_REG_UMR; |
Majd Dibbiny | 31fde03 | 2017-10-30 14:23:13 +0200 | [diff] [blame] | 4706 | qp->send_cq = init_attr->send_cq; |
| 4707 | qp->recv_cq = init_attr->recv_cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4708 | |
| 4709 | attr->qp_state = IB_QPS_INIT; |
| 4710 | attr->port_num = 1; |
| 4711 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX | |
| 4712 | IB_QP_PORT, NULL); |
| 4713 | if (ret) { |
| 4714 | mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); |
| 4715 | goto error_4; |
| 4716 | } |
| 4717 | |
| 4718 | memset(attr, 0, sizeof(*attr)); |
| 4719 | attr->qp_state = IB_QPS_RTR; |
| 4720 | attr->path_mtu = IB_MTU_256; |
| 4721 | |
| 4722 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4723 | if (ret) { |
| 4724 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); |
| 4725 | goto error_4; |
| 4726 | } |
| 4727 | |
| 4728 | memset(attr, 0, sizeof(*attr)); |
| 4729 | attr->qp_state = IB_QPS_RTS; |
| 4730 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4731 | if (ret) { |
| 4732 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); |
| 4733 | goto error_4; |
| 4734 | } |
| 4735 | |
| 4736 | dev->umrc.qp = qp; |
| 4737 | dev->umrc.cq = cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4738 | dev->umrc.pd = pd; |
| 4739 | |
| 4740 | sema_init(&dev->umrc.sem, MAX_UMR_WR); |
| 4741 | ret = mlx5_mr_cache_init(dev); |
| 4742 | if (ret) { |
| 4743 | mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); |
| 4744 | goto error_4; |
| 4745 | } |
| 4746 | |
| 4747 | kfree(attr); |
| 4748 | kfree(init_attr); |
| 4749 | |
| 4750 | return 0; |
| 4751 | |
| 4752 | error_4: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4753 | mlx5_ib_destroy_qp(qp, NULL); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4754 | dev->umrc.qp = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4755 | |
| 4756 | error_3: |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4757 | ib_free_cq(cq); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4758 | dev->umrc.cq = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4759 | |
| 4760 | error_2: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4761 | ib_dealloc_pd(pd); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4762 | dev->umrc.pd = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4763 | |
| 4764 | error_0: |
| 4765 | kfree(attr); |
| 4766 | kfree(init_attr); |
| 4767 | return ret; |
| 4768 | } |
| 4769 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 4770 | static u8 mlx5_get_umr_fence(u8 umr_fence_cap) |
| 4771 | { |
| 4772 | switch (umr_fence_cap) { |
| 4773 | case MLX5_CAP_UMR_FENCE_NONE: |
| 4774 | return MLX5_FENCE_MODE_NONE; |
| 4775 | case MLX5_CAP_UMR_FENCE_SMALL: |
| 4776 | return MLX5_FENCE_MODE_INITIATOR_SMALL; |
| 4777 | default: |
| 4778 | return MLX5_FENCE_MODE_STRONG_ORDERING; |
| 4779 | } |
| 4780 | } |
| 4781 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4782 | static int create_dev_resources(struct mlx5_ib_resources *devr) |
| 4783 | { |
| 4784 | struct ib_srq_init_attr attr; |
| 4785 | struct mlx5_ib_dev *dev; |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4786 | struct ib_device *ibdev; |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 4787 | struct ib_cq_init_attr cq_attr = {.cqe = 1}; |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4788 | int port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4789 | int ret = 0; |
| 4790 | |
| 4791 | dev = container_of(devr, struct mlx5_ib_dev, devr); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4792 | ibdev = &dev->ib_dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4793 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4794 | mutex_init(&devr->mutex); |
| 4795 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4796 | devr->p0 = rdma_zalloc_drv_obj(ibdev, ib_pd); |
| 4797 | if (!devr->p0) |
| 4798 | return -ENOMEM; |
| 4799 | |
| 4800 | devr->p0->device = ibdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4801 | devr->p0->uobject = NULL; |
| 4802 | atomic_set(&devr->p0->usecnt, 0); |
| 4803 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4804 | ret = mlx5_ib_alloc_pd(devr->p0, NULL); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4805 | if (ret) |
| 4806 | goto error0; |
| 4807 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4808 | devr->c0 = mlx5_ib_create_cq(&dev->ib_dev, &cq_attr, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4809 | if (IS_ERR(devr->c0)) { |
| 4810 | ret = PTR_ERR(devr->c0); |
| 4811 | goto error1; |
| 4812 | } |
| 4813 | devr->c0->device = &dev->ib_dev; |
| 4814 | devr->c0->uobject = NULL; |
| 4815 | devr->c0->comp_handler = NULL; |
| 4816 | devr->c0->event_handler = NULL; |
| 4817 | devr->c0->cq_context = NULL; |
| 4818 | atomic_set(&devr->c0->usecnt, 0); |
| 4819 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4820 | devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4821 | if (IS_ERR(devr->x0)) { |
| 4822 | ret = PTR_ERR(devr->x0); |
| 4823 | goto error2; |
| 4824 | } |
| 4825 | devr->x0->device = &dev->ib_dev; |
| 4826 | devr->x0->inode = NULL; |
| 4827 | atomic_set(&devr->x0->usecnt, 0); |
| 4828 | mutex_init(&devr->x0->tgt_qp_mutex); |
| 4829 | INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
| 4830 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4831 | devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4832 | if (IS_ERR(devr->x1)) { |
| 4833 | ret = PTR_ERR(devr->x1); |
| 4834 | goto error3; |
| 4835 | } |
| 4836 | devr->x1->device = &dev->ib_dev; |
| 4837 | devr->x1->inode = NULL; |
| 4838 | atomic_set(&devr->x1->usecnt, 0); |
| 4839 | mutex_init(&devr->x1->tgt_qp_mutex); |
| 4840 | INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
| 4841 | |
| 4842 | memset(&attr, 0, sizeof(attr)); |
| 4843 | attr.attr.max_sge = 1; |
| 4844 | attr.attr.max_wr = 1; |
| 4845 | attr.srq_type = IB_SRQT_XRC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4846 | attr.ext.cq = devr->c0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4847 | attr.ext.xrc.xrcd = devr->x0; |
| 4848 | |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4849 | devr->s0 = rdma_zalloc_drv_obj(ibdev, ib_srq); |
| 4850 | if (!devr->s0) { |
| 4851 | ret = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4852 | goto error4; |
| 4853 | } |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4854 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4855 | devr->s0->device = &dev->ib_dev; |
| 4856 | devr->s0->pd = devr->p0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4857 | devr->s0->srq_type = IB_SRQT_XRC; |
| 4858 | devr->s0->ext.xrc.xrcd = devr->x0; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4859 | devr->s0->ext.cq = devr->c0; |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4860 | ret = mlx5_ib_create_srq(devr->s0, &attr, NULL); |
| 4861 | if (ret) |
| 4862 | goto err_create; |
| 4863 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4864 | atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4865 | atomic_inc(&devr->s0->ext.cq->usecnt); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4866 | atomic_inc(&devr->p0->usecnt); |
| 4867 | atomic_set(&devr->s0->usecnt, 0); |
| 4868 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4869 | memset(&attr, 0, sizeof(attr)); |
| 4870 | attr.attr.max_sge = 1; |
| 4871 | attr.attr.max_wr = 1; |
| 4872 | attr.srq_type = IB_SRQT_BASIC; |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4873 | devr->s1 = rdma_zalloc_drv_obj(ibdev, ib_srq); |
| 4874 | if (!devr->s1) { |
| 4875 | ret = -ENOMEM; |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4876 | goto error5; |
| 4877 | } |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4878 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4879 | devr->s1->device = &dev->ib_dev; |
| 4880 | devr->s1->pd = devr->p0; |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4881 | devr->s1->srq_type = IB_SRQT_BASIC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4882 | devr->s1->ext.cq = devr->c0; |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4883 | |
| 4884 | ret = mlx5_ib_create_srq(devr->s1, &attr, NULL); |
| 4885 | if (ret) |
| 4886 | goto error6; |
| 4887 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4888 | atomic_inc(&devr->p0->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4889 | atomic_set(&devr->s1->usecnt, 0); |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4890 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4891 | for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) { |
| 4892 | INIT_WORK(&devr->ports[port].pkey_change_work, |
| 4893 | pkey_change_handler); |
| 4894 | devr->ports[port].devr = devr; |
| 4895 | } |
| 4896 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4897 | return 0; |
| 4898 | |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4899 | error6: |
| 4900 | kfree(devr->s1); |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4901 | error5: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4902 | mlx5_ib_destroy_srq(devr->s0, NULL); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4903 | err_create: |
| 4904 | kfree(devr->s0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4905 | error4: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4906 | mlx5_ib_dealloc_xrcd(devr->x1, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4907 | error3: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4908 | mlx5_ib_dealloc_xrcd(devr->x0, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4909 | error2: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4910 | mlx5_ib_destroy_cq(devr->c0, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4911 | error1: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4912 | mlx5_ib_dealloc_pd(devr->p0, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4913 | error0: |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4914 | kfree(devr->p0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4915 | return ret; |
| 4916 | } |
| 4917 | |
| 4918 | static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
| 4919 | { |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4920 | int port; |
| 4921 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4922 | mlx5_ib_destroy_srq(devr->s1, NULL); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4923 | kfree(devr->s1); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4924 | mlx5_ib_destroy_srq(devr->s0, NULL); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4925 | kfree(devr->s0); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4926 | mlx5_ib_dealloc_xrcd(devr->x0, NULL); |
| 4927 | mlx5_ib_dealloc_xrcd(devr->x1, NULL); |
| 4928 | mlx5_ib_destroy_cq(devr->c0, NULL); |
| 4929 | mlx5_ib_dealloc_pd(devr->p0, NULL); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4930 | kfree(devr->p0); |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4931 | |
| 4932 | /* Make sure no change P_Key work items are still executing */ |
Mark Bloch | 5d8f6a0 | 2019-03-28 15:27:36 +0200 | [diff] [blame] | 4933 | for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4934 | cancel_work_sync(&devr->ports[port].pkey_change_work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4935 | } |
| 4936 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4937 | static u32 get_core_cap_flags(struct ib_device *ibdev, |
| 4938 | struct mlx5_hca_vport_context *rep) |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4939 | { |
| 4940 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 4941 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, 1); |
| 4942 | u8 l3_type_cap = MLX5_CAP_ROCE(dev->mdev, l3_type); |
| 4943 | u8 roce_version_cap = MLX5_CAP_ROCE(dev->mdev, roce_version); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 4944 | bool raw_support = !mlx5_core_mp_enabled(dev->mdev); |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4945 | u32 ret = 0; |
| 4946 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4947 | if (rep->grh_required) |
| 4948 | ret |= RDMA_CORE_CAP_IB_GRH_REQUIRED; |
| 4949 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4950 | if (ll == IB_LINK_LAYER_INFINIBAND) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4951 | return ret | RDMA_CORE_PORT_IBA_IB; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4952 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 4953 | if (raw_support) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4954 | ret |= RDMA_CORE_PORT_RAW_PACKET; |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4955 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4956 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV4_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4957 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4958 | |
| 4959 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV6_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4960 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4961 | |
| 4962 | if (roce_version_cap & MLX5_ROCE_VERSION_1_CAP) |
| 4963 | ret |= RDMA_CORE_PORT_IBA_ROCE; |
| 4964 | |
| 4965 | if (roce_version_cap & MLX5_ROCE_VERSION_2_CAP) |
| 4966 | ret |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; |
| 4967 | |
| 4968 | return ret; |
| 4969 | } |
| 4970 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4971 | static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 4972 | struct ib_port_immutable *immutable) |
| 4973 | { |
| 4974 | struct ib_port_attr attr; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4975 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 4976 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, port_num); |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4977 | struct mlx5_hca_vport_context rep = {0}; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4978 | int err; |
| 4979 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 4980 | err = ib_query_port(ibdev, port_num, &attr); |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4981 | if (err) |
| 4982 | return err; |
| 4983 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4984 | if (ll == IB_LINK_LAYER_INFINIBAND) { |
| 4985 | err = mlx5_query_hca_vport_context(dev->mdev, 0, port_num, 0, |
| 4986 | &rep); |
| 4987 | if (err) |
| 4988 | return err; |
| 4989 | } |
| 4990 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4991 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 4992 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4993 | immutable->core_cap_flags = get_core_cap_flags(ibdev, &rep); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4994 | if ((ll == IB_LINK_LAYER_INFINIBAND) || MLX5_CAP_GEN(dev->mdev, roce)) |
| 4995 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4996 | |
| 4997 | return 0; |
| 4998 | } |
| 4999 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5000 | static int mlx5_port_rep_immutable(struct ib_device *ibdev, u8 port_num, |
| 5001 | struct ib_port_immutable *immutable) |
| 5002 | { |
| 5003 | struct ib_port_attr attr; |
| 5004 | int err; |
| 5005 | |
| 5006 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 5007 | |
| 5008 | err = ib_query_port(ibdev, port_num, &attr); |
| 5009 | if (err) |
| 5010 | return err; |
| 5011 | |
| 5012 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 5013 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 5014 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 5015 | |
| 5016 | return 0; |
| 5017 | } |
| 5018 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 5019 | static void get_dev_fw_str(struct ib_device *ibdev, char *str) |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 5020 | { |
| 5021 | struct mlx5_ib_dev *dev = |
| 5022 | container_of(ibdev, struct mlx5_ib_dev, ib_dev); |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 5023 | snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%04d", |
| 5024 | fw_rev_maj(dev->mdev), fw_rev_min(dev->mdev), |
| 5025 | fw_rev_sub(dev->mdev)); |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 5026 | } |
| 5027 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5028 | static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5029 | { |
| 5030 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5031 | struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(mdev, |
| 5032 | MLX5_FLOW_NAMESPACE_LAG); |
| 5033 | struct mlx5_flow_table *ft; |
| 5034 | int err; |
| 5035 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 5036 | if (!ns || !mlx5_lag_is_roce(mdev)) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5037 | return 0; |
| 5038 | |
| 5039 | err = mlx5_cmd_create_vport_lag(mdev); |
| 5040 | if (err) |
| 5041 | return err; |
| 5042 | |
| 5043 | ft = mlx5_create_lag_demux_flow_table(ns, 0, 0); |
| 5044 | if (IS_ERR(ft)) { |
| 5045 | err = PTR_ERR(ft); |
| 5046 | goto err_destroy_vport_lag; |
| 5047 | } |
| 5048 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5049 | dev->flow_db->lag_demux_ft = ft; |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 5050 | dev->lag_active = true; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5051 | return 0; |
| 5052 | |
| 5053 | err_destroy_vport_lag: |
| 5054 | mlx5_cmd_destroy_vport_lag(mdev); |
| 5055 | return err; |
| 5056 | } |
| 5057 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5058 | static void mlx5_eth_lag_cleanup(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5059 | { |
| 5060 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5061 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 5062 | if (dev->lag_active) { |
| 5063 | dev->lag_active = false; |
| 5064 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5065 | mlx5_destroy_flow_table(dev->flow_db->lag_demux_ft); |
| 5066 | dev->flow_db->lag_demux_ft = NULL; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5067 | |
| 5068 | mlx5_cmd_destroy_vport_lag(mdev); |
| 5069 | } |
| 5070 | } |
| 5071 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5072 | 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] | 5073 | { |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5074 | int err; |
| 5075 | |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5076 | dev->port[port_num].roce.nb.notifier_call = mlx5_netdev_event; |
| 5077 | err = register_netdevice_notifier(&dev->port[port_num].roce.nb); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 5078 | if (err) { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5079 | dev->port[port_num].roce.nb.notifier_call = NULL; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5080 | return err; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 5081 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5082 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 5083 | return 0; |
| 5084 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5085 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5086 | 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] | 5087 | { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5088 | if (dev->port[port_num].roce.nb.notifier_call) { |
| 5089 | unregister_netdevice_notifier(&dev->port[port_num].roce.nb); |
| 5090 | dev->port[port_num].roce.nb.notifier_call = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5091 | } |
| 5092 | } |
| 5093 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5094 | static int mlx5_enable_eth(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5095 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5096 | int err; |
| 5097 | |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5098 | if (MLX5_CAP_GEN(dev->mdev, roce)) { |
| 5099 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 5100 | if (err) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5101 | return err; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5102 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5103 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5104 | err = mlx5_eth_lag_init(dev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5105 | if (err) |
| 5106 | goto err_disable_roce; |
| 5107 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5108 | return 0; |
| 5109 | |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5110 | err_disable_roce: |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5111 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 5112 | mlx5_nic_vport_disable_roce(dev->mdev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5113 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5114 | return err; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5115 | } |
| 5116 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5117 | static void mlx5_disable_eth(struct mlx5_ib_dev *dev) |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5118 | { |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5119 | mlx5_eth_lag_cleanup(dev); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5120 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 5121 | mlx5_nic_vport_disable_roce(dev->mdev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5122 | } |
| 5123 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5124 | struct mlx5_ib_counter { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5125 | const char *name; |
| 5126 | size_t offset; |
| 5127 | }; |
| 5128 | |
| 5129 | #define INIT_Q_COUNTER(_name) \ |
| 5130 | { .name = #_name, .offset = MLX5_BYTE_OFF(query_q_counter_out, _name)} |
| 5131 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5132 | static const struct mlx5_ib_counter basic_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5133 | INIT_Q_COUNTER(rx_write_requests), |
| 5134 | INIT_Q_COUNTER(rx_read_requests), |
| 5135 | INIT_Q_COUNTER(rx_atomic_requests), |
| 5136 | INIT_Q_COUNTER(out_of_buffer), |
| 5137 | }; |
| 5138 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5139 | static const struct mlx5_ib_counter out_of_seq_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5140 | INIT_Q_COUNTER(out_of_sequence), |
| 5141 | }; |
| 5142 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5143 | static const struct mlx5_ib_counter retrans_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5144 | INIT_Q_COUNTER(duplicate_request), |
| 5145 | INIT_Q_COUNTER(rnr_nak_retry_err), |
| 5146 | INIT_Q_COUNTER(packet_seq_err), |
| 5147 | INIT_Q_COUNTER(implied_nak_seq_err), |
| 5148 | INIT_Q_COUNTER(local_ack_timeout_err), |
| 5149 | }; |
| 5150 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5151 | #define INIT_CONG_COUNTER(_name) \ |
| 5152 | { .name = #_name, .offset = \ |
| 5153 | MLX5_BYTE_OFF(query_cong_statistics_out, _name ## _high)} |
| 5154 | |
| 5155 | static const struct mlx5_ib_counter cong_cnts[] = { |
| 5156 | INIT_CONG_COUNTER(rp_cnp_ignored), |
| 5157 | INIT_CONG_COUNTER(rp_cnp_handled), |
| 5158 | INIT_CONG_COUNTER(np_ecn_marked_roce_packets), |
| 5159 | INIT_CONG_COUNTER(np_cnp_sent), |
| 5160 | }; |
| 5161 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5162 | static const struct mlx5_ib_counter extended_err_cnts[] = { |
| 5163 | INIT_Q_COUNTER(resp_local_length_error), |
| 5164 | INIT_Q_COUNTER(resp_cqe_error), |
| 5165 | INIT_Q_COUNTER(req_cqe_error), |
| 5166 | INIT_Q_COUNTER(req_remote_invalid_request), |
| 5167 | INIT_Q_COUNTER(req_remote_access_errors), |
| 5168 | INIT_Q_COUNTER(resp_remote_access_errors), |
| 5169 | INIT_Q_COUNTER(resp_cqe_flush_error), |
| 5170 | INIT_Q_COUNTER(req_cqe_flush_error), |
| 5171 | }; |
| 5172 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5173 | #define INIT_EXT_PPCNT_COUNTER(_name) \ |
| 5174 | { .name = #_name, .offset = \ |
| 5175 | MLX5_BYTE_OFF(ppcnt_reg, \ |
| 5176 | counter_set.eth_extended_cntrs_grp_data_layout._name##_high)} |
| 5177 | |
| 5178 | static const struct mlx5_ib_counter ext_ppcnt_cnts[] = { |
| 5179 | INIT_EXT_PPCNT_COUNTER(rx_icrc_encapsulated), |
| 5180 | }; |
| 5181 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5182 | static void mlx5_ib_dealloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5183 | { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5184 | int i; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5185 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5186 | for (i = 0; i < dev->num_ports; i++) { |
Parav Pandit | 921c0f5 | 2018-07-08 13:40:30 +0300 | [diff] [blame] | 5187 | if (dev->port[i].cnts.set_id_valid) |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5188 | mlx5_core_dealloc_q_counter(dev->mdev, |
| 5189 | dev->port[i].cnts.set_id); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5190 | kfree(dev->port[i].cnts.names); |
| 5191 | kfree(dev->port[i].cnts.offsets); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5192 | } |
| 5193 | } |
| 5194 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5195 | static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, |
| 5196 | struct mlx5_ib_counters *cnts) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5197 | { |
| 5198 | u32 num_counters; |
| 5199 | |
| 5200 | num_counters = ARRAY_SIZE(basic_q_cnts); |
| 5201 | |
| 5202 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) |
| 5203 | num_counters += ARRAY_SIZE(out_of_seq_q_cnts); |
| 5204 | |
| 5205 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) |
| 5206 | num_counters += ARRAY_SIZE(retrans_q_cnts); |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5207 | |
| 5208 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) |
| 5209 | num_counters += ARRAY_SIZE(extended_err_cnts); |
| 5210 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5211 | cnts->num_q_counters = num_counters; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5212 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5213 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 5214 | cnts->num_cong_counters = ARRAY_SIZE(cong_cnts); |
| 5215 | num_counters += ARRAY_SIZE(cong_cnts); |
| 5216 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5217 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5218 | cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts); |
| 5219 | num_counters += ARRAY_SIZE(ext_ppcnt_cnts); |
| 5220 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5221 | cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL); |
| 5222 | if (!cnts->names) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5223 | return -ENOMEM; |
| 5224 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5225 | cnts->offsets = kcalloc(num_counters, |
| 5226 | sizeof(cnts->offsets), GFP_KERNEL); |
| 5227 | if (!cnts->offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5228 | goto err_names; |
| 5229 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5230 | return 0; |
| 5231 | |
| 5232 | err_names: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5233 | kfree(cnts->names); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5234 | cnts->names = NULL; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5235 | return -ENOMEM; |
| 5236 | } |
| 5237 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5238 | static void mlx5_ib_fill_counters(struct mlx5_ib_dev *dev, |
| 5239 | const char **names, |
| 5240 | size_t *offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5241 | { |
| 5242 | int i; |
| 5243 | int j = 0; |
| 5244 | |
| 5245 | for (i = 0; i < ARRAY_SIZE(basic_q_cnts); i++, j++) { |
| 5246 | names[j] = basic_q_cnts[i].name; |
| 5247 | offsets[j] = basic_q_cnts[i].offset; |
| 5248 | } |
| 5249 | |
| 5250 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) { |
| 5251 | for (i = 0; i < ARRAY_SIZE(out_of_seq_q_cnts); i++, j++) { |
| 5252 | names[j] = out_of_seq_q_cnts[i].name; |
| 5253 | offsets[j] = out_of_seq_q_cnts[i].offset; |
| 5254 | } |
| 5255 | } |
| 5256 | |
| 5257 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) { |
| 5258 | for (i = 0; i < ARRAY_SIZE(retrans_q_cnts); i++, j++) { |
| 5259 | names[j] = retrans_q_cnts[i].name; |
| 5260 | offsets[j] = retrans_q_cnts[i].offset; |
| 5261 | } |
| 5262 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5263 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5264 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) { |
| 5265 | for (i = 0; i < ARRAY_SIZE(extended_err_cnts); i++, j++) { |
| 5266 | names[j] = extended_err_cnts[i].name; |
| 5267 | offsets[j] = extended_err_cnts[i].offset; |
| 5268 | } |
| 5269 | } |
| 5270 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5271 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 5272 | for (i = 0; i < ARRAY_SIZE(cong_cnts); i++, j++) { |
| 5273 | names[j] = cong_cnts[i].name; |
| 5274 | offsets[j] = cong_cnts[i].offset; |
| 5275 | } |
| 5276 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5277 | |
| 5278 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5279 | for (i = 0; i < ARRAY_SIZE(ext_ppcnt_cnts); i++, j++) { |
| 5280 | names[j] = ext_ppcnt_cnts[i].name; |
| 5281 | offsets[j] = ext_ppcnt_cnts[i].offset; |
| 5282 | } |
| 5283 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5284 | } |
| 5285 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5286 | static int mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5287 | { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5288 | int err = 0; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5289 | int i; |
Yishai Hadas | aa74be6 | 2018-12-09 12:52:36 +0200 | [diff] [blame] | 5290 | bool is_shared; |
| 5291 | |
| 5292 | is_shared = MLX5_CAP_GEN(dev->mdev, log_max_uctx) != 0; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5293 | |
| 5294 | for (i = 0; i < dev->num_ports; i++) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5295 | err = __mlx5_ib_alloc_counters(dev, &dev->port[i].cnts); |
| 5296 | if (err) |
| 5297 | goto err_alloc; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5298 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5299 | mlx5_ib_fill_counters(dev, dev->port[i].cnts.names, |
| 5300 | dev->port[i].cnts.offsets); |
| 5301 | |
Yishai Hadas | aa74be6 | 2018-12-09 12:52:36 +0200 | [diff] [blame] | 5302 | err = mlx5_cmd_alloc_q_counter(dev->mdev, |
| 5303 | &dev->port[i].cnts.set_id, |
| 5304 | is_shared ? |
| 5305 | MLX5_SHARED_RESOURCE_UID : 0); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5306 | if (err) { |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5307 | mlx5_ib_warn(dev, |
| 5308 | "couldn't allocate queue counter for port %d, err %d\n", |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5309 | i + 1, err); |
| 5310 | goto err_alloc; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5311 | } |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5312 | dev->port[i].cnts.set_id_valid = true; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | return 0; |
| 5316 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5317 | err_alloc: |
| 5318 | mlx5_ib_dealloc_counters(dev); |
| 5319 | return err; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5320 | } |
| 5321 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5322 | static struct rdma_hw_stats *mlx5_ib_alloc_hw_stats(struct ib_device *ibdev, |
| 5323 | u8 port_num) |
| 5324 | { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5325 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5326 | struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5327 | |
| 5328 | /* We support only per port stats */ |
| 5329 | if (port_num == 0) |
| 5330 | return NULL; |
| 5331 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5332 | return rdma_alloc_hw_stats_struct(port->cnts.names, |
| 5333 | port->cnts.num_q_counters + |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5334 | port->cnts.num_cong_counters + |
| 5335 | port->cnts.num_ext_ppcnt_counters, |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5336 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 5337 | } |
| 5338 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5339 | static int mlx5_ib_query_q_counters(struct mlx5_core_dev *mdev, |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5340 | struct mlx5_ib_port *port, |
| 5341 | struct rdma_hw_stats *stats) |
| 5342 | { |
| 5343 | int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); |
| 5344 | void *out; |
| 5345 | __be32 val; |
| 5346 | int ret, i; |
| 5347 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5348 | out = kvzalloc(outlen, GFP_KERNEL); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5349 | if (!out) |
| 5350 | return -ENOMEM; |
| 5351 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5352 | ret = mlx5_core_query_q_counter(mdev, |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5353 | port->cnts.set_id, 0, |
| 5354 | out, outlen); |
| 5355 | if (ret) |
| 5356 | goto free; |
| 5357 | |
| 5358 | for (i = 0; i < port->cnts.num_q_counters; i++) { |
| 5359 | val = *(__be32 *)(out + port->cnts.offsets[i]); |
| 5360 | stats->value[i] = (u64)be32_to_cpu(val); |
| 5361 | } |
| 5362 | |
| 5363 | free: |
| 5364 | kvfree(out); |
| 5365 | return ret; |
| 5366 | } |
| 5367 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5368 | static int mlx5_ib_query_ext_ppcnt_counters(struct mlx5_ib_dev *dev, |
| 5369 | struct mlx5_ib_port *port, |
| 5370 | struct rdma_hw_stats *stats) |
| 5371 | { |
| 5372 | int offset = port->cnts.num_q_counters + port->cnts.num_cong_counters; |
| 5373 | int sz = MLX5_ST_SZ_BYTES(ppcnt_reg); |
| 5374 | int ret, i; |
| 5375 | void *out; |
| 5376 | |
| 5377 | out = kvzalloc(sz, GFP_KERNEL); |
| 5378 | if (!out) |
| 5379 | return -ENOMEM; |
| 5380 | |
| 5381 | ret = mlx5_cmd_query_ext_ppcnt_counters(dev->mdev, out); |
| 5382 | if (ret) |
| 5383 | goto free; |
| 5384 | |
| 5385 | for (i = 0; i < port->cnts.num_ext_ppcnt_counters; i++) { |
| 5386 | stats->value[i + offset] = |
| 5387 | be64_to_cpup((__be64 *)(out + |
| 5388 | port->cnts.offsets[i + offset])); |
| 5389 | } |
| 5390 | |
| 5391 | free: |
| 5392 | kvfree(out); |
| 5393 | return ret; |
| 5394 | } |
| 5395 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5396 | static int mlx5_ib_get_hw_stats(struct ib_device *ibdev, |
| 5397 | struct rdma_hw_stats *stats, |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5398 | u8 port_num, int index) |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5399 | { |
| 5400 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5401 | struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5402 | struct mlx5_core_dev *mdev; |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5403 | int ret, num_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5404 | u8 mdev_port_num; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5405 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5406 | if (!stats) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5407 | return -EINVAL; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5408 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5409 | num_counters = port->cnts.num_q_counters + |
| 5410 | port->cnts.num_cong_counters + |
| 5411 | port->cnts.num_ext_ppcnt_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5412 | |
| 5413 | /* q_counters are per IB device, query the master mdev */ |
| 5414 | ret = mlx5_ib_query_q_counters(dev->mdev, port, stats); |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5415 | if (ret) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5416 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5417 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5418 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5419 | ret = mlx5_ib_query_ext_ppcnt_counters(dev, port, stats); |
| 5420 | if (ret) |
| 5421 | return ret; |
| 5422 | } |
| 5423 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5424 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5425 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, |
| 5426 | &mdev_port_num); |
| 5427 | if (!mdev) { |
| 5428 | /* If port is not affiliated yet, its in down state |
| 5429 | * which doesn't have any counters yet, so it would be |
| 5430 | * zero. So no need to read from the HCA. |
| 5431 | */ |
| 5432 | goto done; |
| 5433 | } |
Majd Dibbiny | 71a0ff6 | 2017-12-21 17:38:26 +0200 | [diff] [blame] | 5434 | ret = mlx5_lag_query_cong_counters(dev->mdev, |
| 5435 | stats->value + |
| 5436 | port->cnts.num_q_counters, |
| 5437 | port->cnts.num_cong_counters, |
| 5438 | port->cnts.offsets + |
| 5439 | port->cnts.num_q_counters); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5440 | |
| 5441 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5442 | if (ret) |
| 5443 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5444 | } |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5445 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5446 | done: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5447 | return num_counters; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5448 | } |
| 5449 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5450 | static int mlx5_ib_rn_get_params(struct ib_device *device, u8 port_num, |
| 5451 | enum rdma_netdev_t type, |
| 5452 | struct rdma_netdev_alloc_params *params) |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5453 | { |
| 5454 | if (type != RDMA_NETDEV_IPOIB) |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5455 | return -EOPNOTSUPP; |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5456 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5457 | return mlx5_rdma_rn_get_params(to_mdev(device)->mdev, device, params); |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5458 | } |
| 5459 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5460 | static void delay_drop_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 5461 | { |
| 5462 | if (!dev->delay_drop.dbg) |
| 5463 | return; |
| 5464 | debugfs_remove_recursive(dev->delay_drop.dbg->dir_debugfs); |
| 5465 | kfree(dev->delay_drop.dbg); |
| 5466 | dev->delay_drop.dbg = NULL; |
| 5467 | } |
| 5468 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5469 | static void cancel_delay_drop(struct mlx5_ib_dev *dev) |
| 5470 | { |
| 5471 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5472 | return; |
| 5473 | |
| 5474 | cancel_work_sync(&dev->delay_drop.delay_drop_work); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5475 | delay_drop_debugfs_cleanup(dev); |
| 5476 | } |
| 5477 | |
| 5478 | static ssize_t delay_drop_timeout_read(struct file *filp, char __user *buf, |
| 5479 | size_t count, loff_t *pos) |
| 5480 | { |
| 5481 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5482 | char lbuf[20]; |
| 5483 | int len; |
| 5484 | |
| 5485 | len = snprintf(lbuf, sizeof(lbuf), "%u\n", delay_drop->timeout); |
| 5486 | return simple_read_from_buffer(buf, count, pos, lbuf, len); |
| 5487 | } |
| 5488 | |
| 5489 | static ssize_t delay_drop_timeout_write(struct file *filp, const char __user *buf, |
| 5490 | size_t count, loff_t *pos) |
| 5491 | { |
| 5492 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5493 | u32 timeout; |
| 5494 | u32 var; |
| 5495 | |
| 5496 | if (kstrtouint_from_user(buf, count, 0, &var)) |
| 5497 | return -EFAULT; |
| 5498 | |
| 5499 | timeout = min_t(u32, roundup(var, 100), MLX5_MAX_DELAY_DROP_TIMEOUT_MS * |
| 5500 | 1000); |
| 5501 | if (timeout != var) |
| 5502 | mlx5_ib_dbg(delay_drop->dev, "Round delay drop timeout to %u usec\n", |
| 5503 | timeout); |
| 5504 | |
| 5505 | delay_drop->timeout = timeout; |
| 5506 | |
| 5507 | return count; |
| 5508 | } |
| 5509 | |
| 5510 | static const struct file_operations fops_delay_drop_timeout = { |
| 5511 | .owner = THIS_MODULE, |
| 5512 | .open = simple_open, |
| 5513 | .write = delay_drop_timeout_write, |
| 5514 | .read = delay_drop_timeout_read, |
| 5515 | }; |
| 5516 | |
| 5517 | static int delay_drop_debugfs_init(struct mlx5_ib_dev *dev) |
| 5518 | { |
| 5519 | struct mlx5_ib_dbg_delay_drop *dbg; |
| 5520 | |
| 5521 | if (!mlx5_debugfs_root) |
| 5522 | return 0; |
| 5523 | |
| 5524 | dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); |
| 5525 | if (!dbg) |
| 5526 | return -ENOMEM; |
| 5527 | |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5528 | dev->delay_drop.dbg = dbg; |
| 5529 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5530 | dbg->dir_debugfs = |
| 5531 | debugfs_create_dir("delay_drop", |
| 5532 | dev->mdev->priv.dbg_root); |
| 5533 | if (!dbg->dir_debugfs) |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5534 | goto out_debugfs; |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5535 | |
| 5536 | dbg->events_cnt_debugfs = |
| 5537 | debugfs_create_atomic_t("num_timeout_events", 0400, |
| 5538 | dbg->dir_debugfs, |
| 5539 | &dev->delay_drop.events_cnt); |
| 5540 | if (!dbg->events_cnt_debugfs) |
| 5541 | goto out_debugfs; |
| 5542 | |
| 5543 | dbg->rqs_cnt_debugfs = |
| 5544 | debugfs_create_atomic_t("num_rqs", 0400, |
| 5545 | dbg->dir_debugfs, |
| 5546 | &dev->delay_drop.rqs_cnt); |
| 5547 | if (!dbg->rqs_cnt_debugfs) |
| 5548 | goto out_debugfs; |
| 5549 | |
| 5550 | dbg->timeout_debugfs = |
| 5551 | debugfs_create_file("timeout", 0600, |
| 5552 | dbg->dir_debugfs, |
| 5553 | &dev->delay_drop, |
| 5554 | &fops_delay_drop_timeout); |
| 5555 | if (!dbg->timeout_debugfs) |
| 5556 | goto out_debugfs; |
| 5557 | |
| 5558 | return 0; |
| 5559 | |
| 5560 | out_debugfs: |
| 5561 | delay_drop_debugfs_cleanup(dev); |
| 5562 | return -ENOMEM; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | static void init_delay_drop(struct mlx5_ib_dev *dev) |
| 5566 | { |
| 5567 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5568 | return; |
| 5569 | |
| 5570 | mutex_init(&dev->delay_drop.lock); |
| 5571 | dev->delay_drop.dev = dev; |
| 5572 | dev->delay_drop.activate = false; |
| 5573 | dev->delay_drop.timeout = MLX5_MAX_DELAY_DROP_TIMEOUT_MS * 1000; |
| 5574 | INIT_WORK(&dev->delay_drop.delay_drop_work, delay_drop_handler); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5575 | atomic_set(&dev->delay_drop.rqs_cnt, 0); |
| 5576 | atomic_set(&dev->delay_drop.events_cnt, 0); |
| 5577 | |
| 5578 | if (delay_drop_debugfs_init(dev)) |
| 5579 | mlx5_ib_warn(dev, "Failed to init delay drop debugfs\n"); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5580 | } |
| 5581 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5582 | /* The mlx5_ib_multiport_mutex should be held when calling this function */ |
| 5583 | static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5584 | struct mlx5_ib_multiport_info *mpi) |
| 5585 | { |
| 5586 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5587 | struct mlx5_ib_port *port = &ibdev->port[port_num]; |
| 5588 | int comps; |
| 5589 | int err; |
| 5590 | int i; |
| 5591 | |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5592 | mlx5_ib_cleanup_cong_debugfs(ibdev, port_num); |
| 5593 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5594 | spin_lock(&port->mp.mpi_lock); |
| 5595 | if (!mpi->ibdev) { |
| 5596 | spin_unlock(&port->mp.mpi_lock); |
| 5597 | return; |
| 5598 | } |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5599 | |
| 5600 | if (mpi->mdev_events.notifier_call) |
| 5601 | mlx5_notifier_unregister(mpi->mdev, &mpi->mdev_events); |
| 5602 | mpi->mdev_events.notifier_call = NULL; |
| 5603 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5604 | mpi->ibdev = NULL; |
| 5605 | |
| 5606 | spin_unlock(&port->mp.mpi_lock); |
| 5607 | mlx5_remove_netdev_notifier(ibdev, port_num); |
| 5608 | spin_lock(&port->mp.mpi_lock); |
| 5609 | |
| 5610 | comps = mpi->mdev_refcnt; |
| 5611 | if (comps) { |
| 5612 | mpi->unaffiliate = true; |
| 5613 | init_completion(&mpi->unref_comp); |
| 5614 | spin_unlock(&port->mp.mpi_lock); |
| 5615 | |
| 5616 | for (i = 0; i < comps; i++) |
| 5617 | wait_for_completion(&mpi->unref_comp); |
| 5618 | |
| 5619 | spin_lock(&port->mp.mpi_lock); |
| 5620 | mpi->unaffiliate = false; |
| 5621 | } |
| 5622 | |
| 5623 | port->mp.mpi = NULL; |
| 5624 | |
| 5625 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 5626 | |
| 5627 | spin_unlock(&port->mp.mpi_lock); |
| 5628 | |
| 5629 | err = mlx5_nic_vport_unaffiliate_multiport(mpi->mdev); |
| 5630 | |
| 5631 | mlx5_ib_dbg(ibdev, "unaffiliated port %d\n", port_num + 1); |
| 5632 | /* Log an error, still needed to cleanup the pointers and add |
| 5633 | * it back to the list. |
| 5634 | */ |
| 5635 | if (err) |
| 5636 | mlx5_ib_err(ibdev, "Failed to unaffiliate port %u\n", |
| 5637 | port_num + 1); |
| 5638 | |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5639 | ibdev->port[port_num].roce.last_port_state = IB_PORT_DOWN; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5640 | } |
| 5641 | |
| 5642 | /* The mlx5_ib_multiport_mutex should be held when calling this function */ |
| 5643 | static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5644 | struct mlx5_ib_multiport_info *mpi) |
| 5645 | { |
| 5646 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5647 | int err; |
| 5648 | |
| 5649 | spin_lock(&ibdev->port[port_num].mp.mpi_lock); |
| 5650 | if (ibdev->port[port_num].mp.mpi) { |
Qing Huang | 2577188 | 2018-07-23 14:15:08 -0700 | [diff] [blame] | 5651 | mlx5_ib_dbg(ibdev, "port %d already affiliated.\n", |
| 5652 | port_num + 1); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5653 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5654 | return false; |
| 5655 | } |
| 5656 | |
| 5657 | ibdev->port[port_num].mp.mpi = mpi; |
| 5658 | mpi->ibdev = ibdev; |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5659 | mpi->mdev_events.notifier_call = NULL; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5660 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5661 | |
| 5662 | err = mlx5_nic_vport_affiliate_multiport(ibdev->mdev, mpi->mdev); |
| 5663 | if (err) |
| 5664 | goto unbind; |
| 5665 | |
| 5666 | err = get_port_caps(ibdev, mlx5_core_native_port_num(mpi->mdev)); |
| 5667 | if (err) |
| 5668 | goto unbind; |
| 5669 | |
| 5670 | err = mlx5_add_netdev_notifier(ibdev, port_num); |
| 5671 | if (err) { |
| 5672 | mlx5_ib_err(ibdev, "failed adding netdev notifier for port %u\n", |
| 5673 | port_num + 1); |
| 5674 | goto unbind; |
| 5675 | } |
| 5676 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5677 | mpi->mdev_events.notifier_call = mlx5_ib_event_slave_port; |
| 5678 | mlx5_notifier_register(mpi->mdev, &mpi->mdev_events); |
| 5679 | |
Greg Kroah-Hartman | 73eb8f0 | 2019-01-22 16:17:57 +0100 | [diff] [blame] | 5680 | mlx5_ib_init_cong_debugfs(ibdev, port_num); |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5681 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5682 | return true; |
| 5683 | |
| 5684 | unbind: |
| 5685 | mlx5_ib_unbind_slave_port(ibdev, mpi); |
| 5686 | return false; |
| 5687 | } |
| 5688 | |
| 5689 | static int mlx5_ib_init_multiport_master(struct mlx5_ib_dev *dev) |
| 5690 | { |
| 5691 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5692 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5693 | port_num + 1); |
| 5694 | struct mlx5_ib_multiport_info *mpi; |
| 5695 | int err; |
| 5696 | int i; |
| 5697 | |
| 5698 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5699 | return 0; |
| 5700 | |
| 5701 | err = mlx5_query_nic_vport_system_image_guid(dev->mdev, |
| 5702 | &dev->sys_image_guid); |
| 5703 | if (err) |
| 5704 | return err; |
| 5705 | |
| 5706 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 5707 | if (err) |
| 5708 | return err; |
| 5709 | |
| 5710 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5711 | for (i = 0; i < dev->num_ports; i++) { |
| 5712 | bool bound = false; |
| 5713 | |
| 5714 | /* build a stub multiport info struct for the native port. */ |
| 5715 | if (i == port_num) { |
| 5716 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 5717 | if (!mpi) { |
| 5718 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5719 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5720 | return -ENOMEM; |
| 5721 | } |
| 5722 | |
| 5723 | mpi->is_master = true; |
| 5724 | mpi->mdev = dev->mdev; |
| 5725 | mpi->sys_image_guid = dev->sys_image_guid; |
| 5726 | dev->port[i].mp.mpi = mpi; |
| 5727 | mpi->ibdev = dev; |
| 5728 | mpi = NULL; |
| 5729 | continue; |
| 5730 | } |
| 5731 | |
| 5732 | list_for_each_entry(mpi, &mlx5_ib_unaffiliated_port_list, |
| 5733 | list) { |
| 5734 | if (dev->sys_image_guid == mpi->sys_image_guid && |
| 5735 | (mlx5_core_native_port_num(mpi->mdev) - 1) == i) { |
| 5736 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 5737 | } |
| 5738 | |
| 5739 | if (bound) { |
| 5740 | dev_dbg(&mpi->mdev->pdev->dev, "removing port from unaffiliated list.\n"); |
| 5741 | mlx5_ib_dbg(dev, "port %d bound\n", i + 1); |
| 5742 | list_del(&mpi->list); |
| 5743 | break; |
| 5744 | } |
| 5745 | } |
| 5746 | if (!bound) { |
| 5747 | get_port_caps(dev, i + 1); |
| 5748 | mlx5_ib_dbg(dev, "no free port found for port %d\n", |
| 5749 | i + 1); |
| 5750 | } |
| 5751 | } |
| 5752 | |
| 5753 | list_add_tail(&dev->ib_dev_list, &mlx5_ib_dev_list); |
| 5754 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5755 | return err; |
| 5756 | } |
| 5757 | |
| 5758 | static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev) |
| 5759 | { |
| 5760 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5761 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5762 | port_num + 1); |
| 5763 | int i; |
| 5764 | |
| 5765 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5766 | return; |
| 5767 | |
| 5768 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5769 | for (i = 0; i < dev->num_ports; i++) { |
| 5770 | if (dev->port[i].mp.mpi) { |
| 5771 | /* Destroy the native port stub */ |
| 5772 | if (i == port_num) { |
| 5773 | kfree(dev->port[i].mp.mpi); |
| 5774 | dev->port[i].mp.mpi = NULL; |
| 5775 | } else { |
| 5776 | mlx5_ib_dbg(dev, "unbinding port_num: %d\n", i + 1); |
| 5777 | mlx5_ib_unbind_slave_port(dev, dev->port[i].mp.mpi); |
| 5778 | } |
| 5779 | } |
| 5780 | } |
| 5781 | |
| 5782 | mlx5_ib_dbg(dev, "removing from devlist\n"); |
| 5783 | list_del(&dev->ib_dev_list); |
| 5784 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5785 | |
| 5786 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5787 | } |
| 5788 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5789 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 5790 | mlx5_ib_dm, |
| 5791 | UVERBS_OBJECT_DM, |
| 5792 | UVERBS_METHOD_DM_ALLOC, |
| 5793 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 5794 | UVERBS_ATTR_TYPE(u64), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5795 | UA_MANDATORY), |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5796 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 5797 | UVERBS_ATTR_TYPE(u16), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5798 | UA_MANDATORY)); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5799 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5800 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 5801 | mlx5_ib_flow_action, |
| 5802 | UVERBS_OBJECT_FLOW_ACTION, |
| 5803 | UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, |
Jason Gunthorpe | bccd062 | 2018-07-26 16:37:14 -0600 | [diff] [blame] | 5804 | UVERBS_ATTR_FLAGS_IN(MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 5805 | enum mlx5_ib_uapi_flow_action_flags)); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 5806 | |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 5807 | static const struct uapi_definition mlx5_ib_defs[] = { |
| 5808 | #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) |
Jason Gunthorpe | 36e235c | 2018-11-12 22:59:53 +0200 | [diff] [blame] | 5809 | UAPI_DEF_CHAIN(mlx5_ib_devx_defs), |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 5810 | UAPI_DEF_CHAIN(mlx5_ib_flow_defs), |
| 5811 | #endif |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5812 | |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 5813 | UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_FLOW_ACTION, |
| 5814 | &mlx5_ib_flow_action), |
| 5815 | UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_DM, &mlx5_ib_dm), |
| 5816 | {} |
| 5817 | }; |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5818 | |
Raed Salem | 1a1e03d | 2018-05-31 16:43:41 +0300 | [diff] [blame] | 5819 | static int mlx5_ib_read_counters(struct ib_counters *counters, |
| 5820 | struct ib_counters_read_attr *read_attr, |
| 5821 | struct uverbs_attr_bundle *attrs) |
| 5822 | { |
| 5823 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 5824 | struct mlx5_read_counters_attr mread_attr = {}; |
| 5825 | struct mlx5_ib_flow_counters_desc *desc; |
| 5826 | int ret, i; |
| 5827 | |
| 5828 | mutex_lock(&mcounters->mcntrs_mutex); |
| 5829 | if (mcounters->cntrs_max_index > read_attr->ncounters) { |
| 5830 | ret = -EINVAL; |
| 5831 | goto err_bound; |
| 5832 | } |
| 5833 | |
| 5834 | mread_attr.out = kcalloc(mcounters->counters_num, sizeof(u64), |
| 5835 | GFP_KERNEL); |
| 5836 | if (!mread_attr.out) { |
| 5837 | ret = -ENOMEM; |
| 5838 | goto err_bound; |
| 5839 | } |
| 5840 | |
| 5841 | mread_attr.hw_cntrs_hndl = mcounters->hw_cntrs_hndl; |
| 5842 | mread_attr.flags = read_attr->flags; |
| 5843 | ret = mcounters->read_counters(counters->device, &mread_attr); |
| 5844 | if (ret) |
| 5845 | goto err_read; |
| 5846 | |
| 5847 | /* do the pass over the counters data array to assign according to the |
| 5848 | * descriptions and indexing pairs |
| 5849 | */ |
| 5850 | desc = mcounters->counters_data; |
| 5851 | for (i = 0; i < mcounters->ncounters; i++) |
| 5852 | read_attr->counters_buff[desc[i].index] += mread_attr.out[desc[i].description]; |
| 5853 | |
| 5854 | err_read: |
| 5855 | kfree(mread_attr.out); |
| 5856 | err_bound: |
| 5857 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 5858 | return ret; |
| 5859 | } |
| 5860 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5861 | static int mlx5_ib_destroy_counters(struct ib_counters *counters) |
| 5862 | { |
| 5863 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 5864 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 5865 | counters_clear_description(counters); |
| 5866 | if (mcounters->hw_cntrs_hndl) |
| 5867 | mlx5_fc_destroy(to_mdev(counters->device)->mdev, |
| 5868 | mcounters->hw_cntrs_hndl); |
| 5869 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5870 | kfree(mcounters); |
| 5871 | |
| 5872 | return 0; |
| 5873 | } |
| 5874 | |
| 5875 | static struct ib_counters *mlx5_ib_create_counters(struct ib_device *device, |
| 5876 | struct uverbs_attr_bundle *attrs) |
| 5877 | { |
| 5878 | struct mlx5_ib_mcounters *mcounters; |
| 5879 | |
| 5880 | mcounters = kzalloc(sizeof(*mcounters), GFP_KERNEL); |
| 5881 | if (!mcounters) |
| 5882 | return ERR_PTR(-ENOMEM); |
| 5883 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 5884 | mutex_init(&mcounters->mcntrs_mutex); |
| 5885 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5886 | return &mcounters->ibcntrs; |
| 5887 | } |
| 5888 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 5889 | static void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5890 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5891 | mlx5_ib_cleanup_multiport_master(dev); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5892 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
Yishai Hadas | 534fd7a | 2019-01-13 16:01:17 +0200 | [diff] [blame] | 5893 | srcu_barrier(&dev->mr_srcu); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5894 | cleanup_srcu_struct(&dev->mr_srcu); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5895 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5896 | } |
| 5897 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 5898 | static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5899 | { |
| 5900 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5901 | int err; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5902 | int i; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5903 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5904 | for (i = 0; i < dev->num_ports; i++) { |
| 5905 | spin_lock_init(&dev->port[i].mp.mpi_lock); |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5906 | rwlock_init(&dev->port[i].roce.netdev_lock); |
Mark Bloch | d3b5cc1 | 2019-03-28 15:46:26 +0200 | [diff] [blame] | 5907 | dev->port[i].roce.dev = dev; |
| 5908 | dev->port[i].roce.native_port_num = i + 1; |
| 5909 | dev->port[i].roce.last_port_state = IB_PORT_DOWN; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | err = mlx5_ib_init_multiport_master(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5913 | if (err) |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 5914 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5915 | |
Mark Bloch | a989ea0 | 2019-03-28 15:27:40 +0200 | [diff] [blame] | 5916 | err = set_has_smi_cap(dev); |
| 5917 | if (err) |
| 5918 | return err; |
| 5919 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5920 | if (!mlx5_core_mp_enabled(mdev)) { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5921 | for (i = 1; i <= dev->num_ports; i++) { |
| 5922 | err = get_port_caps(dev, i); |
| 5923 | if (err) |
| 5924 | break; |
| 5925 | } |
| 5926 | } else { |
| 5927 | err = get_port_caps(dev, mlx5_core_native_port_num(mdev)); |
| 5928 | } |
| 5929 | if (err) |
| 5930 | goto err_mp; |
| 5931 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 5932 | if (mlx5_use_mad_ifc(dev)) |
| 5933 | get_ext_port_caps(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5934 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5935 | dev->ib_dev.owner = THIS_MODULE; |
| 5936 | dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Sagi Grimberg | c6790aa | 2015-09-24 10:34:23 +0300 | [diff] [blame] | 5937 | dev->ib_dev.local_dma_lkey = 0 /* not supported for now */; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 5938 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
Saeed Mahameed | f2f3df5 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 5939 | dev->ib_dev.num_comp_vectors = mlx5_comp_vectors_count(mdev); |
Bart Van Assche | 9b0c289 | 2017-01-20 13:04:21 -0800 | [diff] [blame] | 5940 | dev->ib_dev.dev.parent = &mdev->pdev->dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5941 | |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5942 | mutex_init(&dev->cap_mask_mutex); |
| 5943 | INIT_LIST_HEAD(&dev->qp_list); |
| 5944 | spin_lock_init(&dev->reset_flow_resource_lock); |
| 5945 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5946 | spin_lock_init(&dev->memic.memic_lock); |
| 5947 | dev->memic.dev = mdev; |
| 5948 | |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5949 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5950 | err = init_srcu_struct(&dev->mr_srcu); |
Moni Shoua | a6bc387 | 2019-02-17 16:08:22 +0200 | [diff] [blame] | 5951 | if (err) |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5952 | goto err_mp; |
Jason Gunthorpe | 623d154 | 2018-12-20 16:39:26 -0700 | [diff] [blame] | 5953 | } |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5954 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5955 | return 0; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5956 | err_mp: |
| 5957 | mlx5_ib_cleanup_multiport_master(dev); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5958 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5959 | return -ENOMEM; |
| 5960 | } |
| 5961 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5962 | static int mlx5_ib_stage_flow_db_init(struct mlx5_ib_dev *dev) |
| 5963 | { |
| 5964 | dev->flow_db = kzalloc(sizeof(*dev->flow_db), GFP_KERNEL); |
| 5965 | |
| 5966 | if (!dev->flow_db) |
| 5967 | return -ENOMEM; |
| 5968 | |
| 5969 | mutex_init(&dev->flow_db->lock); |
| 5970 | |
| 5971 | return 0; |
| 5972 | } |
| 5973 | |
| 5974 | static void mlx5_ib_stage_flow_db_cleanup(struct mlx5_ib_dev *dev) |
| 5975 | { |
| 5976 | kfree(dev->flow_db); |
| 5977 | } |
| 5978 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 5979 | static const struct ib_device_ops mlx5_ib_dev_ops = { |
| 5980 | .add_gid = mlx5_ib_add_gid, |
| 5981 | .alloc_mr = mlx5_ib_alloc_mr, |
| 5982 | .alloc_pd = mlx5_ib_alloc_pd, |
| 5983 | .alloc_ucontext = mlx5_ib_alloc_ucontext, |
| 5984 | .attach_mcast = mlx5_ib_mcg_attach, |
| 5985 | .check_mr_status = mlx5_ib_check_mr_status, |
| 5986 | .create_ah = mlx5_ib_create_ah, |
| 5987 | .create_counters = mlx5_ib_create_counters, |
| 5988 | .create_cq = mlx5_ib_create_cq, |
| 5989 | .create_flow = mlx5_ib_create_flow, |
| 5990 | .create_qp = mlx5_ib_create_qp, |
| 5991 | .create_srq = mlx5_ib_create_srq, |
| 5992 | .dealloc_pd = mlx5_ib_dealloc_pd, |
| 5993 | .dealloc_ucontext = mlx5_ib_dealloc_ucontext, |
| 5994 | .del_gid = mlx5_ib_del_gid, |
| 5995 | .dereg_mr = mlx5_ib_dereg_mr, |
| 5996 | .destroy_ah = mlx5_ib_destroy_ah, |
| 5997 | .destroy_counters = mlx5_ib_destroy_counters, |
| 5998 | .destroy_cq = mlx5_ib_destroy_cq, |
| 5999 | .destroy_flow = mlx5_ib_destroy_flow, |
| 6000 | .destroy_flow_action = mlx5_ib_destroy_flow_action, |
| 6001 | .destroy_qp = mlx5_ib_destroy_qp, |
| 6002 | .destroy_srq = mlx5_ib_destroy_srq, |
| 6003 | .detach_mcast = mlx5_ib_mcg_detach, |
| 6004 | .disassociate_ucontext = mlx5_ib_disassociate_ucontext, |
| 6005 | .drain_rq = mlx5_ib_drain_rq, |
| 6006 | .drain_sq = mlx5_ib_drain_sq, |
| 6007 | .get_dev_fw_str = get_dev_fw_str, |
| 6008 | .get_dma_mr = mlx5_ib_get_dma_mr, |
| 6009 | .get_link_layer = mlx5_ib_port_link_layer, |
| 6010 | .map_mr_sg = mlx5_ib_map_mr_sg, |
| 6011 | .mmap = mlx5_ib_mmap, |
| 6012 | .modify_cq = mlx5_ib_modify_cq, |
| 6013 | .modify_device = mlx5_ib_modify_device, |
| 6014 | .modify_port = mlx5_ib_modify_port, |
| 6015 | .modify_qp = mlx5_ib_modify_qp, |
| 6016 | .modify_srq = mlx5_ib_modify_srq, |
| 6017 | .poll_cq = mlx5_ib_poll_cq, |
| 6018 | .post_recv = mlx5_ib_post_recv, |
| 6019 | .post_send = mlx5_ib_post_send, |
| 6020 | .post_srq_recv = mlx5_ib_post_srq_recv, |
| 6021 | .process_mad = mlx5_ib_process_mad, |
| 6022 | .query_ah = mlx5_ib_query_ah, |
| 6023 | .query_device = mlx5_ib_query_device, |
| 6024 | .query_gid = mlx5_ib_query_gid, |
| 6025 | .query_pkey = mlx5_ib_query_pkey, |
| 6026 | .query_qp = mlx5_ib_query_qp, |
| 6027 | .query_srq = mlx5_ib_query_srq, |
| 6028 | .read_counters = mlx5_ib_read_counters, |
| 6029 | .reg_user_mr = mlx5_ib_reg_user_mr, |
| 6030 | .req_notify_cq = mlx5_ib_arm_cq, |
| 6031 | .rereg_user_mr = mlx5_ib_rereg_user_mr, |
| 6032 | .resize_cq = mlx5_ib_resize_cq, |
Leon Romanovsky | d345691 | 2019-04-03 16:42:42 +0300 | [diff] [blame] | 6033 | |
| 6034 | INIT_RDMA_OBJ_SIZE(ib_ah, mlx5_ib_ah, ibah), |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 6035 | INIT_RDMA_OBJ_SIZE(ib_pd, mlx5_ib_pd, ibpd), |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 6036 | INIT_RDMA_OBJ_SIZE(ib_srq, mlx5_ib_srq, ibsrq), |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 6037 | INIT_RDMA_OBJ_SIZE(ib_ucontext, mlx5_ib_ucontext, ibucontext), |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6038 | }; |
| 6039 | |
| 6040 | static const struct ib_device_ops mlx5_ib_dev_flow_ipsec_ops = { |
| 6041 | .create_flow_action_esp = mlx5_ib_create_flow_action_esp, |
| 6042 | .modify_flow_action_esp = mlx5_ib_modify_flow_action_esp, |
| 6043 | }; |
| 6044 | |
| 6045 | static const struct ib_device_ops mlx5_ib_dev_ipoib_enhanced_ops = { |
| 6046 | .rdma_netdev_get_params = mlx5_ib_rn_get_params, |
| 6047 | }; |
| 6048 | |
| 6049 | static const struct ib_device_ops mlx5_ib_dev_sriov_ops = { |
| 6050 | .get_vf_config = mlx5_ib_get_vf_config, |
| 6051 | .get_vf_stats = mlx5_ib_get_vf_stats, |
| 6052 | .set_vf_guid = mlx5_ib_set_vf_guid, |
| 6053 | .set_vf_link_state = mlx5_ib_set_vf_link_state, |
| 6054 | }; |
| 6055 | |
| 6056 | static const struct ib_device_ops mlx5_ib_dev_mw_ops = { |
| 6057 | .alloc_mw = mlx5_ib_alloc_mw, |
| 6058 | .dealloc_mw = mlx5_ib_dealloc_mw, |
| 6059 | }; |
| 6060 | |
| 6061 | static const struct ib_device_ops mlx5_ib_dev_xrc_ops = { |
| 6062 | .alloc_xrcd = mlx5_ib_alloc_xrcd, |
| 6063 | .dealloc_xrcd = mlx5_ib_dealloc_xrcd, |
| 6064 | }; |
| 6065 | |
| 6066 | static const struct ib_device_ops mlx5_ib_dev_dm_ops = { |
| 6067 | .alloc_dm = mlx5_ib_alloc_dm, |
| 6068 | .dealloc_dm = mlx5_ib_dealloc_dm, |
| 6069 | .reg_dm_mr = mlx5_ib_reg_dm_mr, |
| 6070 | }; |
| 6071 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6072 | static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6073 | { |
| 6074 | struct mlx5_core_dev *mdev = dev->mdev; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6075 | int err; |
| 6076 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6077 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
| 6078 | dev->ib_dev.uverbs_cmd_mask = |
| 6079 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 6080 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 6081 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 6082 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 6083 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
Moni Shoua | 41c450f | 2016-11-23 08:23:26 +0200 | [diff] [blame] | 6084 | (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
| 6085 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6086 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 6087 | (1ull << IB_USER_VERBS_CMD_REREG_MR) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6088 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 6089 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 6090 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 6091 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 6092 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 6093 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 6094 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 6095 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 6096 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 6097 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 6098 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 6099 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 6100 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 6101 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 6102 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 6103 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 6104 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Haggai Eran | 1707cb4 | 2015-02-08 13:28:52 +0200 | [diff] [blame] | 6105 | dev->ib_dev.uverbs_ex_cmd_mask = |
Matan Barak | d4584dd | 2016-01-28 17:51:46 +0200 | [diff] [blame] | 6106 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE) | |
| 6107 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 6108 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) | |
Yonatan Cohen | b0e9df6 | 2017-11-13 10:51:15 +0200 | [diff] [blame] | 6109 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_QP) | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6110 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_CQ) | |
| 6111 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) | |
| 6112 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6113 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 6114 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
| 6115 | IS_ENABLED(CONFIG_MLX5_CORE_IPOIB)) |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6116 | ib_set_device_ops(&dev->ib_dev, |
| 6117 | &mlx5_ib_dev_ipoib_enhanced_ops); |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 6118 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6119 | if (mlx5_core_is_pf(mdev)) |
| 6120 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_sriov_ops); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 6121 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 6122 | dev->umr_fence = mlx5_get_umr_fence(MLX5_CAP_GEN(mdev, umr_fence)); |
| 6123 | |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6124 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6125 | dev->ib_dev.uverbs_cmd_mask |= |
| 6126 | (1ull << IB_USER_VERBS_CMD_ALLOC_MW) | |
| 6127 | (1ull << IB_USER_VERBS_CMD_DEALLOC_MW); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6128 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_mw_ops); |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6129 | } |
| 6130 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 6131 | if (MLX5_CAP_GEN(mdev, xrc)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6132 | dev->ib_dev.uverbs_cmd_mask |= |
| 6133 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 6134 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6135 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_xrc_ops); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6136 | } |
| 6137 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6138 | if (MLX5_CAP_DEV_MEM(mdev, memic)) |
| 6139 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_dm_ops); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 6140 | |
Jason Gunthorpe | dfb631a | 2018-11-12 22:59:49 +0200 | [diff] [blame] | 6141 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6142 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 6143 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_flow_ipsec_ops); |
Matan Barak | 0ede73b | 2018-03-19 15:02:34 +0200 | [diff] [blame] | 6144 | dev->ib_dev.driver_id = RDMA_DRIVER_MLX5; |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6145 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_ops); |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 6146 | |
Jason Gunthorpe | 36e235c | 2018-11-12 22:59:53 +0200 | [diff] [blame] | 6147 | if (IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)) |
| 6148 | dev->ib_dev.driver_def = mlx5_ib_defs; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6149 | |
| 6150 | err = init_node_data(dev); |
| 6151 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6152 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6153 | |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 6154 | if ((MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) && |
Jason Gunthorpe | e7996a9 | 2018-01-29 13:26:40 -0700 | [diff] [blame] | 6155 | (MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) || |
| 6156 | MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 6157 | mutex_init(&dev->lb.mutex); |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 6158 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6159 | return 0; |
| 6160 | } |
| 6161 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6162 | static const struct ib_device_ops mlx5_ib_dev_port_ops = { |
| 6163 | .get_port_immutable = mlx5_port_immutable, |
| 6164 | .query_port = mlx5_ib_query_port, |
| 6165 | }; |
| 6166 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6167 | static int mlx5_ib_stage_non_default_cb(struct mlx5_ib_dev *dev) |
| 6168 | { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6169 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_port_ops); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6170 | return 0; |
| 6171 | } |
| 6172 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6173 | static const struct ib_device_ops mlx5_ib_dev_port_rep_ops = { |
| 6174 | .get_port_immutable = mlx5_port_rep_immutable, |
| 6175 | .query_port = mlx5_ib_rep_query_port, |
| 6176 | }; |
| 6177 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6178 | static int mlx5_ib_stage_rep_non_default_cb(struct mlx5_ib_dev *dev) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6179 | { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6180 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_port_rep_ops); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6181 | return 0; |
| 6182 | } |
| 6183 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6184 | static const struct ib_device_ops mlx5_ib_dev_common_roce_ops = { |
| 6185 | .create_rwq_ind_table = mlx5_ib_create_rwq_ind_table, |
| 6186 | .create_wq = mlx5_ib_create_wq, |
| 6187 | .destroy_rwq_ind_table = mlx5_ib_destroy_rwq_ind_table, |
| 6188 | .destroy_wq = mlx5_ib_destroy_wq, |
| 6189 | .get_netdev = mlx5_ib_get_netdev, |
| 6190 | .modify_wq = mlx5_ib_modify_wq, |
| 6191 | }; |
| 6192 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6193 | static int mlx5_ib_stage_common_roce_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6194 | { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6195 | u8 port_num; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6196 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6197 | dev->ib_dev.uverbs_ex_cmd_mask |= |
| 6198 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_WQ) | |
| 6199 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_WQ) | |
| 6200 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_WQ) | |
| 6201 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) | |
| 6202 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6203 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_common_roce_ops); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6204 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6205 | port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6206 | |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 6207 | /* Register only for native ports */ |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6208 | return mlx5_add_netdev_notifier(dev, port_num); |
| 6209 | } |
| 6210 | |
| 6211 | static void mlx5_ib_stage_common_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6212 | { |
| 6213 | u8 port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6214 | |
| 6215 | mlx5_remove_netdev_notifier(dev, port_num); |
| 6216 | } |
| 6217 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6218 | static int mlx5_ib_stage_rep_roce_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6219 | { |
| 6220 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6221 | enum rdma_link_layer ll; |
| 6222 | int port_type_cap; |
| 6223 | int err = 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6224 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6225 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6226 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6227 | |
| 6228 | if (ll == IB_LINK_LAYER_ETHERNET) |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6229 | err = mlx5_ib_stage_common_roce_init(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6230 | |
| 6231 | return err; |
| 6232 | } |
| 6233 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6234 | static void mlx5_ib_stage_rep_roce_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6235 | { |
| 6236 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 6237 | } |
| 6238 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6239 | static int mlx5_ib_stage_roce_init(struct mlx5_ib_dev *dev) |
| 6240 | { |
| 6241 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6242 | enum rdma_link_layer ll; |
| 6243 | int port_type_cap; |
| 6244 | int err; |
| 6245 | |
| 6246 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6247 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6248 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6249 | if (ll == IB_LINK_LAYER_ETHERNET) { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6250 | err = mlx5_ib_stage_common_roce_init(dev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6251 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6252 | return err; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6253 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6254 | err = mlx5_enable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6255 | if (err) |
| 6256 | goto cleanup; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6257 | } |
| 6258 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6259 | return 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6260 | cleanup: |
| 6261 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 6262 | |
| 6263 | return err; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6264 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6265 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6266 | static void mlx5_ib_stage_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6267 | { |
| 6268 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6269 | enum rdma_link_layer ll; |
| 6270 | int port_type_cap; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6271 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6272 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6273 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6274 | |
| 6275 | if (ll == IB_LINK_LAYER_ETHERNET) { |
| 6276 | mlx5_disable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6277 | mlx5_ib_stage_common_roce_cleanup(dev); |
Kamal Heib | 45bded2 | 2017-01-18 14:10:32 +0200 | [diff] [blame] | 6278 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6279 | } |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6280 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6281 | static int mlx5_ib_stage_dev_res_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6282 | { |
| 6283 | return create_dev_resources(&dev->devr); |
| 6284 | } |
Parav Pandit | 4a2da0b | 2017-05-30 10:05:15 +0300 | [diff] [blame] | 6285 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6286 | static void mlx5_ib_stage_dev_res_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6287 | { |
| 6288 | destroy_dev_resources(&dev->devr); |
| 6289 | } |
| 6290 | |
| 6291 | static int mlx5_ib_stage_odp_init(struct mlx5_ib_dev *dev) |
| 6292 | { |
Mark Bloch | 07321b3 | 2018-01-01 13:07:00 +0200 | [diff] [blame] | 6293 | mlx5_ib_internal_fill_odp_caps(dev); |
| 6294 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6295 | return mlx5_ib_odp_init_one(dev); |
| 6296 | } |
| 6297 | |
Kamal Heib | f3ffed0 | 2019-01-30 16:13:42 +0200 | [diff] [blame] | 6298 | static void mlx5_ib_stage_odp_cleanup(struct mlx5_ib_dev *dev) |
Saeed Mahameed | d5d284b | 2018-11-19 10:52:41 -0800 | [diff] [blame] | 6299 | { |
| 6300 | mlx5_ib_odp_cleanup_one(dev); |
| 6301 | } |
| 6302 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6303 | static const struct ib_device_ops mlx5_ib_dev_hw_stats_ops = { |
| 6304 | .alloc_hw_stats = mlx5_ib_alloc_hw_stats, |
| 6305 | .get_hw_stats = mlx5_ib_get_hw_stats, |
| 6306 | }; |
| 6307 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6308 | static int mlx5_ib_stage_counters_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6309 | { |
Mark Bloch | 5e1e761 | 2018-01-01 13:07:01 +0200 | [diff] [blame] | 6310 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6311 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_hw_stats_ops); |
Mark Bloch | 5e1e761 | 2018-01-01 13:07:01 +0200 | [diff] [blame] | 6312 | |
| 6313 | return mlx5_ib_alloc_counters(dev); |
| 6314 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6315 | |
| 6316 | return 0; |
| 6317 | } |
| 6318 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6319 | static void mlx5_ib_stage_counters_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6320 | { |
| 6321 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) |
| 6322 | mlx5_ib_dealloc_counters(dev); |
| 6323 | } |
| 6324 | |
| 6325 | static int mlx5_ib_stage_cong_debugfs_init(struct mlx5_ib_dev *dev) |
| 6326 | { |
Greg Kroah-Hartman | 73eb8f0 | 2019-01-22 16:17:57 +0100 | [diff] [blame] | 6327 | mlx5_ib_init_cong_debugfs(dev, |
| 6328 | mlx5_core_native_port_num(dev->mdev) - 1); |
| 6329 | return 0; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | static void mlx5_ib_stage_cong_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 6333 | { |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 6334 | mlx5_ib_cleanup_cong_debugfs(dev, |
| 6335 | mlx5_core_native_port_num(dev->mdev) - 1); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | static int mlx5_ib_stage_uar_init(struct mlx5_ib_dev *dev) |
| 6339 | { |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6340 | dev->mdev->priv.uar = mlx5_get_uars_page(dev->mdev); |
Leon Romanovsky | 444261c | 2018-04-23 17:01:56 +0300 | [diff] [blame] | 6341 | return PTR_ERR_OR_ZERO(dev->mdev->priv.uar); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | static void mlx5_ib_stage_uar_cleanup(struct mlx5_ib_dev *dev) |
| 6345 | { |
| 6346 | mlx5_put_uars_page(dev->mdev, dev->mdev->priv.uar); |
| 6347 | } |
| 6348 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6349 | static int mlx5_ib_stage_bfrag_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6350 | { |
| 6351 | int err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6352 | |
| 6353 | err = mlx5_alloc_bfreg(dev->mdev, &dev->bfreg, false, false); |
| 6354 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6355 | return err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6356 | |
| 6357 | err = mlx5_alloc_bfreg(dev->mdev, &dev->fp_bfreg, false, true); |
| 6358 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6359 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6360 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6361 | return err; |
| 6362 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 6363 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6364 | static void mlx5_ib_stage_bfrag_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6365 | { |
| 6366 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
| 6367 | mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
| 6368 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6369 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6370 | static int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6371 | { |
Jason Gunthorpe | e349f85 | 2018-09-25 16:58:09 -0600 | [diff] [blame] | 6372 | const char *name; |
| 6373 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 6374 | rdma_set_device_sysfs_group(&dev->ib_dev, &mlx5_attr_group); |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 6375 | if (!mlx5_lag_is_roce(dev->mdev)) |
Jason Gunthorpe | e349f85 | 2018-09-25 16:58:09 -0600 | [diff] [blame] | 6376 | name = "mlx5_%d"; |
| 6377 | else |
| 6378 | name = "mlx5_bond_%d"; |
Parav Pandit | ea4baf7 | 2018-12-18 14:28:30 +0200 | [diff] [blame] | 6379 | return ib_register_device(&dev->ib_dev, name); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6380 | } |
| 6381 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6382 | static void mlx5_ib_stage_pre_ib_reg_umr_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6383 | { |
| 6384 | destroy_umrc_res(dev); |
| 6385 | } |
| 6386 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6387 | static void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6388 | { |
| 6389 | ib_unregister_device(&dev->ib_dev); |
| 6390 | } |
| 6391 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6392 | static int mlx5_ib_stage_post_ib_reg_umr_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6393 | { |
| 6394 | return create_umr_res(dev); |
| 6395 | } |
| 6396 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6397 | static int mlx5_ib_stage_delay_drop_init(struct mlx5_ib_dev *dev) |
| 6398 | { |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6399 | init_delay_drop(dev); |
| 6400 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6401 | return 0; |
| 6402 | } |
| 6403 | |
| 6404 | static void mlx5_ib_stage_delay_drop_cleanup(struct mlx5_ib_dev *dev) |
| 6405 | { |
| 6406 | cancel_delay_drop(dev); |
| 6407 | } |
| 6408 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6409 | static int mlx5_ib_stage_dev_notifier_init(struct mlx5_ib_dev *dev) |
| 6410 | { |
| 6411 | dev->mdev_events.notifier_call = mlx5_ib_event; |
| 6412 | mlx5_notifier_register(dev->mdev, &dev->mdev_events); |
| 6413 | return 0; |
| 6414 | } |
| 6415 | |
| 6416 | static void mlx5_ib_stage_dev_notifier_cleanup(struct mlx5_ib_dev *dev) |
| 6417 | { |
| 6418 | mlx5_notifier_unregister(dev->mdev, &dev->mdev_events); |
| 6419 | } |
| 6420 | |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6421 | static int mlx5_ib_stage_devx_init(struct mlx5_ib_dev *dev) |
| 6422 | { |
| 6423 | int uid; |
| 6424 | |
Yishai Hadas | fb98153 | 2018-11-26 08:28:36 +0200 | [diff] [blame] | 6425 | uid = mlx5_ib_devx_create(dev, false); |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6426 | if (uid > 0) |
| 6427 | dev->devx_whitelist_uid = uid; |
| 6428 | |
| 6429 | return 0; |
| 6430 | } |
| 6431 | static void mlx5_ib_stage_devx_cleanup(struct mlx5_ib_dev *dev) |
| 6432 | { |
| 6433 | if (dev->devx_whitelist_uid) |
| 6434 | mlx5_ib_devx_destroy(dev, dev->devx_whitelist_uid); |
| 6435 | } |
| 6436 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6437 | void __mlx5_ib_remove(struct mlx5_ib_dev *dev, |
| 6438 | const struct mlx5_ib_profile *profile, |
| 6439 | int stage) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6440 | { |
| 6441 | /* Number of stages to cleanup */ |
| 6442 | while (stage) { |
| 6443 | stage--; |
| 6444 | if (profile->stage[stage].cleanup) |
| 6445 | profile->stage[stage].cleanup(dev); |
| 6446 | } |
Mark Bloch | 4a6dc85 | 2019-03-28 15:27:34 +0200 | [diff] [blame] | 6447 | |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6448 | kfree(dev->port); |
Mark Bloch | 4a6dc85 | 2019-03-28 15:27:34 +0200 | [diff] [blame] | 6449 | ib_dealloc_device(&dev->ib_dev); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6450 | } |
| 6451 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6452 | void *__mlx5_ib_add(struct mlx5_ib_dev *dev, |
| 6453 | const struct mlx5_ib_profile *profile) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6454 | { |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6455 | int err; |
| 6456 | int i; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6457 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6458 | for (i = 0; i < MLX5_IB_STAGE_MAX; i++) { |
| 6459 | if (profile->stage[i].init) { |
| 6460 | err = profile->stage[i].init(dev); |
| 6461 | if (err) |
| 6462 | goto err_out; |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | dev->profile = profile; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6467 | dev->ib_active = true; |
| 6468 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6469 | return dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6470 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6471 | err_out: |
| 6472 | __mlx5_ib_remove(dev, profile, i); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6473 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6474 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6475 | } |
| 6476 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6477 | static const struct mlx5_ib_profile pf_profile = { |
| 6478 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6479 | mlx5_ib_stage_init_init, |
| 6480 | mlx5_ib_stage_init_cleanup), |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 6481 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6482 | mlx5_ib_stage_flow_db_init, |
| 6483 | mlx5_ib_stage_flow_db_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6484 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6485 | mlx5_ib_stage_caps_init, |
| 6486 | NULL), |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6487 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6488 | mlx5_ib_stage_non_default_cb, |
| 6489 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6490 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6491 | mlx5_ib_stage_roce_init, |
| 6492 | mlx5_ib_stage_roce_cleanup), |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 6493 | STAGE_CREATE(MLX5_IB_STAGE_SRQ, |
| 6494 | mlx5_init_srq_table, |
| 6495 | mlx5_cleanup_srq_table), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6496 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6497 | mlx5_ib_stage_dev_res_init, |
| 6498 | mlx5_ib_stage_dev_res_cleanup), |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6499 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER, |
| 6500 | mlx5_ib_stage_dev_notifier_init, |
| 6501 | mlx5_ib_stage_dev_notifier_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6502 | STAGE_CREATE(MLX5_IB_STAGE_ODP, |
| 6503 | mlx5_ib_stage_odp_init, |
Saeed Mahameed | d5d284b | 2018-11-19 10:52:41 -0800 | [diff] [blame] | 6504 | mlx5_ib_stage_odp_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6505 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6506 | mlx5_ib_stage_counters_init, |
| 6507 | mlx5_ib_stage_counters_cleanup), |
| 6508 | STAGE_CREATE(MLX5_IB_STAGE_CONG_DEBUGFS, |
| 6509 | mlx5_ib_stage_cong_debugfs_init, |
| 6510 | mlx5_ib_stage_cong_debugfs_cleanup), |
| 6511 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6512 | mlx5_ib_stage_uar_init, |
| 6513 | mlx5_ib_stage_uar_cleanup), |
| 6514 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6515 | mlx5_ib_stage_bfrag_init, |
| 6516 | mlx5_ib_stage_bfrag_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6517 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6518 | NULL, |
| 6519 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6520 | STAGE_CREATE(MLX5_IB_STAGE_WHITELIST_UID, |
| 6521 | mlx5_ib_stage_devx_init, |
| 6522 | mlx5_ib_stage_devx_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6523 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6524 | mlx5_ib_stage_ib_reg_init, |
| 6525 | mlx5_ib_stage_ib_reg_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6526 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6527 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6528 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6529 | STAGE_CREATE(MLX5_IB_STAGE_DELAY_DROP, |
| 6530 | mlx5_ib_stage_delay_drop_init, |
| 6531 | mlx5_ib_stage_delay_drop_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6532 | }; |
| 6533 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6534 | const struct mlx5_ib_profile uplink_rep_profile = { |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6535 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6536 | mlx5_ib_stage_init_init, |
| 6537 | mlx5_ib_stage_init_cleanup), |
| 6538 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6539 | mlx5_ib_stage_flow_db_init, |
| 6540 | mlx5_ib_stage_flow_db_cleanup), |
| 6541 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6542 | mlx5_ib_stage_caps_init, |
| 6543 | NULL), |
| 6544 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6545 | mlx5_ib_stage_rep_non_default_cb, |
| 6546 | NULL), |
| 6547 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6548 | mlx5_ib_stage_rep_roce_init, |
| 6549 | mlx5_ib_stage_rep_roce_cleanup), |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 6550 | STAGE_CREATE(MLX5_IB_STAGE_SRQ, |
| 6551 | mlx5_init_srq_table, |
| 6552 | mlx5_cleanup_srq_table), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6553 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6554 | mlx5_ib_stage_dev_res_init, |
| 6555 | mlx5_ib_stage_dev_res_cleanup), |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6556 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER, |
| 6557 | mlx5_ib_stage_dev_notifier_init, |
| 6558 | mlx5_ib_stage_dev_notifier_cleanup), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6559 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6560 | mlx5_ib_stage_counters_init, |
| 6561 | mlx5_ib_stage_counters_cleanup), |
| 6562 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6563 | mlx5_ib_stage_uar_init, |
| 6564 | mlx5_ib_stage_uar_cleanup), |
| 6565 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6566 | mlx5_ib_stage_bfrag_init, |
| 6567 | mlx5_ib_stage_bfrag_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6568 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6569 | NULL, |
| 6570 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Mark Bloch | 7f57510 | 2019-03-28 15:46:25 +0200 | [diff] [blame] | 6571 | STAGE_CREATE(MLX5_IB_STAGE_WHITELIST_UID, |
| 6572 | mlx5_ib_stage_devx_init, |
| 6573 | mlx5_ib_stage_devx_cleanup), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6574 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6575 | mlx5_ib_stage_ib_reg_init, |
| 6576 | mlx5_ib_stage_ib_reg_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6577 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6578 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6579 | NULL), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6580 | }; |
| 6581 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6582 | static void *mlx5_ib_add_slave_port(struct mlx5_core_dev *mdev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6583 | { |
| 6584 | struct mlx5_ib_multiport_info *mpi; |
| 6585 | struct mlx5_ib_dev *dev; |
| 6586 | bool bound = false; |
| 6587 | int err; |
| 6588 | |
| 6589 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 6590 | if (!mpi) |
| 6591 | return NULL; |
| 6592 | |
| 6593 | mpi->mdev = mdev; |
| 6594 | |
| 6595 | err = mlx5_query_nic_vport_system_image_guid(mdev, |
| 6596 | &mpi->sys_image_guid); |
| 6597 | if (err) { |
| 6598 | kfree(mpi); |
| 6599 | return NULL; |
| 6600 | } |
| 6601 | |
| 6602 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6603 | list_for_each_entry(dev, &mlx5_ib_dev_list, ib_dev_list) { |
| 6604 | if (dev->sys_image_guid == mpi->sys_image_guid) |
| 6605 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 6606 | |
| 6607 | if (bound) { |
| 6608 | rdma_roce_rescan_device(&dev->ib_dev); |
| 6609 | break; |
| 6610 | } |
| 6611 | } |
| 6612 | |
| 6613 | if (!bound) { |
| 6614 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 6615 | dev_dbg(&mdev->pdev->dev, "no suitable IB device found to bind to, added to unaffiliated list.\n"); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6616 | } |
| 6617 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6618 | |
| 6619 | return mpi; |
| 6620 | } |
| 6621 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6622 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
| 6623 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6624 | enum rdma_link_layer ll; |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6625 | struct mlx5_ib_dev *dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6626 | int port_type_cap; |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6627 | int num_ports; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6628 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6629 | printk_once(KERN_INFO "%s", mlx5_version); |
| 6630 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6631 | if (MLX5_ESWITCH_MANAGER(mdev) && |
| 6632 | mlx5_ib_eswitch_mode(mdev->priv.eswitch) == SRIOV_OFFLOADS) { |
Mark Bloch | 5fb58c9 | 2019-03-28 15:46:27 +0200 | [diff] [blame^] | 6633 | if (!mlx5_core_mp_enabled(mdev)) |
| 6634 | mlx5_ib_register_vport_reps(mdev); |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6635 | return mdev; |
| 6636 | } |
| 6637 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6638 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6639 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6640 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6641 | if (mlx5_core_is_mp_slave(mdev) && ll == IB_LINK_LAYER_ETHERNET) |
| 6642 | return mlx5_ib_add_slave_port(mdev); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6643 | |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6644 | num_ports = max(MLX5_CAP_GEN(mdev, num_ports), |
| 6645 | MLX5_CAP_GEN(mdev, num_vhca_ports)); |
Leon Romanovsky | 459cc69 | 2019-01-30 12:49:11 +0200 | [diff] [blame] | 6646 | dev = ib_alloc_device(mlx5_ib_dev, ib_dev); |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6647 | if (!dev) |
| 6648 | return NULL; |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6649 | dev->port = kcalloc(num_ports, sizeof(*dev->port), |
| 6650 | GFP_KERNEL); |
| 6651 | if (!dev->port) { |
| 6652 | ib_dealloc_device((struct ib_device *)dev); |
| 6653 | return NULL; |
| 6654 | } |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6655 | |
| 6656 | dev->mdev = mdev; |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6657 | dev->num_ports = num_ports; |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6658 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6659 | return __mlx5_ib_add(dev, &pf_profile); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6660 | } |
| 6661 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6662 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6663 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6664 | struct mlx5_ib_multiport_info *mpi; |
| 6665 | struct mlx5_ib_dev *dev; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6666 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6667 | if (MLX5_ESWITCH_MANAGER(mdev) && context == mdev) { |
| 6668 | mlx5_ib_unregister_vport_reps(mdev); |
| 6669 | return; |
| 6670 | } |
| 6671 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6672 | if (mlx5_core_is_mp_slave(mdev)) { |
| 6673 | mpi = context; |
| 6674 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6675 | if (mpi->ibdev) |
| 6676 | mlx5_ib_unbind_slave_port(mpi->ibdev, mpi); |
| 6677 | list_del(&mpi->list); |
| 6678 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6679 | return; |
| 6680 | } |
| 6681 | |
| 6682 | dev = context; |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6683 | __mlx5_ib_remove(dev, dev->profile, MLX5_IB_STAGE_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6684 | } |
| 6685 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6686 | static struct mlx5_interface mlx5_ib_interface = { |
| 6687 | .add = mlx5_ib_add, |
| 6688 | .remove = mlx5_ib_remove, |
Saeed Mahameed | 64613d94 | 2015-04-02 17:07:34 +0300 | [diff] [blame] | 6689 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6690 | }; |
| 6691 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6692 | unsigned long mlx5_ib_get_xlt_emergency_page(void) |
| 6693 | { |
| 6694 | mutex_lock(&xlt_emergency_page_mutex); |
| 6695 | return xlt_emergency_page; |
| 6696 | } |
| 6697 | |
| 6698 | void mlx5_ib_put_xlt_emergency_page(void) |
| 6699 | { |
| 6700 | mutex_unlock(&xlt_emergency_page_mutex); |
| 6701 | } |
| 6702 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6703 | static int __init mlx5_ib_init(void) |
| 6704 | { |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6705 | int err; |
| 6706 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6707 | xlt_emergency_page = __get_free_page(GFP_KERNEL); |
| 6708 | if (!xlt_emergency_page) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6709 | return -ENOMEM; |
| 6710 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6711 | mutex_init(&xlt_emergency_page_mutex); |
| 6712 | |
| 6713 | mlx5_ib_event_wq = alloc_ordered_workqueue("mlx5_ib_event_wq", 0); |
| 6714 | if (!mlx5_ib_event_wq) { |
| 6715 | free_page(xlt_emergency_page); |
| 6716 | return -ENOMEM; |
| 6717 | } |
| 6718 | |
Artemy Kovalyov | 81713d3 | 2017-01-18 16:58:11 +0200 | [diff] [blame] | 6719 | mlx5_ib_odp_init(); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6720 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6721 | err = mlx5_register_interface(&mlx5_ib_interface); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6722 | |
| 6723 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6724 | } |
| 6725 | |
| 6726 | static void __exit mlx5_ib_cleanup(void) |
| 6727 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6728 | mlx5_unregister_interface(&mlx5_ib_interface); |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6729 | destroy_workqueue(mlx5_ib_event_wq); |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6730 | mutex_destroy(&xlt_emergency_page_mutex); |
| 6731 | free_page(xlt_emergency_page); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6732 | } |
| 6733 | |
| 6734 | module_init(mlx5_ib_init); |
| 6735 | module_exit(mlx5_ib_cleanup); |