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