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. |
Noa Osherovich | 50f22fd | 2017-04-20 20:53:32 +0300 | [diff] [blame] | 509 | */ |
Aya Levin | bc4e12f | 2019-02-12 22:55:43 -0800 | [diff] [blame] | 510 | err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, |
| 511 | mdev_port_num); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 512 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 513 | goto out; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 514 | ext = MLX5_CAP_PCAM_FEATURE(dev->mdev, ptys_extended_ethernet); |
| 515 | 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] | 516 | |
Honggang Li | 7672ed3 | 2018-03-16 10:37:13 +0800 | [diff] [blame] | 517 | props->active_width = IB_WIDTH_4X; |
| 518 | props->active_speed = IB_SPEED_QDR; |
| 519 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 520 | translate_eth_proto_oper(eth_prot_oper, &props->active_speed, |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 521 | &props->active_width, ext); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 522 | |
Jason Gunthorpe | 2f944c0 | 2018-07-04 15:57:48 +0300 | [diff] [blame] | 523 | props->port_cap_flags |= IB_PORT_CM_SUP; |
| 524 | props->ip_gids = true; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 525 | |
| 526 | props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev, |
| 527 | roce_address_table_size); |
| 528 | props->max_mtu = IB_MTU_4096; |
| 529 | props->max_msg_sz = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg); |
| 530 | props->pkey_tbl_len = 1; |
| 531 | props->state = IB_PORT_DOWN; |
| 532 | props->phys_state = 3; |
| 533 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 534 | mlx5_query_nic_vport_qkey_viol_cntr(mdev, &qkey_viol_cntr); |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 535 | props->qkey_viol_cntr = qkey_viol_cntr; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 536 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 537 | /* If this is a stub query for an unaffiliated port stop here */ |
| 538 | if (!put_mdev) |
| 539 | goto out; |
| 540 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 541 | ndev = mlx5_ib_get_netdev(device, port_num); |
| 542 | if (!ndev) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 543 | goto out; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 544 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 545 | if (dev->lag_active) { |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 546 | rcu_read_lock(); |
| 547 | upper = netdev_master_upper_dev_get_rcu(ndev); |
| 548 | if (upper) { |
| 549 | dev_put(ndev); |
| 550 | ndev = upper; |
| 551 | dev_hold(ndev); |
| 552 | } |
| 553 | rcu_read_unlock(); |
| 554 | } |
| 555 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 556 | if (netif_running(ndev) && netif_carrier_ok(ndev)) { |
| 557 | props->state = IB_PORT_ACTIVE; |
| 558 | props->phys_state = 5; |
| 559 | } |
| 560 | |
| 561 | ndev_ib_mtu = iboe_get_mtu(ndev->mtu); |
| 562 | |
| 563 | dev_put(ndev); |
| 564 | |
| 565 | props->active_mtu = min(props->max_mtu, ndev_ib_mtu); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 566 | out: |
| 567 | if (put_mdev) |
| 568 | mlx5_ib_put_native_port_mdev(dev, port_num); |
| 569 | return err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 570 | } |
| 571 | |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 572 | struct mlx5_ib_vlan_info { |
| 573 | u16 vlan_id; |
| 574 | bool vlan; |
| 575 | }; |
| 576 | |
| 577 | static int get_lower_dev_vlan(struct net_device *lower_dev, void *data) |
| 578 | { |
| 579 | struct mlx5_ib_vlan_info *vlan_info = data; |
| 580 | |
| 581 | if (is_vlan_dev(lower_dev)) { |
| 582 | vlan_info->vlan = true; |
| 583 | vlan_info->vlan_id = vlan_dev_vlan_id(lower_dev); |
| 584 | } |
| 585 | /* We are interested only in first level vlan device, so |
| 586 | * always return 1 to stop iterating over next level devices. |
| 587 | */ |
| 588 | return 1; |
| 589 | } |
| 590 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 591 | static int set_roce_addr(struct mlx5_ib_dev *dev, u8 port_num, |
| 592 | unsigned int index, const union ib_gid *gid, |
| 593 | const struct ib_gid_attr *attr) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 594 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 595 | enum ib_gid_type gid_type = IB_GID_TYPE_IB; |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 596 | struct mlx5_ib_vlan_info vlan_info = { }; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 597 | u8 roce_version = 0; |
| 598 | u8 roce_l3_type = 0; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 599 | u8 mac[ETH_ALEN]; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 600 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 601 | if (gid) { |
| 602 | gid_type = attr->gid_type; |
| 603 | ether_addr_copy(mac, attr->ndev->dev_addr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 604 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 605 | if (is_vlan_dev(attr->ndev)) { |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 606 | vlan_info.vlan = true; |
| 607 | vlan_info.vlan_id = vlan_dev_vlan_id(attr->ndev); |
| 608 | } else { |
| 609 | /* If the netdev is upper device and if it's lower |
| 610 | * lower device is vlan device, consider vlan id of |
| 611 | * the lower vlan device for this gid entry. |
| 612 | */ |
| 613 | rcu_read_lock(); |
| 614 | netdev_walk_all_lower_dev_rcu(attr->ndev, |
| 615 | get_lower_dev_vlan, &vlan_info); |
| 616 | rcu_read_unlock(); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 617 | } |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 618 | } |
| 619 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 620 | switch (gid_type) { |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 621 | case IB_GID_TYPE_IB: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 622 | roce_version = MLX5_ROCE_VERSION_1; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 623 | break; |
| 624 | case IB_GID_TYPE_ROCE_UDP_ENCAP: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 625 | roce_version = MLX5_ROCE_VERSION_2; |
| 626 | if (ipv6_addr_v4mapped((void *)gid)) |
| 627 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV4; |
| 628 | else |
| 629 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV6; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 630 | break; |
| 631 | |
| 632 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 633 | mlx5_ib_warn(dev, "Unexpected GID type %u\n", gid_type); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 634 | } |
| 635 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 636 | return mlx5_core_roce_gid_set(dev->mdev, index, roce_version, |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 637 | roce_l3_type, gid->raw, mac, |
| 638 | vlan_info.vlan, vlan_info.vlan_id, |
| 639 | port_num); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 640 | } |
| 641 | |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 642 | static int mlx5_ib_add_gid(const struct ib_gid_attr *attr, |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 643 | __always_unused void **context) |
| 644 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 645 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 646 | attr->index, &attr->gid, attr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 647 | } |
| 648 | |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 649 | static int mlx5_ib_del_gid(const struct ib_gid_attr *attr, |
| 650 | __always_unused void **context) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 651 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 652 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
| 653 | attr->index, NULL, NULL); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 654 | } |
| 655 | |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 656 | __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, |
| 657 | const struct ib_gid_attr *attr) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 658 | { |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 659 | if (attr->gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 660 | return 0; |
| 661 | |
| 662 | return cpu_to_be16(MLX5_CAP_ROCE(dev->mdev, r_roce_min_src_udp_port)); |
| 663 | } |
| 664 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 665 | static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) |
| 666 | { |
Noa Osherovich | 7fae665 | 2016-09-12 19:16:23 +0300 | [diff] [blame] | 667 | if (MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_IB) |
| 668 | return !MLX5_CAP_GEN(dev->mdev, ib_virt); |
| 669 | return 0; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | enum { |
| 673 | MLX5_VPORT_ACCESS_METHOD_MAD, |
| 674 | MLX5_VPORT_ACCESS_METHOD_HCA, |
| 675 | MLX5_VPORT_ACCESS_METHOD_NIC, |
| 676 | }; |
| 677 | |
| 678 | static int mlx5_get_vport_access_method(struct ib_device *ibdev) |
| 679 | { |
| 680 | if (mlx5_use_mad_ifc(to_mdev(ibdev))) |
| 681 | return MLX5_VPORT_ACCESS_METHOD_MAD; |
| 682 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 683 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 684 | IB_LINK_LAYER_ETHERNET) |
| 685 | return MLX5_VPORT_ACCESS_METHOD_NIC; |
| 686 | |
| 687 | return MLX5_VPORT_ACCESS_METHOD_HCA; |
| 688 | } |
| 689 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 690 | static void get_atomic_caps(struct mlx5_ib_dev *dev, |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 691 | u8 atomic_size_qp, |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 692 | struct ib_device_attr *props) |
| 693 | { |
| 694 | u8 tmp; |
| 695 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 696 | u8 atomic_req_8B_endianness_mode = |
Or Gerlitz | bd10838 | 2017-05-28 15:24:17 +0300 | [diff] [blame] | 697 | MLX5_CAP_ATOMIC(dev->mdev, atomic_req_8B_endianness_mode); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 698 | |
| 699 | /* Check if HW supports 8 bytes standard atomic operations and capable |
| 700 | * of host endianness respond |
| 701 | */ |
| 702 | tmp = MLX5_ATOMIC_OPS_CMP_SWAP | MLX5_ATOMIC_OPS_FETCH_ADD; |
| 703 | if (((atomic_operations & tmp) == tmp) && |
| 704 | (atomic_size_qp & MLX5_ATOMIC_SIZE_QP_8BYTES) && |
| 705 | (atomic_req_8B_endianness_mode)) { |
| 706 | props->atomic_cap = IB_ATOMIC_HCA; |
| 707 | } else { |
| 708 | props->atomic_cap = IB_ATOMIC_NONE; |
| 709 | } |
| 710 | } |
| 711 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 712 | static void get_atomic_caps_qp(struct mlx5_ib_dev *dev, |
| 713 | struct ib_device_attr *props) |
| 714 | { |
| 715 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 716 | |
| 717 | get_atomic_caps(dev, atomic_size_qp, props); |
| 718 | } |
| 719 | |
| 720 | static void get_atomic_caps_dc(struct mlx5_ib_dev *dev, |
| 721 | struct ib_device_attr *props) |
| 722 | { |
| 723 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc); |
| 724 | |
| 725 | get_atomic_caps(dev, atomic_size_qp, props); |
| 726 | } |
| 727 | |
| 728 | bool mlx5_ib_dc_atomic_is_supported(struct mlx5_ib_dev *dev) |
| 729 | { |
| 730 | struct ib_device_attr props = {}; |
| 731 | |
| 732 | get_atomic_caps_dc(dev, &props); |
| 733 | return (props.atomic_cap == IB_ATOMIC_HCA) ? true : false; |
| 734 | } |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 735 | static int mlx5_query_system_image_guid(struct ib_device *ibdev, |
| 736 | __be64 *sys_image_guid) |
| 737 | { |
| 738 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 739 | struct mlx5_core_dev *mdev = dev->mdev; |
| 740 | u64 tmp; |
| 741 | int err; |
| 742 | |
| 743 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 744 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 745 | return mlx5_query_mad_ifc_system_image_guid(ibdev, |
| 746 | sys_image_guid); |
| 747 | |
| 748 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 749 | err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 750 | break; |
| 751 | |
| 752 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 753 | err = mlx5_query_nic_vport_system_image_guid(mdev, &tmp); |
| 754 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 755 | |
| 756 | default: |
| 757 | return -EINVAL; |
| 758 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 759 | |
| 760 | if (!err) |
| 761 | *sys_image_guid = cpu_to_be64(tmp); |
| 762 | |
| 763 | return err; |
| 764 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | static int mlx5_query_max_pkeys(struct ib_device *ibdev, |
| 768 | u16 *max_pkeys) |
| 769 | { |
| 770 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 771 | struct mlx5_core_dev *mdev = dev->mdev; |
| 772 | |
| 773 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 774 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 775 | return mlx5_query_mad_ifc_max_pkeys(ibdev, max_pkeys); |
| 776 | |
| 777 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 778 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 779 | *max_pkeys = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, |
| 780 | pkey_table_size)); |
| 781 | return 0; |
| 782 | |
| 783 | default: |
| 784 | return -EINVAL; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | static int mlx5_query_vendor_id(struct ib_device *ibdev, |
| 789 | u32 *vendor_id) |
| 790 | { |
| 791 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 792 | |
| 793 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 794 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 795 | return mlx5_query_mad_ifc_vendor_id(ibdev, vendor_id); |
| 796 | |
| 797 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 798 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 799 | return mlx5_core_query_vendor_id(dev->mdev, vendor_id); |
| 800 | |
| 801 | default: |
| 802 | return -EINVAL; |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | static int mlx5_query_node_guid(struct mlx5_ib_dev *dev, |
| 807 | __be64 *node_guid) |
| 808 | { |
| 809 | u64 tmp; |
| 810 | int err; |
| 811 | |
| 812 | switch (mlx5_get_vport_access_method(&dev->ib_dev)) { |
| 813 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 814 | return mlx5_query_mad_ifc_node_guid(dev, node_guid); |
| 815 | |
| 816 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 817 | err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 818 | break; |
| 819 | |
| 820 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 821 | err = mlx5_query_nic_vport_node_guid(dev->mdev, &tmp); |
| 822 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 823 | |
| 824 | default: |
| 825 | return -EINVAL; |
| 826 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 827 | |
| 828 | if (!err) |
| 829 | *node_guid = cpu_to_be64(tmp); |
| 830 | |
| 831 | return err; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | struct mlx5_reg_node_desc { |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 835 | u8 desc[IB_DEVICE_NODE_DESC_MAX]; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 836 | }; |
| 837 | |
| 838 | static int mlx5_query_node_desc(struct mlx5_ib_dev *dev, char *node_desc) |
| 839 | { |
| 840 | struct mlx5_reg_node_desc in; |
| 841 | |
| 842 | if (mlx5_use_mad_ifc(dev)) |
| 843 | return mlx5_query_mad_ifc_node_desc(dev, node_desc); |
| 844 | |
| 845 | memset(&in, 0, sizeof(in)); |
| 846 | |
| 847 | return mlx5_core_access_reg(dev->mdev, &in, sizeof(in), node_desc, |
| 848 | sizeof(struct mlx5_reg_node_desc), |
| 849 | MLX5_REG_NODE_DESC, 0, 0); |
| 850 | } |
| 851 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 852 | static int mlx5_ib_query_device(struct ib_device *ibdev, |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 853 | struct ib_device_attr *props, |
| 854 | struct ib_udata *uhw) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 855 | { |
| 856 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 857 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 858 | int err = -ENOMEM; |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 859 | int max_sq_desc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 860 | int max_rq_sg; |
| 861 | int max_sq_sg; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 862 | u64 min_page_size = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 863 | bool raw_support = !mlx5_core_mp_enabled(mdev); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 864 | struct mlx5_ib_query_device_resp resp = {}; |
| 865 | size_t resp_len; |
| 866 | u64 max_tso; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 867 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 868 | resp_len = sizeof(resp.comp_mask) + sizeof(resp.response_length); |
| 869 | if (uhw->outlen && uhw->outlen < resp_len) |
| 870 | return -EINVAL; |
| 871 | else |
| 872 | resp.response_length = resp_len; |
| 873 | |
| 874 | if (uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen)) |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 875 | return -EINVAL; |
| 876 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 877 | memset(props, 0, sizeof(*props)); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 878 | err = mlx5_query_system_image_guid(ibdev, |
| 879 | &props->sys_image_guid); |
| 880 | if (err) |
| 881 | return err; |
| 882 | |
| 883 | err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys); |
| 884 | if (err) |
| 885 | return err; |
| 886 | |
| 887 | err = mlx5_query_vendor_id(ibdev, &props->vendor_id); |
| 888 | if (err) |
| 889 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 890 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 891 | props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) | |
| 892 | (fw_rev_min(dev->mdev) << 16) | |
| 893 | fw_rev_sub(dev->mdev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 894 | props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | |
| 895 | IB_DEVICE_PORT_ACTIVE_EVENT | |
| 896 | IB_DEVICE_SYS_IMAGE_GUID | |
Eli Cohen | 1a4c3a3 | 2014-02-06 17:41:25 +0200 | [diff] [blame] | 897 | IB_DEVICE_RC_RNR_NAK_GEN; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 898 | |
| 899 | if (MLX5_CAP_GEN(mdev, pkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 900 | props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 901 | if (MLX5_CAP_GEN(mdev, qkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 902 | props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 903 | if (MLX5_CAP_GEN(mdev, apm)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 904 | props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 905 | if (MLX5_CAP_GEN(mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 906 | props->device_cap_flags |= IB_DEVICE_XRC; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 907 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
| 908 | props->device_cap_flags |= IB_DEVICE_MEM_WINDOW | |
| 909 | IB_DEVICE_MEM_WINDOW_TYPE_2B; |
| 910 | props->max_mw = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 911 | /* We support 'Gappy' memory registration too */ |
| 912 | props->device_cap_flags |= IB_DEVICE_SG_GAPS_REG; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 913 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 914 | props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 915 | if (MLX5_CAP_GEN(mdev, sho)) { |
Sagi Grimberg | 2dea909 | 2014-02-23 14:19:13 +0200 | [diff] [blame] | 916 | props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER; |
| 917 | /* At this stage no support for signature handover */ |
| 918 | props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 | |
| 919 | IB_PROT_T10DIF_TYPE_2 | |
| 920 | IB_PROT_T10DIF_TYPE_3; |
| 921 | props->sig_guard_cap = IB_GUARD_T10DIF_CRC | |
| 922 | IB_GUARD_T10DIF_CSUM; |
| 923 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 924 | if (MLX5_CAP_GEN(mdev, block_lb_mc)) |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 925 | props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 926 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 927 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 928 | if (MLX5_CAP_ETH(mdev, csum_cap)) { |
| 929 | /* Legacy bit to support old userspace libraries */ |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 930 | props->device_cap_flags |= IB_DEVICE_RAW_IP_CSUM; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 931 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_IP_CSUM; |
| 932 | } |
| 933 | |
| 934 | if (MLX5_CAP_ETH(dev->mdev, vlan_cap)) |
| 935 | props->raw_packet_caps |= |
| 936 | IB_RAW_PACKET_CAP_CVLAN_STRIPPING; |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 937 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 938 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) { |
| 939 | max_tso = MLX5_CAP_ETH(mdev, max_lso_cap); |
| 940 | if (max_tso) { |
| 941 | resp.tso_caps.max_tso = 1 << max_tso; |
| 942 | resp.tso_caps.supported_qpts |= |
| 943 | 1 << IB_QPT_RAW_PACKET; |
| 944 | resp.response_length += sizeof(resp.tso_caps); |
| 945 | } |
| 946 | } |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 947 | |
| 948 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) { |
| 949 | resp.rss_caps.rx_hash_function = |
| 950 | MLX5_RX_HASH_FUNC_TOEPLITZ; |
| 951 | resp.rss_caps.rx_hash_fields_mask = |
| 952 | MLX5_RX_HASH_SRC_IPV4 | |
| 953 | MLX5_RX_HASH_DST_IPV4 | |
| 954 | MLX5_RX_HASH_SRC_IPV6 | |
| 955 | MLX5_RX_HASH_DST_IPV6 | |
| 956 | MLX5_RX_HASH_SRC_PORT_TCP | |
| 957 | MLX5_RX_HASH_DST_PORT_TCP | |
| 958 | MLX5_RX_HASH_SRC_PORT_UDP | |
Maor Gottlieb | 4e2b53a | 2017-12-24 14:51:25 +0200 | [diff] [blame] | 959 | MLX5_RX_HASH_DST_PORT_UDP | |
| 960 | MLX5_RX_HASH_INNER; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 961 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
| 962 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 963 | resp.rss_caps.rx_hash_fields_mask |= |
| 964 | MLX5_RX_HASH_IPSEC_SPI; |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 965 | resp.response_length += sizeof(resp.rss_caps); |
| 966 | } |
| 967 | } else { |
| 968 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) |
| 969 | resp.response_length += sizeof(resp.tso_caps); |
| 970 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) |
| 971 | resp.response_length += sizeof(resp.rss_caps); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 972 | } |
| 973 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 974 | if (MLX5_CAP_GEN(mdev, ipoib_basic_offloads)) { |
| 975 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 976 | props->device_cap_flags |= IB_DEVICE_UD_TSO; |
| 977 | } |
| 978 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 979 | if (MLX5_CAP_GEN(dev->mdev, rq_delay_drop) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 980 | MLX5_CAP_GEN(dev->mdev, general_notification_event) && |
| 981 | raw_support) |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 982 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_DELAY_DROP; |
| 983 | |
Yishai Hadas | 1d54f89 | 2017-06-08 16:15:11 +0300 | [diff] [blame] | 984 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
| 985 | MLX5_CAP_IPOIB_ENHANCED(mdev, csum_cap)) |
| 986 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 987 | |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 988 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 989 | MLX5_CAP_ETH(dev->mdev, scatter_fcs) && |
| 990 | raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 991 | /* Legacy bit to support old userspace libraries */ |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 992 | props->device_cap_flags |= IB_DEVICE_RAW_SCATTER_FCS; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 993 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_SCATTER_FCS; |
| 994 | } |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 995 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 996 | if (MLX5_CAP_DEV_MEM(mdev, memic)) { |
| 997 | props->max_dm_size = |
| 998 | MLX5_CAP_DEV_MEM(mdev, max_memic_size); |
| 999 | } |
| 1000 | |
Maor Gottlieb | da6d6ba3 | 2016-06-04 15:15:28 +0300 | [diff] [blame] | 1001 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_BYPASS)) |
| 1002 | props->device_cap_flags |= IB_DEVICE_MANAGED_FLOW_STEERING; |
| 1003 | |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 1004 | if (MLX5_CAP_GEN(mdev, end_pad)) |
| 1005 | props->device_cap_flags |= IB_DEVICE_PCI_WRITE_END_PADDING; |
| 1006 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1007 | props->vendor_part_id = mdev->pdev->device; |
| 1008 | props->hw_ver = mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1009 | |
| 1010 | props->max_mr_size = ~0ull; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 1011 | props->page_size_cap = ~(min_page_size - 1); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1012 | props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp); |
| 1013 | props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
| 1014 | max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) / |
| 1015 | sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 1016 | max_sq_desc = min_t(int, MLX5_CAP_GEN(mdev, max_wqe_sz_sq), 512); |
| 1017 | max_sq_sg = (max_sq_desc - sizeof(struct mlx5_wqe_ctrl_seg) - |
| 1018 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 1019 | sizeof(struct mlx5_wqe_data_seg); |
Steve Wise | 33023fb | 2018-06-18 08:05:26 -0700 | [diff] [blame] | 1020 | props->max_send_sge = max_sq_sg; |
| 1021 | props->max_recv_sge = max_rq_sg; |
Sagi Grimberg | 986ef95 | 2016-03-31 19:03:25 +0300 | [diff] [blame] | 1022 | props->max_sge_rd = MLX5_MAX_SGE_RD; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1023 | props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq); |
Leon Romanovsky | 9f17768 | 2016-01-14 08:11:40 +0200 | [diff] [blame] | 1024 | 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] | 1025 | props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
| 1026 | props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd); |
| 1027 | props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp); |
| 1028 | props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp); |
| 1029 | props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq); |
| 1030 | props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1; |
| 1031 | 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] | 1032 | 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] | 1033 | props->max_srq_sge = max_rq_sg - 1; |
Sagi Grimberg | 911f433 | 2016-03-03 13:37:51 +0200 | [diff] [blame] | 1034 | props->max_fast_reg_page_list_len = |
| 1035 | 1 << MLX5_CAP_GEN(mdev, log_max_klm_list_size); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 1036 | get_atomic_caps_qp(dev, props); |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 1037 | props->masked_atomic_cap = IB_ATOMIC_NONE; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1038 | props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg); |
| 1039 | props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1040 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 1041 | props->max_mcast_grp; |
| 1042 | props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */ |
Maor Gottlieb | 86695a6 | 2016-10-27 16:36:38 +0300 | [diff] [blame] | 1043 | props->max_ah = INT_MAX; |
Matan Barak | 7c60bcb | 2015-12-15 20:30:11 +0200 | [diff] [blame] | 1044 | props->hca_core_clock = MLX5_CAP_GEN(mdev, device_frequency_khz); |
| 1045 | props->timestamp_mask = 0x7FFFFFFFFFFFFFFFULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1046 | |
Leon Romanovsky | e502b8b | 2019-01-08 16:07:24 +0200 | [diff] [blame] | 1047 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
| 1048 | if (MLX5_CAP_GEN(mdev, pg)) |
| 1049 | props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
| 1050 | props->odp_caps = dev->odp_caps; |
| 1051 | } |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 1052 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 1053 | if (MLX5_CAP_GEN(mdev, cd)) |
| 1054 | props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL; |
| 1055 | |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 1056 | if (!mlx5_core_is_pf(mdev)) |
| 1057 | props->device_cap_flags |= IB_DEVICE_VIRTUAL_FUNCTION; |
| 1058 | |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 1059 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1060 | IB_LINK_LAYER_ETHERNET && raw_support) { |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 1061 | props->rss_caps.max_rwq_indirection_tables = |
| 1062 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt); |
| 1063 | props->rss_caps.max_rwq_indirection_table_size = |
| 1064 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt_size); |
| 1065 | props->rss_caps.supported_qpts = 1 << IB_QPT_RAW_PACKET; |
| 1066 | props->max_wq_type_rq = |
| 1067 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rq); |
| 1068 | } |
| 1069 | |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1070 | if (MLX5_CAP_GEN(mdev, tag_matching)) { |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1071 | props->tm_caps.max_rndv_hdr_size = MLX5_TM_MAX_RNDV_MSG_SIZE; |
| 1072 | props->tm_caps.max_num_tags = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1073 | (1 << MLX5_CAP_GEN(mdev, log_tag_matching_list_sz)) - 1; |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1074 | props->tm_caps.flags = IB_TM_CAP_RC; |
| 1075 | props->tm_caps.max_ops = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1076 | 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1077 | props->tm_caps.max_sge = MLX5_TM_MAX_SGE; |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1078 | } |
| 1079 | |
Yonatan Cohen | 87ab3f5 | 2017-11-13 10:51:18 +0200 | [diff] [blame] | 1080 | if (MLX5_CAP_GEN(dev->mdev, cq_moderation)) { |
| 1081 | props->cq_caps.max_cq_moderation_count = |
| 1082 | MLX5_MAX_CQ_COUNT; |
| 1083 | props->cq_caps.max_cq_moderation_period = |
| 1084 | MLX5_MAX_CQ_PERIOD; |
| 1085 | } |
| 1086 | |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1087 | if (field_avail(typeof(resp), cqe_comp_caps, uhw->outlen)) { |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1088 | resp.response_length += sizeof(resp.cqe_comp_caps); |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 1089 | |
| 1090 | if (MLX5_CAP_GEN(dev->mdev, cqe_compression)) { |
| 1091 | resp.cqe_comp_caps.max_num = |
| 1092 | MLX5_CAP_GEN(dev->mdev, |
| 1093 | cqe_compression_max_num); |
| 1094 | |
| 1095 | resp.cqe_comp_caps.supported_format = |
| 1096 | MLX5_IB_CQE_RES_FORMAT_HASH | |
| 1097 | MLX5_IB_CQE_RES_FORMAT_CSUM; |
Yonatan Cohen | 6f1006a | 2018-05-27 13:42:34 +0300 | [diff] [blame] | 1098 | |
| 1099 | if (MLX5_CAP_GEN(dev->mdev, mini_cqe_resp_stride_index)) |
| 1100 | resp.cqe_comp_caps.supported_format |= |
| 1101 | MLX5_IB_CQE_RES_FORMAT_CSUM_STRIDX; |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 1102 | } |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1103 | } |
| 1104 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1105 | if (field_avail(typeof(resp), packet_pacing_caps, uhw->outlen) && |
| 1106 | raw_support) { |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 1107 | if (MLX5_CAP_QOS(mdev, packet_pacing) && |
| 1108 | MLX5_CAP_GEN(mdev, qos)) { |
| 1109 | resp.packet_pacing_caps.qp_rate_limit_max = |
| 1110 | MLX5_CAP_QOS(mdev, packet_pacing_max_rate); |
| 1111 | resp.packet_pacing_caps.qp_rate_limit_min = |
| 1112 | MLX5_CAP_QOS(mdev, packet_pacing_min_rate); |
| 1113 | resp.packet_pacing_caps.supported_qpts |= |
| 1114 | 1 << IB_QPT_RAW_PACKET; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 1115 | if (MLX5_CAP_QOS(mdev, packet_pacing_burst_bound) && |
| 1116 | MLX5_CAP_QOS(mdev, packet_pacing_typical_size)) |
| 1117 | resp.packet_pacing_caps.cap_flags |= |
| 1118 | MLX5_IB_PP_SUPPORT_BURST; |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 1119 | } |
| 1120 | resp.response_length += sizeof(resp.packet_pacing_caps); |
| 1121 | } |
| 1122 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1123 | if (field_avail(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes, |
| 1124 | uhw->outlen)) { |
Bodong Wang | 795b609 | 2017-08-17 15:52:34 +0300 | [diff] [blame] | 1125 | if (MLX5_CAP_ETH(mdev, multi_pkt_send_wqe)) |
| 1126 | resp.mlx5_ib_support_multi_pkt_send_wqes = |
| 1127 | MLX5_IB_ALLOW_MPW; |
Bodong Wang | 050da90 | 2017-08-17 15:52:35 +0300 | [diff] [blame] | 1128 | |
| 1129 | if (MLX5_CAP_ETH(mdev, enhanced_multi_pkt_send_wqe)) |
| 1130 | resp.mlx5_ib_support_multi_pkt_send_wqes |= |
| 1131 | MLX5_IB_SUPPORT_EMPW; |
| 1132 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1133 | resp.response_length += |
| 1134 | sizeof(resp.mlx5_ib_support_multi_pkt_send_wqes); |
| 1135 | } |
| 1136 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1137 | if (field_avail(typeof(resp), flags, uhw->outlen)) { |
| 1138 | resp.response_length += sizeof(resp.flags); |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1139 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1140 | if (MLX5_CAP_GEN(mdev, cqe_compression_128)) |
| 1141 | resp.flags |= |
| 1142 | MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_COMP; |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1143 | |
| 1144 | if (MLX5_CAP_GEN(mdev, cqe_128_always)) |
| 1145 | resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_PAD; |
Danit Goldberg | 7e11b91 | 2018-11-30 13:22:06 +0200 | [diff] [blame] | 1146 | if (MLX5_CAP_GEN(mdev, qp_packet_based)) |
| 1147 | resp.flags |= |
| 1148 | MLX5_IB_QUERY_DEV_RESP_PACKET_BASED_CREDIT_MODE; |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1149 | } |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1150 | |
Noa Osherovich | 96dc3fc | 2017-08-17 15:52:28 +0300 | [diff] [blame] | 1151 | if (field_avail(typeof(resp), sw_parsing_caps, |
| 1152 | uhw->outlen)) { |
| 1153 | resp.response_length += sizeof(resp.sw_parsing_caps); |
| 1154 | if (MLX5_CAP_ETH(mdev, swp)) { |
| 1155 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1156 | MLX5_IB_SW_PARSING; |
| 1157 | |
| 1158 | if (MLX5_CAP_ETH(mdev, swp_csum)) |
| 1159 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1160 | MLX5_IB_SW_PARSING_CSUM; |
| 1161 | |
| 1162 | if (MLX5_CAP_ETH(mdev, swp_lso)) |
| 1163 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1164 | MLX5_IB_SW_PARSING_LSO; |
| 1165 | |
| 1166 | if (resp.sw_parsing_caps.sw_parsing_offloads) |
| 1167 | resp.sw_parsing_caps.supported_qpts = |
| 1168 | BIT(IB_QPT_RAW_PACKET); |
| 1169 | } |
| 1170 | } |
| 1171 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1172 | if (field_avail(typeof(resp), striding_rq_caps, uhw->outlen) && |
| 1173 | raw_support) { |
Noa Osherovich | b4f3459 | 2017-10-17 18:01:12 +0300 | [diff] [blame] | 1174 | resp.response_length += sizeof(resp.striding_rq_caps); |
| 1175 | if (MLX5_CAP_GEN(mdev, striding_rq)) { |
| 1176 | resp.striding_rq_caps.min_single_stride_log_num_of_bytes = |
| 1177 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1178 | resp.striding_rq_caps.max_single_stride_log_num_of_bytes = |
| 1179 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1180 | resp.striding_rq_caps.min_single_wqe_log_num_of_strides = |
| 1181 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1182 | resp.striding_rq_caps.max_single_wqe_log_num_of_strides = |
| 1183 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1184 | resp.striding_rq_caps.supported_qpts = |
| 1185 | BIT(IB_QPT_RAW_PACKET); |
| 1186 | } |
| 1187 | } |
| 1188 | |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1189 | if (field_avail(typeof(resp), tunnel_offloads_caps, |
| 1190 | uhw->outlen)) { |
| 1191 | resp.response_length += sizeof(resp.tunnel_offloads_caps); |
| 1192 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan)) |
| 1193 | resp.tunnel_offloads_caps |= |
| 1194 | MLX5_IB_TUNNELED_OFFLOADS_VXLAN; |
| 1195 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_geneve_rx)) |
| 1196 | resp.tunnel_offloads_caps |= |
| 1197 | MLX5_IB_TUNNELED_OFFLOADS_GENEVE; |
| 1198 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_gre)) |
| 1199 | resp.tunnel_offloads_caps |= |
| 1200 | MLX5_IB_TUNNELED_OFFLOADS_GRE; |
Ariel Levkovich | e818e25 | 2018-05-13 14:33:35 +0300 | [diff] [blame] | 1201 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1202 | MLX5_FLEX_PROTO_CW_MPLS_GRE) |
| 1203 | resp.tunnel_offloads_caps |= |
| 1204 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_GRE; |
| 1205 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1206 | MLX5_FLEX_PROTO_CW_MPLS_UDP) |
| 1207 | resp.tunnel_offloads_caps |= |
| 1208 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_UDP; |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1209 | } |
| 1210 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1211 | if (uhw->outlen) { |
| 1212 | err = ib_copy_to_udata(uhw, &resp, resp.response_length); |
| 1213 | |
| 1214 | if (err) |
| 1215 | return err; |
| 1216 | } |
| 1217 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1218 | return 0; |
| 1219 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1220 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1221 | enum mlx5_ib_width { |
| 1222 | MLX5_IB_WIDTH_1X = 1 << 0, |
| 1223 | MLX5_IB_WIDTH_2X = 1 << 1, |
| 1224 | MLX5_IB_WIDTH_4X = 1 << 2, |
| 1225 | MLX5_IB_WIDTH_8X = 1 << 3, |
| 1226 | MLX5_IB_WIDTH_12X = 1 << 4 |
| 1227 | }; |
| 1228 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1229 | static void translate_active_width(struct ib_device *ibdev, u8 active_width, |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1230 | u8 *ib_width) |
| 1231 | { |
| 1232 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1233 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1234 | if (active_width & MLX5_IB_WIDTH_1X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1235 | *ib_width = IB_WIDTH_1X; |
Michael Guralnik | d764970 | 2018-12-09 11:49:54 +0200 | [diff] [blame] | 1236 | else if (active_width & MLX5_IB_WIDTH_2X) |
| 1237 | *ib_width = IB_WIDTH_2X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1238 | else if (active_width & MLX5_IB_WIDTH_4X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1239 | *ib_width = IB_WIDTH_4X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1240 | else if (active_width & MLX5_IB_WIDTH_8X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1241 | *ib_width = IB_WIDTH_8X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1242 | else if (active_width & MLX5_IB_WIDTH_12X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1243 | *ib_width = IB_WIDTH_12X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1244 | else { |
| 1245 | 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] | 1246 | (int)active_width); |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1247 | *ib_width = IB_WIDTH_4X; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1248 | } |
| 1249 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1250 | return; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | static int mlx5_mtu_to_ib_mtu(int mtu) |
| 1254 | { |
| 1255 | switch (mtu) { |
| 1256 | case 256: return 1; |
| 1257 | case 512: return 2; |
| 1258 | case 1024: return 3; |
| 1259 | case 2048: return 4; |
| 1260 | case 4096: return 5; |
| 1261 | default: |
| 1262 | pr_warn("invalid mtu\n"); |
| 1263 | return -1; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | enum ib_max_vl_num { |
| 1268 | __IB_MAX_VL_0 = 1, |
| 1269 | __IB_MAX_VL_0_1 = 2, |
| 1270 | __IB_MAX_VL_0_3 = 3, |
| 1271 | __IB_MAX_VL_0_7 = 4, |
| 1272 | __IB_MAX_VL_0_14 = 5, |
| 1273 | }; |
| 1274 | |
| 1275 | enum mlx5_vl_hw_cap { |
| 1276 | MLX5_VL_HW_0 = 1, |
| 1277 | MLX5_VL_HW_0_1 = 2, |
| 1278 | MLX5_VL_HW_0_2 = 3, |
| 1279 | MLX5_VL_HW_0_3 = 4, |
| 1280 | MLX5_VL_HW_0_4 = 5, |
| 1281 | MLX5_VL_HW_0_5 = 6, |
| 1282 | MLX5_VL_HW_0_6 = 7, |
| 1283 | MLX5_VL_HW_0_7 = 8, |
| 1284 | MLX5_VL_HW_0_14 = 15 |
| 1285 | }; |
| 1286 | |
| 1287 | static int translate_max_vl_num(struct ib_device *ibdev, u8 vl_hw_cap, |
| 1288 | u8 *max_vl_num) |
| 1289 | { |
| 1290 | switch (vl_hw_cap) { |
| 1291 | case MLX5_VL_HW_0: |
| 1292 | *max_vl_num = __IB_MAX_VL_0; |
| 1293 | break; |
| 1294 | case MLX5_VL_HW_0_1: |
| 1295 | *max_vl_num = __IB_MAX_VL_0_1; |
| 1296 | break; |
| 1297 | case MLX5_VL_HW_0_3: |
| 1298 | *max_vl_num = __IB_MAX_VL_0_3; |
| 1299 | break; |
| 1300 | case MLX5_VL_HW_0_7: |
| 1301 | *max_vl_num = __IB_MAX_VL_0_7; |
| 1302 | break; |
| 1303 | case MLX5_VL_HW_0_14: |
| 1304 | *max_vl_num = __IB_MAX_VL_0_14; |
| 1305 | break; |
| 1306 | |
| 1307 | default: |
| 1308 | return -EINVAL; |
| 1309 | } |
| 1310 | |
| 1311 | return 0; |
| 1312 | } |
| 1313 | |
| 1314 | static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port, |
| 1315 | struct ib_port_attr *props) |
| 1316 | { |
| 1317 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1318 | struct mlx5_core_dev *mdev = dev->mdev; |
| 1319 | struct mlx5_hca_vport_context *rep; |
Saeed Mahameed | 046339e | 2016-04-22 00:33:03 +0300 | [diff] [blame] | 1320 | u16 max_mtu; |
| 1321 | u16 oper_mtu; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1322 | int err; |
| 1323 | u8 ib_link_width_oper; |
| 1324 | u8 vl_hw_cap; |
| 1325 | |
| 1326 | rep = kzalloc(sizeof(*rep), GFP_KERNEL); |
| 1327 | if (!rep) { |
| 1328 | err = -ENOMEM; |
| 1329 | goto out; |
| 1330 | } |
| 1331 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1332 | /* props being zeroed by the caller, avoid zeroing it here */ |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1333 | |
| 1334 | err = mlx5_query_hca_vport_context(mdev, 0, port, 0, rep); |
| 1335 | if (err) |
| 1336 | goto out; |
| 1337 | |
| 1338 | props->lid = rep->lid; |
| 1339 | props->lmc = rep->lmc; |
| 1340 | props->sm_lid = rep->sm_lid; |
| 1341 | props->sm_sl = rep->sm_sl; |
| 1342 | props->state = rep->vport_state; |
| 1343 | props->phys_state = rep->port_physical_state; |
| 1344 | props->port_cap_flags = rep->cap_mask1; |
| 1345 | props->gid_tbl_len = mlx5_get_gid_table_len(MLX5_CAP_GEN(mdev, gid_table_size)); |
| 1346 | props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg); |
| 1347 | props->pkey_tbl_len = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, pkey_table_size)); |
| 1348 | props->bad_pkey_cntr = rep->pkey_violation_counter; |
| 1349 | props->qkey_viol_cntr = rep->qkey_violation_counter; |
| 1350 | props->subnet_timeout = rep->subnet_timeout; |
| 1351 | props->init_type_reply = rep->init_type_reply; |
| 1352 | |
Michael Guralnik | 4106a75 | 2018-12-09 11:49:51 +0200 | [diff] [blame] | 1353 | if (props->port_cap_flags & IB_PORT_CAP_MASK2_SUP) |
| 1354 | props->port_cap_flags2 = rep->cap_mask2; |
| 1355 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1356 | err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); |
| 1357 | if (err) |
| 1358 | goto out; |
| 1359 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1360 | translate_active_width(ibdev, ib_link_width_oper, &props->active_width); |
| 1361 | |
Noa Osherovich | d5beb7f | 2016-06-02 10:47:53 +0300 | [diff] [blame] | 1362 | err = mlx5_query_port_ib_proto_oper(mdev, &props->active_speed, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1363 | if (err) |
| 1364 | goto out; |
| 1365 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1366 | mlx5_query_port_max_mtu(mdev, &max_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1367 | |
| 1368 | props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu); |
| 1369 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1370 | mlx5_query_port_oper_mtu(mdev, &oper_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1371 | |
| 1372 | props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu); |
| 1373 | |
| 1374 | err = mlx5_query_port_vl_hw_cap(mdev, &vl_hw_cap, port); |
| 1375 | if (err) |
| 1376 | goto out; |
| 1377 | |
| 1378 | err = translate_max_vl_num(ibdev, vl_hw_cap, |
| 1379 | &props->max_vl_num); |
| 1380 | out: |
| 1381 | kfree(rep); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1382 | return err; |
| 1383 | } |
| 1384 | |
| 1385 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 1386 | struct ib_port_attr *props) |
| 1387 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1388 | unsigned int count; |
| 1389 | int ret; |
| 1390 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1391 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1392 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1393 | ret = mlx5_query_mad_ifc_port(ibdev, port, props); |
| 1394 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1395 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1396 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1397 | ret = mlx5_query_hca_port(ibdev, port, props); |
| 1398 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1399 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1400 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1401 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1402 | break; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1403 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1404 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1405 | ret = -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1406 | } |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1407 | |
| 1408 | if (!ret && props) { |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1409 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1410 | struct mlx5_core_dev *mdev; |
| 1411 | bool put_mdev = true; |
| 1412 | |
| 1413 | mdev = mlx5_ib_get_native_port_mdev(dev, port, NULL); |
| 1414 | if (!mdev) { |
| 1415 | /* If the port isn't affiliated yet query the master. |
| 1416 | * The master and slave will have the same values. |
| 1417 | */ |
| 1418 | mdev = dev->mdev; |
| 1419 | port = 1; |
| 1420 | put_mdev = false; |
| 1421 | } |
| 1422 | count = mlx5_core_reserved_gids_count(mdev); |
| 1423 | if (put_mdev) |
| 1424 | mlx5_ib_put_native_port_mdev(dev, port); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1425 | props->gid_tbl_len -= count; |
| 1426 | } |
| 1427 | return ret; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1428 | } |
| 1429 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 1430 | static int mlx5_ib_rep_query_port(struct ib_device *ibdev, u8 port, |
| 1431 | struct ib_port_attr *props) |
| 1432 | { |
| 1433 | int ret; |
| 1434 | |
| 1435 | /* Only link layer == ethernet is valid for representors */ |
| 1436 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1437 | if (ret || !props) |
| 1438 | return ret; |
| 1439 | |
| 1440 | /* We don't support GIDS */ |
| 1441 | props->gid_tbl_len = 0; |
| 1442 | |
| 1443 | return ret; |
| 1444 | } |
| 1445 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1446 | static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 1447 | union ib_gid *gid) |
| 1448 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1449 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1450 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1451 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1452 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1453 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1454 | return mlx5_query_mad_ifc_gids(ibdev, port, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1455 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1456 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1457 | return mlx5_query_hca_vport_gid(mdev, 0, port, 0, index, gid); |
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 | default: |
| 1460 | return -EINVAL; |
| 1461 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1462 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1463 | } |
| 1464 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1465 | static int mlx5_query_hca_nic_pkey(struct ib_device *ibdev, u8 port, |
| 1466 | u16 index, u16 *pkey) |
| 1467 | { |
| 1468 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1469 | struct mlx5_core_dev *mdev; |
| 1470 | bool put_mdev = true; |
| 1471 | u8 mdev_port_num; |
| 1472 | int err; |
| 1473 | |
| 1474 | mdev = mlx5_ib_get_native_port_mdev(dev, port, &mdev_port_num); |
| 1475 | if (!mdev) { |
| 1476 | /* The port isn't affiliated yet, get the PKey from the master |
| 1477 | * port. For RoCE the PKey tables will be the same. |
| 1478 | */ |
| 1479 | put_mdev = false; |
| 1480 | mdev = dev->mdev; |
| 1481 | mdev_port_num = 1; |
| 1482 | } |
| 1483 | |
| 1484 | err = mlx5_query_hca_vport_pkey(mdev, 0, mdev_port_num, 0, |
| 1485 | index, pkey); |
| 1486 | if (put_mdev) |
| 1487 | mlx5_ib_put_native_port_mdev(dev, port); |
| 1488 | |
| 1489 | return err; |
| 1490 | } |
| 1491 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1492 | static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 1493 | u16 *pkey) |
| 1494 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1495 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1496 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1497 | return mlx5_query_mad_ifc_pkey(ibdev, port, index, pkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1498 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1499 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1500 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1501 | return mlx5_query_hca_nic_pkey(ibdev, port, index, pkey); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1502 | default: |
| 1503 | return -EINVAL; |
| 1504 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1505 | } |
| 1506 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1507 | static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask, |
| 1508 | struct ib_device_modify *props) |
| 1509 | { |
| 1510 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1511 | struct mlx5_reg_node_desc in; |
| 1512 | struct mlx5_reg_node_desc out; |
| 1513 | int err; |
| 1514 | |
| 1515 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 1516 | return -EOPNOTSUPP; |
| 1517 | |
| 1518 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 1519 | return 0; |
| 1520 | |
| 1521 | /* |
| 1522 | * If possible, pass node desc to FW, so it can generate |
| 1523 | * a 144 trap. If cmd fails, just ignore. |
| 1524 | */ |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1525 | memcpy(&in, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1526 | err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1527 | sizeof(out), MLX5_REG_NODE_DESC, 0, 1); |
| 1528 | if (err) |
| 1529 | return err; |
| 1530 | |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1531 | memcpy(ibdev->node_desc, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1532 | |
| 1533 | return err; |
| 1534 | } |
| 1535 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1536 | static int set_port_caps_atomic(struct mlx5_ib_dev *dev, u8 port_num, u32 mask, |
| 1537 | u32 value) |
| 1538 | { |
| 1539 | struct mlx5_hca_vport_context ctx = {}; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1540 | struct mlx5_core_dev *mdev; |
| 1541 | u8 mdev_port_num; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1542 | int err; |
| 1543 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1544 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 1545 | if (!mdev) |
| 1546 | return -ENODEV; |
| 1547 | |
| 1548 | 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] | 1549 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1550 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1551 | |
| 1552 | if (~ctx.cap_mask1_perm & mask) { |
| 1553 | mlx5_ib_warn(dev, "trying to change bitmask 0x%X but change supported 0x%X\n", |
| 1554 | mask, ctx.cap_mask1_perm); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1555 | err = -EINVAL; |
| 1556 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | ctx.cap_mask1 = value; |
| 1560 | ctx.cap_mask1_perm = mask; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1561 | err = mlx5_core_modify_hca_vport_context(mdev, 0, mdev_port_num, |
| 1562 | 0, &ctx); |
| 1563 | |
| 1564 | out: |
| 1565 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1566 | |
| 1567 | return err; |
| 1568 | } |
| 1569 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1570 | static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 1571 | struct ib_port_modify *props) |
| 1572 | { |
| 1573 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1574 | struct ib_port_attr attr; |
| 1575 | u32 tmp; |
| 1576 | int err; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1577 | u32 change_mask; |
| 1578 | u32 value; |
| 1579 | bool is_ib = (mlx5_ib_port_link_layer(ibdev, port) == |
| 1580 | IB_LINK_LAYER_INFINIBAND); |
| 1581 | |
Majd Dibbiny | ec25587 | 2017-08-23 08:35:42 +0300 | [diff] [blame] | 1582 | /* CM layer calls ib_modify_port() regardless of the link layer. For |
| 1583 | * Ethernet ports, qkey violation and Port capabilities are meaningless. |
| 1584 | */ |
| 1585 | if (!is_ib) |
| 1586 | return 0; |
| 1587 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1588 | if (MLX5_CAP_GEN(dev->mdev, ib_virt) && is_ib) { |
| 1589 | change_mask = props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1590 | value = ~props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1591 | return set_port_caps_atomic(dev, port, change_mask, value); |
| 1592 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1593 | |
| 1594 | mutex_lock(&dev->cap_mask_mutex); |
| 1595 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1596 | err = ib_query_port(ibdev, port, &attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1597 | if (err) |
| 1598 | goto out; |
| 1599 | |
| 1600 | tmp = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 1601 | ~props->clr_port_cap_mask; |
| 1602 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1603 | err = mlx5_set_port_caps(dev->mdev, port, tmp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1604 | |
| 1605 | out: |
| 1606 | mutex_unlock(&dev->cap_mask_mutex); |
| 1607 | return err; |
| 1608 | } |
| 1609 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1610 | static void print_lib_caps(struct mlx5_ib_dev *dev, u64 caps) |
| 1611 | { |
| 1612 | mlx5_ib_dbg(dev, "MLX5_LIB_CAP_4K_UAR = %s\n", |
| 1613 | caps & MLX5_LIB_CAP_4K_UAR ? "y" : "n"); |
| 1614 | } |
| 1615 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1616 | static u16 calc_dynamic_bfregs(int uars_per_sys_page) |
| 1617 | { |
| 1618 | /* Large page with non 4k uar support might limit the dynamic size */ |
| 1619 | if (uars_per_sys_page == 1 && PAGE_SIZE > 4096) |
| 1620 | return MLX5_MIN_DYN_BFREGS; |
| 1621 | |
| 1622 | return MLX5_MAX_DYN_BFREGS; |
| 1623 | } |
| 1624 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1625 | static int calc_total_bfregs(struct mlx5_ib_dev *dev, bool lib_uar_4k, |
| 1626 | struct mlx5_ib_alloc_ucontext_req_v2 *req, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1627 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1628 | { |
| 1629 | int uars_per_sys_page; |
| 1630 | int bfregs_per_sys_page; |
| 1631 | int ref_bfregs = req->total_num_bfregs; |
| 1632 | |
| 1633 | if (req->total_num_bfregs == 0) |
| 1634 | return -EINVAL; |
| 1635 | |
| 1636 | BUILD_BUG_ON(MLX5_MAX_BFREGS % MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1637 | BUILD_BUG_ON(MLX5_MAX_BFREGS < MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1638 | |
| 1639 | if (req->total_num_bfregs > MLX5_MAX_BFREGS) |
| 1640 | return -ENOMEM; |
| 1641 | |
| 1642 | uars_per_sys_page = get_uars_per_sys_page(dev, lib_uar_4k); |
| 1643 | 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] | 1644 | /* This holds the required static allocation asked by the user */ |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1645 | 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] | 1646 | if (req->num_low_latency_bfregs > req->total_num_bfregs - 1) |
| 1647 | return -EINVAL; |
| 1648 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1649 | bfregi->num_static_sys_pages = req->total_num_bfregs / bfregs_per_sys_page; |
| 1650 | bfregi->num_dyn_bfregs = ALIGN(calc_dynamic_bfregs(uars_per_sys_page), bfregs_per_sys_page); |
| 1651 | bfregi->total_num_bfregs = req->total_num_bfregs + bfregi->num_dyn_bfregs; |
| 1652 | bfregi->num_sys_pages = bfregi->total_num_bfregs / bfregs_per_sys_page; |
| 1653 | |
| 1654 | 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] | 1655 | MLX5_CAP_GEN(dev->mdev, uar_4k) ? "yes" : "no", |
| 1656 | lib_uar_4k ? "yes" : "no", ref_bfregs, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1657 | req->total_num_bfregs, bfregi->total_num_bfregs, |
| 1658 | bfregi->num_sys_pages); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1659 | |
| 1660 | return 0; |
| 1661 | } |
| 1662 | |
| 1663 | static int allocate_uars(struct mlx5_ib_dev *dev, struct mlx5_ib_ucontext *context) |
| 1664 | { |
| 1665 | struct mlx5_bfreg_info *bfregi; |
| 1666 | int err; |
| 1667 | int i; |
| 1668 | |
| 1669 | bfregi = &context->bfregi; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1670 | for (i = 0; i < bfregi->num_static_sys_pages; i++) { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1671 | err = mlx5_cmd_alloc_uar(dev->mdev, &bfregi->sys_pages[i]); |
| 1672 | if (err) |
| 1673 | goto error; |
| 1674 | |
| 1675 | mlx5_ib_dbg(dev, "allocated uar %d\n", bfregi->sys_pages[i]); |
| 1676 | } |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1677 | |
| 1678 | for (i = bfregi->num_static_sys_pages; i < bfregi->num_sys_pages; i++) |
| 1679 | bfregi->sys_pages[i] = MLX5_IB_INVALID_UAR_INDEX; |
| 1680 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1681 | return 0; |
| 1682 | |
| 1683 | error: |
| 1684 | for (--i; i >= 0; i--) |
| 1685 | if (mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i])) |
| 1686 | mlx5_ib_warn(dev, "failed to free uar %d\n", i); |
| 1687 | |
| 1688 | return err; |
| 1689 | } |
| 1690 | |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1691 | static void deallocate_uars(struct mlx5_ib_dev *dev, |
| 1692 | struct mlx5_ib_ucontext *context) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1693 | { |
| 1694 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1695 | int i; |
| 1696 | |
| 1697 | bfregi = &context->bfregi; |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1698 | for (i = 0; i < bfregi->num_sys_pages; i++) |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1699 | if (i < bfregi->num_static_sys_pages || |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1700 | bfregi->sys_pages[i] != MLX5_IB_INVALID_UAR_INDEX) |
| 1701 | mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i]); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1702 | } |
| 1703 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1704 | 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] | 1705 | { |
| 1706 | int err = 0; |
| 1707 | |
| 1708 | mutex_lock(&dev->lb.mutex); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1709 | if (td) |
| 1710 | dev->lb.user_td++; |
| 1711 | if (qp) |
| 1712 | dev->lb.qps++; |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1713 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1714 | if (dev->lb.user_td == 2 || |
| 1715 | dev->lb.qps == 1) { |
| 1716 | if (!dev->lb.enabled) { |
| 1717 | err = mlx5_nic_vport_update_local_lb(dev->mdev, true); |
| 1718 | dev->lb.enabled = true; |
| 1719 | } |
| 1720 | } |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1721 | |
| 1722 | mutex_unlock(&dev->lb.mutex); |
| 1723 | |
| 1724 | return err; |
| 1725 | } |
| 1726 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1727 | 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] | 1728 | { |
| 1729 | mutex_lock(&dev->lb.mutex); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1730 | if (td) |
| 1731 | dev->lb.user_td--; |
| 1732 | if (qp) |
| 1733 | dev->lb.qps--; |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1734 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1735 | if (dev->lb.user_td == 1 && |
| 1736 | dev->lb.qps == 0) { |
| 1737 | if (dev->lb.enabled) { |
| 1738 | mlx5_nic_vport_update_local_lb(dev->mdev, false); |
| 1739 | dev->lb.enabled = false; |
| 1740 | } |
| 1741 | } |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1742 | |
| 1743 | mutex_unlock(&dev->lb.mutex); |
| 1744 | } |
| 1745 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1746 | static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn, |
| 1747 | u16 uid) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1748 | { |
| 1749 | int err; |
| 1750 | |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1751 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1752 | return 0; |
| 1753 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1754 | err = mlx5_cmd_alloc_transport_domain(dev->mdev, tdn, uid); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1755 | if (err) |
| 1756 | return err; |
| 1757 | |
| 1758 | 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] | 1759 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1760 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1761 | return err; |
| 1762 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1763 | return mlx5_ib_enable_lb(dev, true, false); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1764 | } |
| 1765 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1766 | static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn, |
| 1767 | u16 uid) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1768 | { |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1769 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1770 | return; |
| 1771 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1772 | mlx5_cmd_dealloc_transport_domain(dev->mdev, tdn, uid); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1773 | |
| 1774 | 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] | 1775 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1776 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1777 | return; |
| 1778 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1779 | mlx5_ib_disable_lb(dev, true, false); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1780 | } |
| 1781 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1782 | static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx, |
| 1783 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1784 | { |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1785 | struct ib_device *ibdev = uctx->device; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1786 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1787 | struct mlx5_ib_alloc_ucontext_req_v2 req = {}; |
| 1788 | struct mlx5_ib_alloc_ucontext_resp resp = {}; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1789 | struct mlx5_core_dev *mdev = dev->mdev; |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1790 | struct mlx5_ib_ucontext *context = to_mucontext(uctx); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1791 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1792 | int ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1793 | int err; |
Majd Dibbiny | a168a41c | 2016-01-28 17:51:47 +0200 | [diff] [blame] | 1794 | size_t min_req_v2 = offsetof(struct mlx5_ib_alloc_ucontext_req_v2, |
| 1795 | max_cqe_version); |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1796 | u32 dump_fill_mkey; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1797 | bool lib_uar_4k; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1798 | |
| 1799 | if (!dev->ib_active) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1800 | return -EAGAIN; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1801 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1802 | if (udata->inlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1803 | ver = 0; |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1804 | else if (udata->inlen >= min_req_v2) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1805 | ver = 2; |
| 1806 | else |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1807 | return -EINVAL; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1808 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1809 | err = ib_copy_from_udata(&req, udata, min(udata->inlen, sizeof(req))); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1810 | if (err) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1811 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1812 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1813 | if (req.flags & ~MLX5_IB_ALLOC_UCTX_DEVX) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1814 | return -EOPNOTSUPP; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1815 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1816 | if (req.comp_mask || req.reserved0 || req.reserved1 || req.reserved2) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1817 | return -EOPNOTSUPP; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1818 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1819 | req.total_num_bfregs = ALIGN(req.total_num_bfregs, |
| 1820 | MLX5_NON_FP_BFREGS_PER_UAR); |
| 1821 | if (req.num_low_latency_bfregs > req.total_num_bfregs - 1) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1822 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1823 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1824 | 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] | 1825 | if (mlx5_core_is_pf(dev->mdev) && MLX5_CAP_GEN(dev->mdev, bf)) |
| 1826 | 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] | 1827 | resp.cache_line_size = cache_line_size(); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1828 | resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); |
| 1829 | resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); |
| 1830 | resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1831 | resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1832 | 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] | 1833 | resp.cqe_version = min_t(__u8, |
| 1834 | (__u8)MLX5_CAP_GEN(dev->mdev, cqe_version), |
| 1835 | req.max_cqe_version); |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1836 | resp.log_uar_size = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1837 | MLX5_ADAPTER_PAGE_SHIFT : PAGE_SHIFT; |
| 1838 | resp.num_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1839 | MLX5_CAP_GEN(dev->mdev, num_of_uars_per_page) : 1; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1840 | resp.response_length = min(offsetof(typeof(resp), response_length) + |
| 1841 | sizeof(resp.response_length), udata->outlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1842 | |
Matan Barak | c03faa5 | 2018-03-28 09:27:54 +0300 | [diff] [blame] | 1843 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_DEVICE) { |
| 1844 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_EGRESS)) |
| 1845 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM; |
| 1846 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_REQUIRED_METADATA) |
| 1847 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_REQ_METADATA; |
| 1848 | if (MLX5_CAP_FLOWTABLE(dev->mdev, flow_table_properties_nic_receive.ft_field_support.outer_esp_spi)) |
| 1849 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_SPI_STEERING; |
| 1850 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_TX_IV_IS_ESN) |
| 1851 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_TX_IV_IS_ESN; |
| 1852 | /* MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_FULL_OFFLOAD is currently always 0 */ |
| 1853 | } |
| 1854 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1855 | lib_uar_4k = req.lib_caps & MLX5_LIB_CAP_4K_UAR; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1856 | bfregi = &context->bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1857 | |
| 1858 | /* updates req->total_num_bfregs */ |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1859 | err = calc_total_bfregs(dev, lib_uar_4k, &req, bfregi); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1860 | if (err) |
| 1861 | goto out_ctx; |
| 1862 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1863 | mutex_init(&bfregi->lock); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1864 | bfregi->lib_uar_4k = lib_uar_4k; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1865 | bfregi->count = kcalloc(bfregi->total_num_bfregs, sizeof(*bfregi->count), |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1866 | GFP_KERNEL); |
| 1867 | if (!bfregi->count) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1868 | err = -ENOMEM; |
| 1869 | goto out_ctx; |
| 1870 | } |
| 1871 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1872 | bfregi->sys_pages = kcalloc(bfregi->num_sys_pages, |
| 1873 | sizeof(*bfregi->sys_pages), |
| 1874 | GFP_KERNEL); |
| 1875 | if (!bfregi->sys_pages) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1876 | err = -ENOMEM; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1877 | goto out_count; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1878 | } |
| 1879 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1880 | err = allocate_uars(dev, context); |
| 1881 | if (err) |
| 1882 | goto out_sys_pages; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1883 | |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 1884 | if (ibdev->attrs.device_cap_flags & IB_DEVICE_ON_DEMAND_PAGING) |
| 1885 | context->ibucontext.invalidate_range = |
| 1886 | &mlx5_ib_invalidate_range; |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 1887 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1888 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) { |
Yishai Hadas | fb98153 | 2018-11-26 08:28:36 +0200 | [diff] [blame] | 1889 | err = mlx5_ib_devx_create(dev, true); |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1890 | if (err < 0) |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1891 | goto out_uars; |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1892 | context->devx_uid = err; |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1893 | } |
| 1894 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1895 | err = mlx5_ib_alloc_transport_domain(dev, &context->tdn, |
| 1896 | context->devx_uid); |
| 1897 | if (err) |
| 1898 | goto out_devx; |
| 1899 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1900 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1901 | err = mlx5_cmd_dump_fill_mkey(dev->mdev, &dump_fill_mkey); |
| 1902 | if (err) |
Jason Gunthorpe | 8193abb | 2018-07-04 13:19:46 -0600 | [diff] [blame] | 1903 | goto out_mdev; |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1904 | } |
| 1905 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1906 | INIT_LIST_HEAD(&context->db_page_list); |
| 1907 | mutex_init(&context->db_page_mutex); |
| 1908 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1909 | resp.tot_bfregs = req.total_num_bfregs; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 1910 | resp.num_ports = dev->num_ports; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1911 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1912 | if (field_avail(typeof(resp), cqe_version, udata->outlen)) |
| 1913 | resp.response_length += sizeof(resp.cqe_version); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1914 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1915 | if (field_avail(typeof(resp), cmds_supp_uhw, udata->outlen)) { |
Moni Shoua | 6ad279c5 | 2016-11-23 08:23:23 +0200 | [diff] [blame] | 1916 | resp.cmds_supp_uhw |= MLX5_USER_CMDS_SUPP_UHW_QUERY_DEVICE | |
| 1917 | MLX5_USER_CMDS_SUPP_UHW_CREATE_AH; |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1918 | resp.response_length += sizeof(resp.cmds_supp_uhw); |
| 1919 | } |
| 1920 | |
Or Gerlitz | 7898489 | 2016-11-30 20:33:33 +0200 | [diff] [blame] | 1921 | if (field_avail(typeof(resp), eth_min_inline, udata->outlen)) { |
| 1922 | if (mlx5_ib_port_link_layer(ibdev, 1) == IB_LINK_LAYER_ETHERNET) { |
| 1923 | mlx5_query_min_inline(dev->mdev, &resp.eth_min_inline); |
| 1924 | resp.eth_min_inline++; |
| 1925 | } |
| 1926 | resp.response_length += sizeof(resp.eth_min_inline); |
| 1927 | } |
| 1928 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1929 | if (field_avail(typeof(resp), clock_info_versions, udata->outlen)) { |
| 1930 | if (mdev->clock_info) |
| 1931 | resp.clock_info_versions = BIT(MLX5_IB_CLOCK_INFO_V1); |
| 1932 | resp.response_length += sizeof(resp.clock_info_versions); |
| 1933 | } |
| 1934 | |
Noa Osherovich | bc5c6ee | 2016-06-04 15:15:31 +0300 | [diff] [blame] | 1935 | /* |
| 1936 | * We don't want to expose information from the PCI bar that is located |
| 1937 | * after 4096 bytes, so if the arch only supports larger pages, let's |
| 1938 | * pretend we don't support reading the HCA's core clock. This is also |
| 1939 | * forced by mmap function. |
| 1940 | */ |
Eli Cohen | de8d6e0 | 2017-01-03 23:55:19 +0200 | [diff] [blame] | 1941 | if (field_avail(typeof(resp), hca_core_clock_offset, udata->outlen)) { |
| 1942 | if (PAGE_SIZE <= 4096) { |
| 1943 | resp.comp_mask |= |
| 1944 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET; |
| 1945 | resp.hca_core_clock_offset = |
| 1946 | offsetof(struct mlx5_init_seg, internal_timer_h) % PAGE_SIZE; |
| 1947 | } |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1948 | resp.response_length += sizeof(resp.hca_core_clock_offset); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1949 | } |
| 1950 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1951 | if (field_avail(typeof(resp), log_uar_size, udata->outlen)) |
| 1952 | resp.response_length += sizeof(resp.log_uar_size); |
| 1953 | |
| 1954 | if (field_avail(typeof(resp), num_uars_per_page, udata->outlen)) |
| 1955 | resp.response_length += sizeof(resp.num_uars_per_page); |
| 1956 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1957 | if (field_avail(typeof(resp), num_dyn_bfregs, udata->outlen)) { |
| 1958 | resp.num_dyn_bfregs = bfregi->num_dyn_bfregs; |
| 1959 | resp.response_length += sizeof(resp.num_dyn_bfregs); |
| 1960 | } |
| 1961 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1962 | if (field_avail(typeof(resp), dump_fill_mkey, udata->outlen)) { |
| 1963 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1964 | resp.dump_fill_mkey = dump_fill_mkey; |
| 1965 | resp.comp_mask |= |
| 1966 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_DUMP_FILL_MKEY; |
| 1967 | } |
| 1968 | resp.response_length += sizeof(resp.dump_fill_mkey); |
| 1969 | } |
| 1970 | |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1971 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1972 | if (err) |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1973 | goto out_mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1974 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1975 | bfregi->ver = ver; |
| 1976 | bfregi->num_low_latency_bfregs = req.num_low_latency_bfregs; |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1977 | context->cqe_version = resp.cqe_version; |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1978 | context->lib_caps = req.lib_caps; |
| 1979 | print_lib_caps(dev, context->lib_caps); |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1980 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 1981 | if (dev->lag_active) { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 1982 | u8 port = mlx5_core_native_port_num(dev->mdev) - 1; |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 1983 | |
| 1984 | atomic_set(&context->tx_port_affinity, |
| 1985 | atomic_add_return( |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 1986 | 1, &dev->port[port].roce.tx_port_affinity)); |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 1987 | } |
| 1988 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1989 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1990 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1991 | out_mdev: |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1992 | mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid); |
| 1993 | out_devx: |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1994 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1995 | mlx5_ib_devx_destroy(dev, context->devx_uid); |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1996 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1997 | out_uars: |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1998 | deallocate_uars(dev, context); |
| 1999 | |
| 2000 | out_sys_pages: |
| 2001 | kfree(bfregi->sys_pages); |
| 2002 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2003 | out_count: |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2004 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2005 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2006 | out_ctx: |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 2007 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2008 | } |
| 2009 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 2010 | static void mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2011 | { |
| 2012 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 2013 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2014 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2015 | |
Jason Gunthorpe | f27a0d5 | 2018-09-16 20:48:08 +0300 | [diff] [blame] | 2016 | /* All umem's must be destroyed before destroying the ucontext. */ |
| 2017 | mutex_lock(&ibcontext->per_mm_list_lock); |
| 2018 | WARN_ON(!list_empty(&ibcontext->per_mm_list)); |
| 2019 | mutex_unlock(&ibcontext->per_mm_list_lock); |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 2020 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2021 | bfregi = &context->bfregi; |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 2022 | mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid); |
| 2023 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2024 | if (context->devx_uid) |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 2025 | mlx5_ib_devx_destroy(dev, context->devx_uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2026 | |
| 2027 | deallocate_uars(dev, context); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2028 | kfree(bfregi->sys_pages); |
| 2029 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, |
| 2033 | int uar_idx) |
| 2034 | { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2035 | int fw_uars_per_page; |
| 2036 | |
| 2037 | fw_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? MLX5_UARS_IN_PAGE : 1; |
| 2038 | |
Huy Nguyen | aa8106f | 2019-03-29 15:38:01 -0700 | [diff] [blame] | 2039 | 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] | 2040 | } |
| 2041 | |
| 2042 | static int get_command(unsigned long offset) |
| 2043 | { |
| 2044 | return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK; |
| 2045 | } |
| 2046 | |
| 2047 | static int get_arg(unsigned long offset) |
| 2048 | { |
| 2049 | return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1); |
| 2050 | } |
| 2051 | |
| 2052 | static int get_index(unsigned long offset) |
| 2053 | { |
| 2054 | return get_arg(offset); |
| 2055 | } |
| 2056 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2057 | /* Index resides in an extra byte to enable larger values than 255 */ |
| 2058 | static int get_extended_index(unsigned long offset) |
| 2059 | { |
| 2060 | return get_arg(offset) | ((offset >> 16) & 0xff) << 8; |
| 2061 | } |
| 2062 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2063 | |
| 2064 | static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) |
| 2065 | { |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2066 | } |
| 2067 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2068 | static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd) |
| 2069 | { |
| 2070 | switch (cmd) { |
| 2071 | case MLX5_IB_MMAP_WC_PAGE: |
| 2072 | return "WC"; |
| 2073 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2074 | return "best effort WC"; |
| 2075 | case MLX5_IB_MMAP_NC_PAGE: |
| 2076 | return "NC"; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2077 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2078 | return "Device Memory"; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2079 | default: |
| 2080 | return NULL; |
| 2081 | } |
| 2082 | } |
| 2083 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2084 | static int mlx5_ib_mmap_clock_info_page(struct mlx5_ib_dev *dev, |
| 2085 | struct vm_area_struct *vma, |
| 2086 | struct mlx5_ib_ucontext *context) |
| 2087 | { |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2088 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2089 | return -EINVAL; |
| 2090 | |
| 2091 | if (get_index(vma->vm_pgoff) != MLX5_IB_CLOCK_INFO_V1) |
| 2092 | return -EOPNOTSUPP; |
| 2093 | |
| 2094 | if (vma->vm_flags & VM_WRITE) |
| 2095 | return -EPERM; |
| 2096 | |
| 2097 | if (!dev->mdev->clock_info_page) |
| 2098 | return -EOPNOTSUPP; |
| 2099 | |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2100 | return rdma_user_mmap_page(&context->ibucontext, vma, |
| 2101 | dev->mdev->clock_info_page, PAGE_SIZE); |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2102 | } |
| 2103 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2104 | 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] | 2105 | struct vm_area_struct *vma, |
| 2106 | struct mlx5_ib_ucontext *context) |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2107 | { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2108 | struct mlx5_bfreg_info *bfregi = &context->bfregi; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2109 | int err; |
| 2110 | unsigned long idx; |
Kamal Heib | aa09ea6 | 2018-07-19 00:05:32 +0300 | [diff] [blame] | 2111 | phys_addr_t pfn; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2112 | pgprot_t prot; |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2113 | u32 bfreg_dyn_idx = 0; |
| 2114 | u32 uar_index; |
| 2115 | int dyn_uar = (cmd == MLX5_IB_MMAP_ALLOC_WC); |
| 2116 | int max_valid_idx = dyn_uar ? bfregi->num_sys_pages : |
| 2117 | bfregi->num_static_sys_pages; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2118 | |
| 2119 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2120 | return -EINVAL; |
| 2121 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2122 | if (dyn_uar) |
| 2123 | idx = get_extended_index(vma->vm_pgoff) + bfregi->num_static_sys_pages; |
| 2124 | else |
| 2125 | idx = get_index(vma->vm_pgoff); |
| 2126 | |
| 2127 | if (idx >= max_valid_idx) { |
| 2128 | mlx5_ib_warn(dev, "invalid uar index %lu, max=%d\n", |
| 2129 | idx, max_valid_idx); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2130 | return -EINVAL; |
| 2131 | } |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2132 | |
| 2133 | switch (cmd) { |
| 2134 | case MLX5_IB_MMAP_WC_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2135 | case MLX5_IB_MMAP_ALLOC_WC: |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2136 | /* Some architectures don't support WC memory */ |
| 2137 | #if defined(CONFIG_X86) |
| 2138 | if (!pat_enabled()) |
| 2139 | return -EPERM; |
| 2140 | #elif !(defined(CONFIG_PPC) || (defined(CONFIG_ARM) && defined(CONFIG_MMU))) |
| 2141 | return -EPERM; |
| 2142 | #endif |
| 2143 | /* fall through */ |
| 2144 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2145 | /* For MLX5_IB_MMAP_REGULAR_PAGE do the best effort to get WC */ |
| 2146 | prot = pgprot_writecombine(vma->vm_page_prot); |
| 2147 | break; |
| 2148 | case MLX5_IB_MMAP_NC_PAGE: |
| 2149 | prot = pgprot_noncached(vma->vm_page_prot); |
| 2150 | break; |
| 2151 | default: |
| 2152 | return -EINVAL; |
| 2153 | } |
| 2154 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2155 | if (dyn_uar) { |
| 2156 | int uars_per_page; |
| 2157 | |
| 2158 | uars_per_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k); |
| 2159 | bfreg_dyn_idx = idx * (uars_per_page * MLX5_NON_FP_BFREGS_PER_UAR); |
| 2160 | if (bfreg_dyn_idx >= bfregi->total_num_bfregs) { |
| 2161 | mlx5_ib_warn(dev, "invalid bfreg_dyn_idx %u, max=%u\n", |
| 2162 | bfreg_dyn_idx, bfregi->total_num_bfregs); |
| 2163 | return -EINVAL; |
| 2164 | } |
| 2165 | |
| 2166 | mutex_lock(&bfregi->lock); |
| 2167 | /* Fail if uar already allocated, first bfreg index of each |
| 2168 | * page holds its count. |
| 2169 | */ |
| 2170 | if (bfregi->count[bfreg_dyn_idx]) { |
| 2171 | mlx5_ib_warn(dev, "wrong offset, idx %lu is busy, bfregn=%u\n", idx, bfreg_dyn_idx); |
| 2172 | mutex_unlock(&bfregi->lock); |
| 2173 | return -EINVAL; |
| 2174 | } |
| 2175 | |
| 2176 | bfregi->count[bfreg_dyn_idx]++; |
| 2177 | mutex_unlock(&bfregi->lock); |
| 2178 | |
| 2179 | err = mlx5_cmd_alloc_uar(dev->mdev, &uar_index); |
| 2180 | if (err) { |
| 2181 | mlx5_ib_warn(dev, "UAR alloc failed\n"); |
| 2182 | goto free_bfreg; |
| 2183 | } |
| 2184 | } else { |
| 2185 | uar_index = bfregi->sys_pages[idx]; |
| 2186 | } |
| 2187 | |
| 2188 | pfn = uar_index2pfn(dev, uar_index); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2189 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn %pa\n", idx, &pfn); |
| 2190 | |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2191 | err = rdma_user_mmap_io(&context->ibucontext, vma, pfn, PAGE_SIZE, |
| 2192 | prot); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2193 | if (err) { |
Leon Romanovsky | 8f06228 | 2018-05-22 08:31:03 +0300 | [diff] [blame] | 2194 | mlx5_ib_err(dev, |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2195 | "rdma_user_mmap_io failed with error=%d, mmap_cmd=%s\n", |
Leon Romanovsky | 8f06228 | 2018-05-22 08:31:03 +0300 | [diff] [blame] | 2196 | err, mmap_cmd2str(cmd)); |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2197 | goto err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2198 | } |
| 2199 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2200 | if (dyn_uar) |
| 2201 | bfregi->sys_pages[idx] = uar_index; |
| 2202 | return 0; |
| 2203 | |
| 2204 | err: |
| 2205 | if (!dyn_uar) |
| 2206 | return err; |
| 2207 | |
| 2208 | mlx5_cmd_free_uar(dev->mdev, idx); |
| 2209 | |
| 2210 | free_bfreg: |
| 2211 | mlx5_ib_free_bfreg(dev, bfregi, bfreg_dyn_idx); |
| 2212 | |
| 2213 | return err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2214 | } |
| 2215 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2216 | static int dm_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
| 2217 | { |
| 2218 | struct mlx5_ib_ucontext *mctx = to_mucontext(context); |
| 2219 | struct mlx5_ib_dev *dev = to_mdev(context->device); |
| 2220 | u16 page_idx = get_extended_index(vma->vm_pgoff); |
| 2221 | size_t map_size = vma->vm_end - vma->vm_start; |
| 2222 | u32 npages = map_size >> PAGE_SHIFT; |
| 2223 | phys_addr_t pfn; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2224 | |
| 2225 | if (find_next_zero_bit(mctx->dm_pages, page_idx + npages, page_idx) != |
| 2226 | page_idx + npages) |
| 2227 | return -EINVAL; |
| 2228 | |
Huy Nguyen | aa8106f | 2019-03-29 15:38:01 -0700 | [diff] [blame] | 2229 | pfn = ((dev->mdev->bar_addr + |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2230 | MLX5_CAP64_DEV_MEM(dev->mdev, memic_bar_start_addr)) >> |
| 2231 | PAGE_SHIFT) + |
| 2232 | page_idx; |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2233 | return rdma_user_mmap_io(context, vma, pfn, map_size, |
| 2234 | pgprot_writecombine(vma->vm_page_prot)); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2235 | } |
| 2236 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2237 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
| 2238 | { |
| 2239 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 2240 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2241 | unsigned long command; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2242 | phys_addr_t pfn; |
| 2243 | |
| 2244 | command = get_command(vma->vm_pgoff); |
| 2245 | switch (command) { |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2246 | case MLX5_IB_MMAP_WC_PAGE: |
| 2247 | case MLX5_IB_MMAP_NC_PAGE: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2248 | case MLX5_IB_MMAP_REGULAR_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2249 | case MLX5_IB_MMAP_ALLOC_WC: |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2250 | return uar_mmap(dev, command, vma, context); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2251 | |
| 2252 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
| 2253 | return -ENOSYS; |
| 2254 | |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2255 | case MLX5_IB_MMAP_CORE_CLOCK: |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2256 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2257 | return -EINVAL; |
| 2258 | |
Matan Barak | 6cbac1e | 2016-04-14 16:52:10 +0300 | [diff] [blame] | 2259 | if (vma->vm_flags & VM_WRITE) |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2260 | return -EPERM; |
| 2261 | |
| 2262 | /* Don't expose to user-space information it shouldn't have */ |
| 2263 | if (PAGE_SIZE > 4096) |
| 2264 | return -EOPNOTSUPP; |
| 2265 | |
| 2266 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 2267 | pfn = (dev->mdev->iseg_base + |
| 2268 | offsetof(struct mlx5_init_seg, internal_timer_h)) >> |
| 2269 | PAGE_SHIFT; |
| 2270 | if (io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 2271 | PAGE_SIZE, vma->vm_page_prot)) |
| 2272 | return -EAGAIN; |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2273 | break; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2274 | case MLX5_IB_MMAP_CLOCK_INFO: |
| 2275 | return mlx5_ib_mmap_clock_info_page(dev, vma, context); |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2276 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2277 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2278 | return dm_mmap(ibcontext, vma); |
| 2279 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2280 | default: |
| 2281 | return -EINVAL; |
| 2282 | } |
| 2283 | |
| 2284 | return 0; |
| 2285 | } |
| 2286 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2287 | struct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev, |
| 2288 | struct ib_ucontext *context, |
| 2289 | struct ib_dm_alloc_attr *attr, |
| 2290 | struct uverbs_attr_bundle *attrs) |
| 2291 | { |
| 2292 | u64 act_size = roundup(attr->length, MLX5_MEMIC_BASE_SIZE); |
| 2293 | struct mlx5_memic *memic = &to_mdev(ibdev)->memic; |
| 2294 | phys_addr_t memic_addr; |
| 2295 | struct mlx5_ib_dm *dm; |
| 2296 | u64 start_offset; |
| 2297 | u32 page_idx; |
| 2298 | int err; |
| 2299 | |
| 2300 | dm = kzalloc(sizeof(*dm), GFP_KERNEL); |
| 2301 | if (!dm) |
| 2302 | return ERR_PTR(-ENOMEM); |
| 2303 | |
| 2304 | mlx5_ib_dbg(to_mdev(ibdev), "alloc_memic req: user_length=0x%llx act_length=0x%llx log_alignment=%d\n", |
| 2305 | attr->length, act_size, attr->alignment); |
| 2306 | |
| 2307 | err = mlx5_cmd_alloc_memic(memic, &memic_addr, |
| 2308 | act_size, attr->alignment); |
| 2309 | if (err) |
| 2310 | goto err_free; |
| 2311 | |
| 2312 | start_offset = memic_addr & ~PAGE_MASK; |
Huy Nguyen | aa8106f | 2019-03-29 15:38:01 -0700 | [diff] [blame] | 2313 | page_idx = (memic_addr - memic->dev->bar_addr - |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2314 | MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
| 2315 | PAGE_SHIFT; |
| 2316 | |
| 2317 | err = uverbs_copy_to(attrs, |
| 2318 | MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 2319 | &start_offset, sizeof(start_offset)); |
| 2320 | if (err) |
| 2321 | goto err_dealloc; |
| 2322 | |
| 2323 | err = uverbs_copy_to(attrs, |
| 2324 | MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 2325 | &page_idx, sizeof(page_idx)); |
| 2326 | if (err) |
| 2327 | goto err_dealloc; |
| 2328 | |
| 2329 | bitmap_set(to_mucontext(context)->dm_pages, page_idx, |
| 2330 | DIV_ROUND_UP(act_size, PAGE_SIZE)); |
| 2331 | |
| 2332 | dm->dev_addr = memic_addr; |
| 2333 | |
| 2334 | return &dm->ibdm; |
| 2335 | |
| 2336 | err_dealloc: |
| 2337 | mlx5_cmd_dealloc_memic(memic, memic_addr, |
| 2338 | act_size); |
| 2339 | err_free: |
| 2340 | kfree(dm); |
| 2341 | return ERR_PTR(err); |
| 2342 | } |
| 2343 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2344 | 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] | 2345 | { |
| 2346 | struct mlx5_memic *memic = &to_mdev(ibdm->device)->memic; |
| 2347 | struct mlx5_ib_dm *dm = to_mdm(ibdm); |
| 2348 | u64 act_size = roundup(dm->ibdm.length, MLX5_MEMIC_BASE_SIZE); |
| 2349 | u32 page_idx; |
| 2350 | int ret; |
| 2351 | |
| 2352 | ret = mlx5_cmd_dealloc_memic(memic, dm->dev_addr, act_size); |
| 2353 | if (ret) |
| 2354 | return ret; |
| 2355 | |
Huy Nguyen | aa8106f | 2019-03-29 15:38:01 -0700 | [diff] [blame] | 2356 | page_idx = (dm->dev_addr - memic->dev->bar_addr - |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2357 | MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
| 2358 | PAGE_SHIFT; |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2359 | bitmap_clear(rdma_udata_to_drv_context( |
| 2360 | &attrs->driver_udata, |
| 2361 | struct mlx5_ib_ucontext, |
| 2362 | ibucontext)->dm_pages, |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2363 | page_idx, |
| 2364 | DIV_ROUND_UP(act_size, PAGE_SIZE)); |
| 2365 | |
| 2366 | kfree(dm); |
| 2367 | |
| 2368 | return 0; |
| 2369 | } |
| 2370 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2371 | 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] | 2372 | { |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2373 | struct mlx5_ib_pd *pd = to_mpd(ibpd); |
| 2374 | struct ib_device *ibdev = ibpd->device; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2375 | struct mlx5_ib_alloc_pd_resp resp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2376 | int err; |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2377 | u32 out[MLX5_ST_SZ_DW(alloc_pd_out)] = {}; |
| 2378 | u32 in[MLX5_ST_SZ_DW(alloc_pd_in)] = {}; |
| 2379 | u16 uid = 0; |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2380 | struct mlx5_ib_ucontext *context = rdma_udata_to_drv_context( |
| 2381 | udata, struct mlx5_ib_ucontext, ibucontext); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2382 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2383 | uid = context ? context->devx_uid : 0; |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2384 | MLX5_SET(alloc_pd_in, in, opcode, MLX5_CMD_OP_ALLOC_PD); |
| 2385 | MLX5_SET(alloc_pd_in, in, uid, uid); |
| 2386 | err = mlx5_cmd_exec(to_mdev(ibdev)->mdev, in, sizeof(in), |
| 2387 | out, sizeof(out)); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2388 | if (err) |
| 2389 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2390 | |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2391 | pd->pdn = MLX5_GET(alloc_pd_out, out, pd); |
| 2392 | pd->uid = uid; |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2393 | if (udata) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2394 | resp.pdn = pd->pdn; |
| 2395 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2396 | mlx5_cmd_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn, uid); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2397 | return -EFAULT; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2398 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2399 | } |
| 2400 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2401 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2402 | } |
| 2403 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2404 | 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] | 2405 | { |
| 2406 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 2407 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
| 2408 | |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2409 | mlx5_cmd_dealloc_pd(mdev->mdev, mpd->pdn, mpd->uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2410 | } |
| 2411 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2412 | enum { |
| 2413 | MATCH_CRITERIA_ENABLE_OUTER_BIT, |
| 2414 | MATCH_CRITERIA_ENABLE_MISC_BIT, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2415 | MATCH_CRITERIA_ENABLE_INNER_BIT, |
| 2416 | MATCH_CRITERIA_ENABLE_MISC2_BIT |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2417 | }; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2418 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2419 | #define HEADER_IS_ZERO(match_criteria, headers) \ |
| 2420 | !(memchr_inv(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \ |
| 2421 | 0, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \ |
| 2422 | |
| 2423 | static u8 get_match_criteria_enable(u32 *match_criteria) |
| 2424 | { |
| 2425 | u8 match_criteria_enable; |
| 2426 | |
| 2427 | match_criteria_enable = |
| 2428 | (!HEADER_IS_ZERO(match_criteria, outer_headers)) << |
| 2429 | MATCH_CRITERIA_ENABLE_OUTER_BIT; |
| 2430 | match_criteria_enable |= |
| 2431 | (!HEADER_IS_ZERO(match_criteria, misc_parameters)) << |
| 2432 | MATCH_CRITERIA_ENABLE_MISC_BIT; |
| 2433 | match_criteria_enable |= |
| 2434 | (!HEADER_IS_ZERO(match_criteria, inner_headers)) << |
| 2435 | MATCH_CRITERIA_ENABLE_INNER_BIT; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2436 | match_criteria_enable |= |
| 2437 | (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) << |
| 2438 | MATCH_CRITERIA_ENABLE_MISC2_BIT; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2439 | |
| 2440 | return match_criteria_enable; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2441 | } |
| 2442 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2443 | 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] | 2444 | { |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2445 | u8 entry_mask; |
| 2446 | u8 entry_val; |
| 2447 | int err = 0; |
| 2448 | |
| 2449 | if (!mask) |
| 2450 | goto out; |
| 2451 | |
| 2452 | entry_mask = MLX5_GET(fte_match_set_lyr_2_4, outer_c, |
| 2453 | ip_protocol); |
| 2454 | entry_val = MLX5_GET(fte_match_set_lyr_2_4, outer_v, |
| 2455 | ip_protocol); |
| 2456 | if (!entry_mask) { |
| 2457 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_protocol, mask); |
| 2458 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_protocol, val); |
| 2459 | goto out; |
| 2460 | } |
| 2461 | /* Don't override existing ip protocol */ |
| 2462 | if (mask != entry_mask || val != entry_val) |
| 2463 | err = -EINVAL; |
| 2464 | out: |
| 2465 | return err; |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2466 | } |
| 2467 | |
Daria Velikovsky | 37da2a0 | 2018-05-07 10:20:02 +0300 | [diff] [blame] | 2468 | 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] | 2469 | bool inner) |
| 2470 | { |
| 2471 | if (inner) { |
| 2472 | MLX5_SET(fte_match_set_misc, |
| 2473 | misc_c, inner_ipv6_flow_label, mask); |
| 2474 | MLX5_SET(fte_match_set_misc, |
| 2475 | misc_v, inner_ipv6_flow_label, val); |
| 2476 | } else { |
| 2477 | MLX5_SET(fte_match_set_misc, |
| 2478 | misc_c, outer_ipv6_flow_label, mask); |
| 2479 | MLX5_SET(fte_match_set_misc, |
| 2480 | misc_v, outer_ipv6_flow_label, val); |
| 2481 | } |
| 2482 | } |
| 2483 | |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2484 | static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val) |
| 2485 | { |
| 2486 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_ecn, mask); |
| 2487 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_ecn, val); |
| 2488 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_dscp, mask >> 2); |
| 2489 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_dscp, val >> 2); |
| 2490 | } |
| 2491 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2492 | static int check_mpls_supp_fields(u32 field_support, const __be32 *set_mask) |
| 2493 | { |
| 2494 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_label) && |
| 2495 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_LABEL)) |
| 2496 | return -EOPNOTSUPP; |
| 2497 | |
| 2498 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_exp) && |
| 2499 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_EXP)) |
| 2500 | return -EOPNOTSUPP; |
| 2501 | |
| 2502 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_s_bos) && |
| 2503 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_S_BOS)) |
| 2504 | return -EOPNOTSUPP; |
| 2505 | |
| 2506 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_ttl) && |
| 2507 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_TTL)) |
| 2508 | return -EOPNOTSUPP; |
| 2509 | |
| 2510 | return 0; |
| 2511 | } |
| 2512 | |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2513 | #define LAST_ETH_FIELD vlan_tag |
| 2514 | #define LAST_IB_FIELD sl |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2515 | #define LAST_IPV4_FIELD tos |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2516 | #define LAST_IPV6_FIELD traffic_class |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2517 | #define LAST_TCP_UDP_FIELD src_port |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2518 | #define LAST_TUNNEL_FIELD tunnel_id |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2519 | #define LAST_FLOW_TAG_FIELD tag_id |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2520 | #define LAST_DROP_FIELD size |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2521 | #define LAST_COUNTERS_FIELD counters |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2522 | |
| 2523 | /* Field is the last supported field */ |
| 2524 | #define FIELDS_NOT_SUPPORTED(filter, field)\ |
| 2525 | memchr_inv((void *)&filter.field +\ |
| 2526 | sizeof(filter.field), 0,\ |
| 2527 | sizeof(filter) -\ |
| 2528 | offsetof(typeof(filter), field) -\ |
| 2529 | sizeof(filter.field)) |
| 2530 | |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2531 | int parse_flow_flow_action(struct mlx5_ib_flow_action *maction, |
| 2532 | bool is_egress, |
| 2533 | struct mlx5_flow_act *action) |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2534 | { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2535 | |
| 2536 | switch (maction->ib_action.type) { |
| 2537 | case IB_FLOW_ACTION_ESP: |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2538 | if (action->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 2539 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)) |
| 2540 | return -EINVAL; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2541 | /* Currently only AES_GCM keymat is supported by the driver */ |
| 2542 | action->esp_id = (uintptr_t)maction->esp_aes_gcm.ctx; |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2543 | action->action |= is_egress ? |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2544 | MLX5_FLOW_CONTEXT_ACTION_ENCRYPT : |
| 2545 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT; |
| 2546 | return 0; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2547 | case IB_FLOW_ACTION_UNSPECIFIED: |
| 2548 | if (maction->flow_action_raw.sub_type == |
| 2549 | MLX5_IB_FLOW_ACTION_MODIFY_HEADER) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2550 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) |
| 2551 | return -EINVAL; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2552 | action->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; |
| 2553 | action->modify_id = maction->flow_action_raw.action_id; |
| 2554 | return 0; |
| 2555 | } |
Mark Bloch | 10a3089 | 2018-09-02 12:51:34 +0300 | [diff] [blame] | 2556 | if (maction->flow_action_raw.sub_type == |
| 2557 | MLX5_IB_FLOW_ACTION_DECAP) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2558 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_DECAP) |
| 2559 | return -EINVAL; |
Mark Bloch | 10a3089 | 2018-09-02 12:51:34 +0300 | [diff] [blame] | 2560 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DECAP; |
| 2561 | return 0; |
| 2562 | } |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2563 | if (maction->flow_action_raw.sub_type == |
| 2564 | MLX5_IB_FLOW_ACTION_PACKET_REFORMAT) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2565 | if (action->action & |
| 2566 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT) |
| 2567 | return -EINVAL; |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2568 | action->action |= |
| 2569 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT; |
| 2570 | action->reformat_id = |
| 2571 | maction->flow_action_raw.action_id; |
| 2572 | return 0; |
| 2573 | } |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2574 | /* fall through */ |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2575 | default: |
| 2576 | return -EOPNOTSUPP; |
| 2577 | } |
| 2578 | } |
| 2579 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2580 | static int parse_flow_attr(struct mlx5_core_dev *mdev, u32 *match_c, |
| 2581 | u32 *match_v, const union ib_flow_spec *ib_spec, |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2582 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2583 | struct mlx5_flow_act *action, u32 prev_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2584 | { |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2585 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2586 | misc_parameters); |
| 2587 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2588 | misc_parameters); |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2589 | void *misc_params2_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2590 | misc_parameters_2); |
| 2591 | void *misc_params2_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2592 | misc_parameters_2); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2593 | void *headers_c; |
| 2594 | void *headers_v; |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2595 | int match_ipv; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2596 | int ret; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2597 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2598 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2599 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2600 | inner_headers); |
| 2601 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2602 | inner_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2603 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2604 | ft_field_support.inner_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2605 | } else { |
| 2606 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2607 | outer_headers); |
| 2608 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2609 | outer_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.outer_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2615 | case IB_FLOW_SPEC_ETH: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2616 | if (FIELDS_NOT_SUPPORTED(ib_spec->eth.mask, LAST_ETH_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2617 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2618 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2619 | 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] | 2620 | dmac_47_16), |
| 2621 | ib_spec->eth.mask.dst_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2622 | 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] | 2623 | dmac_47_16), |
| 2624 | ib_spec->eth.val.dst_mac); |
| 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 | ee3da80 | 2016-09-12 19:16:24 +0300 | [diff] [blame] | 2627 | smac_47_16), |
| 2628 | ib_spec->eth.mask.src_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 | ee3da80 | 2016-09-12 19:16:24 +0300 | [diff] [blame] | 2630 | smac_47_16), |
| 2631 | ib_spec->eth.val.src_mac); |
| 2632 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2633 | if (ib_spec->eth.mask.vlan_tag) { |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2634 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2635 | cvlan_tag, 1); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2636 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2637 | cvlan_tag, 1); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2638 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2639 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2640 | first_vid, ntohs(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_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2642 | first_vid, ntohs(ib_spec->eth.val.vlan_tag)); |
| 2643 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2644 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2645 | first_cfi, |
| 2646 | ntohs(ib_spec->eth.mask.vlan_tag) >> 12); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2647 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2648 | first_cfi, |
| 2649 | ntohs(ib_spec->eth.val.vlan_tag) >> 12); |
| 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_prio, |
| 2653 | ntohs(ib_spec->eth.mask.vlan_tag) >> 13); |
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_prio, |
| 2656 | ntohs(ib_spec->eth.val.vlan_tag) >> 13); |
| 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 | ethertype, ntohs(ib_spec->eth.mask.ether_type)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2660 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2661 | ethertype, ntohs(ib_spec->eth.val.ether_type)); |
| 2662 | break; |
| 2663 | case IB_FLOW_SPEC_IPV4: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2664 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv4.mask, LAST_IPV4_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2665 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2666 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2667 | if (match_ipv) { |
| 2668 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2669 | ip_version, 0xf); |
| 2670 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2671 | ip_version, MLX5_FS_IPV4_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2672 | } else { |
| 2673 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2674 | ethertype, 0xffff); |
| 2675 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2676 | ethertype, ETH_P_IP); |
| 2677 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2678 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2679 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2680 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2681 | &ib_spec->ipv4.mask.src_ip, |
| 2682 | sizeof(ib_spec->ipv4.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2683 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2684 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2685 | &ib_spec->ipv4.val.src_ip, |
| 2686 | sizeof(ib_spec->ipv4.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2687 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2688 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2689 | &ib_spec->ipv4.mask.dst_ip, |
| 2690 | sizeof(ib_spec->ipv4.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2691 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2692 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2693 | &ib_spec->ipv4.val.dst_ip, |
| 2694 | sizeof(ib_spec->ipv4.val.dst_ip)); |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2695 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2696 | set_tos(headers_c, headers_v, |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2697 | ib_spec->ipv4.mask.tos, ib_spec->ipv4.val.tos); |
| 2698 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2699 | if (set_proto(headers_c, headers_v, |
| 2700 | ib_spec->ipv4.mask.proto, |
| 2701 | ib_spec->ipv4.val.proto)) |
| 2702 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2703 | break; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2704 | case IB_FLOW_SPEC_IPV6: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2705 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv6.mask, LAST_IPV6_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2706 | return -EOPNOTSUPP; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2707 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2708 | if (match_ipv) { |
| 2709 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2710 | ip_version, 0xf); |
| 2711 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2712 | ip_version, MLX5_FS_IPV6_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2713 | } else { |
| 2714 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2715 | ethertype, 0xffff); |
| 2716 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2717 | ethertype, ETH_P_IPV6); |
| 2718 | } |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2719 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2720 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2721 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2722 | &ib_spec->ipv6.mask.src_ip, |
| 2723 | sizeof(ib_spec->ipv6.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2724 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2725 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2726 | &ib_spec->ipv6.val.src_ip, |
| 2727 | sizeof(ib_spec->ipv6.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2728 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2729 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2730 | &ib_spec->ipv6.mask.dst_ip, |
| 2731 | sizeof(ib_spec->ipv6.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2732 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2733 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2734 | &ib_spec->ipv6.val.dst_ip, |
| 2735 | sizeof(ib_spec->ipv6.val.dst_ip)); |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2736 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2737 | set_tos(headers_c, headers_v, |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2738 | ib_spec->ipv6.mask.traffic_class, |
| 2739 | ib_spec->ipv6.val.traffic_class); |
| 2740 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2741 | if (set_proto(headers_c, headers_v, |
| 2742 | ib_spec->ipv6.mask.next_hdr, |
| 2743 | ib_spec->ipv6.val.next_hdr)) |
| 2744 | return -EINVAL; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2745 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2746 | set_flow_label(misc_params_c, misc_params_v, |
| 2747 | ntohl(ib_spec->ipv6.mask.flow_label), |
| 2748 | ntohl(ib_spec->ipv6.val.flow_label), |
| 2749 | ib_spec->type & IB_FLOW_SPEC_INNER); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2750 | break; |
| 2751 | case IB_FLOW_SPEC_ESP: |
| 2752 | if (ib_spec->esp.mask.seq) |
| 2753 | return -EOPNOTSUPP; |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2754 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2755 | MLX5_SET(fte_match_set_misc, misc_params_c, outer_esp_spi, |
| 2756 | ntohl(ib_spec->esp.mask.spi)); |
| 2757 | MLX5_SET(fte_match_set_misc, misc_params_v, outer_esp_spi, |
| 2758 | ntohl(ib_spec->esp.val.spi)); |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2759 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2760 | case IB_FLOW_SPEC_TCP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2761 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2762 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2763 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2764 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2765 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_TCP)) |
| 2766 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2767 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2768 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2769 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2770 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2771 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2772 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2773 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2774 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2775 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2776 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2777 | break; |
| 2778 | case IB_FLOW_SPEC_UDP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2779 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2780 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2781 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2782 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2783 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_UDP)) |
| 2784 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2785 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2786 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2787 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2788 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2789 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2790 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2791 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2792 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2793 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2794 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2795 | break; |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2796 | case IB_FLOW_SPEC_GRE: |
| 2797 | if (ib_spec->gre.mask.c_ks_res0_ver) |
| 2798 | return -EOPNOTSUPP; |
| 2799 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2800 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_GRE)) |
| 2801 | return -EINVAL; |
| 2802 | |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2803 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
| 2804 | 0xff); |
| 2805 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
| 2806 | IPPROTO_GRE); |
| 2807 | |
| 2808 | MLX5_SET(fte_match_set_misc, misc_params_c, gre_protocol, |
Maor Gottlieb | a93b632 | 2018-07-01 15:50:17 +0300 | [diff] [blame] | 2809 | ntohs(ib_spec->gre.mask.protocol)); |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2810 | MLX5_SET(fte_match_set_misc, misc_params_v, gre_protocol, |
| 2811 | ntohs(ib_spec->gre.val.protocol)); |
| 2812 | |
| 2813 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_c, |
Oz Shlomo | 5886a96 | 2018-12-10 13:15:13 -0800 | [diff] [blame] | 2814 | gre_key.nvgre.hi), |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2815 | &ib_spec->gre.mask.key, |
| 2816 | sizeof(ib_spec->gre.mask.key)); |
| 2817 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_v, |
Oz Shlomo | 5886a96 | 2018-12-10 13:15:13 -0800 | [diff] [blame] | 2818 | gre_key.nvgre.hi), |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2819 | &ib_spec->gre.val.key, |
| 2820 | sizeof(ib_spec->gre.val.key)); |
| 2821 | break; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2822 | case IB_FLOW_SPEC_MPLS: |
| 2823 | switch (prev_type) { |
| 2824 | case IB_FLOW_SPEC_UDP: |
| 2825 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2826 | ft_field_support.outer_first_mpls_over_udp), |
| 2827 | &ib_spec->mpls.mask.tag)) |
| 2828 | return -EOPNOTSUPP; |
| 2829 | |
| 2830 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2831 | outer_first_mpls_over_udp), |
| 2832 | &ib_spec->mpls.val.tag, |
| 2833 | sizeof(ib_spec->mpls.val.tag)); |
| 2834 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2835 | outer_first_mpls_over_udp), |
| 2836 | &ib_spec->mpls.mask.tag, |
| 2837 | sizeof(ib_spec->mpls.mask.tag)); |
| 2838 | break; |
| 2839 | case IB_FLOW_SPEC_GRE: |
| 2840 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2841 | ft_field_support.outer_first_mpls_over_gre), |
| 2842 | &ib_spec->mpls.mask.tag)) |
| 2843 | return -EOPNOTSUPP; |
| 2844 | |
| 2845 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2846 | outer_first_mpls_over_gre), |
| 2847 | &ib_spec->mpls.val.tag, |
| 2848 | sizeof(ib_spec->mpls.val.tag)); |
| 2849 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2850 | outer_first_mpls_over_gre), |
| 2851 | &ib_spec->mpls.mask.tag, |
| 2852 | sizeof(ib_spec->mpls.mask.tag)); |
| 2853 | break; |
| 2854 | default: |
| 2855 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2856 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2857 | ft_field_support.inner_first_mpls), |
| 2858 | &ib_spec->mpls.mask.tag)) |
| 2859 | return -EOPNOTSUPP; |
| 2860 | |
| 2861 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2862 | inner_first_mpls), |
| 2863 | &ib_spec->mpls.val.tag, |
| 2864 | sizeof(ib_spec->mpls.val.tag)); |
| 2865 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2866 | inner_first_mpls), |
| 2867 | &ib_spec->mpls.mask.tag, |
| 2868 | sizeof(ib_spec->mpls.mask.tag)); |
| 2869 | } else { |
| 2870 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2871 | ft_field_support.outer_first_mpls), |
| 2872 | &ib_spec->mpls.mask.tag)) |
| 2873 | return -EOPNOTSUPP; |
| 2874 | |
| 2875 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2876 | outer_first_mpls), |
| 2877 | &ib_spec->mpls.val.tag, |
| 2878 | sizeof(ib_spec->mpls.val.tag)); |
| 2879 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2880 | outer_first_mpls), |
| 2881 | &ib_spec->mpls.mask.tag, |
| 2882 | sizeof(ib_spec->mpls.mask.tag)); |
| 2883 | } |
| 2884 | } |
| 2885 | break; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2886 | case IB_FLOW_SPEC_VXLAN_TUNNEL: |
| 2887 | if (FIELDS_NOT_SUPPORTED(ib_spec->tunnel.mask, |
| 2888 | LAST_TUNNEL_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2889 | return -EOPNOTSUPP; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2890 | |
| 2891 | MLX5_SET(fte_match_set_misc, misc_params_c, vxlan_vni, |
| 2892 | ntohl(ib_spec->tunnel.mask.tunnel_id)); |
| 2893 | MLX5_SET(fte_match_set_misc, misc_params_v, vxlan_vni, |
| 2894 | ntohl(ib_spec->tunnel.val.tunnel_id)); |
| 2895 | break; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2896 | case IB_FLOW_SPEC_ACTION_TAG: |
| 2897 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_tag, |
| 2898 | LAST_FLOW_TAG_FIELD)) |
| 2899 | return -EOPNOTSUPP; |
| 2900 | if (ib_spec->flow_tag.tag_id >= BIT(24)) |
| 2901 | return -EINVAL; |
| 2902 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 2903 | action->flow_tag = ib_spec->flow_tag.tag_id; |
Paul Blakey | d5634fe | 2018-09-20 12:17:48 +0200 | [diff] [blame] | 2904 | action->flags |= FLOW_ACT_HAS_TAG; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2905 | break; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2906 | case IB_FLOW_SPEC_ACTION_DROP: |
| 2907 | if (FIELDS_NOT_SUPPORTED(ib_spec->drop, |
| 2908 | LAST_DROP_FIELD)) |
| 2909 | return -EOPNOTSUPP; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 2910 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DROP; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2911 | break; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2912 | case IB_FLOW_SPEC_ACTION_HANDLE: |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2913 | ret = parse_flow_flow_action(to_mflow_act(ib_spec->action.act), |
| 2914 | flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS, action); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2915 | if (ret) |
| 2916 | return ret; |
| 2917 | break; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2918 | case IB_FLOW_SPEC_ACTION_COUNT: |
| 2919 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_count, |
| 2920 | LAST_COUNTERS_FIELD)) |
| 2921 | return -EOPNOTSUPP; |
| 2922 | |
| 2923 | /* for now support only one counters spec per flow */ |
| 2924 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) |
| 2925 | return -EINVAL; |
| 2926 | |
| 2927 | action->counters = ib_spec->flow_count.counters; |
| 2928 | action->action |= MLX5_FLOW_CONTEXT_ACTION_COUNT; |
| 2929 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2930 | default: |
| 2931 | return -EINVAL; |
| 2932 | } |
| 2933 | |
| 2934 | return 0; |
| 2935 | } |
| 2936 | |
| 2937 | /* If a flow could catch both multicast and unicast packets, |
| 2938 | * it won't fall into the multicast flow steering table and this rule |
| 2939 | * could steal other multicast packets. |
| 2940 | */ |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 2941 | 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] | 2942 | { |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2943 | union ib_flow_spec *flow_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2944 | |
| 2945 | if (ib_attr->type != IB_FLOW_ATTR_NORMAL || |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2946 | ib_attr->num_of_specs < 1) |
| 2947 | return false; |
| 2948 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2949 | flow_spec = (union ib_flow_spec *)(ib_attr + 1); |
| 2950 | if (flow_spec->type == IB_FLOW_SPEC_IPV4) { |
| 2951 | struct ib_flow_spec_ipv4 *ipv4_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2952 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2953 | ipv4_spec = (struct ib_flow_spec_ipv4 *)flow_spec; |
| 2954 | if (ipv4_is_multicast(ipv4_spec->val.dst_ip)) |
| 2955 | return true; |
| 2956 | |
| 2957 | return false; |
| 2958 | } |
| 2959 | |
| 2960 | if (flow_spec->type == IB_FLOW_SPEC_ETH) { |
| 2961 | struct ib_flow_spec_eth *eth_spec; |
| 2962 | |
| 2963 | eth_spec = (struct ib_flow_spec_eth *)flow_spec; |
| 2964 | return is_multicast_ether_addr(eth_spec->mask.dst_mac) && |
| 2965 | is_multicast_ether_addr(eth_spec->val.dst_mac); |
| 2966 | } |
| 2967 | |
| 2968 | return false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2969 | } |
| 2970 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2971 | enum valid_spec { |
| 2972 | VALID_SPEC_INVALID, |
| 2973 | VALID_SPEC_VALID, |
| 2974 | VALID_SPEC_NA, |
| 2975 | }; |
| 2976 | |
| 2977 | static enum valid_spec |
| 2978 | is_valid_esp_aes_gcm(struct mlx5_core_dev *mdev, |
| 2979 | const struct mlx5_flow_spec *spec, |
| 2980 | const struct mlx5_flow_act *flow_act, |
| 2981 | bool egress) |
| 2982 | { |
| 2983 | const u32 *match_c = spec->match_criteria; |
| 2984 | bool is_crypto = |
| 2985 | (flow_act->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 2986 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)); |
| 2987 | bool is_ipsec = mlx5_fs_is_ipsec_flow(match_c); |
| 2988 | bool is_drop = flow_act->action & MLX5_FLOW_CONTEXT_ACTION_DROP; |
| 2989 | |
| 2990 | /* |
| 2991 | * Currently only crypto is supported in egress, when regular egress |
| 2992 | * rules would be supported, always return VALID_SPEC_NA. |
| 2993 | */ |
| 2994 | if (!is_crypto) |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 2995 | return VALID_SPEC_NA; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2996 | |
| 2997 | return is_crypto && is_ipsec && |
Paul Blakey | d5634fe | 2018-09-20 12:17:48 +0200 | [diff] [blame] | 2998 | (!egress || (!is_drop && !(flow_act->flags & FLOW_ACT_HAS_TAG))) ? |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2999 | VALID_SPEC_VALID : VALID_SPEC_INVALID; |
| 3000 | } |
| 3001 | |
| 3002 | static bool is_valid_spec(struct mlx5_core_dev *mdev, |
| 3003 | const struct mlx5_flow_spec *spec, |
| 3004 | const struct mlx5_flow_act *flow_act, |
| 3005 | bool egress) |
| 3006 | { |
| 3007 | /* We curretly only support ipsec egress flow */ |
| 3008 | return is_valid_esp_aes_gcm(mdev, spec, flow_act, egress) != VALID_SPEC_INVALID; |
| 3009 | } |
| 3010 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3011 | static bool is_valid_ethertype(struct mlx5_core_dev *mdev, |
| 3012 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3013 | bool check_inner) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3014 | { |
| 3015 | 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] | 3016 | int match_ipv = check_inner ? |
| 3017 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 3018 | ft_field_support.inner_ip_version) : |
| 3019 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 3020 | ft_field_support.outer_ip_version); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3021 | int inner_bit = check_inner ? IB_FLOW_SPEC_INNER : 0; |
| 3022 | bool ipv4_spec_valid, ipv6_spec_valid; |
| 3023 | unsigned int ip_spec_type = 0; |
| 3024 | bool has_ethertype = false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3025 | unsigned int spec_index; |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3026 | bool mask_valid = true; |
| 3027 | u16 eth_type = 0; |
| 3028 | bool type_valid; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3029 | |
| 3030 | /* Validate that ethertype is correct */ |
| 3031 | 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] | 3032 | if ((ib_spec->type == (IB_FLOW_SPEC_ETH | inner_bit)) && |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3033 | ib_spec->eth.mask.ether_type) { |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3034 | mask_valid = (ib_spec->eth.mask.ether_type == |
| 3035 | htons(0xffff)); |
| 3036 | has_ethertype = true; |
| 3037 | eth_type = ntohs(ib_spec->eth.val.ether_type); |
| 3038 | } else if ((ib_spec->type == (IB_FLOW_SPEC_IPV4 | inner_bit)) || |
| 3039 | (ib_spec->type == (IB_FLOW_SPEC_IPV6 | inner_bit))) { |
| 3040 | ip_spec_type = ib_spec->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3041 | } |
| 3042 | ib_spec = (void *)ib_spec + ib_spec->size; |
| 3043 | } |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3044 | |
| 3045 | type_valid = (!has_ethertype) || (!ip_spec_type); |
| 3046 | if (!type_valid && mask_valid) { |
| 3047 | ipv4_spec_valid = (eth_type == ETH_P_IP) && |
| 3048 | (ip_spec_type == (IB_FLOW_SPEC_IPV4 | inner_bit)); |
| 3049 | ipv6_spec_valid = (eth_type == ETH_P_IPV6) && |
| 3050 | (ip_spec_type == (IB_FLOW_SPEC_IPV6 | inner_bit)); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3051 | |
| 3052 | type_valid = (ipv4_spec_valid) || (ipv6_spec_valid) || |
| 3053 | (((eth_type == ETH_P_MPLS_UC) || |
| 3054 | (eth_type == ETH_P_MPLS_MC)) && match_ipv); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | return type_valid; |
| 3058 | } |
| 3059 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3060 | static bool is_valid_attr(struct mlx5_core_dev *mdev, |
| 3061 | const struct ib_flow_attr *flow_attr) |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3062 | { |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3063 | return is_valid_ethertype(mdev, flow_attr, false) && |
| 3064 | is_valid_ethertype(mdev, flow_attr, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | static void put_flow_table(struct mlx5_ib_dev *dev, |
| 3068 | struct mlx5_ib_flow_prio *prio, bool ft_added) |
| 3069 | { |
| 3070 | prio->refcount -= !!ft_added; |
| 3071 | if (!prio->refcount) { |
| 3072 | mlx5_destroy_flow_table(prio->flow_table); |
| 3073 | prio->flow_table = NULL; |
| 3074 | } |
| 3075 | } |
| 3076 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3077 | static void counters_clear_description(struct ib_counters *counters) |
| 3078 | { |
| 3079 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3080 | |
| 3081 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3082 | kfree(mcounters->counters_data); |
| 3083 | mcounters->counters_data = NULL; |
| 3084 | mcounters->cntrs_max_index = 0; |
| 3085 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3086 | } |
| 3087 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3088 | static int mlx5_ib_destroy_flow(struct ib_flow *flow_id) |
| 3089 | { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3090 | struct mlx5_ib_flow_handler *handler = container_of(flow_id, |
| 3091 | struct mlx5_ib_flow_handler, |
| 3092 | ibflow); |
| 3093 | struct mlx5_ib_flow_handler *iter, *tmp; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3094 | struct mlx5_ib_dev *dev = handler->dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3095 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3096 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3097 | |
| 3098 | list_for_each_entry_safe(iter, tmp, &handler->list, list) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3099 | mlx5_del_flow_rules(iter->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3100 | put_flow_table(dev, iter->prio, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3101 | list_del(&iter->list); |
| 3102 | kfree(iter); |
| 3103 | } |
| 3104 | |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3105 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3106 | put_flow_table(dev, handler->prio, true); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3107 | if (handler->ibcounters && |
| 3108 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3109 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3110 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3111 | mutex_unlock(&dev->flow_db->lock); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3112 | if (handler->flow_matcher) |
| 3113 | atomic_dec(&handler->flow_matcher->usecnt); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3114 | kfree(handler); |
| 3115 | |
| 3116 | return 0; |
| 3117 | } |
| 3118 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3119 | static int ib_prio_to_core_prio(unsigned int priority, bool dont_trap) |
| 3120 | { |
| 3121 | priority *= 2; |
| 3122 | if (!dont_trap) |
| 3123 | priority++; |
| 3124 | return priority; |
| 3125 | } |
| 3126 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3127 | enum flow_table_type { |
| 3128 | MLX5_IB_FT_RX, |
| 3129 | MLX5_IB_FT_TX |
| 3130 | }; |
| 3131 | |
Maor Gottlieb | 00b7c2a | 2017-03-29 06:09:01 +0300 | [diff] [blame] | 3132 | #define MLX5_FS_MAX_TYPES 6 |
| 3133 | #define MLX5_FS_MAX_ENTRIES BIT(16) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3134 | |
| 3135 | static struct mlx5_ib_flow_prio *_get_prio(struct mlx5_flow_namespace *ns, |
| 3136 | struct mlx5_ib_flow_prio *prio, |
| 3137 | int priority, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3138 | int num_entries, int num_groups, |
| 3139 | u32 flags) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3140 | { |
| 3141 | struct mlx5_flow_table *ft; |
| 3142 | |
| 3143 | ft = mlx5_create_auto_grouped_flow_table(ns, priority, |
| 3144 | num_entries, |
| 3145 | num_groups, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3146 | 0, flags); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3147 | if (IS_ERR(ft)) |
| 3148 | return ERR_CAST(ft); |
| 3149 | |
| 3150 | prio->flow_table = ft; |
| 3151 | prio->refcount = 0; |
| 3152 | return prio; |
| 3153 | } |
| 3154 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3155 | 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] | 3156 | struct ib_flow_attr *flow_attr, |
| 3157 | enum flow_table_type ft_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3158 | { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3159 | bool dont_trap = flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3160 | struct mlx5_flow_namespace *ns = NULL; |
| 3161 | struct mlx5_ib_flow_prio *prio; |
| 3162 | struct mlx5_flow_table *ft; |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3163 | int max_table_size; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3164 | int num_entries; |
| 3165 | int num_groups; |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3166 | u32 flags = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3167 | int priority; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3168 | |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3169 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3170 | log_max_ft_size)); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3171 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3172 | enum mlx5_flow_namespace_type fn_type; |
| 3173 | |
| 3174 | if (flow_is_multicast_only(flow_attr) && |
| 3175 | !dont_trap) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3176 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3177 | else |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3178 | priority = ib_prio_to_core_prio(flow_attr->priority, |
| 3179 | dont_trap); |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3180 | if (ft_type == MLX5_IB_FT_RX) { |
| 3181 | fn_type = MLX5_FLOW_NAMESPACE_BYPASS; |
| 3182 | prio = &dev->flow_db->prios[priority]; |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3183 | if (!dev->is_rep && |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3184 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, decap)) |
| 3185 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3186 | if (!dev->is_rep && |
Mark Bloch | 5c2db53 | 2018-09-02 12:51:35 +0300 | [diff] [blame] | 3187 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3188 | reformat_l3_tunnel_to_l2)) |
| 3189 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3190 | } else { |
| 3191 | max_table_size = |
| 3192 | BIT(MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, |
| 3193 | log_max_ft_size)); |
| 3194 | fn_type = MLX5_FLOW_NAMESPACE_EGRESS; |
| 3195 | prio = &dev->flow_db->egress_prios[priority]; |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3196 | if (!dev->is_rep && |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3197 | MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, reformat)) |
| 3198 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3199 | } |
| 3200 | ns = mlx5_get_flow_namespace(dev->mdev, fn_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3201 | num_entries = MLX5_FS_MAX_ENTRIES; |
| 3202 | num_groups = MLX5_FS_MAX_TYPES; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3203 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3204 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3205 | ns = mlx5_get_flow_namespace(dev->mdev, |
| 3206 | MLX5_FLOW_NAMESPACE_LEFTOVERS); |
| 3207 | build_leftovers_ft_param(&priority, |
| 3208 | &num_entries, |
| 3209 | &num_groups); |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3210 | prio = &dev->flow_db->prios[MLX5_IB_FLOW_LEFTOVERS_PRIO]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3211 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3212 | if (!MLX5_CAP_FLOWTABLE(dev->mdev, |
| 3213 | allow_sniffer_and_nic_rx_shared_tir)) |
| 3214 | return ERR_PTR(-ENOTSUPP); |
| 3215 | |
| 3216 | ns = mlx5_get_flow_namespace(dev->mdev, ft_type == MLX5_IB_FT_RX ? |
| 3217 | MLX5_FLOW_NAMESPACE_SNIFFER_RX : |
| 3218 | MLX5_FLOW_NAMESPACE_SNIFFER_TX); |
| 3219 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3220 | prio = &dev->flow_db->sniffer[ft_type]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3221 | priority = 0; |
| 3222 | num_entries = 1; |
| 3223 | num_groups = 1; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | if (!ns) |
| 3227 | return ERR_PTR(-ENOTSUPP); |
| 3228 | |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3229 | if (num_entries > max_table_size) |
| 3230 | return ERR_PTR(-ENOMEM); |
| 3231 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3232 | ft = prio->flow_table; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3233 | if (!ft) |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3234 | return _get_prio(ns, prio, priority, num_entries, num_groups, |
| 3235 | flags); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3236 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3237 | return prio; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3238 | } |
| 3239 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3240 | static void set_underlay_qp(struct mlx5_ib_dev *dev, |
| 3241 | struct mlx5_flow_spec *spec, |
| 3242 | u32 underlay_qpn) |
| 3243 | { |
| 3244 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, |
| 3245 | spec->match_criteria, |
| 3246 | misc_parameters); |
| 3247 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3248 | misc_parameters); |
| 3249 | |
| 3250 | if (underlay_qpn && |
| 3251 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3252 | ft_field_support.bth_dst_qp)) { |
| 3253 | MLX5_SET(fte_match_set_misc, |
| 3254 | misc_params_v, bth_dst_qp, underlay_qpn); |
| 3255 | MLX5_SET(fte_match_set_misc, |
| 3256 | misc_params_c, bth_dst_qp, 0xffffff); |
| 3257 | } |
| 3258 | } |
| 3259 | |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3260 | static int read_flow_counters(struct ib_device *ibdev, |
| 3261 | struct mlx5_read_counters_attr *read_attr) |
| 3262 | { |
| 3263 | struct mlx5_fc *fc = read_attr->hw_cntrs_hndl; |
| 3264 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 3265 | |
| 3266 | return mlx5_fc_query(dev->mdev, fc, |
| 3267 | &read_attr->out[IB_COUNTER_PACKETS], |
| 3268 | &read_attr->out[IB_COUNTER_BYTES]); |
| 3269 | } |
| 3270 | |
| 3271 | /* flow counters currently expose two counters packets and bytes */ |
| 3272 | #define FLOW_COUNTERS_NUM 2 |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3273 | static int counters_set_description(struct ib_counters *counters, |
| 3274 | enum mlx5_ib_counters_type counters_type, |
| 3275 | struct mlx5_ib_flow_counters_desc *desc_data, |
| 3276 | u32 ncounters) |
| 3277 | { |
| 3278 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3279 | u32 cntrs_max_index = 0; |
| 3280 | int i; |
| 3281 | |
| 3282 | if (counters_type != MLX5_IB_COUNTERS_FLOW) |
| 3283 | return -EINVAL; |
| 3284 | |
| 3285 | /* init the fields for the object */ |
| 3286 | mcounters->type = counters_type; |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3287 | mcounters->read_counters = read_flow_counters; |
| 3288 | mcounters->counters_num = FLOW_COUNTERS_NUM; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3289 | mcounters->ncounters = ncounters; |
| 3290 | /* each counter entry have both description and index pair */ |
| 3291 | for (i = 0; i < ncounters; i++) { |
| 3292 | if (desc_data[i].description > IB_COUNTER_BYTES) |
| 3293 | return -EINVAL; |
| 3294 | |
| 3295 | if (cntrs_max_index <= desc_data[i].index) |
| 3296 | cntrs_max_index = desc_data[i].index + 1; |
| 3297 | } |
| 3298 | |
| 3299 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3300 | mcounters->counters_data = desc_data; |
| 3301 | mcounters->cntrs_max_index = cntrs_max_index; |
| 3302 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3303 | |
| 3304 | return 0; |
| 3305 | } |
| 3306 | |
| 3307 | #define MAX_COUNTERS_NUM (USHRT_MAX / (sizeof(u32) * 2)) |
| 3308 | static int flow_counters_set_data(struct ib_counters *ibcounters, |
| 3309 | struct mlx5_ib_create_flow *ucmd) |
| 3310 | { |
| 3311 | struct mlx5_ib_mcounters *mcounters = to_mcounters(ibcounters); |
| 3312 | struct mlx5_ib_flow_counters_data *cntrs_data = NULL; |
| 3313 | struct mlx5_ib_flow_counters_desc *desc_data = NULL; |
| 3314 | bool hw_hndl = false; |
| 3315 | int ret = 0; |
| 3316 | |
| 3317 | if (ucmd && ucmd->ncounters_data != 0) { |
| 3318 | cntrs_data = ucmd->data; |
| 3319 | if (cntrs_data->ncounters > MAX_COUNTERS_NUM) |
| 3320 | return -EINVAL; |
| 3321 | |
| 3322 | desc_data = kcalloc(cntrs_data->ncounters, |
| 3323 | sizeof(*desc_data), |
| 3324 | GFP_KERNEL); |
| 3325 | if (!desc_data) |
| 3326 | return -ENOMEM; |
| 3327 | |
| 3328 | if (copy_from_user(desc_data, |
| 3329 | u64_to_user_ptr(cntrs_data->counters_data), |
| 3330 | sizeof(*desc_data) * cntrs_data->ncounters)) { |
| 3331 | ret = -EFAULT; |
| 3332 | goto free; |
| 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | if (!mcounters->hw_cntrs_hndl) { |
| 3337 | mcounters->hw_cntrs_hndl = mlx5_fc_create( |
| 3338 | to_mdev(ibcounters->device)->mdev, false); |
weiyongjun (A) | e31abf7 | 2018-06-07 01:47:41 +0000 | [diff] [blame] | 3339 | if (IS_ERR(mcounters->hw_cntrs_hndl)) { |
| 3340 | ret = PTR_ERR(mcounters->hw_cntrs_hndl); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3341 | goto free; |
| 3342 | } |
| 3343 | hw_hndl = true; |
| 3344 | } |
| 3345 | |
| 3346 | if (desc_data) { |
| 3347 | /* counters already bound to at least one flow */ |
| 3348 | if (mcounters->cntrs_max_index) { |
| 3349 | ret = -EINVAL; |
| 3350 | goto free_hndl; |
| 3351 | } |
| 3352 | |
| 3353 | ret = counters_set_description(ibcounters, |
| 3354 | MLX5_IB_COUNTERS_FLOW, |
| 3355 | desc_data, |
| 3356 | cntrs_data->ncounters); |
| 3357 | if (ret) |
| 3358 | goto free_hndl; |
| 3359 | |
| 3360 | } else if (!mcounters->cntrs_max_index) { |
| 3361 | /* counters not bound yet, must have udata passed */ |
| 3362 | ret = -EINVAL; |
| 3363 | goto free_hndl; |
| 3364 | } |
| 3365 | |
| 3366 | return 0; |
| 3367 | |
| 3368 | free_hndl: |
| 3369 | if (hw_hndl) { |
| 3370 | mlx5_fc_destroy(to_mdev(ibcounters->device)->mdev, |
| 3371 | mcounters->hw_cntrs_hndl); |
| 3372 | mcounters->hw_cntrs_hndl = NULL; |
| 3373 | } |
| 3374 | free: |
| 3375 | kfree(desc_data); |
| 3376 | return ret; |
| 3377 | } |
| 3378 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3379 | static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev, |
| 3380 | struct mlx5_ib_flow_prio *ft_prio, |
| 3381 | const struct ib_flow_attr *flow_attr, |
| 3382 | struct mlx5_flow_destination *dst, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3383 | u32 underlay_qpn, |
| 3384 | struct mlx5_ib_create_flow *ucmd) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3385 | { |
| 3386 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3387 | struct mlx5_ib_flow_handler *handler; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3388 | 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] | 3389 | struct mlx5_flow_spec *spec; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3390 | struct mlx5_flow_destination dest_arr[2] = {}; |
| 3391 | struct mlx5_flow_destination *rule_dst = dest_arr; |
Maor Gottlieb | dd063d0 | 2016-08-28 14:16:32 +0300 | [diff] [blame] | 3392 | const void *ib_flow = (const void *)flow_attr + sizeof(*flow_attr); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3393 | unsigned int spec_index; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3394 | u32 prev_type = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3395 | int err = 0; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3396 | int dest_num = 0; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3397 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3398 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3399 | if (!is_valid_attr(dev->mdev, flow_attr)) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3400 | return ERR_PTR(-EINVAL); |
| 3401 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3402 | if (dev->is_rep && is_egress) |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3403 | return ERR_PTR(-EINVAL); |
| 3404 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3405 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3406 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3407 | if (!handler || !spec) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3408 | err = -ENOMEM; |
| 3409 | goto free; |
| 3410 | } |
| 3411 | |
| 3412 | INIT_LIST_HEAD(&handler->list); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3413 | if (dst) { |
| 3414 | memcpy(&dest_arr[0], dst, sizeof(*dst)); |
| 3415 | dest_num++; |
| 3416 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3417 | |
| 3418 | 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] | 3419 | err = parse_flow_attr(dev->mdev, spec->match_criteria, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3420 | spec->match_value, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3421 | ib_flow, flow_attr, &flow_act, |
| 3422 | prev_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3423 | if (err < 0) |
| 3424 | goto free; |
| 3425 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3426 | prev_type = ((union ib_flow_spec *)ib_flow)->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3427 | ib_flow += ((union ib_flow_spec *)ib_flow)->size; |
| 3428 | } |
| 3429 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3430 | if (!flow_is_multicast_only(flow_attr)) |
| 3431 | set_underlay_qp(dev, spec, underlay_qpn); |
| 3432 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3433 | if (dev->is_rep) { |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3434 | void *misc; |
| 3435 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3436 | if (!dev->port[flow_attr->port - 1].rep) { |
| 3437 | err = -EINVAL; |
| 3438 | goto free; |
| 3439 | } |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3440 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3441 | misc_parameters); |
| 3442 | MLX5_SET(fte_match_set_misc, misc, source_port, |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3443 | dev->port[flow_attr->port - 1].rep->vport); |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3444 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
| 3445 | misc_parameters); |
| 3446 | MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port); |
| 3447 | } |
| 3448 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 3449 | spec->match_criteria_enable = get_match_criteria_enable(spec->match_criteria); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3450 | |
| 3451 | if (is_egress && |
| 3452 | !is_valid_spec(dev->mdev, spec, &flow_act, is_egress)) { |
| 3453 | err = -EINVAL; |
| 3454 | goto free; |
| 3455 | } |
| 3456 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3457 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3458 | struct mlx5_ib_mcounters *mcounters; |
| 3459 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3460 | err = flow_counters_set_data(flow_act.counters, ucmd); |
| 3461 | if (err) |
| 3462 | goto free; |
| 3463 | |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3464 | mcounters = to_mcounters(flow_act.counters); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3465 | handler->ibcounters = flow_act.counters; |
| 3466 | dest_arr[dest_num].type = |
| 3467 | MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3468 | dest_arr[dest_num].counter_id = |
| 3469 | mlx5_fc_id(mcounters->hw_cntrs_hndl); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3470 | dest_num++; |
| 3471 | } |
| 3472 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3473 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DROP) { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3474 | if (!(flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT)) { |
| 3475 | rule_dst = NULL; |
| 3476 | dest_num = 0; |
| 3477 | } |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3478 | } else { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3479 | if (is_egress) |
| 3480 | flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
| 3481 | else |
| 3482 | flow_act.action |= |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3483 | dest_num ? MLX5_FLOW_CONTEXT_ACTION_FWD_DEST : |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3484 | MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3485 | } |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3486 | |
Paul Blakey | d5634fe | 2018-09-20 12:17:48 +0200 | [diff] [blame] | 3487 | if ((flow_act.flags & FLOW_ACT_HAS_TAG) && |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3488 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3489 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3490 | 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] | 3491 | flow_act.flow_tag, flow_attr->type); |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3492 | err = -EINVAL; |
| 3493 | goto free; |
| 3494 | } |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3495 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Hadar Hen Zion | 66958ed | 2016-11-07 15:14:45 +0200 | [diff] [blame] | 3496 | &flow_act, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3497 | rule_dst, dest_num); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3498 | |
| 3499 | if (IS_ERR(handler->rule)) { |
| 3500 | err = PTR_ERR(handler->rule); |
| 3501 | goto free; |
| 3502 | } |
| 3503 | |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3504 | ft_prio->refcount++; |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3505 | handler->prio = ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3506 | handler->dev = dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3507 | |
| 3508 | ft_prio->flow_table = ft; |
| 3509 | free: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3510 | if (err && handler) { |
| 3511 | if (handler->ibcounters && |
| 3512 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3513 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3514 | kfree(handler); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3515 | } |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3516 | kvfree(spec); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3517 | return err ? ERR_PTR(err) : handler; |
| 3518 | } |
| 3519 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3520 | static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev, |
| 3521 | struct mlx5_ib_flow_prio *ft_prio, |
| 3522 | const struct ib_flow_attr *flow_attr, |
| 3523 | struct mlx5_flow_destination *dst) |
| 3524 | { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3525 | return _create_flow_rule(dev, ft_prio, flow_attr, dst, 0, NULL); |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3526 | } |
| 3527 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3528 | static struct mlx5_ib_flow_handler *create_dont_trap_rule(struct mlx5_ib_dev *dev, |
| 3529 | struct mlx5_ib_flow_prio *ft_prio, |
| 3530 | struct ib_flow_attr *flow_attr, |
| 3531 | struct mlx5_flow_destination *dst) |
| 3532 | { |
| 3533 | struct mlx5_ib_flow_handler *handler_dst = NULL; |
| 3534 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3535 | |
| 3536 | handler = create_flow_rule(dev, ft_prio, flow_attr, NULL); |
| 3537 | if (!IS_ERR(handler)) { |
| 3538 | handler_dst = create_flow_rule(dev, ft_prio, |
| 3539 | flow_attr, dst); |
| 3540 | if (IS_ERR(handler_dst)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3541 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3542 | ft_prio->refcount--; |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3543 | kfree(handler); |
| 3544 | handler = handler_dst; |
| 3545 | } else { |
| 3546 | list_add(&handler_dst->list, &handler->list); |
| 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | return handler; |
| 3551 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3552 | enum { |
| 3553 | LEFTOVERS_MC, |
| 3554 | LEFTOVERS_UC, |
| 3555 | }; |
| 3556 | |
| 3557 | static struct mlx5_ib_flow_handler *create_leftovers_rule(struct mlx5_ib_dev *dev, |
| 3558 | struct mlx5_ib_flow_prio *ft_prio, |
| 3559 | struct ib_flow_attr *flow_attr, |
| 3560 | struct mlx5_flow_destination *dst) |
| 3561 | { |
| 3562 | struct mlx5_ib_flow_handler *handler_ucast = NULL; |
| 3563 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3564 | |
| 3565 | static struct { |
| 3566 | struct ib_flow_attr flow_attr; |
| 3567 | struct ib_flow_spec_eth eth_flow; |
| 3568 | } leftovers_specs[] = { |
| 3569 | [LEFTOVERS_MC] = { |
| 3570 | .flow_attr = { |
| 3571 | .num_of_specs = 1, |
| 3572 | .size = sizeof(leftovers_specs[0]) |
| 3573 | }, |
| 3574 | .eth_flow = { |
| 3575 | .type = IB_FLOW_SPEC_ETH, |
| 3576 | .size = sizeof(struct ib_flow_spec_eth), |
| 3577 | .mask = {.dst_mac = {0x1} }, |
| 3578 | .val = {.dst_mac = {0x1} } |
| 3579 | } |
| 3580 | }, |
| 3581 | [LEFTOVERS_UC] = { |
| 3582 | .flow_attr = { |
| 3583 | .num_of_specs = 1, |
| 3584 | .size = sizeof(leftovers_specs[0]) |
| 3585 | }, |
| 3586 | .eth_flow = { |
| 3587 | .type = IB_FLOW_SPEC_ETH, |
| 3588 | .size = sizeof(struct ib_flow_spec_eth), |
| 3589 | .mask = {.dst_mac = {0x1} }, |
| 3590 | .val = {.dst_mac = {} } |
| 3591 | } |
| 3592 | } |
| 3593 | }; |
| 3594 | |
| 3595 | handler = create_flow_rule(dev, ft_prio, |
| 3596 | &leftovers_specs[LEFTOVERS_MC].flow_attr, |
| 3597 | dst); |
| 3598 | if (!IS_ERR(handler) && |
| 3599 | flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT) { |
| 3600 | handler_ucast = create_flow_rule(dev, ft_prio, |
| 3601 | &leftovers_specs[LEFTOVERS_UC].flow_attr, |
| 3602 | dst); |
| 3603 | if (IS_ERR(handler_ucast)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3604 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3605 | ft_prio->refcount--; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3606 | kfree(handler); |
| 3607 | handler = handler_ucast; |
| 3608 | } else { |
| 3609 | list_add(&handler_ucast->list, &handler->list); |
| 3610 | } |
| 3611 | } |
| 3612 | |
| 3613 | return handler; |
| 3614 | } |
| 3615 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3616 | static struct mlx5_ib_flow_handler *create_sniffer_rule(struct mlx5_ib_dev *dev, |
| 3617 | struct mlx5_ib_flow_prio *ft_rx, |
| 3618 | struct mlx5_ib_flow_prio *ft_tx, |
| 3619 | struct mlx5_flow_destination *dst) |
| 3620 | { |
| 3621 | struct mlx5_ib_flow_handler *handler_rx; |
| 3622 | struct mlx5_ib_flow_handler *handler_tx; |
| 3623 | int err; |
| 3624 | static const struct ib_flow_attr flow_attr = { |
| 3625 | .num_of_specs = 0, |
| 3626 | .size = sizeof(flow_attr) |
| 3627 | }; |
| 3628 | |
| 3629 | handler_rx = create_flow_rule(dev, ft_rx, &flow_attr, dst); |
| 3630 | if (IS_ERR(handler_rx)) { |
| 3631 | err = PTR_ERR(handler_rx); |
| 3632 | goto err; |
| 3633 | } |
| 3634 | |
| 3635 | handler_tx = create_flow_rule(dev, ft_tx, &flow_attr, dst); |
| 3636 | if (IS_ERR(handler_tx)) { |
| 3637 | err = PTR_ERR(handler_tx); |
| 3638 | goto err_tx; |
| 3639 | } |
| 3640 | |
| 3641 | list_add(&handler_tx->list, &handler_rx->list); |
| 3642 | |
| 3643 | return handler_rx; |
| 3644 | |
| 3645 | err_tx: |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3646 | mlx5_del_flow_rules(handler_rx->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3647 | ft_rx->refcount--; |
| 3648 | kfree(handler_rx); |
| 3649 | err: |
| 3650 | return ERR_PTR(err); |
| 3651 | } |
| 3652 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3653 | static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, |
| 3654 | struct ib_flow_attr *flow_attr, |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3655 | int domain, |
| 3656 | struct ib_udata *udata) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3657 | { |
| 3658 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Yishai Hadas | d9f88e5 | 2016-08-28 10:58:37 +0300 | [diff] [blame] | 3659 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3660 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3661 | struct mlx5_flow_destination *dst = NULL; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3662 | struct mlx5_ib_flow_prio *ft_prio_tx = NULL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3663 | struct mlx5_ib_flow_prio *ft_prio; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3664 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3665 | struct mlx5_ib_create_flow *ucmd = NULL, ucmd_hdr; |
| 3666 | size_t min_ucmd_sz, required_ucmd_sz; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3667 | int err; |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3668 | int underlay_qpn; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3669 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3670 | if (udata && udata->inlen) { |
| 3671 | min_ucmd_sz = offsetof(typeof(ucmd_hdr), reserved) + |
| 3672 | sizeof(ucmd_hdr.reserved); |
| 3673 | if (udata->inlen < min_ucmd_sz) |
| 3674 | return ERR_PTR(-EOPNOTSUPP); |
| 3675 | |
| 3676 | err = ib_copy_from_udata(&ucmd_hdr, udata, min_ucmd_sz); |
| 3677 | if (err) |
| 3678 | return ERR_PTR(err); |
| 3679 | |
| 3680 | /* currently supports only one counters data */ |
| 3681 | if (ucmd_hdr.ncounters_data > 1) |
| 3682 | return ERR_PTR(-EINVAL); |
| 3683 | |
| 3684 | required_ucmd_sz = min_ucmd_sz + |
| 3685 | sizeof(struct mlx5_ib_flow_counters_data) * |
| 3686 | ucmd_hdr.ncounters_data; |
| 3687 | if (udata->inlen > required_ucmd_sz && |
| 3688 | !ib_is_udata_cleared(udata, required_ucmd_sz, |
| 3689 | udata->inlen - required_ucmd_sz)) |
| 3690 | return ERR_PTR(-EOPNOTSUPP); |
| 3691 | |
| 3692 | ucmd = kzalloc(required_ucmd_sz, GFP_KERNEL); |
| 3693 | if (!ucmd) |
| 3694 | return ERR_PTR(-ENOMEM); |
| 3695 | |
| 3696 | err = ib_copy_from_udata(ucmd, udata, required_ucmd_sz); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3697 | if (err) |
| 3698 | goto free_ucmd; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3699 | } |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3700 | |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3701 | if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) { |
| 3702 | err = -ENOMEM; |
| 3703 | goto free_ucmd; |
| 3704 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3705 | |
| 3706 | if (domain != IB_FLOW_DOMAIN_USER || |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 3707 | flow_attr->port > dev->num_ports || |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3708 | (flow_attr->flags & ~(IB_FLOW_ATTR_FLAGS_DONT_TRAP | |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3709 | IB_FLOW_ATTR_FLAGS_EGRESS))) { |
| 3710 | err = -EINVAL; |
| 3711 | goto free_ucmd; |
| 3712 | } |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3713 | |
| 3714 | if (is_egress && |
| 3715 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3716 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3717 | err = -EINVAL; |
| 3718 | goto free_ucmd; |
| 3719 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3720 | |
| 3721 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3722 | if (!dst) { |
| 3723 | err = -ENOMEM; |
| 3724 | goto free_ucmd; |
| 3725 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3726 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3727 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3728 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3729 | ft_prio = get_flow_table(dev, flow_attr, |
| 3730 | is_egress ? MLX5_IB_FT_TX : MLX5_IB_FT_RX); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3731 | if (IS_ERR(ft_prio)) { |
| 3732 | err = PTR_ERR(ft_prio); |
| 3733 | goto unlock; |
| 3734 | } |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3735 | if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3736 | ft_prio_tx = get_flow_table(dev, flow_attr, MLX5_IB_FT_TX); |
| 3737 | if (IS_ERR(ft_prio_tx)) { |
| 3738 | err = PTR_ERR(ft_prio_tx); |
| 3739 | ft_prio_tx = NULL; |
| 3740 | goto destroy_ft; |
| 3741 | } |
| 3742 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3743 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3744 | if (is_egress) { |
| 3745 | dst->type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
| 3746 | } else { |
| 3747 | dst->type = MLX5_FLOW_DESTINATION_TYPE_TIR; |
| 3748 | if (mqp->flags & MLX5_IB_QP_RSS) |
| 3749 | dst->tir_num = mqp->rss_qp.tirn; |
| 3750 | else |
| 3751 | dst->tir_num = mqp->raw_packet_qp.rq.tirn; |
| 3752 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3753 | |
| 3754 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3755 | if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) { |
| 3756 | handler = create_dont_trap_rule(dev, ft_prio, |
| 3757 | flow_attr, dst); |
| 3758 | } else { |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3759 | underlay_qpn = (mqp->flags & MLX5_IB_QP_UNDERLAY) ? |
| 3760 | mqp->underlay_qpn : 0; |
| 3761 | handler = _create_flow_rule(dev, ft_prio, flow_attr, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3762 | dst, underlay_qpn, ucmd); |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3763 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3764 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3765 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3766 | handler = create_leftovers_rule(dev, ft_prio, flow_attr, |
| 3767 | dst); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3768 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3769 | handler = create_sniffer_rule(dev, ft_prio, ft_prio_tx, dst); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3770 | } else { |
| 3771 | err = -EINVAL; |
| 3772 | goto destroy_ft; |
| 3773 | } |
| 3774 | |
| 3775 | if (IS_ERR(handler)) { |
| 3776 | err = PTR_ERR(handler); |
| 3777 | handler = NULL; |
| 3778 | goto destroy_ft; |
| 3779 | } |
| 3780 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3781 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3782 | kfree(dst); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3783 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3784 | |
| 3785 | return &handler->ibflow; |
| 3786 | |
| 3787 | destroy_ft: |
| 3788 | put_flow_table(dev, ft_prio, false); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3789 | if (ft_prio_tx) |
| 3790 | put_flow_table(dev, ft_prio_tx, false); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3791 | unlock: |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3792 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3793 | kfree(dst); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3794 | free_ucmd: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3795 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3796 | return ERR_PTR(err); |
| 3797 | } |
| 3798 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3799 | static struct mlx5_ib_flow_prio * |
| 3800 | _get_flow_table(struct mlx5_ib_dev *dev, |
| 3801 | struct mlx5_ib_flow_matcher *fs_matcher, |
| 3802 | bool mcast) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3803 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3804 | struct mlx5_flow_namespace *ns = NULL; |
| 3805 | struct mlx5_ib_flow_prio *prio; |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3806 | int max_table_size; |
| 3807 | u32 flags = 0; |
| 3808 | int priority; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3809 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3810 | if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS) { |
| 3811 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3812 | log_max_ft_size)); |
| 3813 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, decap)) |
| 3814 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
| 3815 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3816 | reformat_l3_tunnel_to_l2)) |
| 3817 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
| 3818 | } else { /* Can only be MLX5_FLOW_NAMESPACE_EGRESS */ |
| 3819 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, |
| 3820 | log_max_ft_size)); |
| 3821 | if (MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, reformat)) |
| 3822 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
| 3823 | } |
| 3824 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3825 | if (max_table_size < MLX5_FS_MAX_ENTRIES) |
| 3826 | return ERR_PTR(-ENOMEM); |
| 3827 | |
| 3828 | if (mcast) |
| 3829 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3830 | else |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3831 | priority = ib_prio_to_core_prio(fs_matcher->priority, false); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3832 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3833 | ns = mlx5_get_flow_namespace(dev->mdev, fs_matcher->ns_type); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3834 | if (!ns) |
| 3835 | return ERR_PTR(-ENOTSUPP); |
| 3836 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3837 | if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS) |
| 3838 | prio = &dev->flow_db->prios[priority]; |
| 3839 | else |
| 3840 | prio = &dev->flow_db->egress_prios[priority]; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3841 | |
| 3842 | if (prio->flow_table) |
| 3843 | return prio; |
| 3844 | |
| 3845 | return _get_prio(ns, prio, priority, MLX5_FS_MAX_ENTRIES, |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3846 | MLX5_FS_MAX_TYPES, flags); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | static struct mlx5_ib_flow_handler * |
| 3850 | _create_raw_flow_rule(struct mlx5_ib_dev *dev, |
| 3851 | struct mlx5_ib_flow_prio *ft_prio, |
| 3852 | struct mlx5_flow_destination *dst, |
| 3853 | struct mlx5_ib_flow_matcher *fs_matcher, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3854 | struct mlx5_flow_act *flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3855 | void *cmd_in, int inlen, |
| 3856 | int dst_num) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3857 | { |
| 3858 | struct mlx5_ib_flow_handler *handler; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3859 | struct mlx5_flow_spec *spec; |
| 3860 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3861 | int err = 0; |
| 3862 | |
| 3863 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
| 3864 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
| 3865 | if (!handler || !spec) { |
| 3866 | err = -ENOMEM; |
| 3867 | goto free; |
| 3868 | } |
| 3869 | |
| 3870 | INIT_LIST_HEAD(&handler->list); |
| 3871 | |
| 3872 | memcpy(spec->match_value, cmd_in, inlen); |
| 3873 | memcpy(spec->match_criteria, fs_matcher->matcher_mask.match_params, |
| 3874 | fs_matcher->mask_len); |
| 3875 | spec->match_criteria_enable = fs_matcher->match_criteria_enable; |
| 3876 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3877 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3878 | flow_act, dst, dst_num); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3879 | |
| 3880 | if (IS_ERR(handler->rule)) { |
| 3881 | err = PTR_ERR(handler->rule); |
| 3882 | goto free; |
| 3883 | } |
| 3884 | |
| 3885 | ft_prio->refcount++; |
| 3886 | handler->prio = ft_prio; |
| 3887 | handler->dev = dev; |
| 3888 | ft_prio->flow_table = ft; |
| 3889 | |
| 3890 | free: |
| 3891 | if (err) |
| 3892 | kfree(handler); |
| 3893 | kvfree(spec); |
| 3894 | return err ? ERR_PTR(err) : handler; |
| 3895 | } |
| 3896 | |
| 3897 | static bool raw_fs_is_multicast(struct mlx5_ib_flow_matcher *fs_matcher, |
| 3898 | void *match_v) |
| 3899 | { |
| 3900 | void *match_c; |
| 3901 | void *match_v_set_lyr_2_4, *match_c_set_lyr_2_4; |
| 3902 | void *dmac, *dmac_mask; |
| 3903 | void *ipv4, *ipv4_mask; |
| 3904 | |
| 3905 | if (!(fs_matcher->match_criteria_enable & |
| 3906 | (1 << MATCH_CRITERIA_ENABLE_OUTER_BIT))) |
| 3907 | return false; |
| 3908 | |
| 3909 | match_c = fs_matcher->matcher_mask.match_params; |
| 3910 | match_v_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_v, |
| 3911 | outer_headers); |
| 3912 | match_c_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_c, |
| 3913 | outer_headers); |
| 3914 | |
| 3915 | dmac = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 3916 | dmac_47_16); |
| 3917 | dmac_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 3918 | dmac_47_16); |
| 3919 | |
| 3920 | if (is_multicast_ether_addr(dmac) && |
| 3921 | is_multicast_ether_addr(dmac_mask)) |
| 3922 | return true; |
| 3923 | |
| 3924 | ipv4 = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 3925 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 3926 | |
| 3927 | ipv4_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 3928 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 3929 | |
| 3930 | if (ipv4_is_multicast(*(__be32 *)(ipv4)) && |
| 3931 | ipv4_is_multicast(*(__be32 *)(ipv4_mask))) |
| 3932 | return true; |
| 3933 | |
| 3934 | return false; |
| 3935 | } |
| 3936 | |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3937 | struct mlx5_ib_flow_handler * |
| 3938 | mlx5_ib_raw_fs_rule_add(struct mlx5_ib_dev *dev, |
| 3939 | struct mlx5_ib_flow_matcher *fs_matcher, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3940 | struct mlx5_flow_act *flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3941 | u32 counter_id, |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3942 | void *cmd_in, int inlen, int dest_id, |
| 3943 | int dest_type) |
| 3944 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3945 | struct mlx5_flow_destination *dst; |
| 3946 | struct mlx5_ib_flow_prio *ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3947 | struct mlx5_ib_flow_handler *handler; |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3948 | int dst_num = 0; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3949 | bool mcast; |
| 3950 | int err; |
| 3951 | |
| 3952 | if (fs_matcher->flow_type != MLX5_IB_FLOW_TYPE_NORMAL) |
| 3953 | return ERR_PTR(-EOPNOTSUPP); |
| 3954 | |
| 3955 | if (fs_matcher->priority > MLX5_IB_FLOW_LAST_PRIO) |
| 3956 | return ERR_PTR(-ENOMEM); |
| 3957 | |
Gustavo A. R. Silva | 8e8aa14 | 2019-01-15 00:00:48 -0600 | [diff] [blame] | 3958 | dst = kcalloc(2, sizeof(*dst), GFP_KERNEL); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3959 | if (!dst) |
| 3960 | return ERR_PTR(-ENOMEM); |
| 3961 | |
| 3962 | mcast = raw_fs_is_multicast(fs_matcher, cmd_in); |
| 3963 | mutex_lock(&dev->flow_db->lock); |
| 3964 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3965 | ft_prio = _get_flow_table(dev, fs_matcher, mcast); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3966 | if (IS_ERR(ft_prio)) { |
| 3967 | err = PTR_ERR(ft_prio); |
| 3968 | goto unlock; |
| 3969 | } |
| 3970 | |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 3971 | if (dest_type == MLX5_FLOW_DESTINATION_TYPE_TIR) { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3972 | dst[dst_num].type = dest_type; |
| 3973 | dst[dst_num].tir_num = dest_id; |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3974 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 3975 | } else if (dest_type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3976 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM; |
| 3977 | dst[dst_num].ft_num = dest_id; |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3978 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 3979 | } else { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3980 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 3981 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 3982 | } |
| 3983 | |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3984 | dst_num++; |
| 3985 | |
| 3986 | if (flow_act->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
| 3987 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
| 3988 | dst[dst_num].counter_id = counter_id; |
| 3989 | dst_num++; |
| 3990 | } |
| 3991 | |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3992 | 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] | 3993 | cmd_in, inlen, dst_num); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3994 | |
| 3995 | if (IS_ERR(handler)) { |
| 3996 | err = PTR_ERR(handler); |
| 3997 | goto destroy_ft; |
| 3998 | } |
| 3999 | |
| 4000 | mutex_unlock(&dev->flow_db->lock); |
| 4001 | atomic_inc(&fs_matcher->usecnt); |
| 4002 | handler->flow_matcher = fs_matcher; |
| 4003 | |
| 4004 | kfree(dst); |
| 4005 | |
| 4006 | return handler; |
| 4007 | |
| 4008 | destroy_ft: |
| 4009 | put_flow_table(dev, ft_prio, false); |
| 4010 | unlock: |
| 4011 | mutex_unlock(&dev->flow_db->lock); |
| 4012 | kfree(dst); |
| 4013 | |
| 4014 | return ERR_PTR(err); |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 4015 | } |
| 4016 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4017 | static u32 mlx5_ib_flow_action_flags_to_accel_xfrm_flags(u32 mlx5_flags) |
| 4018 | { |
| 4019 | u32 flags = 0; |
| 4020 | |
| 4021 | if (mlx5_flags & MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA) |
| 4022 | flags |= MLX5_ACCEL_XFRM_FLAG_REQUIRE_METADATA; |
| 4023 | |
| 4024 | return flags; |
| 4025 | } |
| 4026 | |
| 4027 | #define MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA |
| 4028 | static struct ib_flow_action * |
| 4029 | mlx5_ib_create_flow_action_esp(struct ib_device *device, |
| 4030 | const struct ib_flow_action_attrs_esp *attr, |
| 4031 | struct uverbs_attr_bundle *attrs) |
| 4032 | { |
| 4033 | struct mlx5_ib_dev *mdev = to_mdev(device); |
| 4034 | struct ib_uverbs_flow_action_esp_keymat_aes_gcm *aes_gcm; |
| 4035 | struct mlx5_accel_esp_xfrm_attrs accel_attrs = {}; |
| 4036 | struct mlx5_ib_flow_action *action; |
| 4037 | u64 action_flags; |
| 4038 | u64 flags; |
| 4039 | int err = 0; |
| 4040 | |
Jason Gunthorpe | bccd062 | 2018-07-26 16:37:14 -0600 | [diff] [blame] | 4041 | err = uverbs_get_flags64( |
| 4042 | &action_flags, attrs, MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 4043 | ((MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED << 1) - 1)); |
| 4044 | if (err) |
| 4045 | return ERR_PTR(err); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4046 | |
| 4047 | flags = mlx5_ib_flow_action_flags_to_accel_xfrm_flags(action_flags); |
| 4048 | |
| 4049 | /* We current only support a subset of the standard features. Only a |
| 4050 | * keymat of type AES_GCM, with icv_len == 16, iv_algo == SEQ and esn |
| 4051 | * (with overlap). Full offload mode isn't supported. |
| 4052 | */ |
| 4053 | if (!attr->keymat || attr->replay || attr->encap || |
| 4054 | attr->spi || attr->seq || attr->tfc_pad || |
| 4055 | attr->hard_limit_pkts || |
| 4056 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4057 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT))) |
| 4058 | return ERR_PTR(-EOPNOTSUPP); |
| 4059 | |
| 4060 | if (attr->keymat->protocol != |
| 4061 | IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM) |
| 4062 | return ERR_PTR(-EOPNOTSUPP); |
| 4063 | |
| 4064 | aes_gcm = &attr->keymat->keymat.aes_gcm; |
| 4065 | |
| 4066 | if (aes_gcm->icv_len != 16 || |
| 4067 | aes_gcm->iv_algo != IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ) |
| 4068 | return ERR_PTR(-EOPNOTSUPP); |
| 4069 | |
| 4070 | action = kmalloc(sizeof(*action), GFP_KERNEL); |
| 4071 | if (!action) |
| 4072 | return ERR_PTR(-ENOMEM); |
| 4073 | |
| 4074 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 4075 | memcpy(&accel_attrs.keymat.aes_gcm.aes_key, &aes_gcm->aes_key, |
| 4076 | sizeof(accel_attrs.keymat.aes_gcm.aes_key)); |
| 4077 | accel_attrs.keymat.aes_gcm.key_len = aes_gcm->key_len * 8; |
| 4078 | memcpy(&accel_attrs.keymat.aes_gcm.salt, &aes_gcm->salt, |
| 4079 | sizeof(accel_attrs.keymat.aes_gcm.salt)); |
| 4080 | memcpy(&accel_attrs.keymat.aes_gcm.seq_iv, &aes_gcm->iv, |
| 4081 | sizeof(accel_attrs.keymat.aes_gcm.seq_iv)); |
| 4082 | accel_attrs.keymat.aes_gcm.icv_len = aes_gcm->icv_len * 8; |
| 4083 | accel_attrs.keymat.aes_gcm.iv_algo = MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ; |
| 4084 | accel_attrs.keymat_type = MLX5_ACCEL_ESP_KEYMAT_AES_GCM; |
| 4085 | |
| 4086 | accel_attrs.esn = attr->esn; |
| 4087 | if (attr->flags & IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) |
| 4088 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED; |
| 4089 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 4090 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4091 | |
| 4092 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT) |
| 4093 | accel_attrs.action |= MLX5_ACCEL_ESP_ACTION_ENCRYPT; |
| 4094 | |
| 4095 | action->esp_aes_gcm.ctx = |
| 4096 | mlx5_accel_esp_create_xfrm(mdev->mdev, &accel_attrs, flags); |
| 4097 | if (IS_ERR(action->esp_aes_gcm.ctx)) { |
| 4098 | err = PTR_ERR(action->esp_aes_gcm.ctx); |
| 4099 | goto err_parse; |
| 4100 | } |
| 4101 | |
| 4102 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 4103 | |
| 4104 | return &action->ib_action; |
| 4105 | |
| 4106 | err_parse: |
| 4107 | kfree(action); |
| 4108 | return ERR_PTR(err); |
| 4109 | } |
| 4110 | |
Matan Barak | 349705c | 2018-03-28 09:27:51 +0300 | [diff] [blame] | 4111 | static int |
| 4112 | mlx5_ib_modify_flow_action_esp(struct ib_flow_action *action, |
| 4113 | const struct ib_flow_action_attrs_esp *attr, |
| 4114 | struct uverbs_attr_bundle *attrs) |
| 4115 | { |
| 4116 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 4117 | struct mlx5_accel_esp_xfrm_attrs accel_attrs; |
| 4118 | int err = 0; |
| 4119 | |
| 4120 | if (attr->keymat || attr->replay || attr->encap || |
| 4121 | attr->spi || attr->seq || attr->tfc_pad || |
| 4122 | attr->hard_limit_pkts || |
| 4123 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4124 | IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS | |
| 4125 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW))) |
| 4126 | return -EOPNOTSUPP; |
| 4127 | |
| 4128 | /* Only the ESN value or the MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP can |
| 4129 | * be modified. |
| 4130 | */ |
| 4131 | if (!(maction->esp_aes_gcm.ib_flags & |
| 4132 | IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) && |
| 4133 | attr->flags & (IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4134 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW)) |
| 4135 | return -EINVAL; |
| 4136 | |
| 4137 | memcpy(&accel_attrs, &maction->esp_aes_gcm.ctx->attrs, |
| 4138 | sizeof(accel_attrs)); |
| 4139 | |
| 4140 | accel_attrs.esn = attr->esn; |
| 4141 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 4142 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4143 | else |
| 4144 | accel_attrs.flags &= ~MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4145 | |
| 4146 | err = mlx5_accel_esp_modify_xfrm(maction->esp_aes_gcm.ctx, |
| 4147 | &accel_attrs); |
| 4148 | if (err) |
| 4149 | return err; |
| 4150 | |
| 4151 | maction->esp_aes_gcm.ib_flags &= |
| 4152 | ~IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 4153 | maction->esp_aes_gcm.ib_flags |= |
| 4154 | attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 4155 | |
| 4156 | return 0; |
| 4157 | } |
| 4158 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4159 | static int mlx5_ib_destroy_flow_action(struct ib_flow_action *action) |
| 4160 | { |
| 4161 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 4162 | |
| 4163 | switch (action->type) { |
| 4164 | case IB_FLOW_ACTION_ESP: |
| 4165 | /* |
| 4166 | * We only support aes_gcm by now, so we implicitly know this is |
| 4167 | * the underline crypto. |
| 4168 | */ |
| 4169 | mlx5_accel_esp_destroy_xfrm(maction->esp_aes_gcm.ctx); |
| 4170 | break; |
Mark Bloch | b4749bf | 2018-08-28 14:18:51 +0300 | [diff] [blame] | 4171 | case IB_FLOW_ACTION_UNSPECIFIED: |
| 4172 | mlx5_ib_destroy_flow_action_raw(maction); |
| 4173 | break; |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4174 | default: |
| 4175 | WARN_ON(true); |
| 4176 | break; |
| 4177 | } |
| 4178 | |
| 4179 | kfree(maction); |
| 4180 | return 0; |
| 4181 | } |
| 4182 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4183 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4184 | { |
| 4185 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4186 | struct mlx5_ib_qp *mqp = to_mqp(ibqp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4187 | int err; |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4188 | u16 uid; |
| 4189 | |
| 4190 | uid = ibqp->pd ? |
| 4191 | to_mpd(ibqp->pd)->uid : 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4192 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4193 | if (mqp->flags & MLX5_IB_QP_UNDERLAY) { |
| 4194 | mlx5_ib_dbg(dev, "Attaching a multi cast group to underlay QP is not supported\n"); |
| 4195 | return -EOPNOTSUPP; |
| 4196 | } |
| 4197 | |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4198 | err = mlx5_cmd_attach_mcg(dev->mdev, gid, ibqp->qp_num, uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4199 | if (err) |
| 4200 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
| 4201 | ibqp->qp_num, gid->raw); |
| 4202 | |
| 4203 | return err; |
| 4204 | } |
| 4205 | |
| 4206 | static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4207 | { |
| 4208 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 4209 | int err; |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4210 | u16 uid; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4211 | |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4212 | uid = ibqp->pd ? |
| 4213 | to_mpd(ibqp->pd)->uid : 0; |
| 4214 | err = mlx5_cmd_detach_mcg(dev->mdev, gid, ibqp->qp_num, uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4215 | if (err) |
| 4216 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
| 4217 | ibqp->qp_num, gid->raw); |
| 4218 | |
| 4219 | return err; |
| 4220 | } |
| 4221 | |
| 4222 | static int init_node_data(struct mlx5_ib_dev *dev) |
| 4223 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4224 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4225 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4226 | err = mlx5_query_node_desc(dev, dev->ib_dev.node_desc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4227 | if (err) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4228 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4229 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4230 | dev->mdev->rev_id = dev->mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4231 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4232 | return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4233 | } |
| 4234 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4235 | static ssize_t fw_pages_show(struct device *device, |
| 4236 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4237 | { |
| 4238 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4239 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4240 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4241 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4242 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4243 | static DEVICE_ATTR_RO(fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4244 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4245 | static ssize_t reg_pages_show(struct device *device, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4246 | struct device_attribute *attr, char *buf) |
| 4247 | { |
| 4248 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4249 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4250 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 4251 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4252 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4253 | static DEVICE_ATTR_RO(reg_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4254 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4255 | static ssize_t hca_type_show(struct device *device, |
| 4256 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4257 | { |
| 4258 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4259 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4260 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4261 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4262 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4263 | static DEVICE_ATTR_RO(hca_type); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4264 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4265 | static ssize_t hw_rev_show(struct device *device, |
| 4266 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4267 | { |
| 4268 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4269 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4270 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4271 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4272 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4273 | static DEVICE_ATTR_RO(hw_rev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4274 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4275 | static ssize_t board_id_show(struct device *device, |
| 4276 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4277 | { |
| 4278 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4279 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4280 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4281 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4282 | dev->mdev->board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4283 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4284 | static DEVICE_ATTR_RO(board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4285 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4286 | static struct attribute *mlx5_class_attributes[] = { |
| 4287 | &dev_attr_hw_rev.attr, |
| 4288 | &dev_attr_hca_type.attr, |
| 4289 | &dev_attr_board_id.attr, |
| 4290 | &dev_attr_fw_pages.attr, |
| 4291 | &dev_attr_reg_pages.attr, |
| 4292 | NULL, |
| 4293 | }; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4294 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4295 | static const struct attribute_group mlx5_attr_group = { |
| 4296 | .attrs = mlx5_class_attributes, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4297 | }; |
| 4298 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4299 | static void pkey_change_handler(struct work_struct *work) |
| 4300 | { |
| 4301 | struct mlx5_ib_port_resources *ports = |
| 4302 | container_of(work, struct mlx5_ib_port_resources, |
| 4303 | pkey_change_work); |
| 4304 | |
| 4305 | mutex_lock(&ports->devr->mutex); |
| 4306 | mlx5_ib_gsi_pkey_change(ports->gsi); |
| 4307 | mutex_unlock(&ports->devr->mutex); |
| 4308 | } |
| 4309 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4310 | static void mlx5_ib_handle_internal_error(struct mlx5_ib_dev *ibdev) |
| 4311 | { |
| 4312 | struct mlx5_ib_qp *mqp; |
| 4313 | struct mlx5_ib_cq *send_mcq, *recv_mcq; |
| 4314 | struct mlx5_core_cq *mcq; |
| 4315 | struct list_head cq_armed_list; |
| 4316 | unsigned long flags_qp; |
| 4317 | unsigned long flags_cq; |
| 4318 | unsigned long flags; |
| 4319 | |
| 4320 | INIT_LIST_HEAD(&cq_armed_list); |
| 4321 | |
| 4322 | /* Go over qp list reside on that ibdev, sync with create/destroy qp.*/ |
| 4323 | spin_lock_irqsave(&ibdev->reset_flow_resource_lock, flags); |
| 4324 | list_for_each_entry(mqp, &ibdev->qp_list, qps_list) { |
| 4325 | spin_lock_irqsave(&mqp->sq.lock, flags_qp); |
| 4326 | if (mqp->sq.tail != mqp->sq.head) { |
| 4327 | send_mcq = to_mcq(mqp->ibqp.send_cq); |
| 4328 | spin_lock_irqsave(&send_mcq->lock, flags_cq); |
| 4329 | if (send_mcq->mcq.comp && |
| 4330 | mqp->ibqp.send_cq->comp_handler) { |
| 4331 | if (!send_mcq->mcq.reset_notify_added) { |
| 4332 | send_mcq->mcq.reset_notify_added = 1; |
| 4333 | list_add_tail(&send_mcq->mcq.reset_notify, |
| 4334 | &cq_armed_list); |
| 4335 | } |
| 4336 | } |
| 4337 | spin_unlock_irqrestore(&send_mcq->lock, flags_cq); |
| 4338 | } |
| 4339 | spin_unlock_irqrestore(&mqp->sq.lock, flags_qp); |
| 4340 | spin_lock_irqsave(&mqp->rq.lock, flags_qp); |
| 4341 | /* no handling is needed for SRQ */ |
| 4342 | if (!mqp->ibqp.srq) { |
| 4343 | if (mqp->rq.tail != mqp->rq.head) { |
| 4344 | recv_mcq = to_mcq(mqp->ibqp.recv_cq); |
| 4345 | spin_lock_irqsave(&recv_mcq->lock, flags_cq); |
| 4346 | if (recv_mcq->mcq.comp && |
| 4347 | mqp->ibqp.recv_cq->comp_handler) { |
| 4348 | if (!recv_mcq->mcq.reset_notify_added) { |
| 4349 | recv_mcq->mcq.reset_notify_added = 1; |
| 4350 | list_add_tail(&recv_mcq->mcq.reset_notify, |
| 4351 | &cq_armed_list); |
| 4352 | } |
| 4353 | } |
| 4354 | spin_unlock_irqrestore(&recv_mcq->lock, |
| 4355 | flags_cq); |
| 4356 | } |
| 4357 | } |
| 4358 | spin_unlock_irqrestore(&mqp->rq.lock, flags_qp); |
| 4359 | } |
| 4360 | /*At that point all inflight post send were put to be executed as of we |
| 4361 | * lock/unlock above locks Now need to arm all involved CQs. |
| 4362 | */ |
| 4363 | list_for_each_entry(mcq, &cq_armed_list, reset_notify) { |
| 4364 | mcq->comp(mcq); |
| 4365 | } |
| 4366 | spin_unlock_irqrestore(&ibdev->reset_flow_resource_lock, flags); |
| 4367 | } |
| 4368 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4369 | static void delay_drop_handler(struct work_struct *work) |
| 4370 | { |
| 4371 | int err; |
| 4372 | struct mlx5_ib_delay_drop *delay_drop = |
| 4373 | container_of(work, struct mlx5_ib_delay_drop, |
| 4374 | delay_drop_work); |
| 4375 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 4376 | atomic_inc(&delay_drop->events_cnt); |
| 4377 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4378 | mutex_lock(&delay_drop->lock); |
| 4379 | err = mlx5_core_set_delay_drop(delay_drop->dev->mdev, |
| 4380 | delay_drop->timeout); |
| 4381 | if (err) { |
| 4382 | mlx5_ib_warn(delay_drop->dev, "Failed to set delay drop, timeout=%u\n", |
| 4383 | delay_drop->timeout); |
| 4384 | delay_drop->activate = false; |
| 4385 | } |
| 4386 | mutex_unlock(&delay_drop->lock); |
| 4387 | } |
| 4388 | |
Saeed Mahameed | 09e574f | 2018-11-26 14:39:04 -0800 | [diff] [blame] | 4389 | static void handle_general_event(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, |
| 4390 | struct ib_event *ibev) |
| 4391 | { |
| 4392 | switch (eqe->sub_type) { |
| 4393 | case MLX5_GENERAL_SUBTYPE_DELAY_DROP_TIMEOUT: |
| 4394 | schedule_work(&ibdev->delay_drop.delay_drop_work); |
| 4395 | break; |
| 4396 | default: /* do nothing */ |
| 4397 | return; |
| 4398 | } |
| 4399 | } |
| 4400 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4401 | static int handle_port_change(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, |
| 4402 | struct ib_event *ibev) |
| 4403 | { |
| 4404 | u8 port = (eqe->data.port.port >> 4) & 0xf; |
| 4405 | |
| 4406 | ibev->element.port_num = port; |
| 4407 | |
| 4408 | switch (eqe->sub_type) { |
| 4409 | case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE: |
| 4410 | case MLX5_PORT_CHANGE_SUBTYPE_DOWN: |
| 4411 | case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED: |
| 4412 | /* In RoCE, port up/down events are handled in |
| 4413 | * mlx5_netdev_event(). |
| 4414 | */ |
| 4415 | if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
| 4416 | IB_LINK_LAYER_ETHERNET) |
| 4417 | return -EINVAL; |
| 4418 | |
| 4419 | ibev->event = (eqe->sub_type == MLX5_PORT_CHANGE_SUBTYPE_ACTIVE) ? |
| 4420 | IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
| 4421 | break; |
| 4422 | |
| 4423 | case MLX5_PORT_CHANGE_SUBTYPE_LID: |
| 4424 | ibev->event = IB_EVENT_LID_CHANGE; |
| 4425 | break; |
| 4426 | |
| 4427 | case MLX5_PORT_CHANGE_SUBTYPE_PKEY: |
| 4428 | ibev->event = IB_EVENT_PKEY_CHANGE; |
| 4429 | schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work); |
| 4430 | break; |
| 4431 | |
| 4432 | case MLX5_PORT_CHANGE_SUBTYPE_GUID: |
| 4433 | ibev->event = IB_EVENT_GID_CHANGE; |
| 4434 | break; |
| 4435 | |
| 4436 | case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG: |
| 4437 | ibev->event = IB_EVENT_CLIENT_REREGISTER; |
| 4438 | break; |
| 4439 | default: |
| 4440 | return -EINVAL; |
| 4441 | } |
| 4442 | |
| 4443 | return 0; |
| 4444 | } |
| 4445 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4446 | static void mlx5_ib_handle_event(struct work_struct *_work) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4447 | { |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4448 | struct mlx5_ib_event_work *work = |
| 4449 | container_of(_work, struct mlx5_ib_event_work, work); |
| 4450 | struct mlx5_ib_dev *ibdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4451 | struct ib_event ibev; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4452 | bool fatal = false; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4453 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4454 | if (work->is_slave) { |
| 4455 | ibdev = mlx5_ib_get_ibdev_from_mpi(work->mpi); |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4456 | if (!ibdev) |
| 4457 | goto out; |
| 4458 | } else { |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4459 | ibdev = work->dev; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4460 | } |
| 4461 | |
| 4462 | switch (work->event) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4463 | case MLX5_DEV_EVENT_SYS_ERROR: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4464 | ibev.event = IB_EVENT_DEVICE_FATAL; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4465 | mlx5_ib_handle_internal_error(ibdev); |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4466 | ibev.element.port_num = (u8)(unsigned long)work->param; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4467 | fatal = true; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4468 | break; |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4469 | case MLX5_EVENT_TYPE_PORT_CHANGE: |
| 4470 | if (handle_port_change(ibdev, work->param, &ibev)) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4471 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4472 | break; |
Saeed Mahameed | 09e574f | 2018-11-26 14:39:04 -0800 | [diff] [blame] | 4473 | case MLX5_EVENT_TYPE_GENERAL_EVENT: |
| 4474 | handle_general_event(ibdev, work->param, &ibev); |
| 4475 | /* fall through */ |
Saeed Mahameed | bdc3792 | 2016-09-29 19:35:38 +0300 | [diff] [blame] | 4476 | default: |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4477 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4478 | } |
| 4479 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4480 | ibev.device = &ibdev->ib_dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4481 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4482 | if (!rdma_is_port_valid(&ibdev->ib_dev, ibev.element.port_num)) { |
| 4483 | 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] | 4484 | goto out; |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 4485 | } |
| 4486 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4487 | if (ibdev->ib_active) |
| 4488 | ib_dispatch_event(&ibev); |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4489 | |
| 4490 | if (fatal) |
| 4491 | ibdev->ib_active = false; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4492 | out: |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4493 | kfree(work); |
| 4494 | } |
| 4495 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4496 | static int mlx5_ib_event(struct notifier_block *nb, |
| 4497 | unsigned long event, void *param) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4498 | { |
| 4499 | struct mlx5_ib_event_work *work; |
| 4500 | |
| 4501 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4502 | if (!work) |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4503 | return NOTIFY_DONE; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4504 | |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4505 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4506 | work->dev = container_of(nb, struct mlx5_ib_dev, mdev_events); |
| 4507 | work->is_slave = false; |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4508 | work->param = param; |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4509 | work->event = event; |
| 4510 | |
| 4511 | queue_work(mlx5_ib_event_wq, &work->work); |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4512 | |
| 4513 | return NOTIFY_OK; |
| 4514 | } |
| 4515 | |
| 4516 | static int mlx5_ib_event_slave_port(struct notifier_block *nb, |
| 4517 | unsigned long event, void *param) |
| 4518 | { |
| 4519 | struct mlx5_ib_event_work *work; |
| 4520 | |
| 4521 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
| 4522 | if (!work) |
| 4523 | return NOTIFY_DONE; |
| 4524 | |
| 4525 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
| 4526 | work->mpi = container_of(nb, struct mlx5_ib_multiport_info, mdev_events); |
| 4527 | work->is_slave = true; |
| 4528 | work->param = param; |
| 4529 | work->event = event; |
| 4530 | queue_work(mlx5_ib_event_wq, &work->work); |
| 4531 | |
| 4532 | return NOTIFY_OK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4533 | } |
| 4534 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4535 | static int set_has_smi_cap(struct mlx5_ib_dev *dev) |
| 4536 | { |
| 4537 | struct mlx5_hca_vport_context vport_ctx; |
| 4538 | int err; |
| 4539 | int port; |
| 4540 | |
Mark Bloch | a989ea0 | 2019-03-28 15:27:40 +0200 | [diff] [blame^] | 4541 | for (port = 1; port <= ARRAY_SIZE(dev->mdev->port_caps); port++) { |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4542 | dev->mdev->port_caps[port - 1].has_smi = false; |
| 4543 | if (MLX5_CAP_GEN(dev->mdev, port_type) == |
| 4544 | MLX5_CAP_PORT_TYPE_IB) { |
| 4545 | if (MLX5_CAP_GEN(dev->mdev, ib_virt)) { |
| 4546 | err = mlx5_query_hca_vport_context(dev->mdev, 0, |
| 4547 | port, 0, |
| 4548 | &vport_ctx); |
| 4549 | if (err) { |
| 4550 | mlx5_ib_err(dev, "query_hca_vport_context for port=%d failed %d\n", |
| 4551 | port, err); |
| 4552 | return err; |
| 4553 | } |
| 4554 | dev->mdev->port_caps[port - 1].has_smi = |
| 4555 | vport_ctx.has_smi; |
| 4556 | } else { |
| 4557 | dev->mdev->port_caps[port - 1].has_smi = true; |
| 4558 | } |
| 4559 | } |
| 4560 | } |
| 4561 | return 0; |
| 4562 | } |
| 4563 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4564 | static void get_ext_port_caps(struct mlx5_ib_dev *dev) |
| 4565 | { |
| 4566 | int port; |
| 4567 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4568 | for (port = 1; port <= dev->num_ports; port++) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4569 | mlx5_query_ext_port_caps(dev, port); |
| 4570 | } |
| 4571 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4572 | static int get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4573 | { |
| 4574 | struct ib_device_attr *dprops = NULL; |
| 4575 | struct ib_port_attr *pprops = NULL; |
Dan Carpenter | f614fc1 | 2015-01-12 11:56:58 +0300 | [diff] [blame] | 4576 | int err = -ENOMEM; |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4577 | struct ib_udata uhw = {.inlen = 0, .outlen = 0}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4578 | |
| 4579 | pprops = kmalloc(sizeof(*pprops), GFP_KERNEL); |
| 4580 | if (!pprops) |
| 4581 | goto out; |
| 4582 | |
| 4583 | dprops = kmalloc(sizeof(*dprops), GFP_KERNEL); |
| 4584 | if (!dprops) |
| 4585 | goto out; |
| 4586 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4587 | err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4588 | if (err) { |
| 4589 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
| 4590 | goto out; |
| 4591 | } |
| 4592 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4593 | memset(pprops, 0, sizeof(*pprops)); |
| 4594 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
| 4595 | if (err) { |
| 4596 | mlx5_ib_warn(dev, "query_port %d failed %d\n", |
| 4597 | port, err); |
| 4598 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4599 | } |
| 4600 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4601 | dev->mdev->port_caps[port - 1].pkey_table_len = |
| 4602 | dprops->max_pkeys; |
| 4603 | dev->mdev->port_caps[port - 1].gid_table_len = |
| 4604 | pprops->gid_tbl_len; |
| 4605 | mlx5_ib_dbg(dev, "port %d: pkey_table_len %d, gid_table_len %d\n", |
| 4606 | port, dprops->max_pkeys, pprops->gid_tbl_len); |
| 4607 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4608 | out: |
| 4609 | kfree(pprops); |
| 4610 | kfree(dprops); |
| 4611 | |
| 4612 | return err; |
| 4613 | } |
| 4614 | |
| 4615 | static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
| 4616 | { |
| 4617 | int err; |
| 4618 | |
| 4619 | err = mlx5_mr_cache_cleanup(dev); |
| 4620 | if (err) |
| 4621 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
| 4622 | |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4623 | if (dev->umrc.qp) |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4624 | mlx5_ib_destroy_qp(dev->umrc.qp, NULL); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4625 | if (dev->umrc.cq) |
| 4626 | ib_free_cq(dev->umrc.cq); |
| 4627 | if (dev->umrc.pd) |
| 4628 | ib_dealloc_pd(dev->umrc.pd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | enum { |
| 4632 | MAX_UMR_WR = 128, |
| 4633 | }; |
| 4634 | |
| 4635 | static int create_umr_res(struct mlx5_ib_dev *dev) |
| 4636 | { |
| 4637 | struct ib_qp_init_attr *init_attr = NULL; |
| 4638 | struct ib_qp_attr *attr = NULL; |
| 4639 | struct ib_pd *pd; |
| 4640 | struct ib_cq *cq; |
| 4641 | struct ib_qp *qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4642 | int ret; |
| 4643 | |
| 4644 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| 4645 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 4646 | if (!attr || !init_attr) { |
| 4647 | ret = -ENOMEM; |
| 4648 | goto error_0; |
| 4649 | } |
| 4650 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 4651 | pd = ib_alloc_pd(&dev->ib_dev, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4652 | if (IS_ERR(pd)) { |
| 4653 | mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); |
| 4654 | ret = PTR_ERR(pd); |
| 4655 | goto error_0; |
| 4656 | } |
| 4657 | |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4658 | 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] | 4659 | if (IS_ERR(cq)) { |
| 4660 | mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); |
| 4661 | ret = PTR_ERR(cq); |
| 4662 | goto error_2; |
| 4663 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4664 | |
| 4665 | init_attr->send_cq = cq; |
| 4666 | init_attr->recv_cq = cq; |
| 4667 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
| 4668 | init_attr->cap.max_send_wr = MAX_UMR_WR; |
| 4669 | init_attr->cap.max_send_sge = 1; |
| 4670 | init_attr->qp_type = MLX5_IB_QPT_REG_UMR; |
| 4671 | init_attr->port_num = 1; |
| 4672 | qp = mlx5_ib_create_qp(pd, init_attr, NULL); |
| 4673 | if (IS_ERR(qp)) { |
| 4674 | mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); |
| 4675 | ret = PTR_ERR(qp); |
| 4676 | goto error_3; |
| 4677 | } |
| 4678 | qp->device = &dev->ib_dev; |
| 4679 | qp->real_qp = qp; |
| 4680 | qp->uobject = NULL; |
| 4681 | qp->qp_type = MLX5_IB_QPT_REG_UMR; |
Majd Dibbiny | 31fde03 | 2017-10-30 14:23:13 +0200 | [diff] [blame] | 4682 | qp->send_cq = init_attr->send_cq; |
| 4683 | qp->recv_cq = init_attr->recv_cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4684 | |
| 4685 | attr->qp_state = IB_QPS_INIT; |
| 4686 | attr->port_num = 1; |
| 4687 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX | |
| 4688 | IB_QP_PORT, NULL); |
| 4689 | if (ret) { |
| 4690 | mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); |
| 4691 | goto error_4; |
| 4692 | } |
| 4693 | |
| 4694 | memset(attr, 0, sizeof(*attr)); |
| 4695 | attr->qp_state = IB_QPS_RTR; |
| 4696 | attr->path_mtu = IB_MTU_256; |
| 4697 | |
| 4698 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4699 | if (ret) { |
| 4700 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); |
| 4701 | goto error_4; |
| 4702 | } |
| 4703 | |
| 4704 | memset(attr, 0, sizeof(*attr)); |
| 4705 | attr->qp_state = IB_QPS_RTS; |
| 4706 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4707 | if (ret) { |
| 4708 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); |
| 4709 | goto error_4; |
| 4710 | } |
| 4711 | |
| 4712 | dev->umrc.qp = qp; |
| 4713 | dev->umrc.cq = cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4714 | dev->umrc.pd = pd; |
| 4715 | |
| 4716 | sema_init(&dev->umrc.sem, MAX_UMR_WR); |
| 4717 | ret = mlx5_mr_cache_init(dev); |
| 4718 | if (ret) { |
| 4719 | mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); |
| 4720 | goto error_4; |
| 4721 | } |
| 4722 | |
| 4723 | kfree(attr); |
| 4724 | kfree(init_attr); |
| 4725 | |
| 4726 | return 0; |
| 4727 | |
| 4728 | error_4: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4729 | mlx5_ib_destroy_qp(qp, NULL); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4730 | dev->umrc.qp = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4731 | |
| 4732 | error_3: |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4733 | ib_free_cq(cq); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4734 | dev->umrc.cq = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4735 | |
| 4736 | error_2: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4737 | ib_dealloc_pd(pd); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4738 | dev->umrc.pd = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4739 | |
| 4740 | error_0: |
| 4741 | kfree(attr); |
| 4742 | kfree(init_attr); |
| 4743 | return ret; |
| 4744 | } |
| 4745 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 4746 | static u8 mlx5_get_umr_fence(u8 umr_fence_cap) |
| 4747 | { |
| 4748 | switch (umr_fence_cap) { |
| 4749 | case MLX5_CAP_UMR_FENCE_NONE: |
| 4750 | return MLX5_FENCE_MODE_NONE; |
| 4751 | case MLX5_CAP_UMR_FENCE_SMALL: |
| 4752 | return MLX5_FENCE_MODE_INITIATOR_SMALL; |
| 4753 | default: |
| 4754 | return MLX5_FENCE_MODE_STRONG_ORDERING; |
| 4755 | } |
| 4756 | } |
| 4757 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4758 | static int create_dev_resources(struct mlx5_ib_resources *devr) |
| 4759 | { |
| 4760 | struct ib_srq_init_attr attr; |
| 4761 | struct mlx5_ib_dev *dev; |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4762 | struct ib_device *ibdev; |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 4763 | struct ib_cq_init_attr cq_attr = {.cqe = 1}; |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4764 | int port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4765 | int ret = 0; |
| 4766 | |
| 4767 | dev = container_of(devr, struct mlx5_ib_dev, devr); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4768 | ibdev = &dev->ib_dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4769 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4770 | mutex_init(&devr->mutex); |
| 4771 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4772 | devr->p0 = rdma_zalloc_drv_obj(ibdev, ib_pd); |
| 4773 | if (!devr->p0) |
| 4774 | return -ENOMEM; |
| 4775 | |
| 4776 | devr->p0->device = ibdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4777 | devr->p0->uobject = NULL; |
| 4778 | atomic_set(&devr->p0->usecnt, 0); |
| 4779 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4780 | ret = mlx5_ib_alloc_pd(devr->p0, NULL); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4781 | if (ret) |
| 4782 | goto error0; |
| 4783 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4784 | devr->c0 = mlx5_ib_create_cq(&dev->ib_dev, &cq_attr, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4785 | if (IS_ERR(devr->c0)) { |
| 4786 | ret = PTR_ERR(devr->c0); |
| 4787 | goto error1; |
| 4788 | } |
| 4789 | devr->c0->device = &dev->ib_dev; |
| 4790 | devr->c0->uobject = NULL; |
| 4791 | devr->c0->comp_handler = NULL; |
| 4792 | devr->c0->event_handler = NULL; |
| 4793 | devr->c0->cq_context = NULL; |
| 4794 | atomic_set(&devr->c0->usecnt, 0); |
| 4795 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4796 | devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4797 | if (IS_ERR(devr->x0)) { |
| 4798 | ret = PTR_ERR(devr->x0); |
| 4799 | goto error2; |
| 4800 | } |
| 4801 | devr->x0->device = &dev->ib_dev; |
| 4802 | devr->x0->inode = NULL; |
| 4803 | atomic_set(&devr->x0->usecnt, 0); |
| 4804 | mutex_init(&devr->x0->tgt_qp_mutex); |
| 4805 | INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
| 4806 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4807 | devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4808 | if (IS_ERR(devr->x1)) { |
| 4809 | ret = PTR_ERR(devr->x1); |
| 4810 | goto error3; |
| 4811 | } |
| 4812 | devr->x1->device = &dev->ib_dev; |
| 4813 | devr->x1->inode = NULL; |
| 4814 | atomic_set(&devr->x1->usecnt, 0); |
| 4815 | mutex_init(&devr->x1->tgt_qp_mutex); |
| 4816 | INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
| 4817 | |
| 4818 | memset(&attr, 0, sizeof(attr)); |
| 4819 | attr.attr.max_sge = 1; |
| 4820 | attr.attr.max_wr = 1; |
| 4821 | attr.srq_type = IB_SRQT_XRC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4822 | attr.ext.cq = devr->c0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4823 | attr.ext.xrc.xrcd = devr->x0; |
| 4824 | |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4825 | devr->s0 = rdma_zalloc_drv_obj(ibdev, ib_srq); |
| 4826 | if (!devr->s0) { |
| 4827 | ret = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4828 | goto error4; |
| 4829 | } |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4830 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4831 | devr->s0->device = &dev->ib_dev; |
| 4832 | devr->s0->pd = devr->p0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4833 | devr->s0->srq_type = IB_SRQT_XRC; |
| 4834 | devr->s0->ext.xrc.xrcd = devr->x0; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4835 | devr->s0->ext.cq = devr->c0; |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4836 | ret = mlx5_ib_create_srq(devr->s0, &attr, NULL); |
| 4837 | if (ret) |
| 4838 | goto err_create; |
| 4839 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4840 | atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4841 | atomic_inc(&devr->s0->ext.cq->usecnt); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4842 | atomic_inc(&devr->p0->usecnt); |
| 4843 | atomic_set(&devr->s0->usecnt, 0); |
| 4844 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4845 | memset(&attr, 0, sizeof(attr)); |
| 4846 | attr.attr.max_sge = 1; |
| 4847 | attr.attr.max_wr = 1; |
| 4848 | attr.srq_type = IB_SRQT_BASIC; |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4849 | devr->s1 = rdma_zalloc_drv_obj(ibdev, ib_srq); |
| 4850 | if (!devr->s1) { |
| 4851 | ret = -ENOMEM; |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4852 | goto error5; |
| 4853 | } |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4854 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4855 | devr->s1->device = &dev->ib_dev; |
| 4856 | devr->s1->pd = devr->p0; |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4857 | devr->s1->srq_type = IB_SRQT_BASIC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4858 | devr->s1->ext.cq = devr->c0; |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4859 | |
| 4860 | ret = mlx5_ib_create_srq(devr->s1, &attr, NULL); |
| 4861 | if (ret) |
| 4862 | goto error6; |
| 4863 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4864 | atomic_inc(&devr->p0->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4865 | atomic_set(&devr->s1->usecnt, 0); |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4866 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4867 | for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) { |
| 4868 | INIT_WORK(&devr->ports[port].pkey_change_work, |
| 4869 | pkey_change_handler); |
| 4870 | devr->ports[port].devr = devr; |
| 4871 | } |
| 4872 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4873 | return 0; |
| 4874 | |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4875 | error6: |
| 4876 | kfree(devr->s1); |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4877 | error5: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4878 | mlx5_ib_destroy_srq(devr->s0, NULL); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4879 | err_create: |
| 4880 | kfree(devr->s0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4881 | error4: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4882 | mlx5_ib_dealloc_xrcd(devr->x1, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4883 | error3: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4884 | mlx5_ib_dealloc_xrcd(devr->x0, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4885 | error2: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4886 | mlx5_ib_destroy_cq(devr->c0, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4887 | error1: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4888 | mlx5_ib_dealloc_pd(devr->p0, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4889 | error0: |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4890 | kfree(devr->p0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4891 | return ret; |
| 4892 | } |
| 4893 | |
| 4894 | static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
| 4895 | { |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4896 | int port; |
| 4897 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4898 | mlx5_ib_destroy_srq(devr->s1, NULL); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4899 | kfree(devr->s1); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4900 | mlx5_ib_destroy_srq(devr->s0, NULL); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 4901 | kfree(devr->s0); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4902 | mlx5_ib_dealloc_xrcd(devr->x0, NULL); |
| 4903 | mlx5_ib_dealloc_xrcd(devr->x1, NULL); |
| 4904 | mlx5_ib_destroy_cq(devr->c0, NULL); |
| 4905 | mlx5_ib_dealloc_pd(devr->p0, NULL); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4906 | kfree(devr->p0); |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4907 | |
| 4908 | /* Make sure no change P_Key work items are still executing */ |
Mark Bloch | 5d8f6a0 | 2019-03-28 15:27:36 +0200 | [diff] [blame] | 4909 | for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4910 | cancel_work_sync(&devr->ports[port].pkey_change_work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4911 | } |
| 4912 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4913 | static u32 get_core_cap_flags(struct ib_device *ibdev, |
| 4914 | struct mlx5_hca_vport_context *rep) |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4915 | { |
| 4916 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 4917 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, 1); |
| 4918 | u8 l3_type_cap = MLX5_CAP_ROCE(dev->mdev, l3_type); |
| 4919 | u8 roce_version_cap = MLX5_CAP_ROCE(dev->mdev, roce_version); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 4920 | bool raw_support = !mlx5_core_mp_enabled(dev->mdev); |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4921 | u32 ret = 0; |
| 4922 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4923 | if (rep->grh_required) |
| 4924 | ret |= RDMA_CORE_CAP_IB_GRH_REQUIRED; |
| 4925 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4926 | if (ll == IB_LINK_LAYER_INFINIBAND) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4927 | return ret | RDMA_CORE_PORT_IBA_IB; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4928 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 4929 | if (raw_support) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4930 | ret |= RDMA_CORE_PORT_RAW_PACKET; |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4931 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4932 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV4_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4933 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4934 | |
| 4935 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV6_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4936 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4937 | |
| 4938 | if (roce_version_cap & MLX5_ROCE_VERSION_1_CAP) |
| 4939 | ret |= RDMA_CORE_PORT_IBA_ROCE; |
| 4940 | |
| 4941 | if (roce_version_cap & MLX5_ROCE_VERSION_2_CAP) |
| 4942 | ret |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; |
| 4943 | |
| 4944 | return ret; |
| 4945 | } |
| 4946 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4947 | static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 4948 | struct ib_port_immutable *immutable) |
| 4949 | { |
| 4950 | struct ib_port_attr attr; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4951 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 4952 | 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] | 4953 | struct mlx5_hca_vport_context rep = {0}; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4954 | int err; |
| 4955 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 4956 | err = ib_query_port(ibdev, port_num, &attr); |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4957 | if (err) |
| 4958 | return err; |
| 4959 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4960 | if (ll == IB_LINK_LAYER_INFINIBAND) { |
| 4961 | err = mlx5_query_hca_vport_context(dev->mdev, 0, port_num, 0, |
| 4962 | &rep); |
| 4963 | if (err) |
| 4964 | return err; |
| 4965 | } |
| 4966 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4967 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 4968 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4969 | immutable->core_cap_flags = get_core_cap_flags(ibdev, &rep); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4970 | if ((ll == IB_LINK_LAYER_INFINIBAND) || MLX5_CAP_GEN(dev->mdev, roce)) |
| 4971 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4972 | |
| 4973 | return 0; |
| 4974 | } |
| 4975 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 4976 | static int mlx5_port_rep_immutable(struct ib_device *ibdev, u8 port_num, |
| 4977 | struct ib_port_immutable *immutable) |
| 4978 | { |
| 4979 | struct ib_port_attr attr; |
| 4980 | int err; |
| 4981 | |
| 4982 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 4983 | |
| 4984 | err = ib_query_port(ibdev, port_num, &attr); |
| 4985 | if (err) |
| 4986 | return err; |
| 4987 | |
| 4988 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 4989 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 4990 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 4991 | |
| 4992 | return 0; |
| 4993 | } |
| 4994 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 4995 | static void get_dev_fw_str(struct ib_device *ibdev, char *str) |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 4996 | { |
| 4997 | struct mlx5_ib_dev *dev = |
| 4998 | container_of(ibdev, struct mlx5_ib_dev, ib_dev); |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 4999 | snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%04d", |
| 5000 | fw_rev_maj(dev->mdev), fw_rev_min(dev->mdev), |
| 5001 | fw_rev_sub(dev->mdev)); |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 5002 | } |
| 5003 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5004 | static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5005 | { |
| 5006 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5007 | struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(mdev, |
| 5008 | MLX5_FLOW_NAMESPACE_LAG); |
| 5009 | struct mlx5_flow_table *ft; |
| 5010 | int err; |
| 5011 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 5012 | if (!ns || !mlx5_lag_is_roce(mdev)) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5013 | return 0; |
| 5014 | |
| 5015 | err = mlx5_cmd_create_vport_lag(mdev); |
| 5016 | if (err) |
| 5017 | return err; |
| 5018 | |
| 5019 | ft = mlx5_create_lag_demux_flow_table(ns, 0, 0); |
| 5020 | if (IS_ERR(ft)) { |
| 5021 | err = PTR_ERR(ft); |
| 5022 | goto err_destroy_vport_lag; |
| 5023 | } |
| 5024 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5025 | dev->flow_db->lag_demux_ft = ft; |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 5026 | dev->lag_active = true; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5027 | return 0; |
| 5028 | |
| 5029 | err_destroy_vport_lag: |
| 5030 | mlx5_cmd_destroy_vport_lag(mdev); |
| 5031 | return err; |
| 5032 | } |
| 5033 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5034 | static void mlx5_eth_lag_cleanup(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5035 | { |
| 5036 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5037 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 5038 | if (dev->lag_active) { |
| 5039 | dev->lag_active = false; |
| 5040 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5041 | mlx5_destroy_flow_table(dev->flow_db->lag_demux_ft); |
| 5042 | dev->flow_db->lag_demux_ft = NULL; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5043 | |
| 5044 | mlx5_cmd_destroy_vport_lag(mdev); |
| 5045 | } |
| 5046 | } |
| 5047 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5048 | 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] | 5049 | { |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5050 | int err; |
| 5051 | |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5052 | dev->port[port_num].roce.nb.notifier_call = mlx5_netdev_event; |
| 5053 | err = register_netdevice_notifier(&dev->port[port_num].roce.nb); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 5054 | if (err) { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5055 | dev->port[port_num].roce.nb.notifier_call = NULL; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5056 | return err; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 5057 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5058 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 5059 | return 0; |
| 5060 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5061 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5062 | 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] | 5063 | { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5064 | if (dev->port[port_num].roce.nb.notifier_call) { |
| 5065 | unregister_netdevice_notifier(&dev->port[port_num].roce.nb); |
| 5066 | dev->port[port_num].roce.nb.notifier_call = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5067 | } |
| 5068 | } |
| 5069 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5070 | static int mlx5_enable_eth(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5071 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5072 | int err; |
| 5073 | |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5074 | if (MLX5_CAP_GEN(dev->mdev, roce)) { |
| 5075 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 5076 | if (err) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5077 | return err; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5078 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5079 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5080 | err = mlx5_eth_lag_init(dev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5081 | if (err) |
| 5082 | goto err_disable_roce; |
| 5083 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5084 | return 0; |
| 5085 | |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5086 | err_disable_roce: |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5087 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 5088 | mlx5_nic_vport_disable_roce(dev->mdev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5089 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5090 | return err; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5091 | } |
| 5092 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5093 | static void mlx5_disable_eth(struct mlx5_ib_dev *dev) |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5094 | { |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5095 | mlx5_eth_lag_cleanup(dev); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5096 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 5097 | mlx5_nic_vport_disable_roce(dev->mdev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5098 | } |
| 5099 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5100 | struct mlx5_ib_counter { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5101 | const char *name; |
| 5102 | size_t offset; |
| 5103 | }; |
| 5104 | |
| 5105 | #define INIT_Q_COUNTER(_name) \ |
| 5106 | { .name = #_name, .offset = MLX5_BYTE_OFF(query_q_counter_out, _name)} |
| 5107 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5108 | static const struct mlx5_ib_counter basic_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5109 | INIT_Q_COUNTER(rx_write_requests), |
| 5110 | INIT_Q_COUNTER(rx_read_requests), |
| 5111 | INIT_Q_COUNTER(rx_atomic_requests), |
| 5112 | INIT_Q_COUNTER(out_of_buffer), |
| 5113 | }; |
| 5114 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5115 | static const struct mlx5_ib_counter out_of_seq_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5116 | INIT_Q_COUNTER(out_of_sequence), |
| 5117 | }; |
| 5118 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5119 | static const struct mlx5_ib_counter retrans_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5120 | INIT_Q_COUNTER(duplicate_request), |
| 5121 | INIT_Q_COUNTER(rnr_nak_retry_err), |
| 5122 | INIT_Q_COUNTER(packet_seq_err), |
| 5123 | INIT_Q_COUNTER(implied_nak_seq_err), |
| 5124 | INIT_Q_COUNTER(local_ack_timeout_err), |
| 5125 | }; |
| 5126 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5127 | #define INIT_CONG_COUNTER(_name) \ |
| 5128 | { .name = #_name, .offset = \ |
| 5129 | MLX5_BYTE_OFF(query_cong_statistics_out, _name ## _high)} |
| 5130 | |
| 5131 | static const struct mlx5_ib_counter cong_cnts[] = { |
| 5132 | INIT_CONG_COUNTER(rp_cnp_ignored), |
| 5133 | INIT_CONG_COUNTER(rp_cnp_handled), |
| 5134 | INIT_CONG_COUNTER(np_ecn_marked_roce_packets), |
| 5135 | INIT_CONG_COUNTER(np_cnp_sent), |
| 5136 | }; |
| 5137 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5138 | static const struct mlx5_ib_counter extended_err_cnts[] = { |
| 5139 | INIT_Q_COUNTER(resp_local_length_error), |
| 5140 | INIT_Q_COUNTER(resp_cqe_error), |
| 5141 | INIT_Q_COUNTER(req_cqe_error), |
| 5142 | INIT_Q_COUNTER(req_remote_invalid_request), |
| 5143 | INIT_Q_COUNTER(req_remote_access_errors), |
| 5144 | INIT_Q_COUNTER(resp_remote_access_errors), |
| 5145 | INIT_Q_COUNTER(resp_cqe_flush_error), |
| 5146 | INIT_Q_COUNTER(req_cqe_flush_error), |
| 5147 | }; |
| 5148 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5149 | #define INIT_EXT_PPCNT_COUNTER(_name) \ |
| 5150 | { .name = #_name, .offset = \ |
| 5151 | MLX5_BYTE_OFF(ppcnt_reg, \ |
| 5152 | counter_set.eth_extended_cntrs_grp_data_layout._name##_high)} |
| 5153 | |
| 5154 | static const struct mlx5_ib_counter ext_ppcnt_cnts[] = { |
| 5155 | INIT_EXT_PPCNT_COUNTER(rx_icrc_encapsulated), |
| 5156 | }; |
| 5157 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5158 | static void mlx5_ib_dealloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5159 | { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5160 | int i; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5161 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5162 | for (i = 0; i < dev->num_ports; i++) { |
Parav Pandit | 921c0f5 | 2018-07-08 13:40:30 +0300 | [diff] [blame] | 5163 | if (dev->port[i].cnts.set_id_valid) |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5164 | mlx5_core_dealloc_q_counter(dev->mdev, |
| 5165 | dev->port[i].cnts.set_id); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5166 | kfree(dev->port[i].cnts.names); |
| 5167 | kfree(dev->port[i].cnts.offsets); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5168 | } |
| 5169 | } |
| 5170 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5171 | static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, |
| 5172 | struct mlx5_ib_counters *cnts) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5173 | { |
| 5174 | u32 num_counters; |
| 5175 | |
| 5176 | num_counters = ARRAY_SIZE(basic_q_cnts); |
| 5177 | |
| 5178 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) |
| 5179 | num_counters += ARRAY_SIZE(out_of_seq_q_cnts); |
| 5180 | |
| 5181 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) |
| 5182 | num_counters += ARRAY_SIZE(retrans_q_cnts); |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5183 | |
| 5184 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) |
| 5185 | num_counters += ARRAY_SIZE(extended_err_cnts); |
| 5186 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5187 | cnts->num_q_counters = num_counters; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5188 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5189 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 5190 | cnts->num_cong_counters = ARRAY_SIZE(cong_cnts); |
| 5191 | num_counters += ARRAY_SIZE(cong_cnts); |
| 5192 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5193 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5194 | cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts); |
| 5195 | num_counters += ARRAY_SIZE(ext_ppcnt_cnts); |
| 5196 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5197 | cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL); |
| 5198 | if (!cnts->names) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5199 | return -ENOMEM; |
| 5200 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5201 | cnts->offsets = kcalloc(num_counters, |
| 5202 | sizeof(cnts->offsets), GFP_KERNEL); |
| 5203 | if (!cnts->offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5204 | goto err_names; |
| 5205 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5206 | return 0; |
| 5207 | |
| 5208 | err_names: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5209 | kfree(cnts->names); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5210 | cnts->names = NULL; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5211 | return -ENOMEM; |
| 5212 | } |
| 5213 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5214 | static void mlx5_ib_fill_counters(struct mlx5_ib_dev *dev, |
| 5215 | const char **names, |
| 5216 | size_t *offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5217 | { |
| 5218 | int i; |
| 5219 | int j = 0; |
| 5220 | |
| 5221 | for (i = 0; i < ARRAY_SIZE(basic_q_cnts); i++, j++) { |
| 5222 | names[j] = basic_q_cnts[i].name; |
| 5223 | offsets[j] = basic_q_cnts[i].offset; |
| 5224 | } |
| 5225 | |
| 5226 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) { |
| 5227 | for (i = 0; i < ARRAY_SIZE(out_of_seq_q_cnts); i++, j++) { |
| 5228 | names[j] = out_of_seq_q_cnts[i].name; |
| 5229 | offsets[j] = out_of_seq_q_cnts[i].offset; |
| 5230 | } |
| 5231 | } |
| 5232 | |
| 5233 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) { |
| 5234 | for (i = 0; i < ARRAY_SIZE(retrans_q_cnts); i++, j++) { |
| 5235 | names[j] = retrans_q_cnts[i].name; |
| 5236 | offsets[j] = retrans_q_cnts[i].offset; |
| 5237 | } |
| 5238 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5239 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5240 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) { |
| 5241 | for (i = 0; i < ARRAY_SIZE(extended_err_cnts); i++, j++) { |
| 5242 | names[j] = extended_err_cnts[i].name; |
| 5243 | offsets[j] = extended_err_cnts[i].offset; |
| 5244 | } |
| 5245 | } |
| 5246 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5247 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 5248 | for (i = 0; i < ARRAY_SIZE(cong_cnts); i++, j++) { |
| 5249 | names[j] = cong_cnts[i].name; |
| 5250 | offsets[j] = cong_cnts[i].offset; |
| 5251 | } |
| 5252 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5253 | |
| 5254 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5255 | for (i = 0; i < ARRAY_SIZE(ext_ppcnt_cnts); i++, j++) { |
| 5256 | names[j] = ext_ppcnt_cnts[i].name; |
| 5257 | offsets[j] = ext_ppcnt_cnts[i].offset; |
| 5258 | } |
| 5259 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5260 | } |
| 5261 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5262 | static int mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5263 | { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5264 | int err = 0; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5265 | int i; |
Yishai Hadas | aa74be6 | 2018-12-09 12:52:36 +0200 | [diff] [blame] | 5266 | bool is_shared; |
| 5267 | |
| 5268 | is_shared = MLX5_CAP_GEN(dev->mdev, log_max_uctx) != 0; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5269 | |
| 5270 | for (i = 0; i < dev->num_ports; i++) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5271 | err = __mlx5_ib_alloc_counters(dev, &dev->port[i].cnts); |
| 5272 | if (err) |
| 5273 | goto err_alloc; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5274 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5275 | mlx5_ib_fill_counters(dev, dev->port[i].cnts.names, |
| 5276 | dev->port[i].cnts.offsets); |
| 5277 | |
Yishai Hadas | aa74be6 | 2018-12-09 12:52:36 +0200 | [diff] [blame] | 5278 | err = mlx5_cmd_alloc_q_counter(dev->mdev, |
| 5279 | &dev->port[i].cnts.set_id, |
| 5280 | is_shared ? |
| 5281 | MLX5_SHARED_RESOURCE_UID : 0); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5282 | if (err) { |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5283 | mlx5_ib_warn(dev, |
| 5284 | "couldn't allocate queue counter for port %d, err %d\n", |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5285 | i + 1, err); |
| 5286 | goto err_alloc; |
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 | dev->port[i].cnts.set_id_valid = true; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | return 0; |
| 5292 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5293 | err_alloc: |
| 5294 | mlx5_ib_dealloc_counters(dev); |
| 5295 | return err; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5296 | } |
| 5297 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5298 | static struct rdma_hw_stats *mlx5_ib_alloc_hw_stats(struct ib_device *ibdev, |
| 5299 | u8 port_num) |
| 5300 | { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5301 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5302 | struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5303 | |
| 5304 | /* We support only per port stats */ |
| 5305 | if (port_num == 0) |
| 5306 | return NULL; |
| 5307 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5308 | return rdma_alloc_hw_stats_struct(port->cnts.names, |
| 5309 | port->cnts.num_q_counters + |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5310 | port->cnts.num_cong_counters + |
| 5311 | port->cnts.num_ext_ppcnt_counters, |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5312 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 5313 | } |
| 5314 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5315 | static int mlx5_ib_query_q_counters(struct mlx5_core_dev *mdev, |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5316 | struct mlx5_ib_port *port, |
| 5317 | struct rdma_hw_stats *stats) |
| 5318 | { |
| 5319 | int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); |
| 5320 | void *out; |
| 5321 | __be32 val; |
| 5322 | int ret, i; |
| 5323 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5324 | out = kvzalloc(outlen, GFP_KERNEL); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5325 | if (!out) |
| 5326 | return -ENOMEM; |
| 5327 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5328 | ret = mlx5_core_query_q_counter(mdev, |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5329 | port->cnts.set_id, 0, |
| 5330 | out, outlen); |
| 5331 | if (ret) |
| 5332 | goto free; |
| 5333 | |
| 5334 | for (i = 0; i < port->cnts.num_q_counters; i++) { |
| 5335 | val = *(__be32 *)(out + port->cnts.offsets[i]); |
| 5336 | stats->value[i] = (u64)be32_to_cpu(val); |
| 5337 | } |
| 5338 | |
| 5339 | free: |
| 5340 | kvfree(out); |
| 5341 | return ret; |
| 5342 | } |
| 5343 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5344 | static int mlx5_ib_query_ext_ppcnt_counters(struct mlx5_ib_dev *dev, |
| 5345 | struct mlx5_ib_port *port, |
| 5346 | struct rdma_hw_stats *stats) |
| 5347 | { |
| 5348 | int offset = port->cnts.num_q_counters + port->cnts.num_cong_counters; |
| 5349 | int sz = MLX5_ST_SZ_BYTES(ppcnt_reg); |
| 5350 | int ret, i; |
| 5351 | void *out; |
| 5352 | |
| 5353 | out = kvzalloc(sz, GFP_KERNEL); |
| 5354 | if (!out) |
| 5355 | return -ENOMEM; |
| 5356 | |
| 5357 | ret = mlx5_cmd_query_ext_ppcnt_counters(dev->mdev, out); |
| 5358 | if (ret) |
| 5359 | goto free; |
| 5360 | |
| 5361 | for (i = 0; i < port->cnts.num_ext_ppcnt_counters; i++) { |
| 5362 | stats->value[i + offset] = |
| 5363 | be64_to_cpup((__be64 *)(out + |
| 5364 | port->cnts.offsets[i + offset])); |
| 5365 | } |
| 5366 | |
| 5367 | free: |
| 5368 | kvfree(out); |
| 5369 | return ret; |
| 5370 | } |
| 5371 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5372 | static int mlx5_ib_get_hw_stats(struct ib_device *ibdev, |
| 5373 | struct rdma_hw_stats *stats, |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5374 | u8 port_num, int index) |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5375 | { |
| 5376 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5377 | struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5378 | struct mlx5_core_dev *mdev; |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5379 | int ret, num_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5380 | u8 mdev_port_num; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5381 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5382 | if (!stats) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5383 | return -EINVAL; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5384 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5385 | num_counters = port->cnts.num_q_counters + |
| 5386 | port->cnts.num_cong_counters + |
| 5387 | port->cnts.num_ext_ppcnt_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5388 | |
| 5389 | /* q_counters are per IB device, query the master mdev */ |
| 5390 | ret = mlx5_ib_query_q_counters(dev->mdev, port, stats); |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5391 | if (ret) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5392 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5393 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5394 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5395 | ret = mlx5_ib_query_ext_ppcnt_counters(dev, port, stats); |
| 5396 | if (ret) |
| 5397 | return ret; |
| 5398 | } |
| 5399 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5400 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5401 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, |
| 5402 | &mdev_port_num); |
| 5403 | if (!mdev) { |
| 5404 | /* If port is not affiliated yet, its in down state |
| 5405 | * which doesn't have any counters yet, so it would be |
| 5406 | * zero. So no need to read from the HCA. |
| 5407 | */ |
| 5408 | goto done; |
| 5409 | } |
Majd Dibbiny | 71a0ff6 | 2017-12-21 17:38:26 +0200 | [diff] [blame] | 5410 | ret = mlx5_lag_query_cong_counters(dev->mdev, |
| 5411 | stats->value + |
| 5412 | port->cnts.num_q_counters, |
| 5413 | port->cnts.num_cong_counters, |
| 5414 | port->cnts.offsets + |
| 5415 | port->cnts.num_q_counters); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5416 | |
| 5417 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5418 | if (ret) |
| 5419 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5420 | } |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5421 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5422 | done: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5423 | return num_counters; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5424 | } |
| 5425 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5426 | static int mlx5_ib_rn_get_params(struct ib_device *device, u8 port_num, |
| 5427 | enum rdma_netdev_t type, |
| 5428 | struct rdma_netdev_alloc_params *params) |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5429 | { |
| 5430 | if (type != RDMA_NETDEV_IPOIB) |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5431 | return -EOPNOTSUPP; |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5432 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5433 | return mlx5_rdma_rn_get_params(to_mdev(device)->mdev, device, params); |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5434 | } |
| 5435 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5436 | static void delay_drop_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 5437 | { |
| 5438 | if (!dev->delay_drop.dbg) |
| 5439 | return; |
| 5440 | debugfs_remove_recursive(dev->delay_drop.dbg->dir_debugfs); |
| 5441 | kfree(dev->delay_drop.dbg); |
| 5442 | dev->delay_drop.dbg = NULL; |
| 5443 | } |
| 5444 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5445 | static void cancel_delay_drop(struct mlx5_ib_dev *dev) |
| 5446 | { |
| 5447 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5448 | return; |
| 5449 | |
| 5450 | cancel_work_sync(&dev->delay_drop.delay_drop_work); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5451 | delay_drop_debugfs_cleanup(dev); |
| 5452 | } |
| 5453 | |
| 5454 | static ssize_t delay_drop_timeout_read(struct file *filp, char __user *buf, |
| 5455 | size_t count, loff_t *pos) |
| 5456 | { |
| 5457 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5458 | char lbuf[20]; |
| 5459 | int len; |
| 5460 | |
| 5461 | len = snprintf(lbuf, sizeof(lbuf), "%u\n", delay_drop->timeout); |
| 5462 | return simple_read_from_buffer(buf, count, pos, lbuf, len); |
| 5463 | } |
| 5464 | |
| 5465 | static ssize_t delay_drop_timeout_write(struct file *filp, const char __user *buf, |
| 5466 | size_t count, loff_t *pos) |
| 5467 | { |
| 5468 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5469 | u32 timeout; |
| 5470 | u32 var; |
| 5471 | |
| 5472 | if (kstrtouint_from_user(buf, count, 0, &var)) |
| 5473 | return -EFAULT; |
| 5474 | |
| 5475 | timeout = min_t(u32, roundup(var, 100), MLX5_MAX_DELAY_DROP_TIMEOUT_MS * |
| 5476 | 1000); |
| 5477 | if (timeout != var) |
| 5478 | mlx5_ib_dbg(delay_drop->dev, "Round delay drop timeout to %u usec\n", |
| 5479 | timeout); |
| 5480 | |
| 5481 | delay_drop->timeout = timeout; |
| 5482 | |
| 5483 | return count; |
| 5484 | } |
| 5485 | |
| 5486 | static const struct file_operations fops_delay_drop_timeout = { |
| 5487 | .owner = THIS_MODULE, |
| 5488 | .open = simple_open, |
| 5489 | .write = delay_drop_timeout_write, |
| 5490 | .read = delay_drop_timeout_read, |
| 5491 | }; |
| 5492 | |
| 5493 | static int delay_drop_debugfs_init(struct mlx5_ib_dev *dev) |
| 5494 | { |
| 5495 | struct mlx5_ib_dbg_delay_drop *dbg; |
| 5496 | |
| 5497 | if (!mlx5_debugfs_root) |
| 5498 | return 0; |
| 5499 | |
| 5500 | dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); |
| 5501 | if (!dbg) |
| 5502 | return -ENOMEM; |
| 5503 | |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5504 | dev->delay_drop.dbg = dbg; |
| 5505 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5506 | dbg->dir_debugfs = |
| 5507 | debugfs_create_dir("delay_drop", |
| 5508 | dev->mdev->priv.dbg_root); |
| 5509 | if (!dbg->dir_debugfs) |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5510 | goto out_debugfs; |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5511 | |
| 5512 | dbg->events_cnt_debugfs = |
| 5513 | debugfs_create_atomic_t("num_timeout_events", 0400, |
| 5514 | dbg->dir_debugfs, |
| 5515 | &dev->delay_drop.events_cnt); |
| 5516 | if (!dbg->events_cnt_debugfs) |
| 5517 | goto out_debugfs; |
| 5518 | |
| 5519 | dbg->rqs_cnt_debugfs = |
| 5520 | debugfs_create_atomic_t("num_rqs", 0400, |
| 5521 | dbg->dir_debugfs, |
| 5522 | &dev->delay_drop.rqs_cnt); |
| 5523 | if (!dbg->rqs_cnt_debugfs) |
| 5524 | goto out_debugfs; |
| 5525 | |
| 5526 | dbg->timeout_debugfs = |
| 5527 | debugfs_create_file("timeout", 0600, |
| 5528 | dbg->dir_debugfs, |
| 5529 | &dev->delay_drop, |
| 5530 | &fops_delay_drop_timeout); |
| 5531 | if (!dbg->timeout_debugfs) |
| 5532 | goto out_debugfs; |
| 5533 | |
| 5534 | return 0; |
| 5535 | |
| 5536 | out_debugfs: |
| 5537 | delay_drop_debugfs_cleanup(dev); |
| 5538 | return -ENOMEM; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5539 | } |
| 5540 | |
| 5541 | static void init_delay_drop(struct mlx5_ib_dev *dev) |
| 5542 | { |
| 5543 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5544 | return; |
| 5545 | |
| 5546 | mutex_init(&dev->delay_drop.lock); |
| 5547 | dev->delay_drop.dev = dev; |
| 5548 | dev->delay_drop.activate = false; |
| 5549 | dev->delay_drop.timeout = MLX5_MAX_DELAY_DROP_TIMEOUT_MS * 1000; |
| 5550 | INIT_WORK(&dev->delay_drop.delay_drop_work, delay_drop_handler); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5551 | atomic_set(&dev->delay_drop.rqs_cnt, 0); |
| 5552 | atomic_set(&dev->delay_drop.events_cnt, 0); |
| 5553 | |
| 5554 | if (delay_drop_debugfs_init(dev)) |
| 5555 | mlx5_ib_warn(dev, "Failed to init delay drop debugfs\n"); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5556 | } |
| 5557 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5558 | /* The mlx5_ib_multiport_mutex should be held when calling this function */ |
| 5559 | static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5560 | struct mlx5_ib_multiport_info *mpi) |
| 5561 | { |
| 5562 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5563 | struct mlx5_ib_port *port = &ibdev->port[port_num]; |
| 5564 | int comps; |
| 5565 | int err; |
| 5566 | int i; |
| 5567 | |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5568 | mlx5_ib_cleanup_cong_debugfs(ibdev, port_num); |
| 5569 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5570 | spin_lock(&port->mp.mpi_lock); |
| 5571 | if (!mpi->ibdev) { |
| 5572 | spin_unlock(&port->mp.mpi_lock); |
| 5573 | return; |
| 5574 | } |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5575 | |
| 5576 | if (mpi->mdev_events.notifier_call) |
| 5577 | mlx5_notifier_unregister(mpi->mdev, &mpi->mdev_events); |
| 5578 | mpi->mdev_events.notifier_call = NULL; |
| 5579 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5580 | mpi->ibdev = NULL; |
| 5581 | |
| 5582 | spin_unlock(&port->mp.mpi_lock); |
| 5583 | mlx5_remove_netdev_notifier(ibdev, port_num); |
| 5584 | spin_lock(&port->mp.mpi_lock); |
| 5585 | |
| 5586 | comps = mpi->mdev_refcnt; |
| 5587 | if (comps) { |
| 5588 | mpi->unaffiliate = true; |
| 5589 | init_completion(&mpi->unref_comp); |
| 5590 | spin_unlock(&port->mp.mpi_lock); |
| 5591 | |
| 5592 | for (i = 0; i < comps; i++) |
| 5593 | wait_for_completion(&mpi->unref_comp); |
| 5594 | |
| 5595 | spin_lock(&port->mp.mpi_lock); |
| 5596 | mpi->unaffiliate = false; |
| 5597 | } |
| 5598 | |
| 5599 | port->mp.mpi = NULL; |
| 5600 | |
| 5601 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 5602 | |
| 5603 | spin_unlock(&port->mp.mpi_lock); |
| 5604 | |
| 5605 | err = mlx5_nic_vport_unaffiliate_multiport(mpi->mdev); |
| 5606 | |
| 5607 | mlx5_ib_dbg(ibdev, "unaffiliated port %d\n", port_num + 1); |
| 5608 | /* Log an error, still needed to cleanup the pointers and add |
| 5609 | * it back to the list. |
| 5610 | */ |
| 5611 | if (err) |
| 5612 | mlx5_ib_err(ibdev, "Failed to unaffiliate port %u\n", |
| 5613 | port_num + 1); |
| 5614 | |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5615 | ibdev->port[port_num].roce.last_port_state = IB_PORT_DOWN; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5616 | } |
| 5617 | |
| 5618 | /* The mlx5_ib_multiport_mutex should be held when calling this function */ |
| 5619 | static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5620 | struct mlx5_ib_multiport_info *mpi) |
| 5621 | { |
| 5622 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5623 | int err; |
| 5624 | |
| 5625 | spin_lock(&ibdev->port[port_num].mp.mpi_lock); |
| 5626 | if (ibdev->port[port_num].mp.mpi) { |
Qing Huang | 2577188 | 2018-07-23 14:15:08 -0700 | [diff] [blame] | 5627 | mlx5_ib_dbg(ibdev, "port %d already affiliated.\n", |
| 5628 | port_num + 1); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5629 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5630 | return false; |
| 5631 | } |
| 5632 | |
| 5633 | ibdev->port[port_num].mp.mpi = mpi; |
| 5634 | mpi->ibdev = ibdev; |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5635 | mpi->mdev_events.notifier_call = NULL; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5636 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5637 | |
| 5638 | err = mlx5_nic_vport_affiliate_multiport(ibdev->mdev, mpi->mdev); |
| 5639 | if (err) |
| 5640 | goto unbind; |
| 5641 | |
| 5642 | err = get_port_caps(ibdev, mlx5_core_native_port_num(mpi->mdev)); |
| 5643 | if (err) |
| 5644 | goto unbind; |
| 5645 | |
| 5646 | err = mlx5_add_netdev_notifier(ibdev, port_num); |
| 5647 | if (err) { |
| 5648 | mlx5_ib_err(ibdev, "failed adding netdev notifier for port %u\n", |
| 5649 | port_num + 1); |
| 5650 | goto unbind; |
| 5651 | } |
| 5652 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5653 | mpi->mdev_events.notifier_call = mlx5_ib_event_slave_port; |
| 5654 | mlx5_notifier_register(mpi->mdev, &mpi->mdev_events); |
| 5655 | |
Greg Kroah-Hartman | 73eb8f0 | 2019-01-22 16:17:57 +0100 | [diff] [blame] | 5656 | mlx5_ib_init_cong_debugfs(ibdev, port_num); |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5657 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5658 | return true; |
| 5659 | |
| 5660 | unbind: |
| 5661 | mlx5_ib_unbind_slave_port(ibdev, mpi); |
| 5662 | return false; |
| 5663 | } |
| 5664 | |
| 5665 | static int mlx5_ib_init_multiport_master(struct mlx5_ib_dev *dev) |
| 5666 | { |
| 5667 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5668 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5669 | port_num + 1); |
| 5670 | struct mlx5_ib_multiport_info *mpi; |
| 5671 | int err; |
| 5672 | int i; |
| 5673 | |
| 5674 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5675 | return 0; |
| 5676 | |
| 5677 | err = mlx5_query_nic_vport_system_image_guid(dev->mdev, |
| 5678 | &dev->sys_image_guid); |
| 5679 | if (err) |
| 5680 | return err; |
| 5681 | |
| 5682 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 5683 | if (err) |
| 5684 | return err; |
| 5685 | |
| 5686 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5687 | for (i = 0; i < dev->num_ports; i++) { |
| 5688 | bool bound = false; |
| 5689 | |
| 5690 | /* build a stub multiport info struct for the native port. */ |
| 5691 | if (i == port_num) { |
| 5692 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 5693 | if (!mpi) { |
| 5694 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5695 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5696 | return -ENOMEM; |
| 5697 | } |
| 5698 | |
| 5699 | mpi->is_master = true; |
| 5700 | mpi->mdev = dev->mdev; |
| 5701 | mpi->sys_image_guid = dev->sys_image_guid; |
| 5702 | dev->port[i].mp.mpi = mpi; |
| 5703 | mpi->ibdev = dev; |
| 5704 | mpi = NULL; |
| 5705 | continue; |
| 5706 | } |
| 5707 | |
| 5708 | list_for_each_entry(mpi, &mlx5_ib_unaffiliated_port_list, |
| 5709 | list) { |
| 5710 | if (dev->sys_image_guid == mpi->sys_image_guid && |
| 5711 | (mlx5_core_native_port_num(mpi->mdev) - 1) == i) { |
| 5712 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 5713 | } |
| 5714 | |
| 5715 | if (bound) { |
| 5716 | dev_dbg(&mpi->mdev->pdev->dev, "removing port from unaffiliated list.\n"); |
| 5717 | mlx5_ib_dbg(dev, "port %d bound\n", i + 1); |
| 5718 | list_del(&mpi->list); |
| 5719 | break; |
| 5720 | } |
| 5721 | } |
| 5722 | if (!bound) { |
| 5723 | get_port_caps(dev, i + 1); |
| 5724 | mlx5_ib_dbg(dev, "no free port found for port %d\n", |
| 5725 | i + 1); |
| 5726 | } |
| 5727 | } |
| 5728 | |
| 5729 | list_add_tail(&dev->ib_dev_list, &mlx5_ib_dev_list); |
| 5730 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5731 | return err; |
| 5732 | } |
| 5733 | |
| 5734 | static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev) |
| 5735 | { |
| 5736 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5737 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5738 | port_num + 1); |
| 5739 | int i; |
| 5740 | |
| 5741 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5742 | return; |
| 5743 | |
| 5744 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5745 | for (i = 0; i < dev->num_ports; i++) { |
| 5746 | if (dev->port[i].mp.mpi) { |
| 5747 | /* Destroy the native port stub */ |
| 5748 | if (i == port_num) { |
| 5749 | kfree(dev->port[i].mp.mpi); |
| 5750 | dev->port[i].mp.mpi = NULL; |
| 5751 | } else { |
| 5752 | mlx5_ib_dbg(dev, "unbinding port_num: %d\n", i + 1); |
| 5753 | mlx5_ib_unbind_slave_port(dev, dev->port[i].mp.mpi); |
| 5754 | } |
| 5755 | } |
| 5756 | } |
| 5757 | |
| 5758 | mlx5_ib_dbg(dev, "removing from devlist\n"); |
| 5759 | list_del(&dev->ib_dev_list); |
| 5760 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5761 | |
| 5762 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5763 | } |
| 5764 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5765 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 5766 | mlx5_ib_dm, |
| 5767 | UVERBS_OBJECT_DM, |
| 5768 | UVERBS_METHOD_DM_ALLOC, |
| 5769 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 5770 | UVERBS_ATTR_TYPE(u64), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5771 | UA_MANDATORY), |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5772 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 5773 | UVERBS_ATTR_TYPE(u16), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5774 | UA_MANDATORY)); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5775 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5776 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 5777 | mlx5_ib_flow_action, |
| 5778 | UVERBS_OBJECT_FLOW_ACTION, |
| 5779 | UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, |
Jason Gunthorpe | bccd062 | 2018-07-26 16:37:14 -0600 | [diff] [blame] | 5780 | UVERBS_ATTR_FLAGS_IN(MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 5781 | enum mlx5_ib_uapi_flow_action_flags)); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 5782 | |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 5783 | static const struct uapi_definition mlx5_ib_defs[] = { |
| 5784 | #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) |
Jason Gunthorpe | 36e235c | 2018-11-12 22:59:53 +0200 | [diff] [blame] | 5785 | UAPI_DEF_CHAIN(mlx5_ib_devx_defs), |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 5786 | UAPI_DEF_CHAIN(mlx5_ib_flow_defs), |
| 5787 | #endif |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5788 | |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 5789 | UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_FLOW_ACTION, |
| 5790 | &mlx5_ib_flow_action), |
| 5791 | UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_DM, &mlx5_ib_dm), |
| 5792 | {} |
| 5793 | }; |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5794 | |
Raed Salem | 1a1e03d | 2018-05-31 16:43:41 +0300 | [diff] [blame] | 5795 | static int mlx5_ib_read_counters(struct ib_counters *counters, |
| 5796 | struct ib_counters_read_attr *read_attr, |
| 5797 | struct uverbs_attr_bundle *attrs) |
| 5798 | { |
| 5799 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 5800 | struct mlx5_read_counters_attr mread_attr = {}; |
| 5801 | struct mlx5_ib_flow_counters_desc *desc; |
| 5802 | int ret, i; |
| 5803 | |
| 5804 | mutex_lock(&mcounters->mcntrs_mutex); |
| 5805 | if (mcounters->cntrs_max_index > read_attr->ncounters) { |
| 5806 | ret = -EINVAL; |
| 5807 | goto err_bound; |
| 5808 | } |
| 5809 | |
| 5810 | mread_attr.out = kcalloc(mcounters->counters_num, sizeof(u64), |
| 5811 | GFP_KERNEL); |
| 5812 | if (!mread_attr.out) { |
| 5813 | ret = -ENOMEM; |
| 5814 | goto err_bound; |
| 5815 | } |
| 5816 | |
| 5817 | mread_attr.hw_cntrs_hndl = mcounters->hw_cntrs_hndl; |
| 5818 | mread_attr.flags = read_attr->flags; |
| 5819 | ret = mcounters->read_counters(counters->device, &mread_attr); |
| 5820 | if (ret) |
| 5821 | goto err_read; |
| 5822 | |
| 5823 | /* do the pass over the counters data array to assign according to the |
| 5824 | * descriptions and indexing pairs |
| 5825 | */ |
| 5826 | desc = mcounters->counters_data; |
| 5827 | for (i = 0; i < mcounters->ncounters; i++) |
| 5828 | read_attr->counters_buff[desc[i].index] += mread_attr.out[desc[i].description]; |
| 5829 | |
| 5830 | err_read: |
| 5831 | kfree(mread_attr.out); |
| 5832 | err_bound: |
| 5833 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 5834 | return ret; |
| 5835 | } |
| 5836 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5837 | static int mlx5_ib_destroy_counters(struct ib_counters *counters) |
| 5838 | { |
| 5839 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 5840 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 5841 | counters_clear_description(counters); |
| 5842 | if (mcounters->hw_cntrs_hndl) |
| 5843 | mlx5_fc_destroy(to_mdev(counters->device)->mdev, |
| 5844 | mcounters->hw_cntrs_hndl); |
| 5845 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5846 | kfree(mcounters); |
| 5847 | |
| 5848 | return 0; |
| 5849 | } |
| 5850 | |
| 5851 | static struct ib_counters *mlx5_ib_create_counters(struct ib_device *device, |
| 5852 | struct uverbs_attr_bundle *attrs) |
| 5853 | { |
| 5854 | struct mlx5_ib_mcounters *mcounters; |
| 5855 | |
| 5856 | mcounters = kzalloc(sizeof(*mcounters), GFP_KERNEL); |
| 5857 | if (!mcounters) |
| 5858 | return ERR_PTR(-ENOMEM); |
| 5859 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 5860 | mutex_init(&mcounters->mcntrs_mutex); |
| 5861 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5862 | return &mcounters->ibcntrs; |
| 5863 | } |
| 5864 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5865 | void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5866 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5867 | mlx5_ib_cleanup_multiport_master(dev); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5868 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
Yishai Hadas | 534fd7a | 2019-01-13 16:01:17 +0200 | [diff] [blame] | 5869 | srcu_barrier(&dev->mr_srcu); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5870 | cleanup_srcu_struct(&dev->mr_srcu); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5871 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5872 | } |
| 5873 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5874 | int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5875 | { |
| 5876 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5877 | int err; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5878 | int i; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5879 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5880 | for (i = 0; i < dev->num_ports; i++) { |
| 5881 | spin_lock_init(&dev->port[i].mp.mpi_lock); |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5882 | rwlock_init(&dev->port[i].roce.netdev_lock); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | err = mlx5_ib_init_multiport_master(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5886 | if (err) |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 5887 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5888 | |
Mark Bloch | a989ea0 | 2019-03-28 15:27:40 +0200 | [diff] [blame^] | 5889 | err = set_has_smi_cap(dev); |
| 5890 | if (err) |
| 5891 | return err; |
| 5892 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5893 | if (!mlx5_core_mp_enabled(mdev)) { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5894 | for (i = 1; i <= dev->num_ports; i++) { |
| 5895 | err = get_port_caps(dev, i); |
| 5896 | if (err) |
| 5897 | break; |
| 5898 | } |
| 5899 | } else { |
| 5900 | err = get_port_caps(dev, mlx5_core_native_port_num(mdev)); |
| 5901 | } |
| 5902 | if (err) |
| 5903 | goto err_mp; |
| 5904 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 5905 | if (mlx5_use_mad_ifc(dev)) |
| 5906 | get_ext_port_caps(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5907 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5908 | dev->ib_dev.owner = THIS_MODULE; |
| 5909 | dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Sagi Grimberg | c6790aa | 2015-09-24 10:34:23 +0300 | [diff] [blame] | 5910 | dev->ib_dev.local_dma_lkey = 0 /* not supported for now */; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 5911 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
Saeed Mahameed | f2f3df5 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 5912 | dev->ib_dev.num_comp_vectors = mlx5_comp_vectors_count(mdev); |
Bart Van Assche | 9b0c289 | 2017-01-20 13:04:21 -0800 | [diff] [blame] | 5913 | dev->ib_dev.dev.parent = &mdev->pdev->dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5914 | |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5915 | mutex_init(&dev->cap_mask_mutex); |
| 5916 | INIT_LIST_HEAD(&dev->qp_list); |
| 5917 | spin_lock_init(&dev->reset_flow_resource_lock); |
| 5918 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5919 | spin_lock_init(&dev->memic.memic_lock); |
| 5920 | dev->memic.dev = mdev; |
| 5921 | |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5922 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5923 | err = init_srcu_struct(&dev->mr_srcu); |
Moni Shoua | a6bc387 | 2019-02-17 16:08:22 +0200 | [diff] [blame] | 5924 | if (err) |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5925 | goto err_mp; |
Jason Gunthorpe | 623d154 | 2018-12-20 16:39:26 -0700 | [diff] [blame] | 5926 | } |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5927 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5928 | return 0; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5929 | err_mp: |
| 5930 | mlx5_ib_cleanup_multiport_master(dev); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5931 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5932 | return -ENOMEM; |
| 5933 | } |
| 5934 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5935 | static int mlx5_ib_stage_flow_db_init(struct mlx5_ib_dev *dev) |
| 5936 | { |
| 5937 | dev->flow_db = kzalloc(sizeof(*dev->flow_db), GFP_KERNEL); |
| 5938 | |
| 5939 | if (!dev->flow_db) |
| 5940 | return -ENOMEM; |
| 5941 | |
| 5942 | mutex_init(&dev->flow_db->lock); |
| 5943 | |
| 5944 | return 0; |
| 5945 | } |
| 5946 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5947 | int mlx5_ib_stage_rep_flow_db_init(struct mlx5_ib_dev *dev) |
| 5948 | { |
| 5949 | struct mlx5_ib_dev *nic_dev; |
| 5950 | |
| 5951 | nic_dev = mlx5_ib_get_uplink_ibdev(dev->mdev->priv.eswitch); |
| 5952 | |
| 5953 | if (!nic_dev) |
| 5954 | return -EINVAL; |
| 5955 | |
| 5956 | dev->flow_db = nic_dev->flow_db; |
| 5957 | |
| 5958 | return 0; |
| 5959 | } |
| 5960 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5961 | static void mlx5_ib_stage_flow_db_cleanup(struct mlx5_ib_dev *dev) |
| 5962 | { |
| 5963 | kfree(dev->flow_db); |
| 5964 | } |
| 5965 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 5966 | static const struct ib_device_ops mlx5_ib_dev_ops = { |
| 5967 | .add_gid = mlx5_ib_add_gid, |
| 5968 | .alloc_mr = mlx5_ib_alloc_mr, |
| 5969 | .alloc_pd = mlx5_ib_alloc_pd, |
| 5970 | .alloc_ucontext = mlx5_ib_alloc_ucontext, |
| 5971 | .attach_mcast = mlx5_ib_mcg_attach, |
| 5972 | .check_mr_status = mlx5_ib_check_mr_status, |
| 5973 | .create_ah = mlx5_ib_create_ah, |
| 5974 | .create_counters = mlx5_ib_create_counters, |
| 5975 | .create_cq = mlx5_ib_create_cq, |
| 5976 | .create_flow = mlx5_ib_create_flow, |
| 5977 | .create_qp = mlx5_ib_create_qp, |
| 5978 | .create_srq = mlx5_ib_create_srq, |
| 5979 | .dealloc_pd = mlx5_ib_dealloc_pd, |
| 5980 | .dealloc_ucontext = mlx5_ib_dealloc_ucontext, |
| 5981 | .del_gid = mlx5_ib_del_gid, |
| 5982 | .dereg_mr = mlx5_ib_dereg_mr, |
| 5983 | .destroy_ah = mlx5_ib_destroy_ah, |
| 5984 | .destroy_counters = mlx5_ib_destroy_counters, |
| 5985 | .destroy_cq = mlx5_ib_destroy_cq, |
| 5986 | .destroy_flow = mlx5_ib_destroy_flow, |
| 5987 | .destroy_flow_action = mlx5_ib_destroy_flow_action, |
| 5988 | .destroy_qp = mlx5_ib_destroy_qp, |
| 5989 | .destroy_srq = mlx5_ib_destroy_srq, |
| 5990 | .detach_mcast = mlx5_ib_mcg_detach, |
| 5991 | .disassociate_ucontext = mlx5_ib_disassociate_ucontext, |
| 5992 | .drain_rq = mlx5_ib_drain_rq, |
| 5993 | .drain_sq = mlx5_ib_drain_sq, |
| 5994 | .get_dev_fw_str = get_dev_fw_str, |
| 5995 | .get_dma_mr = mlx5_ib_get_dma_mr, |
| 5996 | .get_link_layer = mlx5_ib_port_link_layer, |
| 5997 | .map_mr_sg = mlx5_ib_map_mr_sg, |
| 5998 | .mmap = mlx5_ib_mmap, |
| 5999 | .modify_cq = mlx5_ib_modify_cq, |
| 6000 | .modify_device = mlx5_ib_modify_device, |
| 6001 | .modify_port = mlx5_ib_modify_port, |
| 6002 | .modify_qp = mlx5_ib_modify_qp, |
| 6003 | .modify_srq = mlx5_ib_modify_srq, |
| 6004 | .poll_cq = mlx5_ib_poll_cq, |
| 6005 | .post_recv = mlx5_ib_post_recv, |
| 6006 | .post_send = mlx5_ib_post_send, |
| 6007 | .post_srq_recv = mlx5_ib_post_srq_recv, |
| 6008 | .process_mad = mlx5_ib_process_mad, |
| 6009 | .query_ah = mlx5_ib_query_ah, |
| 6010 | .query_device = mlx5_ib_query_device, |
| 6011 | .query_gid = mlx5_ib_query_gid, |
| 6012 | .query_pkey = mlx5_ib_query_pkey, |
| 6013 | .query_qp = mlx5_ib_query_qp, |
| 6014 | .query_srq = mlx5_ib_query_srq, |
| 6015 | .read_counters = mlx5_ib_read_counters, |
| 6016 | .reg_user_mr = mlx5_ib_reg_user_mr, |
| 6017 | .req_notify_cq = mlx5_ib_arm_cq, |
| 6018 | .rereg_user_mr = mlx5_ib_rereg_user_mr, |
| 6019 | .resize_cq = mlx5_ib_resize_cq, |
Leon Romanovsky | d345691 | 2019-04-03 16:42:42 +0300 | [diff] [blame] | 6020 | |
| 6021 | INIT_RDMA_OBJ_SIZE(ib_ah, mlx5_ib_ah, ibah), |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 6022 | INIT_RDMA_OBJ_SIZE(ib_pd, mlx5_ib_pd, ibpd), |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 6023 | INIT_RDMA_OBJ_SIZE(ib_srq, mlx5_ib_srq, ibsrq), |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 6024 | INIT_RDMA_OBJ_SIZE(ib_ucontext, mlx5_ib_ucontext, ibucontext), |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6025 | }; |
| 6026 | |
| 6027 | static const struct ib_device_ops mlx5_ib_dev_flow_ipsec_ops = { |
| 6028 | .create_flow_action_esp = mlx5_ib_create_flow_action_esp, |
| 6029 | .modify_flow_action_esp = mlx5_ib_modify_flow_action_esp, |
| 6030 | }; |
| 6031 | |
| 6032 | static const struct ib_device_ops mlx5_ib_dev_ipoib_enhanced_ops = { |
| 6033 | .rdma_netdev_get_params = mlx5_ib_rn_get_params, |
| 6034 | }; |
| 6035 | |
| 6036 | static const struct ib_device_ops mlx5_ib_dev_sriov_ops = { |
| 6037 | .get_vf_config = mlx5_ib_get_vf_config, |
| 6038 | .get_vf_stats = mlx5_ib_get_vf_stats, |
| 6039 | .set_vf_guid = mlx5_ib_set_vf_guid, |
| 6040 | .set_vf_link_state = mlx5_ib_set_vf_link_state, |
| 6041 | }; |
| 6042 | |
| 6043 | static const struct ib_device_ops mlx5_ib_dev_mw_ops = { |
| 6044 | .alloc_mw = mlx5_ib_alloc_mw, |
| 6045 | .dealloc_mw = mlx5_ib_dealloc_mw, |
| 6046 | }; |
| 6047 | |
| 6048 | static const struct ib_device_ops mlx5_ib_dev_xrc_ops = { |
| 6049 | .alloc_xrcd = mlx5_ib_alloc_xrcd, |
| 6050 | .dealloc_xrcd = mlx5_ib_dealloc_xrcd, |
| 6051 | }; |
| 6052 | |
| 6053 | static const struct ib_device_ops mlx5_ib_dev_dm_ops = { |
| 6054 | .alloc_dm = mlx5_ib_alloc_dm, |
| 6055 | .dealloc_dm = mlx5_ib_dealloc_dm, |
| 6056 | .reg_dm_mr = mlx5_ib_reg_dm_mr, |
| 6057 | }; |
| 6058 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6059 | int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6060 | { |
| 6061 | struct mlx5_core_dev *mdev = dev->mdev; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6062 | int err; |
| 6063 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6064 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
| 6065 | dev->ib_dev.uverbs_cmd_mask = |
| 6066 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 6067 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 6068 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 6069 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 6070 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
Moni Shoua | 41c450f | 2016-11-23 08:23:26 +0200 | [diff] [blame] | 6071 | (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
| 6072 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6073 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 6074 | (1ull << IB_USER_VERBS_CMD_REREG_MR) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6075 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 6076 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 6077 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 6078 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 6079 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 6080 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 6081 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 6082 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 6083 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 6084 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 6085 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 6086 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 6087 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 6088 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 6089 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 6090 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 6091 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Haggai Eran | 1707cb4 | 2015-02-08 13:28:52 +0200 | [diff] [blame] | 6092 | dev->ib_dev.uverbs_ex_cmd_mask = |
Matan Barak | d4584dd | 2016-01-28 17:51:46 +0200 | [diff] [blame] | 6093 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE) | |
| 6094 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 6095 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) | |
Yonatan Cohen | b0e9df6 | 2017-11-13 10:51:15 +0200 | [diff] [blame] | 6096 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_QP) | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6097 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_CQ) | |
| 6098 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) | |
| 6099 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6100 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 6101 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
| 6102 | IS_ENABLED(CONFIG_MLX5_CORE_IPOIB)) |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6103 | ib_set_device_ops(&dev->ib_dev, |
| 6104 | &mlx5_ib_dev_ipoib_enhanced_ops); |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 6105 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6106 | if (mlx5_core_is_pf(mdev)) |
| 6107 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_sriov_ops); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 6108 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 6109 | dev->umr_fence = mlx5_get_umr_fence(MLX5_CAP_GEN(mdev, umr_fence)); |
| 6110 | |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6111 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6112 | dev->ib_dev.uverbs_cmd_mask |= |
| 6113 | (1ull << IB_USER_VERBS_CMD_ALLOC_MW) | |
| 6114 | (1ull << IB_USER_VERBS_CMD_DEALLOC_MW); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6115 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_mw_ops); |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6116 | } |
| 6117 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 6118 | if (MLX5_CAP_GEN(mdev, xrc)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6119 | dev->ib_dev.uverbs_cmd_mask |= |
| 6120 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 6121 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6122 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_xrc_ops); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6123 | } |
| 6124 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6125 | if (MLX5_CAP_DEV_MEM(mdev, memic)) |
| 6126 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_dm_ops); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 6127 | |
Jason Gunthorpe | dfb631a | 2018-11-12 22:59:49 +0200 | [diff] [blame] | 6128 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6129 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 6130 | 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] | 6131 | dev->ib_dev.driver_id = RDMA_DRIVER_MLX5; |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6132 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_ops); |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 6133 | |
Jason Gunthorpe | 36e235c | 2018-11-12 22:59:53 +0200 | [diff] [blame] | 6134 | if (IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)) |
| 6135 | dev->ib_dev.driver_def = mlx5_ib_defs; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6136 | |
| 6137 | err = init_node_data(dev); |
| 6138 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6139 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6140 | |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 6141 | 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] | 6142 | (MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) || |
| 6143 | MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 6144 | mutex_init(&dev->lb.mutex); |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 6145 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6146 | return 0; |
| 6147 | } |
| 6148 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6149 | static const struct ib_device_ops mlx5_ib_dev_port_ops = { |
| 6150 | .get_port_immutable = mlx5_port_immutable, |
| 6151 | .query_port = mlx5_ib_query_port, |
| 6152 | }; |
| 6153 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6154 | static int mlx5_ib_stage_non_default_cb(struct mlx5_ib_dev *dev) |
| 6155 | { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6156 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_port_ops); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6157 | return 0; |
| 6158 | } |
| 6159 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6160 | static const struct ib_device_ops mlx5_ib_dev_port_rep_ops = { |
| 6161 | .get_port_immutable = mlx5_port_rep_immutable, |
| 6162 | .query_port = mlx5_ib_rep_query_port, |
| 6163 | }; |
| 6164 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6165 | 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] | 6166 | { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6167 | 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] | 6168 | return 0; |
| 6169 | } |
| 6170 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6171 | static const struct ib_device_ops mlx5_ib_dev_common_roce_ops = { |
| 6172 | .create_rwq_ind_table = mlx5_ib_create_rwq_ind_table, |
| 6173 | .create_wq = mlx5_ib_create_wq, |
| 6174 | .destroy_rwq_ind_table = mlx5_ib_destroy_rwq_ind_table, |
| 6175 | .destroy_wq = mlx5_ib_destroy_wq, |
| 6176 | .get_netdev = mlx5_ib_get_netdev, |
| 6177 | .modify_wq = mlx5_ib_modify_wq, |
| 6178 | }; |
| 6179 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6180 | 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] | 6181 | { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6182 | u8 port_num; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6183 | int i; |
| 6184 | |
| 6185 | for (i = 0; i < dev->num_ports; i++) { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 6186 | dev->port[i].roce.dev = dev; |
| 6187 | dev->port[i].roce.native_port_num = i + 1; |
| 6188 | dev->port[i].roce.last_port_state = IB_PORT_DOWN; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6189 | } |
| 6190 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6191 | dev->ib_dev.uverbs_ex_cmd_mask |= |
| 6192 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_WQ) | |
| 6193 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_WQ) | |
| 6194 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_WQ) | |
| 6195 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) | |
| 6196 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6197 | 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] | 6198 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6199 | port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6200 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6201 | return mlx5_add_netdev_notifier(dev, port_num); |
| 6202 | } |
| 6203 | |
| 6204 | static void mlx5_ib_stage_common_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6205 | { |
| 6206 | u8 port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6207 | |
| 6208 | mlx5_remove_netdev_notifier(dev, port_num); |
| 6209 | } |
| 6210 | |
| 6211 | int mlx5_ib_stage_rep_roce_init(struct mlx5_ib_dev *dev) |
| 6212 | { |
| 6213 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6214 | enum rdma_link_layer ll; |
| 6215 | int port_type_cap; |
| 6216 | int err = 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6217 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6218 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6219 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6220 | |
| 6221 | if (ll == IB_LINK_LAYER_ETHERNET) |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6222 | err = mlx5_ib_stage_common_roce_init(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6223 | |
| 6224 | return err; |
| 6225 | } |
| 6226 | |
| 6227 | void mlx5_ib_stage_rep_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6228 | { |
| 6229 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 6230 | } |
| 6231 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6232 | static int mlx5_ib_stage_roce_init(struct mlx5_ib_dev *dev) |
| 6233 | { |
| 6234 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6235 | enum rdma_link_layer ll; |
| 6236 | int port_type_cap; |
| 6237 | int err; |
| 6238 | |
| 6239 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6240 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6241 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6242 | if (ll == IB_LINK_LAYER_ETHERNET) { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6243 | err = mlx5_ib_stage_common_roce_init(dev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6244 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6245 | return err; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6246 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6247 | err = mlx5_enable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6248 | if (err) |
| 6249 | goto cleanup; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6250 | } |
| 6251 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6252 | return 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6253 | cleanup: |
| 6254 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 6255 | |
| 6256 | return err; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6257 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6258 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6259 | static void mlx5_ib_stage_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6260 | { |
| 6261 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6262 | enum rdma_link_layer ll; |
| 6263 | int port_type_cap; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6264 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6265 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6266 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6267 | |
| 6268 | if (ll == IB_LINK_LAYER_ETHERNET) { |
| 6269 | mlx5_disable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6270 | mlx5_ib_stage_common_roce_cleanup(dev); |
Kamal Heib | 45bded2 | 2017-01-18 14:10:32 +0200 | [diff] [blame] | 6271 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6272 | } |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6273 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6274 | int mlx5_ib_stage_dev_res_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6275 | { |
| 6276 | return create_dev_resources(&dev->devr); |
| 6277 | } |
Parav Pandit | 4a2da0b | 2017-05-30 10:05:15 +0300 | [diff] [blame] | 6278 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6279 | void mlx5_ib_stage_dev_res_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6280 | { |
| 6281 | destroy_dev_resources(&dev->devr); |
| 6282 | } |
| 6283 | |
| 6284 | static int mlx5_ib_stage_odp_init(struct mlx5_ib_dev *dev) |
| 6285 | { |
Mark Bloch | 07321b3 | 2018-01-01 13:07:00 +0200 | [diff] [blame] | 6286 | mlx5_ib_internal_fill_odp_caps(dev); |
| 6287 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6288 | return mlx5_ib_odp_init_one(dev); |
| 6289 | } |
| 6290 | |
Kamal Heib | f3ffed0 | 2019-01-30 16:13:42 +0200 | [diff] [blame] | 6291 | static void mlx5_ib_stage_odp_cleanup(struct mlx5_ib_dev *dev) |
Saeed Mahameed | d5d284b | 2018-11-19 10:52:41 -0800 | [diff] [blame] | 6292 | { |
| 6293 | mlx5_ib_odp_cleanup_one(dev); |
| 6294 | } |
| 6295 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6296 | static const struct ib_device_ops mlx5_ib_dev_hw_stats_ops = { |
| 6297 | .alloc_hw_stats = mlx5_ib_alloc_hw_stats, |
| 6298 | .get_hw_stats = mlx5_ib_get_hw_stats, |
| 6299 | }; |
| 6300 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6301 | int mlx5_ib_stage_counters_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6302 | { |
Mark Bloch | 5e1e761 | 2018-01-01 13:07:01 +0200 | [diff] [blame] | 6303 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6304 | 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] | 6305 | |
| 6306 | return mlx5_ib_alloc_counters(dev); |
| 6307 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6308 | |
| 6309 | return 0; |
| 6310 | } |
| 6311 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6312 | void mlx5_ib_stage_counters_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6313 | { |
| 6314 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) |
| 6315 | mlx5_ib_dealloc_counters(dev); |
| 6316 | } |
| 6317 | |
| 6318 | static int mlx5_ib_stage_cong_debugfs_init(struct mlx5_ib_dev *dev) |
| 6319 | { |
Greg Kroah-Hartman | 73eb8f0 | 2019-01-22 16:17:57 +0100 | [diff] [blame] | 6320 | mlx5_ib_init_cong_debugfs(dev, |
| 6321 | mlx5_core_native_port_num(dev->mdev) - 1); |
| 6322 | return 0; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6323 | } |
| 6324 | |
| 6325 | static void mlx5_ib_stage_cong_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 6326 | { |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 6327 | mlx5_ib_cleanup_cong_debugfs(dev, |
| 6328 | mlx5_core_native_port_num(dev->mdev) - 1); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | static int mlx5_ib_stage_uar_init(struct mlx5_ib_dev *dev) |
| 6332 | { |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6333 | dev->mdev->priv.uar = mlx5_get_uars_page(dev->mdev); |
Leon Romanovsky | 444261c | 2018-04-23 17:01:56 +0300 | [diff] [blame] | 6334 | return PTR_ERR_OR_ZERO(dev->mdev->priv.uar); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6335 | } |
| 6336 | |
| 6337 | static void mlx5_ib_stage_uar_cleanup(struct mlx5_ib_dev *dev) |
| 6338 | { |
| 6339 | mlx5_put_uars_page(dev->mdev, dev->mdev->priv.uar); |
| 6340 | } |
| 6341 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6342 | int mlx5_ib_stage_bfrag_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6343 | { |
| 6344 | int err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6345 | |
| 6346 | err = mlx5_alloc_bfreg(dev->mdev, &dev->bfreg, false, false); |
| 6347 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6348 | return err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6349 | |
| 6350 | err = mlx5_alloc_bfreg(dev->mdev, &dev->fp_bfreg, false, true); |
| 6351 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6352 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6353 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6354 | return err; |
| 6355 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 6356 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6357 | void mlx5_ib_stage_bfrag_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6358 | { |
| 6359 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
| 6360 | mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
| 6361 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6362 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6363 | int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6364 | { |
Jason Gunthorpe | e349f85 | 2018-09-25 16:58:09 -0600 | [diff] [blame] | 6365 | const char *name; |
| 6366 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 6367 | rdma_set_device_sysfs_group(&dev->ib_dev, &mlx5_attr_group); |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 6368 | if (!mlx5_lag_is_roce(dev->mdev)) |
Jason Gunthorpe | e349f85 | 2018-09-25 16:58:09 -0600 | [diff] [blame] | 6369 | name = "mlx5_%d"; |
| 6370 | else |
| 6371 | name = "mlx5_bond_%d"; |
Parav Pandit | ea4baf7 | 2018-12-18 14:28:30 +0200 | [diff] [blame] | 6372 | return ib_register_device(&dev->ib_dev, name); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6373 | } |
| 6374 | |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6375 | 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] | 6376 | { |
| 6377 | destroy_umrc_res(dev); |
| 6378 | } |
| 6379 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6380 | void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6381 | { |
| 6382 | ib_unregister_device(&dev->ib_dev); |
| 6383 | } |
| 6384 | |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6385 | 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] | 6386 | { |
| 6387 | return create_umr_res(dev); |
| 6388 | } |
| 6389 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6390 | static int mlx5_ib_stage_delay_drop_init(struct mlx5_ib_dev *dev) |
| 6391 | { |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6392 | init_delay_drop(dev); |
| 6393 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6394 | return 0; |
| 6395 | } |
| 6396 | |
| 6397 | static void mlx5_ib_stage_delay_drop_cleanup(struct mlx5_ib_dev *dev) |
| 6398 | { |
| 6399 | cancel_delay_drop(dev); |
| 6400 | } |
| 6401 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6402 | static int mlx5_ib_stage_dev_notifier_init(struct mlx5_ib_dev *dev) |
| 6403 | { |
| 6404 | dev->mdev_events.notifier_call = mlx5_ib_event; |
| 6405 | mlx5_notifier_register(dev->mdev, &dev->mdev_events); |
| 6406 | return 0; |
| 6407 | } |
| 6408 | |
| 6409 | static void mlx5_ib_stage_dev_notifier_cleanup(struct mlx5_ib_dev *dev) |
| 6410 | { |
| 6411 | mlx5_notifier_unregister(dev->mdev, &dev->mdev_events); |
| 6412 | } |
| 6413 | |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6414 | static int mlx5_ib_stage_devx_init(struct mlx5_ib_dev *dev) |
| 6415 | { |
| 6416 | int uid; |
| 6417 | |
Yishai Hadas | fb98153 | 2018-11-26 08:28:36 +0200 | [diff] [blame] | 6418 | uid = mlx5_ib_devx_create(dev, false); |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6419 | if (uid > 0) |
| 6420 | dev->devx_whitelist_uid = uid; |
| 6421 | |
| 6422 | return 0; |
| 6423 | } |
| 6424 | static void mlx5_ib_stage_devx_cleanup(struct mlx5_ib_dev *dev) |
| 6425 | { |
| 6426 | if (dev->devx_whitelist_uid) |
| 6427 | mlx5_ib_devx_destroy(dev, dev->devx_whitelist_uid); |
| 6428 | } |
| 6429 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6430 | void __mlx5_ib_remove(struct mlx5_ib_dev *dev, |
| 6431 | const struct mlx5_ib_profile *profile, |
| 6432 | int stage) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6433 | { |
| 6434 | /* Number of stages to cleanup */ |
| 6435 | while (stage) { |
| 6436 | stage--; |
| 6437 | if (profile->stage[stage].cleanup) |
| 6438 | profile->stage[stage].cleanup(dev); |
| 6439 | } |
Mark Bloch | 4a6dc85 | 2019-03-28 15:27:34 +0200 | [diff] [blame] | 6440 | |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6441 | kfree(dev->port); |
Mark Bloch | 4a6dc85 | 2019-03-28 15:27:34 +0200 | [diff] [blame] | 6442 | ib_dealloc_device(&dev->ib_dev); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6443 | } |
| 6444 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6445 | void *__mlx5_ib_add(struct mlx5_ib_dev *dev, |
| 6446 | const struct mlx5_ib_profile *profile) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6447 | { |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6448 | int err; |
| 6449 | int i; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6450 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6451 | for (i = 0; i < MLX5_IB_STAGE_MAX; i++) { |
| 6452 | if (profile->stage[i].init) { |
| 6453 | err = profile->stage[i].init(dev); |
| 6454 | if (err) |
| 6455 | goto err_out; |
| 6456 | } |
| 6457 | } |
| 6458 | |
| 6459 | dev->profile = profile; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6460 | dev->ib_active = true; |
| 6461 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6462 | return dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6463 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6464 | err_out: |
| 6465 | __mlx5_ib_remove(dev, profile, i); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6466 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6467 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6468 | } |
| 6469 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6470 | static const struct mlx5_ib_profile pf_profile = { |
| 6471 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6472 | mlx5_ib_stage_init_init, |
| 6473 | mlx5_ib_stage_init_cleanup), |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 6474 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6475 | mlx5_ib_stage_flow_db_init, |
| 6476 | mlx5_ib_stage_flow_db_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6477 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6478 | mlx5_ib_stage_caps_init, |
| 6479 | NULL), |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6480 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6481 | mlx5_ib_stage_non_default_cb, |
| 6482 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6483 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6484 | mlx5_ib_stage_roce_init, |
| 6485 | mlx5_ib_stage_roce_cleanup), |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 6486 | STAGE_CREATE(MLX5_IB_STAGE_SRQ, |
| 6487 | mlx5_init_srq_table, |
| 6488 | mlx5_cleanup_srq_table), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6489 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6490 | mlx5_ib_stage_dev_res_init, |
| 6491 | mlx5_ib_stage_dev_res_cleanup), |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6492 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER, |
| 6493 | mlx5_ib_stage_dev_notifier_init, |
| 6494 | mlx5_ib_stage_dev_notifier_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6495 | STAGE_CREATE(MLX5_IB_STAGE_ODP, |
| 6496 | mlx5_ib_stage_odp_init, |
Saeed Mahameed | d5d284b | 2018-11-19 10:52:41 -0800 | [diff] [blame] | 6497 | mlx5_ib_stage_odp_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6498 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6499 | mlx5_ib_stage_counters_init, |
| 6500 | mlx5_ib_stage_counters_cleanup), |
| 6501 | STAGE_CREATE(MLX5_IB_STAGE_CONG_DEBUGFS, |
| 6502 | mlx5_ib_stage_cong_debugfs_init, |
| 6503 | mlx5_ib_stage_cong_debugfs_cleanup), |
| 6504 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6505 | mlx5_ib_stage_uar_init, |
| 6506 | mlx5_ib_stage_uar_cleanup), |
| 6507 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6508 | mlx5_ib_stage_bfrag_init, |
| 6509 | mlx5_ib_stage_bfrag_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6510 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6511 | NULL, |
| 6512 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6513 | STAGE_CREATE(MLX5_IB_STAGE_WHITELIST_UID, |
| 6514 | mlx5_ib_stage_devx_init, |
| 6515 | mlx5_ib_stage_devx_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6516 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6517 | mlx5_ib_stage_ib_reg_init, |
| 6518 | mlx5_ib_stage_ib_reg_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6519 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6520 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6521 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6522 | STAGE_CREATE(MLX5_IB_STAGE_DELAY_DROP, |
| 6523 | mlx5_ib_stage_delay_drop_init, |
| 6524 | mlx5_ib_stage_delay_drop_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6525 | }; |
| 6526 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6527 | const struct mlx5_ib_profile uplink_rep_profile = { |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6528 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6529 | mlx5_ib_stage_init_init, |
| 6530 | mlx5_ib_stage_init_cleanup), |
| 6531 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6532 | mlx5_ib_stage_flow_db_init, |
| 6533 | mlx5_ib_stage_flow_db_cleanup), |
| 6534 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6535 | mlx5_ib_stage_caps_init, |
| 6536 | NULL), |
| 6537 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6538 | mlx5_ib_stage_rep_non_default_cb, |
| 6539 | NULL), |
| 6540 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6541 | mlx5_ib_stage_rep_roce_init, |
| 6542 | mlx5_ib_stage_rep_roce_cleanup), |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 6543 | STAGE_CREATE(MLX5_IB_STAGE_SRQ, |
| 6544 | mlx5_init_srq_table, |
| 6545 | mlx5_cleanup_srq_table), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6546 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6547 | mlx5_ib_stage_dev_res_init, |
| 6548 | mlx5_ib_stage_dev_res_cleanup), |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6549 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER, |
| 6550 | mlx5_ib_stage_dev_notifier_init, |
| 6551 | mlx5_ib_stage_dev_notifier_cleanup), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6552 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6553 | mlx5_ib_stage_counters_init, |
| 6554 | mlx5_ib_stage_counters_cleanup), |
| 6555 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6556 | mlx5_ib_stage_uar_init, |
| 6557 | mlx5_ib_stage_uar_cleanup), |
| 6558 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6559 | mlx5_ib_stage_bfrag_init, |
| 6560 | mlx5_ib_stage_bfrag_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6561 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6562 | NULL, |
| 6563 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6564 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6565 | mlx5_ib_stage_ib_reg_init, |
| 6566 | mlx5_ib_stage_ib_reg_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6567 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6568 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6569 | NULL), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6570 | }; |
| 6571 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6572 | static void *mlx5_ib_add_slave_port(struct mlx5_core_dev *mdev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6573 | { |
| 6574 | struct mlx5_ib_multiport_info *mpi; |
| 6575 | struct mlx5_ib_dev *dev; |
| 6576 | bool bound = false; |
| 6577 | int err; |
| 6578 | |
| 6579 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 6580 | if (!mpi) |
| 6581 | return NULL; |
| 6582 | |
| 6583 | mpi->mdev = mdev; |
| 6584 | |
| 6585 | err = mlx5_query_nic_vport_system_image_guid(mdev, |
| 6586 | &mpi->sys_image_guid); |
| 6587 | if (err) { |
| 6588 | kfree(mpi); |
| 6589 | return NULL; |
| 6590 | } |
| 6591 | |
| 6592 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6593 | list_for_each_entry(dev, &mlx5_ib_dev_list, ib_dev_list) { |
| 6594 | if (dev->sys_image_guid == mpi->sys_image_guid) |
| 6595 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 6596 | |
| 6597 | if (bound) { |
| 6598 | rdma_roce_rescan_device(&dev->ib_dev); |
| 6599 | break; |
| 6600 | } |
| 6601 | } |
| 6602 | |
| 6603 | if (!bound) { |
| 6604 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 6605 | 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] | 6606 | } |
| 6607 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6608 | |
| 6609 | return mpi; |
| 6610 | } |
| 6611 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6612 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
| 6613 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6614 | enum rdma_link_layer ll; |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6615 | struct mlx5_ib_dev *dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6616 | int port_type_cap; |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6617 | int num_ports; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6618 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6619 | printk_once(KERN_INFO "%s", mlx5_version); |
| 6620 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6621 | if (MLX5_ESWITCH_MANAGER(mdev) && |
| 6622 | mlx5_ib_eswitch_mode(mdev->priv.eswitch) == SRIOV_OFFLOADS) { |
| 6623 | mlx5_ib_register_vport_reps(mdev); |
| 6624 | return mdev; |
| 6625 | } |
| 6626 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6627 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6628 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6629 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6630 | if (mlx5_core_is_mp_slave(mdev) && ll == IB_LINK_LAYER_ETHERNET) |
| 6631 | return mlx5_ib_add_slave_port(mdev); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6632 | |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6633 | num_ports = max(MLX5_CAP_GEN(mdev, num_ports), |
| 6634 | MLX5_CAP_GEN(mdev, num_vhca_ports)); |
Leon Romanovsky | 459cc69 | 2019-01-30 12:49:11 +0200 | [diff] [blame] | 6635 | dev = ib_alloc_device(mlx5_ib_dev, ib_dev); |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6636 | if (!dev) |
| 6637 | return NULL; |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6638 | dev->port = kcalloc(num_ports, sizeof(*dev->port), |
| 6639 | GFP_KERNEL); |
| 6640 | if (!dev->port) { |
| 6641 | ib_dealloc_device((struct ib_device *)dev); |
| 6642 | return NULL; |
| 6643 | } |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6644 | |
| 6645 | dev->mdev = mdev; |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6646 | dev->num_ports = num_ports; |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6647 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6648 | return __mlx5_ib_add(dev, &pf_profile); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6649 | } |
| 6650 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6651 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6652 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6653 | struct mlx5_ib_multiport_info *mpi; |
| 6654 | struct mlx5_ib_dev *dev; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6655 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6656 | if (MLX5_ESWITCH_MANAGER(mdev) && context == mdev) { |
| 6657 | mlx5_ib_unregister_vport_reps(mdev); |
| 6658 | return; |
| 6659 | } |
| 6660 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6661 | if (mlx5_core_is_mp_slave(mdev)) { |
| 6662 | mpi = context; |
| 6663 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6664 | if (mpi->ibdev) |
| 6665 | mlx5_ib_unbind_slave_port(mpi->ibdev, mpi); |
| 6666 | list_del(&mpi->list); |
| 6667 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6668 | return; |
| 6669 | } |
| 6670 | |
| 6671 | dev = context; |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6672 | __mlx5_ib_remove(dev, dev->profile, MLX5_IB_STAGE_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6673 | } |
| 6674 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6675 | static struct mlx5_interface mlx5_ib_interface = { |
| 6676 | .add = mlx5_ib_add, |
| 6677 | .remove = mlx5_ib_remove, |
Saeed Mahameed | 64613d94 | 2015-04-02 17:07:34 +0300 | [diff] [blame] | 6678 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6679 | }; |
| 6680 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6681 | unsigned long mlx5_ib_get_xlt_emergency_page(void) |
| 6682 | { |
| 6683 | mutex_lock(&xlt_emergency_page_mutex); |
| 6684 | return xlt_emergency_page; |
| 6685 | } |
| 6686 | |
| 6687 | void mlx5_ib_put_xlt_emergency_page(void) |
| 6688 | { |
| 6689 | mutex_unlock(&xlt_emergency_page_mutex); |
| 6690 | } |
| 6691 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6692 | static int __init mlx5_ib_init(void) |
| 6693 | { |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6694 | int err; |
| 6695 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6696 | xlt_emergency_page = __get_free_page(GFP_KERNEL); |
| 6697 | if (!xlt_emergency_page) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6698 | return -ENOMEM; |
| 6699 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6700 | mutex_init(&xlt_emergency_page_mutex); |
| 6701 | |
| 6702 | mlx5_ib_event_wq = alloc_ordered_workqueue("mlx5_ib_event_wq", 0); |
| 6703 | if (!mlx5_ib_event_wq) { |
| 6704 | free_page(xlt_emergency_page); |
| 6705 | return -ENOMEM; |
| 6706 | } |
| 6707 | |
Artemy Kovalyov | 81713d3 | 2017-01-18 16:58:11 +0200 | [diff] [blame] | 6708 | mlx5_ib_odp_init(); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6709 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6710 | err = mlx5_register_interface(&mlx5_ib_interface); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6711 | |
| 6712 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6713 | } |
| 6714 | |
| 6715 | static void __exit mlx5_ib_cleanup(void) |
| 6716 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6717 | mlx5_unregister_interface(&mlx5_ib_interface); |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6718 | destroy_workqueue(mlx5_ib_event_wq); |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6719 | mutex_destroy(&xlt_emergency_page_mutex); |
| 6720 | free_page(xlt_emergency_page); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | module_init(mlx5_ib_init); |
| 6724 | module_exit(mlx5_ib_cleanup); |