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 | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 55 | #include <linux/mlx5/eswitch.h> |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 56 | #include <linux/list.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 57 | #include <rdma/ib_smi.h> |
| 58 | #include <rdma/ib_umem.h> |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 59 | #include <linux/in.h> |
| 60 | #include <linux/etherdevice.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 61 | #include "mlx5_ib.h" |
Mark Bloch | fc385b7 | 2018-01-16 14:34:48 +0000 | [diff] [blame] | 62 | #include "ib_rep.h" |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 63 | #include "cmd.h" |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 64 | #include "srq.h" |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 65 | #include <linux/mlx5/fs_helpers.h> |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 66 | #include <linux/mlx5/accel.h> |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 67 | #include <rdma/uverbs_std_types.h> |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 68 | #include <rdma/mlx5_user_ioctl_verbs.h> |
| 69 | #include <rdma/mlx5_user_ioctl_cmds.h> |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 70 | |
| 71 | #define UVERBS_MODULE_NAME mlx5_ib |
| 72 | #include <rdma/uverbs_named_ioctl.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 73 | |
| 74 | #define DRIVER_NAME "mlx5_ib" |
Tariq Toukan | b359911 | 2017-02-22 17:45:46 +0200 | [diff] [blame] | 75 | #define DRIVER_VERSION "5.0-0" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 76 | |
| 77 | MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); |
| 78 | MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); |
| 79 | MODULE_LICENSE("Dual BSD/GPL"); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 80 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 81 | static char mlx5_version[] = |
| 82 | DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
Tariq Toukan | b359911 | 2017-02-22 17:45:46 +0200 | [diff] [blame] | 83 | DRIVER_VERSION "\n"; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 84 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 85 | struct mlx5_ib_event_work { |
| 86 | struct work_struct work; |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 87 | union { |
| 88 | struct mlx5_ib_dev *dev; |
| 89 | struct mlx5_ib_multiport_info *mpi; |
| 90 | }; |
| 91 | bool is_slave; |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 92 | unsigned int event; |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 93 | void *param; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 94 | }; |
| 95 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 96 | enum { |
| 97 | MLX5_ATOMIC_SIZE_QP_8BYTES = 1 << 3, |
| 98 | }; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 99 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 100 | static struct workqueue_struct *mlx5_ib_event_wq; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 101 | static LIST_HEAD(mlx5_ib_unaffiliated_port_list); |
| 102 | static LIST_HEAD(mlx5_ib_dev_list); |
| 103 | /* |
| 104 | * This mutex should be held when accessing either of the above lists |
| 105 | */ |
| 106 | static DEFINE_MUTEX(mlx5_ib_multiport_mutex); |
| 107 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 108 | /* We can't use an array for xlt_emergency_page because dma_map_single |
| 109 | * doesn't work on kernel modules memory |
| 110 | */ |
| 111 | static unsigned long xlt_emergency_page; |
| 112 | static struct mutex xlt_emergency_page_mutex; |
| 113 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 114 | struct mlx5_ib_dev *mlx5_ib_get_ibdev_from_mpi(struct mlx5_ib_multiport_info *mpi) |
| 115 | { |
| 116 | struct mlx5_ib_dev *dev; |
| 117 | |
| 118 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 119 | dev = mpi->ibdev; |
| 120 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 121 | return dev; |
| 122 | } |
| 123 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 124 | static enum rdma_link_layer |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 125 | mlx5_port_type_cap_to_rdma_ll(int port_type_cap) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 126 | { |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 127 | switch (port_type_cap) { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 128 | case MLX5_CAP_PORT_TYPE_IB: |
| 129 | return IB_LINK_LAYER_INFINIBAND; |
| 130 | case MLX5_CAP_PORT_TYPE_ETH: |
| 131 | return IB_LINK_LAYER_ETHERNET; |
| 132 | default: |
| 133 | return IB_LINK_LAYER_UNSPECIFIED; |
| 134 | } |
| 135 | } |
| 136 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 137 | static enum rdma_link_layer |
| 138 | mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num) |
| 139 | { |
| 140 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 141 | int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type); |
| 142 | |
| 143 | return mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 144 | } |
| 145 | |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 146 | static int get_port_state(struct ib_device *ibdev, |
| 147 | u8 port_num, |
| 148 | enum ib_port_state *state) |
| 149 | { |
| 150 | struct ib_port_attr attr; |
| 151 | int ret; |
| 152 | |
| 153 | memset(&attr, 0, sizeof(attr)); |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 154 | ret = ibdev->ops.query_port(ibdev, port_num, &attr); |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 155 | if (!ret) |
| 156 | *state = attr.state; |
| 157 | return ret; |
| 158 | } |
| 159 | |
Mark Bloch | 35b0aa6 | 2019-03-28 15:27:39 +0200 | [diff] [blame] | 160 | static struct mlx5_roce *mlx5_get_rep_roce(struct mlx5_ib_dev *dev, |
| 161 | struct net_device *ndev, |
| 162 | u8 *port_num) |
| 163 | { |
| 164 | struct mlx5_eswitch *esw = dev->mdev->priv.eswitch; |
| 165 | struct net_device *rep_ndev; |
| 166 | struct mlx5_ib_port *port; |
| 167 | int i; |
| 168 | |
| 169 | for (i = 0; i < dev->num_ports; i++) { |
| 170 | port = &dev->port[i]; |
| 171 | if (!port->rep) |
| 172 | continue; |
| 173 | |
| 174 | read_lock(&port->roce.netdev_lock); |
| 175 | rep_ndev = mlx5_ib_get_rep_netdev(esw, |
| 176 | port->rep->vport); |
| 177 | if (rep_ndev == ndev) { |
| 178 | read_unlock(&port->roce.netdev_lock); |
| 179 | *port_num = i + 1; |
| 180 | return &port->roce; |
| 181 | } |
| 182 | read_unlock(&port->roce.netdev_lock); |
| 183 | } |
| 184 | |
| 185 | return NULL; |
| 186 | } |
| 187 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 188 | static int mlx5_netdev_event(struct notifier_block *this, |
| 189 | unsigned long event, void *ptr) |
| 190 | { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 191 | struct mlx5_roce *roce = container_of(this, struct mlx5_roce, nb); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 192 | struct net_device *ndev = netdev_notifier_info_to_dev(ptr); |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 193 | u8 port_num = roce->native_port_num; |
| 194 | struct mlx5_core_dev *mdev; |
| 195 | struct mlx5_ib_dev *ibdev; |
| 196 | |
| 197 | ibdev = roce->dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 198 | mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL); |
| 199 | if (!mdev) |
| 200 | return NOTIFY_DONE; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 201 | |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 202 | switch (event) { |
| 203 | case NETDEV_REGISTER: |
Mark Bloch | 35b0aa6 | 2019-03-28 15:27:39 +0200 | [diff] [blame] | 204 | /* Should already be registered during the load */ |
| 205 | if (ibdev->is_rep) |
| 206 | break; |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 207 | write_lock(&roce->netdev_lock); |
Linus Torvalds | dce45af | 2019-05-09 09:02:46 -0700 | [diff] [blame] | 208 | if (ndev->dev.parent == mdev->device) |
Or Gerlitz | 842a9c8 | 2018-12-11 18:10:43 +0200 | [diff] [blame] | 209 | roce->netdev = ndev; |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 210 | write_unlock(&roce->netdev_lock); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 211 | break; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 212 | |
Or Gerlitz | 842a9c8 | 2018-12-11 18:10:43 +0200 | [diff] [blame] | 213 | case NETDEV_UNREGISTER: |
Mark Bloch | 35b0aa6 | 2019-03-28 15:27:39 +0200 | [diff] [blame] | 214 | /* In case of reps, ib device goes away before the netdevs */ |
Or Gerlitz | 842a9c8 | 2018-12-11 18:10:43 +0200 | [diff] [blame] | 215 | write_lock(&roce->netdev_lock); |
| 216 | if (roce->netdev == ndev) |
| 217 | roce->netdev = NULL; |
| 218 | write_unlock(&roce->netdev_lock); |
| 219 | break; |
| 220 | |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 221 | case NETDEV_CHANGE: |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 222 | case NETDEV_UP: |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 223 | case NETDEV_DOWN: { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 224 | struct net_device *lag_ndev = mlx5_lag_get_roce_netdev(mdev); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 225 | struct net_device *upper = NULL; |
| 226 | |
| 227 | if (lag_ndev) { |
| 228 | upper = netdev_master_upper_dev_get(lag_ndev); |
| 229 | dev_put(lag_ndev); |
| 230 | } |
| 231 | |
Mark Bloch | 35b0aa6 | 2019-03-28 15:27:39 +0200 | [diff] [blame] | 232 | if (ibdev->is_rep) |
| 233 | roce = mlx5_get_rep_roce(ibdev, ndev, &port_num); |
| 234 | if (!roce) |
| 235 | return NOTIFY_DONE; |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 236 | if ((upper == ndev || (!upper && ndev == roce->netdev)) |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 237 | && ibdev->ib_active) { |
Bart Van Assche | 626bc02 | 2016-12-05 17:18:08 -0800 | [diff] [blame] | 238 | struct ib_event ibev = { }; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 239 | enum ib_port_state port_state; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 240 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 241 | if (get_port_state(&ibdev->ib_dev, port_num, |
| 242 | &port_state)) |
| 243 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 244 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 245 | if (roce->last_port_state == port_state) |
| 246 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 247 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 248 | roce->last_port_state = port_state; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 249 | ibev.device = &ibdev->ib_dev; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 250 | if (port_state == IB_PORT_DOWN) |
| 251 | ibev.event = IB_EVENT_PORT_ERR; |
| 252 | else if (port_state == IB_PORT_ACTIVE) |
| 253 | ibev.event = IB_EVENT_PORT_ACTIVE; |
| 254 | else |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 255 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 256 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 257 | ibev.element.port_num = port_num; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 258 | ib_dispatch_event(&ibev); |
| 259 | } |
| 260 | break; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 261 | } |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 262 | |
| 263 | default: |
| 264 | break; |
| 265 | } |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 266 | done: |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 267 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 268 | return NOTIFY_DONE; |
| 269 | } |
| 270 | |
| 271 | static struct net_device *mlx5_ib_get_netdev(struct ib_device *device, |
| 272 | u8 port_num) |
| 273 | { |
| 274 | struct mlx5_ib_dev *ibdev = to_mdev(device); |
| 275 | struct net_device *ndev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 276 | struct mlx5_core_dev *mdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 277 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 278 | mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL); |
| 279 | if (!mdev) |
| 280 | return NULL; |
| 281 | |
| 282 | ndev = mlx5_lag_get_roce_netdev(mdev); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 283 | if (ndev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 284 | goto out; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 285 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 286 | /* Ensure ndev does not disappear before we invoke dev_hold() |
| 287 | */ |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 288 | read_lock(&ibdev->port[port_num - 1].roce.netdev_lock); |
| 289 | ndev = ibdev->port[port_num - 1].roce.netdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 290 | if (ndev) |
| 291 | dev_hold(ndev); |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 292 | read_unlock(&ibdev->port[port_num - 1].roce.netdev_lock); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 293 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 294 | out: |
| 295 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 296 | return ndev; |
| 297 | } |
| 298 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 299 | struct mlx5_core_dev *mlx5_ib_get_native_port_mdev(struct mlx5_ib_dev *ibdev, |
| 300 | u8 ib_port_num, |
| 301 | u8 *native_port_num) |
| 302 | { |
| 303 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&ibdev->ib_dev, |
| 304 | ib_port_num); |
| 305 | struct mlx5_core_dev *mdev = NULL; |
| 306 | struct mlx5_ib_multiport_info *mpi; |
| 307 | struct mlx5_ib_port *port; |
| 308 | |
Mark Bloch | 210b1f7 | 2018-03-05 20:09:47 +0200 | [diff] [blame] | 309 | if (!mlx5_core_mp_enabled(ibdev->mdev) || |
| 310 | ll != IB_LINK_LAYER_ETHERNET) { |
| 311 | if (native_port_num) |
| 312 | *native_port_num = ib_port_num; |
| 313 | return ibdev->mdev; |
| 314 | } |
| 315 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 316 | if (native_port_num) |
| 317 | *native_port_num = 1; |
| 318 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 319 | port = &ibdev->port[ib_port_num - 1]; |
| 320 | if (!port) |
| 321 | return NULL; |
| 322 | |
| 323 | spin_lock(&port->mp.mpi_lock); |
| 324 | mpi = ibdev->port[ib_port_num - 1].mp.mpi; |
| 325 | if (mpi && !mpi->unaffiliate) { |
| 326 | mdev = mpi->mdev; |
| 327 | /* If it's the master no need to refcount, it'll exist |
| 328 | * as long as the ib_dev exists. |
| 329 | */ |
| 330 | if (!mpi->is_master) |
| 331 | mpi->mdev_refcnt++; |
| 332 | } |
| 333 | spin_unlock(&port->mp.mpi_lock); |
| 334 | |
| 335 | return mdev; |
| 336 | } |
| 337 | |
| 338 | void mlx5_ib_put_native_port_mdev(struct mlx5_ib_dev *ibdev, u8 port_num) |
| 339 | { |
| 340 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&ibdev->ib_dev, |
| 341 | port_num); |
| 342 | struct mlx5_ib_multiport_info *mpi; |
| 343 | struct mlx5_ib_port *port; |
| 344 | |
| 345 | if (!mlx5_core_mp_enabled(ibdev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 346 | return; |
| 347 | |
| 348 | port = &ibdev->port[port_num - 1]; |
| 349 | |
| 350 | spin_lock(&port->mp.mpi_lock); |
| 351 | mpi = ibdev->port[port_num - 1].mp.mpi; |
| 352 | if (mpi->is_master) |
| 353 | goto out; |
| 354 | |
| 355 | mpi->mdev_refcnt--; |
| 356 | if (mpi->unaffiliate) |
| 357 | complete(&mpi->unref_comp); |
| 358 | out: |
| 359 | spin_unlock(&port->mp.mpi_lock); |
| 360 | } |
| 361 | |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 362 | static int translate_eth_legacy_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 363 | u8 *active_width) |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 364 | { |
| 365 | switch (eth_proto_oper) { |
| 366 | case MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII): |
| 367 | case MLX5E_PROT_MASK(MLX5E_1000BASE_KX): |
| 368 | case MLX5E_PROT_MASK(MLX5E_100BASE_TX): |
| 369 | case MLX5E_PROT_MASK(MLX5E_1000BASE_T): |
| 370 | *active_width = IB_WIDTH_1X; |
| 371 | *active_speed = IB_SPEED_SDR; |
| 372 | break; |
| 373 | case MLX5E_PROT_MASK(MLX5E_10GBASE_T): |
| 374 | case MLX5E_PROT_MASK(MLX5E_10GBASE_CX4): |
| 375 | case MLX5E_PROT_MASK(MLX5E_10GBASE_KX4): |
| 376 | case MLX5E_PROT_MASK(MLX5E_10GBASE_KR): |
| 377 | case MLX5E_PROT_MASK(MLX5E_10GBASE_CR): |
| 378 | case MLX5E_PROT_MASK(MLX5E_10GBASE_SR): |
| 379 | case MLX5E_PROT_MASK(MLX5E_10GBASE_ER): |
| 380 | *active_width = IB_WIDTH_1X; |
| 381 | *active_speed = IB_SPEED_QDR; |
| 382 | break; |
| 383 | case MLX5E_PROT_MASK(MLX5E_25GBASE_CR): |
| 384 | case MLX5E_PROT_MASK(MLX5E_25GBASE_KR): |
| 385 | case MLX5E_PROT_MASK(MLX5E_25GBASE_SR): |
| 386 | *active_width = IB_WIDTH_1X; |
| 387 | *active_speed = IB_SPEED_EDR; |
| 388 | break; |
| 389 | case MLX5E_PROT_MASK(MLX5E_40GBASE_CR4): |
| 390 | case MLX5E_PROT_MASK(MLX5E_40GBASE_KR4): |
| 391 | case MLX5E_PROT_MASK(MLX5E_40GBASE_SR4): |
| 392 | case MLX5E_PROT_MASK(MLX5E_40GBASE_LR4): |
| 393 | *active_width = IB_WIDTH_4X; |
| 394 | *active_speed = IB_SPEED_QDR; |
| 395 | break; |
| 396 | case MLX5E_PROT_MASK(MLX5E_50GBASE_CR2): |
| 397 | case MLX5E_PROT_MASK(MLX5E_50GBASE_KR2): |
| 398 | case MLX5E_PROT_MASK(MLX5E_50GBASE_SR2): |
| 399 | *active_width = IB_WIDTH_1X; |
| 400 | *active_speed = IB_SPEED_HDR; |
| 401 | break; |
| 402 | case MLX5E_PROT_MASK(MLX5E_56GBASE_R4): |
| 403 | *active_width = IB_WIDTH_4X; |
| 404 | *active_speed = IB_SPEED_FDR; |
| 405 | break; |
| 406 | case MLX5E_PROT_MASK(MLX5E_100GBASE_CR4): |
| 407 | case MLX5E_PROT_MASK(MLX5E_100GBASE_SR4): |
| 408 | case MLX5E_PROT_MASK(MLX5E_100GBASE_KR4): |
| 409 | case MLX5E_PROT_MASK(MLX5E_100GBASE_LR4): |
| 410 | *active_width = IB_WIDTH_4X; |
| 411 | *active_speed = IB_SPEED_EDR; |
| 412 | break; |
| 413 | default: |
| 414 | return -EINVAL; |
| 415 | } |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 420 | static int translate_eth_ext_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 421 | u8 *active_width) |
| 422 | { |
| 423 | switch (eth_proto_oper) { |
| 424 | case MLX5E_PROT_MASK(MLX5E_SGMII_100M): |
| 425 | case MLX5E_PROT_MASK(MLX5E_1000BASE_X_SGMII): |
| 426 | *active_width = IB_WIDTH_1X; |
| 427 | *active_speed = IB_SPEED_SDR; |
| 428 | break; |
| 429 | case MLX5E_PROT_MASK(MLX5E_5GBASE_R): |
| 430 | *active_width = IB_WIDTH_1X; |
| 431 | *active_speed = IB_SPEED_DDR; |
| 432 | break; |
| 433 | case MLX5E_PROT_MASK(MLX5E_10GBASE_XFI_XAUI_1): |
| 434 | *active_width = IB_WIDTH_1X; |
| 435 | *active_speed = IB_SPEED_QDR; |
| 436 | break; |
| 437 | case MLX5E_PROT_MASK(MLX5E_40GBASE_XLAUI_4_XLPPI_4): |
| 438 | *active_width = IB_WIDTH_4X; |
| 439 | *active_speed = IB_SPEED_QDR; |
| 440 | break; |
| 441 | case MLX5E_PROT_MASK(MLX5E_25GAUI_1_25GBASE_CR_KR): |
| 442 | *active_width = IB_WIDTH_1X; |
| 443 | *active_speed = IB_SPEED_EDR; |
| 444 | break; |
| 445 | case MLX5E_PROT_MASK(MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2): |
Aya Levin | cd27287 | 2019-03-11 14:35:58 +0200 | [diff] [blame] | 446 | *active_width = IB_WIDTH_2X; |
| 447 | *active_speed = IB_SPEED_EDR; |
| 448 | break; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 449 | case MLX5E_PROT_MASK(MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR): |
| 450 | *active_width = IB_WIDTH_1X; |
| 451 | *active_speed = IB_SPEED_HDR; |
| 452 | break; |
Aya Levin | cd27287 | 2019-03-11 14:35:58 +0200 | [diff] [blame] | 453 | case MLX5E_PROT_MASK(MLX5E_CAUI_4_100GBASE_CR4_KR4): |
| 454 | *active_width = IB_WIDTH_4X; |
| 455 | *active_speed = IB_SPEED_EDR; |
| 456 | break; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 457 | case MLX5E_PROT_MASK(MLX5E_100GAUI_2_100GBASE_CR2_KR2): |
| 458 | *active_width = IB_WIDTH_2X; |
| 459 | *active_speed = IB_SPEED_HDR; |
| 460 | break; |
| 461 | case MLX5E_PROT_MASK(MLX5E_200GAUI_4_200GBASE_CR4_KR4): |
| 462 | *active_width = IB_WIDTH_4X; |
| 463 | *active_speed = IB_SPEED_HDR; |
| 464 | break; |
| 465 | default: |
| 466 | return -EINVAL; |
| 467 | } |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | static int translate_eth_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 473 | u8 *active_width, bool ext) |
| 474 | { |
| 475 | return ext ? |
| 476 | translate_eth_ext_proto_oper(eth_proto_oper, active_speed, |
| 477 | active_width) : |
| 478 | translate_eth_legacy_proto_oper(eth_proto_oper, active_speed, |
| 479 | active_width); |
| 480 | } |
| 481 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 482 | static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, |
| 483 | struct ib_port_attr *props) |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 484 | { |
| 485 | struct mlx5_ib_dev *dev = to_mdev(device); |
Aya Levin | bc4e12f | 2019-02-12 22:55:43 -0800 | [diff] [blame] | 486 | u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {0}; |
Colin Ian King | da005f9 | 2018-01-09 15:55:43 +0000 | [diff] [blame] | 487 | struct mlx5_core_dev *mdev; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 488 | struct net_device *ndev, *upper; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 489 | enum ib_mtu ndev_ib_mtu; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 490 | bool put_mdev = true; |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 491 | u16 qkey_viol_cntr; |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 492 | u32 eth_prot_oper; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 493 | u8 mdev_port_num; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 494 | bool ext; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 495 | int err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 496 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 497 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 498 | if (!mdev) { |
| 499 | /* This means the port isn't affiliated yet. Get the |
| 500 | * info for the master port instead. |
| 501 | */ |
| 502 | put_mdev = false; |
| 503 | mdev = dev->mdev; |
| 504 | mdev_port_num = 1; |
| 505 | port_num = 1; |
| 506 | } |
| 507 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 508 | /* Possible bad flows are checked before filling out props so in case |
| 509 | * of an error it will still be zeroed out. |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 510 | * Use native port in case of reps |
Noa Osherovich | 50f22fd | 2017-04-20 20:53:32 +0300 | [diff] [blame] | 511 | */ |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 512 | if (dev->is_rep) |
| 513 | err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, |
| 514 | 1); |
| 515 | else |
| 516 | err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, |
| 517 | mdev_port_num); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 518 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 519 | goto out; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 520 | ext = MLX5_CAP_PCAM_FEATURE(dev->mdev, ptys_extended_ethernet); |
| 521 | 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] | 522 | |
Honggang Li | 7672ed3 | 2018-03-16 10:37:13 +0800 | [diff] [blame] | 523 | props->active_width = IB_WIDTH_4X; |
| 524 | props->active_speed = IB_SPEED_QDR; |
| 525 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 526 | translate_eth_proto_oper(eth_prot_oper, &props->active_speed, |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 527 | &props->active_width, ext); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 528 | |
Jason Gunthorpe | 2f944c0 | 2018-07-04 15:57:48 +0300 | [diff] [blame] | 529 | props->port_cap_flags |= IB_PORT_CM_SUP; |
| 530 | props->ip_gids = true; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 531 | |
| 532 | props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev, |
| 533 | roce_address_table_size); |
| 534 | props->max_mtu = IB_MTU_4096; |
| 535 | props->max_msg_sz = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg); |
| 536 | props->pkey_tbl_len = 1; |
| 537 | props->state = IB_PORT_DOWN; |
Kamal Heib | 72a7720 | 2019-08-07 13:31:35 +0300 | [diff] [blame] | 538 | props->phys_state = IB_PORT_PHYS_STATE_DISABLED; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 539 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 540 | mlx5_query_nic_vport_qkey_viol_cntr(mdev, &qkey_viol_cntr); |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 541 | props->qkey_viol_cntr = qkey_viol_cntr; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 542 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 543 | /* If this is a stub query for an unaffiliated port stop here */ |
| 544 | if (!put_mdev) |
| 545 | goto out; |
| 546 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 547 | ndev = mlx5_ib_get_netdev(device, port_num); |
| 548 | if (!ndev) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 549 | goto out; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 550 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 551 | if (dev->lag_active) { |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 552 | rcu_read_lock(); |
| 553 | upper = netdev_master_upper_dev_get_rcu(ndev); |
| 554 | if (upper) { |
| 555 | dev_put(ndev); |
| 556 | ndev = upper; |
| 557 | dev_hold(ndev); |
| 558 | } |
| 559 | rcu_read_unlock(); |
| 560 | } |
| 561 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 562 | if (netif_running(ndev) && netif_carrier_ok(ndev)) { |
| 563 | props->state = IB_PORT_ACTIVE; |
Kamal Heib | 72a7720 | 2019-08-07 13:31:35 +0300 | [diff] [blame] | 564 | props->phys_state = IB_PORT_PHYS_STATE_LINK_UP; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | ndev_ib_mtu = iboe_get_mtu(ndev->mtu); |
| 568 | |
| 569 | dev_put(ndev); |
| 570 | |
| 571 | props->active_mtu = min(props->max_mtu, ndev_ib_mtu); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 572 | out: |
| 573 | if (put_mdev) |
| 574 | mlx5_ib_put_native_port_mdev(dev, port_num); |
| 575 | return err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 576 | } |
| 577 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 578 | static int set_roce_addr(struct mlx5_ib_dev *dev, u8 port_num, |
| 579 | unsigned int index, const union ib_gid *gid, |
| 580 | const struct ib_gid_attr *attr) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 581 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 582 | enum ib_gid_type gid_type = IB_GID_TYPE_IB; |
Parav Pandit | a70c073 | 2019-05-02 10:48:03 +0300 | [diff] [blame] | 583 | u16 vlan_id = 0xffff; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 584 | u8 roce_version = 0; |
| 585 | u8 roce_l3_type = 0; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 586 | u8 mac[ETH_ALEN]; |
Parav Pandit | a70c073 | 2019-05-02 10:48:03 +0300 | [diff] [blame] | 587 | int ret; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 588 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 589 | if (gid) { |
| 590 | gid_type = attr->gid_type; |
Parav Pandit | a70c073 | 2019-05-02 10:48:03 +0300 | [diff] [blame] | 591 | ret = rdma_read_gid_l2_fields(attr, &vlan_id, &mac[0]); |
| 592 | if (ret) |
| 593 | return ret; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 594 | } |
| 595 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 596 | switch (gid_type) { |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 597 | case IB_GID_TYPE_IB: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 598 | roce_version = MLX5_ROCE_VERSION_1; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 599 | break; |
| 600 | case IB_GID_TYPE_ROCE_UDP_ENCAP: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 601 | roce_version = MLX5_ROCE_VERSION_2; |
| 602 | if (ipv6_addr_v4mapped((void *)gid)) |
| 603 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV4; |
| 604 | else |
| 605 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV6; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 606 | break; |
| 607 | |
| 608 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 609 | mlx5_ib_warn(dev, "Unexpected GID type %u\n", gid_type); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 610 | } |
| 611 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 612 | return mlx5_core_roce_gid_set(dev->mdev, index, roce_version, |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 613 | roce_l3_type, gid->raw, mac, |
Parav Pandit | a70c073 | 2019-05-02 10:48:03 +0300 | [diff] [blame] | 614 | vlan_id < VLAN_CFI_MASK, vlan_id, |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 615 | port_num); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 616 | } |
| 617 | |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 618 | static int mlx5_ib_add_gid(const struct ib_gid_attr *attr, |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 619 | __always_unused void **context) |
| 620 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 621 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 622 | attr->index, &attr->gid, attr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 623 | } |
| 624 | |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 625 | static int mlx5_ib_del_gid(const struct ib_gid_attr *attr, |
| 626 | __always_unused void **context) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 627 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 628 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
| 629 | attr->index, NULL, NULL); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 630 | } |
| 631 | |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 632 | __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, |
| 633 | const struct ib_gid_attr *attr) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 634 | { |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 635 | if (attr->gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 636 | return 0; |
| 637 | |
| 638 | return cpu_to_be16(MLX5_CAP_ROCE(dev->mdev, r_roce_min_src_udp_port)); |
| 639 | } |
| 640 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 641 | static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) |
| 642 | { |
Noa Osherovich | 7fae665 | 2016-09-12 19:16:23 +0300 | [diff] [blame] | 643 | if (MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_IB) |
| 644 | return !MLX5_CAP_GEN(dev->mdev, ib_virt); |
| 645 | return 0; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | enum { |
| 649 | MLX5_VPORT_ACCESS_METHOD_MAD, |
| 650 | MLX5_VPORT_ACCESS_METHOD_HCA, |
| 651 | MLX5_VPORT_ACCESS_METHOD_NIC, |
| 652 | }; |
| 653 | |
| 654 | static int mlx5_get_vport_access_method(struct ib_device *ibdev) |
| 655 | { |
| 656 | if (mlx5_use_mad_ifc(to_mdev(ibdev))) |
| 657 | return MLX5_VPORT_ACCESS_METHOD_MAD; |
| 658 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 659 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 660 | IB_LINK_LAYER_ETHERNET) |
| 661 | return MLX5_VPORT_ACCESS_METHOD_NIC; |
| 662 | |
| 663 | return MLX5_VPORT_ACCESS_METHOD_HCA; |
| 664 | } |
| 665 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 666 | static void get_atomic_caps(struct mlx5_ib_dev *dev, |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 667 | u8 atomic_size_qp, |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 668 | struct ib_device_attr *props) |
| 669 | { |
| 670 | u8 tmp; |
| 671 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 672 | u8 atomic_req_8B_endianness_mode = |
Or Gerlitz | bd10838 | 2017-05-28 15:24:17 +0300 | [diff] [blame] | 673 | MLX5_CAP_ATOMIC(dev->mdev, atomic_req_8B_endianness_mode); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 674 | |
| 675 | /* Check if HW supports 8 bytes standard atomic operations and capable |
| 676 | * of host endianness respond |
| 677 | */ |
| 678 | tmp = MLX5_ATOMIC_OPS_CMP_SWAP | MLX5_ATOMIC_OPS_FETCH_ADD; |
| 679 | if (((atomic_operations & tmp) == tmp) && |
| 680 | (atomic_size_qp & MLX5_ATOMIC_SIZE_QP_8BYTES) && |
| 681 | (atomic_req_8B_endianness_mode)) { |
| 682 | props->atomic_cap = IB_ATOMIC_HCA; |
| 683 | } else { |
| 684 | props->atomic_cap = IB_ATOMIC_NONE; |
| 685 | } |
| 686 | } |
| 687 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 688 | static void get_atomic_caps_qp(struct mlx5_ib_dev *dev, |
| 689 | struct ib_device_attr *props) |
| 690 | { |
| 691 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 692 | |
| 693 | get_atomic_caps(dev, atomic_size_qp, props); |
| 694 | } |
| 695 | |
| 696 | static void get_atomic_caps_dc(struct mlx5_ib_dev *dev, |
| 697 | struct ib_device_attr *props) |
| 698 | { |
| 699 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc); |
| 700 | |
| 701 | get_atomic_caps(dev, atomic_size_qp, props); |
| 702 | } |
| 703 | |
| 704 | bool mlx5_ib_dc_atomic_is_supported(struct mlx5_ib_dev *dev) |
| 705 | { |
| 706 | struct ib_device_attr props = {}; |
| 707 | |
| 708 | get_atomic_caps_dc(dev, &props); |
| 709 | return (props.atomic_cap == IB_ATOMIC_HCA) ? true : false; |
| 710 | } |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 711 | static int mlx5_query_system_image_guid(struct ib_device *ibdev, |
| 712 | __be64 *sys_image_guid) |
| 713 | { |
| 714 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 715 | struct mlx5_core_dev *mdev = dev->mdev; |
| 716 | u64 tmp; |
| 717 | int err; |
| 718 | |
| 719 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 720 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 721 | return mlx5_query_mad_ifc_system_image_guid(ibdev, |
| 722 | sys_image_guid); |
| 723 | |
| 724 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 725 | err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 729 | err = mlx5_query_nic_vport_system_image_guid(mdev, &tmp); |
| 730 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 731 | |
| 732 | default: |
| 733 | return -EINVAL; |
| 734 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 735 | |
| 736 | if (!err) |
| 737 | *sys_image_guid = cpu_to_be64(tmp); |
| 738 | |
| 739 | return err; |
| 740 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | static int mlx5_query_max_pkeys(struct ib_device *ibdev, |
| 744 | u16 *max_pkeys) |
| 745 | { |
| 746 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 747 | struct mlx5_core_dev *mdev = dev->mdev; |
| 748 | |
| 749 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 750 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 751 | return mlx5_query_mad_ifc_max_pkeys(ibdev, max_pkeys); |
| 752 | |
| 753 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 754 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 755 | *max_pkeys = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, |
| 756 | pkey_table_size)); |
| 757 | return 0; |
| 758 | |
| 759 | default: |
| 760 | return -EINVAL; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | static int mlx5_query_vendor_id(struct ib_device *ibdev, |
| 765 | u32 *vendor_id) |
| 766 | { |
| 767 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 768 | |
| 769 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 770 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 771 | return mlx5_query_mad_ifc_vendor_id(ibdev, vendor_id); |
| 772 | |
| 773 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 774 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 775 | return mlx5_core_query_vendor_id(dev->mdev, vendor_id); |
| 776 | |
| 777 | default: |
| 778 | return -EINVAL; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | static int mlx5_query_node_guid(struct mlx5_ib_dev *dev, |
| 783 | __be64 *node_guid) |
| 784 | { |
| 785 | u64 tmp; |
| 786 | int err; |
| 787 | |
| 788 | switch (mlx5_get_vport_access_method(&dev->ib_dev)) { |
| 789 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 790 | return mlx5_query_mad_ifc_node_guid(dev, node_guid); |
| 791 | |
| 792 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 793 | err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 794 | break; |
| 795 | |
| 796 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 797 | err = mlx5_query_nic_vport_node_guid(dev->mdev, &tmp); |
| 798 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 799 | |
| 800 | default: |
| 801 | return -EINVAL; |
| 802 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 803 | |
| 804 | if (!err) |
| 805 | *node_guid = cpu_to_be64(tmp); |
| 806 | |
| 807 | return err; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | struct mlx5_reg_node_desc { |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 811 | u8 desc[IB_DEVICE_NODE_DESC_MAX]; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 812 | }; |
| 813 | |
| 814 | static int mlx5_query_node_desc(struct mlx5_ib_dev *dev, char *node_desc) |
| 815 | { |
| 816 | struct mlx5_reg_node_desc in; |
| 817 | |
| 818 | if (mlx5_use_mad_ifc(dev)) |
| 819 | return mlx5_query_mad_ifc_node_desc(dev, node_desc); |
| 820 | |
| 821 | memset(&in, 0, sizeof(in)); |
| 822 | |
| 823 | return mlx5_core_access_reg(dev->mdev, &in, sizeof(in), node_desc, |
| 824 | sizeof(struct mlx5_reg_node_desc), |
| 825 | MLX5_REG_NODE_DESC, 0, 0); |
| 826 | } |
| 827 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 828 | static int mlx5_ib_query_device(struct ib_device *ibdev, |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 829 | struct ib_device_attr *props, |
| 830 | struct ib_udata *uhw) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 831 | { |
| 832 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 833 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 834 | int err = -ENOMEM; |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 835 | int max_sq_desc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 836 | int max_rq_sg; |
| 837 | int max_sq_sg; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 838 | u64 min_page_size = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 839 | bool raw_support = !mlx5_core_mp_enabled(mdev); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 840 | struct mlx5_ib_query_device_resp resp = {}; |
| 841 | size_t resp_len; |
| 842 | u64 max_tso; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 843 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 844 | resp_len = sizeof(resp.comp_mask) + sizeof(resp.response_length); |
| 845 | if (uhw->outlen && uhw->outlen < resp_len) |
| 846 | return -EINVAL; |
| 847 | else |
| 848 | resp.response_length = resp_len; |
| 849 | |
| 850 | if (uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen)) |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 851 | return -EINVAL; |
| 852 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 853 | memset(props, 0, sizeof(*props)); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 854 | err = mlx5_query_system_image_guid(ibdev, |
| 855 | &props->sys_image_guid); |
| 856 | if (err) |
| 857 | return err; |
| 858 | |
| 859 | err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys); |
| 860 | if (err) |
| 861 | return err; |
| 862 | |
| 863 | err = mlx5_query_vendor_id(ibdev, &props->vendor_id); |
| 864 | if (err) |
| 865 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 866 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 867 | props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) | |
| 868 | (fw_rev_min(dev->mdev) << 16) | |
| 869 | fw_rev_sub(dev->mdev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 870 | props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | |
| 871 | IB_DEVICE_PORT_ACTIVE_EVENT | |
| 872 | IB_DEVICE_SYS_IMAGE_GUID | |
Eli Cohen | 1a4c3a3 | 2014-02-06 17:41:25 +0200 | [diff] [blame] | 873 | IB_DEVICE_RC_RNR_NAK_GEN; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 874 | |
| 875 | if (MLX5_CAP_GEN(mdev, pkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 876 | props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 877 | if (MLX5_CAP_GEN(mdev, qkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 878 | props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 879 | if (MLX5_CAP_GEN(mdev, apm)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 880 | props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 881 | if (MLX5_CAP_GEN(mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 882 | props->device_cap_flags |= IB_DEVICE_XRC; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 883 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
| 884 | props->device_cap_flags |= IB_DEVICE_MEM_WINDOW | |
| 885 | IB_DEVICE_MEM_WINDOW_TYPE_2B; |
| 886 | props->max_mw = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 887 | /* We support 'Gappy' memory registration too */ |
| 888 | props->device_cap_flags |= IB_DEVICE_SG_GAPS_REG; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 889 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 890 | props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 891 | if (MLX5_CAP_GEN(mdev, sho)) { |
Israel Rukshin | c0a6cbb | 2019-06-11 18:52:50 +0300 | [diff] [blame] | 892 | props->device_cap_flags |= IB_DEVICE_INTEGRITY_HANDOVER; |
Sagi Grimberg | 2dea909 | 2014-02-23 14:19:13 +0200 | [diff] [blame] | 893 | /* At this stage no support for signature handover */ |
| 894 | props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 | |
| 895 | IB_PROT_T10DIF_TYPE_2 | |
| 896 | IB_PROT_T10DIF_TYPE_3; |
| 897 | props->sig_guard_cap = IB_GUARD_T10DIF_CRC | |
| 898 | IB_GUARD_T10DIF_CSUM; |
| 899 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 900 | if (MLX5_CAP_GEN(mdev, block_lb_mc)) |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 901 | props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 902 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 903 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 904 | if (MLX5_CAP_ETH(mdev, csum_cap)) { |
| 905 | /* Legacy bit to support old userspace libraries */ |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 906 | props->device_cap_flags |= IB_DEVICE_RAW_IP_CSUM; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 907 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_IP_CSUM; |
| 908 | } |
| 909 | |
| 910 | if (MLX5_CAP_ETH(dev->mdev, vlan_cap)) |
| 911 | props->raw_packet_caps |= |
| 912 | IB_RAW_PACKET_CAP_CVLAN_STRIPPING; |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 913 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 914 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) { |
| 915 | max_tso = MLX5_CAP_ETH(mdev, max_lso_cap); |
| 916 | if (max_tso) { |
| 917 | resp.tso_caps.max_tso = 1 << max_tso; |
| 918 | resp.tso_caps.supported_qpts |= |
| 919 | 1 << IB_QPT_RAW_PACKET; |
| 920 | resp.response_length += sizeof(resp.tso_caps); |
| 921 | } |
| 922 | } |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 923 | |
| 924 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) { |
| 925 | resp.rss_caps.rx_hash_function = |
| 926 | MLX5_RX_HASH_FUNC_TOEPLITZ; |
| 927 | resp.rss_caps.rx_hash_fields_mask = |
| 928 | MLX5_RX_HASH_SRC_IPV4 | |
| 929 | MLX5_RX_HASH_DST_IPV4 | |
| 930 | MLX5_RX_HASH_SRC_IPV6 | |
| 931 | MLX5_RX_HASH_DST_IPV6 | |
| 932 | MLX5_RX_HASH_SRC_PORT_TCP | |
| 933 | MLX5_RX_HASH_DST_PORT_TCP | |
| 934 | MLX5_RX_HASH_SRC_PORT_UDP | |
Maor Gottlieb | 4e2b53a | 2017-12-24 14:51:25 +0200 | [diff] [blame] | 935 | MLX5_RX_HASH_DST_PORT_UDP | |
| 936 | MLX5_RX_HASH_INNER; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 937 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
| 938 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 939 | resp.rss_caps.rx_hash_fields_mask |= |
| 940 | MLX5_RX_HASH_IPSEC_SPI; |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 941 | resp.response_length += sizeof(resp.rss_caps); |
| 942 | } |
| 943 | } else { |
| 944 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) |
| 945 | resp.response_length += sizeof(resp.tso_caps); |
| 946 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) |
| 947 | resp.response_length += sizeof(resp.rss_caps); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 948 | } |
| 949 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 950 | if (MLX5_CAP_GEN(mdev, ipoib_basic_offloads)) { |
| 951 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 952 | props->device_cap_flags |= IB_DEVICE_UD_TSO; |
| 953 | } |
| 954 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 955 | if (MLX5_CAP_GEN(dev->mdev, rq_delay_drop) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 956 | MLX5_CAP_GEN(dev->mdev, general_notification_event) && |
| 957 | raw_support) |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 958 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_DELAY_DROP; |
| 959 | |
Yishai Hadas | 1d54f89 | 2017-06-08 16:15:11 +0300 | [diff] [blame] | 960 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
| 961 | MLX5_CAP_IPOIB_ENHANCED(mdev, csum_cap)) |
| 962 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 963 | |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 964 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 965 | MLX5_CAP_ETH(dev->mdev, scatter_fcs) && |
| 966 | raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 967 | /* Legacy bit to support old userspace libraries */ |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 968 | props->device_cap_flags |= IB_DEVICE_RAW_SCATTER_FCS; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 969 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_SCATTER_FCS; |
| 970 | } |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 971 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 972 | if (MLX5_CAP_DEV_MEM(mdev, memic)) { |
| 973 | props->max_dm_size = |
| 974 | MLX5_CAP_DEV_MEM(mdev, max_memic_size); |
| 975 | } |
| 976 | |
Maor Gottlieb | da6d6ba3 | 2016-06-04 15:15:28 +0300 | [diff] [blame] | 977 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_BYPASS)) |
| 978 | props->device_cap_flags |= IB_DEVICE_MANAGED_FLOW_STEERING; |
| 979 | |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 980 | if (MLX5_CAP_GEN(mdev, end_pad)) |
| 981 | props->device_cap_flags |= IB_DEVICE_PCI_WRITE_END_PADDING; |
| 982 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 983 | props->vendor_part_id = mdev->pdev->device; |
| 984 | props->hw_ver = mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 985 | |
| 986 | props->max_mr_size = ~0ull; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 987 | props->page_size_cap = ~(min_page_size - 1); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 988 | props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp); |
| 989 | props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
| 990 | max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) / |
| 991 | sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 992 | max_sq_desc = min_t(int, MLX5_CAP_GEN(mdev, max_wqe_sz_sq), 512); |
| 993 | max_sq_sg = (max_sq_desc - sizeof(struct mlx5_wqe_ctrl_seg) - |
| 994 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 995 | sizeof(struct mlx5_wqe_data_seg); |
Steve Wise | 33023fb | 2018-06-18 08:05:26 -0700 | [diff] [blame] | 996 | props->max_send_sge = max_sq_sg; |
| 997 | props->max_recv_sge = max_rq_sg; |
Sagi Grimberg | 986ef95 | 2016-03-31 19:03:25 +0300 | [diff] [blame] | 998 | props->max_sge_rd = MLX5_MAX_SGE_RD; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 999 | props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq); |
Leon Romanovsky | 9f17768 | 2016-01-14 08:11:40 +0200 | [diff] [blame] | 1000 | 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] | 1001 | props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
| 1002 | props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd); |
| 1003 | props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp); |
| 1004 | props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp); |
| 1005 | props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq); |
| 1006 | props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1; |
| 1007 | 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] | 1008 | 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] | 1009 | props->max_srq_sge = max_rq_sg - 1; |
Sagi Grimberg | 911f433 | 2016-03-03 13:37:51 +0200 | [diff] [blame] | 1010 | props->max_fast_reg_page_list_len = |
| 1011 | 1 << MLX5_CAP_GEN(mdev, log_max_klm_list_size); |
Max Gurtovoy | 62e3c37 | 2019-06-11 18:52:43 +0300 | [diff] [blame] | 1012 | props->max_pi_fast_reg_page_list_len = |
| 1013 | props->max_fast_reg_page_list_len / 2; |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 1014 | get_atomic_caps_qp(dev, props); |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 1015 | props->masked_atomic_cap = IB_ATOMIC_NONE; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1016 | props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg); |
| 1017 | props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1018 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 1019 | props->max_mcast_grp; |
| 1020 | props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */ |
Maor Gottlieb | 86695a6 | 2016-10-27 16:36:38 +0300 | [diff] [blame] | 1021 | props->max_ah = INT_MAX; |
Matan Barak | 7c60bcb | 2015-12-15 20:30:11 +0200 | [diff] [blame] | 1022 | props->hca_core_clock = MLX5_CAP_GEN(mdev, device_frequency_khz); |
| 1023 | props->timestamp_mask = 0x7FFFFFFFFFFFFFFFULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1024 | |
Leon Romanovsky | e502b8b | 2019-01-08 16:07:24 +0200 | [diff] [blame] | 1025 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
Moni Shoua | 0081575 | 2019-08-15 11:38:32 +0300 | [diff] [blame] | 1026 | if (dev->odp_caps.general_caps & IB_ODP_SUPPORT) |
Leon Romanovsky | e502b8b | 2019-01-08 16:07:24 +0200 | [diff] [blame] | 1027 | props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
| 1028 | props->odp_caps = dev->odp_caps; |
| 1029 | } |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 1030 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 1031 | if (MLX5_CAP_GEN(mdev, cd)) |
| 1032 | props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL; |
| 1033 | |
Parav Pandit | e53a9d2 | 2019-10-28 23:35:30 +0000 | [diff] [blame] | 1034 | if (mlx5_core_is_vf(mdev)) |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 1035 | props->device_cap_flags |= IB_DEVICE_VIRTUAL_FUNCTION; |
| 1036 | |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 1037 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1038 | IB_LINK_LAYER_ETHERNET && raw_support) { |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 1039 | props->rss_caps.max_rwq_indirection_tables = |
| 1040 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt); |
| 1041 | props->rss_caps.max_rwq_indirection_table_size = |
| 1042 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt_size); |
| 1043 | props->rss_caps.supported_qpts = 1 << IB_QPT_RAW_PACKET; |
| 1044 | props->max_wq_type_rq = |
| 1045 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rq); |
| 1046 | } |
| 1047 | |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1048 | if (MLX5_CAP_GEN(mdev, tag_matching)) { |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1049 | props->tm_caps.max_num_tags = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1050 | (1 << MLX5_CAP_GEN(mdev, log_tag_matching_list_sz)) - 1; |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1051 | props->tm_caps.max_ops = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1052 | 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1053 | props->tm_caps.max_sge = MLX5_TM_MAX_SGE; |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1054 | } |
| 1055 | |
Danit Goldberg | 89705e9 | 2019-07-05 19:21:57 +0300 | [diff] [blame] | 1056 | if (MLX5_CAP_GEN(mdev, tag_matching) && |
| 1057 | MLX5_CAP_GEN(mdev, rndv_offload_rc)) { |
| 1058 | props->tm_caps.flags = IB_TM_CAP_RNDV_RC; |
| 1059 | props->tm_caps.max_rndv_hdr_size = MLX5_TM_MAX_RNDV_MSG_SIZE; |
| 1060 | } |
| 1061 | |
Yonatan Cohen | 87ab3f5 | 2017-11-13 10:51:18 +0200 | [diff] [blame] | 1062 | if (MLX5_CAP_GEN(dev->mdev, cq_moderation)) { |
| 1063 | props->cq_caps.max_cq_moderation_count = |
| 1064 | MLX5_MAX_CQ_COUNT; |
| 1065 | props->cq_caps.max_cq_moderation_period = |
| 1066 | MLX5_MAX_CQ_PERIOD; |
| 1067 | } |
| 1068 | |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1069 | if (field_avail(typeof(resp), cqe_comp_caps, uhw->outlen)) { |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1070 | resp.response_length += sizeof(resp.cqe_comp_caps); |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 1071 | |
| 1072 | if (MLX5_CAP_GEN(dev->mdev, cqe_compression)) { |
| 1073 | resp.cqe_comp_caps.max_num = |
| 1074 | MLX5_CAP_GEN(dev->mdev, |
| 1075 | cqe_compression_max_num); |
| 1076 | |
| 1077 | resp.cqe_comp_caps.supported_format = |
| 1078 | MLX5_IB_CQE_RES_FORMAT_HASH | |
| 1079 | MLX5_IB_CQE_RES_FORMAT_CSUM; |
Yonatan Cohen | 6f1006a | 2018-05-27 13:42:34 +0300 | [diff] [blame] | 1080 | |
| 1081 | if (MLX5_CAP_GEN(dev->mdev, mini_cqe_resp_stride_index)) |
| 1082 | resp.cqe_comp_caps.supported_format |= |
| 1083 | MLX5_IB_CQE_RES_FORMAT_CSUM_STRIDX; |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 1084 | } |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1085 | } |
| 1086 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1087 | if (field_avail(typeof(resp), packet_pacing_caps, uhw->outlen) && |
| 1088 | raw_support) { |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 1089 | if (MLX5_CAP_QOS(mdev, packet_pacing) && |
| 1090 | MLX5_CAP_GEN(mdev, qos)) { |
| 1091 | resp.packet_pacing_caps.qp_rate_limit_max = |
| 1092 | MLX5_CAP_QOS(mdev, packet_pacing_max_rate); |
| 1093 | resp.packet_pacing_caps.qp_rate_limit_min = |
| 1094 | MLX5_CAP_QOS(mdev, packet_pacing_min_rate); |
| 1095 | resp.packet_pacing_caps.supported_qpts |= |
| 1096 | 1 << IB_QPT_RAW_PACKET; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 1097 | if (MLX5_CAP_QOS(mdev, packet_pacing_burst_bound) && |
| 1098 | MLX5_CAP_QOS(mdev, packet_pacing_typical_size)) |
| 1099 | resp.packet_pacing_caps.cap_flags |= |
| 1100 | MLX5_IB_PP_SUPPORT_BURST; |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 1101 | } |
| 1102 | resp.response_length += sizeof(resp.packet_pacing_caps); |
| 1103 | } |
| 1104 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1105 | if (field_avail(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes, |
| 1106 | uhw->outlen)) { |
Bodong Wang | 795b609 | 2017-08-17 15:52:34 +0300 | [diff] [blame] | 1107 | if (MLX5_CAP_ETH(mdev, multi_pkt_send_wqe)) |
| 1108 | resp.mlx5_ib_support_multi_pkt_send_wqes = |
| 1109 | MLX5_IB_ALLOW_MPW; |
Bodong Wang | 050da90 | 2017-08-17 15:52:35 +0300 | [diff] [blame] | 1110 | |
| 1111 | if (MLX5_CAP_ETH(mdev, enhanced_multi_pkt_send_wqe)) |
| 1112 | resp.mlx5_ib_support_multi_pkt_send_wqes |= |
| 1113 | MLX5_IB_SUPPORT_EMPW; |
| 1114 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1115 | resp.response_length += |
| 1116 | sizeof(resp.mlx5_ib_support_multi_pkt_send_wqes); |
| 1117 | } |
| 1118 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1119 | if (field_avail(typeof(resp), flags, uhw->outlen)) { |
| 1120 | resp.response_length += sizeof(resp.flags); |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1121 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1122 | if (MLX5_CAP_GEN(mdev, cqe_compression_128)) |
| 1123 | resp.flags |= |
| 1124 | MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_COMP; |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1125 | |
| 1126 | if (MLX5_CAP_GEN(mdev, cqe_128_always)) |
| 1127 | resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_PAD; |
Danit Goldberg | 7e11b91 | 2018-11-30 13:22:06 +0200 | [diff] [blame] | 1128 | if (MLX5_CAP_GEN(mdev, qp_packet_based)) |
| 1129 | resp.flags |= |
| 1130 | MLX5_IB_QUERY_DEV_RESP_PACKET_BASED_CREDIT_MODE; |
Guy Levi | 7249c8e | 2019-04-10 10:59:45 +0300 | [diff] [blame] | 1131 | |
| 1132 | resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_SCAT2CQE_DCT; |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1133 | } |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1134 | |
Noa Osherovich | 96dc3fc | 2017-08-17 15:52:28 +0300 | [diff] [blame] | 1135 | if (field_avail(typeof(resp), sw_parsing_caps, |
| 1136 | uhw->outlen)) { |
| 1137 | resp.response_length += sizeof(resp.sw_parsing_caps); |
| 1138 | if (MLX5_CAP_ETH(mdev, swp)) { |
| 1139 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1140 | MLX5_IB_SW_PARSING; |
| 1141 | |
| 1142 | if (MLX5_CAP_ETH(mdev, swp_csum)) |
| 1143 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1144 | MLX5_IB_SW_PARSING_CSUM; |
| 1145 | |
| 1146 | if (MLX5_CAP_ETH(mdev, swp_lso)) |
| 1147 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1148 | MLX5_IB_SW_PARSING_LSO; |
| 1149 | |
| 1150 | if (resp.sw_parsing_caps.sw_parsing_offloads) |
| 1151 | resp.sw_parsing_caps.supported_qpts = |
| 1152 | BIT(IB_QPT_RAW_PACKET); |
| 1153 | } |
| 1154 | } |
| 1155 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1156 | if (field_avail(typeof(resp), striding_rq_caps, uhw->outlen) && |
| 1157 | raw_support) { |
Noa Osherovich | b4f3459 | 2017-10-17 18:01:12 +0300 | [diff] [blame] | 1158 | resp.response_length += sizeof(resp.striding_rq_caps); |
| 1159 | if (MLX5_CAP_GEN(mdev, striding_rq)) { |
| 1160 | resp.striding_rq_caps.min_single_stride_log_num_of_bytes = |
| 1161 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1162 | resp.striding_rq_caps.max_single_stride_log_num_of_bytes = |
| 1163 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1164 | resp.striding_rq_caps.min_single_wqe_log_num_of_strides = |
| 1165 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1166 | resp.striding_rq_caps.max_single_wqe_log_num_of_strides = |
| 1167 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1168 | resp.striding_rq_caps.supported_qpts = |
| 1169 | BIT(IB_QPT_RAW_PACKET); |
| 1170 | } |
| 1171 | } |
| 1172 | |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1173 | if (field_avail(typeof(resp), tunnel_offloads_caps, |
| 1174 | uhw->outlen)) { |
| 1175 | resp.response_length += sizeof(resp.tunnel_offloads_caps); |
| 1176 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan)) |
| 1177 | resp.tunnel_offloads_caps |= |
| 1178 | MLX5_IB_TUNNELED_OFFLOADS_VXLAN; |
| 1179 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_geneve_rx)) |
| 1180 | resp.tunnel_offloads_caps |= |
| 1181 | MLX5_IB_TUNNELED_OFFLOADS_GENEVE; |
| 1182 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_gre)) |
| 1183 | resp.tunnel_offloads_caps |= |
| 1184 | MLX5_IB_TUNNELED_OFFLOADS_GRE; |
Ariel Levkovich | e818e25 | 2018-05-13 14:33:35 +0300 | [diff] [blame] | 1185 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1186 | MLX5_FLEX_PROTO_CW_MPLS_GRE) |
| 1187 | resp.tunnel_offloads_caps |= |
| 1188 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_GRE; |
| 1189 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1190 | MLX5_FLEX_PROTO_CW_MPLS_UDP) |
| 1191 | resp.tunnel_offloads_caps |= |
| 1192 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_UDP; |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1193 | } |
| 1194 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1195 | if (uhw->outlen) { |
| 1196 | err = ib_copy_to_udata(uhw, &resp, resp.response_length); |
| 1197 | |
| 1198 | if (err) |
| 1199 | return err; |
| 1200 | } |
| 1201 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1202 | return 0; |
| 1203 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1204 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1205 | enum mlx5_ib_width { |
| 1206 | MLX5_IB_WIDTH_1X = 1 << 0, |
| 1207 | MLX5_IB_WIDTH_2X = 1 << 1, |
| 1208 | MLX5_IB_WIDTH_4X = 1 << 2, |
| 1209 | MLX5_IB_WIDTH_8X = 1 << 3, |
| 1210 | MLX5_IB_WIDTH_12X = 1 << 4 |
| 1211 | }; |
| 1212 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1213 | static void translate_active_width(struct ib_device *ibdev, u8 active_width, |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1214 | u8 *ib_width) |
| 1215 | { |
| 1216 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1217 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1218 | if (active_width & MLX5_IB_WIDTH_1X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1219 | *ib_width = IB_WIDTH_1X; |
Michael Guralnik | d764970 | 2018-12-09 11:49:54 +0200 | [diff] [blame] | 1220 | else if (active_width & MLX5_IB_WIDTH_2X) |
| 1221 | *ib_width = IB_WIDTH_2X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1222 | else if (active_width & MLX5_IB_WIDTH_4X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1223 | *ib_width = IB_WIDTH_4X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1224 | else if (active_width & MLX5_IB_WIDTH_8X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1225 | *ib_width = IB_WIDTH_8X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1226 | else if (active_width & MLX5_IB_WIDTH_12X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1227 | *ib_width = IB_WIDTH_12X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1228 | else { |
| 1229 | 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] | 1230 | (int)active_width); |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1231 | *ib_width = IB_WIDTH_4X; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1232 | } |
| 1233 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1234 | return; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | static int mlx5_mtu_to_ib_mtu(int mtu) |
| 1238 | { |
| 1239 | switch (mtu) { |
| 1240 | case 256: return 1; |
| 1241 | case 512: return 2; |
| 1242 | case 1024: return 3; |
| 1243 | case 2048: return 4; |
| 1244 | case 4096: return 5; |
| 1245 | default: |
| 1246 | pr_warn("invalid mtu\n"); |
| 1247 | return -1; |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | enum ib_max_vl_num { |
| 1252 | __IB_MAX_VL_0 = 1, |
| 1253 | __IB_MAX_VL_0_1 = 2, |
| 1254 | __IB_MAX_VL_0_3 = 3, |
| 1255 | __IB_MAX_VL_0_7 = 4, |
| 1256 | __IB_MAX_VL_0_14 = 5, |
| 1257 | }; |
| 1258 | |
| 1259 | enum mlx5_vl_hw_cap { |
| 1260 | MLX5_VL_HW_0 = 1, |
| 1261 | MLX5_VL_HW_0_1 = 2, |
| 1262 | MLX5_VL_HW_0_2 = 3, |
| 1263 | MLX5_VL_HW_0_3 = 4, |
| 1264 | MLX5_VL_HW_0_4 = 5, |
| 1265 | MLX5_VL_HW_0_5 = 6, |
| 1266 | MLX5_VL_HW_0_6 = 7, |
| 1267 | MLX5_VL_HW_0_7 = 8, |
| 1268 | MLX5_VL_HW_0_14 = 15 |
| 1269 | }; |
| 1270 | |
| 1271 | static int translate_max_vl_num(struct ib_device *ibdev, u8 vl_hw_cap, |
| 1272 | u8 *max_vl_num) |
| 1273 | { |
| 1274 | switch (vl_hw_cap) { |
| 1275 | case MLX5_VL_HW_0: |
| 1276 | *max_vl_num = __IB_MAX_VL_0; |
| 1277 | break; |
| 1278 | case MLX5_VL_HW_0_1: |
| 1279 | *max_vl_num = __IB_MAX_VL_0_1; |
| 1280 | break; |
| 1281 | case MLX5_VL_HW_0_3: |
| 1282 | *max_vl_num = __IB_MAX_VL_0_3; |
| 1283 | break; |
| 1284 | case MLX5_VL_HW_0_7: |
| 1285 | *max_vl_num = __IB_MAX_VL_0_7; |
| 1286 | break; |
| 1287 | case MLX5_VL_HW_0_14: |
| 1288 | *max_vl_num = __IB_MAX_VL_0_14; |
| 1289 | break; |
| 1290 | |
| 1291 | default: |
| 1292 | return -EINVAL; |
| 1293 | } |
| 1294 | |
| 1295 | return 0; |
| 1296 | } |
| 1297 | |
| 1298 | static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port, |
| 1299 | struct ib_port_attr *props) |
| 1300 | { |
| 1301 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1302 | struct mlx5_core_dev *mdev = dev->mdev; |
| 1303 | struct mlx5_hca_vport_context *rep; |
Saeed Mahameed | 046339e | 2016-04-22 00:33:03 +0300 | [diff] [blame] | 1304 | u16 max_mtu; |
| 1305 | u16 oper_mtu; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1306 | int err; |
| 1307 | u8 ib_link_width_oper; |
| 1308 | u8 vl_hw_cap; |
| 1309 | |
| 1310 | rep = kzalloc(sizeof(*rep), GFP_KERNEL); |
| 1311 | if (!rep) { |
| 1312 | err = -ENOMEM; |
| 1313 | goto out; |
| 1314 | } |
| 1315 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1316 | /* props being zeroed by the caller, avoid zeroing it here */ |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1317 | |
| 1318 | err = mlx5_query_hca_vport_context(mdev, 0, port, 0, rep); |
| 1319 | if (err) |
| 1320 | goto out; |
| 1321 | |
| 1322 | props->lid = rep->lid; |
| 1323 | props->lmc = rep->lmc; |
| 1324 | props->sm_lid = rep->sm_lid; |
| 1325 | props->sm_sl = rep->sm_sl; |
| 1326 | props->state = rep->vport_state; |
| 1327 | props->phys_state = rep->port_physical_state; |
| 1328 | props->port_cap_flags = rep->cap_mask1; |
| 1329 | props->gid_tbl_len = mlx5_get_gid_table_len(MLX5_CAP_GEN(mdev, gid_table_size)); |
| 1330 | props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg); |
| 1331 | props->pkey_tbl_len = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, pkey_table_size)); |
| 1332 | props->bad_pkey_cntr = rep->pkey_violation_counter; |
| 1333 | props->qkey_viol_cntr = rep->qkey_violation_counter; |
| 1334 | props->subnet_timeout = rep->subnet_timeout; |
| 1335 | props->init_type_reply = rep->init_type_reply; |
| 1336 | |
Michael Guralnik | 4106a75 | 2018-12-09 11:49:51 +0200 | [diff] [blame] | 1337 | if (props->port_cap_flags & IB_PORT_CAP_MASK2_SUP) |
| 1338 | props->port_cap_flags2 = rep->cap_mask2; |
| 1339 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1340 | err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); |
| 1341 | if (err) |
| 1342 | goto out; |
| 1343 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1344 | translate_active_width(ibdev, ib_link_width_oper, &props->active_width); |
| 1345 | |
Noa Osherovich | d5beb7f | 2016-06-02 10:47:53 +0300 | [diff] [blame] | 1346 | err = mlx5_query_port_ib_proto_oper(mdev, &props->active_speed, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1347 | if (err) |
| 1348 | goto out; |
| 1349 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1350 | mlx5_query_port_max_mtu(mdev, &max_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1351 | |
| 1352 | props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu); |
| 1353 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1354 | mlx5_query_port_oper_mtu(mdev, &oper_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1355 | |
| 1356 | props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu); |
| 1357 | |
| 1358 | err = mlx5_query_port_vl_hw_cap(mdev, &vl_hw_cap, port); |
| 1359 | if (err) |
| 1360 | goto out; |
| 1361 | |
| 1362 | err = translate_max_vl_num(ibdev, vl_hw_cap, |
| 1363 | &props->max_vl_num); |
| 1364 | out: |
| 1365 | kfree(rep); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1366 | return err; |
| 1367 | } |
| 1368 | |
| 1369 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 1370 | struct ib_port_attr *props) |
| 1371 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1372 | unsigned int count; |
| 1373 | int ret; |
| 1374 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1375 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1376 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1377 | ret = mlx5_query_mad_ifc_port(ibdev, port, props); |
| 1378 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1379 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1380 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1381 | ret = mlx5_query_hca_port(ibdev, port, props); |
| 1382 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1383 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1384 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1385 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1386 | break; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1387 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1388 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1389 | ret = -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1390 | } |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1391 | |
| 1392 | if (!ret && props) { |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1393 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1394 | struct mlx5_core_dev *mdev; |
| 1395 | bool put_mdev = true; |
| 1396 | |
| 1397 | mdev = mlx5_ib_get_native_port_mdev(dev, port, NULL); |
| 1398 | if (!mdev) { |
| 1399 | /* If the port isn't affiliated yet query the master. |
| 1400 | * The master and slave will have the same values. |
| 1401 | */ |
| 1402 | mdev = dev->mdev; |
| 1403 | port = 1; |
| 1404 | put_mdev = false; |
| 1405 | } |
| 1406 | count = mlx5_core_reserved_gids_count(mdev); |
| 1407 | if (put_mdev) |
| 1408 | mlx5_ib_put_native_port_mdev(dev, port); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1409 | props->gid_tbl_len -= count; |
| 1410 | } |
| 1411 | return ret; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1412 | } |
| 1413 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 1414 | static int mlx5_ib_rep_query_port(struct ib_device *ibdev, u8 port, |
| 1415 | struct ib_port_attr *props) |
| 1416 | { |
| 1417 | int ret; |
| 1418 | |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 1419 | /* Only link layer == ethernet is valid for representors |
| 1420 | * and we always use port 1 |
| 1421 | */ |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 1422 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1423 | if (ret || !props) |
| 1424 | return ret; |
| 1425 | |
| 1426 | /* We don't support GIDS */ |
| 1427 | props->gid_tbl_len = 0; |
| 1428 | |
| 1429 | return ret; |
| 1430 | } |
| 1431 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1432 | static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 1433 | union ib_gid *gid) |
| 1434 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1435 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1436 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1437 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1438 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1439 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1440 | return mlx5_query_mad_ifc_gids(ibdev, port, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1441 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1442 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1443 | return mlx5_query_hca_vport_gid(mdev, 0, port, 0, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1444 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1445 | default: |
| 1446 | return -EINVAL; |
| 1447 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1448 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1449 | } |
| 1450 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1451 | static int mlx5_query_hca_nic_pkey(struct ib_device *ibdev, u8 port, |
| 1452 | u16 index, u16 *pkey) |
| 1453 | { |
| 1454 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1455 | struct mlx5_core_dev *mdev; |
| 1456 | bool put_mdev = true; |
| 1457 | u8 mdev_port_num; |
| 1458 | int err; |
| 1459 | |
| 1460 | mdev = mlx5_ib_get_native_port_mdev(dev, port, &mdev_port_num); |
| 1461 | if (!mdev) { |
| 1462 | /* The port isn't affiliated yet, get the PKey from the master |
| 1463 | * port. For RoCE the PKey tables will be the same. |
| 1464 | */ |
| 1465 | put_mdev = false; |
| 1466 | mdev = dev->mdev; |
| 1467 | mdev_port_num = 1; |
| 1468 | } |
| 1469 | |
| 1470 | err = mlx5_query_hca_vport_pkey(mdev, 0, mdev_port_num, 0, |
| 1471 | index, pkey); |
| 1472 | if (put_mdev) |
| 1473 | mlx5_ib_put_native_port_mdev(dev, port); |
| 1474 | |
| 1475 | return err; |
| 1476 | } |
| 1477 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1478 | static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 1479 | u16 *pkey) |
| 1480 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1481 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1482 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1483 | return mlx5_query_mad_ifc_pkey(ibdev, port, index, pkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1484 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1485 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1486 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1487 | return mlx5_query_hca_nic_pkey(ibdev, port, index, pkey); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1488 | default: |
| 1489 | return -EINVAL; |
| 1490 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1491 | } |
| 1492 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1493 | static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask, |
| 1494 | struct ib_device_modify *props) |
| 1495 | { |
| 1496 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1497 | struct mlx5_reg_node_desc in; |
| 1498 | struct mlx5_reg_node_desc out; |
| 1499 | int err; |
| 1500 | |
| 1501 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 1502 | return -EOPNOTSUPP; |
| 1503 | |
| 1504 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 1505 | return 0; |
| 1506 | |
| 1507 | /* |
| 1508 | * If possible, pass node desc to FW, so it can generate |
| 1509 | * a 144 trap. If cmd fails, just ignore. |
| 1510 | */ |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1511 | memcpy(&in, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1512 | err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1513 | sizeof(out), MLX5_REG_NODE_DESC, 0, 1); |
| 1514 | if (err) |
| 1515 | return err; |
| 1516 | |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1517 | memcpy(ibdev->node_desc, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1518 | |
| 1519 | return err; |
| 1520 | } |
| 1521 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1522 | static int set_port_caps_atomic(struct mlx5_ib_dev *dev, u8 port_num, u32 mask, |
| 1523 | u32 value) |
| 1524 | { |
| 1525 | struct mlx5_hca_vport_context ctx = {}; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1526 | struct mlx5_core_dev *mdev; |
| 1527 | u8 mdev_port_num; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1528 | int err; |
| 1529 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1530 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 1531 | if (!mdev) |
| 1532 | return -ENODEV; |
| 1533 | |
| 1534 | 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] | 1535 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1536 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1537 | |
| 1538 | if (~ctx.cap_mask1_perm & mask) { |
| 1539 | mlx5_ib_warn(dev, "trying to change bitmask 0x%X but change supported 0x%X\n", |
| 1540 | mask, ctx.cap_mask1_perm); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1541 | err = -EINVAL; |
| 1542 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | ctx.cap_mask1 = value; |
| 1546 | ctx.cap_mask1_perm = mask; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1547 | err = mlx5_core_modify_hca_vport_context(mdev, 0, mdev_port_num, |
| 1548 | 0, &ctx); |
| 1549 | |
| 1550 | out: |
| 1551 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1552 | |
| 1553 | return err; |
| 1554 | } |
| 1555 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1556 | static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 1557 | struct ib_port_modify *props) |
| 1558 | { |
| 1559 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1560 | struct ib_port_attr attr; |
| 1561 | u32 tmp; |
| 1562 | int err; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1563 | u32 change_mask; |
| 1564 | u32 value; |
| 1565 | bool is_ib = (mlx5_ib_port_link_layer(ibdev, port) == |
| 1566 | IB_LINK_LAYER_INFINIBAND); |
| 1567 | |
Majd Dibbiny | ec25587 | 2017-08-23 08:35:42 +0300 | [diff] [blame] | 1568 | /* CM layer calls ib_modify_port() regardless of the link layer. For |
| 1569 | * Ethernet ports, qkey violation and Port capabilities are meaningless. |
| 1570 | */ |
| 1571 | if (!is_ib) |
| 1572 | return 0; |
| 1573 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1574 | if (MLX5_CAP_GEN(dev->mdev, ib_virt) && is_ib) { |
| 1575 | change_mask = props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1576 | value = ~props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1577 | return set_port_caps_atomic(dev, port, change_mask, value); |
| 1578 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1579 | |
| 1580 | mutex_lock(&dev->cap_mask_mutex); |
| 1581 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1582 | err = ib_query_port(ibdev, port, &attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1583 | if (err) |
| 1584 | goto out; |
| 1585 | |
| 1586 | tmp = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 1587 | ~props->clr_port_cap_mask; |
| 1588 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1589 | err = mlx5_set_port_caps(dev->mdev, port, tmp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1590 | |
| 1591 | out: |
| 1592 | mutex_unlock(&dev->cap_mask_mutex); |
| 1593 | return err; |
| 1594 | } |
| 1595 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1596 | static void print_lib_caps(struct mlx5_ib_dev *dev, u64 caps) |
| 1597 | { |
| 1598 | mlx5_ib_dbg(dev, "MLX5_LIB_CAP_4K_UAR = %s\n", |
| 1599 | caps & MLX5_LIB_CAP_4K_UAR ? "y" : "n"); |
| 1600 | } |
| 1601 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1602 | static u16 calc_dynamic_bfregs(int uars_per_sys_page) |
| 1603 | { |
| 1604 | /* Large page with non 4k uar support might limit the dynamic size */ |
| 1605 | if (uars_per_sys_page == 1 && PAGE_SIZE > 4096) |
| 1606 | return MLX5_MIN_DYN_BFREGS; |
| 1607 | |
| 1608 | return MLX5_MAX_DYN_BFREGS; |
| 1609 | } |
| 1610 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1611 | static int calc_total_bfregs(struct mlx5_ib_dev *dev, bool lib_uar_4k, |
| 1612 | struct mlx5_ib_alloc_ucontext_req_v2 *req, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1613 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1614 | { |
| 1615 | int uars_per_sys_page; |
| 1616 | int bfregs_per_sys_page; |
| 1617 | int ref_bfregs = req->total_num_bfregs; |
| 1618 | |
| 1619 | if (req->total_num_bfregs == 0) |
| 1620 | return -EINVAL; |
| 1621 | |
| 1622 | BUILD_BUG_ON(MLX5_MAX_BFREGS % MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1623 | BUILD_BUG_ON(MLX5_MAX_BFREGS < MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1624 | |
| 1625 | if (req->total_num_bfregs > MLX5_MAX_BFREGS) |
| 1626 | return -ENOMEM; |
| 1627 | |
| 1628 | uars_per_sys_page = get_uars_per_sys_page(dev, lib_uar_4k); |
| 1629 | 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] | 1630 | /* This holds the required static allocation asked by the user */ |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1631 | 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] | 1632 | if (req->num_low_latency_bfregs > req->total_num_bfregs - 1) |
| 1633 | return -EINVAL; |
| 1634 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1635 | bfregi->num_static_sys_pages = req->total_num_bfregs / bfregs_per_sys_page; |
| 1636 | bfregi->num_dyn_bfregs = ALIGN(calc_dynamic_bfregs(uars_per_sys_page), bfregs_per_sys_page); |
| 1637 | bfregi->total_num_bfregs = req->total_num_bfregs + bfregi->num_dyn_bfregs; |
| 1638 | bfregi->num_sys_pages = bfregi->total_num_bfregs / bfregs_per_sys_page; |
| 1639 | |
| 1640 | 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] | 1641 | MLX5_CAP_GEN(dev->mdev, uar_4k) ? "yes" : "no", |
| 1642 | lib_uar_4k ? "yes" : "no", ref_bfregs, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1643 | req->total_num_bfregs, bfregi->total_num_bfregs, |
| 1644 | bfregi->num_sys_pages); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1645 | |
| 1646 | return 0; |
| 1647 | } |
| 1648 | |
| 1649 | static int allocate_uars(struct mlx5_ib_dev *dev, struct mlx5_ib_ucontext *context) |
| 1650 | { |
| 1651 | struct mlx5_bfreg_info *bfregi; |
| 1652 | int err; |
| 1653 | int i; |
| 1654 | |
| 1655 | bfregi = &context->bfregi; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1656 | for (i = 0; i < bfregi->num_static_sys_pages; i++) { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1657 | err = mlx5_cmd_alloc_uar(dev->mdev, &bfregi->sys_pages[i]); |
| 1658 | if (err) |
| 1659 | goto error; |
| 1660 | |
| 1661 | mlx5_ib_dbg(dev, "allocated uar %d\n", bfregi->sys_pages[i]); |
| 1662 | } |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1663 | |
| 1664 | for (i = bfregi->num_static_sys_pages; i < bfregi->num_sys_pages; i++) |
| 1665 | bfregi->sys_pages[i] = MLX5_IB_INVALID_UAR_INDEX; |
| 1666 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1667 | return 0; |
| 1668 | |
| 1669 | error: |
| 1670 | for (--i; i >= 0; i--) |
| 1671 | if (mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i])) |
| 1672 | mlx5_ib_warn(dev, "failed to free uar %d\n", i); |
| 1673 | |
| 1674 | return err; |
| 1675 | } |
| 1676 | |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1677 | static void deallocate_uars(struct mlx5_ib_dev *dev, |
| 1678 | struct mlx5_ib_ucontext *context) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1679 | { |
| 1680 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1681 | int i; |
| 1682 | |
| 1683 | bfregi = &context->bfregi; |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1684 | for (i = 0; i < bfregi->num_sys_pages; i++) |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1685 | if (i < bfregi->num_static_sys_pages || |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1686 | bfregi->sys_pages[i] != MLX5_IB_INVALID_UAR_INDEX) |
| 1687 | mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i]); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1688 | } |
| 1689 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1690 | 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] | 1691 | { |
| 1692 | int err = 0; |
| 1693 | |
| 1694 | mutex_lock(&dev->lb.mutex); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1695 | if (td) |
| 1696 | dev->lb.user_td++; |
| 1697 | if (qp) |
| 1698 | dev->lb.qps++; |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1699 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1700 | if (dev->lb.user_td == 2 || |
| 1701 | dev->lb.qps == 1) { |
| 1702 | if (!dev->lb.enabled) { |
| 1703 | err = mlx5_nic_vport_update_local_lb(dev->mdev, true); |
| 1704 | dev->lb.enabled = true; |
| 1705 | } |
| 1706 | } |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1707 | |
| 1708 | mutex_unlock(&dev->lb.mutex); |
| 1709 | |
| 1710 | return err; |
| 1711 | } |
| 1712 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1713 | 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] | 1714 | { |
| 1715 | mutex_lock(&dev->lb.mutex); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1716 | if (td) |
| 1717 | dev->lb.user_td--; |
| 1718 | if (qp) |
| 1719 | dev->lb.qps--; |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1720 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1721 | if (dev->lb.user_td == 1 && |
| 1722 | dev->lb.qps == 0) { |
| 1723 | if (dev->lb.enabled) { |
| 1724 | mlx5_nic_vport_update_local_lb(dev->mdev, false); |
| 1725 | dev->lb.enabled = false; |
| 1726 | } |
| 1727 | } |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1728 | |
| 1729 | mutex_unlock(&dev->lb.mutex); |
| 1730 | } |
| 1731 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1732 | static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn, |
| 1733 | u16 uid) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1734 | { |
| 1735 | int err; |
| 1736 | |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1737 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1738 | return 0; |
| 1739 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1740 | err = mlx5_cmd_alloc_transport_domain(dev->mdev, tdn, uid); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1741 | if (err) |
| 1742 | return err; |
| 1743 | |
| 1744 | 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] | 1745 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1746 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1747 | return err; |
| 1748 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1749 | return mlx5_ib_enable_lb(dev, true, false); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1750 | } |
| 1751 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1752 | static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn, |
| 1753 | u16 uid) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1754 | { |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1755 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1756 | return; |
| 1757 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1758 | mlx5_cmd_dealloc_transport_domain(dev->mdev, tdn, uid); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1759 | |
| 1760 | 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] | 1761 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1762 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1763 | return; |
| 1764 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1765 | mlx5_ib_disable_lb(dev, true, false); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1766 | } |
| 1767 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1768 | static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx, |
| 1769 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1770 | { |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1771 | struct ib_device *ibdev = uctx->device; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1772 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1773 | struct mlx5_ib_alloc_ucontext_req_v2 req = {}; |
| 1774 | struct mlx5_ib_alloc_ucontext_resp resp = {}; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1775 | struct mlx5_core_dev *mdev = dev->mdev; |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1776 | struct mlx5_ib_ucontext *context = to_mucontext(uctx); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1777 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1778 | int ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1779 | int err; |
Majd Dibbiny | a168a41c | 2016-01-28 17:51:47 +0200 | [diff] [blame] | 1780 | size_t min_req_v2 = offsetof(struct mlx5_ib_alloc_ucontext_req_v2, |
| 1781 | max_cqe_version); |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1782 | u32 dump_fill_mkey; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1783 | bool lib_uar_4k; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1784 | |
| 1785 | if (!dev->ib_active) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1786 | return -EAGAIN; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1787 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1788 | if (udata->inlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1789 | ver = 0; |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1790 | else if (udata->inlen >= min_req_v2) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1791 | ver = 2; |
| 1792 | else |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1793 | return -EINVAL; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1794 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1795 | err = ib_copy_from_udata(&req, udata, min(udata->inlen, sizeof(req))); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1796 | if (err) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1797 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1798 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1799 | if (req.flags & ~MLX5_IB_ALLOC_UCTX_DEVX) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1800 | return -EOPNOTSUPP; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1801 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1802 | if (req.comp_mask || req.reserved0 || req.reserved1 || req.reserved2) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1803 | return -EOPNOTSUPP; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1804 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1805 | req.total_num_bfregs = ALIGN(req.total_num_bfregs, |
| 1806 | MLX5_NON_FP_BFREGS_PER_UAR); |
| 1807 | if (req.num_low_latency_bfregs > req.total_num_bfregs - 1) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1808 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1809 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1810 | 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] | 1811 | if (mlx5_core_is_pf(dev->mdev) && MLX5_CAP_GEN(dev->mdev, bf)) |
| 1812 | 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] | 1813 | resp.cache_line_size = cache_line_size(); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1814 | resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); |
| 1815 | resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); |
| 1816 | resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1817 | resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1818 | 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] | 1819 | resp.cqe_version = min_t(__u8, |
| 1820 | (__u8)MLX5_CAP_GEN(dev->mdev, cqe_version), |
| 1821 | req.max_cqe_version); |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1822 | resp.log_uar_size = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1823 | MLX5_ADAPTER_PAGE_SHIFT : PAGE_SHIFT; |
| 1824 | resp.num_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1825 | MLX5_CAP_GEN(dev->mdev, num_of_uars_per_page) : 1; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1826 | resp.response_length = min(offsetof(typeof(resp), response_length) + |
| 1827 | sizeof(resp.response_length), udata->outlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1828 | |
Matan Barak | c03faa5 | 2018-03-28 09:27:54 +0300 | [diff] [blame] | 1829 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_DEVICE) { |
| 1830 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_EGRESS)) |
| 1831 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM; |
| 1832 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_REQUIRED_METADATA) |
| 1833 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_REQ_METADATA; |
| 1834 | if (MLX5_CAP_FLOWTABLE(dev->mdev, flow_table_properties_nic_receive.ft_field_support.outer_esp_spi)) |
| 1835 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_SPI_STEERING; |
| 1836 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_TX_IV_IS_ESN) |
| 1837 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_TX_IV_IS_ESN; |
| 1838 | /* MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_FULL_OFFLOAD is currently always 0 */ |
| 1839 | } |
| 1840 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1841 | lib_uar_4k = req.lib_caps & MLX5_LIB_CAP_4K_UAR; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1842 | bfregi = &context->bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1843 | |
| 1844 | /* updates req->total_num_bfregs */ |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1845 | err = calc_total_bfregs(dev, lib_uar_4k, &req, bfregi); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1846 | if (err) |
| 1847 | goto out_ctx; |
| 1848 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1849 | mutex_init(&bfregi->lock); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1850 | bfregi->lib_uar_4k = lib_uar_4k; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1851 | bfregi->count = kcalloc(bfregi->total_num_bfregs, sizeof(*bfregi->count), |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1852 | GFP_KERNEL); |
| 1853 | if (!bfregi->count) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1854 | err = -ENOMEM; |
| 1855 | goto out_ctx; |
| 1856 | } |
| 1857 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1858 | bfregi->sys_pages = kcalloc(bfregi->num_sys_pages, |
| 1859 | sizeof(*bfregi->sys_pages), |
| 1860 | GFP_KERNEL); |
| 1861 | if (!bfregi->sys_pages) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1862 | err = -ENOMEM; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1863 | goto out_count; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1864 | } |
| 1865 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1866 | err = allocate_uars(dev, context); |
| 1867 | if (err) |
| 1868 | goto out_sys_pages; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1869 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1870 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) { |
Yishai Hadas | fb98153 | 2018-11-26 08:28:36 +0200 | [diff] [blame] | 1871 | err = mlx5_ib_devx_create(dev, true); |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1872 | if (err < 0) |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1873 | goto out_uars; |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1874 | context->devx_uid = err; |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1875 | } |
| 1876 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1877 | err = mlx5_ib_alloc_transport_domain(dev, &context->tdn, |
| 1878 | context->devx_uid); |
| 1879 | if (err) |
| 1880 | goto out_devx; |
| 1881 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1882 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1883 | err = mlx5_cmd_dump_fill_mkey(dev->mdev, &dump_fill_mkey); |
| 1884 | if (err) |
Jason Gunthorpe | 8193abb | 2018-07-04 13:19:46 -0600 | [diff] [blame] | 1885 | goto out_mdev; |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1886 | } |
| 1887 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1888 | INIT_LIST_HEAD(&context->db_page_list); |
| 1889 | mutex_init(&context->db_page_mutex); |
| 1890 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1891 | resp.tot_bfregs = req.total_num_bfregs; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 1892 | resp.num_ports = dev->num_ports; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1893 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1894 | if (field_avail(typeof(resp), cqe_version, udata->outlen)) |
| 1895 | resp.response_length += sizeof(resp.cqe_version); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1896 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1897 | if (field_avail(typeof(resp), cmds_supp_uhw, udata->outlen)) { |
Moni Shoua | 6ad279c5 | 2016-11-23 08:23:23 +0200 | [diff] [blame] | 1898 | resp.cmds_supp_uhw |= MLX5_USER_CMDS_SUPP_UHW_QUERY_DEVICE | |
| 1899 | MLX5_USER_CMDS_SUPP_UHW_CREATE_AH; |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1900 | resp.response_length += sizeof(resp.cmds_supp_uhw); |
| 1901 | } |
| 1902 | |
Or Gerlitz | 7898489 | 2016-11-30 20:33:33 +0200 | [diff] [blame] | 1903 | if (field_avail(typeof(resp), eth_min_inline, udata->outlen)) { |
| 1904 | if (mlx5_ib_port_link_layer(ibdev, 1) == IB_LINK_LAYER_ETHERNET) { |
| 1905 | mlx5_query_min_inline(dev->mdev, &resp.eth_min_inline); |
| 1906 | resp.eth_min_inline++; |
| 1907 | } |
| 1908 | resp.response_length += sizeof(resp.eth_min_inline); |
| 1909 | } |
| 1910 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1911 | if (field_avail(typeof(resp), clock_info_versions, udata->outlen)) { |
| 1912 | if (mdev->clock_info) |
| 1913 | resp.clock_info_versions = BIT(MLX5_IB_CLOCK_INFO_V1); |
| 1914 | resp.response_length += sizeof(resp.clock_info_versions); |
| 1915 | } |
| 1916 | |
Noa Osherovich | bc5c6ee | 2016-06-04 15:15:31 +0300 | [diff] [blame] | 1917 | /* |
| 1918 | * We don't want to expose information from the PCI bar that is located |
| 1919 | * after 4096 bytes, so if the arch only supports larger pages, let's |
| 1920 | * pretend we don't support reading the HCA's core clock. This is also |
| 1921 | * forced by mmap function. |
| 1922 | */ |
Eli Cohen | de8d6e0 | 2017-01-03 23:55:19 +0200 | [diff] [blame] | 1923 | if (field_avail(typeof(resp), hca_core_clock_offset, udata->outlen)) { |
| 1924 | if (PAGE_SIZE <= 4096) { |
| 1925 | resp.comp_mask |= |
| 1926 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET; |
| 1927 | resp.hca_core_clock_offset = |
| 1928 | offsetof(struct mlx5_init_seg, internal_timer_h) % PAGE_SIZE; |
| 1929 | } |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1930 | resp.response_length += sizeof(resp.hca_core_clock_offset); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1931 | } |
| 1932 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1933 | if (field_avail(typeof(resp), log_uar_size, udata->outlen)) |
| 1934 | resp.response_length += sizeof(resp.log_uar_size); |
| 1935 | |
| 1936 | if (field_avail(typeof(resp), num_uars_per_page, udata->outlen)) |
| 1937 | resp.response_length += sizeof(resp.num_uars_per_page); |
| 1938 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1939 | if (field_avail(typeof(resp), num_dyn_bfregs, udata->outlen)) { |
| 1940 | resp.num_dyn_bfregs = bfregi->num_dyn_bfregs; |
| 1941 | resp.response_length += sizeof(resp.num_dyn_bfregs); |
| 1942 | } |
| 1943 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1944 | if (field_avail(typeof(resp), dump_fill_mkey, udata->outlen)) { |
| 1945 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1946 | resp.dump_fill_mkey = dump_fill_mkey; |
| 1947 | resp.comp_mask |= |
| 1948 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_DUMP_FILL_MKEY; |
| 1949 | } |
| 1950 | resp.response_length += sizeof(resp.dump_fill_mkey); |
| 1951 | } |
| 1952 | |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1953 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1954 | if (err) |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1955 | goto out_mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1956 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1957 | bfregi->ver = ver; |
| 1958 | bfregi->num_low_latency_bfregs = req.num_low_latency_bfregs; |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1959 | context->cqe_version = resp.cqe_version; |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1960 | context->lib_caps = req.lib_caps; |
| 1961 | print_lib_caps(dev, context->lib_caps); |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1962 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 1963 | if (dev->lag_active) { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 1964 | u8 port = mlx5_core_native_port_num(dev->mdev) - 1; |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 1965 | |
| 1966 | atomic_set(&context->tx_port_affinity, |
| 1967 | atomic_add_return( |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 1968 | 1, &dev->port[port].roce.tx_port_affinity)); |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 1969 | } |
| 1970 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1971 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1972 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1973 | out_mdev: |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1974 | mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid); |
| 1975 | out_devx: |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1976 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1977 | mlx5_ib_devx_destroy(dev, context->devx_uid); |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1978 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1979 | out_uars: |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1980 | deallocate_uars(dev, context); |
| 1981 | |
| 1982 | out_sys_pages: |
| 1983 | kfree(bfregi->sys_pages); |
| 1984 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1985 | out_count: |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1986 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1987 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1988 | out_ctx: |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1989 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1990 | } |
| 1991 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1992 | static void mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1993 | { |
| 1994 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 1995 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1996 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1997 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1998 | bfregi = &context->bfregi; |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1999 | mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid); |
| 2000 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2001 | if (context->devx_uid) |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 2002 | mlx5_ib_devx_destroy(dev, context->devx_uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2003 | |
| 2004 | deallocate_uars(dev, context); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2005 | kfree(bfregi->sys_pages); |
| 2006 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, |
| 2010 | int uar_idx) |
| 2011 | { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2012 | int fw_uars_per_page; |
| 2013 | |
| 2014 | fw_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? MLX5_UARS_IN_PAGE : 1; |
| 2015 | |
Huy Nguyen | aa8106f | 2019-03-29 15:38:01 -0700 | [diff] [blame] | 2016 | 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] | 2017 | } |
| 2018 | |
| 2019 | static int get_command(unsigned long offset) |
| 2020 | { |
| 2021 | return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK; |
| 2022 | } |
| 2023 | |
| 2024 | static int get_arg(unsigned long offset) |
| 2025 | { |
| 2026 | return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1); |
| 2027 | } |
| 2028 | |
| 2029 | static int get_index(unsigned long offset) |
| 2030 | { |
| 2031 | return get_arg(offset); |
| 2032 | } |
| 2033 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2034 | /* Index resides in an extra byte to enable larger values than 255 */ |
| 2035 | static int get_extended_index(unsigned long offset) |
| 2036 | { |
| 2037 | return get_arg(offset) | ((offset >> 16) & 0xff) << 8; |
| 2038 | } |
| 2039 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2040 | |
| 2041 | static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) |
| 2042 | { |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2043 | } |
| 2044 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2045 | static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd) |
| 2046 | { |
| 2047 | switch (cmd) { |
| 2048 | case MLX5_IB_MMAP_WC_PAGE: |
| 2049 | return "WC"; |
| 2050 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2051 | return "best effort WC"; |
| 2052 | case MLX5_IB_MMAP_NC_PAGE: |
| 2053 | return "NC"; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2054 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2055 | return "Device Memory"; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2056 | default: |
| 2057 | return NULL; |
| 2058 | } |
| 2059 | } |
| 2060 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2061 | static int mlx5_ib_mmap_clock_info_page(struct mlx5_ib_dev *dev, |
| 2062 | struct vm_area_struct *vma, |
| 2063 | struct mlx5_ib_ucontext *context) |
| 2064 | { |
Jason Gunthorpe | 4eb6ab1 | 2019-04-16 14:07:30 +0300 | [diff] [blame] | 2065 | if ((vma->vm_end - vma->vm_start != PAGE_SIZE) || |
| 2066 | !(vma->vm_flags & VM_SHARED)) |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2067 | return -EINVAL; |
| 2068 | |
| 2069 | if (get_index(vma->vm_pgoff) != MLX5_IB_CLOCK_INFO_V1) |
| 2070 | return -EOPNOTSUPP; |
| 2071 | |
Jason Gunthorpe | 4eb6ab1 | 2019-04-16 14:07:30 +0300 | [diff] [blame] | 2072 | if (vma->vm_flags & (VM_WRITE | VM_EXEC)) |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2073 | return -EPERM; |
Jason Gunthorpe | c660133 | 2019-04-16 14:07:25 +0300 | [diff] [blame] | 2074 | vma->vm_flags &= ~VM_MAYWRITE; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2075 | |
Jason Gunthorpe | ddcdc36 | 2019-04-16 14:07:29 +0300 | [diff] [blame] | 2076 | if (!dev->mdev->clock_info) |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2077 | return -EOPNOTSUPP; |
| 2078 | |
Jason Gunthorpe | 4eb6ab1 | 2019-04-16 14:07:30 +0300 | [diff] [blame] | 2079 | return vm_insert_page(vma, vma->vm_start, |
| 2080 | virt_to_page(dev->mdev->clock_info)); |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2081 | } |
| 2082 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2083 | 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] | 2084 | struct vm_area_struct *vma, |
| 2085 | struct mlx5_ib_ucontext *context) |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2086 | { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2087 | struct mlx5_bfreg_info *bfregi = &context->bfregi; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2088 | int err; |
| 2089 | unsigned long idx; |
Kamal Heib | aa09ea6 | 2018-07-19 00:05:32 +0300 | [diff] [blame] | 2090 | phys_addr_t pfn; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2091 | pgprot_t prot; |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2092 | u32 bfreg_dyn_idx = 0; |
| 2093 | u32 uar_index; |
| 2094 | int dyn_uar = (cmd == MLX5_IB_MMAP_ALLOC_WC); |
| 2095 | int max_valid_idx = dyn_uar ? bfregi->num_sys_pages : |
| 2096 | bfregi->num_static_sys_pages; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2097 | |
| 2098 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2099 | return -EINVAL; |
| 2100 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2101 | if (dyn_uar) |
| 2102 | idx = get_extended_index(vma->vm_pgoff) + bfregi->num_static_sys_pages; |
| 2103 | else |
| 2104 | idx = get_index(vma->vm_pgoff); |
| 2105 | |
| 2106 | if (idx >= max_valid_idx) { |
| 2107 | mlx5_ib_warn(dev, "invalid uar index %lu, max=%d\n", |
| 2108 | idx, max_valid_idx); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2109 | return -EINVAL; |
| 2110 | } |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2111 | |
| 2112 | switch (cmd) { |
| 2113 | case MLX5_IB_MMAP_WC_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2114 | case MLX5_IB_MMAP_ALLOC_WC: |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2115 | /* Some architectures don't support WC memory */ |
| 2116 | #if defined(CONFIG_X86) |
| 2117 | if (!pat_enabled()) |
| 2118 | return -EPERM; |
| 2119 | #elif !(defined(CONFIG_PPC) || (defined(CONFIG_ARM) && defined(CONFIG_MMU))) |
| 2120 | return -EPERM; |
| 2121 | #endif |
| 2122 | /* fall through */ |
| 2123 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2124 | /* For MLX5_IB_MMAP_REGULAR_PAGE do the best effort to get WC */ |
| 2125 | prot = pgprot_writecombine(vma->vm_page_prot); |
| 2126 | break; |
| 2127 | case MLX5_IB_MMAP_NC_PAGE: |
| 2128 | prot = pgprot_noncached(vma->vm_page_prot); |
| 2129 | break; |
| 2130 | default: |
| 2131 | return -EINVAL; |
| 2132 | } |
| 2133 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2134 | if (dyn_uar) { |
| 2135 | int uars_per_page; |
| 2136 | |
| 2137 | uars_per_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k); |
| 2138 | bfreg_dyn_idx = idx * (uars_per_page * MLX5_NON_FP_BFREGS_PER_UAR); |
| 2139 | if (bfreg_dyn_idx >= bfregi->total_num_bfregs) { |
| 2140 | mlx5_ib_warn(dev, "invalid bfreg_dyn_idx %u, max=%u\n", |
| 2141 | bfreg_dyn_idx, bfregi->total_num_bfregs); |
| 2142 | return -EINVAL; |
| 2143 | } |
| 2144 | |
| 2145 | mutex_lock(&bfregi->lock); |
| 2146 | /* Fail if uar already allocated, first bfreg index of each |
| 2147 | * page holds its count. |
| 2148 | */ |
| 2149 | if (bfregi->count[bfreg_dyn_idx]) { |
| 2150 | mlx5_ib_warn(dev, "wrong offset, idx %lu is busy, bfregn=%u\n", idx, bfreg_dyn_idx); |
| 2151 | mutex_unlock(&bfregi->lock); |
| 2152 | return -EINVAL; |
| 2153 | } |
| 2154 | |
| 2155 | bfregi->count[bfreg_dyn_idx]++; |
| 2156 | mutex_unlock(&bfregi->lock); |
| 2157 | |
| 2158 | err = mlx5_cmd_alloc_uar(dev->mdev, &uar_index); |
| 2159 | if (err) { |
| 2160 | mlx5_ib_warn(dev, "UAR alloc failed\n"); |
| 2161 | goto free_bfreg; |
| 2162 | } |
| 2163 | } else { |
| 2164 | uar_index = bfregi->sys_pages[idx]; |
| 2165 | } |
| 2166 | |
| 2167 | pfn = uar_index2pfn(dev, uar_index); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2168 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn %pa\n", idx, &pfn); |
| 2169 | |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2170 | err = rdma_user_mmap_io(&context->ibucontext, vma, pfn, PAGE_SIZE, |
| 2171 | prot); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2172 | if (err) { |
Leon Romanovsky | 8f06228 | 2018-05-22 08:31:03 +0300 | [diff] [blame] | 2173 | mlx5_ib_err(dev, |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2174 | "rdma_user_mmap_io failed with error=%d, mmap_cmd=%s\n", |
Leon Romanovsky | 8f06228 | 2018-05-22 08:31:03 +0300 | [diff] [blame] | 2175 | err, mmap_cmd2str(cmd)); |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2176 | goto err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2177 | } |
| 2178 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2179 | if (dyn_uar) |
| 2180 | bfregi->sys_pages[idx] = uar_index; |
| 2181 | return 0; |
| 2182 | |
| 2183 | err: |
| 2184 | if (!dyn_uar) |
| 2185 | return err; |
| 2186 | |
| 2187 | mlx5_cmd_free_uar(dev->mdev, idx); |
| 2188 | |
| 2189 | free_bfreg: |
| 2190 | mlx5_ib_free_bfreg(dev, bfregi, bfreg_dyn_idx); |
| 2191 | |
| 2192 | return err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2193 | } |
| 2194 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2195 | static int dm_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
| 2196 | { |
| 2197 | struct mlx5_ib_ucontext *mctx = to_mucontext(context); |
| 2198 | struct mlx5_ib_dev *dev = to_mdev(context->device); |
| 2199 | u16 page_idx = get_extended_index(vma->vm_pgoff); |
| 2200 | size_t map_size = vma->vm_end - vma->vm_start; |
| 2201 | u32 npages = map_size >> PAGE_SHIFT; |
| 2202 | phys_addr_t pfn; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2203 | |
| 2204 | if (find_next_zero_bit(mctx->dm_pages, page_idx + npages, page_idx) != |
| 2205 | page_idx + npages) |
| 2206 | return -EINVAL; |
| 2207 | |
Huy Nguyen | aa8106f | 2019-03-29 15:38:01 -0700 | [diff] [blame] | 2208 | pfn = ((dev->mdev->bar_addr + |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2209 | MLX5_CAP64_DEV_MEM(dev->mdev, memic_bar_start_addr)) >> |
| 2210 | PAGE_SHIFT) + |
| 2211 | page_idx; |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2212 | return rdma_user_mmap_io(context, vma, pfn, map_size, |
| 2213 | pgprot_writecombine(vma->vm_page_prot)); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2214 | } |
| 2215 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2216 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
| 2217 | { |
| 2218 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 2219 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2220 | unsigned long command; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2221 | phys_addr_t pfn; |
| 2222 | |
| 2223 | command = get_command(vma->vm_pgoff); |
| 2224 | switch (command) { |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2225 | case MLX5_IB_MMAP_WC_PAGE: |
| 2226 | case MLX5_IB_MMAP_NC_PAGE: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2227 | case MLX5_IB_MMAP_REGULAR_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2228 | case MLX5_IB_MMAP_ALLOC_WC: |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2229 | return uar_mmap(dev, command, vma, context); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2230 | |
| 2231 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
| 2232 | return -ENOSYS; |
| 2233 | |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2234 | case MLX5_IB_MMAP_CORE_CLOCK: |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2235 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2236 | return -EINVAL; |
| 2237 | |
Matan Barak | 6cbac1e | 2016-04-14 16:52:10 +0300 | [diff] [blame] | 2238 | if (vma->vm_flags & VM_WRITE) |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2239 | return -EPERM; |
Jason Gunthorpe | c660133 | 2019-04-16 14:07:25 +0300 | [diff] [blame] | 2240 | vma->vm_flags &= ~VM_MAYWRITE; |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2241 | |
| 2242 | /* Don't expose to user-space information it shouldn't have */ |
| 2243 | if (PAGE_SIZE > 4096) |
| 2244 | return -EOPNOTSUPP; |
| 2245 | |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2246 | pfn = (dev->mdev->iseg_base + |
| 2247 | offsetof(struct mlx5_init_seg, internal_timer_h)) >> |
| 2248 | PAGE_SHIFT; |
Jason Gunthorpe | d5e560d | 2019-04-16 14:07:26 +0300 | [diff] [blame] | 2249 | return rdma_user_mmap_io(&context->ibucontext, vma, pfn, |
| 2250 | PAGE_SIZE, |
| 2251 | pgprot_noncached(vma->vm_page_prot)); |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2252 | case MLX5_IB_MMAP_CLOCK_INFO: |
| 2253 | return mlx5_ib_mmap_clock_info_page(dev, vma, context); |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2254 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2255 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2256 | return dm_mmap(ibcontext, vma); |
| 2257 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2258 | default: |
| 2259 | return -EINVAL; |
| 2260 | } |
| 2261 | |
| 2262 | return 0; |
| 2263 | } |
| 2264 | |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2265 | static inline int check_dm_type_support(struct mlx5_ib_dev *dev, |
| 2266 | u32 type) |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2267 | { |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2268 | switch (type) { |
| 2269 | case MLX5_IB_UAPI_DM_TYPE_MEMIC: |
| 2270 | if (!MLX5_CAP_DEV_MEM(dev->mdev, memic)) |
| 2271 | return -EOPNOTSUPP; |
| 2272 | break; |
| 2273 | case MLX5_IB_UAPI_DM_TYPE_STEERING_SW_ICM: |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2274 | case MLX5_IB_UAPI_DM_TYPE_HEADER_MODIFY_SW_ICM: |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2275 | if (!capable(CAP_SYS_RAWIO) || |
| 2276 | !capable(CAP_NET_RAW)) |
| 2277 | return -EPERM; |
| 2278 | |
| 2279 | if (!(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, sw_owner) || |
| 2280 | MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, sw_owner))) |
| 2281 | return -EOPNOTSUPP; |
| 2282 | break; |
| 2283 | } |
| 2284 | |
| 2285 | return 0; |
| 2286 | } |
| 2287 | |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2288 | static int handle_alloc_dm_memic(struct ib_ucontext *ctx, |
| 2289 | struct mlx5_ib_dm *dm, |
| 2290 | struct ib_dm_alloc_attr *attr, |
| 2291 | struct uverbs_attr_bundle *attrs) |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2292 | { |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2293 | struct mlx5_dm *dm_db = &to_mdev(ctx->device)->dm; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2294 | u64 start_offset; |
| 2295 | u32 page_idx; |
| 2296 | int err; |
| 2297 | |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2298 | dm->size = roundup(attr->length, MLX5_MEMIC_BASE_SIZE); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2299 | |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2300 | err = mlx5_cmd_alloc_memic(dm_db, &dm->dev_addr, |
| 2301 | dm->size, attr->alignment); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2302 | if (err) |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2303 | return err; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2304 | |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2305 | page_idx = (dm->dev_addr - pci_resource_start(dm_db->dev->pdev, 0) - |
| 2306 | MLX5_CAP64_DEV_MEM(dm_db->dev, memic_bar_start_addr)) >> |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2307 | PAGE_SHIFT; |
| 2308 | |
| 2309 | err = uverbs_copy_to(attrs, |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2310 | MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 2311 | &page_idx, sizeof(page_idx)); |
| 2312 | if (err) |
| 2313 | goto err_dealloc; |
| 2314 | |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2315 | start_offset = dm->dev_addr & ~PAGE_MASK; |
| 2316 | err = uverbs_copy_to(attrs, |
| 2317 | MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 2318 | &start_offset, sizeof(start_offset)); |
| 2319 | if (err) |
| 2320 | goto err_dealloc; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2321 | |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2322 | bitmap_set(to_mucontext(ctx)->dm_pages, page_idx, |
| 2323 | DIV_ROUND_UP(dm->size, PAGE_SIZE)); |
| 2324 | |
| 2325 | return 0; |
| 2326 | |
| 2327 | err_dealloc: |
| 2328 | mlx5_cmd_dealloc_memic(dm_db, dm->dev_addr, dm->size); |
| 2329 | |
| 2330 | return err; |
| 2331 | } |
| 2332 | |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2333 | static int handle_alloc_dm_sw_icm(struct ib_ucontext *ctx, |
| 2334 | struct mlx5_ib_dm *dm, |
| 2335 | struct ib_dm_alloc_attr *attr, |
| 2336 | struct uverbs_attr_bundle *attrs, |
| 2337 | int type) |
| 2338 | { |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2339 | struct mlx5_core_dev *dev = to_mdev(ctx->device)->mdev; |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2340 | u64 act_size; |
| 2341 | int err; |
| 2342 | |
| 2343 | /* Allocation size must a multiple of the basic block size |
| 2344 | * and a power of 2. |
| 2345 | */ |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2346 | act_size = round_up(attr->length, MLX5_SW_ICM_BLOCK_SIZE(dev)); |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2347 | act_size = roundup_pow_of_two(act_size); |
| 2348 | |
| 2349 | dm->size = act_size; |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2350 | err = mlx5_dm_sw_icm_alloc(dev, type, act_size, |
| 2351 | to_mucontext(ctx)->devx_uid, &dm->dev_addr, |
| 2352 | &dm->icm_dm.obj_id); |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2353 | if (err) |
| 2354 | return err; |
| 2355 | |
| 2356 | err = uverbs_copy_to(attrs, |
| 2357 | MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 2358 | &dm->dev_addr, sizeof(dm->dev_addr)); |
| 2359 | if (err) |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2360 | mlx5_dm_sw_icm_dealloc(dev, type, dm->size, |
| 2361 | to_mucontext(ctx)->devx_uid, dm->dev_addr, |
| 2362 | dm->icm_dm.obj_id); |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2363 | |
| 2364 | return err; |
| 2365 | } |
| 2366 | |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2367 | struct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev, |
| 2368 | struct ib_ucontext *context, |
| 2369 | struct ib_dm_alloc_attr *attr, |
| 2370 | struct uverbs_attr_bundle *attrs) |
| 2371 | { |
| 2372 | struct mlx5_ib_dm *dm; |
| 2373 | enum mlx5_ib_uapi_dm_type type; |
| 2374 | int err; |
| 2375 | |
| 2376 | err = uverbs_get_const_default(&type, attrs, |
| 2377 | MLX5_IB_ATTR_ALLOC_DM_REQ_TYPE, |
| 2378 | MLX5_IB_UAPI_DM_TYPE_MEMIC); |
| 2379 | if (err) |
| 2380 | return ERR_PTR(err); |
| 2381 | |
| 2382 | mlx5_ib_dbg(to_mdev(ibdev), "alloc_dm req: dm_type=%d user_length=0x%llx log_alignment=%d\n", |
| 2383 | type, attr->length, attr->alignment); |
| 2384 | |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2385 | err = check_dm_type_support(to_mdev(ibdev), type); |
| 2386 | if (err) |
| 2387 | return ERR_PTR(err); |
| 2388 | |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2389 | dm = kzalloc(sizeof(*dm), GFP_KERNEL); |
| 2390 | if (!dm) |
| 2391 | return ERR_PTR(-ENOMEM); |
| 2392 | |
| 2393 | dm->type = type; |
| 2394 | |
| 2395 | switch (type) { |
| 2396 | case MLX5_IB_UAPI_DM_TYPE_MEMIC: |
| 2397 | err = handle_alloc_dm_memic(context, dm, |
| 2398 | attr, |
| 2399 | attrs); |
| 2400 | break; |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2401 | case MLX5_IB_UAPI_DM_TYPE_STEERING_SW_ICM: |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2402 | err = handle_alloc_dm_sw_icm(context, dm, |
| 2403 | attr, attrs, |
| 2404 | MLX5_SW_ICM_TYPE_STEERING); |
| 2405 | break; |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2406 | case MLX5_IB_UAPI_DM_TYPE_HEADER_MODIFY_SW_ICM: |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2407 | err = handle_alloc_dm_sw_icm(context, dm, |
| 2408 | attr, attrs, |
| 2409 | MLX5_SW_ICM_TYPE_HEADER_MODIFY); |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2410 | break; |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2411 | default: |
| 2412 | err = -EOPNOTSUPP; |
| 2413 | } |
| 2414 | |
| 2415 | if (err) |
| 2416 | goto err_free; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2417 | |
| 2418 | return &dm->ibdm; |
| 2419 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2420 | err_free: |
| 2421 | kfree(dm); |
| 2422 | return ERR_PTR(err); |
| 2423 | } |
| 2424 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2425 | 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] | 2426 | { |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2427 | struct mlx5_ib_ucontext *ctx = rdma_udata_to_drv_context( |
| 2428 | &attrs->driver_udata, struct mlx5_ib_ucontext, ibucontext); |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2429 | struct mlx5_core_dev *dev = to_mdev(ibdm->device)->mdev; |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2430 | struct mlx5_dm *dm_db = &to_mdev(ibdm->device)->dm; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2431 | struct mlx5_ib_dm *dm = to_mdm(ibdm); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2432 | u32 page_idx; |
| 2433 | int ret; |
| 2434 | |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2435 | switch (dm->type) { |
| 2436 | case MLX5_IB_UAPI_DM_TYPE_MEMIC: |
| 2437 | ret = mlx5_cmd_dealloc_memic(dm_db, dm->dev_addr, dm->size); |
| 2438 | if (ret) |
| 2439 | return ret; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2440 | |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2441 | page_idx = (dm->dev_addr - pci_resource_start(dev->pdev, 0) - |
| 2442 | MLX5_CAP64_DEV_MEM(dev, memic_bar_start_addr)) >> |
| 2443 | PAGE_SHIFT; |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2444 | bitmap_clear(ctx->dm_pages, page_idx, |
| 2445 | DIV_ROUND_UP(dm->size, PAGE_SIZE)); |
| 2446 | break; |
| 2447 | case MLX5_IB_UAPI_DM_TYPE_STEERING_SW_ICM: |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2448 | ret = mlx5_dm_sw_icm_dealloc(dev, MLX5_SW_ICM_TYPE_STEERING, |
| 2449 | dm->size, ctx->devx_uid, dm->dev_addr, |
| 2450 | dm->icm_dm.obj_id); |
| 2451 | if (ret) |
| 2452 | return ret; |
| 2453 | break; |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2454 | case MLX5_IB_UAPI_DM_TYPE_HEADER_MODIFY_SW_ICM: |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 2455 | ret = mlx5_dm_sw_icm_dealloc(dev, MLX5_SW_ICM_TYPE_HEADER_MODIFY, |
| 2456 | dm->size, ctx->devx_uid, dm->dev_addr, |
| 2457 | dm->icm_dm.obj_id); |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 2458 | if (ret) |
| 2459 | return ret; |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 2460 | break; |
| 2461 | default: |
| 2462 | return -EOPNOTSUPP; |
| 2463 | } |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2464 | |
| 2465 | kfree(dm); |
| 2466 | |
| 2467 | return 0; |
| 2468 | } |
| 2469 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2470 | 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] | 2471 | { |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2472 | struct mlx5_ib_pd *pd = to_mpd(ibpd); |
| 2473 | struct ib_device *ibdev = ibpd->device; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2474 | struct mlx5_ib_alloc_pd_resp resp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2475 | int err; |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2476 | u32 out[MLX5_ST_SZ_DW(alloc_pd_out)] = {}; |
| 2477 | u32 in[MLX5_ST_SZ_DW(alloc_pd_in)] = {}; |
| 2478 | u16 uid = 0; |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2479 | struct mlx5_ib_ucontext *context = rdma_udata_to_drv_context( |
| 2480 | udata, struct mlx5_ib_ucontext, ibucontext); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2481 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2482 | uid = context ? context->devx_uid : 0; |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2483 | MLX5_SET(alloc_pd_in, in, opcode, MLX5_CMD_OP_ALLOC_PD); |
| 2484 | MLX5_SET(alloc_pd_in, in, uid, uid); |
| 2485 | err = mlx5_cmd_exec(to_mdev(ibdev)->mdev, in, sizeof(in), |
| 2486 | out, sizeof(out)); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2487 | if (err) |
| 2488 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2489 | |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2490 | pd->pdn = MLX5_GET(alloc_pd_out, out, pd); |
| 2491 | pd->uid = uid; |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2492 | if (udata) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2493 | resp.pdn = pd->pdn; |
| 2494 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2495 | mlx5_cmd_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn, uid); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2496 | return -EFAULT; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2497 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2498 | } |
| 2499 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2500 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2501 | } |
| 2502 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2503 | 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] | 2504 | { |
| 2505 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 2506 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
| 2507 | |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2508 | mlx5_cmd_dealloc_pd(mdev->mdev, mpd->pdn, mpd->uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2509 | } |
| 2510 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2511 | enum { |
| 2512 | MATCH_CRITERIA_ENABLE_OUTER_BIT, |
| 2513 | MATCH_CRITERIA_ENABLE_MISC_BIT, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2514 | MATCH_CRITERIA_ENABLE_INNER_BIT, |
| 2515 | MATCH_CRITERIA_ENABLE_MISC2_BIT |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2516 | }; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2517 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2518 | #define HEADER_IS_ZERO(match_criteria, headers) \ |
| 2519 | !(memchr_inv(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \ |
| 2520 | 0, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \ |
| 2521 | |
| 2522 | static u8 get_match_criteria_enable(u32 *match_criteria) |
| 2523 | { |
| 2524 | u8 match_criteria_enable; |
| 2525 | |
| 2526 | match_criteria_enable = |
| 2527 | (!HEADER_IS_ZERO(match_criteria, outer_headers)) << |
| 2528 | MATCH_CRITERIA_ENABLE_OUTER_BIT; |
| 2529 | match_criteria_enable |= |
| 2530 | (!HEADER_IS_ZERO(match_criteria, misc_parameters)) << |
| 2531 | MATCH_CRITERIA_ENABLE_MISC_BIT; |
| 2532 | match_criteria_enable |= |
| 2533 | (!HEADER_IS_ZERO(match_criteria, inner_headers)) << |
| 2534 | MATCH_CRITERIA_ENABLE_INNER_BIT; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2535 | match_criteria_enable |= |
| 2536 | (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) << |
| 2537 | MATCH_CRITERIA_ENABLE_MISC2_BIT; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2538 | |
| 2539 | return match_criteria_enable; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2540 | } |
| 2541 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2542 | 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] | 2543 | { |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2544 | u8 entry_mask; |
| 2545 | u8 entry_val; |
| 2546 | int err = 0; |
| 2547 | |
| 2548 | if (!mask) |
| 2549 | goto out; |
| 2550 | |
| 2551 | entry_mask = MLX5_GET(fte_match_set_lyr_2_4, outer_c, |
| 2552 | ip_protocol); |
| 2553 | entry_val = MLX5_GET(fte_match_set_lyr_2_4, outer_v, |
| 2554 | ip_protocol); |
| 2555 | if (!entry_mask) { |
| 2556 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_protocol, mask); |
| 2557 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_protocol, val); |
| 2558 | goto out; |
| 2559 | } |
| 2560 | /* Don't override existing ip protocol */ |
| 2561 | if (mask != entry_mask || val != entry_val) |
| 2562 | err = -EINVAL; |
| 2563 | out: |
| 2564 | return err; |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2565 | } |
| 2566 | |
Daria Velikovsky | 37da2a0 | 2018-05-07 10:20:02 +0300 | [diff] [blame] | 2567 | 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] | 2568 | bool inner) |
| 2569 | { |
| 2570 | if (inner) { |
| 2571 | MLX5_SET(fte_match_set_misc, |
| 2572 | misc_c, inner_ipv6_flow_label, mask); |
| 2573 | MLX5_SET(fte_match_set_misc, |
| 2574 | misc_v, inner_ipv6_flow_label, val); |
| 2575 | } else { |
| 2576 | MLX5_SET(fte_match_set_misc, |
| 2577 | misc_c, outer_ipv6_flow_label, mask); |
| 2578 | MLX5_SET(fte_match_set_misc, |
| 2579 | misc_v, outer_ipv6_flow_label, val); |
| 2580 | } |
| 2581 | } |
| 2582 | |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2583 | static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val) |
| 2584 | { |
| 2585 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_ecn, mask); |
| 2586 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_ecn, val); |
| 2587 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_dscp, mask >> 2); |
| 2588 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_dscp, val >> 2); |
| 2589 | } |
| 2590 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2591 | static int check_mpls_supp_fields(u32 field_support, const __be32 *set_mask) |
| 2592 | { |
| 2593 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_label) && |
| 2594 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_LABEL)) |
| 2595 | return -EOPNOTSUPP; |
| 2596 | |
| 2597 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_exp) && |
| 2598 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_EXP)) |
| 2599 | return -EOPNOTSUPP; |
| 2600 | |
| 2601 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_s_bos) && |
| 2602 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_S_BOS)) |
| 2603 | return -EOPNOTSUPP; |
| 2604 | |
| 2605 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_ttl) && |
| 2606 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_TTL)) |
| 2607 | return -EOPNOTSUPP; |
| 2608 | |
| 2609 | return 0; |
| 2610 | } |
| 2611 | |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2612 | #define LAST_ETH_FIELD vlan_tag |
| 2613 | #define LAST_IB_FIELD sl |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2614 | #define LAST_IPV4_FIELD tos |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2615 | #define LAST_IPV6_FIELD traffic_class |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2616 | #define LAST_TCP_UDP_FIELD src_port |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2617 | #define LAST_TUNNEL_FIELD tunnel_id |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2618 | #define LAST_FLOW_TAG_FIELD tag_id |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2619 | #define LAST_DROP_FIELD size |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2620 | #define LAST_COUNTERS_FIELD counters |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2621 | |
| 2622 | /* Field is the last supported field */ |
| 2623 | #define FIELDS_NOT_SUPPORTED(filter, field)\ |
| 2624 | memchr_inv((void *)&filter.field +\ |
| 2625 | sizeof(filter.field), 0,\ |
| 2626 | sizeof(filter) -\ |
| 2627 | offsetof(typeof(filter), field) -\ |
| 2628 | sizeof(filter.field)) |
| 2629 | |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2630 | int parse_flow_flow_action(struct mlx5_ib_flow_action *maction, |
| 2631 | bool is_egress, |
| 2632 | struct mlx5_flow_act *action) |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2633 | { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2634 | |
| 2635 | switch (maction->ib_action.type) { |
| 2636 | case IB_FLOW_ACTION_ESP: |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2637 | if (action->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 2638 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)) |
| 2639 | return -EINVAL; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2640 | /* Currently only AES_GCM keymat is supported by the driver */ |
| 2641 | action->esp_id = (uintptr_t)maction->esp_aes_gcm.ctx; |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2642 | action->action |= is_egress ? |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2643 | MLX5_FLOW_CONTEXT_ACTION_ENCRYPT : |
| 2644 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT; |
| 2645 | return 0; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2646 | case IB_FLOW_ACTION_UNSPECIFIED: |
| 2647 | if (maction->flow_action_raw.sub_type == |
| 2648 | MLX5_IB_FLOW_ACTION_MODIFY_HEADER) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2649 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) |
| 2650 | return -EINVAL; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2651 | action->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; |
Maor Gottlieb | 2b688ea | 2019-08-15 13:54:17 +0300 | [diff] [blame] | 2652 | action->modify_hdr = |
| 2653 | maction->flow_action_raw.modify_hdr; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2654 | return 0; |
| 2655 | } |
Mark Bloch | 10a3089 | 2018-09-02 12:51:34 +0300 | [diff] [blame] | 2656 | if (maction->flow_action_raw.sub_type == |
| 2657 | MLX5_IB_FLOW_ACTION_DECAP) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2658 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_DECAP) |
| 2659 | return -EINVAL; |
Mark Bloch | 10a3089 | 2018-09-02 12:51:34 +0300 | [diff] [blame] | 2660 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DECAP; |
| 2661 | return 0; |
| 2662 | } |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2663 | if (maction->flow_action_raw.sub_type == |
| 2664 | MLX5_IB_FLOW_ACTION_PACKET_REFORMAT) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2665 | if (action->action & |
| 2666 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT) |
| 2667 | return -EINVAL; |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2668 | action->action |= |
| 2669 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT; |
Maor Gottlieb | 2b688ea | 2019-08-15 13:54:17 +0300 | [diff] [blame] | 2670 | action->pkt_reformat = |
| 2671 | maction->flow_action_raw.pkt_reformat; |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2672 | return 0; |
| 2673 | } |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2674 | /* fall through */ |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2675 | default: |
| 2676 | return -EOPNOTSUPP; |
| 2677 | } |
| 2678 | } |
| 2679 | |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 2680 | static int parse_flow_attr(struct mlx5_core_dev *mdev, |
| 2681 | struct mlx5_flow_spec *spec, |
| 2682 | const union ib_flow_spec *ib_spec, |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2683 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2684 | struct mlx5_flow_act *action, u32 prev_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2685 | { |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 2686 | struct mlx5_flow_context *flow_context = &spec->flow_context; |
| 2687 | u32 *match_c = spec->match_criteria; |
| 2688 | u32 *match_v = spec->match_value; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2689 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2690 | misc_parameters); |
| 2691 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2692 | misc_parameters); |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2693 | void *misc_params2_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2694 | misc_parameters_2); |
| 2695 | void *misc_params2_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2696 | misc_parameters_2); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2697 | void *headers_c; |
| 2698 | void *headers_v; |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2699 | int match_ipv; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2700 | int ret; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2701 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2702 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2703 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2704 | inner_headers); |
| 2705 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2706 | inner_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2707 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2708 | ft_field_support.inner_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2709 | } else { |
| 2710 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2711 | outer_headers); |
| 2712 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2713 | outer_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2714 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2715 | ft_field_support.outer_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2719 | case IB_FLOW_SPEC_ETH: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2720 | if (FIELDS_NOT_SUPPORTED(ib_spec->eth.mask, LAST_ETH_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2721 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2722 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2723 | 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] | 2724 | dmac_47_16), |
| 2725 | ib_spec->eth.mask.dst_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2726 | 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] | 2727 | dmac_47_16), |
| 2728 | ib_spec->eth.val.dst_mac); |
| 2729 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2730 | 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] | 2731 | smac_47_16), |
| 2732 | ib_spec->eth.mask.src_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2733 | 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] | 2734 | smac_47_16), |
| 2735 | ib_spec->eth.val.src_mac); |
| 2736 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2737 | if (ib_spec->eth.mask.vlan_tag) { |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2738 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2739 | cvlan_tag, 1); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2740 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2741 | cvlan_tag, 1); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2742 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2743 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2744 | first_vid, ntohs(ib_spec->eth.mask.vlan_tag)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2745 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2746 | first_vid, ntohs(ib_spec->eth.val.vlan_tag)); |
| 2747 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2748 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2749 | first_cfi, |
| 2750 | ntohs(ib_spec->eth.mask.vlan_tag) >> 12); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2751 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2752 | first_cfi, |
| 2753 | ntohs(ib_spec->eth.val.vlan_tag) >> 12); |
| 2754 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2755 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2756 | first_prio, |
| 2757 | ntohs(ib_spec->eth.mask.vlan_tag) >> 13); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2758 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2759 | first_prio, |
| 2760 | ntohs(ib_spec->eth.val.vlan_tag) >> 13); |
| 2761 | } |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2762 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2763 | ethertype, ntohs(ib_spec->eth.mask.ether_type)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2764 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2765 | ethertype, ntohs(ib_spec->eth.val.ether_type)); |
| 2766 | break; |
| 2767 | case IB_FLOW_SPEC_IPV4: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2768 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv4.mask, LAST_IPV4_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2769 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2770 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2771 | if (match_ipv) { |
| 2772 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2773 | ip_version, 0xf); |
| 2774 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2775 | ip_version, MLX5_FS_IPV4_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2776 | } else { |
| 2777 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2778 | ethertype, 0xffff); |
| 2779 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2780 | ethertype, ETH_P_IP); |
| 2781 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2782 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2783 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2784 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2785 | &ib_spec->ipv4.mask.src_ip, |
| 2786 | sizeof(ib_spec->ipv4.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2787 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2788 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2789 | &ib_spec->ipv4.val.src_ip, |
| 2790 | sizeof(ib_spec->ipv4.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2791 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2792 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2793 | &ib_spec->ipv4.mask.dst_ip, |
| 2794 | sizeof(ib_spec->ipv4.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2795 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2796 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2797 | &ib_spec->ipv4.val.dst_ip, |
| 2798 | sizeof(ib_spec->ipv4.val.dst_ip)); |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2799 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2800 | set_tos(headers_c, headers_v, |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2801 | ib_spec->ipv4.mask.tos, ib_spec->ipv4.val.tos); |
| 2802 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2803 | if (set_proto(headers_c, headers_v, |
| 2804 | ib_spec->ipv4.mask.proto, |
| 2805 | ib_spec->ipv4.val.proto)) |
| 2806 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2807 | break; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2808 | case IB_FLOW_SPEC_IPV6: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2809 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv6.mask, LAST_IPV6_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2810 | return -EOPNOTSUPP; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2811 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2812 | if (match_ipv) { |
| 2813 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2814 | ip_version, 0xf); |
| 2815 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2816 | ip_version, MLX5_FS_IPV6_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2817 | } else { |
| 2818 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2819 | ethertype, 0xffff); |
| 2820 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2821 | ethertype, ETH_P_IPV6); |
| 2822 | } |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2823 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2824 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2825 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2826 | &ib_spec->ipv6.mask.src_ip, |
| 2827 | sizeof(ib_spec->ipv6.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2828 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2829 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2830 | &ib_spec->ipv6.val.src_ip, |
| 2831 | sizeof(ib_spec->ipv6.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2832 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2833 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2834 | &ib_spec->ipv6.mask.dst_ip, |
| 2835 | sizeof(ib_spec->ipv6.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2836 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2837 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2838 | &ib_spec->ipv6.val.dst_ip, |
| 2839 | sizeof(ib_spec->ipv6.val.dst_ip)); |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2840 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2841 | set_tos(headers_c, headers_v, |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2842 | ib_spec->ipv6.mask.traffic_class, |
| 2843 | ib_spec->ipv6.val.traffic_class); |
| 2844 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2845 | if (set_proto(headers_c, headers_v, |
| 2846 | ib_spec->ipv6.mask.next_hdr, |
| 2847 | ib_spec->ipv6.val.next_hdr)) |
| 2848 | return -EINVAL; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2849 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2850 | set_flow_label(misc_params_c, misc_params_v, |
| 2851 | ntohl(ib_spec->ipv6.mask.flow_label), |
| 2852 | ntohl(ib_spec->ipv6.val.flow_label), |
| 2853 | ib_spec->type & IB_FLOW_SPEC_INNER); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2854 | break; |
| 2855 | case IB_FLOW_SPEC_ESP: |
| 2856 | if (ib_spec->esp.mask.seq) |
| 2857 | return -EOPNOTSUPP; |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2858 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2859 | MLX5_SET(fte_match_set_misc, misc_params_c, outer_esp_spi, |
| 2860 | ntohl(ib_spec->esp.mask.spi)); |
| 2861 | MLX5_SET(fte_match_set_misc, misc_params_v, outer_esp_spi, |
| 2862 | ntohl(ib_spec->esp.val.spi)); |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2863 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2864 | case IB_FLOW_SPEC_TCP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2865 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2866 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2867 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2868 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2869 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_TCP)) |
| 2870 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2871 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2872 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2873 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2874 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2875 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2876 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2877 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2878 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2879 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2880 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2881 | break; |
| 2882 | case IB_FLOW_SPEC_UDP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2883 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2884 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2885 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2886 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2887 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_UDP)) |
| 2888 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2889 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2890 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2891 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2892 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2893 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2894 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2895 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2896 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2897 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2898 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2899 | break; |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2900 | case IB_FLOW_SPEC_GRE: |
| 2901 | if (ib_spec->gre.mask.c_ks_res0_ver) |
| 2902 | return -EOPNOTSUPP; |
| 2903 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2904 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_GRE)) |
| 2905 | return -EINVAL; |
| 2906 | |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2907 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
| 2908 | 0xff); |
| 2909 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
| 2910 | IPPROTO_GRE); |
| 2911 | |
| 2912 | MLX5_SET(fte_match_set_misc, misc_params_c, gre_protocol, |
Maor Gottlieb | a93b632 | 2018-07-01 15:50:17 +0300 | [diff] [blame] | 2913 | ntohs(ib_spec->gre.mask.protocol)); |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2914 | MLX5_SET(fte_match_set_misc, misc_params_v, gre_protocol, |
| 2915 | ntohs(ib_spec->gre.val.protocol)); |
| 2916 | |
| 2917 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_c, |
Oz Shlomo | 5886a96 | 2018-12-10 13:15:13 -0800 | [diff] [blame] | 2918 | gre_key.nvgre.hi), |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2919 | &ib_spec->gre.mask.key, |
| 2920 | sizeof(ib_spec->gre.mask.key)); |
| 2921 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_v, |
Oz Shlomo | 5886a96 | 2018-12-10 13:15:13 -0800 | [diff] [blame] | 2922 | gre_key.nvgre.hi), |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2923 | &ib_spec->gre.val.key, |
| 2924 | sizeof(ib_spec->gre.val.key)); |
| 2925 | break; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2926 | case IB_FLOW_SPEC_MPLS: |
| 2927 | switch (prev_type) { |
| 2928 | case IB_FLOW_SPEC_UDP: |
| 2929 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2930 | ft_field_support.outer_first_mpls_over_udp), |
| 2931 | &ib_spec->mpls.mask.tag)) |
| 2932 | return -EOPNOTSUPP; |
| 2933 | |
| 2934 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2935 | outer_first_mpls_over_udp), |
| 2936 | &ib_spec->mpls.val.tag, |
| 2937 | sizeof(ib_spec->mpls.val.tag)); |
| 2938 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2939 | outer_first_mpls_over_udp), |
| 2940 | &ib_spec->mpls.mask.tag, |
| 2941 | sizeof(ib_spec->mpls.mask.tag)); |
| 2942 | break; |
| 2943 | case IB_FLOW_SPEC_GRE: |
| 2944 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2945 | ft_field_support.outer_first_mpls_over_gre), |
| 2946 | &ib_spec->mpls.mask.tag)) |
| 2947 | return -EOPNOTSUPP; |
| 2948 | |
| 2949 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2950 | outer_first_mpls_over_gre), |
| 2951 | &ib_spec->mpls.val.tag, |
| 2952 | sizeof(ib_spec->mpls.val.tag)); |
| 2953 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2954 | outer_first_mpls_over_gre), |
| 2955 | &ib_spec->mpls.mask.tag, |
| 2956 | sizeof(ib_spec->mpls.mask.tag)); |
| 2957 | break; |
| 2958 | default: |
| 2959 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2960 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2961 | ft_field_support.inner_first_mpls), |
| 2962 | &ib_spec->mpls.mask.tag)) |
| 2963 | return -EOPNOTSUPP; |
| 2964 | |
| 2965 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2966 | inner_first_mpls), |
| 2967 | &ib_spec->mpls.val.tag, |
| 2968 | sizeof(ib_spec->mpls.val.tag)); |
| 2969 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2970 | inner_first_mpls), |
| 2971 | &ib_spec->mpls.mask.tag, |
| 2972 | sizeof(ib_spec->mpls.mask.tag)); |
| 2973 | } else { |
| 2974 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2975 | ft_field_support.outer_first_mpls), |
| 2976 | &ib_spec->mpls.mask.tag)) |
| 2977 | return -EOPNOTSUPP; |
| 2978 | |
| 2979 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2980 | outer_first_mpls), |
| 2981 | &ib_spec->mpls.val.tag, |
| 2982 | sizeof(ib_spec->mpls.val.tag)); |
| 2983 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2984 | outer_first_mpls), |
| 2985 | &ib_spec->mpls.mask.tag, |
| 2986 | sizeof(ib_spec->mpls.mask.tag)); |
| 2987 | } |
| 2988 | } |
| 2989 | break; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2990 | case IB_FLOW_SPEC_VXLAN_TUNNEL: |
| 2991 | if (FIELDS_NOT_SUPPORTED(ib_spec->tunnel.mask, |
| 2992 | LAST_TUNNEL_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2993 | return -EOPNOTSUPP; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2994 | |
| 2995 | MLX5_SET(fte_match_set_misc, misc_params_c, vxlan_vni, |
| 2996 | ntohl(ib_spec->tunnel.mask.tunnel_id)); |
| 2997 | MLX5_SET(fte_match_set_misc, misc_params_v, vxlan_vni, |
| 2998 | ntohl(ib_spec->tunnel.val.tunnel_id)); |
| 2999 | break; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3000 | case IB_FLOW_SPEC_ACTION_TAG: |
| 3001 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_tag, |
| 3002 | LAST_FLOW_TAG_FIELD)) |
| 3003 | return -EOPNOTSUPP; |
| 3004 | if (ib_spec->flow_tag.tag_id >= BIT(24)) |
| 3005 | return -EINVAL; |
| 3006 | |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 3007 | flow_context->flow_tag = ib_spec->flow_tag.tag_id; |
| 3008 | flow_context->flags |= FLOW_CONTEXT_HAS_TAG; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3009 | break; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3010 | case IB_FLOW_SPEC_ACTION_DROP: |
| 3011 | if (FIELDS_NOT_SUPPORTED(ib_spec->drop, |
| 3012 | LAST_DROP_FIELD)) |
| 3013 | return -EOPNOTSUPP; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3014 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DROP; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3015 | break; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3016 | case IB_FLOW_SPEC_ACTION_HANDLE: |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 3017 | ret = parse_flow_flow_action(to_mflow_act(ib_spec->action.act), |
| 3018 | flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS, action); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3019 | if (ret) |
| 3020 | return ret; |
| 3021 | break; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3022 | case IB_FLOW_SPEC_ACTION_COUNT: |
| 3023 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_count, |
| 3024 | LAST_COUNTERS_FIELD)) |
| 3025 | return -EOPNOTSUPP; |
| 3026 | |
| 3027 | /* for now support only one counters spec per flow */ |
| 3028 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) |
| 3029 | return -EINVAL; |
| 3030 | |
| 3031 | action->counters = ib_spec->flow_count.counters; |
| 3032 | action->action |= MLX5_FLOW_CONTEXT_ACTION_COUNT; |
| 3033 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3034 | default: |
| 3035 | return -EINVAL; |
| 3036 | } |
| 3037 | |
| 3038 | return 0; |
| 3039 | } |
| 3040 | |
| 3041 | /* If a flow could catch both multicast and unicast packets, |
| 3042 | * it won't fall into the multicast flow steering table and this rule |
| 3043 | * could steal other multicast packets. |
| 3044 | */ |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3045 | 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] | 3046 | { |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 3047 | union ib_flow_spec *flow_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3048 | |
| 3049 | if (ib_attr->type != IB_FLOW_ATTR_NORMAL || |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3050 | ib_attr->num_of_specs < 1) |
| 3051 | return false; |
| 3052 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 3053 | flow_spec = (union ib_flow_spec *)(ib_attr + 1); |
| 3054 | if (flow_spec->type == IB_FLOW_SPEC_IPV4) { |
| 3055 | struct ib_flow_spec_ipv4 *ipv4_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3056 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 3057 | ipv4_spec = (struct ib_flow_spec_ipv4 *)flow_spec; |
| 3058 | if (ipv4_is_multicast(ipv4_spec->val.dst_ip)) |
| 3059 | return true; |
| 3060 | |
| 3061 | return false; |
| 3062 | } |
| 3063 | |
| 3064 | if (flow_spec->type == IB_FLOW_SPEC_ETH) { |
| 3065 | struct ib_flow_spec_eth *eth_spec; |
| 3066 | |
| 3067 | eth_spec = (struct ib_flow_spec_eth *)flow_spec; |
| 3068 | return is_multicast_ether_addr(eth_spec->mask.dst_mac) && |
| 3069 | is_multicast_ether_addr(eth_spec->val.dst_mac); |
| 3070 | } |
| 3071 | |
| 3072 | return false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3073 | } |
| 3074 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3075 | enum valid_spec { |
| 3076 | VALID_SPEC_INVALID, |
| 3077 | VALID_SPEC_VALID, |
| 3078 | VALID_SPEC_NA, |
| 3079 | }; |
| 3080 | |
| 3081 | static enum valid_spec |
| 3082 | is_valid_esp_aes_gcm(struct mlx5_core_dev *mdev, |
| 3083 | const struct mlx5_flow_spec *spec, |
| 3084 | const struct mlx5_flow_act *flow_act, |
| 3085 | bool egress) |
| 3086 | { |
| 3087 | const u32 *match_c = spec->match_criteria; |
| 3088 | bool is_crypto = |
| 3089 | (flow_act->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 3090 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)); |
| 3091 | bool is_ipsec = mlx5_fs_is_ipsec_flow(match_c); |
| 3092 | bool is_drop = flow_act->action & MLX5_FLOW_CONTEXT_ACTION_DROP; |
| 3093 | |
| 3094 | /* |
| 3095 | * Currently only crypto is supported in egress, when regular egress |
| 3096 | * rules would be supported, always return VALID_SPEC_NA. |
| 3097 | */ |
| 3098 | if (!is_crypto) |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3099 | return VALID_SPEC_NA; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3100 | |
| 3101 | return is_crypto && is_ipsec && |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 3102 | (!egress || (!is_drop && |
| 3103 | !(spec->flow_context.flags & FLOW_CONTEXT_HAS_TAG))) ? |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3104 | VALID_SPEC_VALID : VALID_SPEC_INVALID; |
| 3105 | } |
| 3106 | |
| 3107 | static bool is_valid_spec(struct mlx5_core_dev *mdev, |
| 3108 | const struct mlx5_flow_spec *spec, |
| 3109 | const struct mlx5_flow_act *flow_act, |
| 3110 | bool egress) |
| 3111 | { |
| 3112 | /* We curretly only support ipsec egress flow */ |
| 3113 | return is_valid_esp_aes_gcm(mdev, spec, flow_act, egress) != VALID_SPEC_INVALID; |
| 3114 | } |
| 3115 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3116 | static bool is_valid_ethertype(struct mlx5_core_dev *mdev, |
| 3117 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3118 | bool check_inner) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3119 | { |
| 3120 | 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] | 3121 | int match_ipv = check_inner ? |
| 3122 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 3123 | ft_field_support.inner_ip_version) : |
| 3124 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 3125 | ft_field_support.outer_ip_version); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3126 | int inner_bit = check_inner ? IB_FLOW_SPEC_INNER : 0; |
| 3127 | bool ipv4_spec_valid, ipv6_spec_valid; |
| 3128 | unsigned int ip_spec_type = 0; |
| 3129 | bool has_ethertype = false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3130 | unsigned int spec_index; |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3131 | bool mask_valid = true; |
| 3132 | u16 eth_type = 0; |
| 3133 | bool type_valid; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3134 | |
| 3135 | /* Validate that ethertype is correct */ |
| 3136 | 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] | 3137 | if ((ib_spec->type == (IB_FLOW_SPEC_ETH | inner_bit)) && |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3138 | ib_spec->eth.mask.ether_type) { |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3139 | mask_valid = (ib_spec->eth.mask.ether_type == |
| 3140 | htons(0xffff)); |
| 3141 | has_ethertype = true; |
| 3142 | eth_type = ntohs(ib_spec->eth.val.ether_type); |
| 3143 | } else if ((ib_spec->type == (IB_FLOW_SPEC_IPV4 | inner_bit)) || |
| 3144 | (ib_spec->type == (IB_FLOW_SPEC_IPV6 | inner_bit))) { |
| 3145 | ip_spec_type = ib_spec->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3146 | } |
| 3147 | ib_spec = (void *)ib_spec + ib_spec->size; |
| 3148 | } |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3149 | |
| 3150 | type_valid = (!has_ethertype) || (!ip_spec_type); |
| 3151 | if (!type_valid && mask_valid) { |
| 3152 | ipv4_spec_valid = (eth_type == ETH_P_IP) && |
| 3153 | (ip_spec_type == (IB_FLOW_SPEC_IPV4 | inner_bit)); |
| 3154 | ipv6_spec_valid = (eth_type == ETH_P_IPV6) && |
| 3155 | (ip_spec_type == (IB_FLOW_SPEC_IPV6 | inner_bit)); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3156 | |
| 3157 | type_valid = (ipv4_spec_valid) || (ipv6_spec_valid) || |
| 3158 | (((eth_type == ETH_P_MPLS_UC) || |
| 3159 | (eth_type == ETH_P_MPLS_MC)) && match_ipv); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | return type_valid; |
| 3163 | } |
| 3164 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3165 | static bool is_valid_attr(struct mlx5_core_dev *mdev, |
| 3166 | const struct ib_flow_attr *flow_attr) |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3167 | { |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3168 | return is_valid_ethertype(mdev, flow_attr, false) && |
| 3169 | is_valid_ethertype(mdev, flow_attr, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3170 | } |
| 3171 | |
| 3172 | static void put_flow_table(struct mlx5_ib_dev *dev, |
| 3173 | struct mlx5_ib_flow_prio *prio, bool ft_added) |
| 3174 | { |
| 3175 | prio->refcount -= !!ft_added; |
| 3176 | if (!prio->refcount) { |
| 3177 | mlx5_destroy_flow_table(prio->flow_table); |
| 3178 | prio->flow_table = NULL; |
| 3179 | } |
| 3180 | } |
| 3181 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3182 | static void counters_clear_description(struct ib_counters *counters) |
| 3183 | { |
| 3184 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3185 | |
| 3186 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3187 | kfree(mcounters->counters_data); |
| 3188 | mcounters->counters_data = NULL; |
| 3189 | mcounters->cntrs_max_index = 0; |
| 3190 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3191 | } |
| 3192 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3193 | static int mlx5_ib_destroy_flow(struct ib_flow *flow_id) |
| 3194 | { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3195 | struct mlx5_ib_flow_handler *handler = container_of(flow_id, |
| 3196 | struct mlx5_ib_flow_handler, |
| 3197 | ibflow); |
| 3198 | struct mlx5_ib_flow_handler *iter, *tmp; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3199 | struct mlx5_ib_dev *dev = handler->dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3200 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3201 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3202 | |
| 3203 | list_for_each_entry_safe(iter, tmp, &handler->list, list) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3204 | mlx5_del_flow_rules(iter->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3205 | put_flow_table(dev, iter->prio, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3206 | list_del(&iter->list); |
| 3207 | kfree(iter); |
| 3208 | } |
| 3209 | |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3210 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3211 | put_flow_table(dev, handler->prio, true); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3212 | if (handler->ibcounters && |
| 3213 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3214 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3215 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3216 | mutex_unlock(&dev->flow_db->lock); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3217 | if (handler->flow_matcher) |
| 3218 | atomic_dec(&handler->flow_matcher->usecnt); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3219 | kfree(handler); |
| 3220 | |
| 3221 | return 0; |
| 3222 | } |
| 3223 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3224 | static int ib_prio_to_core_prio(unsigned int priority, bool dont_trap) |
| 3225 | { |
| 3226 | priority *= 2; |
| 3227 | if (!dont_trap) |
| 3228 | priority++; |
| 3229 | return priority; |
| 3230 | } |
| 3231 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3232 | enum flow_table_type { |
| 3233 | MLX5_IB_FT_RX, |
| 3234 | MLX5_IB_FT_TX |
| 3235 | }; |
| 3236 | |
Maor Gottlieb | 00b7c2a | 2017-03-29 06:09:01 +0300 | [diff] [blame] | 3237 | #define MLX5_FS_MAX_TYPES 6 |
| 3238 | #define MLX5_FS_MAX_ENTRIES BIT(16) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3239 | |
| 3240 | static struct mlx5_ib_flow_prio *_get_prio(struct mlx5_flow_namespace *ns, |
| 3241 | struct mlx5_ib_flow_prio *prio, |
| 3242 | int priority, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3243 | int num_entries, int num_groups, |
| 3244 | u32 flags) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3245 | { |
| 3246 | struct mlx5_flow_table *ft; |
| 3247 | |
| 3248 | ft = mlx5_create_auto_grouped_flow_table(ns, priority, |
| 3249 | num_entries, |
| 3250 | num_groups, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3251 | 0, flags); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3252 | if (IS_ERR(ft)) |
| 3253 | return ERR_CAST(ft); |
| 3254 | |
| 3255 | prio->flow_table = ft; |
| 3256 | prio->refcount = 0; |
| 3257 | return prio; |
| 3258 | } |
| 3259 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3260 | 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] | 3261 | struct ib_flow_attr *flow_attr, |
| 3262 | enum flow_table_type ft_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3263 | { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3264 | bool dont_trap = flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3265 | struct mlx5_flow_namespace *ns = NULL; |
| 3266 | struct mlx5_ib_flow_prio *prio; |
| 3267 | struct mlx5_flow_table *ft; |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3268 | int max_table_size; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3269 | int num_entries; |
| 3270 | int num_groups; |
Maor Gottlieb | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 3271 | bool esw_encap; |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3272 | u32 flags = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3273 | int priority; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3274 | |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3275 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3276 | log_max_ft_size)); |
Maor Gottlieb | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 3277 | esw_encap = mlx5_eswitch_get_encap_mode(dev->mdev) != |
| 3278 | DEVLINK_ESWITCH_ENCAP_MODE_NONE; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3279 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3280 | enum mlx5_flow_namespace_type fn_type; |
| 3281 | |
| 3282 | if (flow_is_multicast_only(flow_attr) && |
| 3283 | !dont_trap) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3284 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3285 | else |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3286 | priority = ib_prio_to_core_prio(flow_attr->priority, |
| 3287 | dont_trap); |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3288 | if (ft_type == MLX5_IB_FT_RX) { |
| 3289 | fn_type = MLX5_FLOW_NAMESPACE_BYPASS; |
| 3290 | prio = &dev->flow_db->prios[priority]; |
Maor Gottlieb | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 3291 | if (!dev->is_rep && !esw_encap && |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3292 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, decap)) |
| 3293 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
Maor Gottlieb | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 3294 | if (!dev->is_rep && !esw_encap && |
Mark Bloch | 5c2db53 | 2018-09-02 12:51:35 +0300 | [diff] [blame] | 3295 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3296 | reformat_l3_tunnel_to_l2)) |
| 3297 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3298 | } else { |
| 3299 | max_table_size = |
| 3300 | BIT(MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, |
| 3301 | log_max_ft_size)); |
| 3302 | fn_type = MLX5_FLOW_NAMESPACE_EGRESS; |
| 3303 | prio = &dev->flow_db->egress_prios[priority]; |
Maor Gottlieb | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 3304 | if (!dev->is_rep && !esw_encap && |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3305 | MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, reformat)) |
| 3306 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3307 | } |
| 3308 | ns = mlx5_get_flow_namespace(dev->mdev, fn_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3309 | num_entries = MLX5_FS_MAX_ENTRIES; |
| 3310 | num_groups = MLX5_FS_MAX_TYPES; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3311 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3312 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3313 | ns = mlx5_get_flow_namespace(dev->mdev, |
| 3314 | MLX5_FLOW_NAMESPACE_LEFTOVERS); |
| 3315 | build_leftovers_ft_param(&priority, |
| 3316 | &num_entries, |
| 3317 | &num_groups); |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3318 | prio = &dev->flow_db->prios[MLX5_IB_FLOW_LEFTOVERS_PRIO]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3319 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3320 | if (!MLX5_CAP_FLOWTABLE(dev->mdev, |
| 3321 | allow_sniffer_and_nic_rx_shared_tir)) |
| 3322 | return ERR_PTR(-ENOTSUPP); |
| 3323 | |
| 3324 | ns = mlx5_get_flow_namespace(dev->mdev, ft_type == MLX5_IB_FT_RX ? |
| 3325 | MLX5_FLOW_NAMESPACE_SNIFFER_RX : |
| 3326 | MLX5_FLOW_NAMESPACE_SNIFFER_TX); |
| 3327 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3328 | prio = &dev->flow_db->sniffer[ft_type]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3329 | priority = 0; |
| 3330 | num_entries = 1; |
| 3331 | num_groups = 1; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | if (!ns) |
| 3335 | return ERR_PTR(-ENOTSUPP); |
| 3336 | |
Mark Bloch | 3b70508 | 2019-03-28 15:46:22 +0200 | [diff] [blame] | 3337 | max_table_size = min_t(int, num_entries, max_table_size); |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3338 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3339 | ft = prio->flow_table; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3340 | if (!ft) |
Mark Bloch | 3b70508 | 2019-03-28 15:46:22 +0200 | [diff] [blame] | 3341 | return _get_prio(ns, prio, priority, max_table_size, num_groups, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3342 | flags); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3343 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3344 | return prio; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3345 | } |
| 3346 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3347 | static void set_underlay_qp(struct mlx5_ib_dev *dev, |
| 3348 | struct mlx5_flow_spec *spec, |
| 3349 | u32 underlay_qpn) |
| 3350 | { |
| 3351 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, |
| 3352 | spec->match_criteria, |
| 3353 | misc_parameters); |
| 3354 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3355 | misc_parameters); |
| 3356 | |
| 3357 | if (underlay_qpn && |
| 3358 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3359 | ft_field_support.bth_dst_qp)) { |
| 3360 | MLX5_SET(fte_match_set_misc, |
| 3361 | misc_params_v, bth_dst_qp, underlay_qpn); |
| 3362 | MLX5_SET(fte_match_set_misc, |
| 3363 | misc_params_c, bth_dst_qp, 0xffffff); |
| 3364 | } |
| 3365 | } |
| 3366 | |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3367 | static int read_flow_counters(struct ib_device *ibdev, |
| 3368 | struct mlx5_read_counters_attr *read_attr) |
| 3369 | { |
| 3370 | struct mlx5_fc *fc = read_attr->hw_cntrs_hndl; |
| 3371 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 3372 | |
| 3373 | return mlx5_fc_query(dev->mdev, fc, |
| 3374 | &read_attr->out[IB_COUNTER_PACKETS], |
| 3375 | &read_attr->out[IB_COUNTER_BYTES]); |
| 3376 | } |
| 3377 | |
| 3378 | /* flow counters currently expose two counters packets and bytes */ |
| 3379 | #define FLOW_COUNTERS_NUM 2 |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3380 | static int counters_set_description(struct ib_counters *counters, |
| 3381 | enum mlx5_ib_counters_type counters_type, |
| 3382 | struct mlx5_ib_flow_counters_desc *desc_data, |
| 3383 | u32 ncounters) |
| 3384 | { |
| 3385 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3386 | u32 cntrs_max_index = 0; |
| 3387 | int i; |
| 3388 | |
| 3389 | if (counters_type != MLX5_IB_COUNTERS_FLOW) |
| 3390 | return -EINVAL; |
| 3391 | |
| 3392 | /* init the fields for the object */ |
| 3393 | mcounters->type = counters_type; |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3394 | mcounters->read_counters = read_flow_counters; |
| 3395 | mcounters->counters_num = FLOW_COUNTERS_NUM; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3396 | mcounters->ncounters = ncounters; |
| 3397 | /* each counter entry have both description and index pair */ |
| 3398 | for (i = 0; i < ncounters; i++) { |
| 3399 | if (desc_data[i].description > IB_COUNTER_BYTES) |
| 3400 | return -EINVAL; |
| 3401 | |
| 3402 | if (cntrs_max_index <= desc_data[i].index) |
| 3403 | cntrs_max_index = desc_data[i].index + 1; |
| 3404 | } |
| 3405 | |
| 3406 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3407 | mcounters->counters_data = desc_data; |
| 3408 | mcounters->cntrs_max_index = cntrs_max_index; |
| 3409 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3410 | |
| 3411 | return 0; |
| 3412 | } |
| 3413 | |
| 3414 | #define MAX_COUNTERS_NUM (USHRT_MAX / (sizeof(u32) * 2)) |
| 3415 | static int flow_counters_set_data(struct ib_counters *ibcounters, |
| 3416 | struct mlx5_ib_create_flow *ucmd) |
| 3417 | { |
| 3418 | struct mlx5_ib_mcounters *mcounters = to_mcounters(ibcounters); |
| 3419 | struct mlx5_ib_flow_counters_data *cntrs_data = NULL; |
| 3420 | struct mlx5_ib_flow_counters_desc *desc_data = NULL; |
| 3421 | bool hw_hndl = false; |
| 3422 | int ret = 0; |
| 3423 | |
| 3424 | if (ucmd && ucmd->ncounters_data != 0) { |
| 3425 | cntrs_data = ucmd->data; |
| 3426 | if (cntrs_data->ncounters > MAX_COUNTERS_NUM) |
| 3427 | return -EINVAL; |
| 3428 | |
| 3429 | desc_data = kcalloc(cntrs_data->ncounters, |
| 3430 | sizeof(*desc_data), |
| 3431 | GFP_KERNEL); |
| 3432 | if (!desc_data) |
| 3433 | return -ENOMEM; |
| 3434 | |
| 3435 | if (copy_from_user(desc_data, |
| 3436 | u64_to_user_ptr(cntrs_data->counters_data), |
| 3437 | sizeof(*desc_data) * cntrs_data->ncounters)) { |
| 3438 | ret = -EFAULT; |
| 3439 | goto free; |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | if (!mcounters->hw_cntrs_hndl) { |
| 3444 | mcounters->hw_cntrs_hndl = mlx5_fc_create( |
| 3445 | to_mdev(ibcounters->device)->mdev, false); |
weiyongjun (A) | e31abf7 | 2018-06-07 01:47:41 +0000 | [diff] [blame] | 3446 | if (IS_ERR(mcounters->hw_cntrs_hndl)) { |
| 3447 | ret = PTR_ERR(mcounters->hw_cntrs_hndl); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3448 | goto free; |
| 3449 | } |
| 3450 | hw_hndl = true; |
| 3451 | } |
| 3452 | |
| 3453 | if (desc_data) { |
| 3454 | /* counters already bound to at least one flow */ |
| 3455 | if (mcounters->cntrs_max_index) { |
| 3456 | ret = -EINVAL; |
| 3457 | goto free_hndl; |
| 3458 | } |
| 3459 | |
| 3460 | ret = counters_set_description(ibcounters, |
| 3461 | MLX5_IB_COUNTERS_FLOW, |
| 3462 | desc_data, |
| 3463 | cntrs_data->ncounters); |
| 3464 | if (ret) |
| 3465 | goto free_hndl; |
| 3466 | |
| 3467 | } else if (!mcounters->cntrs_max_index) { |
| 3468 | /* counters not bound yet, must have udata passed */ |
| 3469 | ret = -EINVAL; |
| 3470 | goto free_hndl; |
| 3471 | } |
| 3472 | |
| 3473 | return 0; |
| 3474 | |
| 3475 | free_hndl: |
| 3476 | if (hw_hndl) { |
| 3477 | mlx5_fc_destroy(to_mdev(ibcounters->device)->mdev, |
| 3478 | mcounters->hw_cntrs_hndl); |
| 3479 | mcounters->hw_cntrs_hndl = NULL; |
| 3480 | } |
| 3481 | free: |
| 3482 | kfree(desc_data); |
| 3483 | return ret; |
| 3484 | } |
| 3485 | |
Jianbo Liu | 669ff1e | 2019-06-25 17:48:12 +0000 | [diff] [blame] | 3486 | static void mlx5_ib_set_rule_source_port(struct mlx5_ib_dev *dev, |
| 3487 | struct mlx5_flow_spec *spec, |
| 3488 | struct mlx5_eswitch_rep *rep) |
| 3489 | { |
| 3490 | struct mlx5_eswitch *esw = dev->mdev->priv.eswitch; |
| 3491 | void *misc; |
| 3492 | |
| 3493 | if (mlx5_eswitch_vport_match_metadata_enabled(esw)) { |
| 3494 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3495 | misc_parameters_2); |
| 3496 | |
| 3497 | MLX5_SET(fte_match_set_misc2, misc, metadata_reg_c_0, |
| 3498 | mlx5_eswitch_get_vport_metadata_for_match(esw, |
| 3499 | rep->vport)); |
| 3500 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
| 3501 | misc_parameters_2); |
| 3502 | |
| 3503 | MLX5_SET_TO_ONES(fte_match_set_misc2, misc, metadata_reg_c_0); |
| 3504 | } else { |
| 3505 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3506 | misc_parameters); |
| 3507 | |
| 3508 | MLX5_SET(fte_match_set_misc, misc, source_port, rep->vport); |
| 3509 | |
| 3510 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
| 3511 | misc_parameters); |
| 3512 | |
| 3513 | MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port); |
| 3514 | } |
| 3515 | } |
| 3516 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3517 | static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev, |
| 3518 | struct mlx5_ib_flow_prio *ft_prio, |
| 3519 | const struct ib_flow_attr *flow_attr, |
| 3520 | struct mlx5_flow_destination *dst, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3521 | u32 underlay_qpn, |
| 3522 | struct mlx5_ib_create_flow *ucmd) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3523 | { |
| 3524 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3525 | struct mlx5_ib_flow_handler *handler; |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 3526 | struct mlx5_flow_act flow_act = {}; |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3527 | struct mlx5_flow_spec *spec; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3528 | struct mlx5_flow_destination dest_arr[2] = {}; |
| 3529 | struct mlx5_flow_destination *rule_dst = dest_arr; |
Maor Gottlieb | dd063d0 | 2016-08-28 14:16:32 +0300 | [diff] [blame] | 3530 | const void *ib_flow = (const void *)flow_attr + sizeof(*flow_attr); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3531 | unsigned int spec_index; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3532 | u32 prev_type = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3533 | int err = 0; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3534 | int dest_num = 0; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3535 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3536 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3537 | if (!is_valid_attr(dev->mdev, flow_attr)) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3538 | return ERR_PTR(-EINVAL); |
| 3539 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3540 | if (dev->is_rep && is_egress) |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3541 | return ERR_PTR(-EINVAL); |
| 3542 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3543 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3544 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3545 | if (!handler || !spec) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3546 | err = -ENOMEM; |
| 3547 | goto free; |
| 3548 | } |
| 3549 | |
| 3550 | INIT_LIST_HEAD(&handler->list); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3551 | if (dst) { |
| 3552 | memcpy(&dest_arr[0], dst, sizeof(*dst)); |
| 3553 | dest_num++; |
| 3554 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3555 | |
| 3556 | for (spec_index = 0; spec_index < flow_attr->num_of_specs; spec_index++) { |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 3557 | err = parse_flow_attr(dev->mdev, spec, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3558 | ib_flow, flow_attr, &flow_act, |
| 3559 | prev_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3560 | if (err < 0) |
| 3561 | goto free; |
| 3562 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3563 | prev_type = ((union ib_flow_spec *)ib_flow)->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3564 | ib_flow += ((union ib_flow_spec *)ib_flow)->size; |
| 3565 | } |
| 3566 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3567 | if (!flow_is_multicast_only(flow_attr)) |
| 3568 | set_underlay_qp(dev, spec, underlay_qpn); |
| 3569 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3570 | if (dev->is_rep) { |
Jianbo Liu | 669ff1e | 2019-06-25 17:48:12 +0000 | [diff] [blame] | 3571 | struct mlx5_eswitch_rep *rep; |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3572 | |
Jianbo Liu | 669ff1e | 2019-06-25 17:48:12 +0000 | [diff] [blame] | 3573 | rep = dev->port[flow_attr->port - 1].rep; |
| 3574 | if (!rep) { |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 3575 | err = -EINVAL; |
| 3576 | goto free; |
| 3577 | } |
Jianbo Liu | 669ff1e | 2019-06-25 17:48:12 +0000 | [diff] [blame] | 3578 | |
| 3579 | mlx5_ib_set_rule_source_port(dev, spec, rep); |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3580 | } |
| 3581 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 3582 | spec->match_criteria_enable = get_match_criteria_enable(spec->match_criteria); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3583 | |
| 3584 | if (is_egress && |
| 3585 | !is_valid_spec(dev->mdev, spec, &flow_act, is_egress)) { |
| 3586 | err = -EINVAL; |
| 3587 | goto free; |
| 3588 | } |
| 3589 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3590 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3591 | struct mlx5_ib_mcounters *mcounters; |
| 3592 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3593 | err = flow_counters_set_data(flow_act.counters, ucmd); |
| 3594 | if (err) |
| 3595 | goto free; |
| 3596 | |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3597 | mcounters = to_mcounters(flow_act.counters); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3598 | handler->ibcounters = flow_act.counters; |
| 3599 | dest_arr[dest_num].type = |
| 3600 | MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3601 | dest_arr[dest_num].counter_id = |
| 3602 | mlx5_fc_id(mcounters->hw_cntrs_hndl); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3603 | dest_num++; |
| 3604 | } |
| 3605 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3606 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DROP) { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3607 | if (!(flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT)) { |
| 3608 | rule_dst = NULL; |
| 3609 | dest_num = 0; |
| 3610 | } |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3611 | } else { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3612 | if (is_egress) |
| 3613 | flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
| 3614 | else |
| 3615 | flow_act.action |= |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3616 | dest_num ? MLX5_FLOW_CONTEXT_ACTION_FWD_DEST : |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3617 | MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3618 | } |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3619 | |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 3620 | if ((spec->flow_context.flags & FLOW_CONTEXT_HAS_TAG) && |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3621 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3622 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3623 | mlx5_ib_warn(dev, "Flow tag %u and attribute type %x isn't allowed in leftovers\n", |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 3624 | spec->flow_context.flow_tag, flow_attr->type); |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3625 | err = -EINVAL; |
| 3626 | goto free; |
| 3627 | } |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3628 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Hadar Hen Zion | 66958ed | 2016-11-07 15:14:45 +0200 | [diff] [blame] | 3629 | &flow_act, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3630 | rule_dst, dest_num); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3631 | |
| 3632 | if (IS_ERR(handler->rule)) { |
| 3633 | err = PTR_ERR(handler->rule); |
| 3634 | goto free; |
| 3635 | } |
| 3636 | |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3637 | ft_prio->refcount++; |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3638 | handler->prio = ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3639 | handler->dev = dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3640 | |
| 3641 | ft_prio->flow_table = ft; |
| 3642 | free: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3643 | if (err && handler) { |
| 3644 | if (handler->ibcounters && |
| 3645 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3646 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3647 | kfree(handler); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3648 | } |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3649 | kvfree(spec); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3650 | return err ? ERR_PTR(err) : handler; |
| 3651 | } |
| 3652 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3653 | static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev, |
| 3654 | struct mlx5_ib_flow_prio *ft_prio, |
| 3655 | const struct ib_flow_attr *flow_attr, |
| 3656 | struct mlx5_flow_destination *dst) |
| 3657 | { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3658 | return _create_flow_rule(dev, ft_prio, flow_attr, dst, 0, NULL); |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3659 | } |
| 3660 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3661 | static struct mlx5_ib_flow_handler *create_dont_trap_rule(struct mlx5_ib_dev *dev, |
| 3662 | struct mlx5_ib_flow_prio *ft_prio, |
| 3663 | struct ib_flow_attr *flow_attr, |
| 3664 | struct mlx5_flow_destination *dst) |
| 3665 | { |
| 3666 | struct mlx5_ib_flow_handler *handler_dst = NULL; |
| 3667 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3668 | |
| 3669 | handler = create_flow_rule(dev, ft_prio, flow_attr, NULL); |
| 3670 | if (!IS_ERR(handler)) { |
| 3671 | handler_dst = create_flow_rule(dev, ft_prio, |
| 3672 | flow_attr, dst); |
| 3673 | if (IS_ERR(handler_dst)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3674 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3675 | ft_prio->refcount--; |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3676 | kfree(handler); |
| 3677 | handler = handler_dst; |
| 3678 | } else { |
| 3679 | list_add(&handler_dst->list, &handler->list); |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | return handler; |
| 3684 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3685 | enum { |
| 3686 | LEFTOVERS_MC, |
| 3687 | LEFTOVERS_UC, |
| 3688 | }; |
| 3689 | |
| 3690 | static struct mlx5_ib_flow_handler *create_leftovers_rule(struct mlx5_ib_dev *dev, |
| 3691 | struct mlx5_ib_flow_prio *ft_prio, |
| 3692 | struct ib_flow_attr *flow_attr, |
| 3693 | struct mlx5_flow_destination *dst) |
| 3694 | { |
| 3695 | struct mlx5_ib_flow_handler *handler_ucast = NULL; |
| 3696 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3697 | |
| 3698 | static struct { |
| 3699 | struct ib_flow_attr flow_attr; |
| 3700 | struct ib_flow_spec_eth eth_flow; |
| 3701 | } leftovers_specs[] = { |
| 3702 | [LEFTOVERS_MC] = { |
| 3703 | .flow_attr = { |
| 3704 | .num_of_specs = 1, |
| 3705 | .size = sizeof(leftovers_specs[0]) |
| 3706 | }, |
| 3707 | .eth_flow = { |
| 3708 | .type = IB_FLOW_SPEC_ETH, |
| 3709 | .size = sizeof(struct ib_flow_spec_eth), |
| 3710 | .mask = {.dst_mac = {0x1} }, |
| 3711 | .val = {.dst_mac = {0x1} } |
| 3712 | } |
| 3713 | }, |
| 3714 | [LEFTOVERS_UC] = { |
| 3715 | .flow_attr = { |
| 3716 | .num_of_specs = 1, |
| 3717 | .size = sizeof(leftovers_specs[0]) |
| 3718 | }, |
| 3719 | .eth_flow = { |
| 3720 | .type = IB_FLOW_SPEC_ETH, |
| 3721 | .size = sizeof(struct ib_flow_spec_eth), |
| 3722 | .mask = {.dst_mac = {0x1} }, |
| 3723 | .val = {.dst_mac = {} } |
| 3724 | } |
| 3725 | } |
| 3726 | }; |
| 3727 | |
| 3728 | handler = create_flow_rule(dev, ft_prio, |
| 3729 | &leftovers_specs[LEFTOVERS_MC].flow_attr, |
| 3730 | dst); |
| 3731 | if (!IS_ERR(handler) && |
| 3732 | flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT) { |
| 3733 | handler_ucast = create_flow_rule(dev, ft_prio, |
| 3734 | &leftovers_specs[LEFTOVERS_UC].flow_attr, |
| 3735 | dst); |
| 3736 | if (IS_ERR(handler_ucast)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3737 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3738 | ft_prio->refcount--; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3739 | kfree(handler); |
| 3740 | handler = handler_ucast; |
| 3741 | } else { |
| 3742 | list_add(&handler_ucast->list, &handler->list); |
| 3743 | } |
| 3744 | } |
| 3745 | |
| 3746 | return handler; |
| 3747 | } |
| 3748 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3749 | static struct mlx5_ib_flow_handler *create_sniffer_rule(struct mlx5_ib_dev *dev, |
| 3750 | struct mlx5_ib_flow_prio *ft_rx, |
| 3751 | struct mlx5_ib_flow_prio *ft_tx, |
| 3752 | struct mlx5_flow_destination *dst) |
| 3753 | { |
| 3754 | struct mlx5_ib_flow_handler *handler_rx; |
| 3755 | struct mlx5_ib_flow_handler *handler_tx; |
| 3756 | int err; |
| 3757 | static const struct ib_flow_attr flow_attr = { |
| 3758 | .num_of_specs = 0, |
| 3759 | .size = sizeof(flow_attr) |
| 3760 | }; |
| 3761 | |
| 3762 | handler_rx = create_flow_rule(dev, ft_rx, &flow_attr, dst); |
| 3763 | if (IS_ERR(handler_rx)) { |
| 3764 | err = PTR_ERR(handler_rx); |
| 3765 | goto err; |
| 3766 | } |
| 3767 | |
| 3768 | handler_tx = create_flow_rule(dev, ft_tx, &flow_attr, dst); |
| 3769 | if (IS_ERR(handler_tx)) { |
| 3770 | err = PTR_ERR(handler_tx); |
| 3771 | goto err_tx; |
| 3772 | } |
| 3773 | |
| 3774 | list_add(&handler_tx->list, &handler_rx->list); |
| 3775 | |
| 3776 | return handler_rx; |
| 3777 | |
| 3778 | err_tx: |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3779 | mlx5_del_flow_rules(handler_rx->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3780 | ft_rx->refcount--; |
| 3781 | kfree(handler_rx); |
| 3782 | err: |
| 3783 | return ERR_PTR(err); |
| 3784 | } |
| 3785 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3786 | static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, |
| 3787 | struct ib_flow_attr *flow_attr, |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3788 | int domain, |
| 3789 | struct ib_udata *udata) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3790 | { |
| 3791 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Yishai Hadas | d9f88e5 | 2016-08-28 10:58:37 +0300 | [diff] [blame] | 3792 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3793 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3794 | struct mlx5_flow_destination *dst = NULL; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3795 | struct mlx5_ib_flow_prio *ft_prio_tx = NULL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3796 | struct mlx5_ib_flow_prio *ft_prio; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3797 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3798 | struct mlx5_ib_create_flow *ucmd = NULL, ucmd_hdr; |
| 3799 | size_t min_ucmd_sz, required_ucmd_sz; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3800 | int err; |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3801 | int underlay_qpn; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3802 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3803 | if (udata && udata->inlen) { |
| 3804 | min_ucmd_sz = offsetof(typeof(ucmd_hdr), reserved) + |
| 3805 | sizeof(ucmd_hdr.reserved); |
| 3806 | if (udata->inlen < min_ucmd_sz) |
| 3807 | return ERR_PTR(-EOPNOTSUPP); |
| 3808 | |
| 3809 | err = ib_copy_from_udata(&ucmd_hdr, udata, min_ucmd_sz); |
| 3810 | if (err) |
| 3811 | return ERR_PTR(err); |
| 3812 | |
| 3813 | /* currently supports only one counters data */ |
| 3814 | if (ucmd_hdr.ncounters_data > 1) |
| 3815 | return ERR_PTR(-EINVAL); |
| 3816 | |
| 3817 | required_ucmd_sz = min_ucmd_sz + |
| 3818 | sizeof(struct mlx5_ib_flow_counters_data) * |
| 3819 | ucmd_hdr.ncounters_data; |
| 3820 | if (udata->inlen > required_ucmd_sz && |
| 3821 | !ib_is_udata_cleared(udata, required_ucmd_sz, |
| 3822 | udata->inlen - required_ucmd_sz)) |
| 3823 | return ERR_PTR(-EOPNOTSUPP); |
| 3824 | |
| 3825 | ucmd = kzalloc(required_ucmd_sz, GFP_KERNEL); |
| 3826 | if (!ucmd) |
| 3827 | return ERR_PTR(-ENOMEM); |
| 3828 | |
| 3829 | err = ib_copy_from_udata(ucmd, udata, required_ucmd_sz); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3830 | if (err) |
| 3831 | goto free_ucmd; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3832 | } |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3833 | |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3834 | if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) { |
| 3835 | err = -ENOMEM; |
| 3836 | goto free_ucmd; |
| 3837 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3838 | |
| 3839 | if (domain != IB_FLOW_DOMAIN_USER || |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 3840 | flow_attr->port > dev->num_ports || |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3841 | (flow_attr->flags & ~(IB_FLOW_ATTR_FLAGS_DONT_TRAP | |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3842 | IB_FLOW_ATTR_FLAGS_EGRESS))) { |
| 3843 | err = -EINVAL; |
| 3844 | goto free_ucmd; |
| 3845 | } |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3846 | |
| 3847 | if (is_egress && |
| 3848 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3849 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3850 | err = -EINVAL; |
| 3851 | goto free_ucmd; |
| 3852 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3853 | |
| 3854 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3855 | if (!dst) { |
| 3856 | err = -ENOMEM; |
| 3857 | goto free_ucmd; |
| 3858 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3859 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3860 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3861 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3862 | ft_prio = get_flow_table(dev, flow_attr, |
| 3863 | is_egress ? MLX5_IB_FT_TX : MLX5_IB_FT_RX); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3864 | if (IS_ERR(ft_prio)) { |
| 3865 | err = PTR_ERR(ft_prio); |
| 3866 | goto unlock; |
| 3867 | } |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3868 | if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3869 | ft_prio_tx = get_flow_table(dev, flow_attr, MLX5_IB_FT_TX); |
| 3870 | if (IS_ERR(ft_prio_tx)) { |
| 3871 | err = PTR_ERR(ft_prio_tx); |
| 3872 | ft_prio_tx = NULL; |
| 3873 | goto destroy_ft; |
| 3874 | } |
| 3875 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3876 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3877 | if (is_egress) { |
| 3878 | dst->type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
| 3879 | } else { |
| 3880 | dst->type = MLX5_FLOW_DESTINATION_TYPE_TIR; |
| 3881 | if (mqp->flags & MLX5_IB_QP_RSS) |
| 3882 | dst->tir_num = mqp->rss_qp.tirn; |
| 3883 | else |
| 3884 | dst->tir_num = mqp->raw_packet_qp.rq.tirn; |
| 3885 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3886 | |
| 3887 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3888 | if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) { |
| 3889 | handler = create_dont_trap_rule(dev, ft_prio, |
| 3890 | flow_attr, dst); |
| 3891 | } else { |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3892 | underlay_qpn = (mqp->flags & MLX5_IB_QP_UNDERLAY) ? |
| 3893 | mqp->underlay_qpn : 0; |
| 3894 | handler = _create_flow_rule(dev, ft_prio, flow_attr, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3895 | dst, underlay_qpn, ucmd); |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3896 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3897 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3898 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3899 | handler = create_leftovers_rule(dev, ft_prio, flow_attr, |
| 3900 | dst); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3901 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3902 | handler = create_sniffer_rule(dev, ft_prio, ft_prio_tx, dst); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3903 | } else { |
| 3904 | err = -EINVAL; |
| 3905 | goto destroy_ft; |
| 3906 | } |
| 3907 | |
| 3908 | if (IS_ERR(handler)) { |
| 3909 | err = PTR_ERR(handler); |
| 3910 | handler = NULL; |
| 3911 | goto destroy_ft; |
| 3912 | } |
| 3913 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3914 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3915 | kfree(dst); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3916 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3917 | |
| 3918 | return &handler->ibflow; |
| 3919 | |
| 3920 | destroy_ft: |
| 3921 | put_flow_table(dev, ft_prio, false); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3922 | if (ft_prio_tx) |
| 3923 | put_flow_table(dev, ft_prio_tx, false); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3924 | unlock: |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3925 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3926 | kfree(dst); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3927 | free_ucmd: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3928 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3929 | return ERR_PTR(err); |
| 3930 | } |
| 3931 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3932 | static struct mlx5_ib_flow_prio * |
| 3933 | _get_flow_table(struct mlx5_ib_dev *dev, |
| 3934 | struct mlx5_ib_flow_matcher *fs_matcher, |
| 3935 | bool mcast) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3936 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3937 | struct mlx5_flow_namespace *ns = NULL; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3938 | struct mlx5_ib_flow_prio *prio = NULL; |
| 3939 | int max_table_size = 0; |
Maor Gottlieb | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 3940 | bool esw_encap; |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3941 | u32 flags = 0; |
| 3942 | int priority; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3943 | |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3944 | if (mcast) |
| 3945 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3946 | else |
| 3947 | priority = ib_prio_to_core_prio(fs_matcher->priority, false); |
| 3948 | |
Maor Gottlieb | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 3949 | esw_encap = mlx5_eswitch_get_encap_mode(dev->mdev) != |
| 3950 | DEVLINK_ESWITCH_ENCAP_MODE_NONE; |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3951 | if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS) { |
| 3952 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3953 | log_max_ft_size)); |
Maor Gottlieb | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 3954 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, decap) && !esw_encap) |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3955 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
| 3956 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
Maor Gottlieb | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 3957 | reformat_l3_tunnel_to_l2) && |
| 3958 | !esw_encap) |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3959 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3960 | } else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_EGRESS) { |
| 3961 | max_table_size = BIT( |
| 3962 | MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, log_max_ft_size)); |
Maor Gottlieb | cecae74 | 2019-06-12 15:20:13 +0300 | [diff] [blame] | 3963 | if (MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, reformat) && !esw_encap) |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3964 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3965 | } else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_FDB) { |
| 3966 | max_table_size = BIT( |
| 3967 | MLX5_CAP_ESW_FLOWTABLE_FDB(dev->mdev, log_max_ft_size)); |
Maor Gottlieb | 09d985b | 2019-06-12 15:20:14 +0300 | [diff] [blame] | 3968 | if (MLX5_CAP_ESW_FLOWTABLE_FDB(dev->mdev, decap) && esw_encap) |
| 3969 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
| 3970 | if (MLX5_CAP_ESW_FLOWTABLE_FDB(dev->mdev, reformat_l3_tunnel_to_l2) && |
| 3971 | esw_encap) |
| 3972 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3973 | priority = FDB_BYPASS_PATH; |
Mark Zhang | d8abe88 | 2019-08-19 14:36:26 +0300 | [diff] [blame] | 3974 | } else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_RDMA_RX) { |
| 3975 | max_table_size = |
| 3976 | BIT(MLX5_CAP_FLOWTABLE_RDMA_RX(dev->mdev, |
| 3977 | log_max_ft_size)); |
| 3978 | priority = fs_matcher->priority; |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3979 | } |
| 3980 | |
Mark Bloch | 3b70508 | 2019-03-28 15:46:22 +0200 | [diff] [blame] | 3981 | max_table_size = min_t(int, max_table_size, MLX5_FS_MAX_ENTRIES); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3982 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3983 | ns = mlx5_get_flow_namespace(dev->mdev, fs_matcher->ns_type); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3984 | if (!ns) |
| 3985 | return ERR_PTR(-ENOTSUPP); |
| 3986 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3987 | if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS) |
| 3988 | prio = &dev->flow_db->prios[priority]; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3989 | else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_EGRESS) |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3990 | prio = &dev->flow_db->egress_prios[priority]; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3991 | else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_FDB) |
| 3992 | prio = &dev->flow_db->fdb; |
Mark Zhang | d8abe88 | 2019-08-19 14:36:26 +0300 | [diff] [blame] | 3993 | else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_RDMA_RX) |
| 3994 | prio = &dev->flow_db->rdma_rx[priority]; |
Mark Bloch | 13a4376 | 2019-03-28 15:46:21 +0200 | [diff] [blame] | 3995 | |
| 3996 | if (!prio) |
| 3997 | return ERR_PTR(-EINVAL); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3998 | |
| 3999 | if (prio->flow_table) |
| 4000 | return prio; |
| 4001 | |
Mark Bloch | 3b70508 | 2019-03-28 15:46:22 +0200 | [diff] [blame] | 4002 | return _get_prio(ns, prio, priority, max_table_size, |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 4003 | MLX5_FS_MAX_TYPES, flags); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | static struct mlx5_ib_flow_handler * |
| 4007 | _create_raw_flow_rule(struct mlx5_ib_dev *dev, |
| 4008 | struct mlx5_ib_flow_prio *ft_prio, |
| 4009 | struct mlx5_flow_destination *dst, |
| 4010 | struct mlx5_ib_flow_matcher *fs_matcher, |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 4011 | struct mlx5_flow_context *flow_context, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 4012 | struct mlx5_flow_act *flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 4013 | void *cmd_in, int inlen, |
| 4014 | int dst_num) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4015 | { |
| 4016 | struct mlx5_ib_flow_handler *handler; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4017 | struct mlx5_flow_spec *spec; |
| 4018 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 4019 | int err = 0; |
| 4020 | |
| 4021 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
| 4022 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
| 4023 | if (!handler || !spec) { |
| 4024 | err = -ENOMEM; |
| 4025 | goto free; |
| 4026 | } |
| 4027 | |
| 4028 | INIT_LIST_HEAD(&handler->list); |
| 4029 | |
| 4030 | memcpy(spec->match_value, cmd_in, inlen); |
| 4031 | memcpy(spec->match_criteria, fs_matcher->matcher_mask.match_params, |
| 4032 | fs_matcher->mask_len); |
| 4033 | spec->match_criteria_enable = fs_matcher->match_criteria_enable; |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 4034 | spec->flow_context = *flow_context; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4035 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4036 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 4037 | flow_act, dst, dst_num); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4038 | |
| 4039 | if (IS_ERR(handler->rule)) { |
| 4040 | err = PTR_ERR(handler->rule); |
| 4041 | goto free; |
| 4042 | } |
| 4043 | |
| 4044 | ft_prio->refcount++; |
| 4045 | handler->prio = ft_prio; |
| 4046 | handler->dev = dev; |
| 4047 | ft_prio->flow_table = ft; |
| 4048 | |
| 4049 | free: |
| 4050 | if (err) |
| 4051 | kfree(handler); |
| 4052 | kvfree(spec); |
| 4053 | return err ? ERR_PTR(err) : handler; |
| 4054 | } |
| 4055 | |
| 4056 | static bool raw_fs_is_multicast(struct mlx5_ib_flow_matcher *fs_matcher, |
| 4057 | void *match_v) |
| 4058 | { |
| 4059 | void *match_c; |
| 4060 | void *match_v_set_lyr_2_4, *match_c_set_lyr_2_4; |
| 4061 | void *dmac, *dmac_mask; |
| 4062 | void *ipv4, *ipv4_mask; |
| 4063 | |
| 4064 | if (!(fs_matcher->match_criteria_enable & |
| 4065 | (1 << MATCH_CRITERIA_ENABLE_OUTER_BIT))) |
| 4066 | return false; |
| 4067 | |
| 4068 | match_c = fs_matcher->matcher_mask.match_params; |
| 4069 | match_v_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_v, |
| 4070 | outer_headers); |
| 4071 | match_c_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_c, |
| 4072 | outer_headers); |
| 4073 | |
| 4074 | dmac = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 4075 | dmac_47_16); |
| 4076 | dmac_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 4077 | dmac_47_16); |
| 4078 | |
| 4079 | if (is_multicast_ether_addr(dmac) && |
| 4080 | is_multicast_ether_addr(dmac_mask)) |
| 4081 | return true; |
| 4082 | |
| 4083 | ipv4 = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 4084 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 4085 | |
| 4086 | ipv4_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 4087 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 4088 | |
| 4089 | if (ipv4_is_multicast(*(__be32 *)(ipv4)) && |
| 4090 | ipv4_is_multicast(*(__be32 *)(ipv4_mask))) |
| 4091 | return true; |
| 4092 | |
| 4093 | return false; |
| 4094 | } |
| 4095 | |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 4096 | struct mlx5_ib_flow_handler * |
| 4097 | mlx5_ib_raw_fs_rule_add(struct mlx5_ib_dev *dev, |
| 4098 | struct mlx5_ib_flow_matcher *fs_matcher, |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 4099 | struct mlx5_flow_context *flow_context, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 4100 | struct mlx5_flow_act *flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 4101 | u32 counter_id, |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 4102 | void *cmd_in, int inlen, int dest_id, |
| 4103 | int dest_type) |
| 4104 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4105 | struct mlx5_flow_destination *dst; |
| 4106 | struct mlx5_ib_flow_prio *ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4107 | struct mlx5_ib_flow_handler *handler; |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 4108 | int dst_num = 0; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4109 | bool mcast; |
| 4110 | int err; |
| 4111 | |
| 4112 | if (fs_matcher->flow_type != MLX5_IB_FLOW_TYPE_NORMAL) |
| 4113 | return ERR_PTR(-EOPNOTSUPP); |
| 4114 | |
| 4115 | if (fs_matcher->priority > MLX5_IB_FLOW_LAST_PRIO) |
| 4116 | return ERR_PTR(-ENOMEM); |
| 4117 | |
Gustavo A. R. Silva | 8e8aa14 | 2019-01-15 00:00:48 -0600 | [diff] [blame] | 4118 | dst = kcalloc(2, sizeof(*dst), GFP_KERNEL); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4119 | if (!dst) |
| 4120 | return ERR_PTR(-ENOMEM); |
| 4121 | |
| 4122 | mcast = raw_fs_is_multicast(fs_matcher, cmd_in); |
| 4123 | mutex_lock(&dev->flow_db->lock); |
| 4124 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 4125 | ft_prio = _get_flow_table(dev, fs_matcher, mcast); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4126 | if (IS_ERR(ft_prio)) { |
| 4127 | err = PTR_ERR(ft_prio); |
| 4128 | goto unlock; |
| 4129 | } |
| 4130 | |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 4131 | if (dest_type == MLX5_FLOW_DESTINATION_TYPE_TIR) { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 4132 | dst[dst_num].type = dest_type; |
| 4133 | dst[dst_num].tir_num = dest_id; |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 4134 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 4135 | } else if (dest_type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 4136 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM; |
| 4137 | dst[dst_num].ft_num = dest_id; |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 4138 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 4139 | } else { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 4140 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 4141 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 4142 | } |
| 4143 | |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 4144 | dst_num++; |
| 4145 | |
| 4146 | if (flow_act->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
| 4147 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
| 4148 | dst[dst_num].counter_id = counter_id; |
| 4149 | dst_num++; |
| 4150 | } |
| 4151 | |
Jianbo Liu | bb0ee7d | 2019-06-25 17:47:58 +0000 | [diff] [blame] | 4152 | handler = _create_raw_flow_rule(dev, ft_prio, dst, fs_matcher, |
| 4153 | flow_context, flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 4154 | cmd_in, inlen, dst_num); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 4155 | |
| 4156 | if (IS_ERR(handler)) { |
| 4157 | err = PTR_ERR(handler); |
| 4158 | goto destroy_ft; |
| 4159 | } |
| 4160 | |
| 4161 | mutex_unlock(&dev->flow_db->lock); |
| 4162 | atomic_inc(&fs_matcher->usecnt); |
| 4163 | handler->flow_matcher = fs_matcher; |
| 4164 | |
| 4165 | kfree(dst); |
| 4166 | |
| 4167 | return handler; |
| 4168 | |
| 4169 | destroy_ft: |
| 4170 | put_flow_table(dev, ft_prio, false); |
| 4171 | unlock: |
| 4172 | mutex_unlock(&dev->flow_db->lock); |
| 4173 | kfree(dst); |
| 4174 | |
| 4175 | return ERR_PTR(err); |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 4176 | } |
| 4177 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4178 | static u32 mlx5_ib_flow_action_flags_to_accel_xfrm_flags(u32 mlx5_flags) |
| 4179 | { |
| 4180 | u32 flags = 0; |
| 4181 | |
| 4182 | if (mlx5_flags & MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA) |
| 4183 | flags |= MLX5_ACCEL_XFRM_FLAG_REQUIRE_METADATA; |
| 4184 | |
| 4185 | return flags; |
| 4186 | } |
| 4187 | |
| 4188 | #define MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA |
| 4189 | static struct ib_flow_action * |
| 4190 | mlx5_ib_create_flow_action_esp(struct ib_device *device, |
| 4191 | const struct ib_flow_action_attrs_esp *attr, |
| 4192 | struct uverbs_attr_bundle *attrs) |
| 4193 | { |
| 4194 | struct mlx5_ib_dev *mdev = to_mdev(device); |
| 4195 | struct ib_uverbs_flow_action_esp_keymat_aes_gcm *aes_gcm; |
| 4196 | struct mlx5_accel_esp_xfrm_attrs accel_attrs = {}; |
| 4197 | struct mlx5_ib_flow_action *action; |
| 4198 | u64 action_flags; |
| 4199 | u64 flags; |
| 4200 | int err = 0; |
| 4201 | |
Jason Gunthorpe | bccd062 | 2018-07-26 16:37:14 -0600 | [diff] [blame] | 4202 | err = uverbs_get_flags64( |
| 4203 | &action_flags, attrs, MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 4204 | ((MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED << 1) - 1)); |
| 4205 | if (err) |
| 4206 | return ERR_PTR(err); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4207 | |
| 4208 | flags = mlx5_ib_flow_action_flags_to_accel_xfrm_flags(action_flags); |
| 4209 | |
| 4210 | /* We current only support a subset of the standard features. Only a |
| 4211 | * keymat of type AES_GCM, with icv_len == 16, iv_algo == SEQ and esn |
| 4212 | * (with overlap). Full offload mode isn't supported. |
| 4213 | */ |
| 4214 | if (!attr->keymat || attr->replay || attr->encap || |
| 4215 | attr->spi || attr->seq || attr->tfc_pad || |
| 4216 | attr->hard_limit_pkts || |
| 4217 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4218 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT))) |
| 4219 | return ERR_PTR(-EOPNOTSUPP); |
| 4220 | |
| 4221 | if (attr->keymat->protocol != |
| 4222 | IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM) |
| 4223 | return ERR_PTR(-EOPNOTSUPP); |
| 4224 | |
| 4225 | aes_gcm = &attr->keymat->keymat.aes_gcm; |
| 4226 | |
| 4227 | if (aes_gcm->icv_len != 16 || |
| 4228 | aes_gcm->iv_algo != IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ) |
| 4229 | return ERR_PTR(-EOPNOTSUPP); |
| 4230 | |
| 4231 | action = kmalloc(sizeof(*action), GFP_KERNEL); |
| 4232 | if (!action) |
| 4233 | return ERR_PTR(-ENOMEM); |
| 4234 | |
| 4235 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 4236 | memcpy(&accel_attrs.keymat.aes_gcm.aes_key, &aes_gcm->aes_key, |
| 4237 | sizeof(accel_attrs.keymat.aes_gcm.aes_key)); |
| 4238 | accel_attrs.keymat.aes_gcm.key_len = aes_gcm->key_len * 8; |
| 4239 | memcpy(&accel_attrs.keymat.aes_gcm.salt, &aes_gcm->salt, |
| 4240 | sizeof(accel_attrs.keymat.aes_gcm.salt)); |
| 4241 | memcpy(&accel_attrs.keymat.aes_gcm.seq_iv, &aes_gcm->iv, |
| 4242 | sizeof(accel_attrs.keymat.aes_gcm.seq_iv)); |
| 4243 | accel_attrs.keymat.aes_gcm.icv_len = aes_gcm->icv_len * 8; |
| 4244 | accel_attrs.keymat.aes_gcm.iv_algo = MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ; |
| 4245 | accel_attrs.keymat_type = MLX5_ACCEL_ESP_KEYMAT_AES_GCM; |
| 4246 | |
| 4247 | accel_attrs.esn = attr->esn; |
| 4248 | if (attr->flags & IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) |
| 4249 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED; |
| 4250 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 4251 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4252 | |
| 4253 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT) |
| 4254 | accel_attrs.action |= MLX5_ACCEL_ESP_ACTION_ENCRYPT; |
| 4255 | |
| 4256 | action->esp_aes_gcm.ctx = |
| 4257 | mlx5_accel_esp_create_xfrm(mdev->mdev, &accel_attrs, flags); |
| 4258 | if (IS_ERR(action->esp_aes_gcm.ctx)) { |
| 4259 | err = PTR_ERR(action->esp_aes_gcm.ctx); |
| 4260 | goto err_parse; |
| 4261 | } |
| 4262 | |
| 4263 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 4264 | |
| 4265 | return &action->ib_action; |
| 4266 | |
| 4267 | err_parse: |
| 4268 | kfree(action); |
| 4269 | return ERR_PTR(err); |
| 4270 | } |
| 4271 | |
Matan Barak | 349705c | 2018-03-28 09:27:51 +0300 | [diff] [blame] | 4272 | static int |
| 4273 | mlx5_ib_modify_flow_action_esp(struct ib_flow_action *action, |
| 4274 | const struct ib_flow_action_attrs_esp *attr, |
| 4275 | struct uverbs_attr_bundle *attrs) |
| 4276 | { |
| 4277 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 4278 | struct mlx5_accel_esp_xfrm_attrs accel_attrs; |
| 4279 | int err = 0; |
| 4280 | |
| 4281 | if (attr->keymat || attr->replay || attr->encap || |
| 4282 | attr->spi || attr->seq || attr->tfc_pad || |
| 4283 | attr->hard_limit_pkts || |
| 4284 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4285 | IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS | |
| 4286 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW))) |
| 4287 | return -EOPNOTSUPP; |
| 4288 | |
| 4289 | /* Only the ESN value or the MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP can |
| 4290 | * be modified. |
| 4291 | */ |
| 4292 | if (!(maction->esp_aes_gcm.ib_flags & |
| 4293 | IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) && |
| 4294 | attr->flags & (IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4295 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW)) |
| 4296 | return -EINVAL; |
| 4297 | |
| 4298 | memcpy(&accel_attrs, &maction->esp_aes_gcm.ctx->attrs, |
| 4299 | sizeof(accel_attrs)); |
| 4300 | |
| 4301 | accel_attrs.esn = attr->esn; |
| 4302 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 4303 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4304 | else |
| 4305 | accel_attrs.flags &= ~MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4306 | |
| 4307 | err = mlx5_accel_esp_modify_xfrm(maction->esp_aes_gcm.ctx, |
| 4308 | &accel_attrs); |
| 4309 | if (err) |
| 4310 | return err; |
| 4311 | |
| 4312 | maction->esp_aes_gcm.ib_flags &= |
| 4313 | ~IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 4314 | maction->esp_aes_gcm.ib_flags |= |
| 4315 | attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 4316 | |
| 4317 | return 0; |
| 4318 | } |
| 4319 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4320 | static int mlx5_ib_destroy_flow_action(struct ib_flow_action *action) |
| 4321 | { |
| 4322 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 4323 | |
| 4324 | switch (action->type) { |
| 4325 | case IB_FLOW_ACTION_ESP: |
| 4326 | /* |
| 4327 | * We only support aes_gcm by now, so we implicitly know this is |
| 4328 | * the underline crypto. |
| 4329 | */ |
| 4330 | mlx5_accel_esp_destroy_xfrm(maction->esp_aes_gcm.ctx); |
| 4331 | break; |
Mark Bloch | b4749bf | 2018-08-28 14:18:51 +0300 | [diff] [blame] | 4332 | case IB_FLOW_ACTION_UNSPECIFIED: |
| 4333 | mlx5_ib_destroy_flow_action_raw(maction); |
| 4334 | break; |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4335 | default: |
| 4336 | WARN_ON(true); |
| 4337 | break; |
| 4338 | } |
| 4339 | |
| 4340 | kfree(maction); |
| 4341 | return 0; |
| 4342 | } |
| 4343 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4344 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4345 | { |
| 4346 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4347 | struct mlx5_ib_qp *mqp = to_mqp(ibqp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4348 | int err; |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4349 | u16 uid; |
| 4350 | |
| 4351 | uid = ibqp->pd ? |
| 4352 | to_mpd(ibqp->pd)->uid : 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4353 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4354 | if (mqp->flags & MLX5_IB_QP_UNDERLAY) { |
| 4355 | mlx5_ib_dbg(dev, "Attaching a multi cast group to underlay QP is not supported\n"); |
| 4356 | return -EOPNOTSUPP; |
| 4357 | } |
| 4358 | |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4359 | err = mlx5_cmd_attach_mcg(dev->mdev, gid, ibqp->qp_num, uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4360 | if (err) |
| 4361 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
| 4362 | ibqp->qp_num, gid->raw); |
| 4363 | |
| 4364 | return err; |
| 4365 | } |
| 4366 | |
| 4367 | static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4368 | { |
| 4369 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 4370 | int err; |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4371 | u16 uid; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4372 | |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4373 | uid = ibqp->pd ? |
| 4374 | to_mpd(ibqp->pd)->uid : 0; |
| 4375 | err = mlx5_cmd_detach_mcg(dev->mdev, gid, ibqp->qp_num, uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4376 | if (err) |
| 4377 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
| 4378 | ibqp->qp_num, gid->raw); |
| 4379 | |
| 4380 | return err; |
| 4381 | } |
| 4382 | |
| 4383 | static int init_node_data(struct mlx5_ib_dev *dev) |
| 4384 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4385 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4386 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4387 | err = mlx5_query_node_desc(dev, dev->ib_dev.node_desc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4388 | if (err) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4389 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4390 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4391 | dev->mdev->rev_id = dev->mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4392 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4393 | return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4394 | } |
| 4395 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4396 | static ssize_t fw_pages_show(struct device *device, |
| 4397 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4398 | { |
| 4399 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4400 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4401 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4402 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4403 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4404 | static DEVICE_ATTR_RO(fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4405 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4406 | static ssize_t reg_pages_show(struct device *device, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4407 | struct device_attribute *attr, char *buf) |
| 4408 | { |
| 4409 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4410 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4411 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 4412 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4413 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4414 | static DEVICE_ATTR_RO(reg_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4415 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4416 | static ssize_t hca_type_show(struct device *device, |
| 4417 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4418 | { |
| 4419 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4420 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4421 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4422 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4423 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4424 | static DEVICE_ATTR_RO(hca_type); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4425 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4426 | static ssize_t hw_rev_show(struct device *device, |
| 4427 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4428 | { |
| 4429 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4430 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4431 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4432 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4433 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4434 | static DEVICE_ATTR_RO(hw_rev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4435 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4436 | static ssize_t board_id_show(struct device *device, |
| 4437 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4438 | { |
| 4439 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4440 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4441 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4442 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4443 | dev->mdev->board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4444 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4445 | static DEVICE_ATTR_RO(board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4446 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4447 | static struct attribute *mlx5_class_attributes[] = { |
| 4448 | &dev_attr_hw_rev.attr, |
| 4449 | &dev_attr_hca_type.attr, |
| 4450 | &dev_attr_board_id.attr, |
| 4451 | &dev_attr_fw_pages.attr, |
| 4452 | &dev_attr_reg_pages.attr, |
| 4453 | NULL, |
| 4454 | }; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4455 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4456 | static const struct attribute_group mlx5_attr_group = { |
| 4457 | .attrs = mlx5_class_attributes, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4458 | }; |
| 4459 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4460 | static void pkey_change_handler(struct work_struct *work) |
| 4461 | { |
| 4462 | struct mlx5_ib_port_resources *ports = |
| 4463 | container_of(work, struct mlx5_ib_port_resources, |
| 4464 | pkey_change_work); |
| 4465 | |
| 4466 | mutex_lock(&ports->devr->mutex); |
| 4467 | mlx5_ib_gsi_pkey_change(ports->gsi); |
| 4468 | mutex_unlock(&ports->devr->mutex); |
| 4469 | } |
| 4470 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4471 | static void mlx5_ib_handle_internal_error(struct mlx5_ib_dev *ibdev) |
| 4472 | { |
| 4473 | struct mlx5_ib_qp *mqp; |
| 4474 | struct mlx5_ib_cq *send_mcq, *recv_mcq; |
| 4475 | struct mlx5_core_cq *mcq; |
| 4476 | struct list_head cq_armed_list; |
| 4477 | unsigned long flags_qp; |
| 4478 | unsigned long flags_cq; |
| 4479 | unsigned long flags; |
| 4480 | |
| 4481 | INIT_LIST_HEAD(&cq_armed_list); |
| 4482 | |
| 4483 | /* Go over qp list reside on that ibdev, sync with create/destroy qp.*/ |
| 4484 | spin_lock_irqsave(&ibdev->reset_flow_resource_lock, flags); |
| 4485 | list_for_each_entry(mqp, &ibdev->qp_list, qps_list) { |
| 4486 | spin_lock_irqsave(&mqp->sq.lock, flags_qp); |
| 4487 | if (mqp->sq.tail != mqp->sq.head) { |
| 4488 | send_mcq = to_mcq(mqp->ibqp.send_cq); |
| 4489 | spin_lock_irqsave(&send_mcq->lock, flags_cq); |
| 4490 | if (send_mcq->mcq.comp && |
| 4491 | mqp->ibqp.send_cq->comp_handler) { |
| 4492 | if (!send_mcq->mcq.reset_notify_added) { |
| 4493 | send_mcq->mcq.reset_notify_added = 1; |
| 4494 | list_add_tail(&send_mcq->mcq.reset_notify, |
| 4495 | &cq_armed_list); |
| 4496 | } |
| 4497 | } |
| 4498 | spin_unlock_irqrestore(&send_mcq->lock, flags_cq); |
| 4499 | } |
| 4500 | spin_unlock_irqrestore(&mqp->sq.lock, flags_qp); |
| 4501 | spin_lock_irqsave(&mqp->rq.lock, flags_qp); |
| 4502 | /* no handling is needed for SRQ */ |
| 4503 | if (!mqp->ibqp.srq) { |
| 4504 | if (mqp->rq.tail != mqp->rq.head) { |
| 4505 | recv_mcq = to_mcq(mqp->ibqp.recv_cq); |
| 4506 | spin_lock_irqsave(&recv_mcq->lock, flags_cq); |
| 4507 | if (recv_mcq->mcq.comp && |
| 4508 | mqp->ibqp.recv_cq->comp_handler) { |
| 4509 | if (!recv_mcq->mcq.reset_notify_added) { |
| 4510 | recv_mcq->mcq.reset_notify_added = 1; |
| 4511 | list_add_tail(&recv_mcq->mcq.reset_notify, |
| 4512 | &cq_armed_list); |
| 4513 | } |
| 4514 | } |
| 4515 | spin_unlock_irqrestore(&recv_mcq->lock, |
| 4516 | flags_cq); |
| 4517 | } |
| 4518 | } |
| 4519 | spin_unlock_irqrestore(&mqp->rq.lock, flags_qp); |
| 4520 | } |
| 4521 | /*At that point all inflight post send were put to be executed as of we |
| 4522 | * lock/unlock above locks Now need to arm all involved CQs. |
| 4523 | */ |
| 4524 | list_for_each_entry(mcq, &cq_armed_list, reset_notify) { |
Yishai Hadas | 4e0e2ea | 2019-06-30 19:23:27 +0300 | [diff] [blame] | 4525 | mcq->comp(mcq, NULL); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4526 | } |
| 4527 | spin_unlock_irqrestore(&ibdev->reset_flow_resource_lock, flags); |
| 4528 | } |
| 4529 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4530 | static void delay_drop_handler(struct work_struct *work) |
| 4531 | { |
| 4532 | int err; |
| 4533 | struct mlx5_ib_delay_drop *delay_drop = |
| 4534 | container_of(work, struct mlx5_ib_delay_drop, |
| 4535 | delay_drop_work); |
| 4536 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 4537 | atomic_inc(&delay_drop->events_cnt); |
| 4538 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4539 | mutex_lock(&delay_drop->lock); |
| 4540 | err = mlx5_core_set_delay_drop(delay_drop->dev->mdev, |
| 4541 | delay_drop->timeout); |
| 4542 | if (err) { |
| 4543 | mlx5_ib_warn(delay_drop->dev, "Failed to set delay drop, timeout=%u\n", |
| 4544 | delay_drop->timeout); |
| 4545 | delay_drop->activate = false; |
| 4546 | } |
| 4547 | mutex_unlock(&delay_drop->lock); |
| 4548 | } |
| 4549 | |
Saeed Mahameed | 09e574f | 2018-11-26 14:39:04 -0800 | [diff] [blame] | 4550 | static void handle_general_event(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, |
| 4551 | struct ib_event *ibev) |
| 4552 | { |
Aya Levin | 6cfdc7e | 2019-04-29 18:14:07 +0000 | [diff] [blame] | 4553 | u8 port = (eqe->data.port.port >> 4) & 0xf; |
| 4554 | |
Saeed Mahameed | 09e574f | 2018-11-26 14:39:04 -0800 | [diff] [blame] | 4555 | switch (eqe->sub_type) { |
| 4556 | case MLX5_GENERAL_SUBTYPE_DELAY_DROP_TIMEOUT: |
Aya Levin | 6cfdc7e | 2019-04-29 18:14:07 +0000 | [diff] [blame] | 4557 | if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
| 4558 | IB_LINK_LAYER_ETHERNET) |
| 4559 | schedule_work(&ibdev->delay_drop.delay_drop_work); |
Saeed Mahameed | 09e574f | 2018-11-26 14:39:04 -0800 | [diff] [blame] | 4560 | break; |
| 4561 | default: /* do nothing */ |
| 4562 | return; |
| 4563 | } |
| 4564 | } |
| 4565 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4566 | static int handle_port_change(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, |
| 4567 | struct ib_event *ibev) |
| 4568 | { |
| 4569 | u8 port = (eqe->data.port.port >> 4) & 0xf; |
| 4570 | |
| 4571 | ibev->element.port_num = port; |
| 4572 | |
| 4573 | switch (eqe->sub_type) { |
| 4574 | case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE: |
| 4575 | case MLX5_PORT_CHANGE_SUBTYPE_DOWN: |
| 4576 | case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED: |
| 4577 | /* In RoCE, port up/down events are handled in |
| 4578 | * mlx5_netdev_event(). |
| 4579 | */ |
| 4580 | if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
| 4581 | IB_LINK_LAYER_ETHERNET) |
| 4582 | return -EINVAL; |
| 4583 | |
| 4584 | ibev->event = (eqe->sub_type == MLX5_PORT_CHANGE_SUBTYPE_ACTIVE) ? |
| 4585 | IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
| 4586 | break; |
| 4587 | |
| 4588 | case MLX5_PORT_CHANGE_SUBTYPE_LID: |
| 4589 | ibev->event = IB_EVENT_LID_CHANGE; |
| 4590 | break; |
| 4591 | |
| 4592 | case MLX5_PORT_CHANGE_SUBTYPE_PKEY: |
| 4593 | ibev->event = IB_EVENT_PKEY_CHANGE; |
| 4594 | schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work); |
| 4595 | break; |
| 4596 | |
| 4597 | case MLX5_PORT_CHANGE_SUBTYPE_GUID: |
| 4598 | ibev->event = IB_EVENT_GID_CHANGE; |
| 4599 | break; |
| 4600 | |
| 4601 | case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG: |
| 4602 | ibev->event = IB_EVENT_CLIENT_REREGISTER; |
| 4603 | break; |
| 4604 | default: |
| 4605 | return -EINVAL; |
| 4606 | } |
| 4607 | |
| 4608 | return 0; |
| 4609 | } |
| 4610 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4611 | static void mlx5_ib_handle_event(struct work_struct *_work) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4612 | { |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4613 | struct mlx5_ib_event_work *work = |
| 4614 | container_of(_work, struct mlx5_ib_event_work, work); |
| 4615 | struct mlx5_ib_dev *ibdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4616 | struct ib_event ibev; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4617 | bool fatal = false; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4618 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4619 | if (work->is_slave) { |
| 4620 | ibdev = mlx5_ib_get_ibdev_from_mpi(work->mpi); |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4621 | if (!ibdev) |
| 4622 | goto out; |
| 4623 | } else { |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4624 | ibdev = work->dev; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | switch (work->event) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4628 | case MLX5_DEV_EVENT_SYS_ERROR: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4629 | ibev.event = IB_EVENT_DEVICE_FATAL; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4630 | mlx5_ib_handle_internal_error(ibdev); |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4631 | ibev.element.port_num = (u8)(unsigned long)work->param; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4632 | fatal = true; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4633 | break; |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4634 | case MLX5_EVENT_TYPE_PORT_CHANGE: |
| 4635 | if (handle_port_change(ibdev, work->param, &ibev)) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4636 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4637 | break; |
Saeed Mahameed | 09e574f | 2018-11-26 14:39:04 -0800 | [diff] [blame] | 4638 | case MLX5_EVENT_TYPE_GENERAL_EVENT: |
| 4639 | handle_general_event(ibdev, work->param, &ibev); |
| 4640 | /* fall through */ |
Saeed Mahameed | bdc3792 | 2016-09-29 19:35:38 +0300 | [diff] [blame] | 4641 | default: |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4642 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4643 | } |
| 4644 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4645 | ibev.device = &ibdev->ib_dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4646 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4647 | if (!rdma_is_port_valid(&ibdev->ib_dev, ibev.element.port_num)) { |
| 4648 | 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] | 4649 | goto out; |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 4650 | } |
| 4651 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4652 | if (ibdev->ib_active) |
| 4653 | ib_dispatch_event(&ibev); |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4654 | |
| 4655 | if (fatal) |
| 4656 | ibdev->ib_active = false; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4657 | out: |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4658 | kfree(work); |
| 4659 | } |
| 4660 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4661 | static int mlx5_ib_event(struct notifier_block *nb, |
| 4662 | unsigned long event, void *param) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4663 | { |
| 4664 | struct mlx5_ib_event_work *work; |
| 4665 | |
| 4666 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4667 | if (!work) |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4668 | return NOTIFY_DONE; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4669 | |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4670 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4671 | work->dev = container_of(nb, struct mlx5_ib_dev, mdev_events); |
| 4672 | work->is_slave = false; |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4673 | work->param = param; |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4674 | work->event = event; |
| 4675 | |
| 4676 | queue_work(mlx5_ib_event_wq, &work->work); |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4677 | |
| 4678 | return NOTIFY_OK; |
| 4679 | } |
| 4680 | |
| 4681 | static int mlx5_ib_event_slave_port(struct notifier_block *nb, |
| 4682 | unsigned long event, void *param) |
| 4683 | { |
| 4684 | struct mlx5_ib_event_work *work; |
| 4685 | |
| 4686 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
| 4687 | if (!work) |
| 4688 | return NOTIFY_DONE; |
| 4689 | |
| 4690 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
| 4691 | work->mpi = container_of(nb, struct mlx5_ib_multiport_info, mdev_events); |
| 4692 | work->is_slave = true; |
| 4693 | work->param = param; |
| 4694 | work->event = event; |
| 4695 | queue_work(mlx5_ib_event_wq, &work->work); |
| 4696 | |
| 4697 | return NOTIFY_OK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4698 | } |
| 4699 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4700 | static int set_has_smi_cap(struct mlx5_ib_dev *dev) |
| 4701 | { |
| 4702 | struct mlx5_hca_vport_context vport_ctx; |
| 4703 | int err; |
| 4704 | int port; |
| 4705 | |
Mark Bloch | a989ea0 | 2019-03-28 15:27:40 +0200 | [diff] [blame] | 4706 | for (port = 1; port <= ARRAY_SIZE(dev->mdev->port_caps); port++) { |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4707 | dev->mdev->port_caps[port - 1].has_smi = false; |
| 4708 | if (MLX5_CAP_GEN(dev->mdev, port_type) == |
| 4709 | MLX5_CAP_PORT_TYPE_IB) { |
| 4710 | if (MLX5_CAP_GEN(dev->mdev, ib_virt)) { |
| 4711 | err = mlx5_query_hca_vport_context(dev->mdev, 0, |
| 4712 | port, 0, |
| 4713 | &vport_ctx); |
| 4714 | if (err) { |
| 4715 | mlx5_ib_err(dev, "query_hca_vport_context for port=%d failed %d\n", |
| 4716 | port, err); |
| 4717 | return err; |
| 4718 | } |
| 4719 | dev->mdev->port_caps[port - 1].has_smi = |
| 4720 | vport_ctx.has_smi; |
| 4721 | } else { |
| 4722 | dev->mdev->port_caps[port - 1].has_smi = true; |
| 4723 | } |
| 4724 | } |
| 4725 | } |
| 4726 | return 0; |
| 4727 | } |
| 4728 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4729 | static void get_ext_port_caps(struct mlx5_ib_dev *dev) |
| 4730 | { |
| 4731 | int port; |
| 4732 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4733 | for (port = 1; port <= dev->num_ports; port++) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4734 | mlx5_query_ext_port_caps(dev, port); |
| 4735 | } |
| 4736 | |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 4737 | static int __get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4738 | { |
| 4739 | struct ib_device_attr *dprops = NULL; |
| 4740 | struct ib_port_attr *pprops = NULL; |
Dan Carpenter | f614fc1 | 2015-01-12 11:56:58 +0300 | [diff] [blame] | 4741 | int err = -ENOMEM; |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4742 | struct ib_udata uhw = {.inlen = 0, .outlen = 0}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4743 | |
Leon Romanovsky | 50ba3c1 | 2019-06-30 18:48:32 +0300 | [diff] [blame] | 4744 | pprops = kzalloc(sizeof(*pprops), GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4745 | if (!pprops) |
| 4746 | goto out; |
| 4747 | |
| 4748 | dprops = kmalloc(sizeof(*dprops), GFP_KERNEL); |
| 4749 | if (!dprops) |
| 4750 | goto out; |
| 4751 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4752 | err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4753 | if (err) { |
| 4754 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
| 4755 | goto out; |
| 4756 | } |
| 4757 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4758 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
| 4759 | if (err) { |
| 4760 | mlx5_ib_warn(dev, "query_port %d failed %d\n", |
| 4761 | port, err); |
| 4762 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4763 | } |
| 4764 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4765 | dev->mdev->port_caps[port - 1].pkey_table_len = |
| 4766 | dprops->max_pkeys; |
| 4767 | dev->mdev->port_caps[port - 1].gid_table_len = |
| 4768 | pprops->gid_tbl_len; |
| 4769 | mlx5_ib_dbg(dev, "port %d: pkey_table_len %d, gid_table_len %d\n", |
| 4770 | port, dprops->max_pkeys, pprops->gid_tbl_len); |
| 4771 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4772 | out: |
| 4773 | kfree(pprops); |
| 4774 | kfree(dprops); |
| 4775 | |
| 4776 | return err; |
| 4777 | } |
| 4778 | |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 4779 | static int get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
| 4780 | { |
| 4781 | /* For representors use port 1, is this is the only native |
| 4782 | * port |
| 4783 | */ |
| 4784 | if (dev->is_rep) |
| 4785 | return __get_port_caps(dev, 1); |
| 4786 | return __get_port_caps(dev, port); |
| 4787 | } |
| 4788 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4789 | static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
| 4790 | { |
| 4791 | int err; |
| 4792 | |
| 4793 | err = mlx5_mr_cache_cleanup(dev); |
| 4794 | if (err) |
| 4795 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
| 4796 | |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4797 | if (dev->umrc.qp) |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4798 | mlx5_ib_destroy_qp(dev->umrc.qp, NULL); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4799 | if (dev->umrc.cq) |
| 4800 | ib_free_cq(dev->umrc.cq); |
| 4801 | if (dev->umrc.pd) |
| 4802 | ib_dealloc_pd(dev->umrc.pd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | enum { |
| 4806 | MAX_UMR_WR = 128, |
| 4807 | }; |
| 4808 | |
| 4809 | static int create_umr_res(struct mlx5_ib_dev *dev) |
| 4810 | { |
| 4811 | struct ib_qp_init_attr *init_attr = NULL; |
| 4812 | struct ib_qp_attr *attr = NULL; |
| 4813 | struct ib_pd *pd; |
| 4814 | struct ib_cq *cq; |
| 4815 | struct ib_qp *qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4816 | int ret; |
| 4817 | |
| 4818 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| 4819 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 4820 | if (!attr || !init_attr) { |
| 4821 | ret = -ENOMEM; |
| 4822 | goto error_0; |
| 4823 | } |
| 4824 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 4825 | pd = ib_alloc_pd(&dev->ib_dev, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4826 | if (IS_ERR(pd)) { |
| 4827 | mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); |
| 4828 | ret = PTR_ERR(pd); |
| 4829 | goto error_0; |
| 4830 | } |
| 4831 | |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4832 | 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] | 4833 | if (IS_ERR(cq)) { |
| 4834 | mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); |
| 4835 | ret = PTR_ERR(cq); |
| 4836 | goto error_2; |
| 4837 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4838 | |
| 4839 | init_attr->send_cq = cq; |
| 4840 | init_attr->recv_cq = cq; |
| 4841 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
| 4842 | init_attr->cap.max_send_wr = MAX_UMR_WR; |
| 4843 | init_attr->cap.max_send_sge = 1; |
| 4844 | init_attr->qp_type = MLX5_IB_QPT_REG_UMR; |
| 4845 | init_attr->port_num = 1; |
| 4846 | qp = mlx5_ib_create_qp(pd, init_attr, NULL); |
| 4847 | if (IS_ERR(qp)) { |
| 4848 | mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); |
| 4849 | ret = PTR_ERR(qp); |
| 4850 | goto error_3; |
| 4851 | } |
| 4852 | qp->device = &dev->ib_dev; |
| 4853 | qp->real_qp = qp; |
| 4854 | qp->uobject = NULL; |
| 4855 | qp->qp_type = MLX5_IB_QPT_REG_UMR; |
Majd Dibbiny | 31fde03 | 2017-10-30 14:23:13 +0200 | [diff] [blame] | 4856 | qp->send_cq = init_attr->send_cq; |
| 4857 | qp->recv_cq = init_attr->recv_cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4858 | |
| 4859 | attr->qp_state = IB_QPS_INIT; |
| 4860 | attr->port_num = 1; |
| 4861 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX | |
| 4862 | IB_QP_PORT, NULL); |
| 4863 | if (ret) { |
| 4864 | mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); |
| 4865 | goto error_4; |
| 4866 | } |
| 4867 | |
| 4868 | memset(attr, 0, sizeof(*attr)); |
| 4869 | attr->qp_state = IB_QPS_RTR; |
| 4870 | attr->path_mtu = IB_MTU_256; |
| 4871 | |
| 4872 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4873 | if (ret) { |
| 4874 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); |
| 4875 | goto error_4; |
| 4876 | } |
| 4877 | |
| 4878 | memset(attr, 0, sizeof(*attr)); |
| 4879 | attr->qp_state = IB_QPS_RTS; |
| 4880 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4881 | if (ret) { |
| 4882 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); |
| 4883 | goto error_4; |
| 4884 | } |
| 4885 | |
| 4886 | dev->umrc.qp = qp; |
| 4887 | dev->umrc.cq = cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4888 | dev->umrc.pd = pd; |
| 4889 | |
| 4890 | sema_init(&dev->umrc.sem, MAX_UMR_WR); |
| 4891 | ret = mlx5_mr_cache_init(dev); |
| 4892 | if (ret) { |
| 4893 | mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); |
| 4894 | goto error_4; |
| 4895 | } |
| 4896 | |
| 4897 | kfree(attr); |
| 4898 | kfree(init_attr); |
| 4899 | |
| 4900 | return 0; |
| 4901 | |
| 4902 | error_4: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4903 | mlx5_ib_destroy_qp(qp, NULL); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4904 | dev->umrc.qp = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4905 | |
| 4906 | error_3: |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4907 | ib_free_cq(cq); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4908 | dev->umrc.cq = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4909 | |
| 4910 | error_2: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4911 | ib_dealloc_pd(pd); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4912 | dev->umrc.pd = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4913 | |
| 4914 | error_0: |
| 4915 | kfree(attr); |
| 4916 | kfree(init_attr); |
| 4917 | return ret; |
| 4918 | } |
| 4919 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 4920 | static u8 mlx5_get_umr_fence(u8 umr_fence_cap) |
| 4921 | { |
| 4922 | switch (umr_fence_cap) { |
| 4923 | case MLX5_CAP_UMR_FENCE_NONE: |
| 4924 | return MLX5_FENCE_MODE_NONE; |
| 4925 | case MLX5_CAP_UMR_FENCE_SMALL: |
| 4926 | return MLX5_FENCE_MODE_INITIATOR_SMALL; |
| 4927 | default: |
| 4928 | return MLX5_FENCE_MODE_STRONG_ORDERING; |
| 4929 | } |
| 4930 | } |
| 4931 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4932 | static int create_dev_resources(struct mlx5_ib_resources *devr) |
| 4933 | { |
| 4934 | struct ib_srq_init_attr attr; |
| 4935 | struct mlx5_ib_dev *dev; |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4936 | struct ib_device *ibdev; |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 4937 | struct ib_cq_init_attr cq_attr = {.cqe = 1}; |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4938 | int port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4939 | int ret = 0; |
| 4940 | |
| 4941 | dev = container_of(devr, struct mlx5_ib_dev, devr); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4942 | ibdev = &dev->ib_dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4943 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4944 | mutex_init(&devr->mutex); |
| 4945 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4946 | devr->p0 = rdma_zalloc_drv_obj(ibdev, ib_pd); |
| 4947 | if (!devr->p0) |
| 4948 | return -ENOMEM; |
| 4949 | |
| 4950 | devr->p0->device = ibdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4951 | devr->p0->uobject = NULL; |
| 4952 | atomic_set(&devr->p0->usecnt, 0); |
| 4953 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4954 | ret = mlx5_ib_alloc_pd(devr->p0, NULL); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4955 | if (ret) |
| 4956 | goto error0; |
| 4957 | |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 4958 | devr->c0 = rdma_zalloc_drv_obj(ibdev, ib_cq); |
| 4959 | if (!devr->c0) { |
| 4960 | ret = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4961 | goto error1; |
| 4962 | } |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 4963 | |
| 4964 | devr->c0->device = &dev->ib_dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4965 | atomic_set(&devr->c0->usecnt, 0); |
| 4966 | |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 4967 | ret = mlx5_ib_create_cq(devr->c0, &cq_attr, NULL); |
| 4968 | if (ret) |
| 4969 | goto err_create_cq; |
| 4970 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4971 | devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4972 | if (IS_ERR(devr->x0)) { |
| 4973 | ret = PTR_ERR(devr->x0); |
| 4974 | goto error2; |
| 4975 | } |
| 4976 | devr->x0->device = &dev->ib_dev; |
| 4977 | devr->x0->inode = NULL; |
| 4978 | atomic_set(&devr->x0->usecnt, 0); |
| 4979 | mutex_init(&devr->x0->tgt_qp_mutex); |
| 4980 | INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
| 4981 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 4982 | devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4983 | if (IS_ERR(devr->x1)) { |
| 4984 | ret = PTR_ERR(devr->x1); |
| 4985 | goto error3; |
| 4986 | } |
| 4987 | devr->x1->device = &dev->ib_dev; |
| 4988 | devr->x1->inode = NULL; |
| 4989 | atomic_set(&devr->x1->usecnt, 0); |
| 4990 | mutex_init(&devr->x1->tgt_qp_mutex); |
| 4991 | INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
| 4992 | |
| 4993 | memset(&attr, 0, sizeof(attr)); |
| 4994 | attr.attr.max_sge = 1; |
| 4995 | attr.attr.max_wr = 1; |
| 4996 | attr.srq_type = IB_SRQT_XRC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4997 | attr.ext.cq = devr->c0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4998 | attr.ext.xrc.xrcd = devr->x0; |
| 4999 | |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 5000 | devr->s0 = rdma_zalloc_drv_obj(ibdev, ib_srq); |
| 5001 | if (!devr->s0) { |
| 5002 | ret = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5003 | goto error4; |
| 5004 | } |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 5005 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5006 | devr->s0->device = &dev->ib_dev; |
| 5007 | devr->s0->pd = devr->p0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5008 | devr->s0->srq_type = IB_SRQT_XRC; |
| 5009 | devr->s0->ext.xrc.xrcd = devr->x0; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 5010 | devr->s0->ext.cq = devr->c0; |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 5011 | ret = mlx5_ib_create_srq(devr->s0, &attr, NULL); |
| 5012 | if (ret) |
| 5013 | goto err_create; |
| 5014 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5015 | atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 5016 | atomic_inc(&devr->s0->ext.cq->usecnt); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5017 | atomic_inc(&devr->p0->usecnt); |
| 5018 | atomic_set(&devr->s0->usecnt, 0); |
| 5019 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 5020 | memset(&attr, 0, sizeof(attr)); |
| 5021 | attr.attr.max_sge = 1; |
| 5022 | attr.attr.max_wr = 1; |
| 5023 | attr.srq_type = IB_SRQT_BASIC; |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 5024 | devr->s1 = rdma_zalloc_drv_obj(ibdev, ib_srq); |
| 5025 | if (!devr->s1) { |
| 5026 | ret = -ENOMEM; |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 5027 | goto error5; |
| 5028 | } |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 5029 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 5030 | devr->s1->device = &dev->ib_dev; |
| 5031 | devr->s1->pd = devr->p0; |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 5032 | devr->s1->srq_type = IB_SRQT_BASIC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 5033 | devr->s1->ext.cq = devr->c0; |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 5034 | |
| 5035 | ret = mlx5_ib_create_srq(devr->s1, &attr, NULL); |
| 5036 | if (ret) |
| 5037 | goto error6; |
| 5038 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 5039 | atomic_inc(&devr->p0->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 5040 | atomic_set(&devr->s1->usecnt, 0); |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 5041 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 5042 | for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) { |
| 5043 | INIT_WORK(&devr->ports[port].pkey_change_work, |
| 5044 | pkey_change_handler); |
| 5045 | devr->ports[port].devr = devr; |
| 5046 | } |
| 5047 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5048 | return 0; |
| 5049 | |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 5050 | error6: |
| 5051 | kfree(devr->s1); |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 5052 | error5: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5053 | mlx5_ib_destroy_srq(devr->s0, NULL); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 5054 | err_create: |
| 5055 | kfree(devr->s0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5056 | error4: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5057 | mlx5_ib_dealloc_xrcd(devr->x1, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5058 | error3: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5059 | mlx5_ib_dealloc_xrcd(devr->x0, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5060 | error2: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5061 | mlx5_ib_destroy_cq(devr->c0, NULL); |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 5062 | err_create_cq: |
| 5063 | kfree(devr->c0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5064 | error1: |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5065 | mlx5_ib_dealloc_pd(devr->p0, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5066 | error0: |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 5067 | kfree(devr->p0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5068 | return ret; |
| 5069 | } |
| 5070 | |
| 5071 | static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
| 5072 | { |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 5073 | int port; |
| 5074 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5075 | mlx5_ib_destroy_srq(devr->s1, NULL); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 5076 | kfree(devr->s1); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5077 | mlx5_ib_destroy_srq(devr->s0, NULL); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 5078 | kfree(devr->s0); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5079 | mlx5_ib_dealloc_xrcd(devr->x0, NULL); |
| 5080 | mlx5_ib_dealloc_xrcd(devr->x1, NULL); |
| 5081 | mlx5_ib_destroy_cq(devr->c0, NULL); |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 5082 | kfree(devr->c0); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5083 | mlx5_ib_dealloc_pd(devr->p0, NULL); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 5084 | kfree(devr->p0); |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 5085 | |
| 5086 | /* Make sure no change P_Key work items are still executing */ |
Mark Bloch | 5d8f6a0 | 2019-03-28 15:27:36 +0200 | [diff] [blame] | 5087 | for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 5088 | cancel_work_sync(&devr->ports[port].pkey_change_work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5089 | } |
| 5090 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 5091 | static u32 get_core_cap_flags(struct ib_device *ibdev, |
| 5092 | struct mlx5_hca_vport_context *rep) |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5093 | { |
| 5094 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5095 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, 1); |
| 5096 | u8 l3_type_cap = MLX5_CAP_ROCE(dev->mdev, l3_type); |
| 5097 | u8 roce_version_cap = MLX5_CAP_ROCE(dev->mdev, roce_version); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 5098 | bool raw_support = !mlx5_core_mp_enabled(dev->mdev); |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5099 | u32 ret = 0; |
| 5100 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 5101 | if (rep->grh_required) |
| 5102 | ret |= RDMA_CORE_CAP_IB_GRH_REQUIRED; |
| 5103 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5104 | if (ll == IB_LINK_LAYER_INFINIBAND) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 5105 | return ret | RDMA_CORE_PORT_IBA_IB; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5106 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 5107 | if (raw_support) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 5108 | ret |= RDMA_CORE_PORT_RAW_PACKET; |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 5109 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5110 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV4_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 5111 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5112 | |
| 5113 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV6_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 5114 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5115 | |
| 5116 | if (roce_version_cap & MLX5_ROCE_VERSION_1_CAP) |
| 5117 | ret |= RDMA_CORE_PORT_IBA_ROCE; |
| 5118 | |
| 5119 | if (roce_version_cap & MLX5_ROCE_VERSION_2_CAP) |
| 5120 | ret |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; |
| 5121 | |
| 5122 | return ret; |
| 5123 | } |
| 5124 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 5125 | static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 5126 | struct ib_port_immutable *immutable) |
| 5127 | { |
| 5128 | struct ib_port_attr attr; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5129 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5130 | 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] | 5131 | struct mlx5_hca_vport_context rep = {0}; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 5132 | int err; |
| 5133 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 5134 | err = ib_query_port(ibdev, port_num, &attr); |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 5135 | if (err) |
| 5136 | return err; |
| 5137 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 5138 | if (ll == IB_LINK_LAYER_INFINIBAND) { |
| 5139 | err = mlx5_query_hca_vport_context(dev->mdev, 0, port_num, 0, |
| 5140 | &rep); |
| 5141 | if (err) |
| 5142 | return err; |
| 5143 | } |
| 5144 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 5145 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 5146 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 5147 | immutable->core_cap_flags = get_core_cap_flags(ibdev, &rep); |
Michael Guralnik | 94de879 | 2019-11-08 23:45:28 +0000 | [diff] [blame^] | 5148 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 5149 | |
| 5150 | return 0; |
| 5151 | } |
| 5152 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5153 | static int mlx5_port_rep_immutable(struct ib_device *ibdev, u8 port_num, |
| 5154 | struct ib_port_immutable *immutable) |
| 5155 | { |
| 5156 | struct ib_port_attr attr; |
| 5157 | int err; |
| 5158 | |
| 5159 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 5160 | |
| 5161 | err = ib_query_port(ibdev, port_num, &attr); |
| 5162 | if (err) |
| 5163 | return err; |
| 5164 | |
| 5165 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 5166 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 5167 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 5168 | |
| 5169 | return 0; |
| 5170 | } |
| 5171 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 5172 | static void get_dev_fw_str(struct ib_device *ibdev, char *str) |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 5173 | { |
| 5174 | struct mlx5_ib_dev *dev = |
| 5175 | container_of(ibdev, struct mlx5_ib_dev, ib_dev); |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 5176 | snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%04d", |
| 5177 | fw_rev_maj(dev->mdev), fw_rev_min(dev->mdev), |
| 5178 | fw_rev_sub(dev->mdev)); |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 5179 | } |
| 5180 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5181 | static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5182 | { |
| 5183 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5184 | struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(mdev, |
| 5185 | MLX5_FLOW_NAMESPACE_LAG); |
| 5186 | struct mlx5_flow_table *ft; |
| 5187 | int err; |
| 5188 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 5189 | if (!ns || !mlx5_lag_is_roce(mdev)) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5190 | return 0; |
| 5191 | |
| 5192 | err = mlx5_cmd_create_vport_lag(mdev); |
| 5193 | if (err) |
| 5194 | return err; |
| 5195 | |
| 5196 | ft = mlx5_create_lag_demux_flow_table(ns, 0, 0); |
| 5197 | if (IS_ERR(ft)) { |
| 5198 | err = PTR_ERR(ft); |
| 5199 | goto err_destroy_vport_lag; |
| 5200 | } |
| 5201 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5202 | dev->flow_db->lag_demux_ft = ft; |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 5203 | dev->lag_active = true; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5204 | return 0; |
| 5205 | |
| 5206 | err_destroy_vport_lag: |
| 5207 | mlx5_cmd_destroy_vport_lag(mdev); |
| 5208 | return err; |
| 5209 | } |
| 5210 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5211 | static void mlx5_eth_lag_cleanup(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5212 | { |
| 5213 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5214 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 5215 | if (dev->lag_active) { |
| 5216 | dev->lag_active = false; |
| 5217 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5218 | mlx5_destroy_flow_table(dev->flow_db->lag_demux_ft); |
| 5219 | dev->flow_db->lag_demux_ft = NULL; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5220 | |
| 5221 | mlx5_cmd_destroy_vport_lag(mdev); |
| 5222 | } |
| 5223 | } |
| 5224 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5225 | 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] | 5226 | { |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5227 | int err; |
| 5228 | |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5229 | dev->port[port_num].roce.nb.notifier_call = mlx5_netdev_event; |
| 5230 | err = register_netdevice_notifier(&dev->port[port_num].roce.nb); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 5231 | if (err) { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5232 | dev->port[port_num].roce.nb.notifier_call = NULL; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5233 | return err; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 5234 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5235 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 5236 | return 0; |
| 5237 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5238 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5239 | 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] | 5240 | { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5241 | if (dev->port[port_num].roce.nb.notifier_call) { |
| 5242 | unregister_netdevice_notifier(&dev->port[port_num].roce.nb); |
| 5243 | dev->port[port_num].roce.nb.notifier_call = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5244 | } |
| 5245 | } |
| 5246 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5247 | static int mlx5_enable_eth(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5248 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5249 | int err; |
| 5250 | |
Michael Guralnik | 94de879 | 2019-11-08 23:45:28 +0000 | [diff] [blame^] | 5251 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 5252 | if (err) |
| 5253 | return err; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5254 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5255 | err = mlx5_eth_lag_init(dev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5256 | if (err) |
| 5257 | goto err_disable_roce; |
| 5258 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5259 | return 0; |
| 5260 | |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5261 | err_disable_roce: |
Michael Guralnik | 94de879 | 2019-11-08 23:45:28 +0000 | [diff] [blame^] | 5262 | mlx5_nic_vport_disable_roce(dev->mdev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5263 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5264 | return err; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5265 | } |
| 5266 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5267 | static void mlx5_disable_eth(struct mlx5_ib_dev *dev) |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5268 | { |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5269 | mlx5_eth_lag_cleanup(dev); |
Michael Guralnik | 94de879 | 2019-11-08 23:45:28 +0000 | [diff] [blame^] | 5270 | mlx5_nic_vport_disable_roce(dev->mdev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5271 | } |
| 5272 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5273 | struct mlx5_ib_counter { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5274 | const char *name; |
| 5275 | size_t offset; |
| 5276 | }; |
| 5277 | |
| 5278 | #define INIT_Q_COUNTER(_name) \ |
| 5279 | { .name = #_name, .offset = MLX5_BYTE_OFF(query_q_counter_out, _name)} |
| 5280 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5281 | static const struct mlx5_ib_counter basic_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5282 | INIT_Q_COUNTER(rx_write_requests), |
| 5283 | INIT_Q_COUNTER(rx_read_requests), |
| 5284 | INIT_Q_COUNTER(rx_atomic_requests), |
| 5285 | INIT_Q_COUNTER(out_of_buffer), |
| 5286 | }; |
| 5287 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5288 | static const struct mlx5_ib_counter out_of_seq_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5289 | INIT_Q_COUNTER(out_of_sequence), |
| 5290 | }; |
| 5291 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5292 | static const struct mlx5_ib_counter retrans_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5293 | INIT_Q_COUNTER(duplicate_request), |
| 5294 | INIT_Q_COUNTER(rnr_nak_retry_err), |
| 5295 | INIT_Q_COUNTER(packet_seq_err), |
| 5296 | INIT_Q_COUNTER(implied_nak_seq_err), |
| 5297 | INIT_Q_COUNTER(local_ack_timeout_err), |
| 5298 | }; |
| 5299 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5300 | #define INIT_CONG_COUNTER(_name) \ |
| 5301 | { .name = #_name, .offset = \ |
| 5302 | MLX5_BYTE_OFF(query_cong_statistics_out, _name ## _high)} |
| 5303 | |
| 5304 | static const struct mlx5_ib_counter cong_cnts[] = { |
| 5305 | INIT_CONG_COUNTER(rp_cnp_ignored), |
| 5306 | INIT_CONG_COUNTER(rp_cnp_handled), |
| 5307 | INIT_CONG_COUNTER(np_ecn_marked_roce_packets), |
| 5308 | INIT_CONG_COUNTER(np_cnp_sent), |
| 5309 | }; |
| 5310 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5311 | static const struct mlx5_ib_counter extended_err_cnts[] = { |
| 5312 | INIT_Q_COUNTER(resp_local_length_error), |
| 5313 | INIT_Q_COUNTER(resp_cqe_error), |
| 5314 | INIT_Q_COUNTER(req_cqe_error), |
| 5315 | INIT_Q_COUNTER(req_remote_invalid_request), |
| 5316 | INIT_Q_COUNTER(req_remote_access_errors), |
| 5317 | INIT_Q_COUNTER(resp_remote_access_errors), |
| 5318 | INIT_Q_COUNTER(resp_cqe_flush_error), |
| 5319 | INIT_Q_COUNTER(req_cqe_flush_error), |
| 5320 | }; |
| 5321 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5322 | #define INIT_EXT_PPCNT_COUNTER(_name) \ |
| 5323 | { .name = #_name, .offset = \ |
| 5324 | MLX5_BYTE_OFF(ppcnt_reg, \ |
| 5325 | counter_set.eth_extended_cntrs_grp_data_layout._name##_high)} |
| 5326 | |
| 5327 | static const struct mlx5_ib_counter ext_ppcnt_cnts[] = { |
| 5328 | INIT_EXT_PPCNT_COUNTER(rx_icrc_encapsulated), |
| 5329 | }; |
| 5330 | |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5331 | static bool is_mdev_switchdev_mode(const struct mlx5_core_dev *mdev) |
| 5332 | { |
| 5333 | return MLX5_ESWITCH_MANAGER(mdev) && |
| 5334 | mlx5_ib_eswitch_mode(mdev->priv.eswitch) == |
| 5335 | MLX5_ESWITCH_OFFLOADS; |
| 5336 | } |
| 5337 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5338 | static void mlx5_ib_dealloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5339 | { |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5340 | int num_cnt_ports; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5341 | int i; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5342 | |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5343 | num_cnt_ports = is_mdev_switchdev_mode(dev->mdev) ? 1 : dev->num_ports; |
| 5344 | |
| 5345 | for (i = 0; i < num_cnt_ports; i++) { |
Parav Pandit | 921c0f5 | 2018-07-08 13:40:30 +0300 | [diff] [blame] | 5346 | if (dev->port[i].cnts.set_id_valid) |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5347 | mlx5_core_dealloc_q_counter(dev->mdev, |
| 5348 | dev->port[i].cnts.set_id); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5349 | kfree(dev->port[i].cnts.names); |
| 5350 | kfree(dev->port[i].cnts.offsets); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5351 | } |
| 5352 | } |
| 5353 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5354 | static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, |
| 5355 | struct mlx5_ib_counters *cnts) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5356 | { |
| 5357 | u32 num_counters; |
| 5358 | |
| 5359 | num_counters = ARRAY_SIZE(basic_q_cnts); |
| 5360 | |
| 5361 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) |
| 5362 | num_counters += ARRAY_SIZE(out_of_seq_q_cnts); |
| 5363 | |
| 5364 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) |
| 5365 | num_counters += ARRAY_SIZE(retrans_q_cnts); |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5366 | |
| 5367 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) |
| 5368 | num_counters += ARRAY_SIZE(extended_err_cnts); |
| 5369 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5370 | cnts->num_q_counters = num_counters; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5371 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5372 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 5373 | cnts->num_cong_counters = ARRAY_SIZE(cong_cnts); |
| 5374 | num_counters += ARRAY_SIZE(cong_cnts); |
| 5375 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5376 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5377 | cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts); |
| 5378 | num_counters += ARRAY_SIZE(ext_ppcnt_cnts); |
| 5379 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5380 | cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL); |
| 5381 | if (!cnts->names) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5382 | return -ENOMEM; |
| 5383 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5384 | cnts->offsets = kcalloc(num_counters, |
| 5385 | sizeof(cnts->offsets), GFP_KERNEL); |
| 5386 | if (!cnts->offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5387 | goto err_names; |
| 5388 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5389 | return 0; |
| 5390 | |
| 5391 | err_names: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5392 | kfree(cnts->names); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5393 | cnts->names = NULL; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5394 | return -ENOMEM; |
| 5395 | } |
| 5396 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5397 | static void mlx5_ib_fill_counters(struct mlx5_ib_dev *dev, |
| 5398 | const char **names, |
| 5399 | size_t *offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5400 | { |
| 5401 | int i; |
| 5402 | int j = 0; |
| 5403 | |
| 5404 | for (i = 0; i < ARRAY_SIZE(basic_q_cnts); i++, j++) { |
| 5405 | names[j] = basic_q_cnts[i].name; |
| 5406 | offsets[j] = basic_q_cnts[i].offset; |
| 5407 | } |
| 5408 | |
| 5409 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) { |
| 5410 | for (i = 0; i < ARRAY_SIZE(out_of_seq_q_cnts); i++, j++) { |
| 5411 | names[j] = out_of_seq_q_cnts[i].name; |
| 5412 | offsets[j] = out_of_seq_q_cnts[i].offset; |
| 5413 | } |
| 5414 | } |
| 5415 | |
| 5416 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) { |
| 5417 | for (i = 0; i < ARRAY_SIZE(retrans_q_cnts); i++, j++) { |
| 5418 | names[j] = retrans_q_cnts[i].name; |
| 5419 | offsets[j] = retrans_q_cnts[i].offset; |
| 5420 | } |
| 5421 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5422 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5423 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) { |
| 5424 | for (i = 0; i < ARRAY_SIZE(extended_err_cnts); i++, j++) { |
| 5425 | names[j] = extended_err_cnts[i].name; |
| 5426 | offsets[j] = extended_err_cnts[i].offset; |
| 5427 | } |
| 5428 | } |
| 5429 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5430 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 5431 | for (i = 0; i < ARRAY_SIZE(cong_cnts); i++, j++) { |
| 5432 | names[j] = cong_cnts[i].name; |
| 5433 | offsets[j] = cong_cnts[i].offset; |
| 5434 | } |
| 5435 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5436 | |
| 5437 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5438 | for (i = 0; i < ARRAY_SIZE(ext_ppcnt_cnts); i++, j++) { |
| 5439 | names[j] = ext_ppcnt_cnts[i].name; |
| 5440 | offsets[j] = ext_ppcnt_cnts[i].offset; |
| 5441 | } |
| 5442 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5443 | } |
| 5444 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5445 | static int mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5446 | { |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5447 | int num_cnt_ports; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5448 | int err = 0; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5449 | int i; |
Yishai Hadas | aa74be6 | 2018-12-09 12:52:36 +0200 | [diff] [blame] | 5450 | bool is_shared; |
| 5451 | |
| 5452 | is_shared = MLX5_CAP_GEN(dev->mdev, log_max_uctx) != 0; |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5453 | num_cnt_ports = is_mdev_switchdev_mode(dev->mdev) ? 1 : dev->num_ports; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5454 | |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5455 | for (i = 0; i < num_cnt_ports; i++) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5456 | err = __mlx5_ib_alloc_counters(dev, &dev->port[i].cnts); |
| 5457 | if (err) |
| 5458 | goto err_alloc; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5459 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5460 | mlx5_ib_fill_counters(dev, dev->port[i].cnts.names, |
| 5461 | dev->port[i].cnts.offsets); |
| 5462 | |
Yishai Hadas | aa74be6 | 2018-12-09 12:52:36 +0200 | [diff] [blame] | 5463 | err = mlx5_cmd_alloc_q_counter(dev->mdev, |
| 5464 | &dev->port[i].cnts.set_id, |
| 5465 | is_shared ? |
| 5466 | MLX5_SHARED_RESOURCE_UID : 0); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5467 | if (err) { |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5468 | mlx5_ib_warn(dev, |
| 5469 | "couldn't allocate queue counter for port %d, err %d\n", |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5470 | i + 1, err); |
| 5471 | goto err_alloc; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5472 | } |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5473 | dev->port[i].cnts.set_id_valid = true; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5474 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5475 | return 0; |
| 5476 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5477 | err_alloc: |
| 5478 | mlx5_ib_dealloc_counters(dev); |
| 5479 | return err; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5480 | } |
| 5481 | |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5482 | static const struct mlx5_ib_counters *get_counters(struct mlx5_ib_dev *dev, |
| 5483 | u8 port_num) |
| 5484 | { |
| 5485 | return is_mdev_switchdev_mode(dev->mdev) ? &dev->port[0].cnts : |
| 5486 | &dev->port[port_num].cnts; |
| 5487 | } |
| 5488 | |
| 5489 | /** |
| 5490 | * mlx5_ib_get_counters_id - Returns counters id to use for device+port |
| 5491 | * @dev: Pointer to mlx5 IB device |
| 5492 | * @port_num: Zero based port number |
| 5493 | * |
| 5494 | * mlx5_ib_get_counters_id() Returns counters set id to use for given |
| 5495 | * device port combination in switchdev and non switchdev mode of the |
| 5496 | * parent device. |
| 5497 | */ |
| 5498 | u16 mlx5_ib_get_counters_id(struct mlx5_ib_dev *dev, u8 port_num) |
| 5499 | { |
| 5500 | const struct mlx5_ib_counters *cnts = get_counters(dev, port_num); |
| 5501 | |
| 5502 | return cnts->set_id; |
| 5503 | } |
| 5504 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5505 | static struct rdma_hw_stats *mlx5_ib_alloc_hw_stats(struct ib_device *ibdev, |
| 5506 | u8 port_num) |
| 5507 | { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5508 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5509 | const struct mlx5_ib_counters *cnts; |
| 5510 | bool is_switchdev = is_mdev_switchdev_mode(dev->mdev); |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5511 | |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5512 | if ((is_switchdev && port_num) || (!is_switchdev && !port_num)) |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5513 | return NULL; |
| 5514 | |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5515 | cnts = get_counters(dev, port_num - 1); |
| 5516 | |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5517 | return rdma_alloc_hw_stats_struct(cnts->names, |
| 5518 | cnts->num_q_counters + |
| 5519 | cnts->num_cong_counters + |
| 5520 | cnts->num_ext_ppcnt_counters, |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5521 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 5522 | } |
| 5523 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5524 | static int mlx5_ib_query_q_counters(struct mlx5_core_dev *mdev, |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5525 | const struct mlx5_ib_counters *cnts, |
Mark Zhang | 318d535 | 2019-07-02 13:02:37 +0300 | [diff] [blame] | 5526 | struct rdma_hw_stats *stats, |
| 5527 | u16 set_id) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5528 | { |
| 5529 | int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); |
| 5530 | void *out; |
| 5531 | __be32 val; |
| 5532 | int ret, i; |
| 5533 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5534 | out = kvzalloc(outlen, GFP_KERNEL); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5535 | if (!out) |
| 5536 | return -ENOMEM; |
| 5537 | |
Mark Zhang | 318d535 | 2019-07-02 13:02:37 +0300 | [diff] [blame] | 5538 | ret = mlx5_core_query_q_counter(mdev, set_id, 0, out, outlen); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5539 | if (ret) |
| 5540 | goto free; |
| 5541 | |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5542 | for (i = 0; i < cnts->num_q_counters; i++) { |
| 5543 | val = *(__be32 *)(out + cnts->offsets[i]); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5544 | stats->value[i] = (u64)be32_to_cpu(val); |
| 5545 | } |
| 5546 | |
| 5547 | free: |
| 5548 | kvfree(out); |
| 5549 | return ret; |
| 5550 | } |
| 5551 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5552 | static int mlx5_ib_query_ext_ppcnt_counters(struct mlx5_ib_dev *dev, |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5553 | const struct mlx5_ib_counters *cnts, |
| 5554 | struct rdma_hw_stats *stats) |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5555 | { |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5556 | int offset = cnts->num_q_counters + cnts->num_cong_counters; |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5557 | int sz = MLX5_ST_SZ_BYTES(ppcnt_reg); |
| 5558 | int ret, i; |
| 5559 | void *out; |
| 5560 | |
| 5561 | out = kvzalloc(sz, GFP_KERNEL); |
| 5562 | if (!out) |
| 5563 | return -ENOMEM; |
| 5564 | |
| 5565 | ret = mlx5_cmd_query_ext_ppcnt_counters(dev->mdev, out); |
| 5566 | if (ret) |
| 5567 | goto free; |
| 5568 | |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5569 | for (i = 0; i < cnts->num_ext_ppcnt_counters; i++) |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5570 | stats->value[i + offset] = |
| 5571 | be64_to_cpup((__be64 *)(out + |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5572 | cnts->offsets[i + offset])); |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5573 | free: |
| 5574 | kvfree(out); |
| 5575 | return ret; |
| 5576 | } |
| 5577 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5578 | static int mlx5_ib_get_hw_stats(struct ib_device *ibdev, |
| 5579 | struct rdma_hw_stats *stats, |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5580 | u8 port_num, int index) |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5581 | { |
| 5582 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5583 | const struct mlx5_ib_counters *cnts = get_counters(dev, port_num - 1); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5584 | struct mlx5_core_dev *mdev; |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5585 | int ret, num_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5586 | u8 mdev_port_num; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5587 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5588 | if (!stats) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5589 | return -EINVAL; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5590 | |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5591 | num_counters = cnts->num_q_counters + |
| 5592 | cnts->num_cong_counters + |
| 5593 | cnts->num_ext_ppcnt_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5594 | |
| 5595 | /* q_counters are per IB device, query the master mdev */ |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5596 | ret = mlx5_ib_query_q_counters(dev->mdev, cnts, stats, cnts->set_id); |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5597 | if (ret) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5598 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5599 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5600 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5601 | ret = mlx5_ib_query_ext_ppcnt_counters(dev, cnts, stats); |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5602 | if (ret) |
| 5603 | return ret; |
| 5604 | } |
| 5605 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5606 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5607 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, |
| 5608 | &mdev_port_num); |
| 5609 | if (!mdev) { |
| 5610 | /* If port is not affiliated yet, its in down state |
| 5611 | * which doesn't have any counters yet, so it would be |
| 5612 | * zero. So no need to read from the HCA. |
| 5613 | */ |
| 5614 | goto done; |
| 5615 | } |
Majd Dibbiny | 71a0ff6 | 2017-12-21 17:38:26 +0200 | [diff] [blame] | 5616 | ret = mlx5_lag_query_cong_counters(dev->mdev, |
| 5617 | stats->value + |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5618 | cnts->num_q_counters, |
| 5619 | cnts->num_cong_counters, |
| 5620 | cnts->offsets + |
| 5621 | cnts->num_q_counters); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5622 | |
| 5623 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5624 | if (ret) |
| 5625 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5626 | } |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5627 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5628 | done: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5629 | return num_counters; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5630 | } |
| 5631 | |
Mark Zhang | 18d422c | 2019-07-02 13:02:41 +0300 | [diff] [blame] | 5632 | static struct rdma_hw_stats * |
| 5633 | mlx5_ib_counter_alloc_stats(struct rdma_counter *counter) |
| 5634 | { |
| 5635 | struct mlx5_ib_dev *dev = to_mdev(counter->device); |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5636 | const struct mlx5_ib_counters *cnts = |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5637 | get_counters(dev, counter->port - 1); |
Mark Zhang | 18d422c | 2019-07-02 13:02:41 +0300 | [diff] [blame] | 5638 | |
| 5639 | /* Q counters are in the beginning of all counters */ |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5640 | return rdma_alloc_hw_stats_struct(cnts->names, |
| 5641 | cnts->num_q_counters, |
Mark Zhang | 18d422c | 2019-07-02 13:02:41 +0300 | [diff] [blame] | 5642 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 5643 | } |
| 5644 | |
| 5645 | static int mlx5_ib_counter_update_stats(struct rdma_counter *counter) |
| 5646 | { |
| 5647 | struct mlx5_ib_dev *dev = to_mdev(counter->device); |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5648 | const struct mlx5_ib_counters *cnts = |
| 5649 | get_counters(dev, counter->port - 1); |
Mark Zhang | 18d422c | 2019-07-02 13:02:41 +0300 | [diff] [blame] | 5650 | |
Parav Pandit | 5dcecbc | 2019-07-23 10:31:16 +0300 | [diff] [blame] | 5651 | return mlx5_ib_query_q_counters(dev->mdev, cnts, |
Mark Zhang | 18d422c | 2019-07-02 13:02:41 +0300 | [diff] [blame] | 5652 | counter->stats, counter->id); |
| 5653 | } |
| 5654 | |
Mark Zhang | 45842fc | 2019-07-02 13:02:38 +0300 | [diff] [blame] | 5655 | static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter, |
| 5656 | struct ib_qp *qp) |
| 5657 | { |
| 5658 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 5659 | u16 cnt_set_id = 0; |
| 5660 | int err; |
| 5661 | |
| 5662 | if (!counter->id) { |
| 5663 | err = mlx5_cmd_alloc_q_counter(dev->mdev, |
| 5664 | &cnt_set_id, |
| 5665 | MLX5_SHARED_RESOURCE_UID); |
| 5666 | if (err) |
| 5667 | return err; |
| 5668 | counter->id = cnt_set_id; |
| 5669 | } |
| 5670 | |
| 5671 | err = mlx5_ib_qp_set_counter(qp, counter); |
| 5672 | if (err) |
| 5673 | goto fail_set_counter; |
| 5674 | |
| 5675 | return 0; |
| 5676 | |
| 5677 | fail_set_counter: |
| 5678 | mlx5_core_dealloc_q_counter(dev->mdev, cnt_set_id); |
| 5679 | counter->id = 0; |
| 5680 | |
| 5681 | return err; |
| 5682 | } |
| 5683 | |
| 5684 | static int mlx5_ib_counter_unbind_qp(struct ib_qp *qp) |
| 5685 | { |
| 5686 | return mlx5_ib_qp_set_counter(qp, NULL); |
| 5687 | } |
| 5688 | |
| 5689 | static int mlx5_ib_counter_dealloc(struct rdma_counter *counter) |
| 5690 | { |
| 5691 | struct mlx5_ib_dev *dev = to_mdev(counter->device); |
| 5692 | |
| 5693 | return mlx5_core_dealloc_q_counter(dev->mdev, counter->id); |
| 5694 | } |
| 5695 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5696 | static int mlx5_ib_rn_get_params(struct ib_device *device, u8 port_num, |
| 5697 | enum rdma_netdev_t type, |
| 5698 | struct rdma_netdev_alloc_params *params) |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5699 | { |
| 5700 | if (type != RDMA_NETDEV_IPOIB) |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5701 | return -EOPNOTSUPP; |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5702 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5703 | return mlx5_rdma_rn_get_params(to_mdev(device)->mdev, device, params); |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5704 | } |
| 5705 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5706 | static void delay_drop_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 5707 | { |
| 5708 | if (!dev->delay_drop.dbg) |
| 5709 | return; |
| 5710 | debugfs_remove_recursive(dev->delay_drop.dbg->dir_debugfs); |
| 5711 | kfree(dev->delay_drop.dbg); |
| 5712 | dev->delay_drop.dbg = NULL; |
| 5713 | } |
| 5714 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5715 | static void cancel_delay_drop(struct mlx5_ib_dev *dev) |
| 5716 | { |
| 5717 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5718 | return; |
| 5719 | |
| 5720 | cancel_work_sync(&dev->delay_drop.delay_drop_work); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5721 | delay_drop_debugfs_cleanup(dev); |
| 5722 | } |
| 5723 | |
| 5724 | static ssize_t delay_drop_timeout_read(struct file *filp, char __user *buf, |
| 5725 | size_t count, loff_t *pos) |
| 5726 | { |
| 5727 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5728 | char lbuf[20]; |
| 5729 | int len; |
| 5730 | |
| 5731 | len = snprintf(lbuf, sizeof(lbuf), "%u\n", delay_drop->timeout); |
| 5732 | return simple_read_from_buffer(buf, count, pos, lbuf, len); |
| 5733 | } |
| 5734 | |
| 5735 | static ssize_t delay_drop_timeout_write(struct file *filp, const char __user *buf, |
| 5736 | size_t count, loff_t *pos) |
| 5737 | { |
| 5738 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5739 | u32 timeout; |
| 5740 | u32 var; |
| 5741 | |
| 5742 | if (kstrtouint_from_user(buf, count, 0, &var)) |
| 5743 | return -EFAULT; |
| 5744 | |
| 5745 | timeout = min_t(u32, roundup(var, 100), MLX5_MAX_DELAY_DROP_TIMEOUT_MS * |
| 5746 | 1000); |
| 5747 | if (timeout != var) |
| 5748 | mlx5_ib_dbg(delay_drop->dev, "Round delay drop timeout to %u usec\n", |
| 5749 | timeout); |
| 5750 | |
| 5751 | delay_drop->timeout = timeout; |
| 5752 | |
| 5753 | return count; |
| 5754 | } |
| 5755 | |
| 5756 | static const struct file_operations fops_delay_drop_timeout = { |
| 5757 | .owner = THIS_MODULE, |
| 5758 | .open = simple_open, |
| 5759 | .write = delay_drop_timeout_write, |
| 5760 | .read = delay_drop_timeout_read, |
| 5761 | }; |
| 5762 | |
| 5763 | static int delay_drop_debugfs_init(struct mlx5_ib_dev *dev) |
| 5764 | { |
| 5765 | struct mlx5_ib_dbg_delay_drop *dbg; |
| 5766 | |
| 5767 | if (!mlx5_debugfs_root) |
| 5768 | return 0; |
| 5769 | |
| 5770 | dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); |
| 5771 | if (!dbg) |
| 5772 | return -ENOMEM; |
| 5773 | |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5774 | dev->delay_drop.dbg = dbg; |
| 5775 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5776 | dbg->dir_debugfs = |
| 5777 | debugfs_create_dir("delay_drop", |
| 5778 | dev->mdev->priv.dbg_root); |
| 5779 | if (!dbg->dir_debugfs) |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5780 | goto out_debugfs; |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5781 | |
| 5782 | dbg->events_cnt_debugfs = |
| 5783 | debugfs_create_atomic_t("num_timeout_events", 0400, |
| 5784 | dbg->dir_debugfs, |
| 5785 | &dev->delay_drop.events_cnt); |
| 5786 | if (!dbg->events_cnt_debugfs) |
| 5787 | goto out_debugfs; |
| 5788 | |
| 5789 | dbg->rqs_cnt_debugfs = |
| 5790 | debugfs_create_atomic_t("num_rqs", 0400, |
| 5791 | dbg->dir_debugfs, |
| 5792 | &dev->delay_drop.rqs_cnt); |
| 5793 | if (!dbg->rqs_cnt_debugfs) |
| 5794 | goto out_debugfs; |
| 5795 | |
| 5796 | dbg->timeout_debugfs = |
| 5797 | debugfs_create_file("timeout", 0600, |
| 5798 | dbg->dir_debugfs, |
| 5799 | &dev->delay_drop, |
| 5800 | &fops_delay_drop_timeout); |
| 5801 | if (!dbg->timeout_debugfs) |
| 5802 | goto out_debugfs; |
| 5803 | |
| 5804 | return 0; |
| 5805 | |
| 5806 | out_debugfs: |
| 5807 | delay_drop_debugfs_cleanup(dev); |
| 5808 | return -ENOMEM; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | static void init_delay_drop(struct mlx5_ib_dev *dev) |
| 5812 | { |
| 5813 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5814 | return; |
| 5815 | |
| 5816 | mutex_init(&dev->delay_drop.lock); |
| 5817 | dev->delay_drop.dev = dev; |
| 5818 | dev->delay_drop.activate = false; |
| 5819 | dev->delay_drop.timeout = MLX5_MAX_DELAY_DROP_TIMEOUT_MS * 1000; |
| 5820 | INIT_WORK(&dev->delay_drop.delay_drop_work, delay_drop_handler); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5821 | atomic_set(&dev->delay_drop.rqs_cnt, 0); |
| 5822 | atomic_set(&dev->delay_drop.events_cnt, 0); |
| 5823 | |
| 5824 | if (delay_drop_debugfs_init(dev)) |
| 5825 | mlx5_ib_warn(dev, "Failed to init delay drop debugfs\n"); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5826 | } |
| 5827 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5828 | static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5829 | struct mlx5_ib_multiport_info *mpi) |
| 5830 | { |
| 5831 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5832 | struct mlx5_ib_port *port = &ibdev->port[port_num]; |
| 5833 | int comps; |
| 5834 | int err; |
| 5835 | int i; |
| 5836 | |
Leon Romanovsky | 9dc4cff | 2019-08-13 13:28:14 +0300 | [diff] [blame] | 5837 | lockdep_assert_held(&mlx5_ib_multiport_mutex); |
| 5838 | |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5839 | mlx5_ib_cleanup_cong_debugfs(ibdev, port_num); |
| 5840 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5841 | spin_lock(&port->mp.mpi_lock); |
| 5842 | if (!mpi->ibdev) { |
| 5843 | spin_unlock(&port->mp.mpi_lock); |
| 5844 | return; |
| 5845 | } |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5846 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5847 | mpi->ibdev = NULL; |
| 5848 | |
| 5849 | spin_unlock(&port->mp.mpi_lock); |
Leon Romanovsky | 23eaf3b | 2019-07-31 11:38:52 +0300 | [diff] [blame] | 5850 | if (mpi->mdev_events.notifier_call) |
| 5851 | mlx5_notifier_unregister(mpi->mdev, &mpi->mdev_events); |
| 5852 | mpi->mdev_events.notifier_call = NULL; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5853 | mlx5_remove_netdev_notifier(ibdev, port_num); |
| 5854 | spin_lock(&port->mp.mpi_lock); |
| 5855 | |
| 5856 | comps = mpi->mdev_refcnt; |
| 5857 | if (comps) { |
| 5858 | mpi->unaffiliate = true; |
| 5859 | init_completion(&mpi->unref_comp); |
| 5860 | spin_unlock(&port->mp.mpi_lock); |
| 5861 | |
| 5862 | for (i = 0; i < comps; i++) |
| 5863 | wait_for_completion(&mpi->unref_comp); |
| 5864 | |
| 5865 | spin_lock(&port->mp.mpi_lock); |
| 5866 | mpi->unaffiliate = false; |
| 5867 | } |
| 5868 | |
| 5869 | port->mp.mpi = NULL; |
| 5870 | |
| 5871 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 5872 | |
| 5873 | spin_unlock(&port->mp.mpi_lock); |
| 5874 | |
| 5875 | err = mlx5_nic_vport_unaffiliate_multiport(mpi->mdev); |
| 5876 | |
| 5877 | mlx5_ib_dbg(ibdev, "unaffiliated port %d\n", port_num + 1); |
| 5878 | /* Log an error, still needed to cleanup the pointers and add |
| 5879 | * it back to the list. |
| 5880 | */ |
| 5881 | if (err) |
| 5882 | mlx5_ib_err(ibdev, "Failed to unaffiliate port %u\n", |
| 5883 | port_num + 1); |
| 5884 | |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 5885 | ibdev->port[port_num].roce.last_port_state = IB_PORT_DOWN; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5886 | } |
| 5887 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5888 | static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5889 | struct mlx5_ib_multiport_info *mpi) |
| 5890 | { |
| 5891 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5892 | int err; |
| 5893 | |
Leon Romanovsky | 9dc4cff | 2019-08-13 13:28:14 +0300 | [diff] [blame] | 5894 | lockdep_assert_held(&mlx5_ib_multiport_mutex); |
| 5895 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5896 | spin_lock(&ibdev->port[port_num].mp.mpi_lock); |
| 5897 | if (ibdev->port[port_num].mp.mpi) { |
Qing Huang | 2577188 | 2018-07-23 14:15:08 -0700 | [diff] [blame] | 5898 | mlx5_ib_dbg(ibdev, "port %d already affiliated.\n", |
| 5899 | port_num + 1); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5900 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5901 | return false; |
| 5902 | } |
| 5903 | |
| 5904 | ibdev->port[port_num].mp.mpi = mpi; |
| 5905 | mpi->ibdev = ibdev; |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5906 | mpi->mdev_events.notifier_call = NULL; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5907 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5908 | |
| 5909 | err = mlx5_nic_vport_affiliate_multiport(ibdev->mdev, mpi->mdev); |
| 5910 | if (err) |
| 5911 | goto unbind; |
| 5912 | |
| 5913 | err = get_port_caps(ibdev, mlx5_core_native_port_num(mpi->mdev)); |
| 5914 | if (err) |
| 5915 | goto unbind; |
| 5916 | |
| 5917 | err = mlx5_add_netdev_notifier(ibdev, port_num); |
| 5918 | if (err) { |
| 5919 | mlx5_ib_err(ibdev, "failed adding netdev notifier for port %u\n", |
| 5920 | port_num + 1); |
| 5921 | goto unbind; |
| 5922 | } |
| 5923 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5924 | mpi->mdev_events.notifier_call = mlx5_ib_event_slave_port; |
| 5925 | mlx5_notifier_register(mpi->mdev, &mpi->mdev_events); |
| 5926 | |
Greg Kroah-Hartman | 73eb8f0 | 2019-01-22 16:17:57 +0100 | [diff] [blame] | 5927 | mlx5_ib_init_cong_debugfs(ibdev, port_num); |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5928 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5929 | return true; |
| 5930 | |
| 5931 | unbind: |
| 5932 | mlx5_ib_unbind_slave_port(ibdev, mpi); |
| 5933 | return false; |
| 5934 | } |
| 5935 | |
| 5936 | static int mlx5_ib_init_multiport_master(struct mlx5_ib_dev *dev) |
| 5937 | { |
| 5938 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5939 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5940 | port_num + 1); |
| 5941 | struct mlx5_ib_multiport_info *mpi; |
| 5942 | int err; |
| 5943 | int i; |
| 5944 | |
| 5945 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5946 | return 0; |
| 5947 | |
| 5948 | err = mlx5_query_nic_vport_system_image_guid(dev->mdev, |
| 5949 | &dev->sys_image_guid); |
| 5950 | if (err) |
| 5951 | return err; |
| 5952 | |
| 5953 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 5954 | if (err) |
| 5955 | return err; |
| 5956 | |
| 5957 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5958 | for (i = 0; i < dev->num_ports; i++) { |
| 5959 | bool bound = false; |
| 5960 | |
| 5961 | /* build a stub multiport info struct for the native port. */ |
| 5962 | if (i == port_num) { |
| 5963 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 5964 | if (!mpi) { |
| 5965 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5966 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5967 | return -ENOMEM; |
| 5968 | } |
| 5969 | |
| 5970 | mpi->is_master = true; |
| 5971 | mpi->mdev = dev->mdev; |
| 5972 | mpi->sys_image_guid = dev->sys_image_guid; |
| 5973 | dev->port[i].mp.mpi = mpi; |
| 5974 | mpi->ibdev = dev; |
| 5975 | mpi = NULL; |
| 5976 | continue; |
| 5977 | } |
| 5978 | |
| 5979 | list_for_each_entry(mpi, &mlx5_ib_unaffiliated_port_list, |
| 5980 | list) { |
| 5981 | if (dev->sys_image_guid == mpi->sys_image_guid && |
| 5982 | (mlx5_core_native_port_num(mpi->mdev) - 1) == i) { |
| 5983 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 5984 | } |
| 5985 | |
| 5986 | if (bound) { |
Vu Pham | c42260f1 | 2019-04-29 18:14:05 +0000 | [diff] [blame] | 5987 | dev_dbg(mpi->mdev->device, |
| 5988 | "removing port from unaffiliated list.\n"); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5989 | mlx5_ib_dbg(dev, "port %d bound\n", i + 1); |
| 5990 | list_del(&mpi->list); |
| 5991 | break; |
| 5992 | } |
| 5993 | } |
| 5994 | if (!bound) { |
| 5995 | get_port_caps(dev, i + 1); |
| 5996 | mlx5_ib_dbg(dev, "no free port found for port %d\n", |
| 5997 | i + 1); |
| 5998 | } |
| 5999 | } |
| 6000 | |
| 6001 | list_add_tail(&dev->ib_dev_list, &mlx5_ib_dev_list); |
| 6002 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6003 | return err; |
| 6004 | } |
| 6005 | |
| 6006 | static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev) |
| 6007 | { |
| 6008 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6009 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 6010 | port_num + 1); |
| 6011 | int i; |
| 6012 | |
| 6013 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 6014 | return; |
| 6015 | |
| 6016 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6017 | for (i = 0; i < dev->num_ports; i++) { |
| 6018 | if (dev->port[i].mp.mpi) { |
| 6019 | /* Destroy the native port stub */ |
| 6020 | if (i == port_num) { |
| 6021 | kfree(dev->port[i].mp.mpi); |
| 6022 | dev->port[i].mp.mpi = NULL; |
| 6023 | } else { |
| 6024 | mlx5_ib_dbg(dev, "unbinding port_num: %d\n", i + 1); |
| 6025 | mlx5_ib_unbind_slave_port(dev, dev->port[i].mp.mpi); |
| 6026 | } |
| 6027 | } |
| 6028 | } |
| 6029 | |
| 6030 | mlx5_ib_dbg(dev, "removing from devlist\n"); |
| 6031 | list_del(&dev->ib_dev_list); |
| 6032 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6033 | |
| 6034 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 6035 | } |
| 6036 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 6037 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 6038 | mlx5_ib_dm, |
| 6039 | UVERBS_OBJECT_DM, |
| 6040 | UVERBS_METHOD_DM_ALLOC, |
| 6041 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 6042 | UVERBS_ATTR_TYPE(u64), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 6043 | UA_MANDATORY), |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 6044 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 6045 | UVERBS_ATTR_TYPE(u16), |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 6046 | UA_OPTIONAL), |
| 6047 | UVERBS_ATTR_CONST_IN(MLX5_IB_ATTR_ALLOC_DM_REQ_TYPE, |
| 6048 | enum mlx5_ib_uapi_dm_type, |
| 6049 | UA_OPTIONAL)); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 6050 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 6051 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 6052 | mlx5_ib_flow_action, |
| 6053 | UVERBS_OBJECT_FLOW_ACTION, |
| 6054 | UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, |
Jason Gunthorpe | bccd062 | 2018-07-26 16:37:14 -0600 | [diff] [blame] | 6055 | UVERBS_ATTR_FLAGS_IN(MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 6056 | enum mlx5_ib_uapi_flow_action_flags)); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 6057 | |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 6058 | static const struct uapi_definition mlx5_ib_defs[] = { |
| 6059 | #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) |
Jason Gunthorpe | 36e235c | 2018-11-12 22:59:53 +0200 | [diff] [blame] | 6060 | UAPI_DEF_CHAIN(mlx5_ib_devx_defs), |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 6061 | UAPI_DEF_CHAIN(mlx5_ib_flow_defs), |
| 6062 | #endif |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 6063 | |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 6064 | UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_FLOW_ACTION, |
| 6065 | &mlx5_ib_flow_action), |
| 6066 | UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_DM, &mlx5_ib_dm), |
| 6067 | {} |
| 6068 | }; |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 6069 | |
Raed Salem | 1a1e03d | 2018-05-31 16:43:41 +0300 | [diff] [blame] | 6070 | static int mlx5_ib_read_counters(struct ib_counters *counters, |
| 6071 | struct ib_counters_read_attr *read_attr, |
| 6072 | struct uverbs_attr_bundle *attrs) |
| 6073 | { |
| 6074 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 6075 | struct mlx5_read_counters_attr mread_attr = {}; |
| 6076 | struct mlx5_ib_flow_counters_desc *desc; |
| 6077 | int ret, i; |
| 6078 | |
| 6079 | mutex_lock(&mcounters->mcntrs_mutex); |
| 6080 | if (mcounters->cntrs_max_index > read_attr->ncounters) { |
| 6081 | ret = -EINVAL; |
| 6082 | goto err_bound; |
| 6083 | } |
| 6084 | |
| 6085 | mread_attr.out = kcalloc(mcounters->counters_num, sizeof(u64), |
| 6086 | GFP_KERNEL); |
| 6087 | if (!mread_attr.out) { |
| 6088 | ret = -ENOMEM; |
| 6089 | goto err_bound; |
| 6090 | } |
| 6091 | |
| 6092 | mread_attr.hw_cntrs_hndl = mcounters->hw_cntrs_hndl; |
| 6093 | mread_attr.flags = read_attr->flags; |
| 6094 | ret = mcounters->read_counters(counters->device, &mread_attr); |
| 6095 | if (ret) |
| 6096 | goto err_read; |
| 6097 | |
| 6098 | /* do the pass over the counters data array to assign according to the |
| 6099 | * descriptions and indexing pairs |
| 6100 | */ |
| 6101 | desc = mcounters->counters_data; |
| 6102 | for (i = 0; i < mcounters->ncounters; i++) |
| 6103 | read_attr->counters_buff[desc[i].index] += mread_attr.out[desc[i].description]; |
| 6104 | |
| 6105 | err_read: |
| 6106 | kfree(mread_attr.out); |
| 6107 | err_bound: |
| 6108 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 6109 | return ret; |
| 6110 | } |
| 6111 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 6112 | static int mlx5_ib_destroy_counters(struct ib_counters *counters) |
| 6113 | { |
| 6114 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 6115 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 6116 | counters_clear_description(counters); |
| 6117 | if (mcounters->hw_cntrs_hndl) |
| 6118 | mlx5_fc_destroy(to_mdev(counters->device)->mdev, |
| 6119 | mcounters->hw_cntrs_hndl); |
| 6120 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 6121 | kfree(mcounters); |
| 6122 | |
| 6123 | return 0; |
| 6124 | } |
| 6125 | |
| 6126 | static struct ib_counters *mlx5_ib_create_counters(struct ib_device *device, |
| 6127 | struct uverbs_attr_bundle *attrs) |
| 6128 | { |
| 6129 | struct mlx5_ib_mcounters *mcounters; |
| 6130 | |
| 6131 | mcounters = kzalloc(sizeof(*mcounters), GFP_KERNEL); |
| 6132 | if (!mcounters) |
| 6133 | return ERR_PTR(-ENOMEM); |
| 6134 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 6135 | mutex_init(&mcounters->mcntrs_mutex); |
| 6136 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 6137 | return &mcounters->ibcntrs; |
| 6138 | } |
| 6139 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6140 | static void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6141 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6142 | mlx5_ib_cleanup_multiport_master(dev); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 6143 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
Yishai Hadas | 534fd7a | 2019-01-13 16:01:17 +0200 | [diff] [blame] | 6144 | srcu_barrier(&dev->mr_srcu); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 6145 | cleanup_srcu_struct(&dev->mr_srcu); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 6146 | } |
Ariel Levkovich | 4056b12 | 2019-05-05 17:07:12 +0300 | [diff] [blame] | 6147 | |
| 6148 | WARN_ON(!bitmap_empty(dev->dm.memic_alloc_pages, MLX5_MAX_MEMIC_PAGES)); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6149 | } |
| 6150 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6151 | static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6152 | { |
| 6153 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6154 | int err; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6155 | int i; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6156 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6157 | for (i = 0; i < dev->num_ports; i++) { |
| 6158 | spin_lock_init(&dev->port[i].mp.mpi_lock); |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 6159 | rwlock_init(&dev->port[i].roce.netdev_lock); |
Mark Bloch | d3b5cc1 | 2019-03-28 15:46:26 +0200 | [diff] [blame] | 6160 | dev->port[i].roce.dev = dev; |
| 6161 | dev->port[i].roce.native_port_num = i + 1; |
| 6162 | dev->port[i].roce.last_port_state = IB_PORT_DOWN; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6163 | } |
| 6164 | |
Moni Shoua | 0081575 | 2019-08-15 11:38:32 +0300 | [diff] [blame] | 6165 | mlx5_ib_internal_fill_odp_caps(dev); |
| 6166 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6167 | err = mlx5_ib_init_multiport_master(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6168 | if (err) |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6169 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6170 | |
Mark Bloch | a989ea0 | 2019-03-28 15:27:40 +0200 | [diff] [blame] | 6171 | err = set_has_smi_cap(dev); |
| 6172 | if (err) |
| 6173 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6174 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6175 | if (!mlx5_core_mp_enabled(mdev)) { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6176 | for (i = 1; i <= dev->num_ports; i++) { |
| 6177 | err = get_port_caps(dev, i); |
| 6178 | if (err) |
| 6179 | break; |
| 6180 | } |
| 6181 | } else { |
| 6182 | err = get_port_caps(dev, mlx5_core_native_port_num(mdev)); |
| 6183 | } |
| 6184 | if (err) |
| 6185 | goto err_mp; |
| 6186 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 6187 | if (mlx5_use_mad_ifc(dev)) |
| 6188 | get_ext_port_caps(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6189 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6190 | dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Sagi Grimberg | c6790aa | 2015-09-24 10:34:23 +0300 | [diff] [blame] | 6191 | dev->ib_dev.local_dma_lkey = 0 /* not supported for now */; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 6192 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
Saeed Mahameed | f2f3df5 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 6193 | dev->ib_dev.num_comp_vectors = mlx5_comp_vectors_count(mdev); |
Vu Pham | c42260f1 | 2019-04-29 18:14:05 +0000 | [diff] [blame] | 6194 | dev->ib_dev.dev.parent = mdev->device; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6195 | |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 6196 | mutex_init(&dev->cap_mask_mutex); |
| 6197 | INIT_LIST_HEAD(&dev->qp_list); |
| 6198 | spin_lock_init(&dev->reset_flow_resource_lock); |
| 6199 | |
Ariel Levkovich | 3b113a1 | 2019-05-05 17:07:11 +0300 | [diff] [blame] | 6200 | spin_lock_init(&dev->dm.lock); |
| 6201 | dev->dm.dev = mdev; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 6202 | |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 6203 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 6204 | err = init_srcu_struct(&dev->mr_srcu); |
Moni Shoua | a6bc387 | 2019-02-17 16:08:22 +0200 | [diff] [blame] | 6205 | if (err) |
Ariel Levkovich | c9b9dcb | 2019-08-29 23:42:30 +0000 | [diff] [blame] | 6206 | goto err_mp; |
Jason Gunthorpe | 623d154 | 2018-12-20 16:39:26 -0700 | [diff] [blame] | 6207 | } |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 6208 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6209 | return 0; |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 6210 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6211 | err_mp: |
| 6212 | mlx5_ib_cleanup_multiport_master(dev); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6213 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6214 | return -ENOMEM; |
| 6215 | } |
| 6216 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 6217 | static int mlx5_ib_stage_flow_db_init(struct mlx5_ib_dev *dev) |
| 6218 | { |
| 6219 | dev->flow_db = kzalloc(sizeof(*dev->flow_db), GFP_KERNEL); |
| 6220 | |
| 6221 | if (!dev->flow_db) |
| 6222 | return -ENOMEM; |
| 6223 | |
| 6224 | mutex_init(&dev->flow_db->lock); |
| 6225 | |
| 6226 | return 0; |
| 6227 | } |
| 6228 | |
| 6229 | static void mlx5_ib_stage_flow_db_cleanup(struct mlx5_ib_dev *dev) |
| 6230 | { |
| 6231 | kfree(dev->flow_db); |
| 6232 | } |
| 6233 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6234 | static const struct ib_device_ops mlx5_ib_dev_ops = { |
Jason Gunthorpe | 7a15414 | 2019-06-05 14:39:26 -0300 | [diff] [blame] | 6235 | .owner = THIS_MODULE, |
Jason Gunthorpe | b9560a4 | 2019-06-05 14:39:24 -0300 | [diff] [blame] | 6236 | .driver_id = RDMA_DRIVER_MLX5, |
Jason Gunthorpe | 72c6ec1 | 2019-06-05 14:39:25 -0300 | [diff] [blame] | 6237 | .uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION, |
Jason Gunthorpe | b9560a4 | 2019-06-05 14:39:24 -0300 | [diff] [blame] | 6238 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6239 | .add_gid = mlx5_ib_add_gid, |
| 6240 | .alloc_mr = mlx5_ib_alloc_mr, |
Max Gurtovoy | 6c98447 | 2019-06-11 18:52:42 +0300 | [diff] [blame] | 6241 | .alloc_mr_integrity = mlx5_ib_alloc_mr_integrity, |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6242 | .alloc_pd = mlx5_ib_alloc_pd, |
| 6243 | .alloc_ucontext = mlx5_ib_alloc_ucontext, |
| 6244 | .attach_mcast = mlx5_ib_mcg_attach, |
| 6245 | .check_mr_status = mlx5_ib_check_mr_status, |
| 6246 | .create_ah = mlx5_ib_create_ah, |
| 6247 | .create_counters = mlx5_ib_create_counters, |
| 6248 | .create_cq = mlx5_ib_create_cq, |
| 6249 | .create_flow = mlx5_ib_create_flow, |
| 6250 | .create_qp = mlx5_ib_create_qp, |
| 6251 | .create_srq = mlx5_ib_create_srq, |
| 6252 | .dealloc_pd = mlx5_ib_dealloc_pd, |
| 6253 | .dealloc_ucontext = mlx5_ib_dealloc_ucontext, |
| 6254 | .del_gid = mlx5_ib_del_gid, |
| 6255 | .dereg_mr = mlx5_ib_dereg_mr, |
| 6256 | .destroy_ah = mlx5_ib_destroy_ah, |
| 6257 | .destroy_counters = mlx5_ib_destroy_counters, |
| 6258 | .destroy_cq = mlx5_ib_destroy_cq, |
| 6259 | .destroy_flow = mlx5_ib_destroy_flow, |
| 6260 | .destroy_flow_action = mlx5_ib_destroy_flow_action, |
| 6261 | .destroy_qp = mlx5_ib_destroy_qp, |
| 6262 | .destroy_srq = mlx5_ib_destroy_srq, |
| 6263 | .detach_mcast = mlx5_ib_mcg_detach, |
| 6264 | .disassociate_ucontext = mlx5_ib_disassociate_ucontext, |
| 6265 | .drain_rq = mlx5_ib_drain_rq, |
| 6266 | .drain_sq = mlx5_ib_drain_sq, |
| 6267 | .get_dev_fw_str = get_dev_fw_str, |
| 6268 | .get_dma_mr = mlx5_ib_get_dma_mr, |
| 6269 | .get_link_layer = mlx5_ib_port_link_layer, |
| 6270 | .map_mr_sg = mlx5_ib_map_mr_sg, |
Max Gurtovoy | 6c98447 | 2019-06-11 18:52:42 +0300 | [diff] [blame] | 6271 | .map_mr_sg_pi = mlx5_ib_map_mr_sg_pi, |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6272 | .mmap = mlx5_ib_mmap, |
| 6273 | .modify_cq = mlx5_ib_modify_cq, |
| 6274 | .modify_device = mlx5_ib_modify_device, |
| 6275 | .modify_port = mlx5_ib_modify_port, |
| 6276 | .modify_qp = mlx5_ib_modify_qp, |
| 6277 | .modify_srq = mlx5_ib_modify_srq, |
| 6278 | .poll_cq = mlx5_ib_poll_cq, |
| 6279 | .post_recv = mlx5_ib_post_recv, |
| 6280 | .post_send = mlx5_ib_post_send, |
| 6281 | .post_srq_recv = mlx5_ib_post_srq_recv, |
| 6282 | .process_mad = mlx5_ib_process_mad, |
| 6283 | .query_ah = mlx5_ib_query_ah, |
| 6284 | .query_device = mlx5_ib_query_device, |
| 6285 | .query_gid = mlx5_ib_query_gid, |
| 6286 | .query_pkey = mlx5_ib_query_pkey, |
| 6287 | .query_qp = mlx5_ib_query_qp, |
| 6288 | .query_srq = mlx5_ib_query_srq, |
| 6289 | .read_counters = mlx5_ib_read_counters, |
| 6290 | .reg_user_mr = mlx5_ib_reg_user_mr, |
| 6291 | .req_notify_cq = mlx5_ib_arm_cq, |
| 6292 | .rereg_user_mr = mlx5_ib_rereg_user_mr, |
| 6293 | .resize_cq = mlx5_ib_resize_cq, |
Leon Romanovsky | d345691 | 2019-04-03 16:42:42 +0300 | [diff] [blame] | 6294 | |
| 6295 | INIT_RDMA_OBJ_SIZE(ib_ah, mlx5_ib_ah, ibah), |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 6296 | INIT_RDMA_OBJ_SIZE(ib_cq, mlx5_ib_cq, ibcq), |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 6297 | INIT_RDMA_OBJ_SIZE(ib_pd, mlx5_ib_pd, ibpd), |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 6298 | INIT_RDMA_OBJ_SIZE(ib_srq, mlx5_ib_srq, ibsrq), |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 6299 | INIT_RDMA_OBJ_SIZE(ib_ucontext, mlx5_ib_ucontext, ibucontext), |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6300 | }; |
| 6301 | |
| 6302 | static const struct ib_device_ops mlx5_ib_dev_flow_ipsec_ops = { |
| 6303 | .create_flow_action_esp = mlx5_ib_create_flow_action_esp, |
| 6304 | .modify_flow_action_esp = mlx5_ib_modify_flow_action_esp, |
| 6305 | }; |
| 6306 | |
| 6307 | static const struct ib_device_ops mlx5_ib_dev_ipoib_enhanced_ops = { |
| 6308 | .rdma_netdev_get_params = mlx5_ib_rn_get_params, |
| 6309 | }; |
| 6310 | |
| 6311 | static const struct ib_device_ops mlx5_ib_dev_sriov_ops = { |
| 6312 | .get_vf_config = mlx5_ib_get_vf_config, |
| 6313 | .get_vf_stats = mlx5_ib_get_vf_stats, |
| 6314 | .set_vf_guid = mlx5_ib_set_vf_guid, |
| 6315 | .set_vf_link_state = mlx5_ib_set_vf_link_state, |
| 6316 | }; |
| 6317 | |
| 6318 | static const struct ib_device_ops mlx5_ib_dev_mw_ops = { |
| 6319 | .alloc_mw = mlx5_ib_alloc_mw, |
| 6320 | .dealloc_mw = mlx5_ib_dealloc_mw, |
| 6321 | }; |
| 6322 | |
| 6323 | static const struct ib_device_ops mlx5_ib_dev_xrc_ops = { |
| 6324 | .alloc_xrcd = mlx5_ib_alloc_xrcd, |
| 6325 | .dealloc_xrcd = mlx5_ib_dealloc_xrcd, |
| 6326 | }; |
| 6327 | |
| 6328 | static const struct ib_device_ops mlx5_ib_dev_dm_ops = { |
| 6329 | .alloc_dm = mlx5_ib_alloc_dm, |
| 6330 | .dealloc_dm = mlx5_ib_dealloc_dm, |
| 6331 | .reg_dm_mr = mlx5_ib_reg_dm_mr, |
| 6332 | }; |
| 6333 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6334 | static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6335 | { |
| 6336 | struct mlx5_core_dev *mdev = dev->mdev; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6337 | int err; |
| 6338 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6339 | dev->ib_dev.uverbs_cmd_mask = |
| 6340 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 6341 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 6342 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 6343 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 6344 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
Moni Shoua | 41c450f | 2016-11-23 08:23:26 +0200 | [diff] [blame] | 6345 | (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
| 6346 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6347 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 6348 | (1ull << IB_USER_VERBS_CMD_REREG_MR) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6349 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 6350 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 6351 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 6352 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 6353 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 6354 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 6355 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 6356 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 6357 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 6358 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 6359 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 6360 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 6361 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 6362 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 6363 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 6364 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 6365 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Haggai Eran | 1707cb4 | 2015-02-08 13:28:52 +0200 | [diff] [blame] | 6366 | dev->ib_dev.uverbs_ex_cmd_mask = |
Matan Barak | d4584dd | 2016-01-28 17:51:46 +0200 | [diff] [blame] | 6367 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE) | |
| 6368 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 6369 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) | |
Yonatan Cohen | b0e9df6 | 2017-11-13 10:51:15 +0200 | [diff] [blame] | 6370 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_QP) | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6371 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_CQ) | |
| 6372 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) | |
| 6373 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6374 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 6375 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
| 6376 | IS_ENABLED(CONFIG_MLX5_CORE_IPOIB)) |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6377 | ib_set_device_ops(&dev->ib_dev, |
| 6378 | &mlx5_ib_dev_ipoib_enhanced_ops); |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 6379 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6380 | if (mlx5_core_is_pf(mdev)) |
| 6381 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_sriov_ops); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 6382 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 6383 | dev->umr_fence = mlx5_get_umr_fence(MLX5_CAP_GEN(mdev, umr_fence)); |
| 6384 | |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6385 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6386 | dev->ib_dev.uverbs_cmd_mask |= |
| 6387 | (1ull << IB_USER_VERBS_CMD_ALLOC_MW) | |
| 6388 | (1ull << IB_USER_VERBS_CMD_DEALLOC_MW); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6389 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_mw_ops); |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6390 | } |
| 6391 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 6392 | if (MLX5_CAP_GEN(mdev, xrc)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6393 | dev->ib_dev.uverbs_cmd_mask |= |
| 6394 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 6395 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6396 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_xrc_ops); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6397 | } |
| 6398 | |
Ariel Levkovich | 25c1332 | 2019-05-05 17:07:13 +0300 | [diff] [blame] | 6399 | if (MLX5_CAP_DEV_MEM(mdev, memic) || |
| 6400 | MLX5_CAP_GEN_64(dev->mdev, general_obj_types) & |
| 6401 | MLX5_GENERAL_OBJ_TYPES_CAP_SW_ICM) |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6402 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_dm_ops); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 6403 | |
Jason Gunthorpe | dfb631a | 2018-11-12 22:59:49 +0200 | [diff] [blame] | 6404 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6405 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 6406 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_flow_ipsec_ops); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6407 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_ops); |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 6408 | |
Jason Gunthorpe | 36e235c | 2018-11-12 22:59:53 +0200 | [diff] [blame] | 6409 | if (IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)) |
| 6410 | dev->ib_dev.driver_def = mlx5_ib_defs; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6411 | |
| 6412 | err = init_node_data(dev); |
| 6413 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6414 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6415 | |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 6416 | 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] | 6417 | (MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) || |
| 6418 | MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 6419 | mutex_init(&dev->lb.mutex); |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 6420 | |
Leon Romanovsky | 96e2fd7 | 2019-07-08 13:59:05 +0300 | [diff] [blame] | 6421 | dev->ib_dev.use_cq_dim = true; |
| 6422 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6423 | return 0; |
| 6424 | } |
| 6425 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6426 | static const struct ib_device_ops mlx5_ib_dev_port_ops = { |
| 6427 | .get_port_immutable = mlx5_port_immutable, |
| 6428 | .query_port = mlx5_ib_query_port, |
| 6429 | }; |
| 6430 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6431 | static int mlx5_ib_stage_non_default_cb(struct mlx5_ib_dev *dev) |
| 6432 | { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6433 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_port_ops); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6434 | return 0; |
| 6435 | } |
| 6436 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6437 | static const struct ib_device_ops mlx5_ib_dev_port_rep_ops = { |
| 6438 | .get_port_immutable = mlx5_port_rep_immutable, |
| 6439 | .query_port = mlx5_ib_rep_query_port, |
| 6440 | }; |
| 6441 | |
Michael Guralnik | b5a498b | 2019-11-08 23:45:26 +0000 | [diff] [blame] | 6442 | static int mlx5_ib_stage_raw_eth_non_default_cb(struct mlx5_ib_dev *dev) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6443 | { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6444 | 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] | 6445 | return 0; |
| 6446 | } |
| 6447 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6448 | static const struct ib_device_ops mlx5_ib_dev_common_roce_ops = { |
| 6449 | .create_rwq_ind_table = mlx5_ib_create_rwq_ind_table, |
| 6450 | .create_wq = mlx5_ib_create_wq, |
| 6451 | .destroy_rwq_ind_table = mlx5_ib_destroy_rwq_ind_table, |
| 6452 | .destroy_wq = mlx5_ib_destroy_wq, |
| 6453 | .get_netdev = mlx5_ib_get_netdev, |
| 6454 | .modify_wq = mlx5_ib_modify_wq, |
| 6455 | }; |
| 6456 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6457 | 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] | 6458 | { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6459 | u8 port_num; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6460 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6461 | dev->ib_dev.uverbs_ex_cmd_mask |= |
| 6462 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_WQ) | |
| 6463 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_WQ) | |
| 6464 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_WQ) | |
| 6465 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) | |
| 6466 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6467 | 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] | 6468 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6469 | port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6470 | |
Mark Bloch | 26628e2 | 2019-03-28 15:27:41 +0200 | [diff] [blame] | 6471 | /* Register only for native ports */ |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6472 | return mlx5_add_netdev_notifier(dev, port_num); |
| 6473 | } |
| 6474 | |
| 6475 | static void mlx5_ib_stage_common_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6476 | { |
| 6477 | u8 port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6478 | |
| 6479 | mlx5_remove_netdev_notifier(dev, port_num); |
| 6480 | } |
| 6481 | |
Michael Guralnik | b5a498b | 2019-11-08 23:45:26 +0000 | [diff] [blame] | 6482 | static int mlx5_ib_stage_raw_eth_roce_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6483 | { |
| 6484 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6485 | enum rdma_link_layer ll; |
| 6486 | int port_type_cap; |
| 6487 | int err = 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6488 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6489 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6490 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6491 | |
| 6492 | if (ll == IB_LINK_LAYER_ETHERNET) |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6493 | err = mlx5_ib_stage_common_roce_init(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6494 | |
| 6495 | return err; |
| 6496 | } |
| 6497 | |
Michael Guralnik | b5a498b | 2019-11-08 23:45:26 +0000 | [diff] [blame] | 6498 | static void mlx5_ib_stage_raw_eth_roce_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6499 | { |
| 6500 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 6501 | } |
| 6502 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6503 | static int mlx5_ib_stage_roce_init(struct mlx5_ib_dev *dev) |
| 6504 | { |
| 6505 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6506 | enum rdma_link_layer ll; |
| 6507 | int port_type_cap; |
| 6508 | int err; |
| 6509 | |
| 6510 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6511 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6512 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6513 | if (ll == IB_LINK_LAYER_ETHERNET) { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6514 | err = mlx5_ib_stage_common_roce_init(dev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6515 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6516 | return err; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6517 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6518 | err = mlx5_enable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6519 | if (err) |
| 6520 | goto cleanup; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6521 | } |
| 6522 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6523 | return 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6524 | cleanup: |
| 6525 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 6526 | |
| 6527 | return err; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6528 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6529 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6530 | static void mlx5_ib_stage_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6531 | { |
| 6532 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6533 | enum rdma_link_layer ll; |
| 6534 | int port_type_cap; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6535 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6536 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6537 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6538 | |
| 6539 | if (ll == IB_LINK_LAYER_ETHERNET) { |
| 6540 | mlx5_disable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6541 | mlx5_ib_stage_common_roce_cleanup(dev); |
Kamal Heib | 45bded2 | 2017-01-18 14:10:32 +0200 | [diff] [blame] | 6542 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6543 | } |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6544 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6545 | static int mlx5_ib_stage_dev_res_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6546 | { |
| 6547 | return create_dev_resources(&dev->devr); |
| 6548 | } |
Parav Pandit | 4a2da0b | 2017-05-30 10:05:15 +0300 | [diff] [blame] | 6549 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6550 | static void mlx5_ib_stage_dev_res_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6551 | { |
| 6552 | destroy_dev_resources(&dev->devr); |
| 6553 | } |
| 6554 | |
| 6555 | static int mlx5_ib_stage_odp_init(struct mlx5_ib_dev *dev) |
| 6556 | { |
| 6557 | return mlx5_ib_odp_init_one(dev); |
| 6558 | } |
| 6559 | |
Kamal Heib | f3ffed0 | 2019-01-30 16:13:42 +0200 | [diff] [blame] | 6560 | static void mlx5_ib_stage_odp_cleanup(struct mlx5_ib_dev *dev) |
Saeed Mahameed | d5d284b | 2018-11-19 10:52:41 -0800 | [diff] [blame] | 6561 | { |
| 6562 | mlx5_ib_odp_cleanup_one(dev); |
| 6563 | } |
| 6564 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6565 | static const struct ib_device_ops mlx5_ib_dev_hw_stats_ops = { |
| 6566 | .alloc_hw_stats = mlx5_ib_alloc_hw_stats, |
| 6567 | .get_hw_stats = mlx5_ib_get_hw_stats, |
Mark Zhang | 45842fc | 2019-07-02 13:02:38 +0300 | [diff] [blame] | 6568 | .counter_bind_qp = mlx5_ib_counter_bind_qp, |
| 6569 | .counter_unbind_qp = mlx5_ib_counter_unbind_qp, |
| 6570 | .counter_dealloc = mlx5_ib_counter_dealloc, |
Mark Zhang | 18d422c | 2019-07-02 13:02:41 +0300 | [diff] [blame] | 6571 | .counter_alloc_stats = mlx5_ib_counter_alloc_stats, |
| 6572 | .counter_update_stats = mlx5_ib_counter_update_stats, |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6573 | }; |
| 6574 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6575 | static int mlx5_ib_stage_counters_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6576 | { |
Mark Bloch | 5e1e761 | 2018-01-01 13:07:01 +0200 | [diff] [blame] | 6577 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6578 | 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] | 6579 | |
| 6580 | return mlx5_ib_alloc_counters(dev); |
| 6581 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6582 | |
| 6583 | return 0; |
| 6584 | } |
| 6585 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6586 | static void mlx5_ib_stage_counters_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6587 | { |
| 6588 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) |
| 6589 | mlx5_ib_dealloc_counters(dev); |
| 6590 | } |
| 6591 | |
| 6592 | static int mlx5_ib_stage_cong_debugfs_init(struct mlx5_ib_dev *dev) |
| 6593 | { |
Greg Kroah-Hartman | 73eb8f0 | 2019-01-22 16:17:57 +0100 | [diff] [blame] | 6594 | mlx5_ib_init_cong_debugfs(dev, |
| 6595 | mlx5_core_native_port_num(dev->mdev) - 1); |
| 6596 | return 0; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6597 | } |
| 6598 | |
| 6599 | static void mlx5_ib_stage_cong_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 6600 | { |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 6601 | mlx5_ib_cleanup_cong_debugfs(dev, |
| 6602 | mlx5_core_native_port_num(dev->mdev) - 1); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6603 | } |
| 6604 | |
| 6605 | static int mlx5_ib_stage_uar_init(struct mlx5_ib_dev *dev) |
| 6606 | { |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6607 | dev->mdev->priv.uar = mlx5_get_uars_page(dev->mdev); |
Leon Romanovsky | 444261c | 2018-04-23 17:01:56 +0300 | [diff] [blame] | 6608 | return PTR_ERR_OR_ZERO(dev->mdev->priv.uar); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6609 | } |
| 6610 | |
| 6611 | static void mlx5_ib_stage_uar_cleanup(struct mlx5_ib_dev *dev) |
| 6612 | { |
| 6613 | mlx5_put_uars_page(dev->mdev, dev->mdev->priv.uar); |
| 6614 | } |
| 6615 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6616 | static int mlx5_ib_stage_bfrag_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6617 | { |
| 6618 | int err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6619 | |
| 6620 | err = mlx5_alloc_bfreg(dev->mdev, &dev->bfreg, false, false); |
| 6621 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6622 | return err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6623 | |
| 6624 | err = mlx5_alloc_bfreg(dev->mdev, &dev->fp_bfreg, false, true); |
| 6625 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6626 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6627 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6628 | return err; |
| 6629 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 6630 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6631 | static void mlx5_ib_stage_bfrag_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6632 | { |
| 6633 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
| 6634 | mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
| 6635 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6636 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6637 | static int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6638 | { |
Jason Gunthorpe | e349f85 | 2018-09-25 16:58:09 -0600 | [diff] [blame] | 6639 | const char *name; |
| 6640 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 6641 | rdma_set_device_sysfs_group(&dev->ib_dev, &mlx5_attr_group); |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 6642 | if (!mlx5_lag_is_roce(dev->mdev)) |
Jason Gunthorpe | e349f85 | 2018-09-25 16:58:09 -0600 | [diff] [blame] | 6643 | name = "mlx5_%d"; |
| 6644 | else |
| 6645 | name = "mlx5_bond_%d"; |
Parav Pandit | ea4baf7 | 2018-12-18 14:28:30 +0200 | [diff] [blame] | 6646 | return ib_register_device(&dev->ib_dev, name); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6647 | } |
| 6648 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6649 | static void mlx5_ib_stage_pre_ib_reg_umr_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6650 | { |
| 6651 | destroy_umrc_res(dev); |
| 6652 | } |
| 6653 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6654 | static void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6655 | { |
| 6656 | ib_unregister_device(&dev->ib_dev); |
| 6657 | } |
| 6658 | |
Mark Bloch | fb652d3 | 2019-03-28 15:27:42 +0200 | [diff] [blame] | 6659 | static int mlx5_ib_stage_post_ib_reg_umr_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6660 | { |
| 6661 | return create_umr_res(dev); |
| 6662 | } |
| 6663 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6664 | static int mlx5_ib_stage_delay_drop_init(struct mlx5_ib_dev *dev) |
| 6665 | { |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6666 | init_delay_drop(dev); |
| 6667 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6668 | return 0; |
| 6669 | } |
| 6670 | |
| 6671 | static void mlx5_ib_stage_delay_drop_cleanup(struct mlx5_ib_dev *dev) |
| 6672 | { |
| 6673 | cancel_delay_drop(dev); |
| 6674 | } |
| 6675 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6676 | static int mlx5_ib_stage_dev_notifier_init(struct mlx5_ib_dev *dev) |
| 6677 | { |
| 6678 | dev->mdev_events.notifier_call = mlx5_ib_event; |
| 6679 | mlx5_notifier_register(dev->mdev, &dev->mdev_events); |
| 6680 | return 0; |
| 6681 | } |
| 6682 | |
| 6683 | static void mlx5_ib_stage_dev_notifier_cleanup(struct mlx5_ib_dev *dev) |
| 6684 | { |
| 6685 | mlx5_notifier_unregister(dev->mdev, &dev->mdev_events); |
| 6686 | } |
| 6687 | |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6688 | static int mlx5_ib_stage_devx_init(struct mlx5_ib_dev *dev) |
| 6689 | { |
| 6690 | int uid; |
| 6691 | |
Yishai Hadas | fb98153 | 2018-11-26 08:28:36 +0200 | [diff] [blame] | 6692 | uid = mlx5_ib_devx_create(dev, false); |
Yishai Hadas | e337dd5 | 2019-06-30 19:23:30 +0300 | [diff] [blame] | 6693 | if (uid > 0) { |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6694 | dev->devx_whitelist_uid = uid; |
Yishai Hadas | e337dd5 | 2019-06-30 19:23:30 +0300 | [diff] [blame] | 6695 | mlx5_ib_devx_init_event_table(dev); |
| 6696 | } |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6697 | |
| 6698 | return 0; |
| 6699 | } |
| 6700 | static void mlx5_ib_stage_devx_cleanup(struct mlx5_ib_dev *dev) |
| 6701 | { |
Yishai Hadas | e337dd5 | 2019-06-30 19:23:30 +0300 | [diff] [blame] | 6702 | if (dev->devx_whitelist_uid) { |
| 6703 | mlx5_ib_devx_cleanup_event_table(dev); |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6704 | mlx5_ib_devx_destroy(dev, dev->devx_whitelist_uid); |
Yishai Hadas | e337dd5 | 2019-06-30 19:23:30 +0300 | [diff] [blame] | 6705 | } |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6706 | } |
| 6707 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6708 | void __mlx5_ib_remove(struct mlx5_ib_dev *dev, |
| 6709 | const struct mlx5_ib_profile *profile, |
| 6710 | int stage) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6711 | { |
| 6712 | /* Number of stages to cleanup */ |
| 6713 | while (stage) { |
| 6714 | stage--; |
| 6715 | if (profile->stage[stage].cleanup) |
| 6716 | profile->stage[stage].cleanup(dev); |
| 6717 | } |
Mark Bloch | 4a6dc85 | 2019-03-28 15:27:34 +0200 | [diff] [blame] | 6718 | |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6719 | kfree(dev->port); |
Mark Bloch | 4a6dc85 | 2019-03-28 15:27:34 +0200 | [diff] [blame] | 6720 | ib_dealloc_device(&dev->ib_dev); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6721 | } |
| 6722 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6723 | void *__mlx5_ib_add(struct mlx5_ib_dev *dev, |
| 6724 | const struct mlx5_ib_profile *profile) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6725 | { |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6726 | int err; |
| 6727 | int i; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6728 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6729 | for (i = 0; i < MLX5_IB_STAGE_MAX; i++) { |
| 6730 | if (profile->stage[i].init) { |
| 6731 | err = profile->stage[i].init(dev); |
| 6732 | if (err) |
| 6733 | goto err_out; |
| 6734 | } |
| 6735 | } |
| 6736 | |
| 6737 | dev->profile = profile; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6738 | dev->ib_active = true; |
| 6739 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6740 | return dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6741 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6742 | err_out: |
| 6743 | __mlx5_ib_remove(dev, profile, i); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6744 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6745 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6746 | } |
| 6747 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6748 | static const struct mlx5_ib_profile pf_profile = { |
| 6749 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6750 | mlx5_ib_stage_init_init, |
| 6751 | mlx5_ib_stage_init_cleanup), |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 6752 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6753 | mlx5_ib_stage_flow_db_init, |
| 6754 | mlx5_ib_stage_flow_db_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6755 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6756 | mlx5_ib_stage_caps_init, |
| 6757 | NULL), |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6758 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6759 | mlx5_ib_stage_non_default_cb, |
| 6760 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6761 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6762 | mlx5_ib_stage_roce_init, |
| 6763 | mlx5_ib_stage_roce_cleanup), |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 6764 | STAGE_CREATE(MLX5_IB_STAGE_SRQ, |
| 6765 | mlx5_init_srq_table, |
| 6766 | mlx5_cleanup_srq_table), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6767 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6768 | mlx5_ib_stage_dev_res_init, |
| 6769 | mlx5_ib_stage_dev_res_cleanup), |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6770 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER, |
| 6771 | mlx5_ib_stage_dev_notifier_init, |
| 6772 | mlx5_ib_stage_dev_notifier_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6773 | STAGE_CREATE(MLX5_IB_STAGE_ODP, |
| 6774 | mlx5_ib_stage_odp_init, |
Saeed Mahameed | d5d284b | 2018-11-19 10:52:41 -0800 | [diff] [blame] | 6775 | mlx5_ib_stage_odp_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6776 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6777 | mlx5_ib_stage_counters_init, |
| 6778 | mlx5_ib_stage_counters_cleanup), |
| 6779 | STAGE_CREATE(MLX5_IB_STAGE_CONG_DEBUGFS, |
| 6780 | mlx5_ib_stage_cong_debugfs_init, |
| 6781 | mlx5_ib_stage_cong_debugfs_cleanup), |
| 6782 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6783 | mlx5_ib_stage_uar_init, |
| 6784 | mlx5_ib_stage_uar_cleanup), |
| 6785 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6786 | mlx5_ib_stage_bfrag_init, |
| 6787 | mlx5_ib_stage_bfrag_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6788 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6789 | NULL, |
| 6790 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6791 | STAGE_CREATE(MLX5_IB_STAGE_WHITELIST_UID, |
| 6792 | mlx5_ib_stage_devx_init, |
| 6793 | mlx5_ib_stage_devx_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6794 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6795 | mlx5_ib_stage_ib_reg_init, |
| 6796 | mlx5_ib_stage_ib_reg_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6797 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6798 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6799 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6800 | STAGE_CREATE(MLX5_IB_STAGE_DELAY_DROP, |
| 6801 | mlx5_ib_stage_delay_drop_init, |
| 6802 | mlx5_ib_stage_delay_drop_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6803 | }; |
| 6804 | |
Michael Guralnik | b5a498b | 2019-11-08 23:45:26 +0000 | [diff] [blame] | 6805 | const struct mlx5_ib_profile raw_eth_profile = { |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6806 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6807 | mlx5_ib_stage_init_init, |
| 6808 | mlx5_ib_stage_init_cleanup), |
| 6809 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6810 | mlx5_ib_stage_flow_db_init, |
| 6811 | mlx5_ib_stage_flow_db_cleanup), |
| 6812 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6813 | mlx5_ib_stage_caps_init, |
| 6814 | NULL), |
| 6815 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
Michael Guralnik | b5a498b | 2019-11-08 23:45:26 +0000 | [diff] [blame] | 6816 | mlx5_ib_stage_raw_eth_non_default_cb, |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6817 | NULL), |
| 6818 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
Michael Guralnik | b5a498b | 2019-11-08 23:45:26 +0000 | [diff] [blame] | 6819 | mlx5_ib_stage_raw_eth_roce_init, |
| 6820 | mlx5_ib_stage_raw_eth_roce_cleanup), |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 6821 | STAGE_CREATE(MLX5_IB_STAGE_SRQ, |
| 6822 | mlx5_init_srq_table, |
| 6823 | mlx5_cleanup_srq_table), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6824 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6825 | mlx5_ib_stage_dev_res_init, |
| 6826 | mlx5_ib_stage_dev_res_cleanup), |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6827 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER, |
| 6828 | mlx5_ib_stage_dev_notifier_init, |
| 6829 | mlx5_ib_stage_dev_notifier_cleanup), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6830 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6831 | mlx5_ib_stage_counters_init, |
| 6832 | mlx5_ib_stage_counters_cleanup), |
| 6833 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6834 | mlx5_ib_stage_uar_init, |
| 6835 | mlx5_ib_stage_uar_cleanup), |
| 6836 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6837 | mlx5_ib_stage_bfrag_init, |
| 6838 | mlx5_ib_stage_bfrag_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6839 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6840 | NULL, |
| 6841 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Mark Bloch | 7f57510 | 2019-03-28 15:46:25 +0200 | [diff] [blame] | 6842 | STAGE_CREATE(MLX5_IB_STAGE_WHITELIST_UID, |
| 6843 | mlx5_ib_stage_devx_init, |
| 6844 | mlx5_ib_stage_devx_cleanup), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6845 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6846 | mlx5_ib_stage_ib_reg_init, |
| 6847 | mlx5_ib_stage_ib_reg_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6848 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6849 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6850 | NULL), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6851 | }; |
| 6852 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6853 | static void *mlx5_ib_add_slave_port(struct mlx5_core_dev *mdev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6854 | { |
| 6855 | struct mlx5_ib_multiport_info *mpi; |
| 6856 | struct mlx5_ib_dev *dev; |
| 6857 | bool bound = false; |
| 6858 | int err; |
| 6859 | |
| 6860 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 6861 | if (!mpi) |
| 6862 | return NULL; |
| 6863 | |
| 6864 | mpi->mdev = mdev; |
| 6865 | |
| 6866 | err = mlx5_query_nic_vport_system_image_guid(mdev, |
| 6867 | &mpi->sys_image_guid); |
| 6868 | if (err) { |
| 6869 | kfree(mpi); |
| 6870 | return NULL; |
| 6871 | } |
| 6872 | |
| 6873 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6874 | list_for_each_entry(dev, &mlx5_ib_dev_list, ib_dev_list) { |
| 6875 | if (dev->sys_image_guid == mpi->sys_image_guid) |
| 6876 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 6877 | |
| 6878 | if (bound) { |
| 6879 | rdma_roce_rescan_device(&dev->ib_dev); |
| 6880 | break; |
| 6881 | } |
| 6882 | } |
| 6883 | |
| 6884 | if (!bound) { |
| 6885 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
Vu Pham | c42260f1 | 2019-04-29 18:14:05 +0000 | [diff] [blame] | 6886 | dev_dbg(mdev->device, |
| 6887 | "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] | 6888 | } |
| 6889 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6890 | |
| 6891 | return mpi; |
| 6892 | } |
| 6893 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6894 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
| 6895 | { |
Michael Guralnik | 94de879 | 2019-11-08 23:45:28 +0000 | [diff] [blame^] | 6896 | const struct mlx5_ib_profile *profile; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6897 | enum rdma_link_layer ll; |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6898 | struct mlx5_ib_dev *dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6899 | int port_type_cap; |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6900 | int num_ports; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6901 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6902 | printk_once(KERN_INFO "%s", mlx5_version); |
| 6903 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6904 | if (MLX5_ESWITCH_MANAGER(mdev) && |
Bodong Wang | f6455de | 2019-06-28 22:36:15 +0000 | [diff] [blame] | 6905 | mlx5_ib_eswitch_mode(mdev->priv.eswitch) == MLX5_ESWITCH_OFFLOADS) { |
Mark Bloch | 5fb58c9 | 2019-03-28 15:46:27 +0200 | [diff] [blame] | 6906 | if (!mlx5_core_mp_enabled(mdev)) |
| 6907 | mlx5_ib_register_vport_reps(mdev); |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6908 | return mdev; |
| 6909 | } |
| 6910 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6911 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6912 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6913 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6914 | if (mlx5_core_is_mp_slave(mdev) && ll == IB_LINK_LAYER_ETHERNET) |
| 6915 | return mlx5_ib_add_slave_port(mdev); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6916 | |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6917 | num_ports = max(MLX5_CAP_GEN(mdev, num_ports), |
| 6918 | MLX5_CAP_GEN(mdev, num_vhca_ports)); |
Leon Romanovsky | 459cc69 | 2019-01-30 12:49:11 +0200 | [diff] [blame] | 6919 | dev = ib_alloc_device(mlx5_ib_dev, ib_dev); |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6920 | if (!dev) |
| 6921 | return NULL; |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6922 | dev->port = kcalloc(num_ports, sizeof(*dev->port), |
| 6923 | GFP_KERNEL); |
| 6924 | if (!dev->port) { |
Parav Pandit | a5c9c29 | 2019-07-23 09:57:31 +0300 | [diff] [blame] | 6925 | ib_dealloc_device(&dev->ib_dev); |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6926 | return NULL; |
| 6927 | } |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6928 | |
| 6929 | dev->mdev = mdev; |
Mark Bloch | da796cc | 2019-03-28 15:27:35 +0200 | [diff] [blame] | 6930 | dev->num_ports = num_ports; |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6931 | |
Michael Guralnik | 94de879 | 2019-11-08 23:45:28 +0000 | [diff] [blame^] | 6932 | if (ll == IB_LINK_LAYER_ETHERNET && !mlx5_is_roce_enabled(mdev)) |
| 6933 | profile = &raw_eth_profile; |
| 6934 | else |
| 6935 | profile = &pf_profile; |
| 6936 | |
| 6937 | return __mlx5_ib_add(dev, profile); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6938 | } |
| 6939 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6940 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6941 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6942 | struct mlx5_ib_multiport_info *mpi; |
| 6943 | struct mlx5_ib_dev *dev; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6944 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6945 | if (MLX5_ESWITCH_MANAGER(mdev) && context == mdev) { |
| 6946 | mlx5_ib_unregister_vport_reps(mdev); |
| 6947 | return; |
| 6948 | } |
| 6949 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6950 | if (mlx5_core_is_mp_slave(mdev)) { |
| 6951 | mpi = context; |
| 6952 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6953 | if (mpi->ibdev) |
| 6954 | mlx5_ib_unbind_slave_port(mpi->ibdev, mpi); |
| 6955 | list_del(&mpi->list); |
| 6956 | mutex_unlock(&mlx5_ib_multiport_mutex); |
Danit Goldberg | 5d44ade | 2019-09-16 09:48:18 +0300 | [diff] [blame] | 6957 | kfree(mpi); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6958 | return; |
| 6959 | } |
| 6960 | |
| 6961 | dev = context; |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6962 | __mlx5_ib_remove(dev, dev->profile, MLX5_IB_STAGE_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6963 | } |
| 6964 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6965 | static struct mlx5_interface mlx5_ib_interface = { |
| 6966 | .add = mlx5_ib_add, |
| 6967 | .remove = mlx5_ib_remove, |
Saeed Mahameed | 64613d94 | 2015-04-02 17:07:34 +0300 | [diff] [blame] | 6968 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6969 | }; |
| 6970 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6971 | unsigned long mlx5_ib_get_xlt_emergency_page(void) |
| 6972 | { |
| 6973 | mutex_lock(&xlt_emergency_page_mutex); |
| 6974 | return xlt_emergency_page; |
| 6975 | } |
| 6976 | |
| 6977 | void mlx5_ib_put_xlt_emergency_page(void) |
| 6978 | { |
| 6979 | mutex_unlock(&xlt_emergency_page_mutex); |
| 6980 | } |
| 6981 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6982 | static int __init mlx5_ib_init(void) |
| 6983 | { |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6984 | int err; |
| 6985 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6986 | xlt_emergency_page = __get_free_page(GFP_KERNEL); |
| 6987 | if (!xlt_emergency_page) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6988 | return -ENOMEM; |
| 6989 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6990 | mutex_init(&xlt_emergency_page_mutex); |
| 6991 | |
| 6992 | mlx5_ib_event_wq = alloc_ordered_workqueue("mlx5_ib_event_wq", 0); |
| 6993 | if (!mlx5_ib_event_wq) { |
| 6994 | free_page(xlt_emergency_page); |
| 6995 | return -ENOMEM; |
| 6996 | } |
| 6997 | |
Artemy Kovalyov | 81713d3 | 2017-01-18 16:58:11 +0200 | [diff] [blame] | 6998 | mlx5_ib_odp_init(); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6999 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 7000 | err = mlx5_register_interface(&mlx5_ib_interface); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 7001 | |
| 7002 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 7003 | } |
| 7004 | |
| 7005 | static void __exit mlx5_ib_cleanup(void) |
| 7006 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 7007 | mlx5_unregister_interface(&mlx5_ib_interface); |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 7008 | destroy_workqueue(mlx5_ib_event_wq); |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 7009 | mutex_destroy(&xlt_emergency_page_mutex); |
| 7010 | free_page(xlt_emergency_page); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 7011 | } |
| 7012 | |
| 7013 | module_init(mlx5_ib_init); |
| 7014 | module_exit(mlx5_ib_cleanup); |