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" |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 63 | #include <linux/mlx5/fs_helpers.h> |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 64 | #include <linux/mlx5/accel.h> |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 65 | #include <rdma/uverbs_std_types.h> |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 66 | #include <rdma/mlx5_user_ioctl_verbs.h> |
| 67 | #include <rdma/mlx5_user_ioctl_cmds.h> |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 68 | |
| 69 | #define UVERBS_MODULE_NAME mlx5_ib |
| 70 | #include <rdma/uverbs_named_ioctl.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 71 | |
| 72 | #define DRIVER_NAME "mlx5_ib" |
Tariq Toukan | b359911 | 2017-02-22 17:45:46 +0200 | [diff] [blame] | 73 | #define DRIVER_VERSION "5.0-0" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 74 | |
| 75 | MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); |
| 76 | MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); |
| 77 | MODULE_LICENSE("Dual BSD/GPL"); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 78 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 79 | static char mlx5_version[] = |
| 80 | DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
Tariq Toukan | b359911 | 2017-02-22 17:45:46 +0200 | [diff] [blame] | 81 | DRIVER_VERSION "\n"; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 82 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 83 | struct mlx5_ib_event_work { |
| 84 | struct work_struct work; |
| 85 | struct mlx5_core_dev *dev; |
| 86 | void *context; |
| 87 | enum mlx5_dev_event event; |
| 88 | unsigned long param; |
| 89 | }; |
| 90 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 91 | enum { |
| 92 | MLX5_ATOMIC_SIZE_QP_8BYTES = 1 << 3, |
| 93 | }; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 94 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 95 | static struct workqueue_struct *mlx5_ib_event_wq; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 96 | static LIST_HEAD(mlx5_ib_unaffiliated_port_list); |
| 97 | static LIST_HEAD(mlx5_ib_dev_list); |
| 98 | /* |
| 99 | * This mutex should be held when accessing either of the above lists |
| 100 | */ |
| 101 | static DEFINE_MUTEX(mlx5_ib_multiport_mutex); |
| 102 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 103 | /* We can't use an array for xlt_emergency_page because dma_map_single |
| 104 | * doesn't work on kernel modules memory |
| 105 | */ |
| 106 | static unsigned long xlt_emergency_page; |
| 107 | static struct mutex xlt_emergency_page_mutex; |
| 108 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 109 | struct mlx5_ib_dev *mlx5_ib_get_ibdev_from_mpi(struct mlx5_ib_multiport_info *mpi) |
| 110 | { |
| 111 | struct mlx5_ib_dev *dev; |
| 112 | |
| 113 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 114 | dev = mpi->ibdev; |
| 115 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 116 | return dev; |
| 117 | } |
| 118 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 119 | static enum rdma_link_layer |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 120 | mlx5_port_type_cap_to_rdma_ll(int port_type_cap) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 121 | { |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 122 | switch (port_type_cap) { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 123 | case MLX5_CAP_PORT_TYPE_IB: |
| 124 | return IB_LINK_LAYER_INFINIBAND; |
| 125 | case MLX5_CAP_PORT_TYPE_ETH: |
| 126 | return IB_LINK_LAYER_ETHERNET; |
| 127 | default: |
| 128 | return IB_LINK_LAYER_UNSPECIFIED; |
| 129 | } |
| 130 | } |
| 131 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 132 | static enum rdma_link_layer |
| 133 | mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num) |
| 134 | { |
| 135 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 136 | int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type); |
| 137 | |
| 138 | return mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 139 | } |
| 140 | |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 141 | static int get_port_state(struct ib_device *ibdev, |
| 142 | u8 port_num, |
| 143 | enum ib_port_state *state) |
| 144 | { |
| 145 | struct ib_port_attr attr; |
| 146 | int ret; |
| 147 | |
| 148 | memset(&attr, 0, sizeof(attr)); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 149 | ret = ibdev->query_port(ibdev, port_num, &attr); |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 150 | if (!ret) |
| 151 | *state = attr.state; |
| 152 | return ret; |
| 153 | } |
| 154 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 155 | static int mlx5_netdev_event(struct notifier_block *this, |
| 156 | unsigned long event, void *ptr) |
| 157 | { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 158 | struct mlx5_roce *roce = container_of(this, struct mlx5_roce, nb); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 159 | struct net_device *ndev = netdev_notifier_info_to_dev(ptr); |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 160 | u8 port_num = roce->native_port_num; |
| 161 | struct mlx5_core_dev *mdev; |
| 162 | struct mlx5_ib_dev *ibdev; |
| 163 | |
| 164 | ibdev = roce->dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 165 | mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL); |
| 166 | if (!mdev) |
| 167 | return NOTIFY_DONE; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 168 | |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 169 | switch (event) { |
| 170 | case NETDEV_REGISTER: |
| 171 | case NETDEV_UNREGISTER: |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 172 | write_lock(&roce->netdev_lock); |
Mark Bloch | bcf87f1 | 2018-01-16 15:02:36 +0000 | [diff] [blame] | 173 | if (ibdev->rep) { |
| 174 | struct mlx5_eswitch *esw = ibdev->mdev->priv.eswitch; |
| 175 | struct net_device *rep_ndev; |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 176 | |
Mark Bloch | bcf87f1 | 2018-01-16 15:02:36 +0000 | [diff] [blame] | 177 | rep_ndev = mlx5_ib_get_rep_netdev(esw, |
| 178 | ibdev->rep->vport); |
| 179 | if (rep_ndev == ndev) |
| 180 | roce->netdev = (event == NETDEV_UNREGISTER) ? |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 181 | NULL : ndev; |
Parav Pandit | 84a6a7a | 2018-04-23 17:01:55 +0300 | [diff] [blame] | 182 | } else if (ndev->dev.parent == &mdev->pdev->dev) { |
Mark Bloch | bcf87f1 | 2018-01-16 15:02:36 +0000 | [diff] [blame] | 183 | roce->netdev = (event == NETDEV_UNREGISTER) ? |
| 184 | NULL : ndev; |
| 185 | } |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 186 | write_unlock(&roce->netdev_lock); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 187 | break; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 188 | |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 189 | case NETDEV_CHANGE: |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 190 | case NETDEV_UP: |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 191 | case NETDEV_DOWN: { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 192 | struct net_device *lag_ndev = mlx5_lag_get_roce_netdev(mdev); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 193 | struct net_device *upper = NULL; |
| 194 | |
| 195 | if (lag_ndev) { |
| 196 | upper = netdev_master_upper_dev_get(lag_ndev); |
| 197 | dev_put(lag_ndev); |
| 198 | } |
| 199 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 200 | if ((upper == ndev || (!upper && ndev == roce->netdev)) |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 201 | && ibdev->ib_active) { |
Bart Van Assche | 626bc02 | 2016-12-05 17:18:08 -0800 | [diff] [blame] | 202 | struct ib_event ibev = { }; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 203 | enum ib_port_state port_state; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 204 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 205 | if (get_port_state(&ibdev->ib_dev, port_num, |
| 206 | &port_state)) |
| 207 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 208 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 209 | if (roce->last_port_state == port_state) |
| 210 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 211 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 212 | roce->last_port_state = port_state; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 213 | ibev.device = &ibdev->ib_dev; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 214 | if (port_state == IB_PORT_DOWN) |
| 215 | ibev.event = IB_EVENT_PORT_ERR; |
| 216 | else if (port_state == IB_PORT_ACTIVE) |
| 217 | ibev.event = IB_EVENT_PORT_ACTIVE; |
| 218 | else |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 219 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 220 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 221 | ibev.element.port_num = port_num; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 222 | ib_dispatch_event(&ibev); |
| 223 | } |
| 224 | break; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 225 | } |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 226 | |
| 227 | default: |
| 228 | break; |
| 229 | } |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 230 | done: |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 231 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 232 | return NOTIFY_DONE; |
| 233 | } |
| 234 | |
| 235 | static struct net_device *mlx5_ib_get_netdev(struct ib_device *device, |
| 236 | u8 port_num) |
| 237 | { |
| 238 | struct mlx5_ib_dev *ibdev = to_mdev(device); |
| 239 | struct net_device *ndev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 240 | struct mlx5_core_dev *mdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 241 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 242 | mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL); |
| 243 | if (!mdev) |
| 244 | return NULL; |
| 245 | |
| 246 | ndev = mlx5_lag_get_roce_netdev(mdev); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 247 | if (ndev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 248 | goto out; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 249 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 250 | /* Ensure ndev does not disappear before we invoke dev_hold() |
| 251 | */ |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 252 | read_lock(&ibdev->roce[port_num - 1].netdev_lock); |
| 253 | ndev = ibdev->roce[port_num - 1].netdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 254 | if (ndev) |
| 255 | dev_hold(ndev); |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 256 | read_unlock(&ibdev->roce[port_num - 1].netdev_lock); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 257 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 258 | out: |
| 259 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 260 | return ndev; |
| 261 | } |
| 262 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 263 | struct mlx5_core_dev *mlx5_ib_get_native_port_mdev(struct mlx5_ib_dev *ibdev, |
| 264 | u8 ib_port_num, |
| 265 | u8 *native_port_num) |
| 266 | { |
| 267 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&ibdev->ib_dev, |
| 268 | ib_port_num); |
| 269 | struct mlx5_core_dev *mdev = NULL; |
| 270 | struct mlx5_ib_multiport_info *mpi; |
| 271 | struct mlx5_ib_port *port; |
| 272 | |
Mark Bloch | 210b1f7 | 2018-03-05 20:09:47 +0200 | [diff] [blame] | 273 | if (!mlx5_core_mp_enabled(ibdev->mdev) || |
| 274 | ll != IB_LINK_LAYER_ETHERNET) { |
| 275 | if (native_port_num) |
| 276 | *native_port_num = ib_port_num; |
| 277 | return ibdev->mdev; |
| 278 | } |
| 279 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 280 | if (native_port_num) |
| 281 | *native_port_num = 1; |
| 282 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 283 | port = &ibdev->port[ib_port_num - 1]; |
| 284 | if (!port) |
| 285 | return NULL; |
| 286 | |
| 287 | spin_lock(&port->mp.mpi_lock); |
| 288 | mpi = ibdev->port[ib_port_num - 1].mp.mpi; |
| 289 | if (mpi && !mpi->unaffiliate) { |
| 290 | mdev = mpi->mdev; |
| 291 | /* If it's the master no need to refcount, it'll exist |
| 292 | * as long as the ib_dev exists. |
| 293 | */ |
| 294 | if (!mpi->is_master) |
| 295 | mpi->mdev_refcnt++; |
| 296 | } |
| 297 | spin_unlock(&port->mp.mpi_lock); |
| 298 | |
| 299 | return mdev; |
| 300 | } |
| 301 | |
| 302 | void mlx5_ib_put_native_port_mdev(struct mlx5_ib_dev *ibdev, u8 port_num) |
| 303 | { |
| 304 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&ibdev->ib_dev, |
| 305 | port_num); |
| 306 | struct mlx5_ib_multiport_info *mpi; |
| 307 | struct mlx5_ib_port *port; |
| 308 | |
| 309 | if (!mlx5_core_mp_enabled(ibdev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 310 | return; |
| 311 | |
| 312 | port = &ibdev->port[port_num - 1]; |
| 313 | |
| 314 | spin_lock(&port->mp.mpi_lock); |
| 315 | mpi = ibdev->port[port_num - 1].mp.mpi; |
| 316 | if (mpi->is_master) |
| 317 | goto out; |
| 318 | |
| 319 | mpi->mdev_refcnt--; |
| 320 | if (mpi->unaffiliate) |
| 321 | complete(&mpi->unref_comp); |
| 322 | out: |
| 323 | spin_unlock(&port->mp.mpi_lock); |
| 324 | } |
| 325 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 326 | static int translate_eth_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 327 | u8 *active_width) |
| 328 | { |
| 329 | switch (eth_proto_oper) { |
| 330 | case MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII): |
| 331 | case MLX5E_PROT_MASK(MLX5E_1000BASE_KX): |
| 332 | case MLX5E_PROT_MASK(MLX5E_100BASE_TX): |
| 333 | case MLX5E_PROT_MASK(MLX5E_1000BASE_T): |
| 334 | *active_width = IB_WIDTH_1X; |
| 335 | *active_speed = IB_SPEED_SDR; |
| 336 | break; |
| 337 | case MLX5E_PROT_MASK(MLX5E_10GBASE_T): |
| 338 | case MLX5E_PROT_MASK(MLX5E_10GBASE_CX4): |
| 339 | case MLX5E_PROT_MASK(MLX5E_10GBASE_KX4): |
| 340 | case MLX5E_PROT_MASK(MLX5E_10GBASE_KR): |
| 341 | case MLX5E_PROT_MASK(MLX5E_10GBASE_CR): |
| 342 | case MLX5E_PROT_MASK(MLX5E_10GBASE_SR): |
| 343 | case MLX5E_PROT_MASK(MLX5E_10GBASE_ER): |
| 344 | *active_width = IB_WIDTH_1X; |
| 345 | *active_speed = IB_SPEED_QDR; |
| 346 | break; |
| 347 | case MLX5E_PROT_MASK(MLX5E_25GBASE_CR): |
| 348 | case MLX5E_PROT_MASK(MLX5E_25GBASE_KR): |
| 349 | case MLX5E_PROT_MASK(MLX5E_25GBASE_SR): |
| 350 | *active_width = IB_WIDTH_1X; |
| 351 | *active_speed = IB_SPEED_EDR; |
| 352 | break; |
| 353 | case MLX5E_PROT_MASK(MLX5E_40GBASE_CR4): |
| 354 | case MLX5E_PROT_MASK(MLX5E_40GBASE_KR4): |
| 355 | case MLX5E_PROT_MASK(MLX5E_40GBASE_SR4): |
| 356 | case MLX5E_PROT_MASK(MLX5E_40GBASE_LR4): |
| 357 | *active_width = IB_WIDTH_4X; |
| 358 | *active_speed = IB_SPEED_QDR; |
| 359 | break; |
| 360 | case MLX5E_PROT_MASK(MLX5E_50GBASE_CR2): |
| 361 | case MLX5E_PROT_MASK(MLX5E_50GBASE_KR2): |
| 362 | case MLX5E_PROT_MASK(MLX5E_50GBASE_SR2): |
| 363 | *active_width = IB_WIDTH_1X; |
| 364 | *active_speed = IB_SPEED_HDR; |
| 365 | break; |
| 366 | case MLX5E_PROT_MASK(MLX5E_56GBASE_R4): |
| 367 | *active_width = IB_WIDTH_4X; |
| 368 | *active_speed = IB_SPEED_FDR; |
| 369 | break; |
| 370 | case MLX5E_PROT_MASK(MLX5E_100GBASE_CR4): |
| 371 | case MLX5E_PROT_MASK(MLX5E_100GBASE_SR4): |
| 372 | case MLX5E_PROT_MASK(MLX5E_100GBASE_KR4): |
| 373 | case MLX5E_PROT_MASK(MLX5E_100GBASE_LR4): |
| 374 | *active_width = IB_WIDTH_4X; |
| 375 | *active_speed = IB_SPEED_EDR; |
| 376 | break; |
| 377 | default: |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 384 | static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, |
| 385 | struct ib_port_attr *props) |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 386 | { |
| 387 | struct mlx5_ib_dev *dev = to_mdev(device); |
Colin Ian King | da005f9 | 2018-01-09 15:55:43 +0000 | [diff] [blame] | 388 | struct mlx5_core_dev *mdev; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 389 | struct net_device *ndev, *upper; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 390 | enum ib_mtu ndev_ib_mtu; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 391 | bool put_mdev = true; |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 392 | u16 qkey_viol_cntr; |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 393 | u32 eth_prot_oper; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 394 | u8 mdev_port_num; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 395 | int err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 396 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 397 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 398 | if (!mdev) { |
| 399 | /* This means the port isn't affiliated yet. Get the |
| 400 | * info for the master port instead. |
| 401 | */ |
| 402 | put_mdev = false; |
| 403 | mdev = dev->mdev; |
| 404 | mdev_port_num = 1; |
| 405 | port_num = 1; |
| 406 | } |
| 407 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 408 | /* Possible bad flows are checked before filling out props so in case |
| 409 | * of an error it will still be zeroed out. |
Noa Osherovich | 50f22fd | 2017-04-20 20:53:32 +0300 | [diff] [blame] | 410 | */ |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 411 | err = mlx5_query_port_eth_proto_oper(mdev, ð_prot_oper, |
| 412 | mdev_port_num); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 413 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 414 | goto out; |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 415 | |
Honggang Li | 7672ed3 | 2018-03-16 10:37:13 +0800 | [diff] [blame] | 416 | props->active_width = IB_WIDTH_4X; |
| 417 | props->active_speed = IB_SPEED_QDR; |
| 418 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 419 | translate_eth_proto_oper(eth_prot_oper, &props->active_speed, |
| 420 | &props->active_width); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 421 | |
Jason Gunthorpe | 2f944c0 | 2018-07-04 15:57:48 +0300 | [diff] [blame] | 422 | props->port_cap_flags |= IB_PORT_CM_SUP; |
| 423 | props->ip_gids = true; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 424 | |
| 425 | props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev, |
| 426 | roce_address_table_size); |
| 427 | props->max_mtu = IB_MTU_4096; |
| 428 | props->max_msg_sz = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg); |
| 429 | props->pkey_tbl_len = 1; |
| 430 | props->state = IB_PORT_DOWN; |
| 431 | props->phys_state = 3; |
| 432 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 433 | mlx5_query_nic_vport_qkey_viol_cntr(mdev, &qkey_viol_cntr); |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 434 | props->qkey_viol_cntr = qkey_viol_cntr; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 435 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 436 | /* If this is a stub query for an unaffiliated port stop here */ |
| 437 | if (!put_mdev) |
| 438 | goto out; |
| 439 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 440 | ndev = mlx5_ib_get_netdev(device, port_num); |
| 441 | if (!ndev) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 442 | goto out; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 443 | |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 444 | if (mlx5_lag_is_active(dev->mdev)) { |
| 445 | rcu_read_lock(); |
| 446 | upper = netdev_master_upper_dev_get_rcu(ndev); |
| 447 | if (upper) { |
| 448 | dev_put(ndev); |
| 449 | ndev = upper; |
| 450 | dev_hold(ndev); |
| 451 | } |
| 452 | rcu_read_unlock(); |
| 453 | } |
| 454 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 455 | if (netif_running(ndev) && netif_carrier_ok(ndev)) { |
| 456 | props->state = IB_PORT_ACTIVE; |
| 457 | props->phys_state = 5; |
| 458 | } |
| 459 | |
| 460 | ndev_ib_mtu = iboe_get_mtu(ndev->mtu); |
| 461 | |
| 462 | dev_put(ndev); |
| 463 | |
| 464 | props->active_mtu = min(props->max_mtu, ndev_ib_mtu); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 465 | out: |
| 466 | if (put_mdev) |
| 467 | mlx5_ib_put_native_port_mdev(dev, port_num); |
| 468 | return err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 469 | } |
| 470 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 471 | static int set_roce_addr(struct mlx5_ib_dev *dev, u8 port_num, |
| 472 | unsigned int index, const union ib_gid *gid, |
| 473 | const struct ib_gid_attr *attr) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 474 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 475 | enum ib_gid_type gid_type = IB_GID_TYPE_IB; |
| 476 | u8 roce_version = 0; |
| 477 | u8 roce_l3_type = 0; |
| 478 | bool vlan = false; |
| 479 | u8 mac[ETH_ALEN]; |
| 480 | u16 vlan_id = 0; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 481 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 482 | if (gid) { |
| 483 | gid_type = attr->gid_type; |
| 484 | ether_addr_copy(mac, attr->ndev->dev_addr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 485 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 486 | if (is_vlan_dev(attr->ndev)) { |
| 487 | vlan = true; |
| 488 | vlan_id = vlan_dev_vlan_id(attr->ndev); |
| 489 | } |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 492 | switch (gid_type) { |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 493 | case IB_GID_TYPE_IB: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 494 | roce_version = MLX5_ROCE_VERSION_1; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 495 | break; |
| 496 | case IB_GID_TYPE_ROCE_UDP_ENCAP: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 497 | roce_version = MLX5_ROCE_VERSION_2; |
| 498 | if (ipv6_addr_v4mapped((void *)gid)) |
| 499 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV4; |
| 500 | else |
| 501 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV6; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 502 | break; |
| 503 | |
| 504 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 505 | mlx5_ib_warn(dev, "Unexpected GID type %u\n", gid_type); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 506 | } |
| 507 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 508 | return mlx5_core_roce_gid_set(dev->mdev, index, roce_version, |
| 509 | roce_l3_type, gid->raw, mac, vlan, |
Daniel Jurgens | cfe4e37 | 2018-01-04 17:25:41 +0200 | [diff] [blame] | 510 | vlan_id, port_num); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 511 | } |
| 512 | |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 513 | static int mlx5_ib_add_gid(const struct ib_gid_attr *attr, |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 514 | __always_unused void **context) |
| 515 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 516 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 517 | attr->index, &attr->gid, attr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 520 | static int mlx5_ib_del_gid(const struct ib_gid_attr *attr, |
| 521 | __always_unused void **context) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 522 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 523 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
| 524 | attr->index, NULL, NULL); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 525 | } |
| 526 | |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 527 | __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, |
| 528 | const struct ib_gid_attr *attr) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 529 | { |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 530 | if (attr->gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 531 | return 0; |
| 532 | |
| 533 | return cpu_to_be16(MLX5_CAP_ROCE(dev->mdev, r_roce_min_src_udp_port)); |
| 534 | } |
| 535 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 536 | static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) |
| 537 | { |
Noa Osherovich | 7fae665 | 2016-09-12 19:16:23 +0300 | [diff] [blame] | 538 | if (MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_IB) |
| 539 | return !MLX5_CAP_GEN(dev->mdev, ib_virt); |
| 540 | return 0; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | enum { |
| 544 | MLX5_VPORT_ACCESS_METHOD_MAD, |
| 545 | MLX5_VPORT_ACCESS_METHOD_HCA, |
| 546 | MLX5_VPORT_ACCESS_METHOD_NIC, |
| 547 | }; |
| 548 | |
| 549 | static int mlx5_get_vport_access_method(struct ib_device *ibdev) |
| 550 | { |
| 551 | if (mlx5_use_mad_ifc(to_mdev(ibdev))) |
| 552 | return MLX5_VPORT_ACCESS_METHOD_MAD; |
| 553 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 554 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 555 | IB_LINK_LAYER_ETHERNET) |
| 556 | return MLX5_VPORT_ACCESS_METHOD_NIC; |
| 557 | |
| 558 | return MLX5_VPORT_ACCESS_METHOD_HCA; |
| 559 | } |
| 560 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 561 | static void get_atomic_caps(struct mlx5_ib_dev *dev, |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 562 | u8 atomic_size_qp, |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 563 | struct ib_device_attr *props) |
| 564 | { |
| 565 | u8 tmp; |
| 566 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 567 | u8 atomic_req_8B_endianness_mode = |
Or Gerlitz | bd10838 | 2017-05-28 15:24:17 +0300 | [diff] [blame] | 568 | MLX5_CAP_ATOMIC(dev->mdev, atomic_req_8B_endianness_mode); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 569 | |
| 570 | /* Check if HW supports 8 bytes standard atomic operations and capable |
| 571 | * of host endianness respond |
| 572 | */ |
| 573 | tmp = MLX5_ATOMIC_OPS_CMP_SWAP | MLX5_ATOMIC_OPS_FETCH_ADD; |
| 574 | if (((atomic_operations & tmp) == tmp) && |
| 575 | (atomic_size_qp & MLX5_ATOMIC_SIZE_QP_8BYTES) && |
| 576 | (atomic_req_8B_endianness_mode)) { |
| 577 | props->atomic_cap = IB_ATOMIC_HCA; |
| 578 | } else { |
| 579 | props->atomic_cap = IB_ATOMIC_NONE; |
| 580 | } |
| 581 | } |
| 582 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 583 | static void get_atomic_caps_qp(struct mlx5_ib_dev *dev, |
| 584 | struct ib_device_attr *props) |
| 585 | { |
| 586 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 587 | |
| 588 | get_atomic_caps(dev, atomic_size_qp, props); |
| 589 | } |
| 590 | |
| 591 | static void get_atomic_caps_dc(struct mlx5_ib_dev *dev, |
| 592 | struct ib_device_attr *props) |
| 593 | { |
| 594 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc); |
| 595 | |
| 596 | get_atomic_caps(dev, atomic_size_qp, props); |
| 597 | } |
| 598 | |
| 599 | bool mlx5_ib_dc_atomic_is_supported(struct mlx5_ib_dev *dev) |
| 600 | { |
| 601 | struct ib_device_attr props = {}; |
| 602 | |
| 603 | get_atomic_caps_dc(dev, &props); |
| 604 | return (props.atomic_cap == IB_ATOMIC_HCA) ? true : false; |
| 605 | } |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 606 | static int mlx5_query_system_image_guid(struct ib_device *ibdev, |
| 607 | __be64 *sys_image_guid) |
| 608 | { |
| 609 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 610 | struct mlx5_core_dev *mdev = dev->mdev; |
| 611 | u64 tmp; |
| 612 | int err; |
| 613 | |
| 614 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 615 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 616 | return mlx5_query_mad_ifc_system_image_guid(ibdev, |
| 617 | sys_image_guid); |
| 618 | |
| 619 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 620 | err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 621 | break; |
| 622 | |
| 623 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 624 | err = mlx5_query_nic_vport_system_image_guid(mdev, &tmp); |
| 625 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 626 | |
| 627 | default: |
| 628 | return -EINVAL; |
| 629 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 630 | |
| 631 | if (!err) |
| 632 | *sys_image_guid = cpu_to_be64(tmp); |
| 633 | |
| 634 | return err; |
| 635 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static int mlx5_query_max_pkeys(struct ib_device *ibdev, |
| 639 | u16 *max_pkeys) |
| 640 | { |
| 641 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 642 | struct mlx5_core_dev *mdev = dev->mdev; |
| 643 | |
| 644 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 645 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 646 | return mlx5_query_mad_ifc_max_pkeys(ibdev, max_pkeys); |
| 647 | |
| 648 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 649 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 650 | *max_pkeys = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, |
| 651 | pkey_table_size)); |
| 652 | return 0; |
| 653 | |
| 654 | default: |
| 655 | return -EINVAL; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | static int mlx5_query_vendor_id(struct ib_device *ibdev, |
| 660 | u32 *vendor_id) |
| 661 | { |
| 662 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 663 | |
| 664 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 665 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 666 | return mlx5_query_mad_ifc_vendor_id(ibdev, vendor_id); |
| 667 | |
| 668 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 669 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 670 | return mlx5_core_query_vendor_id(dev->mdev, vendor_id); |
| 671 | |
| 672 | default: |
| 673 | return -EINVAL; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | static int mlx5_query_node_guid(struct mlx5_ib_dev *dev, |
| 678 | __be64 *node_guid) |
| 679 | { |
| 680 | u64 tmp; |
| 681 | int err; |
| 682 | |
| 683 | switch (mlx5_get_vport_access_method(&dev->ib_dev)) { |
| 684 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 685 | return mlx5_query_mad_ifc_node_guid(dev, node_guid); |
| 686 | |
| 687 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 688 | err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 689 | break; |
| 690 | |
| 691 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 692 | err = mlx5_query_nic_vport_node_guid(dev->mdev, &tmp); |
| 693 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 694 | |
| 695 | default: |
| 696 | return -EINVAL; |
| 697 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 698 | |
| 699 | if (!err) |
| 700 | *node_guid = cpu_to_be64(tmp); |
| 701 | |
| 702 | return err; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | struct mlx5_reg_node_desc { |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 706 | u8 desc[IB_DEVICE_NODE_DESC_MAX]; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 707 | }; |
| 708 | |
| 709 | static int mlx5_query_node_desc(struct mlx5_ib_dev *dev, char *node_desc) |
| 710 | { |
| 711 | struct mlx5_reg_node_desc in; |
| 712 | |
| 713 | if (mlx5_use_mad_ifc(dev)) |
| 714 | return mlx5_query_mad_ifc_node_desc(dev, node_desc); |
| 715 | |
| 716 | memset(&in, 0, sizeof(in)); |
| 717 | |
| 718 | return mlx5_core_access_reg(dev->mdev, &in, sizeof(in), node_desc, |
| 719 | sizeof(struct mlx5_reg_node_desc), |
| 720 | MLX5_REG_NODE_DESC, 0, 0); |
| 721 | } |
| 722 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 723 | static int mlx5_ib_query_device(struct ib_device *ibdev, |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 724 | struct ib_device_attr *props, |
| 725 | struct ib_udata *uhw) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 726 | { |
| 727 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 728 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 729 | int err = -ENOMEM; |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 730 | int max_sq_desc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 731 | int max_rq_sg; |
| 732 | int max_sq_sg; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 733 | u64 min_page_size = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 734 | bool raw_support = !mlx5_core_mp_enabled(mdev); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 735 | struct mlx5_ib_query_device_resp resp = {}; |
| 736 | size_t resp_len; |
| 737 | u64 max_tso; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 738 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 739 | resp_len = sizeof(resp.comp_mask) + sizeof(resp.response_length); |
| 740 | if (uhw->outlen && uhw->outlen < resp_len) |
| 741 | return -EINVAL; |
| 742 | else |
| 743 | resp.response_length = resp_len; |
| 744 | |
| 745 | if (uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen)) |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 746 | return -EINVAL; |
| 747 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 748 | memset(props, 0, sizeof(*props)); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 749 | err = mlx5_query_system_image_guid(ibdev, |
| 750 | &props->sys_image_guid); |
| 751 | if (err) |
| 752 | return err; |
| 753 | |
| 754 | err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys); |
| 755 | if (err) |
| 756 | return err; |
| 757 | |
| 758 | err = mlx5_query_vendor_id(ibdev, &props->vendor_id); |
| 759 | if (err) |
| 760 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 761 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 762 | props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) | |
| 763 | (fw_rev_min(dev->mdev) << 16) | |
| 764 | fw_rev_sub(dev->mdev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 765 | props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | |
| 766 | IB_DEVICE_PORT_ACTIVE_EVENT | |
| 767 | IB_DEVICE_SYS_IMAGE_GUID | |
Eli Cohen | 1a4c3a3 | 2014-02-06 17:41:25 +0200 | [diff] [blame] | 768 | IB_DEVICE_RC_RNR_NAK_GEN; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 769 | |
| 770 | if (MLX5_CAP_GEN(mdev, pkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 771 | props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 772 | if (MLX5_CAP_GEN(mdev, qkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 773 | props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 774 | if (MLX5_CAP_GEN(mdev, apm)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 775 | props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 776 | if (MLX5_CAP_GEN(mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 777 | props->device_cap_flags |= IB_DEVICE_XRC; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 778 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
| 779 | props->device_cap_flags |= IB_DEVICE_MEM_WINDOW | |
| 780 | IB_DEVICE_MEM_WINDOW_TYPE_2B; |
| 781 | props->max_mw = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 782 | /* We support 'Gappy' memory registration too */ |
| 783 | props->device_cap_flags |= IB_DEVICE_SG_GAPS_REG; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 784 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 785 | props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 786 | if (MLX5_CAP_GEN(mdev, sho)) { |
Sagi Grimberg | 2dea909 | 2014-02-23 14:19:13 +0200 | [diff] [blame] | 787 | props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER; |
| 788 | /* At this stage no support for signature handover */ |
| 789 | props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 | |
| 790 | IB_PROT_T10DIF_TYPE_2 | |
| 791 | IB_PROT_T10DIF_TYPE_3; |
| 792 | props->sig_guard_cap = IB_GUARD_T10DIF_CRC | |
| 793 | IB_GUARD_T10DIF_CSUM; |
| 794 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 795 | if (MLX5_CAP_GEN(mdev, block_lb_mc)) |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 796 | props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 797 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 798 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 799 | if (MLX5_CAP_ETH(mdev, csum_cap)) { |
| 800 | /* Legacy bit to support old userspace libraries */ |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 801 | props->device_cap_flags |= IB_DEVICE_RAW_IP_CSUM; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 802 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_IP_CSUM; |
| 803 | } |
| 804 | |
| 805 | if (MLX5_CAP_ETH(dev->mdev, vlan_cap)) |
| 806 | props->raw_packet_caps |= |
| 807 | IB_RAW_PACKET_CAP_CVLAN_STRIPPING; |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 808 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 809 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) { |
| 810 | max_tso = MLX5_CAP_ETH(mdev, max_lso_cap); |
| 811 | if (max_tso) { |
| 812 | resp.tso_caps.max_tso = 1 << max_tso; |
| 813 | resp.tso_caps.supported_qpts |= |
| 814 | 1 << IB_QPT_RAW_PACKET; |
| 815 | resp.response_length += sizeof(resp.tso_caps); |
| 816 | } |
| 817 | } |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 818 | |
| 819 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) { |
| 820 | resp.rss_caps.rx_hash_function = |
| 821 | MLX5_RX_HASH_FUNC_TOEPLITZ; |
| 822 | resp.rss_caps.rx_hash_fields_mask = |
| 823 | MLX5_RX_HASH_SRC_IPV4 | |
| 824 | MLX5_RX_HASH_DST_IPV4 | |
| 825 | MLX5_RX_HASH_SRC_IPV6 | |
| 826 | MLX5_RX_HASH_DST_IPV6 | |
| 827 | MLX5_RX_HASH_SRC_PORT_TCP | |
| 828 | MLX5_RX_HASH_DST_PORT_TCP | |
| 829 | MLX5_RX_HASH_SRC_PORT_UDP | |
Maor Gottlieb | 4e2b53a | 2017-12-24 14:51:25 +0200 | [diff] [blame] | 830 | MLX5_RX_HASH_DST_PORT_UDP | |
| 831 | MLX5_RX_HASH_INNER; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 832 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
| 833 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 834 | resp.rss_caps.rx_hash_fields_mask |= |
| 835 | MLX5_RX_HASH_IPSEC_SPI; |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 836 | resp.response_length += sizeof(resp.rss_caps); |
| 837 | } |
| 838 | } else { |
| 839 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) |
| 840 | resp.response_length += sizeof(resp.tso_caps); |
| 841 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) |
| 842 | resp.response_length += sizeof(resp.rss_caps); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 843 | } |
| 844 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 845 | if (MLX5_CAP_GEN(mdev, ipoib_basic_offloads)) { |
| 846 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 847 | props->device_cap_flags |= IB_DEVICE_UD_TSO; |
| 848 | } |
| 849 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 850 | if (MLX5_CAP_GEN(dev->mdev, rq_delay_drop) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 851 | MLX5_CAP_GEN(dev->mdev, general_notification_event) && |
| 852 | raw_support) |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 853 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_DELAY_DROP; |
| 854 | |
Yishai Hadas | 1d54f89 | 2017-06-08 16:15:11 +0300 | [diff] [blame] | 855 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
| 856 | MLX5_CAP_IPOIB_ENHANCED(mdev, csum_cap)) |
| 857 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 858 | |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 859 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 860 | MLX5_CAP_ETH(dev->mdev, scatter_fcs) && |
| 861 | raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 862 | /* Legacy bit to support old userspace libraries */ |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 863 | props->device_cap_flags |= IB_DEVICE_RAW_SCATTER_FCS; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 864 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_SCATTER_FCS; |
| 865 | } |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 866 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 867 | if (MLX5_CAP_DEV_MEM(mdev, memic)) { |
| 868 | props->max_dm_size = |
| 869 | MLX5_CAP_DEV_MEM(mdev, max_memic_size); |
| 870 | } |
| 871 | |
Maor Gottlieb | da6d6ba3 | 2016-06-04 15:15:28 +0300 | [diff] [blame] | 872 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_BYPASS)) |
| 873 | props->device_cap_flags |= IB_DEVICE_MANAGED_FLOW_STEERING; |
| 874 | |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 875 | if (MLX5_CAP_GEN(mdev, end_pad)) |
| 876 | props->device_cap_flags |= IB_DEVICE_PCI_WRITE_END_PADDING; |
| 877 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 878 | props->vendor_part_id = mdev->pdev->device; |
| 879 | props->hw_ver = mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 880 | |
| 881 | props->max_mr_size = ~0ull; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 882 | props->page_size_cap = ~(min_page_size - 1); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 883 | props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp); |
| 884 | props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
| 885 | max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) / |
| 886 | sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 887 | max_sq_desc = min_t(int, MLX5_CAP_GEN(mdev, max_wqe_sz_sq), 512); |
| 888 | max_sq_sg = (max_sq_desc - sizeof(struct mlx5_wqe_ctrl_seg) - |
| 889 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 890 | sizeof(struct mlx5_wqe_data_seg); |
Steve Wise | 33023fb | 2018-06-18 08:05:26 -0700 | [diff] [blame] | 891 | props->max_send_sge = max_sq_sg; |
| 892 | props->max_recv_sge = max_rq_sg; |
Sagi Grimberg | 986ef95 | 2016-03-31 19:03:25 +0300 | [diff] [blame] | 893 | props->max_sge_rd = MLX5_MAX_SGE_RD; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 894 | props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq); |
Leon Romanovsky | 9f17768 | 2016-01-14 08:11:40 +0200 | [diff] [blame] | 895 | 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] | 896 | props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
| 897 | props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd); |
| 898 | props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp); |
| 899 | props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp); |
| 900 | props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq); |
| 901 | props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1; |
| 902 | 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] | 903 | 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] | 904 | props->max_srq_sge = max_rq_sg - 1; |
Sagi Grimberg | 911f433 | 2016-03-03 13:37:51 +0200 | [diff] [blame] | 905 | props->max_fast_reg_page_list_len = |
| 906 | 1 << MLX5_CAP_GEN(mdev, log_max_klm_list_size); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 907 | get_atomic_caps_qp(dev, props); |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 908 | props->masked_atomic_cap = IB_ATOMIC_NONE; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 909 | props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg); |
| 910 | props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 911 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 912 | props->max_mcast_grp; |
| 913 | props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */ |
Maor Gottlieb | 86695a6 | 2016-10-27 16:36:38 +0300 | [diff] [blame] | 914 | props->max_ah = INT_MAX; |
Matan Barak | 7c60bcb | 2015-12-15 20:30:11 +0200 | [diff] [blame] | 915 | props->hca_core_clock = MLX5_CAP_GEN(mdev, device_frequency_khz); |
| 916 | props->timestamp_mask = 0x7FFFFFFFFFFFFFFFULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 917 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 918 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 919 | if (MLX5_CAP_GEN(mdev, pg)) |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 920 | props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
| 921 | props->odp_caps = dev->odp_caps; |
| 922 | #endif |
| 923 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 924 | if (MLX5_CAP_GEN(mdev, cd)) |
| 925 | props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL; |
| 926 | |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 927 | if (!mlx5_core_is_pf(mdev)) |
| 928 | props->device_cap_flags |= IB_DEVICE_VIRTUAL_FUNCTION; |
| 929 | |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 930 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 931 | IB_LINK_LAYER_ETHERNET && raw_support) { |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 932 | props->rss_caps.max_rwq_indirection_tables = |
| 933 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt); |
| 934 | props->rss_caps.max_rwq_indirection_table_size = |
| 935 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt_size); |
| 936 | props->rss_caps.supported_qpts = 1 << IB_QPT_RAW_PACKET; |
| 937 | props->max_wq_type_rq = |
| 938 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rq); |
| 939 | } |
| 940 | |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 941 | if (MLX5_CAP_GEN(mdev, tag_matching)) { |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 942 | props->tm_caps.max_rndv_hdr_size = MLX5_TM_MAX_RNDV_MSG_SIZE; |
| 943 | props->tm_caps.max_num_tags = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 944 | (1 << MLX5_CAP_GEN(mdev, log_tag_matching_list_sz)) - 1; |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 945 | props->tm_caps.flags = IB_TM_CAP_RC; |
| 946 | props->tm_caps.max_ops = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 947 | 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 948 | props->tm_caps.max_sge = MLX5_TM_MAX_SGE; |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 949 | } |
| 950 | |
Yonatan Cohen | 87ab3f5 | 2017-11-13 10:51:18 +0200 | [diff] [blame] | 951 | if (MLX5_CAP_GEN(dev->mdev, cq_moderation)) { |
| 952 | props->cq_caps.max_cq_moderation_count = |
| 953 | MLX5_MAX_CQ_COUNT; |
| 954 | props->cq_caps.max_cq_moderation_period = |
| 955 | MLX5_MAX_CQ_PERIOD; |
| 956 | } |
| 957 | |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 958 | if (field_avail(typeof(resp), cqe_comp_caps, uhw->outlen)) { |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 959 | resp.response_length += sizeof(resp.cqe_comp_caps); |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 960 | |
| 961 | if (MLX5_CAP_GEN(dev->mdev, cqe_compression)) { |
| 962 | resp.cqe_comp_caps.max_num = |
| 963 | MLX5_CAP_GEN(dev->mdev, |
| 964 | cqe_compression_max_num); |
| 965 | |
| 966 | resp.cqe_comp_caps.supported_format = |
| 967 | MLX5_IB_CQE_RES_FORMAT_HASH | |
| 968 | MLX5_IB_CQE_RES_FORMAT_CSUM; |
Yonatan Cohen | 6f1006a | 2018-05-27 13:42:34 +0300 | [diff] [blame] | 969 | |
| 970 | if (MLX5_CAP_GEN(dev->mdev, mini_cqe_resp_stride_index)) |
| 971 | resp.cqe_comp_caps.supported_format |= |
| 972 | MLX5_IB_CQE_RES_FORMAT_CSUM_STRIDX; |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 973 | } |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 974 | } |
| 975 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 976 | if (field_avail(typeof(resp), packet_pacing_caps, uhw->outlen) && |
| 977 | raw_support) { |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 978 | if (MLX5_CAP_QOS(mdev, packet_pacing) && |
| 979 | MLX5_CAP_GEN(mdev, qos)) { |
| 980 | resp.packet_pacing_caps.qp_rate_limit_max = |
| 981 | MLX5_CAP_QOS(mdev, packet_pacing_max_rate); |
| 982 | resp.packet_pacing_caps.qp_rate_limit_min = |
| 983 | MLX5_CAP_QOS(mdev, packet_pacing_min_rate); |
| 984 | resp.packet_pacing_caps.supported_qpts |= |
| 985 | 1 << IB_QPT_RAW_PACKET; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 986 | if (MLX5_CAP_QOS(mdev, packet_pacing_burst_bound) && |
| 987 | MLX5_CAP_QOS(mdev, packet_pacing_typical_size)) |
| 988 | resp.packet_pacing_caps.cap_flags |= |
| 989 | MLX5_IB_PP_SUPPORT_BURST; |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 990 | } |
| 991 | resp.response_length += sizeof(resp.packet_pacing_caps); |
| 992 | } |
| 993 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 994 | if (field_avail(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes, |
| 995 | uhw->outlen)) { |
Bodong Wang | 795b609 | 2017-08-17 15:52:34 +0300 | [diff] [blame] | 996 | if (MLX5_CAP_ETH(mdev, multi_pkt_send_wqe)) |
| 997 | resp.mlx5_ib_support_multi_pkt_send_wqes = |
| 998 | MLX5_IB_ALLOW_MPW; |
Bodong Wang | 050da90 | 2017-08-17 15:52:35 +0300 | [diff] [blame] | 999 | |
| 1000 | if (MLX5_CAP_ETH(mdev, enhanced_multi_pkt_send_wqe)) |
| 1001 | resp.mlx5_ib_support_multi_pkt_send_wqes |= |
| 1002 | MLX5_IB_SUPPORT_EMPW; |
| 1003 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1004 | resp.response_length += |
| 1005 | sizeof(resp.mlx5_ib_support_multi_pkt_send_wqes); |
| 1006 | } |
| 1007 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1008 | if (field_avail(typeof(resp), flags, uhw->outlen)) { |
| 1009 | resp.response_length += sizeof(resp.flags); |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1010 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1011 | if (MLX5_CAP_GEN(mdev, cqe_compression_128)) |
| 1012 | resp.flags |= |
| 1013 | MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_COMP; |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1014 | |
| 1015 | if (MLX5_CAP_GEN(mdev, cqe_128_always)) |
| 1016 | resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_PAD; |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1017 | } |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1018 | |
Noa Osherovich | 96dc3fc | 2017-08-17 15:52:28 +0300 | [diff] [blame] | 1019 | if (field_avail(typeof(resp), sw_parsing_caps, |
| 1020 | uhw->outlen)) { |
| 1021 | resp.response_length += sizeof(resp.sw_parsing_caps); |
| 1022 | if (MLX5_CAP_ETH(mdev, swp)) { |
| 1023 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1024 | MLX5_IB_SW_PARSING; |
| 1025 | |
| 1026 | if (MLX5_CAP_ETH(mdev, swp_csum)) |
| 1027 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1028 | MLX5_IB_SW_PARSING_CSUM; |
| 1029 | |
| 1030 | if (MLX5_CAP_ETH(mdev, swp_lso)) |
| 1031 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1032 | MLX5_IB_SW_PARSING_LSO; |
| 1033 | |
| 1034 | if (resp.sw_parsing_caps.sw_parsing_offloads) |
| 1035 | resp.sw_parsing_caps.supported_qpts = |
| 1036 | BIT(IB_QPT_RAW_PACKET); |
| 1037 | } |
| 1038 | } |
| 1039 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1040 | if (field_avail(typeof(resp), striding_rq_caps, uhw->outlen) && |
| 1041 | raw_support) { |
Noa Osherovich | b4f3459 | 2017-10-17 18:01:12 +0300 | [diff] [blame] | 1042 | resp.response_length += sizeof(resp.striding_rq_caps); |
| 1043 | if (MLX5_CAP_GEN(mdev, striding_rq)) { |
| 1044 | resp.striding_rq_caps.min_single_stride_log_num_of_bytes = |
| 1045 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1046 | resp.striding_rq_caps.max_single_stride_log_num_of_bytes = |
| 1047 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1048 | resp.striding_rq_caps.min_single_wqe_log_num_of_strides = |
| 1049 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1050 | resp.striding_rq_caps.max_single_wqe_log_num_of_strides = |
| 1051 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1052 | resp.striding_rq_caps.supported_qpts = |
| 1053 | BIT(IB_QPT_RAW_PACKET); |
| 1054 | } |
| 1055 | } |
| 1056 | |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1057 | if (field_avail(typeof(resp), tunnel_offloads_caps, |
| 1058 | uhw->outlen)) { |
| 1059 | resp.response_length += sizeof(resp.tunnel_offloads_caps); |
| 1060 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan)) |
| 1061 | resp.tunnel_offloads_caps |= |
| 1062 | MLX5_IB_TUNNELED_OFFLOADS_VXLAN; |
| 1063 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_geneve_rx)) |
| 1064 | resp.tunnel_offloads_caps |= |
| 1065 | MLX5_IB_TUNNELED_OFFLOADS_GENEVE; |
| 1066 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_gre)) |
| 1067 | resp.tunnel_offloads_caps |= |
| 1068 | MLX5_IB_TUNNELED_OFFLOADS_GRE; |
Ariel Levkovich | e818e25 | 2018-05-13 14:33:35 +0300 | [diff] [blame] | 1069 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1070 | MLX5_FLEX_PROTO_CW_MPLS_GRE) |
| 1071 | resp.tunnel_offloads_caps |= |
| 1072 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_GRE; |
| 1073 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1074 | MLX5_FLEX_PROTO_CW_MPLS_UDP) |
| 1075 | resp.tunnel_offloads_caps |= |
| 1076 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_UDP; |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1077 | } |
| 1078 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1079 | if (uhw->outlen) { |
| 1080 | err = ib_copy_to_udata(uhw, &resp, resp.response_length); |
| 1081 | |
| 1082 | if (err) |
| 1083 | return err; |
| 1084 | } |
| 1085 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1086 | return 0; |
| 1087 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1088 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1089 | enum mlx5_ib_width { |
| 1090 | MLX5_IB_WIDTH_1X = 1 << 0, |
| 1091 | MLX5_IB_WIDTH_2X = 1 << 1, |
| 1092 | MLX5_IB_WIDTH_4X = 1 << 2, |
| 1093 | MLX5_IB_WIDTH_8X = 1 << 3, |
| 1094 | MLX5_IB_WIDTH_12X = 1 << 4 |
| 1095 | }; |
| 1096 | |
| 1097 | static int translate_active_width(struct ib_device *ibdev, u8 active_width, |
| 1098 | u8 *ib_width) |
| 1099 | { |
| 1100 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1101 | int err = 0; |
| 1102 | |
| 1103 | if (active_width & MLX5_IB_WIDTH_1X) { |
| 1104 | *ib_width = IB_WIDTH_1X; |
| 1105 | } else if (active_width & MLX5_IB_WIDTH_2X) { |
| 1106 | mlx5_ib_dbg(dev, "active_width %d is not supported by IB spec\n", |
| 1107 | (int)active_width); |
| 1108 | err = -EINVAL; |
| 1109 | } else if (active_width & MLX5_IB_WIDTH_4X) { |
| 1110 | *ib_width = IB_WIDTH_4X; |
| 1111 | } else if (active_width & MLX5_IB_WIDTH_8X) { |
| 1112 | *ib_width = IB_WIDTH_8X; |
| 1113 | } else if (active_width & MLX5_IB_WIDTH_12X) { |
| 1114 | *ib_width = IB_WIDTH_12X; |
| 1115 | } else { |
| 1116 | mlx5_ib_dbg(dev, "Invalid active_width %d\n", |
| 1117 | (int)active_width); |
| 1118 | err = -EINVAL; |
| 1119 | } |
| 1120 | |
| 1121 | return err; |
| 1122 | } |
| 1123 | |
| 1124 | static int mlx5_mtu_to_ib_mtu(int mtu) |
| 1125 | { |
| 1126 | switch (mtu) { |
| 1127 | case 256: return 1; |
| 1128 | case 512: return 2; |
| 1129 | case 1024: return 3; |
| 1130 | case 2048: return 4; |
| 1131 | case 4096: return 5; |
| 1132 | default: |
| 1133 | pr_warn("invalid mtu\n"); |
| 1134 | return -1; |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | enum ib_max_vl_num { |
| 1139 | __IB_MAX_VL_0 = 1, |
| 1140 | __IB_MAX_VL_0_1 = 2, |
| 1141 | __IB_MAX_VL_0_3 = 3, |
| 1142 | __IB_MAX_VL_0_7 = 4, |
| 1143 | __IB_MAX_VL_0_14 = 5, |
| 1144 | }; |
| 1145 | |
| 1146 | enum mlx5_vl_hw_cap { |
| 1147 | MLX5_VL_HW_0 = 1, |
| 1148 | MLX5_VL_HW_0_1 = 2, |
| 1149 | MLX5_VL_HW_0_2 = 3, |
| 1150 | MLX5_VL_HW_0_3 = 4, |
| 1151 | MLX5_VL_HW_0_4 = 5, |
| 1152 | MLX5_VL_HW_0_5 = 6, |
| 1153 | MLX5_VL_HW_0_6 = 7, |
| 1154 | MLX5_VL_HW_0_7 = 8, |
| 1155 | MLX5_VL_HW_0_14 = 15 |
| 1156 | }; |
| 1157 | |
| 1158 | static int translate_max_vl_num(struct ib_device *ibdev, u8 vl_hw_cap, |
| 1159 | u8 *max_vl_num) |
| 1160 | { |
| 1161 | switch (vl_hw_cap) { |
| 1162 | case MLX5_VL_HW_0: |
| 1163 | *max_vl_num = __IB_MAX_VL_0; |
| 1164 | break; |
| 1165 | case MLX5_VL_HW_0_1: |
| 1166 | *max_vl_num = __IB_MAX_VL_0_1; |
| 1167 | break; |
| 1168 | case MLX5_VL_HW_0_3: |
| 1169 | *max_vl_num = __IB_MAX_VL_0_3; |
| 1170 | break; |
| 1171 | case MLX5_VL_HW_0_7: |
| 1172 | *max_vl_num = __IB_MAX_VL_0_7; |
| 1173 | break; |
| 1174 | case MLX5_VL_HW_0_14: |
| 1175 | *max_vl_num = __IB_MAX_VL_0_14; |
| 1176 | break; |
| 1177 | |
| 1178 | default: |
| 1179 | return -EINVAL; |
| 1180 | } |
| 1181 | |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port, |
| 1186 | struct ib_port_attr *props) |
| 1187 | { |
| 1188 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1189 | struct mlx5_core_dev *mdev = dev->mdev; |
| 1190 | struct mlx5_hca_vport_context *rep; |
Saeed Mahameed | 046339e | 2016-04-22 00:33:03 +0300 | [diff] [blame] | 1191 | u16 max_mtu; |
| 1192 | u16 oper_mtu; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1193 | int err; |
| 1194 | u8 ib_link_width_oper; |
| 1195 | u8 vl_hw_cap; |
| 1196 | |
| 1197 | rep = kzalloc(sizeof(*rep), GFP_KERNEL); |
| 1198 | if (!rep) { |
| 1199 | err = -ENOMEM; |
| 1200 | goto out; |
| 1201 | } |
| 1202 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1203 | /* props being zeroed by the caller, avoid zeroing it here */ |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1204 | |
| 1205 | err = mlx5_query_hca_vport_context(mdev, 0, port, 0, rep); |
| 1206 | if (err) |
| 1207 | goto out; |
| 1208 | |
| 1209 | props->lid = rep->lid; |
| 1210 | props->lmc = rep->lmc; |
| 1211 | props->sm_lid = rep->sm_lid; |
| 1212 | props->sm_sl = rep->sm_sl; |
| 1213 | props->state = rep->vport_state; |
| 1214 | props->phys_state = rep->port_physical_state; |
| 1215 | props->port_cap_flags = rep->cap_mask1; |
| 1216 | props->gid_tbl_len = mlx5_get_gid_table_len(MLX5_CAP_GEN(mdev, gid_table_size)); |
| 1217 | props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg); |
| 1218 | props->pkey_tbl_len = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, pkey_table_size)); |
| 1219 | props->bad_pkey_cntr = rep->pkey_violation_counter; |
| 1220 | props->qkey_viol_cntr = rep->qkey_violation_counter; |
| 1221 | props->subnet_timeout = rep->subnet_timeout; |
| 1222 | props->init_type_reply = rep->init_type_reply; |
| 1223 | |
| 1224 | err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); |
| 1225 | if (err) |
| 1226 | goto out; |
| 1227 | |
| 1228 | err = translate_active_width(ibdev, ib_link_width_oper, |
| 1229 | &props->active_width); |
| 1230 | if (err) |
| 1231 | goto out; |
Noa Osherovich | d5beb7f | 2016-06-02 10:47:53 +0300 | [diff] [blame] | 1232 | err = mlx5_query_port_ib_proto_oper(mdev, &props->active_speed, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1233 | if (err) |
| 1234 | goto out; |
| 1235 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1236 | mlx5_query_port_max_mtu(mdev, &max_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1237 | |
| 1238 | props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu); |
| 1239 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1240 | mlx5_query_port_oper_mtu(mdev, &oper_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1241 | |
| 1242 | props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu); |
| 1243 | |
| 1244 | err = mlx5_query_port_vl_hw_cap(mdev, &vl_hw_cap, port); |
| 1245 | if (err) |
| 1246 | goto out; |
| 1247 | |
| 1248 | err = translate_max_vl_num(ibdev, vl_hw_cap, |
| 1249 | &props->max_vl_num); |
| 1250 | out: |
| 1251 | kfree(rep); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1252 | return err; |
| 1253 | } |
| 1254 | |
| 1255 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 1256 | struct ib_port_attr *props) |
| 1257 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1258 | unsigned int count; |
| 1259 | int ret; |
| 1260 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1261 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1262 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1263 | ret = mlx5_query_mad_ifc_port(ibdev, port, props); |
| 1264 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1265 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1266 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1267 | ret = mlx5_query_hca_port(ibdev, port, props); |
| 1268 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1269 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1270 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1271 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1272 | break; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1273 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1274 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1275 | ret = -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1276 | } |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1277 | |
| 1278 | if (!ret && props) { |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1279 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1280 | struct mlx5_core_dev *mdev; |
| 1281 | bool put_mdev = true; |
| 1282 | |
| 1283 | mdev = mlx5_ib_get_native_port_mdev(dev, port, NULL); |
| 1284 | if (!mdev) { |
| 1285 | /* If the port isn't affiliated yet query the master. |
| 1286 | * The master and slave will have the same values. |
| 1287 | */ |
| 1288 | mdev = dev->mdev; |
| 1289 | port = 1; |
| 1290 | put_mdev = false; |
| 1291 | } |
| 1292 | count = mlx5_core_reserved_gids_count(mdev); |
| 1293 | if (put_mdev) |
| 1294 | mlx5_ib_put_native_port_mdev(dev, port); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1295 | props->gid_tbl_len -= count; |
| 1296 | } |
| 1297 | return ret; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1298 | } |
| 1299 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 1300 | static int mlx5_ib_rep_query_port(struct ib_device *ibdev, u8 port, |
| 1301 | struct ib_port_attr *props) |
| 1302 | { |
| 1303 | int ret; |
| 1304 | |
| 1305 | /* Only link layer == ethernet is valid for representors */ |
| 1306 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1307 | if (ret || !props) |
| 1308 | return ret; |
| 1309 | |
| 1310 | /* We don't support GIDS */ |
| 1311 | props->gid_tbl_len = 0; |
| 1312 | |
| 1313 | return ret; |
| 1314 | } |
| 1315 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1316 | static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 1317 | union ib_gid *gid) |
| 1318 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1319 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1320 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1321 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1322 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1323 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1324 | return mlx5_query_mad_ifc_gids(ibdev, port, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1325 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1326 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1327 | return mlx5_query_hca_vport_gid(mdev, 0, port, 0, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1328 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1329 | default: |
| 1330 | return -EINVAL; |
| 1331 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1332 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1333 | } |
| 1334 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1335 | static int mlx5_query_hca_nic_pkey(struct ib_device *ibdev, u8 port, |
| 1336 | u16 index, u16 *pkey) |
| 1337 | { |
| 1338 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1339 | struct mlx5_core_dev *mdev; |
| 1340 | bool put_mdev = true; |
| 1341 | u8 mdev_port_num; |
| 1342 | int err; |
| 1343 | |
| 1344 | mdev = mlx5_ib_get_native_port_mdev(dev, port, &mdev_port_num); |
| 1345 | if (!mdev) { |
| 1346 | /* The port isn't affiliated yet, get the PKey from the master |
| 1347 | * port. For RoCE the PKey tables will be the same. |
| 1348 | */ |
| 1349 | put_mdev = false; |
| 1350 | mdev = dev->mdev; |
| 1351 | mdev_port_num = 1; |
| 1352 | } |
| 1353 | |
| 1354 | err = mlx5_query_hca_vport_pkey(mdev, 0, mdev_port_num, 0, |
| 1355 | index, pkey); |
| 1356 | if (put_mdev) |
| 1357 | mlx5_ib_put_native_port_mdev(dev, port); |
| 1358 | |
| 1359 | return err; |
| 1360 | } |
| 1361 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1362 | static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 1363 | u16 *pkey) |
| 1364 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1365 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1366 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1367 | return mlx5_query_mad_ifc_pkey(ibdev, port, index, pkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1368 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1369 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1370 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1371 | return mlx5_query_hca_nic_pkey(ibdev, port, index, pkey); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1372 | default: |
| 1373 | return -EINVAL; |
| 1374 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1375 | } |
| 1376 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1377 | static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask, |
| 1378 | struct ib_device_modify *props) |
| 1379 | { |
| 1380 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1381 | struct mlx5_reg_node_desc in; |
| 1382 | struct mlx5_reg_node_desc out; |
| 1383 | int err; |
| 1384 | |
| 1385 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 1386 | return -EOPNOTSUPP; |
| 1387 | |
| 1388 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 1389 | return 0; |
| 1390 | |
| 1391 | /* |
| 1392 | * If possible, pass node desc to FW, so it can generate |
| 1393 | * a 144 trap. If cmd fails, just ignore. |
| 1394 | */ |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1395 | memcpy(&in, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1396 | err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1397 | sizeof(out), MLX5_REG_NODE_DESC, 0, 1); |
| 1398 | if (err) |
| 1399 | return err; |
| 1400 | |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1401 | memcpy(ibdev->node_desc, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1402 | |
| 1403 | return err; |
| 1404 | } |
| 1405 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1406 | static int set_port_caps_atomic(struct mlx5_ib_dev *dev, u8 port_num, u32 mask, |
| 1407 | u32 value) |
| 1408 | { |
| 1409 | struct mlx5_hca_vport_context ctx = {}; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1410 | struct mlx5_core_dev *mdev; |
| 1411 | u8 mdev_port_num; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1412 | int err; |
| 1413 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1414 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 1415 | if (!mdev) |
| 1416 | return -ENODEV; |
| 1417 | |
| 1418 | 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] | 1419 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1420 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1421 | |
| 1422 | if (~ctx.cap_mask1_perm & mask) { |
| 1423 | mlx5_ib_warn(dev, "trying to change bitmask 0x%X but change supported 0x%X\n", |
| 1424 | mask, ctx.cap_mask1_perm); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1425 | err = -EINVAL; |
| 1426 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | ctx.cap_mask1 = value; |
| 1430 | ctx.cap_mask1_perm = mask; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1431 | err = mlx5_core_modify_hca_vport_context(mdev, 0, mdev_port_num, |
| 1432 | 0, &ctx); |
| 1433 | |
| 1434 | out: |
| 1435 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1436 | |
| 1437 | return err; |
| 1438 | } |
| 1439 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1440 | static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 1441 | struct ib_port_modify *props) |
| 1442 | { |
| 1443 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1444 | struct ib_port_attr attr; |
| 1445 | u32 tmp; |
| 1446 | int err; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1447 | u32 change_mask; |
| 1448 | u32 value; |
| 1449 | bool is_ib = (mlx5_ib_port_link_layer(ibdev, port) == |
| 1450 | IB_LINK_LAYER_INFINIBAND); |
| 1451 | |
Majd Dibbiny | ec25587 | 2017-08-23 08:35:42 +0300 | [diff] [blame] | 1452 | /* CM layer calls ib_modify_port() regardless of the link layer. For |
| 1453 | * Ethernet ports, qkey violation and Port capabilities are meaningless. |
| 1454 | */ |
| 1455 | if (!is_ib) |
| 1456 | return 0; |
| 1457 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1458 | if (MLX5_CAP_GEN(dev->mdev, ib_virt) && is_ib) { |
| 1459 | change_mask = props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1460 | value = ~props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1461 | return set_port_caps_atomic(dev, port, change_mask, value); |
| 1462 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1463 | |
| 1464 | mutex_lock(&dev->cap_mask_mutex); |
| 1465 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1466 | err = ib_query_port(ibdev, port, &attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1467 | if (err) |
| 1468 | goto out; |
| 1469 | |
| 1470 | tmp = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 1471 | ~props->clr_port_cap_mask; |
| 1472 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1473 | err = mlx5_set_port_caps(dev->mdev, port, tmp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1474 | |
| 1475 | out: |
| 1476 | mutex_unlock(&dev->cap_mask_mutex); |
| 1477 | return err; |
| 1478 | } |
| 1479 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1480 | static void print_lib_caps(struct mlx5_ib_dev *dev, u64 caps) |
| 1481 | { |
| 1482 | mlx5_ib_dbg(dev, "MLX5_LIB_CAP_4K_UAR = %s\n", |
| 1483 | caps & MLX5_LIB_CAP_4K_UAR ? "y" : "n"); |
| 1484 | } |
| 1485 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1486 | static u16 calc_dynamic_bfregs(int uars_per_sys_page) |
| 1487 | { |
| 1488 | /* Large page with non 4k uar support might limit the dynamic size */ |
| 1489 | if (uars_per_sys_page == 1 && PAGE_SIZE > 4096) |
| 1490 | return MLX5_MIN_DYN_BFREGS; |
| 1491 | |
| 1492 | return MLX5_MAX_DYN_BFREGS; |
| 1493 | } |
| 1494 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1495 | static int calc_total_bfregs(struct mlx5_ib_dev *dev, bool lib_uar_4k, |
| 1496 | struct mlx5_ib_alloc_ucontext_req_v2 *req, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1497 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1498 | { |
| 1499 | int uars_per_sys_page; |
| 1500 | int bfregs_per_sys_page; |
| 1501 | int ref_bfregs = req->total_num_bfregs; |
| 1502 | |
| 1503 | if (req->total_num_bfregs == 0) |
| 1504 | return -EINVAL; |
| 1505 | |
| 1506 | BUILD_BUG_ON(MLX5_MAX_BFREGS % MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1507 | BUILD_BUG_ON(MLX5_MAX_BFREGS < MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1508 | |
| 1509 | if (req->total_num_bfregs > MLX5_MAX_BFREGS) |
| 1510 | return -ENOMEM; |
| 1511 | |
| 1512 | uars_per_sys_page = get_uars_per_sys_page(dev, lib_uar_4k); |
| 1513 | 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] | 1514 | /* This holds the required static allocation asked by the user */ |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1515 | 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] | 1516 | if (req->num_low_latency_bfregs > req->total_num_bfregs - 1) |
| 1517 | return -EINVAL; |
| 1518 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1519 | bfregi->num_static_sys_pages = req->total_num_bfregs / bfregs_per_sys_page; |
| 1520 | bfregi->num_dyn_bfregs = ALIGN(calc_dynamic_bfregs(uars_per_sys_page), bfregs_per_sys_page); |
| 1521 | bfregi->total_num_bfregs = req->total_num_bfregs + bfregi->num_dyn_bfregs; |
| 1522 | bfregi->num_sys_pages = bfregi->total_num_bfregs / bfregs_per_sys_page; |
| 1523 | |
| 1524 | 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] | 1525 | MLX5_CAP_GEN(dev->mdev, uar_4k) ? "yes" : "no", |
| 1526 | lib_uar_4k ? "yes" : "no", ref_bfregs, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1527 | req->total_num_bfregs, bfregi->total_num_bfregs, |
| 1528 | bfregi->num_sys_pages); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1529 | |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | static int allocate_uars(struct mlx5_ib_dev *dev, struct mlx5_ib_ucontext *context) |
| 1534 | { |
| 1535 | struct mlx5_bfreg_info *bfregi; |
| 1536 | int err; |
| 1537 | int i; |
| 1538 | |
| 1539 | bfregi = &context->bfregi; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1540 | for (i = 0; i < bfregi->num_static_sys_pages; i++) { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1541 | err = mlx5_cmd_alloc_uar(dev->mdev, &bfregi->sys_pages[i]); |
| 1542 | if (err) |
| 1543 | goto error; |
| 1544 | |
| 1545 | mlx5_ib_dbg(dev, "allocated uar %d\n", bfregi->sys_pages[i]); |
| 1546 | } |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1547 | |
| 1548 | for (i = bfregi->num_static_sys_pages; i < bfregi->num_sys_pages; i++) |
| 1549 | bfregi->sys_pages[i] = MLX5_IB_INVALID_UAR_INDEX; |
| 1550 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1551 | return 0; |
| 1552 | |
| 1553 | error: |
| 1554 | for (--i; i >= 0; i--) |
| 1555 | if (mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i])) |
| 1556 | mlx5_ib_warn(dev, "failed to free uar %d\n", i); |
| 1557 | |
| 1558 | return err; |
| 1559 | } |
| 1560 | |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1561 | static void deallocate_uars(struct mlx5_ib_dev *dev, |
| 1562 | struct mlx5_ib_ucontext *context) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1563 | { |
| 1564 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1565 | int i; |
| 1566 | |
| 1567 | bfregi = &context->bfregi; |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1568 | for (i = 0; i < bfregi->num_sys_pages; i++) |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1569 | if (i < bfregi->num_static_sys_pages || |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1570 | bfregi->sys_pages[i] != MLX5_IB_INVALID_UAR_INDEX) |
| 1571 | mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i]); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1572 | } |
| 1573 | |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1574 | static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn) |
| 1575 | { |
| 1576 | int err; |
| 1577 | |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1578 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1579 | return 0; |
| 1580 | |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1581 | err = mlx5_core_alloc_transport_domain(dev->mdev, tdn); |
| 1582 | if (err) |
| 1583 | return err; |
| 1584 | |
| 1585 | 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] | 1586 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1587 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1588 | return err; |
| 1589 | |
| 1590 | mutex_lock(&dev->lb_mutex); |
| 1591 | dev->user_td++; |
| 1592 | |
| 1593 | if (dev->user_td == 2) |
| 1594 | err = mlx5_nic_vport_update_local_lb(dev->mdev, true); |
| 1595 | |
| 1596 | mutex_unlock(&dev->lb_mutex); |
| 1597 | return err; |
| 1598 | } |
| 1599 | |
| 1600 | static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn) |
| 1601 | { |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1602 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1603 | return; |
| 1604 | |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1605 | mlx5_core_dealloc_transport_domain(dev->mdev, tdn); |
| 1606 | |
| 1607 | 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] | 1608 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1609 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1610 | return; |
| 1611 | |
| 1612 | mutex_lock(&dev->lb_mutex); |
| 1613 | dev->user_td--; |
| 1614 | |
| 1615 | if (dev->user_td < 2) |
| 1616 | mlx5_nic_vport_update_local_lb(dev->mdev, false); |
| 1617 | |
| 1618 | mutex_unlock(&dev->lb_mutex); |
| 1619 | } |
| 1620 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1621 | static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev, |
| 1622 | struct ib_udata *udata) |
| 1623 | { |
| 1624 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1625 | struct mlx5_ib_alloc_ucontext_req_v2 req = {}; |
| 1626 | struct mlx5_ib_alloc_ucontext_resp resp = {}; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1627 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1628 | struct mlx5_ib_ucontext *context; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1629 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1630 | int ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1631 | int err; |
Majd Dibbiny | a168a41c | 2016-01-28 17:51:47 +0200 | [diff] [blame] | 1632 | size_t min_req_v2 = offsetof(struct mlx5_ib_alloc_ucontext_req_v2, |
| 1633 | max_cqe_version); |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1634 | u32 dump_fill_mkey; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1635 | bool lib_uar_4k; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1636 | |
| 1637 | if (!dev->ib_active) |
| 1638 | return ERR_PTR(-EAGAIN); |
| 1639 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1640 | if (udata->inlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1641 | ver = 0; |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1642 | else if (udata->inlen >= min_req_v2) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1643 | ver = 2; |
| 1644 | else |
| 1645 | return ERR_PTR(-EINVAL); |
| 1646 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1647 | err = ib_copy_from_udata(&req, udata, min(udata->inlen, sizeof(req))); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1648 | if (err) |
| 1649 | return ERR_PTR(err); |
| 1650 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1651 | if (req.flags & ~MLX5_IB_ALLOC_UCTX_DEVX) |
| 1652 | return ERR_PTR(-EOPNOTSUPP); |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1653 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1654 | if (req.comp_mask || req.reserved0 || req.reserved1 || req.reserved2) |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1655 | return ERR_PTR(-EOPNOTSUPP); |
| 1656 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1657 | req.total_num_bfregs = ALIGN(req.total_num_bfregs, |
| 1658 | MLX5_NON_FP_BFREGS_PER_UAR); |
| 1659 | if (req.num_low_latency_bfregs > req.total_num_bfregs - 1) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1660 | return ERR_PTR(-EINVAL); |
| 1661 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1662 | 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] | 1663 | if (mlx5_core_is_pf(dev->mdev) && MLX5_CAP_GEN(dev->mdev, bf)) |
| 1664 | 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] | 1665 | resp.cache_line_size = cache_line_size(); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1666 | resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); |
| 1667 | resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); |
| 1668 | resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1669 | resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1670 | 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] | 1671 | resp.cqe_version = min_t(__u8, |
| 1672 | (__u8)MLX5_CAP_GEN(dev->mdev, cqe_version), |
| 1673 | req.max_cqe_version); |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1674 | resp.log_uar_size = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1675 | MLX5_ADAPTER_PAGE_SHIFT : PAGE_SHIFT; |
| 1676 | resp.num_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1677 | MLX5_CAP_GEN(dev->mdev, num_of_uars_per_page) : 1; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1678 | resp.response_length = min(offsetof(typeof(resp), response_length) + |
| 1679 | sizeof(resp.response_length), udata->outlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1680 | |
Matan Barak | c03faa5 | 2018-03-28 09:27:54 +0300 | [diff] [blame] | 1681 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_DEVICE) { |
| 1682 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_EGRESS)) |
| 1683 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM; |
| 1684 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_REQUIRED_METADATA) |
| 1685 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_REQ_METADATA; |
| 1686 | if (MLX5_CAP_FLOWTABLE(dev->mdev, flow_table_properties_nic_receive.ft_field_support.outer_esp_spi)) |
| 1687 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_SPI_STEERING; |
| 1688 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_TX_IV_IS_ESN) |
| 1689 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_TX_IV_IS_ESN; |
| 1690 | /* MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_FULL_OFFLOAD is currently always 0 */ |
| 1691 | } |
| 1692 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1693 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 1694 | if (!context) |
| 1695 | return ERR_PTR(-ENOMEM); |
| 1696 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1697 | lib_uar_4k = req.lib_caps & MLX5_LIB_CAP_4K_UAR; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1698 | bfregi = &context->bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1699 | |
| 1700 | /* updates req->total_num_bfregs */ |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1701 | err = calc_total_bfregs(dev, lib_uar_4k, &req, bfregi); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1702 | if (err) |
| 1703 | goto out_ctx; |
| 1704 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1705 | mutex_init(&bfregi->lock); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1706 | bfregi->lib_uar_4k = lib_uar_4k; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1707 | bfregi->count = kcalloc(bfregi->total_num_bfregs, sizeof(*bfregi->count), |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1708 | GFP_KERNEL); |
| 1709 | if (!bfregi->count) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1710 | err = -ENOMEM; |
| 1711 | goto out_ctx; |
| 1712 | } |
| 1713 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1714 | bfregi->sys_pages = kcalloc(bfregi->num_sys_pages, |
| 1715 | sizeof(*bfregi->sys_pages), |
| 1716 | GFP_KERNEL); |
| 1717 | if (!bfregi->sys_pages) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1718 | err = -ENOMEM; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1719 | goto out_count; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1720 | } |
| 1721 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1722 | err = allocate_uars(dev, context); |
| 1723 | if (err) |
| 1724 | goto out_sys_pages; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1725 | |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 1726 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 1727 | context->ibucontext.invalidate_range = &mlx5_ib_invalidate_range; |
| 1728 | #endif |
| 1729 | |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1730 | err = mlx5_ib_alloc_transport_domain(dev, &context->tdn); |
| 1731 | if (err) |
| 1732 | goto out_uars; |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1733 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1734 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) { |
| 1735 | /* Block DEVX on Infiniband as of SELinux */ |
| 1736 | if (mlx5_ib_port_link_layer(ibdev, 1) != IB_LINK_LAYER_ETHERNET) { |
| 1737 | err = -EPERM; |
| 1738 | goto out_td; |
| 1739 | } |
| 1740 | |
| 1741 | err = mlx5_ib_devx_create(dev, context); |
| 1742 | if (err) |
| 1743 | goto out_td; |
| 1744 | } |
| 1745 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1746 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1747 | err = mlx5_cmd_dump_fill_mkey(dev->mdev, &dump_fill_mkey); |
| 1748 | if (err) |
Jason Gunthorpe | 8193abb | 2018-07-04 13:19:46 -0600 | [diff] [blame] | 1749 | goto out_mdev; |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1750 | } |
| 1751 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1752 | INIT_LIST_HEAD(&context->vma_private_list); |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1753 | mutex_init(&context->vma_private_list_mutex); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1754 | INIT_LIST_HEAD(&context->db_page_list); |
| 1755 | mutex_init(&context->db_page_mutex); |
| 1756 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1757 | resp.tot_bfregs = req.total_num_bfregs; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 1758 | resp.num_ports = dev->num_ports; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1759 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1760 | if (field_avail(typeof(resp), cqe_version, udata->outlen)) |
| 1761 | resp.response_length += sizeof(resp.cqe_version); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1762 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1763 | if (field_avail(typeof(resp), cmds_supp_uhw, udata->outlen)) { |
Moni Shoua | 6ad279c5 | 2016-11-23 08:23:23 +0200 | [diff] [blame] | 1764 | resp.cmds_supp_uhw |= MLX5_USER_CMDS_SUPP_UHW_QUERY_DEVICE | |
| 1765 | MLX5_USER_CMDS_SUPP_UHW_CREATE_AH; |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1766 | resp.response_length += sizeof(resp.cmds_supp_uhw); |
| 1767 | } |
| 1768 | |
Or Gerlitz | 7898489 | 2016-11-30 20:33:33 +0200 | [diff] [blame] | 1769 | if (field_avail(typeof(resp), eth_min_inline, udata->outlen)) { |
| 1770 | if (mlx5_ib_port_link_layer(ibdev, 1) == IB_LINK_LAYER_ETHERNET) { |
| 1771 | mlx5_query_min_inline(dev->mdev, &resp.eth_min_inline); |
| 1772 | resp.eth_min_inline++; |
| 1773 | } |
| 1774 | resp.response_length += sizeof(resp.eth_min_inline); |
| 1775 | } |
| 1776 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1777 | if (field_avail(typeof(resp), clock_info_versions, udata->outlen)) { |
| 1778 | if (mdev->clock_info) |
| 1779 | resp.clock_info_versions = BIT(MLX5_IB_CLOCK_INFO_V1); |
| 1780 | resp.response_length += sizeof(resp.clock_info_versions); |
| 1781 | } |
| 1782 | |
Noa Osherovich | bc5c6ee | 2016-06-04 15:15:31 +0300 | [diff] [blame] | 1783 | /* |
| 1784 | * We don't want to expose information from the PCI bar that is located |
| 1785 | * after 4096 bytes, so if the arch only supports larger pages, let's |
| 1786 | * pretend we don't support reading the HCA's core clock. This is also |
| 1787 | * forced by mmap function. |
| 1788 | */ |
Eli Cohen | de8d6e0 | 2017-01-03 23:55:19 +0200 | [diff] [blame] | 1789 | if (field_avail(typeof(resp), hca_core_clock_offset, udata->outlen)) { |
| 1790 | if (PAGE_SIZE <= 4096) { |
| 1791 | resp.comp_mask |= |
| 1792 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET; |
| 1793 | resp.hca_core_clock_offset = |
| 1794 | offsetof(struct mlx5_init_seg, internal_timer_h) % PAGE_SIZE; |
| 1795 | } |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1796 | resp.response_length += sizeof(resp.hca_core_clock_offset); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1797 | } |
| 1798 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1799 | if (field_avail(typeof(resp), log_uar_size, udata->outlen)) |
| 1800 | resp.response_length += sizeof(resp.log_uar_size); |
| 1801 | |
| 1802 | if (field_avail(typeof(resp), num_uars_per_page, udata->outlen)) |
| 1803 | resp.response_length += sizeof(resp.num_uars_per_page); |
| 1804 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1805 | if (field_avail(typeof(resp), num_dyn_bfregs, udata->outlen)) { |
| 1806 | resp.num_dyn_bfregs = bfregi->num_dyn_bfregs; |
| 1807 | resp.response_length += sizeof(resp.num_dyn_bfregs); |
| 1808 | } |
| 1809 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1810 | if (field_avail(typeof(resp), dump_fill_mkey, udata->outlen)) { |
| 1811 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1812 | resp.dump_fill_mkey = dump_fill_mkey; |
| 1813 | resp.comp_mask |= |
| 1814 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_DUMP_FILL_MKEY; |
| 1815 | } |
| 1816 | resp.response_length += sizeof(resp.dump_fill_mkey); |
| 1817 | } |
| 1818 | |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1819 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1820 | if (err) |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1821 | goto out_mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1822 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1823 | bfregi->ver = ver; |
| 1824 | bfregi->num_low_latency_bfregs = req.num_low_latency_bfregs; |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1825 | context->cqe_version = resp.cqe_version; |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1826 | context->lib_caps = req.lib_caps; |
| 1827 | print_lib_caps(dev, context->lib_caps); |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1828 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1829 | return &context->ibucontext; |
| 1830 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1831 | out_mdev: |
| 1832 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) |
| 1833 | mlx5_ib_devx_destroy(dev, context); |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1834 | out_td: |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1835 | mlx5_ib_dealloc_transport_domain(dev, context->tdn); |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1836 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1837 | out_uars: |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1838 | deallocate_uars(dev, context); |
| 1839 | |
| 1840 | out_sys_pages: |
| 1841 | kfree(bfregi->sys_pages); |
| 1842 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1843 | out_count: |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1844 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1845 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1846 | out_ctx: |
| 1847 | kfree(context); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1848 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1849 | return ERR_PTR(err); |
| 1850 | } |
| 1851 | |
| 1852 | static int mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
| 1853 | { |
| 1854 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 1855 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1856 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1857 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1858 | if (context->devx_uid) |
| 1859 | mlx5_ib_devx_destroy(dev, context); |
| 1860 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1861 | bfregi = &context->bfregi; |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1862 | mlx5_ib_dealloc_transport_domain(dev, context->tdn); |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1863 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1864 | deallocate_uars(dev, context); |
| 1865 | kfree(bfregi->sys_pages); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1866 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1867 | kfree(context); |
| 1868 | |
| 1869 | return 0; |
| 1870 | } |
| 1871 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1872 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1873 | int uar_idx) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1874 | { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1875 | int fw_uars_per_page; |
| 1876 | |
| 1877 | fw_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? MLX5_UARS_IN_PAGE : 1; |
| 1878 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1879 | 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] | 1880 | } |
| 1881 | |
| 1882 | static int get_command(unsigned long offset) |
| 1883 | { |
| 1884 | return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK; |
| 1885 | } |
| 1886 | |
| 1887 | static int get_arg(unsigned long offset) |
| 1888 | { |
| 1889 | return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1); |
| 1890 | } |
| 1891 | |
| 1892 | static int get_index(unsigned long offset) |
| 1893 | { |
| 1894 | return get_arg(offset); |
| 1895 | } |
| 1896 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1897 | /* Index resides in an extra byte to enable larger values than 255 */ |
| 1898 | static int get_extended_index(unsigned long offset) |
| 1899 | { |
| 1900 | return get_arg(offset) | ((offset >> 16) & 0xff) << 8; |
| 1901 | } |
| 1902 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1903 | static void mlx5_ib_vma_open(struct vm_area_struct *area) |
| 1904 | { |
| 1905 | /* vma_open is called when a new VMA is created on top of our VMA. This |
| 1906 | * is done through either mremap flow or split_vma (usually due to |
| 1907 | * mlock, madvise, munmap, etc.) We do not support a clone of the VMA, |
| 1908 | * as this VMA is strongly hardware related. Therefore we set the |
| 1909 | * vm_ops of the newly created/cloned VMA to NULL, to prevent it from |
| 1910 | * calling us again and trying to do incorrect actions. We assume that |
| 1911 | * the original VMA size is exactly a single page, and therefore all |
| 1912 | * "splitting" operation will not happen to it. |
| 1913 | */ |
| 1914 | area->vm_ops = NULL; |
| 1915 | } |
| 1916 | |
| 1917 | static void mlx5_ib_vma_close(struct vm_area_struct *area) |
| 1918 | { |
| 1919 | struct mlx5_ib_vma_private_data *mlx5_ib_vma_priv_data; |
| 1920 | |
| 1921 | /* It's guaranteed that all VMAs opened on a FD are closed before the |
| 1922 | * file itself is closed, therefore no sync is needed with the regular |
| 1923 | * closing flow. (e.g. mlx5 ib_dealloc_ucontext) |
| 1924 | * However need a sync with accessing the vma as part of |
| 1925 | * mlx5_ib_disassociate_ucontext. |
| 1926 | * The close operation is usually called under mm->mmap_sem except when |
| 1927 | * process is exiting. |
| 1928 | * The exiting case is handled explicitly as part of |
| 1929 | * mlx5_ib_disassociate_ucontext. |
| 1930 | */ |
| 1931 | mlx5_ib_vma_priv_data = (struct mlx5_ib_vma_private_data *)area->vm_private_data; |
| 1932 | |
| 1933 | /* setting the vma context pointer to null in the mlx5_ib driver's |
| 1934 | * private data, to protect a race condition in |
| 1935 | * mlx5_ib_disassociate_ucontext(). |
| 1936 | */ |
| 1937 | mlx5_ib_vma_priv_data->vma = NULL; |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1938 | mutex_lock(mlx5_ib_vma_priv_data->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1939 | list_del(&mlx5_ib_vma_priv_data->list); |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1940 | mutex_unlock(mlx5_ib_vma_priv_data->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1941 | kfree(mlx5_ib_vma_priv_data); |
| 1942 | } |
| 1943 | |
| 1944 | static const struct vm_operations_struct mlx5_ib_vm_ops = { |
| 1945 | .open = mlx5_ib_vma_open, |
| 1946 | .close = mlx5_ib_vma_close |
| 1947 | }; |
| 1948 | |
| 1949 | static int mlx5_ib_set_vma_data(struct vm_area_struct *vma, |
| 1950 | struct mlx5_ib_ucontext *ctx) |
| 1951 | { |
| 1952 | struct mlx5_ib_vma_private_data *vma_prv; |
| 1953 | struct list_head *vma_head = &ctx->vma_private_list; |
| 1954 | |
| 1955 | vma_prv = kzalloc(sizeof(*vma_prv), GFP_KERNEL); |
| 1956 | if (!vma_prv) |
| 1957 | return -ENOMEM; |
| 1958 | |
| 1959 | vma_prv->vma = vma; |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1960 | vma_prv->vma_private_list_mutex = &ctx->vma_private_list_mutex; |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1961 | vma->vm_private_data = vma_prv; |
| 1962 | vma->vm_ops = &mlx5_ib_vm_ops; |
| 1963 | |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1964 | mutex_lock(&ctx->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1965 | list_add(&vma_prv->list, vma_head); |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1966 | mutex_unlock(&ctx->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1967 | |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
| 1971 | static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) |
| 1972 | { |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1973 | struct vm_area_struct *vma; |
| 1974 | struct mlx5_ib_vma_private_data *vma_private, *n; |
| 1975 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1976 | |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1977 | mutex_lock(&context->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1978 | list_for_each_entry_safe(vma_private, n, &context->vma_private_list, |
| 1979 | list) { |
| 1980 | vma = vma_private->vma; |
Leon Romanovsky | 2cb4079 | 2018-05-29 15:14:05 +0300 | [diff] [blame] | 1981 | zap_vma_ptes(vma, vma->vm_start, PAGE_SIZE); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1982 | /* context going to be destroyed, should |
| 1983 | * not access ops any more. |
| 1984 | */ |
Maor Gottlieb | 1377661 | 2017-03-29 06:03:03 +0300 | [diff] [blame] | 1985 | vma->vm_flags &= ~(VM_SHARED | VM_MAYSHARE); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1986 | vma->vm_ops = NULL; |
| 1987 | list_del(&vma_private->list); |
| 1988 | kfree(vma_private); |
| 1989 | } |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1990 | mutex_unlock(&context->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1991 | } |
| 1992 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 1993 | static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd) |
| 1994 | { |
| 1995 | switch (cmd) { |
| 1996 | case MLX5_IB_MMAP_WC_PAGE: |
| 1997 | return "WC"; |
| 1998 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 1999 | return "best effort WC"; |
| 2000 | case MLX5_IB_MMAP_NC_PAGE: |
| 2001 | return "NC"; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2002 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2003 | return "Device Memory"; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2004 | default: |
| 2005 | return NULL; |
| 2006 | } |
| 2007 | } |
| 2008 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2009 | static int mlx5_ib_mmap_clock_info_page(struct mlx5_ib_dev *dev, |
| 2010 | struct vm_area_struct *vma, |
| 2011 | struct mlx5_ib_ucontext *context) |
| 2012 | { |
| 2013 | phys_addr_t pfn; |
| 2014 | int err; |
| 2015 | |
| 2016 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2017 | return -EINVAL; |
| 2018 | |
| 2019 | if (get_index(vma->vm_pgoff) != MLX5_IB_CLOCK_INFO_V1) |
| 2020 | return -EOPNOTSUPP; |
| 2021 | |
| 2022 | if (vma->vm_flags & VM_WRITE) |
| 2023 | return -EPERM; |
| 2024 | |
| 2025 | if (!dev->mdev->clock_info_page) |
| 2026 | return -EOPNOTSUPP; |
| 2027 | |
| 2028 | pfn = page_to_pfn(dev->mdev->clock_info_page); |
| 2029 | err = remap_pfn_range(vma, vma->vm_start, pfn, PAGE_SIZE, |
| 2030 | vma->vm_page_prot); |
| 2031 | if (err) |
| 2032 | return err; |
| 2033 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2034 | return mlx5_ib_set_vma_data(vma, context); |
| 2035 | } |
| 2036 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2037 | 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] | 2038 | struct vm_area_struct *vma, |
| 2039 | struct mlx5_ib_ucontext *context) |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2040 | { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2041 | struct mlx5_bfreg_info *bfregi = &context->bfregi; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2042 | int err; |
| 2043 | unsigned long idx; |
Kamal Heib | aa09ea6 | 2018-07-19 00:05:32 +0300 | [diff] [blame] | 2044 | phys_addr_t pfn; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2045 | pgprot_t prot; |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2046 | u32 bfreg_dyn_idx = 0; |
| 2047 | u32 uar_index; |
| 2048 | int dyn_uar = (cmd == MLX5_IB_MMAP_ALLOC_WC); |
| 2049 | int max_valid_idx = dyn_uar ? bfregi->num_sys_pages : |
| 2050 | bfregi->num_static_sys_pages; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2051 | |
| 2052 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2053 | return -EINVAL; |
| 2054 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2055 | if (dyn_uar) |
| 2056 | idx = get_extended_index(vma->vm_pgoff) + bfregi->num_static_sys_pages; |
| 2057 | else |
| 2058 | idx = get_index(vma->vm_pgoff); |
| 2059 | |
| 2060 | if (idx >= max_valid_idx) { |
| 2061 | mlx5_ib_warn(dev, "invalid uar index %lu, max=%d\n", |
| 2062 | idx, max_valid_idx); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2063 | return -EINVAL; |
| 2064 | } |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2065 | |
| 2066 | switch (cmd) { |
| 2067 | case MLX5_IB_MMAP_WC_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2068 | case MLX5_IB_MMAP_ALLOC_WC: |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2069 | /* Some architectures don't support WC memory */ |
| 2070 | #if defined(CONFIG_X86) |
| 2071 | if (!pat_enabled()) |
| 2072 | return -EPERM; |
| 2073 | #elif !(defined(CONFIG_PPC) || (defined(CONFIG_ARM) && defined(CONFIG_MMU))) |
| 2074 | return -EPERM; |
| 2075 | #endif |
| 2076 | /* fall through */ |
| 2077 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2078 | /* For MLX5_IB_MMAP_REGULAR_PAGE do the best effort to get WC */ |
| 2079 | prot = pgprot_writecombine(vma->vm_page_prot); |
| 2080 | break; |
| 2081 | case MLX5_IB_MMAP_NC_PAGE: |
| 2082 | prot = pgprot_noncached(vma->vm_page_prot); |
| 2083 | break; |
| 2084 | default: |
| 2085 | return -EINVAL; |
| 2086 | } |
| 2087 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2088 | if (dyn_uar) { |
| 2089 | int uars_per_page; |
| 2090 | |
| 2091 | uars_per_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k); |
| 2092 | bfreg_dyn_idx = idx * (uars_per_page * MLX5_NON_FP_BFREGS_PER_UAR); |
| 2093 | if (bfreg_dyn_idx >= bfregi->total_num_bfregs) { |
| 2094 | mlx5_ib_warn(dev, "invalid bfreg_dyn_idx %u, max=%u\n", |
| 2095 | bfreg_dyn_idx, bfregi->total_num_bfregs); |
| 2096 | return -EINVAL; |
| 2097 | } |
| 2098 | |
| 2099 | mutex_lock(&bfregi->lock); |
| 2100 | /* Fail if uar already allocated, first bfreg index of each |
| 2101 | * page holds its count. |
| 2102 | */ |
| 2103 | if (bfregi->count[bfreg_dyn_idx]) { |
| 2104 | mlx5_ib_warn(dev, "wrong offset, idx %lu is busy, bfregn=%u\n", idx, bfreg_dyn_idx); |
| 2105 | mutex_unlock(&bfregi->lock); |
| 2106 | return -EINVAL; |
| 2107 | } |
| 2108 | |
| 2109 | bfregi->count[bfreg_dyn_idx]++; |
| 2110 | mutex_unlock(&bfregi->lock); |
| 2111 | |
| 2112 | err = mlx5_cmd_alloc_uar(dev->mdev, &uar_index); |
| 2113 | if (err) { |
| 2114 | mlx5_ib_warn(dev, "UAR alloc failed\n"); |
| 2115 | goto free_bfreg; |
| 2116 | } |
| 2117 | } else { |
| 2118 | uar_index = bfregi->sys_pages[idx]; |
| 2119 | } |
| 2120 | |
| 2121 | pfn = uar_index2pfn(dev, uar_index); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2122 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn %pa\n", idx, &pfn); |
| 2123 | |
| 2124 | vma->vm_page_prot = prot; |
| 2125 | err = io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 2126 | PAGE_SIZE, vma->vm_page_prot); |
| 2127 | if (err) { |
Leon Romanovsky | 8f06228 | 2018-05-22 08:31:03 +0300 | [diff] [blame] | 2128 | mlx5_ib_err(dev, |
| 2129 | "io_remap_pfn_range failed with error=%d, mmap_cmd=%s\n", |
| 2130 | err, mmap_cmd2str(cmd)); |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2131 | err = -EAGAIN; |
| 2132 | goto err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2133 | } |
| 2134 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2135 | err = mlx5_ib_set_vma_data(vma, context); |
| 2136 | if (err) |
| 2137 | goto err; |
| 2138 | |
| 2139 | if (dyn_uar) |
| 2140 | bfregi->sys_pages[idx] = uar_index; |
| 2141 | return 0; |
| 2142 | |
| 2143 | err: |
| 2144 | if (!dyn_uar) |
| 2145 | return err; |
| 2146 | |
| 2147 | mlx5_cmd_free_uar(dev->mdev, idx); |
| 2148 | |
| 2149 | free_bfreg: |
| 2150 | mlx5_ib_free_bfreg(dev, bfregi, bfreg_dyn_idx); |
| 2151 | |
| 2152 | return err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2153 | } |
| 2154 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2155 | static int dm_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
| 2156 | { |
| 2157 | struct mlx5_ib_ucontext *mctx = to_mucontext(context); |
| 2158 | struct mlx5_ib_dev *dev = to_mdev(context->device); |
| 2159 | u16 page_idx = get_extended_index(vma->vm_pgoff); |
| 2160 | size_t map_size = vma->vm_end - vma->vm_start; |
| 2161 | u32 npages = map_size >> PAGE_SHIFT; |
| 2162 | phys_addr_t pfn; |
| 2163 | pgprot_t prot; |
| 2164 | |
| 2165 | if (find_next_zero_bit(mctx->dm_pages, page_idx + npages, page_idx) != |
| 2166 | page_idx + npages) |
| 2167 | return -EINVAL; |
| 2168 | |
| 2169 | pfn = ((pci_resource_start(dev->mdev->pdev, 0) + |
| 2170 | MLX5_CAP64_DEV_MEM(dev->mdev, memic_bar_start_addr)) >> |
| 2171 | PAGE_SHIFT) + |
| 2172 | page_idx; |
| 2173 | prot = pgprot_writecombine(vma->vm_page_prot); |
| 2174 | vma->vm_page_prot = prot; |
| 2175 | |
| 2176 | if (io_remap_pfn_range(vma, vma->vm_start, pfn, map_size, |
| 2177 | vma->vm_page_prot)) |
| 2178 | return -EAGAIN; |
| 2179 | |
| 2180 | return mlx5_ib_set_vma_data(vma, mctx); |
| 2181 | } |
| 2182 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2183 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
| 2184 | { |
| 2185 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 2186 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2187 | unsigned long command; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2188 | phys_addr_t pfn; |
| 2189 | |
| 2190 | command = get_command(vma->vm_pgoff); |
| 2191 | switch (command) { |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2192 | case MLX5_IB_MMAP_WC_PAGE: |
| 2193 | case MLX5_IB_MMAP_NC_PAGE: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2194 | case MLX5_IB_MMAP_REGULAR_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2195 | case MLX5_IB_MMAP_ALLOC_WC: |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2196 | return uar_mmap(dev, command, vma, context); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2197 | |
| 2198 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
| 2199 | return -ENOSYS; |
| 2200 | |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2201 | case MLX5_IB_MMAP_CORE_CLOCK: |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2202 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2203 | return -EINVAL; |
| 2204 | |
Matan Barak | 6cbac1e | 2016-04-14 16:52:10 +0300 | [diff] [blame] | 2205 | if (vma->vm_flags & VM_WRITE) |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2206 | return -EPERM; |
| 2207 | |
| 2208 | /* Don't expose to user-space information it shouldn't have */ |
| 2209 | if (PAGE_SIZE > 4096) |
| 2210 | return -EOPNOTSUPP; |
| 2211 | |
| 2212 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 2213 | pfn = (dev->mdev->iseg_base + |
| 2214 | offsetof(struct mlx5_init_seg, internal_timer_h)) >> |
| 2215 | PAGE_SHIFT; |
| 2216 | if (io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 2217 | PAGE_SIZE, vma->vm_page_prot)) |
| 2218 | return -EAGAIN; |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2219 | break; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2220 | case MLX5_IB_MMAP_CLOCK_INFO: |
| 2221 | return mlx5_ib_mmap_clock_info_page(dev, vma, context); |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2222 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2223 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2224 | return dm_mmap(ibcontext, vma); |
| 2225 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2226 | default: |
| 2227 | return -EINVAL; |
| 2228 | } |
| 2229 | |
| 2230 | return 0; |
| 2231 | } |
| 2232 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2233 | struct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev, |
| 2234 | struct ib_ucontext *context, |
| 2235 | struct ib_dm_alloc_attr *attr, |
| 2236 | struct uverbs_attr_bundle *attrs) |
| 2237 | { |
| 2238 | u64 act_size = roundup(attr->length, MLX5_MEMIC_BASE_SIZE); |
| 2239 | struct mlx5_memic *memic = &to_mdev(ibdev)->memic; |
| 2240 | phys_addr_t memic_addr; |
| 2241 | struct mlx5_ib_dm *dm; |
| 2242 | u64 start_offset; |
| 2243 | u32 page_idx; |
| 2244 | int err; |
| 2245 | |
| 2246 | dm = kzalloc(sizeof(*dm), GFP_KERNEL); |
| 2247 | if (!dm) |
| 2248 | return ERR_PTR(-ENOMEM); |
| 2249 | |
| 2250 | mlx5_ib_dbg(to_mdev(ibdev), "alloc_memic req: user_length=0x%llx act_length=0x%llx log_alignment=%d\n", |
| 2251 | attr->length, act_size, attr->alignment); |
| 2252 | |
| 2253 | err = mlx5_cmd_alloc_memic(memic, &memic_addr, |
| 2254 | act_size, attr->alignment); |
| 2255 | if (err) |
| 2256 | goto err_free; |
| 2257 | |
| 2258 | start_offset = memic_addr & ~PAGE_MASK; |
| 2259 | page_idx = (memic_addr - pci_resource_start(memic->dev->pdev, 0) - |
| 2260 | MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
| 2261 | PAGE_SHIFT; |
| 2262 | |
| 2263 | err = uverbs_copy_to(attrs, |
| 2264 | MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 2265 | &start_offset, sizeof(start_offset)); |
| 2266 | if (err) |
| 2267 | goto err_dealloc; |
| 2268 | |
| 2269 | err = uverbs_copy_to(attrs, |
| 2270 | MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 2271 | &page_idx, sizeof(page_idx)); |
| 2272 | if (err) |
| 2273 | goto err_dealloc; |
| 2274 | |
| 2275 | bitmap_set(to_mucontext(context)->dm_pages, page_idx, |
| 2276 | DIV_ROUND_UP(act_size, PAGE_SIZE)); |
| 2277 | |
| 2278 | dm->dev_addr = memic_addr; |
| 2279 | |
| 2280 | return &dm->ibdm; |
| 2281 | |
| 2282 | err_dealloc: |
| 2283 | mlx5_cmd_dealloc_memic(memic, memic_addr, |
| 2284 | act_size); |
| 2285 | err_free: |
| 2286 | kfree(dm); |
| 2287 | return ERR_PTR(err); |
| 2288 | } |
| 2289 | |
| 2290 | int mlx5_ib_dealloc_dm(struct ib_dm *ibdm) |
| 2291 | { |
| 2292 | struct mlx5_memic *memic = &to_mdev(ibdm->device)->memic; |
| 2293 | struct mlx5_ib_dm *dm = to_mdm(ibdm); |
| 2294 | u64 act_size = roundup(dm->ibdm.length, MLX5_MEMIC_BASE_SIZE); |
| 2295 | u32 page_idx; |
| 2296 | int ret; |
| 2297 | |
| 2298 | ret = mlx5_cmd_dealloc_memic(memic, dm->dev_addr, act_size); |
| 2299 | if (ret) |
| 2300 | return ret; |
| 2301 | |
| 2302 | page_idx = (dm->dev_addr - pci_resource_start(memic->dev->pdev, 0) - |
| 2303 | MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
| 2304 | PAGE_SHIFT; |
| 2305 | bitmap_clear(to_mucontext(ibdm->uobject->context)->dm_pages, |
| 2306 | page_idx, |
| 2307 | DIV_ROUND_UP(act_size, PAGE_SIZE)); |
| 2308 | |
| 2309 | kfree(dm); |
| 2310 | |
| 2311 | return 0; |
| 2312 | } |
| 2313 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2314 | static struct ib_pd *mlx5_ib_alloc_pd(struct ib_device *ibdev, |
| 2315 | struct ib_ucontext *context, |
| 2316 | struct ib_udata *udata) |
| 2317 | { |
| 2318 | struct mlx5_ib_alloc_pd_resp resp; |
| 2319 | struct mlx5_ib_pd *pd; |
| 2320 | int err; |
| 2321 | |
| 2322 | pd = kmalloc(sizeof(*pd), GFP_KERNEL); |
| 2323 | if (!pd) |
| 2324 | return ERR_PTR(-ENOMEM); |
| 2325 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2326 | err = mlx5_core_alloc_pd(to_mdev(ibdev)->mdev, &pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2327 | if (err) { |
| 2328 | kfree(pd); |
| 2329 | return ERR_PTR(err); |
| 2330 | } |
| 2331 | |
| 2332 | if (context) { |
| 2333 | resp.pdn = pd->pdn; |
| 2334 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2335 | mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2336 | kfree(pd); |
| 2337 | return ERR_PTR(-EFAULT); |
| 2338 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | return &pd->ibpd; |
| 2342 | } |
| 2343 | |
| 2344 | static int mlx5_ib_dealloc_pd(struct ib_pd *pd) |
| 2345 | { |
| 2346 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 2347 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
| 2348 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2349 | mlx5_core_dealloc_pd(mdev->mdev, mpd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2350 | kfree(mpd); |
| 2351 | |
| 2352 | return 0; |
| 2353 | } |
| 2354 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2355 | enum { |
| 2356 | MATCH_CRITERIA_ENABLE_OUTER_BIT, |
| 2357 | MATCH_CRITERIA_ENABLE_MISC_BIT, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2358 | MATCH_CRITERIA_ENABLE_INNER_BIT, |
| 2359 | MATCH_CRITERIA_ENABLE_MISC2_BIT |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2360 | }; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2361 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2362 | #define HEADER_IS_ZERO(match_criteria, headers) \ |
| 2363 | !(memchr_inv(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \ |
| 2364 | 0, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \ |
| 2365 | |
| 2366 | static u8 get_match_criteria_enable(u32 *match_criteria) |
| 2367 | { |
| 2368 | u8 match_criteria_enable; |
| 2369 | |
| 2370 | match_criteria_enable = |
| 2371 | (!HEADER_IS_ZERO(match_criteria, outer_headers)) << |
| 2372 | MATCH_CRITERIA_ENABLE_OUTER_BIT; |
| 2373 | match_criteria_enable |= |
| 2374 | (!HEADER_IS_ZERO(match_criteria, misc_parameters)) << |
| 2375 | MATCH_CRITERIA_ENABLE_MISC_BIT; |
| 2376 | match_criteria_enable |= |
| 2377 | (!HEADER_IS_ZERO(match_criteria, inner_headers)) << |
| 2378 | MATCH_CRITERIA_ENABLE_INNER_BIT; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2379 | match_criteria_enable |= |
| 2380 | (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) << |
| 2381 | MATCH_CRITERIA_ENABLE_MISC2_BIT; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2382 | |
| 2383 | return match_criteria_enable; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2384 | } |
| 2385 | |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2386 | static void set_proto(void *outer_c, void *outer_v, u8 mask, u8 val) |
| 2387 | { |
| 2388 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_protocol, mask); |
| 2389 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_protocol, val); |
| 2390 | } |
| 2391 | |
Daria Velikovsky | 37da2a0 | 2018-05-07 10:20:02 +0300 | [diff] [blame] | 2392 | 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] | 2393 | bool inner) |
| 2394 | { |
| 2395 | if (inner) { |
| 2396 | MLX5_SET(fte_match_set_misc, |
| 2397 | misc_c, inner_ipv6_flow_label, mask); |
| 2398 | MLX5_SET(fte_match_set_misc, |
| 2399 | misc_v, inner_ipv6_flow_label, val); |
| 2400 | } else { |
| 2401 | MLX5_SET(fte_match_set_misc, |
| 2402 | misc_c, outer_ipv6_flow_label, mask); |
| 2403 | MLX5_SET(fte_match_set_misc, |
| 2404 | misc_v, outer_ipv6_flow_label, val); |
| 2405 | } |
| 2406 | } |
| 2407 | |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2408 | static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val) |
| 2409 | { |
| 2410 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_ecn, mask); |
| 2411 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_ecn, val); |
| 2412 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_dscp, mask >> 2); |
| 2413 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_dscp, val >> 2); |
| 2414 | } |
| 2415 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2416 | static int check_mpls_supp_fields(u32 field_support, const __be32 *set_mask) |
| 2417 | { |
| 2418 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_label) && |
| 2419 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_LABEL)) |
| 2420 | return -EOPNOTSUPP; |
| 2421 | |
| 2422 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_exp) && |
| 2423 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_EXP)) |
| 2424 | return -EOPNOTSUPP; |
| 2425 | |
| 2426 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_s_bos) && |
| 2427 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_S_BOS)) |
| 2428 | return -EOPNOTSUPP; |
| 2429 | |
| 2430 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_ttl) && |
| 2431 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_TTL)) |
| 2432 | return -EOPNOTSUPP; |
| 2433 | |
| 2434 | return 0; |
| 2435 | } |
| 2436 | |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2437 | #define LAST_ETH_FIELD vlan_tag |
| 2438 | #define LAST_IB_FIELD sl |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2439 | #define LAST_IPV4_FIELD tos |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2440 | #define LAST_IPV6_FIELD traffic_class |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2441 | #define LAST_TCP_UDP_FIELD src_port |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2442 | #define LAST_TUNNEL_FIELD tunnel_id |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2443 | #define LAST_FLOW_TAG_FIELD tag_id |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2444 | #define LAST_DROP_FIELD size |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2445 | #define LAST_COUNTERS_FIELD counters |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2446 | |
| 2447 | /* Field is the last supported field */ |
| 2448 | #define FIELDS_NOT_SUPPORTED(filter, field)\ |
| 2449 | memchr_inv((void *)&filter.field +\ |
| 2450 | sizeof(filter.field), 0,\ |
| 2451 | sizeof(filter) -\ |
| 2452 | offsetof(typeof(filter), field) -\ |
| 2453 | sizeof(filter.field)) |
| 2454 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2455 | static int parse_flow_flow_action(const union ib_flow_spec *ib_spec, |
| 2456 | const struct ib_flow_attr *flow_attr, |
| 2457 | struct mlx5_flow_act *action) |
| 2458 | { |
| 2459 | struct mlx5_ib_flow_action *maction = to_mflow_act(ib_spec->action.act); |
| 2460 | |
| 2461 | switch (maction->ib_action.type) { |
| 2462 | case IB_FLOW_ACTION_ESP: |
| 2463 | /* Currently only AES_GCM keymat is supported by the driver */ |
| 2464 | action->esp_id = (uintptr_t)maction->esp_aes_gcm.ctx; |
| 2465 | action->action |= flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS ? |
| 2466 | MLX5_FLOW_CONTEXT_ACTION_ENCRYPT : |
| 2467 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT; |
| 2468 | return 0; |
| 2469 | default: |
| 2470 | return -EOPNOTSUPP; |
| 2471 | } |
| 2472 | } |
| 2473 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2474 | static int parse_flow_attr(struct mlx5_core_dev *mdev, u32 *match_c, |
| 2475 | u32 *match_v, const union ib_flow_spec *ib_spec, |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2476 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2477 | struct mlx5_flow_act *action, u32 prev_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2478 | { |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2479 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2480 | misc_parameters); |
| 2481 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2482 | misc_parameters); |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2483 | void *misc_params2_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2484 | misc_parameters_2); |
| 2485 | void *misc_params2_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2486 | misc_parameters_2); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2487 | void *headers_c; |
| 2488 | void *headers_v; |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2489 | int match_ipv; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2490 | int ret; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2491 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2492 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2493 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2494 | inner_headers); |
| 2495 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2496 | inner_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2497 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2498 | ft_field_support.inner_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2499 | } else { |
| 2500 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2501 | outer_headers); |
| 2502 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2503 | outer_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2504 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2505 | ft_field_support.outer_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2509 | case IB_FLOW_SPEC_ETH: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2510 | if (FIELDS_NOT_SUPPORTED(ib_spec->eth.mask, LAST_ETH_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2511 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2512 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2513 | 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] | 2514 | dmac_47_16), |
| 2515 | ib_spec->eth.mask.dst_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2516 | 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] | 2517 | dmac_47_16), |
| 2518 | ib_spec->eth.val.dst_mac); |
| 2519 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2520 | 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] | 2521 | smac_47_16), |
| 2522 | ib_spec->eth.mask.src_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2523 | 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] | 2524 | smac_47_16), |
| 2525 | ib_spec->eth.val.src_mac); |
| 2526 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2527 | if (ib_spec->eth.mask.vlan_tag) { |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2528 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2529 | cvlan_tag, 1); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2530 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2531 | cvlan_tag, 1); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2532 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2533 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2534 | first_vid, ntohs(ib_spec->eth.mask.vlan_tag)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2535 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2536 | first_vid, ntohs(ib_spec->eth.val.vlan_tag)); |
| 2537 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2538 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2539 | first_cfi, |
| 2540 | ntohs(ib_spec->eth.mask.vlan_tag) >> 12); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2541 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2542 | first_cfi, |
| 2543 | ntohs(ib_spec->eth.val.vlan_tag) >> 12); |
| 2544 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2545 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2546 | first_prio, |
| 2547 | ntohs(ib_spec->eth.mask.vlan_tag) >> 13); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2548 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2549 | first_prio, |
| 2550 | ntohs(ib_spec->eth.val.vlan_tag) >> 13); |
| 2551 | } |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2552 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2553 | ethertype, ntohs(ib_spec->eth.mask.ether_type)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2554 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2555 | ethertype, ntohs(ib_spec->eth.val.ether_type)); |
| 2556 | break; |
| 2557 | case IB_FLOW_SPEC_IPV4: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2558 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv4.mask, LAST_IPV4_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2559 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2560 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2561 | if (match_ipv) { |
| 2562 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2563 | ip_version, 0xf); |
| 2564 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2565 | ip_version, MLX5_FS_IPV4_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2566 | } else { |
| 2567 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2568 | ethertype, 0xffff); |
| 2569 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2570 | ethertype, ETH_P_IP); |
| 2571 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2572 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2573 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2574 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2575 | &ib_spec->ipv4.mask.src_ip, |
| 2576 | sizeof(ib_spec->ipv4.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2577 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2578 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2579 | &ib_spec->ipv4.val.src_ip, |
| 2580 | sizeof(ib_spec->ipv4.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2581 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2582 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2583 | &ib_spec->ipv4.mask.dst_ip, |
| 2584 | sizeof(ib_spec->ipv4.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2585 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2586 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2587 | &ib_spec->ipv4.val.dst_ip, |
| 2588 | sizeof(ib_spec->ipv4.val.dst_ip)); |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2589 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2590 | set_tos(headers_c, headers_v, |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2591 | ib_spec->ipv4.mask.tos, ib_spec->ipv4.val.tos); |
| 2592 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2593 | set_proto(headers_c, headers_v, |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2594 | ib_spec->ipv4.mask.proto, ib_spec->ipv4.val.proto); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2595 | break; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2596 | case IB_FLOW_SPEC_IPV6: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2597 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv6.mask, LAST_IPV6_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2598 | return -EOPNOTSUPP; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2599 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2600 | if (match_ipv) { |
| 2601 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2602 | ip_version, 0xf); |
| 2603 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2604 | ip_version, MLX5_FS_IPV6_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2605 | } else { |
| 2606 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2607 | ethertype, 0xffff); |
| 2608 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2609 | ethertype, ETH_P_IPV6); |
| 2610 | } |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2611 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2612 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2613 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2614 | &ib_spec->ipv6.mask.src_ip, |
| 2615 | sizeof(ib_spec->ipv6.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2616 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2617 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2618 | &ib_spec->ipv6.val.src_ip, |
| 2619 | sizeof(ib_spec->ipv6.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2620 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2621 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2622 | &ib_spec->ipv6.mask.dst_ip, |
| 2623 | sizeof(ib_spec->ipv6.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2624 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2625 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2626 | &ib_spec->ipv6.val.dst_ip, |
| 2627 | sizeof(ib_spec->ipv6.val.dst_ip)); |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2628 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2629 | set_tos(headers_c, headers_v, |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2630 | ib_spec->ipv6.mask.traffic_class, |
| 2631 | ib_spec->ipv6.val.traffic_class); |
| 2632 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2633 | set_proto(headers_c, headers_v, |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2634 | ib_spec->ipv6.mask.next_hdr, |
| 2635 | ib_spec->ipv6.val.next_hdr); |
| 2636 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2637 | set_flow_label(misc_params_c, misc_params_v, |
| 2638 | ntohl(ib_spec->ipv6.mask.flow_label), |
| 2639 | ntohl(ib_spec->ipv6.val.flow_label), |
| 2640 | ib_spec->type & IB_FLOW_SPEC_INNER); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2641 | break; |
| 2642 | case IB_FLOW_SPEC_ESP: |
| 2643 | if (ib_spec->esp.mask.seq) |
| 2644 | return -EOPNOTSUPP; |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2645 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2646 | MLX5_SET(fte_match_set_misc, misc_params_c, outer_esp_spi, |
| 2647 | ntohl(ib_spec->esp.mask.spi)); |
| 2648 | MLX5_SET(fte_match_set_misc, misc_params_v, outer_esp_spi, |
| 2649 | ntohl(ib_spec->esp.val.spi)); |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2650 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2651 | case IB_FLOW_SPEC_TCP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2652 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2653 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2654 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2655 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2656 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2657 | 0xff); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2658 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2659 | IPPROTO_TCP); |
| 2660 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2661 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2662 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2663 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2664 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2665 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2666 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2667 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2668 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2669 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2670 | break; |
| 2671 | case IB_FLOW_SPEC_UDP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2672 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2673 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2674 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2675 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2676 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2677 | 0xff); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2678 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2679 | IPPROTO_UDP); |
| 2680 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2681 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2682 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2683 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2684 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2685 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2686 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2687 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2688 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2689 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2690 | break; |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2691 | case IB_FLOW_SPEC_GRE: |
| 2692 | if (ib_spec->gre.mask.c_ks_res0_ver) |
| 2693 | return -EOPNOTSUPP; |
| 2694 | |
| 2695 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
| 2696 | 0xff); |
| 2697 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
| 2698 | IPPROTO_GRE); |
| 2699 | |
| 2700 | MLX5_SET(fte_match_set_misc, misc_params_c, gre_protocol, |
Maor Gottlieb | a93b632 | 2018-07-01 15:50:17 +0300 | [diff] [blame] | 2701 | ntohs(ib_spec->gre.mask.protocol)); |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2702 | MLX5_SET(fte_match_set_misc, misc_params_v, gre_protocol, |
| 2703 | ntohs(ib_spec->gre.val.protocol)); |
| 2704 | |
| 2705 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_c, |
| 2706 | gre_key_h), |
| 2707 | &ib_spec->gre.mask.key, |
| 2708 | sizeof(ib_spec->gre.mask.key)); |
| 2709 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_v, |
| 2710 | gre_key_h), |
| 2711 | &ib_spec->gre.val.key, |
| 2712 | sizeof(ib_spec->gre.val.key)); |
| 2713 | break; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2714 | case IB_FLOW_SPEC_MPLS: |
| 2715 | switch (prev_type) { |
| 2716 | case IB_FLOW_SPEC_UDP: |
| 2717 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2718 | ft_field_support.outer_first_mpls_over_udp), |
| 2719 | &ib_spec->mpls.mask.tag)) |
| 2720 | return -EOPNOTSUPP; |
| 2721 | |
| 2722 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2723 | outer_first_mpls_over_udp), |
| 2724 | &ib_spec->mpls.val.tag, |
| 2725 | sizeof(ib_spec->mpls.val.tag)); |
| 2726 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2727 | outer_first_mpls_over_udp), |
| 2728 | &ib_spec->mpls.mask.tag, |
| 2729 | sizeof(ib_spec->mpls.mask.tag)); |
| 2730 | break; |
| 2731 | case IB_FLOW_SPEC_GRE: |
| 2732 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2733 | ft_field_support.outer_first_mpls_over_gre), |
| 2734 | &ib_spec->mpls.mask.tag)) |
| 2735 | return -EOPNOTSUPP; |
| 2736 | |
| 2737 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2738 | outer_first_mpls_over_gre), |
| 2739 | &ib_spec->mpls.val.tag, |
| 2740 | sizeof(ib_spec->mpls.val.tag)); |
| 2741 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2742 | outer_first_mpls_over_gre), |
| 2743 | &ib_spec->mpls.mask.tag, |
| 2744 | sizeof(ib_spec->mpls.mask.tag)); |
| 2745 | break; |
| 2746 | default: |
| 2747 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2748 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2749 | ft_field_support.inner_first_mpls), |
| 2750 | &ib_spec->mpls.mask.tag)) |
| 2751 | return -EOPNOTSUPP; |
| 2752 | |
| 2753 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2754 | inner_first_mpls), |
| 2755 | &ib_spec->mpls.val.tag, |
| 2756 | sizeof(ib_spec->mpls.val.tag)); |
| 2757 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2758 | inner_first_mpls), |
| 2759 | &ib_spec->mpls.mask.tag, |
| 2760 | sizeof(ib_spec->mpls.mask.tag)); |
| 2761 | } else { |
| 2762 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2763 | ft_field_support.outer_first_mpls), |
| 2764 | &ib_spec->mpls.mask.tag)) |
| 2765 | return -EOPNOTSUPP; |
| 2766 | |
| 2767 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2768 | outer_first_mpls), |
| 2769 | &ib_spec->mpls.val.tag, |
| 2770 | sizeof(ib_spec->mpls.val.tag)); |
| 2771 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2772 | outer_first_mpls), |
| 2773 | &ib_spec->mpls.mask.tag, |
| 2774 | sizeof(ib_spec->mpls.mask.tag)); |
| 2775 | } |
| 2776 | } |
| 2777 | break; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2778 | case IB_FLOW_SPEC_VXLAN_TUNNEL: |
| 2779 | if (FIELDS_NOT_SUPPORTED(ib_spec->tunnel.mask, |
| 2780 | LAST_TUNNEL_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2781 | return -EOPNOTSUPP; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2782 | |
| 2783 | MLX5_SET(fte_match_set_misc, misc_params_c, vxlan_vni, |
| 2784 | ntohl(ib_spec->tunnel.mask.tunnel_id)); |
| 2785 | MLX5_SET(fte_match_set_misc, misc_params_v, vxlan_vni, |
| 2786 | ntohl(ib_spec->tunnel.val.tunnel_id)); |
| 2787 | break; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2788 | case IB_FLOW_SPEC_ACTION_TAG: |
| 2789 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_tag, |
| 2790 | LAST_FLOW_TAG_FIELD)) |
| 2791 | return -EOPNOTSUPP; |
| 2792 | if (ib_spec->flow_tag.tag_id >= BIT(24)) |
| 2793 | return -EINVAL; |
| 2794 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 2795 | action->flow_tag = ib_spec->flow_tag.tag_id; |
Matan Barak | a9db0ec | 2017-08-16 09:43:48 +0300 | [diff] [blame] | 2796 | action->has_flow_tag = true; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2797 | break; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2798 | case IB_FLOW_SPEC_ACTION_DROP: |
| 2799 | if (FIELDS_NOT_SUPPORTED(ib_spec->drop, |
| 2800 | LAST_DROP_FIELD)) |
| 2801 | return -EOPNOTSUPP; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 2802 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DROP; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2803 | break; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2804 | case IB_FLOW_SPEC_ACTION_HANDLE: |
| 2805 | ret = parse_flow_flow_action(ib_spec, flow_attr, action); |
| 2806 | if (ret) |
| 2807 | return ret; |
| 2808 | break; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2809 | case IB_FLOW_SPEC_ACTION_COUNT: |
| 2810 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_count, |
| 2811 | LAST_COUNTERS_FIELD)) |
| 2812 | return -EOPNOTSUPP; |
| 2813 | |
| 2814 | /* for now support only one counters spec per flow */ |
| 2815 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) |
| 2816 | return -EINVAL; |
| 2817 | |
| 2818 | action->counters = ib_spec->flow_count.counters; |
| 2819 | action->action |= MLX5_FLOW_CONTEXT_ACTION_COUNT; |
| 2820 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2821 | default: |
| 2822 | return -EINVAL; |
| 2823 | } |
| 2824 | |
| 2825 | return 0; |
| 2826 | } |
| 2827 | |
| 2828 | /* If a flow could catch both multicast and unicast packets, |
| 2829 | * it won't fall into the multicast flow steering table and this rule |
| 2830 | * could steal other multicast packets. |
| 2831 | */ |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 2832 | 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] | 2833 | { |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2834 | union ib_flow_spec *flow_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2835 | |
| 2836 | if (ib_attr->type != IB_FLOW_ATTR_NORMAL || |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2837 | ib_attr->num_of_specs < 1) |
| 2838 | return false; |
| 2839 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2840 | flow_spec = (union ib_flow_spec *)(ib_attr + 1); |
| 2841 | if (flow_spec->type == IB_FLOW_SPEC_IPV4) { |
| 2842 | struct ib_flow_spec_ipv4 *ipv4_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2843 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2844 | ipv4_spec = (struct ib_flow_spec_ipv4 *)flow_spec; |
| 2845 | if (ipv4_is_multicast(ipv4_spec->val.dst_ip)) |
| 2846 | return true; |
| 2847 | |
| 2848 | return false; |
| 2849 | } |
| 2850 | |
| 2851 | if (flow_spec->type == IB_FLOW_SPEC_ETH) { |
| 2852 | struct ib_flow_spec_eth *eth_spec; |
| 2853 | |
| 2854 | eth_spec = (struct ib_flow_spec_eth *)flow_spec; |
| 2855 | return is_multicast_ether_addr(eth_spec->mask.dst_mac) && |
| 2856 | is_multicast_ether_addr(eth_spec->val.dst_mac); |
| 2857 | } |
| 2858 | |
| 2859 | return false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2860 | } |
| 2861 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2862 | enum valid_spec { |
| 2863 | VALID_SPEC_INVALID, |
| 2864 | VALID_SPEC_VALID, |
| 2865 | VALID_SPEC_NA, |
| 2866 | }; |
| 2867 | |
| 2868 | static enum valid_spec |
| 2869 | is_valid_esp_aes_gcm(struct mlx5_core_dev *mdev, |
| 2870 | const struct mlx5_flow_spec *spec, |
| 2871 | const struct mlx5_flow_act *flow_act, |
| 2872 | bool egress) |
| 2873 | { |
| 2874 | const u32 *match_c = spec->match_criteria; |
| 2875 | bool is_crypto = |
| 2876 | (flow_act->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 2877 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)); |
| 2878 | bool is_ipsec = mlx5_fs_is_ipsec_flow(match_c); |
| 2879 | bool is_drop = flow_act->action & MLX5_FLOW_CONTEXT_ACTION_DROP; |
| 2880 | |
| 2881 | /* |
| 2882 | * Currently only crypto is supported in egress, when regular egress |
| 2883 | * rules would be supported, always return VALID_SPEC_NA. |
| 2884 | */ |
| 2885 | if (!is_crypto) |
| 2886 | return egress ? VALID_SPEC_INVALID : VALID_SPEC_NA; |
| 2887 | |
| 2888 | return is_crypto && is_ipsec && |
| 2889 | (!egress || (!is_drop && !flow_act->has_flow_tag)) ? |
| 2890 | VALID_SPEC_VALID : VALID_SPEC_INVALID; |
| 2891 | } |
| 2892 | |
| 2893 | static bool is_valid_spec(struct mlx5_core_dev *mdev, |
| 2894 | const struct mlx5_flow_spec *spec, |
| 2895 | const struct mlx5_flow_act *flow_act, |
| 2896 | bool egress) |
| 2897 | { |
| 2898 | /* We curretly only support ipsec egress flow */ |
| 2899 | return is_valid_esp_aes_gcm(mdev, spec, flow_act, egress) != VALID_SPEC_INVALID; |
| 2900 | } |
| 2901 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2902 | static bool is_valid_ethertype(struct mlx5_core_dev *mdev, |
| 2903 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2904 | bool check_inner) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2905 | { |
| 2906 | 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] | 2907 | int match_ipv = check_inner ? |
| 2908 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2909 | ft_field_support.inner_ip_version) : |
| 2910 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2911 | ft_field_support.outer_ip_version); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2912 | int inner_bit = check_inner ? IB_FLOW_SPEC_INNER : 0; |
| 2913 | bool ipv4_spec_valid, ipv6_spec_valid; |
| 2914 | unsigned int ip_spec_type = 0; |
| 2915 | bool has_ethertype = false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2916 | unsigned int spec_index; |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2917 | bool mask_valid = true; |
| 2918 | u16 eth_type = 0; |
| 2919 | bool type_valid; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2920 | |
| 2921 | /* Validate that ethertype is correct */ |
| 2922 | 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] | 2923 | if ((ib_spec->type == (IB_FLOW_SPEC_ETH | inner_bit)) && |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2924 | ib_spec->eth.mask.ether_type) { |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2925 | mask_valid = (ib_spec->eth.mask.ether_type == |
| 2926 | htons(0xffff)); |
| 2927 | has_ethertype = true; |
| 2928 | eth_type = ntohs(ib_spec->eth.val.ether_type); |
| 2929 | } else if ((ib_spec->type == (IB_FLOW_SPEC_IPV4 | inner_bit)) || |
| 2930 | (ib_spec->type == (IB_FLOW_SPEC_IPV6 | inner_bit))) { |
| 2931 | ip_spec_type = ib_spec->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2932 | } |
| 2933 | ib_spec = (void *)ib_spec + ib_spec->size; |
| 2934 | } |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2935 | |
| 2936 | type_valid = (!has_ethertype) || (!ip_spec_type); |
| 2937 | if (!type_valid && mask_valid) { |
| 2938 | ipv4_spec_valid = (eth_type == ETH_P_IP) && |
| 2939 | (ip_spec_type == (IB_FLOW_SPEC_IPV4 | inner_bit)); |
| 2940 | ipv6_spec_valid = (eth_type == ETH_P_IPV6) && |
| 2941 | (ip_spec_type == (IB_FLOW_SPEC_IPV6 | inner_bit)); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2942 | |
| 2943 | type_valid = (ipv4_spec_valid) || (ipv6_spec_valid) || |
| 2944 | (((eth_type == ETH_P_MPLS_UC) || |
| 2945 | (eth_type == ETH_P_MPLS_MC)) && match_ipv); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | return type_valid; |
| 2949 | } |
| 2950 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2951 | static bool is_valid_attr(struct mlx5_core_dev *mdev, |
| 2952 | const struct ib_flow_attr *flow_attr) |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2953 | { |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2954 | return is_valid_ethertype(mdev, flow_attr, false) && |
| 2955 | is_valid_ethertype(mdev, flow_attr, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | static void put_flow_table(struct mlx5_ib_dev *dev, |
| 2959 | struct mlx5_ib_flow_prio *prio, bool ft_added) |
| 2960 | { |
| 2961 | prio->refcount -= !!ft_added; |
| 2962 | if (!prio->refcount) { |
| 2963 | mlx5_destroy_flow_table(prio->flow_table); |
| 2964 | prio->flow_table = NULL; |
| 2965 | } |
| 2966 | } |
| 2967 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2968 | static void counters_clear_description(struct ib_counters *counters) |
| 2969 | { |
| 2970 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 2971 | |
| 2972 | mutex_lock(&mcounters->mcntrs_mutex); |
| 2973 | kfree(mcounters->counters_data); |
| 2974 | mcounters->counters_data = NULL; |
| 2975 | mcounters->cntrs_max_index = 0; |
| 2976 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 2977 | } |
| 2978 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2979 | static int mlx5_ib_destroy_flow(struct ib_flow *flow_id) |
| 2980 | { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2981 | struct mlx5_ib_flow_handler *handler = container_of(flow_id, |
| 2982 | struct mlx5_ib_flow_handler, |
| 2983 | ibflow); |
| 2984 | struct mlx5_ib_flow_handler *iter, *tmp; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 2985 | struct mlx5_ib_dev *dev = handler->dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2986 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 2987 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2988 | |
| 2989 | list_for_each_entry_safe(iter, tmp, &handler->list, list) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 2990 | mlx5_del_flow_rules(iter->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 2991 | put_flow_table(dev, iter->prio, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2992 | list_del(&iter->list); |
| 2993 | kfree(iter); |
| 2994 | } |
| 2995 | |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 2996 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 2997 | put_flow_table(dev, handler->prio, true); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2998 | if (handler->ibcounters && |
| 2999 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3000 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3001 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3002 | mutex_unlock(&dev->flow_db->lock); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3003 | if (handler->flow_matcher) |
| 3004 | atomic_dec(&handler->flow_matcher->usecnt); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3005 | kfree(handler); |
| 3006 | |
| 3007 | return 0; |
| 3008 | } |
| 3009 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3010 | static int ib_prio_to_core_prio(unsigned int priority, bool dont_trap) |
| 3011 | { |
| 3012 | priority *= 2; |
| 3013 | if (!dont_trap) |
| 3014 | priority++; |
| 3015 | return priority; |
| 3016 | } |
| 3017 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3018 | enum flow_table_type { |
| 3019 | MLX5_IB_FT_RX, |
| 3020 | MLX5_IB_FT_TX |
| 3021 | }; |
| 3022 | |
Maor Gottlieb | 00b7c2a | 2017-03-29 06:09:01 +0300 | [diff] [blame] | 3023 | #define MLX5_FS_MAX_TYPES 6 |
| 3024 | #define MLX5_FS_MAX_ENTRIES BIT(16) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3025 | |
| 3026 | static struct mlx5_ib_flow_prio *_get_prio(struct mlx5_flow_namespace *ns, |
| 3027 | struct mlx5_ib_flow_prio *prio, |
| 3028 | int priority, |
| 3029 | int num_entries, int num_groups) |
| 3030 | { |
| 3031 | struct mlx5_flow_table *ft; |
| 3032 | |
| 3033 | ft = mlx5_create_auto_grouped_flow_table(ns, priority, |
| 3034 | num_entries, |
| 3035 | num_groups, |
| 3036 | 0, 0); |
| 3037 | if (IS_ERR(ft)) |
| 3038 | return ERR_CAST(ft); |
| 3039 | |
| 3040 | prio->flow_table = ft; |
| 3041 | prio->refcount = 0; |
| 3042 | return prio; |
| 3043 | } |
| 3044 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3045 | 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] | 3046 | struct ib_flow_attr *flow_attr, |
| 3047 | enum flow_table_type ft_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3048 | { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3049 | bool dont_trap = flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3050 | struct mlx5_flow_namespace *ns = NULL; |
| 3051 | struct mlx5_ib_flow_prio *prio; |
| 3052 | struct mlx5_flow_table *ft; |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3053 | int max_table_size; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3054 | int num_entries; |
| 3055 | int num_groups; |
| 3056 | int priority; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3057 | |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3058 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3059 | log_max_ft_size)); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3060 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3061 | if (ft_type == MLX5_IB_FT_TX) |
| 3062 | priority = 0; |
| 3063 | else if (flow_is_multicast_only(flow_attr) && |
| 3064 | !dont_trap) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3065 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3066 | else |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3067 | priority = ib_prio_to_core_prio(flow_attr->priority, |
| 3068 | dont_trap); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3069 | ns = mlx5_get_flow_namespace(dev->mdev, |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3070 | ft_type == MLX5_IB_FT_TX ? |
| 3071 | MLX5_FLOW_NAMESPACE_EGRESS : |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3072 | MLX5_FLOW_NAMESPACE_BYPASS); |
| 3073 | num_entries = MLX5_FS_MAX_ENTRIES; |
| 3074 | num_groups = MLX5_FS_MAX_TYPES; |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3075 | prio = &dev->flow_db->prios[priority]; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3076 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3077 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3078 | ns = mlx5_get_flow_namespace(dev->mdev, |
| 3079 | MLX5_FLOW_NAMESPACE_LEFTOVERS); |
| 3080 | build_leftovers_ft_param(&priority, |
| 3081 | &num_entries, |
| 3082 | &num_groups); |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3083 | prio = &dev->flow_db->prios[MLX5_IB_FLOW_LEFTOVERS_PRIO]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3084 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3085 | if (!MLX5_CAP_FLOWTABLE(dev->mdev, |
| 3086 | allow_sniffer_and_nic_rx_shared_tir)) |
| 3087 | return ERR_PTR(-ENOTSUPP); |
| 3088 | |
| 3089 | ns = mlx5_get_flow_namespace(dev->mdev, ft_type == MLX5_IB_FT_RX ? |
| 3090 | MLX5_FLOW_NAMESPACE_SNIFFER_RX : |
| 3091 | MLX5_FLOW_NAMESPACE_SNIFFER_TX); |
| 3092 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3093 | prio = &dev->flow_db->sniffer[ft_type]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3094 | priority = 0; |
| 3095 | num_entries = 1; |
| 3096 | num_groups = 1; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | if (!ns) |
| 3100 | return ERR_PTR(-ENOTSUPP); |
| 3101 | |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3102 | if (num_entries > max_table_size) |
| 3103 | return ERR_PTR(-ENOMEM); |
| 3104 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3105 | ft = prio->flow_table; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3106 | if (!ft) |
| 3107 | return _get_prio(ns, prio, priority, num_entries, num_groups); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3108 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3109 | return prio; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3110 | } |
| 3111 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3112 | static void set_underlay_qp(struct mlx5_ib_dev *dev, |
| 3113 | struct mlx5_flow_spec *spec, |
| 3114 | u32 underlay_qpn) |
| 3115 | { |
| 3116 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, |
| 3117 | spec->match_criteria, |
| 3118 | misc_parameters); |
| 3119 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3120 | misc_parameters); |
| 3121 | |
| 3122 | if (underlay_qpn && |
| 3123 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3124 | ft_field_support.bth_dst_qp)) { |
| 3125 | MLX5_SET(fte_match_set_misc, |
| 3126 | misc_params_v, bth_dst_qp, underlay_qpn); |
| 3127 | MLX5_SET(fte_match_set_misc, |
| 3128 | misc_params_c, bth_dst_qp, 0xffffff); |
| 3129 | } |
| 3130 | } |
| 3131 | |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3132 | static int read_flow_counters(struct ib_device *ibdev, |
| 3133 | struct mlx5_read_counters_attr *read_attr) |
| 3134 | { |
| 3135 | struct mlx5_fc *fc = read_attr->hw_cntrs_hndl; |
| 3136 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 3137 | |
| 3138 | return mlx5_fc_query(dev->mdev, fc, |
| 3139 | &read_attr->out[IB_COUNTER_PACKETS], |
| 3140 | &read_attr->out[IB_COUNTER_BYTES]); |
| 3141 | } |
| 3142 | |
| 3143 | /* flow counters currently expose two counters packets and bytes */ |
| 3144 | #define FLOW_COUNTERS_NUM 2 |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3145 | static int counters_set_description(struct ib_counters *counters, |
| 3146 | enum mlx5_ib_counters_type counters_type, |
| 3147 | struct mlx5_ib_flow_counters_desc *desc_data, |
| 3148 | u32 ncounters) |
| 3149 | { |
| 3150 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3151 | u32 cntrs_max_index = 0; |
| 3152 | int i; |
| 3153 | |
| 3154 | if (counters_type != MLX5_IB_COUNTERS_FLOW) |
| 3155 | return -EINVAL; |
| 3156 | |
| 3157 | /* init the fields for the object */ |
| 3158 | mcounters->type = counters_type; |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3159 | mcounters->read_counters = read_flow_counters; |
| 3160 | mcounters->counters_num = FLOW_COUNTERS_NUM; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3161 | mcounters->ncounters = ncounters; |
| 3162 | /* each counter entry have both description and index pair */ |
| 3163 | for (i = 0; i < ncounters; i++) { |
| 3164 | if (desc_data[i].description > IB_COUNTER_BYTES) |
| 3165 | return -EINVAL; |
| 3166 | |
| 3167 | if (cntrs_max_index <= desc_data[i].index) |
| 3168 | cntrs_max_index = desc_data[i].index + 1; |
| 3169 | } |
| 3170 | |
| 3171 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3172 | mcounters->counters_data = desc_data; |
| 3173 | mcounters->cntrs_max_index = cntrs_max_index; |
| 3174 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3175 | |
| 3176 | return 0; |
| 3177 | } |
| 3178 | |
| 3179 | #define MAX_COUNTERS_NUM (USHRT_MAX / (sizeof(u32) * 2)) |
| 3180 | static int flow_counters_set_data(struct ib_counters *ibcounters, |
| 3181 | struct mlx5_ib_create_flow *ucmd) |
| 3182 | { |
| 3183 | struct mlx5_ib_mcounters *mcounters = to_mcounters(ibcounters); |
| 3184 | struct mlx5_ib_flow_counters_data *cntrs_data = NULL; |
| 3185 | struct mlx5_ib_flow_counters_desc *desc_data = NULL; |
| 3186 | bool hw_hndl = false; |
| 3187 | int ret = 0; |
| 3188 | |
| 3189 | if (ucmd && ucmd->ncounters_data != 0) { |
| 3190 | cntrs_data = ucmd->data; |
| 3191 | if (cntrs_data->ncounters > MAX_COUNTERS_NUM) |
| 3192 | return -EINVAL; |
| 3193 | |
| 3194 | desc_data = kcalloc(cntrs_data->ncounters, |
| 3195 | sizeof(*desc_data), |
| 3196 | GFP_KERNEL); |
| 3197 | if (!desc_data) |
| 3198 | return -ENOMEM; |
| 3199 | |
| 3200 | if (copy_from_user(desc_data, |
| 3201 | u64_to_user_ptr(cntrs_data->counters_data), |
| 3202 | sizeof(*desc_data) * cntrs_data->ncounters)) { |
| 3203 | ret = -EFAULT; |
| 3204 | goto free; |
| 3205 | } |
| 3206 | } |
| 3207 | |
| 3208 | if (!mcounters->hw_cntrs_hndl) { |
| 3209 | mcounters->hw_cntrs_hndl = mlx5_fc_create( |
| 3210 | to_mdev(ibcounters->device)->mdev, false); |
| 3211 | if (!mcounters->hw_cntrs_hndl) { |
| 3212 | ret = -ENOMEM; |
| 3213 | goto free; |
| 3214 | } |
| 3215 | hw_hndl = true; |
| 3216 | } |
| 3217 | |
| 3218 | if (desc_data) { |
| 3219 | /* counters already bound to at least one flow */ |
| 3220 | if (mcounters->cntrs_max_index) { |
| 3221 | ret = -EINVAL; |
| 3222 | goto free_hndl; |
| 3223 | } |
| 3224 | |
| 3225 | ret = counters_set_description(ibcounters, |
| 3226 | MLX5_IB_COUNTERS_FLOW, |
| 3227 | desc_data, |
| 3228 | cntrs_data->ncounters); |
| 3229 | if (ret) |
| 3230 | goto free_hndl; |
| 3231 | |
| 3232 | } else if (!mcounters->cntrs_max_index) { |
| 3233 | /* counters not bound yet, must have udata passed */ |
| 3234 | ret = -EINVAL; |
| 3235 | goto free_hndl; |
| 3236 | } |
| 3237 | |
| 3238 | return 0; |
| 3239 | |
| 3240 | free_hndl: |
| 3241 | if (hw_hndl) { |
| 3242 | mlx5_fc_destroy(to_mdev(ibcounters->device)->mdev, |
| 3243 | mcounters->hw_cntrs_hndl); |
| 3244 | mcounters->hw_cntrs_hndl = NULL; |
| 3245 | } |
| 3246 | free: |
| 3247 | kfree(desc_data); |
| 3248 | return ret; |
| 3249 | } |
| 3250 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3251 | static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev, |
| 3252 | struct mlx5_ib_flow_prio *ft_prio, |
| 3253 | const struct ib_flow_attr *flow_attr, |
| 3254 | struct mlx5_flow_destination *dst, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3255 | u32 underlay_qpn, |
| 3256 | struct mlx5_ib_create_flow *ucmd) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3257 | { |
| 3258 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3259 | struct mlx5_ib_flow_handler *handler; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3260 | 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] | 3261 | struct mlx5_flow_spec *spec; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3262 | struct mlx5_flow_destination dest_arr[2] = {}; |
| 3263 | struct mlx5_flow_destination *rule_dst = dest_arr; |
Maor Gottlieb | dd063d0 | 2016-08-28 14:16:32 +0300 | [diff] [blame] | 3264 | const void *ib_flow = (const void *)flow_attr + sizeof(*flow_attr); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3265 | unsigned int spec_index; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3266 | u32 prev_type = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3267 | int err = 0; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3268 | int dest_num = 0; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3269 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3270 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3271 | if (!is_valid_attr(dev->mdev, flow_attr)) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3272 | return ERR_PTR(-EINVAL); |
| 3273 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3274 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3275 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3276 | if (!handler || !spec) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3277 | err = -ENOMEM; |
| 3278 | goto free; |
| 3279 | } |
| 3280 | |
| 3281 | INIT_LIST_HEAD(&handler->list); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3282 | if (dst) { |
| 3283 | memcpy(&dest_arr[0], dst, sizeof(*dst)); |
| 3284 | dest_num++; |
| 3285 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3286 | |
| 3287 | 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] | 3288 | err = parse_flow_attr(dev->mdev, spec->match_criteria, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3289 | spec->match_value, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3290 | ib_flow, flow_attr, &flow_act, |
| 3291 | prev_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3292 | if (err < 0) |
| 3293 | goto free; |
| 3294 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3295 | prev_type = ((union ib_flow_spec *)ib_flow)->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3296 | ib_flow += ((union ib_flow_spec *)ib_flow)->size; |
| 3297 | } |
| 3298 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3299 | if (!flow_is_multicast_only(flow_attr)) |
| 3300 | set_underlay_qp(dev, spec, underlay_qpn); |
| 3301 | |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3302 | if (dev->rep) { |
| 3303 | void *misc; |
| 3304 | |
| 3305 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3306 | misc_parameters); |
| 3307 | MLX5_SET(fte_match_set_misc, misc, source_port, |
| 3308 | dev->rep->vport); |
| 3309 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
| 3310 | misc_parameters); |
| 3311 | MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port); |
| 3312 | } |
| 3313 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 3314 | spec->match_criteria_enable = get_match_criteria_enable(spec->match_criteria); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3315 | |
| 3316 | if (is_egress && |
| 3317 | !is_valid_spec(dev->mdev, spec, &flow_act, is_egress)) { |
| 3318 | err = -EINVAL; |
| 3319 | goto free; |
| 3320 | } |
| 3321 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3322 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
| 3323 | err = flow_counters_set_data(flow_act.counters, ucmd); |
| 3324 | if (err) |
| 3325 | goto free; |
| 3326 | |
| 3327 | handler->ibcounters = flow_act.counters; |
| 3328 | dest_arr[dest_num].type = |
| 3329 | MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
| 3330 | dest_arr[dest_num].counter = |
| 3331 | to_mcounters(flow_act.counters)->hw_cntrs_hndl; |
| 3332 | dest_num++; |
| 3333 | } |
| 3334 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3335 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DROP) { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3336 | if (!(flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT)) { |
| 3337 | rule_dst = NULL; |
| 3338 | dest_num = 0; |
| 3339 | } |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3340 | } else { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3341 | if (is_egress) |
| 3342 | flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
| 3343 | else |
| 3344 | flow_act.action |= |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3345 | dest_num ? MLX5_FLOW_CONTEXT_ACTION_FWD_DEST : |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3346 | MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3347 | } |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3348 | |
Matan Barak | a9db0ec | 2017-08-16 09:43:48 +0300 | [diff] [blame] | 3349 | if (flow_act.has_flow_tag && |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3350 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3351 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3352 | 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] | 3353 | flow_act.flow_tag, flow_attr->type); |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3354 | err = -EINVAL; |
| 3355 | goto free; |
| 3356 | } |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3357 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Hadar Hen Zion | 66958ed | 2016-11-07 15:14:45 +0200 | [diff] [blame] | 3358 | &flow_act, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3359 | rule_dst, dest_num); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3360 | |
| 3361 | if (IS_ERR(handler->rule)) { |
| 3362 | err = PTR_ERR(handler->rule); |
| 3363 | goto free; |
| 3364 | } |
| 3365 | |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3366 | ft_prio->refcount++; |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3367 | handler->prio = ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3368 | handler->dev = dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3369 | |
| 3370 | ft_prio->flow_table = ft; |
| 3371 | free: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3372 | if (err && handler) { |
| 3373 | if (handler->ibcounters && |
| 3374 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3375 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3376 | kfree(handler); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3377 | } |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3378 | kvfree(spec); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3379 | return err ? ERR_PTR(err) : handler; |
| 3380 | } |
| 3381 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3382 | static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev, |
| 3383 | struct mlx5_ib_flow_prio *ft_prio, |
| 3384 | const struct ib_flow_attr *flow_attr, |
| 3385 | struct mlx5_flow_destination *dst) |
| 3386 | { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3387 | return _create_flow_rule(dev, ft_prio, flow_attr, dst, 0, NULL); |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3388 | } |
| 3389 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3390 | static struct mlx5_ib_flow_handler *create_dont_trap_rule(struct mlx5_ib_dev *dev, |
| 3391 | struct mlx5_ib_flow_prio *ft_prio, |
| 3392 | struct ib_flow_attr *flow_attr, |
| 3393 | struct mlx5_flow_destination *dst) |
| 3394 | { |
| 3395 | struct mlx5_ib_flow_handler *handler_dst = NULL; |
| 3396 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3397 | |
| 3398 | handler = create_flow_rule(dev, ft_prio, flow_attr, NULL); |
| 3399 | if (!IS_ERR(handler)) { |
| 3400 | handler_dst = create_flow_rule(dev, ft_prio, |
| 3401 | flow_attr, dst); |
| 3402 | if (IS_ERR(handler_dst)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3403 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3404 | ft_prio->refcount--; |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3405 | kfree(handler); |
| 3406 | handler = handler_dst; |
| 3407 | } else { |
| 3408 | list_add(&handler_dst->list, &handler->list); |
| 3409 | } |
| 3410 | } |
| 3411 | |
| 3412 | return handler; |
| 3413 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3414 | enum { |
| 3415 | LEFTOVERS_MC, |
| 3416 | LEFTOVERS_UC, |
| 3417 | }; |
| 3418 | |
| 3419 | static struct mlx5_ib_flow_handler *create_leftovers_rule(struct mlx5_ib_dev *dev, |
| 3420 | struct mlx5_ib_flow_prio *ft_prio, |
| 3421 | struct ib_flow_attr *flow_attr, |
| 3422 | struct mlx5_flow_destination *dst) |
| 3423 | { |
| 3424 | struct mlx5_ib_flow_handler *handler_ucast = NULL; |
| 3425 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3426 | |
| 3427 | static struct { |
| 3428 | struct ib_flow_attr flow_attr; |
| 3429 | struct ib_flow_spec_eth eth_flow; |
| 3430 | } leftovers_specs[] = { |
| 3431 | [LEFTOVERS_MC] = { |
| 3432 | .flow_attr = { |
| 3433 | .num_of_specs = 1, |
| 3434 | .size = sizeof(leftovers_specs[0]) |
| 3435 | }, |
| 3436 | .eth_flow = { |
| 3437 | .type = IB_FLOW_SPEC_ETH, |
| 3438 | .size = sizeof(struct ib_flow_spec_eth), |
| 3439 | .mask = {.dst_mac = {0x1} }, |
| 3440 | .val = {.dst_mac = {0x1} } |
| 3441 | } |
| 3442 | }, |
| 3443 | [LEFTOVERS_UC] = { |
| 3444 | .flow_attr = { |
| 3445 | .num_of_specs = 1, |
| 3446 | .size = sizeof(leftovers_specs[0]) |
| 3447 | }, |
| 3448 | .eth_flow = { |
| 3449 | .type = IB_FLOW_SPEC_ETH, |
| 3450 | .size = sizeof(struct ib_flow_spec_eth), |
| 3451 | .mask = {.dst_mac = {0x1} }, |
| 3452 | .val = {.dst_mac = {} } |
| 3453 | } |
| 3454 | } |
| 3455 | }; |
| 3456 | |
| 3457 | handler = create_flow_rule(dev, ft_prio, |
| 3458 | &leftovers_specs[LEFTOVERS_MC].flow_attr, |
| 3459 | dst); |
| 3460 | if (!IS_ERR(handler) && |
| 3461 | flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT) { |
| 3462 | handler_ucast = create_flow_rule(dev, ft_prio, |
| 3463 | &leftovers_specs[LEFTOVERS_UC].flow_attr, |
| 3464 | dst); |
| 3465 | if (IS_ERR(handler_ucast)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3466 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3467 | ft_prio->refcount--; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3468 | kfree(handler); |
| 3469 | handler = handler_ucast; |
| 3470 | } else { |
| 3471 | list_add(&handler_ucast->list, &handler->list); |
| 3472 | } |
| 3473 | } |
| 3474 | |
| 3475 | return handler; |
| 3476 | } |
| 3477 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3478 | static struct mlx5_ib_flow_handler *create_sniffer_rule(struct mlx5_ib_dev *dev, |
| 3479 | struct mlx5_ib_flow_prio *ft_rx, |
| 3480 | struct mlx5_ib_flow_prio *ft_tx, |
| 3481 | struct mlx5_flow_destination *dst) |
| 3482 | { |
| 3483 | struct mlx5_ib_flow_handler *handler_rx; |
| 3484 | struct mlx5_ib_flow_handler *handler_tx; |
| 3485 | int err; |
| 3486 | static const struct ib_flow_attr flow_attr = { |
| 3487 | .num_of_specs = 0, |
| 3488 | .size = sizeof(flow_attr) |
| 3489 | }; |
| 3490 | |
| 3491 | handler_rx = create_flow_rule(dev, ft_rx, &flow_attr, dst); |
| 3492 | if (IS_ERR(handler_rx)) { |
| 3493 | err = PTR_ERR(handler_rx); |
| 3494 | goto err; |
| 3495 | } |
| 3496 | |
| 3497 | handler_tx = create_flow_rule(dev, ft_tx, &flow_attr, dst); |
| 3498 | if (IS_ERR(handler_tx)) { |
| 3499 | err = PTR_ERR(handler_tx); |
| 3500 | goto err_tx; |
| 3501 | } |
| 3502 | |
| 3503 | list_add(&handler_tx->list, &handler_rx->list); |
| 3504 | |
| 3505 | return handler_rx; |
| 3506 | |
| 3507 | err_tx: |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3508 | mlx5_del_flow_rules(handler_rx->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3509 | ft_rx->refcount--; |
| 3510 | kfree(handler_rx); |
| 3511 | err: |
| 3512 | return ERR_PTR(err); |
| 3513 | } |
| 3514 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3515 | static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, |
| 3516 | struct ib_flow_attr *flow_attr, |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3517 | int domain, |
| 3518 | struct ib_udata *udata) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3519 | { |
| 3520 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Yishai Hadas | d9f88e5 | 2016-08-28 10:58:37 +0300 | [diff] [blame] | 3521 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3522 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3523 | struct mlx5_flow_destination *dst = NULL; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3524 | struct mlx5_ib_flow_prio *ft_prio_tx = NULL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3525 | struct mlx5_ib_flow_prio *ft_prio; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3526 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3527 | struct mlx5_ib_create_flow *ucmd = NULL, ucmd_hdr; |
| 3528 | size_t min_ucmd_sz, required_ucmd_sz; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3529 | int err; |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3530 | int underlay_qpn; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3531 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3532 | if (udata && udata->inlen) { |
| 3533 | min_ucmd_sz = offsetof(typeof(ucmd_hdr), reserved) + |
| 3534 | sizeof(ucmd_hdr.reserved); |
| 3535 | if (udata->inlen < min_ucmd_sz) |
| 3536 | return ERR_PTR(-EOPNOTSUPP); |
| 3537 | |
| 3538 | err = ib_copy_from_udata(&ucmd_hdr, udata, min_ucmd_sz); |
| 3539 | if (err) |
| 3540 | return ERR_PTR(err); |
| 3541 | |
| 3542 | /* currently supports only one counters data */ |
| 3543 | if (ucmd_hdr.ncounters_data > 1) |
| 3544 | return ERR_PTR(-EINVAL); |
| 3545 | |
| 3546 | required_ucmd_sz = min_ucmd_sz + |
| 3547 | sizeof(struct mlx5_ib_flow_counters_data) * |
| 3548 | ucmd_hdr.ncounters_data; |
| 3549 | if (udata->inlen > required_ucmd_sz && |
| 3550 | !ib_is_udata_cleared(udata, required_ucmd_sz, |
| 3551 | udata->inlen - required_ucmd_sz)) |
| 3552 | return ERR_PTR(-EOPNOTSUPP); |
| 3553 | |
| 3554 | ucmd = kzalloc(required_ucmd_sz, GFP_KERNEL); |
| 3555 | if (!ucmd) |
| 3556 | return ERR_PTR(-ENOMEM); |
| 3557 | |
| 3558 | err = ib_copy_from_udata(ucmd, udata, required_ucmd_sz); |
| 3559 | if (err) { |
| 3560 | kfree(ucmd); |
| 3561 | return ERR_PTR(err); |
| 3562 | } |
| 3563 | } |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3564 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3565 | if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3566 | return ERR_PTR(-ENOMEM); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3567 | |
| 3568 | if (domain != IB_FLOW_DOMAIN_USER || |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 3569 | flow_attr->port > dev->num_ports || |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3570 | (flow_attr->flags & ~(IB_FLOW_ATTR_FLAGS_DONT_TRAP | |
| 3571 | IB_FLOW_ATTR_FLAGS_EGRESS))) |
| 3572 | return ERR_PTR(-EINVAL); |
| 3573 | |
| 3574 | if (is_egress && |
| 3575 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3576 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3577 | return ERR_PTR(-EINVAL); |
| 3578 | |
| 3579 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
| 3580 | if (!dst) |
| 3581 | return ERR_PTR(-ENOMEM); |
| 3582 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3583 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3584 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3585 | ft_prio = get_flow_table(dev, flow_attr, |
| 3586 | is_egress ? MLX5_IB_FT_TX : MLX5_IB_FT_RX); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3587 | if (IS_ERR(ft_prio)) { |
| 3588 | err = PTR_ERR(ft_prio); |
| 3589 | goto unlock; |
| 3590 | } |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3591 | if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3592 | ft_prio_tx = get_flow_table(dev, flow_attr, MLX5_IB_FT_TX); |
| 3593 | if (IS_ERR(ft_prio_tx)) { |
| 3594 | err = PTR_ERR(ft_prio_tx); |
| 3595 | ft_prio_tx = NULL; |
| 3596 | goto destroy_ft; |
| 3597 | } |
| 3598 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3599 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3600 | if (is_egress) { |
| 3601 | dst->type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
| 3602 | } else { |
| 3603 | dst->type = MLX5_FLOW_DESTINATION_TYPE_TIR; |
| 3604 | if (mqp->flags & MLX5_IB_QP_RSS) |
| 3605 | dst->tir_num = mqp->rss_qp.tirn; |
| 3606 | else |
| 3607 | dst->tir_num = mqp->raw_packet_qp.rq.tirn; |
| 3608 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3609 | |
| 3610 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3611 | if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) { |
| 3612 | handler = create_dont_trap_rule(dev, ft_prio, |
| 3613 | flow_attr, dst); |
| 3614 | } else { |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3615 | underlay_qpn = (mqp->flags & MLX5_IB_QP_UNDERLAY) ? |
| 3616 | mqp->underlay_qpn : 0; |
| 3617 | handler = _create_flow_rule(dev, ft_prio, flow_attr, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3618 | dst, underlay_qpn, ucmd); |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3619 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3620 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3621 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3622 | handler = create_leftovers_rule(dev, ft_prio, flow_attr, |
| 3623 | dst); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3624 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3625 | handler = create_sniffer_rule(dev, ft_prio, ft_prio_tx, dst); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3626 | } else { |
| 3627 | err = -EINVAL; |
| 3628 | goto destroy_ft; |
| 3629 | } |
| 3630 | |
| 3631 | if (IS_ERR(handler)) { |
| 3632 | err = PTR_ERR(handler); |
| 3633 | handler = NULL; |
| 3634 | goto destroy_ft; |
| 3635 | } |
| 3636 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3637 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3638 | kfree(dst); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3639 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3640 | |
| 3641 | return &handler->ibflow; |
| 3642 | |
| 3643 | destroy_ft: |
| 3644 | put_flow_table(dev, ft_prio, false); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3645 | if (ft_prio_tx) |
| 3646 | put_flow_table(dev, ft_prio_tx, false); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3647 | unlock: |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3648 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3649 | kfree(dst); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3650 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3651 | kfree(handler); |
| 3652 | return ERR_PTR(err); |
| 3653 | } |
| 3654 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3655 | static struct mlx5_ib_flow_prio *_get_flow_table(struct mlx5_ib_dev *dev, |
| 3656 | int priority, bool mcast) |
| 3657 | { |
| 3658 | int max_table_size; |
| 3659 | struct mlx5_flow_namespace *ns = NULL; |
| 3660 | struct mlx5_ib_flow_prio *prio; |
| 3661 | |
| 3662 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3663 | log_max_ft_size)); |
| 3664 | if (max_table_size < MLX5_FS_MAX_ENTRIES) |
| 3665 | return ERR_PTR(-ENOMEM); |
| 3666 | |
| 3667 | if (mcast) |
| 3668 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3669 | else |
| 3670 | priority = ib_prio_to_core_prio(priority, false); |
| 3671 | |
| 3672 | ns = mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_BYPASS); |
| 3673 | if (!ns) |
| 3674 | return ERR_PTR(-ENOTSUPP); |
| 3675 | |
| 3676 | prio = &dev->flow_db->prios[priority]; |
| 3677 | |
| 3678 | if (prio->flow_table) |
| 3679 | return prio; |
| 3680 | |
| 3681 | return _get_prio(ns, prio, priority, MLX5_FS_MAX_ENTRIES, |
| 3682 | MLX5_FS_MAX_TYPES); |
| 3683 | } |
| 3684 | |
| 3685 | static struct mlx5_ib_flow_handler * |
| 3686 | _create_raw_flow_rule(struct mlx5_ib_dev *dev, |
| 3687 | struct mlx5_ib_flow_prio *ft_prio, |
| 3688 | struct mlx5_flow_destination *dst, |
| 3689 | struct mlx5_ib_flow_matcher *fs_matcher, |
| 3690 | void *cmd_in, int inlen) |
| 3691 | { |
| 3692 | struct mlx5_ib_flow_handler *handler; |
| 3693 | struct mlx5_flow_act flow_act = {.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG}; |
| 3694 | struct mlx5_flow_spec *spec; |
| 3695 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3696 | int err = 0; |
| 3697 | |
| 3698 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
| 3699 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
| 3700 | if (!handler || !spec) { |
| 3701 | err = -ENOMEM; |
| 3702 | goto free; |
| 3703 | } |
| 3704 | |
| 3705 | INIT_LIST_HEAD(&handler->list); |
| 3706 | |
| 3707 | memcpy(spec->match_value, cmd_in, inlen); |
| 3708 | memcpy(spec->match_criteria, fs_matcher->matcher_mask.match_params, |
| 3709 | fs_matcher->mask_len); |
| 3710 | spec->match_criteria_enable = fs_matcher->match_criteria_enable; |
| 3711 | |
| 3712 | flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
| 3713 | handler->rule = mlx5_add_flow_rules(ft, spec, |
| 3714 | &flow_act, dst, 1); |
| 3715 | |
| 3716 | if (IS_ERR(handler->rule)) { |
| 3717 | err = PTR_ERR(handler->rule); |
| 3718 | goto free; |
| 3719 | } |
| 3720 | |
| 3721 | ft_prio->refcount++; |
| 3722 | handler->prio = ft_prio; |
| 3723 | handler->dev = dev; |
| 3724 | ft_prio->flow_table = ft; |
| 3725 | |
| 3726 | free: |
| 3727 | if (err) |
| 3728 | kfree(handler); |
| 3729 | kvfree(spec); |
| 3730 | return err ? ERR_PTR(err) : handler; |
| 3731 | } |
| 3732 | |
| 3733 | static bool raw_fs_is_multicast(struct mlx5_ib_flow_matcher *fs_matcher, |
| 3734 | void *match_v) |
| 3735 | { |
| 3736 | void *match_c; |
| 3737 | void *match_v_set_lyr_2_4, *match_c_set_lyr_2_4; |
| 3738 | void *dmac, *dmac_mask; |
| 3739 | void *ipv4, *ipv4_mask; |
| 3740 | |
| 3741 | if (!(fs_matcher->match_criteria_enable & |
| 3742 | (1 << MATCH_CRITERIA_ENABLE_OUTER_BIT))) |
| 3743 | return false; |
| 3744 | |
| 3745 | match_c = fs_matcher->matcher_mask.match_params; |
| 3746 | match_v_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_v, |
| 3747 | outer_headers); |
| 3748 | match_c_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_c, |
| 3749 | outer_headers); |
| 3750 | |
| 3751 | dmac = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 3752 | dmac_47_16); |
| 3753 | dmac_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 3754 | dmac_47_16); |
| 3755 | |
| 3756 | if (is_multicast_ether_addr(dmac) && |
| 3757 | is_multicast_ether_addr(dmac_mask)) |
| 3758 | return true; |
| 3759 | |
| 3760 | ipv4 = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 3761 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 3762 | |
| 3763 | ipv4_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 3764 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 3765 | |
| 3766 | if (ipv4_is_multicast(*(__be32 *)(ipv4)) && |
| 3767 | ipv4_is_multicast(*(__be32 *)(ipv4_mask))) |
| 3768 | return true; |
| 3769 | |
| 3770 | return false; |
| 3771 | } |
| 3772 | |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3773 | struct mlx5_ib_flow_handler * |
| 3774 | mlx5_ib_raw_fs_rule_add(struct mlx5_ib_dev *dev, |
| 3775 | struct mlx5_ib_flow_matcher *fs_matcher, |
| 3776 | void *cmd_in, int inlen, int dest_id, |
| 3777 | int dest_type) |
| 3778 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3779 | struct mlx5_flow_destination *dst; |
| 3780 | struct mlx5_ib_flow_prio *ft_prio; |
| 3781 | int priority = fs_matcher->priority; |
| 3782 | struct mlx5_ib_flow_handler *handler; |
| 3783 | bool mcast; |
| 3784 | int err; |
| 3785 | |
| 3786 | if (fs_matcher->flow_type != MLX5_IB_FLOW_TYPE_NORMAL) |
| 3787 | return ERR_PTR(-EOPNOTSUPP); |
| 3788 | |
| 3789 | if (fs_matcher->priority > MLX5_IB_FLOW_LAST_PRIO) |
| 3790 | return ERR_PTR(-ENOMEM); |
| 3791 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3792 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
| 3793 | if (!dst) |
| 3794 | return ERR_PTR(-ENOMEM); |
| 3795 | |
| 3796 | mcast = raw_fs_is_multicast(fs_matcher, cmd_in); |
| 3797 | mutex_lock(&dev->flow_db->lock); |
| 3798 | |
| 3799 | ft_prio = _get_flow_table(dev, priority, mcast); |
| 3800 | if (IS_ERR(ft_prio)) { |
| 3801 | err = PTR_ERR(ft_prio); |
| 3802 | goto unlock; |
| 3803 | } |
| 3804 | |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame^] | 3805 | if (dest_type == MLX5_FLOW_DESTINATION_TYPE_TIR) { |
| 3806 | dst->type = dest_type; |
| 3807 | dst->tir_num = dest_id; |
| 3808 | } else { |
| 3809 | dst->type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM; |
| 3810 | dst->ft_num = dest_id; |
| 3811 | } |
| 3812 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3813 | handler = _create_raw_flow_rule(dev, ft_prio, dst, fs_matcher, cmd_in, |
| 3814 | inlen); |
| 3815 | |
| 3816 | if (IS_ERR(handler)) { |
| 3817 | err = PTR_ERR(handler); |
| 3818 | goto destroy_ft; |
| 3819 | } |
| 3820 | |
| 3821 | mutex_unlock(&dev->flow_db->lock); |
| 3822 | atomic_inc(&fs_matcher->usecnt); |
| 3823 | handler->flow_matcher = fs_matcher; |
| 3824 | |
| 3825 | kfree(dst); |
| 3826 | |
| 3827 | return handler; |
| 3828 | |
| 3829 | destroy_ft: |
| 3830 | put_flow_table(dev, ft_prio, false); |
| 3831 | unlock: |
| 3832 | mutex_unlock(&dev->flow_db->lock); |
| 3833 | kfree(dst); |
| 3834 | |
| 3835 | return ERR_PTR(err); |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3836 | } |
| 3837 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 3838 | static u32 mlx5_ib_flow_action_flags_to_accel_xfrm_flags(u32 mlx5_flags) |
| 3839 | { |
| 3840 | u32 flags = 0; |
| 3841 | |
| 3842 | if (mlx5_flags & MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA) |
| 3843 | flags |= MLX5_ACCEL_XFRM_FLAG_REQUIRE_METADATA; |
| 3844 | |
| 3845 | return flags; |
| 3846 | } |
| 3847 | |
| 3848 | #define MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA |
| 3849 | static struct ib_flow_action * |
| 3850 | mlx5_ib_create_flow_action_esp(struct ib_device *device, |
| 3851 | const struct ib_flow_action_attrs_esp *attr, |
| 3852 | struct uverbs_attr_bundle *attrs) |
| 3853 | { |
| 3854 | struct mlx5_ib_dev *mdev = to_mdev(device); |
| 3855 | struct ib_uverbs_flow_action_esp_keymat_aes_gcm *aes_gcm; |
| 3856 | struct mlx5_accel_esp_xfrm_attrs accel_attrs = {}; |
| 3857 | struct mlx5_ib_flow_action *action; |
| 3858 | u64 action_flags; |
| 3859 | u64 flags; |
| 3860 | int err = 0; |
| 3861 | |
| 3862 | if (IS_UVERBS_COPY_ERR(uverbs_copy_from(&action_flags, attrs, |
| 3863 | MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS))) |
| 3864 | return ERR_PTR(-EFAULT); |
| 3865 | |
| 3866 | if (action_flags >= (MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED << 1)) |
| 3867 | return ERR_PTR(-EOPNOTSUPP); |
| 3868 | |
| 3869 | flags = mlx5_ib_flow_action_flags_to_accel_xfrm_flags(action_flags); |
| 3870 | |
| 3871 | /* We current only support a subset of the standard features. Only a |
| 3872 | * keymat of type AES_GCM, with icv_len == 16, iv_algo == SEQ and esn |
| 3873 | * (with overlap). Full offload mode isn't supported. |
| 3874 | */ |
| 3875 | if (!attr->keymat || attr->replay || attr->encap || |
| 3876 | attr->spi || attr->seq || attr->tfc_pad || |
| 3877 | attr->hard_limit_pkts || |
| 3878 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 3879 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT))) |
| 3880 | return ERR_PTR(-EOPNOTSUPP); |
| 3881 | |
| 3882 | if (attr->keymat->protocol != |
| 3883 | IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM) |
| 3884 | return ERR_PTR(-EOPNOTSUPP); |
| 3885 | |
| 3886 | aes_gcm = &attr->keymat->keymat.aes_gcm; |
| 3887 | |
| 3888 | if (aes_gcm->icv_len != 16 || |
| 3889 | aes_gcm->iv_algo != IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ) |
| 3890 | return ERR_PTR(-EOPNOTSUPP); |
| 3891 | |
| 3892 | action = kmalloc(sizeof(*action), GFP_KERNEL); |
| 3893 | if (!action) |
| 3894 | return ERR_PTR(-ENOMEM); |
| 3895 | |
| 3896 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 3897 | memcpy(&accel_attrs.keymat.aes_gcm.aes_key, &aes_gcm->aes_key, |
| 3898 | sizeof(accel_attrs.keymat.aes_gcm.aes_key)); |
| 3899 | accel_attrs.keymat.aes_gcm.key_len = aes_gcm->key_len * 8; |
| 3900 | memcpy(&accel_attrs.keymat.aes_gcm.salt, &aes_gcm->salt, |
| 3901 | sizeof(accel_attrs.keymat.aes_gcm.salt)); |
| 3902 | memcpy(&accel_attrs.keymat.aes_gcm.seq_iv, &aes_gcm->iv, |
| 3903 | sizeof(accel_attrs.keymat.aes_gcm.seq_iv)); |
| 3904 | accel_attrs.keymat.aes_gcm.icv_len = aes_gcm->icv_len * 8; |
| 3905 | accel_attrs.keymat.aes_gcm.iv_algo = MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ; |
| 3906 | accel_attrs.keymat_type = MLX5_ACCEL_ESP_KEYMAT_AES_GCM; |
| 3907 | |
| 3908 | accel_attrs.esn = attr->esn; |
| 3909 | if (attr->flags & IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) |
| 3910 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED; |
| 3911 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 3912 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 3913 | |
| 3914 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT) |
| 3915 | accel_attrs.action |= MLX5_ACCEL_ESP_ACTION_ENCRYPT; |
| 3916 | |
| 3917 | action->esp_aes_gcm.ctx = |
| 3918 | mlx5_accel_esp_create_xfrm(mdev->mdev, &accel_attrs, flags); |
| 3919 | if (IS_ERR(action->esp_aes_gcm.ctx)) { |
| 3920 | err = PTR_ERR(action->esp_aes_gcm.ctx); |
| 3921 | goto err_parse; |
| 3922 | } |
| 3923 | |
| 3924 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 3925 | |
| 3926 | return &action->ib_action; |
| 3927 | |
| 3928 | err_parse: |
| 3929 | kfree(action); |
| 3930 | return ERR_PTR(err); |
| 3931 | } |
| 3932 | |
Matan Barak | 349705c | 2018-03-28 09:27:51 +0300 | [diff] [blame] | 3933 | static int |
| 3934 | mlx5_ib_modify_flow_action_esp(struct ib_flow_action *action, |
| 3935 | const struct ib_flow_action_attrs_esp *attr, |
| 3936 | struct uverbs_attr_bundle *attrs) |
| 3937 | { |
| 3938 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 3939 | struct mlx5_accel_esp_xfrm_attrs accel_attrs; |
| 3940 | int err = 0; |
| 3941 | |
| 3942 | if (attr->keymat || attr->replay || attr->encap || |
| 3943 | attr->spi || attr->seq || attr->tfc_pad || |
| 3944 | attr->hard_limit_pkts || |
| 3945 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 3946 | IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS | |
| 3947 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW))) |
| 3948 | return -EOPNOTSUPP; |
| 3949 | |
| 3950 | /* Only the ESN value or the MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP can |
| 3951 | * be modified. |
| 3952 | */ |
| 3953 | if (!(maction->esp_aes_gcm.ib_flags & |
| 3954 | IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) && |
| 3955 | attr->flags & (IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 3956 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW)) |
| 3957 | return -EINVAL; |
| 3958 | |
| 3959 | memcpy(&accel_attrs, &maction->esp_aes_gcm.ctx->attrs, |
| 3960 | sizeof(accel_attrs)); |
| 3961 | |
| 3962 | accel_attrs.esn = attr->esn; |
| 3963 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 3964 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 3965 | else |
| 3966 | accel_attrs.flags &= ~MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 3967 | |
| 3968 | err = mlx5_accel_esp_modify_xfrm(maction->esp_aes_gcm.ctx, |
| 3969 | &accel_attrs); |
| 3970 | if (err) |
| 3971 | return err; |
| 3972 | |
| 3973 | maction->esp_aes_gcm.ib_flags &= |
| 3974 | ~IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 3975 | maction->esp_aes_gcm.ib_flags |= |
| 3976 | attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 3977 | |
| 3978 | return 0; |
| 3979 | } |
| 3980 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 3981 | static int mlx5_ib_destroy_flow_action(struct ib_flow_action *action) |
| 3982 | { |
| 3983 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 3984 | |
| 3985 | switch (action->type) { |
| 3986 | case IB_FLOW_ACTION_ESP: |
| 3987 | /* |
| 3988 | * We only support aes_gcm by now, so we implicitly know this is |
| 3989 | * the underline crypto. |
| 3990 | */ |
| 3991 | mlx5_accel_esp_destroy_xfrm(maction->esp_aes_gcm.ctx); |
| 3992 | break; |
| 3993 | default: |
| 3994 | WARN_ON(true); |
| 3995 | break; |
| 3996 | } |
| 3997 | |
| 3998 | kfree(maction); |
| 3999 | return 0; |
| 4000 | } |
| 4001 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4002 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4003 | { |
| 4004 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4005 | struct mlx5_ib_qp *mqp = to_mqp(ibqp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4006 | int err; |
| 4007 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4008 | if (mqp->flags & MLX5_IB_QP_UNDERLAY) { |
| 4009 | mlx5_ib_dbg(dev, "Attaching a multi cast group to underlay QP is not supported\n"); |
| 4010 | return -EOPNOTSUPP; |
| 4011 | } |
| 4012 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4013 | err = mlx5_core_attach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4014 | if (err) |
| 4015 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
| 4016 | ibqp->qp_num, gid->raw); |
| 4017 | |
| 4018 | return err; |
| 4019 | } |
| 4020 | |
| 4021 | static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4022 | { |
| 4023 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 4024 | int err; |
| 4025 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4026 | err = mlx5_core_detach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4027 | if (err) |
| 4028 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
| 4029 | ibqp->qp_num, gid->raw); |
| 4030 | |
| 4031 | return err; |
| 4032 | } |
| 4033 | |
| 4034 | static int init_node_data(struct mlx5_ib_dev *dev) |
| 4035 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4036 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4037 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4038 | err = mlx5_query_node_desc(dev, dev->ib_dev.node_desc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4039 | if (err) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4040 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4041 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4042 | dev->mdev->rev_id = dev->mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4043 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4044 | return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | static ssize_t show_fw_pages(struct device *device, struct device_attribute *attr, |
| 4048 | char *buf) |
| 4049 | { |
| 4050 | struct mlx5_ib_dev *dev = |
| 4051 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 4052 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4053 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4054 | } |
| 4055 | |
| 4056 | static ssize_t show_reg_pages(struct device *device, |
| 4057 | struct device_attribute *attr, char *buf) |
| 4058 | { |
| 4059 | struct mlx5_ib_dev *dev = |
| 4060 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 4061 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 4062 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | static ssize_t show_hca(struct device *device, struct device_attribute *attr, |
| 4066 | char *buf) |
| 4067 | { |
| 4068 | struct mlx5_ib_dev *dev = |
| 4069 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4070 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4071 | } |
| 4072 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4073 | static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
| 4074 | char *buf) |
| 4075 | { |
| 4076 | struct mlx5_ib_dev *dev = |
| 4077 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4078 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | static ssize_t show_board(struct device *device, struct device_attribute *attr, |
| 4082 | char *buf) |
| 4083 | { |
| 4084 | struct mlx5_ib_dev *dev = |
| 4085 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 4086 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4087 | dev->mdev->board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4091 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 4092 | static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
| 4093 | static DEVICE_ATTR(fw_pages, S_IRUGO, show_fw_pages, NULL); |
| 4094 | static DEVICE_ATTR(reg_pages, S_IRUGO, show_reg_pages, NULL); |
| 4095 | |
| 4096 | static struct device_attribute *mlx5_class_attributes[] = { |
| 4097 | &dev_attr_hw_rev, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4098 | &dev_attr_hca_type, |
| 4099 | &dev_attr_board_id, |
| 4100 | &dev_attr_fw_pages, |
| 4101 | &dev_attr_reg_pages, |
| 4102 | }; |
| 4103 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4104 | static void pkey_change_handler(struct work_struct *work) |
| 4105 | { |
| 4106 | struct mlx5_ib_port_resources *ports = |
| 4107 | container_of(work, struct mlx5_ib_port_resources, |
| 4108 | pkey_change_work); |
| 4109 | |
| 4110 | mutex_lock(&ports->devr->mutex); |
| 4111 | mlx5_ib_gsi_pkey_change(ports->gsi); |
| 4112 | mutex_unlock(&ports->devr->mutex); |
| 4113 | } |
| 4114 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4115 | static void mlx5_ib_handle_internal_error(struct mlx5_ib_dev *ibdev) |
| 4116 | { |
| 4117 | struct mlx5_ib_qp *mqp; |
| 4118 | struct mlx5_ib_cq *send_mcq, *recv_mcq; |
| 4119 | struct mlx5_core_cq *mcq; |
| 4120 | struct list_head cq_armed_list; |
| 4121 | unsigned long flags_qp; |
| 4122 | unsigned long flags_cq; |
| 4123 | unsigned long flags; |
| 4124 | |
| 4125 | INIT_LIST_HEAD(&cq_armed_list); |
| 4126 | |
| 4127 | /* Go over qp list reside on that ibdev, sync with create/destroy qp.*/ |
| 4128 | spin_lock_irqsave(&ibdev->reset_flow_resource_lock, flags); |
| 4129 | list_for_each_entry(mqp, &ibdev->qp_list, qps_list) { |
| 4130 | spin_lock_irqsave(&mqp->sq.lock, flags_qp); |
| 4131 | if (mqp->sq.tail != mqp->sq.head) { |
| 4132 | send_mcq = to_mcq(mqp->ibqp.send_cq); |
| 4133 | spin_lock_irqsave(&send_mcq->lock, flags_cq); |
| 4134 | if (send_mcq->mcq.comp && |
| 4135 | mqp->ibqp.send_cq->comp_handler) { |
| 4136 | if (!send_mcq->mcq.reset_notify_added) { |
| 4137 | send_mcq->mcq.reset_notify_added = 1; |
| 4138 | list_add_tail(&send_mcq->mcq.reset_notify, |
| 4139 | &cq_armed_list); |
| 4140 | } |
| 4141 | } |
| 4142 | spin_unlock_irqrestore(&send_mcq->lock, flags_cq); |
| 4143 | } |
| 4144 | spin_unlock_irqrestore(&mqp->sq.lock, flags_qp); |
| 4145 | spin_lock_irqsave(&mqp->rq.lock, flags_qp); |
| 4146 | /* no handling is needed for SRQ */ |
| 4147 | if (!mqp->ibqp.srq) { |
| 4148 | if (mqp->rq.tail != mqp->rq.head) { |
| 4149 | recv_mcq = to_mcq(mqp->ibqp.recv_cq); |
| 4150 | spin_lock_irqsave(&recv_mcq->lock, flags_cq); |
| 4151 | if (recv_mcq->mcq.comp && |
| 4152 | mqp->ibqp.recv_cq->comp_handler) { |
| 4153 | if (!recv_mcq->mcq.reset_notify_added) { |
| 4154 | recv_mcq->mcq.reset_notify_added = 1; |
| 4155 | list_add_tail(&recv_mcq->mcq.reset_notify, |
| 4156 | &cq_armed_list); |
| 4157 | } |
| 4158 | } |
| 4159 | spin_unlock_irqrestore(&recv_mcq->lock, |
| 4160 | flags_cq); |
| 4161 | } |
| 4162 | } |
| 4163 | spin_unlock_irqrestore(&mqp->rq.lock, flags_qp); |
| 4164 | } |
| 4165 | /*At that point all inflight post send were put to be executed as of we |
| 4166 | * lock/unlock above locks Now need to arm all involved CQs. |
| 4167 | */ |
| 4168 | list_for_each_entry(mcq, &cq_armed_list, reset_notify) { |
| 4169 | mcq->comp(mcq); |
| 4170 | } |
| 4171 | spin_unlock_irqrestore(&ibdev->reset_flow_resource_lock, flags); |
| 4172 | } |
| 4173 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4174 | static void delay_drop_handler(struct work_struct *work) |
| 4175 | { |
| 4176 | int err; |
| 4177 | struct mlx5_ib_delay_drop *delay_drop = |
| 4178 | container_of(work, struct mlx5_ib_delay_drop, |
| 4179 | delay_drop_work); |
| 4180 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 4181 | atomic_inc(&delay_drop->events_cnt); |
| 4182 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4183 | mutex_lock(&delay_drop->lock); |
| 4184 | err = mlx5_core_set_delay_drop(delay_drop->dev->mdev, |
| 4185 | delay_drop->timeout); |
| 4186 | if (err) { |
| 4187 | mlx5_ib_warn(delay_drop->dev, "Failed to set delay drop, timeout=%u\n", |
| 4188 | delay_drop->timeout); |
| 4189 | delay_drop->activate = false; |
| 4190 | } |
| 4191 | mutex_unlock(&delay_drop->lock); |
| 4192 | } |
| 4193 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4194 | static void mlx5_ib_handle_event(struct work_struct *_work) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4195 | { |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4196 | struct mlx5_ib_event_work *work = |
| 4197 | container_of(_work, struct mlx5_ib_event_work, work); |
| 4198 | struct mlx5_ib_dev *ibdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4199 | struct ib_event ibev; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4200 | bool fatal = false; |
Daniel Jurgens | aba4621 | 2018-02-25 13:39:53 +0200 | [diff] [blame] | 4201 | u8 port = (u8)work->param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4202 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4203 | if (mlx5_core_is_mp_slave(work->dev)) { |
| 4204 | ibdev = mlx5_ib_get_ibdev_from_mpi(work->context); |
| 4205 | if (!ibdev) |
| 4206 | goto out; |
| 4207 | } else { |
| 4208 | ibdev = work->context; |
| 4209 | } |
| 4210 | |
| 4211 | switch (work->event) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4212 | case MLX5_DEV_EVENT_SYS_ERROR: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4213 | ibev.event = IB_EVENT_DEVICE_FATAL; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4214 | mlx5_ib_handle_internal_error(ibdev); |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4215 | fatal = true; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4216 | break; |
| 4217 | |
| 4218 | case MLX5_DEV_EVENT_PORT_UP: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4219 | case MLX5_DEV_EVENT_PORT_DOWN: |
Noa Osherovich | 2788cf3 | 2016-06-04 15:15:29 +0300 | [diff] [blame] | 4220 | case MLX5_DEV_EVENT_PORT_INITIALIZED: |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 4221 | /* In RoCE, port up/down events are handled in |
| 4222 | * mlx5_netdev_event(). |
| 4223 | */ |
| 4224 | if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
| 4225 | IB_LINK_LAYER_ETHERNET) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4226 | goto out; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 4227 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4228 | ibev.event = (work->event == MLX5_DEV_EVENT_PORT_UP) ? |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 4229 | IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4230 | break; |
| 4231 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4232 | case MLX5_DEV_EVENT_LID_CHANGE: |
| 4233 | ibev.event = IB_EVENT_LID_CHANGE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4234 | break; |
| 4235 | |
| 4236 | case MLX5_DEV_EVENT_PKEY_CHANGE: |
| 4237 | ibev.event = IB_EVENT_PKEY_CHANGE; |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4238 | schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4239 | break; |
| 4240 | |
| 4241 | case MLX5_DEV_EVENT_GUID_CHANGE: |
| 4242 | ibev.event = IB_EVENT_GID_CHANGE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4243 | break; |
| 4244 | |
| 4245 | case MLX5_DEV_EVENT_CLIENT_REREG: |
| 4246 | ibev.event = IB_EVENT_CLIENT_REREGISTER; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4247 | break; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4248 | case MLX5_DEV_EVENT_DELAY_DROP_TIMEOUT: |
| 4249 | schedule_work(&ibdev->delay_drop.delay_drop_work); |
| 4250 | goto out; |
Saeed Mahameed | bdc3792 | 2016-09-29 19:35:38 +0300 | [diff] [blame] | 4251 | default: |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4252 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | ibev.device = &ibdev->ib_dev; |
| 4256 | ibev.element.port_num = port; |
| 4257 | |
Daniel Jurgens | aba4621 | 2018-02-25 13:39:53 +0200 | [diff] [blame] | 4258 | if (!rdma_is_port_valid(&ibdev->ib_dev, port)) { |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 4259 | mlx5_ib_warn(ibdev, "warning: event on port %d\n", port); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4260 | goto out; |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 4261 | } |
| 4262 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4263 | if (ibdev->ib_active) |
| 4264 | ib_dispatch_event(&ibev); |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4265 | |
| 4266 | if (fatal) |
| 4267 | ibdev->ib_active = false; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4268 | out: |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4269 | kfree(work); |
| 4270 | } |
| 4271 | |
| 4272 | static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context, |
| 4273 | enum mlx5_dev_event event, unsigned long param) |
| 4274 | { |
| 4275 | struct mlx5_ib_event_work *work; |
| 4276 | |
| 4277 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4278 | if (!work) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4279 | return; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4280 | |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4281 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
| 4282 | work->dev = dev; |
| 4283 | work->param = param; |
| 4284 | work->context = context; |
| 4285 | work->event = event; |
| 4286 | |
| 4287 | queue_work(mlx5_ib_event_wq, &work->work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4288 | } |
| 4289 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4290 | static int set_has_smi_cap(struct mlx5_ib_dev *dev) |
| 4291 | { |
| 4292 | struct mlx5_hca_vport_context vport_ctx; |
| 4293 | int err; |
| 4294 | int port; |
| 4295 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4296 | for (port = 1; port <= dev->num_ports; port++) { |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4297 | dev->mdev->port_caps[port - 1].has_smi = false; |
| 4298 | if (MLX5_CAP_GEN(dev->mdev, port_type) == |
| 4299 | MLX5_CAP_PORT_TYPE_IB) { |
| 4300 | if (MLX5_CAP_GEN(dev->mdev, ib_virt)) { |
| 4301 | err = mlx5_query_hca_vport_context(dev->mdev, 0, |
| 4302 | port, 0, |
| 4303 | &vport_ctx); |
| 4304 | if (err) { |
| 4305 | mlx5_ib_err(dev, "query_hca_vport_context for port=%d failed %d\n", |
| 4306 | port, err); |
| 4307 | return err; |
| 4308 | } |
| 4309 | dev->mdev->port_caps[port - 1].has_smi = |
| 4310 | vport_ctx.has_smi; |
| 4311 | } else { |
| 4312 | dev->mdev->port_caps[port - 1].has_smi = true; |
| 4313 | } |
| 4314 | } |
| 4315 | } |
| 4316 | return 0; |
| 4317 | } |
| 4318 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4319 | static void get_ext_port_caps(struct mlx5_ib_dev *dev) |
| 4320 | { |
| 4321 | int port; |
| 4322 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4323 | for (port = 1; port <= dev->num_ports; port++) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4324 | mlx5_query_ext_port_caps(dev, port); |
| 4325 | } |
| 4326 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4327 | static int get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4328 | { |
| 4329 | struct ib_device_attr *dprops = NULL; |
| 4330 | struct ib_port_attr *pprops = NULL; |
Dan Carpenter | f614fc1 | 2015-01-12 11:56:58 +0300 | [diff] [blame] | 4331 | int err = -ENOMEM; |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4332 | struct ib_udata uhw = {.inlen = 0, .outlen = 0}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4333 | |
| 4334 | pprops = kmalloc(sizeof(*pprops), GFP_KERNEL); |
| 4335 | if (!pprops) |
| 4336 | goto out; |
| 4337 | |
| 4338 | dprops = kmalloc(sizeof(*dprops), GFP_KERNEL); |
| 4339 | if (!dprops) |
| 4340 | goto out; |
| 4341 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4342 | err = set_has_smi_cap(dev); |
| 4343 | if (err) |
| 4344 | goto out; |
| 4345 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4346 | err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4347 | if (err) { |
| 4348 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
| 4349 | goto out; |
| 4350 | } |
| 4351 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4352 | memset(pprops, 0, sizeof(*pprops)); |
| 4353 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
| 4354 | if (err) { |
| 4355 | mlx5_ib_warn(dev, "query_port %d failed %d\n", |
| 4356 | port, err); |
| 4357 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4358 | } |
| 4359 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4360 | dev->mdev->port_caps[port - 1].pkey_table_len = |
| 4361 | dprops->max_pkeys; |
| 4362 | dev->mdev->port_caps[port - 1].gid_table_len = |
| 4363 | pprops->gid_tbl_len; |
| 4364 | mlx5_ib_dbg(dev, "port %d: pkey_table_len %d, gid_table_len %d\n", |
| 4365 | port, dprops->max_pkeys, pprops->gid_tbl_len); |
| 4366 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4367 | out: |
| 4368 | kfree(pprops); |
| 4369 | kfree(dprops); |
| 4370 | |
| 4371 | return err; |
| 4372 | } |
| 4373 | |
| 4374 | static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
| 4375 | { |
| 4376 | int err; |
| 4377 | |
| 4378 | err = mlx5_mr_cache_cleanup(dev); |
| 4379 | if (err) |
| 4380 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
| 4381 | |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4382 | if (dev->umrc.qp) |
| 4383 | mlx5_ib_destroy_qp(dev->umrc.qp); |
| 4384 | if (dev->umrc.cq) |
| 4385 | ib_free_cq(dev->umrc.cq); |
| 4386 | if (dev->umrc.pd) |
| 4387 | ib_dealloc_pd(dev->umrc.pd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | enum { |
| 4391 | MAX_UMR_WR = 128, |
| 4392 | }; |
| 4393 | |
| 4394 | static int create_umr_res(struct mlx5_ib_dev *dev) |
| 4395 | { |
| 4396 | struct ib_qp_init_attr *init_attr = NULL; |
| 4397 | struct ib_qp_attr *attr = NULL; |
| 4398 | struct ib_pd *pd; |
| 4399 | struct ib_cq *cq; |
| 4400 | struct ib_qp *qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4401 | int ret; |
| 4402 | |
| 4403 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| 4404 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 4405 | if (!attr || !init_attr) { |
| 4406 | ret = -ENOMEM; |
| 4407 | goto error_0; |
| 4408 | } |
| 4409 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 4410 | pd = ib_alloc_pd(&dev->ib_dev, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4411 | if (IS_ERR(pd)) { |
| 4412 | mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); |
| 4413 | ret = PTR_ERR(pd); |
| 4414 | goto error_0; |
| 4415 | } |
| 4416 | |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4417 | 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] | 4418 | if (IS_ERR(cq)) { |
| 4419 | mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); |
| 4420 | ret = PTR_ERR(cq); |
| 4421 | goto error_2; |
| 4422 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4423 | |
| 4424 | init_attr->send_cq = cq; |
| 4425 | init_attr->recv_cq = cq; |
| 4426 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
| 4427 | init_attr->cap.max_send_wr = MAX_UMR_WR; |
| 4428 | init_attr->cap.max_send_sge = 1; |
| 4429 | init_attr->qp_type = MLX5_IB_QPT_REG_UMR; |
| 4430 | init_attr->port_num = 1; |
| 4431 | qp = mlx5_ib_create_qp(pd, init_attr, NULL); |
| 4432 | if (IS_ERR(qp)) { |
| 4433 | mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); |
| 4434 | ret = PTR_ERR(qp); |
| 4435 | goto error_3; |
| 4436 | } |
| 4437 | qp->device = &dev->ib_dev; |
| 4438 | qp->real_qp = qp; |
| 4439 | qp->uobject = NULL; |
| 4440 | qp->qp_type = MLX5_IB_QPT_REG_UMR; |
Majd Dibbiny | 31fde03 | 2017-10-30 14:23:13 +0200 | [diff] [blame] | 4441 | qp->send_cq = init_attr->send_cq; |
| 4442 | qp->recv_cq = init_attr->recv_cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4443 | |
| 4444 | attr->qp_state = IB_QPS_INIT; |
| 4445 | attr->port_num = 1; |
| 4446 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX | |
| 4447 | IB_QP_PORT, NULL); |
| 4448 | if (ret) { |
| 4449 | mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); |
| 4450 | goto error_4; |
| 4451 | } |
| 4452 | |
| 4453 | memset(attr, 0, sizeof(*attr)); |
| 4454 | attr->qp_state = IB_QPS_RTR; |
| 4455 | attr->path_mtu = IB_MTU_256; |
| 4456 | |
| 4457 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4458 | if (ret) { |
| 4459 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); |
| 4460 | goto error_4; |
| 4461 | } |
| 4462 | |
| 4463 | memset(attr, 0, sizeof(*attr)); |
| 4464 | attr->qp_state = IB_QPS_RTS; |
| 4465 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4466 | if (ret) { |
| 4467 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); |
| 4468 | goto error_4; |
| 4469 | } |
| 4470 | |
| 4471 | dev->umrc.qp = qp; |
| 4472 | dev->umrc.cq = cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4473 | dev->umrc.pd = pd; |
| 4474 | |
| 4475 | sema_init(&dev->umrc.sem, MAX_UMR_WR); |
| 4476 | ret = mlx5_mr_cache_init(dev); |
| 4477 | if (ret) { |
| 4478 | mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); |
| 4479 | goto error_4; |
| 4480 | } |
| 4481 | |
| 4482 | kfree(attr); |
| 4483 | kfree(init_attr); |
| 4484 | |
| 4485 | return 0; |
| 4486 | |
| 4487 | error_4: |
| 4488 | mlx5_ib_destroy_qp(qp); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4489 | dev->umrc.qp = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4490 | |
| 4491 | error_3: |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4492 | ib_free_cq(cq); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4493 | dev->umrc.cq = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4494 | |
| 4495 | error_2: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4496 | ib_dealloc_pd(pd); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4497 | dev->umrc.pd = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4498 | |
| 4499 | error_0: |
| 4500 | kfree(attr); |
| 4501 | kfree(init_attr); |
| 4502 | return ret; |
| 4503 | } |
| 4504 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 4505 | static u8 mlx5_get_umr_fence(u8 umr_fence_cap) |
| 4506 | { |
| 4507 | switch (umr_fence_cap) { |
| 4508 | case MLX5_CAP_UMR_FENCE_NONE: |
| 4509 | return MLX5_FENCE_MODE_NONE; |
| 4510 | case MLX5_CAP_UMR_FENCE_SMALL: |
| 4511 | return MLX5_FENCE_MODE_INITIATOR_SMALL; |
| 4512 | default: |
| 4513 | return MLX5_FENCE_MODE_STRONG_ORDERING; |
| 4514 | } |
| 4515 | } |
| 4516 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4517 | static int create_dev_resources(struct mlx5_ib_resources *devr) |
| 4518 | { |
| 4519 | struct ib_srq_init_attr attr; |
| 4520 | struct mlx5_ib_dev *dev; |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 4521 | struct ib_cq_init_attr cq_attr = {.cqe = 1}; |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4522 | int port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4523 | int ret = 0; |
| 4524 | |
| 4525 | dev = container_of(devr, struct mlx5_ib_dev, devr); |
| 4526 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4527 | mutex_init(&devr->mutex); |
| 4528 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4529 | devr->p0 = mlx5_ib_alloc_pd(&dev->ib_dev, NULL, NULL); |
| 4530 | if (IS_ERR(devr->p0)) { |
| 4531 | ret = PTR_ERR(devr->p0); |
| 4532 | goto error0; |
| 4533 | } |
| 4534 | devr->p0->device = &dev->ib_dev; |
| 4535 | devr->p0->uobject = NULL; |
| 4536 | atomic_set(&devr->p0->usecnt, 0); |
| 4537 | |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 4538 | 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] | 4539 | if (IS_ERR(devr->c0)) { |
| 4540 | ret = PTR_ERR(devr->c0); |
| 4541 | goto error1; |
| 4542 | } |
| 4543 | devr->c0->device = &dev->ib_dev; |
| 4544 | devr->c0->uobject = NULL; |
| 4545 | devr->c0->comp_handler = NULL; |
| 4546 | devr->c0->event_handler = NULL; |
| 4547 | devr->c0->cq_context = NULL; |
| 4548 | atomic_set(&devr->c0->usecnt, 0); |
| 4549 | |
| 4550 | devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 4551 | if (IS_ERR(devr->x0)) { |
| 4552 | ret = PTR_ERR(devr->x0); |
| 4553 | goto error2; |
| 4554 | } |
| 4555 | devr->x0->device = &dev->ib_dev; |
| 4556 | devr->x0->inode = NULL; |
| 4557 | atomic_set(&devr->x0->usecnt, 0); |
| 4558 | mutex_init(&devr->x0->tgt_qp_mutex); |
| 4559 | INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
| 4560 | |
| 4561 | devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 4562 | if (IS_ERR(devr->x1)) { |
| 4563 | ret = PTR_ERR(devr->x1); |
| 4564 | goto error3; |
| 4565 | } |
| 4566 | devr->x1->device = &dev->ib_dev; |
| 4567 | devr->x1->inode = NULL; |
| 4568 | atomic_set(&devr->x1->usecnt, 0); |
| 4569 | mutex_init(&devr->x1->tgt_qp_mutex); |
| 4570 | INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
| 4571 | |
| 4572 | memset(&attr, 0, sizeof(attr)); |
| 4573 | attr.attr.max_sge = 1; |
| 4574 | attr.attr.max_wr = 1; |
| 4575 | attr.srq_type = IB_SRQT_XRC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4576 | attr.ext.cq = devr->c0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4577 | attr.ext.xrc.xrcd = devr->x0; |
| 4578 | |
| 4579 | devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 4580 | if (IS_ERR(devr->s0)) { |
| 4581 | ret = PTR_ERR(devr->s0); |
| 4582 | goto error4; |
| 4583 | } |
| 4584 | devr->s0->device = &dev->ib_dev; |
| 4585 | devr->s0->pd = devr->p0; |
| 4586 | devr->s0->uobject = NULL; |
| 4587 | devr->s0->event_handler = NULL; |
| 4588 | devr->s0->srq_context = NULL; |
| 4589 | devr->s0->srq_type = IB_SRQT_XRC; |
| 4590 | devr->s0->ext.xrc.xrcd = devr->x0; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4591 | devr->s0->ext.cq = devr->c0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4592 | atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4593 | atomic_inc(&devr->s0->ext.cq->usecnt); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4594 | atomic_inc(&devr->p0->usecnt); |
| 4595 | atomic_set(&devr->s0->usecnt, 0); |
| 4596 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4597 | memset(&attr, 0, sizeof(attr)); |
| 4598 | attr.attr.max_sge = 1; |
| 4599 | attr.attr.max_wr = 1; |
| 4600 | attr.srq_type = IB_SRQT_BASIC; |
| 4601 | devr->s1 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 4602 | if (IS_ERR(devr->s1)) { |
| 4603 | ret = PTR_ERR(devr->s1); |
| 4604 | goto error5; |
| 4605 | } |
| 4606 | devr->s1->device = &dev->ib_dev; |
| 4607 | devr->s1->pd = devr->p0; |
| 4608 | devr->s1->uobject = NULL; |
| 4609 | devr->s1->event_handler = NULL; |
| 4610 | devr->s1->srq_context = NULL; |
| 4611 | devr->s1->srq_type = IB_SRQT_BASIC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4612 | devr->s1->ext.cq = devr->c0; |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4613 | atomic_inc(&devr->p0->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4614 | atomic_set(&devr->s1->usecnt, 0); |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4615 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4616 | for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) { |
| 4617 | INIT_WORK(&devr->ports[port].pkey_change_work, |
| 4618 | pkey_change_handler); |
| 4619 | devr->ports[port].devr = devr; |
| 4620 | } |
| 4621 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4622 | return 0; |
| 4623 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4624 | error5: |
| 4625 | mlx5_ib_destroy_srq(devr->s0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4626 | error4: |
| 4627 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 4628 | error3: |
| 4629 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 4630 | error2: |
| 4631 | mlx5_ib_destroy_cq(devr->c0); |
| 4632 | error1: |
| 4633 | mlx5_ib_dealloc_pd(devr->p0); |
| 4634 | error0: |
| 4635 | return ret; |
| 4636 | } |
| 4637 | |
| 4638 | static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
| 4639 | { |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4640 | struct mlx5_ib_dev *dev = |
| 4641 | container_of(devr, struct mlx5_ib_dev, devr); |
| 4642 | int port; |
| 4643 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4644 | mlx5_ib_destroy_srq(devr->s1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4645 | mlx5_ib_destroy_srq(devr->s0); |
| 4646 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 4647 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 4648 | mlx5_ib_destroy_cq(devr->c0); |
| 4649 | mlx5_ib_dealloc_pd(devr->p0); |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4650 | |
| 4651 | /* Make sure no change P_Key work items are still executing */ |
| 4652 | for (port = 0; port < dev->num_ports; ++port) |
| 4653 | cancel_work_sync(&devr->ports[port].pkey_change_work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4654 | } |
| 4655 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4656 | static u32 get_core_cap_flags(struct ib_device *ibdev, |
| 4657 | struct mlx5_hca_vport_context *rep) |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4658 | { |
| 4659 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 4660 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, 1); |
| 4661 | u8 l3_type_cap = MLX5_CAP_ROCE(dev->mdev, l3_type); |
| 4662 | u8 roce_version_cap = MLX5_CAP_ROCE(dev->mdev, roce_version); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 4663 | bool raw_support = !mlx5_core_mp_enabled(dev->mdev); |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4664 | u32 ret = 0; |
| 4665 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4666 | if (rep->grh_required) |
| 4667 | ret |= RDMA_CORE_CAP_IB_GRH_REQUIRED; |
| 4668 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4669 | if (ll == IB_LINK_LAYER_INFINIBAND) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4670 | return ret | RDMA_CORE_PORT_IBA_IB; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4671 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 4672 | if (raw_support) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4673 | ret |= RDMA_CORE_PORT_RAW_PACKET; |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4674 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4675 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV4_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4676 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4677 | |
| 4678 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV6_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4679 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4680 | |
| 4681 | if (roce_version_cap & MLX5_ROCE_VERSION_1_CAP) |
| 4682 | ret |= RDMA_CORE_PORT_IBA_ROCE; |
| 4683 | |
| 4684 | if (roce_version_cap & MLX5_ROCE_VERSION_2_CAP) |
| 4685 | ret |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; |
| 4686 | |
| 4687 | return ret; |
| 4688 | } |
| 4689 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4690 | static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 4691 | struct ib_port_immutable *immutable) |
| 4692 | { |
| 4693 | struct ib_port_attr attr; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4694 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 4695 | 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] | 4696 | struct mlx5_hca_vport_context rep = {0}; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4697 | int err; |
| 4698 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 4699 | err = ib_query_port(ibdev, port_num, &attr); |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4700 | if (err) |
| 4701 | return err; |
| 4702 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4703 | if (ll == IB_LINK_LAYER_INFINIBAND) { |
| 4704 | err = mlx5_query_hca_vport_context(dev->mdev, 0, port_num, 0, |
| 4705 | &rep); |
| 4706 | if (err) |
| 4707 | return err; |
| 4708 | } |
| 4709 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4710 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 4711 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4712 | immutable->core_cap_flags = get_core_cap_flags(ibdev, &rep); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4713 | if ((ll == IB_LINK_LAYER_INFINIBAND) || MLX5_CAP_GEN(dev->mdev, roce)) |
| 4714 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4715 | |
| 4716 | return 0; |
| 4717 | } |
| 4718 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 4719 | static int mlx5_port_rep_immutable(struct ib_device *ibdev, u8 port_num, |
| 4720 | struct ib_port_immutable *immutable) |
| 4721 | { |
| 4722 | struct ib_port_attr attr; |
| 4723 | int err; |
| 4724 | |
| 4725 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 4726 | |
| 4727 | err = ib_query_port(ibdev, port_num, &attr); |
| 4728 | if (err) |
| 4729 | return err; |
| 4730 | |
| 4731 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 4732 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 4733 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 4734 | |
| 4735 | return 0; |
| 4736 | } |
| 4737 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 4738 | static void get_dev_fw_str(struct ib_device *ibdev, char *str) |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 4739 | { |
| 4740 | struct mlx5_ib_dev *dev = |
| 4741 | container_of(ibdev, struct mlx5_ib_dev, ib_dev); |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 4742 | snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%04d", |
| 4743 | fw_rev_maj(dev->mdev), fw_rev_min(dev->mdev), |
| 4744 | fw_rev_sub(dev->mdev)); |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 4745 | } |
| 4746 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4747 | static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4748 | { |
| 4749 | struct mlx5_core_dev *mdev = dev->mdev; |
| 4750 | struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(mdev, |
| 4751 | MLX5_FLOW_NAMESPACE_LAG); |
| 4752 | struct mlx5_flow_table *ft; |
| 4753 | int err; |
| 4754 | |
| 4755 | if (!ns || !mlx5_lag_is_active(mdev)) |
| 4756 | return 0; |
| 4757 | |
| 4758 | err = mlx5_cmd_create_vport_lag(mdev); |
| 4759 | if (err) |
| 4760 | return err; |
| 4761 | |
| 4762 | ft = mlx5_create_lag_demux_flow_table(ns, 0, 0); |
| 4763 | if (IS_ERR(ft)) { |
| 4764 | err = PTR_ERR(ft); |
| 4765 | goto err_destroy_vport_lag; |
| 4766 | } |
| 4767 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 4768 | dev->flow_db->lag_demux_ft = ft; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4769 | return 0; |
| 4770 | |
| 4771 | err_destroy_vport_lag: |
| 4772 | mlx5_cmd_destroy_vport_lag(mdev); |
| 4773 | return err; |
| 4774 | } |
| 4775 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4776 | static void mlx5_eth_lag_cleanup(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4777 | { |
| 4778 | struct mlx5_core_dev *mdev = dev->mdev; |
| 4779 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 4780 | if (dev->flow_db->lag_demux_ft) { |
| 4781 | mlx5_destroy_flow_table(dev->flow_db->lag_demux_ft); |
| 4782 | dev->flow_db->lag_demux_ft = NULL; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4783 | |
| 4784 | mlx5_cmd_destroy_vport_lag(mdev); |
| 4785 | } |
| 4786 | } |
| 4787 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 4788 | 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] | 4789 | { |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4790 | int err; |
| 4791 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 4792 | dev->roce[port_num].nb.notifier_call = mlx5_netdev_event; |
| 4793 | err = register_netdevice_notifier(&dev->roce[port_num].nb); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 4794 | if (err) { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 4795 | dev->roce[port_num].nb.notifier_call = NULL; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4796 | return err; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 4797 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4798 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 4799 | return 0; |
| 4800 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4801 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 4802 | 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] | 4803 | { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 4804 | if (dev->roce[port_num].nb.notifier_call) { |
| 4805 | unregister_netdevice_notifier(&dev->roce[port_num].nb); |
| 4806 | dev->roce[port_num].nb.notifier_call = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4807 | } |
| 4808 | } |
| 4809 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 4810 | static int mlx5_enable_eth(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4811 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4812 | int err; |
| 4813 | |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4814 | if (MLX5_CAP_GEN(dev->mdev, roce)) { |
| 4815 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 4816 | if (err) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 4817 | return err; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4818 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4819 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4820 | err = mlx5_eth_lag_init(dev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4821 | if (err) |
| 4822 | goto err_disable_roce; |
| 4823 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4824 | return 0; |
| 4825 | |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4826 | err_disable_roce: |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4827 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 4828 | mlx5_nic_vport_disable_roce(dev->mdev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4829 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4830 | return err; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 4831 | } |
| 4832 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4833 | static void mlx5_disable_eth(struct mlx5_ib_dev *dev) |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 4834 | { |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4835 | mlx5_eth_lag_cleanup(dev); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4836 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 4837 | mlx5_nic_vport_disable_roce(dev->mdev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 4838 | } |
| 4839 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4840 | struct mlx5_ib_counter { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4841 | const char *name; |
| 4842 | size_t offset; |
| 4843 | }; |
| 4844 | |
| 4845 | #define INIT_Q_COUNTER(_name) \ |
| 4846 | { .name = #_name, .offset = MLX5_BYTE_OFF(query_q_counter_out, _name)} |
| 4847 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4848 | static const struct mlx5_ib_counter basic_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4849 | INIT_Q_COUNTER(rx_write_requests), |
| 4850 | INIT_Q_COUNTER(rx_read_requests), |
| 4851 | INIT_Q_COUNTER(rx_atomic_requests), |
| 4852 | INIT_Q_COUNTER(out_of_buffer), |
| 4853 | }; |
| 4854 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4855 | static const struct mlx5_ib_counter out_of_seq_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4856 | INIT_Q_COUNTER(out_of_sequence), |
| 4857 | }; |
| 4858 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4859 | static const struct mlx5_ib_counter retrans_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4860 | INIT_Q_COUNTER(duplicate_request), |
| 4861 | INIT_Q_COUNTER(rnr_nak_retry_err), |
| 4862 | INIT_Q_COUNTER(packet_seq_err), |
| 4863 | INIT_Q_COUNTER(implied_nak_seq_err), |
| 4864 | INIT_Q_COUNTER(local_ack_timeout_err), |
| 4865 | }; |
| 4866 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4867 | #define INIT_CONG_COUNTER(_name) \ |
| 4868 | { .name = #_name, .offset = \ |
| 4869 | MLX5_BYTE_OFF(query_cong_statistics_out, _name ## _high)} |
| 4870 | |
| 4871 | static const struct mlx5_ib_counter cong_cnts[] = { |
| 4872 | INIT_CONG_COUNTER(rp_cnp_ignored), |
| 4873 | INIT_CONG_COUNTER(rp_cnp_handled), |
| 4874 | INIT_CONG_COUNTER(np_ecn_marked_roce_packets), |
| 4875 | INIT_CONG_COUNTER(np_cnp_sent), |
| 4876 | }; |
| 4877 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 4878 | static const struct mlx5_ib_counter extended_err_cnts[] = { |
| 4879 | INIT_Q_COUNTER(resp_local_length_error), |
| 4880 | INIT_Q_COUNTER(resp_cqe_error), |
| 4881 | INIT_Q_COUNTER(req_cqe_error), |
| 4882 | INIT_Q_COUNTER(req_remote_invalid_request), |
| 4883 | INIT_Q_COUNTER(req_remote_access_errors), |
| 4884 | INIT_Q_COUNTER(resp_remote_access_errors), |
| 4885 | INIT_Q_COUNTER(resp_cqe_flush_error), |
| 4886 | INIT_Q_COUNTER(req_cqe_flush_error), |
| 4887 | }; |
| 4888 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 4889 | #define INIT_EXT_PPCNT_COUNTER(_name) \ |
| 4890 | { .name = #_name, .offset = \ |
| 4891 | MLX5_BYTE_OFF(ppcnt_reg, \ |
| 4892 | counter_set.eth_extended_cntrs_grp_data_layout._name##_high)} |
| 4893 | |
| 4894 | static const struct mlx5_ib_counter ext_ppcnt_cnts[] = { |
| 4895 | INIT_EXT_PPCNT_COUNTER(rx_icrc_encapsulated), |
| 4896 | }; |
| 4897 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4898 | static void mlx5_ib_dealloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 4899 | { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 4900 | int i; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 4901 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4902 | for (i = 0; i < dev->num_ports; i++) { |
Parav Pandit | 921c0f5 | 2018-07-08 13:40:30 +0300 | [diff] [blame] | 4903 | if (dev->port[i].cnts.set_id_valid) |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 4904 | mlx5_core_dealloc_q_counter(dev->mdev, |
| 4905 | dev->port[i].cnts.set_id); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4906 | kfree(dev->port[i].cnts.names); |
| 4907 | kfree(dev->port[i].cnts.offsets); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4908 | } |
| 4909 | } |
| 4910 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4911 | static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, |
| 4912 | struct mlx5_ib_counters *cnts) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4913 | { |
| 4914 | u32 num_counters; |
| 4915 | |
| 4916 | num_counters = ARRAY_SIZE(basic_q_cnts); |
| 4917 | |
| 4918 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) |
| 4919 | num_counters += ARRAY_SIZE(out_of_seq_q_cnts); |
| 4920 | |
| 4921 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) |
| 4922 | num_counters += ARRAY_SIZE(retrans_q_cnts); |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 4923 | |
| 4924 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) |
| 4925 | num_counters += ARRAY_SIZE(extended_err_cnts); |
| 4926 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4927 | cnts->num_q_counters = num_counters; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4928 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4929 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 4930 | cnts->num_cong_counters = ARRAY_SIZE(cong_cnts); |
| 4931 | num_counters += ARRAY_SIZE(cong_cnts); |
| 4932 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 4933 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 4934 | cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts); |
| 4935 | num_counters += ARRAY_SIZE(ext_ppcnt_cnts); |
| 4936 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4937 | cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL); |
| 4938 | if (!cnts->names) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4939 | return -ENOMEM; |
| 4940 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4941 | cnts->offsets = kcalloc(num_counters, |
| 4942 | sizeof(cnts->offsets), GFP_KERNEL); |
| 4943 | if (!cnts->offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4944 | goto err_names; |
| 4945 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4946 | return 0; |
| 4947 | |
| 4948 | err_names: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4949 | kfree(cnts->names); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 4950 | cnts->names = NULL; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4951 | return -ENOMEM; |
| 4952 | } |
| 4953 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4954 | static void mlx5_ib_fill_counters(struct mlx5_ib_dev *dev, |
| 4955 | const char **names, |
| 4956 | size_t *offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4957 | { |
| 4958 | int i; |
| 4959 | int j = 0; |
| 4960 | |
| 4961 | for (i = 0; i < ARRAY_SIZE(basic_q_cnts); i++, j++) { |
| 4962 | names[j] = basic_q_cnts[i].name; |
| 4963 | offsets[j] = basic_q_cnts[i].offset; |
| 4964 | } |
| 4965 | |
| 4966 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) { |
| 4967 | for (i = 0; i < ARRAY_SIZE(out_of_seq_q_cnts); i++, j++) { |
| 4968 | names[j] = out_of_seq_q_cnts[i].name; |
| 4969 | offsets[j] = out_of_seq_q_cnts[i].offset; |
| 4970 | } |
| 4971 | } |
| 4972 | |
| 4973 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) { |
| 4974 | for (i = 0; i < ARRAY_SIZE(retrans_q_cnts); i++, j++) { |
| 4975 | names[j] = retrans_q_cnts[i].name; |
| 4976 | offsets[j] = retrans_q_cnts[i].offset; |
| 4977 | } |
| 4978 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4979 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 4980 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) { |
| 4981 | for (i = 0; i < ARRAY_SIZE(extended_err_cnts); i++, j++) { |
| 4982 | names[j] = extended_err_cnts[i].name; |
| 4983 | offsets[j] = extended_err_cnts[i].offset; |
| 4984 | } |
| 4985 | } |
| 4986 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4987 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 4988 | for (i = 0; i < ARRAY_SIZE(cong_cnts); i++, j++) { |
| 4989 | names[j] = cong_cnts[i].name; |
| 4990 | offsets[j] = cong_cnts[i].offset; |
| 4991 | } |
| 4992 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 4993 | |
| 4994 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 4995 | for (i = 0; i < ARRAY_SIZE(ext_ppcnt_cnts); i++, j++) { |
| 4996 | names[j] = ext_ppcnt_cnts[i].name; |
| 4997 | offsets[j] = ext_ppcnt_cnts[i].offset; |
| 4998 | } |
| 4999 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5000 | } |
| 5001 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5002 | static int mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5003 | { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5004 | int err = 0; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5005 | int i; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5006 | |
| 5007 | for (i = 0; i < dev->num_ports; i++) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5008 | err = __mlx5_ib_alloc_counters(dev, &dev->port[i].cnts); |
| 5009 | if (err) |
| 5010 | goto err_alloc; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5011 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5012 | mlx5_ib_fill_counters(dev, dev->port[i].cnts.names, |
| 5013 | dev->port[i].cnts.offsets); |
| 5014 | |
| 5015 | err = mlx5_core_alloc_q_counter(dev->mdev, |
| 5016 | &dev->port[i].cnts.set_id); |
| 5017 | if (err) { |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5018 | mlx5_ib_warn(dev, |
| 5019 | "couldn't allocate queue counter for port %d, err %d\n", |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5020 | i + 1, err); |
| 5021 | goto err_alloc; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5022 | } |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5023 | dev->port[i].cnts.set_id_valid = true; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | return 0; |
| 5027 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5028 | err_alloc: |
| 5029 | mlx5_ib_dealloc_counters(dev); |
| 5030 | return err; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5031 | } |
| 5032 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5033 | static struct rdma_hw_stats *mlx5_ib_alloc_hw_stats(struct ib_device *ibdev, |
| 5034 | u8 port_num) |
| 5035 | { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5036 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5037 | struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5038 | |
| 5039 | /* We support only per port stats */ |
| 5040 | if (port_num == 0) |
| 5041 | return NULL; |
| 5042 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5043 | return rdma_alloc_hw_stats_struct(port->cnts.names, |
| 5044 | port->cnts.num_q_counters + |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5045 | port->cnts.num_cong_counters + |
| 5046 | port->cnts.num_ext_ppcnt_counters, |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5047 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 5048 | } |
| 5049 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5050 | static int mlx5_ib_query_q_counters(struct mlx5_core_dev *mdev, |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5051 | struct mlx5_ib_port *port, |
| 5052 | struct rdma_hw_stats *stats) |
| 5053 | { |
| 5054 | int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); |
| 5055 | void *out; |
| 5056 | __be32 val; |
| 5057 | int ret, i; |
| 5058 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5059 | out = kvzalloc(outlen, GFP_KERNEL); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5060 | if (!out) |
| 5061 | return -ENOMEM; |
| 5062 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5063 | ret = mlx5_core_query_q_counter(mdev, |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5064 | port->cnts.set_id, 0, |
| 5065 | out, outlen); |
| 5066 | if (ret) |
| 5067 | goto free; |
| 5068 | |
| 5069 | for (i = 0; i < port->cnts.num_q_counters; i++) { |
| 5070 | val = *(__be32 *)(out + port->cnts.offsets[i]); |
| 5071 | stats->value[i] = (u64)be32_to_cpu(val); |
| 5072 | } |
| 5073 | |
| 5074 | free: |
| 5075 | kvfree(out); |
| 5076 | return ret; |
| 5077 | } |
| 5078 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5079 | static int mlx5_ib_query_ext_ppcnt_counters(struct mlx5_ib_dev *dev, |
| 5080 | struct mlx5_ib_port *port, |
| 5081 | struct rdma_hw_stats *stats) |
| 5082 | { |
| 5083 | int offset = port->cnts.num_q_counters + port->cnts.num_cong_counters; |
| 5084 | int sz = MLX5_ST_SZ_BYTES(ppcnt_reg); |
| 5085 | int ret, i; |
| 5086 | void *out; |
| 5087 | |
| 5088 | out = kvzalloc(sz, GFP_KERNEL); |
| 5089 | if (!out) |
| 5090 | return -ENOMEM; |
| 5091 | |
| 5092 | ret = mlx5_cmd_query_ext_ppcnt_counters(dev->mdev, out); |
| 5093 | if (ret) |
| 5094 | goto free; |
| 5095 | |
| 5096 | for (i = 0; i < port->cnts.num_ext_ppcnt_counters; i++) { |
| 5097 | stats->value[i + offset] = |
| 5098 | be64_to_cpup((__be64 *)(out + |
| 5099 | port->cnts.offsets[i + offset])); |
| 5100 | } |
| 5101 | |
| 5102 | free: |
| 5103 | kvfree(out); |
| 5104 | return ret; |
| 5105 | } |
| 5106 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5107 | static int mlx5_ib_get_hw_stats(struct ib_device *ibdev, |
| 5108 | struct rdma_hw_stats *stats, |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5109 | u8 port_num, int index) |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5110 | { |
| 5111 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5112 | struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5113 | struct mlx5_core_dev *mdev; |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5114 | int ret, num_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5115 | u8 mdev_port_num; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5116 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5117 | if (!stats) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5118 | return -EINVAL; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5119 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5120 | num_counters = port->cnts.num_q_counters + |
| 5121 | port->cnts.num_cong_counters + |
| 5122 | port->cnts.num_ext_ppcnt_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5123 | |
| 5124 | /* q_counters are per IB device, query the master mdev */ |
| 5125 | ret = mlx5_ib_query_q_counters(dev->mdev, port, stats); |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5126 | if (ret) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5127 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5128 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5129 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5130 | ret = mlx5_ib_query_ext_ppcnt_counters(dev, port, stats); |
| 5131 | if (ret) |
| 5132 | return ret; |
| 5133 | } |
| 5134 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5135 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5136 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, |
| 5137 | &mdev_port_num); |
| 5138 | if (!mdev) { |
| 5139 | /* If port is not affiliated yet, its in down state |
| 5140 | * which doesn't have any counters yet, so it would be |
| 5141 | * zero. So no need to read from the HCA. |
| 5142 | */ |
| 5143 | goto done; |
| 5144 | } |
Majd Dibbiny | 71a0ff6 | 2017-12-21 17:38:26 +0200 | [diff] [blame] | 5145 | ret = mlx5_lag_query_cong_counters(dev->mdev, |
| 5146 | stats->value + |
| 5147 | port->cnts.num_q_counters, |
| 5148 | port->cnts.num_cong_counters, |
| 5149 | port->cnts.offsets + |
| 5150 | port->cnts.num_q_counters); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5151 | |
| 5152 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5153 | if (ret) |
| 5154 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5155 | } |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5156 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5157 | done: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5158 | return num_counters; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5159 | } |
| 5160 | |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5161 | static void mlx5_ib_free_rdma_netdev(struct net_device *netdev) |
| 5162 | { |
| 5163 | return mlx5_rdma_netdev_free(netdev); |
| 5164 | } |
| 5165 | |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5166 | static struct net_device* |
| 5167 | mlx5_ib_alloc_rdma_netdev(struct ib_device *hca, |
| 5168 | u8 port_num, |
| 5169 | enum rdma_netdev_t type, |
| 5170 | const char *name, |
| 5171 | unsigned char name_assign_type, |
| 5172 | void (*setup)(struct net_device *)) |
| 5173 | { |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5174 | struct net_device *netdev; |
| 5175 | struct rdma_netdev *rn; |
| 5176 | |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5177 | if (type != RDMA_NETDEV_IPOIB) |
| 5178 | return ERR_PTR(-EOPNOTSUPP); |
| 5179 | |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5180 | netdev = mlx5_rdma_netdev_alloc(to_mdev(hca)->mdev, hca, |
| 5181 | name, setup); |
| 5182 | if (likely(!IS_ERR_OR_NULL(netdev))) { |
| 5183 | rn = netdev_priv(netdev); |
| 5184 | rn->free_rdma_netdev = mlx5_ib_free_rdma_netdev; |
| 5185 | } |
| 5186 | return netdev; |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5187 | } |
| 5188 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5189 | static void delay_drop_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 5190 | { |
| 5191 | if (!dev->delay_drop.dbg) |
| 5192 | return; |
| 5193 | debugfs_remove_recursive(dev->delay_drop.dbg->dir_debugfs); |
| 5194 | kfree(dev->delay_drop.dbg); |
| 5195 | dev->delay_drop.dbg = NULL; |
| 5196 | } |
| 5197 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5198 | static void cancel_delay_drop(struct mlx5_ib_dev *dev) |
| 5199 | { |
| 5200 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5201 | return; |
| 5202 | |
| 5203 | cancel_work_sync(&dev->delay_drop.delay_drop_work); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5204 | delay_drop_debugfs_cleanup(dev); |
| 5205 | } |
| 5206 | |
| 5207 | static ssize_t delay_drop_timeout_read(struct file *filp, char __user *buf, |
| 5208 | size_t count, loff_t *pos) |
| 5209 | { |
| 5210 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5211 | char lbuf[20]; |
| 5212 | int len; |
| 5213 | |
| 5214 | len = snprintf(lbuf, sizeof(lbuf), "%u\n", delay_drop->timeout); |
| 5215 | return simple_read_from_buffer(buf, count, pos, lbuf, len); |
| 5216 | } |
| 5217 | |
| 5218 | static ssize_t delay_drop_timeout_write(struct file *filp, const char __user *buf, |
| 5219 | size_t count, loff_t *pos) |
| 5220 | { |
| 5221 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5222 | u32 timeout; |
| 5223 | u32 var; |
| 5224 | |
| 5225 | if (kstrtouint_from_user(buf, count, 0, &var)) |
| 5226 | return -EFAULT; |
| 5227 | |
| 5228 | timeout = min_t(u32, roundup(var, 100), MLX5_MAX_DELAY_DROP_TIMEOUT_MS * |
| 5229 | 1000); |
| 5230 | if (timeout != var) |
| 5231 | mlx5_ib_dbg(delay_drop->dev, "Round delay drop timeout to %u usec\n", |
| 5232 | timeout); |
| 5233 | |
| 5234 | delay_drop->timeout = timeout; |
| 5235 | |
| 5236 | return count; |
| 5237 | } |
| 5238 | |
| 5239 | static const struct file_operations fops_delay_drop_timeout = { |
| 5240 | .owner = THIS_MODULE, |
| 5241 | .open = simple_open, |
| 5242 | .write = delay_drop_timeout_write, |
| 5243 | .read = delay_drop_timeout_read, |
| 5244 | }; |
| 5245 | |
| 5246 | static int delay_drop_debugfs_init(struct mlx5_ib_dev *dev) |
| 5247 | { |
| 5248 | struct mlx5_ib_dbg_delay_drop *dbg; |
| 5249 | |
| 5250 | if (!mlx5_debugfs_root) |
| 5251 | return 0; |
| 5252 | |
| 5253 | dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); |
| 5254 | if (!dbg) |
| 5255 | return -ENOMEM; |
| 5256 | |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5257 | dev->delay_drop.dbg = dbg; |
| 5258 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5259 | dbg->dir_debugfs = |
| 5260 | debugfs_create_dir("delay_drop", |
| 5261 | dev->mdev->priv.dbg_root); |
| 5262 | if (!dbg->dir_debugfs) |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5263 | goto out_debugfs; |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5264 | |
| 5265 | dbg->events_cnt_debugfs = |
| 5266 | debugfs_create_atomic_t("num_timeout_events", 0400, |
| 5267 | dbg->dir_debugfs, |
| 5268 | &dev->delay_drop.events_cnt); |
| 5269 | if (!dbg->events_cnt_debugfs) |
| 5270 | goto out_debugfs; |
| 5271 | |
| 5272 | dbg->rqs_cnt_debugfs = |
| 5273 | debugfs_create_atomic_t("num_rqs", 0400, |
| 5274 | dbg->dir_debugfs, |
| 5275 | &dev->delay_drop.rqs_cnt); |
| 5276 | if (!dbg->rqs_cnt_debugfs) |
| 5277 | goto out_debugfs; |
| 5278 | |
| 5279 | dbg->timeout_debugfs = |
| 5280 | debugfs_create_file("timeout", 0600, |
| 5281 | dbg->dir_debugfs, |
| 5282 | &dev->delay_drop, |
| 5283 | &fops_delay_drop_timeout); |
| 5284 | if (!dbg->timeout_debugfs) |
| 5285 | goto out_debugfs; |
| 5286 | |
| 5287 | return 0; |
| 5288 | |
| 5289 | out_debugfs: |
| 5290 | delay_drop_debugfs_cleanup(dev); |
| 5291 | return -ENOMEM; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5292 | } |
| 5293 | |
| 5294 | static void init_delay_drop(struct mlx5_ib_dev *dev) |
| 5295 | { |
| 5296 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5297 | return; |
| 5298 | |
| 5299 | mutex_init(&dev->delay_drop.lock); |
| 5300 | dev->delay_drop.dev = dev; |
| 5301 | dev->delay_drop.activate = false; |
| 5302 | dev->delay_drop.timeout = MLX5_MAX_DELAY_DROP_TIMEOUT_MS * 1000; |
| 5303 | INIT_WORK(&dev->delay_drop.delay_drop_work, delay_drop_handler); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5304 | atomic_set(&dev->delay_drop.rqs_cnt, 0); |
| 5305 | atomic_set(&dev->delay_drop.events_cnt, 0); |
| 5306 | |
| 5307 | if (delay_drop_debugfs_init(dev)) |
| 5308 | mlx5_ib_warn(dev, "Failed to init delay drop debugfs\n"); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5309 | } |
| 5310 | |
Leon Romanovsky | 84305d71 | 2017-08-17 15:50:53 +0300 | [diff] [blame] | 5311 | static const struct cpumask * |
| 5312 | mlx5_ib_get_vector_affinity(struct ib_device *ibdev, int comp_vector) |
Sagi Grimberg | 40b2440 | 2017-07-13 11:09:42 +0300 | [diff] [blame] | 5313 | { |
| 5314 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5315 | |
Israel Rukshin | 6082d9c | 2018-04-12 09:49:11 +0000 | [diff] [blame] | 5316 | return mlx5_get_vector_affinity_hint(dev->mdev, comp_vector); |
Sagi Grimberg | 40b2440 | 2017-07-13 11:09:42 +0300 | [diff] [blame] | 5317 | } |
| 5318 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5319 | /* The mlx5_ib_multiport_mutex should be held when calling this function */ |
| 5320 | static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5321 | struct mlx5_ib_multiport_info *mpi) |
| 5322 | { |
| 5323 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5324 | struct mlx5_ib_port *port = &ibdev->port[port_num]; |
| 5325 | int comps; |
| 5326 | int err; |
| 5327 | int i; |
| 5328 | |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5329 | mlx5_ib_cleanup_cong_debugfs(ibdev, port_num); |
| 5330 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5331 | spin_lock(&port->mp.mpi_lock); |
| 5332 | if (!mpi->ibdev) { |
| 5333 | spin_unlock(&port->mp.mpi_lock); |
| 5334 | return; |
| 5335 | } |
| 5336 | mpi->ibdev = NULL; |
| 5337 | |
| 5338 | spin_unlock(&port->mp.mpi_lock); |
| 5339 | mlx5_remove_netdev_notifier(ibdev, port_num); |
| 5340 | spin_lock(&port->mp.mpi_lock); |
| 5341 | |
| 5342 | comps = mpi->mdev_refcnt; |
| 5343 | if (comps) { |
| 5344 | mpi->unaffiliate = true; |
| 5345 | init_completion(&mpi->unref_comp); |
| 5346 | spin_unlock(&port->mp.mpi_lock); |
| 5347 | |
| 5348 | for (i = 0; i < comps; i++) |
| 5349 | wait_for_completion(&mpi->unref_comp); |
| 5350 | |
| 5351 | spin_lock(&port->mp.mpi_lock); |
| 5352 | mpi->unaffiliate = false; |
| 5353 | } |
| 5354 | |
| 5355 | port->mp.mpi = NULL; |
| 5356 | |
| 5357 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 5358 | |
| 5359 | spin_unlock(&port->mp.mpi_lock); |
| 5360 | |
| 5361 | err = mlx5_nic_vport_unaffiliate_multiport(mpi->mdev); |
| 5362 | |
| 5363 | mlx5_ib_dbg(ibdev, "unaffiliated port %d\n", port_num + 1); |
| 5364 | /* Log an error, still needed to cleanup the pointers and add |
| 5365 | * it back to the list. |
| 5366 | */ |
| 5367 | if (err) |
| 5368 | mlx5_ib_err(ibdev, "Failed to unaffiliate port %u\n", |
| 5369 | port_num + 1); |
| 5370 | |
| 5371 | ibdev->roce[port_num].last_port_state = IB_PORT_DOWN; |
| 5372 | } |
| 5373 | |
| 5374 | /* The mlx5_ib_multiport_mutex should be held when calling this function */ |
| 5375 | static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5376 | struct mlx5_ib_multiport_info *mpi) |
| 5377 | { |
| 5378 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5379 | int err; |
| 5380 | |
| 5381 | spin_lock(&ibdev->port[port_num].mp.mpi_lock); |
| 5382 | if (ibdev->port[port_num].mp.mpi) { |
| 5383 | mlx5_ib_warn(ibdev, "port %d already affiliated.\n", |
| 5384 | port_num + 1); |
| 5385 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5386 | return false; |
| 5387 | } |
| 5388 | |
| 5389 | ibdev->port[port_num].mp.mpi = mpi; |
| 5390 | mpi->ibdev = ibdev; |
| 5391 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5392 | |
| 5393 | err = mlx5_nic_vport_affiliate_multiport(ibdev->mdev, mpi->mdev); |
| 5394 | if (err) |
| 5395 | goto unbind; |
| 5396 | |
| 5397 | err = get_port_caps(ibdev, mlx5_core_native_port_num(mpi->mdev)); |
| 5398 | if (err) |
| 5399 | goto unbind; |
| 5400 | |
| 5401 | err = mlx5_add_netdev_notifier(ibdev, port_num); |
| 5402 | if (err) { |
| 5403 | mlx5_ib_err(ibdev, "failed adding netdev notifier for port %u\n", |
| 5404 | port_num + 1); |
| 5405 | goto unbind; |
| 5406 | } |
| 5407 | |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5408 | err = mlx5_ib_init_cong_debugfs(ibdev, port_num); |
| 5409 | if (err) |
| 5410 | goto unbind; |
| 5411 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5412 | return true; |
| 5413 | |
| 5414 | unbind: |
| 5415 | mlx5_ib_unbind_slave_port(ibdev, mpi); |
| 5416 | return false; |
| 5417 | } |
| 5418 | |
| 5419 | static int mlx5_ib_init_multiport_master(struct mlx5_ib_dev *dev) |
| 5420 | { |
| 5421 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5422 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5423 | port_num + 1); |
| 5424 | struct mlx5_ib_multiport_info *mpi; |
| 5425 | int err; |
| 5426 | int i; |
| 5427 | |
| 5428 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5429 | return 0; |
| 5430 | |
| 5431 | err = mlx5_query_nic_vport_system_image_guid(dev->mdev, |
| 5432 | &dev->sys_image_guid); |
| 5433 | if (err) |
| 5434 | return err; |
| 5435 | |
| 5436 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 5437 | if (err) |
| 5438 | return err; |
| 5439 | |
| 5440 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5441 | for (i = 0; i < dev->num_ports; i++) { |
| 5442 | bool bound = false; |
| 5443 | |
| 5444 | /* build a stub multiport info struct for the native port. */ |
| 5445 | if (i == port_num) { |
| 5446 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 5447 | if (!mpi) { |
| 5448 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5449 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5450 | return -ENOMEM; |
| 5451 | } |
| 5452 | |
| 5453 | mpi->is_master = true; |
| 5454 | mpi->mdev = dev->mdev; |
| 5455 | mpi->sys_image_guid = dev->sys_image_guid; |
| 5456 | dev->port[i].mp.mpi = mpi; |
| 5457 | mpi->ibdev = dev; |
| 5458 | mpi = NULL; |
| 5459 | continue; |
| 5460 | } |
| 5461 | |
| 5462 | list_for_each_entry(mpi, &mlx5_ib_unaffiliated_port_list, |
| 5463 | list) { |
| 5464 | if (dev->sys_image_guid == mpi->sys_image_guid && |
| 5465 | (mlx5_core_native_port_num(mpi->mdev) - 1) == i) { |
| 5466 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 5467 | } |
| 5468 | |
| 5469 | if (bound) { |
| 5470 | dev_dbg(&mpi->mdev->pdev->dev, "removing port from unaffiliated list.\n"); |
| 5471 | mlx5_ib_dbg(dev, "port %d bound\n", i + 1); |
| 5472 | list_del(&mpi->list); |
| 5473 | break; |
| 5474 | } |
| 5475 | } |
| 5476 | if (!bound) { |
| 5477 | get_port_caps(dev, i + 1); |
| 5478 | mlx5_ib_dbg(dev, "no free port found for port %d\n", |
| 5479 | i + 1); |
| 5480 | } |
| 5481 | } |
| 5482 | |
| 5483 | list_add_tail(&dev->ib_dev_list, &mlx5_ib_dev_list); |
| 5484 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5485 | return err; |
| 5486 | } |
| 5487 | |
| 5488 | static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev) |
| 5489 | { |
| 5490 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5491 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5492 | port_num + 1); |
| 5493 | int i; |
| 5494 | |
| 5495 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5496 | return; |
| 5497 | |
| 5498 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5499 | for (i = 0; i < dev->num_ports; i++) { |
| 5500 | if (dev->port[i].mp.mpi) { |
| 5501 | /* Destroy the native port stub */ |
| 5502 | if (i == port_num) { |
| 5503 | kfree(dev->port[i].mp.mpi); |
| 5504 | dev->port[i].mp.mpi = NULL; |
| 5505 | } else { |
| 5506 | mlx5_ib_dbg(dev, "unbinding port_num: %d\n", i + 1); |
| 5507 | mlx5_ib_unbind_slave_port(dev, dev->port[i].mp.mpi); |
| 5508 | } |
| 5509 | } |
| 5510 | } |
| 5511 | |
| 5512 | mlx5_ib_dbg(dev, "removing from devlist\n"); |
| 5513 | list_del(&dev->ib_dev_list); |
| 5514 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5515 | |
| 5516 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5517 | } |
| 5518 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5519 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 5520 | mlx5_ib_dm, |
| 5521 | UVERBS_OBJECT_DM, |
| 5522 | UVERBS_METHOD_DM_ALLOC, |
| 5523 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 5524 | UVERBS_ATTR_TYPE(u64), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5525 | UA_MANDATORY), |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5526 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 5527 | UVERBS_ATTR_TYPE(u16), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5528 | UA_MANDATORY)); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5529 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5530 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 5531 | mlx5_ib_flow_action, |
| 5532 | UVERBS_OBJECT_FLOW_ACTION, |
| 5533 | UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, |
| 5534 | UVERBS_ATTR_PTR_IN(MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 5535 | UVERBS_ATTR_TYPE(u64), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5536 | UA_MANDATORY)); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 5537 | |
Yishai Hadas | c59450c | 2018-06-17 13:00:06 +0300 | [diff] [blame] | 5538 | #define NUM_TREES 3 |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5539 | static int populate_specs_root(struct mlx5_ib_dev *dev) |
| 5540 | { |
| 5541 | const struct uverbs_object_tree_def *default_root[NUM_TREES + 1] = { |
| 5542 | uverbs_default_get_objects()}; |
| 5543 | size_t num_trees = 1; |
| 5544 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 5545 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_DEVICE && |
| 5546 | !WARN_ON(num_trees >= ARRAY_SIZE(default_root))) |
| 5547 | default_root[num_trees++] = &mlx5_ib_flow_action; |
| 5548 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5549 | if (MLX5_CAP_DEV_MEM(dev->mdev, memic) && |
| 5550 | !WARN_ON(num_trees >= ARRAY_SIZE(default_root))) |
| 5551 | default_root[num_trees++] = &mlx5_ib_dm; |
| 5552 | |
Yishai Hadas | c59450c | 2018-06-17 13:00:06 +0300 | [diff] [blame] | 5553 | if (MLX5_CAP_GEN_64(dev->mdev, general_obj_types) & |
| 5554 | MLX5_GENERAL_OBJ_TYPES_CAP_UCTX && |
| 5555 | !WARN_ON(num_trees >= ARRAY_SIZE(default_root))) |
| 5556 | default_root[num_trees++] = mlx5_ib_get_devx_tree(); |
| 5557 | |
Jason Gunthorpe | 87fc2a6 | 2018-07-04 08:50:23 +0300 | [diff] [blame] | 5558 | dev->ib_dev.driver_specs_root = |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5559 | uverbs_alloc_spec_tree(num_trees, default_root); |
| 5560 | |
Jason Gunthorpe | 87fc2a6 | 2018-07-04 08:50:23 +0300 | [diff] [blame] | 5561 | return PTR_ERR_OR_ZERO(dev->ib_dev.driver_specs_root); |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5562 | } |
| 5563 | |
| 5564 | static void depopulate_specs_root(struct mlx5_ib_dev *dev) |
| 5565 | { |
Jason Gunthorpe | 87fc2a6 | 2018-07-04 08:50:23 +0300 | [diff] [blame] | 5566 | uverbs_free_spec_tree(dev->ib_dev.driver_specs_root); |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5567 | } |
| 5568 | |
Raed Salem | 1a1e03d | 2018-05-31 16:43:41 +0300 | [diff] [blame] | 5569 | static int mlx5_ib_read_counters(struct ib_counters *counters, |
| 5570 | struct ib_counters_read_attr *read_attr, |
| 5571 | struct uverbs_attr_bundle *attrs) |
| 5572 | { |
| 5573 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 5574 | struct mlx5_read_counters_attr mread_attr = {}; |
| 5575 | struct mlx5_ib_flow_counters_desc *desc; |
| 5576 | int ret, i; |
| 5577 | |
| 5578 | mutex_lock(&mcounters->mcntrs_mutex); |
| 5579 | if (mcounters->cntrs_max_index > read_attr->ncounters) { |
| 5580 | ret = -EINVAL; |
| 5581 | goto err_bound; |
| 5582 | } |
| 5583 | |
| 5584 | mread_attr.out = kcalloc(mcounters->counters_num, sizeof(u64), |
| 5585 | GFP_KERNEL); |
| 5586 | if (!mread_attr.out) { |
| 5587 | ret = -ENOMEM; |
| 5588 | goto err_bound; |
| 5589 | } |
| 5590 | |
| 5591 | mread_attr.hw_cntrs_hndl = mcounters->hw_cntrs_hndl; |
| 5592 | mread_attr.flags = read_attr->flags; |
| 5593 | ret = mcounters->read_counters(counters->device, &mread_attr); |
| 5594 | if (ret) |
| 5595 | goto err_read; |
| 5596 | |
| 5597 | /* do the pass over the counters data array to assign according to the |
| 5598 | * descriptions and indexing pairs |
| 5599 | */ |
| 5600 | desc = mcounters->counters_data; |
| 5601 | for (i = 0; i < mcounters->ncounters; i++) |
| 5602 | read_attr->counters_buff[desc[i].index] += mread_attr.out[desc[i].description]; |
| 5603 | |
| 5604 | err_read: |
| 5605 | kfree(mread_attr.out); |
| 5606 | err_bound: |
| 5607 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 5608 | return ret; |
| 5609 | } |
| 5610 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5611 | static int mlx5_ib_destroy_counters(struct ib_counters *counters) |
| 5612 | { |
| 5613 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 5614 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 5615 | counters_clear_description(counters); |
| 5616 | if (mcounters->hw_cntrs_hndl) |
| 5617 | mlx5_fc_destroy(to_mdev(counters->device)->mdev, |
| 5618 | mcounters->hw_cntrs_hndl); |
| 5619 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5620 | kfree(mcounters); |
| 5621 | |
| 5622 | return 0; |
| 5623 | } |
| 5624 | |
| 5625 | static struct ib_counters *mlx5_ib_create_counters(struct ib_device *device, |
| 5626 | struct uverbs_attr_bundle *attrs) |
| 5627 | { |
| 5628 | struct mlx5_ib_mcounters *mcounters; |
| 5629 | |
| 5630 | mcounters = kzalloc(sizeof(*mcounters), GFP_KERNEL); |
| 5631 | if (!mcounters) |
| 5632 | return ERR_PTR(-ENOMEM); |
| 5633 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 5634 | mutex_init(&mcounters->mcntrs_mutex); |
| 5635 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5636 | return &mcounters->ibcntrs; |
| 5637 | } |
| 5638 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5639 | void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5640 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5641 | mlx5_ib_cleanup_multiport_master(dev); |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5642 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 5643 | cleanup_srcu_struct(&dev->mr_srcu); |
| 5644 | #endif |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5645 | kfree(dev->port); |
| 5646 | } |
| 5647 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5648 | int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5649 | { |
| 5650 | struct mlx5_core_dev *mdev = dev->mdev; |
Aviv Heller | 4babcf9 | 2016-09-18 20:48:03 +0300 | [diff] [blame] | 5651 | const char *name; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5652 | int err; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5653 | int i; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5654 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 5655 | dev->port = kcalloc(dev->num_ports, sizeof(*dev->port), |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5656 | GFP_KERNEL); |
| 5657 | if (!dev->port) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5658 | return -ENOMEM; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5659 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5660 | for (i = 0; i < dev->num_ports; i++) { |
| 5661 | spin_lock_init(&dev->port[i].mp.mpi_lock); |
| 5662 | rwlock_init(&dev->roce[i].netdev_lock); |
| 5663 | } |
| 5664 | |
| 5665 | err = mlx5_ib_init_multiport_master(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5666 | if (err) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5667 | goto err_free_port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5668 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5669 | if (!mlx5_core_mp_enabled(mdev)) { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5670 | for (i = 1; i <= dev->num_ports; i++) { |
| 5671 | err = get_port_caps(dev, i); |
| 5672 | if (err) |
| 5673 | break; |
| 5674 | } |
| 5675 | } else { |
| 5676 | err = get_port_caps(dev, mlx5_core_native_port_num(mdev)); |
| 5677 | } |
| 5678 | if (err) |
| 5679 | goto err_mp; |
| 5680 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 5681 | if (mlx5_use_mad_ifc(dev)) |
| 5682 | get_ext_port_caps(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5683 | |
Aviv Heller | 4babcf9 | 2016-09-18 20:48:03 +0300 | [diff] [blame] | 5684 | if (!mlx5_lag_is_active(mdev)) |
| 5685 | name = "mlx5_%d"; |
| 5686 | else |
| 5687 | name = "mlx5_bond_%d"; |
| 5688 | |
| 5689 | strlcpy(dev->ib_dev.name, name, IB_DEVICE_NAME_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5690 | dev->ib_dev.owner = THIS_MODULE; |
| 5691 | dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Sagi Grimberg | c6790aa | 2015-09-24 10:34:23 +0300 | [diff] [blame] | 5692 | dev->ib_dev.local_dma_lkey = 0 /* not supported for now */; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 5693 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 5694 | dev->ib_dev.num_comp_vectors = |
| 5695 | dev->mdev->priv.eq_table.num_comp_vectors; |
Bart Van Assche | 9b0c289 | 2017-01-20 13:04:21 -0800 | [diff] [blame] | 5696 | dev->ib_dev.dev.parent = &mdev->pdev->dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5697 | |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5698 | mutex_init(&dev->cap_mask_mutex); |
| 5699 | INIT_LIST_HEAD(&dev->qp_list); |
| 5700 | spin_lock_init(&dev->reset_flow_resource_lock); |
| 5701 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5702 | spin_lock_init(&dev->memic.memic_lock); |
| 5703 | dev->memic.dev = mdev; |
| 5704 | |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5705 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 5706 | err = init_srcu_struct(&dev->mr_srcu); |
| 5707 | if (err) |
| 5708 | goto err_free_port; |
| 5709 | #endif |
| 5710 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5711 | return 0; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5712 | err_mp: |
| 5713 | mlx5_ib_cleanup_multiport_master(dev); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5714 | |
| 5715 | err_free_port: |
| 5716 | kfree(dev->port); |
| 5717 | |
| 5718 | return -ENOMEM; |
| 5719 | } |
| 5720 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5721 | static int mlx5_ib_stage_flow_db_init(struct mlx5_ib_dev *dev) |
| 5722 | { |
| 5723 | dev->flow_db = kzalloc(sizeof(*dev->flow_db), GFP_KERNEL); |
| 5724 | |
| 5725 | if (!dev->flow_db) |
| 5726 | return -ENOMEM; |
| 5727 | |
| 5728 | mutex_init(&dev->flow_db->lock); |
| 5729 | |
| 5730 | return 0; |
| 5731 | } |
| 5732 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5733 | int mlx5_ib_stage_rep_flow_db_init(struct mlx5_ib_dev *dev) |
| 5734 | { |
| 5735 | struct mlx5_ib_dev *nic_dev; |
| 5736 | |
| 5737 | nic_dev = mlx5_ib_get_uplink_ibdev(dev->mdev->priv.eswitch); |
| 5738 | |
| 5739 | if (!nic_dev) |
| 5740 | return -EINVAL; |
| 5741 | |
| 5742 | dev->flow_db = nic_dev->flow_db; |
| 5743 | |
| 5744 | return 0; |
| 5745 | } |
| 5746 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5747 | static void mlx5_ib_stage_flow_db_cleanup(struct mlx5_ib_dev *dev) |
| 5748 | { |
| 5749 | kfree(dev->flow_db); |
| 5750 | } |
| 5751 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5752 | int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5753 | { |
| 5754 | struct mlx5_core_dev *mdev = dev->mdev; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5755 | int err; |
| 5756 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5757 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
| 5758 | dev->ib_dev.uverbs_cmd_mask = |
| 5759 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 5760 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 5761 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 5762 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 5763 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
Moni Shoua | 41c450f | 2016-11-23 08:23:26 +0200 | [diff] [blame] | 5764 | (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
| 5765 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5766 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 5767 | (1ull << IB_USER_VERBS_CMD_REREG_MR) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5768 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 5769 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 5770 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 5771 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 5772 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 5773 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 5774 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 5775 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 5776 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 5777 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 5778 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 5779 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 5780 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 5781 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 5782 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 5783 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 5784 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Haggai Eran | 1707cb4 | 2015-02-08 13:28:52 +0200 | [diff] [blame] | 5785 | dev->ib_dev.uverbs_ex_cmd_mask = |
Matan Barak | d4584dd | 2016-01-28 17:51:46 +0200 | [diff] [blame] | 5786 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE) | |
| 5787 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 5788 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) | |
Yonatan Cohen | b0e9df6 | 2017-11-13 10:51:15 +0200 | [diff] [blame] | 5789 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_QP) | |
| 5790 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_CQ); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5791 | |
| 5792 | dev->ib_dev.query_device = mlx5_ib_query_device; |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 5793 | dev->ib_dev.get_link_layer = mlx5_ib_port_link_layer; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5794 | dev->ib_dev.query_gid = mlx5_ib_query_gid; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 5795 | dev->ib_dev.add_gid = mlx5_ib_add_gid; |
| 5796 | dev->ib_dev.del_gid = mlx5_ib_del_gid; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5797 | dev->ib_dev.query_pkey = mlx5_ib_query_pkey; |
| 5798 | dev->ib_dev.modify_device = mlx5_ib_modify_device; |
| 5799 | dev->ib_dev.modify_port = mlx5_ib_modify_port; |
| 5800 | dev->ib_dev.alloc_ucontext = mlx5_ib_alloc_ucontext; |
| 5801 | dev->ib_dev.dealloc_ucontext = mlx5_ib_dealloc_ucontext; |
| 5802 | dev->ib_dev.mmap = mlx5_ib_mmap; |
| 5803 | dev->ib_dev.alloc_pd = mlx5_ib_alloc_pd; |
| 5804 | dev->ib_dev.dealloc_pd = mlx5_ib_dealloc_pd; |
| 5805 | dev->ib_dev.create_ah = mlx5_ib_create_ah; |
| 5806 | dev->ib_dev.query_ah = mlx5_ib_query_ah; |
| 5807 | dev->ib_dev.destroy_ah = mlx5_ib_destroy_ah; |
| 5808 | dev->ib_dev.create_srq = mlx5_ib_create_srq; |
| 5809 | dev->ib_dev.modify_srq = mlx5_ib_modify_srq; |
| 5810 | dev->ib_dev.query_srq = mlx5_ib_query_srq; |
| 5811 | dev->ib_dev.destroy_srq = mlx5_ib_destroy_srq; |
| 5812 | dev->ib_dev.post_srq_recv = mlx5_ib_post_srq_recv; |
| 5813 | dev->ib_dev.create_qp = mlx5_ib_create_qp; |
| 5814 | dev->ib_dev.modify_qp = mlx5_ib_modify_qp; |
| 5815 | dev->ib_dev.query_qp = mlx5_ib_query_qp; |
| 5816 | dev->ib_dev.destroy_qp = mlx5_ib_destroy_qp; |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5817 | dev->ib_dev.drain_sq = mlx5_ib_drain_sq; |
| 5818 | dev->ib_dev.drain_rq = mlx5_ib_drain_rq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5819 | dev->ib_dev.post_send = mlx5_ib_post_send; |
| 5820 | dev->ib_dev.post_recv = mlx5_ib_post_recv; |
| 5821 | dev->ib_dev.create_cq = mlx5_ib_create_cq; |
| 5822 | dev->ib_dev.modify_cq = mlx5_ib_modify_cq; |
| 5823 | dev->ib_dev.resize_cq = mlx5_ib_resize_cq; |
| 5824 | dev->ib_dev.destroy_cq = mlx5_ib_destroy_cq; |
| 5825 | dev->ib_dev.poll_cq = mlx5_ib_poll_cq; |
| 5826 | dev->ib_dev.req_notify_cq = mlx5_ib_arm_cq; |
| 5827 | dev->ib_dev.get_dma_mr = mlx5_ib_get_dma_mr; |
| 5828 | dev->ib_dev.reg_user_mr = mlx5_ib_reg_user_mr; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 5829 | dev->ib_dev.rereg_user_mr = mlx5_ib_rereg_user_mr; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5830 | dev->ib_dev.dereg_mr = mlx5_ib_dereg_mr; |
| 5831 | dev->ib_dev.attach_mcast = mlx5_ib_mcg_attach; |
| 5832 | dev->ib_dev.detach_mcast = mlx5_ib_mcg_detach; |
| 5833 | dev->ib_dev.process_mad = mlx5_ib_process_mad; |
Sagi Grimberg | 9bee178 | 2015-07-30 10:32:35 +0300 | [diff] [blame] | 5834 | dev->ib_dev.alloc_mr = mlx5_ib_alloc_mr; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 5835 | dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg; |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 5836 | dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status; |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 5837 | dev->ib_dev.get_dev_fw_str = get_dev_fw_str; |
Sagi Grimberg | 40b2440 | 2017-07-13 11:09:42 +0300 | [diff] [blame] | 5838 | dev->ib_dev.get_vector_affinity = mlx5_ib_get_vector_affinity; |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5839 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads)) |
Alex Vesker | 022d038 | 2017-06-14 09:59:06 +0300 | [diff] [blame] | 5840 | dev->ib_dev.alloc_rdma_netdev = mlx5_ib_alloc_rdma_netdev; |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5841 | |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 5842 | if (mlx5_core_is_pf(mdev)) { |
| 5843 | dev->ib_dev.get_vf_config = mlx5_ib_get_vf_config; |
| 5844 | dev->ib_dev.set_vf_link_state = mlx5_ib_set_vf_link_state; |
| 5845 | dev->ib_dev.get_vf_stats = mlx5_ib_get_vf_stats; |
| 5846 | dev->ib_dev.set_vf_guid = mlx5_ib_set_vf_guid; |
| 5847 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5848 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 5849 | dev->ib_dev.disassociate_ucontext = mlx5_ib_disassociate_ucontext; |
| 5850 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 5851 | dev->umr_fence = mlx5_get_umr_fence(MLX5_CAP_GEN(mdev, umr_fence)); |
| 5852 | |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 5853 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
| 5854 | dev->ib_dev.alloc_mw = mlx5_ib_alloc_mw; |
| 5855 | dev->ib_dev.dealloc_mw = mlx5_ib_dealloc_mw; |
| 5856 | dev->ib_dev.uverbs_cmd_mask |= |
| 5857 | (1ull << IB_USER_VERBS_CMD_ALLOC_MW) | |
| 5858 | (1ull << IB_USER_VERBS_CMD_DEALLOC_MW); |
| 5859 | } |
| 5860 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 5861 | if (MLX5_CAP_GEN(mdev, xrc)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5862 | dev->ib_dev.alloc_xrcd = mlx5_ib_alloc_xrcd; |
| 5863 | dev->ib_dev.dealloc_xrcd = mlx5_ib_dealloc_xrcd; |
| 5864 | dev->ib_dev.uverbs_cmd_mask |= |
| 5865 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 5866 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
| 5867 | } |
| 5868 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5869 | if (MLX5_CAP_DEV_MEM(mdev, memic)) { |
| 5870 | dev->ib_dev.alloc_dm = mlx5_ib_alloc_dm; |
| 5871 | dev->ib_dev.dealloc_dm = mlx5_ib_dealloc_dm; |
Ariel Levkovich | 6c29f57 | 2018-04-05 18:53:29 +0300 | [diff] [blame] | 5872 | dev->ib_dev.reg_dm_mr = mlx5_ib_reg_dm_mr; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5873 | } |
| 5874 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 5875 | dev->ib_dev.create_flow = mlx5_ib_create_flow; |
| 5876 | dev->ib_dev.destroy_flow = mlx5_ib_destroy_flow; |
| 5877 | dev->ib_dev.uverbs_ex_cmd_mask |= |
| 5878 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) | |
| 5879 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 5880 | dev->ib_dev.create_flow_action_esp = mlx5_ib_create_flow_action_esp; |
| 5881 | dev->ib_dev.destroy_flow_action = mlx5_ib_destroy_flow_action; |
Matan Barak | 349705c | 2018-03-28 09:27:51 +0300 | [diff] [blame] | 5882 | dev->ib_dev.modify_flow_action_esp = mlx5_ib_modify_flow_action_esp; |
Matan Barak | 0ede73b | 2018-03-19 15:02:34 +0200 | [diff] [blame] | 5883 | dev->ib_dev.driver_id = RDMA_DRIVER_MLX5; |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5884 | dev->ib_dev.create_counters = mlx5_ib_create_counters; |
| 5885 | dev->ib_dev.destroy_counters = mlx5_ib_destroy_counters; |
Raed Salem | 1a1e03d | 2018-05-31 16:43:41 +0300 | [diff] [blame] | 5886 | dev->ib_dev.read_counters = mlx5_ib_read_counters; |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 5887 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5888 | err = init_node_data(dev); |
| 5889 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5890 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5891 | |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 5892 | 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] | 5893 | (MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) || |
| 5894 | MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 5895 | mutex_init(&dev->lb_mutex); |
| 5896 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5897 | return 0; |
| 5898 | } |
| 5899 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5900 | static int mlx5_ib_stage_non_default_cb(struct mlx5_ib_dev *dev) |
| 5901 | { |
| 5902 | dev->ib_dev.get_port_immutable = mlx5_port_immutable; |
| 5903 | dev->ib_dev.query_port = mlx5_ib_query_port; |
| 5904 | |
| 5905 | return 0; |
| 5906 | } |
| 5907 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5908 | 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] | 5909 | { |
| 5910 | dev->ib_dev.get_port_immutable = mlx5_port_rep_immutable; |
| 5911 | dev->ib_dev.query_port = mlx5_ib_rep_query_port; |
| 5912 | |
| 5913 | return 0; |
| 5914 | } |
| 5915 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5916 | 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] | 5917 | { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5918 | u8 port_num; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5919 | int i; |
| 5920 | |
| 5921 | for (i = 0; i < dev->num_ports; i++) { |
| 5922 | dev->roce[i].dev = dev; |
| 5923 | dev->roce[i].native_port_num = i + 1; |
| 5924 | dev->roce[i].last_port_state = IB_PORT_DOWN; |
| 5925 | } |
| 5926 | |
| 5927 | dev->ib_dev.get_netdev = mlx5_ib_get_netdev; |
| 5928 | dev->ib_dev.create_wq = mlx5_ib_create_wq; |
| 5929 | dev->ib_dev.modify_wq = mlx5_ib_modify_wq; |
| 5930 | dev->ib_dev.destroy_wq = mlx5_ib_destroy_wq; |
| 5931 | dev->ib_dev.create_rwq_ind_table = mlx5_ib_create_rwq_ind_table; |
| 5932 | dev->ib_dev.destroy_rwq_ind_table = mlx5_ib_destroy_rwq_ind_table; |
| 5933 | |
| 5934 | dev->ib_dev.uverbs_ex_cmd_mask |= |
| 5935 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_WQ) | |
| 5936 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_WQ) | |
| 5937 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_WQ) | |
| 5938 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) | |
| 5939 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL); |
| 5940 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5941 | port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5942 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5943 | return mlx5_add_netdev_notifier(dev, port_num); |
| 5944 | } |
| 5945 | |
| 5946 | static void mlx5_ib_stage_common_roce_cleanup(struct mlx5_ib_dev *dev) |
| 5947 | { |
| 5948 | u8 port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5949 | |
| 5950 | mlx5_remove_netdev_notifier(dev, port_num); |
| 5951 | } |
| 5952 | |
| 5953 | int mlx5_ib_stage_rep_roce_init(struct mlx5_ib_dev *dev) |
| 5954 | { |
| 5955 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5956 | enum rdma_link_layer ll; |
| 5957 | int port_type_cap; |
| 5958 | int err = 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5959 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5960 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 5961 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 5962 | |
| 5963 | if (ll == IB_LINK_LAYER_ETHERNET) |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5964 | err = mlx5_ib_stage_common_roce_init(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5965 | |
| 5966 | return err; |
| 5967 | } |
| 5968 | |
| 5969 | void mlx5_ib_stage_rep_roce_cleanup(struct mlx5_ib_dev *dev) |
| 5970 | { |
| 5971 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 5972 | } |
| 5973 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5974 | static int mlx5_ib_stage_roce_init(struct mlx5_ib_dev *dev) |
| 5975 | { |
| 5976 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5977 | enum rdma_link_layer ll; |
| 5978 | int port_type_cap; |
| 5979 | int err; |
| 5980 | |
| 5981 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 5982 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 5983 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5984 | if (ll == IB_LINK_LAYER_ETHERNET) { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5985 | err = mlx5_ib_stage_common_roce_init(dev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5986 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5987 | return err; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5988 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5989 | err = mlx5_enable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5990 | if (err) |
| 5991 | goto cleanup; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 5992 | } |
| 5993 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5994 | return 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5995 | cleanup: |
| 5996 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 5997 | |
| 5998 | return err; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5999 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6000 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6001 | static void mlx5_ib_stage_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6002 | { |
| 6003 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6004 | enum rdma_link_layer ll; |
| 6005 | int port_type_cap; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6006 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6007 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6008 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6009 | |
| 6010 | if (ll == IB_LINK_LAYER_ETHERNET) { |
| 6011 | mlx5_disable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6012 | mlx5_ib_stage_common_roce_cleanup(dev); |
Kamal Heib | 45bded2 | 2017-01-18 14:10:32 +0200 | [diff] [blame] | 6013 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6014 | } |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6015 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6016 | int mlx5_ib_stage_dev_res_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6017 | { |
| 6018 | return create_dev_resources(&dev->devr); |
| 6019 | } |
Parav Pandit | 4a2da0b | 2017-05-30 10:05:15 +0300 | [diff] [blame] | 6020 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6021 | void mlx5_ib_stage_dev_res_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6022 | { |
| 6023 | destroy_dev_resources(&dev->devr); |
| 6024 | } |
| 6025 | |
| 6026 | static int mlx5_ib_stage_odp_init(struct mlx5_ib_dev *dev) |
| 6027 | { |
Mark Bloch | 07321b3 | 2018-01-01 13:07:00 +0200 | [diff] [blame] | 6028 | mlx5_ib_internal_fill_odp_caps(dev); |
| 6029 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6030 | return mlx5_ib_odp_init_one(dev); |
| 6031 | } |
| 6032 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6033 | int mlx5_ib_stage_counters_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6034 | { |
Mark Bloch | 5e1e761 | 2018-01-01 13:07:01 +0200 | [diff] [blame] | 6035 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) { |
| 6036 | dev->ib_dev.get_hw_stats = mlx5_ib_get_hw_stats; |
| 6037 | dev->ib_dev.alloc_hw_stats = mlx5_ib_alloc_hw_stats; |
| 6038 | |
| 6039 | return mlx5_ib_alloc_counters(dev); |
| 6040 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6041 | |
| 6042 | return 0; |
| 6043 | } |
| 6044 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6045 | void mlx5_ib_stage_counters_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6046 | { |
| 6047 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) |
| 6048 | mlx5_ib_dealloc_counters(dev); |
| 6049 | } |
| 6050 | |
| 6051 | static int mlx5_ib_stage_cong_debugfs_init(struct mlx5_ib_dev *dev) |
| 6052 | { |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 6053 | return mlx5_ib_init_cong_debugfs(dev, |
| 6054 | mlx5_core_native_port_num(dev->mdev) - 1); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | static void mlx5_ib_stage_cong_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 6058 | { |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 6059 | mlx5_ib_cleanup_cong_debugfs(dev, |
| 6060 | mlx5_core_native_port_num(dev->mdev) - 1); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | static int mlx5_ib_stage_uar_init(struct mlx5_ib_dev *dev) |
| 6064 | { |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6065 | dev->mdev->priv.uar = mlx5_get_uars_page(dev->mdev); |
Leon Romanovsky | 444261c | 2018-04-23 17:01:56 +0300 | [diff] [blame] | 6066 | return PTR_ERR_OR_ZERO(dev->mdev->priv.uar); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6067 | } |
| 6068 | |
| 6069 | static void mlx5_ib_stage_uar_cleanup(struct mlx5_ib_dev *dev) |
| 6070 | { |
| 6071 | mlx5_put_uars_page(dev->mdev, dev->mdev->priv.uar); |
| 6072 | } |
| 6073 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6074 | int mlx5_ib_stage_bfrag_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6075 | { |
| 6076 | int err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6077 | |
| 6078 | err = mlx5_alloc_bfreg(dev->mdev, &dev->bfreg, false, false); |
| 6079 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6080 | return err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6081 | |
| 6082 | err = mlx5_alloc_bfreg(dev->mdev, &dev->fp_bfreg, false, true); |
| 6083 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6084 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6085 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6086 | return err; |
| 6087 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 6088 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6089 | void mlx5_ib_stage_bfrag_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6090 | { |
| 6091 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
| 6092 | mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
| 6093 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6094 | |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 6095 | static int mlx5_ib_stage_populate_specs(struct mlx5_ib_dev *dev) |
| 6096 | { |
| 6097 | return populate_specs_root(dev); |
| 6098 | } |
| 6099 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6100 | int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6101 | { |
| 6102 | return ib_register_device(&dev->ib_dev, NULL); |
| 6103 | } |
| 6104 | |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 6105 | static void mlx5_ib_stage_depopulate_specs(struct mlx5_ib_dev *dev) |
| 6106 | { |
| 6107 | depopulate_specs_root(dev); |
| 6108 | } |
| 6109 | |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6110 | 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] | 6111 | { |
| 6112 | destroy_umrc_res(dev); |
| 6113 | } |
| 6114 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6115 | void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6116 | { |
| 6117 | ib_unregister_device(&dev->ib_dev); |
| 6118 | } |
| 6119 | |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6120 | 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] | 6121 | { |
| 6122 | return create_umr_res(dev); |
| 6123 | } |
| 6124 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6125 | static int mlx5_ib_stage_delay_drop_init(struct mlx5_ib_dev *dev) |
| 6126 | { |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6127 | init_delay_drop(dev); |
| 6128 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6129 | return 0; |
| 6130 | } |
| 6131 | |
| 6132 | static void mlx5_ib_stage_delay_drop_cleanup(struct mlx5_ib_dev *dev) |
| 6133 | { |
| 6134 | cancel_delay_drop(dev); |
| 6135 | } |
| 6136 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6137 | int mlx5_ib_stage_class_attr_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6138 | { |
| 6139 | int err; |
| 6140 | int i; |
| 6141 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6142 | for (i = 0; i < ARRAY_SIZE(mlx5_class_attributes); i++) { |
Wei Yongjun | 281d1a9 | 2013-07-30 07:54:26 +0800 | [diff] [blame] | 6143 | err = device_create_file(&dev->ib_dev.dev, |
| 6144 | mlx5_class_attributes[i]); |
| 6145 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6146 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6147 | } |
| 6148 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6149 | return 0; |
| 6150 | } |
| 6151 | |
Mark Bloch | fc385b7 | 2018-01-16 14:34:48 +0000 | [diff] [blame] | 6152 | static int mlx5_ib_stage_rep_reg_init(struct mlx5_ib_dev *dev) |
| 6153 | { |
| 6154 | mlx5_ib_register_vport_reps(dev); |
| 6155 | |
| 6156 | return 0; |
| 6157 | } |
| 6158 | |
| 6159 | static void mlx5_ib_stage_rep_reg_cleanup(struct mlx5_ib_dev *dev) |
| 6160 | { |
| 6161 | mlx5_ib_unregister_vport_reps(dev); |
| 6162 | } |
| 6163 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6164 | void __mlx5_ib_remove(struct mlx5_ib_dev *dev, |
| 6165 | const struct mlx5_ib_profile *profile, |
| 6166 | int stage) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6167 | { |
| 6168 | /* Number of stages to cleanup */ |
| 6169 | while (stage) { |
| 6170 | stage--; |
| 6171 | if (profile->stage[stage].cleanup) |
| 6172 | profile->stage[stage].cleanup(dev); |
| 6173 | } |
| 6174 | |
| 6175 | ib_dealloc_device((struct ib_device *)dev); |
| 6176 | } |
| 6177 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6178 | void *__mlx5_ib_add(struct mlx5_ib_dev *dev, |
| 6179 | const struct mlx5_ib_profile *profile) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6180 | { |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6181 | int err; |
| 6182 | int i; |
| 6183 | |
| 6184 | printk_once(KERN_INFO "%s", mlx5_version); |
| 6185 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6186 | for (i = 0; i < MLX5_IB_STAGE_MAX; i++) { |
| 6187 | if (profile->stage[i].init) { |
| 6188 | err = profile->stage[i].init(dev); |
| 6189 | if (err) |
| 6190 | goto err_out; |
| 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | dev->profile = profile; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6195 | dev->ib_active = true; |
| 6196 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6197 | return dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6198 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6199 | err_out: |
| 6200 | __mlx5_ib_remove(dev, profile, i); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6201 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6202 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6203 | } |
| 6204 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6205 | static const struct mlx5_ib_profile pf_profile = { |
| 6206 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6207 | mlx5_ib_stage_init_init, |
| 6208 | mlx5_ib_stage_init_cleanup), |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 6209 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6210 | mlx5_ib_stage_flow_db_init, |
| 6211 | mlx5_ib_stage_flow_db_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6212 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6213 | mlx5_ib_stage_caps_init, |
| 6214 | NULL), |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6215 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6216 | mlx5_ib_stage_non_default_cb, |
| 6217 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6218 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6219 | mlx5_ib_stage_roce_init, |
| 6220 | mlx5_ib_stage_roce_cleanup), |
| 6221 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6222 | mlx5_ib_stage_dev_res_init, |
| 6223 | mlx5_ib_stage_dev_res_cleanup), |
| 6224 | STAGE_CREATE(MLX5_IB_STAGE_ODP, |
| 6225 | mlx5_ib_stage_odp_init, |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 6226 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6227 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6228 | mlx5_ib_stage_counters_init, |
| 6229 | mlx5_ib_stage_counters_cleanup), |
| 6230 | STAGE_CREATE(MLX5_IB_STAGE_CONG_DEBUGFS, |
| 6231 | mlx5_ib_stage_cong_debugfs_init, |
| 6232 | mlx5_ib_stage_cong_debugfs_cleanup), |
| 6233 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6234 | mlx5_ib_stage_uar_init, |
| 6235 | mlx5_ib_stage_uar_cleanup), |
| 6236 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6237 | mlx5_ib_stage_bfrag_init, |
| 6238 | mlx5_ib_stage_bfrag_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6239 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6240 | NULL, |
| 6241 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 6242 | STAGE_CREATE(MLX5_IB_STAGE_SPECS, |
| 6243 | mlx5_ib_stage_populate_specs, |
| 6244 | mlx5_ib_stage_depopulate_specs), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6245 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6246 | mlx5_ib_stage_ib_reg_init, |
| 6247 | mlx5_ib_stage_ib_reg_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6248 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6249 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6250 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6251 | STAGE_CREATE(MLX5_IB_STAGE_DELAY_DROP, |
| 6252 | mlx5_ib_stage_delay_drop_init, |
| 6253 | mlx5_ib_stage_delay_drop_cleanup), |
| 6254 | STAGE_CREATE(MLX5_IB_STAGE_CLASS_ATTR, |
| 6255 | mlx5_ib_stage_class_attr_init, |
| 6256 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6257 | }; |
| 6258 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6259 | static const struct mlx5_ib_profile nic_rep_profile = { |
| 6260 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6261 | mlx5_ib_stage_init_init, |
| 6262 | mlx5_ib_stage_init_cleanup), |
| 6263 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6264 | mlx5_ib_stage_flow_db_init, |
| 6265 | mlx5_ib_stage_flow_db_cleanup), |
| 6266 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6267 | mlx5_ib_stage_caps_init, |
| 6268 | NULL), |
| 6269 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6270 | mlx5_ib_stage_rep_non_default_cb, |
| 6271 | NULL), |
| 6272 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6273 | mlx5_ib_stage_rep_roce_init, |
| 6274 | mlx5_ib_stage_rep_roce_cleanup), |
| 6275 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6276 | mlx5_ib_stage_dev_res_init, |
| 6277 | mlx5_ib_stage_dev_res_cleanup), |
| 6278 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6279 | mlx5_ib_stage_counters_init, |
| 6280 | mlx5_ib_stage_counters_cleanup), |
| 6281 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6282 | mlx5_ib_stage_uar_init, |
| 6283 | mlx5_ib_stage_uar_cleanup), |
| 6284 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6285 | mlx5_ib_stage_bfrag_init, |
| 6286 | mlx5_ib_stage_bfrag_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6287 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6288 | NULL, |
| 6289 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 6290 | STAGE_CREATE(MLX5_IB_STAGE_SPECS, |
| 6291 | mlx5_ib_stage_populate_specs, |
| 6292 | mlx5_ib_stage_depopulate_specs), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6293 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6294 | mlx5_ib_stage_ib_reg_init, |
| 6295 | mlx5_ib_stage_ib_reg_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6296 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6297 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6298 | NULL), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6299 | STAGE_CREATE(MLX5_IB_STAGE_CLASS_ATTR, |
| 6300 | mlx5_ib_stage_class_attr_init, |
| 6301 | NULL), |
| 6302 | STAGE_CREATE(MLX5_IB_STAGE_REP_REG, |
| 6303 | mlx5_ib_stage_rep_reg_init, |
| 6304 | mlx5_ib_stage_rep_reg_cleanup), |
| 6305 | }; |
| 6306 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6307 | static void *mlx5_ib_add_slave_port(struct mlx5_core_dev *mdev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6308 | { |
| 6309 | struct mlx5_ib_multiport_info *mpi; |
| 6310 | struct mlx5_ib_dev *dev; |
| 6311 | bool bound = false; |
| 6312 | int err; |
| 6313 | |
| 6314 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 6315 | if (!mpi) |
| 6316 | return NULL; |
| 6317 | |
| 6318 | mpi->mdev = mdev; |
| 6319 | |
| 6320 | err = mlx5_query_nic_vport_system_image_guid(mdev, |
| 6321 | &mpi->sys_image_guid); |
| 6322 | if (err) { |
| 6323 | kfree(mpi); |
| 6324 | return NULL; |
| 6325 | } |
| 6326 | |
| 6327 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6328 | list_for_each_entry(dev, &mlx5_ib_dev_list, ib_dev_list) { |
| 6329 | if (dev->sys_image_guid == mpi->sys_image_guid) |
| 6330 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 6331 | |
| 6332 | if (bound) { |
| 6333 | rdma_roce_rescan_device(&dev->ib_dev); |
| 6334 | break; |
| 6335 | } |
| 6336 | } |
| 6337 | |
| 6338 | if (!bound) { |
| 6339 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 6340 | 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] | 6341 | } |
| 6342 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6343 | |
| 6344 | return mpi; |
| 6345 | } |
| 6346 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6347 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
| 6348 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6349 | enum rdma_link_layer ll; |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6350 | struct mlx5_ib_dev *dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6351 | int port_type_cap; |
| 6352 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6353 | printk_once(KERN_INFO "%s", mlx5_version); |
| 6354 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6355 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6356 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6357 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6358 | if (mlx5_core_is_mp_slave(mdev) && ll == IB_LINK_LAYER_ETHERNET) |
| 6359 | return mlx5_ib_add_slave_port(mdev); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6360 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6361 | dev = (struct mlx5_ib_dev *)ib_alloc_device(sizeof(*dev)); |
| 6362 | if (!dev) |
| 6363 | return NULL; |
| 6364 | |
| 6365 | dev->mdev = mdev; |
| 6366 | dev->num_ports = max(MLX5_CAP_GEN(mdev, num_ports), |
| 6367 | MLX5_CAP_GEN(mdev, num_vhca_ports)); |
| 6368 | |
| 6369 | if (MLX5_VPORT_MANAGER(mdev) && |
| 6370 | mlx5_ib_eswitch_mode(mdev->priv.eswitch) == SRIOV_OFFLOADS) { |
| 6371 | dev->rep = mlx5_ib_vport_rep(mdev->priv.eswitch, 0); |
| 6372 | |
| 6373 | return __mlx5_ib_add(dev, &nic_rep_profile); |
| 6374 | } |
| 6375 | |
| 6376 | return __mlx5_ib_add(dev, &pf_profile); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6377 | } |
| 6378 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6379 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6380 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6381 | struct mlx5_ib_multiport_info *mpi; |
| 6382 | struct mlx5_ib_dev *dev; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6383 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6384 | if (mlx5_core_is_mp_slave(mdev)) { |
| 6385 | mpi = context; |
| 6386 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6387 | if (mpi->ibdev) |
| 6388 | mlx5_ib_unbind_slave_port(mpi->ibdev, mpi); |
| 6389 | list_del(&mpi->list); |
| 6390 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6391 | return; |
| 6392 | } |
| 6393 | |
| 6394 | dev = context; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6395 | __mlx5_ib_remove(dev, dev->profile, MLX5_IB_STAGE_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6396 | } |
| 6397 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6398 | static struct mlx5_interface mlx5_ib_interface = { |
| 6399 | .add = mlx5_ib_add, |
| 6400 | .remove = mlx5_ib_remove, |
| 6401 | .event = mlx5_ib_event, |
Artemy Kovalyov | d9aaed8 | 2017-01-02 11:37:46 +0200 | [diff] [blame] | 6402 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 6403 | .pfault = mlx5_ib_pfault, |
| 6404 | #endif |
Saeed Mahameed | 64613d94 | 2015-04-02 17:07:34 +0300 | [diff] [blame] | 6405 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6406 | }; |
| 6407 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6408 | unsigned long mlx5_ib_get_xlt_emergency_page(void) |
| 6409 | { |
| 6410 | mutex_lock(&xlt_emergency_page_mutex); |
| 6411 | return xlt_emergency_page; |
| 6412 | } |
| 6413 | |
| 6414 | void mlx5_ib_put_xlt_emergency_page(void) |
| 6415 | { |
| 6416 | mutex_unlock(&xlt_emergency_page_mutex); |
| 6417 | } |
| 6418 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6419 | static int __init mlx5_ib_init(void) |
| 6420 | { |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6421 | int err; |
| 6422 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6423 | xlt_emergency_page = __get_free_page(GFP_KERNEL); |
| 6424 | if (!xlt_emergency_page) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6425 | return -ENOMEM; |
| 6426 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6427 | mutex_init(&xlt_emergency_page_mutex); |
| 6428 | |
| 6429 | mlx5_ib_event_wq = alloc_ordered_workqueue("mlx5_ib_event_wq", 0); |
| 6430 | if (!mlx5_ib_event_wq) { |
| 6431 | free_page(xlt_emergency_page); |
| 6432 | return -ENOMEM; |
| 6433 | } |
| 6434 | |
Artemy Kovalyov | 81713d3 | 2017-01-18 16:58:11 +0200 | [diff] [blame] | 6435 | mlx5_ib_odp_init(); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6436 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6437 | err = mlx5_register_interface(&mlx5_ib_interface); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6438 | |
| 6439 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6440 | } |
| 6441 | |
| 6442 | static void __exit mlx5_ib_cleanup(void) |
| 6443 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6444 | mlx5_unregister_interface(&mlx5_ib_interface); |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6445 | destroy_workqueue(mlx5_ib_event_wq); |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6446 | mutex_destroy(&xlt_emergency_page_mutex); |
| 6447 | free_page(xlt_emergency_page); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6448 | } |
| 6449 | |
| 6450 | module_init(mlx5_ib_init); |
| 6451 | module_exit(mlx5_ib_cleanup); |