Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1 | /* |
Saeed Mahameed | 6cf0a15 | 2015-04-02 17:07:30 +0300 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 33 | #include <linux/debugfs.h> |
Christoph Hellwig | adec640 | 2015-08-28 09:27:19 +0200 | [diff] [blame] | 34 | #include <linux/highmem.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 35 | #include <linux/module.h> |
| 36 | #include <linux/init.h> |
| 37 | #include <linux/errno.h> |
| 38 | #include <linux/pci.h> |
| 39 | #include <linux/dma-mapping.h> |
| 40 | #include <linux/slab.h> |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 41 | #include <linux/bitmap.h> |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 42 | #if defined(CONFIG_X86) |
| 43 | #include <asm/pat.h> |
| 44 | #endif |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 45 | #include <linux/sched.h> |
Ingo Molnar | 6e84f31 | 2017-02-08 18:51:29 +0100 | [diff] [blame] | 46 | #include <linux/sched/mm.h> |
Ingo Molnar | 0881e7b | 2017-02-05 15:30:50 +0100 | [diff] [blame] | 47 | #include <linux/sched/task.h> |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 48 | #include <linux/delay.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 49 | #include <rdma/ib_user_verbs.h> |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 50 | #include <rdma/ib_addr.h> |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 51 | #include <rdma/ib_cache.h> |
Achiad Shochat | ada68c3 | 2016-02-22 18:17:23 +0200 | [diff] [blame] | 52 | #include <linux/mlx5/port.h> |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 53 | #include <linux/mlx5/vport.h> |
Pravin Shedge | 72c7fe9 | 2017-12-06 22:19:39 +0530 | [diff] [blame] | 54 | #include <linux/mlx5/fs.h> |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 55 | #include <linux/list.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 56 | #include <rdma/ib_smi.h> |
| 57 | #include <rdma/ib_umem.h> |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 58 | #include <linux/in.h> |
| 59 | #include <linux/etherdevice.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 60 | #include "mlx5_ib.h" |
Mark Bloch | fc385b7 | 2018-01-16 14:34:48 +0000 | [diff] [blame] | 61 | #include "ib_rep.h" |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 62 | #include "cmd.h" |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 63 | #include <linux/mlx5/fs_helpers.h> |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 64 | #include <linux/mlx5/accel.h> |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 65 | #include <rdma/uverbs_std_types.h> |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 66 | #include <rdma/mlx5_user_ioctl_verbs.h> |
| 67 | #include <rdma/mlx5_user_ioctl_cmds.h> |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 68 | |
| 69 | #define UVERBS_MODULE_NAME mlx5_ib |
| 70 | #include <rdma/uverbs_named_ioctl.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 71 | |
| 72 | #define DRIVER_NAME "mlx5_ib" |
Tariq Toukan | b359911 | 2017-02-22 17:45:46 +0200 | [diff] [blame] | 73 | #define DRIVER_VERSION "5.0-0" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 74 | |
| 75 | MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); |
| 76 | MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); |
| 77 | MODULE_LICENSE("Dual BSD/GPL"); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 78 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 79 | static char mlx5_version[] = |
| 80 | DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
Tariq Toukan | b359911 | 2017-02-22 17:45:46 +0200 | [diff] [blame] | 81 | DRIVER_VERSION "\n"; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 82 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 83 | struct mlx5_ib_event_work { |
| 84 | struct work_struct work; |
| 85 | struct mlx5_core_dev *dev; |
| 86 | void *context; |
| 87 | enum mlx5_dev_event event; |
| 88 | unsigned long param; |
| 89 | }; |
| 90 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 91 | enum { |
| 92 | MLX5_ATOMIC_SIZE_QP_8BYTES = 1 << 3, |
| 93 | }; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 94 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 95 | static struct workqueue_struct *mlx5_ib_event_wq; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 96 | static LIST_HEAD(mlx5_ib_unaffiliated_port_list); |
| 97 | static LIST_HEAD(mlx5_ib_dev_list); |
| 98 | /* |
| 99 | * This mutex should be held when accessing either of the above lists |
| 100 | */ |
| 101 | static DEFINE_MUTEX(mlx5_ib_multiport_mutex); |
| 102 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 103 | /* We can't use an array for xlt_emergency_page because dma_map_single |
| 104 | * doesn't work on kernel modules memory |
| 105 | */ |
| 106 | static unsigned long xlt_emergency_page; |
| 107 | static struct mutex xlt_emergency_page_mutex; |
| 108 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 109 | struct mlx5_ib_dev *mlx5_ib_get_ibdev_from_mpi(struct mlx5_ib_multiport_info *mpi) |
| 110 | { |
| 111 | struct mlx5_ib_dev *dev; |
| 112 | |
| 113 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 114 | dev = mpi->ibdev; |
| 115 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 116 | return dev; |
| 117 | } |
| 118 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 119 | static enum rdma_link_layer |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 120 | mlx5_port_type_cap_to_rdma_ll(int port_type_cap) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 121 | { |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 122 | switch (port_type_cap) { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 123 | case MLX5_CAP_PORT_TYPE_IB: |
| 124 | return IB_LINK_LAYER_INFINIBAND; |
| 125 | case MLX5_CAP_PORT_TYPE_ETH: |
| 126 | return IB_LINK_LAYER_ETHERNET; |
| 127 | default: |
| 128 | return IB_LINK_LAYER_UNSPECIFIED; |
| 129 | } |
| 130 | } |
| 131 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 132 | static enum rdma_link_layer |
| 133 | mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num) |
| 134 | { |
| 135 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 136 | int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type); |
| 137 | |
| 138 | return mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 139 | } |
| 140 | |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 141 | static int get_port_state(struct ib_device *ibdev, |
| 142 | u8 port_num, |
| 143 | enum ib_port_state *state) |
| 144 | { |
| 145 | struct ib_port_attr attr; |
| 146 | int ret; |
| 147 | |
| 148 | memset(&attr, 0, sizeof(attr)); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 149 | ret = ibdev->query_port(ibdev, port_num, &attr); |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 150 | if (!ret) |
| 151 | *state = attr.state; |
| 152 | return ret; |
| 153 | } |
| 154 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 155 | static int mlx5_netdev_event(struct notifier_block *this, |
| 156 | unsigned long event, void *ptr) |
| 157 | { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 158 | struct mlx5_roce *roce = container_of(this, struct mlx5_roce, nb); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 159 | struct net_device *ndev = netdev_notifier_info_to_dev(ptr); |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 160 | u8 port_num = roce->native_port_num; |
| 161 | struct mlx5_core_dev *mdev; |
| 162 | struct mlx5_ib_dev *ibdev; |
| 163 | |
| 164 | ibdev = roce->dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 165 | mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL); |
| 166 | if (!mdev) |
| 167 | return NOTIFY_DONE; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 168 | |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 169 | switch (event) { |
| 170 | case NETDEV_REGISTER: |
| 171 | case NETDEV_UNREGISTER: |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 172 | write_lock(&roce->netdev_lock); |
Mark Bloch | bcf87f1 | 2018-01-16 15:02:36 +0000 | [diff] [blame] | 173 | if (ibdev->rep) { |
| 174 | struct mlx5_eswitch *esw = ibdev->mdev->priv.eswitch; |
| 175 | struct net_device *rep_ndev; |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 176 | |
Mark Bloch | bcf87f1 | 2018-01-16 15:02:36 +0000 | [diff] [blame] | 177 | rep_ndev = mlx5_ib_get_rep_netdev(esw, |
| 178 | ibdev->rep->vport); |
| 179 | if (rep_ndev == ndev) |
| 180 | roce->netdev = (event == NETDEV_UNREGISTER) ? |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 181 | NULL : ndev; |
Parav Pandit | 84a6a7a | 2018-04-23 17:01:55 +0300 | [diff] [blame] | 182 | } else if (ndev->dev.parent == &mdev->pdev->dev) { |
Mark Bloch | bcf87f1 | 2018-01-16 15:02:36 +0000 | [diff] [blame] | 183 | roce->netdev = (event == NETDEV_UNREGISTER) ? |
| 184 | NULL : ndev; |
| 185 | } |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 186 | write_unlock(&roce->netdev_lock); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 187 | break; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 188 | |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 189 | case NETDEV_CHANGE: |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 190 | case NETDEV_UP: |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 191 | case NETDEV_DOWN: { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 192 | struct net_device *lag_ndev = mlx5_lag_get_roce_netdev(mdev); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 193 | struct net_device *upper = NULL; |
| 194 | |
| 195 | if (lag_ndev) { |
| 196 | upper = netdev_master_upper_dev_get(lag_ndev); |
| 197 | dev_put(lag_ndev); |
| 198 | } |
| 199 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 200 | if ((upper == ndev || (!upper && ndev == roce->netdev)) |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 201 | && ibdev->ib_active) { |
Bart Van Assche | 626bc02 | 2016-12-05 17:18:08 -0800 | [diff] [blame] | 202 | struct ib_event ibev = { }; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 203 | enum ib_port_state port_state; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 204 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 205 | if (get_port_state(&ibdev->ib_dev, port_num, |
| 206 | &port_state)) |
| 207 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 208 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 209 | if (roce->last_port_state == port_state) |
| 210 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 211 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 212 | roce->last_port_state = port_state; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 213 | ibev.device = &ibdev->ib_dev; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 214 | if (port_state == IB_PORT_DOWN) |
| 215 | ibev.event = IB_EVENT_PORT_ERR; |
| 216 | else if (port_state == IB_PORT_ACTIVE) |
| 217 | ibev.event = IB_EVENT_PORT_ACTIVE; |
| 218 | else |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 219 | goto done; |
Moni Shoua | fd65f1b | 2017-05-30 09:56:05 +0300 | [diff] [blame] | 220 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 221 | ibev.element.port_num = port_num; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 222 | ib_dispatch_event(&ibev); |
| 223 | } |
| 224 | break; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 225 | } |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 226 | |
| 227 | default: |
| 228 | break; |
| 229 | } |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 230 | done: |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 231 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 232 | return NOTIFY_DONE; |
| 233 | } |
| 234 | |
| 235 | static struct net_device *mlx5_ib_get_netdev(struct ib_device *device, |
| 236 | u8 port_num) |
| 237 | { |
| 238 | struct mlx5_ib_dev *ibdev = to_mdev(device); |
| 239 | struct net_device *ndev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 240 | struct mlx5_core_dev *mdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 241 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 242 | mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL); |
| 243 | if (!mdev) |
| 244 | return NULL; |
| 245 | |
| 246 | ndev = mlx5_lag_get_roce_netdev(mdev); |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 247 | if (ndev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 248 | goto out; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 249 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 250 | /* Ensure ndev does not disappear before we invoke dev_hold() |
| 251 | */ |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 252 | read_lock(&ibdev->roce[port_num - 1].netdev_lock); |
| 253 | ndev = ibdev->roce[port_num - 1].netdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 254 | if (ndev) |
| 255 | dev_hold(ndev); |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 256 | read_unlock(&ibdev->roce[port_num - 1].netdev_lock); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 257 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 258 | out: |
| 259 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 260 | return ndev; |
| 261 | } |
| 262 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 263 | struct mlx5_core_dev *mlx5_ib_get_native_port_mdev(struct mlx5_ib_dev *ibdev, |
| 264 | u8 ib_port_num, |
| 265 | u8 *native_port_num) |
| 266 | { |
| 267 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&ibdev->ib_dev, |
| 268 | ib_port_num); |
| 269 | struct mlx5_core_dev *mdev = NULL; |
| 270 | struct mlx5_ib_multiport_info *mpi; |
| 271 | struct mlx5_ib_port *port; |
| 272 | |
Mark Bloch | 210b1f7 | 2018-03-05 20:09:47 +0200 | [diff] [blame] | 273 | if (!mlx5_core_mp_enabled(ibdev->mdev) || |
| 274 | ll != IB_LINK_LAYER_ETHERNET) { |
| 275 | if (native_port_num) |
| 276 | *native_port_num = ib_port_num; |
| 277 | return ibdev->mdev; |
| 278 | } |
| 279 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 280 | if (native_port_num) |
| 281 | *native_port_num = 1; |
| 282 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 283 | port = &ibdev->port[ib_port_num - 1]; |
| 284 | if (!port) |
| 285 | return NULL; |
| 286 | |
| 287 | spin_lock(&port->mp.mpi_lock); |
| 288 | mpi = ibdev->port[ib_port_num - 1].mp.mpi; |
| 289 | if (mpi && !mpi->unaffiliate) { |
| 290 | mdev = mpi->mdev; |
| 291 | /* If it's the master no need to refcount, it'll exist |
| 292 | * as long as the ib_dev exists. |
| 293 | */ |
| 294 | if (!mpi->is_master) |
| 295 | mpi->mdev_refcnt++; |
| 296 | } |
| 297 | spin_unlock(&port->mp.mpi_lock); |
| 298 | |
| 299 | return mdev; |
| 300 | } |
| 301 | |
| 302 | void mlx5_ib_put_native_port_mdev(struct mlx5_ib_dev *ibdev, u8 port_num) |
| 303 | { |
| 304 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&ibdev->ib_dev, |
| 305 | port_num); |
| 306 | struct mlx5_ib_multiport_info *mpi; |
| 307 | struct mlx5_ib_port *port; |
| 308 | |
| 309 | if (!mlx5_core_mp_enabled(ibdev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 310 | return; |
| 311 | |
| 312 | port = &ibdev->port[port_num - 1]; |
| 313 | |
| 314 | spin_lock(&port->mp.mpi_lock); |
| 315 | mpi = ibdev->port[port_num - 1].mp.mpi; |
| 316 | if (mpi->is_master) |
| 317 | goto out; |
| 318 | |
| 319 | mpi->mdev_refcnt--; |
| 320 | if (mpi->unaffiliate) |
| 321 | complete(&mpi->unref_comp); |
| 322 | out: |
| 323 | spin_unlock(&port->mp.mpi_lock); |
| 324 | } |
| 325 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 326 | static int translate_eth_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
| 327 | u8 *active_width) |
| 328 | { |
| 329 | switch (eth_proto_oper) { |
| 330 | case MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII): |
| 331 | case MLX5E_PROT_MASK(MLX5E_1000BASE_KX): |
| 332 | case MLX5E_PROT_MASK(MLX5E_100BASE_TX): |
| 333 | case MLX5E_PROT_MASK(MLX5E_1000BASE_T): |
| 334 | *active_width = IB_WIDTH_1X; |
| 335 | *active_speed = IB_SPEED_SDR; |
| 336 | break; |
| 337 | case MLX5E_PROT_MASK(MLX5E_10GBASE_T): |
| 338 | case MLX5E_PROT_MASK(MLX5E_10GBASE_CX4): |
| 339 | case MLX5E_PROT_MASK(MLX5E_10GBASE_KX4): |
| 340 | case MLX5E_PROT_MASK(MLX5E_10GBASE_KR): |
| 341 | case MLX5E_PROT_MASK(MLX5E_10GBASE_CR): |
| 342 | case MLX5E_PROT_MASK(MLX5E_10GBASE_SR): |
| 343 | case MLX5E_PROT_MASK(MLX5E_10GBASE_ER): |
| 344 | *active_width = IB_WIDTH_1X; |
| 345 | *active_speed = IB_SPEED_QDR; |
| 346 | break; |
| 347 | case MLX5E_PROT_MASK(MLX5E_25GBASE_CR): |
| 348 | case MLX5E_PROT_MASK(MLX5E_25GBASE_KR): |
| 349 | case MLX5E_PROT_MASK(MLX5E_25GBASE_SR): |
| 350 | *active_width = IB_WIDTH_1X; |
| 351 | *active_speed = IB_SPEED_EDR; |
| 352 | break; |
| 353 | case MLX5E_PROT_MASK(MLX5E_40GBASE_CR4): |
| 354 | case MLX5E_PROT_MASK(MLX5E_40GBASE_KR4): |
| 355 | case MLX5E_PROT_MASK(MLX5E_40GBASE_SR4): |
| 356 | case MLX5E_PROT_MASK(MLX5E_40GBASE_LR4): |
| 357 | *active_width = IB_WIDTH_4X; |
| 358 | *active_speed = IB_SPEED_QDR; |
| 359 | break; |
| 360 | case MLX5E_PROT_MASK(MLX5E_50GBASE_CR2): |
| 361 | case MLX5E_PROT_MASK(MLX5E_50GBASE_KR2): |
| 362 | case MLX5E_PROT_MASK(MLX5E_50GBASE_SR2): |
| 363 | *active_width = IB_WIDTH_1X; |
| 364 | *active_speed = IB_SPEED_HDR; |
| 365 | break; |
| 366 | case MLX5E_PROT_MASK(MLX5E_56GBASE_R4): |
| 367 | *active_width = IB_WIDTH_4X; |
| 368 | *active_speed = IB_SPEED_FDR; |
| 369 | break; |
| 370 | case MLX5E_PROT_MASK(MLX5E_100GBASE_CR4): |
| 371 | case MLX5E_PROT_MASK(MLX5E_100GBASE_SR4): |
| 372 | case MLX5E_PROT_MASK(MLX5E_100GBASE_KR4): |
| 373 | case MLX5E_PROT_MASK(MLX5E_100GBASE_LR4): |
| 374 | *active_width = IB_WIDTH_4X; |
| 375 | *active_speed = IB_SPEED_EDR; |
| 376 | break; |
| 377 | default: |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 384 | static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, |
| 385 | struct ib_port_attr *props) |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 386 | { |
| 387 | struct mlx5_ib_dev *dev = to_mdev(device); |
Colin Ian King | da005f9 | 2018-01-09 15:55:43 +0000 | [diff] [blame] | 388 | struct mlx5_core_dev *mdev; |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 389 | struct net_device *ndev, *upper; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 390 | enum ib_mtu ndev_ib_mtu; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 391 | bool put_mdev = true; |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 392 | u16 qkey_viol_cntr; |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 393 | u32 eth_prot_oper; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 394 | u8 mdev_port_num; |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 395 | int err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 396 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 397 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 398 | if (!mdev) { |
| 399 | /* This means the port isn't affiliated yet. Get the |
| 400 | * info for the master port instead. |
| 401 | */ |
| 402 | put_mdev = false; |
| 403 | mdev = dev->mdev; |
| 404 | mdev_port_num = 1; |
| 405 | port_num = 1; |
| 406 | } |
| 407 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 408 | /* Possible bad flows are checked before filling out props so in case |
| 409 | * of an error it will still be zeroed out. |
Noa Osherovich | 50f22fd | 2017-04-20 20:53:32 +0300 | [diff] [blame] | 410 | */ |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 411 | err = mlx5_query_port_eth_proto_oper(mdev, ð_prot_oper, |
| 412 | mdev_port_num); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 413 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 414 | goto out; |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 415 | |
Honggang Li | 7672ed3 | 2018-03-16 10:37:13 +0800 | [diff] [blame] | 416 | props->active_width = IB_WIDTH_4X; |
| 417 | props->active_speed = IB_SPEED_QDR; |
| 418 | |
Noa Osherovich | f1b65df | 2017-04-20 20:53:33 +0300 | [diff] [blame] | 419 | translate_eth_proto_oper(eth_prot_oper, &props->active_speed, |
| 420 | &props->active_width); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 421 | |
Jason Gunthorpe | 2f944c0 | 2018-07-04 15:57:48 +0300 | [diff] [blame] | 422 | props->port_cap_flags |= IB_PORT_CM_SUP; |
| 423 | props->ip_gids = true; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 424 | |
| 425 | props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev, |
| 426 | roce_address_table_size); |
| 427 | props->max_mtu = IB_MTU_4096; |
| 428 | props->max_msg_sz = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg); |
| 429 | props->pkey_tbl_len = 1; |
| 430 | props->state = IB_PORT_DOWN; |
| 431 | props->phys_state = 3; |
| 432 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 433 | mlx5_query_nic_vport_qkey_viol_cntr(mdev, &qkey_viol_cntr); |
Leon Romanovsky | c876a1b | 2016-01-09 13:06:25 +0200 | [diff] [blame] | 434 | props->qkey_viol_cntr = qkey_viol_cntr; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 435 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 436 | /* If this is a stub query for an unaffiliated port stop here */ |
| 437 | if (!put_mdev) |
| 438 | goto out; |
| 439 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 440 | ndev = mlx5_ib_get_netdev(device, port_num); |
| 441 | if (!ndev) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 442 | goto out; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 443 | |
Aviv Heller | 88621df | 2016-09-18 20:48:02 +0300 | [diff] [blame] | 444 | if (mlx5_lag_is_active(dev->mdev)) { |
| 445 | rcu_read_lock(); |
| 446 | upper = netdev_master_upper_dev_get_rcu(ndev); |
| 447 | if (upper) { |
| 448 | dev_put(ndev); |
| 449 | ndev = upper; |
| 450 | dev_hold(ndev); |
| 451 | } |
| 452 | rcu_read_unlock(); |
| 453 | } |
| 454 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 455 | if (netif_running(ndev) && netif_carrier_ok(ndev)) { |
| 456 | props->state = IB_PORT_ACTIVE; |
| 457 | props->phys_state = 5; |
| 458 | } |
| 459 | |
| 460 | ndev_ib_mtu = iboe_get_mtu(ndev->mtu); |
| 461 | |
| 462 | dev_put(ndev); |
| 463 | |
| 464 | props->active_mtu = min(props->max_mtu, ndev_ib_mtu); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 465 | out: |
| 466 | if (put_mdev) |
| 467 | mlx5_ib_put_native_port_mdev(dev, port_num); |
| 468 | return err; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 469 | } |
| 470 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 471 | static int set_roce_addr(struct mlx5_ib_dev *dev, u8 port_num, |
| 472 | unsigned int index, const union ib_gid *gid, |
| 473 | const struct ib_gid_attr *attr) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 474 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 475 | enum ib_gid_type gid_type = IB_GID_TYPE_IB; |
| 476 | u8 roce_version = 0; |
| 477 | u8 roce_l3_type = 0; |
| 478 | bool vlan = false; |
| 479 | u8 mac[ETH_ALEN]; |
| 480 | u16 vlan_id = 0; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 481 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 482 | if (gid) { |
| 483 | gid_type = attr->gid_type; |
| 484 | ether_addr_copy(mac, attr->ndev->dev_addr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 485 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 486 | if (is_vlan_dev(attr->ndev)) { |
| 487 | vlan = true; |
| 488 | vlan_id = vlan_dev_vlan_id(attr->ndev); |
| 489 | } |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 492 | switch (gid_type) { |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 493 | case IB_GID_TYPE_IB: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 494 | roce_version = MLX5_ROCE_VERSION_1; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 495 | break; |
| 496 | case IB_GID_TYPE_ROCE_UDP_ENCAP: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 497 | roce_version = MLX5_ROCE_VERSION_2; |
| 498 | if (ipv6_addr_v4mapped((void *)gid)) |
| 499 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV4; |
| 500 | else |
| 501 | roce_l3_type = MLX5_ROCE_L3_TYPE_IPV6; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 502 | break; |
| 503 | |
| 504 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 505 | mlx5_ib_warn(dev, "Unexpected GID type %u\n", gid_type); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 506 | } |
| 507 | |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 508 | return mlx5_core_roce_gid_set(dev->mdev, index, roce_version, |
| 509 | roce_l3_type, gid->raw, mac, vlan, |
Daniel Jurgens | cfe4e37 | 2018-01-04 17:25:41 +0200 | [diff] [blame] | 510 | vlan_id, port_num); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 511 | } |
| 512 | |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 513 | static int mlx5_ib_add_gid(const struct ib_gid_attr *attr, |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 514 | __always_unused void **context) |
| 515 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 516 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
Parav Pandit | f4df9a7 | 2018-06-05 08:40:16 +0300 | [diff] [blame] | 517 | attr->index, &attr->gid, attr); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 520 | static int mlx5_ib_del_gid(const struct ib_gid_attr *attr, |
| 521 | __always_unused void **context) |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 522 | { |
Parav Pandit | 414448d | 2018-04-01 15:08:24 +0300 | [diff] [blame] | 523 | return set_roce_addr(to_mdev(attr->device), attr->port_num, |
| 524 | attr->index, NULL, NULL); |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 525 | } |
| 526 | |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 527 | __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, |
| 528 | const struct ib_gid_attr *attr) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 529 | { |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 530 | if (attr->gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 531 | return 0; |
| 532 | |
| 533 | return cpu_to_be16(MLX5_CAP_ROCE(dev->mdev, r_roce_min_src_udp_port)); |
| 534 | } |
| 535 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 536 | static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) |
| 537 | { |
Noa Osherovich | 7fae665 | 2016-09-12 19:16:23 +0300 | [diff] [blame] | 538 | if (MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_IB) |
| 539 | return !MLX5_CAP_GEN(dev->mdev, ib_virt); |
| 540 | return 0; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | enum { |
| 544 | MLX5_VPORT_ACCESS_METHOD_MAD, |
| 545 | MLX5_VPORT_ACCESS_METHOD_HCA, |
| 546 | MLX5_VPORT_ACCESS_METHOD_NIC, |
| 547 | }; |
| 548 | |
| 549 | static int mlx5_get_vport_access_method(struct ib_device *ibdev) |
| 550 | { |
| 551 | if (mlx5_use_mad_ifc(to_mdev(ibdev))) |
| 552 | return MLX5_VPORT_ACCESS_METHOD_MAD; |
| 553 | |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 554 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 555 | IB_LINK_LAYER_ETHERNET) |
| 556 | return MLX5_VPORT_ACCESS_METHOD_NIC; |
| 557 | |
| 558 | return MLX5_VPORT_ACCESS_METHOD_HCA; |
| 559 | } |
| 560 | |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 561 | static void get_atomic_caps(struct mlx5_ib_dev *dev, |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 562 | u8 atomic_size_qp, |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 563 | struct ib_device_attr *props) |
| 564 | { |
| 565 | u8 tmp; |
| 566 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 567 | u8 atomic_req_8B_endianness_mode = |
Or Gerlitz | bd10838 | 2017-05-28 15:24:17 +0300 | [diff] [blame] | 568 | MLX5_CAP_ATOMIC(dev->mdev, atomic_req_8B_endianness_mode); |
Eran Ben Elisha | da7525d | 2015-12-14 16:34:10 +0200 | [diff] [blame] | 569 | |
| 570 | /* Check if HW supports 8 bytes standard atomic operations and capable |
| 571 | * of host endianness respond |
| 572 | */ |
| 573 | tmp = MLX5_ATOMIC_OPS_CMP_SWAP | MLX5_ATOMIC_OPS_FETCH_ADD; |
| 574 | if (((atomic_operations & tmp) == tmp) && |
| 575 | (atomic_size_qp & MLX5_ATOMIC_SIZE_QP_8BYTES) && |
| 576 | (atomic_req_8B_endianness_mode)) { |
| 577 | props->atomic_cap = IB_ATOMIC_HCA; |
| 578 | } else { |
| 579 | props->atomic_cap = IB_ATOMIC_NONE; |
| 580 | } |
| 581 | } |
| 582 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 583 | static void get_atomic_caps_qp(struct mlx5_ib_dev *dev, |
| 584 | struct ib_device_attr *props) |
| 585 | { |
| 586 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 587 | |
| 588 | get_atomic_caps(dev, atomic_size_qp, props); |
| 589 | } |
| 590 | |
| 591 | static void get_atomic_caps_dc(struct mlx5_ib_dev *dev, |
| 592 | struct ib_device_attr *props) |
| 593 | { |
| 594 | u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc); |
| 595 | |
| 596 | get_atomic_caps(dev, atomic_size_qp, props); |
| 597 | } |
| 598 | |
| 599 | bool mlx5_ib_dc_atomic_is_supported(struct mlx5_ib_dev *dev) |
| 600 | { |
| 601 | struct ib_device_attr props = {}; |
| 602 | |
| 603 | get_atomic_caps_dc(dev, &props); |
| 604 | return (props.atomic_cap == IB_ATOMIC_HCA) ? true : false; |
| 605 | } |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 606 | static int mlx5_query_system_image_guid(struct ib_device *ibdev, |
| 607 | __be64 *sys_image_guid) |
| 608 | { |
| 609 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 610 | struct mlx5_core_dev *mdev = dev->mdev; |
| 611 | u64 tmp; |
| 612 | int err; |
| 613 | |
| 614 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 615 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 616 | return mlx5_query_mad_ifc_system_image_guid(ibdev, |
| 617 | sys_image_guid); |
| 618 | |
| 619 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 620 | err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 621 | break; |
| 622 | |
| 623 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 624 | err = mlx5_query_nic_vport_system_image_guid(mdev, &tmp); |
| 625 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 626 | |
| 627 | default: |
| 628 | return -EINVAL; |
| 629 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 630 | |
| 631 | if (!err) |
| 632 | *sys_image_guid = cpu_to_be64(tmp); |
| 633 | |
| 634 | return err; |
| 635 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static int mlx5_query_max_pkeys(struct ib_device *ibdev, |
| 639 | u16 *max_pkeys) |
| 640 | { |
| 641 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 642 | struct mlx5_core_dev *mdev = dev->mdev; |
| 643 | |
| 644 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 645 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 646 | return mlx5_query_mad_ifc_max_pkeys(ibdev, max_pkeys); |
| 647 | |
| 648 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 649 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 650 | *max_pkeys = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, |
| 651 | pkey_table_size)); |
| 652 | return 0; |
| 653 | |
| 654 | default: |
| 655 | return -EINVAL; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | static int mlx5_query_vendor_id(struct ib_device *ibdev, |
| 660 | u32 *vendor_id) |
| 661 | { |
| 662 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 663 | |
| 664 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 665 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 666 | return mlx5_query_mad_ifc_vendor_id(ibdev, vendor_id); |
| 667 | |
| 668 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 669 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 670 | return mlx5_core_query_vendor_id(dev->mdev, vendor_id); |
| 671 | |
| 672 | default: |
| 673 | return -EINVAL; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | static int mlx5_query_node_guid(struct mlx5_ib_dev *dev, |
| 678 | __be64 *node_guid) |
| 679 | { |
| 680 | u64 tmp; |
| 681 | int err; |
| 682 | |
| 683 | switch (mlx5_get_vport_access_method(&dev->ib_dev)) { |
| 684 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 685 | return mlx5_query_mad_ifc_node_guid(dev, node_guid); |
| 686 | |
| 687 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 688 | err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp); |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 689 | break; |
| 690 | |
| 691 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
| 692 | err = mlx5_query_nic_vport_node_guid(dev->mdev, &tmp); |
| 693 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 694 | |
| 695 | default: |
| 696 | return -EINVAL; |
| 697 | } |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 698 | |
| 699 | if (!err) |
| 700 | *node_guid = cpu_to_be64(tmp); |
| 701 | |
| 702 | return err; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | struct mlx5_reg_node_desc { |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 706 | u8 desc[IB_DEVICE_NODE_DESC_MAX]; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 707 | }; |
| 708 | |
| 709 | static int mlx5_query_node_desc(struct mlx5_ib_dev *dev, char *node_desc) |
| 710 | { |
| 711 | struct mlx5_reg_node_desc in; |
| 712 | |
| 713 | if (mlx5_use_mad_ifc(dev)) |
| 714 | return mlx5_query_mad_ifc_node_desc(dev, node_desc); |
| 715 | |
| 716 | memset(&in, 0, sizeof(in)); |
| 717 | |
| 718 | return mlx5_core_access_reg(dev->mdev, &in, sizeof(in), node_desc, |
| 719 | sizeof(struct mlx5_reg_node_desc), |
| 720 | MLX5_REG_NODE_DESC, 0, 0); |
| 721 | } |
| 722 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 723 | static int mlx5_ib_query_device(struct ib_device *ibdev, |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 724 | struct ib_device_attr *props, |
| 725 | struct ib_udata *uhw) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 726 | { |
| 727 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 728 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 729 | int err = -ENOMEM; |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 730 | int max_sq_desc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 731 | int max_rq_sg; |
| 732 | int max_sq_sg; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 733 | u64 min_page_size = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 734 | bool raw_support = !mlx5_core_mp_enabled(mdev); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 735 | struct mlx5_ib_query_device_resp resp = {}; |
| 736 | size_t resp_len; |
| 737 | u64 max_tso; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 738 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 739 | resp_len = sizeof(resp.comp_mask) + sizeof(resp.response_length); |
| 740 | if (uhw->outlen && uhw->outlen < resp_len) |
| 741 | return -EINVAL; |
| 742 | else |
| 743 | resp.response_length = resp_len; |
| 744 | |
| 745 | if (uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen)) |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 746 | return -EINVAL; |
| 747 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 748 | memset(props, 0, sizeof(*props)); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 749 | err = mlx5_query_system_image_guid(ibdev, |
| 750 | &props->sys_image_guid); |
| 751 | if (err) |
| 752 | return err; |
| 753 | |
| 754 | err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys); |
| 755 | if (err) |
| 756 | return err; |
| 757 | |
| 758 | err = mlx5_query_vendor_id(ibdev, &props->vendor_id); |
| 759 | if (err) |
| 760 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 761 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 762 | props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) | |
| 763 | (fw_rev_min(dev->mdev) << 16) | |
| 764 | fw_rev_sub(dev->mdev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 765 | props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | |
| 766 | IB_DEVICE_PORT_ACTIVE_EVENT | |
| 767 | IB_DEVICE_SYS_IMAGE_GUID | |
Eli Cohen | 1a4c3a3 | 2014-02-06 17:41:25 +0200 | [diff] [blame] | 768 | IB_DEVICE_RC_RNR_NAK_GEN; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 769 | |
| 770 | if (MLX5_CAP_GEN(mdev, pkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 771 | props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 772 | if (MLX5_CAP_GEN(mdev, qkv)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 773 | props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 774 | if (MLX5_CAP_GEN(mdev, apm)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 775 | props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 776 | if (MLX5_CAP_GEN(mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 777 | props->device_cap_flags |= IB_DEVICE_XRC; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 778 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
| 779 | props->device_cap_flags |= IB_DEVICE_MEM_WINDOW | |
| 780 | IB_DEVICE_MEM_WINDOW_TYPE_2B; |
| 781 | props->max_mw = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 782 | /* We support 'Gappy' memory registration too */ |
| 783 | props->device_cap_flags |= IB_DEVICE_SG_GAPS_REG; |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 784 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 785 | props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 786 | if (MLX5_CAP_GEN(mdev, sho)) { |
Sagi Grimberg | 2dea909 | 2014-02-23 14:19:13 +0200 | [diff] [blame] | 787 | props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER; |
| 788 | /* At this stage no support for signature handover */ |
| 789 | props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 | |
| 790 | IB_PROT_T10DIF_TYPE_2 | |
| 791 | IB_PROT_T10DIF_TYPE_3; |
| 792 | props->sig_guard_cap = IB_GUARD_T10DIF_CRC | |
| 793 | IB_GUARD_T10DIF_CSUM; |
| 794 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 795 | if (MLX5_CAP_GEN(mdev, block_lb_mc)) |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 796 | props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 797 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 798 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 799 | if (MLX5_CAP_ETH(mdev, csum_cap)) { |
| 800 | /* Legacy bit to support old userspace libraries */ |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 801 | props->device_cap_flags |= IB_DEVICE_RAW_IP_CSUM; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 802 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_IP_CSUM; |
| 803 | } |
| 804 | |
| 805 | if (MLX5_CAP_ETH(dev->mdev, vlan_cap)) |
| 806 | props->raw_packet_caps |= |
| 807 | IB_RAW_PACKET_CAP_CVLAN_STRIPPING; |
Bodong Wang | 88115fe | 2015-12-18 13:53:20 +0200 | [diff] [blame] | 808 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 809 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) { |
| 810 | max_tso = MLX5_CAP_ETH(mdev, max_lso_cap); |
| 811 | if (max_tso) { |
| 812 | resp.tso_caps.max_tso = 1 << max_tso; |
| 813 | resp.tso_caps.supported_qpts |= |
| 814 | 1 << IB_QPT_RAW_PACKET; |
| 815 | resp.response_length += sizeof(resp.tso_caps); |
| 816 | } |
| 817 | } |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 818 | |
| 819 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) { |
| 820 | resp.rss_caps.rx_hash_function = |
| 821 | MLX5_RX_HASH_FUNC_TOEPLITZ; |
| 822 | resp.rss_caps.rx_hash_fields_mask = |
| 823 | MLX5_RX_HASH_SRC_IPV4 | |
| 824 | MLX5_RX_HASH_DST_IPV4 | |
| 825 | MLX5_RX_HASH_SRC_IPV6 | |
| 826 | MLX5_RX_HASH_DST_IPV6 | |
| 827 | MLX5_RX_HASH_SRC_PORT_TCP | |
| 828 | MLX5_RX_HASH_DST_PORT_TCP | |
| 829 | MLX5_RX_HASH_SRC_PORT_UDP | |
Maor Gottlieb | 4e2b53a | 2017-12-24 14:51:25 +0200 | [diff] [blame] | 830 | MLX5_RX_HASH_DST_PORT_UDP | |
| 831 | MLX5_RX_HASH_INNER; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 832 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
| 833 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 834 | resp.rss_caps.rx_hash_fields_mask |= |
| 835 | MLX5_RX_HASH_IPSEC_SPI; |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 836 | resp.response_length += sizeof(resp.rss_caps); |
| 837 | } |
| 838 | } else { |
| 839 | if (field_avail(typeof(resp), tso_caps, uhw->outlen)) |
| 840 | resp.response_length += sizeof(resp.tso_caps); |
| 841 | if (field_avail(typeof(resp), rss_caps, uhw->outlen)) |
| 842 | resp.response_length += sizeof(resp.rss_caps); |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 843 | } |
| 844 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 845 | if (MLX5_CAP_GEN(mdev, ipoib_basic_offloads)) { |
| 846 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 847 | props->device_cap_flags |= IB_DEVICE_UD_TSO; |
| 848 | } |
| 849 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 850 | if (MLX5_CAP_GEN(dev->mdev, rq_delay_drop) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 851 | MLX5_CAP_GEN(dev->mdev, general_notification_event) && |
| 852 | raw_support) |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 853 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_DELAY_DROP; |
| 854 | |
Yishai Hadas | 1d54f89 | 2017-06-08 16:15:11 +0300 | [diff] [blame] | 855 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
| 856 | MLX5_CAP_IPOIB_ENHANCED(mdev, csum_cap)) |
| 857 | props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; |
| 858 | |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 859 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 860 | MLX5_CAP_ETH(dev->mdev, scatter_fcs) && |
| 861 | raw_support) { |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 862 | /* Legacy bit to support old userspace libraries */ |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 863 | props->device_cap_flags |= IB_DEVICE_RAW_SCATTER_FCS; |
Noa Osherovich | e816133 | 2017-01-18 15:40:01 +0200 | [diff] [blame] | 864 | props->raw_packet_caps |= IB_RAW_PACKET_CAP_SCATTER_FCS; |
| 865 | } |
Majd Dibbiny | cff5a0f | 2016-04-17 17:19:38 +0300 | [diff] [blame] | 866 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 867 | if (MLX5_CAP_DEV_MEM(mdev, memic)) { |
| 868 | props->max_dm_size = |
| 869 | MLX5_CAP_DEV_MEM(mdev, max_memic_size); |
| 870 | } |
| 871 | |
Maor Gottlieb | da6d6ba3 | 2016-06-04 15:15:28 +0300 | [diff] [blame] | 872 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_BYPASS)) |
| 873 | props->device_cap_flags |= IB_DEVICE_MANAGED_FLOW_STEERING; |
| 874 | |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 875 | if (MLX5_CAP_GEN(mdev, end_pad)) |
| 876 | props->device_cap_flags |= IB_DEVICE_PCI_WRITE_END_PADDING; |
| 877 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 878 | props->vendor_part_id = mdev->pdev->device; |
| 879 | props->hw_ver = mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 880 | |
| 881 | props->max_mr_size = ~0ull; |
Sagi Grimberg | e0238a6 | 2015-07-21 14:40:12 +0300 | [diff] [blame] | 882 | props->page_size_cap = ~(min_page_size - 1); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 883 | props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp); |
| 884 | props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
| 885 | max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) / |
| 886 | sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 887 | max_sq_desc = min_t(int, MLX5_CAP_GEN(mdev, max_wqe_sz_sq), 512); |
| 888 | max_sq_sg = (max_sq_desc - sizeof(struct mlx5_wqe_ctrl_seg) - |
| 889 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 890 | sizeof(struct mlx5_wqe_data_seg); |
Steve Wise | 33023fb | 2018-06-18 08:05:26 -0700 | [diff] [blame] | 891 | props->max_send_sge = max_sq_sg; |
| 892 | props->max_recv_sge = max_rq_sg; |
Sagi Grimberg | 986ef95 | 2016-03-31 19:03:25 +0300 | [diff] [blame] | 893 | props->max_sge_rd = MLX5_MAX_SGE_RD; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 894 | props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq); |
Leon Romanovsky | 9f17768 | 2016-01-14 08:11:40 +0200 | [diff] [blame] | 895 | props->max_cqe = (1 << MLX5_CAP_GEN(mdev, log_max_cq_sz)) - 1; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 896 | props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey); |
| 897 | props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd); |
| 898 | props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp); |
| 899 | props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp); |
| 900 | props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq); |
| 901 | props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1; |
| 902 | props->local_ca_ack_delay = MLX5_CAP_GEN(mdev, local_ca_ack_delay); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 903 | props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 904 | props->max_srq_sge = max_rq_sg - 1; |
Sagi Grimberg | 911f433 | 2016-03-03 13:37:51 +0200 | [diff] [blame] | 905 | props->max_fast_reg_page_list_len = |
| 906 | 1 << MLX5_CAP_GEN(mdev, log_max_klm_list_size); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 907 | get_atomic_caps_qp(dev, props); |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 908 | props->masked_atomic_cap = IB_ATOMIC_NONE; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 909 | props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg); |
| 910 | props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 911 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 912 | props->max_mcast_grp; |
| 913 | props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */ |
Maor Gottlieb | 86695a6 | 2016-10-27 16:36:38 +0300 | [diff] [blame] | 914 | props->max_ah = INT_MAX; |
Matan Barak | 7c60bcb | 2015-12-15 20:30:11 +0200 | [diff] [blame] | 915 | props->hca_core_clock = MLX5_CAP_GEN(mdev, device_frequency_khz); |
| 916 | props->timestamp_mask = 0x7FFFFFFFFFFFFFFFULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 917 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 918 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 919 | if (MLX5_CAP_GEN(mdev, pg)) |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 920 | props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
| 921 | props->odp_caps = dev->odp_caps; |
| 922 | #endif |
| 923 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 924 | if (MLX5_CAP_GEN(mdev, cd)) |
| 925 | props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL; |
| 926 | |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 927 | if (!mlx5_core_is_pf(mdev)) |
| 928 | props->device_cap_flags |= IB_DEVICE_VIRTUAL_FUNCTION; |
| 929 | |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 930 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 931 | IB_LINK_LAYER_ETHERNET && raw_support) { |
Yishai Hadas | 31f69a8 | 2016-08-28 11:28:45 +0300 | [diff] [blame] | 932 | props->rss_caps.max_rwq_indirection_tables = |
| 933 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt); |
| 934 | props->rss_caps.max_rwq_indirection_table_size = |
| 935 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rqt_size); |
| 936 | props->rss_caps.supported_qpts = 1 << IB_QPT_RAW_PACKET; |
| 937 | props->max_wq_type_rq = |
| 938 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_rq); |
| 939 | } |
| 940 | |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 941 | if (MLX5_CAP_GEN(mdev, tag_matching)) { |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 942 | props->tm_caps.max_rndv_hdr_size = MLX5_TM_MAX_RNDV_MSG_SIZE; |
| 943 | props->tm_caps.max_num_tags = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 944 | (1 << MLX5_CAP_GEN(mdev, log_tag_matching_list_sz)) - 1; |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 945 | props->tm_caps.flags = IB_TM_CAP_RC; |
| 946 | props->tm_caps.max_ops = |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 947 | 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 948 | props->tm_caps.max_sge = MLX5_TM_MAX_SGE; |
Artemy Kovalyov | eb76189 | 2017-08-17 15:52:09 +0300 | [diff] [blame] | 949 | } |
| 950 | |
Yonatan Cohen | 87ab3f5 | 2017-11-13 10:51:18 +0200 | [diff] [blame] | 951 | if (MLX5_CAP_GEN(dev->mdev, cq_moderation)) { |
| 952 | props->cq_caps.max_cq_moderation_count = |
| 953 | MLX5_MAX_CQ_COUNT; |
| 954 | props->cq_caps.max_cq_moderation_period = |
| 955 | MLX5_MAX_CQ_PERIOD; |
| 956 | } |
| 957 | |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 958 | if (field_avail(typeof(resp), cqe_comp_caps, uhw->outlen)) { |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 959 | resp.response_length += sizeof(resp.cqe_comp_caps); |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 960 | |
| 961 | if (MLX5_CAP_GEN(dev->mdev, cqe_compression)) { |
| 962 | resp.cqe_comp_caps.max_num = |
| 963 | MLX5_CAP_GEN(dev->mdev, |
| 964 | cqe_compression_max_num); |
| 965 | |
| 966 | resp.cqe_comp_caps.supported_format = |
| 967 | MLX5_IB_CQE_RES_FORMAT_HASH | |
| 968 | MLX5_IB_CQE_RES_FORMAT_CSUM; |
Yonatan Cohen | 6f1006a | 2018-05-27 13:42:34 +0300 | [diff] [blame] | 969 | |
| 970 | if (MLX5_CAP_GEN(dev->mdev, mini_cqe_resp_stride_index)) |
| 971 | resp.cqe_comp_caps.supported_format |= |
| 972 | MLX5_IB_CQE_RES_FORMAT_CSUM_STRIDX; |
Yonatan Cohen | 572f46b | 2018-05-27 13:42:33 +0300 | [diff] [blame] | 973 | } |
Bodong Wang | 7e43a2a | 2016-10-31 12:16:44 +0200 | [diff] [blame] | 974 | } |
| 975 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 976 | if (field_avail(typeof(resp), packet_pacing_caps, uhw->outlen) && |
| 977 | raw_support) { |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 978 | if (MLX5_CAP_QOS(mdev, packet_pacing) && |
| 979 | MLX5_CAP_GEN(mdev, qos)) { |
| 980 | resp.packet_pacing_caps.qp_rate_limit_max = |
| 981 | MLX5_CAP_QOS(mdev, packet_pacing_max_rate); |
| 982 | resp.packet_pacing_caps.qp_rate_limit_min = |
| 983 | MLX5_CAP_QOS(mdev, packet_pacing_min_rate); |
| 984 | resp.packet_pacing_caps.supported_qpts |= |
| 985 | 1 << IB_QPT_RAW_PACKET; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 986 | if (MLX5_CAP_QOS(mdev, packet_pacing_burst_bound) && |
| 987 | MLX5_CAP_QOS(mdev, packet_pacing_typical_size)) |
| 988 | resp.packet_pacing_caps.cap_flags |= |
| 989 | MLX5_IB_PP_SUPPORT_BURST; |
Bodong Wang | d949167 | 2016-12-01 13:43:13 +0200 | [diff] [blame] | 990 | } |
| 991 | resp.response_length += sizeof(resp.packet_pacing_caps); |
| 992 | } |
| 993 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 994 | if (field_avail(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes, |
| 995 | uhw->outlen)) { |
Bodong Wang | 795b609 | 2017-08-17 15:52:34 +0300 | [diff] [blame] | 996 | if (MLX5_CAP_ETH(mdev, multi_pkt_send_wqe)) |
| 997 | resp.mlx5_ib_support_multi_pkt_send_wqes = |
| 998 | MLX5_IB_ALLOW_MPW; |
Bodong Wang | 050da90 | 2017-08-17 15:52:35 +0300 | [diff] [blame] | 999 | |
| 1000 | if (MLX5_CAP_ETH(mdev, enhanced_multi_pkt_send_wqe)) |
| 1001 | resp.mlx5_ib_support_multi_pkt_send_wqes |= |
| 1002 | MLX5_IB_SUPPORT_EMPW; |
| 1003 | |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1004 | resp.response_length += |
| 1005 | sizeof(resp.mlx5_ib_support_multi_pkt_send_wqes); |
| 1006 | } |
| 1007 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1008 | if (field_avail(typeof(resp), flags, uhw->outlen)) { |
| 1009 | resp.response_length += sizeof(resp.flags); |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1010 | |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1011 | if (MLX5_CAP_GEN(mdev, cqe_compression_128)) |
| 1012 | resp.flags |= |
| 1013 | MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_COMP; |
Guy Levi | 7a0c8f4 | 2017-10-19 08:25:53 +0300 | [diff] [blame] | 1014 | |
| 1015 | if (MLX5_CAP_GEN(mdev, cqe_128_always)) |
| 1016 | resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_PAD; |
Guy Levi | de57f2a | 2017-10-19 08:25:52 +0300 | [diff] [blame] | 1017 | } |
Leon Romanovsky | 9f88520 | 2017-01-02 11:37:39 +0200 | [diff] [blame] | 1018 | |
Noa Osherovich | 96dc3fc | 2017-08-17 15:52:28 +0300 | [diff] [blame] | 1019 | if (field_avail(typeof(resp), sw_parsing_caps, |
| 1020 | uhw->outlen)) { |
| 1021 | resp.response_length += sizeof(resp.sw_parsing_caps); |
| 1022 | if (MLX5_CAP_ETH(mdev, swp)) { |
| 1023 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1024 | MLX5_IB_SW_PARSING; |
| 1025 | |
| 1026 | if (MLX5_CAP_ETH(mdev, swp_csum)) |
| 1027 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1028 | MLX5_IB_SW_PARSING_CSUM; |
| 1029 | |
| 1030 | if (MLX5_CAP_ETH(mdev, swp_lso)) |
| 1031 | resp.sw_parsing_caps.sw_parsing_offloads |= |
| 1032 | MLX5_IB_SW_PARSING_LSO; |
| 1033 | |
| 1034 | if (resp.sw_parsing_caps.sw_parsing_offloads) |
| 1035 | resp.sw_parsing_caps.supported_qpts = |
| 1036 | BIT(IB_QPT_RAW_PACKET); |
| 1037 | } |
| 1038 | } |
| 1039 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 1040 | if (field_avail(typeof(resp), striding_rq_caps, uhw->outlen) && |
| 1041 | raw_support) { |
Noa Osherovich | b4f3459 | 2017-10-17 18:01:12 +0300 | [diff] [blame] | 1042 | resp.response_length += sizeof(resp.striding_rq_caps); |
| 1043 | if (MLX5_CAP_GEN(mdev, striding_rq)) { |
| 1044 | resp.striding_rq_caps.min_single_stride_log_num_of_bytes = |
| 1045 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1046 | resp.striding_rq_caps.max_single_stride_log_num_of_bytes = |
| 1047 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES; |
| 1048 | resp.striding_rq_caps.min_single_wqe_log_num_of_strides = |
| 1049 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1050 | resp.striding_rq_caps.max_single_wqe_log_num_of_strides = |
| 1051 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES; |
| 1052 | resp.striding_rq_caps.supported_qpts = |
| 1053 | BIT(IB_QPT_RAW_PACKET); |
| 1054 | } |
| 1055 | } |
| 1056 | |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1057 | if (field_avail(typeof(resp), tunnel_offloads_caps, |
| 1058 | uhw->outlen)) { |
| 1059 | resp.response_length += sizeof(resp.tunnel_offloads_caps); |
| 1060 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan)) |
| 1061 | resp.tunnel_offloads_caps |= |
| 1062 | MLX5_IB_TUNNELED_OFFLOADS_VXLAN; |
| 1063 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_geneve_rx)) |
| 1064 | resp.tunnel_offloads_caps |= |
| 1065 | MLX5_IB_TUNNELED_OFFLOADS_GENEVE; |
| 1066 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_gre)) |
| 1067 | resp.tunnel_offloads_caps |= |
| 1068 | MLX5_IB_TUNNELED_OFFLOADS_GRE; |
Ariel Levkovich | e818e25 | 2018-05-13 14:33:35 +0300 | [diff] [blame] | 1069 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1070 | MLX5_FLEX_PROTO_CW_MPLS_GRE) |
| 1071 | resp.tunnel_offloads_caps |= |
| 1072 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_GRE; |
| 1073 | if (MLX5_CAP_GEN(mdev, flex_parser_protocols) & |
| 1074 | MLX5_FLEX_PROTO_CW_MPLS_UDP) |
| 1075 | resp.tunnel_offloads_caps |= |
| 1076 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_UDP; |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1077 | } |
| 1078 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1079 | if (uhw->outlen) { |
| 1080 | err = ib_copy_to_udata(uhw, &resp, resp.response_length); |
| 1081 | |
| 1082 | if (err) |
| 1083 | return err; |
| 1084 | } |
| 1085 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1086 | return 0; |
| 1087 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1088 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1089 | enum mlx5_ib_width { |
| 1090 | MLX5_IB_WIDTH_1X = 1 << 0, |
| 1091 | MLX5_IB_WIDTH_2X = 1 << 1, |
| 1092 | MLX5_IB_WIDTH_4X = 1 << 2, |
| 1093 | MLX5_IB_WIDTH_8X = 1 << 3, |
| 1094 | MLX5_IB_WIDTH_12X = 1 << 4 |
| 1095 | }; |
| 1096 | |
| 1097 | static int translate_active_width(struct ib_device *ibdev, u8 active_width, |
| 1098 | u8 *ib_width) |
| 1099 | { |
| 1100 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1101 | int err = 0; |
| 1102 | |
| 1103 | if (active_width & MLX5_IB_WIDTH_1X) { |
| 1104 | *ib_width = IB_WIDTH_1X; |
| 1105 | } else if (active_width & MLX5_IB_WIDTH_2X) { |
| 1106 | mlx5_ib_dbg(dev, "active_width %d is not supported by IB spec\n", |
| 1107 | (int)active_width); |
| 1108 | err = -EINVAL; |
| 1109 | } else if (active_width & MLX5_IB_WIDTH_4X) { |
| 1110 | *ib_width = IB_WIDTH_4X; |
| 1111 | } else if (active_width & MLX5_IB_WIDTH_8X) { |
| 1112 | *ib_width = IB_WIDTH_8X; |
| 1113 | } else if (active_width & MLX5_IB_WIDTH_12X) { |
| 1114 | *ib_width = IB_WIDTH_12X; |
| 1115 | } else { |
| 1116 | mlx5_ib_dbg(dev, "Invalid active_width %d\n", |
| 1117 | (int)active_width); |
| 1118 | err = -EINVAL; |
| 1119 | } |
| 1120 | |
| 1121 | return err; |
| 1122 | } |
| 1123 | |
| 1124 | static int mlx5_mtu_to_ib_mtu(int mtu) |
| 1125 | { |
| 1126 | switch (mtu) { |
| 1127 | case 256: return 1; |
| 1128 | case 512: return 2; |
| 1129 | case 1024: return 3; |
| 1130 | case 2048: return 4; |
| 1131 | case 4096: return 5; |
| 1132 | default: |
| 1133 | pr_warn("invalid mtu\n"); |
| 1134 | return -1; |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | enum ib_max_vl_num { |
| 1139 | __IB_MAX_VL_0 = 1, |
| 1140 | __IB_MAX_VL_0_1 = 2, |
| 1141 | __IB_MAX_VL_0_3 = 3, |
| 1142 | __IB_MAX_VL_0_7 = 4, |
| 1143 | __IB_MAX_VL_0_14 = 5, |
| 1144 | }; |
| 1145 | |
| 1146 | enum mlx5_vl_hw_cap { |
| 1147 | MLX5_VL_HW_0 = 1, |
| 1148 | MLX5_VL_HW_0_1 = 2, |
| 1149 | MLX5_VL_HW_0_2 = 3, |
| 1150 | MLX5_VL_HW_0_3 = 4, |
| 1151 | MLX5_VL_HW_0_4 = 5, |
| 1152 | MLX5_VL_HW_0_5 = 6, |
| 1153 | MLX5_VL_HW_0_6 = 7, |
| 1154 | MLX5_VL_HW_0_7 = 8, |
| 1155 | MLX5_VL_HW_0_14 = 15 |
| 1156 | }; |
| 1157 | |
| 1158 | static int translate_max_vl_num(struct ib_device *ibdev, u8 vl_hw_cap, |
| 1159 | u8 *max_vl_num) |
| 1160 | { |
| 1161 | switch (vl_hw_cap) { |
| 1162 | case MLX5_VL_HW_0: |
| 1163 | *max_vl_num = __IB_MAX_VL_0; |
| 1164 | break; |
| 1165 | case MLX5_VL_HW_0_1: |
| 1166 | *max_vl_num = __IB_MAX_VL_0_1; |
| 1167 | break; |
| 1168 | case MLX5_VL_HW_0_3: |
| 1169 | *max_vl_num = __IB_MAX_VL_0_3; |
| 1170 | break; |
| 1171 | case MLX5_VL_HW_0_7: |
| 1172 | *max_vl_num = __IB_MAX_VL_0_7; |
| 1173 | break; |
| 1174 | case MLX5_VL_HW_0_14: |
| 1175 | *max_vl_num = __IB_MAX_VL_0_14; |
| 1176 | break; |
| 1177 | |
| 1178 | default: |
| 1179 | return -EINVAL; |
| 1180 | } |
| 1181 | |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port, |
| 1186 | struct ib_port_attr *props) |
| 1187 | { |
| 1188 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1189 | struct mlx5_core_dev *mdev = dev->mdev; |
| 1190 | struct mlx5_hca_vport_context *rep; |
Saeed Mahameed | 046339e | 2016-04-22 00:33:03 +0300 | [diff] [blame] | 1191 | u16 max_mtu; |
| 1192 | u16 oper_mtu; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1193 | int err; |
| 1194 | u8 ib_link_width_oper; |
| 1195 | u8 vl_hw_cap; |
| 1196 | |
| 1197 | rep = kzalloc(sizeof(*rep), GFP_KERNEL); |
| 1198 | if (!rep) { |
| 1199 | err = -ENOMEM; |
| 1200 | goto out; |
| 1201 | } |
| 1202 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1203 | /* props being zeroed by the caller, avoid zeroing it here */ |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1204 | |
| 1205 | err = mlx5_query_hca_vport_context(mdev, 0, port, 0, rep); |
| 1206 | if (err) |
| 1207 | goto out; |
| 1208 | |
| 1209 | props->lid = rep->lid; |
| 1210 | props->lmc = rep->lmc; |
| 1211 | props->sm_lid = rep->sm_lid; |
| 1212 | props->sm_sl = rep->sm_sl; |
| 1213 | props->state = rep->vport_state; |
| 1214 | props->phys_state = rep->port_physical_state; |
| 1215 | props->port_cap_flags = rep->cap_mask1; |
| 1216 | props->gid_tbl_len = mlx5_get_gid_table_len(MLX5_CAP_GEN(mdev, gid_table_size)); |
| 1217 | props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg); |
| 1218 | props->pkey_tbl_len = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, pkey_table_size)); |
| 1219 | props->bad_pkey_cntr = rep->pkey_violation_counter; |
| 1220 | props->qkey_viol_cntr = rep->qkey_violation_counter; |
| 1221 | props->subnet_timeout = rep->subnet_timeout; |
| 1222 | props->init_type_reply = rep->init_type_reply; |
| 1223 | |
| 1224 | err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); |
| 1225 | if (err) |
| 1226 | goto out; |
| 1227 | |
| 1228 | err = translate_active_width(ibdev, ib_link_width_oper, |
| 1229 | &props->active_width); |
| 1230 | if (err) |
| 1231 | goto out; |
Noa Osherovich | d5beb7f | 2016-06-02 10:47:53 +0300 | [diff] [blame] | 1232 | err = mlx5_query_port_ib_proto_oper(mdev, &props->active_speed, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1233 | if (err) |
| 1234 | goto out; |
| 1235 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1236 | mlx5_query_port_max_mtu(mdev, &max_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1237 | |
| 1238 | props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu); |
| 1239 | |
Saeed Mahameed | facc969 | 2015-06-11 14:47:27 +0300 | [diff] [blame] | 1240 | mlx5_query_port_oper_mtu(mdev, &oper_mtu, port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1241 | |
| 1242 | props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu); |
| 1243 | |
| 1244 | err = mlx5_query_port_vl_hw_cap(mdev, &vl_hw_cap, port); |
| 1245 | if (err) |
| 1246 | goto out; |
| 1247 | |
| 1248 | err = translate_max_vl_num(ibdev, vl_hw_cap, |
| 1249 | &props->max_vl_num); |
| 1250 | out: |
| 1251 | kfree(rep); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1252 | return err; |
| 1253 | } |
| 1254 | |
| 1255 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 1256 | struct ib_port_attr *props) |
| 1257 | { |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1258 | unsigned int count; |
| 1259 | int ret; |
| 1260 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1261 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1262 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1263 | ret = mlx5_query_mad_ifc_port(ibdev, port, props); |
| 1264 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1265 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1266 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1267 | ret = mlx5_query_hca_port(ibdev, port, props); |
| 1268 | break; |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1269 | |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1270 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1271 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1272 | break; |
Achiad Shochat | 3f89a64 | 2015-12-23 18:47:21 +0200 | [diff] [blame] | 1273 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1274 | default: |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1275 | ret = -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1276 | } |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1277 | |
| 1278 | if (!ret && props) { |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1279 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1280 | struct mlx5_core_dev *mdev; |
| 1281 | bool put_mdev = true; |
| 1282 | |
| 1283 | mdev = mlx5_ib_get_native_port_mdev(dev, port, NULL); |
| 1284 | if (!mdev) { |
| 1285 | /* If the port isn't affiliated yet query the master. |
| 1286 | * The master and slave will have the same values. |
| 1287 | */ |
| 1288 | mdev = dev->mdev; |
| 1289 | port = 1; |
| 1290 | put_mdev = false; |
| 1291 | } |
| 1292 | count = mlx5_core_reserved_gids_count(mdev); |
| 1293 | if (put_mdev) |
| 1294 | mlx5_ib_put_native_port_mdev(dev, port); |
Ilan Tayari | 095b092 | 2017-05-14 16:04:30 +0300 | [diff] [blame] | 1295 | props->gid_tbl_len -= count; |
| 1296 | } |
| 1297 | return ret; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1298 | } |
| 1299 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 1300 | static int mlx5_ib_rep_query_port(struct ib_device *ibdev, u8 port, |
| 1301 | struct ib_port_attr *props) |
| 1302 | { |
| 1303 | int ret; |
| 1304 | |
| 1305 | /* Only link layer == ethernet is valid for representors */ |
| 1306 | ret = mlx5_query_port_roce(ibdev, port, props); |
| 1307 | if (ret || !props) |
| 1308 | return ret; |
| 1309 | |
| 1310 | /* We don't support GIDS */ |
| 1311 | props->gid_tbl_len = 0; |
| 1312 | |
| 1313 | return ret; |
| 1314 | } |
| 1315 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1316 | static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 1317 | union ib_gid *gid) |
| 1318 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1319 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1320 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1321 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1322 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1323 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1324 | return mlx5_query_mad_ifc_gids(ibdev, port, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1325 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1326 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1327 | return mlx5_query_hca_vport_gid(mdev, 0, port, 0, index, gid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1328 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1329 | default: |
| 1330 | return -EINVAL; |
| 1331 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1332 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1333 | } |
| 1334 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1335 | static int mlx5_query_hca_nic_pkey(struct ib_device *ibdev, u8 port, |
| 1336 | u16 index, u16 *pkey) |
| 1337 | { |
| 1338 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1339 | struct mlx5_core_dev *mdev; |
| 1340 | bool put_mdev = true; |
| 1341 | u8 mdev_port_num; |
| 1342 | int err; |
| 1343 | |
| 1344 | mdev = mlx5_ib_get_native_port_mdev(dev, port, &mdev_port_num); |
| 1345 | if (!mdev) { |
| 1346 | /* The port isn't affiliated yet, get the PKey from the master |
| 1347 | * port. For RoCE the PKey tables will be the same. |
| 1348 | */ |
| 1349 | put_mdev = false; |
| 1350 | mdev = dev->mdev; |
| 1351 | mdev_port_num = 1; |
| 1352 | } |
| 1353 | |
| 1354 | err = mlx5_query_hca_vport_pkey(mdev, 0, mdev_port_num, 0, |
| 1355 | index, pkey); |
| 1356 | if (put_mdev) |
| 1357 | mlx5_ib_put_native_port_mdev(dev, port); |
| 1358 | |
| 1359 | return err; |
| 1360 | } |
| 1361 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1362 | static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 1363 | u16 *pkey) |
| 1364 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1365 | switch (mlx5_get_vport_access_method(ibdev)) { |
| 1366 | case MLX5_VPORT_ACCESS_METHOD_MAD: |
| 1367 | return mlx5_query_mad_ifc_pkey(ibdev, port, index, pkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1368 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1369 | case MLX5_VPORT_ACCESS_METHOD_HCA: |
| 1370 | case MLX5_VPORT_ACCESS_METHOD_NIC: |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1371 | return mlx5_query_hca_nic_pkey(ibdev, port, index, pkey); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 1372 | default: |
| 1373 | return -EINVAL; |
| 1374 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1375 | } |
| 1376 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1377 | static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask, |
| 1378 | struct ib_device_modify *props) |
| 1379 | { |
| 1380 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1381 | struct mlx5_reg_node_desc in; |
| 1382 | struct mlx5_reg_node_desc out; |
| 1383 | int err; |
| 1384 | |
| 1385 | if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) |
| 1386 | return -EOPNOTSUPP; |
| 1387 | |
| 1388 | if (!(mask & IB_DEVICE_MODIFY_NODE_DESC)) |
| 1389 | return 0; |
| 1390 | |
| 1391 | /* |
| 1392 | * If possible, pass node desc to FW, so it can generate |
| 1393 | * a 144 trap. If cmd fails, just ignore. |
| 1394 | */ |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1395 | memcpy(&in, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1396 | err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1397 | sizeof(out), MLX5_REG_NODE_DESC, 0, 1); |
| 1398 | if (err) |
| 1399 | return err; |
| 1400 | |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 1401 | memcpy(ibdev->node_desc, props->node_desc, IB_DEVICE_NODE_DESC_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1402 | |
| 1403 | return err; |
| 1404 | } |
| 1405 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1406 | static int set_port_caps_atomic(struct mlx5_ib_dev *dev, u8 port_num, u32 mask, |
| 1407 | u32 value) |
| 1408 | { |
| 1409 | struct mlx5_hca_vport_context ctx = {}; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1410 | struct mlx5_core_dev *mdev; |
| 1411 | u8 mdev_port_num; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1412 | int err; |
| 1413 | |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1414 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
| 1415 | if (!mdev) |
| 1416 | return -ENODEV; |
| 1417 | |
| 1418 | err = mlx5_query_hca_vport_context(mdev, 0, mdev_port_num, 0, &ctx); |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1419 | if (err) |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1420 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1421 | |
| 1422 | if (~ctx.cap_mask1_perm & mask) { |
| 1423 | mlx5_ib_warn(dev, "trying to change bitmask 0x%X but change supported 0x%X\n", |
| 1424 | mask, ctx.cap_mask1_perm); |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1425 | err = -EINVAL; |
| 1426 | goto out; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | ctx.cap_mask1 = value; |
| 1430 | ctx.cap_mask1_perm = mask; |
Daniel Jurgens | b3cbd6f | 2018-01-04 17:25:38 +0200 | [diff] [blame] | 1431 | err = mlx5_core_modify_hca_vport_context(mdev, 0, mdev_port_num, |
| 1432 | 0, &ctx); |
| 1433 | |
| 1434 | out: |
| 1435 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1436 | |
| 1437 | return err; |
| 1438 | } |
| 1439 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1440 | static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask, |
| 1441 | struct ib_port_modify *props) |
| 1442 | { |
| 1443 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 1444 | struct ib_port_attr attr; |
| 1445 | u32 tmp; |
| 1446 | int err; |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1447 | u32 change_mask; |
| 1448 | u32 value; |
| 1449 | bool is_ib = (mlx5_ib_port_link_layer(ibdev, port) == |
| 1450 | IB_LINK_LAYER_INFINIBAND); |
| 1451 | |
Majd Dibbiny | ec25587 | 2017-08-23 08:35:42 +0300 | [diff] [blame] | 1452 | /* CM layer calls ib_modify_port() regardless of the link layer. For |
| 1453 | * Ethernet ports, qkey violation and Port capabilities are meaningless. |
| 1454 | */ |
| 1455 | if (!is_ib) |
| 1456 | return 0; |
| 1457 | |
Eli Cohen | cdbe33d | 2017-02-14 07:25:38 +0200 | [diff] [blame] | 1458 | if (MLX5_CAP_GEN(dev->mdev, ib_virt) && is_ib) { |
| 1459 | change_mask = props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1460 | value = ~props->clr_port_cap_mask | props->set_port_cap_mask; |
| 1461 | return set_port_caps_atomic(dev, port, change_mask, value); |
| 1462 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1463 | |
| 1464 | mutex_lock(&dev->cap_mask_mutex); |
| 1465 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 1466 | err = ib_query_port(ibdev, port, &attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1467 | if (err) |
| 1468 | goto out; |
| 1469 | |
| 1470 | tmp = (attr.port_cap_flags | props->set_port_cap_mask) & |
| 1471 | ~props->clr_port_cap_mask; |
| 1472 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1473 | err = mlx5_set_port_caps(dev->mdev, port, tmp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1474 | |
| 1475 | out: |
| 1476 | mutex_unlock(&dev->cap_mask_mutex); |
| 1477 | return err; |
| 1478 | } |
| 1479 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1480 | static void print_lib_caps(struct mlx5_ib_dev *dev, u64 caps) |
| 1481 | { |
| 1482 | mlx5_ib_dbg(dev, "MLX5_LIB_CAP_4K_UAR = %s\n", |
| 1483 | caps & MLX5_LIB_CAP_4K_UAR ? "y" : "n"); |
| 1484 | } |
| 1485 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1486 | static u16 calc_dynamic_bfregs(int uars_per_sys_page) |
| 1487 | { |
| 1488 | /* Large page with non 4k uar support might limit the dynamic size */ |
| 1489 | if (uars_per_sys_page == 1 && PAGE_SIZE > 4096) |
| 1490 | return MLX5_MIN_DYN_BFREGS; |
| 1491 | |
| 1492 | return MLX5_MAX_DYN_BFREGS; |
| 1493 | } |
| 1494 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1495 | static int calc_total_bfregs(struct mlx5_ib_dev *dev, bool lib_uar_4k, |
| 1496 | struct mlx5_ib_alloc_ucontext_req_v2 *req, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1497 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1498 | { |
| 1499 | int uars_per_sys_page; |
| 1500 | int bfregs_per_sys_page; |
| 1501 | int ref_bfregs = req->total_num_bfregs; |
| 1502 | |
| 1503 | if (req->total_num_bfregs == 0) |
| 1504 | return -EINVAL; |
| 1505 | |
| 1506 | BUILD_BUG_ON(MLX5_MAX_BFREGS % MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1507 | BUILD_BUG_ON(MLX5_MAX_BFREGS < MLX5_NON_FP_BFREGS_IN_PAGE); |
| 1508 | |
| 1509 | if (req->total_num_bfregs > MLX5_MAX_BFREGS) |
| 1510 | return -ENOMEM; |
| 1511 | |
| 1512 | uars_per_sys_page = get_uars_per_sys_page(dev, lib_uar_4k); |
| 1513 | bfregs_per_sys_page = uars_per_sys_page * MLX5_NON_FP_BFREGS_PER_UAR; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1514 | /* This holds the required static allocation asked by the user */ |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1515 | req->total_num_bfregs = ALIGN(req->total_num_bfregs, bfregs_per_sys_page); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1516 | if (req->num_low_latency_bfregs > req->total_num_bfregs - 1) |
| 1517 | return -EINVAL; |
| 1518 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1519 | bfregi->num_static_sys_pages = req->total_num_bfregs / bfregs_per_sys_page; |
| 1520 | bfregi->num_dyn_bfregs = ALIGN(calc_dynamic_bfregs(uars_per_sys_page), bfregs_per_sys_page); |
| 1521 | bfregi->total_num_bfregs = req->total_num_bfregs + bfregi->num_dyn_bfregs; |
| 1522 | bfregi->num_sys_pages = bfregi->total_num_bfregs / bfregs_per_sys_page; |
| 1523 | |
| 1524 | mlx5_ib_dbg(dev, "uar_4k: fw support %s, lib support %s, user requested %d bfregs, allocated %d, total bfregs %d, using %d sys pages\n", |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1525 | MLX5_CAP_GEN(dev->mdev, uar_4k) ? "yes" : "no", |
| 1526 | lib_uar_4k ? "yes" : "no", ref_bfregs, |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1527 | req->total_num_bfregs, bfregi->total_num_bfregs, |
| 1528 | bfregi->num_sys_pages); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1529 | |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | static int allocate_uars(struct mlx5_ib_dev *dev, struct mlx5_ib_ucontext *context) |
| 1534 | { |
| 1535 | struct mlx5_bfreg_info *bfregi; |
| 1536 | int err; |
| 1537 | int i; |
| 1538 | |
| 1539 | bfregi = &context->bfregi; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1540 | for (i = 0; i < bfregi->num_static_sys_pages; i++) { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1541 | err = mlx5_cmd_alloc_uar(dev->mdev, &bfregi->sys_pages[i]); |
| 1542 | if (err) |
| 1543 | goto error; |
| 1544 | |
| 1545 | mlx5_ib_dbg(dev, "allocated uar %d\n", bfregi->sys_pages[i]); |
| 1546 | } |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1547 | |
| 1548 | for (i = bfregi->num_static_sys_pages; i < bfregi->num_sys_pages; i++) |
| 1549 | bfregi->sys_pages[i] = MLX5_IB_INVALID_UAR_INDEX; |
| 1550 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1551 | return 0; |
| 1552 | |
| 1553 | error: |
| 1554 | for (--i; i >= 0; i--) |
| 1555 | if (mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i])) |
| 1556 | mlx5_ib_warn(dev, "failed to free uar %d\n", i); |
| 1557 | |
| 1558 | return err; |
| 1559 | } |
| 1560 | |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1561 | static void deallocate_uars(struct mlx5_ib_dev *dev, |
| 1562 | struct mlx5_ib_ucontext *context) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1563 | { |
| 1564 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1565 | int i; |
| 1566 | |
| 1567 | bfregi = &context->bfregi; |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1568 | for (i = 0; i < bfregi->num_sys_pages; i++) |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1569 | if (i < bfregi->num_static_sys_pages || |
Leon Romanovsky | 1517799 | 2018-06-27 10:44:24 +0300 | [diff] [blame] | 1570 | bfregi->sys_pages[i] != MLX5_IB_INVALID_UAR_INDEX) |
| 1571 | mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i]); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1572 | } |
| 1573 | |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1574 | static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn) |
| 1575 | { |
| 1576 | int err; |
| 1577 | |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1578 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1579 | return 0; |
| 1580 | |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1581 | err = mlx5_core_alloc_transport_domain(dev->mdev, tdn); |
| 1582 | if (err) |
| 1583 | return err; |
| 1584 | |
| 1585 | if ((MLX5_CAP_GEN(dev->mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH) || |
Eran Ben Elisha | 8978cc9 | 2018-01-09 11:41:10 +0200 | [diff] [blame] | 1586 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1587 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1588 | return err; |
| 1589 | |
| 1590 | mutex_lock(&dev->lb_mutex); |
| 1591 | dev->user_td++; |
| 1592 | |
| 1593 | if (dev->user_td == 2) |
| 1594 | err = mlx5_nic_vport_update_local_lb(dev->mdev, true); |
| 1595 | |
| 1596 | mutex_unlock(&dev->lb_mutex); |
| 1597 | return err; |
| 1598 | } |
| 1599 | |
| 1600 | static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn) |
| 1601 | { |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1602 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
| 1603 | return; |
| 1604 | |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1605 | mlx5_core_dealloc_transport_domain(dev->mdev, tdn); |
| 1606 | |
| 1607 | if ((MLX5_CAP_GEN(dev->mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH) || |
Eran Ben Elisha | 8978cc9 | 2018-01-09 11:41:10 +0200 | [diff] [blame] | 1608 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
| 1609 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Huy Nguyen | c85023e | 2017-05-30 09:42:54 +0300 | [diff] [blame] | 1610 | return; |
| 1611 | |
| 1612 | mutex_lock(&dev->lb_mutex); |
| 1613 | dev->user_td--; |
| 1614 | |
| 1615 | if (dev->user_td < 2) |
| 1616 | mlx5_nic_vport_update_local_lb(dev->mdev, false); |
| 1617 | |
| 1618 | mutex_unlock(&dev->lb_mutex); |
| 1619 | } |
| 1620 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1621 | static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev, |
| 1622 | struct ib_udata *udata) |
| 1623 | { |
| 1624 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1625 | struct mlx5_ib_alloc_ucontext_req_v2 req = {}; |
| 1626 | struct mlx5_ib_alloc_ucontext_resp resp = {}; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1627 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1628 | struct mlx5_ib_ucontext *context; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1629 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1630 | int ver; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1631 | int err; |
Majd Dibbiny | a168a41c | 2016-01-28 17:51:47 +0200 | [diff] [blame] | 1632 | size_t min_req_v2 = offsetof(struct mlx5_ib_alloc_ucontext_req_v2, |
| 1633 | max_cqe_version); |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1634 | u32 dump_fill_mkey; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1635 | bool lib_uar_4k; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1636 | |
| 1637 | if (!dev->ib_active) |
| 1638 | return ERR_PTR(-EAGAIN); |
| 1639 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1640 | if (udata->inlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1641 | ver = 0; |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1642 | else if (udata->inlen >= min_req_v2) |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1643 | ver = 2; |
| 1644 | else |
| 1645 | return ERR_PTR(-EINVAL); |
| 1646 | |
Amrani, Ram | e093111 | 2017-06-27 17:04:42 +0300 | [diff] [blame] | 1647 | err = ib_copy_from_udata(&req, udata, min(udata->inlen, sizeof(req))); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1648 | if (err) |
| 1649 | return ERR_PTR(err); |
| 1650 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1651 | if (req.flags & ~MLX5_IB_ALLOC_UCTX_DEVX) |
| 1652 | return ERR_PTR(-EOPNOTSUPP); |
Eli Cohen | 78c0f98 | 2014-01-30 13:49:48 +0200 | [diff] [blame] | 1653 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1654 | if (req.comp_mask || req.reserved0 || req.reserved1 || req.reserved2) |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1655 | return ERR_PTR(-EOPNOTSUPP); |
| 1656 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1657 | req.total_num_bfregs = ALIGN(req.total_num_bfregs, |
| 1658 | MLX5_NON_FP_BFREGS_PER_UAR); |
| 1659 | if (req.num_low_latency_bfregs > req.total_num_bfregs - 1) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1660 | return ERR_PTR(-EINVAL); |
| 1661 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1662 | resp.qp_tab_size = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp); |
Noa Osherovich | 2cc6ad5 | 2016-06-04 15:15:33 +0300 | [diff] [blame] | 1663 | if (mlx5_core_is_pf(dev->mdev) && MLX5_CAP_GEN(dev->mdev, bf)) |
| 1664 | resp.bf_reg_size = 1 << MLX5_CAP_GEN(dev->mdev, log_bf_reg_size); |
Daniel Jurgens | b47bd6e | 2016-10-25 18:36:24 +0300 | [diff] [blame] | 1665 | resp.cache_line_size = cache_line_size(); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1666 | resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); |
| 1667 | resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); |
| 1668 | resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1669 | resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
| 1670 | resp.max_srq_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz); |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1671 | resp.cqe_version = min_t(__u8, |
| 1672 | (__u8)MLX5_CAP_GEN(dev->mdev, cqe_version), |
| 1673 | req.max_cqe_version); |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1674 | resp.log_uar_size = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1675 | MLX5_ADAPTER_PAGE_SHIFT : PAGE_SHIFT; |
| 1676 | resp.num_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
| 1677 | MLX5_CAP_GEN(dev->mdev, num_of_uars_per_page) : 1; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1678 | resp.response_length = min(offsetof(typeof(resp), response_length) + |
| 1679 | sizeof(resp.response_length), udata->outlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1680 | |
Matan Barak | c03faa5 | 2018-03-28 09:27:54 +0300 | [diff] [blame] | 1681 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_DEVICE) { |
| 1682 | if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_EGRESS)) |
| 1683 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM; |
| 1684 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_REQUIRED_METADATA) |
| 1685 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_REQ_METADATA; |
| 1686 | if (MLX5_CAP_FLOWTABLE(dev->mdev, flow_table_properties_nic_receive.ft_field_support.outer_esp_spi)) |
| 1687 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_SPI_STEERING; |
| 1688 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_TX_IV_IS_ESN) |
| 1689 | resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_TX_IV_IS_ESN; |
| 1690 | /* MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_FULL_OFFLOAD is currently always 0 */ |
| 1691 | } |
| 1692 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1693 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 1694 | if (!context) |
| 1695 | return ERR_PTR(-ENOMEM); |
| 1696 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1697 | lib_uar_4k = req.lib_caps & MLX5_LIB_CAP_4K_UAR; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1698 | bfregi = &context->bfregi; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1699 | |
| 1700 | /* updates req->total_num_bfregs */ |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1701 | err = calc_total_bfregs(dev, lib_uar_4k, &req, bfregi); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1702 | if (err) |
| 1703 | goto out_ctx; |
| 1704 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1705 | mutex_init(&bfregi->lock); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1706 | bfregi->lib_uar_4k = lib_uar_4k; |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1707 | bfregi->count = kcalloc(bfregi->total_num_bfregs, sizeof(*bfregi->count), |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1708 | GFP_KERNEL); |
| 1709 | if (!bfregi->count) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1710 | err = -ENOMEM; |
| 1711 | goto out_ctx; |
| 1712 | } |
| 1713 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1714 | bfregi->sys_pages = kcalloc(bfregi->num_sys_pages, |
| 1715 | sizeof(*bfregi->sys_pages), |
| 1716 | GFP_KERNEL); |
| 1717 | if (!bfregi->sys_pages) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1718 | err = -ENOMEM; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1719 | goto out_count; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1720 | } |
| 1721 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1722 | err = allocate_uars(dev, context); |
| 1723 | if (err) |
| 1724 | goto out_sys_pages; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1725 | |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 1726 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 1727 | context->ibucontext.invalidate_range = &mlx5_ib_invalidate_range; |
| 1728 | #endif |
| 1729 | |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1730 | err = mlx5_ib_alloc_transport_domain(dev, &context->tdn); |
| 1731 | if (err) |
| 1732 | goto out_uars; |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1733 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1734 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) { |
| 1735 | /* Block DEVX on Infiniband as of SELinux */ |
| 1736 | if (mlx5_ib_port_link_layer(ibdev, 1) != IB_LINK_LAYER_ETHERNET) { |
| 1737 | err = -EPERM; |
| 1738 | goto out_td; |
| 1739 | } |
| 1740 | |
| 1741 | err = mlx5_ib_devx_create(dev, context); |
| 1742 | if (err) |
| 1743 | goto out_td; |
| 1744 | } |
| 1745 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1746 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1747 | err = mlx5_cmd_dump_fill_mkey(dev->mdev, &dump_fill_mkey); |
| 1748 | if (err) |
Jason Gunthorpe | 8193abb | 2018-07-04 13:19:46 -0600 | [diff] [blame] | 1749 | goto out_mdev; |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1750 | } |
| 1751 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1752 | INIT_LIST_HEAD(&context->vma_private_list); |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1753 | mutex_init(&context->vma_private_list_mutex); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1754 | INIT_LIST_HEAD(&context->db_page_list); |
| 1755 | mutex_init(&context->db_page_mutex); |
| 1756 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1757 | resp.tot_bfregs = req.total_num_bfregs; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 1758 | resp.num_ports = dev->num_ports; |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1759 | |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1760 | if (field_avail(typeof(resp), cqe_version, udata->outlen)) |
| 1761 | resp.response_length += sizeof(resp.cqe_version); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1762 | |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1763 | if (field_avail(typeof(resp), cmds_supp_uhw, udata->outlen)) { |
Moni Shoua | 6ad279c5 | 2016-11-23 08:23:23 +0200 | [diff] [blame] | 1764 | resp.cmds_supp_uhw |= MLX5_USER_CMDS_SUPP_UHW_QUERY_DEVICE | |
| 1765 | MLX5_USER_CMDS_SUPP_UHW_CREATE_AH; |
Bodong Wang | 402ca53 | 2016-06-17 15:02:20 +0300 | [diff] [blame] | 1766 | resp.response_length += sizeof(resp.cmds_supp_uhw); |
| 1767 | } |
| 1768 | |
Or Gerlitz | 7898489 | 2016-11-30 20:33:33 +0200 | [diff] [blame] | 1769 | if (field_avail(typeof(resp), eth_min_inline, udata->outlen)) { |
| 1770 | if (mlx5_ib_port_link_layer(ibdev, 1) == IB_LINK_LAYER_ETHERNET) { |
| 1771 | mlx5_query_min_inline(dev->mdev, &resp.eth_min_inline); |
| 1772 | resp.eth_min_inline++; |
| 1773 | } |
| 1774 | resp.response_length += sizeof(resp.eth_min_inline); |
| 1775 | } |
| 1776 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1777 | if (field_avail(typeof(resp), clock_info_versions, udata->outlen)) { |
| 1778 | if (mdev->clock_info) |
| 1779 | resp.clock_info_versions = BIT(MLX5_IB_CLOCK_INFO_V1); |
| 1780 | resp.response_length += sizeof(resp.clock_info_versions); |
| 1781 | } |
| 1782 | |
Noa Osherovich | bc5c6ee | 2016-06-04 15:15:31 +0300 | [diff] [blame] | 1783 | /* |
| 1784 | * We don't want to expose information from the PCI bar that is located |
| 1785 | * after 4096 bytes, so if the arch only supports larger pages, let's |
| 1786 | * pretend we don't support reading the HCA's core clock. This is also |
| 1787 | * forced by mmap function. |
| 1788 | */ |
Eli Cohen | de8d6e0 | 2017-01-03 23:55:19 +0200 | [diff] [blame] | 1789 | if (field_avail(typeof(resp), hca_core_clock_offset, udata->outlen)) { |
| 1790 | if (PAGE_SIZE <= 4096) { |
| 1791 | resp.comp_mask |= |
| 1792 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET; |
| 1793 | resp.hca_core_clock_offset = |
| 1794 | offsetof(struct mlx5_init_seg, internal_timer_h) % PAGE_SIZE; |
| 1795 | } |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 1796 | resp.response_length += sizeof(resp.hca_core_clock_offset); |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1797 | } |
| 1798 | |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1799 | if (field_avail(typeof(resp), log_uar_size, udata->outlen)) |
| 1800 | resp.response_length += sizeof(resp.log_uar_size); |
| 1801 | |
| 1802 | if (field_avail(typeof(resp), num_uars_per_page, udata->outlen)) |
| 1803 | resp.response_length += sizeof(resp.num_uars_per_page); |
| 1804 | |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 1805 | if (field_avail(typeof(resp), num_dyn_bfregs, udata->outlen)) { |
| 1806 | resp.num_dyn_bfregs = bfregi->num_dyn_bfregs; |
| 1807 | resp.response_length += sizeof(resp.num_dyn_bfregs); |
| 1808 | } |
| 1809 | |
Yonatan Cohen | 25bb36e | 2018-06-19 08:47:24 +0300 | [diff] [blame] | 1810 | if (field_avail(typeof(resp), dump_fill_mkey, udata->outlen)) { |
| 1811 | if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
| 1812 | resp.dump_fill_mkey = dump_fill_mkey; |
| 1813 | resp.comp_mask |= |
| 1814 | MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_DUMP_FILL_MKEY; |
| 1815 | } |
| 1816 | resp.response_length += sizeof(resp.dump_fill_mkey); |
| 1817 | } |
| 1818 | |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame] | 1819 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1820 | if (err) |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1821 | goto out_mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1822 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1823 | bfregi->ver = ver; |
| 1824 | bfregi->num_low_latency_bfregs = req.num_low_latency_bfregs; |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1825 | context->cqe_version = resp.cqe_version; |
Eli Cohen | 30aa60b | 2017-01-03 23:55:27 +0200 | [diff] [blame] | 1826 | context->lib_caps = req.lib_caps; |
| 1827 | print_lib_caps(dev, context->lib_caps); |
Haggai Abramovsky | f72300c | 2016-01-14 19:12:58 +0200 | [diff] [blame] | 1828 | |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 1829 | if (mlx5_lag_is_active(dev->mdev)) { |
| 1830 | u8 port = mlx5_core_native_port_num(dev->mdev); |
| 1831 | |
| 1832 | atomic_set(&context->tx_port_affinity, |
| 1833 | atomic_add_return( |
| 1834 | 1, &dev->roce[port].tx_port_affinity)); |
| 1835 | } |
| 1836 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1837 | return &context->ibucontext; |
| 1838 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1839 | out_mdev: |
| 1840 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) |
| 1841 | mlx5_ib_devx_destroy(dev, context); |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1842 | out_td: |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1843 | mlx5_ib_dealloc_transport_domain(dev, context->tdn); |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1844 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1845 | out_uars: |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1846 | deallocate_uars(dev, context); |
| 1847 | |
| 1848 | out_sys_pages: |
| 1849 | kfree(bfregi->sys_pages); |
| 1850 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1851 | out_count: |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1852 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1853 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1854 | out_ctx: |
| 1855 | kfree(context); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1856 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1857 | return ERR_PTR(err); |
| 1858 | } |
| 1859 | |
| 1860 | static int mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
| 1861 | { |
| 1862 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 1863 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1864 | struct mlx5_bfreg_info *bfregi; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1865 | |
Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame] | 1866 | if (context->devx_uid) |
| 1867 | mlx5_ib_devx_destroy(dev, context); |
| 1868 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1869 | bfregi = &context->bfregi; |
Leon Romanovsky | cfdeb89 | 2018-06-19 10:39:06 +0300 | [diff] [blame] | 1870 | mlx5_ib_dealloc_transport_domain(dev, context->tdn); |
majd@mellanox.com | 146d2f1 | 2016-01-14 19:13:02 +0200 | [diff] [blame] | 1871 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1872 | deallocate_uars(dev, context); |
| 1873 | kfree(bfregi->sys_pages); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1874 | kfree(bfregi->count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1875 | kfree(context); |
| 1876 | |
| 1877 | return 0; |
| 1878 | } |
| 1879 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1880 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1881 | int uar_idx) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1882 | { |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1883 | int fw_uars_per_page; |
| 1884 | |
| 1885 | fw_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? MLX5_UARS_IN_PAGE : 1; |
| 1886 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1887 | 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] | 1888 | } |
| 1889 | |
| 1890 | static int get_command(unsigned long offset) |
| 1891 | { |
| 1892 | return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK; |
| 1893 | } |
| 1894 | |
| 1895 | static int get_arg(unsigned long offset) |
| 1896 | { |
| 1897 | return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1); |
| 1898 | } |
| 1899 | |
| 1900 | static int get_index(unsigned long offset) |
| 1901 | { |
| 1902 | return get_arg(offset); |
| 1903 | } |
| 1904 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 1905 | /* Index resides in an extra byte to enable larger values than 255 */ |
| 1906 | static int get_extended_index(unsigned long offset) |
| 1907 | { |
| 1908 | return get_arg(offset) | ((offset >> 16) & 0xff) << 8; |
| 1909 | } |
| 1910 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1911 | static void mlx5_ib_vma_open(struct vm_area_struct *area) |
| 1912 | { |
| 1913 | /* vma_open is called when a new VMA is created on top of our VMA. This |
| 1914 | * is done through either mremap flow or split_vma (usually due to |
| 1915 | * mlock, madvise, munmap, etc.) We do not support a clone of the VMA, |
| 1916 | * as this VMA is strongly hardware related. Therefore we set the |
| 1917 | * vm_ops of the newly created/cloned VMA to NULL, to prevent it from |
| 1918 | * calling us again and trying to do incorrect actions. We assume that |
| 1919 | * the original VMA size is exactly a single page, and therefore all |
| 1920 | * "splitting" operation will not happen to it. |
| 1921 | */ |
| 1922 | area->vm_ops = NULL; |
| 1923 | } |
| 1924 | |
| 1925 | static void mlx5_ib_vma_close(struct vm_area_struct *area) |
| 1926 | { |
| 1927 | struct mlx5_ib_vma_private_data *mlx5_ib_vma_priv_data; |
| 1928 | |
| 1929 | /* It's guaranteed that all VMAs opened on a FD are closed before the |
| 1930 | * file itself is closed, therefore no sync is needed with the regular |
| 1931 | * closing flow. (e.g. mlx5 ib_dealloc_ucontext) |
| 1932 | * However need a sync with accessing the vma as part of |
| 1933 | * mlx5_ib_disassociate_ucontext. |
| 1934 | * The close operation is usually called under mm->mmap_sem except when |
| 1935 | * process is exiting. |
| 1936 | * The exiting case is handled explicitly as part of |
| 1937 | * mlx5_ib_disassociate_ucontext. |
| 1938 | */ |
| 1939 | mlx5_ib_vma_priv_data = (struct mlx5_ib_vma_private_data *)area->vm_private_data; |
| 1940 | |
| 1941 | /* setting the vma context pointer to null in the mlx5_ib driver's |
| 1942 | * private data, to protect a race condition in |
| 1943 | * mlx5_ib_disassociate_ucontext(). |
| 1944 | */ |
| 1945 | mlx5_ib_vma_priv_data->vma = NULL; |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1946 | mutex_lock(mlx5_ib_vma_priv_data->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1947 | list_del(&mlx5_ib_vma_priv_data->list); |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1948 | mutex_unlock(mlx5_ib_vma_priv_data->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1949 | kfree(mlx5_ib_vma_priv_data); |
| 1950 | } |
| 1951 | |
| 1952 | static const struct vm_operations_struct mlx5_ib_vm_ops = { |
| 1953 | .open = mlx5_ib_vma_open, |
| 1954 | .close = mlx5_ib_vma_close |
| 1955 | }; |
| 1956 | |
| 1957 | static int mlx5_ib_set_vma_data(struct vm_area_struct *vma, |
| 1958 | struct mlx5_ib_ucontext *ctx) |
| 1959 | { |
| 1960 | struct mlx5_ib_vma_private_data *vma_prv; |
| 1961 | struct list_head *vma_head = &ctx->vma_private_list; |
| 1962 | |
| 1963 | vma_prv = kzalloc(sizeof(*vma_prv), GFP_KERNEL); |
| 1964 | if (!vma_prv) |
| 1965 | return -ENOMEM; |
| 1966 | |
| 1967 | vma_prv->vma = vma; |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1968 | vma_prv->vma_private_list_mutex = &ctx->vma_private_list_mutex; |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1969 | vma->vm_private_data = vma_prv; |
| 1970 | vma->vm_ops = &mlx5_ib_vm_ops; |
| 1971 | |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1972 | mutex_lock(&ctx->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1973 | list_add(&vma_prv->list, vma_head); |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1974 | mutex_unlock(&ctx->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1975 | |
| 1976 | return 0; |
| 1977 | } |
| 1978 | |
| 1979 | static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) |
| 1980 | { |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1981 | struct vm_area_struct *vma; |
| 1982 | struct mlx5_ib_vma_private_data *vma_private, *n; |
| 1983 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1984 | |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1985 | mutex_lock(&context->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1986 | list_for_each_entry_safe(vma_private, n, &context->vma_private_list, |
| 1987 | list) { |
| 1988 | vma = vma_private->vma; |
Leon Romanovsky | 2cb4079 | 2018-05-29 15:14:05 +0300 | [diff] [blame] | 1989 | zap_vma_ptes(vma, vma->vm_start, PAGE_SIZE); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1990 | /* context going to be destroyed, should |
| 1991 | * not access ops any more. |
| 1992 | */ |
Maor Gottlieb | 1377661 | 2017-03-29 06:03:03 +0300 | [diff] [blame] | 1993 | vma->vm_flags &= ~(VM_SHARED | VM_MAYSHARE); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1994 | vma->vm_ops = NULL; |
| 1995 | list_del(&vma_private->list); |
| 1996 | kfree(vma_private); |
| 1997 | } |
Majd Dibbiny | ad9a366 | 2017-12-24 13:54:56 +0200 | [diff] [blame] | 1998 | mutex_unlock(&context->vma_private_list_mutex); |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 1999 | } |
| 2000 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2001 | static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd) |
| 2002 | { |
| 2003 | switch (cmd) { |
| 2004 | case MLX5_IB_MMAP_WC_PAGE: |
| 2005 | return "WC"; |
| 2006 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2007 | return "best effort WC"; |
| 2008 | case MLX5_IB_MMAP_NC_PAGE: |
| 2009 | return "NC"; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2010 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2011 | return "Device Memory"; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2012 | default: |
| 2013 | return NULL; |
| 2014 | } |
| 2015 | } |
| 2016 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2017 | static int mlx5_ib_mmap_clock_info_page(struct mlx5_ib_dev *dev, |
| 2018 | struct vm_area_struct *vma, |
| 2019 | struct mlx5_ib_ucontext *context) |
| 2020 | { |
| 2021 | phys_addr_t pfn; |
| 2022 | int err; |
| 2023 | |
| 2024 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2025 | return -EINVAL; |
| 2026 | |
| 2027 | if (get_index(vma->vm_pgoff) != MLX5_IB_CLOCK_INFO_V1) |
| 2028 | return -EOPNOTSUPP; |
| 2029 | |
| 2030 | if (vma->vm_flags & VM_WRITE) |
| 2031 | return -EPERM; |
| 2032 | |
| 2033 | if (!dev->mdev->clock_info_page) |
| 2034 | return -EOPNOTSUPP; |
| 2035 | |
| 2036 | pfn = page_to_pfn(dev->mdev->clock_info_page); |
| 2037 | err = remap_pfn_range(vma, vma->vm_start, pfn, PAGE_SIZE, |
| 2038 | vma->vm_page_prot); |
| 2039 | if (err) |
| 2040 | return err; |
| 2041 | |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2042 | return mlx5_ib_set_vma_data(vma, context); |
| 2043 | } |
| 2044 | |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2045 | 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] | 2046 | struct vm_area_struct *vma, |
| 2047 | struct mlx5_ib_ucontext *context) |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2048 | { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 2049 | struct mlx5_bfreg_info *bfregi = &context->bfregi; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2050 | int err; |
| 2051 | unsigned long idx; |
Kamal Heib | aa09ea6 | 2018-07-19 00:05:32 +0300 | [diff] [blame] | 2052 | phys_addr_t pfn; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2053 | pgprot_t prot; |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2054 | u32 bfreg_dyn_idx = 0; |
| 2055 | u32 uar_index; |
| 2056 | int dyn_uar = (cmd == MLX5_IB_MMAP_ALLOC_WC); |
| 2057 | int max_valid_idx = dyn_uar ? bfregi->num_sys_pages : |
| 2058 | bfregi->num_static_sys_pages; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2059 | |
| 2060 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2061 | return -EINVAL; |
| 2062 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2063 | if (dyn_uar) |
| 2064 | idx = get_extended_index(vma->vm_pgoff) + bfregi->num_static_sys_pages; |
| 2065 | else |
| 2066 | idx = get_index(vma->vm_pgoff); |
| 2067 | |
| 2068 | if (idx >= max_valid_idx) { |
| 2069 | mlx5_ib_warn(dev, "invalid uar index %lu, max=%d\n", |
| 2070 | idx, max_valid_idx); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2071 | return -EINVAL; |
| 2072 | } |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2073 | |
| 2074 | switch (cmd) { |
| 2075 | case MLX5_IB_MMAP_WC_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2076 | case MLX5_IB_MMAP_ALLOC_WC: |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2077 | /* Some architectures don't support WC memory */ |
| 2078 | #if defined(CONFIG_X86) |
| 2079 | if (!pat_enabled()) |
| 2080 | return -EPERM; |
| 2081 | #elif !(defined(CONFIG_PPC) || (defined(CONFIG_ARM) && defined(CONFIG_MMU))) |
| 2082 | return -EPERM; |
| 2083 | #endif |
| 2084 | /* fall through */ |
| 2085 | case MLX5_IB_MMAP_REGULAR_PAGE: |
| 2086 | /* For MLX5_IB_MMAP_REGULAR_PAGE do the best effort to get WC */ |
| 2087 | prot = pgprot_writecombine(vma->vm_page_prot); |
| 2088 | break; |
| 2089 | case MLX5_IB_MMAP_NC_PAGE: |
| 2090 | prot = pgprot_noncached(vma->vm_page_prot); |
| 2091 | break; |
| 2092 | default: |
| 2093 | return -EINVAL; |
| 2094 | } |
| 2095 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2096 | if (dyn_uar) { |
| 2097 | int uars_per_page; |
| 2098 | |
| 2099 | uars_per_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k); |
| 2100 | bfreg_dyn_idx = idx * (uars_per_page * MLX5_NON_FP_BFREGS_PER_UAR); |
| 2101 | if (bfreg_dyn_idx >= bfregi->total_num_bfregs) { |
| 2102 | mlx5_ib_warn(dev, "invalid bfreg_dyn_idx %u, max=%u\n", |
| 2103 | bfreg_dyn_idx, bfregi->total_num_bfregs); |
| 2104 | return -EINVAL; |
| 2105 | } |
| 2106 | |
| 2107 | mutex_lock(&bfregi->lock); |
| 2108 | /* Fail if uar already allocated, first bfreg index of each |
| 2109 | * page holds its count. |
| 2110 | */ |
| 2111 | if (bfregi->count[bfreg_dyn_idx]) { |
| 2112 | mlx5_ib_warn(dev, "wrong offset, idx %lu is busy, bfregn=%u\n", idx, bfreg_dyn_idx); |
| 2113 | mutex_unlock(&bfregi->lock); |
| 2114 | return -EINVAL; |
| 2115 | } |
| 2116 | |
| 2117 | bfregi->count[bfreg_dyn_idx]++; |
| 2118 | mutex_unlock(&bfregi->lock); |
| 2119 | |
| 2120 | err = mlx5_cmd_alloc_uar(dev->mdev, &uar_index); |
| 2121 | if (err) { |
| 2122 | mlx5_ib_warn(dev, "UAR alloc failed\n"); |
| 2123 | goto free_bfreg; |
| 2124 | } |
| 2125 | } else { |
| 2126 | uar_index = bfregi->sys_pages[idx]; |
| 2127 | } |
| 2128 | |
| 2129 | pfn = uar_index2pfn(dev, uar_index); |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2130 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn %pa\n", idx, &pfn); |
| 2131 | |
| 2132 | vma->vm_page_prot = prot; |
| 2133 | err = io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 2134 | PAGE_SIZE, vma->vm_page_prot); |
| 2135 | if (err) { |
Leon Romanovsky | 8f06228 | 2018-05-22 08:31:03 +0300 | [diff] [blame] | 2136 | mlx5_ib_err(dev, |
| 2137 | "io_remap_pfn_range failed with error=%d, mmap_cmd=%s\n", |
| 2138 | err, mmap_cmd2str(cmd)); |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2139 | err = -EAGAIN; |
| 2140 | goto err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2141 | } |
| 2142 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2143 | err = mlx5_ib_set_vma_data(vma, context); |
| 2144 | if (err) |
| 2145 | goto err; |
| 2146 | |
| 2147 | if (dyn_uar) |
| 2148 | bfregi->sys_pages[idx] = uar_index; |
| 2149 | return 0; |
| 2150 | |
| 2151 | err: |
| 2152 | if (!dyn_uar) |
| 2153 | return err; |
| 2154 | |
| 2155 | mlx5_cmd_free_uar(dev->mdev, idx); |
| 2156 | |
| 2157 | free_bfreg: |
| 2158 | mlx5_ib_free_bfreg(dev, bfregi, bfreg_dyn_idx); |
| 2159 | |
| 2160 | return err; |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2161 | } |
| 2162 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2163 | static int dm_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
| 2164 | { |
| 2165 | struct mlx5_ib_ucontext *mctx = to_mucontext(context); |
| 2166 | struct mlx5_ib_dev *dev = to_mdev(context->device); |
| 2167 | u16 page_idx = get_extended_index(vma->vm_pgoff); |
| 2168 | size_t map_size = vma->vm_end - vma->vm_start; |
| 2169 | u32 npages = map_size >> PAGE_SHIFT; |
| 2170 | phys_addr_t pfn; |
| 2171 | pgprot_t prot; |
| 2172 | |
| 2173 | if (find_next_zero_bit(mctx->dm_pages, page_idx + npages, page_idx) != |
| 2174 | page_idx + npages) |
| 2175 | return -EINVAL; |
| 2176 | |
| 2177 | pfn = ((pci_resource_start(dev->mdev->pdev, 0) + |
| 2178 | MLX5_CAP64_DEV_MEM(dev->mdev, memic_bar_start_addr)) >> |
| 2179 | PAGE_SHIFT) + |
| 2180 | page_idx; |
| 2181 | prot = pgprot_writecombine(vma->vm_page_prot); |
| 2182 | vma->vm_page_prot = prot; |
| 2183 | |
| 2184 | if (io_remap_pfn_range(vma, vma->vm_start, pfn, map_size, |
| 2185 | vma->vm_page_prot)) |
| 2186 | return -EAGAIN; |
| 2187 | |
| 2188 | return mlx5_ib_set_vma_data(vma, mctx); |
| 2189 | } |
| 2190 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2191 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
| 2192 | { |
| 2193 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
| 2194 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2195 | unsigned long command; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2196 | phys_addr_t pfn; |
| 2197 | |
| 2198 | command = get_command(vma->vm_pgoff); |
| 2199 | switch (command) { |
Guy Levi | 37aa5c3 | 2016-04-27 16:49:50 +0300 | [diff] [blame] | 2200 | case MLX5_IB_MMAP_WC_PAGE: |
| 2201 | case MLX5_IB_MMAP_NC_PAGE: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2202 | case MLX5_IB_MMAP_REGULAR_PAGE: |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 2203 | case MLX5_IB_MMAP_ALLOC_WC: |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 2204 | return uar_mmap(dev, command, vma, context); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2205 | |
| 2206 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
| 2207 | return -ENOSYS; |
| 2208 | |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2209 | case MLX5_IB_MMAP_CORE_CLOCK: |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2210 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
| 2211 | return -EINVAL; |
| 2212 | |
Matan Barak | 6cbac1e | 2016-04-14 16:52:10 +0300 | [diff] [blame] | 2213 | if (vma->vm_flags & VM_WRITE) |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2214 | return -EPERM; |
| 2215 | |
| 2216 | /* Don't expose to user-space information it shouldn't have */ |
| 2217 | if (PAGE_SIZE > 4096) |
| 2218 | return -EOPNOTSUPP; |
| 2219 | |
| 2220 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 2221 | pfn = (dev->mdev->iseg_base + |
| 2222 | offsetof(struct mlx5_init_seg, internal_timer_h)) >> |
| 2223 | PAGE_SHIFT; |
| 2224 | if (io_remap_pfn_range(vma, vma->vm_start, pfn, |
| 2225 | PAGE_SIZE, vma->vm_page_prot)) |
| 2226 | return -EAGAIN; |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2227 | break; |
Feras Daoud | 5c99eae | 2018-01-16 20:08:41 +0200 | [diff] [blame] | 2228 | case MLX5_IB_MMAP_CLOCK_INFO: |
| 2229 | return mlx5_ib_mmap_clock_info_page(dev, vma, context); |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 2230 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2231 | case MLX5_IB_MMAP_DEVICE_MEM: |
| 2232 | return dm_mmap(ibcontext, vma); |
| 2233 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2234 | default: |
| 2235 | return -EINVAL; |
| 2236 | } |
| 2237 | |
| 2238 | return 0; |
| 2239 | } |
| 2240 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 2241 | struct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev, |
| 2242 | struct ib_ucontext *context, |
| 2243 | struct ib_dm_alloc_attr *attr, |
| 2244 | struct uverbs_attr_bundle *attrs) |
| 2245 | { |
| 2246 | u64 act_size = roundup(attr->length, MLX5_MEMIC_BASE_SIZE); |
| 2247 | struct mlx5_memic *memic = &to_mdev(ibdev)->memic; |
| 2248 | phys_addr_t memic_addr; |
| 2249 | struct mlx5_ib_dm *dm; |
| 2250 | u64 start_offset; |
| 2251 | u32 page_idx; |
| 2252 | int err; |
| 2253 | |
| 2254 | dm = kzalloc(sizeof(*dm), GFP_KERNEL); |
| 2255 | if (!dm) |
| 2256 | return ERR_PTR(-ENOMEM); |
| 2257 | |
| 2258 | mlx5_ib_dbg(to_mdev(ibdev), "alloc_memic req: user_length=0x%llx act_length=0x%llx log_alignment=%d\n", |
| 2259 | attr->length, act_size, attr->alignment); |
| 2260 | |
| 2261 | err = mlx5_cmd_alloc_memic(memic, &memic_addr, |
| 2262 | act_size, attr->alignment); |
| 2263 | if (err) |
| 2264 | goto err_free; |
| 2265 | |
| 2266 | start_offset = memic_addr & ~PAGE_MASK; |
| 2267 | page_idx = (memic_addr - pci_resource_start(memic->dev->pdev, 0) - |
| 2268 | MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
| 2269 | PAGE_SHIFT; |
| 2270 | |
| 2271 | err = uverbs_copy_to(attrs, |
| 2272 | MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 2273 | &start_offset, sizeof(start_offset)); |
| 2274 | if (err) |
| 2275 | goto err_dealloc; |
| 2276 | |
| 2277 | err = uverbs_copy_to(attrs, |
| 2278 | MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 2279 | &page_idx, sizeof(page_idx)); |
| 2280 | if (err) |
| 2281 | goto err_dealloc; |
| 2282 | |
| 2283 | bitmap_set(to_mucontext(context)->dm_pages, page_idx, |
| 2284 | DIV_ROUND_UP(act_size, PAGE_SIZE)); |
| 2285 | |
| 2286 | dm->dev_addr = memic_addr; |
| 2287 | |
| 2288 | return &dm->ibdm; |
| 2289 | |
| 2290 | err_dealloc: |
| 2291 | mlx5_cmd_dealloc_memic(memic, memic_addr, |
| 2292 | act_size); |
| 2293 | err_free: |
| 2294 | kfree(dm); |
| 2295 | return ERR_PTR(err); |
| 2296 | } |
| 2297 | |
| 2298 | int mlx5_ib_dealloc_dm(struct ib_dm *ibdm) |
| 2299 | { |
| 2300 | struct mlx5_memic *memic = &to_mdev(ibdm->device)->memic; |
| 2301 | struct mlx5_ib_dm *dm = to_mdm(ibdm); |
| 2302 | u64 act_size = roundup(dm->ibdm.length, MLX5_MEMIC_BASE_SIZE); |
| 2303 | u32 page_idx; |
| 2304 | int ret; |
| 2305 | |
| 2306 | ret = mlx5_cmd_dealloc_memic(memic, dm->dev_addr, act_size); |
| 2307 | if (ret) |
| 2308 | return ret; |
| 2309 | |
| 2310 | page_idx = (dm->dev_addr - pci_resource_start(memic->dev->pdev, 0) - |
| 2311 | MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
| 2312 | PAGE_SHIFT; |
| 2313 | bitmap_clear(to_mucontext(ibdm->uobject->context)->dm_pages, |
| 2314 | page_idx, |
| 2315 | DIV_ROUND_UP(act_size, PAGE_SIZE)); |
| 2316 | |
| 2317 | kfree(dm); |
| 2318 | |
| 2319 | return 0; |
| 2320 | } |
| 2321 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2322 | static struct ib_pd *mlx5_ib_alloc_pd(struct ib_device *ibdev, |
| 2323 | struct ib_ucontext *context, |
| 2324 | struct ib_udata *udata) |
| 2325 | { |
| 2326 | struct mlx5_ib_alloc_pd_resp resp; |
| 2327 | struct mlx5_ib_pd *pd; |
| 2328 | int err; |
| 2329 | |
| 2330 | pd = kmalloc(sizeof(*pd), GFP_KERNEL); |
| 2331 | if (!pd) |
| 2332 | return ERR_PTR(-ENOMEM); |
| 2333 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2334 | err = mlx5_core_alloc_pd(to_mdev(ibdev)->mdev, &pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2335 | if (err) { |
| 2336 | kfree(pd); |
| 2337 | return ERR_PTR(err); |
| 2338 | } |
| 2339 | |
| 2340 | if (context) { |
| 2341 | resp.pdn = pd->pdn; |
| 2342 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2343 | mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2344 | kfree(pd); |
| 2345 | return ERR_PTR(-EFAULT); |
| 2346 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | return &pd->ibpd; |
| 2350 | } |
| 2351 | |
| 2352 | static int mlx5_ib_dealloc_pd(struct ib_pd *pd) |
| 2353 | { |
| 2354 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 2355 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
| 2356 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 2357 | mlx5_core_dealloc_pd(mdev->mdev, mpd->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2358 | kfree(mpd); |
| 2359 | |
| 2360 | return 0; |
| 2361 | } |
| 2362 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2363 | enum { |
| 2364 | MATCH_CRITERIA_ENABLE_OUTER_BIT, |
| 2365 | MATCH_CRITERIA_ENABLE_MISC_BIT, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2366 | MATCH_CRITERIA_ENABLE_INNER_BIT, |
| 2367 | MATCH_CRITERIA_ENABLE_MISC2_BIT |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2368 | }; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2369 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2370 | #define HEADER_IS_ZERO(match_criteria, headers) \ |
| 2371 | !(memchr_inv(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \ |
| 2372 | 0, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \ |
| 2373 | |
| 2374 | static u8 get_match_criteria_enable(u32 *match_criteria) |
| 2375 | { |
| 2376 | u8 match_criteria_enable; |
| 2377 | |
| 2378 | match_criteria_enable = |
| 2379 | (!HEADER_IS_ZERO(match_criteria, outer_headers)) << |
| 2380 | MATCH_CRITERIA_ENABLE_OUTER_BIT; |
| 2381 | match_criteria_enable |= |
| 2382 | (!HEADER_IS_ZERO(match_criteria, misc_parameters)) << |
| 2383 | MATCH_CRITERIA_ENABLE_MISC_BIT; |
| 2384 | match_criteria_enable |= |
| 2385 | (!HEADER_IS_ZERO(match_criteria, inner_headers)) << |
| 2386 | MATCH_CRITERIA_ENABLE_INNER_BIT; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2387 | match_criteria_enable |= |
| 2388 | (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) << |
| 2389 | MATCH_CRITERIA_ENABLE_MISC2_BIT; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2390 | |
| 2391 | return match_criteria_enable; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2392 | } |
| 2393 | |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2394 | static void set_proto(void *outer_c, void *outer_v, u8 mask, u8 val) |
| 2395 | { |
| 2396 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_protocol, mask); |
| 2397 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_protocol, val); |
| 2398 | } |
| 2399 | |
Daria Velikovsky | 37da2a0 | 2018-05-07 10:20:02 +0300 | [diff] [blame] | 2400 | static void set_flow_label(void *misc_c, void *misc_v, u32 mask, u32 val, |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2401 | bool inner) |
| 2402 | { |
| 2403 | if (inner) { |
| 2404 | MLX5_SET(fte_match_set_misc, |
| 2405 | misc_c, inner_ipv6_flow_label, mask); |
| 2406 | MLX5_SET(fte_match_set_misc, |
| 2407 | misc_v, inner_ipv6_flow_label, val); |
| 2408 | } else { |
| 2409 | MLX5_SET(fte_match_set_misc, |
| 2410 | misc_c, outer_ipv6_flow_label, mask); |
| 2411 | MLX5_SET(fte_match_set_misc, |
| 2412 | misc_v, outer_ipv6_flow_label, val); |
| 2413 | } |
| 2414 | } |
| 2415 | |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2416 | static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val) |
| 2417 | { |
| 2418 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_ecn, mask); |
| 2419 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_ecn, val); |
| 2420 | MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_dscp, mask >> 2); |
| 2421 | MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_dscp, val >> 2); |
| 2422 | } |
| 2423 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2424 | static int check_mpls_supp_fields(u32 field_support, const __be32 *set_mask) |
| 2425 | { |
| 2426 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_label) && |
| 2427 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_LABEL)) |
| 2428 | return -EOPNOTSUPP; |
| 2429 | |
| 2430 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_exp) && |
| 2431 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_EXP)) |
| 2432 | return -EOPNOTSUPP; |
| 2433 | |
| 2434 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_s_bos) && |
| 2435 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_S_BOS)) |
| 2436 | return -EOPNOTSUPP; |
| 2437 | |
| 2438 | if (MLX5_GET(fte_match_mpls, set_mask, mpls_ttl) && |
| 2439 | !(field_support & MLX5_FIELD_SUPPORT_MPLS_TTL)) |
| 2440 | return -EOPNOTSUPP; |
| 2441 | |
| 2442 | return 0; |
| 2443 | } |
| 2444 | |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2445 | #define LAST_ETH_FIELD vlan_tag |
| 2446 | #define LAST_IB_FIELD sl |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2447 | #define LAST_IPV4_FIELD tos |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2448 | #define LAST_IPV6_FIELD traffic_class |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2449 | #define LAST_TCP_UDP_FIELD src_port |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2450 | #define LAST_TUNNEL_FIELD tunnel_id |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2451 | #define LAST_FLOW_TAG_FIELD tag_id |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2452 | #define LAST_DROP_FIELD size |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2453 | #define LAST_COUNTERS_FIELD counters |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2454 | |
| 2455 | /* Field is the last supported field */ |
| 2456 | #define FIELDS_NOT_SUPPORTED(filter, field)\ |
| 2457 | memchr_inv((void *)&filter.field +\ |
| 2458 | sizeof(filter.field), 0,\ |
| 2459 | sizeof(filter) -\ |
| 2460 | offsetof(typeof(filter), field) -\ |
| 2461 | sizeof(filter.field)) |
| 2462 | |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2463 | int parse_flow_flow_action(struct mlx5_ib_flow_action *maction, |
| 2464 | bool is_egress, |
| 2465 | struct mlx5_flow_act *action) |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2466 | { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2467 | |
| 2468 | switch (maction->ib_action.type) { |
| 2469 | case IB_FLOW_ACTION_ESP: |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2470 | if (action->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 2471 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)) |
| 2472 | return -EINVAL; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2473 | /* Currently only AES_GCM keymat is supported by the driver */ |
| 2474 | action->esp_id = (uintptr_t)maction->esp_aes_gcm.ctx; |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2475 | action->action |= is_egress ? |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2476 | MLX5_FLOW_CONTEXT_ACTION_ENCRYPT : |
| 2477 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT; |
| 2478 | return 0; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2479 | case IB_FLOW_ACTION_UNSPECIFIED: |
| 2480 | if (maction->flow_action_raw.sub_type == |
| 2481 | MLX5_IB_FLOW_ACTION_MODIFY_HEADER) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2482 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) |
| 2483 | return -EINVAL; |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2484 | action->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; |
| 2485 | action->modify_id = maction->flow_action_raw.action_id; |
| 2486 | return 0; |
| 2487 | } |
Mark Bloch | 10a3089 | 2018-09-02 12:51:34 +0300 | [diff] [blame] | 2488 | if (maction->flow_action_raw.sub_type == |
| 2489 | MLX5_IB_FLOW_ACTION_DECAP) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2490 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_DECAP) |
| 2491 | return -EINVAL; |
Mark Bloch | 10a3089 | 2018-09-02 12:51:34 +0300 | [diff] [blame] | 2492 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DECAP; |
| 2493 | return 0; |
| 2494 | } |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2495 | if (maction->flow_action_raw.sub_type == |
| 2496 | MLX5_IB_FLOW_ACTION_PACKET_REFORMAT) { |
Mark Bloch | 501f14e | 2018-09-06 17:27:04 +0300 | [diff] [blame] | 2497 | if (action->action & |
| 2498 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT) |
| 2499 | return -EINVAL; |
Mark Bloch | e806f93 | 2018-09-02 12:51:36 +0300 | [diff] [blame] | 2500 | action->action |= |
| 2501 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT; |
| 2502 | action->reformat_id = |
| 2503 | maction->flow_action_raw.action_id; |
| 2504 | return 0; |
| 2505 | } |
Mark Bloch | b1085be | 2018-09-02 12:51:32 +0300 | [diff] [blame] | 2506 | /* fall through */ |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2507 | default: |
| 2508 | return -EOPNOTSUPP; |
| 2509 | } |
| 2510 | } |
| 2511 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2512 | static int parse_flow_attr(struct mlx5_core_dev *mdev, u32 *match_c, |
| 2513 | u32 *match_v, const union ib_flow_spec *ib_spec, |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2514 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2515 | struct mlx5_flow_act *action, u32 prev_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2516 | { |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2517 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2518 | misc_parameters); |
| 2519 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2520 | misc_parameters); |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2521 | void *misc_params2_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2522 | misc_parameters_2); |
| 2523 | void *misc_params2_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2524 | misc_parameters_2); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2525 | void *headers_c; |
| 2526 | void *headers_v; |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2527 | int match_ipv; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2528 | int ret; |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2529 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2530 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2531 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2532 | inner_headers); |
| 2533 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2534 | inner_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2535 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2536 | ft_field_support.inner_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2537 | } else { |
| 2538 | headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
| 2539 | outer_headers); |
| 2540 | headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
| 2541 | outer_headers); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2542 | match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2543 | ft_field_support.outer_ip_version); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2547 | case IB_FLOW_SPEC_ETH: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2548 | if (FIELDS_NOT_SUPPORTED(ib_spec->eth.mask, LAST_ETH_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2549 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2550 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2551 | 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] | 2552 | dmac_47_16), |
| 2553 | ib_spec->eth.mask.dst_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2554 | 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] | 2555 | dmac_47_16), |
| 2556 | ib_spec->eth.val.dst_mac); |
| 2557 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2558 | 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] | 2559 | smac_47_16), |
| 2560 | ib_spec->eth.mask.src_mac); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2561 | 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] | 2562 | smac_47_16), |
| 2563 | ib_spec->eth.val.src_mac); |
| 2564 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2565 | if (ib_spec->eth.mask.vlan_tag) { |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2566 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2567 | cvlan_tag, 1); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2568 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Mohamad Haj Yahia | 1054336 | 2016-10-09 16:25:43 +0300 | [diff] [blame] | 2569 | cvlan_tag, 1); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2570 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2571 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2572 | first_vid, ntohs(ib_spec->eth.mask.vlan_tag)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2573 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2574 | first_vid, ntohs(ib_spec->eth.val.vlan_tag)); |
| 2575 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2576 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2577 | first_cfi, |
| 2578 | ntohs(ib_spec->eth.mask.vlan_tag) >> 12); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2579 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2580 | first_cfi, |
| 2581 | ntohs(ib_spec->eth.val.vlan_tag) >> 12); |
| 2582 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2583 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2584 | first_prio, |
| 2585 | ntohs(ib_spec->eth.mask.vlan_tag) >> 13); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2586 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2587 | first_prio, |
| 2588 | ntohs(ib_spec->eth.val.vlan_tag) >> 13); |
| 2589 | } |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2590 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2591 | ethertype, ntohs(ib_spec->eth.mask.ether_type)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2592 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2593 | ethertype, ntohs(ib_spec->eth.val.ether_type)); |
| 2594 | break; |
| 2595 | case IB_FLOW_SPEC_IPV4: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2596 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv4.mask, LAST_IPV4_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2597 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2598 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2599 | if (match_ipv) { |
| 2600 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2601 | ip_version, 0xf); |
| 2602 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2603 | ip_version, MLX5_FS_IPV4_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2604 | } else { |
| 2605 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2606 | ethertype, 0xffff); |
| 2607 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2608 | ethertype, ETH_P_IP); |
| 2609 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2610 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2611 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2612 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2613 | &ib_spec->ipv4.mask.src_ip, |
| 2614 | sizeof(ib_spec->ipv4.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2615 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2616 | src_ipv4_src_ipv6.ipv4_layout.ipv4), |
| 2617 | &ib_spec->ipv4.val.src_ip, |
| 2618 | sizeof(ib_spec->ipv4.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2619 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2620 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2621 | &ib_spec->ipv4.mask.dst_ip, |
| 2622 | sizeof(ib_spec->ipv4.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2623 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2624 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
| 2625 | &ib_spec->ipv4.val.dst_ip, |
| 2626 | sizeof(ib_spec->ipv4.val.dst_ip)); |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2627 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2628 | set_tos(headers_c, headers_v, |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2629 | ib_spec->ipv4.mask.tos, ib_spec->ipv4.val.tos); |
| 2630 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2631 | set_proto(headers_c, headers_v, |
Maor Gottlieb | ca0d475 | 2016-08-30 16:58:35 +0300 | [diff] [blame] | 2632 | ib_spec->ipv4.mask.proto, ib_spec->ipv4.val.proto); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2633 | break; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2634 | case IB_FLOW_SPEC_IPV6: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2635 | if (FIELDS_NOT_SUPPORTED(ib_spec->ipv6.mask, LAST_IPV6_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2636 | return -EOPNOTSUPP; |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2637 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2638 | if (match_ipv) { |
| 2639 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2640 | ip_version, 0xf); |
| 2641 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
Boris Pismenny | 3346c48 | 2017-08-20 15:13:08 +0300 | [diff] [blame] | 2642 | ip_version, MLX5_FS_IPV6_VERSION); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2643 | } else { |
| 2644 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
| 2645 | ethertype, 0xffff); |
| 2646 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
| 2647 | ethertype, ETH_P_IPV6); |
| 2648 | } |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2649 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2650 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2651 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2652 | &ib_spec->ipv6.mask.src_ip, |
| 2653 | sizeof(ib_spec->ipv6.mask.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2654 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2655 | src_ipv4_src_ipv6.ipv6_layout.ipv6), |
| 2656 | &ib_spec->ipv6.val.src_ip, |
| 2657 | sizeof(ib_spec->ipv6.val.src_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2658 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2659 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2660 | &ib_spec->ipv6.mask.dst_ip, |
| 2661 | sizeof(ib_spec->ipv6.mask.dst_ip)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2662 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2663 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
| 2664 | &ib_spec->ipv6.val.dst_ip, |
| 2665 | sizeof(ib_spec->ipv6.val.dst_ip)); |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2666 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2667 | set_tos(headers_c, headers_v, |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2668 | ib_spec->ipv6.mask.traffic_class, |
| 2669 | ib_spec->ipv6.val.traffic_class); |
| 2670 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2671 | set_proto(headers_c, headers_v, |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 2672 | ib_spec->ipv6.mask.next_hdr, |
| 2673 | ib_spec->ipv6.val.next_hdr); |
| 2674 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2675 | set_flow_label(misc_params_c, misc_params_v, |
| 2676 | ntohl(ib_spec->ipv6.mask.flow_label), |
| 2677 | ntohl(ib_spec->ipv6.val.flow_label), |
| 2678 | ib_spec->type & IB_FLOW_SPEC_INNER); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2679 | break; |
| 2680 | case IB_FLOW_SPEC_ESP: |
| 2681 | if (ib_spec->esp.mask.seq) |
| 2682 | return -EOPNOTSUPP; |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2683 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2684 | MLX5_SET(fte_match_set_misc, misc_params_c, outer_esp_spi, |
| 2685 | ntohl(ib_spec->esp.mask.spi)); |
| 2686 | MLX5_SET(fte_match_set_misc, misc_params_v, outer_esp_spi, |
| 2687 | ntohl(ib_spec->esp.val.spi)); |
Maor Gottlieb | 026bae0 | 2016-06-17 15:14:51 +0300 | [diff] [blame] | 2688 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2689 | case IB_FLOW_SPEC_TCP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2690 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2691 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2692 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2693 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2694 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2695 | 0xff); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2696 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2697 | IPPROTO_TCP); |
| 2698 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2699 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2700 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2701 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2702 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2703 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2704 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2705 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2706 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2707 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2708 | break; |
| 2709 | case IB_FLOW_SPEC_UDP: |
Maor Gottlieb | c47ac6a | 2016-08-30 16:58:31 +0300 | [diff] [blame] | 2710 | if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
| 2711 | LAST_TCP_UDP_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2712 | return -EOPNOTSUPP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2713 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2714 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2715 | 0xff); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2716 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2717 | IPPROTO_UDP); |
| 2718 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2719 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2720 | ntohs(ib_spec->tcp_udp.mask.src_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2721 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2722 | ntohs(ib_spec->tcp_udp.val.src_port)); |
| 2723 | |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2724 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2725 | ntohs(ib_spec->tcp_udp.mask.dst_port)); |
Moses Reuben | 2d1e697 | 2016-11-14 19:04:52 +0200 | [diff] [blame] | 2726 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2727 | ntohs(ib_spec->tcp_udp.val.dst_port)); |
| 2728 | break; |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2729 | case IB_FLOW_SPEC_GRE: |
| 2730 | if (ib_spec->gre.mask.c_ks_res0_ver) |
| 2731 | return -EOPNOTSUPP; |
| 2732 | |
| 2733 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
| 2734 | 0xff); |
| 2735 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
| 2736 | IPPROTO_GRE); |
| 2737 | |
| 2738 | MLX5_SET(fte_match_set_misc, misc_params_c, gre_protocol, |
Maor Gottlieb | a93b632 | 2018-07-01 15:50:17 +0300 | [diff] [blame] | 2739 | ntohs(ib_spec->gre.mask.protocol)); |
Ariel Levkovich | da2f22a | 2018-05-13 14:33:33 +0300 | [diff] [blame] | 2740 | MLX5_SET(fte_match_set_misc, misc_params_v, gre_protocol, |
| 2741 | ntohs(ib_spec->gre.val.protocol)); |
| 2742 | |
| 2743 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_c, |
| 2744 | gre_key_h), |
| 2745 | &ib_spec->gre.mask.key, |
| 2746 | sizeof(ib_spec->gre.mask.key)); |
| 2747 | memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_v, |
| 2748 | gre_key_h), |
| 2749 | &ib_spec->gre.val.key, |
| 2750 | sizeof(ib_spec->gre.val.key)); |
| 2751 | break; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 2752 | case IB_FLOW_SPEC_MPLS: |
| 2753 | switch (prev_type) { |
| 2754 | case IB_FLOW_SPEC_UDP: |
| 2755 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2756 | ft_field_support.outer_first_mpls_over_udp), |
| 2757 | &ib_spec->mpls.mask.tag)) |
| 2758 | return -EOPNOTSUPP; |
| 2759 | |
| 2760 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2761 | outer_first_mpls_over_udp), |
| 2762 | &ib_spec->mpls.val.tag, |
| 2763 | sizeof(ib_spec->mpls.val.tag)); |
| 2764 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2765 | outer_first_mpls_over_udp), |
| 2766 | &ib_spec->mpls.mask.tag, |
| 2767 | sizeof(ib_spec->mpls.mask.tag)); |
| 2768 | break; |
| 2769 | case IB_FLOW_SPEC_GRE: |
| 2770 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2771 | ft_field_support.outer_first_mpls_over_gre), |
| 2772 | &ib_spec->mpls.mask.tag)) |
| 2773 | return -EOPNOTSUPP; |
| 2774 | |
| 2775 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2776 | outer_first_mpls_over_gre), |
| 2777 | &ib_spec->mpls.val.tag, |
| 2778 | sizeof(ib_spec->mpls.val.tag)); |
| 2779 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2780 | outer_first_mpls_over_gre), |
| 2781 | &ib_spec->mpls.mask.tag, |
| 2782 | sizeof(ib_spec->mpls.mask.tag)); |
| 2783 | break; |
| 2784 | default: |
| 2785 | if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
| 2786 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2787 | ft_field_support.inner_first_mpls), |
| 2788 | &ib_spec->mpls.mask.tag)) |
| 2789 | return -EOPNOTSUPP; |
| 2790 | |
| 2791 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2792 | inner_first_mpls), |
| 2793 | &ib_spec->mpls.val.tag, |
| 2794 | sizeof(ib_spec->mpls.val.tag)); |
| 2795 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2796 | inner_first_mpls), |
| 2797 | &ib_spec->mpls.mask.tag, |
| 2798 | sizeof(ib_spec->mpls.mask.tag)); |
| 2799 | } else { |
| 2800 | if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2801 | ft_field_support.outer_first_mpls), |
| 2802 | &ib_spec->mpls.mask.tag)) |
| 2803 | return -EOPNOTSUPP; |
| 2804 | |
| 2805 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
| 2806 | outer_first_mpls), |
| 2807 | &ib_spec->mpls.val.tag, |
| 2808 | sizeof(ib_spec->mpls.val.tag)); |
| 2809 | memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
| 2810 | outer_first_mpls), |
| 2811 | &ib_spec->mpls.mask.tag, |
| 2812 | sizeof(ib_spec->mpls.mask.tag)); |
| 2813 | } |
| 2814 | } |
| 2815 | break; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2816 | case IB_FLOW_SPEC_VXLAN_TUNNEL: |
| 2817 | if (FIELDS_NOT_SUPPORTED(ib_spec->tunnel.mask, |
| 2818 | LAST_TUNNEL_FIELD)) |
Leon Romanovsky | 1ffd3a2 | 2017-01-18 14:59:51 +0200 | [diff] [blame] | 2819 | return -EOPNOTSUPP; |
Moses Reuben | ffb30d8 | 2016-11-14 19:04:50 +0200 | [diff] [blame] | 2820 | |
| 2821 | MLX5_SET(fte_match_set_misc, misc_params_c, vxlan_vni, |
| 2822 | ntohl(ib_spec->tunnel.mask.tunnel_id)); |
| 2823 | MLX5_SET(fte_match_set_misc, misc_params_v, vxlan_vni, |
| 2824 | ntohl(ib_spec->tunnel.val.tunnel_id)); |
| 2825 | break; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2826 | case IB_FLOW_SPEC_ACTION_TAG: |
| 2827 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_tag, |
| 2828 | LAST_FLOW_TAG_FIELD)) |
| 2829 | return -EOPNOTSUPP; |
| 2830 | if (ib_spec->flow_tag.tag_id >= BIT(24)) |
| 2831 | return -EINVAL; |
| 2832 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 2833 | action->flow_tag = ib_spec->flow_tag.tag_id; |
Matan Barak | a9db0ec | 2017-08-16 09:43:48 +0300 | [diff] [blame] | 2834 | action->has_flow_tag = true; |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 2835 | break; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2836 | case IB_FLOW_SPEC_ACTION_DROP: |
| 2837 | if (FIELDS_NOT_SUPPORTED(ib_spec->drop, |
| 2838 | LAST_DROP_FIELD)) |
| 2839 | return -EOPNOTSUPP; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 2840 | action->action |= MLX5_FLOW_CONTEXT_ACTION_DROP; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 2841 | break; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2842 | case IB_FLOW_SPEC_ACTION_HANDLE: |
Mark Bloch | 2ea2620 | 2018-09-06 17:27:03 +0300 | [diff] [blame] | 2843 | ret = parse_flow_flow_action(to_mflow_act(ib_spec->action.act), |
| 2844 | flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS, action); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2845 | if (ret) |
| 2846 | return ret; |
| 2847 | break; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 2848 | case IB_FLOW_SPEC_ACTION_COUNT: |
| 2849 | if (FIELDS_NOT_SUPPORTED(ib_spec->flow_count, |
| 2850 | LAST_COUNTERS_FIELD)) |
| 2851 | return -EOPNOTSUPP; |
| 2852 | |
| 2853 | /* for now support only one counters spec per flow */ |
| 2854 | if (action->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) |
| 2855 | return -EINVAL; |
| 2856 | |
| 2857 | action->counters = ib_spec->flow_count.counters; |
| 2858 | action->action |= MLX5_FLOW_CONTEXT_ACTION_COUNT; |
| 2859 | break; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2860 | default: |
| 2861 | return -EINVAL; |
| 2862 | } |
| 2863 | |
| 2864 | return 0; |
| 2865 | } |
| 2866 | |
| 2867 | /* If a flow could catch both multicast and unicast packets, |
| 2868 | * it won't fall into the multicast flow steering table and this rule |
| 2869 | * could steal other multicast packets. |
| 2870 | */ |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 2871 | 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] | 2872 | { |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2873 | union ib_flow_spec *flow_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2874 | |
| 2875 | if (ib_attr->type != IB_FLOW_ATTR_NORMAL || |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2876 | ib_attr->num_of_specs < 1) |
| 2877 | return false; |
| 2878 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2879 | flow_spec = (union ib_flow_spec *)(ib_attr + 1); |
| 2880 | if (flow_spec->type == IB_FLOW_SPEC_IPV4) { |
| 2881 | struct ib_flow_spec_ipv4 *ipv4_spec; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2882 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 2883 | ipv4_spec = (struct ib_flow_spec_ipv4 *)flow_spec; |
| 2884 | if (ipv4_is_multicast(ipv4_spec->val.dst_ip)) |
| 2885 | return true; |
| 2886 | |
| 2887 | return false; |
| 2888 | } |
| 2889 | |
| 2890 | if (flow_spec->type == IB_FLOW_SPEC_ETH) { |
| 2891 | struct ib_flow_spec_eth *eth_spec; |
| 2892 | |
| 2893 | eth_spec = (struct ib_flow_spec_eth *)flow_spec; |
| 2894 | return is_multicast_ether_addr(eth_spec->mask.dst_mac) && |
| 2895 | is_multicast_ether_addr(eth_spec->val.dst_mac); |
| 2896 | } |
| 2897 | |
| 2898 | return false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2899 | } |
| 2900 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2901 | enum valid_spec { |
| 2902 | VALID_SPEC_INVALID, |
| 2903 | VALID_SPEC_VALID, |
| 2904 | VALID_SPEC_NA, |
| 2905 | }; |
| 2906 | |
| 2907 | static enum valid_spec |
| 2908 | is_valid_esp_aes_gcm(struct mlx5_core_dev *mdev, |
| 2909 | const struct mlx5_flow_spec *spec, |
| 2910 | const struct mlx5_flow_act *flow_act, |
| 2911 | bool egress) |
| 2912 | { |
| 2913 | const u32 *match_c = spec->match_criteria; |
| 2914 | bool is_crypto = |
| 2915 | (flow_act->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
| 2916 | MLX5_FLOW_CONTEXT_ACTION_DECRYPT)); |
| 2917 | bool is_ipsec = mlx5_fs_is_ipsec_flow(match_c); |
| 2918 | bool is_drop = flow_act->action & MLX5_FLOW_CONTEXT_ACTION_DROP; |
| 2919 | |
| 2920 | /* |
| 2921 | * Currently only crypto is supported in egress, when regular egress |
| 2922 | * rules would be supported, always return VALID_SPEC_NA. |
| 2923 | */ |
| 2924 | if (!is_crypto) |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 2925 | return VALID_SPEC_NA; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 2926 | |
| 2927 | return is_crypto && is_ipsec && |
| 2928 | (!egress || (!is_drop && !flow_act->has_flow_tag)) ? |
| 2929 | VALID_SPEC_VALID : VALID_SPEC_INVALID; |
| 2930 | } |
| 2931 | |
| 2932 | static bool is_valid_spec(struct mlx5_core_dev *mdev, |
| 2933 | const struct mlx5_flow_spec *spec, |
| 2934 | const struct mlx5_flow_act *flow_act, |
| 2935 | bool egress) |
| 2936 | { |
| 2937 | /* We curretly only support ipsec egress flow */ |
| 2938 | return is_valid_esp_aes_gcm(mdev, spec, flow_act, egress) != VALID_SPEC_INVALID; |
| 2939 | } |
| 2940 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2941 | static bool is_valid_ethertype(struct mlx5_core_dev *mdev, |
| 2942 | const struct ib_flow_attr *flow_attr, |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2943 | bool check_inner) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2944 | { |
| 2945 | 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] | 2946 | int match_ipv = check_inner ? |
| 2947 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2948 | ft_field_support.inner_ip_version) : |
| 2949 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
| 2950 | ft_field_support.outer_ip_version); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2951 | int inner_bit = check_inner ? IB_FLOW_SPEC_INNER : 0; |
| 2952 | bool ipv4_spec_valid, ipv6_spec_valid; |
| 2953 | unsigned int ip_spec_type = 0; |
| 2954 | bool has_ethertype = false; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2955 | unsigned int spec_index; |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2956 | bool mask_valid = true; |
| 2957 | u16 eth_type = 0; |
| 2958 | bool type_valid; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2959 | |
| 2960 | /* Validate that ethertype is correct */ |
| 2961 | 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] | 2962 | if ((ib_spec->type == (IB_FLOW_SPEC_ETH | inner_bit)) && |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2963 | ib_spec->eth.mask.ether_type) { |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2964 | mask_valid = (ib_spec->eth.mask.ether_type == |
| 2965 | htons(0xffff)); |
| 2966 | has_ethertype = true; |
| 2967 | eth_type = ntohs(ib_spec->eth.val.ether_type); |
| 2968 | } else if ((ib_spec->type == (IB_FLOW_SPEC_IPV4 | inner_bit)) || |
| 2969 | (ib_spec->type == (IB_FLOW_SPEC_IPV6 | inner_bit))) { |
| 2970 | ip_spec_type = ib_spec->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2971 | } |
| 2972 | ib_spec = (void *)ib_spec + ib_spec->size; |
| 2973 | } |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2974 | |
| 2975 | type_valid = (!has_ethertype) || (!ip_spec_type); |
| 2976 | if (!type_valid && mask_valid) { |
| 2977 | ipv4_spec_valid = (eth_type == ETH_P_IP) && |
| 2978 | (ip_spec_type == (IB_FLOW_SPEC_IPV4 | inner_bit)); |
| 2979 | ipv6_spec_valid = (eth_type == ETH_P_IPV6) && |
| 2980 | (ip_spec_type == (IB_FLOW_SPEC_IPV6 | inner_bit)); |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2981 | |
| 2982 | type_valid = (ipv4_spec_valid) || (ipv6_spec_valid) || |
| 2983 | (((eth_type == ETH_P_MPLS_UC) || |
| 2984 | (eth_type == ETH_P_MPLS_MC)) && match_ipv); |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | return type_valid; |
| 2988 | } |
| 2989 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2990 | static bool is_valid_attr(struct mlx5_core_dev *mdev, |
| 2991 | const struct ib_flow_attr *flow_attr) |
Ariel Levkovich | 0f75096 | 2017-04-03 13:11:02 +0300 | [diff] [blame] | 2992 | { |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 2993 | return is_valid_ethertype(mdev, flow_attr, false) && |
| 2994 | is_valid_ethertype(mdev, flow_attr, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | static void put_flow_table(struct mlx5_ib_dev *dev, |
| 2998 | struct mlx5_ib_flow_prio *prio, bool ft_added) |
| 2999 | { |
| 3000 | prio->refcount -= !!ft_added; |
| 3001 | if (!prio->refcount) { |
| 3002 | mlx5_destroy_flow_table(prio->flow_table); |
| 3003 | prio->flow_table = NULL; |
| 3004 | } |
| 3005 | } |
| 3006 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3007 | static void counters_clear_description(struct ib_counters *counters) |
| 3008 | { |
| 3009 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3010 | |
| 3011 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3012 | kfree(mcounters->counters_data); |
| 3013 | mcounters->counters_data = NULL; |
| 3014 | mcounters->cntrs_max_index = 0; |
| 3015 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3016 | } |
| 3017 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3018 | static int mlx5_ib_destroy_flow(struct ib_flow *flow_id) |
| 3019 | { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3020 | struct mlx5_ib_flow_handler *handler = container_of(flow_id, |
| 3021 | struct mlx5_ib_flow_handler, |
| 3022 | ibflow); |
| 3023 | struct mlx5_ib_flow_handler *iter, *tmp; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3024 | struct mlx5_ib_dev *dev = handler->dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3025 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3026 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3027 | |
| 3028 | list_for_each_entry_safe(iter, tmp, &handler->list, list) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3029 | mlx5_del_flow_rules(iter->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3030 | put_flow_table(dev, iter->prio, true); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3031 | list_del(&iter->list); |
| 3032 | kfree(iter); |
| 3033 | } |
| 3034 | |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3035 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3036 | put_flow_table(dev, handler->prio, true); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3037 | if (handler->ibcounters && |
| 3038 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3039 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3040 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3041 | mutex_unlock(&dev->flow_db->lock); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3042 | if (handler->flow_matcher) |
| 3043 | atomic_dec(&handler->flow_matcher->usecnt); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3044 | kfree(handler); |
| 3045 | |
| 3046 | return 0; |
| 3047 | } |
| 3048 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3049 | static int ib_prio_to_core_prio(unsigned int priority, bool dont_trap) |
| 3050 | { |
| 3051 | priority *= 2; |
| 3052 | if (!dont_trap) |
| 3053 | priority++; |
| 3054 | return priority; |
| 3055 | } |
| 3056 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3057 | enum flow_table_type { |
| 3058 | MLX5_IB_FT_RX, |
| 3059 | MLX5_IB_FT_TX |
| 3060 | }; |
| 3061 | |
Maor Gottlieb | 00b7c2a | 2017-03-29 06:09:01 +0300 | [diff] [blame] | 3062 | #define MLX5_FS_MAX_TYPES 6 |
| 3063 | #define MLX5_FS_MAX_ENTRIES BIT(16) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3064 | |
| 3065 | static struct mlx5_ib_flow_prio *_get_prio(struct mlx5_flow_namespace *ns, |
| 3066 | struct mlx5_ib_flow_prio *prio, |
| 3067 | int priority, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3068 | int num_entries, int num_groups, |
| 3069 | u32 flags) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3070 | { |
| 3071 | struct mlx5_flow_table *ft; |
| 3072 | |
| 3073 | ft = mlx5_create_auto_grouped_flow_table(ns, priority, |
| 3074 | num_entries, |
| 3075 | num_groups, |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3076 | 0, flags); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3077 | if (IS_ERR(ft)) |
| 3078 | return ERR_CAST(ft); |
| 3079 | |
| 3080 | prio->flow_table = ft; |
| 3081 | prio->refcount = 0; |
| 3082 | return prio; |
| 3083 | } |
| 3084 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3085 | 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] | 3086 | struct ib_flow_attr *flow_attr, |
| 3087 | enum flow_table_type ft_type) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3088 | { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3089 | bool dont_trap = flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3090 | struct mlx5_flow_namespace *ns = NULL; |
| 3091 | struct mlx5_ib_flow_prio *prio; |
| 3092 | struct mlx5_flow_table *ft; |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3093 | int max_table_size; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3094 | int num_entries; |
| 3095 | int num_groups; |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3096 | u32 flags = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3097 | int priority; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3098 | |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3099 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3100 | log_max_ft_size)); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3101 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3102 | enum mlx5_flow_namespace_type fn_type; |
| 3103 | |
| 3104 | if (flow_is_multicast_only(flow_attr) && |
| 3105 | !dont_trap) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3106 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3107 | else |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3108 | priority = ib_prio_to_core_prio(flow_attr->priority, |
| 3109 | dont_trap); |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3110 | if (ft_type == MLX5_IB_FT_RX) { |
| 3111 | fn_type = MLX5_FLOW_NAMESPACE_BYPASS; |
| 3112 | prio = &dev->flow_db->prios[priority]; |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3113 | if (!dev->rep && |
| 3114 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, decap)) |
| 3115 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
Mark Bloch | 5c2db53 | 2018-09-02 12:51:35 +0300 | [diff] [blame] | 3116 | if (!dev->rep && |
| 3117 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3118 | reformat_l3_tunnel_to_l2)) |
| 3119 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3120 | } else { |
| 3121 | max_table_size = |
| 3122 | BIT(MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, |
| 3123 | log_max_ft_size)); |
| 3124 | fn_type = MLX5_FLOW_NAMESPACE_EGRESS; |
| 3125 | prio = &dev->flow_db->egress_prios[priority]; |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3126 | if (!dev->rep && |
| 3127 | MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, reformat)) |
| 3128 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3129 | } |
| 3130 | ns = mlx5_get_flow_namespace(dev->mdev, fn_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3131 | num_entries = MLX5_FS_MAX_ENTRIES; |
| 3132 | num_groups = MLX5_FS_MAX_TYPES; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3133 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3134 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3135 | ns = mlx5_get_flow_namespace(dev->mdev, |
| 3136 | MLX5_FLOW_NAMESPACE_LEFTOVERS); |
| 3137 | build_leftovers_ft_param(&priority, |
| 3138 | &num_entries, |
| 3139 | &num_groups); |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3140 | prio = &dev->flow_db->prios[MLX5_IB_FLOW_LEFTOVERS_PRIO]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3141 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3142 | if (!MLX5_CAP_FLOWTABLE(dev->mdev, |
| 3143 | allow_sniffer_and_nic_rx_shared_tir)) |
| 3144 | return ERR_PTR(-ENOTSUPP); |
| 3145 | |
| 3146 | ns = mlx5_get_flow_namespace(dev->mdev, ft_type == MLX5_IB_FT_RX ? |
| 3147 | MLX5_FLOW_NAMESPACE_SNIFFER_RX : |
| 3148 | MLX5_FLOW_NAMESPACE_SNIFFER_TX); |
| 3149 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3150 | prio = &dev->flow_db->sniffer[ft_type]; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3151 | priority = 0; |
| 3152 | num_entries = 1; |
| 3153 | num_groups = 1; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | if (!ns) |
| 3157 | return ERR_PTR(-ENOTSUPP); |
| 3158 | |
Maor Gottlieb | dac388e | 2017-03-29 06:09:00 +0300 | [diff] [blame] | 3159 | if (num_entries > max_table_size) |
| 3160 | return ERR_PTR(-ENOMEM); |
| 3161 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3162 | ft = prio->flow_table; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3163 | if (!ft) |
Mark Bloch | 4adda11 | 2018-09-02 12:51:33 +0300 | [diff] [blame] | 3164 | return _get_prio(ns, prio, priority, num_entries, num_groups, |
| 3165 | flags); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3166 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3167 | return prio; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3168 | } |
| 3169 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3170 | static void set_underlay_qp(struct mlx5_ib_dev *dev, |
| 3171 | struct mlx5_flow_spec *spec, |
| 3172 | u32 underlay_qpn) |
| 3173 | { |
| 3174 | void *misc_params_c = MLX5_ADDR_OF(fte_match_param, |
| 3175 | spec->match_criteria, |
| 3176 | misc_parameters); |
| 3177 | void *misc_params_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3178 | misc_parameters); |
| 3179 | |
| 3180 | if (underlay_qpn && |
| 3181 | MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3182 | ft_field_support.bth_dst_qp)) { |
| 3183 | MLX5_SET(fte_match_set_misc, |
| 3184 | misc_params_v, bth_dst_qp, underlay_qpn); |
| 3185 | MLX5_SET(fte_match_set_misc, |
| 3186 | misc_params_c, bth_dst_qp, 0xffffff); |
| 3187 | } |
| 3188 | } |
| 3189 | |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3190 | static int read_flow_counters(struct ib_device *ibdev, |
| 3191 | struct mlx5_read_counters_attr *read_attr) |
| 3192 | { |
| 3193 | struct mlx5_fc *fc = read_attr->hw_cntrs_hndl; |
| 3194 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 3195 | |
| 3196 | return mlx5_fc_query(dev->mdev, fc, |
| 3197 | &read_attr->out[IB_COUNTER_PACKETS], |
| 3198 | &read_attr->out[IB_COUNTER_BYTES]); |
| 3199 | } |
| 3200 | |
| 3201 | /* flow counters currently expose two counters packets and bytes */ |
| 3202 | #define FLOW_COUNTERS_NUM 2 |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3203 | static int counters_set_description(struct ib_counters *counters, |
| 3204 | enum mlx5_ib_counters_type counters_type, |
| 3205 | struct mlx5_ib_flow_counters_desc *desc_data, |
| 3206 | u32 ncounters) |
| 3207 | { |
| 3208 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 3209 | u32 cntrs_max_index = 0; |
| 3210 | int i; |
| 3211 | |
| 3212 | if (counters_type != MLX5_IB_COUNTERS_FLOW) |
| 3213 | return -EINVAL; |
| 3214 | |
| 3215 | /* init the fields for the object */ |
| 3216 | mcounters->type = counters_type; |
Raed Salem | 5e95af5 | 2018-05-31 16:43:40 +0300 | [diff] [blame] | 3217 | mcounters->read_counters = read_flow_counters; |
| 3218 | mcounters->counters_num = FLOW_COUNTERS_NUM; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3219 | mcounters->ncounters = ncounters; |
| 3220 | /* each counter entry have both description and index pair */ |
| 3221 | for (i = 0; i < ncounters; i++) { |
| 3222 | if (desc_data[i].description > IB_COUNTER_BYTES) |
| 3223 | return -EINVAL; |
| 3224 | |
| 3225 | if (cntrs_max_index <= desc_data[i].index) |
| 3226 | cntrs_max_index = desc_data[i].index + 1; |
| 3227 | } |
| 3228 | |
| 3229 | mutex_lock(&mcounters->mcntrs_mutex); |
| 3230 | mcounters->counters_data = desc_data; |
| 3231 | mcounters->cntrs_max_index = cntrs_max_index; |
| 3232 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 3233 | |
| 3234 | return 0; |
| 3235 | } |
| 3236 | |
| 3237 | #define MAX_COUNTERS_NUM (USHRT_MAX / (sizeof(u32) * 2)) |
| 3238 | static int flow_counters_set_data(struct ib_counters *ibcounters, |
| 3239 | struct mlx5_ib_create_flow *ucmd) |
| 3240 | { |
| 3241 | struct mlx5_ib_mcounters *mcounters = to_mcounters(ibcounters); |
| 3242 | struct mlx5_ib_flow_counters_data *cntrs_data = NULL; |
| 3243 | struct mlx5_ib_flow_counters_desc *desc_data = NULL; |
| 3244 | bool hw_hndl = false; |
| 3245 | int ret = 0; |
| 3246 | |
| 3247 | if (ucmd && ucmd->ncounters_data != 0) { |
| 3248 | cntrs_data = ucmd->data; |
| 3249 | if (cntrs_data->ncounters > MAX_COUNTERS_NUM) |
| 3250 | return -EINVAL; |
| 3251 | |
| 3252 | desc_data = kcalloc(cntrs_data->ncounters, |
| 3253 | sizeof(*desc_data), |
| 3254 | GFP_KERNEL); |
| 3255 | if (!desc_data) |
| 3256 | return -ENOMEM; |
| 3257 | |
| 3258 | if (copy_from_user(desc_data, |
| 3259 | u64_to_user_ptr(cntrs_data->counters_data), |
| 3260 | sizeof(*desc_data) * cntrs_data->ncounters)) { |
| 3261 | ret = -EFAULT; |
| 3262 | goto free; |
| 3263 | } |
| 3264 | } |
| 3265 | |
| 3266 | if (!mcounters->hw_cntrs_hndl) { |
| 3267 | mcounters->hw_cntrs_hndl = mlx5_fc_create( |
| 3268 | to_mdev(ibcounters->device)->mdev, false); |
weiyongjun (A) | e31abf7 | 2018-06-07 01:47:41 +0000 | [diff] [blame] | 3269 | if (IS_ERR(mcounters->hw_cntrs_hndl)) { |
| 3270 | ret = PTR_ERR(mcounters->hw_cntrs_hndl); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3271 | goto free; |
| 3272 | } |
| 3273 | hw_hndl = true; |
| 3274 | } |
| 3275 | |
| 3276 | if (desc_data) { |
| 3277 | /* counters already bound to at least one flow */ |
| 3278 | if (mcounters->cntrs_max_index) { |
| 3279 | ret = -EINVAL; |
| 3280 | goto free_hndl; |
| 3281 | } |
| 3282 | |
| 3283 | ret = counters_set_description(ibcounters, |
| 3284 | MLX5_IB_COUNTERS_FLOW, |
| 3285 | desc_data, |
| 3286 | cntrs_data->ncounters); |
| 3287 | if (ret) |
| 3288 | goto free_hndl; |
| 3289 | |
| 3290 | } else if (!mcounters->cntrs_max_index) { |
| 3291 | /* counters not bound yet, must have udata passed */ |
| 3292 | ret = -EINVAL; |
| 3293 | goto free_hndl; |
| 3294 | } |
| 3295 | |
| 3296 | return 0; |
| 3297 | |
| 3298 | free_hndl: |
| 3299 | if (hw_hndl) { |
| 3300 | mlx5_fc_destroy(to_mdev(ibcounters->device)->mdev, |
| 3301 | mcounters->hw_cntrs_hndl); |
| 3302 | mcounters->hw_cntrs_hndl = NULL; |
| 3303 | } |
| 3304 | free: |
| 3305 | kfree(desc_data); |
| 3306 | return ret; |
| 3307 | } |
| 3308 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3309 | static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev, |
| 3310 | struct mlx5_ib_flow_prio *ft_prio, |
| 3311 | const struct ib_flow_attr *flow_attr, |
| 3312 | struct mlx5_flow_destination *dst, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3313 | u32 underlay_qpn, |
| 3314 | struct mlx5_ib_create_flow *ucmd) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3315 | { |
| 3316 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3317 | struct mlx5_ib_flow_handler *handler; |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3318 | 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] | 3319 | struct mlx5_flow_spec *spec; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3320 | struct mlx5_flow_destination dest_arr[2] = {}; |
| 3321 | struct mlx5_flow_destination *rule_dst = dest_arr; |
Maor Gottlieb | dd063d0 | 2016-08-28 14:16:32 +0300 | [diff] [blame] | 3322 | const void *ib_flow = (const void *)flow_attr + sizeof(*flow_attr); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3323 | unsigned int spec_index; |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3324 | u32 prev_type = 0; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3325 | int err = 0; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3326 | int dest_num = 0; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3327 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3328 | |
Ariel Levkovich | 19cc752 | 2017-04-03 13:11:03 +0300 | [diff] [blame] | 3329 | if (!is_valid_attr(dev->mdev, flow_attr)) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3330 | return ERR_PTR(-EINVAL); |
| 3331 | |
Mark Bloch | 78dd0c4 | 2018-09-02 12:51:31 +0300 | [diff] [blame] | 3332 | if (dev->rep && is_egress) |
| 3333 | return ERR_PTR(-EINVAL); |
| 3334 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3335 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3336 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3337 | if (!handler || !spec) { |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3338 | err = -ENOMEM; |
| 3339 | goto free; |
| 3340 | } |
| 3341 | |
| 3342 | INIT_LIST_HEAD(&handler->list); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3343 | if (dst) { |
| 3344 | memcpy(&dest_arr[0], dst, sizeof(*dst)); |
| 3345 | dest_num++; |
| 3346 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3347 | |
| 3348 | 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] | 3349 | err = parse_flow_attr(dev->mdev, spec->match_criteria, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3350 | spec->match_value, |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3351 | ib_flow, flow_attr, &flow_act, |
| 3352 | prev_type); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3353 | if (err < 0) |
| 3354 | goto free; |
| 3355 | |
Ariel Levkovich | 71c6e86 | 2018-05-13 14:33:34 +0300 | [diff] [blame] | 3356 | prev_type = ((union ib_flow_spec *)ib_flow)->type; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3357 | ib_flow += ((union ib_flow_spec *)ib_flow)->size; |
| 3358 | } |
| 3359 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3360 | if (!flow_is_multicast_only(flow_attr)) |
| 3361 | set_underlay_qp(dev, spec, underlay_qpn); |
| 3362 | |
Mark Bloch | 018a94e | 2018-01-16 14:44:29 +0000 | [diff] [blame] | 3363 | if (dev->rep) { |
| 3364 | void *misc; |
| 3365 | |
| 3366 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
| 3367 | misc_parameters); |
| 3368 | MLX5_SET(fte_match_set_misc, misc, source_port, |
| 3369 | dev->rep->vport); |
| 3370 | misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
| 3371 | misc_parameters); |
| 3372 | MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port); |
| 3373 | } |
| 3374 | |
Maor Gottlieb | 466fa6d | 2016-08-30 16:58:36 +0300 | [diff] [blame] | 3375 | spec->match_criteria_enable = get_match_criteria_enable(spec->match_criteria); |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3376 | |
| 3377 | if (is_egress && |
| 3378 | !is_valid_spec(dev->mdev, spec, &flow_act, is_egress)) { |
| 3379 | err = -EINVAL; |
| 3380 | goto free; |
| 3381 | } |
| 3382 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3383 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
| 3384 | err = flow_counters_set_data(flow_act.counters, ucmd); |
| 3385 | if (err) |
| 3386 | goto free; |
| 3387 | |
| 3388 | handler->ibcounters = flow_act.counters; |
| 3389 | dest_arr[dest_num].type = |
| 3390 | MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
| 3391 | dest_arr[dest_num].counter = |
| 3392 | to_mcounters(flow_act.counters)->hw_cntrs_hndl; |
| 3393 | dest_num++; |
| 3394 | } |
| 3395 | |
Boris Pismenny | 075572d | 2017-08-16 09:33:30 +0300 | [diff] [blame] | 3396 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DROP) { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3397 | if (!(flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT)) { |
| 3398 | rule_dst = NULL; |
| 3399 | dest_num = 0; |
| 3400 | } |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3401 | } else { |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3402 | if (is_egress) |
| 3403 | flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
| 3404 | else |
| 3405 | flow_act.action |= |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3406 | dest_num ? MLX5_FLOW_CONTEXT_ACTION_FWD_DEST : |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3407 | MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO; |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3408 | } |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3409 | |
Matan Barak | a9db0ec | 2017-08-16 09:43:48 +0300 | [diff] [blame] | 3410 | if (flow_act.has_flow_tag && |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3411 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3412 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3413 | 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] | 3414 | flow_act.flow_tag, flow_attr->type); |
Moses Reuben | 2ac693f | 2017-01-18 14:59:50 +0200 | [diff] [blame] | 3415 | err = -EINVAL; |
| 3416 | goto free; |
| 3417 | } |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3418 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Hadar Hen Zion | 66958ed | 2016-11-07 15:14:45 +0200 | [diff] [blame] | 3419 | &flow_act, |
Slava Shwartsman | a22ed86 | 2017-04-03 13:13:52 +0300 | [diff] [blame] | 3420 | rule_dst, dest_num); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3421 | |
| 3422 | if (IS_ERR(handler->rule)) { |
| 3423 | err = PTR_ERR(handler->rule); |
| 3424 | goto free; |
| 3425 | } |
| 3426 | |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3427 | ft_prio->refcount++; |
Maor Gottlieb | 5497adc | 2016-08-28 14:16:31 +0300 | [diff] [blame] | 3428 | handler->prio = ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3429 | handler->dev = dev; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3430 | |
| 3431 | ft_prio->flow_table = ft; |
| 3432 | free: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3433 | if (err && handler) { |
| 3434 | if (handler->ibcounters && |
| 3435 | atomic_read(&handler->ibcounters->usecnt) == 1) |
| 3436 | counters_clear_description(handler->ibcounters); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3437 | kfree(handler); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3438 | } |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 3439 | kvfree(spec); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3440 | return err ? ERR_PTR(err) : handler; |
| 3441 | } |
| 3442 | |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3443 | static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev, |
| 3444 | struct mlx5_ib_flow_prio *ft_prio, |
| 3445 | const struct ib_flow_attr *flow_attr, |
| 3446 | struct mlx5_flow_destination *dst) |
| 3447 | { |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3448 | return _create_flow_rule(dev, ft_prio, flow_attr, dst, 0, NULL); |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3449 | } |
| 3450 | |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3451 | static struct mlx5_ib_flow_handler *create_dont_trap_rule(struct mlx5_ib_dev *dev, |
| 3452 | struct mlx5_ib_flow_prio *ft_prio, |
| 3453 | struct ib_flow_attr *flow_attr, |
| 3454 | struct mlx5_flow_destination *dst) |
| 3455 | { |
| 3456 | struct mlx5_ib_flow_handler *handler_dst = NULL; |
| 3457 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3458 | |
| 3459 | handler = create_flow_rule(dev, ft_prio, flow_attr, NULL); |
| 3460 | if (!IS_ERR(handler)) { |
| 3461 | handler_dst = create_flow_rule(dev, ft_prio, |
| 3462 | flow_attr, dst); |
| 3463 | if (IS_ERR(handler_dst)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3464 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3465 | ft_prio->refcount--; |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3466 | kfree(handler); |
| 3467 | handler = handler_dst; |
| 3468 | } else { |
| 3469 | list_add(&handler_dst->list, &handler->list); |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | return handler; |
| 3474 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3475 | enum { |
| 3476 | LEFTOVERS_MC, |
| 3477 | LEFTOVERS_UC, |
| 3478 | }; |
| 3479 | |
| 3480 | static struct mlx5_ib_flow_handler *create_leftovers_rule(struct mlx5_ib_dev *dev, |
| 3481 | struct mlx5_ib_flow_prio *ft_prio, |
| 3482 | struct ib_flow_attr *flow_attr, |
| 3483 | struct mlx5_flow_destination *dst) |
| 3484 | { |
| 3485 | struct mlx5_ib_flow_handler *handler_ucast = NULL; |
| 3486 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3487 | |
| 3488 | static struct { |
| 3489 | struct ib_flow_attr flow_attr; |
| 3490 | struct ib_flow_spec_eth eth_flow; |
| 3491 | } leftovers_specs[] = { |
| 3492 | [LEFTOVERS_MC] = { |
| 3493 | .flow_attr = { |
| 3494 | .num_of_specs = 1, |
| 3495 | .size = sizeof(leftovers_specs[0]) |
| 3496 | }, |
| 3497 | .eth_flow = { |
| 3498 | .type = IB_FLOW_SPEC_ETH, |
| 3499 | .size = sizeof(struct ib_flow_spec_eth), |
| 3500 | .mask = {.dst_mac = {0x1} }, |
| 3501 | .val = {.dst_mac = {0x1} } |
| 3502 | } |
| 3503 | }, |
| 3504 | [LEFTOVERS_UC] = { |
| 3505 | .flow_attr = { |
| 3506 | .num_of_specs = 1, |
| 3507 | .size = sizeof(leftovers_specs[0]) |
| 3508 | }, |
| 3509 | .eth_flow = { |
| 3510 | .type = IB_FLOW_SPEC_ETH, |
| 3511 | .size = sizeof(struct ib_flow_spec_eth), |
| 3512 | .mask = {.dst_mac = {0x1} }, |
| 3513 | .val = {.dst_mac = {} } |
| 3514 | } |
| 3515 | } |
| 3516 | }; |
| 3517 | |
| 3518 | handler = create_flow_rule(dev, ft_prio, |
| 3519 | &leftovers_specs[LEFTOVERS_MC].flow_attr, |
| 3520 | dst); |
| 3521 | if (!IS_ERR(handler) && |
| 3522 | flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT) { |
| 3523 | handler_ucast = create_flow_rule(dev, ft_prio, |
| 3524 | &leftovers_specs[LEFTOVERS_UC].flow_attr, |
| 3525 | dst); |
| 3526 | if (IS_ERR(handler_ucast)) { |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3527 | mlx5_del_flow_rules(handler->rule); |
Maor Gottlieb | d9d4980 | 2016-08-28 14:16:33 +0300 | [diff] [blame] | 3528 | ft_prio->refcount--; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3529 | kfree(handler); |
| 3530 | handler = handler_ucast; |
| 3531 | } else { |
| 3532 | list_add(&handler_ucast->list, &handler->list); |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | return handler; |
| 3537 | } |
| 3538 | |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3539 | static struct mlx5_ib_flow_handler *create_sniffer_rule(struct mlx5_ib_dev *dev, |
| 3540 | struct mlx5_ib_flow_prio *ft_rx, |
| 3541 | struct mlx5_ib_flow_prio *ft_tx, |
| 3542 | struct mlx5_flow_destination *dst) |
| 3543 | { |
| 3544 | struct mlx5_ib_flow_handler *handler_rx; |
| 3545 | struct mlx5_ib_flow_handler *handler_tx; |
| 3546 | int err; |
| 3547 | static const struct ib_flow_attr flow_attr = { |
| 3548 | .num_of_specs = 0, |
| 3549 | .size = sizeof(flow_attr) |
| 3550 | }; |
| 3551 | |
| 3552 | handler_rx = create_flow_rule(dev, ft_rx, &flow_attr, dst); |
| 3553 | if (IS_ERR(handler_rx)) { |
| 3554 | err = PTR_ERR(handler_rx); |
| 3555 | goto err; |
| 3556 | } |
| 3557 | |
| 3558 | handler_tx = create_flow_rule(dev, ft_tx, &flow_attr, dst); |
| 3559 | if (IS_ERR(handler_tx)) { |
| 3560 | err = PTR_ERR(handler_tx); |
| 3561 | goto err_tx; |
| 3562 | } |
| 3563 | |
| 3564 | list_add(&handler_tx->list, &handler_rx->list); |
| 3565 | |
| 3566 | return handler_rx; |
| 3567 | |
| 3568 | err_tx: |
Mark Bloch | 74491de | 2016-08-31 11:24:25 +0000 | [diff] [blame] | 3569 | mlx5_del_flow_rules(handler_rx->rule); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3570 | ft_rx->refcount--; |
| 3571 | kfree(handler_rx); |
| 3572 | err: |
| 3573 | return ERR_PTR(err); |
| 3574 | } |
| 3575 | |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3576 | static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, |
| 3577 | struct ib_flow_attr *flow_attr, |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3578 | int domain, |
| 3579 | struct ib_udata *udata) |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3580 | { |
| 3581 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Yishai Hadas | d9f88e5 | 2016-08-28 10:58:37 +0300 | [diff] [blame] | 3582 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3583 | struct mlx5_ib_flow_handler *handler = NULL; |
| 3584 | struct mlx5_flow_destination *dst = NULL; |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3585 | struct mlx5_ib_flow_prio *ft_prio_tx = NULL; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3586 | struct mlx5_ib_flow_prio *ft_prio; |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3587 | bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3588 | struct mlx5_ib_create_flow *ucmd = NULL, ucmd_hdr; |
| 3589 | size_t min_ucmd_sz, required_ucmd_sz; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3590 | int err; |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3591 | int underlay_qpn; |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3592 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3593 | if (udata && udata->inlen) { |
| 3594 | min_ucmd_sz = offsetof(typeof(ucmd_hdr), reserved) + |
| 3595 | sizeof(ucmd_hdr.reserved); |
| 3596 | if (udata->inlen < min_ucmd_sz) |
| 3597 | return ERR_PTR(-EOPNOTSUPP); |
| 3598 | |
| 3599 | err = ib_copy_from_udata(&ucmd_hdr, udata, min_ucmd_sz); |
| 3600 | if (err) |
| 3601 | return ERR_PTR(err); |
| 3602 | |
| 3603 | /* currently supports only one counters data */ |
| 3604 | if (ucmd_hdr.ncounters_data > 1) |
| 3605 | return ERR_PTR(-EINVAL); |
| 3606 | |
| 3607 | required_ucmd_sz = min_ucmd_sz + |
| 3608 | sizeof(struct mlx5_ib_flow_counters_data) * |
| 3609 | ucmd_hdr.ncounters_data; |
| 3610 | if (udata->inlen > required_ucmd_sz && |
| 3611 | !ib_is_udata_cleared(udata, required_ucmd_sz, |
| 3612 | udata->inlen - required_ucmd_sz)) |
| 3613 | return ERR_PTR(-EOPNOTSUPP); |
| 3614 | |
| 3615 | ucmd = kzalloc(required_ucmd_sz, GFP_KERNEL); |
| 3616 | if (!ucmd) |
| 3617 | return ERR_PTR(-ENOMEM); |
| 3618 | |
| 3619 | err = ib_copy_from_udata(ucmd, udata, required_ucmd_sz); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3620 | if (err) |
| 3621 | goto free_ucmd; |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3622 | } |
Matan Barak | 59082a3 | 2018-05-31 16:43:35 +0300 | [diff] [blame] | 3623 | |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3624 | if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) { |
| 3625 | err = -ENOMEM; |
| 3626 | goto free_ucmd; |
| 3627 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3628 | |
| 3629 | if (domain != IB_FLOW_DOMAIN_USER || |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 3630 | flow_attr->port > dev->num_ports || |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3631 | (flow_attr->flags & ~(IB_FLOW_ATTR_FLAGS_DONT_TRAP | |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3632 | IB_FLOW_ATTR_FLAGS_EGRESS))) { |
| 3633 | err = -EINVAL; |
| 3634 | goto free_ucmd; |
| 3635 | } |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3636 | |
| 3637 | if (is_egress && |
| 3638 | (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3639 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
| 3640 | err = -EINVAL; |
| 3641 | goto free_ucmd; |
| 3642 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3643 | |
| 3644 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3645 | if (!dst) { |
| 3646 | err = -ENOMEM; |
| 3647 | goto free_ucmd; |
| 3648 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3649 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3650 | mutex_lock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3651 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3652 | ft_prio = get_flow_table(dev, flow_attr, |
| 3653 | is_egress ? MLX5_IB_FT_TX : MLX5_IB_FT_RX); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3654 | if (IS_ERR(ft_prio)) { |
| 3655 | err = PTR_ERR(ft_prio); |
| 3656 | goto unlock; |
| 3657 | } |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3658 | if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3659 | ft_prio_tx = get_flow_table(dev, flow_attr, MLX5_IB_FT_TX); |
| 3660 | if (IS_ERR(ft_prio_tx)) { |
| 3661 | err = PTR_ERR(ft_prio_tx); |
| 3662 | ft_prio_tx = NULL; |
| 3663 | goto destroy_ft; |
| 3664 | } |
| 3665 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3666 | |
Aviad Yehezkel | 802c212 | 2018-03-28 09:27:53 +0300 | [diff] [blame] | 3667 | if (is_egress) { |
| 3668 | dst->type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
| 3669 | } else { |
| 3670 | dst->type = MLX5_FLOW_DESTINATION_TYPE_TIR; |
| 3671 | if (mqp->flags & MLX5_IB_QP_RSS) |
| 3672 | dst->tir_num = mqp->rss_qp.tirn; |
| 3673 | else |
| 3674 | dst->tir_num = mqp->raw_packet_qp.rq.tirn; |
| 3675 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3676 | |
| 3677 | if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3678 | if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) { |
| 3679 | handler = create_dont_trap_rule(dev, ft_prio, |
| 3680 | flow_attr, dst); |
| 3681 | } else { |
Yishai Hadas | a550ddf | 2017-08-17 15:52:33 +0300 | [diff] [blame] | 3682 | underlay_qpn = (mqp->flags & MLX5_IB_QP_UNDERLAY) ? |
| 3683 | mqp->underlay_qpn : 0; |
| 3684 | handler = _create_flow_rule(dev, ft_prio, flow_attr, |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3685 | dst, underlay_qpn, ucmd); |
Maor Gottlieb | 35d19011 | 2016-03-07 18:51:47 +0200 | [diff] [blame] | 3686 | } |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3687 | } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
| 3688 | flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
| 3689 | handler = create_leftovers_rule(dev, ft_prio, flow_attr, |
| 3690 | dst); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3691 | } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
| 3692 | handler = create_sniffer_rule(dev, ft_prio, ft_prio_tx, dst); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3693 | } else { |
| 3694 | err = -EINVAL; |
| 3695 | goto destroy_ft; |
| 3696 | } |
| 3697 | |
| 3698 | if (IS_ERR(handler)) { |
| 3699 | err = PTR_ERR(handler); |
| 3700 | handler = NULL; |
| 3701 | goto destroy_ft; |
| 3702 | } |
| 3703 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3704 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3705 | kfree(dst); |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3706 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3707 | |
| 3708 | return &handler->ibflow; |
| 3709 | |
| 3710 | destroy_ft: |
| 3711 | put_flow_table(dev, ft_prio, false); |
Maor Gottlieb | cc0e5d4 | 2016-08-28 14:16:34 +0300 | [diff] [blame] | 3712 | if (ft_prio_tx) |
| 3713 | put_flow_table(dev, ft_prio_tx, false); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3714 | unlock: |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 3715 | mutex_unlock(&dev->flow_db->lock); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3716 | kfree(dst); |
Gustavo A. R. Silva | 299eafe | 2018-06-07 14:19:15 -0500 | [diff] [blame] | 3717 | free_ucmd: |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 3718 | kfree(ucmd); |
Maor Gottlieb | 038d2ef | 2016-01-11 10:26:07 +0200 | [diff] [blame] | 3719 | return ERR_PTR(err); |
| 3720 | } |
| 3721 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3722 | static struct mlx5_ib_flow_prio * |
| 3723 | _get_flow_table(struct mlx5_ib_dev *dev, |
| 3724 | struct mlx5_ib_flow_matcher *fs_matcher, |
| 3725 | bool mcast) |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3726 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3727 | struct mlx5_flow_namespace *ns = NULL; |
| 3728 | struct mlx5_ib_flow_prio *prio; |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3729 | int max_table_size; |
| 3730 | u32 flags = 0; |
| 3731 | int priority; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3732 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3733 | if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS) { |
| 3734 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3735 | log_max_ft_size)); |
| 3736 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, decap)) |
| 3737 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_DECAP; |
| 3738 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
| 3739 | reformat_l3_tunnel_to_l2)) |
| 3740 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
| 3741 | } else { /* Can only be MLX5_FLOW_NAMESPACE_EGRESS */ |
| 3742 | max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, |
| 3743 | log_max_ft_size)); |
| 3744 | if (MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, reformat)) |
| 3745 | flags |= MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; |
| 3746 | } |
| 3747 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3748 | if (max_table_size < MLX5_FS_MAX_ENTRIES) |
| 3749 | return ERR_PTR(-ENOMEM); |
| 3750 | |
| 3751 | if (mcast) |
| 3752 | priority = MLX5_IB_FLOW_MCAST_PRIO; |
| 3753 | else |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3754 | priority = ib_prio_to_core_prio(fs_matcher->priority, false); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3755 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3756 | ns = mlx5_get_flow_namespace(dev->mdev, fs_matcher->ns_type); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3757 | if (!ns) |
| 3758 | return ERR_PTR(-ENOTSUPP); |
| 3759 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3760 | if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS) |
| 3761 | prio = &dev->flow_db->prios[priority]; |
| 3762 | else |
| 3763 | prio = &dev->flow_db->egress_prios[priority]; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3764 | |
| 3765 | if (prio->flow_table) |
| 3766 | return prio; |
| 3767 | |
| 3768 | return _get_prio(ns, prio, priority, MLX5_FS_MAX_ENTRIES, |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3769 | MLX5_FS_MAX_TYPES, flags); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | static struct mlx5_ib_flow_handler * |
| 3773 | _create_raw_flow_rule(struct mlx5_ib_dev *dev, |
| 3774 | struct mlx5_ib_flow_prio *ft_prio, |
| 3775 | struct mlx5_flow_destination *dst, |
| 3776 | struct mlx5_ib_flow_matcher *fs_matcher, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3777 | struct mlx5_flow_act *flow_act, |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3778 | void *cmd_in, int inlen) |
| 3779 | { |
| 3780 | struct mlx5_ib_flow_handler *handler; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3781 | struct mlx5_flow_spec *spec; |
| 3782 | struct mlx5_flow_table *ft = ft_prio->flow_table; |
| 3783 | int err = 0; |
| 3784 | |
| 3785 | spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
| 3786 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
| 3787 | if (!handler || !spec) { |
| 3788 | err = -ENOMEM; |
| 3789 | goto free; |
| 3790 | } |
| 3791 | |
| 3792 | INIT_LIST_HEAD(&handler->list); |
| 3793 | |
| 3794 | memcpy(spec->match_value, cmd_in, inlen); |
| 3795 | memcpy(spec->match_criteria, fs_matcher->matcher_mask.match_params, |
| 3796 | fs_matcher->mask_len); |
| 3797 | spec->match_criteria_enable = fs_matcher->match_criteria_enable; |
| 3798 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3799 | handler->rule = mlx5_add_flow_rules(ft, spec, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3800 | flow_act, dst, 1); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3801 | |
| 3802 | if (IS_ERR(handler->rule)) { |
| 3803 | err = PTR_ERR(handler->rule); |
| 3804 | goto free; |
| 3805 | } |
| 3806 | |
| 3807 | ft_prio->refcount++; |
| 3808 | handler->prio = ft_prio; |
| 3809 | handler->dev = dev; |
| 3810 | ft_prio->flow_table = ft; |
| 3811 | |
| 3812 | free: |
| 3813 | if (err) |
| 3814 | kfree(handler); |
| 3815 | kvfree(spec); |
| 3816 | return err ? ERR_PTR(err) : handler; |
| 3817 | } |
| 3818 | |
| 3819 | static bool raw_fs_is_multicast(struct mlx5_ib_flow_matcher *fs_matcher, |
| 3820 | void *match_v) |
| 3821 | { |
| 3822 | void *match_c; |
| 3823 | void *match_v_set_lyr_2_4, *match_c_set_lyr_2_4; |
| 3824 | void *dmac, *dmac_mask; |
| 3825 | void *ipv4, *ipv4_mask; |
| 3826 | |
| 3827 | if (!(fs_matcher->match_criteria_enable & |
| 3828 | (1 << MATCH_CRITERIA_ENABLE_OUTER_BIT))) |
| 3829 | return false; |
| 3830 | |
| 3831 | match_c = fs_matcher->matcher_mask.match_params; |
| 3832 | match_v_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_v, |
| 3833 | outer_headers); |
| 3834 | match_c_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_c, |
| 3835 | outer_headers); |
| 3836 | |
| 3837 | dmac = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 3838 | dmac_47_16); |
| 3839 | dmac_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 3840 | dmac_47_16); |
| 3841 | |
| 3842 | if (is_multicast_ether_addr(dmac) && |
| 3843 | is_multicast_ether_addr(dmac_mask)) |
| 3844 | return true; |
| 3845 | |
| 3846 | ipv4 = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
| 3847 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 3848 | |
| 3849 | ipv4_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
| 3850 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
| 3851 | |
| 3852 | if (ipv4_is_multicast(*(__be32 *)(ipv4)) && |
| 3853 | ipv4_is_multicast(*(__be32 *)(ipv4_mask))) |
| 3854 | return true; |
| 3855 | |
| 3856 | return false; |
| 3857 | } |
| 3858 | |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3859 | struct mlx5_ib_flow_handler * |
| 3860 | mlx5_ib_raw_fs_rule_add(struct mlx5_ib_dev *dev, |
| 3861 | struct mlx5_ib_flow_matcher *fs_matcher, |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3862 | struct mlx5_flow_act *flow_act, |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3863 | void *cmd_in, int inlen, int dest_id, |
| 3864 | int dest_type) |
| 3865 | { |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3866 | struct mlx5_flow_destination *dst; |
| 3867 | struct mlx5_ib_flow_prio *ft_prio; |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3868 | struct mlx5_ib_flow_handler *handler; |
| 3869 | bool mcast; |
| 3870 | int err; |
| 3871 | |
| 3872 | if (fs_matcher->flow_type != MLX5_IB_FLOW_TYPE_NORMAL) |
| 3873 | return ERR_PTR(-EOPNOTSUPP); |
| 3874 | |
| 3875 | if (fs_matcher->priority > MLX5_IB_FLOW_LAST_PRIO) |
| 3876 | return ERR_PTR(-ENOMEM); |
| 3877 | |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3878 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
| 3879 | if (!dst) |
| 3880 | return ERR_PTR(-ENOMEM); |
| 3881 | |
| 3882 | mcast = raw_fs_is_multicast(fs_matcher, cmd_in); |
| 3883 | mutex_lock(&dev->flow_db->lock); |
| 3884 | |
Mark Bloch | b47fd4f | 2018-09-06 17:27:07 +0300 | [diff] [blame] | 3885 | ft_prio = _get_flow_table(dev, fs_matcher, mcast); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3886 | if (IS_ERR(ft_prio)) { |
| 3887 | err = PTR_ERR(ft_prio); |
| 3888 | goto unlock; |
| 3889 | } |
| 3890 | |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 3891 | if (dest_type == MLX5_FLOW_DESTINATION_TYPE_TIR) { |
| 3892 | dst->type = dest_type; |
| 3893 | dst->tir_num = dest_id; |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3894 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame^] | 3895 | } else if (dest_type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) { |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 3896 | dst->type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM; |
| 3897 | dst->ft_num = dest_id; |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3898 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
Mark Bloch | a7ee18b | 2018-09-06 17:27:08 +0300 | [diff] [blame^] | 3899 | } else { |
| 3900 | dst->type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
| 3901 | flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
Yishai Hadas | 6346f0b | 2018-07-23 15:25:11 +0300 | [diff] [blame] | 3902 | } |
| 3903 | |
Mark Bloch | b823dd6 | 2018-09-06 17:27:05 +0300 | [diff] [blame] | 3904 | handler = _create_raw_flow_rule(dev, ft_prio, dst, fs_matcher, flow_act, |
| 3905 | cmd_in, inlen); |
Yishai Hadas | d4be3f4 | 2018-07-23 15:25:10 +0300 | [diff] [blame] | 3906 | |
| 3907 | if (IS_ERR(handler)) { |
| 3908 | err = PTR_ERR(handler); |
| 3909 | goto destroy_ft; |
| 3910 | } |
| 3911 | |
| 3912 | mutex_unlock(&dev->flow_db->lock); |
| 3913 | atomic_inc(&fs_matcher->usecnt); |
| 3914 | handler->flow_matcher = fs_matcher; |
| 3915 | |
| 3916 | kfree(dst); |
| 3917 | |
| 3918 | return handler; |
| 3919 | |
| 3920 | destroy_ft: |
| 3921 | put_flow_table(dev, ft_prio, false); |
| 3922 | unlock: |
| 3923 | mutex_unlock(&dev->flow_db->lock); |
| 3924 | kfree(dst); |
| 3925 | |
| 3926 | return ERR_PTR(err); |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 3927 | } |
| 3928 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 3929 | static u32 mlx5_ib_flow_action_flags_to_accel_xfrm_flags(u32 mlx5_flags) |
| 3930 | { |
| 3931 | u32 flags = 0; |
| 3932 | |
| 3933 | if (mlx5_flags & MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA) |
| 3934 | flags |= MLX5_ACCEL_XFRM_FLAG_REQUIRE_METADATA; |
| 3935 | |
| 3936 | return flags; |
| 3937 | } |
| 3938 | |
| 3939 | #define MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA |
| 3940 | static struct ib_flow_action * |
| 3941 | mlx5_ib_create_flow_action_esp(struct ib_device *device, |
| 3942 | const struct ib_flow_action_attrs_esp *attr, |
| 3943 | struct uverbs_attr_bundle *attrs) |
| 3944 | { |
| 3945 | struct mlx5_ib_dev *mdev = to_mdev(device); |
| 3946 | struct ib_uverbs_flow_action_esp_keymat_aes_gcm *aes_gcm; |
| 3947 | struct mlx5_accel_esp_xfrm_attrs accel_attrs = {}; |
| 3948 | struct mlx5_ib_flow_action *action; |
| 3949 | u64 action_flags; |
| 3950 | u64 flags; |
| 3951 | int err = 0; |
| 3952 | |
Jason Gunthorpe | bccd062 | 2018-07-26 16:37:14 -0600 | [diff] [blame] | 3953 | err = uverbs_get_flags64( |
| 3954 | &action_flags, attrs, MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 3955 | ((MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED << 1) - 1)); |
| 3956 | if (err) |
| 3957 | return ERR_PTR(err); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 3958 | |
| 3959 | flags = mlx5_ib_flow_action_flags_to_accel_xfrm_flags(action_flags); |
| 3960 | |
| 3961 | /* We current only support a subset of the standard features. Only a |
| 3962 | * keymat of type AES_GCM, with icv_len == 16, iv_algo == SEQ and esn |
| 3963 | * (with overlap). Full offload mode isn't supported. |
| 3964 | */ |
| 3965 | if (!attr->keymat || attr->replay || attr->encap || |
| 3966 | attr->spi || attr->seq || attr->tfc_pad || |
| 3967 | attr->hard_limit_pkts || |
| 3968 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 3969 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT))) |
| 3970 | return ERR_PTR(-EOPNOTSUPP); |
| 3971 | |
| 3972 | if (attr->keymat->protocol != |
| 3973 | IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM) |
| 3974 | return ERR_PTR(-EOPNOTSUPP); |
| 3975 | |
| 3976 | aes_gcm = &attr->keymat->keymat.aes_gcm; |
| 3977 | |
| 3978 | if (aes_gcm->icv_len != 16 || |
| 3979 | aes_gcm->iv_algo != IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ) |
| 3980 | return ERR_PTR(-EOPNOTSUPP); |
| 3981 | |
| 3982 | action = kmalloc(sizeof(*action), GFP_KERNEL); |
| 3983 | if (!action) |
| 3984 | return ERR_PTR(-ENOMEM); |
| 3985 | |
| 3986 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 3987 | memcpy(&accel_attrs.keymat.aes_gcm.aes_key, &aes_gcm->aes_key, |
| 3988 | sizeof(accel_attrs.keymat.aes_gcm.aes_key)); |
| 3989 | accel_attrs.keymat.aes_gcm.key_len = aes_gcm->key_len * 8; |
| 3990 | memcpy(&accel_attrs.keymat.aes_gcm.salt, &aes_gcm->salt, |
| 3991 | sizeof(accel_attrs.keymat.aes_gcm.salt)); |
| 3992 | memcpy(&accel_attrs.keymat.aes_gcm.seq_iv, &aes_gcm->iv, |
| 3993 | sizeof(accel_attrs.keymat.aes_gcm.seq_iv)); |
| 3994 | accel_attrs.keymat.aes_gcm.icv_len = aes_gcm->icv_len * 8; |
| 3995 | accel_attrs.keymat.aes_gcm.iv_algo = MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ; |
| 3996 | accel_attrs.keymat_type = MLX5_ACCEL_ESP_KEYMAT_AES_GCM; |
| 3997 | |
| 3998 | accel_attrs.esn = attr->esn; |
| 3999 | if (attr->flags & IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) |
| 4000 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED; |
| 4001 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 4002 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4003 | |
| 4004 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT) |
| 4005 | accel_attrs.action |= MLX5_ACCEL_ESP_ACTION_ENCRYPT; |
| 4006 | |
| 4007 | action->esp_aes_gcm.ctx = |
| 4008 | mlx5_accel_esp_create_xfrm(mdev->mdev, &accel_attrs, flags); |
| 4009 | if (IS_ERR(action->esp_aes_gcm.ctx)) { |
| 4010 | err = PTR_ERR(action->esp_aes_gcm.ctx); |
| 4011 | goto err_parse; |
| 4012 | } |
| 4013 | |
| 4014 | action->esp_aes_gcm.ib_flags = attr->flags; |
| 4015 | |
| 4016 | return &action->ib_action; |
| 4017 | |
| 4018 | err_parse: |
| 4019 | kfree(action); |
| 4020 | return ERR_PTR(err); |
| 4021 | } |
| 4022 | |
Matan Barak | 349705c | 2018-03-28 09:27:51 +0300 | [diff] [blame] | 4023 | static int |
| 4024 | mlx5_ib_modify_flow_action_esp(struct ib_flow_action *action, |
| 4025 | const struct ib_flow_action_attrs_esp *attr, |
| 4026 | struct uverbs_attr_bundle *attrs) |
| 4027 | { |
| 4028 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 4029 | struct mlx5_accel_esp_xfrm_attrs accel_attrs; |
| 4030 | int err = 0; |
| 4031 | |
| 4032 | if (attr->keymat || attr->replay || attr->encap || |
| 4033 | attr->spi || attr->seq || attr->tfc_pad || |
| 4034 | attr->hard_limit_pkts || |
| 4035 | (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4036 | IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS | |
| 4037 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW))) |
| 4038 | return -EOPNOTSUPP; |
| 4039 | |
| 4040 | /* Only the ESN value or the MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP can |
| 4041 | * be modified. |
| 4042 | */ |
| 4043 | if (!(maction->esp_aes_gcm.ib_flags & |
| 4044 | IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) && |
| 4045 | attr->flags & (IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 4046 | IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW)) |
| 4047 | return -EINVAL; |
| 4048 | |
| 4049 | memcpy(&accel_attrs, &maction->esp_aes_gcm.ctx->attrs, |
| 4050 | sizeof(accel_attrs)); |
| 4051 | |
| 4052 | accel_attrs.esn = attr->esn; |
| 4053 | if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 4054 | accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4055 | else |
| 4056 | accel_attrs.flags &= ~MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 4057 | |
| 4058 | err = mlx5_accel_esp_modify_xfrm(maction->esp_aes_gcm.ctx, |
| 4059 | &accel_attrs); |
| 4060 | if (err) |
| 4061 | return err; |
| 4062 | |
| 4063 | maction->esp_aes_gcm.ib_flags &= |
| 4064 | ~IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 4065 | maction->esp_aes_gcm.ib_flags |= |
| 4066 | attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
| 4067 | |
| 4068 | return 0; |
| 4069 | } |
| 4070 | |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4071 | static int mlx5_ib_destroy_flow_action(struct ib_flow_action *action) |
| 4072 | { |
| 4073 | struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 4074 | |
| 4075 | switch (action->type) { |
| 4076 | case IB_FLOW_ACTION_ESP: |
| 4077 | /* |
| 4078 | * We only support aes_gcm by now, so we implicitly know this is |
| 4079 | * the underline crypto. |
| 4080 | */ |
| 4081 | mlx5_accel_esp_destroy_xfrm(maction->esp_aes_gcm.ctx); |
| 4082 | break; |
Mark Bloch | b4749bf | 2018-08-28 14:18:51 +0300 | [diff] [blame] | 4083 | case IB_FLOW_ACTION_UNSPECIFIED: |
| 4084 | mlx5_ib_destroy_flow_action_raw(maction); |
| 4085 | break; |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 4086 | default: |
| 4087 | WARN_ON(true); |
| 4088 | break; |
| 4089 | } |
| 4090 | |
| 4091 | kfree(maction); |
| 4092 | return 0; |
| 4093 | } |
| 4094 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4095 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4096 | { |
| 4097 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4098 | struct mlx5_ib_qp *mqp = to_mqp(ibqp); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4099 | int err; |
| 4100 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 4101 | if (mqp->flags & MLX5_IB_QP_UNDERLAY) { |
| 4102 | mlx5_ib_dbg(dev, "Attaching a multi cast group to underlay QP is not supported\n"); |
| 4103 | return -EOPNOTSUPP; |
| 4104 | } |
| 4105 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4106 | err = mlx5_core_attach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4107 | if (err) |
| 4108 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
| 4109 | ibqp->qp_num, gid->raw); |
| 4110 | |
| 4111 | return err; |
| 4112 | } |
| 4113 | |
| 4114 | static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 4115 | { |
| 4116 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 4117 | int err; |
| 4118 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4119 | err = mlx5_core_detach_mcg(dev->mdev, gid, ibqp->qp_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4120 | if (err) |
| 4121 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
| 4122 | ibqp->qp_num, gid->raw); |
| 4123 | |
| 4124 | return err; |
| 4125 | } |
| 4126 | |
| 4127 | static int init_node_data(struct mlx5_ib_dev *dev) |
| 4128 | { |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4129 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4130 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4131 | err = mlx5_query_node_desc(dev, dev->ib_dev.node_desc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4132 | if (err) |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4133 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4134 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4135 | dev->mdev->rev_id = dev->mdev->pdev->revision; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4136 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 4137 | return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4138 | } |
| 4139 | |
| 4140 | static ssize_t show_fw_pages(struct device *device, struct device_attribute *attr, |
| 4141 | char *buf) |
| 4142 | { |
| 4143 | struct mlx5_ib_dev *dev = |
| 4144 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 4145 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4146 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | static ssize_t show_reg_pages(struct device *device, |
| 4150 | struct device_attribute *attr, char *buf) |
| 4151 | { |
| 4152 | struct mlx5_ib_dev *dev = |
| 4153 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 4154 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 4155 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | static ssize_t show_hca(struct device *device, struct device_attribute *attr, |
| 4159 | char *buf) |
| 4160 | { |
| 4161 | struct mlx5_ib_dev *dev = |
| 4162 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4163 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4164 | } |
| 4165 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4166 | static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
| 4167 | char *buf) |
| 4168 | { |
| 4169 | struct mlx5_ib_dev *dev = |
| 4170 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4171 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | static ssize_t show_board(struct device *device, struct device_attribute *attr, |
| 4175 | char *buf) |
| 4176 | { |
| 4177 | struct mlx5_ib_dev *dev = |
| 4178 | container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
| 4179 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 4180 | dev->mdev->board_id); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4184 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 4185 | static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
| 4186 | static DEVICE_ATTR(fw_pages, S_IRUGO, show_fw_pages, NULL); |
| 4187 | static DEVICE_ATTR(reg_pages, S_IRUGO, show_reg_pages, NULL); |
| 4188 | |
| 4189 | static struct device_attribute *mlx5_class_attributes[] = { |
| 4190 | &dev_attr_hw_rev, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4191 | &dev_attr_hca_type, |
| 4192 | &dev_attr_board_id, |
| 4193 | &dev_attr_fw_pages, |
| 4194 | &dev_attr_reg_pages, |
| 4195 | }; |
| 4196 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4197 | static void pkey_change_handler(struct work_struct *work) |
| 4198 | { |
| 4199 | struct mlx5_ib_port_resources *ports = |
| 4200 | container_of(work, struct mlx5_ib_port_resources, |
| 4201 | pkey_change_work); |
| 4202 | |
| 4203 | mutex_lock(&ports->devr->mutex); |
| 4204 | mlx5_ib_gsi_pkey_change(ports->gsi); |
| 4205 | mutex_unlock(&ports->devr->mutex); |
| 4206 | } |
| 4207 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4208 | static void mlx5_ib_handle_internal_error(struct mlx5_ib_dev *ibdev) |
| 4209 | { |
| 4210 | struct mlx5_ib_qp *mqp; |
| 4211 | struct mlx5_ib_cq *send_mcq, *recv_mcq; |
| 4212 | struct mlx5_core_cq *mcq; |
| 4213 | struct list_head cq_armed_list; |
| 4214 | unsigned long flags_qp; |
| 4215 | unsigned long flags_cq; |
| 4216 | unsigned long flags; |
| 4217 | |
| 4218 | INIT_LIST_HEAD(&cq_armed_list); |
| 4219 | |
| 4220 | /* Go over qp list reside on that ibdev, sync with create/destroy qp.*/ |
| 4221 | spin_lock_irqsave(&ibdev->reset_flow_resource_lock, flags); |
| 4222 | list_for_each_entry(mqp, &ibdev->qp_list, qps_list) { |
| 4223 | spin_lock_irqsave(&mqp->sq.lock, flags_qp); |
| 4224 | if (mqp->sq.tail != mqp->sq.head) { |
| 4225 | send_mcq = to_mcq(mqp->ibqp.send_cq); |
| 4226 | spin_lock_irqsave(&send_mcq->lock, flags_cq); |
| 4227 | if (send_mcq->mcq.comp && |
| 4228 | mqp->ibqp.send_cq->comp_handler) { |
| 4229 | if (!send_mcq->mcq.reset_notify_added) { |
| 4230 | send_mcq->mcq.reset_notify_added = 1; |
| 4231 | list_add_tail(&send_mcq->mcq.reset_notify, |
| 4232 | &cq_armed_list); |
| 4233 | } |
| 4234 | } |
| 4235 | spin_unlock_irqrestore(&send_mcq->lock, flags_cq); |
| 4236 | } |
| 4237 | spin_unlock_irqrestore(&mqp->sq.lock, flags_qp); |
| 4238 | spin_lock_irqsave(&mqp->rq.lock, flags_qp); |
| 4239 | /* no handling is needed for SRQ */ |
| 4240 | if (!mqp->ibqp.srq) { |
| 4241 | if (mqp->rq.tail != mqp->rq.head) { |
| 4242 | recv_mcq = to_mcq(mqp->ibqp.recv_cq); |
| 4243 | spin_lock_irqsave(&recv_mcq->lock, flags_cq); |
| 4244 | if (recv_mcq->mcq.comp && |
| 4245 | mqp->ibqp.recv_cq->comp_handler) { |
| 4246 | if (!recv_mcq->mcq.reset_notify_added) { |
| 4247 | recv_mcq->mcq.reset_notify_added = 1; |
| 4248 | list_add_tail(&recv_mcq->mcq.reset_notify, |
| 4249 | &cq_armed_list); |
| 4250 | } |
| 4251 | } |
| 4252 | spin_unlock_irqrestore(&recv_mcq->lock, |
| 4253 | flags_cq); |
| 4254 | } |
| 4255 | } |
| 4256 | spin_unlock_irqrestore(&mqp->rq.lock, flags_qp); |
| 4257 | } |
| 4258 | /*At that point all inflight post send were put to be executed as of we |
| 4259 | * lock/unlock above locks Now need to arm all involved CQs. |
| 4260 | */ |
| 4261 | list_for_each_entry(mcq, &cq_armed_list, reset_notify) { |
| 4262 | mcq->comp(mcq); |
| 4263 | } |
| 4264 | spin_unlock_irqrestore(&ibdev->reset_flow_resource_lock, flags); |
| 4265 | } |
| 4266 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4267 | static void delay_drop_handler(struct work_struct *work) |
| 4268 | { |
| 4269 | int err; |
| 4270 | struct mlx5_ib_delay_drop *delay_drop = |
| 4271 | container_of(work, struct mlx5_ib_delay_drop, |
| 4272 | delay_drop_work); |
| 4273 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 4274 | atomic_inc(&delay_drop->events_cnt); |
| 4275 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4276 | mutex_lock(&delay_drop->lock); |
| 4277 | err = mlx5_core_set_delay_drop(delay_drop->dev->mdev, |
| 4278 | delay_drop->timeout); |
| 4279 | if (err) { |
| 4280 | mlx5_ib_warn(delay_drop->dev, "Failed to set delay drop, timeout=%u\n", |
| 4281 | delay_drop->timeout); |
| 4282 | delay_drop->activate = false; |
| 4283 | } |
| 4284 | mutex_unlock(&delay_drop->lock); |
| 4285 | } |
| 4286 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4287 | static void mlx5_ib_handle_event(struct work_struct *_work) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4288 | { |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4289 | struct mlx5_ib_event_work *work = |
| 4290 | container_of(_work, struct mlx5_ib_event_work, work); |
| 4291 | struct mlx5_ib_dev *ibdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4292 | struct ib_event ibev; |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4293 | bool fatal = false; |
Daniel Jurgens | aba4621 | 2018-02-25 13:39:53 +0200 | [diff] [blame] | 4294 | u8 port = (u8)work->param; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4295 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4296 | if (mlx5_core_is_mp_slave(work->dev)) { |
| 4297 | ibdev = mlx5_ib_get_ibdev_from_mpi(work->context); |
| 4298 | if (!ibdev) |
| 4299 | goto out; |
| 4300 | } else { |
| 4301 | ibdev = work->context; |
| 4302 | } |
| 4303 | |
| 4304 | switch (work->event) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4305 | case MLX5_DEV_EVENT_SYS_ERROR: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4306 | ibev.event = IB_EVENT_DEVICE_FATAL; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4307 | mlx5_ib_handle_internal_error(ibdev); |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4308 | fatal = true; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4309 | break; |
| 4310 | |
| 4311 | case MLX5_DEV_EVENT_PORT_UP: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4312 | case MLX5_DEV_EVENT_PORT_DOWN: |
Noa Osherovich | 2788cf3 | 2016-06-04 15:15:29 +0300 | [diff] [blame] | 4313 | case MLX5_DEV_EVENT_PORT_INITIALIZED: |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 4314 | /* In RoCE, port up/down events are handled in |
| 4315 | * mlx5_netdev_event(). |
| 4316 | */ |
| 4317 | if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
| 4318 | IB_LINK_LAYER_ETHERNET) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4319 | goto out; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 4320 | |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4321 | ibev.event = (work->event == MLX5_DEV_EVENT_PORT_UP) ? |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 4322 | IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4323 | break; |
| 4324 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4325 | case MLX5_DEV_EVENT_LID_CHANGE: |
| 4326 | ibev.event = IB_EVENT_LID_CHANGE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4327 | break; |
| 4328 | |
| 4329 | case MLX5_DEV_EVENT_PKEY_CHANGE: |
| 4330 | ibev.event = IB_EVENT_PKEY_CHANGE; |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4331 | schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4332 | break; |
| 4333 | |
| 4334 | case MLX5_DEV_EVENT_GUID_CHANGE: |
| 4335 | ibev.event = IB_EVENT_GID_CHANGE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4336 | break; |
| 4337 | |
| 4338 | case MLX5_DEV_EVENT_CLIENT_REREG: |
| 4339 | ibev.event = IB_EVENT_CLIENT_REREGISTER; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4340 | break; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4341 | case MLX5_DEV_EVENT_DELAY_DROP_TIMEOUT: |
| 4342 | schedule_work(&ibdev->delay_drop.delay_drop_work); |
| 4343 | goto out; |
Saeed Mahameed | bdc3792 | 2016-09-29 19:35:38 +0300 | [diff] [blame] | 4344 | default: |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4345 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | ibev.device = &ibdev->ib_dev; |
| 4349 | ibev.element.port_num = port; |
| 4350 | |
Daniel Jurgens | aba4621 | 2018-02-25 13:39:53 +0200 | [diff] [blame] | 4351 | if (!rdma_is_port_valid(&ibdev->ib_dev, port)) { |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 4352 | mlx5_ib_warn(ibdev, "warning: event on port %d\n", port); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4353 | goto out; |
Eli Cohen | a0c84c3 | 2013-09-11 16:35:27 +0300 | [diff] [blame] | 4354 | } |
| 4355 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4356 | if (ibdev->ib_active) |
| 4357 | ib_dispatch_event(&ibev); |
Eli Cohen | dbaaff2 | 2016-10-27 16:36:44 +0300 | [diff] [blame] | 4358 | |
| 4359 | if (fatal) |
| 4360 | ibdev->ib_active = false; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4361 | out: |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4362 | kfree(work); |
| 4363 | } |
| 4364 | |
| 4365 | static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context, |
| 4366 | enum mlx5_dev_event event, unsigned long param) |
| 4367 | { |
| 4368 | struct mlx5_ib_event_work *work; |
| 4369 | |
| 4370 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4371 | if (!work) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4372 | return; |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 4373 | |
Leon Romanovsky | 10bea9c | 2018-01-19 13:07:11 +0200 | [diff] [blame] | 4374 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
| 4375 | work->dev = dev; |
| 4376 | work->param = param; |
| 4377 | work->context = context; |
| 4378 | work->event = event; |
| 4379 | |
| 4380 | queue_work(mlx5_ib_event_wq, &work->work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4381 | } |
| 4382 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4383 | static int set_has_smi_cap(struct mlx5_ib_dev *dev) |
| 4384 | { |
| 4385 | struct mlx5_hca_vport_context vport_ctx; |
| 4386 | int err; |
| 4387 | int port; |
| 4388 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4389 | for (port = 1; port <= dev->num_ports; port++) { |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4390 | dev->mdev->port_caps[port - 1].has_smi = false; |
| 4391 | if (MLX5_CAP_GEN(dev->mdev, port_type) == |
| 4392 | MLX5_CAP_PORT_TYPE_IB) { |
| 4393 | if (MLX5_CAP_GEN(dev->mdev, ib_virt)) { |
| 4394 | err = mlx5_query_hca_vport_context(dev->mdev, 0, |
| 4395 | port, 0, |
| 4396 | &vport_ctx); |
| 4397 | if (err) { |
| 4398 | mlx5_ib_err(dev, "query_hca_vport_context for port=%d failed %d\n", |
| 4399 | port, err); |
| 4400 | return err; |
| 4401 | } |
| 4402 | dev->mdev->port_caps[port - 1].has_smi = |
| 4403 | vport_ctx.has_smi; |
| 4404 | } else { |
| 4405 | dev->mdev->port_caps[port - 1].has_smi = true; |
| 4406 | } |
| 4407 | } |
| 4408 | } |
| 4409 | return 0; |
| 4410 | } |
| 4411 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4412 | static void get_ext_port_caps(struct mlx5_ib_dev *dev) |
| 4413 | { |
| 4414 | int port; |
| 4415 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4416 | for (port = 1; port <= dev->num_ports; port++) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4417 | mlx5_query_ext_port_caps(dev, port); |
| 4418 | } |
| 4419 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4420 | static int get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4421 | { |
| 4422 | struct ib_device_attr *dprops = NULL; |
| 4423 | struct ib_port_attr *pprops = NULL; |
Dan Carpenter | f614fc1 | 2015-01-12 11:56:58 +0300 | [diff] [blame] | 4424 | int err = -ENOMEM; |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4425 | struct ib_udata uhw = {.inlen = 0, .outlen = 0}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4426 | |
| 4427 | pprops = kmalloc(sizeof(*pprops), GFP_KERNEL); |
| 4428 | if (!pprops) |
| 4429 | goto out; |
| 4430 | |
| 4431 | dprops = kmalloc(sizeof(*dprops), GFP_KERNEL); |
| 4432 | if (!dprops) |
| 4433 | goto out; |
| 4434 | |
Maor Gottlieb | c43f111 | 2017-01-18 14:10:33 +0200 | [diff] [blame] | 4435 | err = set_has_smi_cap(dev); |
| 4436 | if (err) |
| 4437 | goto out; |
| 4438 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 4439 | err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4440 | if (err) { |
| 4441 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
| 4442 | goto out; |
| 4443 | } |
| 4444 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4445 | memset(pprops, 0, sizeof(*pprops)); |
| 4446 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
| 4447 | if (err) { |
| 4448 | mlx5_ib_warn(dev, "query_port %d failed %d\n", |
| 4449 | port, err); |
| 4450 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4451 | } |
| 4452 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4453 | dev->mdev->port_caps[port - 1].pkey_table_len = |
| 4454 | dprops->max_pkeys; |
| 4455 | dev->mdev->port_caps[port - 1].gid_table_len = |
| 4456 | pprops->gid_tbl_len; |
| 4457 | mlx5_ib_dbg(dev, "port %d: pkey_table_len %d, gid_table_len %d\n", |
| 4458 | port, dprops->max_pkeys, pprops->gid_tbl_len); |
| 4459 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4460 | out: |
| 4461 | kfree(pprops); |
| 4462 | kfree(dprops); |
| 4463 | |
| 4464 | return err; |
| 4465 | } |
| 4466 | |
| 4467 | static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
| 4468 | { |
| 4469 | int err; |
| 4470 | |
| 4471 | err = mlx5_mr_cache_cleanup(dev); |
| 4472 | if (err) |
| 4473 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
| 4474 | |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4475 | if (dev->umrc.qp) |
| 4476 | mlx5_ib_destroy_qp(dev->umrc.qp); |
| 4477 | if (dev->umrc.cq) |
| 4478 | ib_free_cq(dev->umrc.cq); |
| 4479 | if (dev->umrc.pd) |
| 4480 | ib_dealloc_pd(dev->umrc.pd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | enum { |
| 4484 | MAX_UMR_WR = 128, |
| 4485 | }; |
| 4486 | |
| 4487 | static int create_umr_res(struct mlx5_ib_dev *dev) |
| 4488 | { |
| 4489 | struct ib_qp_init_attr *init_attr = NULL; |
| 4490 | struct ib_qp_attr *attr = NULL; |
| 4491 | struct ib_pd *pd; |
| 4492 | struct ib_cq *cq; |
| 4493 | struct ib_qp *qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4494 | int ret; |
| 4495 | |
| 4496 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| 4497 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 4498 | if (!attr || !init_attr) { |
| 4499 | ret = -ENOMEM; |
| 4500 | goto error_0; |
| 4501 | } |
| 4502 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 4503 | pd = ib_alloc_pd(&dev->ib_dev, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4504 | if (IS_ERR(pd)) { |
| 4505 | mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); |
| 4506 | ret = PTR_ERR(pd); |
| 4507 | goto error_0; |
| 4508 | } |
| 4509 | |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4510 | 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] | 4511 | if (IS_ERR(cq)) { |
| 4512 | mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); |
| 4513 | ret = PTR_ERR(cq); |
| 4514 | goto error_2; |
| 4515 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4516 | |
| 4517 | init_attr->send_cq = cq; |
| 4518 | init_attr->recv_cq = cq; |
| 4519 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
| 4520 | init_attr->cap.max_send_wr = MAX_UMR_WR; |
| 4521 | init_attr->cap.max_send_sge = 1; |
| 4522 | init_attr->qp_type = MLX5_IB_QPT_REG_UMR; |
| 4523 | init_attr->port_num = 1; |
| 4524 | qp = mlx5_ib_create_qp(pd, init_attr, NULL); |
| 4525 | if (IS_ERR(qp)) { |
| 4526 | mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); |
| 4527 | ret = PTR_ERR(qp); |
| 4528 | goto error_3; |
| 4529 | } |
| 4530 | qp->device = &dev->ib_dev; |
| 4531 | qp->real_qp = qp; |
| 4532 | qp->uobject = NULL; |
| 4533 | qp->qp_type = MLX5_IB_QPT_REG_UMR; |
Majd Dibbiny | 31fde03 | 2017-10-30 14:23:13 +0200 | [diff] [blame] | 4534 | qp->send_cq = init_attr->send_cq; |
| 4535 | qp->recv_cq = init_attr->recv_cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4536 | |
| 4537 | attr->qp_state = IB_QPS_INIT; |
| 4538 | attr->port_num = 1; |
| 4539 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX | |
| 4540 | IB_QP_PORT, NULL); |
| 4541 | if (ret) { |
| 4542 | mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); |
| 4543 | goto error_4; |
| 4544 | } |
| 4545 | |
| 4546 | memset(attr, 0, sizeof(*attr)); |
| 4547 | attr->qp_state = IB_QPS_RTR; |
| 4548 | attr->path_mtu = IB_MTU_256; |
| 4549 | |
| 4550 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4551 | if (ret) { |
| 4552 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); |
| 4553 | goto error_4; |
| 4554 | } |
| 4555 | |
| 4556 | memset(attr, 0, sizeof(*attr)); |
| 4557 | attr->qp_state = IB_QPS_RTS; |
| 4558 | ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL); |
| 4559 | if (ret) { |
| 4560 | mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); |
| 4561 | goto error_4; |
| 4562 | } |
| 4563 | |
| 4564 | dev->umrc.qp = qp; |
| 4565 | dev->umrc.cq = cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4566 | dev->umrc.pd = pd; |
| 4567 | |
| 4568 | sema_init(&dev->umrc.sem, MAX_UMR_WR); |
| 4569 | ret = mlx5_mr_cache_init(dev); |
| 4570 | if (ret) { |
| 4571 | mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); |
| 4572 | goto error_4; |
| 4573 | } |
| 4574 | |
| 4575 | kfree(attr); |
| 4576 | kfree(init_attr); |
| 4577 | |
| 4578 | return 0; |
| 4579 | |
| 4580 | error_4: |
| 4581 | mlx5_ib_destroy_qp(qp); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4582 | dev->umrc.qp = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4583 | |
| 4584 | error_3: |
Christoph Hellwig | add08d7 | 2016-03-03 09:38:22 +0100 | [diff] [blame] | 4585 | ib_free_cq(cq); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4586 | dev->umrc.cq = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4587 | |
| 4588 | error_2: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4589 | ib_dealloc_pd(pd); |
Mark Bloch | 32927e2 | 2018-03-20 15:45:37 +0200 | [diff] [blame] | 4590 | dev->umrc.pd = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4591 | |
| 4592 | error_0: |
| 4593 | kfree(attr); |
| 4594 | kfree(init_attr); |
| 4595 | return ret; |
| 4596 | } |
| 4597 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 4598 | static u8 mlx5_get_umr_fence(u8 umr_fence_cap) |
| 4599 | { |
| 4600 | switch (umr_fence_cap) { |
| 4601 | case MLX5_CAP_UMR_FENCE_NONE: |
| 4602 | return MLX5_FENCE_MODE_NONE; |
| 4603 | case MLX5_CAP_UMR_FENCE_SMALL: |
| 4604 | return MLX5_FENCE_MODE_INITIATOR_SMALL; |
| 4605 | default: |
| 4606 | return MLX5_FENCE_MODE_STRONG_ORDERING; |
| 4607 | } |
| 4608 | } |
| 4609 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4610 | static int create_dev_resources(struct mlx5_ib_resources *devr) |
| 4611 | { |
| 4612 | struct ib_srq_init_attr attr; |
| 4613 | struct mlx5_ib_dev *dev; |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 4614 | struct ib_cq_init_attr cq_attr = {.cqe = 1}; |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4615 | int port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4616 | int ret = 0; |
| 4617 | |
| 4618 | dev = container_of(devr, struct mlx5_ib_dev, devr); |
| 4619 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4620 | mutex_init(&devr->mutex); |
| 4621 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4622 | devr->p0 = mlx5_ib_alloc_pd(&dev->ib_dev, NULL, NULL); |
| 4623 | if (IS_ERR(devr->p0)) { |
| 4624 | ret = PTR_ERR(devr->p0); |
| 4625 | goto error0; |
| 4626 | } |
| 4627 | devr->p0->device = &dev->ib_dev; |
| 4628 | devr->p0->uobject = NULL; |
| 4629 | atomic_set(&devr->p0->usecnt, 0); |
| 4630 | |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 4631 | 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] | 4632 | if (IS_ERR(devr->c0)) { |
| 4633 | ret = PTR_ERR(devr->c0); |
| 4634 | goto error1; |
| 4635 | } |
| 4636 | devr->c0->device = &dev->ib_dev; |
| 4637 | devr->c0->uobject = NULL; |
| 4638 | devr->c0->comp_handler = NULL; |
| 4639 | devr->c0->event_handler = NULL; |
| 4640 | devr->c0->cq_context = NULL; |
| 4641 | atomic_set(&devr->c0->usecnt, 0); |
| 4642 | |
| 4643 | devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 4644 | if (IS_ERR(devr->x0)) { |
| 4645 | ret = PTR_ERR(devr->x0); |
| 4646 | goto error2; |
| 4647 | } |
| 4648 | devr->x0->device = &dev->ib_dev; |
| 4649 | devr->x0->inode = NULL; |
| 4650 | atomic_set(&devr->x0->usecnt, 0); |
| 4651 | mutex_init(&devr->x0->tgt_qp_mutex); |
| 4652 | INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
| 4653 | |
| 4654 | devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
| 4655 | if (IS_ERR(devr->x1)) { |
| 4656 | ret = PTR_ERR(devr->x1); |
| 4657 | goto error3; |
| 4658 | } |
| 4659 | devr->x1->device = &dev->ib_dev; |
| 4660 | devr->x1->inode = NULL; |
| 4661 | atomic_set(&devr->x1->usecnt, 0); |
| 4662 | mutex_init(&devr->x1->tgt_qp_mutex); |
| 4663 | INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
| 4664 | |
| 4665 | memset(&attr, 0, sizeof(attr)); |
| 4666 | attr.attr.max_sge = 1; |
| 4667 | attr.attr.max_wr = 1; |
| 4668 | attr.srq_type = IB_SRQT_XRC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4669 | attr.ext.cq = devr->c0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4670 | attr.ext.xrc.xrcd = devr->x0; |
| 4671 | |
| 4672 | devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 4673 | if (IS_ERR(devr->s0)) { |
| 4674 | ret = PTR_ERR(devr->s0); |
| 4675 | goto error4; |
| 4676 | } |
| 4677 | devr->s0->device = &dev->ib_dev; |
| 4678 | devr->s0->pd = devr->p0; |
| 4679 | devr->s0->uobject = NULL; |
| 4680 | devr->s0->event_handler = NULL; |
| 4681 | devr->s0->srq_context = NULL; |
| 4682 | devr->s0->srq_type = IB_SRQT_XRC; |
| 4683 | devr->s0->ext.xrc.xrcd = devr->x0; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4684 | devr->s0->ext.cq = devr->c0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4685 | atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4686 | atomic_inc(&devr->s0->ext.cq->usecnt); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4687 | atomic_inc(&devr->p0->usecnt); |
| 4688 | atomic_set(&devr->s0->usecnt, 0); |
| 4689 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4690 | memset(&attr, 0, sizeof(attr)); |
| 4691 | attr.attr.max_sge = 1; |
| 4692 | attr.attr.max_wr = 1; |
| 4693 | attr.srq_type = IB_SRQT_BASIC; |
| 4694 | devr->s1 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
| 4695 | if (IS_ERR(devr->s1)) { |
| 4696 | ret = PTR_ERR(devr->s1); |
| 4697 | goto error5; |
| 4698 | } |
| 4699 | devr->s1->device = &dev->ib_dev; |
| 4700 | devr->s1->pd = devr->p0; |
| 4701 | devr->s1->uobject = NULL; |
| 4702 | devr->s1->event_handler = NULL; |
| 4703 | devr->s1->srq_context = NULL; |
| 4704 | devr->s1->srq_type = IB_SRQT_BASIC; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4705 | devr->s1->ext.cq = devr->c0; |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4706 | atomic_inc(&devr->p0->usecnt); |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 4707 | atomic_set(&devr->s1->usecnt, 0); |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4708 | |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4709 | for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) { |
| 4710 | INIT_WORK(&devr->ports[port].pkey_change_work, |
| 4711 | pkey_change_handler); |
| 4712 | devr->ports[port].devr = devr; |
| 4713 | } |
| 4714 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4715 | return 0; |
| 4716 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4717 | error5: |
| 4718 | mlx5_ib_destroy_srq(devr->s0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4719 | error4: |
| 4720 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 4721 | error3: |
| 4722 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 4723 | error2: |
| 4724 | mlx5_ib_destroy_cq(devr->c0); |
| 4725 | error1: |
| 4726 | mlx5_ib_dealloc_pd(devr->p0); |
| 4727 | error0: |
| 4728 | return ret; |
| 4729 | } |
| 4730 | |
| 4731 | static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
| 4732 | { |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4733 | struct mlx5_ib_dev *dev = |
| 4734 | container_of(devr, struct mlx5_ib_dev, devr); |
| 4735 | int port; |
| 4736 | |
Haggai Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 4737 | mlx5_ib_destroy_srq(devr->s1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4738 | mlx5_ib_destroy_srq(devr->s0); |
| 4739 | mlx5_ib_dealloc_xrcd(devr->x0); |
| 4740 | mlx5_ib_dealloc_xrcd(devr->x1); |
| 4741 | mlx5_ib_destroy_cq(devr->c0); |
| 4742 | mlx5_ib_dealloc_pd(devr->p0); |
Haggai Eran | 7722f47 | 2016-02-29 15:45:07 +0200 | [diff] [blame] | 4743 | |
| 4744 | /* Make sure no change P_Key work items are still executing */ |
| 4745 | for (port = 0; port < dev->num_ports; ++port) |
| 4746 | cancel_work_sync(&devr->ports[port].pkey_change_work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4747 | } |
| 4748 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4749 | static u32 get_core_cap_flags(struct ib_device *ibdev, |
| 4750 | struct mlx5_hca_vport_context *rep) |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4751 | { |
| 4752 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 4753 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, 1); |
| 4754 | u8 l3_type_cap = MLX5_CAP_ROCE(dev->mdev, l3_type); |
| 4755 | u8 roce_version_cap = MLX5_CAP_ROCE(dev->mdev, roce_version); |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 4756 | bool raw_support = !mlx5_core_mp_enabled(dev->mdev); |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4757 | u32 ret = 0; |
| 4758 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4759 | if (rep->grh_required) |
| 4760 | ret |= RDMA_CORE_CAP_IB_GRH_REQUIRED; |
| 4761 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4762 | if (ll == IB_LINK_LAYER_INFINIBAND) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4763 | return ret | RDMA_CORE_PORT_IBA_IB; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4764 | |
Daniel Jurgens | 85c7c01 | 2018-01-04 17:25:43 +0200 | [diff] [blame] | 4765 | if (raw_support) |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4766 | ret |= RDMA_CORE_PORT_RAW_PACKET; |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4767 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4768 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV4_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4769 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4770 | |
| 4771 | if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV6_CAP)) |
Or Gerlitz | 72cd571 | 2017-01-24 13:02:36 +0200 | [diff] [blame] | 4772 | return ret; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4773 | |
| 4774 | if (roce_version_cap & MLX5_ROCE_VERSION_1_CAP) |
| 4775 | ret |= RDMA_CORE_PORT_IBA_ROCE; |
| 4776 | |
| 4777 | if (roce_version_cap & MLX5_ROCE_VERSION_2_CAP) |
| 4778 | ret |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; |
| 4779 | |
| 4780 | return ret; |
| 4781 | } |
| 4782 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4783 | static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 4784 | struct ib_port_immutable *immutable) |
| 4785 | { |
| 4786 | struct ib_port_attr attr; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4787 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 4788 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, port_num); |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4789 | struct mlx5_hca_vport_context rep = {0}; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4790 | int err; |
| 4791 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 4792 | err = ib_query_port(ibdev, port_num, &attr); |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4793 | if (err) |
| 4794 | return err; |
| 4795 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4796 | if (ll == IB_LINK_LAYER_INFINIBAND) { |
| 4797 | err = mlx5_query_hca_vport_context(dev->mdev, 0, port_num, 0, |
| 4798 | &rep); |
| 4799 | if (err) |
| 4800 | return err; |
| 4801 | } |
| 4802 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4803 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 4804 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 4805 | immutable->core_cap_flags = get_core_cap_flags(ibdev, &rep); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4806 | if ((ll == IB_LINK_LAYER_INFINIBAND) || MLX5_CAP_GEN(dev->mdev, roce)) |
| 4807 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 4808 | |
| 4809 | return 0; |
| 4810 | } |
| 4811 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 4812 | static int mlx5_port_rep_immutable(struct ib_device *ibdev, u8 port_num, |
| 4813 | struct ib_port_immutable *immutable) |
| 4814 | { |
| 4815 | struct ib_port_attr attr; |
| 4816 | int err; |
| 4817 | |
| 4818 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 4819 | |
| 4820 | err = ib_query_port(ibdev, port_num, &attr); |
| 4821 | if (err) |
| 4822 | return err; |
| 4823 | |
| 4824 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 4825 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 4826 | immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
| 4827 | |
| 4828 | return 0; |
| 4829 | } |
| 4830 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 4831 | static void get_dev_fw_str(struct ib_device *ibdev, char *str) |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 4832 | { |
| 4833 | struct mlx5_ib_dev *dev = |
| 4834 | container_of(ibdev, struct mlx5_ib_dev, ib_dev); |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 4835 | snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%04d", |
| 4836 | fw_rev_maj(dev->mdev), fw_rev_min(dev->mdev), |
| 4837 | fw_rev_sub(dev->mdev)); |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 4838 | } |
| 4839 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4840 | static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4841 | { |
| 4842 | struct mlx5_core_dev *mdev = dev->mdev; |
| 4843 | struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(mdev, |
| 4844 | MLX5_FLOW_NAMESPACE_LAG); |
| 4845 | struct mlx5_flow_table *ft; |
| 4846 | int err; |
| 4847 | |
| 4848 | if (!ns || !mlx5_lag_is_active(mdev)) |
| 4849 | return 0; |
| 4850 | |
| 4851 | err = mlx5_cmd_create_vport_lag(mdev); |
| 4852 | if (err) |
| 4853 | return err; |
| 4854 | |
| 4855 | ft = mlx5_create_lag_demux_flow_table(ns, 0, 0); |
| 4856 | if (IS_ERR(ft)) { |
| 4857 | err = PTR_ERR(ft); |
| 4858 | goto err_destroy_vport_lag; |
| 4859 | } |
| 4860 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 4861 | dev->flow_db->lag_demux_ft = ft; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4862 | return 0; |
| 4863 | |
| 4864 | err_destroy_vport_lag: |
| 4865 | mlx5_cmd_destroy_vport_lag(mdev); |
| 4866 | return err; |
| 4867 | } |
| 4868 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4869 | static void mlx5_eth_lag_cleanup(struct mlx5_ib_dev *dev) |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4870 | { |
| 4871 | struct mlx5_core_dev *mdev = dev->mdev; |
| 4872 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 4873 | if (dev->flow_db->lag_demux_ft) { |
| 4874 | mlx5_destroy_flow_table(dev->flow_db->lag_demux_ft); |
| 4875 | dev->flow_db->lag_demux_ft = NULL; |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4876 | |
| 4877 | mlx5_cmd_destroy_vport_lag(mdev); |
| 4878 | } |
| 4879 | } |
| 4880 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 4881 | 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] | 4882 | { |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4883 | int err; |
| 4884 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 4885 | dev->roce[port_num].nb.notifier_call = mlx5_netdev_event; |
| 4886 | err = register_netdevice_notifier(&dev->roce[port_num].nb); |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 4887 | if (err) { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 4888 | dev->roce[port_num].nb.notifier_call = NULL; |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4889 | return err; |
Aviv Heller | 5ec8c83 | 2016-09-18 20:48:00 +0300 | [diff] [blame] | 4890 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4891 | |
Or Gerlitz | d012f5d | 2016-11-27 16:51:34 +0200 | [diff] [blame] | 4892 | return 0; |
| 4893 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4894 | |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 4895 | 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] | 4896 | { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 4897 | if (dev->roce[port_num].nb.notifier_call) { |
| 4898 | unregister_netdevice_notifier(&dev->roce[port_num].nb); |
| 4899 | dev->roce[port_num].nb.notifier_call = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4900 | } |
| 4901 | } |
| 4902 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 4903 | static int mlx5_enable_eth(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4904 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4905 | int err; |
| 4906 | |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4907 | if (MLX5_CAP_GEN(dev->mdev, roce)) { |
| 4908 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 4909 | if (err) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 4910 | return err; |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4911 | } |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4912 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4913 | err = mlx5_eth_lag_init(dev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4914 | if (err) |
| 4915 | goto err_disable_roce; |
| 4916 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4917 | return 0; |
| 4918 | |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4919 | err_disable_roce: |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4920 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 4921 | mlx5_nic_vport_disable_roce(dev->mdev); |
Aviv Heller | 9ef9c64 | 2016-09-18 20:48:01 +0300 | [diff] [blame] | 4922 | |
Achiad Shochat | e53505a | 2015-12-23 18:47:25 +0200 | [diff] [blame] | 4923 | return err; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 4924 | } |
| 4925 | |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4926 | static void mlx5_disable_eth(struct mlx5_ib_dev *dev) |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 4927 | { |
Or Gerlitz | 45f95ac | 2016-11-27 16:51:35 +0200 | [diff] [blame] | 4928 | mlx5_eth_lag_cleanup(dev); |
Or Gerlitz | ca5b91d | 2016-11-27 16:51:36 +0200 | [diff] [blame] | 4929 | if (MLX5_CAP_GEN(dev->mdev, roce)) |
| 4930 | mlx5_nic_vport_disable_roce(dev->mdev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 4931 | } |
| 4932 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4933 | struct mlx5_ib_counter { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4934 | const char *name; |
| 4935 | size_t offset; |
| 4936 | }; |
| 4937 | |
| 4938 | #define INIT_Q_COUNTER(_name) \ |
| 4939 | { .name = #_name, .offset = MLX5_BYTE_OFF(query_q_counter_out, _name)} |
| 4940 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4941 | static const struct mlx5_ib_counter basic_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4942 | INIT_Q_COUNTER(rx_write_requests), |
| 4943 | INIT_Q_COUNTER(rx_read_requests), |
| 4944 | INIT_Q_COUNTER(rx_atomic_requests), |
| 4945 | INIT_Q_COUNTER(out_of_buffer), |
| 4946 | }; |
| 4947 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4948 | static const struct mlx5_ib_counter out_of_seq_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4949 | INIT_Q_COUNTER(out_of_sequence), |
| 4950 | }; |
| 4951 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4952 | static const struct mlx5_ib_counter retrans_q_cnts[] = { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4953 | INIT_Q_COUNTER(duplicate_request), |
| 4954 | INIT_Q_COUNTER(rnr_nak_retry_err), |
| 4955 | INIT_Q_COUNTER(packet_seq_err), |
| 4956 | INIT_Q_COUNTER(implied_nak_seq_err), |
| 4957 | INIT_Q_COUNTER(local_ack_timeout_err), |
| 4958 | }; |
| 4959 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4960 | #define INIT_CONG_COUNTER(_name) \ |
| 4961 | { .name = #_name, .offset = \ |
| 4962 | MLX5_BYTE_OFF(query_cong_statistics_out, _name ## _high)} |
| 4963 | |
| 4964 | static const struct mlx5_ib_counter cong_cnts[] = { |
| 4965 | INIT_CONG_COUNTER(rp_cnp_ignored), |
| 4966 | INIT_CONG_COUNTER(rp_cnp_handled), |
| 4967 | INIT_CONG_COUNTER(np_ecn_marked_roce_packets), |
| 4968 | INIT_CONG_COUNTER(np_cnp_sent), |
| 4969 | }; |
| 4970 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 4971 | static const struct mlx5_ib_counter extended_err_cnts[] = { |
| 4972 | INIT_Q_COUNTER(resp_local_length_error), |
| 4973 | INIT_Q_COUNTER(resp_cqe_error), |
| 4974 | INIT_Q_COUNTER(req_cqe_error), |
| 4975 | INIT_Q_COUNTER(req_remote_invalid_request), |
| 4976 | INIT_Q_COUNTER(req_remote_access_errors), |
| 4977 | INIT_Q_COUNTER(resp_remote_access_errors), |
| 4978 | INIT_Q_COUNTER(resp_cqe_flush_error), |
| 4979 | INIT_Q_COUNTER(req_cqe_flush_error), |
| 4980 | }; |
| 4981 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 4982 | #define INIT_EXT_PPCNT_COUNTER(_name) \ |
| 4983 | { .name = #_name, .offset = \ |
| 4984 | MLX5_BYTE_OFF(ppcnt_reg, \ |
| 4985 | counter_set.eth_extended_cntrs_grp_data_layout._name##_high)} |
| 4986 | |
| 4987 | static const struct mlx5_ib_counter ext_ppcnt_cnts[] = { |
| 4988 | INIT_EXT_PPCNT_COUNTER(rx_icrc_encapsulated), |
| 4989 | }; |
| 4990 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4991 | static void mlx5_ib_dealloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 4992 | { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 4993 | int i; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 4994 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 4995 | for (i = 0; i < dev->num_ports; i++) { |
Parav Pandit | 921c0f5 | 2018-07-08 13:40:30 +0300 | [diff] [blame] | 4996 | if (dev->port[i].cnts.set_id_valid) |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 4997 | mlx5_core_dealloc_q_counter(dev->mdev, |
| 4998 | dev->port[i].cnts.set_id); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 4999 | kfree(dev->port[i].cnts.names); |
| 5000 | kfree(dev->port[i].cnts.offsets); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5001 | } |
| 5002 | } |
| 5003 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5004 | static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, |
| 5005 | struct mlx5_ib_counters *cnts) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5006 | { |
| 5007 | u32 num_counters; |
| 5008 | |
| 5009 | num_counters = ARRAY_SIZE(basic_q_cnts); |
| 5010 | |
| 5011 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) |
| 5012 | num_counters += ARRAY_SIZE(out_of_seq_q_cnts); |
| 5013 | |
| 5014 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) |
| 5015 | num_counters += ARRAY_SIZE(retrans_q_cnts); |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5016 | |
| 5017 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) |
| 5018 | num_counters += ARRAY_SIZE(extended_err_cnts); |
| 5019 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5020 | cnts->num_q_counters = num_counters; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5021 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5022 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 5023 | cnts->num_cong_counters = ARRAY_SIZE(cong_cnts); |
| 5024 | num_counters += ARRAY_SIZE(cong_cnts); |
| 5025 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5026 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5027 | cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts); |
| 5028 | num_counters += ARRAY_SIZE(ext_ppcnt_cnts); |
| 5029 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5030 | cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL); |
| 5031 | if (!cnts->names) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5032 | return -ENOMEM; |
| 5033 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5034 | cnts->offsets = kcalloc(num_counters, |
| 5035 | sizeof(cnts->offsets), GFP_KERNEL); |
| 5036 | if (!cnts->offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5037 | goto err_names; |
| 5038 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5039 | return 0; |
| 5040 | |
| 5041 | err_names: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5042 | kfree(cnts->names); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5043 | cnts->names = NULL; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5044 | return -ENOMEM; |
| 5045 | } |
| 5046 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5047 | static void mlx5_ib_fill_counters(struct mlx5_ib_dev *dev, |
| 5048 | const char **names, |
| 5049 | size_t *offsets) |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5050 | { |
| 5051 | int i; |
| 5052 | int j = 0; |
| 5053 | |
| 5054 | for (i = 0; i < ARRAY_SIZE(basic_q_cnts); i++, j++) { |
| 5055 | names[j] = basic_q_cnts[i].name; |
| 5056 | offsets[j] = basic_q_cnts[i].offset; |
| 5057 | } |
| 5058 | |
| 5059 | if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) { |
| 5060 | for (i = 0; i < ARRAY_SIZE(out_of_seq_q_cnts); i++, j++) { |
| 5061 | names[j] = out_of_seq_q_cnts[i].name; |
| 5062 | offsets[j] = out_of_seq_q_cnts[i].offset; |
| 5063 | } |
| 5064 | } |
| 5065 | |
| 5066 | if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) { |
| 5067 | for (i = 0; i < ARRAY_SIZE(retrans_q_cnts); i++, j++) { |
| 5068 | names[j] = retrans_q_cnts[i].name; |
| 5069 | offsets[j] = retrans_q_cnts[i].offset; |
| 5070 | } |
| 5071 | } |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5072 | |
Parav Pandit | 58dcb60 | 2017-06-19 07:19:37 +0300 | [diff] [blame] | 5073 | if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) { |
| 5074 | for (i = 0; i < ARRAY_SIZE(extended_err_cnts); i++, j++) { |
| 5075 | names[j] = extended_err_cnts[i].name; |
| 5076 | offsets[j] = extended_err_cnts[i].offset; |
| 5077 | } |
| 5078 | } |
| 5079 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5080 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
| 5081 | for (i = 0; i < ARRAY_SIZE(cong_cnts); i++, j++) { |
| 5082 | names[j] = cong_cnts[i].name; |
| 5083 | offsets[j] = cong_cnts[i].offset; |
| 5084 | } |
| 5085 | } |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5086 | |
| 5087 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5088 | for (i = 0; i < ARRAY_SIZE(ext_ppcnt_cnts); i++, j++) { |
| 5089 | names[j] = ext_ppcnt_cnts[i].name; |
| 5090 | offsets[j] = ext_ppcnt_cnts[i].offset; |
| 5091 | } |
| 5092 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5093 | } |
| 5094 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5095 | static int mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5096 | { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5097 | int err = 0; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5098 | int i; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5099 | |
| 5100 | for (i = 0; i < dev->num_ports; i++) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5101 | err = __mlx5_ib_alloc_counters(dev, &dev->port[i].cnts); |
| 5102 | if (err) |
| 5103 | goto err_alloc; |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5104 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5105 | mlx5_ib_fill_counters(dev, dev->port[i].cnts.names, |
| 5106 | dev->port[i].cnts.offsets); |
| 5107 | |
| 5108 | err = mlx5_core_alloc_q_counter(dev->mdev, |
| 5109 | &dev->port[i].cnts.set_id); |
| 5110 | if (err) { |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5111 | mlx5_ib_warn(dev, |
| 5112 | "couldn't allocate queue counter for port %d, err %d\n", |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5113 | i + 1, err); |
| 5114 | goto err_alloc; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5115 | } |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5116 | dev->port[i].cnts.set_id_valid = true; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5117 | } |
| 5118 | |
| 5119 | return 0; |
| 5120 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5121 | err_alloc: |
| 5122 | mlx5_ib_dealloc_counters(dev); |
| 5123 | return err; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5124 | } |
| 5125 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5126 | static struct rdma_hw_stats *mlx5_ib_alloc_hw_stats(struct ib_device *ibdev, |
| 5127 | u8 port_num) |
| 5128 | { |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5129 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5130 | struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5131 | |
| 5132 | /* We support only per port stats */ |
| 5133 | if (port_num == 0) |
| 5134 | return NULL; |
| 5135 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5136 | return rdma_alloc_hw_stats_struct(port->cnts.names, |
| 5137 | port->cnts.num_q_counters + |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5138 | port->cnts.num_cong_counters + |
| 5139 | port->cnts.num_ext_ppcnt_counters, |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5140 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 5141 | } |
| 5142 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5143 | static int mlx5_ib_query_q_counters(struct mlx5_core_dev *mdev, |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5144 | struct mlx5_ib_port *port, |
| 5145 | struct rdma_hw_stats *stats) |
| 5146 | { |
| 5147 | int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); |
| 5148 | void *out; |
| 5149 | __be32 val; |
| 5150 | int ret, i; |
| 5151 | |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5152 | out = kvzalloc(outlen, GFP_KERNEL); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5153 | if (!out) |
| 5154 | return -ENOMEM; |
| 5155 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5156 | ret = mlx5_core_query_q_counter(mdev, |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5157 | port->cnts.set_id, 0, |
| 5158 | out, outlen); |
| 5159 | if (ret) |
| 5160 | goto free; |
| 5161 | |
| 5162 | for (i = 0; i < port->cnts.num_q_counters; i++) { |
| 5163 | val = *(__be32 *)(out + port->cnts.offsets[i]); |
| 5164 | stats->value[i] = (u64)be32_to_cpu(val); |
| 5165 | } |
| 5166 | |
| 5167 | free: |
| 5168 | kvfree(out); |
| 5169 | return ret; |
| 5170 | } |
| 5171 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5172 | static int mlx5_ib_query_ext_ppcnt_counters(struct mlx5_ib_dev *dev, |
| 5173 | struct mlx5_ib_port *port, |
| 5174 | struct rdma_hw_stats *stats) |
| 5175 | { |
| 5176 | int offset = port->cnts.num_q_counters + port->cnts.num_cong_counters; |
| 5177 | int sz = MLX5_ST_SZ_BYTES(ppcnt_reg); |
| 5178 | int ret, i; |
| 5179 | void *out; |
| 5180 | |
| 5181 | out = kvzalloc(sz, GFP_KERNEL); |
| 5182 | if (!out) |
| 5183 | return -ENOMEM; |
| 5184 | |
| 5185 | ret = mlx5_cmd_query_ext_ppcnt_counters(dev->mdev, out); |
| 5186 | if (ret) |
| 5187 | goto free; |
| 5188 | |
| 5189 | for (i = 0; i < port->cnts.num_ext_ppcnt_counters; i++) { |
| 5190 | stats->value[i + offset] = |
| 5191 | be64_to_cpup((__be64 *)(out + |
| 5192 | port->cnts.offsets[i + offset])); |
| 5193 | } |
| 5194 | |
| 5195 | free: |
| 5196 | kvfree(out); |
| 5197 | return ret; |
| 5198 | } |
| 5199 | |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5200 | static int mlx5_ib_get_hw_stats(struct ib_device *ibdev, |
| 5201 | struct rdma_hw_stats *stats, |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5202 | u8 port_num, int index) |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5203 | { |
| 5204 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5205 | struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5206 | struct mlx5_core_dev *mdev; |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5207 | int ret, num_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5208 | u8 mdev_port_num; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5209 | |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5210 | if (!stats) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5211 | return -EINVAL; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5212 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5213 | num_counters = port->cnts.num_q_counters + |
| 5214 | port->cnts.num_cong_counters + |
| 5215 | port->cnts.num_ext_ppcnt_counters; |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5216 | |
| 5217 | /* q_counters are per IB device, query the master mdev */ |
| 5218 | ret = mlx5_ib_query_q_counters(dev->mdev, port, stats); |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5219 | if (ret) |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5220 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5221 | |
Talat Batheesh | 9f876f3 | 2018-06-21 15:37:56 +0300 | [diff] [blame] | 5222 | if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
| 5223 | ret = mlx5_ib_query_ext_ppcnt_counters(dev, port, stats); |
| 5224 | if (ret) |
| 5225 | return ret; |
| 5226 | } |
| 5227 | |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5228 | if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5229 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, |
| 5230 | &mdev_port_num); |
| 5231 | if (!mdev) { |
| 5232 | /* If port is not affiliated yet, its in down state |
| 5233 | * which doesn't have any counters yet, so it would be |
| 5234 | * zero. So no need to read from the HCA. |
| 5235 | */ |
| 5236 | goto done; |
| 5237 | } |
Majd Dibbiny | 71a0ff6 | 2017-12-21 17:38:26 +0200 | [diff] [blame] | 5238 | ret = mlx5_lag_query_cong_counters(dev->mdev, |
| 5239 | stats->value + |
| 5240 | port->cnts.num_q_counters, |
| 5241 | port->cnts.num_cong_counters, |
| 5242 | port->cnts.offsets + |
| 5243 | port->cnts.num_q_counters); |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5244 | |
| 5245 | mlx5_ib_put_native_port_mdev(dev, port_num); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5246 | if (ret) |
| 5247 | return ret; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5248 | } |
Kamal Heib | 7c16f47 | 2017-01-18 15:25:09 +0200 | [diff] [blame] | 5249 | |
Daniel Jurgens | aac4492 | 2018-01-04 17:25:40 +0200 | [diff] [blame] | 5250 | done: |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 5251 | return num_counters; |
Mark Bloch | 0ad17a8 | 2016-06-17 15:10:56 +0300 | [diff] [blame] | 5252 | } |
| 5253 | |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5254 | static struct net_device* |
| 5255 | mlx5_ib_alloc_rdma_netdev(struct ib_device *hca, |
| 5256 | u8 port_num, |
| 5257 | enum rdma_netdev_t type, |
| 5258 | const char *name, |
| 5259 | unsigned char name_assign_type, |
| 5260 | void (*setup)(struct net_device *)) |
| 5261 | { |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5262 | struct net_device *netdev; |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5263 | |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5264 | if (type != RDMA_NETDEV_IPOIB) |
| 5265 | return ERR_PTR(-EOPNOTSUPP); |
| 5266 | |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5267 | netdev = mlx5_rdma_netdev_alloc(to_mdev(hca)->mdev, hca, |
| 5268 | name, setup); |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5269 | return netdev; |
Erez Shitrit | 693dfd5 | 2017-04-27 17:01:34 +0300 | [diff] [blame] | 5270 | } |
| 5271 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5272 | static void delay_drop_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 5273 | { |
| 5274 | if (!dev->delay_drop.dbg) |
| 5275 | return; |
| 5276 | debugfs_remove_recursive(dev->delay_drop.dbg->dir_debugfs); |
| 5277 | kfree(dev->delay_drop.dbg); |
| 5278 | dev->delay_drop.dbg = NULL; |
| 5279 | } |
| 5280 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5281 | static void cancel_delay_drop(struct mlx5_ib_dev *dev) |
| 5282 | { |
| 5283 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5284 | return; |
| 5285 | |
| 5286 | cancel_work_sync(&dev->delay_drop.delay_drop_work); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5287 | delay_drop_debugfs_cleanup(dev); |
| 5288 | } |
| 5289 | |
| 5290 | static ssize_t delay_drop_timeout_read(struct file *filp, char __user *buf, |
| 5291 | size_t count, loff_t *pos) |
| 5292 | { |
| 5293 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5294 | char lbuf[20]; |
| 5295 | int len; |
| 5296 | |
| 5297 | len = snprintf(lbuf, sizeof(lbuf), "%u\n", delay_drop->timeout); |
| 5298 | return simple_read_from_buffer(buf, count, pos, lbuf, len); |
| 5299 | } |
| 5300 | |
| 5301 | static ssize_t delay_drop_timeout_write(struct file *filp, const char __user *buf, |
| 5302 | size_t count, loff_t *pos) |
| 5303 | { |
| 5304 | struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
| 5305 | u32 timeout; |
| 5306 | u32 var; |
| 5307 | |
| 5308 | if (kstrtouint_from_user(buf, count, 0, &var)) |
| 5309 | return -EFAULT; |
| 5310 | |
| 5311 | timeout = min_t(u32, roundup(var, 100), MLX5_MAX_DELAY_DROP_TIMEOUT_MS * |
| 5312 | 1000); |
| 5313 | if (timeout != var) |
| 5314 | mlx5_ib_dbg(delay_drop->dev, "Round delay drop timeout to %u usec\n", |
| 5315 | timeout); |
| 5316 | |
| 5317 | delay_drop->timeout = timeout; |
| 5318 | |
| 5319 | return count; |
| 5320 | } |
| 5321 | |
| 5322 | static const struct file_operations fops_delay_drop_timeout = { |
| 5323 | .owner = THIS_MODULE, |
| 5324 | .open = simple_open, |
| 5325 | .write = delay_drop_timeout_write, |
| 5326 | .read = delay_drop_timeout_read, |
| 5327 | }; |
| 5328 | |
| 5329 | static int delay_drop_debugfs_init(struct mlx5_ib_dev *dev) |
| 5330 | { |
| 5331 | struct mlx5_ib_dbg_delay_drop *dbg; |
| 5332 | |
| 5333 | if (!mlx5_debugfs_root) |
| 5334 | return 0; |
| 5335 | |
| 5336 | dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); |
| 5337 | if (!dbg) |
| 5338 | return -ENOMEM; |
| 5339 | |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5340 | dev->delay_drop.dbg = dbg; |
| 5341 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5342 | dbg->dir_debugfs = |
| 5343 | debugfs_create_dir("delay_drop", |
| 5344 | dev->mdev->priv.dbg_root); |
| 5345 | if (!dbg->dir_debugfs) |
Sudip Mukherjee | cbafad8 | 2017-09-18 12:28:48 +0100 | [diff] [blame] | 5346 | goto out_debugfs; |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5347 | |
| 5348 | dbg->events_cnt_debugfs = |
| 5349 | debugfs_create_atomic_t("num_timeout_events", 0400, |
| 5350 | dbg->dir_debugfs, |
| 5351 | &dev->delay_drop.events_cnt); |
| 5352 | if (!dbg->events_cnt_debugfs) |
| 5353 | goto out_debugfs; |
| 5354 | |
| 5355 | dbg->rqs_cnt_debugfs = |
| 5356 | debugfs_create_atomic_t("num_rqs", 0400, |
| 5357 | dbg->dir_debugfs, |
| 5358 | &dev->delay_drop.rqs_cnt); |
| 5359 | if (!dbg->rqs_cnt_debugfs) |
| 5360 | goto out_debugfs; |
| 5361 | |
| 5362 | dbg->timeout_debugfs = |
| 5363 | debugfs_create_file("timeout", 0600, |
| 5364 | dbg->dir_debugfs, |
| 5365 | &dev->delay_drop, |
| 5366 | &fops_delay_drop_timeout); |
| 5367 | if (!dbg->timeout_debugfs) |
| 5368 | goto out_debugfs; |
| 5369 | |
| 5370 | return 0; |
| 5371 | |
| 5372 | out_debugfs: |
| 5373 | delay_drop_debugfs_cleanup(dev); |
| 5374 | return -ENOMEM; |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5375 | } |
| 5376 | |
| 5377 | static void init_delay_drop(struct mlx5_ib_dev *dev) |
| 5378 | { |
| 5379 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
| 5380 | return; |
| 5381 | |
| 5382 | mutex_init(&dev->delay_drop.lock); |
| 5383 | dev->delay_drop.dev = dev; |
| 5384 | dev->delay_drop.activate = false; |
| 5385 | dev->delay_drop.timeout = MLX5_MAX_DELAY_DROP_TIMEOUT_MS * 1000; |
| 5386 | INIT_WORK(&dev->delay_drop.delay_drop_work, delay_drop_handler); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5387 | atomic_set(&dev->delay_drop.rqs_cnt, 0); |
| 5388 | atomic_set(&dev->delay_drop.events_cnt, 0); |
| 5389 | |
| 5390 | if (delay_drop_debugfs_init(dev)) |
| 5391 | mlx5_ib_warn(dev, "Failed to init delay drop debugfs\n"); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5392 | } |
| 5393 | |
Leon Romanovsky | 84305d71 | 2017-08-17 15:50:53 +0300 | [diff] [blame] | 5394 | static const struct cpumask * |
| 5395 | mlx5_ib_get_vector_affinity(struct ib_device *ibdev, int comp_vector) |
Sagi Grimberg | 40b2440 | 2017-07-13 11:09:42 +0300 | [diff] [blame] | 5396 | { |
| 5397 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5398 | |
Israel Rukshin | 6082d9c | 2018-04-12 09:49:11 +0000 | [diff] [blame] | 5399 | return mlx5_get_vector_affinity_hint(dev->mdev, comp_vector); |
Sagi Grimberg | 40b2440 | 2017-07-13 11:09:42 +0300 | [diff] [blame] | 5400 | } |
| 5401 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5402 | /* The mlx5_ib_multiport_mutex should be held when calling this function */ |
| 5403 | static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5404 | struct mlx5_ib_multiport_info *mpi) |
| 5405 | { |
| 5406 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5407 | struct mlx5_ib_port *port = &ibdev->port[port_num]; |
| 5408 | int comps; |
| 5409 | int err; |
| 5410 | int i; |
| 5411 | |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5412 | mlx5_ib_cleanup_cong_debugfs(ibdev, port_num); |
| 5413 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5414 | spin_lock(&port->mp.mpi_lock); |
| 5415 | if (!mpi->ibdev) { |
| 5416 | spin_unlock(&port->mp.mpi_lock); |
| 5417 | return; |
| 5418 | } |
| 5419 | mpi->ibdev = NULL; |
| 5420 | |
| 5421 | spin_unlock(&port->mp.mpi_lock); |
| 5422 | mlx5_remove_netdev_notifier(ibdev, port_num); |
| 5423 | spin_lock(&port->mp.mpi_lock); |
| 5424 | |
| 5425 | comps = mpi->mdev_refcnt; |
| 5426 | if (comps) { |
| 5427 | mpi->unaffiliate = true; |
| 5428 | init_completion(&mpi->unref_comp); |
| 5429 | spin_unlock(&port->mp.mpi_lock); |
| 5430 | |
| 5431 | for (i = 0; i < comps; i++) |
| 5432 | wait_for_completion(&mpi->unref_comp); |
| 5433 | |
| 5434 | spin_lock(&port->mp.mpi_lock); |
| 5435 | mpi->unaffiliate = false; |
| 5436 | } |
| 5437 | |
| 5438 | port->mp.mpi = NULL; |
| 5439 | |
| 5440 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 5441 | |
| 5442 | spin_unlock(&port->mp.mpi_lock); |
| 5443 | |
| 5444 | err = mlx5_nic_vport_unaffiliate_multiport(mpi->mdev); |
| 5445 | |
| 5446 | mlx5_ib_dbg(ibdev, "unaffiliated port %d\n", port_num + 1); |
| 5447 | /* Log an error, still needed to cleanup the pointers and add |
| 5448 | * it back to the list. |
| 5449 | */ |
| 5450 | if (err) |
| 5451 | mlx5_ib_err(ibdev, "Failed to unaffiliate port %u\n", |
| 5452 | port_num + 1); |
| 5453 | |
| 5454 | ibdev->roce[port_num].last_port_state = IB_PORT_DOWN; |
| 5455 | } |
| 5456 | |
| 5457 | /* The mlx5_ib_multiport_mutex should be held when calling this function */ |
| 5458 | static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev, |
| 5459 | struct mlx5_ib_multiport_info *mpi) |
| 5460 | { |
| 5461 | u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
| 5462 | int err; |
| 5463 | |
| 5464 | spin_lock(&ibdev->port[port_num].mp.mpi_lock); |
| 5465 | if (ibdev->port[port_num].mp.mpi) { |
Qing Huang | 2577188 | 2018-07-23 14:15:08 -0700 | [diff] [blame] | 5466 | mlx5_ib_dbg(ibdev, "port %d already affiliated.\n", |
| 5467 | port_num + 1); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5468 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5469 | return false; |
| 5470 | } |
| 5471 | |
| 5472 | ibdev->port[port_num].mp.mpi = mpi; |
| 5473 | mpi->ibdev = ibdev; |
| 5474 | spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
| 5475 | |
| 5476 | err = mlx5_nic_vport_affiliate_multiport(ibdev->mdev, mpi->mdev); |
| 5477 | if (err) |
| 5478 | goto unbind; |
| 5479 | |
| 5480 | err = get_port_caps(ibdev, mlx5_core_native_port_num(mpi->mdev)); |
| 5481 | if (err) |
| 5482 | goto unbind; |
| 5483 | |
| 5484 | err = mlx5_add_netdev_notifier(ibdev, port_num); |
| 5485 | if (err) { |
| 5486 | mlx5_ib_err(ibdev, "failed adding netdev notifier for port %u\n", |
| 5487 | port_num + 1); |
| 5488 | goto unbind; |
| 5489 | } |
| 5490 | |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 5491 | err = mlx5_ib_init_cong_debugfs(ibdev, port_num); |
| 5492 | if (err) |
| 5493 | goto unbind; |
| 5494 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5495 | return true; |
| 5496 | |
| 5497 | unbind: |
| 5498 | mlx5_ib_unbind_slave_port(ibdev, mpi); |
| 5499 | return false; |
| 5500 | } |
| 5501 | |
| 5502 | static int mlx5_ib_init_multiport_master(struct mlx5_ib_dev *dev) |
| 5503 | { |
| 5504 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5505 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5506 | port_num + 1); |
| 5507 | struct mlx5_ib_multiport_info *mpi; |
| 5508 | int err; |
| 5509 | int i; |
| 5510 | |
| 5511 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5512 | return 0; |
| 5513 | |
| 5514 | err = mlx5_query_nic_vport_system_image_guid(dev->mdev, |
| 5515 | &dev->sys_image_guid); |
| 5516 | if (err) |
| 5517 | return err; |
| 5518 | |
| 5519 | err = mlx5_nic_vport_enable_roce(dev->mdev); |
| 5520 | if (err) |
| 5521 | return err; |
| 5522 | |
| 5523 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5524 | for (i = 0; i < dev->num_ports; i++) { |
| 5525 | bool bound = false; |
| 5526 | |
| 5527 | /* build a stub multiport info struct for the native port. */ |
| 5528 | if (i == port_num) { |
| 5529 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 5530 | if (!mpi) { |
| 5531 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5532 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5533 | return -ENOMEM; |
| 5534 | } |
| 5535 | |
| 5536 | mpi->is_master = true; |
| 5537 | mpi->mdev = dev->mdev; |
| 5538 | mpi->sys_image_guid = dev->sys_image_guid; |
| 5539 | dev->port[i].mp.mpi = mpi; |
| 5540 | mpi->ibdev = dev; |
| 5541 | mpi = NULL; |
| 5542 | continue; |
| 5543 | } |
| 5544 | |
| 5545 | list_for_each_entry(mpi, &mlx5_ib_unaffiliated_port_list, |
| 5546 | list) { |
| 5547 | if (dev->sys_image_guid == mpi->sys_image_guid && |
| 5548 | (mlx5_core_native_port_num(mpi->mdev) - 1) == i) { |
| 5549 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 5550 | } |
| 5551 | |
| 5552 | if (bound) { |
| 5553 | dev_dbg(&mpi->mdev->pdev->dev, "removing port from unaffiliated list.\n"); |
| 5554 | mlx5_ib_dbg(dev, "port %d bound\n", i + 1); |
| 5555 | list_del(&mpi->list); |
| 5556 | break; |
| 5557 | } |
| 5558 | } |
| 5559 | if (!bound) { |
| 5560 | get_port_caps(dev, i + 1); |
| 5561 | mlx5_ib_dbg(dev, "no free port found for port %d\n", |
| 5562 | i + 1); |
| 5563 | } |
| 5564 | } |
| 5565 | |
| 5566 | list_add_tail(&dev->ib_dev_list, &mlx5_ib_dev_list); |
| 5567 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5568 | return err; |
| 5569 | } |
| 5570 | |
| 5571 | static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev) |
| 5572 | { |
| 5573 | int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 5574 | enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
| 5575 | port_num + 1); |
| 5576 | int i; |
| 5577 | |
| 5578 | if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
| 5579 | return; |
| 5580 | |
| 5581 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 5582 | for (i = 0; i < dev->num_ports; i++) { |
| 5583 | if (dev->port[i].mp.mpi) { |
| 5584 | /* Destroy the native port stub */ |
| 5585 | if (i == port_num) { |
| 5586 | kfree(dev->port[i].mp.mpi); |
| 5587 | dev->port[i].mp.mpi = NULL; |
| 5588 | } else { |
| 5589 | mlx5_ib_dbg(dev, "unbinding port_num: %d\n", i + 1); |
| 5590 | mlx5_ib_unbind_slave_port(dev, dev->port[i].mp.mpi); |
| 5591 | } |
| 5592 | } |
| 5593 | } |
| 5594 | |
| 5595 | mlx5_ib_dbg(dev, "removing from devlist\n"); |
| 5596 | list_del(&dev->ib_dev_list); |
| 5597 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 5598 | |
| 5599 | mlx5_nic_vport_disable_roce(dev->mdev); |
| 5600 | } |
| 5601 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5602 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 5603 | mlx5_ib_dm, |
| 5604 | UVERBS_OBJECT_DM, |
| 5605 | UVERBS_METHOD_DM_ALLOC, |
| 5606 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
| 5607 | UVERBS_ATTR_TYPE(u64), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5608 | UA_MANDATORY), |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5609 | UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
| 5610 | UVERBS_ATTR_TYPE(u16), |
Jason Gunthorpe | 83bb444 | 2018-07-04 08:50:29 +0300 | [diff] [blame] | 5611 | UA_MANDATORY)); |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5612 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 5613 | ADD_UVERBS_ATTRIBUTES_SIMPLE( |
| 5614 | mlx5_ib_flow_action, |
| 5615 | UVERBS_OBJECT_FLOW_ACTION, |
| 5616 | UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, |
Jason Gunthorpe | bccd062 | 2018-07-26 16:37:14 -0600 | [diff] [blame] | 5617 | UVERBS_ATTR_FLAGS_IN(MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 5618 | enum mlx5_ib_uapi_flow_action_flags)); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 5619 | |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5620 | static int populate_specs_root(struct mlx5_ib_dev *dev) |
| 5621 | { |
Jason Gunthorpe | 7d96c9b | 2018-08-09 20:14:35 -0600 | [diff] [blame] | 5622 | const struct uverbs_object_tree_def **trees = dev->driver_trees; |
| 5623 | size_t num_trees = 0; |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5624 | |
Jason Gunthorpe | 7d96c9b | 2018-08-09 20:14:35 -0600 | [diff] [blame] | 5625 | if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
| 5626 | MLX5_ACCEL_IPSEC_CAP_DEVICE) |
| 5627 | trees[num_trees++] = &mlx5_ib_flow_action; |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 5628 | |
Jason Gunthorpe | 7d96c9b | 2018-08-09 20:14:35 -0600 | [diff] [blame] | 5629 | if (MLX5_CAP_DEV_MEM(dev->mdev, memic)) |
| 5630 | trees[num_trees++] = &mlx5_ib_dm; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5631 | |
Yishai Hadas | c59450c | 2018-06-17 13:00:06 +0300 | [diff] [blame] | 5632 | if (MLX5_CAP_GEN_64(dev->mdev, general_obj_types) & |
Jason Gunthorpe | 7d96c9b | 2018-08-09 20:14:35 -0600 | [diff] [blame] | 5633 | MLX5_GENERAL_OBJ_TYPES_CAP_UCTX) |
| 5634 | trees[num_trees++] = mlx5_ib_get_devx_tree(); |
Yishai Hadas | c59450c | 2018-06-17 13:00:06 +0300 | [diff] [blame] | 5635 | |
Jason Gunthorpe | 7d96c9b | 2018-08-09 20:14:35 -0600 | [diff] [blame] | 5636 | num_trees += mlx5_ib_get_flow_trees(trees + num_trees); |
Yishai Hadas | cb80fb1 | 2018-07-23 15:25:12 +0300 | [diff] [blame] | 5637 | |
Jason Gunthorpe | 7d96c9b | 2018-08-09 20:14:35 -0600 | [diff] [blame] | 5638 | WARN_ON(num_trees >= ARRAY_SIZE(dev->driver_trees)); |
| 5639 | trees[num_trees] = NULL; |
| 5640 | dev->ib_dev.driver_specs = trees; |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5641 | |
Jason Gunthorpe | 7d96c9b | 2018-08-09 20:14:35 -0600 | [diff] [blame] | 5642 | return 0; |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 5643 | } |
| 5644 | |
Raed Salem | 1a1e03d | 2018-05-31 16:43:41 +0300 | [diff] [blame] | 5645 | static int mlx5_ib_read_counters(struct ib_counters *counters, |
| 5646 | struct ib_counters_read_attr *read_attr, |
| 5647 | struct uverbs_attr_bundle *attrs) |
| 5648 | { |
| 5649 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 5650 | struct mlx5_read_counters_attr mread_attr = {}; |
| 5651 | struct mlx5_ib_flow_counters_desc *desc; |
| 5652 | int ret, i; |
| 5653 | |
| 5654 | mutex_lock(&mcounters->mcntrs_mutex); |
| 5655 | if (mcounters->cntrs_max_index > read_attr->ncounters) { |
| 5656 | ret = -EINVAL; |
| 5657 | goto err_bound; |
| 5658 | } |
| 5659 | |
| 5660 | mread_attr.out = kcalloc(mcounters->counters_num, sizeof(u64), |
| 5661 | GFP_KERNEL); |
| 5662 | if (!mread_attr.out) { |
| 5663 | ret = -ENOMEM; |
| 5664 | goto err_bound; |
| 5665 | } |
| 5666 | |
| 5667 | mread_attr.hw_cntrs_hndl = mcounters->hw_cntrs_hndl; |
| 5668 | mread_attr.flags = read_attr->flags; |
| 5669 | ret = mcounters->read_counters(counters->device, &mread_attr); |
| 5670 | if (ret) |
| 5671 | goto err_read; |
| 5672 | |
| 5673 | /* do the pass over the counters data array to assign according to the |
| 5674 | * descriptions and indexing pairs |
| 5675 | */ |
| 5676 | desc = mcounters->counters_data; |
| 5677 | for (i = 0; i < mcounters->ncounters; i++) |
| 5678 | read_attr->counters_buff[desc[i].index] += mread_attr.out[desc[i].description]; |
| 5679 | |
| 5680 | err_read: |
| 5681 | kfree(mread_attr.out); |
| 5682 | err_bound: |
| 5683 | mutex_unlock(&mcounters->mcntrs_mutex); |
| 5684 | return ret; |
| 5685 | } |
| 5686 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5687 | static int mlx5_ib_destroy_counters(struct ib_counters *counters) |
| 5688 | { |
| 5689 | struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
| 5690 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 5691 | counters_clear_description(counters); |
| 5692 | if (mcounters->hw_cntrs_hndl) |
| 5693 | mlx5_fc_destroy(to_mdev(counters->device)->mdev, |
| 5694 | mcounters->hw_cntrs_hndl); |
| 5695 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5696 | kfree(mcounters); |
| 5697 | |
| 5698 | return 0; |
| 5699 | } |
| 5700 | |
| 5701 | static struct ib_counters *mlx5_ib_create_counters(struct ib_device *device, |
| 5702 | struct uverbs_attr_bundle *attrs) |
| 5703 | { |
| 5704 | struct mlx5_ib_mcounters *mcounters; |
| 5705 | |
| 5706 | mcounters = kzalloc(sizeof(*mcounters), GFP_KERNEL); |
| 5707 | if (!mcounters) |
| 5708 | return ERR_PTR(-ENOMEM); |
| 5709 | |
Raed Salem | 3b3233f | 2018-05-31 16:43:39 +0300 | [diff] [blame] | 5710 | mutex_init(&mcounters->mcntrs_mutex); |
| 5711 | |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5712 | return &mcounters->ibcntrs; |
| 5713 | } |
| 5714 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5715 | void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5716 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5717 | mlx5_ib_cleanup_multiport_master(dev); |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5718 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 5719 | cleanup_srcu_struct(&dev->mr_srcu); |
| 5720 | #endif |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5721 | kfree(dev->port); |
| 5722 | } |
| 5723 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5724 | int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5725 | { |
| 5726 | struct mlx5_core_dev *mdev = dev->mdev; |
Aviv Heller | 4babcf9 | 2016-09-18 20:48:03 +0300 | [diff] [blame] | 5727 | const char *name; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5728 | int err; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5729 | int i; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5730 | |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 5731 | dev->port = kcalloc(dev->num_ports, sizeof(*dev->port), |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5732 | GFP_KERNEL); |
| 5733 | if (!dev->port) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5734 | return -ENOMEM; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5735 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5736 | for (i = 0; i < dev->num_ports; i++) { |
| 5737 | spin_lock_init(&dev->port[i].mp.mpi_lock); |
| 5738 | rwlock_init(&dev->roce[i].netdev_lock); |
| 5739 | } |
| 5740 | |
| 5741 | err = mlx5_ib_init_multiport_master(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5742 | if (err) |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 5743 | goto err_free_port; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5744 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5745 | if (!mlx5_core_mp_enabled(mdev)) { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5746 | for (i = 1; i <= dev->num_ports; i++) { |
| 5747 | err = get_port_caps(dev, i); |
| 5748 | if (err) |
| 5749 | break; |
| 5750 | } |
| 5751 | } else { |
| 5752 | err = get_port_caps(dev, mlx5_core_native_port_num(mdev)); |
| 5753 | } |
| 5754 | if (err) |
| 5755 | goto err_mp; |
| 5756 | |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 5757 | if (mlx5_use_mad_ifc(dev)) |
| 5758 | get_ext_port_caps(dev); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5759 | |
Aviv Heller | 4babcf9 | 2016-09-18 20:48:03 +0300 | [diff] [blame] | 5760 | if (!mlx5_lag_is_active(mdev)) |
| 5761 | name = "mlx5_%d"; |
| 5762 | else |
| 5763 | name = "mlx5_bond_%d"; |
| 5764 | |
| 5765 | strlcpy(dev->ib_dev.name, name, IB_DEVICE_NAME_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5766 | dev->ib_dev.owner = THIS_MODULE; |
| 5767 | dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
Sagi Grimberg | c6790aa | 2015-09-24 10:34:23 +0300 | [diff] [blame] | 5768 | dev->ib_dev.local_dma_lkey = 0 /* not supported for now */; |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 5769 | dev->ib_dev.phys_port_cnt = dev->num_ports; |
Saeed Mahameed | 233d05d | 2015-04-02 17:07:32 +0300 | [diff] [blame] | 5770 | dev->ib_dev.num_comp_vectors = |
| 5771 | dev->mdev->priv.eq_table.num_comp_vectors; |
Bart Van Assche | 9b0c289 | 2017-01-20 13:04:21 -0800 | [diff] [blame] | 5772 | dev->ib_dev.dev.parent = &mdev->pdev->dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5773 | |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5774 | mutex_init(&dev->cap_mask_mutex); |
| 5775 | INIT_LIST_HEAD(&dev->qp_list); |
| 5776 | spin_lock_init(&dev->reset_flow_resource_lock); |
| 5777 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5778 | spin_lock_init(&dev->memic.memic_lock); |
| 5779 | dev->memic.dev = mdev; |
| 5780 | |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 5781 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 5782 | err = init_srcu_struct(&dev->mr_srcu); |
| 5783 | if (err) |
| 5784 | goto err_free_port; |
| 5785 | #endif |
| 5786 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5787 | return 0; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 5788 | err_mp: |
| 5789 | mlx5_ib_cleanup_multiport_master(dev); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5790 | |
| 5791 | err_free_port: |
| 5792 | kfree(dev->port); |
| 5793 | |
| 5794 | return -ENOMEM; |
| 5795 | } |
| 5796 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5797 | static int mlx5_ib_stage_flow_db_init(struct mlx5_ib_dev *dev) |
| 5798 | { |
| 5799 | dev->flow_db = kzalloc(sizeof(*dev->flow_db), GFP_KERNEL); |
| 5800 | |
| 5801 | if (!dev->flow_db) |
| 5802 | return -ENOMEM; |
| 5803 | |
| 5804 | mutex_init(&dev->flow_db->lock); |
| 5805 | |
| 5806 | return 0; |
| 5807 | } |
| 5808 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5809 | int mlx5_ib_stage_rep_flow_db_init(struct mlx5_ib_dev *dev) |
| 5810 | { |
| 5811 | struct mlx5_ib_dev *nic_dev; |
| 5812 | |
| 5813 | nic_dev = mlx5_ib_get_uplink_ibdev(dev->mdev->priv.eswitch); |
| 5814 | |
| 5815 | if (!nic_dev) |
| 5816 | return -EINVAL; |
| 5817 | |
| 5818 | dev->flow_db = nic_dev->flow_db; |
| 5819 | |
| 5820 | return 0; |
| 5821 | } |
| 5822 | |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 5823 | static void mlx5_ib_stage_flow_db_cleanup(struct mlx5_ib_dev *dev) |
| 5824 | { |
| 5825 | kfree(dev->flow_db); |
| 5826 | } |
| 5827 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5828 | int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5829 | { |
| 5830 | struct mlx5_core_dev *mdev = dev->mdev; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5831 | int err; |
| 5832 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5833 | dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
| 5834 | dev->ib_dev.uverbs_cmd_mask = |
| 5835 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 5836 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 5837 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 5838 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 5839 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
Moni Shoua | 41c450f | 2016-11-23 08:23:26 +0200 | [diff] [blame] | 5840 | (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
| 5841 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5842 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 5843 | (1ull << IB_USER_VERBS_CMD_REREG_MR) | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5844 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 5845 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 5846 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 5847 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 5848 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 5849 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 5850 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 5851 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 5852 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 5853 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 5854 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 5855 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 5856 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 5857 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 5858 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 5859 | (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
| 5860 | (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
Haggai Eran | 1707cb4 | 2015-02-08 13:28:52 +0200 | [diff] [blame] | 5861 | dev->ib_dev.uverbs_ex_cmd_mask = |
Matan Barak | d4584dd | 2016-01-28 17:51:46 +0200 | [diff] [blame] | 5862 | (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE) | |
| 5863 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 5864 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) | |
Yonatan Cohen | b0e9df6 | 2017-11-13 10:51:15 +0200 | [diff] [blame] | 5865 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_QP) | |
| 5866 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_CQ); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5867 | |
| 5868 | dev->ib_dev.query_device = mlx5_ib_query_device; |
Achiad Shochat | ebd61f6 | 2015-12-23 18:47:16 +0200 | [diff] [blame] | 5869 | dev->ib_dev.get_link_layer = mlx5_ib_port_link_layer; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5870 | dev->ib_dev.query_gid = mlx5_ib_query_gid; |
Achiad Shochat | 3cca260 | 2015-12-23 18:47:23 +0200 | [diff] [blame] | 5871 | dev->ib_dev.add_gid = mlx5_ib_add_gid; |
| 5872 | dev->ib_dev.del_gid = mlx5_ib_del_gid; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5873 | dev->ib_dev.query_pkey = mlx5_ib_query_pkey; |
| 5874 | dev->ib_dev.modify_device = mlx5_ib_modify_device; |
| 5875 | dev->ib_dev.modify_port = mlx5_ib_modify_port; |
| 5876 | dev->ib_dev.alloc_ucontext = mlx5_ib_alloc_ucontext; |
| 5877 | dev->ib_dev.dealloc_ucontext = mlx5_ib_dealloc_ucontext; |
| 5878 | dev->ib_dev.mmap = mlx5_ib_mmap; |
| 5879 | dev->ib_dev.alloc_pd = mlx5_ib_alloc_pd; |
| 5880 | dev->ib_dev.dealloc_pd = mlx5_ib_dealloc_pd; |
| 5881 | dev->ib_dev.create_ah = mlx5_ib_create_ah; |
| 5882 | dev->ib_dev.query_ah = mlx5_ib_query_ah; |
| 5883 | dev->ib_dev.destroy_ah = mlx5_ib_destroy_ah; |
| 5884 | dev->ib_dev.create_srq = mlx5_ib_create_srq; |
| 5885 | dev->ib_dev.modify_srq = mlx5_ib_modify_srq; |
| 5886 | dev->ib_dev.query_srq = mlx5_ib_query_srq; |
| 5887 | dev->ib_dev.destroy_srq = mlx5_ib_destroy_srq; |
| 5888 | dev->ib_dev.post_srq_recv = mlx5_ib_post_srq_recv; |
| 5889 | dev->ib_dev.create_qp = mlx5_ib_create_qp; |
| 5890 | dev->ib_dev.modify_qp = mlx5_ib_modify_qp; |
| 5891 | dev->ib_dev.query_qp = mlx5_ib_query_qp; |
| 5892 | dev->ib_dev.destroy_qp = mlx5_ib_destroy_qp; |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5893 | dev->ib_dev.drain_sq = mlx5_ib_drain_sq; |
| 5894 | dev->ib_dev.drain_rq = mlx5_ib_drain_rq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5895 | dev->ib_dev.post_send = mlx5_ib_post_send; |
| 5896 | dev->ib_dev.post_recv = mlx5_ib_post_recv; |
| 5897 | dev->ib_dev.create_cq = mlx5_ib_create_cq; |
| 5898 | dev->ib_dev.modify_cq = mlx5_ib_modify_cq; |
| 5899 | dev->ib_dev.resize_cq = mlx5_ib_resize_cq; |
| 5900 | dev->ib_dev.destroy_cq = mlx5_ib_destroy_cq; |
| 5901 | dev->ib_dev.poll_cq = mlx5_ib_poll_cq; |
| 5902 | dev->ib_dev.req_notify_cq = mlx5_ib_arm_cq; |
| 5903 | dev->ib_dev.get_dma_mr = mlx5_ib_get_dma_mr; |
| 5904 | dev->ib_dev.reg_user_mr = mlx5_ib_reg_user_mr; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 5905 | dev->ib_dev.rereg_user_mr = mlx5_ib_rereg_user_mr; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5906 | dev->ib_dev.dereg_mr = mlx5_ib_dereg_mr; |
| 5907 | dev->ib_dev.attach_mcast = mlx5_ib_mcg_attach; |
| 5908 | dev->ib_dev.detach_mcast = mlx5_ib_mcg_detach; |
| 5909 | dev->ib_dev.process_mad = mlx5_ib_process_mad; |
Sagi Grimberg | 9bee178 | 2015-07-30 10:32:35 +0300 | [diff] [blame] | 5910 | dev->ib_dev.alloc_mr = mlx5_ib_alloc_mr; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 5911 | dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg; |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 5912 | dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status; |
Ira Weiny | c734282 | 2016-06-15 02:22:01 -0400 | [diff] [blame] | 5913 | dev->ib_dev.get_dev_fw_str = get_dev_fw_str; |
Sagi Grimberg | 40b2440 | 2017-07-13 11:09:42 +0300 | [diff] [blame] | 5914 | dev->ib_dev.get_vector_affinity = mlx5_ib_get_vector_affinity; |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5915 | if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads)) |
Alex Vesker | 022d038 | 2017-06-14 09:59:06 +0300 | [diff] [blame] | 5916 | dev->ib_dev.alloc_rdma_netdev = mlx5_ib_alloc_rdma_netdev; |
Niranjana Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 5917 | |
Eli Cohen | eff901d | 2016-03-11 22:58:42 +0200 | [diff] [blame] | 5918 | if (mlx5_core_is_pf(mdev)) { |
| 5919 | dev->ib_dev.get_vf_config = mlx5_ib_get_vf_config; |
| 5920 | dev->ib_dev.set_vf_link_state = mlx5_ib_set_vf_link_state; |
| 5921 | dev->ib_dev.get_vf_stats = mlx5_ib_get_vf_stats; |
| 5922 | dev->ib_dev.set_vf_guid = mlx5_ib_set_vf_guid; |
| 5923 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5924 | |
Maor Gottlieb | 7c2344c | 2016-06-17 14:56:44 +0300 | [diff] [blame] | 5925 | dev->ib_dev.disassociate_ucontext = mlx5_ib_disassociate_ucontext; |
| 5926 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 5927 | dev->umr_fence = mlx5_get_umr_fence(MLX5_CAP_GEN(mdev, umr_fence)); |
| 5928 | |
Matan Barak | d2370e0 | 2016-02-29 18:05:30 +0200 | [diff] [blame] | 5929 | if (MLX5_CAP_GEN(mdev, imaicl)) { |
| 5930 | dev->ib_dev.alloc_mw = mlx5_ib_alloc_mw; |
| 5931 | dev->ib_dev.dealloc_mw = mlx5_ib_dealloc_mw; |
| 5932 | dev->ib_dev.uverbs_cmd_mask |= |
| 5933 | (1ull << IB_USER_VERBS_CMD_ALLOC_MW) | |
| 5934 | (1ull << IB_USER_VERBS_CMD_DEALLOC_MW); |
| 5935 | } |
| 5936 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 5937 | if (MLX5_CAP_GEN(mdev, xrc)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5938 | dev->ib_dev.alloc_xrcd = mlx5_ib_alloc_xrcd; |
| 5939 | dev->ib_dev.dealloc_xrcd = mlx5_ib_dealloc_xrcd; |
| 5940 | dev->ib_dev.uverbs_cmd_mask |= |
| 5941 | (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
| 5942 | (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
| 5943 | } |
| 5944 | |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5945 | if (MLX5_CAP_DEV_MEM(mdev, memic)) { |
| 5946 | dev->ib_dev.alloc_dm = mlx5_ib_alloc_dm; |
| 5947 | dev->ib_dev.dealloc_dm = mlx5_ib_dealloc_dm; |
Ariel Levkovich | 6c29f57 | 2018-04-05 18:53:29 +0300 | [diff] [blame] | 5948 | dev->ib_dev.reg_dm_mr = mlx5_ib_reg_dm_mr; |
Ariel Levkovich | 24da001 | 2018-04-05 18:53:27 +0300 | [diff] [blame] | 5949 | } |
| 5950 | |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 5951 | dev->ib_dev.create_flow = mlx5_ib_create_flow; |
| 5952 | dev->ib_dev.destroy_flow = mlx5_ib_destroy_flow; |
| 5953 | dev->ib_dev.uverbs_ex_cmd_mask |= |
| 5954 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) | |
| 5955 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW); |
Aviad Yehezkel | c6475a0 | 2018-03-28 09:27:50 +0300 | [diff] [blame] | 5956 | dev->ib_dev.create_flow_action_esp = mlx5_ib_create_flow_action_esp; |
| 5957 | dev->ib_dev.destroy_flow_action = mlx5_ib_destroy_flow_action; |
Matan Barak | 349705c | 2018-03-28 09:27:51 +0300 | [diff] [blame] | 5958 | 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] | 5959 | dev->ib_dev.driver_id = RDMA_DRIVER_MLX5; |
Raed Salem | b29e2a1 | 2018-05-31 16:43:38 +0300 | [diff] [blame] | 5960 | dev->ib_dev.create_counters = mlx5_ib_create_counters; |
| 5961 | dev->ib_dev.destroy_counters = mlx5_ib_destroy_counters; |
Raed Salem | 1a1e03d | 2018-05-31 16:43:41 +0300 | [diff] [blame] | 5962 | dev->ib_dev.read_counters = mlx5_ib_read_counters; |
Yishai Hadas | 81e3088 | 2017-06-08 16:15:09 +0300 | [diff] [blame] | 5963 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5964 | err = init_node_data(dev); |
| 5965 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5966 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5967 | |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 5968 | 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] | 5969 | (MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) || |
| 5970 | MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
Mark Bloch | c8b8992 | 2018-01-01 13:07:02 +0200 | [diff] [blame] | 5971 | mutex_init(&dev->lb_mutex); |
| 5972 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 5973 | return 0; |
| 5974 | } |
| 5975 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5976 | static int mlx5_ib_stage_non_default_cb(struct mlx5_ib_dev *dev) |
| 5977 | { |
| 5978 | dev->ib_dev.get_port_immutable = mlx5_port_immutable; |
| 5979 | dev->ib_dev.query_port = mlx5_ib_query_port; |
| 5980 | |
| 5981 | return 0; |
| 5982 | } |
| 5983 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 5984 | 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] | 5985 | { |
| 5986 | dev->ib_dev.get_port_immutable = mlx5_port_rep_immutable; |
| 5987 | dev->ib_dev.query_port = mlx5_ib_rep_query_port; |
| 5988 | |
| 5989 | return 0; |
| 5990 | } |
| 5991 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5992 | static int mlx5_ib_stage_common_roce_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5993 | { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 5994 | u8 port_num; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 5995 | int i; |
| 5996 | |
| 5997 | for (i = 0; i < dev->num_ports; i++) { |
| 5998 | dev->roce[i].dev = dev; |
| 5999 | dev->roce[i].native_port_num = i + 1; |
| 6000 | dev->roce[i].last_port_state = IB_PORT_DOWN; |
| 6001 | } |
| 6002 | |
| 6003 | dev->ib_dev.get_netdev = mlx5_ib_get_netdev; |
| 6004 | dev->ib_dev.create_wq = mlx5_ib_create_wq; |
| 6005 | dev->ib_dev.modify_wq = mlx5_ib_modify_wq; |
| 6006 | dev->ib_dev.destroy_wq = mlx5_ib_destroy_wq; |
| 6007 | dev->ib_dev.create_rwq_ind_table = mlx5_ib_create_rwq_ind_table; |
| 6008 | dev->ib_dev.destroy_rwq_ind_table = mlx5_ib_destroy_rwq_ind_table; |
| 6009 | |
| 6010 | dev->ib_dev.uverbs_ex_cmd_mask |= |
| 6011 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_WQ) | |
| 6012 | (1ull << IB_USER_VERBS_EX_CMD_MODIFY_WQ) | |
| 6013 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_WQ) | |
| 6014 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) | |
| 6015 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL); |
| 6016 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6017 | port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6018 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6019 | return mlx5_add_netdev_notifier(dev, port_num); |
| 6020 | } |
| 6021 | |
| 6022 | static void mlx5_ib_stage_common_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6023 | { |
| 6024 | u8 port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 6025 | |
| 6026 | mlx5_remove_netdev_notifier(dev, port_num); |
| 6027 | } |
| 6028 | |
| 6029 | int mlx5_ib_stage_rep_roce_init(struct mlx5_ib_dev *dev) |
| 6030 | { |
| 6031 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6032 | enum rdma_link_layer ll; |
| 6033 | int port_type_cap; |
| 6034 | int err = 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6035 | |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6036 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6037 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6038 | |
| 6039 | if (ll == IB_LINK_LAYER_ETHERNET) |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6040 | err = mlx5_ib_stage_common_roce_init(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6041 | |
| 6042 | return err; |
| 6043 | } |
| 6044 | |
| 6045 | void mlx5_ib_stage_rep_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6046 | { |
| 6047 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 6048 | } |
| 6049 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6050 | static int mlx5_ib_stage_roce_init(struct mlx5_ib_dev *dev) |
| 6051 | { |
| 6052 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6053 | enum rdma_link_layer ll; |
| 6054 | int port_type_cap; |
| 6055 | int err; |
| 6056 | |
| 6057 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6058 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6059 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6060 | if (ll == IB_LINK_LAYER_ETHERNET) { |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6061 | err = mlx5_ib_stage_common_roce_init(dev); |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6062 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6063 | return err; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6064 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6065 | err = mlx5_enable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6066 | if (err) |
| 6067 | goto cleanup; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 6068 | } |
| 6069 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6070 | return 0; |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6071 | cleanup: |
| 6072 | mlx5_ib_stage_common_roce_cleanup(dev); |
| 6073 | |
| 6074 | return err; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6075 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6076 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6077 | static void mlx5_ib_stage_roce_cleanup(struct mlx5_ib_dev *dev) |
| 6078 | { |
| 6079 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6080 | enum rdma_link_layer ll; |
| 6081 | int port_type_cap; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6082 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6083 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6084 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6085 | |
| 6086 | if (ll == IB_LINK_LAYER_ETHERNET) { |
| 6087 | mlx5_disable_eth(dev); |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6088 | mlx5_ib_stage_common_roce_cleanup(dev); |
Kamal Heib | 45bded2 | 2017-01-18 14:10:32 +0200 | [diff] [blame] | 6089 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6090 | } |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6091 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6092 | int mlx5_ib_stage_dev_res_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6093 | { |
| 6094 | return create_dev_resources(&dev->devr); |
| 6095 | } |
Parav Pandit | 4a2da0b | 2017-05-30 10:05:15 +0300 | [diff] [blame] | 6096 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6097 | void mlx5_ib_stage_dev_res_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6098 | { |
| 6099 | destroy_dev_resources(&dev->devr); |
| 6100 | } |
| 6101 | |
| 6102 | static int mlx5_ib_stage_odp_init(struct mlx5_ib_dev *dev) |
| 6103 | { |
Mark Bloch | 07321b3 | 2018-01-01 13:07:00 +0200 | [diff] [blame] | 6104 | mlx5_ib_internal_fill_odp_caps(dev); |
| 6105 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6106 | return mlx5_ib_odp_init_one(dev); |
| 6107 | } |
| 6108 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6109 | int mlx5_ib_stage_counters_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6110 | { |
Mark Bloch | 5e1e761 | 2018-01-01 13:07:01 +0200 | [diff] [blame] | 6111 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) { |
| 6112 | dev->ib_dev.get_hw_stats = mlx5_ib_get_hw_stats; |
| 6113 | dev->ib_dev.alloc_hw_stats = mlx5_ib_alloc_hw_stats; |
| 6114 | |
| 6115 | return mlx5_ib_alloc_counters(dev); |
| 6116 | } |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6117 | |
| 6118 | return 0; |
| 6119 | } |
| 6120 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6121 | void mlx5_ib_stage_counters_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6122 | { |
| 6123 | if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) |
| 6124 | mlx5_ib_dealloc_counters(dev); |
| 6125 | } |
| 6126 | |
| 6127 | static int mlx5_ib_stage_cong_debugfs_init(struct mlx5_ib_dev *dev) |
| 6128 | { |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 6129 | return mlx5_ib_init_cong_debugfs(dev, |
| 6130 | mlx5_core_native_port_num(dev->mdev) - 1); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6131 | } |
| 6132 | |
| 6133 | static void mlx5_ib_stage_cong_debugfs_cleanup(struct mlx5_ib_dev *dev) |
| 6134 | { |
Parav Pandit | a9e546e | 2018-01-04 17:25:39 +0200 | [diff] [blame] | 6135 | mlx5_ib_cleanup_cong_debugfs(dev, |
| 6136 | mlx5_core_native_port_num(dev->mdev) - 1); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | static int mlx5_ib_stage_uar_init(struct mlx5_ib_dev *dev) |
| 6140 | { |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6141 | dev->mdev->priv.uar = mlx5_get_uars_page(dev->mdev); |
Leon Romanovsky | 444261c | 2018-04-23 17:01:56 +0300 | [diff] [blame] | 6142 | return PTR_ERR_OR_ZERO(dev->mdev->priv.uar); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6143 | } |
| 6144 | |
| 6145 | static void mlx5_ib_stage_uar_cleanup(struct mlx5_ib_dev *dev) |
| 6146 | { |
| 6147 | mlx5_put_uars_page(dev->mdev, dev->mdev->priv.uar); |
| 6148 | } |
| 6149 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6150 | int mlx5_ib_stage_bfrag_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6151 | { |
| 6152 | int err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6153 | |
| 6154 | err = mlx5_alloc_bfreg(dev->mdev, &dev->bfreg, false, false); |
| 6155 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6156 | return err; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6157 | |
| 6158 | err = mlx5_alloc_bfreg(dev->mdev, &dev->fp_bfreg, false, true); |
| 6159 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6160 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 6161 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6162 | return err; |
| 6163 | } |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 6164 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6165 | void mlx5_ib_stage_bfrag_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6166 | { |
| 6167 | mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
| 6168 | mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
| 6169 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6170 | |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 6171 | static int mlx5_ib_stage_populate_specs(struct mlx5_ib_dev *dev) |
| 6172 | { |
| 6173 | return populate_specs_root(dev); |
| 6174 | } |
| 6175 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6176 | int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6177 | { |
| 6178 | return ib_register_device(&dev->ib_dev, NULL); |
| 6179 | } |
| 6180 | |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6181 | 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] | 6182 | { |
| 6183 | destroy_umrc_res(dev); |
| 6184 | } |
| 6185 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6186 | void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6187 | { |
| 6188 | ib_unregister_device(&dev->ib_dev); |
| 6189 | } |
| 6190 | |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6191 | 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] | 6192 | { |
| 6193 | return create_umr_res(dev); |
| 6194 | } |
| 6195 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6196 | static int mlx5_ib_stage_delay_drop_init(struct mlx5_ib_dev *dev) |
| 6197 | { |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6198 | init_delay_drop(dev); |
| 6199 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6200 | return 0; |
| 6201 | } |
| 6202 | |
| 6203 | static void mlx5_ib_stage_delay_drop_cleanup(struct mlx5_ib_dev *dev) |
| 6204 | { |
| 6205 | cancel_delay_drop(dev); |
| 6206 | } |
| 6207 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6208 | int mlx5_ib_stage_class_attr_init(struct mlx5_ib_dev *dev) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6209 | { |
| 6210 | int err; |
| 6211 | int i; |
| 6212 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6213 | for (i = 0; i < ARRAY_SIZE(mlx5_class_attributes); i++) { |
Wei Yongjun | 281d1a9 | 2013-07-30 07:54:26 +0800 | [diff] [blame] | 6214 | err = device_create_file(&dev->ib_dev.dev, |
| 6215 | mlx5_class_attributes[i]); |
| 6216 | if (err) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6217 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6218 | } |
| 6219 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6220 | return 0; |
| 6221 | } |
| 6222 | |
Mark Bloch | fc385b7 | 2018-01-16 14:34:48 +0000 | [diff] [blame] | 6223 | static int mlx5_ib_stage_rep_reg_init(struct mlx5_ib_dev *dev) |
| 6224 | { |
| 6225 | mlx5_ib_register_vport_reps(dev); |
| 6226 | |
| 6227 | return 0; |
| 6228 | } |
| 6229 | |
| 6230 | static void mlx5_ib_stage_rep_reg_cleanup(struct mlx5_ib_dev *dev) |
| 6231 | { |
| 6232 | mlx5_ib_unregister_vport_reps(dev); |
| 6233 | } |
| 6234 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6235 | void __mlx5_ib_remove(struct mlx5_ib_dev *dev, |
| 6236 | const struct mlx5_ib_profile *profile, |
| 6237 | int stage) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6238 | { |
| 6239 | /* Number of stages to cleanup */ |
| 6240 | while (stage) { |
| 6241 | stage--; |
| 6242 | if (profile->stage[stage].cleanup) |
| 6243 | profile->stage[stage].cleanup(dev); |
| 6244 | } |
| 6245 | |
| 6246 | ib_dealloc_device((struct ib_device *)dev); |
| 6247 | } |
| 6248 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6249 | void *__mlx5_ib_add(struct mlx5_ib_dev *dev, |
| 6250 | const struct mlx5_ib_profile *profile) |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6251 | { |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6252 | int err; |
| 6253 | int i; |
| 6254 | |
| 6255 | printk_once(KERN_INFO "%s", mlx5_version); |
| 6256 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6257 | for (i = 0; i < MLX5_IB_STAGE_MAX; i++) { |
| 6258 | if (profile->stage[i].init) { |
| 6259 | err = profile->stage[i].init(dev); |
| 6260 | if (err) |
| 6261 | goto err_out; |
| 6262 | } |
| 6263 | } |
| 6264 | |
| 6265 | dev->profile = profile; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6266 | dev->ib_active = true; |
| 6267 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6268 | return dev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6269 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6270 | err_out: |
| 6271 | __mlx5_ib_remove(dev, profile, i); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6272 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6273 | return NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6274 | } |
| 6275 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6276 | static const struct mlx5_ib_profile pf_profile = { |
| 6277 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6278 | mlx5_ib_stage_init_init, |
| 6279 | mlx5_ib_stage_init_cleanup), |
Mark Bloch | 9a4ca38 | 2018-01-16 14:42:35 +0000 | [diff] [blame] | 6280 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6281 | mlx5_ib_stage_flow_db_init, |
| 6282 | mlx5_ib_stage_flow_db_cleanup), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6283 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6284 | mlx5_ib_stage_caps_init, |
| 6285 | NULL), |
Mark Bloch | 8e6efa3 | 2017-11-06 12:22:13 +0000 | [diff] [blame] | 6286 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6287 | mlx5_ib_stage_non_default_cb, |
| 6288 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6289 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6290 | mlx5_ib_stage_roce_init, |
| 6291 | mlx5_ib_stage_roce_cleanup), |
| 6292 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6293 | mlx5_ib_stage_dev_res_init, |
| 6294 | mlx5_ib_stage_dev_res_cleanup), |
| 6295 | STAGE_CREATE(MLX5_IB_STAGE_ODP, |
| 6296 | mlx5_ib_stage_odp_init, |
Mark Bloch | 3cc297d | 2018-01-01 13:07:03 +0200 | [diff] [blame] | 6297 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6298 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6299 | mlx5_ib_stage_counters_init, |
| 6300 | mlx5_ib_stage_counters_cleanup), |
| 6301 | STAGE_CREATE(MLX5_IB_STAGE_CONG_DEBUGFS, |
| 6302 | mlx5_ib_stage_cong_debugfs_init, |
| 6303 | mlx5_ib_stage_cong_debugfs_cleanup), |
| 6304 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6305 | mlx5_ib_stage_uar_init, |
| 6306 | mlx5_ib_stage_uar_cleanup), |
| 6307 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6308 | mlx5_ib_stage_bfrag_init, |
| 6309 | mlx5_ib_stage_bfrag_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6310 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6311 | NULL, |
| 6312 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 6313 | STAGE_CREATE(MLX5_IB_STAGE_SPECS, |
| 6314 | mlx5_ib_stage_populate_specs, |
Jason Gunthorpe | 7d96c9b | 2018-08-09 20:14:35 -0600 | [diff] [blame] | 6315 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6316 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6317 | mlx5_ib_stage_ib_reg_init, |
| 6318 | mlx5_ib_stage_ib_reg_cleanup), |
Mark Bloch | 42cea83 | 2018-03-14 09:14:15 +0200 | [diff] [blame] | 6319 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6320 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6321 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6322 | STAGE_CREATE(MLX5_IB_STAGE_DELAY_DROP, |
| 6323 | mlx5_ib_stage_delay_drop_init, |
| 6324 | mlx5_ib_stage_delay_drop_cleanup), |
| 6325 | STAGE_CREATE(MLX5_IB_STAGE_CLASS_ATTR, |
| 6326 | mlx5_ib_stage_class_attr_init, |
| 6327 | NULL), |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6328 | }; |
| 6329 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6330 | static const struct mlx5_ib_profile nic_rep_profile = { |
| 6331 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
| 6332 | mlx5_ib_stage_init_init, |
| 6333 | mlx5_ib_stage_init_cleanup), |
| 6334 | STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
| 6335 | mlx5_ib_stage_flow_db_init, |
| 6336 | mlx5_ib_stage_flow_db_cleanup), |
| 6337 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
| 6338 | mlx5_ib_stage_caps_init, |
| 6339 | NULL), |
| 6340 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
| 6341 | mlx5_ib_stage_rep_non_default_cb, |
| 6342 | NULL), |
| 6343 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
| 6344 | mlx5_ib_stage_rep_roce_init, |
| 6345 | mlx5_ib_stage_rep_roce_cleanup), |
| 6346 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
| 6347 | mlx5_ib_stage_dev_res_init, |
| 6348 | mlx5_ib_stage_dev_res_cleanup), |
| 6349 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
| 6350 | mlx5_ib_stage_counters_init, |
| 6351 | mlx5_ib_stage_counters_cleanup), |
| 6352 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
| 6353 | mlx5_ib_stage_uar_init, |
| 6354 | mlx5_ib_stage_uar_cleanup), |
| 6355 | STAGE_CREATE(MLX5_IB_STAGE_BFREG, |
| 6356 | mlx5_ib_stage_bfrag_init, |
| 6357 | mlx5_ib_stage_bfrag_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6358 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
| 6359 | NULL, |
| 6360 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
Matan Barak | 8c84660 | 2018-03-28 09:27:41 +0300 | [diff] [blame] | 6361 | STAGE_CREATE(MLX5_IB_STAGE_SPECS, |
| 6362 | mlx5_ib_stage_populate_specs, |
Jason Gunthorpe | 7d96c9b | 2018-08-09 20:14:35 -0600 | [diff] [blame] | 6363 | NULL), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6364 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
| 6365 | mlx5_ib_stage_ib_reg_init, |
| 6366 | mlx5_ib_stage_ib_reg_cleanup), |
David S. Miller | 03fe2de | 2018-03-23 11:24:57 -0400 | [diff] [blame] | 6367 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
| 6368 | mlx5_ib_stage_post_ib_reg_umr_init, |
| 6369 | NULL), |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6370 | STAGE_CREATE(MLX5_IB_STAGE_CLASS_ATTR, |
| 6371 | mlx5_ib_stage_class_attr_init, |
| 6372 | NULL), |
| 6373 | STAGE_CREATE(MLX5_IB_STAGE_REP_REG, |
| 6374 | mlx5_ib_stage_rep_reg_init, |
| 6375 | mlx5_ib_stage_rep_reg_cleanup), |
| 6376 | }; |
| 6377 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6378 | static void *mlx5_ib_add_slave_port(struct mlx5_core_dev *mdev) |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6379 | { |
| 6380 | struct mlx5_ib_multiport_info *mpi; |
| 6381 | struct mlx5_ib_dev *dev; |
| 6382 | bool bound = false; |
| 6383 | int err; |
| 6384 | |
| 6385 | mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
| 6386 | if (!mpi) |
| 6387 | return NULL; |
| 6388 | |
| 6389 | mpi->mdev = mdev; |
| 6390 | |
| 6391 | err = mlx5_query_nic_vport_system_image_guid(mdev, |
| 6392 | &mpi->sys_image_guid); |
| 6393 | if (err) { |
| 6394 | kfree(mpi); |
| 6395 | return NULL; |
| 6396 | } |
| 6397 | |
| 6398 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6399 | list_for_each_entry(dev, &mlx5_ib_dev_list, ib_dev_list) { |
| 6400 | if (dev->sys_image_guid == mpi->sys_image_guid) |
| 6401 | bound = mlx5_ib_bind_slave_port(dev, mpi); |
| 6402 | |
| 6403 | if (bound) { |
| 6404 | rdma_roce_rescan_device(&dev->ib_dev); |
| 6405 | break; |
| 6406 | } |
| 6407 | } |
| 6408 | |
| 6409 | if (!bound) { |
| 6410 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
| 6411 | dev_dbg(&mdev->pdev->dev, "no suitable IB device found to bind to, added to unaffiliated list.\n"); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6412 | } |
| 6413 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6414 | |
| 6415 | return mpi; |
| 6416 | } |
| 6417 | |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6418 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
| 6419 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6420 | enum rdma_link_layer ll; |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6421 | struct mlx5_ib_dev *dev; |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6422 | int port_type_cap; |
| 6423 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6424 | printk_once(KERN_INFO "%s", mlx5_version); |
| 6425 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6426 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
| 6427 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
| 6428 | |
Leon Romanovsky | e3f1ed1 | 2018-07-08 12:55:43 +0300 | [diff] [blame] | 6429 | if (mlx5_core_is_mp_slave(mdev) && ll == IB_LINK_LAYER_ETHERNET) |
| 6430 | return mlx5_ib_add_slave_port(mdev); |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6431 | |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6432 | dev = (struct mlx5_ib_dev *)ib_alloc_device(sizeof(*dev)); |
| 6433 | if (!dev) |
| 6434 | return NULL; |
| 6435 | |
| 6436 | dev->mdev = mdev; |
| 6437 | dev->num_ports = max(MLX5_CAP_GEN(mdev, num_ports), |
| 6438 | MLX5_CAP_GEN(mdev, num_vhca_ports)); |
| 6439 | |
Or Gerlitz | aff2252 | 2018-05-31 11:40:17 +0300 | [diff] [blame] | 6440 | if (MLX5_ESWITCH_MANAGER(mdev) && |
Mark Bloch | b5ca15a | 2018-01-23 11:16:30 +0000 | [diff] [blame] | 6441 | mlx5_ib_eswitch_mode(mdev->priv.eswitch) == SRIOV_OFFLOADS) { |
| 6442 | dev->rep = mlx5_ib_vport_rep(mdev->priv.eswitch, 0); |
| 6443 | |
| 6444 | return __mlx5_ib_add(dev, &nic_rep_profile); |
| 6445 | } |
| 6446 | |
| 6447 | return __mlx5_ib_add(dev, &pf_profile); |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6448 | } |
| 6449 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6450 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6451 | { |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6452 | struct mlx5_ib_multiport_info *mpi; |
| 6453 | struct mlx5_ib_dev *dev; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6454 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 6455 | if (mlx5_core_is_mp_slave(mdev)) { |
| 6456 | mpi = context; |
| 6457 | mutex_lock(&mlx5_ib_multiport_mutex); |
| 6458 | if (mpi->ibdev) |
| 6459 | mlx5_ib_unbind_slave_port(mpi->ibdev, mpi); |
| 6460 | list_del(&mpi->list); |
| 6461 | mutex_unlock(&mlx5_ib_multiport_mutex); |
| 6462 | return; |
| 6463 | } |
| 6464 | |
| 6465 | dev = context; |
Mark Bloch | 16c1975 | 2018-01-01 13:06:58 +0200 | [diff] [blame] | 6466 | __mlx5_ib_remove(dev, dev->profile, MLX5_IB_STAGE_MAX); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6467 | } |
| 6468 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6469 | static struct mlx5_interface mlx5_ib_interface = { |
| 6470 | .add = mlx5_ib_add, |
| 6471 | .remove = mlx5_ib_remove, |
| 6472 | .event = mlx5_ib_event, |
Artemy Kovalyov | d9aaed8 | 2017-01-02 11:37:46 +0200 | [diff] [blame] | 6473 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 6474 | .pfault = mlx5_ib_pfault, |
| 6475 | #endif |
Saeed Mahameed | 64613d94 | 2015-04-02 17:07:34 +0300 | [diff] [blame] | 6476 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6477 | }; |
| 6478 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6479 | unsigned long mlx5_ib_get_xlt_emergency_page(void) |
| 6480 | { |
| 6481 | mutex_lock(&xlt_emergency_page_mutex); |
| 6482 | return xlt_emergency_page; |
| 6483 | } |
| 6484 | |
| 6485 | void mlx5_ib_put_xlt_emergency_page(void) |
| 6486 | { |
| 6487 | mutex_unlock(&xlt_emergency_page_mutex); |
| 6488 | } |
| 6489 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6490 | static int __init mlx5_ib_init(void) |
| 6491 | { |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6492 | int err; |
| 6493 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6494 | xlt_emergency_page = __get_free_page(GFP_KERNEL); |
| 6495 | if (!xlt_emergency_page) |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6496 | return -ENOMEM; |
| 6497 | |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6498 | mutex_init(&xlt_emergency_page_mutex); |
| 6499 | |
| 6500 | mlx5_ib_event_wq = alloc_ordered_workqueue("mlx5_ib_event_wq", 0); |
| 6501 | if (!mlx5_ib_event_wq) { |
| 6502 | free_page(xlt_emergency_page); |
| 6503 | return -ENOMEM; |
| 6504 | } |
| 6505 | |
Artemy Kovalyov | 81713d3 | 2017-01-18 16:58:11 +0200 | [diff] [blame] | 6506 | mlx5_ib_odp_init(); |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6507 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6508 | err = mlx5_register_interface(&mlx5_ib_interface); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 6509 | |
| 6510 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6511 | } |
| 6512 | |
| 6513 | static void __exit mlx5_ib_cleanup(void) |
| 6514 | { |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 6515 | mlx5_unregister_interface(&mlx5_ib_interface); |
Daniel Jurgens | d69a24e | 2018-01-04 17:25:37 +0200 | [diff] [blame] | 6516 | destroy_workqueue(mlx5_ib_event_wq); |
Ilya Lesokhin | c44ef99 | 2018-03-13 15:18:48 +0200 | [diff] [blame] | 6517 | mutex_destroy(&xlt_emergency_page_mutex); |
| 6518 | free_page(xlt_emergency_page); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 6519 | } |
| 6520 | |
| 6521 | module_init(mlx5_ib_init); |
| 6522 | module_exit(mlx5_ib_cleanup); |