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