Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1 | /* |
Saeed Mahameed | 6cf0a15 | 2015-04-02 17:07:30 +0300 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 33 | #include <linux/debugfs.h> |
Christoph Hellwig | adec640 | 2015-08-28 09:27:19 +0200 | [diff] [blame] | 34 | #include <linux/highmem.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 35 | #include <linux/module.h> |
| 36 | #include <linux/init.h> |
| 37 | #include <linux/errno.h> |
| 38 | #include <linux/pci.h> |
| 39 | #include <linux/dma-mapping.h> |
| 40 | #include <linux/slab.h> |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 41 | #include <linux/bitmap.h> |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 42 | #if defined(CONFIG_X86) |
| 43 | #include <asm/pat.h> |
| 44 | #endif |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 45 | #include <linux/sched.h> |
Ingo Molnar | 6e84f31 | 2017-02-08 18:51:29 +0100 | [diff] [blame] | 46 | #include <linux/sched/mm.h> |
Ingo Molnar | 0881e7b | 2017-02-05 15:30:50 +0100 | [diff] [blame] | 47 | #include <linux/sched/task.h> |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 48 | #include <linux/delay.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 49 | #include <rdma/ib_user_verbs.h> |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 50 | #include <rdma/ib_addr.h> |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 51 | #include <rdma/ib_cache.h> |
Achiad Shochat | ada68c3 | 2016-02-22 18:17:23 +0200 | [diff] [blame] | 52 | #include <linux/mlx5/port.h> |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 53 | #include <linux/mlx5/vport.h> |
Pravin Shedge | 72c7fe9 | 2017-12-06 22:19:39 +0530 | [diff] [blame] | 54 | #include <linux/mlx5/fs.h> |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 55 | #include <linux/list.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 56 | #include <rdma/ib_smi.h> |
| 57 | #include <rdma/ib_umem.h> |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 58 | #include <linux/in.h> |
| 59 | #include <linux/etherdevice.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 60 | #include "mlx5_ib.h" |
Mark Bloch | fc385b7 | 2018-01-16 14:34:48 +0000 | [diff] [blame] | 61 | #include "ib_rep.h" |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 62 | #include "cmd.h" |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 63 | #include "srq.h" |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 64 | #include <linux/mlx5/fs_helpers.h> |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 65 | #include <linux/mlx5/accel.h> |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 66 | #include <rdma/uverbs_std_types.h> |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 67 | #include <rdma/mlx5_user_ioctl_verbs.h> |
| 68 | #include <rdma/mlx5_user_ioctl_cmds.h> |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 69 | |
| 70 | #define UVERBS_MODULE_NAME mlx5_ib |
| 71 | #include <rdma/uverbs_named_ioctl.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 72 | |
| 73 | #define DRIVER_NAME "mlx5_ib" |
Tariq Toukan | b359911 | 2017-02-22 17:45:46 +0200 | [diff] [blame] | 74 | #define DRIVER_VERSION "5.0-0" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 75 | |
| 76 | MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); |
| 77 | MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); |
| 78 | MODULE_LICENSE("Dual BSD/GPL"); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 79 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 80 | static char mlx5_version[] = |
| 81 | DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
Tariq Toukan | b359911 | 2017-02-22 17:45:46 +0200 | [diff] [blame] | 82 | DRIVER_VERSION "\n"; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 83 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 84 | struct mlx5_ib_event_work { |
| 85 | struct work_struct work; |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 86 | union { |
| 87 | struct mlx5_ib_dev *dev; |
| 88 | struct mlx5_ib_multiport_info *mpi; |
| 89 | }; |
| 90 | bool is_slave; |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 91 | unsigned int event; |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 92 | void *param; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 93 | }; |
| 94 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 95 | enum { |
| 96 | MLX5_ATOMIC_SIZE_QP_8BYTES = 1 << 3, |
| 97 | }; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 98 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 99 | static struct workqueue_struct *mlx5_ib_event_wq; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 100 | static LIST_HEAD(mlx5_ib_unaffiliated_port_list); |
| 101 | static LIST_HEAD(mlx5_ib_dev_list); |
| 102 | /* |
| 103 | * This mutex should be held when accessing either of the above lists |
| 104 | */ |
| 105 | static DEFINE_MUTEX(mlx5_ib_multiport_mutex); |
| 106 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 107 | /* We can't use an array for xlt_emergency_page because dma_map_single |
| 108 | * doesn't work on kernel modules memory |
| 109 | */ |
| 110 | static unsigned long xlt_emergency_page; |
| 111 | static struct mutex xlt_emergency_page_mutex; |
| 112 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 113 | struct mlx5_ib_dev *mlx5_ib_get_ibdev_from_mpi(struct mlx5_ib_multiport_info *mpi) |
| 114 | { |
| 115 | struct mlx5_ib_dev *dev; |
| 116 | |
| 117 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 118 | dev = mpi->ibdev; |
| 119 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 120 | return dev; |
| 121 | } |
| 122 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 123 | static enum rdma_link_layer |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 124 | mlx5_port_type_cap_to_rdma_ll(int port_type_cap) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 125 | { |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 126 | switch (port_type_cap) { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 127 | case MLX5_CAP_PORT_TYPE_IB: |
| 128 | return IB_LINK_LAYER_INFINIBAND; |
| 129 | case MLX5_CAP_PORT_TYPE_ETH: |
| 130 | return IB_LINK_LAYER_ETHERNET; |
| 131 | default: |
| 132 | return IB_LINK_LAYER_UNSPECIFIED; |
| 133 | } |
| 134 | } |
| 135 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 136 | static enum rdma_link_layer |
| 137 | mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num) |
| 138 | { |
| 139 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 140 | int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type); |
| 141 | |
| 142 | return mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 143 | } |
| 144 | |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 145 | static int get_port_state(struct ib_device *ibdev, |
| 146 | u8 port_num, |
| 147 | enum ib_port_state *state) |
| 148 | { |
| 149 | struct ib_port_attr attr; |
| 150 | int ret; |
| 151 | |
| 152 | memset(&attr, 0, sizeof(attr)); |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 153 | ret = ibdev->ops.query_port(ibdev, port_num, &attr); |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 154 | if (!ret) |
| 155 | *state = attr.state; |
| 156 | return ret; |
| 157 | } |
| 158 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 159 | static int mlx5_netdev_event(struct notifier_block *this, |
| 160 | unsigned long event, void *ptr) |
| 161 | { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 162 | struct mlx5_roce *roce = container_of(this, struct mlx5_roce, nb); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 163 | struct net_device *ndev = netdev_notifier_info_to_dev(ptr); |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 164 | u8 port_num = roce->native_port_num; |
| 165 | struct mlx5_core_dev *mdev; |
| 166 | struct mlx5_ib_dev *ibdev; |
| 167 | |
| 168 | ibdev = roce->dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 169 | mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL); |
| 170 | if (!mdev) |
| 171 | return NOTIFY_DONE; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 172 | |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 173 | switch (event) { |
| 174 | case NETDEV_REGISTER: |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 175 | write_lock(&roce->netdev_lock); |
Mark Bloch | bcf87f1 | 2018-01-16 15:02:36 +0000 | [diff] [blame] | 176 | if (ibdev->rep) { |
| 177 | struct mlx5_eswitch *esw = ibdev->mdev->priv.eswitch; |
| 178 | struct net_device *rep_ndev; |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 179 | |
Mark Bloch | bcf87f1 | 2018-01-16 15:02:36 +0000 | [diff] [blame] | 180 | rep_ndev = mlx5_ib_get_rep_netdev(esw, |
| 181 | ibdev->rep->vport); |
| 182 | if (rep_ndev == ndev) |
Or Gerlitz | 842a9c8 | 2018-12-11 18:10:43 +0200 | [diff] [blame] | 183 | roce->netdev = ndev; |
Parav Pandit | 84a6a7a | 2018-04-23 17:01:55 +0300 | [diff] [blame] | 184 | } else if (ndev->dev.parent == &mdev->pdev->dev) { |
Or Gerlitz | 842a9c8 | 2018-12-11 18:10:43 +0200 | [diff] [blame] | 185 | roce->netdev = ndev; |
Mark Bloch | bcf87f1 | 2018-01-16 15:02:36 +0000 | [diff] [blame] | 186 | } |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 187 | write_unlock(&roce->netdev_lock); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 188 | break; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 189 | |
Or Gerlitz | 842a9c8 | 2018-12-11 18:10:43 +0200 | [diff] [blame] | 190 | case NETDEV_UNREGISTER: |
| 191 | write_lock(&roce->netdev_lock); |
| 192 | if (roce->netdev == ndev) |
| 193 | roce->netdev = NULL; |
| 194 | write_unlock(&roce->netdev_lock); |
| 195 | break; |
| 196 | |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 197 | case NETDEV_CHANGE: |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 198 | case NETDEV_UP: |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 199 | case NETDEV_DOWN: { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 200 | struct net_device *lag_ndev = mlx5_lag_get_roce_netdev(mdev); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 201 | struct net_device *upper = NULL; |
| 202 | |
| 203 | if (lag_ndev) { |
| 204 | upper = netdev_master_upper_dev_get(lag_ndev); |
| 205 | dev_put(lag_ndev); |
| 206 | } |
| 207 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 208 | if ((upper == ndev || (!upper && ndev == roce->netdev)) |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 209 | && ibdev->ib_active) { |
Bart Van Assche | 626bc02 | 2016-12-05 17:18:08 -0800 | [diff] [blame] | 210 | struct ib_event ibev = { }; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 211 | enum ib_port_state port_state; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 212 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 213 | if (get_port_state(&ibdev->ib_dev, port_num, |
| 214 | &port_state)) |
| 215 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 216 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 217 | if (roce->last_port_state == port_state) |
| 218 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 219 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 220 | roce->last_port_state = port_state; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 221 | ibev.device = &ibdev->ib_dev; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 222 | if (port_state == IB_PORT_DOWN) |
| 223 | ibev.event = IB_EVENT_PORT_ERR; |
| 224 | else if (port_state == IB_PORT_ACTIVE) |
| 225 | ibev.event = IB_EVENT_PORT_ACTIVE; |
| 226 | else |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 227 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 228 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 229 | ibev.element.port_num = port_num; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 230 | ib_dispatch_event(&ibev); |
| 231 | } |
| 232 | break; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 233 | } |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 234 | |
| 235 | default: |
| 236 | break; |
| 237 | } |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 238 | done: |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 239 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 240 | return NOTIFY_DONE; |
| 241 | } |
| 242 | |
| 243 | static struct net_device *mlx5_ib_get_netdev(struct ib_device *device, |
| 244 | u8 port_num) |
| 245 | { |
| 246 | struct mlx5_ib_dev *ibdev = to_mdev(device); |
| 247 | struct net_device *ndev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 248 | struct mlx5_core_dev *mdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 249 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 250 | mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL); |
| 251 | if (!mdev) |
| 252 | return NULL; |
| 253 | |
| 254 | ndev = mlx5_lag_get_roce_netdev(mdev); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 255 | if (ndev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 256 | goto out; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 257 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 258 | /* Ensure ndev does not disappear before we invoke dev_hold() |
| 259 | */ |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 260 | read_lock(&ibdev->roce[port_num - 1].netdev_lock); |
| 261 | ndev = ibdev->roce[port_num - 1].netdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 262 | if (ndev) |
| 263 | dev_hold(ndev); |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 264 | read_unlock(&ibdev->roce[port_num - 1].netdev_lock); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 265 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 266 | out: |
| 267 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 268 | return ndev; |
| 269 | } |
| 270 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 271 | struct mlx5_core_dev *mlx5_ib_get_native_port_mdev(struct mlx5_ib_dev *ibdev, |
| 272 | u8 ib_port_num, |
| 273 | u8 *native_port_num) |
| 274 | { |
| 275 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&ibdev->ib_dev, |
| 276 | ib_port_num); |
| 277 | struct mlx5_core_dev *mdev = NULL; |
| 278 | struct mlx5_ib_multiport_info *mpi; |
| 279 | struct mlx5_ib_port *port; |
| 280 | |
Mark Bloch | 210b1f7 | 2018-03-05 20:09:47 +0200 | [diff] [blame] | 281 | if (!mlx5_core_mp_enabled(ibdev->mdev) || |
| 282 | ll != IB_LINK_LAYER_ETHERNET) { |
| 283 | if (native_port_num) |
| 284 | *native_port_num = ib_port_num; |
| 285 | return ibdev->mdev; |
| 286 | } |
| 287 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 288 | if (native_port_num) |
| 289 | *native_port_num = 1; |
| 290 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 291 | port = &ibdev->port[ib_port_num - 1]; |
| 292 | if (!port) |
| 293 | return NULL; |
| 294 | |
| 295 | spin_lock(&port->mp.mpi_lock); |
| 296 | mpi = ibdev->port[ib_port_num - 1].mp.mpi; |
| 297 | if (mpi && !mpi->unaffiliate) { |
| 298 | mdev = mpi->mdev; |
| 299 | /* If it's the master no need to refcount, it'll exist |
| 300 | * as long as the ib_dev exists. |
| 301 | */ |
| 302 | if (!mpi->is_master) |
| 303 | mpi->mdev_refcnt++; |
| 304 | } |
| 305 | spin_unlock(&port->mp.mpi_lock); |
| 306 | |
| 307 | return mdev; |
| 308 | } |
| 309 | |
| 310 | void mlx5_ib_put_native_port_mdev(struct mlx5_ib_dev *ibdev, u8 port_num) |
| 311 | { |
| 312 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&ibdev->ib_dev, |
| 313 | port_num); |
| 314 | struct mlx5_ib_multiport_info *mpi; |
| 315 | struct mlx5_ib_port *port; |
| 316 | |
| 317 | if (!mlx5_core_mp_enabled(ibdev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 318 | return; |
| 319 | |
| 320 | port = &ibdev->port[port_num - 1]; |
| 321 | |
| 322 | spin_lock(&port->mp.mpi_lock); |
| 323 | mpi = ibdev->port[port_num - 1].mp.mpi; |
| 324 | if (mpi->is_master) |
| 325 | goto out; |
| 326 | |
| 327 | mpi->mdev_refcnt--; |
| 328 | if (mpi->unaffiliate) |
| 329 | complete(&mpi->unref_comp); |
| 330 | out: |
| 331 | spin_unlock(&port->mp.mpi_lock); |
| 332 | } |
| 333 | |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 334 | static int translate_eth_legacy_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 335 | u8 *active_width) |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 336 | { |
| 337 | switch (eth_proto_oper) { |
| 338 | case MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII): |
| 339 | case MLX5E_PROT_MASK(MLX5E_1000BASE_KX): |
| 340 | case MLX5E_PROT_MASK(MLX5E_100BASE_TX): |
| 341 | case MLX5E_PROT_MASK(MLX5E_1000BASE_T): |
| 342 | *active_width = IB_WIDTH_1X; |
| 343 | *active_speed = IB_SPEED_SDR; |
| 344 | break; |
| 345 | case MLX5E_PROT_MASK(MLX5E_10GBASE_T): |
| 346 | case MLX5E_PROT_MASK(MLX5E_10GBASE_CX4): |
| 347 | case MLX5E_PROT_MASK(MLX5E_10GBASE_KX4): |
| 348 | case MLX5E_PROT_MASK(MLX5E_10GBASE_KR): |
| 349 | case MLX5E_PROT_MASK(MLX5E_10GBASE_CR): |
| 350 | case MLX5E_PROT_MASK(MLX5E_10GBASE_SR): |
| 351 | case MLX5E_PROT_MASK(MLX5E_10GBASE_ER): |
| 352 | *active_width = IB_WIDTH_1X; |
| 353 | *active_speed = IB_SPEED_QDR; |
| 354 | break; |
| 355 | case MLX5E_PROT_MASK(MLX5E_25GBASE_CR): |
| 356 | case MLX5E_PROT_MASK(MLX5E_25GBASE_KR): |
| 357 | case MLX5E_PROT_MASK(MLX5E_25GBASE_SR): |
| 358 | *active_width = IB_WIDTH_1X; |
| 359 | *active_speed = IB_SPEED_EDR; |
| 360 | break; |
| 361 | case MLX5E_PROT_MASK(MLX5E_40GBASE_CR4): |
| 362 | case MLX5E_PROT_MASK(MLX5E_40GBASE_KR4): |
| 363 | case MLX5E_PROT_MASK(MLX5E_40GBASE_SR4): |
| 364 | case MLX5E_PROT_MASK(MLX5E_40GBASE_LR4): |
| 365 | *active_width = IB_WIDTH_4X; |
| 366 | *active_speed = IB_SPEED_QDR; |
| 367 | break; |
| 368 | case MLX5E_PROT_MASK(MLX5E_50GBASE_CR2): |
| 369 | case MLX5E_PROT_MASK(MLX5E_50GBASE_KR2): |
| 370 | case MLX5E_PROT_MASK(MLX5E_50GBASE_SR2): |
| 371 | *active_width = IB_WIDTH_1X; |
| 372 | *active_speed = IB_SPEED_HDR; |
| 373 | break; |
| 374 | case MLX5E_PROT_MASK(MLX5E_56GBASE_R4): |
| 375 | *active_width = IB_WIDTH_4X; |
| 376 | *active_speed = IB_SPEED_FDR; |
| 377 | break; |
| 378 | case MLX5E_PROT_MASK(MLX5E_100GBASE_CR4): |
| 379 | case MLX5E_PROT_MASK(MLX5E_100GBASE_SR4): |
| 380 | case MLX5E_PROT_MASK(MLX5E_100GBASE_KR4): |
| 381 | case MLX5E_PROT_MASK(MLX5E_100GBASE_LR4): |
| 382 | *active_width = IB_WIDTH_4X; |
| 383 | *active_speed = IB_SPEED_EDR; |
| 384 | break; |
| 385 | default: |
| 386 | return -EINVAL; |
| 387 | } |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 392 | static int translate_eth_ext_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 393 | u8 *active_width) |
| 394 | { |
| 395 | switch (eth_proto_oper) { |
| 396 | case MLX5E_PROT_MASK(MLX5E_SGMII_100M): |
| 397 | case MLX5E_PROT_MASK(MLX5E_1000BASE_X_SGMII): |
| 398 | *active_width = IB_WIDTH_1X; |
| 399 | *active_speed = IB_SPEED_SDR; |
| 400 | break; |
| 401 | case MLX5E_PROT_MASK(MLX5E_5GBASE_R): |
| 402 | *active_width = IB_WIDTH_1X; |
| 403 | *active_speed = IB_SPEED_DDR; |
| 404 | break; |
| 405 | case MLX5E_PROT_MASK(MLX5E_10GBASE_XFI_XAUI_1): |
| 406 | *active_width = IB_WIDTH_1X; |
| 407 | *active_speed = IB_SPEED_QDR; |
| 408 | break; |
| 409 | case MLX5E_PROT_MASK(MLX5E_40GBASE_XLAUI_4_XLPPI_4): |
| 410 | *active_width = IB_WIDTH_4X; |
| 411 | *active_speed = IB_SPEED_QDR; |
| 412 | break; |
| 413 | case MLX5E_PROT_MASK(MLX5E_25GAUI_1_25GBASE_CR_KR): |
| 414 | *active_width = IB_WIDTH_1X; |
| 415 | *active_speed = IB_SPEED_EDR; |
| 416 | break; |
| 417 | case MLX5E_PROT_MASK(MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2): |
Aya Levin | cd27287 | 2019-03-11 14:35:58 +0200 | [diff] [blame] | 418 | *active_width = IB_WIDTH_2X; |
| 419 | *active_speed = IB_SPEED_EDR; |
| 420 | break; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 421 | case MLX5E_PROT_MASK(MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR): |
| 422 | *active_width = IB_WIDTH_1X; |
| 423 | *active_speed = IB_SPEED_HDR; |
| 424 | break; |
Aya Levin | cd27287 | 2019-03-11 14:35:58 +0200 | [diff] [blame] | 425 | case MLX5E_PROT_MASK(MLX5E_CAUI_4_100GBASE_CR4_KR4): |
| 426 | *active_width = IB_WIDTH_4X; |
| 427 | *active_speed = IB_SPEED_EDR; |
| 428 | break; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 429 | case MLX5E_PROT_MASK(MLX5E_100GAUI_2_100GBASE_CR2_KR2): |
| 430 | *active_width = IB_WIDTH_2X; |
| 431 | *active_speed = IB_SPEED_HDR; |
| 432 | break; |
| 433 | case MLX5E_PROT_MASK(MLX5E_200GAUI_4_200GBASE_CR4_KR4): |
| 434 | *active_width = IB_WIDTH_4X; |
| 435 | *active_speed = IB_SPEED_HDR; |
| 436 | break; |
| 437 | default: |
| 438 | return -EINVAL; |
| 439 | } |
| 440 | |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | static int translate_eth_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 445 | u8 *active_width, bool ext) |
| 446 | { |
| 447 | return ext ? |
| 448 | translate_eth_ext_proto_oper(eth_proto_oper, active_speed, |
| 449 | active_width) : |
| 450 | translate_eth_legacy_proto_oper(eth_proto_oper, active_speed, |
| 451 | active_width); |
| 452 | } |
| 453 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 454 | static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, |
| 455 | struct ib_port_attr *props) |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 456 | { |
| 457 | struct mlx5_ib_dev *dev = to_mdev(device); |
Aya Levin | bc4e12f | 2019-02-12 22:55:43 -0800 | [diff] [blame] | 458 | u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {0}; |
Colin Ian King | da005f9 | 2018-01-09 15:55:43 +0000 | [diff] [blame] | 459 | struct mlx5_core_dev *mdev; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 460 | struct net_device *ndev, *upper; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 461 | enum ib_mtu ndev_ib_mtu; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 462 | bool put_mdev = true; |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 463 | u16 qkey_viol_cntr; |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 464 | u32 eth_prot_oper; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 465 | u8 mdev_port_num; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 466 | bool ext; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 467 | int err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 468 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 469 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 470 | if (!mdev) { |
| 471 | /* This means the port isn't affiliated yet. Get the |
| 472 | * info for the master port instead. |
| 473 | */ |
| 474 | put_mdev = false; |
| 475 | mdev = dev->mdev; |
| 476 | mdev_port_num = 1; |
| 477 | port_num = 1; |
| 478 | } |
| 479 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 480 | /* Possible bad flows are checked before filling out props so in case |
| 481 | * of an error it will still be zeroed out. |
Noa Osherovich | 50f22fd | 2017-04-20 20:53:32 +0300 | [diff] [blame] | 482 | */ |
Aya Levin | bc4e12f | 2019-02-12 22:55:43 -0800 | [diff] [blame] | 483 | err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, |
| 484 | mdev_port_num); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 485 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 486 | goto out; |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 487 | ext = MLX5_CAP_PCAM_FEATURE(dev->mdev, ptys_extended_ethernet); |
| 488 | 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] | 489 | |
Honggang Li | 7672ed3 | 2018-03-16 10:37:13 +0800 | [diff] [blame] | 490 | props->active_width = IB_WIDTH_4X; |
| 491 | props->active_speed = IB_SPEED_QDR; |
| 492 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 493 | translate_eth_proto_oper(eth_prot_oper, &props->active_speed, |
Aya Levin | 08e8676 | 2019-02-12 22:55:46 -0800 | [diff] [blame] | 494 | &props->active_width, ext); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 495 | |
Jason Gunthorpe | 2f944c0 | 2018-07-04 15:57:48 +0300 | [diff] [blame] | 496 | props->port_cap_flags |= IB_PORT_CM_SUP; |
| 497 | props->ip_gids = true; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 498 | |
| 499 | props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev, |
| 500 | roce_address_table_size); |
| 501 | props->max_mtu = IB_MTU_4096; |
| 502 | props->max_msg_sz = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg); |
| 503 | props->pkey_tbl_len = 1; |
| 504 | props->state = IB_PORT_DOWN; |
| 505 | props->phys_state = 3; |
| 506 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 507 | mlx5_query_nic_vport_qkey_viol_cntr(mdev, &qkey_viol_cntr); |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 508 | props->qkey_viol_cntr = qkey_viol_cntr; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 509 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 510 | /* If this is a stub query for an unaffiliated port stop here */ |
| 511 | if (!put_mdev) |
| 512 | goto out; |
| 513 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 514 | ndev = mlx5_ib_get_netdev(device, port_num); |
| 515 | if (!ndev) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 516 | goto out; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 517 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 518 | if (dev->lag_active) { |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 519 | rcu_read_lock(); |
| 520 | upper = netdev_master_upper_dev_get_rcu(ndev); |
| 521 | if (upper) { |
| 522 | dev_put(ndev); |
| 523 | ndev = upper; |
| 524 | dev_hold(ndev); |
| 525 | } |
| 526 | rcu_read_unlock(); |
| 527 | } |
| 528 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 529 | if (netif_running(ndev) && netif_carrier_ok(ndev)) { |
| 530 | props->state = IB_PORT_ACTIVE; |
| 531 | props->phys_state = 5; |
| 532 | } |
| 533 | |
| 534 | ndev_ib_mtu = iboe_get_mtu(ndev->mtu); |
| 535 | |
| 536 | dev_put(ndev); |
| 537 | |
| 538 | props->active_mtu = min(props->max_mtu, ndev_ib_mtu); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 539 | out: |
| 540 | if (put_mdev) |
| 541 | mlx5_ib_put_native_port_mdev(dev, port_num); |
| 542 | return err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 543 | } |
| 544 | |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 545 | struct mlx5_ib_vlan_info { |
| 546 | u16 vlan_id; |
| 547 | bool vlan; |
| 548 | }; |
| 549 | |
| 550 | static int get_lower_dev_vlan(struct net_device *lower_dev, void *data) |
| 551 | { |
| 552 | struct mlx5_ib_vlan_info *vlan_info = data; |
| 553 | |
| 554 | if (is_vlan_dev(lower_dev)) { |
| 555 | vlan_info->vlan = true; |
| 556 | vlan_info->vlan_id = vlan_dev_vlan_id(lower_dev); |
| 557 | } |
| 558 | /* We are interested only in first level vlan device, so |
| 559 | * always return 1 to stop iterating over next level devices. |
| 560 | */ |
| 561 | return 1; |
| 562 | } |
| 563 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 564 | static int set_roce_addr(struct mlx5_ib_dev *dev, u8 port_num, |
| 565 | unsigned int index, const union ib_gid *gid, |
| 566 | const struct ib_gid_attr *attr) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 567 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 568 | enum ib_gid_type gid_type = IB_GID_TYPE_IB; |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 569 | struct mlx5_ib_vlan_info vlan_info = { }; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 570 | u8 roce_version = 0; |
| 571 | u8 roce_l3_type = 0; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 572 | u8 mac[ETH_ALEN]; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 573 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 574 | if (gid) { |
| 575 | gid_type = attr->gid_type; |
| 576 | ether_addr_copy(mac, attr->ndev->dev_addr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 577 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 578 | if (is_vlan_dev(attr->ndev)) { |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 579 | vlan_info.vlan = true; |
| 580 | vlan_info.vlan_id = vlan_dev_vlan_id(attr->ndev); |
| 581 | } else { |
| 582 | /* If the netdev is upper device and if it's lower |
| 583 | * lower device is vlan device, consider vlan id of |
| 584 | * the lower vlan device for this gid entry. |
| 585 | */ |
| 586 | rcu_read_lock(); |
| 587 | netdev_walk_all_lower_dev_rcu(attr->ndev, |
| 588 | get_lower_dev_vlan, &vlan_info); |
| 589 | rcu_read_unlock(); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 590 | } |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 591 | } |
| 592 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 593 | switch (gid_type) { |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 594 | case IB_GID_TYPE_IB: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 595 | roce_version = MLX5_ROCE_VERSION_1; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 596 | break; |
| 597 | case IB_GID_TYPE_ROCE_UDP_ENCAP: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 598 | roce_version = MLX5_ROCE_VERSION_2; |
| 599 | if (ipv6_addr_v4mapped((void *)gid)) |
| 600 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV4; |
| 601 | else |
| 602 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV6; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 603 | break; |
| 604 | |
| 605 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 606 | mlx5_ib_warn(dev, "Unexpected GID type %u\n", gid_type); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 607 | } |
| 608 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 609 | return mlx5_core_roce_gid_set(dev->mdev, index, roce_version, |
Parav Pandit | cf34e1f | 2019-01-27 20:35:50 +0200 | [diff] [blame] | 610 | roce_l3_type, gid->raw, mac, |
| 611 | vlan_info.vlan, vlan_info.vlan_id, |
| 612 | port_num); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 613 | } |
| 614 | |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 615 | static int mlx5_ib_add_gid(const struct ib_gid_attr *attr, |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 616 | __always_unused void **context) |
| 617 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 618 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 619 | attr->index, &attr->gid, attr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 620 | } |
| 621 | |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 622 | static int mlx5_ib_del_gid(const struct ib_gid_attr *attr, |
| 623 | __always_unused void **context) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 624 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 625 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
| 626 | attr->index, NULL, NULL); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 627 | } |
| 628 | |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 629 | __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, |
| 630 | const struct ib_gid_attr *attr) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 631 | { |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 632 | if (attr->gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 633 | return 0; |
| 634 | |
| 635 | return cpu_to_be16(MLX5_CAP_ROCE(dev->mdev, r_roce_min_src_udp_port)); |
| 636 | } |
| 637 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 638 | static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) |
| 639 | { |
Noa Osherovich | 7fae665 | 2016-09-12 19:16:23 +0300 | [diff] [blame] | 640 | if (MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_IB) |
| 641 | return !MLX5_CAP_GEN(dev->mdev, ib_virt); |
| 642 | return 0; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | enum { |
| 646 | MLX5_VPORT_ACCESS_METHOD_MAD, |
| 647 | MLX5_VPORT_ACCESS_METHOD_HCA, |
| 648 | MLX5_VPORT_ACCESS_METHOD_NIC, |
| 649 | }; |
| 650 | |
| 651 | static int mlx5_get_vport_access_method(struct ib_device *ibdev) |
| 652 | { |
| 653 | if (mlx5_use_mad_ifc(to_mdev(ibdev))) |
| 654 | return MLX5_VPORT_ACCESS_METHOD_MAD; |
| 655 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 656 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 657 | IB_LINK_LAYER_ETHERNET) |
| 658 | return MLX5_VPORT_ACCESS_METHOD_NIC; |
| 659 | |
| 660 | return MLX5_VPORT_ACCESS_METHOD_HCA; |
| 661 | } |
| 662 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 663 | static void get_atomic_caps(struct mlx5_ib_dev *dev, |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 664 | u8 atomic_size_qp, |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 665 | struct ib_device_attr *props) |
| 666 | { |
| 667 | u8 tmp; |
| 668 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 669 | u8 atomic_req_8B_endianness_mode = |
Or Gerlitz | bd10838 | 2017-05-28 15:24:17 +0300 | [diff] [blame] | 670 | MLX5_CAP_ATOMIC(dev->mdev, atomic_req_8B_endianness_mode); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 671 | |
| 672 | /* Check if HW supports 8 bytes standard atomic operations and capable |
| 673 | * of host endianness respond |
| 674 | */ |
| 675 | tmp = MLX5_ATOMIC_OPS_CMP_SWAP | MLX5_ATOMIC_OPS_FETCH_ADD; |
| 676 | if (((atomic_operations & tmp) == tmp) && |
| 677 | (atomic_size_qp & MLX5_ATOMIC_SIZE_QP_8BYTES) && |
| 678 | (atomic_req_8B_endianness_mode)) { |
| 679 | props->atomic_cap = IB_ATOMIC_HCA; |
| 680 | } else { |
| 681 | props->atomic_cap = IB_ATOMIC_NONE; |
| 682 | } |
| 683 | } |
| 684 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 685 | static void get_atomic_caps_qp(struct mlx5_ib_dev *dev, |
| 686 | struct ib_device_attr *props) |
| 687 | { |
| 688 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 689 | |
| 690 | get_atomic_caps(dev, atomic_size_qp, props); |
| 691 | } |
| 692 | |
| 693 | static void get_atomic_caps_dc(struct mlx5_ib_dev *dev, |
| 694 | struct ib_device_attr *props) |
| 695 | { |
| 696 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc); |
| 697 | |
| 698 | get_atomic_caps(dev, atomic_size_qp, props); |
| 699 | } |
| 700 | |
| 701 | bool mlx5_ib_dc_atomic_is_supported(struct mlx5_ib_dev *dev) |
| 702 | { |
| 703 | struct ib_device_attr props = {}; |
| 704 | |
| 705 | get_atomic_caps_dc(dev, &props); |
| 706 | return (props.atomic_cap == IB_ATOMIC_HCA) ? true : false; |
| 707 | } |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 708 | static int mlx5_query_system_image_guid(struct ib_device *ibdev, |
| 709 | __be64 *sys_image_guid) |
| 710 | { |
| 711 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 712 | struct mlx5_core_dev *mdev = dev->mdev; |
| 713 | u64 tmp; |
| 714 | int err; |
| 715 | |
| 716 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 717 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 718 | return mlx5_query_mad_ifc_system_image_guid(ibdev, |
| 719 | sys_image_guid); |
| 720 | |
| 721 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 722 | err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 723 | break; |
| 724 | |
| 725 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 726 | err = mlx5_query_nic_vport_system_image_guid(mdev, &tmp); |
| 727 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 728 | |
| 729 | default: |
| 730 | return -EINVAL; |
| 731 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 732 | |
| 733 | if (!err) |
| 734 | *sys_image_guid = cpu_to_be64(tmp); |
| 735 | |
| 736 | return err; |
| 737 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | static int mlx5_query_max_pkeys(struct ib_device *ibdev, |
| 741 | u16 *max_pkeys) |
| 742 | { |
| 743 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 744 | struct mlx5_core_dev *mdev = dev->mdev; |
| 745 | |
| 746 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 747 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 748 | return mlx5_query_mad_ifc_max_pkeys(ibdev, max_pkeys); |
| 749 | |
| 750 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 751 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 752 | *max_pkeys = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, |
| 753 | pkey_table_size)); |
| 754 | return 0; |
| 755 | |
| 756 | default: |
| 757 | return -EINVAL; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | static int mlx5_query_vendor_id(struct ib_device *ibdev, |
| 762 | u32 *vendor_id) |
| 763 | { |
| 764 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 765 | |
| 766 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 767 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 768 | return mlx5_query_mad_ifc_vendor_id(ibdev, vendor_id); |
| 769 | |
| 770 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 771 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 772 | return mlx5_core_query_vendor_id(dev->mdev, vendor_id); |
| 773 | |
| 774 | default: |
| 775 | return -EINVAL; |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | static int mlx5_query_node_guid(struct mlx5_ib_dev *dev, |
| 780 | __be64 *node_guid) |
| 781 | { |
| 782 | u64 tmp; |
| 783 | int err; |
| 784 | |
| 785 | switch (mlx5_get_vport_access_method(&dev->ib_dev)) { |
| 786 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 787 | return mlx5_query_mad_ifc_node_guid(dev, node_guid); |
| 788 | |
| 789 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 790 | err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 791 | break; |
| 792 | |
| 793 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 794 | err = mlx5_query_nic_vport_node_guid(dev->mdev, &tmp); |
| 795 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 796 | |
| 797 | default: |
| 798 | return -EINVAL; |
| 799 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 800 | |
| 801 | if (!err) |
| 802 | *node_guid = cpu_to_be64(tmp); |
| 803 | |
| 804 | return err; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | struct mlx5_reg_node_desc { |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 808 | u8 desc[IB_DEVICE_NODE_DESC_MAX]; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 809 | }; |
| 810 | |
| 811 | static int mlx5_query_node_desc(struct mlx5_ib_dev *dev, char *node_desc) |
| 812 | { |
| 813 | struct mlx5_reg_node_desc in; |
| 814 | |
| 815 | if (mlx5_use_mad_ifc(dev)) |
| 816 | return mlx5_query_mad_ifc_node_desc(dev, node_desc); |
| 817 | |
| 818 | memset(&in, 0, sizeof(in)); |
| 819 | |
| 820 | return mlx5_core_access_reg(dev->mdev, &in, sizeof(in), node_desc, |
| 821 | sizeof(struct mlx5_reg_node_desc), |
| 822 | MLX5_REG_NODE_DESC, 0, 0); |
| 823 | } |
| 824 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 825 | static int mlx5_ib_query_device(struct ib_device *ibdev, |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 826 | struct ib_device_attr *props, |
| 827 | struct ib_udata *uhw) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 828 | { |
| 829 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 830 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 831 | int err = -ENOMEM; |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 832 | int max_sq_desc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 833 | int max_rq_sg; |
| 834 | int max_sq_sg; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 835 | u64 min_page_size = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 836 | bool raw_support = !mlx5_core_mp_enabled(mdev); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 837 | struct mlx5_ib_query_device_resp resp = {}; |
| 838 | size_t resp_len; |
| 839 | u64 max_tso; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 840 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 841 | resp_len = sizeof(resp.comp_mask) + sizeof(resp.response_length); |
| 842 | if (uhw->outlen && uhw->outlen < resp_len) |
| 843 | return -EINVAL; |
| 844 | else |
| 845 | resp.response_length = resp_len; |
| 846 | |
| 847 | if (uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen)) |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 848 | return -EINVAL; |
| 849 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 850 | memset(props, 0, sizeof(*props)); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 851 | err = mlx5_query_system_image_guid(ibdev, |
| 852 | &props->sys_image_guid); |
| 853 | if (err) |
| 854 | return err; |
| 855 | |
| 856 | err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys); |
| 857 | if (err) |
| 858 | return err; |
| 859 | |
| 860 | err = mlx5_query_vendor_id(ibdev, &props->vendor_id); |
| 861 | if (err) |
| 862 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 863 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 864 | props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) | |
| 865 | (fw_rev_min(dev->mdev) << 16) | |
| 866 | fw_rev_sub(dev->mdev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 867 | props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | |
| 868 | IB_DEVICE_PORT_ACTIVE_EVENT | |
| 869 | IB_DEVICE_SYS_IMAGE_GUID | |
Eli Cohen | 1a4c3a3 | 2014-02-06 17:41:25 +0200 | [diff] [blame] | 870 | IB_DEVICE_RC_RNR_NAK_GEN; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 871 | |
| 872 | if (MLX5_CAP_GEN(mdev, pkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 873 | props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 874 | if (MLX5_CAP_GEN(mdev, qkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 875 | props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 876 | if (MLX5_CAP_GEN(mdev, apm)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 877 | props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 878 | if (MLX5_CAP_GEN(mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 879 | props->device_cap_flags |= IB_DEVICE_XRC; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 880 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
| 881 | props->device_cap_flags |= IB_DEVICE_MEM_WINDOW | |
| 882 | IB_DEVICE_MEM_WINDOW_TYPE_2B; |
| 883 | props->max_mw = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 884 | /* We support 'Gappy' memory registration too */ |
| 885 | props->device_cap_flags |= IB_DEVICE_SG_GAPS_REG; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 886 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 887 | props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 888 | if (MLX5_CAP_GEN(mdev, sho)) { |
Sagi Grimberg | 2dea909 | 2014-02-23 14:19:13 +0200 | [diff] [blame] | 889 | props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER; |
| 890 | /* At this stage no support for signature handover */ |
| 891 | props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 | |
| 892 | IB_PROT_T10DIF_TYPE_2 | |
| 893 | IB_PROT_T10DIF_TYPE_3; |
| 894 | props->sig_guard_cap = IB_GUARD_T10DIF_CRC | |
| 895 | IB_GUARD_T10DIF_CSUM; |
| 896 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 897 | if (MLX5_CAP_GEN(mdev, block_lb_mc)) |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 898 | props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 899 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 900 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 901 | if (MLX5_CAP_ETH(mdev, csum_cap)) { |
| 902 | /* Legacy bit to support old userspace libraries */ |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 903 | props->device_cap_flags |= IB_DEVICE_RAW_IP_CSUM; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 904 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_IP_CSUM; |
| 905 | } |
| 906 | |
| 907 | if (MLX5_CAP_ETH(dev->mdev, vlan_cap)) |
| 908 | props->raw_packet_caps |= |
| 909 | IB_RAW_PACKET_CAP_CVLAN_STRIPPING; |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 910 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 911 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) { |
| 912 | max_tso = MLX5_CAP_ETH(mdev, max_lso_cap); |
| 913 | if (max_tso) { |
| 914 | resp.tso_caps.max_tso = 1 << max_tso; |
| 915 | resp.tso_caps.supported_qpts |= |
| 916 | 1 << IB_QPT_RAW_PACKET; |
| 917 | resp.response_length += sizeof(resp.tso_caps); |
| 918 | } |
| 919 | } |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 920 | |
| 921 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) { |
| 922 | resp.rss_caps.rx_hash_function = |
| 923 | MLX5_RX_HASH_FUNC_TOEPLITZ; |
| 924 | resp.rss_caps.rx_hash_fields_mask = |
| 925 | MLX5_RX_HASH_SRC_IPV4 | |
| 926 | MLX5_RX_HASH_DST_IPV4 | |
| 927 | MLX5_RX_HASH_SRC_IPV6 | |
| 928 | MLX5_RX_HASH_DST_IPV6 | |
| 929 | MLX5_RX_HASH_SRC_PORT_TCP | |
| 930 | MLX5_RX_HASH_DST_PORT_TCP | |
| 931 | MLX5_RX_HASH_SRC_PORT_UDP | |
Maor Gottlieb | 4e2b53a | 2017-12-24 14:51:25 +0200 | [diff] [blame] | 932 | MLX5_RX_HASH_DST_PORT_UDP | |
| 933 | MLX5_RX_HASH_INNER; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 934 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
| 935 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 936 | resp.rss_caps.rx_hash_fields_mask |= |
| 937 | MLX5_RX_HASH_IPSEC_SPI; |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 938 | resp.response_length += sizeof(resp.rss_caps); |
| 939 | } |
| 940 | } else { |
| 941 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) |
| 942 | resp.response_length += sizeof(resp.tso_caps); |
| 943 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) |
| 944 | resp.response_length += sizeof(resp.rss_caps); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 945 | } |
| 946 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 947 | if (MLX5_CAP_GEN(mdev, ipoib_basic_offloads)) { |
| 948 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 949 | props->device_cap_flags |= IB_DEVICE_UD_TSO; |
| 950 | } |
| 951 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 952 | if (MLX5_CAP_GEN(dev->mdev, rq_delay_drop) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 953 | MLX5_CAP_GEN(dev->mdev, general_notification_event) && |
| 954 | raw_support) |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 955 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_DELAY_DROP; |
| 956 | |
Yishai Hadas | 1d54f89 | 2017-06-08 16:15:11 +0300 | [diff] [blame] | 957 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
| 958 | MLX5_CAP_IPOIB_ENHANCED(mdev, csum_cap)) |
| 959 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 960 | |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 961 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 962 | MLX5_CAP_ETH(dev->mdev, scatter_fcs) && |
| 963 | raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 964 | /* Legacy bit to support old userspace libraries */ |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 965 | props->device_cap_flags |= IB_DEVICE_RAW_SCATTER_FCS; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 966 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_SCATTER_FCS; |
| 967 | } |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 968 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 969 | if (MLX5_CAP_DEV_MEM(mdev, memic)) { |
| 970 | props->max_dm_size = |
| 971 | MLX5_CAP_DEV_MEM(mdev, max_memic_size); |
| 972 | } |
| 973 | |
Maor Gottlieb | da6d6ba3 | 2016-06-04 15:15:28 +0300 | [diff] [blame] | 974 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_BYPASS)) |
| 975 | props->device_cap_flags |= IB_DEVICE_MANAGED_FLOW_STEERING; |
| 976 | |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 977 | if (MLX5_CAP_GEN(mdev, end_pad)) |
| 978 | props->device_cap_flags |= IB_DEVICE_PCI_WRITE_END_PADDING; |
| 979 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 980 | props->vendor_part_id = mdev->pdev->device; |
| 981 | props->hw_ver = mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 982 | |
| 983 | props->max_mr_size = ~0ull; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 984 | props->page_size_cap = ~(min_page_size - 1); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 985 | props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp); |
| 986 | props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
| 987 | max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) / |
| 988 | sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 989 | max_sq_desc = min_t(int, MLX5_CAP_GEN(mdev, max_wqe_sz_sq), 512); |
| 990 | max_sq_sg = (max_sq_desc - sizeof(struct mlx5_wqe_ctrl_seg) - |
| 991 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 992 | sizeof(struct mlx5_wqe_data_seg); |
Steve Wise | 33023fb | 2018-06-18 08:05:26 -0700 | [diff] [blame] | 993 | props->max_send_sge = max_sq_sg; |
| 994 | props->max_recv_sge = max_rq_sg; |
Sagi Grimberg | 986ef95 | 2016-03-31 19:03:25 +0300 | [diff] [blame] | 995 | props->max_sge_rd = MLX5_MAX_SGE_RD; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 996 | props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq); |
Leon Romanovsky | 9f17768 | 2016-01-14 08:11:40 +0200 | [diff] [blame] | 997 | 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] | 998 | props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
| 999 | props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd); |
| 1000 | props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp); |
| 1001 | props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp); |
| 1002 | props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq); |
| 1003 | props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1; |
| 1004 | 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] | 1005 | 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] | 1006 | props->max_srq_sge = max_rq_sg - 1; |
Sagi Grimberg | 911f433 | 2016-03-03 13:37:51 +0200 | [diff] [blame] | 1007 | props->max_fast_reg_page_list_len = |
| 1008 | 1 << MLX5_CAP_GEN(mdev, log_max_klm_list_size); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 1009 | get_atomic_caps_qp(dev, props); |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 1010 | props->masked_atomic_cap = IB_ATOMIC_NONE; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1011 | props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg); |
| 1012 | props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1013 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 1014 | props->max_mcast_grp; |
| 1015 | props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */ |
Maor Gottlieb | 86695a6 | 2016-10-27 16:36:38 +0300 | [diff] [blame] | 1016 | props->max_ah = INT_MAX; |
Matan Barak | 7c60bcb | 2015-12-15 20:30:11 +0200 | [diff] [blame] | 1017 | props->hca_core_clock = MLX5_CAP_GEN(mdev, device_frequency_khz); |
| 1018 | props->timestamp_mask = 0x7FFFFFFFFFFFFFFFULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1019 | |
Leon Romanovsky | e502b8b | 2019-01-08 16:07:24 +0200 | [diff] [blame] | 1020 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
| 1021 | if (MLX5_CAP_GEN(mdev, pg)) |
| 1022 | props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
| 1023 | props->odp_caps = dev->odp_caps; |
| 1024 | } |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 1025 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 1026 | if (MLX5_CAP_GEN(mdev, cd)) |
| 1027 | props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL; |
| 1028 | |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 1029 | if (!mlx5_core_is_pf(mdev)) |
| 1030 | props->device_cap_flags |= IB_DEVICE_VIRTUAL_FUNCTION; |
| 1031 | |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 1032 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1033 | IB_LINK_LAYER_ETHERNET && raw_support) { |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 1034 | props->rss_caps.max_rwq_indirection_tables = |
| 1035 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt); |
| 1036 | props->rss_caps.max_rwq_indirection_table_size = |
| 1037 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt_size); |
| 1038 | props->rss_caps.supported_qpts = 1 << IB_QPT_RAW_PACKET; |
| 1039 | props->max_wq_type_rq = |
| 1040 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rq); |
| 1041 | } |
| 1042 | |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1043 | if (MLX5_CAP_GEN(mdev, tag_matching)) { |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1044 | props->tm_caps.max_rndv_hdr_size = MLX5_TM_MAX_RNDV_MSG_SIZE; |
| 1045 | props->tm_caps.max_num_tags = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1046 | (1 << MLX5_CAP_GEN(mdev, log_tag_matching_list_sz)) - 1; |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1047 | props->tm_caps.flags = IB_TM_CAP_RC; |
| 1048 | props->tm_caps.max_ops = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1049 | 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 1050 | props->tm_caps.max_sge = MLX5_TM_MAX_SGE; |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 1051 | } |
| 1052 | |
Yonatan Cohen | 87ab3f5 | 2017-11-13 10:51:18 +0200 | [diff] [blame] | 1053 | if (MLX5_CAP_GEN(dev->mdev, cq_moderation)) { |
| 1054 | props->cq_caps.max_cq_moderation_count = |
| 1055 | MLX5_MAX_CQ_COUNT; |
| 1056 | props->cq_caps.max_cq_moderation_period = |
| 1057 | MLX5_MAX_CQ_PERIOD; |
| 1058 | } |
| 1059 | |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1060 | if (field_avail(typeof(resp), cqe_comp_caps, uhw->outlen)) { |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1061 | resp.response_length += sizeof(resp.cqe_comp_caps); |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 1062 | |
| 1063 | if (MLX5_CAP_GEN(dev->mdev, cqe_compression)) { |
| 1064 | resp.cqe_comp_caps.max_num = |
| 1065 | MLX5_CAP_GEN(dev->mdev, |
| 1066 | cqe_compression_max_num); |
| 1067 | |
| 1068 | resp.cqe_comp_caps.supported_format = |
| 1069 | MLX5_IB_CQE_RES_FORMAT_HASH | |
| 1070 | MLX5_IB_CQE_RES_FORMAT_CSUM; |
Yonatan Cohen | 6f1006a | 2018-05-27 13:42:34 +0300 | [diff] [blame] | 1071 | |
| 1072 | if (MLX5_CAP_GEN(dev->mdev, mini_cqe_resp_stride_index)) |
| 1073 | resp.cqe_comp_caps.supported_format |= |
| 1074 | MLX5_IB_CQE_RES_FORMAT_CSUM_STRIDX; |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 1075 | } |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 1076 | } |
| 1077 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1078 | if (field_avail(typeof(resp), packet_pacing_caps, uhw->outlen) && |
| 1079 | raw_support) { |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 1080 | if (MLX5_CAP_QOS(mdev, packet_pacing) && |
| 1081 | MLX5_CAP_GEN(mdev, qos)) { |
| 1082 | resp.packet_pacing_caps.qp_rate_limit_max = |
| 1083 | MLX5_CAP_QOS(mdev, packet_pacing_max_rate); |
| 1084 | resp.packet_pacing_caps.qp_rate_limit_min = |
| 1085 | MLX5_CAP_QOS(mdev, packet_pacing_min_rate); |
| 1086 | resp.packet_pacing_caps.supported_qpts |= |
| 1087 | 1 << IB_QPT_RAW_PACKET; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 1088 | if (MLX5_CAP_QOS(mdev, packet_pacing_burst_bound) && |
| 1089 | MLX5_CAP_QOS(mdev, packet_pacing_typical_size)) |
| 1090 | resp.packet_pacing_caps.cap_flags |= |
| 1091 | MLX5_IB_PP_SUPPORT_BURST; |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 1092 | } |
| 1093 | resp.response_length += sizeof(resp.packet_pacing_caps); |
| 1094 | } |
| 1095 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1096 | if (field_avail(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes, |
| 1097 | uhw->outlen)) { |
Bodong Wang | 795b609 | 2017-08-17 15:52:34 +0300 | [diff] [blame] | 1098 | if (MLX5_CAP_ETH(mdev, multi_pkt_send_wqe)) |
| 1099 | resp.mlx5_ib_support_multi_pkt_send_wqes = |
| 1100 | MLX5_IB_ALLOW_MPW; |
Bodong Wang | 050da90 | 2017-08-17 15:52:35 +0300 | [diff] [blame] | 1101 | |
| 1102 | if (MLX5_CAP_ETH(mdev, enhanced_multi_pkt_send_wqe)) |
| 1103 | resp.mlx5_ib_support_multi_pkt_send_wqes |= |
| 1104 | MLX5_IB_SUPPORT_EMPW; |
| 1105 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1106 | resp.response_length += |
| 1107 | sizeof(resp.mlx5_ib_support_multi_pkt_send_wqes); |
| 1108 | } |
| 1109 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1110 | if (field_avail(typeof(resp), flags, uhw->outlen)) { |
| 1111 | resp.response_length += sizeof(resp.flags); |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1112 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1113 | if (MLX5_CAP_GEN(mdev, cqe_compression_128)) |
| 1114 | resp.flags |= |
| 1115 | MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_COMP; |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1116 | |
| 1117 | if (MLX5_CAP_GEN(mdev, cqe_128_always)) |
| 1118 | resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_PAD; |
Danit Goldberg | 7e11b91 | 2018-11-30 13:22:06 +0200 | [diff] [blame] | 1119 | if (MLX5_CAP_GEN(mdev, qp_packet_based)) |
| 1120 | resp.flags |= |
| 1121 | MLX5_IB_QUERY_DEV_RESP_PACKET_BASED_CREDIT_MODE; |
Guy Levi | 7249c8e | 2019-04-10 10:59:45 +0300 | [diff] [blame] | 1122 | |
| 1123 | resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_SCAT2CQE_DCT; |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1124 | } |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1125 | |
Noa Osherovich | 96dc3fc | 2017-08-17 15:52:28 +0300 | [diff] [blame] | 1126 | if (field_avail(typeof(resp), sw_parsing_caps, |
| 1127 | uhw->outlen)) { |
| 1128 | resp.response_length += sizeof(resp.sw_parsing_caps); |
| 1129 | if (MLX5_CAP_ETH(mdev, swp)) { |
| 1130 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1131 | MLX5_IB_SW_PARSING; |
| 1132 | |
| 1133 | if (MLX5_CAP_ETH(mdev, swp_csum)) |
| 1134 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1135 | MLX5_IB_SW_PARSING_CSUM; |
| 1136 | |
| 1137 | if (MLX5_CAP_ETH(mdev, swp_lso)) |
| 1138 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1139 | MLX5_IB_SW_PARSING_LSO; |
| 1140 | |
| 1141 | if (resp.sw_parsing_caps.sw_parsing_offloads) |
| 1142 | resp.sw_parsing_caps.supported_qpts = |
| 1143 | BIT(IB_QPT_RAW_PACKET); |
| 1144 | } |
| 1145 | } |
| 1146 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1147 | if (field_avail(typeof(resp), striding_rq_caps, uhw->outlen) && |
| 1148 | raw_support) { |
Noa Osherovich | b4f3459 | 2017-10-17 18:01:12 +0300 | [diff] [blame] | 1149 | resp.response_length += sizeof(resp.striding_rq_caps); |
| 1150 | if (MLX5_CAP_GEN(mdev, striding_rq)) { |
| 1151 | resp.striding_rq_caps.min_single_stride_log_num_of_bytes = |
| 1152 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1153 | resp.striding_rq_caps.max_single_stride_log_num_of_bytes = |
| 1154 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1155 | resp.striding_rq_caps.min_single_wqe_log_num_of_strides = |
| 1156 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1157 | resp.striding_rq_caps.max_single_wqe_log_num_of_strides = |
| 1158 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1159 | resp.striding_rq_caps.supported_qpts = |
| 1160 | BIT(IB_QPT_RAW_PACKET); |
| 1161 | } |
| 1162 | } |
| 1163 | |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1164 | if (field_avail(typeof(resp), tunnel_offloads_caps, |
| 1165 | uhw->outlen)) { |
| 1166 | resp.response_length += sizeof(resp.tunnel_offloads_caps); |
| 1167 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan)) |
| 1168 | resp.tunnel_offloads_caps |= |
| 1169 | MLX5_IB_TUNNELED_OFFLOADS_VXLAN; |
| 1170 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_geneve_rx)) |
| 1171 | resp.tunnel_offloads_caps |= |
| 1172 | MLX5_IB_TUNNELED_OFFLOADS_GENEVE; |
| 1173 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_gre)) |
| 1174 | resp.tunnel_offloads_caps |= |
| 1175 | MLX5_IB_TUNNELED_OFFLOADS_GRE; |
Ariel Levkovich | e818e25 | 2018-05-13 14:33:35 +0300 | [diff] [blame] | 1176 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1177 | MLX5_FLEX_PROTO_CW_MPLS_GRE) |
| 1178 | resp.tunnel_offloads_caps |= |
| 1179 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_GRE; |
| 1180 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1181 | MLX5_FLEX_PROTO_CW_MPLS_UDP) |
| 1182 | resp.tunnel_offloads_caps |= |
| 1183 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_UDP; |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1184 | } |
| 1185 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1186 | if (uhw->outlen) { |
| 1187 | err = ib_copy_to_udata(uhw, &resp, resp.response_length); |
| 1188 | |
| 1189 | if (err) |
| 1190 | return err; |
| 1191 | } |
| 1192 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1193 | return 0; |
| 1194 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1195 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1196 | enum mlx5_ib_width { |
| 1197 | MLX5_IB_WIDTH_1X = 1 << 0, |
| 1198 | MLX5_IB_WIDTH_2X = 1 << 1, |
| 1199 | MLX5_IB_WIDTH_4X = 1 << 2, |
| 1200 | MLX5_IB_WIDTH_8X = 1 << 3, |
| 1201 | MLX5_IB_WIDTH_12X = 1 << 4 |
| 1202 | }; |
| 1203 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1204 | static void translate_active_width(struct ib_device *ibdev, u8 active_width, |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1205 | u8 *ib_width) |
| 1206 | { |
| 1207 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1208 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1209 | if (active_width & MLX5_IB_WIDTH_1X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1210 | *ib_width = IB_WIDTH_1X; |
Michael Guralnik | d764970 | 2018-12-09 11:49:54 +0200 | [diff] [blame] | 1211 | else if (active_width & MLX5_IB_WIDTH_2X) |
| 1212 | *ib_width = IB_WIDTH_2X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1213 | else if (active_width & MLX5_IB_WIDTH_4X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1214 | *ib_width = IB_WIDTH_4X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1215 | else if (active_width & MLX5_IB_WIDTH_8X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1216 | *ib_width = IB_WIDTH_8X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1217 | else if (active_width & MLX5_IB_WIDTH_12X) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1218 | *ib_width = IB_WIDTH_12X; |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1219 | else { |
| 1220 | 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] | 1221 | (int)active_width); |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1222 | *ib_width = IB_WIDTH_4X; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1223 | } |
| 1224 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1225 | return; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | static int mlx5_mtu_to_ib_mtu(int mtu) |
| 1229 | { |
| 1230 | switch (mtu) { |
| 1231 | case 256: return 1; |
| 1232 | case 512: return 2; |
| 1233 | case 1024: return 3; |
| 1234 | case 2048: return 4; |
| 1235 | case 4096: return 5; |
| 1236 | default: |
| 1237 | pr_warn("invalid mtu\n"); |
| 1238 | return -1; |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | enum ib_max_vl_num { |
| 1243 | __IB_MAX_VL_0 = 1, |
| 1244 | __IB_MAX_VL_0_1 = 2, |
| 1245 | __IB_MAX_VL_0_3 = 3, |
| 1246 | __IB_MAX_VL_0_7 = 4, |
| 1247 | __IB_MAX_VL_0_14 = 5, |
| 1248 | }; |
| 1249 | |
| 1250 | enum mlx5_vl_hw_cap { |
| 1251 | MLX5_VL_HW_0 = 1, |
| 1252 | MLX5_VL_HW_0_1 = 2, |
| 1253 | MLX5_VL_HW_0_2 = 3, |
| 1254 | MLX5_VL_HW_0_3 = 4, |
| 1255 | MLX5_VL_HW_0_4 = 5, |
| 1256 | MLX5_VL_HW_0_5 = 6, |
| 1257 | MLX5_VL_HW_0_6 = 7, |
| 1258 | MLX5_VL_HW_0_7 = 8, |
| 1259 | MLX5_VL_HW_0_14 = 15 |
| 1260 | }; |
| 1261 | |
| 1262 | static int translate_max_vl_num(struct ib_device *ibdev, u8 vl_hw_cap, |
| 1263 | u8 *max_vl_num) |
| 1264 | { |
| 1265 | switch (vl_hw_cap) { |
| 1266 | case MLX5_VL_HW_0: |
| 1267 | *max_vl_num = __IB_MAX_VL_0; |
| 1268 | break; |
| 1269 | case MLX5_VL_HW_0_1: |
| 1270 | *max_vl_num = __IB_MAX_VL_0_1; |
| 1271 | break; |
| 1272 | case MLX5_VL_HW_0_3: |
| 1273 | *max_vl_num = __IB_MAX_VL_0_3; |
| 1274 | break; |
| 1275 | case MLX5_VL_HW_0_7: |
| 1276 | *max_vl_num = __IB_MAX_VL_0_7; |
| 1277 | break; |
| 1278 | case MLX5_VL_HW_0_14: |
| 1279 | *max_vl_num = __IB_MAX_VL_0_14; |
| 1280 | break; |
| 1281 | |
| 1282 | default: |
| 1283 | return -EINVAL; |
| 1284 | } |
| 1285 | |
| 1286 | return 0; |
| 1287 | } |
| 1288 | |
| 1289 | static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port, |
| 1290 | struct ib_port_attr *props) |
| 1291 | { |
| 1292 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1293 | struct mlx5_core_dev *mdev = dev->mdev; |
| 1294 | struct mlx5_hca_vport_context *rep; |
Saeed Mahameed | 046339e | 2016-04-22 00:33:03 +0300 | [diff] [blame] | 1295 | u16 max_mtu; |
| 1296 | u16 oper_mtu; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1297 | int err; |
| 1298 | u8 ib_link_width_oper; |
| 1299 | u8 vl_hw_cap; |
| 1300 | |
| 1301 | rep = kzalloc(sizeof(*rep), GFP_KERNEL); |
| 1302 | if (!rep) { |
| 1303 | err = -ENOMEM; |
| 1304 | goto out; |
| 1305 | } |
| 1306 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1307 | /* props being zeroed by the caller, avoid zeroing it here */ |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1308 | |
| 1309 | err = mlx5_query_hca_vport_context(mdev, 0, port, 0, rep); |
| 1310 | if (err) |
| 1311 | goto out; |
| 1312 | |
| 1313 | props->lid = rep->lid; |
| 1314 | props->lmc = rep->lmc; |
| 1315 | props->sm_lid = rep->sm_lid; |
| 1316 | props->sm_sl = rep->sm_sl; |
| 1317 | props->state = rep->vport_state; |
| 1318 | props->phys_state = rep->port_physical_state; |
| 1319 | props->port_cap_flags = rep->cap_mask1; |
| 1320 | props->gid_tbl_len = mlx5_get_gid_table_len(MLX5_CAP_GEN(mdev, gid_table_size)); |
| 1321 | props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg); |
| 1322 | props->pkey_tbl_len = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, pkey_table_size)); |
| 1323 | props->bad_pkey_cntr = rep->pkey_violation_counter; |
| 1324 | props->qkey_viol_cntr = rep->qkey_violation_counter; |
| 1325 | props->subnet_timeout = rep->subnet_timeout; |
| 1326 | props->init_type_reply = rep->init_type_reply; |
| 1327 | |
Michael Guralnik | 4106a75 | 2018-12-09 11:49:51 +0200 | [diff] [blame] | 1328 | if (props->port_cap_flags & IB_PORT_CAP_MASK2_SUP) |
| 1329 | props->port_cap_flags2 = rep->cap_mask2; |
| 1330 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1331 | err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); |
| 1332 | if (err) |
| 1333 | goto out; |
| 1334 | |
Michael Guralnik | db7a691 | 2018-11-21 15:03:54 +0200 | [diff] [blame] | 1335 | translate_active_width(ibdev, ib_link_width_oper, &props->active_width); |
| 1336 | |
Noa Osherovich | d5beb7f | 2016-06-02 10:47:53 +0300 | [diff] [blame] | 1337 | err = mlx5_query_port_ib_proto_oper(mdev, &props->active_speed, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1338 | if (err) |
| 1339 | goto out; |
| 1340 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1341 | mlx5_query_port_max_mtu(mdev, &max_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1342 | |
| 1343 | props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu); |
| 1344 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1345 | mlx5_query_port_oper_mtu(mdev, &oper_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1346 | |
| 1347 | props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu); |
| 1348 | |
| 1349 | err = mlx5_query_port_vl_hw_cap(mdev, &vl_hw_cap, port); |
| 1350 | if (err) |
| 1351 | goto out; |
| 1352 | |
| 1353 | err = translate_max_vl_num(ibdev, vl_hw_cap, |
| 1354 | &props->max_vl_num); |
| 1355 | out: |
| 1356 | kfree(rep); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1357 | return err; |
| 1358 | } |
| 1359 | |
| 1360 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 1361 | struct ib_port_attr *props) |
| 1362 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1363 | unsigned int count; |
| 1364 | int ret; |
| 1365 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1366 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1367 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1368 | ret = mlx5_query_mad_ifc_port(ibdev, port, props); |
| 1369 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1370 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1371 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1372 | ret = mlx5_query_hca_port(ibdev, port, props); |
| 1373 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1374 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1375 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1376 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1377 | break; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1378 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1379 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1380 | ret = -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1381 | } |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1382 | |
| 1383 | if (!ret && props) { |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1384 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1385 | struct mlx5_core_dev *mdev; |
| 1386 | bool put_mdev = true; |
| 1387 | |
| 1388 | mdev = mlx5_ib_get_native_port_mdev(dev, port, NULL); |
| 1389 | if (!mdev) { |
| 1390 | /* If the port isn't affiliated yet query the master. |
| 1391 | * The master and slave will have the same values. |
| 1392 | */ |
| 1393 | mdev = dev->mdev; |
| 1394 | port = 1; |
| 1395 | put_mdev = false; |
| 1396 | } |
| 1397 | count = mlx5_core_reserved_gids_count(mdev); |
| 1398 | if (put_mdev) |
| 1399 | mlx5_ib_put_native_port_mdev(dev, port); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1400 | props->gid_tbl_len -= count; |
| 1401 | } |
| 1402 | return ret; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1403 | } |
| 1404 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 1405 | static int mlx5_ib_rep_query_port(struct ib_device *ibdev, u8 port, |
| 1406 | struct ib_port_attr *props) |
| 1407 | { |
| 1408 | int ret; |
| 1409 | |
| 1410 | /* Only link layer == ethernet is valid for representors */ |
| 1411 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1412 | if (ret || !props) |
| 1413 | return ret; |
| 1414 | |
| 1415 | /* We don't support GIDS */ |
| 1416 | props->gid_tbl_len = 0; |
| 1417 | |
| 1418 | return ret; |
| 1419 | } |
| 1420 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1421 | static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 1422 | union ib_gid *gid) |
| 1423 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1424 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1425 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1426 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1427 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1428 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1429 | return mlx5_query_mad_ifc_gids(ibdev, port, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1430 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1431 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1432 | return mlx5_query_hca_vport_gid(mdev, 0, port, 0, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1433 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1434 | default: |
| 1435 | return -EINVAL; |
| 1436 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1437 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1438 | } |
| 1439 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1440 | static int mlx5_query_hca_nic_pkey(struct ib_device *ibdev, u8 port, |
| 1441 | u16 index, u16 *pkey) |
| 1442 | { |
| 1443 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1444 | struct mlx5_core_dev *mdev; |
| 1445 | bool put_mdev = true; |
| 1446 | u8 mdev_port_num; |
| 1447 | int err; |
| 1448 | |
| 1449 | mdev = mlx5_ib_get_native_port_mdev(dev, port, &mdev_port_num); |
| 1450 | if (!mdev) { |
| 1451 | /* The port isn't affiliated yet, get the PKey from the master |
| 1452 | * port. For RoCE the PKey tables will be the same. |
| 1453 | */ |
| 1454 | put_mdev = false; |
| 1455 | mdev = dev->mdev; |
| 1456 | mdev_port_num = 1; |
| 1457 | } |
| 1458 | |
| 1459 | err = mlx5_query_hca_vport_pkey(mdev, 0, mdev_port_num, 0, |
| 1460 | index, pkey); |
| 1461 | if (put_mdev) |
| 1462 | mlx5_ib_put_native_port_mdev(dev, port); |
| 1463 | |
| 1464 | return err; |
| 1465 | } |
| 1466 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1467 | static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 1468 | u16 *pkey) |
| 1469 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1470 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1471 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1472 | return mlx5_query_mad_ifc_pkey(ibdev, port, index, pkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1473 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1474 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1475 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1476 | return mlx5_query_hca_nic_pkey(ibdev, port, index, pkey); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1477 | default: |
| 1478 | return -EINVAL; |
| 1479 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1480 | } |
| 1481 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1482 | static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask, |
| 1483 | struct ib_device_modify *props) |
| 1484 | { |
| 1485 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1486 | struct mlx5_reg_node_desc in; |
| 1487 | struct mlx5_reg_node_desc out; |
| 1488 | int err; |
| 1489 | |
| 1490 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 1491 | return -EOPNOTSUPP; |
| 1492 | |
| 1493 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 1494 | return 0; |
| 1495 | |
| 1496 | /* |
| 1497 | * If possible, pass node desc to FW, so it can generate |
| 1498 | * a 144 trap. If cmd fails, just ignore. |
| 1499 | */ |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1500 | memcpy(&in, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1501 | err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1502 | sizeof(out), MLX5_REG_NODE_DESC, 0, 1); |
| 1503 | if (err) |
| 1504 | return err; |
| 1505 | |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1506 | memcpy(ibdev->node_desc, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1507 | |
| 1508 | return err; |
| 1509 | } |
| 1510 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1511 | static int set_port_caps_atomic(struct mlx5_ib_dev *dev, u8 port_num, u32 mask, |
| 1512 | u32 value) |
| 1513 | { |
| 1514 | struct mlx5_hca_vport_context ctx = {}; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1515 | struct mlx5_core_dev *mdev; |
| 1516 | u8 mdev_port_num; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1517 | int err; |
| 1518 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1519 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 1520 | if (!mdev) |
| 1521 | return -ENODEV; |
| 1522 | |
| 1523 | 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] | 1524 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1525 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1526 | |
| 1527 | if (~ctx.cap_mask1_perm & mask) { |
| 1528 | mlx5_ib_warn(dev, "trying to change bitmask 0x%X but change supported 0x%X\n", |
| 1529 | mask, ctx.cap_mask1_perm); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1530 | err = -EINVAL; |
| 1531 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | ctx.cap_mask1 = value; |
| 1535 | ctx.cap_mask1_perm = mask; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1536 | err = mlx5_core_modify_hca_vport_context(mdev, 0, mdev_port_num, |
| 1537 | 0, &ctx); |
| 1538 | |
| 1539 | out: |
| 1540 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1541 | |
| 1542 | return err; |
| 1543 | } |
| 1544 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1545 | static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 1546 | struct ib_port_modify *props) |
| 1547 | { |
| 1548 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1549 | struct ib_port_attr attr; |
| 1550 | u32 tmp; |
| 1551 | int err; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1552 | u32 change_mask; |
| 1553 | u32 value; |
| 1554 | bool is_ib = (mlx5_ib_port_link_layer(ibdev, port) == |
| 1555 | IB_LINK_LAYER_INFINIBAND); |
| 1556 | |
Majd Dibbiny | ec25587 | 2017-08-23 08:35:42 +0300 | [diff] [blame] | 1557 | /* CM layer calls ib_modify_port() regardless of the link layer. For |
| 1558 | * Ethernet ports, qkey violation and Port capabilities are meaningless. |
| 1559 | */ |
| 1560 | if (!is_ib) |
| 1561 | return 0; |
| 1562 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1563 | if (MLX5_CAP_GEN(dev->mdev, ib_virt) && is_ib) { |
| 1564 | change_mask = props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1565 | value = ~props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1566 | return set_port_caps_atomic(dev, port, change_mask, value); |
| 1567 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1568 | |
| 1569 | mutex_lock(&dev->cap_mask_mutex); |
| 1570 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1571 | err = ib_query_port(ibdev, port, &attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1572 | if (err) |
| 1573 | goto out; |
| 1574 | |
| 1575 | tmp = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 1576 | ~props->clr_port_cap_mask; |
| 1577 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1578 | err = mlx5_set_port_caps(dev->mdev, port, tmp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1579 | |
| 1580 | out: |
| 1581 | mutex_unlock(&dev->cap_mask_mutex); |
| 1582 | return err; |
| 1583 | } |
| 1584 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1585 | static void print_lib_caps(struct mlx5_ib_dev *dev, u64 caps) |
| 1586 | { |
| 1587 | mlx5_ib_dbg(dev, "MLX5_LIB_CAP_4K_UAR = %s\n", |
| 1588 | caps & MLX5_LIB_CAP_4K_UAR ? "y" : "n"); |
| 1589 | } |
| 1590 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1591 | static u16 calc_dynamic_bfregs(int uars_per_sys_page) |
| 1592 | { |
| 1593 | /* Large page with non 4k uar support might limit the dynamic size */ |
| 1594 | if (uars_per_sys_page == 1 && PAGE_SIZE > 4096) |
| 1595 | return MLX5_MIN_DYN_BFREGS; |
| 1596 | |
| 1597 | return MLX5_MAX_DYN_BFREGS; |
| 1598 | } |
| 1599 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1600 | static int calc_total_bfregs(struct mlx5_ib_dev *dev, bool lib_uar_4k, |
| 1601 | struct mlx5_ib_alloc_ucontext_req_v2 *req, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1602 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1603 | { |
| 1604 | int uars_per_sys_page; |
| 1605 | int bfregs_per_sys_page; |
| 1606 | int ref_bfregs = req->total_num_bfregs; |
| 1607 | |
| 1608 | if (req->total_num_bfregs == 0) |
| 1609 | return -EINVAL; |
| 1610 | |
| 1611 | BUILD_BUG_ON(MLX5_MAX_BFREGS % MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1612 | BUILD_BUG_ON(MLX5_MAX_BFREGS < MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1613 | |
| 1614 | if (req->total_num_bfregs > MLX5_MAX_BFREGS) |
| 1615 | return -ENOMEM; |
| 1616 | |
| 1617 | uars_per_sys_page = get_uars_per_sys_page(dev, lib_uar_4k); |
| 1618 | 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] | 1619 | /* This holds the required static allocation asked by the user */ |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1620 | 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] | 1621 | if (req->num_low_latency_bfregs > req->total_num_bfregs - 1) |
| 1622 | return -EINVAL; |
| 1623 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1624 | bfregi->num_static_sys_pages = req->total_num_bfregs / bfregs_per_sys_page; |
| 1625 | bfregi->num_dyn_bfregs = ALIGN(calc_dynamic_bfregs(uars_per_sys_page), bfregs_per_sys_page); |
| 1626 | bfregi->total_num_bfregs = req->total_num_bfregs + bfregi->num_dyn_bfregs; |
| 1627 | bfregi->num_sys_pages = bfregi->total_num_bfregs / bfregs_per_sys_page; |
| 1628 | |
| 1629 | 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] | 1630 | MLX5_CAP_GEN(dev->mdev, uar_4k) ? "yes" : "no", |
| 1631 | lib_uar_4k ? "yes" : "no", ref_bfregs, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1632 | req->total_num_bfregs, bfregi->total_num_bfregs, |
| 1633 | bfregi->num_sys_pages); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1634 | |
| 1635 | return 0; |
| 1636 | } |
| 1637 | |
| 1638 | static int allocate_uars(struct mlx5_ib_dev *dev, struct mlx5_ib_ucontext *context) |
| 1639 | { |
| 1640 | struct mlx5_bfreg_info *bfregi; |
| 1641 | int err; |
| 1642 | int i; |
| 1643 | |
| 1644 | bfregi = &context->bfregi; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1645 | for (i = 0; i < bfregi->num_static_sys_pages; i++) { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1646 | err = mlx5_cmd_alloc_uar(dev->mdev, &bfregi->sys_pages[i]); |
| 1647 | if (err) |
| 1648 | goto error; |
| 1649 | |
| 1650 | mlx5_ib_dbg(dev, "allocated uar %d\n", bfregi->sys_pages[i]); |
| 1651 | } |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1652 | |
| 1653 | for (i = bfregi->num_static_sys_pages; i < bfregi->num_sys_pages; i++) |
| 1654 | bfregi->sys_pages[i] = MLX5_IB_INVALID_UAR_INDEX; |
| 1655 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1656 | return 0; |
| 1657 | |
| 1658 | error: |
| 1659 | for (--i; i >= 0; i--) |
| 1660 | if (mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i])) |
| 1661 | mlx5_ib_warn(dev, "failed to free uar %d\n", i); |
| 1662 | |
| 1663 | return err; |
| 1664 | } |
| 1665 | |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1666 | static void deallocate_uars(struct mlx5_ib_dev *dev, |
| 1667 | struct mlx5_ib_ucontext *context) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1668 | { |
| 1669 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1670 | int i; |
| 1671 | |
| 1672 | bfregi = &context->bfregi; |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1673 | for (i = 0; i < bfregi->num_sys_pages; i++) |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1674 | if (i < bfregi->num_static_sys_pages || |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1675 | bfregi->sys_pages[i] != MLX5_IB_INVALID_UAR_INDEX) |
| 1676 | mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i]); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1677 | } |
| 1678 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1679 | 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] | 1680 | { |
| 1681 | int err = 0; |
| 1682 | |
| 1683 | mutex_lock(&dev->lb.mutex); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1684 | if (td) |
| 1685 | dev->lb.user_td++; |
| 1686 | if (qp) |
| 1687 | dev->lb.qps++; |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1688 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1689 | if (dev->lb.user_td == 2 || |
| 1690 | dev->lb.qps == 1) { |
| 1691 | if (!dev->lb.enabled) { |
| 1692 | err = mlx5_nic_vport_update_local_lb(dev->mdev, true); |
| 1693 | dev->lb.enabled = true; |
| 1694 | } |
| 1695 | } |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1696 | |
| 1697 | mutex_unlock(&dev->lb.mutex); |
| 1698 | |
| 1699 | return err; |
| 1700 | } |
| 1701 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1702 | 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] | 1703 | { |
| 1704 | mutex_lock(&dev->lb.mutex); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1705 | if (td) |
| 1706 | dev->lb.user_td--; |
| 1707 | if (qp) |
| 1708 | dev->lb.qps--; |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1709 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1710 | if (dev->lb.user_td == 1 && |
| 1711 | dev->lb.qps == 0) { |
| 1712 | if (dev->lb.enabled) { |
| 1713 | mlx5_nic_vport_update_local_lb(dev->mdev, false); |
| 1714 | dev->lb.enabled = false; |
| 1715 | } |
| 1716 | } |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 1717 | |
| 1718 | mutex_unlock(&dev->lb.mutex); |
| 1719 | } |
| 1720 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1721 | static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn, |
| 1722 | u16 uid) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1723 | { |
| 1724 | int err; |
| 1725 | |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1726 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1727 | return 0; |
| 1728 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1729 | err = mlx5_cmd_alloc_transport_domain(dev->mdev, tdn, uid); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1730 | if (err) |
| 1731 | return err; |
| 1732 | |
| 1733 | 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] | 1734 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1735 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1736 | return err; |
| 1737 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1738 | return mlx5_ib_enable_lb(dev, true, false); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1739 | } |
| 1740 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1741 | static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn, |
| 1742 | u16 uid) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1743 | { |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1744 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1745 | return; |
| 1746 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1747 | mlx5_cmd_dealloc_transport_domain(dev->mdev, tdn, uid); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1748 | |
| 1749 | 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] | 1750 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1751 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1752 | return; |
| 1753 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1754 | mlx5_ib_disable_lb(dev, true, false); |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1755 | } |
| 1756 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1757 | static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx, |
| 1758 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1759 | { |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1760 | struct ib_device *ibdev = uctx->device; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1761 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1762 | struct mlx5_ib_alloc_ucontext_req_v2 req = {}; |
| 1763 | struct mlx5_ib_alloc_ucontext_resp resp = {}; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1764 | struct mlx5_core_dev *mdev = dev->mdev; |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1765 | struct mlx5_ib_ucontext *context = to_mucontext(uctx); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1766 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1767 | int ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1768 | int err; |
Majd Dibbiny | a168a41c | 2016-01-28 17:51:47 +0200 | [diff] [blame] | 1769 | size_t min_req_v2 = offsetof(struct mlx5_ib_alloc_ucontext_req_v2, |
| 1770 | max_cqe_version); |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1771 | u32 dump_fill_mkey; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1772 | bool lib_uar_4k; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1773 | |
| 1774 | if (!dev->ib_active) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1775 | return -EAGAIN; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1776 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1777 | if (udata->inlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1778 | ver = 0; |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1779 | else if (udata->inlen >= min_req_v2) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1780 | ver = 2; |
| 1781 | else |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1782 | return -EINVAL; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1783 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1784 | err = ib_copy_from_udata(&req, udata, min(udata->inlen, sizeof(req))); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1785 | if (err) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1786 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1787 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1788 | if (req.flags & ~MLX5_IB_ALLOC_UCTX_DEVX) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1789 | return -EOPNOTSUPP; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1790 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1791 | if (req.comp_mask || req.reserved0 || req.reserved1 || req.reserved2) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1792 | return -EOPNOTSUPP; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1793 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1794 | req.total_num_bfregs = ALIGN(req.total_num_bfregs, |
| 1795 | MLX5_NON_FP_BFREGS_PER_UAR); |
| 1796 | if (req.num_low_latency_bfregs > req.total_num_bfregs - 1) |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1797 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1798 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1799 | 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] | 1800 | if (mlx5_core_is_pf(dev->mdev) && MLX5_CAP_GEN(dev->mdev, bf)) |
| 1801 | 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] | 1802 | resp.cache_line_size = cache_line_size(); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1803 | resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); |
| 1804 | resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); |
| 1805 | resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1806 | resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1807 | 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] | 1808 | resp.cqe_version = min_t(__u8, |
| 1809 | (__u8)MLX5_CAP_GEN(dev->mdev, cqe_version), |
| 1810 | req.max_cqe_version); |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1811 | resp.log_uar_size = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1812 | MLX5_ADAPTER_PAGE_SHIFT : PAGE_SHIFT; |
| 1813 | resp.num_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1814 | MLX5_CAP_GEN(dev->mdev, num_of_uars_per_page) : 1; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1815 | resp.response_length = min(offsetof(typeof(resp), response_length) + |
| 1816 | sizeof(resp.response_length), udata->outlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1817 | |
Matan Barak | c03faa5 | 2018-03-28 09:27:54 +0300 | [diff] [blame] | 1818 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_DEVICE) { |
| 1819 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_EGRESS)) |
| 1820 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM; |
| 1821 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_REQUIRED_METADATA) |
| 1822 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_REQ_METADATA; |
| 1823 | if (MLX5_CAP_FLOWTABLE(dev->mdev, flow_table_properties_nic_receive.ft_field_support.outer_esp_spi)) |
| 1824 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_SPI_STEERING; |
| 1825 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_TX_IV_IS_ESN) |
| 1826 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_TX_IV_IS_ESN; |
| 1827 | /* MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_FULL_OFFLOAD is currently always 0 */ |
| 1828 | } |
| 1829 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1830 | lib_uar_4k = req.lib_caps & MLX5_LIB_CAP_4K_UAR; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1831 | bfregi = &context->bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1832 | |
| 1833 | /* updates req->total_num_bfregs */ |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1834 | err = calc_total_bfregs(dev, lib_uar_4k, &req, bfregi); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1835 | if (err) |
| 1836 | goto out_ctx; |
| 1837 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1838 | mutex_init(&bfregi->lock); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1839 | bfregi->lib_uar_4k = lib_uar_4k; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1840 | bfregi->count = kcalloc(bfregi->total_num_bfregs, sizeof(*bfregi->count), |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1841 | GFP_KERNEL); |
| 1842 | if (!bfregi->count) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1843 | err = -ENOMEM; |
| 1844 | goto out_ctx; |
| 1845 | } |
| 1846 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1847 | bfregi->sys_pages = kcalloc(bfregi->num_sys_pages, |
| 1848 | sizeof(*bfregi->sys_pages), |
| 1849 | GFP_KERNEL); |
| 1850 | if (!bfregi->sys_pages) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1851 | err = -ENOMEM; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1852 | goto out_count; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1853 | } |
| 1854 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1855 | err = allocate_uars(dev, context); |
| 1856 | if (err) |
| 1857 | goto out_sys_pages; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1858 | |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 1859 | if (ibdev->attrs.device_cap_flags & IB_DEVICE_ON_DEMAND_PAGING) |
| 1860 | context->ibucontext.invalidate_range = |
| 1861 | &mlx5_ib_invalidate_range; |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 1862 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1863 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) { |
Yishai Hadas | fb98153 | 2018-11-26 08:28:36 +0200 | [diff] [blame] | 1864 | err = mlx5_ib_devx_create(dev, true); |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1865 | if (err < 0) |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1866 | goto out_uars; |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1867 | context->devx_uid = err; |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1868 | } |
| 1869 | |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1870 | err = mlx5_ib_alloc_transport_domain(dev, &context->tdn, |
| 1871 | context->devx_uid); |
| 1872 | if (err) |
| 1873 | goto out_devx; |
| 1874 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1875 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1876 | err = mlx5_cmd_dump_fill_mkey(dev->mdev, &dump_fill_mkey); |
| 1877 | if (err) |
Jason Gunthorpe | 8193abb | 2018-07-04 13:19:46 -0600 | [diff] [blame] | 1878 | goto out_mdev; |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1879 | } |
| 1880 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1881 | INIT_LIST_HEAD(&context->db_page_list); |
| 1882 | mutex_init(&context->db_page_mutex); |
| 1883 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1884 | resp.tot_bfregs = req.total_num_bfregs; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 1885 | resp.num_ports = dev->num_ports; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1886 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1887 | if (field_avail(typeof(resp), cqe_version, udata->outlen)) |
| 1888 | resp.response_length += sizeof(resp.cqe_version); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1889 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1890 | if (field_avail(typeof(resp), cmds_supp_uhw, udata->outlen)) { |
Moni Shoua | 6ad279c5 | 2016-11-23 08:23:23 +0200 | [diff] [blame] | 1891 | resp.cmds_supp_uhw |= MLX5_USER_CMDS_SUPP_UHW_QUERY_DEVICE | |
| 1892 | MLX5_USER_CMDS_SUPP_UHW_CREATE_AH; |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1893 | resp.response_length += sizeof(resp.cmds_supp_uhw); |
| 1894 | } |
| 1895 | |
Or Gerlitz | 7898489 | 2016-11-30 20:33:33 +0200 | [diff] [blame] | 1896 | if (field_avail(typeof(resp), eth_min_inline, udata->outlen)) { |
| 1897 | if (mlx5_ib_port_link_layer(ibdev, 1) == IB_LINK_LAYER_ETHERNET) { |
| 1898 | mlx5_query_min_inline(dev->mdev, &resp.eth_min_inline); |
| 1899 | resp.eth_min_inline++; |
| 1900 | } |
| 1901 | resp.response_length += sizeof(resp.eth_min_inline); |
| 1902 | } |
| 1903 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1904 | if (field_avail(typeof(resp), clock_info_versions, udata->outlen)) { |
| 1905 | if (mdev->clock_info) |
| 1906 | resp.clock_info_versions = BIT(MLX5_IB_CLOCK_INFO_V1); |
| 1907 | resp.response_length += sizeof(resp.clock_info_versions); |
| 1908 | } |
| 1909 | |
Noa Osherovich | bc5c6ee | 2016-06-04 15:15:31 +0300 | [diff] [blame] | 1910 | /* |
| 1911 | * We don't want to expose information from the PCI bar that is located |
| 1912 | * after 4096 bytes, so if the arch only supports larger pages, let's |
| 1913 | * pretend we don't support reading the HCA's core clock. This is also |
| 1914 | * forced by mmap function. |
| 1915 | */ |
Eli Cohen | de8d6e0 | 2017-01-03 23:55:19 +0200 | [diff] [blame] | 1916 | if (field_avail(typeof(resp), hca_core_clock_offset, udata->outlen)) { |
| 1917 | if (PAGE_SIZE <= 4096) { |
| 1918 | resp.comp_mask |= |
| 1919 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET; |
| 1920 | resp.hca_core_clock_offset = |
| 1921 | offsetof(struct mlx5_init_seg, internal_timer_h) % PAGE_SIZE; |
| 1922 | } |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1923 | resp.response_length += sizeof(resp.hca_core_clock_offset); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1924 | } |
| 1925 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1926 | if (field_avail(typeof(resp), log_uar_size, udata->outlen)) |
| 1927 | resp.response_length += sizeof(resp.log_uar_size); |
| 1928 | |
| 1929 | if (field_avail(typeof(resp), num_uars_per_page, udata->outlen)) |
| 1930 | resp.response_length += sizeof(resp.num_uars_per_page); |
| 1931 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1932 | if (field_avail(typeof(resp), num_dyn_bfregs, udata->outlen)) { |
| 1933 | resp.num_dyn_bfregs = bfregi->num_dyn_bfregs; |
| 1934 | resp.response_length += sizeof(resp.num_dyn_bfregs); |
| 1935 | } |
| 1936 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1937 | if (field_avail(typeof(resp), dump_fill_mkey, udata->outlen)) { |
| 1938 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1939 | resp.dump_fill_mkey = dump_fill_mkey; |
| 1940 | resp.comp_mask |= |
| 1941 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_DUMP_FILL_MKEY; |
| 1942 | } |
| 1943 | resp.response_length += sizeof(resp.dump_fill_mkey); |
| 1944 | } |
| 1945 | |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1946 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1947 | if (err) |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1948 | goto out_mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1949 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1950 | bfregi->ver = ver; |
| 1951 | bfregi->num_low_latency_bfregs = req.num_low_latency_bfregs; |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1952 | context->cqe_version = resp.cqe_version; |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1953 | context->lib_caps = req.lib_caps; |
| 1954 | print_lib_caps(dev, context->lib_caps); |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1955 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 1956 | if (dev->lag_active) { |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 1957 | u8 port = mlx5_core_native_port_num(dev->mdev); |
| 1958 | |
| 1959 | atomic_set(&context->tx_port_affinity, |
| 1960 | atomic_add_return( |
| 1961 | 1, &dev->roce[port].tx_port_affinity)); |
| 1962 | } |
| 1963 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1964 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1965 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1966 | out_mdev: |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1967 | mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid); |
| 1968 | out_devx: |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1969 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 1970 | mlx5_ib_devx_destroy(dev, context->devx_uid); |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1971 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1972 | out_uars: |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1973 | deallocate_uars(dev, context); |
| 1974 | |
| 1975 | out_sys_pages: |
| 1976 | kfree(bfregi->sys_pages); |
| 1977 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1978 | out_count: |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1979 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1980 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1981 | out_ctx: |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1982 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1983 | } |
| 1984 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1985 | static void mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1986 | { |
| 1987 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 1988 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1989 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1990 | |
Jason Gunthorpe | f27a0d5 | 2018-09-16 20:48:08 +0300 | [diff] [blame] | 1991 | /* All umem's must be destroyed before destroying the ucontext. */ |
| 1992 | mutex_lock(&ibcontext->per_mm_list_lock); |
| 1993 | WARN_ON(!list_empty(&ibcontext->per_mm_list)); |
| 1994 | mutex_unlock(&ibcontext->per_mm_list_lock); |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1995 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1996 | bfregi = &context->bfregi; |
Yishai Hadas | d2d1912 | 2018-09-20 21:39:32 +0300 | [diff] [blame] | 1997 | mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid); |
| 1998 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1999 | if (context->devx_uid) |
Yishai Hadas | 76dc5a8 | 2018-09-20 21:45:19 +0300 | [diff] [blame] | 2000 | mlx5_ib_devx_destroy(dev, context->devx_uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2001 | |
| 2002 | deallocate_uars(dev, context); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2003 | kfree(bfregi->sys_pages); |
| 2004 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, |
| 2008 | int uar_idx) |
| 2009 | { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2010 | int fw_uars_per_page; |
| 2011 | |
| 2012 | fw_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? MLX5_UARS_IN_PAGE : 1; |
| 2013 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2014 | return (pci_resource_start(dev->mdev->pdev, 0) >> PAGE_SHIFT) + uar_idx / fw_uars_per_page; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | static int get_command(unsigned long offset) |
| 2018 | { |
| 2019 | return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK; |
| 2020 | } |
| 2021 | |
| 2022 | static int get_arg(unsigned long offset) |
| 2023 | { |
| 2024 | return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1); |
| 2025 | } |
| 2026 | |
| 2027 | static int get_index(unsigned long offset) |
| 2028 | { |
| 2029 | return get_arg(offset); |
| 2030 | } |
| 2031 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2032 | /* Index resides in an extra byte to enable larger values than 255 */ |
| 2033 | static int get_extended_index(unsigned long offset) |
| 2034 | { |
| 2035 | return get_arg(offset) | ((offset >> 16) & 0xff) << 8; |
| 2036 | } |
| 2037 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2038 | |
| 2039 | static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) |
| 2040 | { |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2041 | } |
| 2042 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2043 | static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd) |
| 2044 | { |
| 2045 | switch (cmd) { |
| 2046 | case MLX5_IB_MMAP_WC_PAGE: |
| 2047 | return "WC"; |
| 2048 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2049 | return "best effort WC"; |
| 2050 | case MLX5_IB_MMAP_NC_PAGE: |
| 2051 | return "NC"; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2052 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2053 | return "Device Memory"; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2054 | default: |
| 2055 | return NULL; |
| 2056 | } |
| 2057 | } |
| 2058 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2059 | static int mlx5_ib_mmap_clock_info_page(struct mlx5_ib_dev *dev, |
| 2060 | struct vm_area_struct *vma, |
| 2061 | struct mlx5_ib_ucontext *context) |
| 2062 | { |
Jason Gunthorpe | 4eb6ab1 | 2019-04-16 14:07:30 +0300 | [diff] [blame^] | 2063 | if ((vma->vm_end - vma->vm_start != PAGE_SIZE) || |
| 2064 | !(vma->vm_flags & VM_SHARED)) |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2065 | return -EINVAL; |
| 2066 | |
| 2067 | if (get_index(vma->vm_pgoff) != MLX5_IB_CLOCK_INFO_V1) |
| 2068 | return -EOPNOTSUPP; |
| 2069 | |
Jason Gunthorpe | 4eb6ab1 | 2019-04-16 14:07:30 +0300 | [diff] [blame^] | 2070 | if (vma->vm_flags & (VM_WRITE | VM_EXEC)) |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2071 | return -EPERM; |
Jason Gunthorpe | 4eb6ab1 | 2019-04-16 14:07:30 +0300 | [diff] [blame^] | 2072 | vma->vm_flags &= ~(VM_MAYWRITE | VM_MAYEXEC); |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2073 | |
Jason Gunthorpe | ddcdc36 | 2019-04-16 14:07:29 +0300 | [diff] [blame] | 2074 | if (!dev->mdev->clock_info) |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2075 | return -EOPNOTSUPP; |
| 2076 | |
Jason Gunthorpe | 4eb6ab1 | 2019-04-16 14:07:30 +0300 | [diff] [blame^] | 2077 | return vm_insert_page(vma, vma->vm_start, |
| 2078 | virt_to_page(dev->mdev->clock_info)); |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2079 | } |
| 2080 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2081 | 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] | 2082 | struct vm_area_struct *vma, |
| 2083 | struct mlx5_ib_ucontext *context) |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2084 | { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2085 | struct mlx5_bfreg_info *bfregi = &context->bfregi; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2086 | int err; |
| 2087 | unsigned long idx; |
Kamal Heib | aa09ea6 | 2018-07-19 00:05:32 +0300 | [diff] [blame] | 2088 | phys_addr_t pfn; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2089 | pgprot_t prot; |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2090 | u32 bfreg_dyn_idx = 0; |
| 2091 | u32 uar_index; |
| 2092 | int dyn_uar = (cmd == MLX5_IB_MMAP_ALLOC_WC); |
| 2093 | int max_valid_idx = dyn_uar ? bfregi->num_sys_pages : |
| 2094 | bfregi->num_static_sys_pages; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2095 | |
| 2096 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2097 | return -EINVAL; |
| 2098 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2099 | if (dyn_uar) |
| 2100 | idx = get_extended_index(vma->vm_pgoff) + bfregi->num_static_sys_pages; |
| 2101 | else |
| 2102 | idx = get_index(vma->vm_pgoff); |
| 2103 | |
| 2104 | if (idx >= max_valid_idx) { |
| 2105 | mlx5_ib_warn(dev, "invalid uar index %lu, max=%d\n", |
| 2106 | idx, max_valid_idx); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2107 | return -EINVAL; |
| 2108 | } |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2109 | |
| 2110 | switch (cmd) { |
| 2111 | case MLX5_IB_MMAP_WC_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2112 | case MLX5_IB_MMAP_ALLOC_WC: |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2113 | /* Some architectures don't support WC memory */ |
| 2114 | #if defined(CONFIG_X86) |
| 2115 | if (!pat_enabled()) |
| 2116 | return -EPERM; |
| 2117 | #elif !(defined(CONFIG_PPC) || (defined(CONFIG_ARM) && defined(CONFIG_MMU))) |
| 2118 | return -EPERM; |
| 2119 | #endif |
| 2120 | /* fall through */ |
| 2121 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2122 | /* For MLX5_IB_MMAP_REGULAR_PAGE do the best effort to get WC */ |
| 2123 | prot = pgprot_writecombine(vma->vm_page_prot); |
| 2124 | break; |
| 2125 | case MLX5_IB_MMAP_NC_PAGE: |
| 2126 | prot = pgprot_noncached(vma->vm_page_prot); |
| 2127 | break; |
| 2128 | default: |
| 2129 | return -EINVAL; |
| 2130 | } |
| 2131 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2132 | if (dyn_uar) { |
| 2133 | int uars_per_page; |
| 2134 | |
| 2135 | uars_per_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k); |
| 2136 | bfreg_dyn_idx = idx * (uars_per_page * MLX5_NON_FP_BFREGS_PER_UAR); |
| 2137 | if (bfreg_dyn_idx >= bfregi->total_num_bfregs) { |
| 2138 | mlx5_ib_warn(dev, "invalid bfreg_dyn_idx %u, max=%u\n", |
| 2139 | bfreg_dyn_idx, bfregi->total_num_bfregs); |
| 2140 | return -EINVAL; |
| 2141 | } |
| 2142 | |
| 2143 | mutex_lock(&bfregi->lock); |
| 2144 | /* Fail if uar already allocated, first bfreg index of each |
| 2145 | * page holds its count. |
| 2146 | */ |
| 2147 | if (bfregi->count[bfreg_dyn_idx]) { |
| 2148 | mlx5_ib_warn(dev, "wrong offset, idx %lu is busy, bfregn=%u\n", idx, bfreg_dyn_idx); |
| 2149 | mutex_unlock(&bfregi->lock); |
| 2150 | return -EINVAL; |
| 2151 | } |
| 2152 | |
| 2153 | bfregi->count[bfreg_dyn_idx]++; |
| 2154 | mutex_unlock(&bfregi->lock); |
| 2155 | |
| 2156 | err = mlx5_cmd_alloc_uar(dev->mdev, &uar_index); |
| 2157 | if (err) { |
| 2158 | mlx5_ib_warn(dev, "UAR alloc failed\n"); |
| 2159 | goto free_bfreg; |
| 2160 | } |
| 2161 | } else { |
| 2162 | uar_index = bfregi->sys_pages[idx]; |
| 2163 | } |
| 2164 | |
| 2165 | pfn = uar_index2pfn(dev, uar_index); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2166 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn %pa\n", idx, &pfn); |
| 2167 | |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2168 | err = rdma_user_mmap_io(&context->ibucontext, vma, pfn, PAGE_SIZE, |
| 2169 | prot); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2170 | if (err) { |
Leon Romanovsky | 8f06228 | 2018-05-22 08:31:03 +0300 | [diff] [blame] | 2171 | mlx5_ib_err(dev, |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2172 | "rdma_user_mmap_io failed with error=%d, mmap_cmd=%s\n", |
Leon Romanovsky | 8f06228 | 2018-05-22 08:31:03 +0300 | [diff] [blame] | 2173 | err, mmap_cmd2str(cmd)); |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2174 | goto err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2175 | } |
| 2176 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2177 | if (dyn_uar) |
| 2178 | bfregi->sys_pages[idx] = uar_index; |
| 2179 | return 0; |
| 2180 | |
| 2181 | err: |
| 2182 | if (!dyn_uar) |
| 2183 | return err; |
| 2184 | |
| 2185 | mlx5_cmd_free_uar(dev->mdev, idx); |
| 2186 | |
| 2187 | free_bfreg: |
| 2188 | mlx5_ib_free_bfreg(dev, bfregi, bfreg_dyn_idx); |
| 2189 | |
| 2190 | return err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2191 | } |
| 2192 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2193 | static int dm_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
| 2194 | { |
| 2195 | struct mlx5_ib_ucontext *mctx = to_mucontext(context); |
| 2196 | struct mlx5_ib_dev *dev = to_mdev(context->device); |
| 2197 | u16 page_idx = get_extended_index(vma->vm_pgoff); |
| 2198 | size_t map_size = vma->vm_end - vma->vm_start; |
| 2199 | u32 npages = map_size >> PAGE_SHIFT; |
| 2200 | phys_addr_t pfn; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2201 | |
| 2202 | if (find_next_zero_bit(mctx->dm_pages, page_idx + npages, page_idx) != |
| 2203 | page_idx + npages) |
| 2204 | return -EINVAL; |
| 2205 | |
| 2206 | pfn = ((pci_resource_start(dev->mdev->pdev, 0) + |
| 2207 | MLX5_CAP64_DEV_MEM(dev->mdev, memic_bar_start_addr)) >> |
| 2208 | PAGE_SHIFT) + |
| 2209 | page_idx; |
Jason Gunthorpe | e2cd1d1 | 2018-09-16 20:43:10 +0300 | [diff] [blame] | 2210 | return rdma_user_mmap_io(context, vma, pfn, map_size, |
| 2211 | pgprot_writecombine(vma->vm_page_prot)); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2212 | } |
| 2213 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2214 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
| 2215 | { |
| 2216 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 2217 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2218 | unsigned long command; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2219 | phys_addr_t pfn; |
| 2220 | |
| 2221 | command = get_command(vma->vm_pgoff); |
| 2222 | switch (command) { |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2223 | case MLX5_IB_MMAP_WC_PAGE: |
| 2224 | case MLX5_IB_MMAP_NC_PAGE: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2225 | case MLX5_IB_MMAP_REGULAR_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2226 | case MLX5_IB_MMAP_ALLOC_WC: |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2227 | return uar_mmap(dev, command, vma, context); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2228 | |
| 2229 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
| 2230 | return -ENOSYS; |
| 2231 | |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2232 | case MLX5_IB_MMAP_CORE_CLOCK: |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2233 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2234 | return -EINVAL; |
| 2235 | |
Matan Barak | 6cbac1e | 2016-04-14 16:52:10 +0300 | [diff] [blame] | 2236 | if (vma->vm_flags & VM_WRITE) |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2237 | return -EPERM; |
Jason Gunthorpe | c660133 | 2019-04-16 14:07:25 +0300 | [diff] [blame] | 2238 | vma->vm_flags &= ~VM_MAYWRITE; |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2239 | |
| 2240 | /* Don't expose to user-space information it shouldn't have */ |
| 2241 | if (PAGE_SIZE > 4096) |
| 2242 | return -EOPNOTSUPP; |
| 2243 | |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2244 | pfn = (dev->mdev->iseg_base + |
| 2245 | offsetof(struct mlx5_init_seg, internal_timer_h)) >> |
| 2246 | PAGE_SHIFT; |
Jason Gunthorpe | d5e560d | 2019-04-16 14:07:26 +0300 | [diff] [blame] | 2247 | return rdma_user_mmap_io(&context->ibucontext, vma, pfn, |
| 2248 | PAGE_SIZE, |
| 2249 | pgprot_noncached(vma->vm_page_prot)); |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2250 | case MLX5_IB_MMAP_CLOCK_INFO: |
| 2251 | return mlx5_ib_mmap_clock_info_page(dev, vma, context); |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2252 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2253 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2254 | return dm_mmap(ibcontext, vma); |
| 2255 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2256 | default: |
| 2257 | return -EINVAL; |
| 2258 | } |
| 2259 | |
| 2260 | return 0; |
| 2261 | } |
| 2262 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2263 | struct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev, |
| 2264 | struct ib_ucontext *context, |
| 2265 | struct ib_dm_alloc_attr *attr, |
| 2266 | struct uverbs_attr_bundle *attrs) |
| 2267 | { |
| 2268 | u64 act_size = roundup(attr->length, MLX5_MEMIC_BASE_SIZE); |
| 2269 | struct mlx5_memic *memic = &to_mdev(ibdev)->memic; |
| 2270 | phys_addr_t memic_addr; |
| 2271 | struct mlx5_ib_dm *dm; |
| 2272 | u64 start_offset; |
| 2273 | u32 page_idx; |
| 2274 | int err; |
| 2275 | |
| 2276 | dm = kzalloc(sizeof(*dm), GFP_KERNEL); |
| 2277 | if (!dm) |
| 2278 | return ERR_PTR(-ENOMEM); |
| 2279 | |
| 2280 | mlx5_ib_dbg(to_mdev(ibdev), "alloc_memic req: user_length=0x%llx act_length=0x%llx log_alignment=%d\n", |
| 2281 | attr->length, act_size, attr->alignment); |
| 2282 | |
| 2283 | err = mlx5_cmd_alloc_memic(memic, &memic_addr, |
| 2284 | act_size, attr->alignment); |
| 2285 | if (err) |
| 2286 | goto err_free; |
| 2287 | |
| 2288 | start_offset = memic_addr & ~PAGE_MASK; |
| 2289 | page_idx = (memic_addr - pci_resource_start(memic->dev->pdev, 0) - |
| 2290 | MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
| 2291 | PAGE_SHIFT; |
| 2292 | |
| 2293 | err = uverbs_copy_to(attrs, |
| 2294 | MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 2295 | &start_offset, sizeof(start_offset)); |
| 2296 | if (err) |
| 2297 | goto err_dealloc; |
| 2298 | |
| 2299 | err = uverbs_copy_to(attrs, |
| 2300 | MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 2301 | &page_idx, sizeof(page_idx)); |
| 2302 | if (err) |
| 2303 | goto err_dealloc; |
| 2304 | |
| 2305 | bitmap_set(to_mucontext(context)->dm_pages, page_idx, |
| 2306 | DIV_ROUND_UP(act_size, PAGE_SIZE)); |
| 2307 | |
| 2308 | dm->dev_addr = memic_addr; |
| 2309 | |
| 2310 | return &dm->ibdm; |
| 2311 | |
| 2312 | err_dealloc: |
| 2313 | mlx5_cmd_dealloc_memic(memic, memic_addr, |
| 2314 | act_size); |
| 2315 | err_free: |
| 2316 | kfree(dm); |
| 2317 | return ERR_PTR(err); |
| 2318 | } |
| 2319 | |
| 2320 | int mlx5_ib_dealloc_dm(struct ib_dm *ibdm) |
| 2321 | { |
| 2322 | struct mlx5_memic *memic = &to_mdev(ibdm->device)->memic; |
| 2323 | struct mlx5_ib_dm *dm = to_mdm(ibdm); |
| 2324 | u64 act_size = roundup(dm->ibdm.length, MLX5_MEMIC_BASE_SIZE); |
| 2325 | u32 page_idx; |
| 2326 | int ret; |
| 2327 | |
| 2328 | ret = mlx5_cmd_dealloc_memic(memic, dm->dev_addr, act_size); |
| 2329 | if (ret) |
| 2330 | return ret; |
| 2331 | |
| 2332 | page_idx = (dm->dev_addr - pci_resource_start(memic->dev->pdev, 0) - |
| 2333 | MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
| 2334 | PAGE_SHIFT; |
| 2335 | bitmap_clear(to_mucontext(ibdm->uobject->context)->dm_pages, |
| 2336 | page_idx, |
| 2337 | DIV_ROUND_UP(act_size, PAGE_SIZE)); |
| 2338 | |
| 2339 | kfree(dm); |
| 2340 | |
| 2341 | return 0; |
| 2342 | } |
| 2343 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2344 | static int mlx5_ib_alloc_pd(struct ib_pd *ibpd, struct ib_ucontext *context, |
| 2345 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2346 | { |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2347 | struct mlx5_ib_pd *pd = to_mpd(ibpd); |
| 2348 | struct ib_device *ibdev = ibpd->device; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2349 | struct mlx5_ib_alloc_pd_resp resp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2350 | int err; |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2351 | u32 out[MLX5_ST_SZ_DW(alloc_pd_out)] = {}; |
| 2352 | u32 in[MLX5_ST_SZ_DW(alloc_pd_in)] = {}; |
| 2353 | u16 uid = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2354 | |
Yishai Hadas | 58895f0 | 2018-09-20 21:39:29 +0300 | [diff] [blame] | 2355 | uid = context ? to_mucontext(context)->devx_uid : 0; |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2356 | MLX5_SET(alloc_pd_in, in, opcode, MLX5_CMD_OP_ALLOC_PD); |
| 2357 | MLX5_SET(alloc_pd_in, in, uid, uid); |
| 2358 | err = mlx5_cmd_exec(to_mdev(ibdev)->mdev, in, sizeof(in), |
| 2359 | out, sizeof(out)); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2360 | if (err) |
| 2361 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2362 | |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2363 | pd->pdn = MLX5_GET(alloc_pd_out, out, pd); |
| 2364 | pd->uid = uid; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2365 | if (context) { |
| 2366 | resp.pdn = pd->pdn; |
| 2367 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2368 | mlx5_cmd_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn, uid); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2369 | return -EFAULT; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2370 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2371 | } |
| 2372 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2373 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2374 | } |
| 2375 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2376 | static void mlx5_ib_dealloc_pd(struct ib_pd *pd) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2377 | { |
| 2378 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 2379 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
| 2380 | |
Yishai Hadas | a1069c1 | 2018-09-20 21:39:19 +0300 | [diff] [blame] | 2381 | mlx5_cmd_dealloc_pd(mdev->mdev, mpd->pdn, mpd->uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2382 | } |
| 2383 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2384 | enum { |
| 2385 | MATCH_CRITERIA_ENABLE_OUTER_BIT, |
| 2386 | MATCH_CRITERIA_ENABLE_MISC_BIT, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2387 | MATCH_CRITERIA_ENABLE_INNER_BIT, |
| 2388 | MATCH_CRITERIA_ENABLE_MISC2_BIT |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2389 | }; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2390 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2391 | #define HEADER_IS_ZERO(match_criteria, headers) \ |
| 2392 | !(memchr_inv(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \ |
| 2393 | 0, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \ |
| 2394 | |
| 2395 | static u8 get_match_criteria_enable(u32 *match_criteria) |
| 2396 | { |
| 2397 | u8 match_criteria_enable; |
| 2398 | |
| 2399 | match_criteria_enable = |
| 2400 | (!HEADER_IS_ZERO(match_criteria, outer_headers)) << |
| 2401 | MATCH_CRITERIA_ENABLE_OUTER_BIT; |
| 2402 | match_criteria_enable |= |
| 2403 | (!HEADER_IS_ZERO(match_criteria, misc_parameters)) << |
| 2404 | MATCH_CRITERIA_ENABLE_MISC_BIT; |
| 2405 | match_criteria_enable |= |
| 2406 | (!HEADER_IS_ZERO(match_criteria, inner_headers)) << |
| 2407 | MATCH_CRITERIA_ENABLE_INNER_BIT; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2408 | match_criteria_enable |= |
| 2409 | (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) << |
| 2410 | MATCH_CRITERIA_ENABLE_MISC2_BIT; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2411 | |
| 2412 | return match_criteria_enable; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2413 | } |
| 2414 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2415 | 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] | 2416 | { |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2417 | u8 entry_mask; |
| 2418 | u8 entry_val; |
| 2419 | int err = 0; |
| 2420 | |
| 2421 | if (!mask) |
| 2422 | goto out; |
| 2423 | |
| 2424 | entry_mask = MLX5_GET(fte_match_set_lyr_2_4, outer_c, |
| 2425 | ip_protocol); |
| 2426 | entry_val = MLX5_GET(fte_match_set_lyr_2_4, outer_v, |
| 2427 | ip_protocol); |
| 2428 | if (!entry_mask) { |
| 2429 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_protocol, mask); |
| 2430 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_protocol, val); |
| 2431 | goto out; |
| 2432 | } |
| 2433 | /* Don't override existing ip protocol */ |
| 2434 | if (mask != entry_mask || val != entry_val) |
| 2435 | err = -EINVAL; |
| 2436 | out: |
| 2437 | return err; |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2438 | } |
| 2439 | |
Daria Velikovsky | 37da2a0 | 2018-05-07 10:20:02 +0300 | [diff] [blame] | 2440 | 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] | 2441 | bool inner) |
| 2442 | { |
| 2443 | if (inner) { |
| 2444 | MLX5_SET(fte_match_set_misc, |
| 2445 | misc_c, inner_ipv6_flow_label, mask); |
| 2446 | MLX5_SET(fte_match_set_misc, |
| 2447 | misc_v, inner_ipv6_flow_label, val); |
| 2448 | } else { |
| 2449 | MLX5_SET(fte_match_set_misc, |
| 2450 | misc_c, outer_ipv6_flow_label, mask); |
| 2451 | MLX5_SET(fte_match_set_misc, |
| 2452 | misc_v, outer_ipv6_flow_label, val); |
| 2453 | } |
| 2454 | } |
| 2455 | |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2456 | static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val) |
| 2457 | { |
| 2458 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_ecn, mask); |
| 2459 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_ecn, val); |
| 2460 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_dscp, mask >> 2); |
| 2461 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_dscp, val >> 2); |
| 2462 | } |
| 2463 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2464 | static int check_mpls_supp_fields(u32 field_support, const __be32 *set_mask) |
| 2465 | { |
| 2466 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_label) && |
| 2467 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_LABEL)) |
| 2468 | return -EOPNOTSUPP; |
| 2469 | |
| 2470 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_exp) && |
| 2471 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_EXP)) |
| 2472 | return -EOPNOTSUPP; |
| 2473 | |
| 2474 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_s_bos) && |
| 2475 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_S_BOS)) |
| 2476 | return -EOPNOTSUPP; |
| 2477 | |
| 2478 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_ttl) && |
| 2479 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_TTL)) |
| 2480 | return -EOPNOTSUPP; |
| 2481 | |
| 2482 | return 0; |
| 2483 | } |
| 2484 | |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2485 | #define LAST_ETH_FIELD vlan_tag |
| 2486 | #define LAST_IB_FIELD sl |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2487 | #define LAST_IPV4_FIELD tos |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2488 | #define LAST_IPV6_FIELD traffic_class |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2489 | #define LAST_TCP_UDP_FIELD src_port |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2490 | #define LAST_TUNNEL_FIELD tunnel_id |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2491 | #define LAST_FLOW_TAG_FIELD tag_id |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2492 | #define LAST_DROP_FIELD size |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2493 | #define LAST_COUNTERS_FIELD counters |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2494 | |
| 2495 | /* Field is the last supported field */ |
| 2496 | #define FIELDS_NOT_SUPPORTED(filter, field)\ |
| 2497 | memchr_inv((void *)&filter.field +\ |
| 2498 | sizeof(filter.field), 0,\ |
| 2499 | sizeof(filter) -\ |
| 2500 | offsetof(typeof(filter), field) -\ |
| 2501 | sizeof(filter.field)) |
| 2502 | |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2503 | int parse_flow_flow_action(struct mlx5_ib_flow_action *maction, |
| 2504 | bool is_egress, |
| 2505 | struct mlx5_flow_act *action) |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2506 | { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2507 | |
| 2508 | switch (maction->ib_action.type) { |
| 2509 | case IB_FLOW_ACTION_ESP: |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2510 | if (action->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 2511 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)) |
| 2512 | return -EINVAL; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2513 | /* Currently only AES_GCM keymat is supported by the driver */ |
| 2514 | action->esp_id = (uintptr_t)maction->esp_aes_gcm.ctx; |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2515 | action->action |= is_egress ? |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2516 | MLX5_FLOW_CONTEXT_ACTION_ENCRYPT : |
| 2517 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT; |
| 2518 | return 0; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2519 | case IB_FLOW_ACTION_UNSPECIFIED: |
| 2520 | if (maction->flow_action_raw.sub_type == |
| 2521 | MLX5_IB_FLOW_ACTION_MODIFY_HEADER) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2522 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) |
| 2523 | return -EINVAL; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2524 | action->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; |
| 2525 | action->modify_id = maction->flow_action_raw.action_id; |
| 2526 | return 0; |
| 2527 | } |
Mark Bloch | 10a3089 | 2018-09-02 12:51:34 +0300 | [diff] [blame] | 2528 | if (maction->flow_action_raw.sub_type == |
| 2529 | MLX5_IB_FLOW_ACTION_DECAP) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2530 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_DECAP) |
| 2531 | return -EINVAL; |
Mark Bloch | 10a3089 | 2018-09-02 12:51:34 +0300 | [diff] [blame] | 2532 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DECAP; |
| 2533 | return 0; |
| 2534 | } |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2535 | if (maction->flow_action_raw.sub_type == |
| 2536 | MLX5_IB_FLOW_ACTION_PACKET_REFORMAT) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2537 | if (action->action & |
| 2538 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT) |
| 2539 | return -EINVAL; |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2540 | action->action |= |
| 2541 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT; |
| 2542 | action->reformat_id = |
| 2543 | maction->flow_action_raw.action_id; |
| 2544 | return 0; |
| 2545 | } |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2546 | /* fall through */ |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2547 | default: |
| 2548 | return -EOPNOTSUPP; |
| 2549 | } |
| 2550 | } |
| 2551 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2552 | static int parse_flow_attr(struct mlx5_core_dev *mdev, u32 *match_c, |
| 2553 | u32 *match_v, const union ib_flow_spec *ib_spec, |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2554 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2555 | struct mlx5_flow_act *action, u32 prev_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2556 | { |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2557 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2558 | misc_parameters); |
| 2559 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2560 | misc_parameters); |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2561 | void *misc_params2_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2562 | misc_parameters_2); |
| 2563 | void *misc_params2_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2564 | misc_parameters_2); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2565 | void *headers_c; |
| 2566 | void *headers_v; |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2567 | int match_ipv; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2568 | int ret; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2569 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2570 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2571 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2572 | inner_headers); |
| 2573 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2574 | inner_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2575 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2576 | ft_field_support.inner_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2577 | } else { |
| 2578 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2579 | outer_headers); |
| 2580 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2581 | outer_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2582 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2583 | ft_field_support.outer_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2587 | case IB_FLOW_SPEC_ETH: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2588 | if (FIELDS_NOT_SUPPORTED(ib_spec->eth.mask, LAST_ETH_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2589 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2590 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2591 | 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] | 2592 | dmac_47_16), |
| 2593 | ib_spec->eth.mask.dst_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2594 | 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] | 2595 | dmac_47_16), |
| 2596 | ib_spec->eth.val.dst_mac); |
| 2597 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2598 | 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] | 2599 | smac_47_16), |
| 2600 | ib_spec->eth.mask.src_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2601 | 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] | 2602 | smac_47_16), |
| 2603 | ib_spec->eth.val.src_mac); |
| 2604 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2605 | if (ib_spec->eth.mask.vlan_tag) { |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2606 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2607 | cvlan_tag, 1); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2608 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2609 | cvlan_tag, 1); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2610 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2611 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2612 | first_vid, ntohs(ib_spec->eth.mask.vlan_tag)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2613 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2614 | first_vid, ntohs(ib_spec->eth.val.vlan_tag)); |
| 2615 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2616 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2617 | first_cfi, |
| 2618 | ntohs(ib_spec->eth.mask.vlan_tag) >> 12); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2619 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2620 | first_cfi, |
| 2621 | ntohs(ib_spec->eth.val.vlan_tag) >> 12); |
| 2622 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2623 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2624 | first_prio, |
| 2625 | ntohs(ib_spec->eth.mask.vlan_tag) >> 13); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2626 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2627 | first_prio, |
| 2628 | ntohs(ib_spec->eth.val.vlan_tag) >> 13); |
| 2629 | } |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2630 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2631 | ethertype, ntohs(ib_spec->eth.mask.ether_type)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2632 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2633 | ethertype, ntohs(ib_spec->eth.val.ether_type)); |
| 2634 | break; |
| 2635 | case IB_FLOW_SPEC_IPV4: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2636 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv4.mask, LAST_IPV4_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2637 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2638 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2639 | if (match_ipv) { |
| 2640 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2641 | ip_version, 0xf); |
| 2642 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2643 | ip_version, MLX5_FS_IPV4_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2644 | } else { |
| 2645 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2646 | ethertype, 0xffff); |
| 2647 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2648 | ethertype, ETH_P_IP); |
| 2649 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2650 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2651 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2652 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2653 | &ib_spec->ipv4.mask.src_ip, |
| 2654 | sizeof(ib_spec->ipv4.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2655 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2656 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2657 | &ib_spec->ipv4.val.src_ip, |
| 2658 | sizeof(ib_spec->ipv4.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2659 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2660 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2661 | &ib_spec->ipv4.mask.dst_ip, |
| 2662 | sizeof(ib_spec->ipv4.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2663 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2664 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2665 | &ib_spec->ipv4.val.dst_ip, |
| 2666 | sizeof(ib_spec->ipv4.val.dst_ip)); |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2667 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2668 | set_tos(headers_c, headers_v, |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2669 | ib_spec->ipv4.mask.tos, ib_spec->ipv4.val.tos); |
| 2670 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2671 | if (set_proto(headers_c, headers_v, |
| 2672 | ib_spec->ipv4.mask.proto, |
| 2673 | ib_spec->ipv4.val.proto)) |
| 2674 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2675 | break; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2676 | case IB_FLOW_SPEC_IPV6: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2677 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv6.mask, LAST_IPV6_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2678 | return -EOPNOTSUPP; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2679 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2680 | if (match_ipv) { |
| 2681 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2682 | ip_version, 0xf); |
| 2683 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2684 | ip_version, MLX5_FS_IPV6_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2685 | } else { |
| 2686 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2687 | ethertype, 0xffff); |
| 2688 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2689 | ethertype, ETH_P_IPV6); |
| 2690 | } |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2691 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2692 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2693 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2694 | &ib_spec->ipv6.mask.src_ip, |
| 2695 | sizeof(ib_spec->ipv6.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2696 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2697 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2698 | &ib_spec->ipv6.val.src_ip, |
| 2699 | sizeof(ib_spec->ipv6.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2700 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2701 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2702 | &ib_spec->ipv6.mask.dst_ip, |
| 2703 | sizeof(ib_spec->ipv6.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2704 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2705 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2706 | &ib_spec->ipv6.val.dst_ip, |
| 2707 | sizeof(ib_spec->ipv6.val.dst_ip)); |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2708 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2709 | set_tos(headers_c, headers_v, |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2710 | ib_spec->ipv6.mask.traffic_class, |
| 2711 | ib_spec->ipv6.val.traffic_class); |
| 2712 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2713 | if (set_proto(headers_c, headers_v, |
| 2714 | ib_spec->ipv6.mask.next_hdr, |
| 2715 | ib_spec->ipv6.val.next_hdr)) |
| 2716 | return -EINVAL; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2717 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2718 | set_flow_label(misc_params_c, misc_params_v, |
| 2719 | ntohl(ib_spec->ipv6.mask.flow_label), |
| 2720 | ntohl(ib_spec->ipv6.val.flow_label), |
| 2721 | ib_spec->type & IB_FLOW_SPEC_INNER); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2722 | break; |
| 2723 | case IB_FLOW_SPEC_ESP: |
| 2724 | if (ib_spec->esp.mask.seq) |
| 2725 | return -EOPNOTSUPP; |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2726 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2727 | MLX5_SET(fte_match_set_misc, misc_params_c, outer_esp_spi, |
| 2728 | ntohl(ib_spec->esp.mask.spi)); |
| 2729 | MLX5_SET(fte_match_set_misc, misc_params_v, outer_esp_spi, |
| 2730 | ntohl(ib_spec->esp.val.spi)); |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2731 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2732 | case IB_FLOW_SPEC_TCP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2733 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2734 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2735 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2736 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2737 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_TCP)) |
| 2738 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2739 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2740 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2741 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2742 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2743 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2744 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2745 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2746 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2747 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2748 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2749 | break; |
| 2750 | case IB_FLOW_SPEC_UDP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2751 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2752 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2753 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2754 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2755 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_UDP)) |
| 2756 | return -EINVAL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2757 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2758 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2759 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2760 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2761 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2762 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2763 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2764 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2765 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2766 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2767 | break; |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2768 | case IB_FLOW_SPEC_GRE: |
| 2769 | if (ib_spec->gre.mask.c_ks_res0_ver) |
| 2770 | return -EOPNOTSUPP; |
| 2771 | |
Maor Gottlieb | 6113cc4 | 2019-01-17 20:08:15 +0200 | [diff] [blame] | 2772 | if (set_proto(headers_c, headers_v, 0xff, IPPROTO_GRE)) |
| 2773 | return -EINVAL; |
| 2774 | |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2775 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
| 2776 | 0xff); |
| 2777 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
| 2778 | IPPROTO_GRE); |
| 2779 | |
| 2780 | MLX5_SET(fte_match_set_misc, misc_params_c, gre_protocol, |
Maor Gottlieb | a93b632 | 2018-07-01 15:50:17 +0300 | [diff] [blame] | 2781 | ntohs(ib_spec->gre.mask.protocol)); |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2782 | MLX5_SET(fte_match_set_misc, misc_params_v, gre_protocol, |
| 2783 | ntohs(ib_spec->gre.val.protocol)); |
| 2784 | |
| 2785 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_c, |
Oz Shlomo | 5886a96 | 2018-12-10 13:15:13 -0800 | [diff] [blame] | 2786 | gre_key.nvgre.hi), |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2787 | &ib_spec->gre.mask.key, |
| 2788 | sizeof(ib_spec->gre.mask.key)); |
| 2789 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_v, |
Oz Shlomo | 5886a96 | 2018-12-10 13:15:13 -0800 | [diff] [blame] | 2790 | gre_key.nvgre.hi), |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2791 | &ib_spec->gre.val.key, |
| 2792 | sizeof(ib_spec->gre.val.key)); |
| 2793 | break; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2794 | case IB_FLOW_SPEC_MPLS: |
| 2795 | switch (prev_type) { |
| 2796 | case IB_FLOW_SPEC_UDP: |
| 2797 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2798 | ft_field_support.outer_first_mpls_over_udp), |
| 2799 | &ib_spec->mpls.mask.tag)) |
| 2800 | return -EOPNOTSUPP; |
| 2801 | |
| 2802 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2803 | outer_first_mpls_over_udp), |
| 2804 | &ib_spec->mpls.val.tag, |
| 2805 | sizeof(ib_spec->mpls.val.tag)); |
| 2806 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2807 | outer_first_mpls_over_udp), |
| 2808 | &ib_spec->mpls.mask.tag, |
| 2809 | sizeof(ib_spec->mpls.mask.tag)); |
| 2810 | break; |
| 2811 | case IB_FLOW_SPEC_GRE: |
| 2812 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2813 | ft_field_support.outer_first_mpls_over_gre), |
| 2814 | &ib_spec->mpls.mask.tag)) |
| 2815 | return -EOPNOTSUPP; |
| 2816 | |
| 2817 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2818 | outer_first_mpls_over_gre), |
| 2819 | &ib_spec->mpls.val.tag, |
| 2820 | sizeof(ib_spec->mpls.val.tag)); |
| 2821 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2822 | outer_first_mpls_over_gre), |
| 2823 | &ib_spec->mpls.mask.tag, |
| 2824 | sizeof(ib_spec->mpls.mask.tag)); |
| 2825 | break; |
| 2826 | default: |
| 2827 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2828 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2829 | ft_field_support.inner_first_mpls), |
| 2830 | &ib_spec->mpls.mask.tag)) |
| 2831 | return -EOPNOTSUPP; |
| 2832 | |
| 2833 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2834 | inner_first_mpls), |
| 2835 | &ib_spec->mpls.val.tag, |
| 2836 | sizeof(ib_spec->mpls.val.tag)); |
| 2837 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2838 | inner_first_mpls), |
| 2839 | &ib_spec->mpls.mask.tag, |
| 2840 | sizeof(ib_spec->mpls.mask.tag)); |
| 2841 | } else { |
| 2842 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2843 | ft_field_support.outer_first_mpls), |
| 2844 | &ib_spec->mpls.mask.tag)) |
| 2845 | return -EOPNOTSUPP; |
| 2846 | |
| 2847 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2848 | outer_first_mpls), |
| 2849 | &ib_spec->mpls.val.tag, |
| 2850 | sizeof(ib_spec->mpls.val.tag)); |
| 2851 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2852 | outer_first_mpls), |
| 2853 | &ib_spec->mpls.mask.tag, |
| 2854 | sizeof(ib_spec->mpls.mask.tag)); |
| 2855 | } |
| 2856 | } |
| 2857 | break; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2858 | case IB_FLOW_SPEC_VXLAN_TUNNEL: |
| 2859 | if (FIELDS_NOT_SUPPORTED(ib_spec->tunnel.mask, |
| 2860 | LAST_TUNNEL_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2861 | return -EOPNOTSUPP; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2862 | |
| 2863 | MLX5_SET(fte_match_set_misc, misc_params_c, vxlan_vni, |
| 2864 | ntohl(ib_spec->tunnel.mask.tunnel_id)); |
| 2865 | MLX5_SET(fte_match_set_misc, misc_params_v, vxlan_vni, |
| 2866 | ntohl(ib_spec->tunnel.val.tunnel_id)); |
| 2867 | break; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2868 | case IB_FLOW_SPEC_ACTION_TAG: |
| 2869 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_tag, |
| 2870 | LAST_FLOW_TAG_FIELD)) |
| 2871 | return -EOPNOTSUPP; |
| 2872 | if (ib_spec->flow_tag.tag_id >= BIT(24)) |
| 2873 | return -EINVAL; |
| 2874 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 2875 | action->flow_tag = ib_spec->flow_tag.tag_id; |
Paul Blakey | d5634fe | 2018-09-20 12:17:48 +0200 | [diff] [blame] | 2876 | action->flags |= FLOW_ACT_HAS_TAG; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2877 | break; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2878 | case IB_FLOW_SPEC_ACTION_DROP: |
| 2879 | if (FIELDS_NOT_SUPPORTED(ib_spec->drop, |
| 2880 | LAST_DROP_FIELD)) |
| 2881 | return -EOPNOTSUPP; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 2882 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DROP; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2883 | break; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2884 | case IB_FLOW_SPEC_ACTION_HANDLE: |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2885 | ret = parse_flow_flow_action(to_mflow_act(ib_spec->action.act), |
| 2886 | flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS, action); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2887 | if (ret) |
| 2888 | return ret; |
| 2889 | break; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2890 | case IB_FLOW_SPEC_ACTION_COUNT: |
| 2891 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_count, |
| 2892 | LAST_COUNTERS_FIELD)) |
| 2893 | return -EOPNOTSUPP; |
| 2894 | |
| 2895 | /* for now support only one counters spec per flow */ |
| 2896 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) |
| 2897 | return -EINVAL; |
| 2898 | |
| 2899 | action->counters = ib_spec->flow_count.counters; |
| 2900 | action->action |= MLX5_FLOW_CONTEXT_ACTION_COUNT; |
| 2901 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2902 | default: |
| 2903 | return -EINVAL; |
| 2904 | } |
| 2905 | |
| 2906 | return 0; |
| 2907 | } |
| 2908 | |
| 2909 | /* If a flow could catch both multicast and unicast packets, |
| 2910 | * it won't fall into the multicast flow steering table and this rule |
| 2911 | * could steal other multicast packets. |
| 2912 | */ |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 2913 | 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] | 2914 | { |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2915 | union ib_flow_spec *flow_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2916 | |
| 2917 | if (ib_attr->type != IB_FLOW_ATTR_NORMAL || |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2918 | ib_attr->num_of_specs < 1) |
| 2919 | return false; |
| 2920 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2921 | flow_spec = (union ib_flow_spec *)(ib_attr + 1); |
| 2922 | if (flow_spec->type == IB_FLOW_SPEC_IPV4) { |
| 2923 | struct ib_flow_spec_ipv4 *ipv4_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2924 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2925 | ipv4_spec = (struct ib_flow_spec_ipv4 *)flow_spec; |
| 2926 | if (ipv4_is_multicast(ipv4_spec->val.dst_ip)) |
| 2927 | return true; |
| 2928 | |
| 2929 | return false; |
| 2930 | } |
| 2931 | |
| 2932 | if (flow_spec->type == IB_FLOW_SPEC_ETH) { |
| 2933 | struct ib_flow_spec_eth *eth_spec; |
| 2934 | |
| 2935 | eth_spec = (struct ib_flow_spec_eth *)flow_spec; |
| 2936 | return is_multicast_ether_addr(eth_spec->mask.dst_mac) && |
| 2937 | is_multicast_ether_addr(eth_spec->val.dst_mac); |
| 2938 | } |
| 2939 | |
| 2940 | return false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2941 | } |
| 2942 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2943 | enum valid_spec { |
| 2944 | VALID_SPEC_INVALID, |
| 2945 | VALID_SPEC_VALID, |
| 2946 | VALID_SPEC_NA, |
| 2947 | }; |
| 2948 | |
| 2949 | static enum valid_spec |
| 2950 | is_valid_esp_aes_gcm(struct mlx5_core_dev *mdev, |
| 2951 | const struct mlx5_flow_spec *spec, |
| 2952 | const struct mlx5_flow_act *flow_act, |
| 2953 | bool egress) |
| 2954 | { |
| 2955 | const u32 *match_c = spec->match_criteria; |
| 2956 | bool is_crypto = |
| 2957 | (flow_act->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 2958 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)); |
| 2959 | bool is_ipsec = mlx5_fs_is_ipsec_flow(match_c); |
| 2960 | bool is_drop = flow_act->action & MLX5_FLOW_CONTEXT_ACTION_DROP; |
| 2961 | |
| 2962 | /* |
| 2963 | * Currently only crypto is supported in egress, when regular egress |
| 2964 | * rules would be supported, always return VALID_SPEC_NA. |
| 2965 | */ |
| 2966 | if (!is_crypto) |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 2967 | return VALID_SPEC_NA; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2968 | |
| 2969 | return is_crypto && is_ipsec && |
Paul Blakey | d5634fe | 2018-09-20 12:17:48 +0200 | [diff] [blame] | 2970 | (!egress || (!is_drop && !(flow_act->flags & FLOW_ACT_HAS_TAG))) ? |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2971 | VALID_SPEC_VALID : VALID_SPEC_INVALID; |
| 2972 | } |
| 2973 | |
| 2974 | static bool is_valid_spec(struct mlx5_core_dev *mdev, |
| 2975 | const struct mlx5_flow_spec *spec, |
| 2976 | const struct mlx5_flow_act *flow_act, |
| 2977 | bool egress) |
| 2978 | { |
| 2979 | /* We curretly only support ipsec egress flow */ |
| 2980 | return is_valid_esp_aes_gcm(mdev, spec, flow_act, egress) != VALID_SPEC_INVALID; |
| 2981 | } |
| 2982 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2983 | static bool is_valid_ethertype(struct mlx5_core_dev *mdev, |
| 2984 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2985 | bool check_inner) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2986 | { |
| 2987 | 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] | 2988 | int match_ipv = check_inner ? |
| 2989 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2990 | ft_field_support.inner_ip_version) : |
| 2991 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2992 | ft_field_support.outer_ip_version); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2993 | int inner_bit = check_inner ? IB_FLOW_SPEC_INNER : 0; |
| 2994 | bool ipv4_spec_valid, ipv6_spec_valid; |
| 2995 | unsigned int ip_spec_type = 0; |
| 2996 | bool has_ethertype = false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2997 | unsigned int spec_index; |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2998 | bool mask_valid = true; |
| 2999 | u16 eth_type = 0; |
| 3000 | bool type_valid; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3001 | |
| 3002 | /* Validate that ethertype is correct */ |
| 3003 | 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] | 3004 | if ((ib_spec->type == (IB_FLOW_SPEC_ETH | inner_bit)) && |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3005 | ib_spec->eth.mask.ether_type) { |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3006 | mask_valid = (ib_spec->eth.mask.ether_type == |
| 3007 | htons(0xffff)); |
| 3008 | has_ethertype = true; |
| 3009 | eth_type = ntohs(ib_spec->eth.val.ether_type); |
| 3010 | } else if ((ib_spec->type == (IB_FLOW_SPEC_IPV4 | inner_bit)) || |
| 3011 | (ib_spec->type == (IB_FLOW_SPEC_IPV6 | inner_bit))) { |
| 3012 | ip_spec_type = ib_spec->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3013 | } |
| 3014 | ib_spec = (void *)ib_spec + ib_spec->size; |
| 3015 | } |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3016 | |
| 3017 | type_valid = (!has_ethertype) || (!ip_spec_type); |
| 3018 | if (!type_valid && mask_valid) { |
| 3019 | ipv4_spec_valid = (eth_type == ETH_P_IP) && |
| 3020 | (ip_spec_type == (IB_FLOW_SPEC_IPV4 | inner_bit)); |
| 3021 | ipv6_spec_valid = (eth_type == ETH_P_IPV6) && |
| 3022 | (ip_spec_type == (IB_FLOW_SPEC_IPV6 | inner_bit)); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3023 | |
| 3024 | type_valid = (ipv4_spec_valid) || (ipv6_spec_valid) || |
| 3025 | (((eth_type == ETH_P_MPLS_UC) || |
| 3026 | (eth_type == ETH_P_MPLS_MC)) && match_ipv); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | return type_valid; |
| 3030 | } |
| 3031 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3032 | static bool is_valid_attr(struct mlx5_core_dev *mdev, |
| 3033 | const struct ib_flow_attr *flow_attr) |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 3034 | { |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3035 | return is_valid_ethertype(mdev, flow_attr, false) && |
| 3036 | is_valid_ethertype(mdev, flow_attr, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | static void put_flow_table(struct mlx5_ib_dev *dev, |
| 3040 | struct mlx5_ib_flow_prio *prio, bool ft_added) |
| 3041 | { |
| 3042 | prio->refcount -= !!ft_added; |
| 3043 | if (!prio->refcount) { |
| 3044 | mlx5_destroy_flow_table(prio->flow_table); |
| 3045 | prio->flow_table = NULL; |
| 3046 | } |
| 3047 | } |
| 3048 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3049 | static void counters_clear_description(struct ib_counters *counters) |
| 3050 | { |
| 3051 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3052 | |
| 3053 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3054 | kfree(mcounters->counters_data); |
| 3055 | mcounters->counters_data = NULL; |
| 3056 | mcounters->cntrs_max_index = 0; |
| 3057 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3058 | } |
| 3059 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3060 | static int mlx5_ib_destroy_flow(struct ib_flow *flow_id) |
| 3061 | { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3062 | struct mlx5_ib_flow_handler *handler = container_of(flow_id, |
| 3063 | struct mlx5_ib_flow_handler, |
| 3064 | ibflow); |
| 3065 | struct mlx5_ib_flow_handler *iter, *tmp; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3066 | struct mlx5_ib_dev *dev = handler->dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3067 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3068 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3069 | |
| 3070 | list_for_each_entry_safe(iter, tmp, &handler->list, list) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3071 | mlx5_del_flow_rules(iter->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3072 | put_flow_table(dev, iter->prio, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3073 | list_del(&iter->list); |
| 3074 | kfree(iter); |
| 3075 | } |
| 3076 | |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3077 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3078 | put_flow_table(dev, handler->prio, true); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3079 | if (handler->ibcounters && |
| 3080 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3081 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3082 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3083 | mutex_unlock(&dev->flow_db->lock); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3084 | if (handler->flow_matcher) |
| 3085 | atomic_dec(&handler->flow_matcher->usecnt); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3086 | kfree(handler); |
| 3087 | |
| 3088 | return 0; |
| 3089 | } |
| 3090 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3091 | static int ib_prio_to_core_prio(unsigned int priority, bool dont_trap) |
| 3092 | { |
| 3093 | priority *= 2; |
| 3094 | if (!dont_trap) |
| 3095 | priority++; |
| 3096 | return priority; |
| 3097 | } |
| 3098 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3099 | enum flow_table_type { |
| 3100 | MLX5_IB_FT_RX, |
| 3101 | MLX5_IB_FT_TX |
| 3102 | }; |
| 3103 | |
Maor Gottlieb | 00b7c2a | 2017-03-29 06:09:01 +0300 | [diff] [blame] | 3104 | #define MLX5_FS_MAX_TYPES 6 |
| 3105 | #define MLX5_FS_MAX_ENTRIES BIT(16) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3106 | |
| 3107 | static struct mlx5_ib_flow_prio *_get_prio(struct mlx5_flow_namespace *ns, |
| 3108 | struct mlx5_ib_flow_prio *prio, |
| 3109 | int priority, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3110 | int num_entries, int num_groups, |
| 3111 | u32 flags) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3112 | { |
| 3113 | struct mlx5_flow_table *ft; |
| 3114 | |
| 3115 | ft = mlx5_create_auto_grouped_flow_table(ns, priority, |
| 3116 | num_entries, |
| 3117 | num_groups, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3118 | 0, flags); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3119 | if (IS_ERR(ft)) |
| 3120 | return ERR_CAST(ft); |
| 3121 | |
| 3122 | prio->flow_table = ft; |
| 3123 | prio->refcount = 0; |
| 3124 | return prio; |
| 3125 | } |
| 3126 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3127 | 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] | 3128 | struct ib_flow_attr *flow_attr, |
| 3129 | enum flow_table_type ft_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3130 | { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3131 | bool dont_trap = flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3132 | struct mlx5_flow_namespace *ns = NULL; |
| 3133 | struct mlx5_ib_flow_prio *prio; |
| 3134 | struct mlx5_flow_table *ft; |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3135 | int max_table_size; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3136 | int num_entries; |
| 3137 | int num_groups; |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3138 | u32 flags = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3139 | int priority; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3140 | |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3141 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3142 | log_max_ft_size)); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3143 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3144 | enum mlx5_flow_namespace_type fn_type; |
| 3145 | |
| 3146 | if (flow_is_multicast_only(flow_attr) && |
| 3147 | !dont_trap) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3148 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3149 | else |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3150 | priority = ib_prio_to_core_prio(flow_attr->priority, |
| 3151 | dont_trap); |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3152 | if (ft_type == MLX5_IB_FT_RX) { |
| 3153 | fn_type = MLX5_FLOW_NAMESPACE_BYPASS; |
| 3154 | prio = &dev->flow_db->prios[priority]; |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3155 | if (!dev->rep && |
| 3156 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, decap)) |
| 3157 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
Mark Bloch | 5c2db53 | 2018-09-02 12:51:35 +0300 | [diff] [blame] | 3158 | if (!dev->rep && |
| 3159 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3160 | reformat_l3_tunnel_to_l2)) |
| 3161 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3162 | } else { |
| 3163 | max_table_size = |
| 3164 | BIT(MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, |
| 3165 | log_max_ft_size)); |
| 3166 | fn_type = MLX5_FLOW_NAMESPACE_EGRESS; |
| 3167 | prio = &dev->flow_db->egress_prios[priority]; |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3168 | if (!dev->rep && |
| 3169 | MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, reformat)) |
| 3170 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3171 | } |
| 3172 | ns = mlx5_get_flow_namespace(dev->mdev, fn_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3173 | num_entries = MLX5_FS_MAX_ENTRIES; |
| 3174 | num_groups = MLX5_FS_MAX_TYPES; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3175 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3176 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3177 | ns = mlx5_get_flow_namespace(dev->mdev, |
| 3178 | MLX5_FLOW_NAMESPACE_LEFTOVERS); |
| 3179 | build_leftovers_ft_param(&priority, |
| 3180 | &num_entries, |
| 3181 | &num_groups); |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3182 | prio = &dev->flow_db->prios[MLX5_IB_FLOW_LEFTOVERS_PRIO]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3183 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3184 | if (!MLX5_CAP_FLOWTABLE(dev->mdev, |
| 3185 | allow_sniffer_and_nic_rx_shared_tir)) |
| 3186 | return ERR_PTR(-ENOTSUPP); |
| 3187 | |
| 3188 | ns = mlx5_get_flow_namespace(dev->mdev, ft_type == MLX5_IB_FT_RX ? |
| 3189 | MLX5_FLOW_NAMESPACE_SNIFFER_RX : |
| 3190 | MLX5_FLOW_NAMESPACE_SNIFFER_TX); |
| 3191 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3192 | prio = &dev->flow_db->sniffer[ft_type]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3193 | priority = 0; |
| 3194 | num_entries = 1; |
| 3195 | num_groups = 1; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | if (!ns) |
| 3199 | return ERR_PTR(-ENOTSUPP); |
| 3200 | |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3201 | if (num_entries > max_table_size) |
| 3202 | return ERR_PTR(-ENOMEM); |
| 3203 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3204 | ft = prio->flow_table; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3205 | if (!ft) |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3206 | return _get_prio(ns, prio, priority, num_entries, num_groups, |
| 3207 | flags); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3208 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3209 | return prio; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3210 | } |
| 3211 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3212 | static void set_underlay_qp(struct mlx5_ib_dev *dev, |
| 3213 | struct mlx5_flow_spec *spec, |
| 3214 | u32 underlay_qpn) |
| 3215 | { |
| 3216 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, |
| 3217 | spec->match_criteria, |
| 3218 | misc_parameters); |
| 3219 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3220 | misc_parameters); |
| 3221 | |
| 3222 | if (underlay_qpn && |
| 3223 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3224 | ft_field_support.bth_dst_qp)) { |
| 3225 | MLX5_SET(fte_match_set_misc, |
| 3226 | misc_params_v, bth_dst_qp, underlay_qpn); |
| 3227 | MLX5_SET(fte_match_set_misc, |
| 3228 | misc_params_c, bth_dst_qp, 0xffffff); |
| 3229 | } |
| 3230 | } |
| 3231 | |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3232 | static int read_flow_counters(struct ib_device *ibdev, |
| 3233 | struct mlx5_read_counters_attr *read_attr) |
| 3234 | { |
| 3235 | struct mlx5_fc *fc = read_attr->hw_cntrs_hndl; |
| 3236 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 3237 | |
| 3238 | return mlx5_fc_query(dev->mdev, fc, |
| 3239 | &read_attr->out[IB_COUNTER_PACKETS], |
| 3240 | &read_attr->out[IB_COUNTER_BYTES]); |
| 3241 | } |
| 3242 | |
| 3243 | /* flow counters currently expose two counters packets and bytes */ |
| 3244 | #define FLOW_COUNTERS_NUM 2 |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3245 | static int counters_set_description(struct ib_counters *counters, |
| 3246 | enum mlx5_ib_counters_type counters_type, |
| 3247 | struct mlx5_ib_flow_counters_desc *desc_data, |
| 3248 | u32 ncounters) |
| 3249 | { |
| 3250 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3251 | u32 cntrs_max_index = 0; |
| 3252 | int i; |
| 3253 | |
| 3254 | if (counters_type != MLX5_IB_COUNTERS_FLOW) |
| 3255 | return -EINVAL; |
| 3256 | |
| 3257 | /* init the fields for the object */ |
| 3258 | mcounters->type = counters_type; |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3259 | mcounters->read_counters = read_flow_counters; |
| 3260 | mcounters->counters_num = FLOW_COUNTERS_NUM; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3261 | mcounters->ncounters = ncounters; |
| 3262 | /* each counter entry have both description and index pair */ |
| 3263 | for (i = 0; i < ncounters; i++) { |
| 3264 | if (desc_data[i].description > IB_COUNTER_BYTES) |
| 3265 | return -EINVAL; |
| 3266 | |
| 3267 | if (cntrs_max_index <= desc_data[i].index) |
| 3268 | cntrs_max_index = desc_data[i].index + 1; |
| 3269 | } |
| 3270 | |
| 3271 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3272 | mcounters->counters_data = desc_data; |
| 3273 | mcounters->cntrs_max_index = cntrs_max_index; |
| 3274 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3275 | |
| 3276 | return 0; |
| 3277 | } |
| 3278 | |
| 3279 | #define MAX_COUNTERS_NUM (USHRT_MAX / (sizeof(u32) * 2)) |
| 3280 | static int flow_counters_set_data(struct ib_counters *ibcounters, |
| 3281 | struct mlx5_ib_create_flow *ucmd) |
| 3282 | { |
| 3283 | struct mlx5_ib_mcounters *mcounters = to_mcounters(ibcounters); |
| 3284 | struct mlx5_ib_flow_counters_data *cntrs_data = NULL; |
| 3285 | struct mlx5_ib_flow_counters_desc *desc_data = NULL; |
| 3286 | bool hw_hndl = false; |
| 3287 | int ret = 0; |
| 3288 | |
| 3289 | if (ucmd && ucmd->ncounters_data != 0) { |
| 3290 | cntrs_data = ucmd->data; |
| 3291 | if (cntrs_data->ncounters > MAX_COUNTERS_NUM) |
| 3292 | return -EINVAL; |
| 3293 | |
| 3294 | desc_data = kcalloc(cntrs_data->ncounters, |
| 3295 | sizeof(*desc_data), |
| 3296 | GFP_KERNEL); |
| 3297 | if (!desc_data) |
| 3298 | return -ENOMEM; |
| 3299 | |
| 3300 | if (copy_from_user(desc_data, |
| 3301 | u64_to_user_ptr(cntrs_data->counters_data), |
| 3302 | sizeof(*desc_data) * cntrs_data->ncounters)) { |
| 3303 | ret = -EFAULT; |
| 3304 | goto free; |
| 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | if (!mcounters->hw_cntrs_hndl) { |
| 3309 | mcounters->hw_cntrs_hndl = mlx5_fc_create( |
| 3310 | to_mdev(ibcounters->device)->mdev, false); |
weiyongjun (A) | e31abf7 | 2018-06-07 01:47:41 +0000 | [diff] [blame] | 3311 | if (IS_ERR(mcounters->hw_cntrs_hndl)) { |
| 3312 | ret = PTR_ERR(mcounters->hw_cntrs_hndl); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3313 | goto free; |
| 3314 | } |
| 3315 | hw_hndl = true; |
| 3316 | } |
| 3317 | |
| 3318 | if (desc_data) { |
| 3319 | /* counters already bound to at least one flow */ |
| 3320 | if (mcounters->cntrs_max_index) { |
| 3321 | ret = -EINVAL; |
| 3322 | goto free_hndl; |
| 3323 | } |
| 3324 | |
| 3325 | ret = counters_set_description(ibcounters, |
| 3326 | MLX5_IB_COUNTERS_FLOW, |
| 3327 | desc_data, |
| 3328 | cntrs_data->ncounters); |
| 3329 | if (ret) |
| 3330 | goto free_hndl; |
| 3331 | |
| 3332 | } else if (!mcounters->cntrs_max_index) { |
| 3333 | /* counters not bound yet, must have udata passed */ |
| 3334 | ret = -EINVAL; |
| 3335 | goto free_hndl; |
| 3336 | } |
| 3337 | |
| 3338 | return 0; |
| 3339 | |
| 3340 | free_hndl: |
| 3341 | if (hw_hndl) { |
| 3342 | mlx5_fc_destroy(to_mdev(ibcounters->device)->mdev, |
| 3343 | mcounters->hw_cntrs_hndl); |
| 3344 | mcounters->hw_cntrs_hndl = NULL; |
| 3345 | } |
| 3346 | free: |
| 3347 | kfree(desc_data); |
| 3348 | return ret; |
| 3349 | } |
| 3350 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3351 | static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev, |
| 3352 | struct mlx5_ib_flow_prio *ft_prio, |
| 3353 | const struct ib_flow_attr *flow_attr, |
| 3354 | struct mlx5_flow_destination *dst, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3355 | u32 underlay_qpn, |
| 3356 | struct mlx5_ib_create_flow *ucmd) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3357 | { |
| 3358 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3359 | struct mlx5_ib_flow_handler *handler; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3360 | struct mlx5_flow_act flow_act = {.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG}; |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3361 | struct mlx5_flow_spec *spec; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3362 | struct mlx5_flow_destination dest_arr[2] = {}; |
| 3363 | struct mlx5_flow_destination *rule_dst = dest_arr; |
Maor Gottlieb | dd063d0 | 2016-08-28 14:16:32 +0300 | [diff] [blame] | 3364 | const void *ib_flow = (const void *)flow_attr + sizeof(*flow_attr); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3365 | unsigned int spec_index; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3366 | u32 prev_type = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3367 | int err = 0; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3368 | int dest_num = 0; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3369 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3370 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3371 | if (!is_valid_attr(dev->mdev, flow_attr)) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3372 | return ERR_PTR(-EINVAL); |
| 3373 | |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3374 | if (dev->rep && is_egress) |
| 3375 | return ERR_PTR(-EINVAL); |
| 3376 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3377 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3378 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3379 | if (!handler || !spec) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3380 | err = -ENOMEM; |
| 3381 | goto free; |
| 3382 | } |
| 3383 | |
| 3384 | INIT_LIST_HEAD(&handler->list); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3385 | if (dst) { |
| 3386 | memcpy(&dest_arr[0], dst, sizeof(*dst)); |
| 3387 | dest_num++; |
| 3388 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3389 | |
| 3390 | for (spec_index = 0; spec_index < flow_attr->num_of_specs; spec_index++) { |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3391 | err = parse_flow_attr(dev->mdev, spec->match_criteria, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3392 | spec->match_value, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3393 | ib_flow, flow_attr, &flow_act, |
| 3394 | prev_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3395 | if (err < 0) |
| 3396 | goto free; |
| 3397 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3398 | prev_type = ((union ib_flow_spec *)ib_flow)->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3399 | ib_flow += ((union ib_flow_spec *)ib_flow)->size; |
| 3400 | } |
| 3401 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3402 | if (!flow_is_multicast_only(flow_attr)) |
| 3403 | set_underlay_qp(dev, spec, underlay_qpn); |
| 3404 | |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3405 | if (dev->rep) { |
| 3406 | void *misc; |
| 3407 | |
| 3408 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3409 | misc_parameters); |
| 3410 | MLX5_SET(fte_match_set_misc, misc, source_port, |
| 3411 | dev->rep->vport); |
| 3412 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
| 3413 | misc_parameters); |
| 3414 | MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port); |
| 3415 | } |
| 3416 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 3417 | spec->match_criteria_enable = get_match_criteria_enable(spec->match_criteria); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3418 | |
| 3419 | if (is_egress && |
| 3420 | !is_valid_spec(dev->mdev, spec, &flow_act, is_egress)) { |
| 3421 | err = -EINVAL; |
| 3422 | goto free; |
| 3423 | } |
| 3424 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3425 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3426 | struct mlx5_ib_mcounters *mcounters; |
| 3427 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3428 | err = flow_counters_set_data(flow_act.counters, ucmd); |
| 3429 | if (err) |
| 3430 | goto free; |
| 3431 | |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3432 | mcounters = to_mcounters(flow_act.counters); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3433 | handler->ibcounters = flow_act.counters; |
| 3434 | dest_arr[dest_num].type = |
| 3435 | MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
Mark Bloch | 171c7625b | 2018-10-03 00:03:35 +0000 | [diff] [blame] | 3436 | dest_arr[dest_num].counter_id = |
| 3437 | mlx5_fc_id(mcounters->hw_cntrs_hndl); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3438 | dest_num++; |
| 3439 | } |
| 3440 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3441 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DROP) { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3442 | if (!(flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT)) { |
| 3443 | rule_dst = NULL; |
| 3444 | dest_num = 0; |
| 3445 | } |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3446 | } else { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3447 | if (is_egress) |
| 3448 | flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
| 3449 | else |
| 3450 | flow_act.action |= |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3451 | dest_num ? MLX5_FLOW_CONTEXT_ACTION_FWD_DEST : |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3452 | MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3453 | } |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3454 | |
Paul Blakey | d5634fe | 2018-09-20 12:17:48 +0200 | [diff] [blame] | 3455 | if ((flow_act.flags & FLOW_ACT_HAS_TAG) && |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3456 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3457 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3458 | mlx5_ib_warn(dev, "Flow tag %u and attribute type %x isn't allowed in leftovers\n", |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3459 | flow_act.flow_tag, flow_attr->type); |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3460 | err = -EINVAL; |
| 3461 | goto free; |
| 3462 | } |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3463 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Hadar Hen Zion | 66958ed | 2016-11-07 15:14:45 +0200 | [diff] [blame] | 3464 | &flow_act, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3465 | rule_dst, dest_num); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3466 | |
| 3467 | if (IS_ERR(handler->rule)) { |
| 3468 | err = PTR_ERR(handler->rule); |
| 3469 | goto free; |
| 3470 | } |
| 3471 | |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3472 | ft_prio->refcount++; |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3473 | handler->prio = ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3474 | handler->dev = dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3475 | |
| 3476 | ft_prio->flow_table = ft; |
| 3477 | free: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3478 | if (err && handler) { |
| 3479 | if (handler->ibcounters && |
| 3480 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3481 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3482 | kfree(handler); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3483 | } |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3484 | kvfree(spec); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3485 | return err ? ERR_PTR(err) : handler; |
| 3486 | } |
| 3487 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3488 | static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev, |
| 3489 | struct mlx5_ib_flow_prio *ft_prio, |
| 3490 | const struct ib_flow_attr *flow_attr, |
| 3491 | struct mlx5_flow_destination *dst) |
| 3492 | { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3493 | return _create_flow_rule(dev, ft_prio, flow_attr, dst, 0, NULL); |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3494 | } |
| 3495 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3496 | static struct mlx5_ib_flow_handler *create_dont_trap_rule(struct mlx5_ib_dev *dev, |
| 3497 | struct mlx5_ib_flow_prio *ft_prio, |
| 3498 | struct ib_flow_attr *flow_attr, |
| 3499 | struct mlx5_flow_destination *dst) |
| 3500 | { |
| 3501 | struct mlx5_ib_flow_handler *handler_dst = NULL; |
| 3502 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3503 | |
| 3504 | handler = create_flow_rule(dev, ft_prio, flow_attr, NULL); |
| 3505 | if (!IS_ERR(handler)) { |
| 3506 | handler_dst = create_flow_rule(dev, ft_prio, |
| 3507 | flow_attr, dst); |
| 3508 | if (IS_ERR(handler_dst)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3509 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3510 | ft_prio->refcount--; |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3511 | kfree(handler); |
| 3512 | handler = handler_dst; |
| 3513 | } else { |
| 3514 | list_add(&handler_dst->list, &handler->list); |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | return handler; |
| 3519 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3520 | enum { |
| 3521 | LEFTOVERS_MC, |
| 3522 | LEFTOVERS_UC, |
| 3523 | }; |
| 3524 | |
| 3525 | static struct mlx5_ib_flow_handler *create_leftovers_rule(struct mlx5_ib_dev *dev, |
| 3526 | struct mlx5_ib_flow_prio *ft_prio, |
| 3527 | struct ib_flow_attr *flow_attr, |
| 3528 | struct mlx5_flow_destination *dst) |
| 3529 | { |
| 3530 | struct mlx5_ib_flow_handler *handler_ucast = NULL; |
| 3531 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3532 | |
| 3533 | static struct { |
| 3534 | struct ib_flow_attr flow_attr; |
| 3535 | struct ib_flow_spec_eth eth_flow; |
| 3536 | } leftovers_specs[] = { |
| 3537 | [LEFTOVERS_MC] = { |
| 3538 | .flow_attr = { |
| 3539 | .num_of_specs = 1, |
| 3540 | .size = sizeof(leftovers_specs[0]) |
| 3541 | }, |
| 3542 | .eth_flow = { |
| 3543 | .type = IB_FLOW_SPEC_ETH, |
| 3544 | .size = sizeof(struct ib_flow_spec_eth), |
| 3545 | .mask = {.dst_mac = {0x1} }, |
| 3546 | .val = {.dst_mac = {0x1} } |
| 3547 | } |
| 3548 | }, |
| 3549 | [LEFTOVERS_UC] = { |
| 3550 | .flow_attr = { |
| 3551 | .num_of_specs = 1, |
| 3552 | .size = sizeof(leftovers_specs[0]) |
| 3553 | }, |
| 3554 | .eth_flow = { |
| 3555 | .type = IB_FLOW_SPEC_ETH, |
| 3556 | .size = sizeof(struct ib_flow_spec_eth), |
| 3557 | .mask = {.dst_mac = {0x1} }, |
| 3558 | .val = {.dst_mac = {} } |
| 3559 | } |
| 3560 | } |
| 3561 | }; |
| 3562 | |
| 3563 | handler = create_flow_rule(dev, ft_prio, |
| 3564 | &leftovers_specs[LEFTOVERS_MC].flow_attr, |
| 3565 | dst); |
| 3566 | if (!IS_ERR(handler) && |
| 3567 | flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT) { |
| 3568 | handler_ucast = create_flow_rule(dev, ft_prio, |
| 3569 | &leftovers_specs[LEFTOVERS_UC].flow_attr, |
| 3570 | dst); |
| 3571 | if (IS_ERR(handler_ucast)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3572 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3573 | ft_prio->refcount--; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3574 | kfree(handler); |
| 3575 | handler = handler_ucast; |
| 3576 | } else { |
| 3577 | list_add(&handler_ucast->list, &handler->list); |
| 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | return handler; |
| 3582 | } |
| 3583 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3584 | static struct mlx5_ib_flow_handler *create_sniffer_rule(struct mlx5_ib_dev *dev, |
| 3585 | struct mlx5_ib_flow_prio *ft_rx, |
| 3586 | struct mlx5_ib_flow_prio *ft_tx, |
| 3587 | struct mlx5_flow_destination *dst) |
| 3588 | { |
| 3589 | struct mlx5_ib_flow_handler *handler_rx; |
| 3590 | struct mlx5_ib_flow_handler *handler_tx; |
| 3591 | int err; |
| 3592 | static const struct ib_flow_attr flow_attr = { |
| 3593 | .num_of_specs = 0, |
| 3594 | .size = sizeof(flow_attr) |
| 3595 | }; |
| 3596 | |
| 3597 | handler_rx = create_flow_rule(dev, ft_rx, &flow_attr, dst); |
| 3598 | if (IS_ERR(handler_rx)) { |
| 3599 | err = PTR_ERR(handler_rx); |
| 3600 | goto err; |
| 3601 | } |
| 3602 | |
| 3603 | handler_tx = create_flow_rule(dev, ft_tx, &flow_attr, dst); |
| 3604 | if (IS_ERR(handler_tx)) { |
| 3605 | err = PTR_ERR(handler_tx); |
| 3606 | goto err_tx; |
| 3607 | } |
| 3608 | |
| 3609 | list_add(&handler_tx->list, &handler_rx->list); |
| 3610 | |
| 3611 | return handler_rx; |
| 3612 | |
| 3613 | err_tx: |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3614 | mlx5_del_flow_rules(handler_rx->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3615 | ft_rx->refcount--; |
| 3616 | kfree(handler_rx); |
| 3617 | err: |
| 3618 | return ERR_PTR(err); |
| 3619 | } |
| 3620 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3621 | static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, |
| 3622 | struct ib_flow_attr *flow_attr, |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3623 | int domain, |
| 3624 | struct ib_udata *udata) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3625 | { |
| 3626 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Yishai Hadas | d9f88e5 | 2016-08-28 10:58:37 +0300 | [diff] [blame] | 3627 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3628 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3629 | struct mlx5_flow_destination *dst = NULL; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3630 | struct mlx5_ib_flow_prio *ft_prio_tx = NULL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3631 | struct mlx5_ib_flow_prio *ft_prio; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3632 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3633 | struct mlx5_ib_create_flow *ucmd = NULL, ucmd_hdr; |
| 3634 | size_t min_ucmd_sz, required_ucmd_sz; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3635 | int err; |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3636 | int underlay_qpn; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3637 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3638 | if (udata && udata->inlen) { |
| 3639 | min_ucmd_sz = offsetof(typeof(ucmd_hdr), reserved) + |
| 3640 | sizeof(ucmd_hdr.reserved); |
| 3641 | if (udata->inlen < min_ucmd_sz) |
| 3642 | return ERR_PTR(-EOPNOTSUPP); |
| 3643 | |
| 3644 | err = ib_copy_from_udata(&ucmd_hdr, udata, min_ucmd_sz); |
| 3645 | if (err) |
| 3646 | return ERR_PTR(err); |
| 3647 | |
| 3648 | /* currently supports only one counters data */ |
| 3649 | if (ucmd_hdr.ncounters_data > 1) |
| 3650 | return ERR_PTR(-EINVAL); |
| 3651 | |
| 3652 | required_ucmd_sz = min_ucmd_sz + |
| 3653 | sizeof(struct mlx5_ib_flow_counters_data) * |
| 3654 | ucmd_hdr.ncounters_data; |
| 3655 | if (udata->inlen > required_ucmd_sz && |
| 3656 | !ib_is_udata_cleared(udata, required_ucmd_sz, |
| 3657 | udata->inlen - required_ucmd_sz)) |
| 3658 | return ERR_PTR(-EOPNOTSUPP); |
| 3659 | |
| 3660 | ucmd = kzalloc(required_ucmd_sz, GFP_KERNEL); |
| 3661 | if (!ucmd) |
| 3662 | return ERR_PTR(-ENOMEM); |
| 3663 | |
| 3664 | err = ib_copy_from_udata(ucmd, udata, required_ucmd_sz); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3665 | if (err) |
| 3666 | goto free_ucmd; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3667 | } |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3668 | |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3669 | if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) { |
| 3670 | err = -ENOMEM; |
| 3671 | goto free_ucmd; |
| 3672 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3673 | |
| 3674 | if (domain != IB_FLOW_DOMAIN_USER || |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 3675 | flow_attr->port > dev->num_ports || |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3676 | (flow_attr->flags & ~(IB_FLOW_ATTR_FLAGS_DONT_TRAP | |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3677 | IB_FLOW_ATTR_FLAGS_EGRESS))) { |
| 3678 | err = -EINVAL; |
| 3679 | goto free_ucmd; |
| 3680 | } |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3681 | |
| 3682 | if (is_egress && |
| 3683 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3684 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3685 | err = -EINVAL; |
| 3686 | goto free_ucmd; |
| 3687 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3688 | |
| 3689 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3690 | if (!dst) { |
| 3691 | err = -ENOMEM; |
| 3692 | goto free_ucmd; |
| 3693 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3694 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3695 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3696 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3697 | ft_prio = get_flow_table(dev, flow_attr, |
| 3698 | is_egress ? MLX5_IB_FT_TX : MLX5_IB_FT_RX); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3699 | if (IS_ERR(ft_prio)) { |
| 3700 | err = PTR_ERR(ft_prio); |
| 3701 | goto unlock; |
| 3702 | } |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3703 | if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3704 | ft_prio_tx = get_flow_table(dev, flow_attr, MLX5_IB_FT_TX); |
| 3705 | if (IS_ERR(ft_prio_tx)) { |
| 3706 | err = PTR_ERR(ft_prio_tx); |
| 3707 | ft_prio_tx = NULL; |
| 3708 | goto destroy_ft; |
| 3709 | } |
| 3710 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3711 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3712 | if (is_egress) { |
| 3713 | dst->type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
| 3714 | } else { |
| 3715 | dst->type = MLX5_FLOW_DESTINATION_TYPE_TIR; |
| 3716 | if (mqp->flags & MLX5_IB_QP_RSS) |
| 3717 | dst->tir_num = mqp->rss_qp.tirn; |
| 3718 | else |
| 3719 | dst->tir_num = mqp->raw_packet_qp.rq.tirn; |
| 3720 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3721 | |
| 3722 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3723 | if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) { |
| 3724 | handler = create_dont_trap_rule(dev, ft_prio, |
| 3725 | flow_attr, dst); |
| 3726 | } else { |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3727 | underlay_qpn = (mqp->flags & MLX5_IB_QP_UNDERLAY) ? |
| 3728 | mqp->underlay_qpn : 0; |
| 3729 | handler = _create_flow_rule(dev, ft_prio, flow_attr, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3730 | dst, underlay_qpn, ucmd); |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3731 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3732 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3733 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3734 | handler = create_leftovers_rule(dev, ft_prio, flow_attr, |
| 3735 | dst); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3736 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3737 | handler = create_sniffer_rule(dev, ft_prio, ft_prio_tx, dst); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3738 | } else { |
| 3739 | err = -EINVAL; |
| 3740 | goto destroy_ft; |
| 3741 | } |
| 3742 | |
| 3743 | if (IS_ERR(handler)) { |
| 3744 | err = PTR_ERR(handler); |
| 3745 | handler = NULL; |
| 3746 | goto destroy_ft; |
| 3747 | } |
| 3748 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3749 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3750 | kfree(dst); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3751 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3752 | |
| 3753 | return &handler->ibflow; |
| 3754 | |
| 3755 | destroy_ft: |
| 3756 | put_flow_table(dev, ft_prio, false); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3757 | if (ft_prio_tx) |
| 3758 | put_flow_table(dev, ft_prio_tx, false); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3759 | unlock: |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3760 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3761 | kfree(dst); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3762 | free_ucmd: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3763 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3764 | return ERR_PTR(err); |
| 3765 | } |
| 3766 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3767 | static struct mlx5_ib_flow_prio * |
| 3768 | _get_flow_table(struct mlx5_ib_dev *dev, |
| 3769 | struct mlx5_ib_flow_matcher *fs_matcher, |
| 3770 | bool mcast) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3771 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3772 | struct mlx5_flow_namespace *ns = NULL; |
| 3773 | struct mlx5_ib_flow_prio *prio; |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3774 | int max_table_size; |
| 3775 | u32 flags = 0; |
| 3776 | int priority; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3777 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3778 | if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS) { |
| 3779 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3780 | log_max_ft_size)); |
| 3781 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, decap)) |
| 3782 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
| 3783 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3784 | reformat_l3_tunnel_to_l2)) |
| 3785 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
| 3786 | } else { /* Can only be MLX5_FLOW_NAMESPACE_EGRESS */ |
| 3787 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, |
| 3788 | log_max_ft_size)); |
| 3789 | if (MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, reformat)) |
| 3790 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
| 3791 | } |
| 3792 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3793 | if (max_table_size < MLX5_FS_MAX_ENTRIES) |
| 3794 | return ERR_PTR(-ENOMEM); |
| 3795 | |
| 3796 | if (mcast) |
| 3797 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3798 | else |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3799 | priority = ib_prio_to_core_prio(fs_matcher->priority, false); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3800 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3801 | ns = mlx5_get_flow_namespace(dev->mdev, fs_matcher->ns_type); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3802 | if (!ns) |
| 3803 | return ERR_PTR(-ENOTSUPP); |
| 3804 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3805 | if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS) |
| 3806 | prio = &dev->flow_db->prios[priority]; |
| 3807 | else |
| 3808 | prio = &dev->flow_db->egress_prios[priority]; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3809 | |
| 3810 | if (prio->flow_table) |
| 3811 | return prio; |
| 3812 | |
| 3813 | return _get_prio(ns, prio, priority, MLX5_FS_MAX_ENTRIES, |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3814 | MLX5_FS_MAX_TYPES, flags); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3815 | } |
| 3816 | |
| 3817 | static struct mlx5_ib_flow_handler * |
| 3818 | _create_raw_flow_rule(struct mlx5_ib_dev *dev, |
| 3819 | struct mlx5_ib_flow_prio *ft_prio, |
| 3820 | struct mlx5_flow_destination *dst, |
| 3821 | struct mlx5_ib_flow_matcher *fs_matcher, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3822 | struct mlx5_flow_act *flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3823 | void *cmd_in, int inlen, |
| 3824 | int dst_num) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3825 | { |
| 3826 | struct mlx5_ib_flow_handler *handler; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3827 | struct mlx5_flow_spec *spec; |
| 3828 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3829 | int err = 0; |
| 3830 | |
| 3831 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
| 3832 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
| 3833 | if (!handler || !spec) { |
| 3834 | err = -ENOMEM; |
| 3835 | goto free; |
| 3836 | } |
| 3837 | |
| 3838 | INIT_LIST_HEAD(&handler->list); |
| 3839 | |
| 3840 | memcpy(spec->match_value, cmd_in, inlen); |
| 3841 | memcpy(spec->match_criteria, fs_matcher->matcher_mask.match_params, |
| 3842 | fs_matcher->mask_len); |
| 3843 | spec->match_criteria_enable = fs_matcher->match_criteria_enable; |
| 3844 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3845 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3846 | flow_act, dst, dst_num); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3847 | |
| 3848 | if (IS_ERR(handler->rule)) { |
| 3849 | err = PTR_ERR(handler->rule); |
| 3850 | goto free; |
| 3851 | } |
| 3852 | |
| 3853 | ft_prio->refcount++; |
| 3854 | handler->prio = ft_prio; |
| 3855 | handler->dev = dev; |
| 3856 | ft_prio->flow_table = ft; |
| 3857 | |
| 3858 | free: |
| 3859 | if (err) |
| 3860 | kfree(handler); |
| 3861 | kvfree(spec); |
| 3862 | return err ? ERR_PTR(err) : handler; |
| 3863 | } |
| 3864 | |
| 3865 | static bool raw_fs_is_multicast(struct mlx5_ib_flow_matcher *fs_matcher, |
| 3866 | void *match_v) |
| 3867 | { |
| 3868 | void *match_c; |
| 3869 | void *match_v_set_lyr_2_4, *match_c_set_lyr_2_4; |
| 3870 | void *dmac, *dmac_mask; |
| 3871 | void *ipv4, *ipv4_mask; |
| 3872 | |
| 3873 | if (!(fs_matcher->match_criteria_enable & |
| 3874 | (1 << MATCH_CRITERIA_ENABLE_OUTER_BIT))) |
| 3875 | return false; |
| 3876 | |
| 3877 | match_c = fs_matcher->matcher_mask.match_params; |
| 3878 | match_v_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_v, |
| 3879 | outer_headers); |
| 3880 | match_c_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_c, |
| 3881 | outer_headers); |
| 3882 | |
| 3883 | dmac = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 3884 | dmac_47_16); |
| 3885 | dmac_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 3886 | dmac_47_16); |
| 3887 | |
| 3888 | if (is_multicast_ether_addr(dmac) && |
| 3889 | is_multicast_ether_addr(dmac_mask)) |
| 3890 | return true; |
| 3891 | |
| 3892 | ipv4 = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 3893 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 3894 | |
| 3895 | ipv4_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 3896 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 3897 | |
| 3898 | if (ipv4_is_multicast(*(__be32 *)(ipv4)) && |
| 3899 | ipv4_is_multicast(*(__be32 *)(ipv4_mask))) |
| 3900 | return true; |
| 3901 | |
| 3902 | return false; |
| 3903 | } |
| 3904 | |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3905 | struct mlx5_ib_flow_handler * |
| 3906 | mlx5_ib_raw_fs_rule_add(struct mlx5_ib_dev *dev, |
| 3907 | struct mlx5_ib_flow_matcher *fs_matcher, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3908 | struct mlx5_flow_act *flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3909 | u32 counter_id, |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3910 | void *cmd_in, int inlen, int dest_id, |
| 3911 | int dest_type) |
| 3912 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3913 | struct mlx5_flow_destination *dst; |
| 3914 | struct mlx5_ib_flow_prio *ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3915 | struct mlx5_ib_flow_handler *handler; |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3916 | int dst_num = 0; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3917 | bool mcast; |
| 3918 | int err; |
| 3919 | |
| 3920 | if (fs_matcher->flow_type != MLX5_IB_FLOW_TYPE_NORMAL) |
| 3921 | return ERR_PTR(-EOPNOTSUPP); |
| 3922 | |
| 3923 | if (fs_matcher->priority > MLX5_IB_FLOW_LAST_PRIO) |
| 3924 | return ERR_PTR(-ENOMEM); |
| 3925 | |
Gustavo A. R. Silva | 8e8aa14 | 2019-01-15 00:00:48 -0600 | [diff] [blame] | 3926 | dst = kcalloc(2, sizeof(*dst), GFP_KERNEL); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3927 | if (!dst) |
| 3928 | return ERR_PTR(-ENOMEM); |
| 3929 | |
| 3930 | mcast = raw_fs_is_multicast(fs_matcher, cmd_in); |
| 3931 | mutex_lock(&dev->flow_db->lock); |
| 3932 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3933 | ft_prio = _get_flow_table(dev, fs_matcher, mcast); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3934 | if (IS_ERR(ft_prio)) { |
| 3935 | err = PTR_ERR(ft_prio); |
| 3936 | goto unlock; |
| 3937 | } |
| 3938 | |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 3939 | if (dest_type == MLX5_FLOW_DESTINATION_TYPE_TIR) { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3940 | dst[dst_num].type = dest_type; |
| 3941 | dst[dst_num].tir_num = dest_id; |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3942 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 3943 | } else if (dest_type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3944 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM; |
| 3945 | dst[dst_num].ft_num = dest_id; |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3946 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 3947 | } else { |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3948 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame] | 3949 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 3950 | } |
| 3951 | |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3952 | dst_num++; |
| 3953 | |
| 3954 | if (flow_act->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
| 3955 | dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
| 3956 | dst[dst_num].counter_id = counter_id; |
| 3957 | dst_num++; |
| 3958 | } |
| 3959 | |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3960 | handler = _create_raw_flow_rule(dev, ft_prio, dst, fs_matcher, flow_act, |
Mark Bloch | bfc5d83 | 2018-11-20 20:31:08 +0200 | [diff] [blame] | 3961 | cmd_in, inlen, dst_num); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3962 | |
| 3963 | if (IS_ERR(handler)) { |
| 3964 | err = PTR_ERR(handler); |
| 3965 | goto destroy_ft; |
| 3966 | } |
| 3967 | |
| 3968 | mutex_unlock(&dev->flow_db->lock); |
| 3969 | atomic_inc(&fs_matcher->usecnt); |
| 3970 | handler->flow_matcher = fs_matcher; |
| 3971 | |
| 3972 | kfree(dst); |
| 3973 | |
| 3974 | return handler; |
| 3975 | |
| 3976 | destroy_ft: |
| 3977 | put_flow_table(dev, ft_prio, false); |
| 3978 | unlock: |
| 3979 | mutex_unlock(&dev->flow_db->lock); |
| 3980 | kfree(dst); |
| 3981 | |
| 3982 | return ERR_PTR(err); |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3983 | } |
| 3984 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 3985 | static u32 mlx5_ib_flow_action_flags_to_accel_xfrm_flags(u32 mlx5_flags) |
| 3986 | { |
| 3987 | u32 flags = 0; |
| 3988 | |
| 3989 | if (mlx5_flags & MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA) |
| 3990 | flags |= MLX5_ACCEL_XFRM_FLAG_REQUIRE_METADATA; |
| 3991 | |
| 3992 | return flags; |
| 3993 | } |
| 3994 | |
| 3995 | #define MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA |
| 3996 | static struct ib_flow_action * |
| 3997 | mlx5_ib_create_flow_action_esp(struct ib_device *device, |
| 3998 | const struct ib_flow_action_attrs_esp *attr, |
| 3999 | struct uverbs_attr_bundle *attrs) |
| 4000 | { |
| 4001 | struct mlx5_ib_dev *mdev = to_mdev(device); |
| 4002 | struct ib_uverbs_flow_action_esp_keymat_aes_gcm *aes_gcm; |
| 4003 | struct mlx5_accel_esp_xfrm_attrs accel_attrs = {}; |
| 4004 | struct mlx5_ib_flow_action *action; |
| 4005 | u64 action_flags; |
| 4006 | u64 flags; |
| 4007 | int err = 0; |
| 4008 | |
Jason Gunthorpe | bccd062 | 2018-07-26 16:37:14 -0600 | [diff] [blame] | 4009 | err = uverbs_get_flags64( |
| 4010 | &action_flags, attrs, MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 4011 | ((MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED << 1) - 1)); |
| 4012 | if (err) |
| 4013 | return ERR_PTR(err); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4014 | |
| 4015 | flags = mlx5_ib_flow_action_flags_to_accel_xfrm_flags(action_flags); |
| 4016 | |
| 4017 | /* We current only support a subset of the standard features. Only a |
| 4018 | * keymat of type AES_GCM, with icv_len == 16, iv_algo == SEQ and esn |
| 4019 | * (with overlap). Full offload mode isn't supported. |
| 4020 | */ |
| 4021 | if (!attr->keymat || attr->replay || attr->encap || |
| 4022 | attr->spi || attr->seq || attr->tfc_pad || |
| 4023 | attr->hard_limit_pkts || |
| 4024 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4025 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT))) |
| 4026 | return ERR_PTR(-EOPNOTSUPP); |
| 4027 | |
| 4028 | if (attr->keymat->protocol != |
| 4029 | IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM) |
| 4030 | return ERR_PTR(-EOPNOTSUPP); |
| 4031 | |
| 4032 | aes_gcm = &attr->keymat->keymat.aes_gcm; |
| 4033 | |
| 4034 | if (aes_gcm->icv_len != 16 || |
| 4035 | aes_gcm->iv_algo != IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ) |
| 4036 | return ERR_PTR(-EOPNOTSUPP); |
| 4037 | |
| 4038 | action = kmalloc(sizeof(*action), GFP_KERNEL); |
| 4039 | if (!action) |
| 4040 | return ERR_PTR(-ENOMEM); |
| 4041 | |
| 4042 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 4043 | memcpy(&accel_attrs.keymat.aes_gcm.aes_key, &aes_gcm->aes_key, |
| 4044 | sizeof(accel_attrs.keymat.aes_gcm.aes_key)); |
| 4045 | accel_attrs.keymat.aes_gcm.key_len = aes_gcm->key_len * 8; |
| 4046 | memcpy(&accel_attrs.keymat.aes_gcm.salt, &aes_gcm->salt, |
| 4047 | sizeof(accel_attrs.keymat.aes_gcm.salt)); |
| 4048 | memcpy(&accel_attrs.keymat.aes_gcm.seq_iv, &aes_gcm->iv, |
| 4049 | sizeof(accel_attrs.keymat.aes_gcm.seq_iv)); |
| 4050 | accel_attrs.keymat.aes_gcm.icv_len = aes_gcm->icv_len * 8; |
| 4051 | accel_attrs.keymat.aes_gcm.iv_algo = MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ; |
| 4052 | accel_attrs.keymat_type = MLX5_ACCEL_ESP_KEYMAT_AES_GCM; |
| 4053 | |
| 4054 | accel_attrs.esn = attr->esn; |
| 4055 | if (attr->flags & IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) |
| 4056 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED; |
| 4057 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 4058 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4059 | |
| 4060 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT) |
| 4061 | accel_attrs.action |= MLX5_ACCEL_ESP_ACTION_ENCRYPT; |
| 4062 | |
| 4063 | action->esp_aes_gcm.ctx = |
| 4064 | mlx5_accel_esp_create_xfrm(mdev->mdev, &accel_attrs, flags); |
| 4065 | if (IS_ERR(action->esp_aes_gcm.ctx)) { |
| 4066 | err = PTR_ERR(action->esp_aes_gcm.ctx); |
| 4067 | goto err_parse; |
| 4068 | } |
| 4069 | |
| 4070 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 4071 | |
| 4072 | return &action->ib_action; |
| 4073 | |
| 4074 | err_parse: |
| 4075 | kfree(action); |
| 4076 | return ERR_PTR(err); |
| 4077 | } |
| 4078 | |
Matan Barak | 349705c | 2018-03-28 09:27:51 +0300 | [diff] [blame] | 4079 | static int |
| 4080 | mlx5_ib_modify_flow_action_esp(struct ib_flow_action *action, |
| 4081 | const struct ib_flow_action_attrs_esp *attr, |
| 4082 | struct uverbs_attr_bundle *attrs) |
| 4083 | { |
| 4084 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 4085 | struct mlx5_accel_esp_xfrm_attrs accel_attrs; |
| 4086 | int err = 0; |
| 4087 | |
| 4088 | if (attr->keymat || attr->replay || attr->encap || |
| 4089 | attr->spi || attr->seq || attr->tfc_pad || |
| 4090 | attr->hard_limit_pkts || |
| 4091 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4092 | IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS | |
| 4093 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW))) |
| 4094 | return -EOPNOTSUPP; |
| 4095 | |
| 4096 | /* Only the ESN value or the MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP can |
| 4097 | * be modified. |
| 4098 | */ |
| 4099 | if (!(maction->esp_aes_gcm.ib_flags & |
| 4100 | IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) && |
| 4101 | attr->flags & (IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4102 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW)) |
| 4103 | return -EINVAL; |
| 4104 | |
| 4105 | memcpy(&accel_attrs, &maction->esp_aes_gcm.ctx->attrs, |
| 4106 | sizeof(accel_attrs)); |
| 4107 | |
| 4108 | accel_attrs.esn = attr->esn; |
| 4109 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 4110 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4111 | else |
| 4112 | accel_attrs.flags &= ~MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4113 | |
| 4114 | err = mlx5_accel_esp_modify_xfrm(maction->esp_aes_gcm.ctx, |
| 4115 | &accel_attrs); |
| 4116 | if (err) |
| 4117 | return err; |
| 4118 | |
| 4119 | maction->esp_aes_gcm.ib_flags &= |
| 4120 | ~IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 4121 | maction->esp_aes_gcm.ib_flags |= |
| 4122 | attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 4123 | |
| 4124 | return 0; |
| 4125 | } |
| 4126 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4127 | static int mlx5_ib_destroy_flow_action(struct ib_flow_action *action) |
| 4128 | { |
| 4129 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 4130 | |
| 4131 | switch (action->type) { |
| 4132 | case IB_FLOW_ACTION_ESP: |
| 4133 | /* |
| 4134 | * We only support aes_gcm by now, so we implicitly know this is |
| 4135 | * the underline crypto. |
| 4136 | */ |
| 4137 | mlx5_accel_esp_destroy_xfrm(maction->esp_aes_gcm.ctx); |
| 4138 | break; |
Mark Bloch | b4749bf | 2018-08-28 14:18:51 +0300 | [diff] [blame] | 4139 | case IB_FLOW_ACTION_UNSPECIFIED: |
| 4140 | mlx5_ib_destroy_flow_action_raw(maction); |
| 4141 | break; |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4142 | default: |
| 4143 | WARN_ON(true); |
| 4144 | break; |
| 4145 | } |
| 4146 | |
| 4147 | kfree(maction); |
| 4148 | return 0; |
| 4149 | } |
| 4150 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4151 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4152 | { |
| 4153 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4154 | struct mlx5_ib_qp *mqp = to_mqp(ibqp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4155 | int err; |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4156 | u16 uid; |
| 4157 | |
| 4158 | uid = ibqp->pd ? |
| 4159 | to_mpd(ibqp->pd)->uid : 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4160 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4161 | if (mqp->flags & MLX5_IB_QP_UNDERLAY) { |
| 4162 | mlx5_ib_dbg(dev, "Attaching a multi cast group to underlay QP is not supported\n"); |
| 4163 | return -EOPNOTSUPP; |
| 4164 | } |
| 4165 | |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4166 | err = mlx5_cmd_attach_mcg(dev->mdev, gid, ibqp->qp_num, uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4167 | if (err) |
| 4168 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
| 4169 | ibqp->qp_num, gid->raw); |
| 4170 | |
| 4171 | return err; |
| 4172 | } |
| 4173 | |
| 4174 | static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4175 | { |
| 4176 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 4177 | int err; |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4178 | u16 uid; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4179 | |
Yishai Hadas | 539ec98 | 2018-09-20 21:39:25 +0300 | [diff] [blame] | 4180 | uid = ibqp->pd ? |
| 4181 | to_mpd(ibqp->pd)->uid : 0; |
| 4182 | err = mlx5_cmd_detach_mcg(dev->mdev, gid, ibqp->qp_num, uid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4183 | if (err) |
| 4184 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
| 4185 | ibqp->qp_num, gid->raw); |
| 4186 | |
| 4187 | return err; |
| 4188 | } |
| 4189 | |
| 4190 | static int init_node_data(struct mlx5_ib_dev *dev) |
| 4191 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4192 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4193 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4194 | err = mlx5_query_node_desc(dev, dev->ib_dev.node_desc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4195 | if (err) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4196 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4197 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4198 | dev->mdev->rev_id = dev->mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4199 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4200 | return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4201 | } |
| 4202 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4203 | static ssize_t fw_pages_show(struct device *device, |
| 4204 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4205 | { |
| 4206 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4207 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4208 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4209 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4210 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4211 | static DEVICE_ATTR_RO(fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4212 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4213 | static ssize_t reg_pages_show(struct device *device, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4214 | struct device_attribute *attr, char *buf) |
| 4215 | { |
| 4216 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4217 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4218 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 4219 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4220 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4221 | static DEVICE_ATTR_RO(reg_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4222 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4223 | static ssize_t hca_type_show(struct device *device, |
| 4224 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4225 | { |
| 4226 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4227 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4228 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4229 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4230 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4231 | static DEVICE_ATTR_RO(hca_type); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4232 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4233 | static ssize_t hw_rev_show(struct device *device, |
| 4234 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4235 | { |
| 4236 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4237 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4238 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4239 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4240 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4241 | static DEVICE_ATTR_RO(hw_rev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4242 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4243 | static ssize_t board_id_show(struct device *device, |
| 4244 | struct device_attribute *attr, char *buf) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4245 | { |
| 4246 | struct mlx5_ib_dev *dev = |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4247 | rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
| 4248 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4249 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4250 | dev->mdev->board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4251 | } |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4252 | static DEVICE_ATTR_RO(board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4253 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4254 | static struct attribute *mlx5_class_attributes[] = { |
| 4255 | &dev_attr_hw_rev.attr, |
| 4256 | &dev_attr_hca_type.attr, |
| 4257 | &dev_attr_board_id.attr, |
| 4258 | &dev_attr_fw_pages.attr, |
| 4259 | &dev_attr_reg_pages.attr, |
| 4260 | NULL, |
| 4261 | }; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4262 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 4263 | static const struct attribute_group mlx5_attr_group = { |
| 4264 | .attrs = mlx5_class_attributes, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4265 | }; |
| 4266 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4267 | static void pkey_change_handler(struct work_struct *work) |
| 4268 | { |
| 4269 | struct mlx5_ib_port_resources *ports = |
| 4270 | container_of(work, struct mlx5_ib_port_resources, |
| 4271 | pkey_change_work); |
| 4272 | |
| 4273 | mutex_lock(&ports->devr->mutex); |
| 4274 | mlx5_ib_gsi_pkey_change(ports->gsi); |
| 4275 | mutex_unlock(&ports->devr->mutex); |
| 4276 | } |
| 4277 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4278 | static void mlx5_ib_handle_internal_error(struct mlx5_ib_dev *ibdev) |
| 4279 | { |
| 4280 | struct mlx5_ib_qp *mqp; |
| 4281 | struct mlx5_ib_cq *send_mcq, *recv_mcq; |
| 4282 | struct mlx5_core_cq *mcq; |
| 4283 | struct list_head cq_armed_list; |
| 4284 | unsigned long flags_qp; |
| 4285 | unsigned long flags_cq; |
| 4286 | unsigned long flags; |
| 4287 | |
| 4288 | INIT_LIST_HEAD(&cq_armed_list); |
| 4289 | |
| 4290 | /* Go over qp list reside on that ibdev, sync with create/destroy qp.*/ |
| 4291 | spin_lock_irqsave(&ibdev->reset_flow_resource_lock, flags); |
| 4292 | list_for_each_entry(mqp, &ibdev->qp_list, qps_list) { |
| 4293 | spin_lock_irqsave(&mqp->sq.lock, flags_qp); |
| 4294 | if (mqp->sq.tail != mqp->sq.head) { |
| 4295 | send_mcq = to_mcq(mqp->ibqp.send_cq); |
| 4296 | spin_lock_irqsave(&send_mcq->lock, flags_cq); |
| 4297 | if (send_mcq->mcq.comp && |
| 4298 | mqp->ibqp.send_cq->comp_handler) { |
| 4299 | if (!send_mcq->mcq.reset_notify_added) { |
| 4300 | send_mcq->mcq.reset_notify_added = 1; |
| 4301 | list_add_tail(&send_mcq->mcq.reset_notify, |
| 4302 | &cq_armed_list); |
| 4303 | } |
| 4304 | } |
| 4305 | spin_unlock_irqrestore(&send_mcq->lock, flags_cq); |
| 4306 | } |
| 4307 | spin_unlock_irqrestore(&mqp->sq.lock, flags_qp); |
| 4308 | spin_lock_irqsave(&mqp->rq.lock, flags_qp); |
| 4309 | /* no handling is needed for SRQ */ |
| 4310 | if (!mqp->ibqp.srq) { |
| 4311 | if (mqp->rq.tail != mqp->rq.head) { |
| 4312 | recv_mcq = to_mcq(mqp->ibqp.recv_cq); |
| 4313 | spin_lock_irqsave(&recv_mcq->lock, flags_cq); |
| 4314 | if (recv_mcq->mcq.comp && |
| 4315 | mqp->ibqp.recv_cq->comp_handler) { |
| 4316 | if (!recv_mcq->mcq.reset_notify_added) { |
| 4317 | recv_mcq->mcq.reset_notify_added = 1; |
| 4318 | list_add_tail(&recv_mcq->mcq.reset_notify, |
| 4319 | &cq_armed_list); |
| 4320 | } |
| 4321 | } |
| 4322 | spin_unlock_irqrestore(&recv_mcq->lock, |
| 4323 | flags_cq); |
| 4324 | } |
| 4325 | } |
| 4326 | spin_unlock_irqrestore(&mqp->rq.lock, flags_qp); |
| 4327 | } |
| 4328 | /*At that point all inflight post send were put to be executed as of we |
| 4329 | * lock/unlock above locks Now need to arm all involved CQs. |
| 4330 | */ |
| 4331 | list_for_each_entry(mcq, &cq_armed_list, reset_notify) { |
| 4332 | mcq->comp(mcq); |
| 4333 | } |
| 4334 | spin_unlock_irqrestore(&ibdev->reset_flow_resource_lock, flags); |
| 4335 | } |
| 4336 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4337 | static void delay_drop_handler(struct work_struct *work) |
| 4338 | { |
| 4339 | int err; |
| 4340 | struct mlx5_ib_delay_drop *delay_drop = |
| 4341 | container_of(work, struct mlx5_ib_delay_drop, |
| 4342 | delay_drop_work); |
| 4343 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 4344 | atomic_inc(&delay_drop->events_cnt); |
| 4345 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4346 | mutex_lock(&delay_drop->lock); |
| 4347 | err = mlx5_core_set_delay_drop(delay_drop->dev->mdev, |
| 4348 | delay_drop->timeout); |
| 4349 | if (err) { |
| 4350 | mlx5_ib_warn(delay_drop->dev, "Failed to set delay drop, timeout=%u\n", |
| 4351 | delay_drop->timeout); |
| 4352 | delay_drop->activate = false; |
| 4353 | } |
| 4354 | mutex_unlock(&delay_drop->lock); |
| 4355 | } |
| 4356 | |
Saeed Mahameed | 09e574f | 2018-11-26 14:39:04 -0800 | [diff] [blame] | 4357 | static void handle_general_event(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, |
| 4358 | struct ib_event *ibev) |
| 4359 | { |
| 4360 | switch (eqe->sub_type) { |
| 4361 | case MLX5_GENERAL_SUBTYPE_DELAY_DROP_TIMEOUT: |
| 4362 | schedule_work(&ibdev->delay_drop.delay_drop_work); |
| 4363 | break; |
| 4364 | default: /* do nothing */ |
| 4365 | return; |
| 4366 | } |
| 4367 | } |
| 4368 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4369 | static int handle_port_change(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, |
| 4370 | struct ib_event *ibev) |
| 4371 | { |
| 4372 | u8 port = (eqe->data.port.port >> 4) & 0xf; |
| 4373 | |
| 4374 | ibev->element.port_num = port; |
| 4375 | |
| 4376 | switch (eqe->sub_type) { |
| 4377 | case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE: |
| 4378 | case MLX5_PORT_CHANGE_SUBTYPE_DOWN: |
| 4379 | case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED: |
| 4380 | /* In RoCE, port up/down events are handled in |
| 4381 | * mlx5_netdev_event(). |
| 4382 | */ |
| 4383 | if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
| 4384 | IB_LINK_LAYER_ETHERNET) |
| 4385 | return -EINVAL; |
| 4386 | |
| 4387 | ibev->event = (eqe->sub_type == MLX5_PORT_CHANGE_SUBTYPE_ACTIVE) ? |
| 4388 | IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
| 4389 | break; |
| 4390 | |
| 4391 | case MLX5_PORT_CHANGE_SUBTYPE_LID: |
| 4392 | ibev->event = IB_EVENT_LID_CHANGE; |
| 4393 | break; |
| 4394 | |
| 4395 | case MLX5_PORT_CHANGE_SUBTYPE_PKEY: |
| 4396 | ibev->event = IB_EVENT_PKEY_CHANGE; |
| 4397 | schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work); |
| 4398 | break; |
| 4399 | |
| 4400 | case MLX5_PORT_CHANGE_SUBTYPE_GUID: |
| 4401 | ibev->event = IB_EVENT_GID_CHANGE; |
| 4402 | break; |
| 4403 | |
| 4404 | case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG: |
| 4405 | ibev->event = IB_EVENT_CLIENT_REREGISTER; |
| 4406 | break; |
| 4407 | default: |
| 4408 | return -EINVAL; |
| 4409 | } |
| 4410 | |
| 4411 | return 0; |
| 4412 | } |
| 4413 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4414 | static void mlx5_ib_handle_event(struct work_struct *_work) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4415 | { |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4416 | struct mlx5_ib_event_work *work = |
| 4417 | container_of(_work, struct mlx5_ib_event_work, work); |
| 4418 | struct mlx5_ib_dev *ibdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4419 | struct ib_event ibev; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4420 | bool fatal = false; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4421 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4422 | if (work->is_slave) { |
| 4423 | ibdev = mlx5_ib_get_ibdev_from_mpi(work->mpi); |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4424 | if (!ibdev) |
| 4425 | goto out; |
| 4426 | } else { |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4427 | ibdev = work->dev; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4428 | } |
| 4429 | |
| 4430 | switch (work->event) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4431 | case MLX5_DEV_EVENT_SYS_ERROR: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4432 | ibev.event = IB_EVENT_DEVICE_FATAL; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4433 | mlx5_ib_handle_internal_error(ibdev); |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4434 | ibev.element.port_num = (u8)(unsigned long)work->param; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4435 | fatal = true; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4436 | break; |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4437 | case MLX5_EVENT_TYPE_PORT_CHANGE: |
| 4438 | if (handle_port_change(ibdev, work->param, &ibev)) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4439 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4440 | break; |
Saeed Mahameed | 09e574f | 2018-11-26 14:39:04 -0800 | [diff] [blame] | 4441 | case MLX5_EVENT_TYPE_GENERAL_EVENT: |
| 4442 | handle_general_event(ibdev, work->param, &ibev); |
| 4443 | /* fall through */ |
Saeed Mahameed | bdc3792 | 2016-09-29 19:35:38 +0300 | [diff] [blame] | 4444 | default: |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4445 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4446 | } |
| 4447 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4448 | ibev.device = &ibdev->ib_dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4449 | |
Saeed Mahameed | 134e934 | 2018-11-26 14:39:02 -0800 | [diff] [blame] | 4450 | if (!rdma_is_port_valid(&ibdev->ib_dev, ibev.element.port_num)) { |
| 4451 | 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] | 4452 | goto out; |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 4453 | } |
| 4454 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4455 | if (ibdev->ib_active) |
| 4456 | ib_dispatch_event(&ibev); |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4457 | |
| 4458 | if (fatal) |
| 4459 | ibdev->ib_active = false; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4460 | out: |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4461 | kfree(work); |
| 4462 | } |
| 4463 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4464 | static int mlx5_ib_event(struct notifier_block *nb, |
| 4465 | unsigned long event, void *param) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4466 | { |
| 4467 | struct mlx5_ib_event_work *work; |
| 4468 | |
| 4469 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4470 | if (!work) |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4471 | return NOTIFY_DONE; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4472 | |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4473 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4474 | work->dev = container_of(nb, struct mlx5_ib_dev, mdev_events); |
| 4475 | work->is_slave = false; |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4476 | work->param = param; |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4477 | work->event = event; |
| 4478 | |
| 4479 | queue_work(mlx5_ib_event_wq, &work->work); |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 4480 | |
| 4481 | return NOTIFY_OK; |
| 4482 | } |
| 4483 | |
| 4484 | static int mlx5_ib_event_slave_port(struct notifier_block *nb, |
| 4485 | unsigned long event, void *param) |
| 4486 | { |
| 4487 | struct mlx5_ib_event_work *work; |
| 4488 | |
| 4489 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
| 4490 | if (!work) |
| 4491 | return NOTIFY_DONE; |
| 4492 | |
| 4493 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
| 4494 | work->mpi = container_of(nb, struct mlx5_ib_multiport_info, mdev_events); |
| 4495 | work->is_slave = true; |
| 4496 | work->param = param; |
| 4497 | work->event = event; |
| 4498 | queue_work(mlx5_ib_event_wq, &work->work); |
| 4499 | |
| 4500 | return NOTIFY_OK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4501 | } |
| 4502 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4503 | static int set_has_smi_cap(struct mlx5_ib_dev *dev) |
| 4504 | { |
| 4505 | struct mlx5_hca_vport_context vport_ctx; |
| 4506 | int err; |
| 4507 | int port; |
| 4508 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4509 | for (port = 1; port <= dev->num_ports; port++) { |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4510 | dev->mdev->port_caps[port - 1].has_smi = false; |
| 4511 | if (MLX5_CAP_GEN(dev->mdev, port_type) == |
| 4512 | MLX5_CAP_PORT_TYPE_IB) { |
| 4513 | if (MLX5_CAP_GEN(dev->mdev, ib_virt)) { |
| 4514 | err = mlx5_query_hca_vport_context(dev->mdev, 0, |
| 4515 | port, 0, |
| 4516 | &vport_ctx); |
| 4517 | if (err) { |
| 4518 | mlx5_ib_err(dev, "query_hca_vport_context for port=%d failed %d\n", |
| 4519 | port, err); |
| 4520 | return err; |
| 4521 | } |
| 4522 | dev->mdev->port_caps[port - 1].has_smi = |
| 4523 | vport_ctx.has_smi; |
| 4524 | } else { |
| 4525 | dev->mdev->port_caps[port - 1].has_smi = true; |
| 4526 | } |
| 4527 | } |
| 4528 | } |
| 4529 | return 0; |
| 4530 | } |
| 4531 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4532 | static void get_ext_port_caps(struct mlx5_ib_dev *dev) |
| 4533 | { |
| 4534 | int port; |
| 4535 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4536 | for (port = 1; port <= dev->num_ports; port++) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4537 | mlx5_query_ext_port_caps(dev, port); |
| 4538 | } |
| 4539 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4540 | static int get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4541 | { |
| 4542 | struct ib_device_attr *dprops = NULL; |
| 4543 | struct ib_port_attr *pprops = NULL; |
Dan Carpenter | f614fc1 | 2015-01-12 11:56:58 +0300 | [diff] [blame] | 4544 | int err = -ENOMEM; |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4545 | struct ib_udata uhw = {.inlen = 0, .outlen = 0}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4546 | |
| 4547 | pprops = kmalloc(sizeof(*pprops), GFP_KERNEL); |
| 4548 | if (!pprops) |
| 4549 | goto out; |
| 4550 | |
| 4551 | dprops = kmalloc(sizeof(*dprops), GFP_KERNEL); |
| 4552 | if (!dprops) |
| 4553 | goto out; |
| 4554 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4555 | err = set_has_smi_cap(dev); |
| 4556 | if (err) |
| 4557 | goto out; |
| 4558 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4559 | err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4560 | if (err) { |
| 4561 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
| 4562 | goto out; |
| 4563 | } |
| 4564 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4565 | memset(pprops, 0, sizeof(*pprops)); |
| 4566 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
| 4567 | if (err) { |
| 4568 | mlx5_ib_warn(dev, "query_port %d failed %d\n", |
| 4569 | port, err); |
| 4570 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4571 | } |
| 4572 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4573 | dev->mdev->port_caps[port - 1].pkey_table_len = |
| 4574 | dprops->max_pkeys; |
| 4575 | dev->mdev->port_caps[port - 1].gid_table_len = |
| 4576 | pprops->gid_tbl_len; |
| 4577 | mlx5_ib_dbg(dev, "port %d: pkey_table_len %d, gid_table_len %d\n", |
| 4578 | port, dprops->max_pkeys, pprops->gid_tbl_len); |
| 4579 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4580 | out: |
| 4581 | kfree(pprops); |
| 4582 | kfree(dprops); |
| 4583 | |
| 4584 | return err; |
| 4585 | } |
| 4586 | |
| 4587 | static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
| 4588 | { |
| 4589 | int err; |
| 4590 | |
| 4591 | err = mlx5_mr_cache_cleanup(dev); |
| 4592 | if (err) |
| 4593 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
| 4594 | |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4595 | if (dev->umrc.qp) |
| 4596 | mlx5_ib_destroy_qp(dev->umrc.qp); |
| 4597 | if (dev->umrc.cq) |
| 4598 | ib_free_cq(dev->umrc.cq); |
| 4599 | if (dev->umrc.pd) |
| 4600 | ib_dealloc_pd(dev->umrc.pd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | enum { |
| 4604 | MAX_UMR_WR = 128, |
| 4605 | }; |
| 4606 | |
| 4607 | static int create_umr_res(struct mlx5_ib_dev *dev) |
| 4608 | { |
| 4609 | struct ib_qp_init_attr *init_attr = NULL; |
| 4610 | struct ib_qp_attr *attr = NULL; |
| 4611 | struct ib_pd *pd; |
| 4612 | struct ib_cq *cq; |
| 4613 | struct ib_qp *qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4614 | int ret; |
| 4615 | |
| 4616 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| 4617 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 4618 | if (!attr || !init_attr) { |
| 4619 | ret = -ENOMEM; |
| 4620 | goto error_0; |
| 4621 | } |
| 4622 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 4623 | pd = ib_alloc_pd(&dev->ib_dev, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4624 | if (IS_ERR(pd)) { |
| 4625 | mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); |
| 4626 | ret = PTR_ERR(pd); |
| 4627 | goto error_0; |
| 4628 | } |
| 4629 | |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4630 | 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] | 4631 | if (IS_ERR(cq)) { |
| 4632 | mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); |
| 4633 | ret = PTR_ERR(cq); |
| 4634 | goto error_2; |
| 4635 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4636 | |
| 4637 | init_attr->send_cq = cq; |
| 4638 | init_attr->recv_cq = cq; |
| 4639 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
| 4640 | init_attr->cap.max_send_wr = MAX_UMR_WR; |
| 4641 | init_attr->cap.max_send_sge = 1; |
| 4642 | init_attr->qp_type = MLX5_IB_QPT_REG_UMR; |
| 4643 | init_attr->port_num = 1; |
| 4644 | qp = mlx5_ib_create_qp(pd, init_attr, NULL); |
| 4645 | if (IS_ERR(qp)) { |
| 4646 | mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); |
| 4647 | ret = PTR_ERR(qp); |
| 4648 | goto error_3; |
| 4649 | } |
| 4650 | qp->device = &dev->ib_dev; |
| 4651 | qp->real_qp = qp; |
| 4652 | qp->uobject = NULL; |
| 4653 | qp->qp_type = MLX5_IB_QPT_REG_UMR; |
Majd Dibbiny | 31fde03 | 2017-10-30 14:23:13 +0200 | [diff] [blame] | 4654 | qp->send_cq = init_attr->send_cq; |
| 4655 | qp->recv_cq = init_attr->recv_cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4656 | |
| 4657 | attr->qp_state = IB_QPS_INIT; |
| 4658 | attr->port_num = 1; |
| 4659 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX | |
| 4660 | IB_QP_PORT, NULL); |
| 4661 | if (ret) { |
| 4662 | mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); |
| 4663 | goto error_4; |
| 4664 | } |
| 4665 | |
| 4666 | memset(attr, 0, sizeof(*attr)); |
| 4667 | attr->qp_state = IB_QPS_RTR; |
| 4668 | attr->path_mtu = IB_MTU_256; |
| 4669 | |
| 4670 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4671 | if (ret) { |
| 4672 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); |
| 4673 | goto error_4; |
| 4674 | } |
| 4675 | |
| 4676 | memset(attr, 0, sizeof(*attr)); |
| 4677 | attr->qp_state = IB_QPS_RTS; |
| 4678 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4679 | if (ret) { |
| 4680 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); |
| 4681 | goto error_4; |
| 4682 | } |
| 4683 | |
| 4684 | dev->umrc.qp = qp; |
| 4685 | dev->umrc.cq = cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4686 | dev->umrc.pd = pd; |
| 4687 | |
| 4688 | sema_init(&dev->umrc.sem, MAX_UMR_WR); |
| 4689 | ret = mlx5_mr_cache_init(dev); |
| 4690 | if (ret) { |
| 4691 | mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); |
| 4692 | goto error_4; |
| 4693 | } |
| 4694 | |
| 4695 | kfree(attr); |
| 4696 | kfree(init_attr); |
| 4697 | |
| 4698 | return 0; |
| 4699 | |
| 4700 | error_4: |
| 4701 | mlx5_ib_destroy_qp(qp); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4702 | dev->umrc.qp = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4703 | |
| 4704 | error_3: |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4705 | ib_free_cq(cq); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4706 | dev->umrc.cq = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4707 | |
| 4708 | error_2: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4709 | ib_dealloc_pd(pd); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4710 | dev->umrc.pd = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4711 | |
| 4712 | error_0: |
| 4713 | kfree(attr); |
| 4714 | kfree(init_attr); |
| 4715 | return ret; |
| 4716 | } |
| 4717 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 4718 | static u8 mlx5_get_umr_fence(u8 umr_fence_cap) |
| 4719 | { |
| 4720 | switch (umr_fence_cap) { |
| 4721 | case MLX5_CAP_UMR_FENCE_NONE: |
| 4722 | return MLX5_FENCE_MODE_NONE; |
| 4723 | case MLX5_CAP_UMR_FENCE_SMALL: |
| 4724 | return MLX5_FENCE_MODE_INITIATOR_SMALL; |
| 4725 | default: |
| 4726 | return MLX5_FENCE_MODE_STRONG_ORDERING; |
| 4727 | } |
| 4728 | } |
| 4729 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4730 | static int create_dev_resources(struct mlx5_ib_resources *devr) |
| 4731 | { |
| 4732 | struct ib_srq_init_attr attr; |
| 4733 | struct mlx5_ib_dev *dev; |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4734 | struct ib_device *ibdev; |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 4735 | struct ib_cq_init_attr cq_attr = {.cqe = 1}; |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4736 | int port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4737 | int ret = 0; |
| 4738 | |
| 4739 | dev = container_of(devr, struct mlx5_ib_dev, devr); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4740 | ibdev = &dev->ib_dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4741 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4742 | mutex_init(&devr->mutex); |
| 4743 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4744 | devr->p0 = rdma_zalloc_drv_obj(ibdev, ib_pd); |
| 4745 | if (!devr->p0) |
| 4746 | return -ENOMEM; |
| 4747 | |
| 4748 | devr->p0->device = ibdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4749 | devr->p0->uobject = NULL; |
| 4750 | atomic_set(&devr->p0->usecnt, 0); |
| 4751 | |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4752 | ret = mlx5_ib_alloc_pd(devr->p0, NULL, NULL); |
| 4753 | if (ret) |
| 4754 | goto error0; |
| 4755 | |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 4756 | devr->c0 = mlx5_ib_create_cq(&dev->ib_dev, &cq_attr, NULL, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4757 | if (IS_ERR(devr->c0)) { |
| 4758 | ret = PTR_ERR(devr->c0); |
| 4759 | goto error1; |
| 4760 | } |
| 4761 | devr->c0->device = &dev->ib_dev; |
| 4762 | devr->c0->uobject = NULL; |
| 4763 | devr->c0->comp_handler = NULL; |
| 4764 | devr->c0->event_handler = NULL; |
| 4765 | devr->c0->cq_context = NULL; |
| 4766 | atomic_set(&devr->c0->usecnt, 0); |
| 4767 | |
| 4768 | devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 4769 | if (IS_ERR(devr->x0)) { |
| 4770 | ret = PTR_ERR(devr->x0); |
| 4771 | goto error2; |
| 4772 | } |
| 4773 | devr->x0->device = &dev->ib_dev; |
| 4774 | devr->x0->inode = NULL; |
| 4775 | atomic_set(&devr->x0->usecnt, 0); |
| 4776 | mutex_init(&devr->x0->tgt_qp_mutex); |
| 4777 | INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
| 4778 | |
| 4779 | devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 4780 | if (IS_ERR(devr->x1)) { |
| 4781 | ret = PTR_ERR(devr->x1); |
| 4782 | goto error3; |
| 4783 | } |
| 4784 | devr->x1->device = &dev->ib_dev; |
| 4785 | devr->x1->inode = NULL; |
| 4786 | atomic_set(&devr->x1->usecnt, 0); |
| 4787 | mutex_init(&devr->x1->tgt_qp_mutex); |
| 4788 | INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
| 4789 | |
| 4790 | memset(&attr, 0, sizeof(attr)); |
| 4791 | attr.attr.max_sge = 1; |
| 4792 | attr.attr.max_wr = 1; |
| 4793 | attr.srq_type = IB_SRQT_XRC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4794 | attr.ext.cq = devr->c0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4795 | attr.ext.xrc.xrcd = devr->x0; |
| 4796 | |
| 4797 | devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 4798 | if (IS_ERR(devr->s0)) { |
| 4799 | ret = PTR_ERR(devr->s0); |
| 4800 | goto error4; |
| 4801 | } |
| 4802 | devr->s0->device = &dev->ib_dev; |
| 4803 | devr->s0->pd = devr->p0; |
| 4804 | devr->s0->uobject = NULL; |
| 4805 | devr->s0->event_handler = NULL; |
| 4806 | devr->s0->srq_context = NULL; |
| 4807 | devr->s0->srq_type = IB_SRQT_XRC; |
| 4808 | devr->s0->ext.xrc.xrcd = devr->x0; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4809 | devr->s0->ext.cq = devr->c0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4810 | atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4811 | atomic_inc(&devr->s0->ext.cq->usecnt); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4812 | atomic_inc(&devr->p0->usecnt); |
| 4813 | atomic_set(&devr->s0->usecnt, 0); |
| 4814 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4815 | memset(&attr, 0, sizeof(attr)); |
| 4816 | attr.attr.max_sge = 1; |
| 4817 | attr.attr.max_wr = 1; |
| 4818 | attr.srq_type = IB_SRQT_BASIC; |
| 4819 | devr->s1 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 4820 | if (IS_ERR(devr->s1)) { |
| 4821 | ret = PTR_ERR(devr->s1); |
| 4822 | goto error5; |
| 4823 | } |
| 4824 | devr->s1->device = &dev->ib_dev; |
| 4825 | devr->s1->pd = devr->p0; |
| 4826 | devr->s1->uobject = NULL; |
| 4827 | devr->s1->event_handler = NULL; |
| 4828 | devr->s1->srq_context = NULL; |
| 4829 | devr->s1->srq_type = IB_SRQT_BASIC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4830 | devr->s1->ext.cq = devr->c0; |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4831 | atomic_inc(&devr->p0->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4832 | atomic_set(&devr->s1->usecnt, 0); |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4833 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4834 | for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) { |
| 4835 | INIT_WORK(&devr->ports[port].pkey_change_work, |
| 4836 | pkey_change_handler); |
| 4837 | devr->ports[port].devr = devr; |
| 4838 | } |
| 4839 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4840 | return 0; |
| 4841 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4842 | error5: |
| 4843 | mlx5_ib_destroy_srq(devr->s0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4844 | error4: |
| 4845 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 4846 | error3: |
| 4847 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 4848 | error2: |
| 4849 | mlx5_ib_destroy_cq(devr->c0); |
| 4850 | error1: |
| 4851 | mlx5_ib_dealloc_pd(devr->p0); |
| 4852 | error0: |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4853 | kfree(devr->p0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4854 | return ret; |
| 4855 | } |
| 4856 | |
| 4857 | static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
| 4858 | { |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4859 | struct mlx5_ib_dev *dev = |
| 4860 | container_of(devr, struct mlx5_ib_dev, devr); |
| 4861 | int port; |
| 4862 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4863 | mlx5_ib_destroy_srq(devr->s1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4864 | mlx5_ib_destroy_srq(devr->s0); |
| 4865 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 4866 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 4867 | mlx5_ib_destroy_cq(devr->c0); |
| 4868 | mlx5_ib_dealloc_pd(devr->p0); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 4869 | kfree(devr->p0); |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4870 | |
| 4871 | /* Make sure no change P_Key work items are still executing */ |
| 4872 | for (port = 0; port < dev->num_ports; ++port) |
| 4873 | cancel_work_sync(&devr->ports[port].pkey_change_work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4874 | } |
| 4875 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4876 | static u32 get_core_cap_flags(struct ib_device *ibdev, |
| 4877 | struct mlx5_hca_vport_context *rep) |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4878 | { |
| 4879 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 4880 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, 1); |
| 4881 | u8 l3_type_cap = MLX5_CAP_ROCE(dev->mdev, l3_type); |
| 4882 | u8 roce_version_cap = MLX5_CAP_ROCE(dev->mdev, roce_version); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 4883 | bool raw_support = !mlx5_core_mp_enabled(dev->mdev); |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4884 | u32 ret = 0; |
| 4885 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4886 | if (rep->grh_required) |
| 4887 | ret |= RDMA_CORE_CAP_IB_GRH_REQUIRED; |
| 4888 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4889 | if (ll == IB_LINK_LAYER_INFINIBAND) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4890 | return ret | RDMA_CORE_PORT_IBA_IB; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4891 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 4892 | if (raw_support) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4893 | ret |= RDMA_CORE_PORT_RAW_PACKET; |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4894 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4895 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV4_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4896 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4897 | |
| 4898 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV6_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4899 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4900 | |
| 4901 | if (roce_version_cap & MLX5_ROCE_VERSION_1_CAP) |
| 4902 | ret |= RDMA_CORE_PORT_IBA_ROCE; |
| 4903 | |
| 4904 | if (roce_version_cap & MLX5_ROCE_VERSION_2_CAP) |
| 4905 | ret |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; |
| 4906 | |
| 4907 | return ret; |
| 4908 | } |
| 4909 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4910 | static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 4911 | struct ib_port_immutable *immutable) |
| 4912 | { |
| 4913 | struct ib_port_attr attr; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4914 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 4915 | 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] | 4916 | struct mlx5_hca_vport_context rep = {0}; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4917 | int err; |
| 4918 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 4919 | err = ib_query_port(ibdev, port_num, &attr); |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4920 | if (err) |
| 4921 | return err; |
| 4922 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4923 | if (ll == IB_LINK_LAYER_INFINIBAND) { |
| 4924 | err = mlx5_query_hca_vport_context(dev->mdev, 0, port_num, 0, |
| 4925 | &rep); |
| 4926 | if (err) |
| 4927 | return err; |
| 4928 | } |
| 4929 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4930 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 4931 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4932 | immutable->core_cap_flags = get_core_cap_flags(ibdev, &rep); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4933 | if ((ll == IB_LINK_LAYER_INFINIBAND) || MLX5_CAP_GEN(dev->mdev, roce)) |
| 4934 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4935 | |
| 4936 | return 0; |
| 4937 | } |
| 4938 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 4939 | static int mlx5_port_rep_immutable(struct ib_device *ibdev, u8 port_num, |
| 4940 | struct ib_port_immutable *immutable) |
| 4941 | { |
| 4942 | struct ib_port_attr attr; |
| 4943 | int err; |
| 4944 | |
| 4945 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 4946 | |
| 4947 | err = ib_query_port(ibdev, port_num, &attr); |
| 4948 | if (err) |
| 4949 | return err; |
| 4950 | |
| 4951 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 4952 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 4953 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 4954 | |
| 4955 | return 0; |
| 4956 | } |
| 4957 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 4958 | static void get_dev_fw_str(struct ib_device *ibdev, char *str) |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 4959 | { |
| 4960 | struct mlx5_ib_dev *dev = |
| 4961 | container_of(ibdev, struct mlx5_ib_dev, ib_dev); |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 4962 | snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%04d", |
| 4963 | fw_rev_maj(dev->mdev), fw_rev_min(dev->mdev), |
| 4964 | fw_rev_sub(dev->mdev)); |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 4965 | } |
| 4966 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4967 | static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4968 | { |
| 4969 | struct mlx5_core_dev *mdev = dev->mdev; |
| 4970 | struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(mdev, |
| 4971 | MLX5_FLOW_NAMESPACE_LAG); |
| 4972 | struct mlx5_flow_table *ft; |
| 4973 | int err; |
| 4974 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 4975 | if (!ns || !mlx5_lag_is_roce(mdev)) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4976 | return 0; |
| 4977 | |
| 4978 | err = mlx5_cmd_create_vport_lag(mdev); |
| 4979 | if (err) |
| 4980 | return err; |
| 4981 | |
| 4982 | ft = mlx5_create_lag_demux_flow_table(ns, 0, 0); |
| 4983 | if (IS_ERR(ft)) { |
| 4984 | err = PTR_ERR(ft); |
| 4985 | goto err_destroy_vport_lag; |
| 4986 | } |
| 4987 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 4988 | dev->flow_db->lag_demux_ft = ft; |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 4989 | dev->lag_active = true; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4990 | return 0; |
| 4991 | |
| 4992 | err_destroy_vport_lag: |
| 4993 | mlx5_cmd_destroy_vport_lag(mdev); |
| 4994 | return err; |
| 4995 | } |
| 4996 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4997 | static void mlx5_eth_lag_cleanup(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4998 | { |
| 4999 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5000 | |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 5001 | if (dev->lag_active) { |
| 5002 | dev->lag_active = false; |
| 5003 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5004 | mlx5_destroy_flow_table(dev->flow_db->lag_demux_ft); |
| 5005 | dev->flow_db->lag_demux_ft = NULL; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5006 | |
| 5007 | mlx5_cmd_destroy_vport_lag(mdev); |
| 5008 | } |
| 5009 | } |
| 5010 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5011 | 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] | 5012 | { |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5013 | int err; |
| 5014 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5015 | dev->roce[port_num].nb.notifier_call = mlx5_netdev_event; |
| 5016 | err = register_netdevice_notifier(&dev->roce[port_num].nb); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 5017 | if (err) { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5018 | dev->roce[port_num].nb.notifier_call = NULL; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5019 | return err; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 5020 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5021 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 5022 | return 0; |
| 5023 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5024 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5025 | 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] | 5026 | { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 5027 | if (dev->roce[port_num].nb.notifier_call) { |
| 5028 | unregister_netdevice_notifier(&dev->roce[port_num].nb); |
| 5029 | dev->roce[port_num].nb.notifier_call = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5030 | } |
| 5031 | } |
| 5032 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5033 | static int mlx5_enable_eth(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5034 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5035 | int err; |
| 5036 | |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5037 | if (MLX5_CAP_GEN(dev->mdev, roce)) { |
| 5038 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 5039 | if (err) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5040 | return err; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5041 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5042 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5043 | err = mlx5_eth_lag_init(dev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5044 | if (err) |
| 5045 | goto err_disable_roce; |
| 5046 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5047 | return 0; |
| 5048 | |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5049 | err_disable_roce: |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5050 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 5051 | mlx5_nic_vport_disable_roce(dev->mdev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 5052 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 5053 | return err; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5054 | } |
| 5055 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5056 | static void mlx5_disable_eth(struct mlx5_ib_dev *dev) |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5057 | { |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 5058 | mlx5_eth_lag_cleanup(dev); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 5059 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 5060 | mlx5_nic_vport_disable_roce(dev->mdev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5061 | } |
| 5062 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5063 | struct mlx5_ib_counter { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5064 | const char *name; |
| 5065 | size_t offset; |
| 5066 | }; |
| 5067 | |
| 5068 | #define INIT_Q_COUNTER(_name) \ |
| 5069 | { .name = #_name, .offset = MLX5_BYTE_OFF(query_q_counter_out, _name)} |
| 5070 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5071 | static const struct mlx5_ib_counter basic_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5072 | INIT_Q_COUNTER(rx_write_requests), |
| 5073 | INIT_Q_COUNTER(rx_read_requests), |
| 5074 | INIT_Q_COUNTER(rx_atomic_requests), |
| 5075 | INIT_Q_COUNTER(out_of_buffer), |
| 5076 | }; |
| 5077 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5078 | static const struct mlx5_ib_counter out_of_seq_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5079 | INIT_Q_COUNTER(out_of_sequence), |
| 5080 | }; |
| 5081 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5082 | static const struct mlx5_ib_counter retrans_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5083 | INIT_Q_COUNTER(duplicate_request), |
| 5084 | INIT_Q_COUNTER(rnr_nak_retry_err), |
| 5085 | INIT_Q_COUNTER(packet_seq_err), |
| 5086 | INIT_Q_COUNTER(implied_nak_seq_err), |
| 5087 | INIT_Q_COUNTER(local_ack_timeout_err), |
| 5088 | }; |
| 5089 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5090 | #define INIT_CONG_COUNTER(_name) \ |
| 5091 | { .name = #_name, .offset = \ |
| 5092 | MLX5_BYTE_OFF(query_cong_statistics_out, _name ## _high)} |
| 5093 | |
| 5094 | static const struct mlx5_ib_counter cong_cnts[] = { |
| 5095 | INIT_CONG_COUNTER(rp_cnp_ignored), |
| 5096 | INIT_CONG_COUNTER(rp_cnp_handled), |
| 5097 | INIT_CONG_COUNTER(np_ecn_marked_roce_packets), |
| 5098 | INIT_CONG_COUNTER(np_cnp_sent), |
| 5099 | }; |
| 5100 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5101 | static const struct mlx5_ib_counter extended_err_cnts[] = { |
| 5102 | INIT_Q_COUNTER(resp_local_length_error), |
| 5103 | INIT_Q_COUNTER(resp_cqe_error), |
| 5104 | INIT_Q_COUNTER(req_cqe_error), |
| 5105 | INIT_Q_COUNTER(req_remote_invalid_request), |
| 5106 | INIT_Q_COUNTER(req_remote_access_errors), |
| 5107 | INIT_Q_COUNTER(resp_remote_access_errors), |
| 5108 | INIT_Q_COUNTER(resp_cqe_flush_error), |
| 5109 | INIT_Q_COUNTER(req_cqe_flush_error), |
| 5110 | }; |
| 5111 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5112 | #define INIT_EXT_PPCNT_COUNTER(_name) \ |
| 5113 | { .name = #_name, .offset = \ |
| 5114 | MLX5_BYTE_OFF(ppcnt_reg, \ |
| 5115 | counter_set.eth_extended_cntrs_grp_data_layout._name##_high)} |
| 5116 | |
| 5117 | static const struct mlx5_ib_counter ext_ppcnt_cnts[] = { |
| 5118 | INIT_EXT_PPCNT_COUNTER(rx_icrc_encapsulated), |
| 5119 | }; |
| 5120 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5121 | static void mlx5_ib_dealloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5122 | { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5123 | int i; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5124 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5125 | for (i = 0; i < dev->num_ports; i++) { |
Parav Pandit | 921c0f5 | 2018-07-08 13:40:30 +0300 | [diff] [blame] | 5126 | if (dev->port[i].cnts.set_id_valid) |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5127 | mlx5_core_dealloc_q_counter(dev->mdev, |
| 5128 | dev->port[i].cnts.set_id); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5129 | kfree(dev->port[i].cnts.names); |
| 5130 | kfree(dev->port[i].cnts.offsets); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5131 | } |
| 5132 | } |
| 5133 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5134 | static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, |
| 5135 | struct mlx5_ib_counters *cnts) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5136 | { |
| 5137 | u32 num_counters; |
| 5138 | |
| 5139 | num_counters = ARRAY_SIZE(basic_q_cnts); |
| 5140 | |
| 5141 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) |
| 5142 | num_counters += ARRAY_SIZE(out_of_seq_q_cnts); |
| 5143 | |
| 5144 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) |
| 5145 | num_counters += ARRAY_SIZE(retrans_q_cnts); |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5146 | |
| 5147 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) |
| 5148 | num_counters += ARRAY_SIZE(extended_err_cnts); |
| 5149 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5150 | cnts->num_q_counters = num_counters; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5151 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5152 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 5153 | cnts->num_cong_counters = ARRAY_SIZE(cong_cnts); |
| 5154 | num_counters += ARRAY_SIZE(cong_cnts); |
| 5155 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5156 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5157 | cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts); |
| 5158 | num_counters += ARRAY_SIZE(ext_ppcnt_cnts); |
| 5159 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5160 | cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL); |
| 5161 | if (!cnts->names) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5162 | return -ENOMEM; |
| 5163 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5164 | cnts->offsets = kcalloc(num_counters, |
| 5165 | sizeof(cnts->offsets), GFP_KERNEL); |
| 5166 | if (!cnts->offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5167 | goto err_names; |
| 5168 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5169 | return 0; |
| 5170 | |
| 5171 | err_names: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5172 | kfree(cnts->names); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5173 | cnts->names = NULL; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5174 | return -ENOMEM; |
| 5175 | } |
| 5176 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5177 | static void mlx5_ib_fill_counters(struct mlx5_ib_dev *dev, |
| 5178 | const char **names, |
| 5179 | size_t *offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5180 | { |
| 5181 | int i; |
| 5182 | int j = 0; |
| 5183 | |
| 5184 | for (i = 0; i < ARRAY_SIZE(basic_q_cnts); i++, j++) { |
| 5185 | names[j] = basic_q_cnts[i].name; |
| 5186 | offsets[j] = basic_q_cnts[i].offset; |
| 5187 | } |
| 5188 | |
| 5189 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) { |
| 5190 | for (i = 0; i < ARRAY_SIZE(out_of_seq_q_cnts); i++, j++) { |
| 5191 | names[j] = out_of_seq_q_cnts[i].name; |
| 5192 | offsets[j] = out_of_seq_q_cnts[i].offset; |
| 5193 | } |
| 5194 | } |
| 5195 | |
| 5196 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) { |
| 5197 | for (i = 0; i < ARRAY_SIZE(retrans_q_cnts); i++, j++) { |
| 5198 | names[j] = retrans_q_cnts[i].name; |
| 5199 | offsets[j] = retrans_q_cnts[i].offset; |
| 5200 | } |
| 5201 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5202 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5203 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) { |
| 5204 | for (i = 0; i < ARRAY_SIZE(extended_err_cnts); i++, j++) { |
| 5205 | names[j] = extended_err_cnts[i].name; |
| 5206 | offsets[j] = extended_err_cnts[i].offset; |
| 5207 | } |
| 5208 | } |
| 5209 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5210 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 5211 | for (i = 0; i < ARRAY_SIZE(cong_cnts); i++, j++) { |
| 5212 | names[j] = cong_cnts[i].name; |
| 5213 | offsets[j] = cong_cnts[i].offset; |
| 5214 | } |
| 5215 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5216 | |
| 5217 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5218 | for (i = 0; i < ARRAY_SIZE(ext_ppcnt_cnts); i++, j++) { |
| 5219 | names[j] = ext_ppcnt_cnts[i].name; |
| 5220 | offsets[j] = ext_ppcnt_cnts[i].offset; |
| 5221 | } |
| 5222 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5223 | } |
| 5224 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5225 | static int mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5226 | { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5227 | int err = 0; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5228 | int i; |
Yishai Hadas | aa74be6 | 2018-12-09 12:52:36 +0200 | [diff] [blame] | 5229 | bool is_shared; |
| 5230 | |
| 5231 | is_shared = MLX5_CAP_GEN(dev->mdev, log_max_uctx) != 0; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5232 | |
| 5233 | for (i = 0; i < dev->num_ports; i++) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5234 | err = __mlx5_ib_alloc_counters(dev, &dev->port[i].cnts); |
| 5235 | if (err) |
| 5236 | goto err_alloc; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5237 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5238 | mlx5_ib_fill_counters(dev, dev->port[i].cnts.names, |
| 5239 | dev->port[i].cnts.offsets); |
| 5240 | |
Yishai Hadas | aa74be6 | 2018-12-09 12:52:36 +0200 | [diff] [blame] | 5241 | err = mlx5_cmd_alloc_q_counter(dev->mdev, |
| 5242 | &dev->port[i].cnts.set_id, |
| 5243 | is_shared ? |
| 5244 | MLX5_SHARED_RESOURCE_UID : 0); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5245 | if (err) { |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5246 | mlx5_ib_warn(dev, |
| 5247 | "couldn't allocate queue counter for port %d, err %d\n", |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5248 | i + 1, err); |
| 5249 | goto err_alloc; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5250 | } |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5251 | dev->port[i].cnts.set_id_valid = true; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | return 0; |
| 5255 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5256 | err_alloc: |
| 5257 | mlx5_ib_dealloc_counters(dev); |
| 5258 | return err; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5259 | } |
| 5260 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5261 | static struct rdma_hw_stats *mlx5_ib_alloc_hw_stats(struct ib_device *ibdev, |
| 5262 | u8 port_num) |
| 5263 | { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5264 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5265 | struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5266 | |
| 5267 | /* We support only per port stats */ |
| 5268 | if (port_num == 0) |
| 5269 | return NULL; |
| 5270 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5271 | return rdma_alloc_hw_stats_struct(port->cnts.names, |
| 5272 | port->cnts.num_q_counters + |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5273 | port->cnts.num_cong_counters + |
| 5274 | port->cnts.num_ext_ppcnt_counters, |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5275 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 5276 | } |
| 5277 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5278 | static int mlx5_ib_query_q_counters(struct mlx5_core_dev *mdev, |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5279 | struct mlx5_ib_port *port, |
| 5280 | struct rdma_hw_stats *stats) |
| 5281 | { |
| 5282 | int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); |
| 5283 | void *out; |
| 5284 | __be32 val; |
| 5285 | int ret, i; |
| 5286 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5287 | out = kvzalloc(outlen, GFP_KERNEL); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5288 | if (!out) |
| 5289 | return -ENOMEM; |
| 5290 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5291 | ret = mlx5_core_query_q_counter(mdev, |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5292 | port->cnts.set_id, 0, |
| 5293 | out, outlen); |
| 5294 | if (ret) |
| 5295 | goto free; |
| 5296 | |
| 5297 | for (i = 0; i < port->cnts.num_q_counters; i++) { |
| 5298 | val = *(__be32 *)(out + port->cnts.offsets[i]); |
| 5299 | stats->value[i] = (u64)be32_to_cpu(val); |
| 5300 | } |
| 5301 | |
| 5302 | free: |
| 5303 | kvfree(out); |
| 5304 | return ret; |
| 5305 | } |
| 5306 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5307 | static int mlx5_ib_query_ext_ppcnt_counters(struct mlx5_ib_dev *dev, |
| 5308 | struct mlx5_ib_port *port, |
| 5309 | struct rdma_hw_stats *stats) |
| 5310 | { |
| 5311 | int offset = port->cnts.num_q_counters + port->cnts.num_cong_counters; |
| 5312 | int sz = MLX5_ST_SZ_BYTES(ppcnt_reg); |
| 5313 | int ret, i; |
| 5314 | void *out; |
| 5315 | |
| 5316 | out = kvzalloc(sz, GFP_KERNEL); |
| 5317 | if (!out) |
| 5318 | return -ENOMEM; |
| 5319 | |
| 5320 | ret = mlx5_cmd_query_ext_ppcnt_counters(dev->mdev, out); |
| 5321 | if (ret) |
| 5322 | goto free; |
| 5323 | |
| 5324 | for (i = 0; i < port->cnts.num_ext_ppcnt_counters; i++) { |
| 5325 | stats->value[i + offset] = |
| 5326 | be64_to_cpup((__be64 *)(out + |
| 5327 | port->cnts.offsets[i + offset])); |
| 5328 | } |
| 5329 | |
| 5330 | free: |
| 5331 | kvfree(out); |
| 5332 | return ret; |
| 5333 | } |
| 5334 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5335 | static int mlx5_ib_get_hw_stats(struct ib_device *ibdev, |
| 5336 | struct rdma_hw_stats *stats, |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5337 | u8 port_num, int index) |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5338 | { |
| 5339 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5340 | struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5341 | struct mlx5_core_dev *mdev; |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5342 | int ret, num_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5343 | u8 mdev_port_num; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5344 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5345 | if (!stats) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5346 | return -EINVAL; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5347 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5348 | num_counters = port->cnts.num_q_counters + |
| 5349 | port->cnts.num_cong_counters + |
| 5350 | port->cnts.num_ext_ppcnt_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5351 | |
| 5352 | /* q_counters are per IB device, query the master mdev */ |
| 5353 | ret = mlx5_ib_query_q_counters(dev->mdev, port, stats); |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5354 | if (ret) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5355 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5356 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5357 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5358 | ret = mlx5_ib_query_ext_ppcnt_counters(dev, port, stats); |
| 5359 | if (ret) |
| 5360 | return ret; |
| 5361 | } |
| 5362 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5363 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5364 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, |
| 5365 | &mdev_port_num); |
| 5366 | if (!mdev) { |
| 5367 | /* If port is not affiliated yet, its in down state |
| 5368 | * which doesn't have any counters yet, so it would be |
| 5369 | * zero. So no need to read from the HCA. |
| 5370 | */ |
| 5371 | goto done; |
| 5372 | } |
Majd Dibbiny | 71a0ff6 | 2017-12-21 17:38:26 +0200 | [diff] [blame] | 5373 | ret = mlx5_lag_query_cong_counters(dev->mdev, |
| 5374 | stats->value + |
| 5375 | port->cnts.num_q_counters, |
| 5376 | port->cnts.num_cong_counters, |
| 5377 | port->cnts.offsets + |
| 5378 | port->cnts.num_q_counters); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5379 | |
| 5380 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5381 | if (ret) |
| 5382 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5383 | } |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5384 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5385 | done: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5386 | return num_counters; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5387 | } |
| 5388 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5389 | static int mlx5_ib_rn_get_params(struct ib_device *device, u8 port_num, |
| 5390 | enum rdma_netdev_t type, |
| 5391 | struct rdma_netdev_alloc_params *params) |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5392 | { |
| 5393 | if (type != RDMA_NETDEV_IPOIB) |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5394 | return -EOPNOTSUPP; |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5395 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 5396 | return mlx5_rdma_rn_get_params(to_mdev(device)->mdev, device, params); |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5397 | } |
| 5398 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5399 | static void delay_drop_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 5400 | { |
| 5401 | if (!dev->delay_drop.dbg) |
| 5402 | return; |
| 5403 | debugfs_remove_recursive(dev->delay_drop.dbg->dir_debugfs); |
| 5404 | kfree(dev->delay_drop.dbg); |
| 5405 | dev->delay_drop.dbg = NULL; |
| 5406 | } |
| 5407 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5408 | static void cancel_delay_drop(struct mlx5_ib_dev *dev) |
| 5409 | { |
| 5410 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5411 | return; |
| 5412 | |
| 5413 | cancel_work_sync(&dev->delay_drop.delay_drop_work); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5414 | delay_drop_debugfs_cleanup(dev); |
| 5415 | } |
| 5416 | |
| 5417 | static ssize_t delay_drop_timeout_read(struct file *filp, char __user *buf, |
| 5418 | size_t count, loff_t *pos) |
| 5419 | { |
| 5420 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5421 | char lbuf[20]; |
| 5422 | int len; |
| 5423 | |
| 5424 | len = snprintf(lbuf, sizeof(lbuf), "%u\n", delay_drop->timeout); |
| 5425 | return simple_read_from_buffer(buf, count, pos, lbuf, len); |
| 5426 | } |
| 5427 | |
| 5428 | static ssize_t delay_drop_timeout_write(struct file *filp, const char __user *buf, |
| 5429 | size_t count, loff_t *pos) |
| 5430 | { |
| 5431 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5432 | u32 timeout; |
| 5433 | u32 var; |
| 5434 | |
| 5435 | if (kstrtouint_from_user(buf, count, 0, &var)) |
| 5436 | return -EFAULT; |
| 5437 | |
| 5438 | timeout = min_t(u32, roundup(var, 100), MLX5_MAX_DELAY_DROP_TIMEOUT_MS * |
| 5439 | 1000); |
| 5440 | if (timeout != var) |
| 5441 | mlx5_ib_dbg(delay_drop->dev, "Round delay drop timeout to %u usec\n", |
| 5442 | timeout); |
| 5443 | |
| 5444 | delay_drop->timeout = timeout; |
| 5445 | |
| 5446 | return count; |
| 5447 | } |
| 5448 | |
| 5449 | static const struct file_operations fops_delay_drop_timeout = { |
| 5450 | .owner = THIS_MODULE, |
| 5451 | .open = simple_open, |
| 5452 | .write = delay_drop_timeout_write, |
| 5453 | .read = delay_drop_timeout_read, |
| 5454 | }; |
| 5455 | |
| 5456 | static int delay_drop_debugfs_init(struct mlx5_ib_dev *dev) |
| 5457 | { |
| 5458 | struct mlx5_ib_dbg_delay_drop *dbg; |
| 5459 | |
| 5460 | if (!mlx5_debugfs_root) |
| 5461 | return 0; |
| 5462 | |
| 5463 | dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); |
| 5464 | if (!dbg) |
| 5465 | return -ENOMEM; |
| 5466 | |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5467 | dev->delay_drop.dbg = dbg; |
| 5468 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5469 | dbg->dir_debugfs = |
| 5470 | debugfs_create_dir("delay_drop", |
| 5471 | dev->mdev->priv.dbg_root); |
| 5472 | if (!dbg->dir_debugfs) |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5473 | goto out_debugfs; |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5474 | |
| 5475 | dbg->events_cnt_debugfs = |
| 5476 | debugfs_create_atomic_t("num_timeout_events", 0400, |
| 5477 | dbg->dir_debugfs, |
| 5478 | &dev->delay_drop.events_cnt); |
| 5479 | if (!dbg->events_cnt_debugfs) |
| 5480 | goto out_debugfs; |
| 5481 | |
| 5482 | dbg->rqs_cnt_debugfs = |
| 5483 | debugfs_create_atomic_t("num_rqs", 0400, |
| 5484 | dbg->dir_debugfs, |
| 5485 | &dev->delay_drop.rqs_cnt); |
| 5486 | if (!dbg->rqs_cnt_debugfs) |
| 5487 | goto out_debugfs; |
| 5488 | |
| 5489 | dbg->timeout_debugfs = |
| 5490 | debugfs_create_file("timeout", 0600, |
| 5491 | dbg->dir_debugfs, |
| 5492 | &dev->delay_drop, |
| 5493 | &fops_delay_drop_timeout); |
| 5494 | if (!dbg->timeout_debugfs) |
| 5495 | goto out_debugfs; |
| 5496 | |
| 5497 | return 0; |
| 5498 | |
| 5499 | out_debugfs: |
| 5500 | delay_drop_debugfs_cleanup(dev); |
| 5501 | return -ENOMEM; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | static void init_delay_drop(struct mlx5_ib_dev *dev) |
| 5505 | { |
| 5506 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5507 | return; |
| 5508 | |
| 5509 | mutex_init(&dev->delay_drop.lock); |
| 5510 | dev->delay_drop.dev = dev; |
| 5511 | dev->delay_drop.activate = false; |
| 5512 | dev->delay_drop.timeout = MLX5_MAX_DELAY_DROP_TIMEOUT_MS * 1000; |
| 5513 | INIT_WORK(&dev->delay_drop.delay_drop_work, delay_drop_handler); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5514 | atomic_set(&dev->delay_drop.rqs_cnt, 0); |
| 5515 | atomic_set(&dev->delay_drop.events_cnt, 0); |
| 5516 | |
| 5517 | if (delay_drop_debugfs_init(dev)) |
| 5518 | mlx5_ib_warn(dev, "Failed to init delay drop debugfs\n"); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5519 | } |
| 5520 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5521 | /* The mlx5_ib_multiport_mutex should be held when calling this function */ |
| 5522 | static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5523 | struct mlx5_ib_multiport_info *mpi) |
| 5524 | { |
| 5525 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5526 | struct mlx5_ib_port *port = &ibdev->port[port_num]; |
| 5527 | int comps; |
| 5528 | int err; |
| 5529 | int i; |
| 5530 | |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5531 | mlx5_ib_cleanup_cong_debugfs(ibdev, port_num); |
| 5532 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5533 | spin_lock(&port->mp.mpi_lock); |
| 5534 | if (!mpi->ibdev) { |
| 5535 | spin_unlock(&port->mp.mpi_lock); |
| 5536 | return; |
| 5537 | } |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5538 | |
| 5539 | if (mpi->mdev_events.notifier_call) |
| 5540 | mlx5_notifier_unregister(mpi->mdev, &mpi->mdev_events); |
| 5541 | mpi->mdev_events.notifier_call = NULL; |
| 5542 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5543 | mpi->ibdev = NULL; |
| 5544 | |
| 5545 | spin_unlock(&port->mp.mpi_lock); |
| 5546 | mlx5_remove_netdev_notifier(ibdev, port_num); |
| 5547 | spin_lock(&port->mp.mpi_lock); |
| 5548 | |
| 5549 | comps = mpi->mdev_refcnt; |
| 5550 | if (comps) { |
| 5551 | mpi->unaffiliate = true; |
| 5552 | init_completion(&mpi->unref_comp); |
| 5553 | spin_unlock(&port->mp.mpi_lock); |
| 5554 | |
| 5555 | for (i = 0; i < comps; i++) |
| 5556 | wait_for_completion(&mpi->unref_comp); |
| 5557 | |
| 5558 | spin_lock(&port->mp.mpi_lock); |
| 5559 | mpi->unaffiliate = false; |
| 5560 | } |
| 5561 | |
| 5562 | port->mp.mpi = NULL; |
| 5563 | |
| 5564 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 5565 | |
| 5566 | spin_unlock(&port->mp.mpi_lock); |
| 5567 | |
| 5568 | err = mlx5_nic_vport_unaffiliate_multiport(mpi->mdev); |
| 5569 | |
| 5570 | mlx5_ib_dbg(ibdev, "unaffiliated port %d\n", port_num + 1); |
| 5571 | /* Log an error, still needed to cleanup the pointers and add |
| 5572 | * it back to the list. |
| 5573 | */ |
| 5574 | if (err) |
| 5575 | mlx5_ib_err(ibdev, "Failed to unaffiliate port %u\n", |
| 5576 | port_num + 1); |
| 5577 | |
| 5578 | ibdev->roce[port_num].last_port_state = IB_PORT_DOWN; |
| 5579 | } |
| 5580 | |
| 5581 | /* The mlx5_ib_multiport_mutex should be held when calling this function */ |
| 5582 | static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5583 | struct mlx5_ib_multiport_info *mpi) |
| 5584 | { |
| 5585 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5586 | int err; |
| 5587 | |
| 5588 | spin_lock(&ibdev->port[port_num].mp.mpi_lock); |
| 5589 | if (ibdev->port[port_num].mp.mpi) { |
Qing Huang | 2577188 | 2018-07-23 14:15:08 -0700 | [diff] [blame] | 5590 | mlx5_ib_dbg(ibdev, "port %d already affiliated.\n", |
| 5591 | port_num + 1); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5592 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5593 | return false; |
| 5594 | } |
| 5595 | |
| 5596 | ibdev->port[port_num].mp.mpi = mpi; |
| 5597 | mpi->ibdev = ibdev; |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5598 | mpi->mdev_events.notifier_call = NULL; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5599 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5600 | |
| 5601 | err = mlx5_nic_vport_affiliate_multiport(ibdev->mdev, mpi->mdev); |
| 5602 | if (err) |
| 5603 | goto unbind; |
| 5604 | |
| 5605 | err = get_port_caps(ibdev, mlx5_core_native_port_num(mpi->mdev)); |
| 5606 | if (err) |
| 5607 | goto unbind; |
| 5608 | |
| 5609 | err = mlx5_add_netdev_notifier(ibdev, port_num); |
| 5610 | if (err) { |
| 5611 | mlx5_ib_err(ibdev, "failed adding netdev notifier for port %u\n", |
| 5612 | port_num + 1); |
| 5613 | goto unbind; |
| 5614 | } |
| 5615 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 5616 | mpi->mdev_events.notifier_call = mlx5_ib_event_slave_port; |
| 5617 | mlx5_notifier_register(mpi->mdev, &mpi->mdev_events); |
| 5618 | |
Greg Kroah-Hartman | 73eb8f0 | 2019-01-22 16:17:57 +0100 | [diff] [blame] | 5619 | mlx5_ib_init_cong_debugfs(ibdev, port_num); |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5620 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5621 | return true; |
| 5622 | |
| 5623 | unbind: |
| 5624 | mlx5_ib_unbind_slave_port(ibdev, mpi); |
| 5625 | return false; |
| 5626 | } |
| 5627 | |
| 5628 | static int mlx5_ib_init_multiport_master(struct mlx5_ib_dev *dev) |
| 5629 | { |
| 5630 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5631 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5632 | port_num + 1); |
| 5633 | struct mlx5_ib_multiport_info *mpi; |
| 5634 | int err; |
| 5635 | int i; |
| 5636 | |
| 5637 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5638 | return 0; |
| 5639 | |
| 5640 | err = mlx5_query_nic_vport_system_image_guid(dev->mdev, |
| 5641 | &dev->sys_image_guid); |
| 5642 | if (err) |
| 5643 | return err; |
| 5644 | |
| 5645 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 5646 | if (err) |
| 5647 | return err; |
| 5648 | |
| 5649 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5650 | for (i = 0; i < dev->num_ports; i++) { |
| 5651 | bool bound = false; |
| 5652 | |
| 5653 | /* build a stub multiport info struct for the native port. */ |
| 5654 | if (i == port_num) { |
| 5655 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 5656 | if (!mpi) { |
| 5657 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5658 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5659 | return -ENOMEM; |
| 5660 | } |
| 5661 | |
| 5662 | mpi->is_master = true; |
| 5663 | mpi->mdev = dev->mdev; |
| 5664 | mpi->sys_image_guid = dev->sys_image_guid; |
| 5665 | dev->port[i].mp.mpi = mpi; |
| 5666 | mpi->ibdev = dev; |
| 5667 | mpi = NULL; |
| 5668 | continue; |
| 5669 | } |
| 5670 | |
| 5671 | list_for_each_entry(mpi, &mlx5_ib_unaffiliated_port_list, |
| 5672 | list) { |
| 5673 | if (dev->sys_image_guid == mpi->sys_image_guid && |
| 5674 | (mlx5_core_native_port_num(mpi->mdev) - 1) == i) { |
| 5675 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 5676 | } |
| 5677 | |
| 5678 | if (bound) { |
| 5679 | dev_dbg(&mpi->mdev->pdev->dev, "removing port from unaffiliated list.\n"); |
| 5680 | mlx5_ib_dbg(dev, "port %d bound\n", i + 1); |
| 5681 | list_del(&mpi->list); |
| 5682 | break; |
| 5683 | } |
| 5684 | } |
| 5685 | if (!bound) { |
| 5686 | get_port_caps(dev, i + 1); |
| 5687 | mlx5_ib_dbg(dev, "no free port found for port %d\n", |
| 5688 | i + 1); |
| 5689 | } |
| 5690 | } |
| 5691 | |
| 5692 | list_add_tail(&dev->ib_dev_list, &mlx5_ib_dev_list); |
| 5693 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5694 | return err; |
| 5695 | } |
| 5696 | |
| 5697 | static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev) |
| 5698 | { |
| 5699 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5700 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5701 | port_num + 1); |
| 5702 | int i; |
| 5703 | |
| 5704 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5705 | return; |
| 5706 | |
| 5707 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5708 | for (i = 0; i < dev->num_ports; i++) { |
| 5709 | if (dev->port[i].mp.mpi) { |
| 5710 | /* Destroy the native port stub */ |
| 5711 | if (i == port_num) { |
| 5712 | kfree(dev->port[i].mp.mpi); |
| 5713 | dev->port[i].mp.mpi = NULL; |
| 5714 | } else { |
| 5715 | mlx5_ib_dbg(dev, "unbinding port_num: %d\n", i + 1); |
| 5716 | mlx5_ib_unbind_slave_port(dev, dev->port[i].mp.mpi); |
| 5717 | } |
| 5718 | } |
| 5719 | } |
| 5720 | |
| 5721 | mlx5_ib_dbg(dev, "removing from devlist\n"); |
| 5722 | list_del(&dev->ib_dev_list); |
| 5723 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5724 | |
| 5725 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5726 | } |
| 5727 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5728 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 5729 | mlx5_ib_dm, |
| 5730 | UVERBS_OBJECT_DM, |
| 5731 | UVERBS_METHOD_DM_ALLOC, |
| 5732 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 5733 | UVERBS_ATTR_TYPE(u64), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5734 | UA_MANDATORY), |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5735 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 5736 | UVERBS_ATTR_TYPE(u16), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5737 | UA_MANDATORY)); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5738 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5739 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 5740 | mlx5_ib_flow_action, |
| 5741 | UVERBS_OBJECT_FLOW_ACTION, |
| 5742 | UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, |
Jason Gunthorpe | bccd062 | 2018-07-26 16:37:14 -0600 | [diff] [blame] | 5743 | UVERBS_ATTR_FLAGS_IN(MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 5744 | enum mlx5_ib_uapi_flow_action_flags)); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 5745 | |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 5746 | static const struct uapi_definition mlx5_ib_defs[] = { |
| 5747 | #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) |
Jason Gunthorpe | 36e235c | 2018-11-12 22:59:53 +0200 | [diff] [blame] | 5748 | UAPI_DEF_CHAIN(mlx5_ib_devx_defs), |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 5749 | UAPI_DEF_CHAIN(mlx5_ib_flow_defs), |
| 5750 | #endif |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5751 | |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 5752 | UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_FLOW_ACTION, |
| 5753 | &mlx5_ib_flow_action), |
| 5754 | UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_DM, &mlx5_ib_dm), |
| 5755 | {} |
| 5756 | }; |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5757 | |
Raed Salem | 1a1e03d | 2018-05-31 16:43:41 +0300 | [diff] [blame] | 5758 | static int mlx5_ib_read_counters(struct ib_counters *counters, |
| 5759 | struct ib_counters_read_attr *read_attr, |
| 5760 | struct uverbs_attr_bundle *attrs) |
| 5761 | { |
| 5762 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 5763 | struct mlx5_read_counters_attr mread_attr = {}; |
| 5764 | struct mlx5_ib_flow_counters_desc *desc; |
| 5765 | int ret, i; |
| 5766 | |
| 5767 | mutex_lock(&mcounters->mcntrs_mutex); |
| 5768 | if (mcounters->cntrs_max_index > read_attr->ncounters) { |
| 5769 | ret = -EINVAL; |
| 5770 | goto err_bound; |
| 5771 | } |
| 5772 | |
| 5773 | mread_attr.out = kcalloc(mcounters->counters_num, sizeof(u64), |
| 5774 | GFP_KERNEL); |
| 5775 | if (!mread_attr.out) { |
| 5776 | ret = -ENOMEM; |
| 5777 | goto err_bound; |
| 5778 | } |
| 5779 | |
| 5780 | mread_attr.hw_cntrs_hndl = mcounters->hw_cntrs_hndl; |
| 5781 | mread_attr.flags = read_attr->flags; |
| 5782 | ret = mcounters->read_counters(counters->device, &mread_attr); |
| 5783 | if (ret) |
| 5784 | goto err_read; |
| 5785 | |
| 5786 | /* do the pass over the counters data array to assign according to the |
| 5787 | * descriptions and indexing pairs |
| 5788 | */ |
| 5789 | desc = mcounters->counters_data; |
| 5790 | for (i = 0; i < mcounters->ncounters; i++) |
| 5791 | read_attr->counters_buff[desc[i].index] += mread_attr.out[desc[i].description]; |
| 5792 | |
| 5793 | err_read: |
| 5794 | kfree(mread_attr.out); |
| 5795 | err_bound: |
| 5796 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 5797 | return ret; |
| 5798 | } |
| 5799 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5800 | static int mlx5_ib_destroy_counters(struct ib_counters *counters) |
| 5801 | { |
| 5802 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 5803 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 5804 | counters_clear_description(counters); |
| 5805 | if (mcounters->hw_cntrs_hndl) |
| 5806 | mlx5_fc_destroy(to_mdev(counters->device)->mdev, |
| 5807 | mcounters->hw_cntrs_hndl); |
| 5808 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5809 | kfree(mcounters); |
| 5810 | |
| 5811 | return 0; |
| 5812 | } |
| 5813 | |
| 5814 | static struct ib_counters *mlx5_ib_create_counters(struct ib_device *device, |
| 5815 | struct uverbs_attr_bundle *attrs) |
| 5816 | { |
| 5817 | struct mlx5_ib_mcounters *mcounters; |
| 5818 | |
| 5819 | mcounters = kzalloc(sizeof(*mcounters), GFP_KERNEL); |
| 5820 | if (!mcounters) |
| 5821 | return ERR_PTR(-ENOMEM); |
| 5822 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 5823 | mutex_init(&mcounters->mcntrs_mutex); |
| 5824 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5825 | return &mcounters->ibcntrs; |
| 5826 | } |
| 5827 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5828 | void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5829 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5830 | mlx5_ib_cleanup_multiport_master(dev); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5831 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
Yishai Hadas | 534fd7a | 2019-01-13 16:01:17 +0200 | [diff] [blame] | 5832 | srcu_barrier(&dev->mr_srcu); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5833 | cleanup_srcu_struct(&dev->mr_srcu); |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5834 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5835 | kfree(dev->port); |
| 5836 | } |
| 5837 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5838 | int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5839 | { |
| 5840 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5841 | int err; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5842 | int i; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5843 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 5844 | dev->port = kcalloc(dev->num_ports, sizeof(*dev->port), |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5845 | GFP_KERNEL); |
| 5846 | if (!dev->port) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5847 | return -ENOMEM; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5848 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5849 | for (i = 0; i < dev->num_ports; i++) { |
| 5850 | spin_lock_init(&dev->port[i].mp.mpi_lock); |
| 5851 | rwlock_init(&dev->roce[i].netdev_lock); |
| 5852 | } |
| 5853 | |
| 5854 | err = mlx5_ib_init_multiport_master(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5855 | if (err) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5856 | goto err_free_port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5857 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5858 | if (!mlx5_core_mp_enabled(mdev)) { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5859 | for (i = 1; i <= dev->num_ports; i++) { |
| 5860 | err = get_port_caps(dev, i); |
| 5861 | if (err) |
| 5862 | break; |
| 5863 | } |
| 5864 | } else { |
| 5865 | err = get_port_caps(dev, mlx5_core_native_port_num(mdev)); |
| 5866 | } |
| 5867 | if (err) |
| 5868 | goto err_mp; |
| 5869 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 5870 | if (mlx5_use_mad_ifc(dev)) |
| 5871 | get_ext_port_caps(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5872 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5873 | dev->ib_dev.owner = THIS_MODULE; |
| 5874 | dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Sagi Grimberg | c6790aa | 2015-09-24 10:34:23 +0300 | [diff] [blame] | 5875 | dev->ib_dev.local_dma_lkey = 0 /* not supported for now */; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 5876 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
Saeed Mahameed | f2f3df5 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 5877 | dev->ib_dev.num_comp_vectors = mlx5_comp_vectors_count(mdev); |
Bart Van Assche | 9b0c289 | 2017-01-20 13:04:21 -0800 | [diff] [blame] | 5878 | dev->ib_dev.dev.parent = &mdev->pdev->dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5879 | |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5880 | mutex_init(&dev->cap_mask_mutex); |
| 5881 | INIT_LIST_HEAD(&dev->qp_list); |
| 5882 | spin_lock_init(&dev->reset_flow_resource_lock); |
| 5883 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5884 | spin_lock_init(&dev->memic.memic_lock); |
| 5885 | dev->memic.dev = mdev; |
| 5886 | |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5887 | if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5888 | err = init_srcu_struct(&dev->mr_srcu); |
Moni Shoua | a6bc387 | 2019-02-17 16:08:22 +0200 | [diff] [blame] | 5889 | if (err) |
Leon Romanovsky | 13859d5d | 2019-01-08 16:07:26 +0200 | [diff] [blame] | 5890 | goto err_mp; |
Jason Gunthorpe | 623d154 | 2018-12-20 16:39:26 -0700 | [diff] [blame] | 5891 | } |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5892 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5893 | return 0; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5894 | err_mp: |
| 5895 | mlx5_ib_cleanup_multiport_master(dev); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5896 | |
| 5897 | err_free_port: |
| 5898 | kfree(dev->port); |
| 5899 | |
| 5900 | return -ENOMEM; |
| 5901 | } |
| 5902 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5903 | static int mlx5_ib_stage_flow_db_init(struct mlx5_ib_dev *dev) |
| 5904 | { |
| 5905 | dev->flow_db = kzalloc(sizeof(*dev->flow_db), GFP_KERNEL); |
| 5906 | |
| 5907 | if (!dev->flow_db) |
| 5908 | return -ENOMEM; |
| 5909 | |
| 5910 | mutex_init(&dev->flow_db->lock); |
| 5911 | |
| 5912 | return 0; |
| 5913 | } |
| 5914 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5915 | int mlx5_ib_stage_rep_flow_db_init(struct mlx5_ib_dev *dev) |
| 5916 | { |
| 5917 | struct mlx5_ib_dev *nic_dev; |
| 5918 | |
| 5919 | nic_dev = mlx5_ib_get_uplink_ibdev(dev->mdev->priv.eswitch); |
| 5920 | |
| 5921 | if (!nic_dev) |
| 5922 | return -EINVAL; |
| 5923 | |
| 5924 | dev->flow_db = nic_dev->flow_db; |
| 5925 | |
| 5926 | return 0; |
| 5927 | } |
| 5928 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5929 | static void mlx5_ib_stage_flow_db_cleanup(struct mlx5_ib_dev *dev) |
| 5930 | { |
| 5931 | kfree(dev->flow_db); |
| 5932 | } |
| 5933 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 5934 | static const struct ib_device_ops mlx5_ib_dev_ops = { |
| 5935 | .add_gid = mlx5_ib_add_gid, |
| 5936 | .alloc_mr = mlx5_ib_alloc_mr, |
| 5937 | .alloc_pd = mlx5_ib_alloc_pd, |
| 5938 | .alloc_ucontext = mlx5_ib_alloc_ucontext, |
| 5939 | .attach_mcast = mlx5_ib_mcg_attach, |
| 5940 | .check_mr_status = mlx5_ib_check_mr_status, |
| 5941 | .create_ah = mlx5_ib_create_ah, |
| 5942 | .create_counters = mlx5_ib_create_counters, |
| 5943 | .create_cq = mlx5_ib_create_cq, |
| 5944 | .create_flow = mlx5_ib_create_flow, |
| 5945 | .create_qp = mlx5_ib_create_qp, |
| 5946 | .create_srq = mlx5_ib_create_srq, |
| 5947 | .dealloc_pd = mlx5_ib_dealloc_pd, |
| 5948 | .dealloc_ucontext = mlx5_ib_dealloc_ucontext, |
| 5949 | .del_gid = mlx5_ib_del_gid, |
| 5950 | .dereg_mr = mlx5_ib_dereg_mr, |
| 5951 | .destroy_ah = mlx5_ib_destroy_ah, |
| 5952 | .destroy_counters = mlx5_ib_destroy_counters, |
| 5953 | .destroy_cq = mlx5_ib_destroy_cq, |
| 5954 | .destroy_flow = mlx5_ib_destroy_flow, |
| 5955 | .destroy_flow_action = mlx5_ib_destroy_flow_action, |
| 5956 | .destroy_qp = mlx5_ib_destroy_qp, |
| 5957 | .destroy_srq = mlx5_ib_destroy_srq, |
| 5958 | .detach_mcast = mlx5_ib_mcg_detach, |
| 5959 | .disassociate_ucontext = mlx5_ib_disassociate_ucontext, |
| 5960 | .drain_rq = mlx5_ib_drain_rq, |
| 5961 | .drain_sq = mlx5_ib_drain_sq, |
| 5962 | .get_dev_fw_str = get_dev_fw_str, |
| 5963 | .get_dma_mr = mlx5_ib_get_dma_mr, |
| 5964 | .get_link_layer = mlx5_ib_port_link_layer, |
| 5965 | .map_mr_sg = mlx5_ib_map_mr_sg, |
| 5966 | .mmap = mlx5_ib_mmap, |
| 5967 | .modify_cq = mlx5_ib_modify_cq, |
| 5968 | .modify_device = mlx5_ib_modify_device, |
| 5969 | .modify_port = mlx5_ib_modify_port, |
| 5970 | .modify_qp = mlx5_ib_modify_qp, |
| 5971 | .modify_srq = mlx5_ib_modify_srq, |
| 5972 | .poll_cq = mlx5_ib_poll_cq, |
| 5973 | .post_recv = mlx5_ib_post_recv, |
| 5974 | .post_send = mlx5_ib_post_send, |
| 5975 | .post_srq_recv = mlx5_ib_post_srq_recv, |
| 5976 | .process_mad = mlx5_ib_process_mad, |
| 5977 | .query_ah = mlx5_ib_query_ah, |
| 5978 | .query_device = mlx5_ib_query_device, |
| 5979 | .query_gid = mlx5_ib_query_gid, |
| 5980 | .query_pkey = mlx5_ib_query_pkey, |
| 5981 | .query_qp = mlx5_ib_query_qp, |
| 5982 | .query_srq = mlx5_ib_query_srq, |
| 5983 | .read_counters = mlx5_ib_read_counters, |
| 5984 | .reg_user_mr = mlx5_ib_reg_user_mr, |
| 5985 | .req_notify_cq = mlx5_ib_arm_cq, |
| 5986 | .rereg_user_mr = mlx5_ib_rereg_user_mr, |
| 5987 | .resize_cq = mlx5_ib_resize_cq, |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 5988 | INIT_RDMA_OBJ_SIZE(ib_pd, mlx5_ib_pd, ibpd), |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 5989 | INIT_RDMA_OBJ_SIZE(ib_ucontext, mlx5_ib_ucontext, ibucontext), |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 5990 | }; |
| 5991 | |
| 5992 | static const struct ib_device_ops mlx5_ib_dev_flow_ipsec_ops = { |
| 5993 | .create_flow_action_esp = mlx5_ib_create_flow_action_esp, |
| 5994 | .modify_flow_action_esp = mlx5_ib_modify_flow_action_esp, |
| 5995 | }; |
| 5996 | |
| 5997 | static const struct ib_device_ops mlx5_ib_dev_ipoib_enhanced_ops = { |
| 5998 | .rdma_netdev_get_params = mlx5_ib_rn_get_params, |
| 5999 | }; |
| 6000 | |
| 6001 | static const struct ib_device_ops mlx5_ib_dev_sriov_ops = { |
| 6002 | .get_vf_config = mlx5_ib_get_vf_config, |
| 6003 | .get_vf_stats = mlx5_ib_get_vf_stats, |
| 6004 | .set_vf_guid = mlx5_ib_set_vf_guid, |
| 6005 | .set_vf_link_state = mlx5_ib_set_vf_link_state, |
| 6006 | }; |
| 6007 | |
| 6008 | static const struct ib_device_ops mlx5_ib_dev_mw_ops = { |
| 6009 | .alloc_mw = mlx5_ib_alloc_mw, |
| 6010 | .dealloc_mw = mlx5_ib_dealloc_mw, |
| 6011 | }; |
| 6012 | |
| 6013 | static const struct ib_device_ops mlx5_ib_dev_xrc_ops = { |
| 6014 | .alloc_xrcd = mlx5_ib_alloc_xrcd, |
| 6015 | .dealloc_xrcd = mlx5_ib_dealloc_xrcd, |
| 6016 | }; |
| 6017 | |
| 6018 | static const struct ib_device_ops mlx5_ib_dev_dm_ops = { |
| 6019 | .alloc_dm = mlx5_ib_alloc_dm, |
| 6020 | .dealloc_dm = mlx5_ib_dealloc_dm, |
| 6021 | .reg_dm_mr = mlx5_ib_reg_dm_mr, |
| 6022 | }; |
| 6023 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6024 | int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6025 | { |
| 6026 | struct mlx5_core_dev *mdev = dev->mdev; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6027 | int err; |
| 6028 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6029 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
| 6030 | dev->ib_dev.uverbs_cmd_mask = |
| 6031 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 6032 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 6033 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 6034 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 6035 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
Moni Shoua | 41c450f | 2016-11-23 08:23:26 +0200 | [diff] [blame] | 6036 | (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
| 6037 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6038 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 6039 | (1ull << IB_USER_VERBS_CMD_REREG_MR) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6040 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 6041 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 6042 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 6043 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 6044 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 6045 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 6046 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 6047 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 6048 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 6049 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 6050 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 6051 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 6052 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 6053 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 6054 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 6055 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 6056 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Haggai Eran | 1707cb4 | 2015-02-08 13:28:52 +0200 | [diff] [blame] | 6057 | dev->ib_dev.uverbs_ex_cmd_mask = |
Matan Barak | d4584dd | 2016-01-28 17:51:46 +0200 | [diff] [blame] | 6058 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE) | |
| 6059 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 6060 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) | |
Yonatan Cohen | b0e9df6 | 2017-11-13 10:51:15 +0200 | [diff] [blame] | 6061 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_QP) | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6062 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_CQ) | |
| 6063 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) | |
| 6064 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6065 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 6066 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
| 6067 | IS_ENABLED(CONFIG_MLX5_CORE_IPOIB)) |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6068 | ib_set_device_ops(&dev->ib_dev, |
| 6069 | &mlx5_ib_dev_ipoib_enhanced_ops); |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 6070 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6071 | if (mlx5_core_is_pf(mdev)) |
| 6072 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_sriov_ops); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 6073 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 6074 | dev->umr_fence = mlx5_get_umr_fence(MLX5_CAP_GEN(mdev, umr_fence)); |
| 6075 | |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6076 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6077 | dev->ib_dev.uverbs_cmd_mask |= |
| 6078 | (1ull << IB_USER_VERBS_CMD_ALLOC_MW) | |
| 6079 | (1ull << IB_USER_VERBS_CMD_DEALLOC_MW); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6080 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_mw_ops); |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 6081 | } |
| 6082 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 6083 | if (MLX5_CAP_GEN(mdev, xrc)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6084 | dev->ib_dev.uverbs_cmd_mask |= |
| 6085 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 6086 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6087 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_xrc_ops); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6088 | } |
| 6089 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6090 | if (MLX5_CAP_DEV_MEM(mdev, memic)) |
| 6091 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_dm_ops); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 6092 | |
Jason Gunthorpe | dfb631a | 2018-11-12 22:59:49 +0200 | [diff] [blame] | 6093 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6094 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 6095 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_flow_ipsec_ops); |
Matan Barak | 0ede73b | 2018-03-19 15:02:34 +0200 | [diff] [blame] | 6096 | dev->ib_dev.driver_id = RDMA_DRIVER_MLX5; |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6097 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_ops); |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 6098 | |
Jason Gunthorpe | 36e235c | 2018-11-12 22:59:53 +0200 | [diff] [blame] | 6099 | if (IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)) |
| 6100 | dev->ib_dev.driver_def = mlx5_ib_defs; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6101 | |
| 6102 | err = init_node_data(dev); |
| 6103 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6104 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6105 | |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 6106 | 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] | 6107 | (MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) || |
| 6108 | MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Mark Bloch | a560f1d | 2018-09-17 13:30:47 +0300 | [diff] [blame] | 6109 | mutex_init(&dev->lb.mutex); |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 6110 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6111 | return 0; |
| 6112 | } |
| 6113 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6114 | static const struct ib_device_ops mlx5_ib_dev_port_ops = { |
| 6115 | .get_port_immutable = mlx5_port_immutable, |
| 6116 | .query_port = mlx5_ib_query_port, |
| 6117 | }; |
| 6118 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6119 | static int mlx5_ib_stage_non_default_cb(struct mlx5_ib_dev *dev) |
| 6120 | { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6121 | ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_port_ops); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6122 | return 0; |
| 6123 | } |
| 6124 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6125 | static const struct ib_device_ops mlx5_ib_dev_port_rep_ops = { |
| 6126 | .get_port_immutable = mlx5_port_rep_immutable, |
| 6127 | .query_port = mlx5_ib_rep_query_port, |
| 6128 | }; |
| 6129 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6130 | int mlx5_ib_stage_rep_non_default_cb(struct mlx5_ib_dev *dev) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6131 | { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6132 | 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] | 6133 | return 0; |
| 6134 | } |
| 6135 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6136 | static const struct ib_device_ops mlx5_ib_dev_common_roce_ops = { |
| 6137 | .create_rwq_ind_table = mlx5_ib_create_rwq_ind_table, |
| 6138 | .create_wq = mlx5_ib_create_wq, |
| 6139 | .destroy_rwq_ind_table = mlx5_ib_destroy_rwq_ind_table, |
| 6140 | .destroy_wq = mlx5_ib_destroy_wq, |
| 6141 | .get_netdev = mlx5_ib_get_netdev, |
| 6142 | .modify_wq = mlx5_ib_modify_wq, |
| 6143 | }; |
| 6144 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6145 | 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] | 6146 | { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6147 | u8 port_num; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6148 | int i; |
| 6149 | |
| 6150 | for (i = 0; i < dev->num_ports; i++) { |
| 6151 | dev->roce[i].dev = dev; |
| 6152 | dev->roce[i].native_port_num = i + 1; |
| 6153 | dev->roce[i].last_port_state = IB_PORT_DOWN; |
| 6154 | } |
| 6155 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6156 | dev->ib_dev.uverbs_ex_cmd_mask |= |
| 6157 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_WQ) | |
| 6158 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_WQ) | |
| 6159 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_WQ) | |
| 6160 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) | |
| 6161 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL); |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6162 | 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] | 6163 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6164 | port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6165 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6166 | return mlx5_add_netdev_notifier(dev, port_num); |
| 6167 | } |
| 6168 | |
| 6169 | static void mlx5_ib_stage_common_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6170 | { |
| 6171 | u8 port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6172 | |
| 6173 | mlx5_remove_netdev_notifier(dev, port_num); |
| 6174 | } |
| 6175 | |
| 6176 | int mlx5_ib_stage_rep_roce_init(struct mlx5_ib_dev *dev) |
| 6177 | { |
| 6178 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6179 | enum rdma_link_layer ll; |
| 6180 | int port_type_cap; |
| 6181 | int err = 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6182 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6183 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6184 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6185 | |
| 6186 | if (ll == IB_LINK_LAYER_ETHERNET) |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6187 | err = mlx5_ib_stage_common_roce_init(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6188 | |
| 6189 | return err; |
| 6190 | } |
| 6191 | |
| 6192 | void mlx5_ib_stage_rep_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6193 | { |
| 6194 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 6195 | } |
| 6196 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6197 | static int mlx5_ib_stage_roce_init(struct mlx5_ib_dev *dev) |
| 6198 | { |
| 6199 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6200 | enum rdma_link_layer ll; |
| 6201 | int port_type_cap; |
| 6202 | int err; |
| 6203 | |
| 6204 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6205 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6206 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6207 | if (ll == IB_LINK_LAYER_ETHERNET) { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6208 | err = mlx5_ib_stage_common_roce_init(dev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6209 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6210 | return err; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6211 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6212 | err = mlx5_enable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6213 | if (err) |
| 6214 | goto cleanup; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6215 | } |
| 6216 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6217 | return 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6218 | cleanup: |
| 6219 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 6220 | |
| 6221 | return err; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6222 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6223 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6224 | static void mlx5_ib_stage_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6225 | { |
| 6226 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6227 | enum rdma_link_layer ll; |
| 6228 | int port_type_cap; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6229 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6230 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6231 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6232 | |
| 6233 | if (ll == IB_LINK_LAYER_ETHERNET) { |
| 6234 | mlx5_disable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6235 | mlx5_ib_stage_common_roce_cleanup(dev); |
Kamal Heib | 45bded2 | 2017-01-18 14:10:32 +0200 | [diff] [blame] | 6236 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6237 | } |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6238 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6239 | int mlx5_ib_stage_dev_res_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6240 | { |
| 6241 | return create_dev_resources(&dev->devr); |
| 6242 | } |
Parav Pandit | 4a2da0b | 2017-05-30 10:05:15 +0300 | [diff] [blame] | 6243 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6244 | void mlx5_ib_stage_dev_res_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6245 | { |
| 6246 | destroy_dev_resources(&dev->devr); |
| 6247 | } |
| 6248 | |
| 6249 | static int mlx5_ib_stage_odp_init(struct mlx5_ib_dev *dev) |
| 6250 | { |
Mark Bloch | 07321b3 | 2018-01-01 13:07:00 +0200 | [diff] [blame] | 6251 | mlx5_ib_internal_fill_odp_caps(dev); |
| 6252 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6253 | return mlx5_ib_odp_init_one(dev); |
| 6254 | } |
| 6255 | |
Kamal Heib | f3ffed0 | 2019-01-30 16:13:42 +0200 | [diff] [blame] | 6256 | static void mlx5_ib_stage_odp_cleanup(struct mlx5_ib_dev *dev) |
Saeed Mahameed | d5d284b | 2018-11-19 10:52:41 -0800 | [diff] [blame] | 6257 | { |
| 6258 | mlx5_ib_odp_cleanup_one(dev); |
| 6259 | } |
| 6260 | |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6261 | static const struct ib_device_ops mlx5_ib_dev_hw_stats_ops = { |
| 6262 | .alloc_hw_stats = mlx5_ib_alloc_hw_stats, |
| 6263 | .get_hw_stats = mlx5_ib_get_hw_stats, |
| 6264 | }; |
| 6265 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6266 | int mlx5_ib_stage_counters_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6267 | { |
Mark Bloch | 5e1e761 | 2018-01-01 13:07:01 +0200 | [diff] [blame] | 6268 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) { |
Kamal Heib | 96458233e | 2018-12-10 21:09:38 +0200 | [diff] [blame] | 6269 | 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] | 6270 | |
| 6271 | return mlx5_ib_alloc_counters(dev); |
| 6272 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6273 | |
| 6274 | return 0; |
| 6275 | } |
| 6276 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6277 | void mlx5_ib_stage_counters_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6278 | { |
| 6279 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) |
| 6280 | mlx5_ib_dealloc_counters(dev); |
| 6281 | } |
| 6282 | |
| 6283 | static int mlx5_ib_stage_cong_debugfs_init(struct mlx5_ib_dev *dev) |
| 6284 | { |
Greg Kroah-Hartman | 73eb8f0 | 2019-01-22 16:17:57 +0100 | [diff] [blame] | 6285 | mlx5_ib_init_cong_debugfs(dev, |
| 6286 | mlx5_core_native_port_num(dev->mdev) - 1); |
| 6287 | return 0; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6288 | } |
| 6289 | |
| 6290 | static void mlx5_ib_stage_cong_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 6291 | { |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 6292 | mlx5_ib_cleanup_cong_debugfs(dev, |
| 6293 | mlx5_core_native_port_num(dev->mdev) - 1); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6294 | } |
| 6295 | |
| 6296 | static int mlx5_ib_stage_uar_init(struct mlx5_ib_dev *dev) |
| 6297 | { |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6298 | dev->mdev->priv.uar = mlx5_get_uars_page(dev->mdev); |
Leon Romanovsky | 444261c | 2018-04-23 17:01:56 +0300 | [diff] [blame] | 6299 | return PTR_ERR_OR_ZERO(dev->mdev->priv.uar); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6300 | } |
| 6301 | |
| 6302 | static void mlx5_ib_stage_uar_cleanup(struct mlx5_ib_dev *dev) |
| 6303 | { |
| 6304 | mlx5_put_uars_page(dev->mdev, dev->mdev->priv.uar); |
| 6305 | } |
| 6306 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6307 | int mlx5_ib_stage_bfrag_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6308 | { |
| 6309 | int err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6310 | |
| 6311 | err = mlx5_alloc_bfreg(dev->mdev, &dev->bfreg, false, false); |
| 6312 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6313 | return err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6314 | |
| 6315 | err = mlx5_alloc_bfreg(dev->mdev, &dev->fp_bfreg, false, true); |
| 6316 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6317 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6318 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6319 | return err; |
| 6320 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 6321 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6322 | void mlx5_ib_stage_bfrag_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6323 | { |
| 6324 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
| 6325 | mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
| 6326 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6327 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6328 | int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6329 | { |
Jason Gunthorpe | e349f85 | 2018-09-25 16:58:09 -0600 | [diff] [blame] | 6330 | const char *name; |
| 6331 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 6332 | rdma_set_device_sysfs_group(&dev->ib_dev, &mlx5_attr_group); |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 6333 | if (!mlx5_lag_is_roce(dev->mdev)) |
Jason Gunthorpe | e349f85 | 2018-09-25 16:58:09 -0600 | [diff] [blame] | 6334 | name = "mlx5_%d"; |
| 6335 | else |
| 6336 | name = "mlx5_bond_%d"; |
Parav Pandit | ea4baf7 | 2018-12-18 14:28:30 +0200 | [diff] [blame] | 6337 | return ib_register_device(&dev->ib_dev, name); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6338 | } |
| 6339 | |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6340 | 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] | 6341 | { |
| 6342 | destroy_umrc_res(dev); |
| 6343 | } |
| 6344 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6345 | void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6346 | { |
| 6347 | ib_unregister_device(&dev->ib_dev); |
| 6348 | } |
| 6349 | |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6350 | 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] | 6351 | { |
| 6352 | return create_umr_res(dev); |
| 6353 | } |
| 6354 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6355 | static int mlx5_ib_stage_delay_drop_init(struct mlx5_ib_dev *dev) |
| 6356 | { |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6357 | init_delay_drop(dev); |
| 6358 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6359 | return 0; |
| 6360 | } |
| 6361 | |
| 6362 | static void mlx5_ib_stage_delay_drop_cleanup(struct mlx5_ib_dev *dev) |
| 6363 | { |
| 6364 | cancel_delay_drop(dev); |
| 6365 | } |
| 6366 | |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6367 | static int mlx5_ib_stage_dev_notifier_init(struct mlx5_ib_dev *dev) |
| 6368 | { |
| 6369 | dev->mdev_events.notifier_call = mlx5_ib_event; |
| 6370 | mlx5_notifier_register(dev->mdev, &dev->mdev_events); |
| 6371 | return 0; |
| 6372 | } |
| 6373 | |
| 6374 | static void mlx5_ib_stage_dev_notifier_cleanup(struct mlx5_ib_dev *dev) |
| 6375 | { |
| 6376 | mlx5_notifier_unregister(dev->mdev, &dev->mdev_events); |
| 6377 | } |
| 6378 | |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6379 | static int mlx5_ib_stage_devx_init(struct mlx5_ib_dev *dev) |
| 6380 | { |
| 6381 | int uid; |
| 6382 | |
Yishai Hadas | fb98153 | 2018-11-26 08:28:36 +0200 | [diff] [blame] | 6383 | uid = mlx5_ib_devx_create(dev, false); |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6384 | if (uid > 0) |
| 6385 | dev->devx_whitelist_uid = uid; |
| 6386 | |
| 6387 | return 0; |
| 6388 | } |
| 6389 | static void mlx5_ib_stage_devx_cleanup(struct mlx5_ib_dev *dev) |
| 6390 | { |
| 6391 | if (dev->devx_whitelist_uid) |
| 6392 | mlx5_ib_devx_destroy(dev, dev->devx_whitelist_uid); |
| 6393 | } |
| 6394 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6395 | void __mlx5_ib_remove(struct mlx5_ib_dev *dev, |
| 6396 | const struct mlx5_ib_profile *profile, |
| 6397 | int stage) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6398 | { |
| 6399 | /* Number of stages to cleanup */ |
| 6400 | while (stage) { |
| 6401 | stage--; |
| 6402 | if (profile->stage[stage].cleanup) |
| 6403 | profile->stage[stage].cleanup(dev); |
| 6404 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6405 | } |
| 6406 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6407 | void *__mlx5_ib_add(struct mlx5_ib_dev *dev, |
| 6408 | const struct mlx5_ib_profile *profile) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6409 | { |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6410 | int err; |
| 6411 | int i; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6412 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6413 | for (i = 0; i < MLX5_IB_STAGE_MAX; i++) { |
| 6414 | if (profile->stage[i].init) { |
| 6415 | err = profile->stage[i].init(dev); |
| 6416 | if (err) |
| 6417 | goto err_out; |
| 6418 | } |
| 6419 | } |
| 6420 | |
| 6421 | dev->profile = profile; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6422 | dev->ib_active = true; |
| 6423 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6424 | return dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6425 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6426 | err_out: |
| 6427 | __mlx5_ib_remove(dev, profile, i); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6428 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6429 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6430 | } |
| 6431 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6432 | static const struct mlx5_ib_profile pf_profile = { |
| 6433 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6434 | mlx5_ib_stage_init_init, |
| 6435 | mlx5_ib_stage_init_cleanup), |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 6436 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6437 | mlx5_ib_stage_flow_db_init, |
| 6438 | mlx5_ib_stage_flow_db_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6439 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6440 | mlx5_ib_stage_caps_init, |
| 6441 | NULL), |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6442 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6443 | mlx5_ib_stage_non_default_cb, |
| 6444 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6445 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6446 | mlx5_ib_stage_roce_init, |
| 6447 | mlx5_ib_stage_roce_cleanup), |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 6448 | STAGE_CREATE(MLX5_IB_STAGE_SRQ, |
| 6449 | mlx5_init_srq_table, |
| 6450 | mlx5_cleanup_srq_table), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6451 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6452 | mlx5_ib_stage_dev_res_init, |
| 6453 | mlx5_ib_stage_dev_res_cleanup), |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6454 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER, |
| 6455 | mlx5_ib_stage_dev_notifier_init, |
| 6456 | mlx5_ib_stage_dev_notifier_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6457 | STAGE_CREATE(MLX5_IB_STAGE_ODP, |
| 6458 | mlx5_ib_stage_odp_init, |
Saeed Mahameed | d5d284b | 2018-11-19 10:52:41 -0800 | [diff] [blame] | 6459 | mlx5_ib_stage_odp_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6460 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6461 | mlx5_ib_stage_counters_init, |
| 6462 | mlx5_ib_stage_counters_cleanup), |
| 6463 | STAGE_CREATE(MLX5_IB_STAGE_CONG_DEBUGFS, |
| 6464 | mlx5_ib_stage_cong_debugfs_init, |
| 6465 | mlx5_ib_stage_cong_debugfs_cleanup), |
| 6466 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6467 | mlx5_ib_stage_uar_init, |
| 6468 | mlx5_ib_stage_uar_cleanup), |
| 6469 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6470 | mlx5_ib_stage_bfrag_init, |
| 6471 | mlx5_ib_stage_bfrag_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6472 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6473 | NULL, |
| 6474 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Leon Romanovsky | 81773ce | 2018-11-28 20:53:39 +0200 | [diff] [blame] | 6475 | STAGE_CREATE(MLX5_IB_STAGE_WHITELIST_UID, |
| 6476 | mlx5_ib_stage_devx_init, |
| 6477 | mlx5_ib_stage_devx_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6478 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6479 | mlx5_ib_stage_ib_reg_init, |
| 6480 | mlx5_ib_stage_ib_reg_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6481 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6482 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6483 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6484 | STAGE_CREATE(MLX5_IB_STAGE_DELAY_DROP, |
| 6485 | mlx5_ib_stage_delay_drop_init, |
| 6486 | mlx5_ib_stage_delay_drop_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6487 | }; |
| 6488 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6489 | const struct mlx5_ib_profile uplink_rep_profile = { |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6490 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6491 | mlx5_ib_stage_init_init, |
| 6492 | mlx5_ib_stage_init_cleanup), |
| 6493 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6494 | mlx5_ib_stage_flow_db_init, |
| 6495 | mlx5_ib_stage_flow_db_cleanup), |
| 6496 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6497 | mlx5_ib_stage_caps_init, |
| 6498 | NULL), |
| 6499 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6500 | mlx5_ib_stage_rep_non_default_cb, |
| 6501 | NULL), |
| 6502 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6503 | mlx5_ib_stage_rep_roce_init, |
| 6504 | mlx5_ib_stage_rep_roce_cleanup), |
Leon Romanovsky | f3da657 | 2018-11-28 20:53:41 +0200 | [diff] [blame] | 6505 | STAGE_CREATE(MLX5_IB_STAGE_SRQ, |
| 6506 | mlx5_init_srq_table, |
| 6507 | mlx5_cleanup_srq_table), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6508 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6509 | mlx5_ib_stage_dev_res_init, |
| 6510 | mlx5_ib_stage_dev_res_cleanup), |
Saeed Mahameed | df097a2 | 2018-11-26 14:39:00 -0800 | [diff] [blame] | 6511 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER, |
| 6512 | mlx5_ib_stage_dev_notifier_init, |
| 6513 | mlx5_ib_stage_dev_notifier_cleanup), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6514 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6515 | mlx5_ib_stage_counters_init, |
| 6516 | mlx5_ib_stage_counters_cleanup), |
| 6517 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6518 | mlx5_ib_stage_uar_init, |
| 6519 | mlx5_ib_stage_uar_cleanup), |
| 6520 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6521 | mlx5_ib_stage_bfrag_init, |
| 6522 | mlx5_ib_stage_bfrag_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6523 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6524 | NULL, |
| 6525 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6526 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6527 | mlx5_ib_stage_ib_reg_init, |
| 6528 | mlx5_ib_stage_ib_reg_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6529 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6530 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6531 | NULL), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6532 | }; |
| 6533 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6534 | static void *mlx5_ib_add_slave_port(struct mlx5_core_dev *mdev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6535 | { |
| 6536 | struct mlx5_ib_multiport_info *mpi; |
| 6537 | struct mlx5_ib_dev *dev; |
| 6538 | bool bound = false; |
| 6539 | int err; |
| 6540 | |
| 6541 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 6542 | if (!mpi) |
| 6543 | return NULL; |
| 6544 | |
| 6545 | mpi->mdev = mdev; |
| 6546 | |
| 6547 | err = mlx5_query_nic_vport_system_image_guid(mdev, |
| 6548 | &mpi->sys_image_guid); |
| 6549 | if (err) { |
| 6550 | kfree(mpi); |
| 6551 | return NULL; |
| 6552 | } |
| 6553 | |
| 6554 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6555 | list_for_each_entry(dev, &mlx5_ib_dev_list, ib_dev_list) { |
| 6556 | if (dev->sys_image_guid == mpi->sys_image_guid) |
| 6557 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 6558 | |
| 6559 | if (bound) { |
| 6560 | rdma_roce_rescan_device(&dev->ib_dev); |
| 6561 | break; |
| 6562 | } |
| 6563 | } |
| 6564 | |
| 6565 | if (!bound) { |
| 6566 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 6567 | dev_dbg(&mdev->pdev->dev, "no suitable IB device found to bind to, added to unaffiliated list.\n"); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6568 | } |
| 6569 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6570 | |
| 6571 | return mpi; |
| 6572 | } |
| 6573 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6574 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
| 6575 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6576 | enum rdma_link_layer ll; |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6577 | struct mlx5_ib_dev *dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6578 | int port_type_cap; |
| 6579 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6580 | printk_once(KERN_INFO "%s", mlx5_version); |
| 6581 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6582 | if (MLX5_ESWITCH_MANAGER(mdev) && |
| 6583 | mlx5_ib_eswitch_mode(mdev->priv.eswitch) == SRIOV_OFFLOADS) { |
| 6584 | mlx5_ib_register_vport_reps(mdev); |
| 6585 | return mdev; |
| 6586 | } |
| 6587 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6588 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6589 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6590 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6591 | if (mlx5_core_is_mp_slave(mdev) && ll == IB_LINK_LAYER_ETHERNET) |
| 6592 | return mlx5_ib_add_slave_port(mdev); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6593 | |
Leon Romanovsky | 459cc69 | 2019-01-30 12:49:11 +0200 | [diff] [blame] | 6594 | dev = ib_alloc_device(mlx5_ib_dev, ib_dev); |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6595 | if (!dev) |
| 6596 | return NULL; |
| 6597 | |
| 6598 | dev->mdev = mdev; |
| 6599 | dev->num_ports = max(MLX5_CAP_GEN(mdev, num_ports), |
| 6600 | MLX5_CAP_GEN(mdev, num_vhca_ports)); |
| 6601 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6602 | return __mlx5_ib_add(dev, &pf_profile); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6603 | } |
| 6604 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6605 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6606 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6607 | struct mlx5_ib_multiport_info *mpi; |
| 6608 | struct mlx5_ib_dev *dev; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6609 | |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6610 | if (MLX5_ESWITCH_MANAGER(mdev) && context == mdev) { |
| 6611 | mlx5_ib_unregister_vport_reps(mdev); |
| 6612 | return; |
| 6613 | } |
| 6614 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6615 | if (mlx5_core_is_mp_slave(mdev)) { |
| 6616 | mpi = context; |
| 6617 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6618 | if (mpi->ibdev) |
| 6619 | mlx5_ib_unbind_slave_port(mpi->ibdev, mpi); |
| 6620 | list_del(&mpi->list); |
| 6621 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6622 | return; |
| 6623 | } |
| 6624 | |
| 6625 | dev = context; |
Bodong Wang | f0666f1 | 2019-02-12 22:55:34 -0800 | [diff] [blame] | 6626 | __mlx5_ib_remove(dev, dev->profile, MLX5_IB_STAGE_MAX); |
Mark Bloch | 06cc74a | 2018-12-12 19:11:37 -0800 | [diff] [blame] | 6627 | |
| 6628 | ib_dealloc_device((struct ib_device *)dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6629 | } |
| 6630 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6631 | static struct mlx5_interface mlx5_ib_interface = { |
| 6632 | .add = mlx5_ib_add, |
| 6633 | .remove = mlx5_ib_remove, |
Saeed Mahameed | 64613d94 | 2015-04-02 17:07:34 +0300 | [diff] [blame] | 6634 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6635 | }; |
| 6636 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6637 | unsigned long mlx5_ib_get_xlt_emergency_page(void) |
| 6638 | { |
| 6639 | mutex_lock(&xlt_emergency_page_mutex); |
| 6640 | return xlt_emergency_page; |
| 6641 | } |
| 6642 | |
| 6643 | void mlx5_ib_put_xlt_emergency_page(void) |
| 6644 | { |
| 6645 | mutex_unlock(&xlt_emergency_page_mutex); |
| 6646 | } |
| 6647 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6648 | static int __init mlx5_ib_init(void) |
| 6649 | { |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6650 | int err; |
| 6651 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6652 | xlt_emergency_page = __get_free_page(GFP_KERNEL); |
| 6653 | if (!xlt_emergency_page) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6654 | return -ENOMEM; |
| 6655 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6656 | mutex_init(&xlt_emergency_page_mutex); |
| 6657 | |
| 6658 | mlx5_ib_event_wq = alloc_ordered_workqueue("mlx5_ib_event_wq", 0); |
| 6659 | if (!mlx5_ib_event_wq) { |
| 6660 | free_page(xlt_emergency_page); |
| 6661 | return -ENOMEM; |
| 6662 | } |
| 6663 | |
Artemy Kovalyov | 81713d3 | 2017-01-18 16:58:11 +0200 | [diff] [blame] | 6664 | mlx5_ib_odp_init(); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6665 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6666 | err = mlx5_register_interface(&mlx5_ib_interface); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6667 | |
| 6668 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6669 | } |
| 6670 | |
| 6671 | static void __exit mlx5_ib_cleanup(void) |
| 6672 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6673 | mlx5_unregister_interface(&mlx5_ib_interface); |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6674 | destroy_workqueue(mlx5_ib_event_wq); |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6675 | mutex_destroy(&xlt_emergency_page_mutex); |
| 6676 | free_page(xlt_emergency_page); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6677 | } |
| 6678 | |
| 6679 | module_init(mlx5_ib_init); |
| 6680 | module_exit(mlx5_ib_cleanup); |