| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
|---|
| 1 | 2 | /* |
|---|
| 2 | | - * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. |
|---|
| 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. |
|---|
| 3 | + * Copyright (c) 2013-2020, Mellanox Technologies inc. All rights reserved. |
|---|
| 31 | 4 | */ |
|---|
| 32 | 5 | |
|---|
| 33 | 6 | #include <linux/debugfs.h> |
|---|
| .. | .. |
|---|
| 39 | 12 | #include <linux/dma-mapping.h> |
|---|
| 40 | 13 | #include <linux/slab.h> |
|---|
| 41 | 14 | #include <linux/bitmap.h> |
|---|
| 42 | | -#if defined(CONFIG_X86) |
|---|
| 43 | | -#include <asm/pat.h> |
|---|
| 44 | | -#endif |
|---|
| 45 | 15 | #include <linux/sched.h> |
|---|
| 46 | 16 | #include <linux/sched/mm.h> |
|---|
| 47 | 17 | #include <linux/sched/task.h> |
|---|
| .. | .. |
|---|
| 52 | 22 | #include <linux/mlx5/port.h> |
|---|
| 53 | 23 | #include <linux/mlx5/vport.h> |
|---|
| 54 | 24 | #include <linux/mlx5/fs.h> |
|---|
| 25 | +#include <linux/mlx5/eswitch.h> |
|---|
| 55 | 26 | #include <linux/list.h> |
|---|
| 56 | 27 | #include <rdma/ib_smi.h> |
|---|
| 57 | 28 | #include <rdma/ib_umem.h> |
|---|
| 29 | +#include <rdma/lag.h> |
|---|
| 58 | 30 | #include <linux/in.h> |
|---|
| 59 | 31 | #include <linux/etherdevice.h> |
|---|
| 60 | 32 | #include "mlx5_ib.h" |
|---|
| 61 | 33 | #include "ib_rep.h" |
|---|
| 62 | 34 | #include "cmd.h" |
|---|
| 63 | | -#include <linux/mlx5/fs_helpers.h> |
|---|
| 35 | +#include "devx.h" |
|---|
| 36 | +#include "fs.h" |
|---|
| 37 | +#include "srq.h" |
|---|
| 38 | +#include "qp.h" |
|---|
| 39 | +#include "wr.h" |
|---|
| 40 | +#include "restrack.h" |
|---|
| 41 | +#include "counters.h" |
|---|
| 64 | 42 | #include <linux/mlx5/accel.h> |
|---|
| 65 | 43 | #include <rdma/uverbs_std_types.h> |
|---|
| 66 | 44 | #include <rdma/mlx5_user_ioctl_verbs.h> |
|---|
| 67 | 45 | #include <rdma/mlx5_user_ioctl_cmds.h> |
|---|
| 46 | +#include <rdma/ib_umem_odp.h> |
|---|
| 68 | 47 | |
|---|
| 69 | 48 | #define UVERBS_MODULE_NAME mlx5_ib |
|---|
| 70 | 49 | #include <rdma/uverbs_named_ioctl.h> |
|---|
| 71 | 50 | |
|---|
| 72 | | -#define DRIVER_NAME "mlx5_ib" |
|---|
| 73 | | -#define DRIVER_VERSION "5.0-0" |
|---|
| 74 | | - |
|---|
| 75 | 51 | MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); |
|---|
| 76 | | -MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); |
|---|
| 52 | +MODULE_DESCRIPTION("Mellanox 5th generation network adapters (ConnectX series) IB driver"); |
|---|
| 77 | 53 | MODULE_LICENSE("Dual BSD/GPL"); |
|---|
| 78 | | - |
|---|
| 79 | | -static char mlx5_version[] = |
|---|
| 80 | | - DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
|---|
| 81 | | - DRIVER_VERSION "\n"; |
|---|
| 82 | 54 | |
|---|
| 83 | 55 | struct mlx5_ib_event_work { |
|---|
| 84 | 56 | struct work_struct work; |
|---|
| 85 | | - struct mlx5_core_dev *dev; |
|---|
| 86 | | - void *context; |
|---|
| 87 | | - enum mlx5_dev_event event; |
|---|
| 88 | | - unsigned long param; |
|---|
| 57 | + union { |
|---|
| 58 | + struct mlx5_ib_dev *dev; |
|---|
| 59 | + struct mlx5_ib_multiport_info *mpi; |
|---|
| 60 | + }; |
|---|
| 61 | + bool is_slave; |
|---|
| 62 | + unsigned int event; |
|---|
| 63 | + void *param; |
|---|
| 89 | 64 | }; |
|---|
| 90 | 65 | |
|---|
| 91 | 66 | enum { |
|---|
| .. | .. |
|---|
| 146 | 121 | int ret; |
|---|
| 147 | 122 | |
|---|
| 148 | 123 | memset(&attr, 0, sizeof(attr)); |
|---|
| 149 | | - ret = ibdev->query_port(ibdev, port_num, &attr); |
|---|
| 124 | + ret = ibdev->ops.query_port(ibdev, port_num, &attr); |
|---|
| 150 | 125 | if (!ret) |
|---|
| 151 | 126 | *state = attr.state; |
|---|
| 152 | 127 | return ret; |
|---|
| 128 | +} |
|---|
| 129 | + |
|---|
| 130 | +static struct mlx5_roce *mlx5_get_rep_roce(struct mlx5_ib_dev *dev, |
|---|
| 131 | + struct net_device *ndev, |
|---|
| 132 | + u8 *port_num) |
|---|
| 133 | +{ |
|---|
| 134 | + struct mlx5_eswitch *esw = dev->mdev->priv.eswitch; |
|---|
| 135 | + struct net_device *rep_ndev; |
|---|
| 136 | + struct mlx5_ib_port *port; |
|---|
| 137 | + int i; |
|---|
| 138 | + |
|---|
| 139 | + for (i = 0; i < dev->num_ports; i++) { |
|---|
| 140 | + port = &dev->port[i]; |
|---|
| 141 | + if (!port->rep) |
|---|
| 142 | + continue; |
|---|
| 143 | + |
|---|
| 144 | + read_lock(&port->roce.netdev_lock); |
|---|
| 145 | + rep_ndev = mlx5_ib_get_rep_netdev(esw, |
|---|
| 146 | + port->rep->vport); |
|---|
| 147 | + if (rep_ndev == ndev) { |
|---|
| 148 | + read_unlock(&port->roce.netdev_lock); |
|---|
| 149 | + *port_num = i + 1; |
|---|
| 150 | + return &port->roce; |
|---|
| 151 | + } |
|---|
| 152 | + read_unlock(&port->roce.netdev_lock); |
|---|
| 153 | + } |
|---|
| 154 | + |
|---|
| 155 | + return NULL; |
|---|
| 153 | 156 | } |
|---|
| 154 | 157 | |
|---|
| 155 | 158 | static int mlx5_netdev_event(struct notifier_block *this, |
|---|
| .. | .. |
|---|
| 168 | 171 | |
|---|
| 169 | 172 | switch (event) { |
|---|
| 170 | 173 | case NETDEV_REGISTER: |
|---|
| 171 | | - case NETDEV_UNREGISTER: |
|---|
| 174 | + /* Should already be registered during the load */ |
|---|
| 175 | + if (ibdev->is_rep) |
|---|
| 176 | + break; |
|---|
| 172 | 177 | write_lock(&roce->netdev_lock); |
|---|
| 173 | | - if (ibdev->rep) { |
|---|
| 174 | | - struct mlx5_eswitch *esw = ibdev->mdev->priv.eswitch; |
|---|
| 175 | | - struct net_device *rep_ndev; |
|---|
| 178 | + if (ndev->dev.parent == mdev->device) |
|---|
| 179 | + roce->netdev = ndev; |
|---|
| 180 | + write_unlock(&roce->netdev_lock); |
|---|
| 181 | + break; |
|---|
| 176 | 182 | |
|---|
| 177 | | - rep_ndev = mlx5_ib_get_rep_netdev(esw, |
|---|
| 178 | | - ibdev->rep->vport); |
|---|
| 179 | | - if (rep_ndev == ndev) |
|---|
| 180 | | - roce->netdev = (event == NETDEV_UNREGISTER) ? |
|---|
| 181 | | - NULL : ndev; |
|---|
| 182 | | - } else if (ndev->dev.parent == &mdev->pdev->dev) { |
|---|
| 183 | | - roce->netdev = (event == NETDEV_UNREGISTER) ? |
|---|
| 184 | | - NULL : ndev; |
|---|
| 185 | | - } |
|---|
| 183 | + case NETDEV_UNREGISTER: |
|---|
| 184 | + /* In case of reps, ib device goes away before the netdevs */ |
|---|
| 185 | + write_lock(&roce->netdev_lock); |
|---|
| 186 | + if (roce->netdev == ndev) |
|---|
| 187 | + roce->netdev = NULL; |
|---|
| 186 | 188 | write_unlock(&roce->netdev_lock); |
|---|
| 187 | 189 | break; |
|---|
| 188 | 190 | |
|---|
| .. | .. |
|---|
| 197 | 199 | dev_put(lag_ndev); |
|---|
| 198 | 200 | } |
|---|
| 199 | 201 | |
|---|
| 202 | + if (ibdev->is_rep) |
|---|
| 203 | + roce = mlx5_get_rep_roce(ibdev, ndev, &port_num); |
|---|
| 204 | + if (!roce) |
|---|
| 205 | + return NOTIFY_DONE; |
|---|
| 200 | 206 | if ((upper == ndev || (!upper && ndev == roce->netdev)) |
|---|
| 201 | 207 | && ibdev->ib_active) { |
|---|
| 202 | 208 | struct ib_event ibev = { }; |
|---|
| .. | .. |
|---|
| 249 | 255 | |
|---|
| 250 | 256 | /* Ensure ndev does not disappear before we invoke dev_hold() |
|---|
| 251 | 257 | */ |
|---|
| 252 | | - read_lock(&ibdev->roce[port_num - 1].netdev_lock); |
|---|
| 253 | | - ndev = ibdev->roce[port_num - 1].netdev; |
|---|
| 258 | + read_lock(&ibdev->port[port_num - 1].roce.netdev_lock); |
|---|
| 259 | + ndev = ibdev->port[port_num - 1].roce.netdev; |
|---|
| 254 | 260 | if (ndev) |
|---|
| 255 | 261 | dev_hold(ndev); |
|---|
| 256 | | - read_unlock(&ibdev->roce[port_num - 1].netdev_lock); |
|---|
| 262 | + read_unlock(&ibdev->port[port_num - 1].roce.netdev_lock); |
|---|
| 257 | 263 | |
|---|
| 258 | 264 | out: |
|---|
| 259 | 265 | mlx5_ib_put_native_port_mdev(ibdev, port_num); |
|---|
| .. | .. |
|---|
| 281 | 287 | *native_port_num = 1; |
|---|
| 282 | 288 | |
|---|
| 283 | 289 | port = &ibdev->port[ib_port_num - 1]; |
|---|
| 284 | | - if (!port) |
|---|
| 285 | | - return NULL; |
|---|
| 286 | | - |
|---|
| 287 | 290 | spin_lock(&port->mp.mpi_lock); |
|---|
| 288 | 291 | mpi = ibdev->port[ib_port_num - 1].mp.mpi; |
|---|
| 289 | 292 | if (mpi && !mpi->unaffiliate) { |
|---|
| .. | .. |
|---|
| 323 | 326 | spin_unlock(&port->mp.mpi_lock); |
|---|
| 324 | 327 | } |
|---|
| 325 | 328 | |
|---|
| 326 | | -static int translate_eth_proto_oper(u32 eth_proto_oper, u8 *active_speed, |
|---|
| 327 | | - u8 *active_width) |
|---|
| 329 | +static int translate_eth_legacy_proto_oper(u32 eth_proto_oper, |
|---|
| 330 | + u16 *active_speed, u8 *active_width) |
|---|
| 328 | 331 | { |
|---|
| 329 | 332 | switch (eth_proto_oper) { |
|---|
| 330 | 333 | case MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII): |
|---|
| .. | .. |
|---|
| 381 | 384 | return 0; |
|---|
| 382 | 385 | } |
|---|
| 383 | 386 | |
|---|
| 387 | +static int translate_eth_ext_proto_oper(u32 eth_proto_oper, u16 *active_speed, |
|---|
| 388 | + u8 *active_width) |
|---|
| 389 | +{ |
|---|
| 390 | + switch (eth_proto_oper) { |
|---|
| 391 | + case MLX5E_PROT_MASK(MLX5E_SGMII_100M): |
|---|
| 392 | + case MLX5E_PROT_MASK(MLX5E_1000BASE_X_SGMII): |
|---|
| 393 | + *active_width = IB_WIDTH_1X; |
|---|
| 394 | + *active_speed = IB_SPEED_SDR; |
|---|
| 395 | + break; |
|---|
| 396 | + case MLX5E_PROT_MASK(MLX5E_5GBASE_R): |
|---|
| 397 | + *active_width = IB_WIDTH_1X; |
|---|
| 398 | + *active_speed = IB_SPEED_DDR; |
|---|
| 399 | + break; |
|---|
| 400 | + case MLX5E_PROT_MASK(MLX5E_10GBASE_XFI_XAUI_1): |
|---|
| 401 | + *active_width = IB_WIDTH_1X; |
|---|
| 402 | + *active_speed = IB_SPEED_QDR; |
|---|
| 403 | + break; |
|---|
| 404 | + case MLX5E_PROT_MASK(MLX5E_40GBASE_XLAUI_4_XLPPI_4): |
|---|
| 405 | + *active_width = IB_WIDTH_4X; |
|---|
| 406 | + *active_speed = IB_SPEED_QDR; |
|---|
| 407 | + break; |
|---|
| 408 | + case MLX5E_PROT_MASK(MLX5E_25GAUI_1_25GBASE_CR_KR): |
|---|
| 409 | + *active_width = IB_WIDTH_1X; |
|---|
| 410 | + *active_speed = IB_SPEED_EDR; |
|---|
| 411 | + break; |
|---|
| 412 | + case MLX5E_PROT_MASK(MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2): |
|---|
| 413 | + *active_width = IB_WIDTH_2X; |
|---|
| 414 | + *active_speed = IB_SPEED_EDR; |
|---|
| 415 | + break; |
|---|
| 416 | + case MLX5E_PROT_MASK(MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR): |
|---|
| 417 | + *active_width = IB_WIDTH_1X; |
|---|
| 418 | + *active_speed = IB_SPEED_HDR; |
|---|
| 419 | + break; |
|---|
| 420 | + case MLX5E_PROT_MASK(MLX5E_CAUI_4_100GBASE_CR4_KR4): |
|---|
| 421 | + *active_width = IB_WIDTH_4X; |
|---|
| 422 | + *active_speed = IB_SPEED_EDR; |
|---|
| 423 | + break; |
|---|
| 424 | + case MLX5E_PROT_MASK(MLX5E_100GAUI_2_100GBASE_CR2_KR2): |
|---|
| 425 | + *active_width = IB_WIDTH_2X; |
|---|
| 426 | + *active_speed = IB_SPEED_HDR; |
|---|
| 427 | + break; |
|---|
| 428 | + case MLX5E_PROT_MASK(MLX5E_100GAUI_1_100GBASE_CR_KR): |
|---|
| 429 | + *active_width = IB_WIDTH_1X; |
|---|
| 430 | + *active_speed = IB_SPEED_NDR; |
|---|
| 431 | + break; |
|---|
| 432 | + case MLX5E_PROT_MASK(MLX5E_200GAUI_4_200GBASE_CR4_KR4): |
|---|
| 433 | + *active_width = IB_WIDTH_4X; |
|---|
| 434 | + *active_speed = IB_SPEED_HDR; |
|---|
| 435 | + break; |
|---|
| 436 | + case MLX5E_PROT_MASK(MLX5E_200GAUI_2_200GBASE_CR2_KR2): |
|---|
| 437 | + *active_width = IB_WIDTH_2X; |
|---|
| 438 | + *active_speed = IB_SPEED_NDR; |
|---|
| 439 | + break; |
|---|
| 440 | + case MLX5E_PROT_MASK(MLX5E_400GAUI_8): |
|---|
| 441 | + *active_width = IB_WIDTH_8X; |
|---|
| 442 | + *active_speed = IB_SPEED_HDR; |
|---|
| 443 | + break; |
|---|
| 444 | + case MLX5E_PROT_MASK(MLX5E_400GAUI_4_400GBASE_CR4_KR4): |
|---|
| 445 | + *active_width = IB_WIDTH_4X; |
|---|
| 446 | + *active_speed = IB_SPEED_NDR; |
|---|
| 447 | + break; |
|---|
| 448 | + default: |
|---|
| 449 | + return -EINVAL; |
|---|
| 450 | + } |
|---|
| 451 | + |
|---|
| 452 | + return 0; |
|---|
| 453 | +} |
|---|
| 454 | + |
|---|
| 455 | +static int translate_eth_proto_oper(u32 eth_proto_oper, u16 *active_speed, |
|---|
| 456 | + u8 *active_width, bool ext) |
|---|
| 457 | +{ |
|---|
| 458 | + return ext ? |
|---|
| 459 | + translate_eth_ext_proto_oper(eth_proto_oper, active_speed, |
|---|
| 460 | + active_width) : |
|---|
| 461 | + translate_eth_legacy_proto_oper(eth_proto_oper, active_speed, |
|---|
| 462 | + active_width); |
|---|
| 463 | +} |
|---|
| 464 | + |
|---|
| 384 | 465 | static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, |
|---|
| 385 | 466 | struct ib_port_attr *props) |
|---|
| 386 | 467 | { |
|---|
| 387 | 468 | struct mlx5_ib_dev *dev = to_mdev(device); |
|---|
| 469 | + u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {0}; |
|---|
| 388 | 470 | struct mlx5_core_dev *mdev; |
|---|
| 389 | 471 | struct net_device *ndev, *upper; |
|---|
| 390 | 472 | enum ib_mtu ndev_ib_mtu; |
|---|
| .. | .. |
|---|
| 392 | 474 | u16 qkey_viol_cntr; |
|---|
| 393 | 475 | u32 eth_prot_oper; |
|---|
| 394 | 476 | u8 mdev_port_num; |
|---|
| 477 | + bool ext; |
|---|
| 395 | 478 | int err; |
|---|
| 396 | 479 | |
|---|
| 397 | 480 | mdev = mlx5_ib_get_native_port_mdev(dev, port_num, &mdev_port_num); |
|---|
| .. | .. |
|---|
| 407 | 490 | |
|---|
| 408 | 491 | /* Possible bad flows are checked before filling out props so in case |
|---|
| 409 | 492 | * of an error it will still be zeroed out. |
|---|
| 493 | + * Use native port in case of reps |
|---|
| 410 | 494 | */ |
|---|
| 411 | | - err = mlx5_query_port_eth_proto_oper(mdev, ð_prot_oper, |
|---|
| 412 | | - mdev_port_num); |
|---|
| 495 | + if (dev->is_rep) |
|---|
| 496 | + err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, |
|---|
| 497 | + 1); |
|---|
| 498 | + else |
|---|
| 499 | + err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, |
|---|
| 500 | + mdev_port_num); |
|---|
| 413 | 501 | if (err) |
|---|
| 414 | 502 | goto out; |
|---|
| 503 | + ext = !!MLX5_GET_ETH_PROTO(ptys_reg, out, true, eth_proto_capability); |
|---|
| 504 | + eth_prot_oper = MLX5_GET_ETH_PROTO(ptys_reg, out, ext, eth_proto_oper); |
|---|
| 415 | 505 | |
|---|
| 416 | 506 | props->active_width = IB_WIDTH_4X; |
|---|
| 417 | 507 | props->active_speed = IB_SPEED_QDR; |
|---|
| 418 | 508 | |
|---|
| 419 | 509 | translate_eth_proto_oper(eth_prot_oper, &props->active_speed, |
|---|
| 420 | | - &props->active_width); |
|---|
| 510 | + &props->active_width, ext); |
|---|
| 421 | 511 | |
|---|
| 422 | 512 | props->port_cap_flags |= IB_PORT_CM_SUP; |
|---|
| 423 | 513 | props->ip_gids = true; |
|---|
| .. | .. |
|---|
| 428 | 518 | props->max_msg_sz = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg); |
|---|
| 429 | 519 | props->pkey_tbl_len = 1; |
|---|
| 430 | 520 | props->state = IB_PORT_DOWN; |
|---|
| 431 | | - props->phys_state = 3; |
|---|
| 521 | + props->phys_state = IB_PORT_PHYS_STATE_DISABLED; |
|---|
| 432 | 522 | |
|---|
| 433 | 523 | mlx5_query_nic_vport_qkey_viol_cntr(mdev, &qkey_viol_cntr); |
|---|
| 434 | 524 | props->qkey_viol_cntr = qkey_viol_cntr; |
|---|
| .. | .. |
|---|
| 441 | 531 | if (!ndev) |
|---|
| 442 | 532 | goto out; |
|---|
| 443 | 533 | |
|---|
| 444 | | - if (mlx5_lag_is_active(dev->mdev)) { |
|---|
| 534 | + if (dev->lag_active) { |
|---|
| 445 | 535 | rcu_read_lock(); |
|---|
| 446 | 536 | upper = netdev_master_upper_dev_get_rcu(ndev); |
|---|
| 447 | 537 | if (upper) { |
|---|
| .. | .. |
|---|
| 454 | 544 | |
|---|
| 455 | 545 | if (netif_running(ndev) && netif_carrier_ok(ndev)) { |
|---|
| 456 | 546 | props->state = IB_PORT_ACTIVE; |
|---|
| 457 | | - props->phys_state = 5; |
|---|
| 547 | + props->phys_state = IB_PORT_PHYS_STATE_LINK_UP; |
|---|
| 458 | 548 | } |
|---|
| 459 | 549 | |
|---|
| 460 | 550 | ndev_ib_mtu = iboe_get_mtu(ndev->mtu); |
|---|
| .. | .. |
|---|
| 472 | 562 | unsigned int index, const union ib_gid *gid, |
|---|
| 473 | 563 | const struct ib_gid_attr *attr) |
|---|
| 474 | 564 | { |
|---|
| 475 | | - enum ib_gid_type gid_type = IB_GID_TYPE_IB; |
|---|
| 565 | + enum ib_gid_type gid_type = IB_GID_TYPE_ROCE; |
|---|
| 566 | + u16 vlan_id = 0xffff; |
|---|
| 476 | 567 | u8 roce_version = 0; |
|---|
| 477 | 568 | u8 roce_l3_type = 0; |
|---|
| 478 | | - bool vlan = false; |
|---|
| 479 | 569 | u8 mac[ETH_ALEN]; |
|---|
| 480 | | - u16 vlan_id = 0; |
|---|
| 570 | + int ret; |
|---|
| 481 | 571 | |
|---|
| 482 | 572 | if (gid) { |
|---|
| 483 | 573 | gid_type = attr->gid_type; |
|---|
| 484 | | - ether_addr_copy(mac, attr->ndev->dev_addr); |
|---|
| 485 | | - |
|---|
| 486 | | - if (is_vlan_dev(attr->ndev)) { |
|---|
| 487 | | - vlan = true; |
|---|
| 488 | | - vlan_id = vlan_dev_vlan_id(attr->ndev); |
|---|
| 489 | | - } |
|---|
| 574 | + ret = rdma_read_gid_l2_fields(attr, &vlan_id, &mac[0]); |
|---|
| 575 | + if (ret) |
|---|
| 576 | + return ret; |
|---|
| 490 | 577 | } |
|---|
| 491 | 578 | |
|---|
| 492 | 579 | switch (gid_type) { |
|---|
| 493 | | - case IB_GID_TYPE_IB: |
|---|
| 580 | + case IB_GID_TYPE_ROCE: |
|---|
| 494 | 581 | roce_version = MLX5_ROCE_VERSION_1; |
|---|
| 495 | 582 | break; |
|---|
| 496 | 583 | case IB_GID_TYPE_ROCE_UDP_ENCAP: |
|---|
| .. | .. |
|---|
| 506 | 593 | } |
|---|
| 507 | 594 | |
|---|
| 508 | 595 | return mlx5_core_roce_gid_set(dev->mdev, index, roce_version, |
|---|
| 509 | | - roce_l3_type, gid->raw, mac, vlan, |
|---|
| 510 | | - vlan_id, port_num); |
|---|
| 596 | + roce_l3_type, gid->raw, mac, |
|---|
| 597 | + vlan_id < VLAN_CFI_MASK, vlan_id, |
|---|
| 598 | + port_num); |
|---|
| 511 | 599 | } |
|---|
| 512 | 600 | |
|---|
| 513 | 601 | static int mlx5_ib_add_gid(const struct ib_gid_attr *attr, |
|---|
| .. | .. |
|---|
| 524 | 612 | attr->index, NULL, NULL); |
|---|
| 525 | 613 | } |
|---|
| 526 | 614 | |
|---|
| 527 | | -__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, |
|---|
| 528 | | - const struct ib_gid_attr *attr) |
|---|
| 615 | +__be16 mlx5_get_roce_udp_sport_min(const struct mlx5_ib_dev *dev, |
|---|
| 616 | + const struct ib_gid_attr *attr) |
|---|
| 529 | 617 | { |
|---|
| 530 | 618 | if (attr->gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP) |
|---|
| 531 | 619 | return 0; |
|---|
| .. | .. |
|---|
| 588 | 676 | get_atomic_caps(dev, atomic_size_qp, props); |
|---|
| 589 | 677 | } |
|---|
| 590 | 678 | |
|---|
| 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 | | -} |
|---|
| 606 | 679 | static int mlx5_query_system_image_guid(struct ib_device *ibdev, |
|---|
| 607 | 680 | __be64 *sys_image_guid) |
|---|
| 608 | 681 | { |
|---|
| .. | .. |
|---|
| 724 | 797 | struct ib_device_attr *props, |
|---|
| 725 | 798 | struct ib_udata *uhw) |
|---|
| 726 | 799 | { |
|---|
| 800 | + size_t uhw_outlen = (uhw) ? uhw->outlen : 0; |
|---|
| 727 | 801 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 728 | 802 | struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 729 | 803 | int err = -ENOMEM; |
|---|
| .. | .. |
|---|
| 737 | 811 | u64 max_tso; |
|---|
| 738 | 812 | |
|---|
| 739 | 813 | resp_len = sizeof(resp.comp_mask) + sizeof(resp.response_length); |
|---|
| 740 | | - if (uhw->outlen && uhw->outlen < resp_len) |
|---|
| 814 | + if (uhw_outlen && uhw_outlen < resp_len) |
|---|
| 741 | 815 | return -EINVAL; |
|---|
| 742 | | - else |
|---|
| 743 | | - resp.response_length = resp_len; |
|---|
| 744 | 816 | |
|---|
| 745 | | - if (uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen)) |
|---|
| 817 | + resp.response_length = resp_len; |
|---|
| 818 | + |
|---|
| 819 | + if (uhw && uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen)) |
|---|
| 746 | 820 | return -EINVAL; |
|---|
| 747 | 821 | |
|---|
| 748 | 822 | memset(props, 0, sizeof(*props)); |
|---|
| .. | .. |
|---|
| 782 | 856 | /* We support 'Gappy' memory registration too */ |
|---|
| 783 | 857 | props->device_cap_flags |= IB_DEVICE_SG_GAPS_REG; |
|---|
| 784 | 858 | } |
|---|
| 785 | | - props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
|---|
| 859 | + /* IB_WR_REG_MR always requires changing the entity size with UMR */ |
|---|
| 860 | + if (!MLX5_CAP_GEN(dev->mdev, umr_modify_entity_size_disabled)) |
|---|
| 861 | + props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
|---|
| 786 | 862 | if (MLX5_CAP_GEN(mdev, sho)) { |
|---|
| 787 | | - props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER; |
|---|
| 863 | + props->device_cap_flags |= IB_DEVICE_INTEGRITY_HANDOVER; |
|---|
| 788 | 864 | /* At this stage no support for signature handover */ |
|---|
| 789 | 865 | props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 | |
|---|
| 790 | 866 | IB_PROT_T10DIF_TYPE_2 | |
|---|
| .. | .. |
|---|
| 806 | 882 | props->raw_packet_caps |= |
|---|
| 807 | 883 | IB_RAW_PACKET_CAP_CVLAN_STRIPPING; |
|---|
| 808 | 884 | |
|---|
| 809 | | - if (field_avail(typeof(resp), tso_caps, uhw->outlen)) { |
|---|
| 885 | + if (offsetofend(typeof(resp), tso_caps) <= uhw_outlen) { |
|---|
| 810 | 886 | max_tso = MLX5_CAP_ETH(mdev, max_lso_cap); |
|---|
| 811 | 887 | if (max_tso) { |
|---|
| 812 | 888 | resp.tso_caps.max_tso = 1 << max_tso; |
|---|
| .. | .. |
|---|
| 816 | 892 | } |
|---|
| 817 | 893 | } |
|---|
| 818 | 894 | |
|---|
| 819 | | - if (field_avail(typeof(resp), rss_caps, uhw->outlen)) { |
|---|
| 895 | + if (offsetofend(typeof(resp), rss_caps) <= uhw_outlen) { |
|---|
| 820 | 896 | resp.rss_caps.rx_hash_function = |
|---|
| 821 | 897 | MLX5_RX_HASH_FUNC_TOEPLITZ; |
|---|
| 822 | 898 | resp.rss_caps.rx_hash_fields_mask = |
|---|
| .. | .. |
|---|
| 836 | 912 | resp.response_length += sizeof(resp.rss_caps); |
|---|
| 837 | 913 | } |
|---|
| 838 | 914 | } else { |
|---|
| 839 | | - if (field_avail(typeof(resp), tso_caps, uhw->outlen)) |
|---|
| 915 | + if (offsetofend(typeof(resp), tso_caps) <= uhw_outlen) |
|---|
| 840 | 916 | resp.response_length += sizeof(resp.tso_caps); |
|---|
| 841 | | - if (field_avail(typeof(resp), rss_caps, uhw->outlen)) |
|---|
| 917 | + if (offsetofend(typeof(resp), rss_caps) <= uhw_outlen) |
|---|
| 842 | 918 | resp.response_length += sizeof(resp.rss_caps); |
|---|
| 843 | 919 | } |
|---|
| 844 | 920 | |
|---|
| .. | .. |
|---|
| 904 | 980 | props->max_srq_sge = max_rq_sg - 1; |
|---|
| 905 | 981 | props->max_fast_reg_page_list_len = |
|---|
| 906 | 982 | 1 << MLX5_CAP_GEN(mdev, log_max_klm_list_size); |
|---|
| 983 | + props->max_pi_fast_reg_page_list_len = |
|---|
| 984 | + props->max_fast_reg_page_list_len / 2; |
|---|
| 985 | + props->max_sgl_rd = |
|---|
| 986 | + MLX5_CAP_GEN(mdev, max_sgl_for_optimized_performance); |
|---|
| 907 | 987 | get_atomic_caps_qp(dev, props); |
|---|
| 908 | 988 | props->masked_atomic_cap = IB_ATOMIC_NONE; |
|---|
| 909 | 989 | props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg); |
|---|
| 910 | 990 | props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg); |
|---|
| 911 | 991 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
|---|
| 912 | 992 | props->max_mcast_grp; |
|---|
| 913 | | - props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */ |
|---|
| 914 | 993 | props->max_ah = INT_MAX; |
|---|
| 915 | 994 | props->hca_core_clock = MLX5_CAP_GEN(mdev, device_frequency_khz); |
|---|
| 916 | 995 | props->timestamp_mask = 0x7FFFFFFFFFFFFFFFULL; |
|---|
| 917 | 996 | |
|---|
| 918 | | -#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
|---|
| 919 | | - if (MLX5_CAP_GEN(mdev, pg)) |
|---|
| 920 | | - props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
|---|
| 921 | | - props->odp_caps = dev->odp_caps; |
|---|
| 922 | | -#endif |
|---|
| 997 | + if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { |
|---|
| 998 | + if (dev->odp_caps.general_caps & IB_ODP_SUPPORT) |
|---|
| 999 | + props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING; |
|---|
| 1000 | + props->odp_caps = dev->odp_caps; |
|---|
| 1001 | + if (!uhw) { |
|---|
| 1002 | + /* ODP for kernel QPs is not implemented for receive |
|---|
| 1003 | + * WQEs and SRQ WQEs |
|---|
| 1004 | + */ |
|---|
| 1005 | + props->odp_caps.per_transport_caps.rc_odp_caps &= |
|---|
| 1006 | + ~(IB_ODP_SUPPORT_READ | |
|---|
| 1007 | + IB_ODP_SUPPORT_SRQ_RECV); |
|---|
| 1008 | + props->odp_caps.per_transport_caps.uc_odp_caps &= |
|---|
| 1009 | + ~(IB_ODP_SUPPORT_READ | |
|---|
| 1010 | + IB_ODP_SUPPORT_SRQ_RECV); |
|---|
| 1011 | + props->odp_caps.per_transport_caps.ud_odp_caps &= |
|---|
| 1012 | + ~(IB_ODP_SUPPORT_READ | |
|---|
| 1013 | + IB_ODP_SUPPORT_SRQ_RECV); |
|---|
| 1014 | + props->odp_caps.per_transport_caps.xrc_odp_caps &= |
|---|
| 1015 | + ~(IB_ODP_SUPPORT_READ | |
|---|
| 1016 | + IB_ODP_SUPPORT_SRQ_RECV); |
|---|
| 1017 | + } |
|---|
| 1018 | + } |
|---|
| 923 | 1019 | |
|---|
| 924 | 1020 | if (MLX5_CAP_GEN(mdev, cd)) |
|---|
| 925 | 1021 | props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL; |
|---|
| 926 | 1022 | |
|---|
| 927 | | - if (!mlx5_core_is_pf(mdev)) |
|---|
| 1023 | + if (mlx5_core_is_vf(mdev)) |
|---|
| 928 | 1024 | props->device_cap_flags |= IB_DEVICE_VIRTUAL_FUNCTION; |
|---|
| 929 | 1025 | |
|---|
| 930 | 1026 | if (mlx5_ib_port_link_layer(ibdev, 1) == |
|---|
| .. | .. |
|---|
| 959 | 1055 | MLX5_MAX_CQ_PERIOD; |
|---|
| 960 | 1056 | } |
|---|
| 961 | 1057 | |
|---|
| 962 | | - if (field_avail(typeof(resp), cqe_comp_caps, uhw->outlen)) { |
|---|
| 1058 | + if (offsetofend(typeof(resp), cqe_comp_caps) <= uhw_outlen) { |
|---|
| 963 | 1059 | resp.response_length += sizeof(resp.cqe_comp_caps); |
|---|
| 964 | 1060 | |
|---|
| 965 | 1061 | if (MLX5_CAP_GEN(dev->mdev, cqe_compression)) { |
|---|
| .. | .. |
|---|
| 977 | 1073 | } |
|---|
| 978 | 1074 | } |
|---|
| 979 | 1075 | |
|---|
| 980 | | - if (field_avail(typeof(resp), packet_pacing_caps, uhw->outlen) && |
|---|
| 1076 | + if (offsetofend(typeof(resp), packet_pacing_caps) <= uhw_outlen && |
|---|
| 981 | 1077 | raw_support) { |
|---|
| 982 | 1078 | if (MLX5_CAP_QOS(mdev, packet_pacing) && |
|---|
| 983 | 1079 | MLX5_CAP_GEN(mdev, qos)) { |
|---|
| .. | .. |
|---|
| 995 | 1091 | resp.response_length += sizeof(resp.packet_pacing_caps); |
|---|
| 996 | 1092 | } |
|---|
| 997 | 1093 | |
|---|
| 998 | | - if (field_avail(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes, |
|---|
| 999 | | - uhw->outlen)) { |
|---|
| 1094 | + if (offsetofend(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes) <= |
|---|
| 1095 | + uhw_outlen) { |
|---|
| 1000 | 1096 | if (MLX5_CAP_ETH(mdev, multi_pkt_send_wqe)) |
|---|
| 1001 | 1097 | resp.mlx5_ib_support_multi_pkt_send_wqes = |
|---|
| 1002 | 1098 | MLX5_IB_ALLOW_MPW; |
|---|
| .. | .. |
|---|
| 1009 | 1105 | sizeof(resp.mlx5_ib_support_multi_pkt_send_wqes); |
|---|
| 1010 | 1106 | } |
|---|
| 1011 | 1107 | |
|---|
| 1012 | | - if (field_avail(typeof(resp), flags, uhw->outlen)) { |
|---|
| 1108 | + if (offsetofend(typeof(resp), flags) <= uhw_outlen) { |
|---|
| 1013 | 1109 | resp.response_length += sizeof(resp.flags); |
|---|
| 1014 | 1110 | |
|---|
| 1015 | 1111 | if (MLX5_CAP_GEN(mdev, cqe_compression_128)) |
|---|
| .. | .. |
|---|
| 1018 | 1114 | |
|---|
| 1019 | 1115 | if (MLX5_CAP_GEN(mdev, cqe_128_always)) |
|---|
| 1020 | 1116 | resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_PAD; |
|---|
| 1117 | + if (MLX5_CAP_GEN(mdev, qp_packet_based)) |
|---|
| 1118 | + resp.flags |= |
|---|
| 1119 | + MLX5_IB_QUERY_DEV_RESP_PACKET_BASED_CREDIT_MODE; |
|---|
| 1120 | + |
|---|
| 1121 | + resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_SCAT2CQE_DCT; |
|---|
| 1021 | 1122 | } |
|---|
| 1022 | 1123 | |
|---|
| 1023 | | - if (field_avail(typeof(resp), sw_parsing_caps, |
|---|
| 1024 | | - uhw->outlen)) { |
|---|
| 1124 | + if (offsetofend(typeof(resp), sw_parsing_caps) <= uhw_outlen) { |
|---|
| 1025 | 1125 | resp.response_length += sizeof(resp.sw_parsing_caps); |
|---|
| 1026 | 1126 | if (MLX5_CAP_ETH(mdev, swp)) { |
|---|
| 1027 | 1127 | resp.sw_parsing_caps.sw_parsing_offloads |= |
|---|
| .. | .. |
|---|
| 1041 | 1141 | } |
|---|
| 1042 | 1142 | } |
|---|
| 1043 | 1143 | |
|---|
| 1044 | | - if (field_avail(typeof(resp), striding_rq_caps, uhw->outlen) && |
|---|
| 1144 | + if (offsetofend(typeof(resp), striding_rq_caps) <= uhw_outlen && |
|---|
| 1045 | 1145 | raw_support) { |
|---|
| 1046 | 1146 | resp.response_length += sizeof(resp.striding_rq_caps); |
|---|
| 1047 | 1147 | if (MLX5_CAP_GEN(mdev, striding_rq)) { |
|---|
| .. | .. |
|---|
| 1049 | 1149 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES; |
|---|
| 1050 | 1150 | resp.striding_rq_caps.max_single_stride_log_num_of_bytes = |
|---|
| 1051 | 1151 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES; |
|---|
| 1052 | | - resp.striding_rq_caps.min_single_wqe_log_num_of_strides = |
|---|
| 1053 | | - MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES; |
|---|
| 1152 | + if (MLX5_CAP_GEN(dev->mdev, ext_stride_num_range)) |
|---|
| 1153 | + resp.striding_rq_caps |
|---|
| 1154 | + .min_single_wqe_log_num_of_strides = |
|---|
| 1155 | + MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES; |
|---|
| 1156 | + else |
|---|
| 1157 | + resp.striding_rq_caps |
|---|
| 1158 | + .min_single_wqe_log_num_of_strides = |
|---|
| 1159 | + MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES; |
|---|
| 1054 | 1160 | resp.striding_rq_caps.max_single_wqe_log_num_of_strides = |
|---|
| 1055 | 1161 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES; |
|---|
| 1056 | 1162 | resp.striding_rq_caps.supported_qpts = |
|---|
| .. | .. |
|---|
| 1058 | 1164 | } |
|---|
| 1059 | 1165 | } |
|---|
| 1060 | 1166 | |
|---|
| 1061 | | - if (field_avail(typeof(resp), tunnel_offloads_caps, |
|---|
| 1062 | | - uhw->outlen)) { |
|---|
| 1167 | + if (offsetofend(typeof(resp), tunnel_offloads_caps) <= uhw_outlen) { |
|---|
| 1063 | 1168 | resp.response_length += sizeof(resp.tunnel_offloads_caps); |
|---|
| 1064 | 1169 | if (MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan)) |
|---|
| 1065 | 1170 | resp.tunnel_offloads_caps |= |
|---|
| .. | .. |
|---|
| 1078 | 1183 | MLX5_IB_TUNNELED_OFFLOADS_MPLS_UDP; |
|---|
| 1079 | 1184 | } |
|---|
| 1080 | 1185 | |
|---|
| 1081 | | - if (uhw->outlen) { |
|---|
| 1186 | + if (uhw_outlen) { |
|---|
| 1082 | 1187 | err = ib_copy_to_udata(uhw, &resp, resp.response_length); |
|---|
| 1083 | 1188 | |
|---|
| 1084 | 1189 | if (err) |
|---|
| .. | .. |
|---|
| 1088 | 1193 | return 0; |
|---|
| 1089 | 1194 | } |
|---|
| 1090 | 1195 | |
|---|
| 1091 | | -enum mlx5_ib_width { |
|---|
| 1092 | | - MLX5_IB_WIDTH_1X = 1 << 0, |
|---|
| 1093 | | - MLX5_IB_WIDTH_2X = 1 << 1, |
|---|
| 1094 | | - MLX5_IB_WIDTH_4X = 1 << 2, |
|---|
| 1095 | | - MLX5_IB_WIDTH_8X = 1 << 3, |
|---|
| 1096 | | - MLX5_IB_WIDTH_12X = 1 << 4 |
|---|
| 1097 | | -}; |
|---|
| 1098 | | - |
|---|
| 1099 | | -static void translate_active_width(struct ib_device *ibdev, u8 active_width, |
|---|
| 1100 | | - u8 *ib_width) |
|---|
| 1196 | +static void translate_active_width(struct ib_device *ibdev, u16 active_width, |
|---|
| 1197 | + u8 *ib_width) |
|---|
| 1101 | 1198 | { |
|---|
| 1102 | 1199 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 1103 | 1200 | |
|---|
| 1104 | | - if (active_width & MLX5_IB_WIDTH_1X) |
|---|
| 1201 | + if (active_width & MLX5_PTYS_WIDTH_1X) |
|---|
| 1105 | 1202 | *ib_width = IB_WIDTH_1X; |
|---|
| 1106 | | - else if (active_width & MLX5_IB_WIDTH_4X) |
|---|
| 1203 | + else if (active_width & MLX5_PTYS_WIDTH_2X) |
|---|
| 1204 | + *ib_width = IB_WIDTH_2X; |
|---|
| 1205 | + else if (active_width & MLX5_PTYS_WIDTH_4X) |
|---|
| 1107 | 1206 | *ib_width = IB_WIDTH_4X; |
|---|
| 1108 | | - else if (active_width & MLX5_IB_WIDTH_8X) |
|---|
| 1207 | + else if (active_width & MLX5_PTYS_WIDTH_8X) |
|---|
| 1109 | 1208 | *ib_width = IB_WIDTH_8X; |
|---|
| 1110 | | - else if (active_width & MLX5_IB_WIDTH_12X) |
|---|
| 1209 | + else if (active_width & MLX5_PTYS_WIDTH_12X) |
|---|
| 1111 | 1210 | *ib_width = IB_WIDTH_12X; |
|---|
| 1112 | 1211 | else { |
|---|
| 1113 | 1212 | mlx5_ib_dbg(dev, "Invalid active_width %d, setting width to default value: 4x\n", |
|---|
| 1114 | | - (int)active_width); |
|---|
| 1213 | + active_width); |
|---|
| 1115 | 1214 | *ib_width = IB_WIDTH_4X; |
|---|
| 1116 | 1215 | } |
|---|
| 1117 | 1216 | |
|---|
| .. | .. |
|---|
| 1188 | 1287 | u16 max_mtu; |
|---|
| 1189 | 1288 | u16 oper_mtu; |
|---|
| 1190 | 1289 | int err; |
|---|
| 1191 | | - u8 ib_link_width_oper; |
|---|
| 1290 | + u16 ib_link_width_oper; |
|---|
| 1192 | 1291 | u8 vl_hw_cap; |
|---|
| 1193 | 1292 | |
|---|
| 1194 | 1293 | rep = kzalloc(sizeof(*rep), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 1218 | 1317 | props->subnet_timeout = rep->subnet_timeout; |
|---|
| 1219 | 1318 | props->init_type_reply = rep->init_type_reply; |
|---|
| 1220 | 1319 | |
|---|
| 1221 | | - err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); |
|---|
| 1320 | + if (props->port_cap_flags & IB_PORT_CAP_MASK2_SUP) |
|---|
| 1321 | + props->port_cap_flags2 = rep->cap_mask2; |
|---|
| 1322 | + |
|---|
| 1323 | + err = mlx5_query_ib_port_oper(mdev, &ib_link_width_oper, |
|---|
| 1324 | + &props->active_speed, port); |
|---|
| 1222 | 1325 | if (err) |
|---|
| 1223 | 1326 | goto out; |
|---|
| 1224 | 1327 | |
|---|
| 1225 | 1328 | translate_active_width(ibdev, ib_link_width_oper, &props->active_width); |
|---|
| 1226 | | - |
|---|
| 1227 | | - err = mlx5_query_port_ib_proto_oper(mdev, &props->active_speed, port); |
|---|
| 1228 | | - if (err) |
|---|
| 1229 | | - goto out; |
|---|
| 1230 | 1329 | |
|---|
| 1231 | 1330 | mlx5_query_port_max_mtu(mdev, &max_mtu, port); |
|---|
| 1232 | 1331 | |
|---|
| .. | .. |
|---|
| 1297 | 1396 | { |
|---|
| 1298 | 1397 | int ret; |
|---|
| 1299 | 1398 | |
|---|
| 1300 | | - /* Only link layer == ethernet is valid for representors */ |
|---|
| 1399 | + /* Only link layer == ethernet is valid for representors |
|---|
| 1400 | + * and we always use port 1 |
|---|
| 1401 | + */ |
|---|
| 1301 | 1402 | ret = mlx5_query_port_roce(ibdev, port, props); |
|---|
| 1302 | 1403 | if (ret || !props) |
|---|
| 1303 | 1404 | return ret; |
|---|
| .. | .. |
|---|
| 1566 | 1667 | mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i]); |
|---|
| 1567 | 1668 | } |
|---|
| 1568 | 1669 | |
|---|
| 1569 | | -static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn) |
|---|
| 1670 | +int mlx5_ib_enable_lb(struct mlx5_ib_dev *dev, bool td, bool qp) |
|---|
| 1671 | +{ |
|---|
| 1672 | + int err = 0; |
|---|
| 1673 | + |
|---|
| 1674 | + mutex_lock(&dev->lb.mutex); |
|---|
| 1675 | + if (td) |
|---|
| 1676 | + dev->lb.user_td++; |
|---|
| 1677 | + if (qp) |
|---|
| 1678 | + dev->lb.qps++; |
|---|
| 1679 | + |
|---|
| 1680 | + if (dev->lb.user_td == 2 || |
|---|
| 1681 | + dev->lb.qps == 1) { |
|---|
| 1682 | + if (!dev->lb.enabled) { |
|---|
| 1683 | + err = mlx5_nic_vport_update_local_lb(dev->mdev, true); |
|---|
| 1684 | + dev->lb.enabled = true; |
|---|
| 1685 | + } |
|---|
| 1686 | + } |
|---|
| 1687 | + |
|---|
| 1688 | + mutex_unlock(&dev->lb.mutex); |
|---|
| 1689 | + |
|---|
| 1690 | + return err; |
|---|
| 1691 | +} |
|---|
| 1692 | + |
|---|
| 1693 | +void mlx5_ib_disable_lb(struct mlx5_ib_dev *dev, bool td, bool qp) |
|---|
| 1694 | +{ |
|---|
| 1695 | + mutex_lock(&dev->lb.mutex); |
|---|
| 1696 | + if (td) |
|---|
| 1697 | + dev->lb.user_td--; |
|---|
| 1698 | + if (qp) |
|---|
| 1699 | + dev->lb.qps--; |
|---|
| 1700 | + |
|---|
| 1701 | + if (dev->lb.user_td == 1 && |
|---|
| 1702 | + dev->lb.qps == 0) { |
|---|
| 1703 | + if (dev->lb.enabled) { |
|---|
| 1704 | + mlx5_nic_vport_update_local_lb(dev->mdev, false); |
|---|
| 1705 | + dev->lb.enabled = false; |
|---|
| 1706 | + } |
|---|
| 1707 | + } |
|---|
| 1708 | + |
|---|
| 1709 | + mutex_unlock(&dev->lb.mutex); |
|---|
| 1710 | +} |
|---|
| 1711 | + |
|---|
| 1712 | +static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn, |
|---|
| 1713 | + u16 uid) |
|---|
| 1570 | 1714 | { |
|---|
| 1571 | 1715 | int err; |
|---|
| 1572 | 1716 | |
|---|
| 1573 | 1717 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
|---|
| 1574 | 1718 | return 0; |
|---|
| 1575 | 1719 | |
|---|
| 1576 | | - err = mlx5_core_alloc_transport_domain(dev->mdev, tdn); |
|---|
| 1720 | + err = mlx5_cmd_alloc_transport_domain(dev->mdev, tdn, uid); |
|---|
| 1577 | 1721 | if (err) |
|---|
| 1578 | 1722 | return err; |
|---|
| 1579 | 1723 | |
|---|
| .. | .. |
|---|
| 1582 | 1726 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
|---|
| 1583 | 1727 | return err; |
|---|
| 1584 | 1728 | |
|---|
| 1585 | | - mutex_lock(&dev->lb_mutex); |
|---|
| 1586 | | - dev->user_td++; |
|---|
| 1587 | | - |
|---|
| 1588 | | - if (dev->user_td == 2) |
|---|
| 1589 | | - err = mlx5_nic_vport_update_local_lb(dev->mdev, true); |
|---|
| 1590 | | - |
|---|
| 1591 | | - mutex_unlock(&dev->lb_mutex); |
|---|
| 1592 | | - return err; |
|---|
| 1729 | + return mlx5_ib_enable_lb(dev, true, false); |
|---|
| 1593 | 1730 | } |
|---|
| 1594 | 1731 | |
|---|
| 1595 | | -static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn) |
|---|
| 1732 | +static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn, |
|---|
| 1733 | + u16 uid) |
|---|
| 1596 | 1734 | { |
|---|
| 1597 | 1735 | if (!MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) |
|---|
| 1598 | 1736 | return; |
|---|
| 1599 | 1737 | |
|---|
| 1600 | | - mlx5_core_dealloc_transport_domain(dev->mdev, tdn); |
|---|
| 1738 | + mlx5_cmd_dealloc_transport_domain(dev->mdev, tdn, uid); |
|---|
| 1601 | 1739 | |
|---|
| 1602 | 1740 | if ((MLX5_CAP_GEN(dev->mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH) || |
|---|
| 1603 | 1741 | (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) && |
|---|
| 1604 | 1742 | !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
|---|
| 1605 | 1743 | return; |
|---|
| 1606 | 1744 | |
|---|
| 1607 | | - mutex_lock(&dev->lb_mutex); |
|---|
| 1608 | | - dev->user_td--; |
|---|
| 1609 | | - |
|---|
| 1610 | | - if (dev->user_td < 2) |
|---|
| 1611 | | - mlx5_nic_vport_update_local_lb(dev->mdev, false); |
|---|
| 1612 | | - |
|---|
| 1613 | | - mutex_unlock(&dev->lb_mutex); |
|---|
| 1745 | + mlx5_ib_disable_lb(dev, true, false); |
|---|
| 1614 | 1746 | } |
|---|
| 1615 | 1747 | |
|---|
| 1616 | | -static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev, |
|---|
| 1617 | | - struct ib_udata *udata) |
|---|
| 1748 | +static int set_ucontext_resp(struct ib_ucontext *uctx, |
|---|
| 1749 | + struct mlx5_ib_alloc_ucontext_resp *resp) |
|---|
| 1618 | 1750 | { |
|---|
| 1751 | + struct ib_device *ibdev = uctx->device; |
|---|
| 1752 | + struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 1753 | + struct mlx5_ib_ucontext *context = to_mucontext(uctx); |
|---|
| 1754 | + struct mlx5_bfreg_info *bfregi = &context->bfregi; |
|---|
| 1755 | + int err; |
|---|
| 1756 | + |
|---|
| 1757 | + if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
|---|
| 1758 | + err = mlx5_cmd_dump_fill_mkey(dev->mdev, |
|---|
| 1759 | + &resp->dump_fill_mkey); |
|---|
| 1760 | + if (err) |
|---|
| 1761 | + return err; |
|---|
| 1762 | + resp->comp_mask |= |
|---|
| 1763 | + MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_DUMP_FILL_MKEY; |
|---|
| 1764 | + } |
|---|
| 1765 | + |
|---|
| 1766 | + resp->qp_tab_size = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp); |
|---|
| 1767 | + if (dev->wc_support) |
|---|
| 1768 | + resp->bf_reg_size = 1 << MLX5_CAP_GEN(dev->mdev, |
|---|
| 1769 | + log_bf_reg_size); |
|---|
| 1770 | + resp->cache_line_size = cache_line_size(); |
|---|
| 1771 | + resp->max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); |
|---|
| 1772 | + resp->max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); |
|---|
| 1773 | + resp->max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
|---|
| 1774 | + resp->max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
|---|
| 1775 | + resp->max_srq_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz); |
|---|
| 1776 | + resp->cqe_version = context->cqe_version; |
|---|
| 1777 | + resp->log_uar_size = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
|---|
| 1778 | + MLX5_ADAPTER_PAGE_SHIFT : PAGE_SHIFT; |
|---|
| 1779 | + resp->num_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
|---|
| 1780 | + MLX5_CAP_GEN(dev->mdev, |
|---|
| 1781 | + num_of_uars_per_page) : 1; |
|---|
| 1782 | + |
|---|
| 1783 | + if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
|---|
| 1784 | + MLX5_ACCEL_IPSEC_CAP_DEVICE) { |
|---|
| 1785 | + if (mlx5_get_flow_namespace(dev->mdev, |
|---|
| 1786 | + MLX5_FLOW_NAMESPACE_EGRESS)) |
|---|
| 1787 | + resp->flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM; |
|---|
| 1788 | + if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
|---|
| 1789 | + MLX5_ACCEL_IPSEC_CAP_REQUIRED_METADATA) |
|---|
| 1790 | + resp->flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_REQ_METADATA; |
|---|
| 1791 | + if (MLX5_CAP_FLOWTABLE(dev->mdev, flow_table_properties_nic_receive.ft_field_support.outer_esp_spi)) |
|---|
| 1792 | + resp->flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_SPI_STEERING; |
|---|
| 1793 | + if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
|---|
| 1794 | + MLX5_ACCEL_IPSEC_CAP_TX_IV_IS_ESN) |
|---|
| 1795 | + resp->flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_TX_IV_IS_ESN; |
|---|
| 1796 | + /* MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_FULL_OFFLOAD is currently always 0 */ |
|---|
| 1797 | + } |
|---|
| 1798 | + |
|---|
| 1799 | + resp->tot_bfregs = bfregi->lib_uar_dyn ? 0 : |
|---|
| 1800 | + bfregi->total_num_bfregs - bfregi->num_dyn_bfregs; |
|---|
| 1801 | + resp->num_ports = dev->num_ports; |
|---|
| 1802 | + resp->cmds_supp_uhw |= MLX5_USER_CMDS_SUPP_UHW_QUERY_DEVICE | |
|---|
| 1803 | + MLX5_USER_CMDS_SUPP_UHW_CREATE_AH; |
|---|
| 1804 | + |
|---|
| 1805 | + if (mlx5_ib_port_link_layer(ibdev, 1) == IB_LINK_LAYER_ETHERNET) { |
|---|
| 1806 | + mlx5_query_min_inline(dev->mdev, &resp->eth_min_inline); |
|---|
| 1807 | + resp->eth_min_inline++; |
|---|
| 1808 | + } |
|---|
| 1809 | + |
|---|
| 1810 | + if (dev->mdev->clock_info) |
|---|
| 1811 | + resp->clock_info_versions = BIT(MLX5_IB_CLOCK_INFO_V1); |
|---|
| 1812 | + |
|---|
| 1813 | + /* |
|---|
| 1814 | + * We don't want to expose information from the PCI bar that is located |
|---|
| 1815 | + * after 4096 bytes, so if the arch only supports larger pages, let's |
|---|
| 1816 | + * pretend we don't support reading the HCA's core clock. This is also |
|---|
| 1817 | + * forced by mmap function. |
|---|
| 1818 | + */ |
|---|
| 1819 | + if (PAGE_SIZE <= 4096) { |
|---|
| 1820 | + resp->comp_mask |= |
|---|
| 1821 | + MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET; |
|---|
| 1822 | + resp->hca_core_clock_offset = |
|---|
| 1823 | + offsetof(struct mlx5_init_seg, |
|---|
| 1824 | + internal_timer_h) % PAGE_SIZE; |
|---|
| 1825 | + } |
|---|
| 1826 | + |
|---|
| 1827 | + if (MLX5_CAP_GEN(dev->mdev, ece_support)) |
|---|
| 1828 | + resp->comp_mask |= MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_ECE; |
|---|
| 1829 | + |
|---|
| 1830 | + resp->num_dyn_bfregs = bfregi->num_dyn_bfregs; |
|---|
| 1831 | + return 0; |
|---|
| 1832 | +} |
|---|
| 1833 | + |
|---|
| 1834 | +static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx, |
|---|
| 1835 | + struct ib_udata *udata) |
|---|
| 1836 | +{ |
|---|
| 1837 | + struct ib_device *ibdev = uctx->device; |
|---|
| 1619 | 1838 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 1620 | 1839 | struct mlx5_ib_alloc_ucontext_req_v2 req = {}; |
|---|
| 1621 | 1840 | struct mlx5_ib_alloc_ucontext_resp resp = {}; |
|---|
| 1622 | | - struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 1623 | | - struct mlx5_ib_ucontext *context; |
|---|
| 1841 | + struct mlx5_ib_ucontext *context = to_mucontext(uctx); |
|---|
| 1624 | 1842 | struct mlx5_bfreg_info *bfregi; |
|---|
| 1625 | 1843 | int ver; |
|---|
| 1626 | 1844 | int err; |
|---|
| 1627 | 1845 | size_t min_req_v2 = offsetof(struct mlx5_ib_alloc_ucontext_req_v2, |
|---|
| 1628 | 1846 | max_cqe_version); |
|---|
| 1629 | | - u32 dump_fill_mkey; |
|---|
| 1630 | 1847 | bool lib_uar_4k; |
|---|
| 1848 | + bool lib_uar_dyn; |
|---|
| 1631 | 1849 | |
|---|
| 1632 | 1850 | if (!dev->ib_active) |
|---|
| 1633 | | - return ERR_PTR(-EAGAIN); |
|---|
| 1851 | + return -EAGAIN; |
|---|
| 1634 | 1852 | |
|---|
| 1635 | 1853 | if (udata->inlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) |
|---|
| 1636 | 1854 | ver = 0; |
|---|
| 1637 | 1855 | else if (udata->inlen >= min_req_v2) |
|---|
| 1638 | 1856 | ver = 2; |
|---|
| 1639 | 1857 | else |
|---|
| 1640 | | - return ERR_PTR(-EINVAL); |
|---|
| 1858 | + return -EINVAL; |
|---|
| 1641 | 1859 | |
|---|
| 1642 | 1860 | err = ib_copy_from_udata(&req, udata, min(udata->inlen, sizeof(req))); |
|---|
| 1643 | 1861 | if (err) |
|---|
| 1644 | | - return ERR_PTR(err); |
|---|
| 1862 | + return err; |
|---|
| 1645 | 1863 | |
|---|
| 1646 | 1864 | if (req.flags & ~MLX5_IB_ALLOC_UCTX_DEVX) |
|---|
| 1647 | | - return ERR_PTR(-EOPNOTSUPP); |
|---|
| 1865 | + return -EOPNOTSUPP; |
|---|
| 1648 | 1866 | |
|---|
| 1649 | 1867 | if (req.comp_mask || req.reserved0 || req.reserved1 || req.reserved2) |
|---|
| 1650 | | - return ERR_PTR(-EOPNOTSUPP); |
|---|
| 1868 | + return -EOPNOTSUPP; |
|---|
| 1651 | 1869 | |
|---|
| 1652 | 1870 | req.total_num_bfregs = ALIGN(req.total_num_bfregs, |
|---|
| 1653 | 1871 | MLX5_NON_FP_BFREGS_PER_UAR); |
|---|
| 1654 | 1872 | if (req.num_low_latency_bfregs > req.total_num_bfregs - 1) |
|---|
| 1655 | | - return ERR_PTR(-EINVAL); |
|---|
| 1656 | | - |
|---|
| 1657 | | - resp.qp_tab_size = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp); |
|---|
| 1658 | | - if (mlx5_core_is_pf(dev->mdev) && MLX5_CAP_GEN(dev->mdev, bf)) |
|---|
| 1659 | | - resp.bf_reg_size = 1 << MLX5_CAP_GEN(dev->mdev, log_bf_reg_size); |
|---|
| 1660 | | - resp.cache_line_size = cache_line_size(); |
|---|
| 1661 | | - resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); |
|---|
| 1662 | | - resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); |
|---|
| 1663 | | - resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
|---|
| 1664 | | - resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); |
|---|
| 1665 | | - resp.max_srq_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz); |
|---|
| 1666 | | - resp.cqe_version = min_t(__u8, |
|---|
| 1667 | | - (__u8)MLX5_CAP_GEN(dev->mdev, cqe_version), |
|---|
| 1668 | | - req.max_cqe_version); |
|---|
| 1669 | | - resp.log_uar_size = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
|---|
| 1670 | | - MLX5_ADAPTER_PAGE_SHIFT : PAGE_SHIFT; |
|---|
| 1671 | | - resp.num_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
|---|
| 1672 | | - MLX5_CAP_GEN(dev->mdev, num_of_uars_per_page) : 1; |
|---|
| 1673 | | - resp.response_length = min(offsetof(typeof(resp), response_length) + |
|---|
| 1674 | | - sizeof(resp.response_length), udata->outlen); |
|---|
| 1675 | | - |
|---|
| 1676 | | - if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_DEVICE) { |
|---|
| 1677 | | - if (mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_EGRESS)) |
|---|
| 1678 | | - resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM; |
|---|
| 1679 | | - if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_REQUIRED_METADATA) |
|---|
| 1680 | | - resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_REQ_METADATA; |
|---|
| 1681 | | - if (MLX5_CAP_FLOWTABLE(dev->mdev, flow_table_properties_nic_receive.ft_field_support.outer_esp_spi)) |
|---|
| 1682 | | - resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_SPI_STEERING; |
|---|
| 1683 | | - if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_TX_IV_IS_ESN) |
|---|
| 1684 | | - resp.flow_action_flags |= MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_TX_IV_IS_ESN; |
|---|
| 1685 | | - /* MLX5_USER_ALLOC_UCONTEXT_FLOW_ACTION_FLAGS_ESP_AES_GCM_FULL_OFFLOAD is currently always 0 */ |
|---|
| 1686 | | - } |
|---|
| 1687 | | - |
|---|
| 1688 | | - context = kzalloc(sizeof(*context), GFP_KERNEL); |
|---|
| 1689 | | - if (!context) |
|---|
| 1690 | | - return ERR_PTR(-ENOMEM); |
|---|
| 1873 | + return -EINVAL; |
|---|
| 1691 | 1874 | |
|---|
| 1692 | 1875 | lib_uar_4k = req.lib_caps & MLX5_LIB_CAP_4K_UAR; |
|---|
| 1876 | + lib_uar_dyn = req.lib_caps & MLX5_LIB_CAP_DYN_UAR; |
|---|
| 1693 | 1877 | bfregi = &context->bfregi; |
|---|
| 1878 | + |
|---|
| 1879 | + if (lib_uar_dyn) { |
|---|
| 1880 | + bfregi->lib_uar_dyn = lib_uar_dyn; |
|---|
| 1881 | + goto uar_done; |
|---|
| 1882 | + } |
|---|
| 1694 | 1883 | |
|---|
| 1695 | 1884 | /* updates req->total_num_bfregs */ |
|---|
| 1696 | 1885 | err = calc_total_bfregs(dev, lib_uar_4k, &req, bfregi); |
|---|
| .. | .. |
|---|
| 1718 | 1907 | if (err) |
|---|
| 1719 | 1908 | goto out_sys_pages; |
|---|
| 1720 | 1909 | |
|---|
| 1721 | | -#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
|---|
| 1722 | | - context->ibucontext.invalidate_range = &mlx5_ib_invalidate_range; |
|---|
| 1723 | | -#endif |
|---|
| 1724 | | - |
|---|
| 1725 | | - err = mlx5_ib_alloc_transport_domain(dev, &context->tdn); |
|---|
| 1726 | | - if (err) |
|---|
| 1727 | | - goto out_uars; |
|---|
| 1728 | | - |
|---|
| 1910 | +uar_done: |
|---|
| 1729 | 1911 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) { |
|---|
| 1730 | | - /* Block DEVX on Infiniband as of SELinux */ |
|---|
| 1731 | | - if (mlx5_ib_port_link_layer(ibdev, 1) != IB_LINK_LAYER_ETHERNET) { |
|---|
| 1732 | | - err = -EPERM; |
|---|
| 1733 | | - goto out_td; |
|---|
| 1734 | | - } |
|---|
| 1735 | | - |
|---|
| 1736 | | - err = mlx5_ib_devx_create(dev, context); |
|---|
| 1737 | | - if (err) |
|---|
| 1738 | | - goto out_td; |
|---|
| 1912 | + err = mlx5_ib_devx_create(dev, true); |
|---|
| 1913 | + if (err < 0) |
|---|
| 1914 | + goto out_uars; |
|---|
| 1915 | + context->devx_uid = err; |
|---|
| 1739 | 1916 | } |
|---|
| 1740 | 1917 | |
|---|
| 1741 | | - if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
|---|
| 1742 | | - err = mlx5_cmd_dump_fill_mkey(dev->mdev, &dump_fill_mkey); |
|---|
| 1743 | | - if (err) |
|---|
| 1744 | | - goto out_mdev; |
|---|
| 1745 | | - } |
|---|
| 1918 | + err = mlx5_ib_alloc_transport_domain(dev, &context->tdn, |
|---|
| 1919 | + context->devx_uid); |
|---|
| 1920 | + if (err) |
|---|
| 1921 | + goto out_devx; |
|---|
| 1746 | 1922 | |
|---|
| 1747 | | - INIT_LIST_HEAD(&context->vma_private_list); |
|---|
| 1748 | | - mutex_init(&context->vma_private_list_mutex); |
|---|
| 1749 | 1923 | INIT_LIST_HEAD(&context->db_page_list); |
|---|
| 1750 | 1924 | mutex_init(&context->db_page_mutex); |
|---|
| 1751 | 1925 | |
|---|
| 1752 | | - resp.tot_bfregs = req.total_num_bfregs; |
|---|
| 1753 | | - resp.num_ports = dev->num_ports; |
|---|
| 1926 | + context->cqe_version = min_t(__u8, |
|---|
| 1927 | + (__u8)MLX5_CAP_GEN(dev->mdev, cqe_version), |
|---|
| 1928 | + req.max_cqe_version); |
|---|
| 1754 | 1929 | |
|---|
| 1755 | | - if (field_avail(typeof(resp), cqe_version, udata->outlen)) |
|---|
| 1756 | | - resp.response_length += sizeof(resp.cqe_version); |
|---|
| 1930 | + err = set_ucontext_resp(uctx, &resp); |
|---|
| 1931 | + if (err) |
|---|
| 1932 | + goto out_mdev; |
|---|
| 1757 | 1933 | |
|---|
| 1758 | | - if (field_avail(typeof(resp), cmds_supp_uhw, udata->outlen)) { |
|---|
| 1759 | | - resp.cmds_supp_uhw |= MLX5_USER_CMDS_SUPP_UHW_QUERY_DEVICE | |
|---|
| 1760 | | - MLX5_USER_CMDS_SUPP_UHW_CREATE_AH; |
|---|
| 1761 | | - resp.response_length += sizeof(resp.cmds_supp_uhw); |
|---|
| 1762 | | - } |
|---|
| 1763 | | - |
|---|
| 1764 | | - if (field_avail(typeof(resp), eth_min_inline, udata->outlen)) { |
|---|
| 1765 | | - if (mlx5_ib_port_link_layer(ibdev, 1) == IB_LINK_LAYER_ETHERNET) { |
|---|
| 1766 | | - mlx5_query_min_inline(dev->mdev, &resp.eth_min_inline); |
|---|
| 1767 | | - resp.eth_min_inline++; |
|---|
| 1768 | | - } |
|---|
| 1769 | | - resp.response_length += sizeof(resp.eth_min_inline); |
|---|
| 1770 | | - } |
|---|
| 1771 | | - |
|---|
| 1772 | | - if (field_avail(typeof(resp), clock_info_versions, udata->outlen)) { |
|---|
| 1773 | | - if (mdev->clock_info) |
|---|
| 1774 | | - resp.clock_info_versions = BIT(MLX5_IB_CLOCK_INFO_V1); |
|---|
| 1775 | | - resp.response_length += sizeof(resp.clock_info_versions); |
|---|
| 1776 | | - } |
|---|
| 1777 | | - |
|---|
| 1778 | | - /* |
|---|
| 1779 | | - * We don't want to expose information from the PCI bar that is located |
|---|
| 1780 | | - * after 4096 bytes, so if the arch only supports larger pages, let's |
|---|
| 1781 | | - * pretend we don't support reading the HCA's core clock. This is also |
|---|
| 1782 | | - * forced by mmap function. |
|---|
| 1783 | | - */ |
|---|
| 1784 | | - if (field_avail(typeof(resp), hca_core_clock_offset, udata->outlen)) { |
|---|
| 1785 | | - if (PAGE_SIZE <= 4096) { |
|---|
| 1786 | | - resp.comp_mask |= |
|---|
| 1787 | | - MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET; |
|---|
| 1788 | | - resp.hca_core_clock_offset = |
|---|
| 1789 | | - offsetof(struct mlx5_init_seg, internal_timer_h) % PAGE_SIZE; |
|---|
| 1790 | | - } |
|---|
| 1791 | | - resp.response_length += sizeof(resp.hca_core_clock_offset); |
|---|
| 1792 | | - } |
|---|
| 1793 | | - |
|---|
| 1794 | | - if (field_avail(typeof(resp), log_uar_size, udata->outlen)) |
|---|
| 1795 | | - resp.response_length += sizeof(resp.log_uar_size); |
|---|
| 1796 | | - |
|---|
| 1797 | | - if (field_avail(typeof(resp), num_uars_per_page, udata->outlen)) |
|---|
| 1798 | | - resp.response_length += sizeof(resp.num_uars_per_page); |
|---|
| 1799 | | - |
|---|
| 1800 | | - if (field_avail(typeof(resp), num_dyn_bfregs, udata->outlen)) { |
|---|
| 1801 | | - resp.num_dyn_bfregs = bfregi->num_dyn_bfregs; |
|---|
| 1802 | | - resp.response_length += sizeof(resp.num_dyn_bfregs); |
|---|
| 1803 | | - } |
|---|
| 1804 | | - |
|---|
| 1805 | | - if (field_avail(typeof(resp), dump_fill_mkey, udata->outlen)) { |
|---|
| 1806 | | - if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) { |
|---|
| 1807 | | - resp.dump_fill_mkey = dump_fill_mkey; |
|---|
| 1808 | | - resp.comp_mask |= |
|---|
| 1809 | | - MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_DUMP_FILL_MKEY; |
|---|
| 1810 | | - } |
|---|
| 1811 | | - resp.response_length += sizeof(resp.dump_fill_mkey); |
|---|
| 1812 | | - } |
|---|
| 1813 | | - |
|---|
| 1934 | + resp.response_length = min(udata->outlen, sizeof(resp)); |
|---|
| 1814 | 1935 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
|---|
| 1815 | 1936 | if (err) |
|---|
| 1816 | 1937 | goto out_mdev; |
|---|
| 1817 | 1938 | |
|---|
| 1818 | 1939 | bfregi->ver = ver; |
|---|
| 1819 | 1940 | bfregi->num_low_latency_bfregs = req.num_low_latency_bfregs; |
|---|
| 1820 | | - context->cqe_version = resp.cqe_version; |
|---|
| 1821 | 1941 | context->lib_caps = req.lib_caps; |
|---|
| 1822 | 1942 | print_lib_caps(dev, context->lib_caps); |
|---|
| 1823 | 1943 | |
|---|
| 1824 | | - if (mlx5_lag_is_active(dev->mdev)) { |
|---|
| 1825 | | - u8 port = mlx5_core_native_port_num(dev->mdev); |
|---|
| 1944 | + if (mlx5_ib_lag_should_assign_affinity(dev)) { |
|---|
| 1945 | + u8 port = mlx5_core_native_port_num(dev->mdev) - 1; |
|---|
| 1826 | 1946 | |
|---|
| 1827 | 1947 | atomic_set(&context->tx_port_affinity, |
|---|
| 1828 | 1948 | atomic_add_return( |
|---|
| 1829 | | - 1, &dev->roce[port].tx_port_affinity)); |
|---|
| 1949 | + 1, &dev->port[port].roce.tx_port_affinity)); |
|---|
| 1830 | 1950 | } |
|---|
| 1831 | 1951 | |
|---|
| 1832 | | - return &context->ibucontext; |
|---|
| 1952 | + return 0; |
|---|
| 1833 | 1953 | |
|---|
| 1834 | 1954 | out_mdev: |
|---|
| 1955 | + mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid); |
|---|
| 1956 | +out_devx: |
|---|
| 1835 | 1957 | if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) |
|---|
| 1836 | | - mlx5_ib_devx_destroy(dev, context); |
|---|
| 1837 | | -out_td: |
|---|
| 1838 | | - mlx5_ib_dealloc_transport_domain(dev, context->tdn); |
|---|
| 1958 | + mlx5_ib_devx_destroy(dev, context->devx_uid); |
|---|
| 1839 | 1959 | |
|---|
| 1840 | 1960 | out_uars: |
|---|
| 1841 | 1961 | deallocate_uars(dev, context); |
|---|
| .. | .. |
|---|
| 1847 | 1967 | kfree(bfregi->count); |
|---|
| 1848 | 1968 | |
|---|
| 1849 | 1969 | out_ctx: |
|---|
| 1850 | | - kfree(context); |
|---|
| 1851 | | - |
|---|
| 1852 | | - return ERR_PTR(err); |
|---|
| 1970 | + return err; |
|---|
| 1853 | 1971 | } |
|---|
| 1854 | 1972 | |
|---|
| 1855 | | -static int mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
|---|
| 1973 | +static int mlx5_ib_query_ucontext(struct ib_ucontext *ibcontext, |
|---|
| 1974 | + struct uverbs_attr_bundle *attrs) |
|---|
| 1975 | +{ |
|---|
| 1976 | + struct mlx5_ib_alloc_ucontext_resp uctx_resp = {}; |
|---|
| 1977 | + int ret; |
|---|
| 1978 | + |
|---|
| 1979 | + ret = set_ucontext_resp(ibcontext, &uctx_resp); |
|---|
| 1980 | + if (ret) |
|---|
| 1981 | + return ret; |
|---|
| 1982 | + |
|---|
| 1983 | + uctx_resp.response_length = |
|---|
| 1984 | + min_t(size_t, |
|---|
| 1985 | + uverbs_attr_get_len(attrs, |
|---|
| 1986 | + MLX5_IB_ATTR_QUERY_CONTEXT_RESP_UCTX), |
|---|
| 1987 | + sizeof(uctx_resp)); |
|---|
| 1988 | + |
|---|
| 1989 | + ret = uverbs_copy_to_struct_or_zero(attrs, |
|---|
| 1990 | + MLX5_IB_ATTR_QUERY_CONTEXT_RESP_UCTX, |
|---|
| 1991 | + &uctx_resp, |
|---|
| 1992 | + sizeof(uctx_resp)); |
|---|
| 1993 | + return ret; |
|---|
| 1994 | +} |
|---|
| 1995 | + |
|---|
| 1996 | +static void mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) |
|---|
| 1856 | 1997 | { |
|---|
| 1857 | 1998 | struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
|---|
| 1858 | 1999 | struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); |
|---|
| 1859 | 2000 | struct mlx5_bfreg_info *bfregi; |
|---|
| 1860 | 2001 | |
|---|
| 1861 | | - if (context->devx_uid) |
|---|
| 1862 | | - mlx5_ib_devx_destroy(dev, context); |
|---|
| 1863 | | - |
|---|
| 1864 | 2002 | bfregi = &context->bfregi; |
|---|
| 1865 | | - mlx5_ib_dealloc_transport_domain(dev, context->tdn); |
|---|
| 2003 | + mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid); |
|---|
| 2004 | + |
|---|
| 2005 | + if (context->devx_uid) |
|---|
| 2006 | + mlx5_ib_devx_destroy(dev, context->devx_uid); |
|---|
| 1866 | 2007 | |
|---|
| 1867 | 2008 | deallocate_uars(dev, context); |
|---|
| 1868 | 2009 | kfree(bfregi->sys_pages); |
|---|
| 1869 | 2010 | kfree(bfregi->count); |
|---|
| 1870 | | - kfree(context); |
|---|
| 1871 | | - |
|---|
| 1872 | | - return 0; |
|---|
| 1873 | 2011 | } |
|---|
| 1874 | 2012 | |
|---|
| 1875 | 2013 | static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, |
|---|
| .. | .. |
|---|
| 1879 | 2017 | |
|---|
| 1880 | 2018 | fw_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? MLX5_UARS_IN_PAGE : 1; |
|---|
| 1881 | 2019 | |
|---|
| 1882 | | - return (pci_resource_start(dev->mdev->pdev, 0) >> PAGE_SHIFT) + uar_idx / fw_uars_per_page; |
|---|
| 2020 | + return (dev->mdev->bar_addr >> PAGE_SHIFT) + uar_idx / fw_uars_per_page; |
|---|
| 2021 | +} |
|---|
| 2022 | + |
|---|
| 2023 | +static u64 uar_index2paddress(struct mlx5_ib_dev *dev, |
|---|
| 2024 | + int uar_idx) |
|---|
| 2025 | +{ |
|---|
| 2026 | + unsigned int fw_uars_per_page; |
|---|
| 2027 | + |
|---|
| 2028 | + fw_uars_per_page = MLX5_CAP_GEN(dev->mdev, uar_4k) ? |
|---|
| 2029 | + MLX5_UARS_IN_PAGE : 1; |
|---|
| 2030 | + |
|---|
| 2031 | + return (dev->mdev->bar_addr + (uar_idx / fw_uars_per_page) * PAGE_SIZE); |
|---|
| 1883 | 2032 | } |
|---|
| 1884 | 2033 | |
|---|
| 1885 | 2034 | static int get_command(unsigned long offset) |
|---|
| .. | .. |
|---|
| 1903 | 2052 | return get_arg(offset) | ((offset >> 16) & 0xff) << 8; |
|---|
| 1904 | 2053 | } |
|---|
| 1905 | 2054 | |
|---|
| 1906 | | -static void mlx5_ib_vma_open(struct vm_area_struct *area) |
|---|
| 1907 | | -{ |
|---|
| 1908 | | - /* vma_open is called when a new VMA is created on top of our VMA. This |
|---|
| 1909 | | - * is done through either mremap flow or split_vma (usually due to |
|---|
| 1910 | | - * mlock, madvise, munmap, etc.) We do not support a clone of the VMA, |
|---|
| 1911 | | - * as this VMA is strongly hardware related. Therefore we set the |
|---|
| 1912 | | - * vm_ops of the newly created/cloned VMA to NULL, to prevent it from |
|---|
| 1913 | | - * calling us again and trying to do incorrect actions. We assume that |
|---|
| 1914 | | - * the original VMA size is exactly a single page, and therefore all |
|---|
| 1915 | | - * "splitting" operation will not happen to it. |
|---|
| 1916 | | - */ |
|---|
| 1917 | | - area->vm_ops = NULL; |
|---|
| 1918 | | -} |
|---|
| 1919 | | - |
|---|
| 1920 | | -static void mlx5_ib_vma_close(struct vm_area_struct *area) |
|---|
| 1921 | | -{ |
|---|
| 1922 | | - struct mlx5_ib_vma_private_data *mlx5_ib_vma_priv_data; |
|---|
| 1923 | | - |
|---|
| 1924 | | - /* It's guaranteed that all VMAs opened on a FD are closed before the |
|---|
| 1925 | | - * file itself is closed, therefore no sync is needed with the regular |
|---|
| 1926 | | - * closing flow. (e.g. mlx5 ib_dealloc_ucontext) |
|---|
| 1927 | | - * However need a sync with accessing the vma as part of |
|---|
| 1928 | | - * mlx5_ib_disassociate_ucontext. |
|---|
| 1929 | | - * The close operation is usually called under mm->mmap_sem except when |
|---|
| 1930 | | - * process is exiting. |
|---|
| 1931 | | - * The exiting case is handled explicitly as part of |
|---|
| 1932 | | - * mlx5_ib_disassociate_ucontext. |
|---|
| 1933 | | - */ |
|---|
| 1934 | | - mlx5_ib_vma_priv_data = (struct mlx5_ib_vma_private_data *)area->vm_private_data; |
|---|
| 1935 | | - |
|---|
| 1936 | | - /* setting the vma context pointer to null in the mlx5_ib driver's |
|---|
| 1937 | | - * private data, to protect a race condition in |
|---|
| 1938 | | - * mlx5_ib_disassociate_ucontext(). |
|---|
| 1939 | | - */ |
|---|
| 1940 | | - mlx5_ib_vma_priv_data->vma = NULL; |
|---|
| 1941 | | - mutex_lock(mlx5_ib_vma_priv_data->vma_private_list_mutex); |
|---|
| 1942 | | - list_del(&mlx5_ib_vma_priv_data->list); |
|---|
| 1943 | | - mutex_unlock(mlx5_ib_vma_priv_data->vma_private_list_mutex); |
|---|
| 1944 | | - kfree(mlx5_ib_vma_priv_data); |
|---|
| 1945 | | -} |
|---|
| 1946 | | - |
|---|
| 1947 | | -static const struct vm_operations_struct mlx5_ib_vm_ops = { |
|---|
| 1948 | | - .open = mlx5_ib_vma_open, |
|---|
| 1949 | | - .close = mlx5_ib_vma_close |
|---|
| 1950 | | -}; |
|---|
| 1951 | | - |
|---|
| 1952 | | -static int mlx5_ib_set_vma_data(struct vm_area_struct *vma, |
|---|
| 1953 | | - struct mlx5_ib_ucontext *ctx) |
|---|
| 1954 | | -{ |
|---|
| 1955 | | - struct mlx5_ib_vma_private_data *vma_prv; |
|---|
| 1956 | | - struct list_head *vma_head = &ctx->vma_private_list; |
|---|
| 1957 | | - |
|---|
| 1958 | | - vma_prv = kzalloc(sizeof(*vma_prv), GFP_KERNEL); |
|---|
| 1959 | | - if (!vma_prv) |
|---|
| 1960 | | - return -ENOMEM; |
|---|
| 1961 | | - |
|---|
| 1962 | | - vma_prv->vma = vma; |
|---|
| 1963 | | - vma_prv->vma_private_list_mutex = &ctx->vma_private_list_mutex; |
|---|
| 1964 | | - vma->vm_private_data = vma_prv; |
|---|
| 1965 | | - vma->vm_ops = &mlx5_ib_vm_ops; |
|---|
| 1966 | | - |
|---|
| 1967 | | - mutex_lock(&ctx->vma_private_list_mutex); |
|---|
| 1968 | | - list_add(&vma_prv->list, vma_head); |
|---|
| 1969 | | - mutex_unlock(&ctx->vma_private_list_mutex); |
|---|
| 1970 | | - |
|---|
| 1971 | | - return 0; |
|---|
| 1972 | | -} |
|---|
| 1973 | 2055 | |
|---|
| 1974 | 2056 | static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) |
|---|
| 1975 | 2057 | { |
|---|
| 1976 | | - struct vm_area_struct *vma; |
|---|
| 1977 | | - struct mlx5_ib_vma_private_data *vma_private, *n; |
|---|
| 1978 | | - struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); |
|---|
| 1979 | | - |
|---|
| 1980 | | - mutex_lock(&context->vma_private_list_mutex); |
|---|
| 1981 | | - list_for_each_entry_safe(vma_private, n, &context->vma_private_list, |
|---|
| 1982 | | - list) { |
|---|
| 1983 | | - vma = vma_private->vma; |
|---|
| 1984 | | - zap_vma_ptes(vma, vma->vm_start, PAGE_SIZE); |
|---|
| 1985 | | - /* context going to be destroyed, should |
|---|
| 1986 | | - * not access ops any more. |
|---|
| 1987 | | - */ |
|---|
| 1988 | | - vma->vm_flags &= ~(VM_SHARED | VM_MAYSHARE); |
|---|
| 1989 | | - vma->vm_ops = NULL; |
|---|
| 1990 | | - list_del(&vma_private->list); |
|---|
| 1991 | | - kfree(vma_private); |
|---|
| 1992 | | - } |
|---|
| 1993 | | - mutex_unlock(&context->vma_private_list_mutex); |
|---|
| 1994 | 2058 | } |
|---|
| 1995 | 2059 | |
|---|
| 1996 | 2060 | static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd) |
|---|
| .. | .. |
|---|
| 2005 | 2069 | case MLX5_IB_MMAP_DEVICE_MEM: |
|---|
| 2006 | 2070 | return "Device Memory"; |
|---|
| 2007 | 2071 | default: |
|---|
| 2008 | | - return NULL; |
|---|
| 2072 | + return "Unknown"; |
|---|
| 2009 | 2073 | } |
|---|
| 2010 | 2074 | } |
|---|
| 2011 | 2075 | |
|---|
| .. | .. |
|---|
| 2013 | 2077 | struct vm_area_struct *vma, |
|---|
| 2014 | 2078 | struct mlx5_ib_ucontext *context) |
|---|
| 2015 | 2079 | { |
|---|
| 2016 | | - phys_addr_t pfn; |
|---|
| 2017 | | - int err; |
|---|
| 2018 | | - |
|---|
| 2019 | | - if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
|---|
| 2080 | + if ((vma->vm_end - vma->vm_start != PAGE_SIZE) || |
|---|
| 2081 | + !(vma->vm_flags & VM_SHARED)) |
|---|
| 2020 | 2082 | return -EINVAL; |
|---|
| 2021 | 2083 | |
|---|
| 2022 | 2084 | if (get_index(vma->vm_pgoff) != MLX5_IB_CLOCK_INFO_V1) |
|---|
| 2023 | 2085 | return -EOPNOTSUPP; |
|---|
| 2024 | 2086 | |
|---|
| 2025 | | - if (vma->vm_flags & VM_WRITE) |
|---|
| 2087 | + if (vma->vm_flags & (VM_WRITE | VM_EXEC)) |
|---|
| 2026 | 2088 | return -EPERM; |
|---|
| 2027 | 2089 | vma->vm_flags &= ~VM_MAYWRITE; |
|---|
| 2028 | 2090 | |
|---|
| 2029 | | - if (!dev->mdev->clock_info_page) |
|---|
| 2091 | + if (!dev->mdev->clock_info) |
|---|
| 2030 | 2092 | return -EOPNOTSUPP; |
|---|
| 2031 | 2093 | |
|---|
| 2032 | | - pfn = page_to_pfn(dev->mdev->clock_info_page); |
|---|
| 2033 | | - err = remap_pfn_range(vma, vma->vm_start, pfn, PAGE_SIZE, |
|---|
| 2034 | | - vma->vm_page_prot); |
|---|
| 2035 | | - if (err) |
|---|
| 2036 | | - return err; |
|---|
| 2094 | + return vm_insert_page(vma, vma->vm_start, |
|---|
| 2095 | + virt_to_page(dev->mdev->clock_info)); |
|---|
| 2096 | +} |
|---|
| 2037 | 2097 | |
|---|
| 2038 | | - return mlx5_ib_set_vma_data(vma, context); |
|---|
| 2098 | +static void mlx5_ib_mmap_free(struct rdma_user_mmap_entry *entry) |
|---|
| 2099 | +{ |
|---|
| 2100 | + struct mlx5_user_mmap_entry *mentry = to_mmmap(entry); |
|---|
| 2101 | + struct mlx5_ib_dev *dev = to_mdev(entry->ucontext->device); |
|---|
| 2102 | + struct mlx5_var_table *var_table = &dev->var_table; |
|---|
| 2103 | + struct mlx5_ib_dm *mdm; |
|---|
| 2104 | + |
|---|
| 2105 | + switch (mentry->mmap_flag) { |
|---|
| 2106 | + case MLX5_IB_MMAP_TYPE_MEMIC: |
|---|
| 2107 | + mdm = container_of(mentry, struct mlx5_ib_dm, mentry); |
|---|
| 2108 | + mlx5_cmd_dealloc_memic(&dev->dm, mdm->dev_addr, |
|---|
| 2109 | + mdm->size); |
|---|
| 2110 | + kfree(mdm); |
|---|
| 2111 | + break; |
|---|
| 2112 | + case MLX5_IB_MMAP_TYPE_VAR: |
|---|
| 2113 | + mutex_lock(&var_table->bitmap_lock); |
|---|
| 2114 | + clear_bit(mentry->page_idx, var_table->bitmap); |
|---|
| 2115 | + mutex_unlock(&var_table->bitmap_lock); |
|---|
| 2116 | + kfree(mentry); |
|---|
| 2117 | + break; |
|---|
| 2118 | + case MLX5_IB_MMAP_TYPE_UAR_WC: |
|---|
| 2119 | + case MLX5_IB_MMAP_TYPE_UAR_NC: |
|---|
| 2120 | + mlx5_cmd_free_uar(dev->mdev, mentry->page_idx); |
|---|
| 2121 | + kfree(mentry); |
|---|
| 2122 | + break; |
|---|
| 2123 | + default: |
|---|
| 2124 | + WARN_ON(true); |
|---|
| 2125 | + } |
|---|
| 2039 | 2126 | } |
|---|
| 2040 | 2127 | |
|---|
| 2041 | 2128 | static int uar_mmap(struct mlx5_ib_dev *dev, enum mlx5_ib_mmap_cmd cmd, |
|---|
| .. | .. |
|---|
| 2052 | 2139 | int dyn_uar = (cmd == MLX5_IB_MMAP_ALLOC_WC); |
|---|
| 2053 | 2140 | int max_valid_idx = dyn_uar ? bfregi->num_sys_pages : |
|---|
| 2054 | 2141 | bfregi->num_static_sys_pages; |
|---|
| 2142 | + |
|---|
| 2143 | + if (bfregi->lib_uar_dyn) |
|---|
| 2144 | + return -EINVAL; |
|---|
| 2055 | 2145 | |
|---|
| 2056 | 2146 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) |
|---|
| 2057 | 2147 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 2070 | 2160 | switch (cmd) { |
|---|
| 2071 | 2161 | case MLX5_IB_MMAP_WC_PAGE: |
|---|
| 2072 | 2162 | case MLX5_IB_MMAP_ALLOC_WC: |
|---|
| 2073 | | -/* Some architectures don't support WC memory */ |
|---|
| 2074 | | -#if defined(CONFIG_X86) |
|---|
| 2075 | | - if (!pat_enabled()) |
|---|
| 2076 | | - return -EPERM; |
|---|
| 2077 | | -#elif !(defined(CONFIG_PPC) || (defined(CONFIG_ARM) && defined(CONFIG_MMU))) |
|---|
| 2078 | | - return -EPERM; |
|---|
| 2079 | | -#endif |
|---|
| 2080 | | - /* fall through */ |
|---|
| 2081 | 2163 | case MLX5_IB_MMAP_REGULAR_PAGE: |
|---|
| 2082 | 2164 | /* For MLX5_IB_MMAP_REGULAR_PAGE do the best effort to get WC */ |
|---|
| 2083 | 2165 | prot = pgprot_writecombine(vma->vm_page_prot); |
|---|
| .. | .. |
|---|
| 2125 | 2207 | pfn = uar_index2pfn(dev, uar_index); |
|---|
| 2126 | 2208 | mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn %pa\n", idx, &pfn); |
|---|
| 2127 | 2209 | |
|---|
| 2128 | | - vma->vm_page_prot = prot; |
|---|
| 2129 | | - err = io_remap_pfn_range(vma, vma->vm_start, pfn, |
|---|
| 2130 | | - PAGE_SIZE, vma->vm_page_prot); |
|---|
| 2210 | + err = rdma_user_mmap_io(&context->ibucontext, vma, pfn, PAGE_SIZE, |
|---|
| 2211 | + prot, NULL); |
|---|
| 2131 | 2212 | if (err) { |
|---|
| 2132 | 2213 | mlx5_ib_err(dev, |
|---|
| 2133 | | - "io_remap_pfn_range failed with error=%d, mmap_cmd=%s\n", |
|---|
| 2214 | + "rdma_user_mmap_io failed with error=%d, mmap_cmd=%s\n", |
|---|
| 2134 | 2215 | err, mmap_cmd2str(cmd)); |
|---|
| 2135 | | - err = -EAGAIN; |
|---|
| 2136 | 2216 | goto err; |
|---|
| 2137 | 2217 | } |
|---|
| 2138 | | - |
|---|
| 2139 | | - err = mlx5_ib_set_vma_data(vma, context); |
|---|
| 2140 | | - if (err) |
|---|
| 2141 | | - goto err; |
|---|
| 2142 | 2218 | |
|---|
| 2143 | 2219 | if (dyn_uar) |
|---|
| 2144 | 2220 | bfregi->sys_pages[idx] = uar_index; |
|---|
| .. | .. |
|---|
| 2156 | 2232 | return err; |
|---|
| 2157 | 2233 | } |
|---|
| 2158 | 2234 | |
|---|
| 2159 | | -static int dm_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
|---|
| 2235 | +static int add_dm_mmap_entry(struct ib_ucontext *context, |
|---|
| 2236 | + struct mlx5_ib_dm *mdm, |
|---|
| 2237 | + u64 address) |
|---|
| 2160 | 2238 | { |
|---|
| 2161 | | - struct mlx5_ib_ucontext *mctx = to_mucontext(context); |
|---|
| 2162 | | - struct mlx5_ib_dev *dev = to_mdev(context->device); |
|---|
| 2163 | | - u16 page_idx = get_extended_index(vma->vm_pgoff); |
|---|
| 2164 | | - size_t map_size = vma->vm_end - vma->vm_start; |
|---|
| 2165 | | - u32 npages = map_size >> PAGE_SHIFT; |
|---|
| 2166 | | - phys_addr_t pfn; |
|---|
| 2167 | | - pgprot_t prot; |
|---|
| 2239 | + mdm->mentry.mmap_flag = MLX5_IB_MMAP_TYPE_MEMIC; |
|---|
| 2240 | + mdm->mentry.address = address; |
|---|
| 2241 | + return rdma_user_mmap_entry_insert_range( |
|---|
| 2242 | + context, &mdm->mentry.rdma_entry, |
|---|
| 2243 | + mdm->size, |
|---|
| 2244 | + MLX5_IB_MMAP_DEVICE_MEM << 16, |
|---|
| 2245 | + (MLX5_IB_MMAP_DEVICE_MEM << 16) + (1UL << 16) - 1); |
|---|
| 2246 | +} |
|---|
| 2168 | 2247 | |
|---|
| 2169 | | - if (find_next_zero_bit(mctx->dm_pages, page_idx + npages, page_idx) != |
|---|
| 2170 | | - page_idx + npages) |
|---|
| 2248 | +static unsigned long mlx5_vma_to_pgoff(struct vm_area_struct *vma) |
|---|
| 2249 | +{ |
|---|
| 2250 | + unsigned long idx; |
|---|
| 2251 | + u8 command; |
|---|
| 2252 | + |
|---|
| 2253 | + command = get_command(vma->vm_pgoff); |
|---|
| 2254 | + idx = get_extended_index(vma->vm_pgoff); |
|---|
| 2255 | + |
|---|
| 2256 | + return (command << 16 | idx); |
|---|
| 2257 | +} |
|---|
| 2258 | + |
|---|
| 2259 | +static int mlx5_ib_mmap_offset(struct mlx5_ib_dev *dev, |
|---|
| 2260 | + struct vm_area_struct *vma, |
|---|
| 2261 | + struct ib_ucontext *ucontext) |
|---|
| 2262 | +{ |
|---|
| 2263 | + struct mlx5_user_mmap_entry *mentry; |
|---|
| 2264 | + struct rdma_user_mmap_entry *entry; |
|---|
| 2265 | + unsigned long pgoff; |
|---|
| 2266 | + pgprot_t prot; |
|---|
| 2267 | + phys_addr_t pfn; |
|---|
| 2268 | + int ret; |
|---|
| 2269 | + |
|---|
| 2270 | + pgoff = mlx5_vma_to_pgoff(vma); |
|---|
| 2271 | + entry = rdma_user_mmap_entry_get_pgoff(ucontext, pgoff); |
|---|
| 2272 | + if (!entry) |
|---|
| 2171 | 2273 | return -EINVAL; |
|---|
| 2172 | 2274 | |
|---|
| 2173 | | - pfn = ((pci_resource_start(dev->mdev->pdev, 0) + |
|---|
| 2174 | | - MLX5_CAP64_DEV_MEM(dev->mdev, memic_bar_start_addr)) >> |
|---|
| 2175 | | - PAGE_SHIFT) + |
|---|
| 2176 | | - page_idx; |
|---|
| 2177 | | - prot = pgprot_writecombine(vma->vm_page_prot); |
|---|
| 2178 | | - vma->vm_page_prot = prot; |
|---|
| 2275 | + mentry = to_mmmap(entry); |
|---|
| 2276 | + pfn = (mentry->address >> PAGE_SHIFT); |
|---|
| 2277 | + if (mentry->mmap_flag == MLX5_IB_MMAP_TYPE_VAR || |
|---|
| 2278 | + mentry->mmap_flag == MLX5_IB_MMAP_TYPE_UAR_NC) |
|---|
| 2279 | + prot = pgprot_noncached(vma->vm_page_prot); |
|---|
| 2280 | + else |
|---|
| 2281 | + prot = pgprot_writecombine(vma->vm_page_prot); |
|---|
| 2282 | + ret = rdma_user_mmap_io(ucontext, vma, pfn, |
|---|
| 2283 | + entry->npages * PAGE_SIZE, |
|---|
| 2284 | + prot, |
|---|
| 2285 | + entry); |
|---|
| 2286 | + rdma_user_mmap_entry_put(&mentry->rdma_entry); |
|---|
| 2287 | + return ret; |
|---|
| 2288 | +} |
|---|
| 2179 | 2289 | |
|---|
| 2180 | | - if (io_remap_pfn_range(vma, vma->vm_start, pfn, map_size, |
|---|
| 2181 | | - vma->vm_page_prot)) |
|---|
| 2182 | | - return -EAGAIN; |
|---|
| 2290 | +static u64 mlx5_entry_to_mmap_offset(struct mlx5_user_mmap_entry *entry) |
|---|
| 2291 | +{ |
|---|
| 2292 | + u64 cmd = (entry->rdma_entry.start_pgoff >> 16) & 0xFFFF; |
|---|
| 2293 | + u64 index = entry->rdma_entry.start_pgoff & 0xFFFF; |
|---|
| 2183 | 2294 | |
|---|
| 2184 | | - return mlx5_ib_set_vma_data(vma, mctx); |
|---|
| 2295 | + return (((index >> 8) << 16) | (cmd << MLX5_IB_MMAP_CMD_SHIFT) | |
|---|
| 2296 | + (index & 0xFF)) << PAGE_SHIFT; |
|---|
| 2185 | 2297 | } |
|---|
| 2186 | 2298 | |
|---|
| 2187 | 2299 | static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) |
|---|
| .. | .. |
|---|
| 2194 | 2306 | command = get_command(vma->vm_pgoff); |
|---|
| 2195 | 2307 | switch (command) { |
|---|
| 2196 | 2308 | case MLX5_IB_MMAP_WC_PAGE: |
|---|
| 2309 | + case MLX5_IB_MMAP_ALLOC_WC: |
|---|
| 2310 | + if (!dev->wc_support) |
|---|
| 2311 | + return -EPERM; |
|---|
| 2312 | + fallthrough; |
|---|
| 2197 | 2313 | case MLX5_IB_MMAP_NC_PAGE: |
|---|
| 2198 | 2314 | case MLX5_IB_MMAP_REGULAR_PAGE: |
|---|
| 2199 | | - case MLX5_IB_MMAP_ALLOC_WC: |
|---|
| 2200 | 2315 | return uar_mmap(dev, command, vma, context); |
|---|
| 2201 | 2316 | |
|---|
| 2202 | 2317 | case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: |
|---|
| .. | .. |
|---|
| 2214 | 2329 | if (PAGE_SIZE > 4096) |
|---|
| 2215 | 2330 | return -EOPNOTSUPP; |
|---|
| 2216 | 2331 | |
|---|
| 2217 | | - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
|---|
| 2218 | 2332 | pfn = (dev->mdev->iseg_base + |
|---|
| 2219 | 2333 | offsetof(struct mlx5_init_seg, internal_timer_h)) >> |
|---|
| 2220 | 2334 | PAGE_SHIFT; |
|---|
| 2221 | | - if (io_remap_pfn_range(vma, vma->vm_start, pfn, |
|---|
| 2222 | | - PAGE_SIZE, vma->vm_page_prot)) |
|---|
| 2223 | | - return -EAGAIN; |
|---|
| 2224 | | - break; |
|---|
| 2335 | + return rdma_user_mmap_io(&context->ibucontext, vma, pfn, |
|---|
| 2336 | + PAGE_SIZE, |
|---|
| 2337 | + pgprot_noncached(vma->vm_page_prot), |
|---|
| 2338 | + NULL); |
|---|
| 2225 | 2339 | case MLX5_IB_MMAP_CLOCK_INFO: |
|---|
| 2226 | 2340 | return mlx5_ib_mmap_clock_info_page(dev, vma, context); |
|---|
| 2227 | 2341 | |
|---|
| 2228 | | - case MLX5_IB_MMAP_DEVICE_MEM: |
|---|
| 2229 | | - return dm_mmap(ibcontext, vma); |
|---|
| 2230 | | - |
|---|
| 2231 | 2342 | default: |
|---|
| 2232 | | - return -EINVAL; |
|---|
| 2343 | + return mlx5_ib_mmap_offset(dev, vma, ibcontext); |
|---|
| 2233 | 2344 | } |
|---|
| 2234 | 2345 | |
|---|
| 2235 | 2346 | return 0; |
|---|
| 2347 | +} |
|---|
| 2348 | + |
|---|
| 2349 | +static inline int check_dm_type_support(struct mlx5_ib_dev *dev, |
|---|
| 2350 | + u32 type) |
|---|
| 2351 | +{ |
|---|
| 2352 | + switch (type) { |
|---|
| 2353 | + case MLX5_IB_UAPI_DM_TYPE_MEMIC: |
|---|
| 2354 | + if (!MLX5_CAP_DEV_MEM(dev->mdev, memic)) |
|---|
| 2355 | + return -EOPNOTSUPP; |
|---|
| 2356 | + break; |
|---|
| 2357 | + case MLX5_IB_UAPI_DM_TYPE_STEERING_SW_ICM: |
|---|
| 2358 | + case MLX5_IB_UAPI_DM_TYPE_HEADER_MODIFY_SW_ICM: |
|---|
| 2359 | + if (!capable(CAP_SYS_RAWIO) || |
|---|
| 2360 | + !capable(CAP_NET_RAW)) |
|---|
| 2361 | + return -EPERM; |
|---|
| 2362 | + |
|---|
| 2363 | + if (!(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, sw_owner) || |
|---|
| 2364 | + MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, sw_owner) || |
|---|
| 2365 | + MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, sw_owner_v2) || |
|---|
| 2366 | + MLX5_CAP_FLOWTABLE_NIC_TX(dev->mdev, sw_owner_v2))) |
|---|
| 2367 | + return -EOPNOTSUPP; |
|---|
| 2368 | + break; |
|---|
| 2369 | + } |
|---|
| 2370 | + |
|---|
| 2371 | + return 0; |
|---|
| 2372 | +} |
|---|
| 2373 | + |
|---|
| 2374 | +static int handle_alloc_dm_memic(struct ib_ucontext *ctx, |
|---|
| 2375 | + struct mlx5_ib_dm *dm, |
|---|
| 2376 | + struct ib_dm_alloc_attr *attr, |
|---|
| 2377 | + struct uverbs_attr_bundle *attrs) |
|---|
| 2378 | +{ |
|---|
| 2379 | + struct mlx5_dm *dm_db = &to_mdev(ctx->device)->dm; |
|---|
| 2380 | + u64 start_offset; |
|---|
| 2381 | + u16 page_idx; |
|---|
| 2382 | + int err; |
|---|
| 2383 | + u64 address; |
|---|
| 2384 | + |
|---|
| 2385 | + dm->size = roundup(attr->length, MLX5_MEMIC_BASE_SIZE); |
|---|
| 2386 | + |
|---|
| 2387 | + err = mlx5_cmd_alloc_memic(dm_db, &dm->dev_addr, |
|---|
| 2388 | + dm->size, attr->alignment); |
|---|
| 2389 | + if (err) |
|---|
| 2390 | + return err; |
|---|
| 2391 | + |
|---|
| 2392 | + address = dm->dev_addr & PAGE_MASK; |
|---|
| 2393 | + err = add_dm_mmap_entry(ctx, dm, address); |
|---|
| 2394 | + if (err) |
|---|
| 2395 | + goto err_dealloc; |
|---|
| 2396 | + |
|---|
| 2397 | + page_idx = dm->mentry.rdma_entry.start_pgoff & 0xFFFF; |
|---|
| 2398 | + err = uverbs_copy_to(attrs, |
|---|
| 2399 | + MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
|---|
| 2400 | + &page_idx, |
|---|
| 2401 | + sizeof(page_idx)); |
|---|
| 2402 | + if (err) |
|---|
| 2403 | + goto err_copy; |
|---|
| 2404 | + |
|---|
| 2405 | + start_offset = dm->dev_addr & ~PAGE_MASK; |
|---|
| 2406 | + err = uverbs_copy_to(attrs, |
|---|
| 2407 | + MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
|---|
| 2408 | + &start_offset, sizeof(start_offset)); |
|---|
| 2409 | + if (err) |
|---|
| 2410 | + goto err_copy; |
|---|
| 2411 | + |
|---|
| 2412 | + return 0; |
|---|
| 2413 | + |
|---|
| 2414 | +err_copy: |
|---|
| 2415 | + rdma_user_mmap_entry_remove(&dm->mentry.rdma_entry); |
|---|
| 2416 | +err_dealloc: |
|---|
| 2417 | + mlx5_cmd_dealloc_memic(dm_db, dm->dev_addr, dm->size); |
|---|
| 2418 | + |
|---|
| 2419 | + return err; |
|---|
| 2420 | +} |
|---|
| 2421 | + |
|---|
| 2422 | +static int handle_alloc_dm_sw_icm(struct ib_ucontext *ctx, |
|---|
| 2423 | + struct mlx5_ib_dm *dm, |
|---|
| 2424 | + struct ib_dm_alloc_attr *attr, |
|---|
| 2425 | + struct uverbs_attr_bundle *attrs, |
|---|
| 2426 | + int type) |
|---|
| 2427 | +{ |
|---|
| 2428 | + struct mlx5_core_dev *dev = to_mdev(ctx->device)->mdev; |
|---|
| 2429 | + u64 act_size; |
|---|
| 2430 | + int err; |
|---|
| 2431 | + |
|---|
| 2432 | + /* Allocation size must a multiple of the basic block size |
|---|
| 2433 | + * and a power of 2. |
|---|
| 2434 | + */ |
|---|
| 2435 | + act_size = round_up(attr->length, MLX5_SW_ICM_BLOCK_SIZE(dev)); |
|---|
| 2436 | + act_size = roundup_pow_of_two(act_size); |
|---|
| 2437 | + |
|---|
| 2438 | + dm->size = act_size; |
|---|
| 2439 | + err = mlx5_dm_sw_icm_alloc(dev, type, act_size, attr->alignment, |
|---|
| 2440 | + to_mucontext(ctx)->devx_uid, &dm->dev_addr, |
|---|
| 2441 | + &dm->icm_dm.obj_id); |
|---|
| 2442 | + if (err) |
|---|
| 2443 | + return err; |
|---|
| 2444 | + |
|---|
| 2445 | + err = uverbs_copy_to(attrs, |
|---|
| 2446 | + MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
|---|
| 2447 | + &dm->dev_addr, sizeof(dm->dev_addr)); |
|---|
| 2448 | + if (err) |
|---|
| 2449 | + mlx5_dm_sw_icm_dealloc(dev, type, dm->size, |
|---|
| 2450 | + to_mucontext(ctx)->devx_uid, dm->dev_addr, |
|---|
| 2451 | + dm->icm_dm.obj_id); |
|---|
| 2452 | + |
|---|
| 2453 | + return err; |
|---|
| 2236 | 2454 | } |
|---|
| 2237 | 2455 | |
|---|
| 2238 | 2456 | struct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev, |
|---|
| .. | .. |
|---|
| 2240 | 2458 | struct ib_dm_alloc_attr *attr, |
|---|
| 2241 | 2459 | struct uverbs_attr_bundle *attrs) |
|---|
| 2242 | 2460 | { |
|---|
| 2243 | | - u64 act_size = roundup(attr->length, MLX5_MEMIC_BASE_SIZE); |
|---|
| 2244 | | - struct mlx5_memic *memic = &to_mdev(ibdev)->memic; |
|---|
| 2245 | | - phys_addr_t memic_addr; |
|---|
| 2246 | 2461 | struct mlx5_ib_dm *dm; |
|---|
| 2247 | | - u64 start_offset; |
|---|
| 2248 | | - u32 page_idx; |
|---|
| 2462 | + enum mlx5_ib_uapi_dm_type type; |
|---|
| 2249 | 2463 | int err; |
|---|
| 2464 | + |
|---|
| 2465 | + err = uverbs_get_const_default(&type, attrs, |
|---|
| 2466 | + MLX5_IB_ATTR_ALLOC_DM_REQ_TYPE, |
|---|
| 2467 | + MLX5_IB_UAPI_DM_TYPE_MEMIC); |
|---|
| 2468 | + if (err) |
|---|
| 2469 | + return ERR_PTR(err); |
|---|
| 2470 | + |
|---|
| 2471 | + mlx5_ib_dbg(to_mdev(ibdev), "alloc_dm req: dm_type=%d user_length=0x%llx log_alignment=%d\n", |
|---|
| 2472 | + type, attr->length, attr->alignment); |
|---|
| 2473 | + |
|---|
| 2474 | + err = check_dm_type_support(to_mdev(ibdev), type); |
|---|
| 2475 | + if (err) |
|---|
| 2476 | + return ERR_PTR(err); |
|---|
| 2250 | 2477 | |
|---|
| 2251 | 2478 | dm = kzalloc(sizeof(*dm), GFP_KERNEL); |
|---|
| 2252 | 2479 | if (!dm) |
|---|
| 2253 | 2480 | return ERR_PTR(-ENOMEM); |
|---|
| 2254 | 2481 | |
|---|
| 2255 | | - mlx5_ib_dbg(to_mdev(ibdev), "alloc_memic req: user_length=0x%llx act_length=0x%llx log_alignment=%d\n", |
|---|
| 2256 | | - attr->length, act_size, attr->alignment); |
|---|
| 2482 | + dm->type = type; |
|---|
| 2257 | 2483 | |
|---|
| 2258 | | - err = mlx5_cmd_alloc_memic(memic, &memic_addr, |
|---|
| 2259 | | - act_size, attr->alignment); |
|---|
| 2484 | + switch (type) { |
|---|
| 2485 | + case MLX5_IB_UAPI_DM_TYPE_MEMIC: |
|---|
| 2486 | + err = handle_alloc_dm_memic(context, dm, |
|---|
| 2487 | + attr, |
|---|
| 2488 | + attrs); |
|---|
| 2489 | + break; |
|---|
| 2490 | + case MLX5_IB_UAPI_DM_TYPE_STEERING_SW_ICM: |
|---|
| 2491 | + err = handle_alloc_dm_sw_icm(context, dm, |
|---|
| 2492 | + attr, attrs, |
|---|
| 2493 | + MLX5_SW_ICM_TYPE_STEERING); |
|---|
| 2494 | + break; |
|---|
| 2495 | + case MLX5_IB_UAPI_DM_TYPE_HEADER_MODIFY_SW_ICM: |
|---|
| 2496 | + err = handle_alloc_dm_sw_icm(context, dm, |
|---|
| 2497 | + attr, attrs, |
|---|
| 2498 | + MLX5_SW_ICM_TYPE_HEADER_MODIFY); |
|---|
| 2499 | + break; |
|---|
| 2500 | + default: |
|---|
| 2501 | + err = -EOPNOTSUPP; |
|---|
| 2502 | + } |
|---|
| 2503 | + |
|---|
| 2260 | 2504 | if (err) |
|---|
| 2261 | 2505 | goto err_free; |
|---|
| 2262 | 2506 | |
|---|
| 2263 | | - start_offset = memic_addr & ~PAGE_MASK; |
|---|
| 2264 | | - page_idx = (memic_addr - pci_resource_start(memic->dev->pdev, 0) - |
|---|
| 2265 | | - MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
|---|
| 2266 | | - PAGE_SHIFT; |
|---|
| 2267 | | - |
|---|
| 2268 | | - err = uverbs_copy_to(attrs, |
|---|
| 2269 | | - MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
|---|
| 2270 | | - &start_offset, sizeof(start_offset)); |
|---|
| 2271 | | - if (err) |
|---|
| 2272 | | - goto err_dealloc; |
|---|
| 2273 | | - |
|---|
| 2274 | | - err = uverbs_copy_to(attrs, |
|---|
| 2275 | | - MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
|---|
| 2276 | | - &page_idx, sizeof(page_idx)); |
|---|
| 2277 | | - if (err) |
|---|
| 2278 | | - goto err_dealloc; |
|---|
| 2279 | | - |
|---|
| 2280 | | - bitmap_set(to_mucontext(context)->dm_pages, page_idx, |
|---|
| 2281 | | - DIV_ROUND_UP(act_size, PAGE_SIZE)); |
|---|
| 2282 | | - |
|---|
| 2283 | | - dm->dev_addr = memic_addr; |
|---|
| 2284 | | - |
|---|
| 2285 | 2507 | return &dm->ibdm; |
|---|
| 2286 | 2508 | |
|---|
| 2287 | | -err_dealloc: |
|---|
| 2288 | | - mlx5_cmd_dealloc_memic(memic, memic_addr, |
|---|
| 2289 | | - act_size); |
|---|
| 2290 | 2509 | err_free: |
|---|
| 2291 | 2510 | kfree(dm); |
|---|
| 2292 | 2511 | return ERR_PTR(err); |
|---|
| 2293 | 2512 | } |
|---|
| 2294 | 2513 | |
|---|
| 2295 | | -int mlx5_ib_dealloc_dm(struct ib_dm *ibdm) |
|---|
| 2514 | +int mlx5_ib_dealloc_dm(struct ib_dm *ibdm, struct uverbs_attr_bundle *attrs) |
|---|
| 2296 | 2515 | { |
|---|
| 2297 | | - struct mlx5_memic *memic = &to_mdev(ibdm->device)->memic; |
|---|
| 2516 | + struct mlx5_ib_ucontext *ctx = rdma_udata_to_drv_context( |
|---|
| 2517 | + &attrs->driver_udata, struct mlx5_ib_ucontext, ibucontext); |
|---|
| 2518 | + struct mlx5_core_dev *dev = to_mdev(ibdm->device)->mdev; |
|---|
| 2298 | 2519 | struct mlx5_ib_dm *dm = to_mdm(ibdm); |
|---|
| 2299 | | - u64 act_size = roundup(dm->ibdm.length, MLX5_MEMIC_BASE_SIZE); |
|---|
| 2300 | | - u32 page_idx; |
|---|
| 2301 | 2520 | int ret; |
|---|
| 2302 | 2521 | |
|---|
| 2303 | | - ret = mlx5_cmd_dealloc_memic(memic, dm->dev_addr, act_size); |
|---|
| 2304 | | - if (ret) |
|---|
| 2305 | | - return ret; |
|---|
| 2306 | | - |
|---|
| 2307 | | - page_idx = (dm->dev_addr - pci_resource_start(memic->dev->pdev, 0) - |
|---|
| 2308 | | - MLX5_CAP64_DEV_MEM(memic->dev, memic_bar_start_addr)) >> |
|---|
| 2309 | | - PAGE_SHIFT; |
|---|
| 2310 | | - bitmap_clear(to_mucontext(ibdm->uobject->context)->dm_pages, |
|---|
| 2311 | | - page_idx, |
|---|
| 2312 | | - DIV_ROUND_UP(act_size, PAGE_SIZE)); |
|---|
| 2522 | + switch (dm->type) { |
|---|
| 2523 | + case MLX5_IB_UAPI_DM_TYPE_MEMIC: |
|---|
| 2524 | + rdma_user_mmap_entry_remove(&dm->mentry.rdma_entry); |
|---|
| 2525 | + return 0; |
|---|
| 2526 | + case MLX5_IB_UAPI_DM_TYPE_STEERING_SW_ICM: |
|---|
| 2527 | + ret = mlx5_dm_sw_icm_dealloc(dev, MLX5_SW_ICM_TYPE_STEERING, |
|---|
| 2528 | + dm->size, ctx->devx_uid, dm->dev_addr, |
|---|
| 2529 | + dm->icm_dm.obj_id); |
|---|
| 2530 | + if (ret) |
|---|
| 2531 | + return ret; |
|---|
| 2532 | + break; |
|---|
| 2533 | + case MLX5_IB_UAPI_DM_TYPE_HEADER_MODIFY_SW_ICM: |
|---|
| 2534 | + ret = mlx5_dm_sw_icm_dealloc(dev, MLX5_SW_ICM_TYPE_HEADER_MODIFY, |
|---|
| 2535 | + dm->size, ctx->devx_uid, dm->dev_addr, |
|---|
| 2536 | + dm->icm_dm.obj_id); |
|---|
| 2537 | + if (ret) |
|---|
| 2538 | + return ret; |
|---|
| 2539 | + break; |
|---|
| 2540 | + default: |
|---|
| 2541 | + return -EOPNOTSUPP; |
|---|
| 2542 | + } |
|---|
| 2313 | 2543 | |
|---|
| 2314 | 2544 | kfree(dm); |
|---|
| 2315 | 2545 | |
|---|
| 2316 | 2546 | return 0; |
|---|
| 2317 | 2547 | } |
|---|
| 2318 | 2548 | |
|---|
| 2319 | | -static struct ib_pd *mlx5_ib_alloc_pd(struct ib_device *ibdev, |
|---|
| 2320 | | - struct ib_ucontext *context, |
|---|
| 2321 | | - struct ib_udata *udata) |
|---|
| 2549 | +static int mlx5_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) |
|---|
| 2322 | 2550 | { |
|---|
| 2551 | + struct mlx5_ib_pd *pd = to_mpd(ibpd); |
|---|
| 2552 | + struct ib_device *ibdev = ibpd->device; |
|---|
| 2323 | 2553 | struct mlx5_ib_alloc_pd_resp resp; |
|---|
| 2324 | | - struct mlx5_ib_pd *pd; |
|---|
| 2325 | 2554 | int err; |
|---|
| 2555 | + u32 out[MLX5_ST_SZ_DW(alloc_pd_out)] = {}; |
|---|
| 2556 | + u32 in[MLX5_ST_SZ_DW(alloc_pd_in)] = {}; |
|---|
| 2557 | + u16 uid = 0; |
|---|
| 2558 | + struct mlx5_ib_ucontext *context = rdma_udata_to_drv_context( |
|---|
| 2559 | + udata, struct mlx5_ib_ucontext, ibucontext); |
|---|
| 2326 | 2560 | |
|---|
| 2327 | | - pd = kmalloc(sizeof(*pd), GFP_KERNEL); |
|---|
| 2328 | | - if (!pd) |
|---|
| 2329 | | - return ERR_PTR(-ENOMEM); |
|---|
| 2561 | + uid = context ? context->devx_uid : 0; |
|---|
| 2562 | + MLX5_SET(alloc_pd_in, in, opcode, MLX5_CMD_OP_ALLOC_PD); |
|---|
| 2563 | + MLX5_SET(alloc_pd_in, in, uid, uid); |
|---|
| 2564 | + err = mlx5_cmd_exec_inout(to_mdev(ibdev)->mdev, alloc_pd, in, out); |
|---|
| 2565 | + if (err) |
|---|
| 2566 | + return err; |
|---|
| 2330 | 2567 | |
|---|
| 2331 | | - err = mlx5_core_alloc_pd(to_mdev(ibdev)->mdev, &pd->pdn); |
|---|
| 2332 | | - if (err) { |
|---|
| 2333 | | - kfree(pd); |
|---|
| 2334 | | - return ERR_PTR(err); |
|---|
| 2335 | | - } |
|---|
| 2336 | | - |
|---|
| 2337 | | - if (context) { |
|---|
| 2568 | + pd->pdn = MLX5_GET(alloc_pd_out, out, pd); |
|---|
| 2569 | + pd->uid = uid; |
|---|
| 2570 | + if (udata) { |
|---|
| 2338 | 2571 | resp.pdn = pd->pdn; |
|---|
| 2339 | 2572 | if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { |
|---|
| 2340 | | - mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn); |
|---|
| 2341 | | - kfree(pd); |
|---|
| 2342 | | - return ERR_PTR(-EFAULT); |
|---|
| 2573 | + mlx5_cmd_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn, uid); |
|---|
| 2574 | + return -EFAULT; |
|---|
| 2343 | 2575 | } |
|---|
| 2344 | 2576 | } |
|---|
| 2345 | 2577 | |
|---|
| 2346 | | - return &pd->ibpd; |
|---|
| 2578 | + return 0; |
|---|
| 2347 | 2579 | } |
|---|
| 2348 | 2580 | |
|---|
| 2349 | | -static int mlx5_ib_dealloc_pd(struct ib_pd *pd) |
|---|
| 2581 | +static int mlx5_ib_dealloc_pd(struct ib_pd *pd, struct ib_udata *udata) |
|---|
| 2350 | 2582 | { |
|---|
| 2351 | 2583 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
|---|
| 2352 | 2584 | struct mlx5_ib_pd *mpd = to_mpd(pd); |
|---|
| 2353 | 2585 | |
|---|
| 2354 | | - mlx5_core_dealloc_pd(mdev->mdev, mpd->pdn); |
|---|
| 2355 | | - kfree(mpd); |
|---|
| 2356 | | - |
|---|
| 2357 | | - return 0; |
|---|
| 2358 | | -} |
|---|
| 2359 | | - |
|---|
| 2360 | | -enum { |
|---|
| 2361 | | - MATCH_CRITERIA_ENABLE_OUTER_BIT, |
|---|
| 2362 | | - MATCH_CRITERIA_ENABLE_MISC_BIT, |
|---|
| 2363 | | - MATCH_CRITERIA_ENABLE_INNER_BIT, |
|---|
| 2364 | | - MATCH_CRITERIA_ENABLE_MISC2_BIT |
|---|
| 2365 | | -}; |
|---|
| 2366 | | - |
|---|
| 2367 | | -#define HEADER_IS_ZERO(match_criteria, headers) \ |
|---|
| 2368 | | - !(memchr_inv(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \ |
|---|
| 2369 | | - 0, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \ |
|---|
| 2370 | | - |
|---|
| 2371 | | -static u8 get_match_criteria_enable(u32 *match_criteria) |
|---|
| 2372 | | -{ |
|---|
| 2373 | | - u8 match_criteria_enable; |
|---|
| 2374 | | - |
|---|
| 2375 | | - match_criteria_enable = |
|---|
| 2376 | | - (!HEADER_IS_ZERO(match_criteria, outer_headers)) << |
|---|
| 2377 | | - MATCH_CRITERIA_ENABLE_OUTER_BIT; |
|---|
| 2378 | | - match_criteria_enable |= |
|---|
| 2379 | | - (!HEADER_IS_ZERO(match_criteria, misc_parameters)) << |
|---|
| 2380 | | - MATCH_CRITERIA_ENABLE_MISC_BIT; |
|---|
| 2381 | | - match_criteria_enable |= |
|---|
| 2382 | | - (!HEADER_IS_ZERO(match_criteria, inner_headers)) << |
|---|
| 2383 | | - MATCH_CRITERIA_ENABLE_INNER_BIT; |
|---|
| 2384 | | - match_criteria_enable |= |
|---|
| 2385 | | - (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) << |
|---|
| 2386 | | - MATCH_CRITERIA_ENABLE_MISC2_BIT; |
|---|
| 2387 | | - |
|---|
| 2388 | | - return match_criteria_enable; |
|---|
| 2389 | | -} |
|---|
| 2390 | | - |
|---|
| 2391 | | -static int set_proto(void *outer_c, void *outer_v, u8 mask, u8 val) |
|---|
| 2392 | | -{ |
|---|
| 2393 | | - u8 entry_mask; |
|---|
| 2394 | | - u8 entry_val; |
|---|
| 2395 | | - int err = 0; |
|---|
| 2396 | | - |
|---|
| 2397 | | - if (!mask) |
|---|
| 2398 | | - goto out; |
|---|
| 2399 | | - |
|---|
| 2400 | | - entry_mask = MLX5_GET(fte_match_set_lyr_2_4, outer_c, |
|---|
| 2401 | | - ip_protocol); |
|---|
| 2402 | | - entry_val = MLX5_GET(fte_match_set_lyr_2_4, outer_v, |
|---|
| 2403 | | - ip_protocol); |
|---|
| 2404 | | - if (!entry_mask) { |
|---|
| 2405 | | - MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_protocol, mask); |
|---|
| 2406 | | - MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_protocol, val); |
|---|
| 2407 | | - goto out; |
|---|
| 2408 | | - } |
|---|
| 2409 | | - /* Don't override existing ip protocol */ |
|---|
| 2410 | | - if (mask != entry_mask || val != entry_val) |
|---|
| 2411 | | - err = -EINVAL; |
|---|
| 2412 | | -out: |
|---|
| 2413 | | - return err; |
|---|
| 2414 | | -} |
|---|
| 2415 | | - |
|---|
| 2416 | | -static void set_flow_label(void *misc_c, void *misc_v, u32 mask, u32 val, |
|---|
| 2417 | | - bool inner) |
|---|
| 2418 | | -{ |
|---|
| 2419 | | - if (inner) { |
|---|
| 2420 | | - MLX5_SET(fte_match_set_misc, |
|---|
| 2421 | | - misc_c, inner_ipv6_flow_label, mask); |
|---|
| 2422 | | - MLX5_SET(fte_match_set_misc, |
|---|
| 2423 | | - misc_v, inner_ipv6_flow_label, val); |
|---|
| 2424 | | - } else { |
|---|
| 2425 | | - MLX5_SET(fte_match_set_misc, |
|---|
| 2426 | | - misc_c, outer_ipv6_flow_label, mask); |
|---|
| 2427 | | - MLX5_SET(fte_match_set_misc, |
|---|
| 2428 | | - misc_v, outer_ipv6_flow_label, val); |
|---|
| 2429 | | - } |
|---|
| 2430 | | -} |
|---|
| 2431 | | - |
|---|
| 2432 | | -static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val) |
|---|
| 2433 | | -{ |
|---|
| 2434 | | - MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_ecn, mask); |
|---|
| 2435 | | - MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_ecn, val); |
|---|
| 2436 | | - MLX5_SET(fte_match_set_lyr_2_4, outer_c, ip_dscp, mask >> 2); |
|---|
| 2437 | | - MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_dscp, val >> 2); |
|---|
| 2438 | | -} |
|---|
| 2439 | | - |
|---|
| 2440 | | -static int check_mpls_supp_fields(u32 field_support, const __be32 *set_mask) |
|---|
| 2441 | | -{ |
|---|
| 2442 | | - if (MLX5_GET(fte_match_mpls, set_mask, mpls_label) && |
|---|
| 2443 | | - !(field_support & MLX5_FIELD_SUPPORT_MPLS_LABEL)) |
|---|
| 2444 | | - return -EOPNOTSUPP; |
|---|
| 2445 | | - |
|---|
| 2446 | | - if (MLX5_GET(fte_match_mpls, set_mask, mpls_exp) && |
|---|
| 2447 | | - !(field_support & MLX5_FIELD_SUPPORT_MPLS_EXP)) |
|---|
| 2448 | | - return -EOPNOTSUPP; |
|---|
| 2449 | | - |
|---|
| 2450 | | - if (MLX5_GET(fte_match_mpls, set_mask, mpls_s_bos) && |
|---|
| 2451 | | - !(field_support & MLX5_FIELD_SUPPORT_MPLS_S_BOS)) |
|---|
| 2452 | | - return -EOPNOTSUPP; |
|---|
| 2453 | | - |
|---|
| 2454 | | - if (MLX5_GET(fte_match_mpls, set_mask, mpls_ttl) && |
|---|
| 2455 | | - !(field_support & MLX5_FIELD_SUPPORT_MPLS_TTL)) |
|---|
| 2456 | | - return -EOPNOTSUPP; |
|---|
| 2457 | | - |
|---|
| 2458 | | - return 0; |
|---|
| 2459 | | -} |
|---|
| 2460 | | - |
|---|
| 2461 | | -#define LAST_ETH_FIELD vlan_tag |
|---|
| 2462 | | -#define LAST_IB_FIELD sl |
|---|
| 2463 | | -#define LAST_IPV4_FIELD tos |
|---|
| 2464 | | -#define LAST_IPV6_FIELD traffic_class |
|---|
| 2465 | | -#define LAST_TCP_UDP_FIELD src_port |
|---|
| 2466 | | -#define LAST_TUNNEL_FIELD tunnel_id |
|---|
| 2467 | | -#define LAST_FLOW_TAG_FIELD tag_id |
|---|
| 2468 | | -#define LAST_DROP_FIELD size |
|---|
| 2469 | | -#define LAST_COUNTERS_FIELD counters |
|---|
| 2470 | | - |
|---|
| 2471 | | -/* Field is the last supported field */ |
|---|
| 2472 | | -#define FIELDS_NOT_SUPPORTED(filter, field)\ |
|---|
| 2473 | | - memchr_inv((void *)&filter.field +\ |
|---|
| 2474 | | - sizeof(filter.field), 0,\ |
|---|
| 2475 | | - sizeof(filter) -\ |
|---|
| 2476 | | - offsetof(typeof(filter), field) -\ |
|---|
| 2477 | | - sizeof(filter.field)) |
|---|
| 2478 | | - |
|---|
| 2479 | | -static int parse_flow_flow_action(const union ib_flow_spec *ib_spec, |
|---|
| 2480 | | - const struct ib_flow_attr *flow_attr, |
|---|
| 2481 | | - struct mlx5_flow_act *action) |
|---|
| 2482 | | -{ |
|---|
| 2483 | | - struct mlx5_ib_flow_action *maction = to_mflow_act(ib_spec->action.act); |
|---|
| 2484 | | - |
|---|
| 2485 | | - switch (maction->ib_action.type) { |
|---|
| 2486 | | - case IB_FLOW_ACTION_ESP: |
|---|
| 2487 | | - /* Currently only AES_GCM keymat is supported by the driver */ |
|---|
| 2488 | | - action->esp_id = (uintptr_t)maction->esp_aes_gcm.ctx; |
|---|
| 2489 | | - action->action |= flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS ? |
|---|
| 2490 | | - MLX5_FLOW_CONTEXT_ACTION_ENCRYPT : |
|---|
| 2491 | | - MLX5_FLOW_CONTEXT_ACTION_DECRYPT; |
|---|
| 2492 | | - return 0; |
|---|
| 2493 | | - default: |
|---|
| 2494 | | - return -EOPNOTSUPP; |
|---|
| 2495 | | - } |
|---|
| 2496 | | -} |
|---|
| 2497 | | - |
|---|
| 2498 | | -static int parse_flow_attr(struct mlx5_core_dev *mdev, u32 *match_c, |
|---|
| 2499 | | - u32 *match_v, const union ib_flow_spec *ib_spec, |
|---|
| 2500 | | - const struct ib_flow_attr *flow_attr, |
|---|
| 2501 | | - struct mlx5_flow_act *action, u32 prev_type) |
|---|
| 2502 | | -{ |
|---|
| 2503 | | - void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c, |
|---|
| 2504 | | - misc_parameters); |
|---|
| 2505 | | - void *misc_params_v = MLX5_ADDR_OF(fte_match_param, match_v, |
|---|
| 2506 | | - misc_parameters); |
|---|
| 2507 | | - void *misc_params2_c = MLX5_ADDR_OF(fte_match_param, match_c, |
|---|
| 2508 | | - misc_parameters_2); |
|---|
| 2509 | | - void *misc_params2_v = MLX5_ADDR_OF(fte_match_param, match_v, |
|---|
| 2510 | | - misc_parameters_2); |
|---|
| 2511 | | - void *headers_c; |
|---|
| 2512 | | - void *headers_v; |
|---|
| 2513 | | - int match_ipv; |
|---|
| 2514 | | - int ret; |
|---|
| 2515 | | - |
|---|
| 2516 | | - if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
|---|
| 2517 | | - headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
|---|
| 2518 | | - inner_headers); |
|---|
| 2519 | | - headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
|---|
| 2520 | | - inner_headers); |
|---|
| 2521 | | - match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
|---|
| 2522 | | - ft_field_support.inner_ip_version); |
|---|
| 2523 | | - } else { |
|---|
| 2524 | | - headers_c = MLX5_ADDR_OF(fte_match_param, match_c, |
|---|
| 2525 | | - outer_headers); |
|---|
| 2526 | | - headers_v = MLX5_ADDR_OF(fte_match_param, match_v, |
|---|
| 2527 | | - outer_headers); |
|---|
| 2528 | | - match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
|---|
| 2529 | | - ft_field_support.outer_ip_version); |
|---|
| 2530 | | - } |
|---|
| 2531 | | - |
|---|
| 2532 | | - switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) { |
|---|
| 2533 | | - case IB_FLOW_SPEC_ETH: |
|---|
| 2534 | | - if (FIELDS_NOT_SUPPORTED(ib_spec->eth.mask, LAST_ETH_FIELD)) |
|---|
| 2535 | | - return -EOPNOTSUPP; |
|---|
| 2536 | | - |
|---|
| 2537 | | - ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2538 | | - dmac_47_16), |
|---|
| 2539 | | - ib_spec->eth.mask.dst_mac); |
|---|
| 2540 | | - ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2541 | | - dmac_47_16), |
|---|
| 2542 | | - ib_spec->eth.val.dst_mac); |
|---|
| 2543 | | - |
|---|
| 2544 | | - ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2545 | | - smac_47_16), |
|---|
| 2546 | | - ib_spec->eth.mask.src_mac); |
|---|
| 2547 | | - ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2548 | | - smac_47_16), |
|---|
| 2549 | | - ib_spec->eth.val.src_mac); |
|---|
| 2550 | | - |
|---|
| 2551 | | - if (ib_spec->eth.mask.vlan_tag) { |
|---|
| 2552 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2553 | | - cvlan_tag, 1); |
|---|
| 2554 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2555 | | - cvlan_tag, 1); |
|---|
| 2556 | | - |
|---|
| 2557 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2558 | | - first_vid, ntohs(ib_spec->eth.mask.vlan_tag)); |
|---|
| 2559 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2560 | | - first_vid, ntohs(ib_spec->eth.val.vlan_tag)); |
|---|
| 2561 | | - |
|---|
| 2562 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2563 | | - first_cfi, |
|---|
| 2564 | | - ntohs(ib_spec->eth.mask.vlan_tag) >> 12); |
|---|
| 2565 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2566 | | - first_cfi, |
|---|
| 2567 | | - ntohs(ib_spec->eth.val.vlan_tag) >> 12); |
|---|
| 2568 | | - |
|---|
| 2569 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2570 | | - first_prio, |
|---|
| 2571 | | - ntohs(ib_spec->eth.mask.vlan_tag) >> 13); |
|---|
| 2572 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2573 | | - first_prio, |
|---|
| 2574 | | - ntohs(ib_spec->eth.val.vlan_tag) >> 13); |
|---|
| 2575 | | - } |
|---|
| 2576 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2577 | | - ethertype, ntohs(ib_spec->eth.mask.ether_type)); |
|---|
| 2578 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2579 | | - ethertype, ntohs(ib_spec->eth.val.ether_type)); |
|---|
| 2580 | | - break; |
|---|
| 2581 | | - case IB_FLOW_SPEC_IPV4: |
|---|
| 2582 | | - if (FIELDS_NOT_SUPPORTED(ib_spec->ipv4.mask, LAST_IPV4_FIELD)) |
|---|
| 2583 | | - return -EOPNOTSUPP; |
|---|
| 2584 | | - |
|---|
| 2585 | | - if (match_ipv) { |
|---|
| 2586 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2587 | | - ip_version, 0xf); |
|---|
| 2588 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2589 | | - ip_version, MLX5_FS_IPV4_VERSION); |
|---|
| 2590 | | - } else { |
|---|
| 2591 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2592 | | - ethertype, 0xffff); |
|---|
| 2593 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2594 | | - ethertype, ETH_P_IP); |
|---|
| 2595 | | - } |
|---|
| 2596 | | - |
|---|
| 2597 | | - memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2598 | | - src_ipv4_src_ipv6.ipv4_layout.ipv4), |
|---|
| 2599 | | - &ib_spec->ipv4.mask.src_ip, |
|---|
| 2600 | | - sizeof(ib_spec->ipv4.mask.src_ip)); |
|---|
| 2601 | | - memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2602 | | - src_ipv4_src_ipv6.ipv4_layout.ipv4), |
|---|
| 2603 | | - &ib_spec->ipv4.val.src_ip, |
|---|
| 2604 | | - sizeof(ib_spec->ipv4.val.src_ip)); |
|---|
| 2605 | | - memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2606 | | - dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
|---|
| 2607 | | - &ib_spec->ipv4.mask.dst_ip, |
|---|
| 2608 | | - sizeof(ib_spec->ipv4.mask.dst_ip)); |
|---|
| 2609 | | - memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2610 | | - dst_ipv4_dst_ipv6.ipv4_layout.ipv4), |
|---|
| 2611 | | - &ib_spec->ipv4.val.dst_ip, |
|---|
| 2612 | | - sizeof(ib_spec->ipv4.val.dst_ip)); |
|---|
| 2613 | | - |
|---|
| 2614 | | - set_tos(headers_c, headers_v, |
|---|
| 2615 | | - ib_spec->ipv4.mask.tos, ib_spec->ipv4.val.tos); |
|---|
| 2616 | | - |
|---|
| 2617 | | - if (set_proto(headers_c, headers_v, |
|---|
| 2618 | | - ib_spec->ipv4.mask.proto, |
|---|
| 2619 | | - ib_spec->ipv4.val.proto)) |
|---|
| 2620 | | - return -EINVAL; |
|---|
| 2621 | | - break; |
|---|
| 2622 | | - case IB_FLOW_SPEC_IPV6: |
|---|
| 2623 | | - if (FIELDS_NOT_SUPPORTED(ib_spec->ipv6.mask, LAST_IPV6_FIELD)) |
|---|
| 2624 | | - return -EOPNOTSUPP; |
|---|
| 2625 | | - |
|---|
| 2626 | | - if (match_ipv) { |
|---|
| 2627 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2628 | | - ip_version, 0xf); |
|---|
| 2629 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2630 | | - ip_version, MLX5_FS_IPV6_VERSION); |
|---|
| 2631 | | - } else { |
|---|
| 2632 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2633 | | - ethertype, 0xffff); |
|---|
| 2634 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2635 | | - ethertype, ETH_P_IPV6); |
|---|
| 2636 | | - } |
|---|
| 2637 | | - |
|---|
| 2638 | | - memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2639 | | - src_ipv4_src_ipv6.ipv6_layout.ipv6), |
|---|
| 2640 | | - &ib_spec->ipv6.mask.src_ip, |
|---|
| 2641 | | - sizeof(ib_spec->ipv6.mask.src_ip)); |
|---|
| 2642 | | - memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2643 | | - src_ipv4_src_ipv6.ipv6_layout.ipv6), |
|---|
| 2644 | | - &ib_spec->ipv6.val.src_ip, |
|---|
| 2645 | | - sizeof(ib_spec->ipv6.val.src_ip)); |
|---|
| 2646 | | - memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
|---|
| 2647 | | - dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
|---|
| 2648 | | - &ib_spec->ipv6.mask.dst_ip, |
|---|
| 2649 | | - sizeof(ib_spec->ipv6.mask.dst_ip)); |
|---|
| 2650 | | - memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
|---|
| 2651 | | - dst_ipv4_dst_ipv6.ipv6_layout.ipv6), |
|---|
| 2652 | | - &ib_spec->ipv6.val.dst_ip, |
|---|
| 2653 | | - sizeof(ib_spec->ipv6.val.dst_ip)); |
|---|
| 2654 | | - |
|---|
| 2655 | | - set_tos(headers_c, headers_v, |
|---|
| 2656 | | - ib_spec->ipv6.mask.traffic_class, |
|---|
| 2657 | | - ib_spec->ipv6.val.traffic_class); |
|---|
| 2658 | | - |
|---|
| 2659 | | - if (set_proto(headers_c, headers_v, |
|---|
| 2660 | | - ib_spec->ipv6.mask.next_hdr, |
|---|
| 2661 | | - ib_spec->ipv6.val.next_hdr)) |
|---|
| 2662 | | - return -EINVAL; |
|---|
| 2663 | | - |
|---|
| 2664 | | - set_flow_label(misc_params_c, misc_params_v, |
|---|
| 2665 | | - ntohl(ib_spec->ipv6.mask.flow_label), |
|---|
| 2666 | | - ntohl(ib_spec->ipv6.val.flow_label), |
|---|
| 2667 | | - ib_spec->type & IB_FLOW_SPEC_INNER); |
|---|
| 2668 | | - break; |
|---|
| 2669 | | - case IB_FLOW_SPEC_ESP: |
|---|
| 2670 | | - if (ib_spec->esp.mask.seq) |
|---|
| 2671 | | - return -EOPNOTSUPP; |
|---|
| 2672 | | - |
|---|
| 2673 | | - MLX5_SET(fte_match_set_misc, misc_params_c, outer_esp_spi, |
|---|
| 2674 | | - ntohl(ib_spec->esp.mask.spi)); |
|---|
| 2675 | | - MLX5_SET(fte_match_set_misc, misc_params_v, outer_esp_spi, |
|---|
| 2676 | | - ntohl(ib_spec->esp.val.spi)); |
|---|
| 2677 | | - break; |
|---|
| 2678 | | - case IB_FLOW_SPEC_TCP: |
|---|
| 2679 | | - if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
|---|
| 2680 | | - LAST_TCP_UDP_FIELD)) |
|---|
| 2681 | | - return -EOPNOTSUPP; |
|---|
| 2682 | | - |
|---|
| 2683 | | - if (set_proto(headers_c, headers_v, 0xff, IPPROTO_TCP)) |
|---|
| 2684 | | - return -EINVAL; |
|---|
| 2685 | | - |
|---|
| 2686 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_sport, |
|---|
| 2687 | | - ntohs(ib_spec->tcp_udp.mask.src_port)); |
|---|
| 2688 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport, |
|---|
| 2689 | | - ntohs(ib_spec->tcp_udp.val.src_port)); |
|---|
| 2690 | | - |
|---|
| 2691 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_dport, |
|---|
| 2692 | | - ntohs(ib_spec->tcp_udp.mask.dst_port)); |
|---|
| 2693 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport, |
|---|
| 2694 | | - ntohs(ib_spec->tcp_udp.val.dst_port)); |
|---|
| 2695 | | - break; |
|---|
| 2696 | | - case IB_FLOW_SPEC_UDP: |
|---|
| 2697 | | - if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, |
|---|
| 2698 | | - LAST_TCP_UDP_FIELD)) |
|---|
| 2699 | | - return -EOPNOTSUPP; |
|---|
| 2700 | | - |
|---|
| 2701 | | - if (set_proto(headers_c, headers_v, 0xff, IPPROTO_UDP)) |
|---|
| 2702 | | - return -EINVAL; |
|---|
| 2703 | | - |
|---|
| 2704 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_sport, |
|---|
| 2705 | | - ntohs(ib_spec->tcp_udp.mask.src_port)); |
|---|
| 2706 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport, |
|---|
| 2707 | | - ntohs(ib_spec->tcp_udp.val.src_port)); |
|---|
| 2708 | | - |
|---|
| 2709 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, udp_dport, |
|---|
| 2710 | | - ntohs(ib_spec->tcp_udp.mask.dst_port)); |
|---|
| 2711 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, |
|---|
| 2712 | | - ntohs(ib_spec->tcp_udp.val.dst_port)); |
|---|
| 2713 | | - break; |
|---|
| 2714 | | - case IB_FLOW_SPEC_GRE: |
|---|
| 2715 | | - if (ib_spec->gre.mask.c_ks_res0_ver) |
|---|
| 2716 | | - return -EOPNOTSUPP; |
|---|
| 2717 | | - |
|---|
| 2718 | | - if (set_proto(headers_c, headers_v, 0xff, IPPROTO_GRE)) |
|---|
| 2719 | | - return -EINVAL; |
|---|
| 2720 | | - |
|---|
| 2721 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, |
|---|
| 2722 | | - 0xff); |
|---|
| 2723 | | - MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
|---|
| 2724 | | - IPPROTO_GRE); |
|---|
| 2725 | | - |
|---|
| 2726 | | - MLX5_SET(fte_match_set_misc, misc_params_c, gre_protocol, |
|---|
| 2727 | | - ntohs(ib_spec->gre.mask.protocol)); |
|---|
| 2728 | | - MLX5_SET(fte_match_set_misc, misc_params_v, gre_protocol, |
|---|
| 2729 | | - ntohs(ib_spec->gre.val.protocol)); |
|---|
| 2730 | | - |
|---|
| 2731 | | - memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_c, |
|---|
| 2732 | | - gre_key_h), |
|---|
| 2733 | | - &ib_spec->gre.mask.key, |
|---|
| 2734 | | - sizeof(ib_spec->gre.mask.key)); |
|---|
| 2735 | | - memcpy(MLX5_ADDR_OF(fte_match_set_misc, misc_params_v, |
|---|
| 2736 | | - gre_key_h), |
|---|
| 2737 | | - &ib_spec->gre.val.key, |
|---|
| 2738 | | - sizeof(ib_spec->gre.val.key)); |
|---|
| 2739 | | - break; |
|---|
| 2740 | | - case IB_FLOW_SPEC_MPLS: |
|---|
| 2741 | | - switch (prev_type) { |
|---|
| 2742 | | - case IB_FLOW_SPEC_UDP: |
|---|
| 2743 | | - if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
|---|
| 2744 | | - ft_field_support.outer_first_mpls_over_udp), |
|---|
| 2745 | | - &ib_spec->mpls.mask.tag)) |
|---|
| 2746 | | - return -EOPNOTSUPP; |
|---|
| 2747 | | - |
|---|
| 2748 | | - memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
|---|
| 2749 | | - outer_first_mpls_over_udp), |
|---|
| 2750 | | - &ib_spec->mpls.val.tag, |
|---|
| 2751 | | - sizeof(ib_spec->mpls.val.tag)); |
|---|
| 2752 | | - memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
|---|
| 2753 | | - outer_first_mpls_over_udp), |
|---|
| 2754 | | - &ib_spec->mpls.mask.tag, |
|---|
| 2755 | | - sizeof(ib_spec->mpls.mask.tag)); |
|---|
| 2756 | | - break; |
|---|
| 2757 | | - case IB_FLOW_SPEC_GRE: |
|---|
| 2758 | | - if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
|---|
| 2759 | | - ft_field_support.outer_first_mpls_over_gre), |
|---|
| 2760 | | - &ib_spec->mpls.mask.tag)) |
|---|
| 2761 | | - return -EOPNOTSUPP; |
|---|
| 2762 | | - |
|---|
| 2763 | | - memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
|---|
| 2764 | | - outer_first_mpls_over_gre), |
|---|
| 2765 | | - &ib_spec->mpls.val.tag, |
|---|
| 2766 | | - sizeof(ib_spec->mpls.val.tag)); |
|---|
| 2767 | | - memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
|---|
| 2768 | | - outer_first_mpls_over_gre), |
|---|
| 2769 | | - &ib_spec->mpls.mask.tag, |
|---|
| 2770 | | - sizeof(ib_spec->mpls.mask.tag)); |
|---|
| 2771 | | - break; |
|---|
| 2772 | | - default: |
|---|
| 2773 | | - if (ib_spec->type & IB_FLOW_SPEC_INNER) { |
|---|
| 2774 | | - if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
|---|
| 2775 | | - ft_field_support.inner_first_mpls), |
|---|
| 2776 | | - &ib_spec->mpls.mask.tag)) |
|---|
| 2777 | | - return -EOPNOTSUPP; |
|---|
| 2778 | | - |
|---|
| 2779 | | - memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
|---|
| 2780 | | - inner_first_mpls), |
|---|
| 2781 | | - &ib_spec->mpls.val.tag, |
|---|
| 2782 | | - sizeof(ib_spec->mpls.val.tag)); |
|---|
| 2783 | | - memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
|---|
| 2784 | | - inner_first_mpls), |
|---|
| 2785 | | - &ib_spec->mpls.mask.tag, |
|---|
| 2786 | | - sizeof(ib_spec->mpls.mask.tag)); |
|---|
| 2787 | | - } else { |
|---|
| 2788 | | - if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
|---|
| 2789 | | - ft_field_support.outer_first_mpls), |
|---|
| 2790 | | - &ib_spec->mpls.mask.tag)) |
|---|
| 2791 | | - return -EOPNOTSUPP; |
|---|
| 2792 | | - |
|---|
| 2793 | | - memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v, |
|---|
| 2794 | | - outer_first_mpls), |
|---|
| 2795 | | - &ib_spec->mpls.val.tag, |
|---|
| 2796 | | - sizeof(ib_spec->mpls.val.tag)); |
|---|
| 2797 | | - memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c, |
|---|
| 2798 | | - outer_first_mpls), |
|---|
| 2799 | | - &ib_spec->mpls.mask.tag, |
|---|
| 2800 | | - sizeof(ib_spec->mpls.mask.tag)); |
|---|
| 2801 | | - } |
|---|
| 2802 | | - } |
|---|
| 2803 | | - break; |
|---|
| 2804 | | - case IB_FLOW_SPEC_VXLAN_TUNNEL: |
|---|
| 2805 | | - if (FIELDS_NOT_SUPPORTED(ib_spec->tunnel.mask, |
|---|
| 2806 | | - LAST_TUNNEL_FIELD)) |
|---|
| 2807 | | - return -EOPNOTSUPP; |
|---|
| 2808 | | - |
|---|
| 2809 | | - MLX5_SET(fte_match_set_misc, misc_params_c, vxlan_vni, |
|---|
| 2810 | | - ntohl(ib_spec->tunnel.mask.tunnel_id)); |
|---|
| 2811 | | - MLX5_SET(fte_match_set_misc, misc_params_v, vxlan_vni, |
|---|
| 2812 | | - ntohl(ib_spec->tunnel.val.tunnel_id)); |
|---|
| 2813 | | - break; |
|---|
| 2814 | | - case IB_FLOW_SPEC_ACTION_TAG: |
|---|
| 2815 | | - if (FIELDS_NOT_SUPPORTED(ib_spec->flow_tag, |
|---|
| 2816 | | - LAST_FLOW_TAG_FIELD)) |
|---|
| 2817 | | - return -EOPNOTSUPP; |
|---|
| 2818 | | - if (ib_spec->flow_tag.tag_id >= BIT(24)) |
|---|
| 2819 | | - return -EINVAL; |
|---|
| 2820 | | - |
|---|
| 2821 | | - action->flow_tag = ib_spec->flow_tag.tag_id; |
|---|
| 2822 | | - action->has_flow_tag = true; |
|---|
| 2823 | | - break; |
|---|
| 2824 | | - case IB_FLOW_SPEC_ACTION_DROP: |
|---|
| 2825 | | - if (FIELDS_NOT_SUPPORTED(ib_spec->drop, |
|---|
| 2826 | | - LAST_DROP_FIELD)) |
|---|
| 2827 | | - return -EOPNOTSUPP; |
|---|
| 2828 | | - action->action |= MLX5_FLOW_CONTEXT_ACTION_DROP; |
|---|
| 2829 | | - break; |
|---|
| 2830 | | - case IB_FLOW_SPEC_ACTION_HANDLE: |
|---|
| 2831 | | - ret = parse_flow_flow_action(ib_spec, flow_attr, action); |
|---|
| 2832 | | - if (ret) |
|---|
| 2833 | | - return ret; |
|---|
| 2834 | | - break; |
|---|
| 2835 | | - case IB_FLOW_SPEC_ACTION_COUNT: |
|---|
| 2836 | | - if (FIELDS_NOT_SUPPORTED(ib_spec->flow_count, |
|---|
| 2837 | | - LAST_COUNTERS_FIELD)) |
|---|
| 2838 | | - return -EOPNOTSUPP; |
|---|
| 2839 | | - |
|---|
| 2840 | | - /* for now support only one counters spec per flow */ |
|---|
| 2841 | | - if (action->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) |
|---|
| 2842 | | - return -EINVAL; |
|---|
| 2843 | | - |
|---|
| 2844 | | - action->counters = ib_spec->flow_count.counters; |
|---|
| 2845 | | - action->action |= MLX5_FLOW_CONTEXT_ACTION_COUNT; |
|---|
| 2846 | | - break; |
|---|
| 2847 | | - default: |
|---|
| 2848 | | - return -EINVAL; |
|---|
| 2849 | | - } |
|---|
| 2850 | | - |
|---|
| 2851 | | - return 0; |
|---|
| 2852 | | -} |
|---|
| 2853 | | - |
|---|
| 2854 | | -/* If a flow could catch both multicast and unicast packets, |
|---|
| 2855 | | - * it won't fall into the multicast flow steering table and this rule |
|---|
| 2856 | | - * could steal other multicast packets. |
|---|
| 2857 | | - */ |
|---|
| 2858 | | -static bool flow_is_multicast_only(const struct ib_flow_attr *ib_attr) |
|---|
| 2859 | | -{ |
|---|
| 2860 | | - union ib_flow_spec *flow_spec; |
|---|
| 2861 | | - |
|---|
| 2862 | | - if (ib_attr->type != IB_FLOW_ATTR_NORMAL || |
|---|
| 2863 | | - ib_attr->num_of_specs < 1) |
|---|
| 2864 | | - return false; |
|---|
| 2865 | | - |
|---|
| 2866 | | - flow_spec = (union ib_flow_spec *)(ib_attr + 1); |
|---|
| 2867 | | - if (flow_spec->type == IB_FLOW_SPEC_IPV4) { |
|---|
| 2868 | | - struct ib_flow_spec_ipv4 *ipv4_spec; |
|---|
| 2869 | | - |
|---|
| 2870 | | - ipv4_spec = (struct ib_flow_spec_ipv4 *)flow_spec; |
|---|
| 2871 | | - if (ipv4_is_multicast(ipv4_spec->val.dst_ip)) |
|---|
| 2872 | | - return true; |
|---|
| 2873 | | - |
|---|
| 2874 | | - return false; |
|---|
| 2875 | | - } |
|---|
| 2876 | | - |
|---|
| 2877 | | - if (flow_spec->type == IB_FLOW_SPEC_ETH) { |
|---|
| 2878 | | - struct ib_flow_spec_eth *eth_spec; |
|---|
| 2879 | | - |
|---|
| 2880 | | - eth_spec = (struct ib_flow_spec_eth *)flow_spec; |
|---|
| 2881 | | - return is_multicast_ether_addr(eth_spec->mask.dst_mac) && |
|---|
| 2882 | | - is_multicast_ether_addr(eth_spec->val.dst_mac); |
|---|
| 2883 | | - } |
|---|
| 2884 | | - |
|---|
| 2885 | | - return false; |
|---|
| 2886 | | -} |
|---|
| 2887 | | - |
|---|
| 2888 | | -enum valid_spec { |
|---|
| 2889 | | - VALID_SPEC_INVALID, |
|---|
| 2890 | | - VALID_SPEC_VALID, |
|---|
| 2891 | | - VALID_SPEC_NA, |
|---|
| 2892 | | -}; |
|---|
| 2893 | | - |
|---|
| 2894 | | -static enum valid_spec |
|---|
| 2895 | | -is_valid_esp_aes_gcm(struct mlx5_core_dev *mdev, |
|---|
| 2896 | | - const struct mlx5_flow_spec *spec, |
|---|
| 2897 | | - const struct mlx5_flow_act *flow_act, |
|---|
| 2898 | | - bool egress) |
|---|
| 2899 | | -{ |
|---|
| 2900 | | - const u32 *match_c = spec->match_criteria; |
|---|
| 2901 | | - bool is_crypto = |
|---|
| 2902 | | - (flow_act->action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT | |
|---|
| 2903 | | - MLX5_FLOW_CONTEXT_ACTION_DECRYPT)); |
|---|
| 2904 | | - bool is_ipsec = mlx5_fs_is_ipsec_flow(match_c); |
|---|
| 2905 | | - bool is_drop = flow_act->action & MLX5_FLOW_CONTEXT_ACTION_DROP; |
|---|
| 2906 | | - |
|---|
| 2907 | | - /* |
|---|
| 2908 | | - * Currently only crypto is supported in egress, when regular egress |
|---|
| 2909 | | - * rules would be supported, always return VALID_SPEC_NA. |
|---|
| 2910 | | - */ |
|---|
| 2911 | | - if (!is_crypto) |
|---|
| 2912 | | - return egress ? VALID_SPEC_INVALID : VALID_SPEC_NA; |
|---|
| 2913 | | - |
|---|
| 2914 | | - return is_crypto && is_ipsec && |
|---|
| 2915 | | - (!egress || (!is_drop && !flow_act->has_flow_tag)) ? |
|---|
| 2916 | | - VALID_SPEC_VALID : VALID_SPEC_INVALID; |
|---|
| 2917 | | -} |
|---|
| 2918 | | - |
|---|
| 2919 | | -static bool is_valid_spec(struct mlx5_core_dev *mdev, |
|---|
| 2920 | | - const struct mlx5_flow_spec *spec, |
|---|
| 2921 | | - const struct mlx5_flow_act *flow_act, |
|---|
| 2922 | | - bool egress) |
|---|
| 2923 | | -{ |
|---|
| 2924 | | - /* We curretly only support ipsec egress flow */ |
|---|
| 2925 | | - return is_valid_esp_aes_gcm(mdev, spec, flow_act, egress) != VALID_SPEC_INVALID; |
|---|
| 2926 | | -} |
|---|
| 2927 | | - |
|---|
| 2928 | | -static bool is_valid_ethertype(struct mlx5_core_dev *mdev, |
|---|
| 2929 | | - const struct ib_flow_attr *flow_attr, |
|---|
| 2930 | | - bool check_inner) |
|---|
| 2931 | | -{ |
|---|
| 2932 | | - union ib_flow_spec *ib_spec = (union ib_flow_spec *)(flow_attr + 1); |
|---|
| 2933 | | - int match_ipv = check_inner ? |
|---|
| 2934 | | - MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
|---|
| 2935 | | - ft_field_support.inner_ip_version) : |
|---|
| 2936 | | - MLX5_CAP_FLOWTABLE_NIC_RX(mdev, |
|---|
| 2937 | | - ft_field_support.outer_ip_version); |
|---|
| 2938 | | - int inner_bit = check_inner ? IB_FLOW_SPEC_INNER : 0; |
|---|
| 2939 | | - bool ipv4_spec_valid, ipv6_spec_valid; |
|---|
| 2940 | | - unsigned int ip_spec_type = 0; |
|---|
| 2941 | | - bool has_ethertype = false; |
|---|
| 2942 | | - unsigned int spec_index; |
|---|
| 2943 | | - bool mask_valid = true; |
|---|
| 2944 | | - u16 eth_type = 0; |
|---|
| 2945 | | - bool type_valid; |
|---|
| 2946 | | - |
|---|
| 2947 | | - /* Validate that ethertype is correct */ |
|---|
| 2948 | | - for (spec_index = 0; spec_index < flow_attr->num_of_specs; spec_index++) { |
|---|
| 2949 | | - if ((ib_spec->type == (IB_FLOW_SPEC_ETH | inner_bit)) && |
|---|
| 2950 | | - ib_spec->eth.mask.ether_type) { |
|---|
| 2951 | | - mask_valid = (ib_spec->eth.mask.ether_type == |
|---|
| 2952 | | - htons(0xffff)); |
|---|
| 2953 | | - has_ethertype = true; |
|---|
| 2954 | | - eth_type = ntohs(ib_spec->eth.val.ether_type); |
|---|
| 2955 | | - } else if ((ib_spec->type == (IB_FLOW_SPEC_IPV4 | inner_bit)) || |
|---|
| 2956 | | - (ib_spec->type == (IB_FLOW_SPEC_IPV6 | inner_bit))) { |
|---|
| 2957 | | - ip_spec_type = ib_spec->type; |
|---|
| 2958 | | - } |
|---|
| 2959 | | - ib_spec = (void *)ib_spec + ib_spec->size; |
|---|
| 2960 | | - } |
|---|
| 2961 | | - |
|---|
| 2962 | | - type_valid = (!has_ethertype) || (!ip_spec_type); |
|---|
| 2963 | | - if (!type_valid && mask_valid) { |
|---|
| 2964 | | - ipv4_spec_valid = (eth_type == ETH_P_IP) && |
|---|
| 2965 | | - (ip_spec_type == (IB_FLOW_SPEC_IPV4 | inner_bit)); |
|---|
| 2966 | | - ipv6_spec_valid = (eth_type == ETH_P_IPV6) && |
|---|
| 2967 | | - (ip_spec_type == (IB_FLOW_SPEC_IPV6 | inner_bit)); |
|---|
| 2968 | | - |
|---|
| 2969 | | - type_valid = (ipv4_spec_valid) || (ipv6_spec_valid) || |
|---|
| 2970 | | - (((eth_type == ETH_P_MPLS_UC) || |
|---|
| 2971 | | - (eth_type == ETH_P_MPLS_MC)) && match_ipv); |
|---|
| 2972 | | - } |
|---|
| 2973 | | - |
|---|
| 2974 | | - return type_valid; |
|---|
| 2975 | | -} |
|---|
| 2976 | | - |
|---|
| 2977 | | -static bool is_valid_attr(struct mlx5_core_dev *mdev, |
|---|
| 2978 | | - const struct ib_flow_attr *flow_attr) |
|---|
| 2979 | | -{ |
|---|
| 2980 | | - return is_valid_ethertype(mdev, flow_attr, false) && |
|---|
| 2981 | | - is_valid_ethertype(mdev, flow_attr, true); |
|---|
| 2982 | | -} |
|---|
| 2983 | | - |
|---|
| 2984 | | -static void put_flow_table(struct mlx5_ib_dev *dev, |
|---|
| 2985 | | - struct mlx5_ib_flow_prio *prio, bool ft_added) |
|---|
| 2986 | | -{ |
|---|
| 2987 | | - prio->refcount -= !!ft_added; |
|---|
| 2988 | | - if (!prio->refcount) { |
|---|
| 2989 | | - mlx5_destroy_flow_table(prio->flow_table); |
|---|
| 2990 | | - prio->flow_table = NULL; |
|---|
| 2991 | | - } |
|---|
| 2992 | | -} |
|---|
| 2993 | | - |
|---|
| 2994 | | -static void counters_clear_description(struct ib_counters *counters) |
|---|
| 2995 | | -{ |
|---|
| 2996 | | - struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
|---|
| 2997 | | - |
|---|
| 2998 | | - mutex_lock(&mcounters->mcntrs_mutex); |
|---|
| 2999 | | - kfree(mcounters->counters_data); |
|---|
| 3000 | | - mcounters->counters_data = NULL; |
|---|
| 3001 | | - mcounters->cntrs_max_index = 0; |
|---|
| 3002 | | - mutex_unlock(&mcounters->mcntrs_mutex); |
|---|
| 3003 | | -} |
|---|
| 3004 | | - |
|---|
| 3005 | | -static int mlx5_ib_destroy_flow(struct ib_flow *flow_id) |
|---|
| 3006 | | -{ |
|---|
| 3007 | | - struct mlx5_ib_flow_handler *handler = container_of(flow_id, |
|---|
| 3008 | | - struct mlx5_ib_flow_handler, |
|---|
| 3009 | | - ibflow); |
|---|
| 3010 | | - struct mlx5_ib_flow_handler *iter, *tmp; |
|---|
| 3011 | | - struct mlx5_ib_dev *dev = handler->dev; |
|---|
| 3012 | | - |
|---|
| 3013 | | - mutex_lock(&dev->flow_db->lock); |
|---|
| 3014 | | - |
|---|
| 3015 | | - list_for_each_entry_safe(iter, tmp, &handler->list, list) { |
|---|
| 3016 | | - mlx5_del_flow_rules(iter->rule); |
|---|
| 3017 | | - put_flow_table(dev, iter->prio, true); |
|---|
| 3018 | | - list_del(&iter->list); |
|---|
| 3019 | | - kfree(iter); |
|---|
| 3020 | | - } |
|---|
| 3021 | | - |
|---|
| 3022 | | - mlx5_del_flow_rules(handler->rule); |
|---|
| 3023 | | - put_flow_table(dev, handler->prio, true); |
|---|
| 3024 | | - if (handler->ibcounters && |
|---|
| 3025 | | - atomic_read(&handler->ibcounters->usecnt) == 1) |
|---|
| 3026 | | - counters_clear_description(handler->ibcounters); |
|---|
| 3027 | | - |
|---|
| 3028 | | - mutex_unlock(&dev->flow_db->lock); |
|---|
| 3029 | | - if (handler->flow_matcher) |
|---|
| 3030 | | - atomic_dec(&handler->flow_matcher->usecnt); |
|---|
| 3031 | | - kfree(handler); |
|---|
| 3032 | | - |
|---|
| 3033 | | - return 0; |
|---|
| 3034 | | -} |
|---|
| 3035 | | - |
|---|
| 3036 | | -static int ib_prio_to_core_prio(unsigned int priority, bool dont_trap) |
|---|
| 3037 | | -{ |
|---|
| 3038 | | - priority *= 2; |
|---|
| 3039 | | - if (!dont_trap) |
|---|
| 3040 | | - priority++; |
|---|
| 3041 | | - return priority; |
|---|
| 3042 | | -} |
|---|
| 3043 | | - |
|---|
| 3044 | | -enum flow_table_type { |
|---|
| 3045 | | - MLX5_IB_FT_RX, |
|---|
| 3046 | | - MLX5_IB_FT_TX |
|---|
| 3047 | | -}; |
|---|
| 3048 | | - |
|---|
| 3049 | | -#define MLX5_FS_MAX_TYPES 6 |
|---|
| 3050 | | -#define MLX5_FS_MAX_ENTRIES BIT(16) |
|---|
| 3051 | | - |
|---|
| 3052 | | -static struct mlx5_ib_flow_prio *_get_prio(struct mlx5_flow_namespace *ns, |
|---|
| 3053 | | - struct mlx5_ib_flow_prio *prio, |
|---|
| 3054 | | - int priority, |
|---|
| 3055 | | - int num_entries, int num_groups) |
|---|
| 3056 | | -{ |
|---|
| 3057 | | - struct mlx5_flow_table *ft; |
|---|
| 3058 | | - |
|---|
| 3059 | | - ft = mlx5_create_auto_grouped_flow_table(ns, priority, |
|---|
| 3060 | | - num_entries, |
|---|
| 3061 | | - num_groups, |
|---|
| 3062 | | - 0, 0); |
|---|
| 3063 | | - if (IS_ERR(ft)) |
|---|
| 3064 | | - return ERR_CAST(ft); |
|---|
| 3065 | | - |
|---|
| 3066 | | - prio->flow_table = ft; |
|---|
| 3067 | | - prio->refcount = 0; |
|---|
| 3068 | | - return prio; |
|---|
| 3069 | | -} |
|---|
| 3070 | | - |
|---|
| 3071 | | -static struct mlx5_ib_flow_prio *get_flow_table(struct mlx5_ib_dev *dev, |
|---|
| 3072 | | - struct ib_flow_attr *flow_attr, |
|---|
| 3073 | | - enum flow_table_type ft_type) |
|---|
| 3074 | | -{ |
|---|
| 3075 | | - bool dont_trap = flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP; |
|---|
| 3076 | | - struct mlx5_flow_namespace *ns = NULL; |
|---|
| 3077 | | - struct mlx5_ib_flow_prio *prio; |
|---|
| 3078 | | - struct mlx5_flow_table *ft; |
|---|
| 3079 | | - int max_table_size; |
|---|
| 3080 | | - int num_entries; |
|---|
| 3081 | | - int num_groups; |
|---|
| 3082 | | - int priority; |
|---|
| 3083 | | - |
|---|
| 3084 | | - max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
|---|
| 3085 | | - log_max_ft_size)); |
|---|
| 3086 | | - if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
|---|
| 3087 | | - if (ft_type == MLX5_IB_FT_TX) |
|---|
| 3088 | | - priority = 0; |
|---|
| 3089 | | - else if (flow_is_multicast_only(flow_attr) && |
|---|
| 3090 | | - !dont_trap) |
|---|
| 3091 | | - priority = MLX5_IB_FLOW_MCAST_PRIO; |
|---|
| 3092 | | - else |
|---|
| 3093 | | - priority = ib_prio_to_core_prio(flow_attr->priority, |
|---|
| 3094 | | - dont_trap); |
|---|
| 3095 | | - ns = mlx5_get_flow_namespace(dev->mdev, |
|---|
| 3096 | | - ft_type == MLX5_IB_FT_TX ? |
|---|
| 3097 | | - MLX5_FLOW_NAMESPACE_EGRESS : |
|---|
| 3098 | | - MLX5_FLOW_NAMESPACE_BYPASS); |
|---|
| 3099 | | - num_entries = MLX5_FS_MAX_ENTRIES; |
|---|
| 3100 | | - num_groups = MLX5_FS_MAX_TYPES; |
|---|
| 3101 | | - prio = &dev->flow_db->prios[priority]; |
|---|
| 3102 | | - } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
|---|
| 3103 | | - flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
|---|
| 3104 | | - ns = mlx5_get_flow_namespace(dev->mdev, |
|---|
| 3105 | | - MLX5_FLOW_NAMESPACE_LEFTOVERS); |
|---|
| 3106 | | - build_leftovers_ft_param(&priority, |
|---|
| 3107 | | - &num_entries, |
|---|
| 3108 | | - &num_groups); |
|---|
| 3109 | | - prio = &dev->flow_db->prios[MLX5_IB_FLOW_LEFTOVERS_PRIO]; |
|---|
| 3110 | | - } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
|---|
| 3111 | | - if (!MLX5_CAP_FLOWTABLE(dev->mdev, |
|---|
| 3112 | | - allow_sniffer_and_nic_rx_shared_tir)) |
|---|
| 3113 | | - return ERR_PTR(-ENOTSUPP); |
|---|
| 3114 | | - |
|---|
| 3115 | | - ns = mlx5_get_flow_namespace(dev->mdev, ft_type == MLX5_IB_FT_RX ? |
|---|
| 3116 | | - MLX5_FLOW_NAMESPACE_SNIFFER_RX : |
|---|
| 3117 | | - MLX5_FLOW_NAMESPACE_SNIFFER_TX); |
|---|
| 3118 | | - |
|---|
| 3119 | | - prio = &dev->flow_db->sniffer[ft_type]; |
|---|
| 3120 | | - priority = 0; |
|---|
| 3121 | | - num_entries = 1; |
|---|
| 3122 | | - num_groups = 1; |
|---|
| 3123 | | - } |
|---|
| 3124 | | - |
|---|
| 3125 | | - if (!ns) |
|---|
| 3126 | | - return ERR_PTR(-ENOTSUPP); |
|---|
| 3127 | | - |
|---|
| 3128 | | - if (num_entries > max_table_size) |
|---|
| 3129 | | - return ERR_PTR(-ENOMEM); |
|---|
| 3130 | | - |
|---|
| 3131 | | - ft = prio->flow_table; |
|---|
| 3132 | | - if (!ft) |
|---|
| 3133 | | - return _get_prio(ns, prio, priority, num_entries, num_groups); |
|---|
| 3134 | | - |
|---|
| 3135 | | - return prio; |
|---|
| 3136 | | -} |
|---|
| 3137 | | - |
|---|
| 3138 | | -static void set_underlay_qp(struct mlx5_ib_dev *dev, |
|---|
| 3139 | | - struct mlx5_flow_spec *spec, |
|---|
| 3140 | | - u32 underlay_qpn) |
|---|
| 3141 | | -{ |
|---|
| 3142 | | - void *misc_params_c = MLX5_ADDR_OF(fte_match_param, |
|---|
| 3143 | | - spec->match_criteria, |
|---|
| 3144 | | - misc_parameters); |
|---|
| 3145 | | - void *misc_params_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
|---|
| 3146 | | - misc_parameters); |
|---|
| 3147 | | - |
|---|
| 3148 | | - if (underlay_qpn && |
|---|
| 3149 | | - MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
|---|
| 3150 | | - ft_field_support.bth_dst_qp)) { |
|---|
| 3151 | | - MLX5_SET(fte_match_set_misc, |
|---|
| 3152 | | - misc_params_v, bth_dst_qp, underlay_qpn); |
|---|
| 3153 | | - MLX5_SET(fte_match_set_misc, |
|---|
| 3154 | | - misc_params_c, bth_dst_qp, 0xffffff); |
|---|
| 3155 | | - } |
|---|
| 3156 | | -} |
|---|
| 3157 | | - |
|---|
| 3158 | | -static int read_flow_counters(struct ib_device *ibdev, |
|---|
| 3159 | | - struct mlx5_read_counters_attr *read_attr) |
|---|
| 3160 | | -{ |
|---|
| 3161 | | - struct mlx5_fc *fc = read_attr->hw_cntrs_hndl; |
|---|
| 3162 | | - struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 3163 | | - |
|---|
| 3164 | | - return mlx5_fc_query(dev->mdev, fc, |
|---|
| 3165 | | - &read_attr->out[IB_COUNTER_PACKETS], |
|---|
| 3166 | | - &read_attr->out[IB_COUNTER_BYTES]); |
|---|
| 3167 | | -} |
|---|
| 3168 | | - |
|---|
| 3169 | | -/* flow counters currently expose two counters packets and bytes */ |
|---|
| 3170 | | -#define FLOW_COUNTERS_NUM 2 |
|---|
| 3171 | | -static int counters_set_description(struct ib_counters *counters, |
|---|
| 3172 | | - enum mlx5_ib_counters_type counters_type, |
|---|
| 3173 | | - struct mlx5_ib_flow_counters_desc *desc_data, |
|---|
| 3174 | | - u32 ncounters) |
|---|
| 3175 | | -{ |
|---|
| 3176 | | - struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
|---|
| 3177 | | - u32 cntrs_max_index = 0; |
|---|
| 3178 | | - int i; |
|---|
| 3179 | | - |
|---|
| 3180 | | - if (counters_type != MLX5_IB_COUNTERS_FLOW) |
|---|
| 3181 | | - return -EINVAL; |
|---|
| 3182 | | - |
|---|
| 3183 | | - /* init the fields for the object */ |
|---|
| 3184 | | - mcounters->type = counters_type; |
|---|
| 3185 | | - mcounters->read_counters = read_flow_counters; |
|---|
| 3186 | | - mcounters->counters_num = FLOW_COUNTERS_NUM; |
|---|
| 3187 | | - mcounters->ncounters = ncounters; |
|---|
| 3188 | | - /* each counter entry have both description and index pair */ |
|---|
| 3189 | | - for (i = 0; i < ncounters; i++) { |
|---|
| 3190 | | - if (desc_data[i].description > IB_COUNTER_BYTES) |
|---|
| 3191 | | - return -EINVAL; |
|---|
| 3192 | | - |
|---|
| 3193 | | - if (cntrs_max_index <= desc_data[i].index) |
|---|
| 3194 | | - cntrs_max_index = desc_data[i].index + 1; |
|---|
| 3195 | | - } |
|---|
| 3196 | | - |
|---|
| 3197 | | - mutex_lock(&mcounters->mcntrs_mutex); |
|---|
| 3198 | | - mcounters->counters_data = desc_data; |
|---|
| 3199 | | - mcounters->cntrs_max_index = cntrs_max_index; |
|---|
| 3200 | | - mutex_unlock(&mcounters->mcntrs_mutex); |
|---|
| 3201 | | - |
|---|
| 3202 | | - return 0; |
|---|
| 3203 | | -} |
|---|
| 3204 | | - |
|---|
| 3205 | | -#define MAX_COUNTERS_NUM (USHRT_MAX / (sizeof(u32) * 2)) |
|---|
| 3206 | | -static int flow_counters_set_data(struct ib_counters *ibcounters, |
|---|
| 3207 | | - struct mlx5_ib_create_flow *ucmd) |
|---|
| 3208 | | -{ |
|---|
| 3209 | | - struct mlx5_ib_mcounters *mcounters = to_mcounters(ibcounters); |
|---|
| 3210 | | - struct mlx5_ib_flow_counters_data *cntrs_data = NULL; |
|---|
| 3211 | | - struct mlx5_ib_flow_counters_desc *desc_data = NULL; |
|---|
| 3212 | | - bool hw_hndl = false; |
|---|
| 3213 | | - int ret = 0; |
|---|
| 3214 | | - |
|---|
| 3215 | | - if (ucmd && ucmd->ncounters_data != 0) { |
|---|
| 3216 | | - cntrs_data = ucmd->data; |
|---|
| 3217 | | - if (cntrs_data->ncounters > MAX_COUNTERS_NUM) |
|---|
| 3218 | | - return -EINVAL; |
|---|
| 3219 | | - |
|---|
| 3220 | | - desc_data = kcalloc(cntrs_data->ncounters, |
|---|
| 3221 | | - sizeof(*desc_data), |
|---|
| 3222 | | - GFP_KERNEL); |
|---|
| 3223 | | - if (!desc_data) |
|---|
| 3224 | | - return -ENOMEM; |
|---|
| 3225 | | - |
|---|
| 3226 | | - if (copy_from_user(desc_data, |
|---|
| 3227 | | - u64_to_user_ptr(cntrs_data->counters_data), |
|---|
| 3228 | | - sizeof(*desc_data) * cntrs_data->ncounters)) { |
|---|
| 3229 | | - ret = -EFAULT; |
|---|
| 3230 | | - goto free; |
|---|
| 3231 | | - } |
|---|
| 3232 | | - } |
|---|
| 3233 | | - |
|---|
| 3234 | | - if (!mcounters->hw_cntrs_hndl) { |
|---|
| 3235 | | - mcounters->hw_cntrs_hndl = mlx5_fc_create( |
|---|
| 3236 | | - to_mdev(ibcounters->device)->mdev, false); |
|---|
| 3237 | | - if (IS_ERR(mcounters->hw_cntrs_hndl)) { |
|---|
| 3238 | | - ret = PTR_ERR(mcounters->hw_cntrs_hndl); |
|---|
| 3239 | | - goto free; |
|---|
| 3240 | | - } |
|---|
| 3241 | | - hw_hndl = true; |
|---|
| 3242 | | - } |
|---|
| 3243 | | - |
|---|
| 3244 | | - if (desc_data) { |
|---|
| 3245 | | - /* counters already bound to at least one flow */ |
|---|
| 3246 | | - if (mcounters->cntrs_max_index) { |
|---|
| 3247 | | - ret = -EINVAL; |
|---|
| 3248 | | - goto free_hndl; |
|---|
| 3249 | | - } |
|---|
| 3250 | | - |
|---|
| 3251 | | - ret = counters_set_description(ibcounters, |
|---|
| 3252 | | - MLX5_IB_COUNTERS_FLOW, |
|---|
| 3253 | | - desc_data, |
|---|
| 3254 | | - cntrs_data->ncounters); |
|---|
| 3255 | | - if (ret) |
|---|
| 3256 | | - goto free_hndl; |
|---|
| 3257 | | - |
|---|
| 3258 | | - } else if (!mcounters->cntrs_max_index) { |
|---|
| 3259 | | - /* counters not bound yet, must have udata passed */ |
|---|
| 3260 | | - ret = -EINVAL; |
|---|
| 3261 | | - goto free_hndl; |
|---|
| 3262 | | - } |
|---|
| 3263 | | - |
|---|
| 3264 | | - return 0; |
|---|
| 3265 | | - |
|---|
| 3266 | | -free_hndl: |
|---|
| 3267 | | - if (hw_hndl) { |
|---|
| 3268 | | - mlx5_fc_destroy(to_mdev(ibcounters->device)->mdev, |
|---|
| 3269 | | - mcounters->hw_cntrs_hndl); |
|---|
| 3270 | | - mcounters->hw_cntrs_hndl = NULL; |
|---|
| 3271 | | - } |
|---|
| 3272 | | -free: |
|---|
| 3273 | | - kfree(desc_data); |
|---|
| 3274 | | - return ret; |
|---|
| 3275 | | -} |
|---|
| 3276 | | - |
|---|
| 3277 | | -static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev, |
|---|
| 3278 | | - struct mlx5_ib_flow_prio *ft_prio, |
|---|
| 3279 | | - const struct ib_flow_attr *flow_attr, |
|---|
| 3280 | | - struct mlx5_flow_destination *dst, |
|---|
| 3281 | | - u32 underlay_qpn, |
|---|
| 3282 | | - struct mlx5_ib_create_flow *ucmd) |
|---|
| 3283 | | -{ |
|---|
| 3284 | | - struct mlx5_flow_table *ft = ft_prio->flow_table; |
|---|
| 3285 | | - struct mlx5_ib_flow_handler *handler; |
|---|
| 3286 | | - struct mlx5_flow_act flow_act = {.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG}; |
|---|
| 3287 | | - struct mlx5_flow_spec *spec; |
|---|
| 3288 | | - struct mlx5_flow_destination dest_arr[2] = {}; |
|---|
| 3289 | | - struct mlx5_flow_destination *rule_dst = dest_arr; |
|---|
| 3290 | | - const void *ib_flow = (const void *)flow_attr + sizeof(*flow_attr); |
|---|
| 3291 | | - unsigned int spec_index; |
|---|
| 3292 | | - u32 prev_type = 0; |
|---|
| 3293 | | - int err = 0; |
|---|
| 3294 | | - int dest_num = 0; |
|---|
| 3295 | | - bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
|---|
| 3296 | | - |
|---|
| 3297 | | - if (!is_valid_attr(dev->mdev, flow_attr)) |
|---|
| 3298 | | - return ERR_PTR(-EINVAL); |
|---|
| 3299 | | - |
|---|
| 3300 | | - spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
|---|
| 3301 | | - handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
|---|
| 3302 | | - if (!handler || !spec) { |
|---|
| 3303 | | - err = -ENOMEM; |
|---|
| 3304 | | - goto free; |
|---|
| 3305 | | - } |
|---|
| 3306 | | - |
|---|
| 3307 | | - INIT_LIST_HEAD(&handler->list); |
|---|
| 3308 | | - |
|---|
| 3309 | | - for (spec_index = 0; spec_index < flow_attr->num_of_specs; spec_index++) { |
|---|
| 3310 | | - err = parse_flow_attr(dev->mdev, spec->match_criteria, |
|---|
| 3311 | | - spec->match_value, |
|---|
| 3312 | | - ib_flow, flow_attr, &flow_act, |
|---|
| 3313 | | - prev_type); |
|---|
| 3314 | | - if (err < 0) |
|---|
| 3315 | | - goto free; |
|---|
| 3316 | | - |
|---|
| 3317 | | - prev_type = ((union ib_flow_spec *)ib_flow)->type; |
|---|
| 3318 | | - ib_flow += ((union ib_flow_spec *)ib_flow)->size; |
|---|
| 3319 | | - } |
|---|
| 3320 | | - |
|---|
| 3321 | | - if (dst && !(flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DROP)) { |
|---|
| 3322 | | - memcpy(&dest_arr[0], dst, sizeof(*dst)); |
|---|
| 3323 | | - dest_num++; |
|---|
| 3324 | | - } |
|---|
| 3325 | | - |
|---|
| 3326 | | - if (!flow_is_multicast_only(flow_attr)) |
|---|
| 3327 | | - set_underlay_qp(dev, spec, underlay_qpn); |
|---|
| 3328 | | - |
|---|
| 3329 | | - if (dev->rep) { |
|---|
| 3330 | | - void *misc; |
|---|
| 3331 | | - |
|---|
| 3332 | | - misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, |
|---|
| 3333 | | - misc_parameters); |
|---|
| 3334 | | - MLX5_SET(fte_match_set_misc, misc, source_port, |
|---|
| 3335 | | - dev->rep->vport); |
|---|
| 3336 | | - misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
|---|
| 3337 | | - misc_parameters); |
|---|
| 3338 | | - MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port); |
|---|
| 3339 | | - } |
|---|
| 3340 | | - |
|---|
| 3341 | | - spec->match_criteria_enable = get_match_criteria_enable(spec->match_criteria); |
|---|
| 3342 | | - |
|---|
| 3343 | | - if (is_egress && |
|---|
| 3344 | | - !is_valid_spec(dev->mdev, spec, &flow_act, is_egress)) { |
|---|
| 3345 | | - err = -EINVAL; |
|---|
| 3346 | | - goto free; |
|---|
| 3347 | | - } |
|---|
| 3348 | | - |
|---|
| 3349 | | - if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
|---|
| 3350 | | - err = flow_counters_set_data(flow_act.counters, ucmd); |
|---|
| 3351 | | - if (err) |
|---|
| 3352 | | - goto free; |
|---|
| 3353 | | - |
|---|
| 3354 | | - handler->ibcounters = flow_act.counters; |
|---|
| 3355 | | - dest_arr[dest_num].type = |
|---|
| 3356 | | - MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
|---|
| 3357 | | - dest_arr[dest_num].counter = |
|---|
| 3358 | | - to_mcounters(flow_act.counters)->hw_cntrs_hndl; |
|---|
| 3359 | | - dest_num++; |
|---|
| 3360 | | - } |
|---|
| 3361 | | - |
|---|
| 3362 | | - if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DROP) { |
|---|
| 3363 | | - if (!dest_num) |
|---|
| 3364 | | - rule_dst = NULL; |
|---|
| 3365 | | - } else { |
|---|
| 3366 | | - if (is_egress) |
|---|
| 3367 | | - flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW; |
|---|
| 3368 | | - else |
|---|
| 3369 | | - flow_act.action |= |
|---|
| 3370 | | - dest_num ? MLX5_FLOW_CONTEXT_ACTION_FWD_DEST : |
|---|
| 3371 | | - MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO; |
|---|
| 3372 | | - } |
|---|
| 3373 | | - |
|---|
| 3374 | | - if (flow_act.has_flow_tag && |
|---|
| 3375 | | - (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
|---|
| 3376 | | - flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
|---|
| 3377 | | - mlx5_ib_warn(dev, "Flow tag %u and attribute type %x isn't allowed in leftovers\n", |
|---|
| 3378 | | - flow_act.flow_tag, flow_attr->type); |
|---|
| 3379 | | - err = -EINVAL; |
|---|
| 3380 | | - goto free; |
|---|
| 3381 | | - } |
|---|
| 3382 | | - handler->rule = mlx5_add_flow_rules(ft, spec, |
|---|
| 3383 | | - &flow_act, |
|---|
| 3384 | | - rule_dst, dest_num); |
|---|
| 3385 | | - |
|---|
| 3386 | | - if (IS_ERR(handler->rule)) { |
|---|
| 3387 | | - err = PTR_ERR(handler->rule); |
|---|
| 3388 | | - goto free; |
|---|
| 3389 | | - } |
|---|
| 3390 | | - |
|---|
| 3391 | | - ft_prio->refcount++; |
|---|
| 3392 | | - handler->prio = ft_prio; |
|---|
| 3393 | | - handler->dev = dev; |
|---|
| 3394 | | - |
|---|
| 3395 | | - ft_prio->flow_table = ft; |
|---|
| 3396 | | -free: |
|---|
| 3397 | | - if (err && handler) { |
|---|
| 3398 | | - if (handler->ibcounters && |
|---|
| 3399 | | - atomic_read(&handler->ibcounters->usecnt) == 1) |
|---|
| 3400 | | - counters_clear_description(handler->ibcounters); |
|---|
| 3401 | | - kfree(handler); |
|---|
| 3402 | | - } |
|---|
| 3403 | | - kvfree(spec); |
|---|
| 3404 | | - return err ? ERR_PTR(err) : handler; |
|---|
| 3405 | | -} |
|---|
| 3406 | | - |
|---|
| 3407 | | -static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev, |
|---|
| 3408 | | - struct mlx5_ib_flow_prio *ft_prio, |
|---|
| 3409 | | - const struct ib_flow_attr *flow_attr, |
|---|
| 3410 | | - struct mlx5_flow_destination *dst) |
|---|
| 3411 | | -{ |
|---|
| 3412 | | - return _create_flow_rule(dev, ft_prio, flow_attr, dst, 0, NULL); |
|---|
| 3413 | | -} |
|---|
| 3414 | | - |
|---|
| 3415 | | -static struct mlx5_ib_flow_handler *create_dont_trap_rule(struct mlx5_ib_dev *dev, |
|---|
| 3416 | | - struct mlx5_ib_flow_prio *ft_prio, |
|---|
| 3417 | | - struct ib_flow_attr *flow_attr, |
|---|
| 3418 | | - struct mlx5_flow_destination *dst) |
|---|
| 3419 | | -{ |
|---|
| 3420 | | - struct mlx5_ib_flow_handler *handler_dst = NULL; |
|---|
| 3421 | | - struct mlx5_ib_flow_handler *handler = NULL; |
|---|
| 3422 | | - |
|---|
| 3423 | | - handler = create_flow_rule(dev, ft_prio, flow_attr, NULL); |
|---|
| 3424 | | - if (!IS_ERR(handler)) { |
|---|
| 3425 | | - handler_dst = create_flow_rule(dev, ft_prio, |
|---|
| 3426 | | - flow_attr, dst); |
|---|
| 3427 | | - if (IS_ERR(handler_dst)) { |
|---|
| 3428 | | - mlx5_del_flow_rules(handler->rule); |
|---|
| 3429 | | - ft_prio->refcount--; |
|---|
| 3430 | | - kfree(handler); |
|---|
| 3431 | | - handler = handler_dst; |
|---|
| 3432 | | - } else { |
|---|
| 3433 | | - list_add(&handler_dst->list, &handler->list); |
|---|
| 3434 | | - } |
|---|
| 3435 | | - } |
|---|
| 3436 | | - |
|---|
| 3437 | | - return handler; |
|---|
| 3438 | | -} |
|---|
| 3439 | | -enum { |
|---|
| 3440 | | - LEFTOVERS_MC, |
|---|
| 3441 | | - LEFTOVERS_UC, |
|---|
| 3442 | | -}; |
|---|
| 3443 | | - |
|---|
| 3444 | | -static struct mlx5_ib_flow_handler *create_leftovers_rule(struct mlx5_ib_dev *dev, |
|---|
| 3445 | | - struct mlx5_ib_flow_prio *ft_prio, |
|---|
| 3446 | | - struct ib_flow_attr *flow_attr, |
|---|
| 3447 | | - struct mlx5_flow_destination *dst) |
|---|
| 3448 | | -{ |
|---|
| 3449 | | - struct mlx5_ib_flow_handler *handler_ucast = NULL; |
|---|
| 3450 | | - struct mlx5_ib_flow_handler *handler = NULL; |
|---|
| 3451 | | - |
|---|
| 3452 | | - static struct { |
|---|
| 3453 | | - struct ib_flow_attr flow_attr; |
|---|
| 3454 | | - struct ib_flow_spec_eth eth_flow; |
|---|
| 3455 | | - } leftovers_specs[] = { |
|---|
| 3456 | | - [LEFTOVERS_MC] = { |
|---|
| 3457 | | - .flow_attr = { |
|---|
| 3458 | | - .num_of_specs = 1, |
|---|
| 3459 | | - .size = sizeof(leftovers_specs[0]) |
|---|
| 3460 | | - }, |
|---|
| 3461 | | - .eth_flow = { |
|---|
| 3462 | | - .type = IB_FLOW_SPEC_ETH, |
|---|
| 3463 | | - .size = sizeof(struct ib_flow_spec_eth), |
|---|
| 3464 | | - .mask = {.dst_mac = {0x1} }, |
|---|
| 3465 | | - .val = {.dst_mac = {0x1} } |
|---|
| 3466 | | - } |
|---|
| 3467 | | - }, |
|---|
| 3468 | | - [LEFTOVERS_UC] = { |
|---|
| 3469 | | - .flow_attr = { |
|---|
| 3470 | | - .num_of_specs = 1, |
|---|
| 3471 | | - .size = sizeof(leftovers_specs[0]) |
|---|
| 3472 | | - }, |
|---|
| 3473 | | - .eth_flow = { |
|---|
| 3474 | | - .type = IB_FLOW_SPEC_ETH, |
|---|
| 3475 | | - .size = sizeof(struct ib_flow_spec_eth), |
|---|
| 3476 | | - .mask = {.dst_mac = {0x1} }, |
|---|
| 3477 | | - .val = {.dst_mac = {} } |
|---|
| 3478 | | - } |
|---|
| 3479 | | - } |
|---|
| 3480 | | - }; |
|---|
| 3481 | | - |
|---|
| 3482 | | - handler = create_flow_rule(dev, ft_prio, |
|---|
| 3483 | | - &leftovers_specs[LEFTOVERS_MC].flow_attr, |
|---|
| 3484 | | - dst); |
|---|
| 3485 | | - if (!IS_ERR(handler) && |
|---|
| 3486 | | - flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT) { |
|---|
| 3487 | | - handler_ucast = create_flow_rule(dev, ft_prio, |
|---|
| 3488 | | - &leftovers_specs[LEFTOVERS_UC].flow_attr, |
|---|
| 3489 | | - dst); |
|---|
| 3490 | | - if (IS_ERR(handler_ucast)) { |
|---|
| 3491 | | - mlx5_del_flow_rules(handler->rule); |
|---|
| 3492 | | - ft_prio->refcount--; |
|---|
| 3493 | | - kfree(handler); |
|---|
| 3494 | | - handler = handler_ucast; |
|---|
| 3495 | | - } else { |
|---|
| 3496 | | - list_add(&handler_ucast->list, &handler->list); |
|---|
| 3497 | | - } |
|---|
| 3498 | | - } |
|---|
| 3499 | | - |
|---|
| 3500 | | - return handler; |
|---|
| 3501 | | -} |
|---|
| 3502 | | - |
|---|
| 3503 | | -static struct mlx5_ib_flow_handler *create_sniffer_rule(struct mlx5_ib_dev *dev, |
|---|
| 3504 | | - struct mlx5_ib_flow_prio *ft_rx, |
|---|
| 3505 | | - struct mlx5_ib_flow_prio *ft_tx, |
|---|
| 3506 | | - struct mlx5_flow_destination *dst) |
|---|
| 3507 | | -{ |
|---|
| 3508 | | - struct mlx5_ib_flow_handler *handler_rx; |
|---|
| 3509 | | - struct mlx5_ib_flow_handler *handler_tx; |
|---|
| 3510 | | - int err; |
|---|
| 3511 | | - static const struct ib_flow_attr flow_attr = { |
|---|
| 3512 | | - .num_of_specs = 0, |
|---|
| 3513 | | - .size = sizeof(flow_attr) |
|---|
| 3514 | | - }; |
|---|
| 3515 | | - |
|---|
| 3516 | | - handler_rx = create_flow_rule(dev, ft_rx, &flow_attr, dst); |
|---|
| 3517 | | - if (IS_ERR(handler_rx)) { |
|---|
| 3518 | | - err = PTR_ERR(handler_rx); |
|---|
| 3519 | | - goto err; |
|---|
| 3520 | | - } |
|---|
| 3521 | | - |
|---|
| 3522 | | - handler_tx = create_flow_rule(dev, ft_tx, &flow_attr, dst); |
|---|
| 3523 | | - if (IS_ERR(handler_tx)) { |
|---|
| 3524 | | - err = PTR_ERR(handler_tx); |
|---|
| 3525 | | - goto err_tx; |
|---|
| 3526 | | - } |
|---|
| 3527 | | - |
|---|
| 3528 | | - list_add(&handler_tx->list, &handler_rx->list); |
|---|
| 3529 | | - |
|---|
| 3530 | | - return handler_rx; |
|---|
| 3531 | | - |
|---|
| 3532 | | -err_tx: |
|---|
| 3533 | | - mlx5_del_flow_rules(handler_rx->rule); |
|---|
| 3534 | | - ft_rx->refcount--; |
|---|
| 3535 | | - kfree(handler_rx); |
|---|
| 3536 | | -err: |
|---|
| 3537 | | - return ERR_PTR(err); |
|---|
| 3538 | | -} |
|---|
| 3539 | | - |
|---|
| 3540 | | -static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, |
|---|
| 3541 | | - struct ib_flow_attr *flow_attr, |
|---|
| 3542 | | - int domain, |
|---|
| 3543 | | - struct ib_udata *udata) |
|---|
| 3544 | | -{ |
|---|
| 3545 | | - struct mlx5_ib_dev *dev = to_mdev(qp->device); |
|---|
| 3546 | | - struct mlx5_ib_qp *mqp = to_mqp(qp); |
|---|
| 3547 | | - struct mlx5_ib_flow_handler *handler = NULL; |
|---|
| 3548 | | - struct mlx5_flow_destination *dst = NULL; |
|---|
| 3549 | | - struct mlx5_ib_flow_prio *ft_prio_tx = NULL; |
|---|
| 3550 | | - struct mlx5_ib_flow_prio *ft_prio; |
|---|
| 3551 | | - bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS; |
|---|
| 3552 | | - struct mlx5_ib_create_flow *ucmd = NULL, ucmd_hdr; |
|---|
| 3553 | | - size_t min_ucmd_sz, required_ucmd_sz; |
|---|
| 3554 | | - int err; |
|---|
| 3555 | | - int underlay_qpn; |
|---|
| 3556 | | - |
|---|
| 3557 | | - if (udata && udata->inlen) { |
|---|
| 3558 | | - min_ucmd_sz = offsetof(typeof(ucmd_hdr), reserved) + |
|---|
| 3559 | | - sizeof(ucmd_hdr.reserved); |
|---|
| 3560 | | - if (udata->inlen < min_ucmd_sz) |
|---|
| 3561 | | - return ERR_PTR(-EOPNOTSUPP); |
|---|
| 3562 | | - |
|---|
| 3563 | | - err = ib_copy_from_udata(&ucmd_hdr, udata, min_ucmd_sz); |
|---|
| 3564 | | - if (err) |
|---|
| 3565 | | - return ERR_PTR(err); |
|---|
| 3566 | | - |
|---|
| 3567 | | - /* currently supports only one counters data */ |
|---|
| 3568 | | - if (ucmd_hdr.ncounters_data > 1) |
|---|
| 3569 | | - return ERR_PTR(-EINVAL); |
|---|
| 3570 | | - |
|---|
| 3571 | | - required_ucmd_sz = min_ucmd_sz + |
|---|
| 3572 | | - sizeof(struct mlx5_ib_flow_counters_data) * |
|---|
| 3573 | | - ucmd_hdr.ncounters_data; |
|---|
| 3574 | | - if (udata->inlen > required_ucmd_sz && |
|---|
| 3575 | | - !ib_is_udata_cleared(udata, required_ucmd_sz, |
|---|
| 3576 | | - udata->inlen - required_ucmd_sz)) |
|---|
| 3577 | | - return ERR_PTR(-EOPNOTSUPP); |
|---|
| 3578 | | - |
|---|
| 3579 | | - ucmd = kzalloc(required_ucmd_sz, GFP_KERNEL); |
|---|
| 3580 | | - if (!ucmd) |
|---|
| 3581 | | - return ERR_PTR(-ENOMEM); |
|---|
| 3582 | | - |
|---|
| 3583 | | - err = ib_copy_from_udata(ucmd, udata, required_ucmd_sz); |
|---|
| 3584 | | - if (err) |
|---|
| 3585 | | - goto free_ucmd; |
|---|
| 3586 | | - } |
|---|
| 3587 | | - |
|---|
| 3588 | | - if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) { |
|---|
| 3589 | | - err = -ENOMEM; |
|---|
| 3590 | | - goto free_ucmd; |
|---|
| 3591 | | - } |
|---|
| 3592 | | - |
|---|
| 3593 | | - if (domain != IB_FLOW_DOMAIN_USER || |
|---|
| 3594 | | - flow_attr->port > dev->num_ports || |
|---|
| 3595 | | - (flow_attr->flags & ~(IB_FLOW_ATTR_FLAGS_DONT_TRAP | |
|---|
| 3596 | | - IB_FLOW_ATTR_FLAGS_EGRESS))) { |
|---|
| 3597 | | - err = -EINVAL; |
|---|
| 3598 | | - goto free_ucmd; |
|---|
| 3599 | | - } |
|---|
| 3600 | | - |
|---|
| 3601 | | - if (is_egress && |
|---|
| 3602 | | - (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
|---|
| 3603 | | - flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) { |
|---|
| 3604 | | - err = -EINVAL; |
|---|
| 3605 | | - goto free_ucmd; |
|---|
| 3606 | | - } |
|---|
| 3607 | | - |
|---|
| 3608 | | - dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
|---|
| 3609 | | - if (!dst) { |
|---|
| 3610 | | - err = -ENOMEM; |
|---|
| 3611 | | - goto free_ucmd; |
|---|
| 3612 | | - } |
|---|
| 3613 | | - |
|---|
| 3614 | | - mutex_lock(&dev->flow_db->lock); |
|---|
| 3615 | | - |
|---|
| 3616 | | - ft_prio = get_flow_table(dev, flow_attr, |
|---|
| 3617 | | - is_egress ? MLX5_IB_FT_TX : MLX5_IB_FT_RX); |
|---|
| 3618 | | - if (IS_ERR(ft_prio)) { |
|---|
| 3619 | | - err = PTR_ERR(ft_prio); |
|---|
| 3620 | | - goto unlock; |
|---|
| 3621 | | - } |
|---|
| 3622 | | - if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
|---|
| 3623 | | - ft_prio_tx = get_flow_table(dev, flow_attr, MLX5_IB_FT_TX); |
|---|
| 3624 | | - if (IS_ERR(ft_prio_tx)) { |
|---|
| 3625 | | - err = PTR_ERR(ft_prio_tx); |
|---|
| 3626 | | - ft_prio_tx = NULL; |
|---|
| 3627 | | - goto destroy_ft; |
|---|
| 3628 | | - } |
|---|
| 3629 | | - } |
|---|
| 3630 | | - |
|---|
| 3631 | | - if (is_egress) { |
|---|
| 3632 | | - dst->type = MLX5_FLOW_DESTINATION_TYPE_PORT; |
|---|
| 3633 | | - } else { |
|---|
| 3634 | | - dst->type = MLX5_FLOW_DESTINATION_TYPE_TIR; |
|---|
| 3635 | | - if (mqp->flags & MLX5_IB_QP_RSS) |
|---|
| 3636 | | - dst->tir_num = mqp->rss_qp.tirn; |
|---|
| 3637 | | - else |
|---|
| 3638 | | - dst->tir_num = mqp->raw_packet_qp.rq.tirn; |
|---|
| 3639 | | - } |
|---|
| 3640 | | - |
|---|
| 3641 | | - if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { |
|---|
| 3642 | | - if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) { |
|---|
| 3643 | | - handler = create_dont_trap_rule(dev, ft_prio, |
|---|
| 3644 | | - flow_attr, dst); |
|---|
| 3645 | | - } else { |
|---|
| 3646 | | - underlay_qpn = (mqp->flags & MLX5_IB_QP_UNDERLAY) ? |
|---|
| 3647 | | - mqp->underlay_qpn : 0; |
|---|
| 3648 | | - handler = _create_flow_rule(dev, ft_prio, flow_attr, |
|---|
| 3649 | | - dst, underlay_qpn, ucmd); |
|---|
| 3650 | | - } |
|---|
| 3651 | | - } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || |
|---|
| 3652 | | - flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { |
|---|
| 3653 | | - handler = create_leftovers_rule(dev, ft_prio, flow_attr, |
|---|
| 3654 | | - dst); |
|---|
| 3655 | | - } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { |
|---|
| 3656 | | - handler = create_sniffer_rule(dev, ft_prio, ft_prio_tx, dst); |
|---|
| 3657 | | - } else { |
|---|
| 3658 | | - err = -EINVAL; |
|---|
| 3659 | | - goto destroy_ft; |
|---|
| 3660 | | - } |
|---|
| 3661 | | - |
|---|
| 3662 | | - if (IS_ERR(handler)) { |
|---|
| 3663 | | - err = PTR_ERR(handler); |
|---|
| 3664 | | - handler = NULL; |
|---|
| 3665 | | - goto destroy_ft; |
|---|
| 3666 | | - } |
|---|
| 3667 | | - |
|---|
| 3668 | | - mutex_unlock(&dev->flow_db->lock); |
|---|
| 3669 | | - kfree(dst); |
|---|
| 3670 | | - kfree(ucmd); |
|---|
| 3671 | | - |
|---|
| 3672 | | - return &handler->ibflow; |
|---|
| 3673 | | - |
|---|
| 3674 | | -destroy_ft: |
|---|
| 3675 | | - put_flow_table(dev, ft_prio, false); |
|---|
| 3676 | | - if (ft_prio_tx) |
|---|
| 3677 | | - put_flow_table(dev, ft_prio_tx, false); |
|---|
| 3678 | | -unlock: |
|---|
| 3679 | | - mutex_unlock(&dev->flow_db->lock); |
|---|
| 3680 | | - kfree(dst); |
|---|
| 3681 | | -free_ucmd: |
|---|
| 3682 | | - kfree(ucmd); |
|---|
| 3683 | | - return ERR_PTR(err); |
|---|
| 3684 | | -} |
|---|
| 3685 | | - |
|---|
| 3686 | | -static struct mlx5_ib_flow_prio *_get_flow_table(struct mlx5_ib_dev *dev, |
|---|
| 3687 | | - int priority, bool mcast) |
|---|
| 3688 | | -{ |
|---|
| 3689 | | - int max_table_size; |
|---|
| 3690 | | - struct mlx5_flow_namespace *ns = NULL; |
|---|
| 3691 | | - struct mlx5_ib_flow_prio *prio; |
|---|
| 3692 | | - |
|---|
| 3693 | | - max_table_size = BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, |
|---|
| 3694 | | - log_max_ft_size)); |
|---|
| 3695 | | - if (max_table_size < MLX5_FS_MAX_ENTRIES) |
|---|
| 3696 | | - return ERR_PTR(-ENOMEM); |
|---|
| 3697 | | - |
|---|
| 3698 | | - if (mcast) |
|---|
| 3699 | | - priority = MLX5_IB_FLOW_MCAST_PRIO; |
|---|
| 3700 | | - else |
|---|
| 3701 | | - priority = ib_prio_to_core_prio(priority, false); |
|---|
| 3702 | | - |
|---|
| 3703 | | - ns = mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_BYPASS); |
|---|
| 3704 | | - if (!ns) |
|---|
| 3705 | | - return ERR_PTR(-ENOTSUPP); |
|---|
| 3706 | | - |
|---|
| 3707 | | - prio = &dev->flow_db->prios[priority]; |
|---|
| 3708 | | - |
|---|
| 3709 | | - if (prio->flow_table) |
|---|
| 3710 | | - return prio; |
|---|
| 3711 | | - |
|---|
| 3712 | | - return _get_prio(ns, prio, priority, MLX5_FS_MAX_ENTRIES, |
|---|
| 3713 | | - MLX5_FS_MAX_TYPES); |
|---|
| 3714 | | -} |
|---|
| 3715 | | - |
|---|
| 3716 | | -static struct mlx5_ib_flow_handler * |
|---|
| 3717 | | -_create_raw_flow_rule(struct mlx5_ib_dev *dev, |
|---|
| 3718 | | - struct mlx5_ib_flow_prio *ft_prio, |
|---|
| 3719 | | - struct mlx5_flow_destination *dst, |
|---|
| 3720 | | - struct mlx5_ib_flow_matcher *fs_matcher, |
|---|
| 3721 | | - void *cmd_in, int inlen) |
|---|
| 3722 | | -{ |
|---|
| 3723 | | - struct mlx5_ib_flow_handler *handler; |
|---|
| 3724 | | - struct mlx5_flow_act flow_act = {.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG}; |
|---|
| 3725 | | - struct mlx5_flow_spec *spec; |
|---|
| 3726 | | - struct mlx5_flow_table *ft = ft_prio->flow_table; |
|---|
| 3727 | | - int err = 0; |
|---|
| 3728 | | - |
|---|
| 3729 | | - spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
|---|
| 3730 | | - handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
|---|
| 3731 | | - if (!handler || !spec) { |
|---|
| 3732 | | - err = -ENOMEM; |
|---|
| 3733 | | - goto free; |
|---|
| 3734 | | - } |
|---|
| 3735 | | - |
|---|
| 3736 | | - INIT_LIST_HEAD(&handler->list); |
|---|
| 3737 | | - |
|---|
| 3738 | | - memcpy(spec->match_value, cmd_in, inlen); |
|---|
| 3739 | | - memcpy(spec->match_criteria, fs_matcher->matcher_mask.match_params, |
|---|
| 3740 | | - fs_matcher->mask_len); |
|---|
| 3741 | | - spec->match_criteria_enable = fs_matcher->match_criteria_enable; |
|---|
| 3742 | | - |
|---|
| 3743 | | - flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
|---|
| 3744 | | - handler->rule = mlx5_add_flow_rules(ft, spec, |
|---|
| 3745 | | - &flow_act, dst, 1); |
|---|
| 3746 | | - |
|---|
| 3747 | | - if (IS_ERR(handler->rule)) { |
|---|
| 3748 | | - err = PTR_ERR(handler->rule); |
|---|
| 3749 | | - goto free; |
|---|
| 3750 | | - } |
|---|
| 3751 | | - |
|---|
| 3752 | | - ft_prio->refcount++; |
|---|
| 3753 | | - handler->prio = ft_prio; |
|---|
| 3754 | | - handler->dev = dev; |
|---|
| 3755 | | - ft_prio->flow_table = ft; |
|---|
| 3756 | | - |
|---|
| 3757 | | -free: |
|---|
| 3758 | | - if (err) |
|---|
| 3759 | | - kfree(handler); |
|---|
| 3760 | | - kvfree(spec); |
|---|
| 3761 | | - return err ? ERR_PTR(err) : handler; |
|---|
| 3762 | | -} |
|---|
| 3763 | | - |
|---|
| 3764 | | -static bool raw_fs_is_multicast(struct mlx5_ib_flow_matcher *fs_matcher, |
|---|
| 3765 | | - void *match_v) |
|---|
| 3766 | | -{ |
|---|
| 3767 | | - void *match_c; |
|---|
| 3768 | | - void *match_v_set_lyr_2_4, *match_c_set_lyr_2_4; |
|---|
| 3769 | | - void *dmac, *dmac_mask; |
|---|
| 3770 | | - void *ipv4, *ipv4_mask; |
|---|
| 3771 | | - |
|---|
| 3772 | | - if (!(fs_matcher->match_criteria_enable & |
|---|
| 3773 | | - (1 << MATCH_CRITERIA_ENABLE_OUTER_BIT))) |
|---|
| 3774 | | - return false; |
|---|
| 3775 | | - |
|---|
| 3776 | | - match_c = fs_matcher->matcher_mask.match_params; |
|---|
| 3777 | | - match_v_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_v, |
|---|
| 3778 | | - outer_headers); |
|---|
| 3779 | | - match_c_set_lyr_2_4 = MLX5_ADDR_OF(fte_match_param, match_c, |
|---|
| 3780 | | - outer_headers); |
|---|
| 3781 | | - |
|---|
| 3782 | | - dmac = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
|---|
| 3783 | | - dmac_47_16); |
|---|
| 3784 | | - dmac_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
|---|
| 3785 | | - dmac_47_16); |
|---|
| 3786 | | - |
|---|
| 3787 | | - if (is_multicast_ether_addr(dmac) && |
|---|
| 3788 | | - is_multicast_ether_addr(dmac_mask)) |
|---|
| 3789 | | - return true; |
|---|
| 3790 | | - |
|---|
| 3791 | | - ipv4 = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_v_set_lyr_2_4, |
|---|
| 3792 | | - dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
|---|
| 3793 | | - |
|---|
| 3794 | | - ipv4_mask = MLX5_ADDR_OF(fte_match_set_lyr_2_4, match_c_set_lyr_2_4, |
|---|
| 3795 | | - dst_ipv4_dst_ipv6.ipv4_layout.ipv4); |
|---|
| 3796 | | - |
|---|
| 3797 | | - if (ipv4_is_multicast(*(__be32 *)(ipv4)) && |
|---|
| 3798 | | - ipv4_is_multicast(*(__be32 *)(ipv4_mask))) |
|---|
| 3799 | | - return true; |
|---|
| 3800 | | - |
|---|
| 3801 | | - return false; |
|---|
| 3802 | | -} |
|---|
| 3803 | | - |
|---|
| 3804 | | -struct mlx5_ib_flow_handler * |
|---|
| 3805 | | -mlx5_ib_raw_fs_rule_add(struct mlx5_ib_dev *dev, |
|---|
| 3806 | | - struct mlx5_ib_flow_matcher *fs_matcher, |
|---|
| 3807 | | - void *cmd_in, int inlen, int dest_id, |
|---|
| 3808 | | - int dest_type) |
|---|
| 3809 | | -{ |
|---|
| 3810 | | - struct mlx5_flow_destination *dst; |
|---|
| 3811 | | - struct mlx5_ib_flow_prio *ft_prio; |
|---|
| 3812 | | - int priority = fs_matcher->priority; |
|---|
| 3813 | | - struct mlx5_ib_flow_handler *handler; |
|---|
| 3814 | | - bool mcast; |
|---|
| 3815 | | - int err; |
|---|
| 3816 | | - |
|---|
| 3817 | | - if (fs_matcher->flow_type != MLX5_IB_FLOW_TYPE_NORMAL) |
|---|
| 3818 | | - return ERR_PTR(-EOPNOTSUPP); |
|---|
| 3819 | | - |
|---|
| 3820 | | - if (fs_matcher->priority > MLX5_IB_FLOW_LAST_PRIO) |
|---|
| 3821 | | - return ERR_PTR(-ENOMEM); |
|---|
| 3822 | | - |
|---|
| 3823 | | - dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
|---|
| 3824 | | - if (!dst) |
|---|
| 3825 | | - return ERR_PTR(-ENOMEM); |
|---|
| 3826 | | - |
|---|
| 3827 | | - mcast = raw_fs_is_multicast(fs_matcher, cmd_in); |
|---|
| 3828 | | - mutex_lock(&dev->flow_db->lock); |
|---|
| 3829 | | - |
|---|
| 3830 | | - ft_prio = _get_flow_table(dev, priority, mcast); |
|---|
| 3831 | | - if (IS_ERR(ft_prio)) { |
|---|
| 3832 | | - err = PTR_ERR(ft_prio); |
|---|
| 3833 | | - goto unlock; |
|---|
| 3834 | | - } |
|---|
| 3835 | | - |
|---|
| 3836 | | - if (dest_type == MLX5_FLOW_DESTINATION_TYPE_TIR) { |
|---|
| 3837 | | - dst->type = dest_type; |
|---|
| 3838 | | - dst->tir_num = dest_id; |
|---|
| 3839 | | - } else { |
|---|
| 3840 | | - dst->type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM; |
|---|
| 3841 | | - dst->ft_num = dest_id; |
|---|
| 3842 | | - } |
|---|
| 3843 | | - |
|---|
| 3844 | | - handler = _create_raw_flow_rule(dev, ft_prio, dst, fs_matcher, cmd_in, |
|---|
| 3845 | | - inlen); |
|---|
| 3846 | | - |
|---|
| 3847 | | - if (IS_ERR(handler)) { |
|---|
| 3848 | | - err = PTR_ERR(handler); |
|---|
| 3849 | | - goto destroy_ft; |
|---|
| 3850 | | - } |
|---|
| 3851 | | - |
|---|
| 3852 | | - mutex_unlock(&dev->flow_db->lock); |
|---|
| 3853 | | - atomic_inc(&fs_matcher->usecnt); |
|---|
| 3854 | | - handler->flow_matcher = fs_matcher; |
|---|
| 3855 | | - |
|---|
| 3856 | | - kfree(dst); |
|---|
| 3857 | | - |
|---|
| 3858 | | - return handler; |
|---|
| 3859 | | - |
|---|
| 3860 | | -destroy_ft: |
|---|
| 3861 | | - put_flow_table(dev, ft_prio, false); |
|---|
| 3862 | | -unlock: |
|---|
| 3863 | | - mutex_unlock(&dev->flow_db->lock); |
|---|
| 3864 | | - kfree(dst); |
|---|
| 3865 | | - |
|---|
| 3866 | | - return ERR_PTR(err); |
|---|
| 3867 | | -} |
|---|
| 3868 | | - |
|---|
| 3869 | | -static u32 mlx5_ib_flow_action_flags_to_accel_xfrm_flags(u32 mlx5_flags) |
|---|
| 3870 | | -{ |
|---|
| 3871 | | - u32 flags = 0; |
|---|
| 3872 | | - |
|---|
| 3873 | | - if (mlx5_flags & MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA) |
|---|
| 3874 | | - flags |= MLX5_ACCEL_XFRM_FLAG_REQUIRE_METADATA; |
|---|
| 3875 | | - |
|---|
| 3876 | | - return flags; |
|---|
| 3877 | | -} |
|---|
| 3878 | | - |
|---|
| 3879 | | -#define MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA |
|---|
| 3880 | | -static struct ib_flow_action * |
|---|
| 3881 | | -mlx5_ib_create_flow_action_esp(struct ib_device *device, |
|---|
| 3882 | | - const struct ib_flow_action_attrs_esp *attr, |
|---|
| 3883 | | - struct uverbs_attr_bundle *attrs) |
|---|
| 3884 | | -{ |
|---|
| 3885 | | - struct mlx5_ib_dev *mdev = to_mdev(device); |
|---|
| 3886 | | - struct ib_uverbs_flow_action_esp_keymat_aes_gcm *aes_gcm; |
|---|
| 3887 | | - struct mlx5_accel_esp_xfrm_attrs accel_attrs = {}; |
|---|
| 3888 | | - struct mlx5_ib_flow_action *action; |
|---|
| 3889 | | - u64 action_flags; |
|---|
| 3890 | | - u64 flags; |
|---|
| 3891 | | - int err = 0; |
|---|
| 3892 | | - |
|---|
| 3893 | | - err = uverbs_get_flags64( |
|---|
| 3894 | | - &action_flags, attrs, MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
|---|
| 3895 | | - ((MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED << 1) - 1)); |
|---|
| 3896 | | - if (err) |
|---|
| 3897 | | - return ERR_PTR(err); |
|---|
| 3898 | | - |
|---|
| 3899 | | - flags = mlx5_ib_flow_action_flags_to_accel_xfrm_flags(action_flags); |
|---|
| 3900 | | - |
|---|
| 3901 | | - /* We current only support a subset of the standard features. Only a |
|---|
| 3902 | | - * keymat of type AES_GCM, with icv_len == 16, iv_algo == SEQ and esn |
|---|
| 3903 | | - * (with overlap). Full offload mode isn't supported. |
|---|
| 3904 | | - */ |
|---|
| 3905 | | - if (!attr->keymat || attr->replay || attr->encap || |
|---|
| 3906 | | - attr->spi || attr->seq || attr->tfc_pad || |
|---|
| 3907 | | - attr->hard_limit_pkts || |
|---|
| 3908 | | - (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
|---|
| 3909 | | - IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT))) |
|---|
| 3910 | | - return ERR_PTR(-EOPNOTSUPP); |
|---|
| 3911 | | - |
|---|
| 3912 | | - if (attr->keymat->protocol != |
|---|
| 3913 | | - IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM) |
|---|
| 3914 | | - return ERR_PTR(-EOPNOTSUPP); |
|---|
| 3915 | | - |
|---|
| 3916 | | - aes_gcm = &attr->keymat->keymat.aes_gcm; |
|---|
| 3917 | | - |
|---|
| 3918 | | - if (aes_gcm->icv_len != 16 || |
|---|
| 3919 | | - aes_gcm->iv_algo != IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ) |
|---|
| 3920 | | - return ERR_PTR(-EOPNOTSUPP); |
|---|
| 3921 | | - |
|---|
| 3922 | | - action = kmalloc(sizeof(*action), GFP_KERNEL); |
|---|
| 3923 | | - if (!action) |
|---|
| 3924 | | - return ERR_PTR(-ENOMEM); |
|---|
| 3925 | | - |
|---|
| 3926 | | - action->esp_aes_gcm.ib_flags = attr->flags; |
|---|
| 3927 | | - memcpy(&accel_attrs.keymat.aes_gcm.aes_key, &aes_gcm->aes_key, |
|---|
| 3928 | | - sizeof(accel_attrs.keymat.aes_gcm.aes_key)); |
|---|
| 3929 | | - accel_attrs.keymat.aes_gcm.key_len = aes_gcm->key_len * 8; |
|---|
| 3930 | | - memcpy(&accel_attrs.keymat.aes_gcm.salt, &aes_gcm->salt, |
|---|
| 3931 | | - sizeof(accel_attrs.keymat.aes_gcm.salt)); |
|---|
| 3932 | | - memcpy(&accel_attrs.keymat.aes_gcm.seq_iv, &aes_gcm->iv, |
|---|
| 3933 | | - sizeof(accel_attrs.keymat.aes_gcm.seq_iv)); |
|---|
| 3934 | | - accel_attrs.keymat.aes_gcm.icv_len = aes_gcm->icv_len * 8; |
|---|
| 3935 | | - accel_attrs.keymat.aes_gcm.iv_algo = MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ; |
|---|
| 3936 | | - accel_attrs.keymat_type = MLX5_ACCEL_ESP_KEYMAT_AES_GCM; |
|---|
| 3937 | | - |
|---|
| 3938 | | - accel_attrs.esn = attr->esn; |
|---|
| 3939 | | - if (attr->flags & IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) |
|---|
| 3940 | | - accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED; |
|---|
| 3941 | | - if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
|---|
| 3942 | | - accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
|---|
| 3943 | | - |
|---|
| 3944 | | - if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT) |
|---|
| 3945 | | - accel_attrs.action |= MLX5_ACCEL_ESP_ACTION_ENCRYPT; |
|---|
| 3946 | | - |
|---|
| 3947 | | - action->esp_aes_gcm.ctx = |
|---|
| 3948 | | - mlx5_accel_esp_create_xfrm(mdev->mdev, &accel_attrs, flags); |
|---|
| 3949 | | - if (IS_ERR(action->esp_aes_gcm.ctx)) { |
|---|
| 3950 | | - err = PTR_ERR(action->esp_aes_gcm.ctx); |
|---|
| 3951 | | - goto err_parse; |
|---|
| 3952 | | - } |
|---|
| 3953 | | - |
|---|
| 3954 | | - action->esp_aes_gcm.ib_flags = attr->flags; |
|---|
| 3955 | | - |
|---|
| 3956 | | - return &action->ib_action; |
|---|
| 3957 | | - |
|---|
| 3958 | | -err_parse: |
|---|
| 3959 | | - kfree(action); |
|---|
| 3960 | | - return ERR_PTR(err); |
|---|
| 3961 | | -} |
|---|
| 3962 | | - |
|---|
| 3963 | | -static int |
|---|
| 3964 | | -mlx5_ib_modify_flow_action_esp(struct ib_flow_action *action, |
|---|
| 3965 | | - const struct ib_flow_action_attrs_esp *attr, |
|---|
| 3966 | | - struct uverbs_attr_bundle *attrs) |
|---|
| 3967 | | -{ |
|---|
| 3968 | | - struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
|---|
| 3969 | | - struct mlx5_accel_esp_xfrm_attrs accel_attrs; |
|---|
| 3970 | | - int err = 0; |
|---|
| 3971 | | - |
|---|
| 3972 | | - if (attr->keymat || attr->replay || attr->encap || |
|---|
| 3973 | | - attr->spi || attr->seq || attr->tfc_pad || |
|---|
| 3974 | | - attr->hard_limit_pkts || |
|---|
| 3975 | | - (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
|---|
| 3976 | | - IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS | |
|---|
| 3977 | | - IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW))) |
|---|
| 3978 | | - return -EOPNOTSUPP; |
|---|
| 3979 | | - |
|---|
| 3980 | | - /* Only the ESN value or the MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP can |
|---|
| 3981 | | - * be modified. |
|---|
| 3982 | | - */ |
|---|
| 3983 | | - if (!(maction->esp_aes_gcm.ib_flags & |
|---|
| 3984 | | - IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) && |
|---|
| 3985 | | - attr->flags & (IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
|---|
| 3986 | | - IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW)) |
|---|
| 3987 | | - return -EINVAL; |
|---|
| 3988 | | - |
|---|
| 3989 | | - memcpy(&accel_attrs, &maction->esp_aes_gcm.ctx->attrs, |
|---|
| 3990 | | - sizeof(accel_attrs)); |
|---|
| 3991 | | - |
|---|
| 3992 | | - accel_attrs.esn = attr->esn; |
|---|
| 3993 | | - if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
|---|
| 3994 | | - accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
|---|
| 3995 | | - else |
|---|
| 3996 | | - accel_attrs.flags &= ~MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
|---|
| 3997 | | - |
|---|
| 3998 | | - err = mlx5_accel_esp_modify_xfrm(maction->esp_aes_gcm.ctx, |
|---|
| 3999 | | - &accel_attrs); |
|---|
| 4000 | | - if (err) |
|---|
| 4001 | | - return err; |
|---|
| 4002 | | - |
|---|
| 4003 | | - maction->esp_aes_gcm.ib_flags &= |
|---|
| 4004 | | - ~IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
|---|
| 4005 | | - maction->esp_aes_gcm.ib_flags |= |
|---|
| 4006 | | - attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW; |
|---|
| 4007 | | - |
|---|
| 4008 | | - return 0; |
|---|
| 4009 | | -} |
|---|
| 4010 | | - |
|---|
| 4011 | | -static int mlx5_ib_destroy_flow_action(struct ib_flow_action *action) |
|---|
| 4012 | | -{ |
|---|
| 4013 | | - struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
|---|
| 4014 | | - |
|---|
| 4015 | | - switch (action->type) { |
|---|
| 4016 | | - case IB_FLOW_ACTION_ESP: |
|---|
| 4017 | | - /* |
|---|
| 4018 | | - * We only support aes_gcm by now, so we implicitly know this is |
|---|
| 4019 | | - * the underline crypto. |
|---|
| 4020 | | - */ |
|---|
| 4021 | | - mlx5_accel_esp_destroy_xfrm(maction->esp_aes_gcm.ctx); |
|---|
| 4022 | | - break; |
|---|
| 4023 | | - default: |
|---|
| 4024 | | - WARN_ON(true); |
|---|
| 4025 | | - break; |
|---|
| 4026 | | - } |
|---|
| 4027 | | - |
|---|
| 4028 | | - kfree(maction); |
|---|
| 4029 | | - return 0; |
|---|
| 2586 | + return mlx5_cmd_dealloc_pd(mdev->mdev, mpd->pdn, mpd->uid); |
|---|
| 4030 | 2587 | } |
|---|
| 4031 | 2588 | |
|---|
| 4032 | 2589 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
|---|
| .. | .. |
|---|
| 4034 | 2591 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
|---|
| 4035 | 2592 | struct mlx5_ib_qp *mqp = to_mqp(ibqp); |
|---|
| 4036 | 2593 | int err; |
|---|
| 2594 | + u16 uid; |
|---|
| 4037 | 2595 | |
|---|
| 4038 | | - if (mqp->flags & MLX5_IB_QP_UNDERLAY) { |
|---|
| 2596 | + uid = ibqp->pd ? |
|---|
| 2597 | + to_mpd(ibqp->pd)->uid : 0; |
|---|
| 2598 | + |
|---|
| 2599 | + if (mqp->flags & IB_QP_CREATE_SOURCE_QPN) { |
|---|
| 4039 | 2600 | mlx5_ib_dbg(dev, "Attaching a multi cast group to underlay QP is not supported\n"); |
|---|
| 4040 | 2601 | return -EOPNOTSUPP; |
|---|
| 4041 | 2602 | } |
|---|
| 4042 | 2603 | |
|---|
| 4043 | | - err = mlx5_core_attach_mcg(dev->mdev, gid, ibqp->qp_num); |
|---|
| 2604 | + err = mlx5_cmd_attach_mcg(dev->mdev, gid, ibqp->qp_num, uid); |
|---|
| 4044 | 2605 | if (err) |
|---|
| 4045 | 2606 | mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n", |
|---|
| 4046 | 2607 | ibqp->qp_num, gid->raw); |
|---|
| .. | .. |
|---|
| 4052 | 2613 | { |
|---|
| 4053 | 2614 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
|---|
| 4054 | 2615 | int err; |
|---|
| 2616 | + u16 uid; |
|---|
| 4055 | 2617 | |
|---|
| 4056 | | - err = mlx5_core_detach_mcg(dev->mdev, gid, ibqp->qp_num); |
|---|
| 2618 | + uid = ibqp->pd ? |
|---|
| 2619 | + to_mpd(ibqp->pd)->uid : 0; |
|---|
| 2620 | + err = mlx5_cmd_detach_mcg(dev->mdev, gid, ibqp->qp_num, uid); |
|---|
| 4057 | 2621 | if (err) |
|---|
| 4058 | 2622 | mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n", |
|---|
| 4059 | 2623 | ibqp->qp_num, gid->raw); |
|---|
| .. | .. |
|---|
| 4074 | 2638 | return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid); |
|---|
| 4075 | 2639 | } |
|---|
| 4076 | 2640 | |
|---|
| 4077 | | -static ssize_t show_fw_pages(struct device *device, struct device_attribute *attr, |
|---|
| 4078 | | - char *buf) |
|---|
| 2641 | +static ssize_t fw_pages_show(struct device *device, |
|---|
| 2642 | + struct device_attribute *attr, char *buf) |
|---|
| 4079 | 2643 | { |
|---|
| 4080 | 2644 | struct mlx5_ib_dev *dev = |
|---|
| 4081 | | - container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
|---|
| 2645 | + rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
|---|
| 4082 | 2646 | |
|---|
| 4083 | 2647 | return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); |
|---|
| 4084 | 2648 | } |
|---|
| 2649 | +static DEVICE_ATTR_RO(fw_pages); |
|---|
| 4085 | 2650 | |
|---|
| 4086 | | -static ssize_t show_reg_pages(struct device *device, |
|---|
| 2651 | +static ssize_t reg_pages_show(struct device *device, |
|---|
| 4087 | 2652 | struct device_attribute *attr, char *buf) |
|---|
| 4088 | 2653 | { |
|---|
| 4089 | 2654 | struct mlx5_ib_dev *dev = |
|---|
| 4090 | | - container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
|---|
| 2655 | + rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
|---|
| 4091 | 2656 | |
|---|
| 4092 | 2657 | return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); |
|---|
| 4093 | 2658 | } |
|---|
| 2659 | +static DEVICE_ATTR_RO(reg_pages); |
|---|
| 4094 | 2660 | |
|---|
| 4095 | | -static ssize_t show_hca(struct device *device, struct device_attribute *attr, |
|---|
| 4096 | | - char *buf) |
|---|
| 2661 | +static ssize_t hca_type_show(struct device *device, |
|---|
| 2662 | + struct device_attribute *attr, char *buf) |
|---|
| 4097 | 2663 | { |
|---|
| 4098 | 2664 | struct mlx5_ib_dev *dev = |
|---|
| 4099 | | - container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
|---|
| 2665 | + rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
|---|
| 2666 | + |
|---|
| 4100 | 2667 | return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); |
|---|
| 4101 | 2668 | } |
|---|
| 2669 | +static DEVICE_ATTR_RO(hca_type); |
|---|
| 4102 | 2670 | |
|---|
| 4103 | | -static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
|---|
| 4104 | | - char *buf) |
|---|
| 2671 | +static ssize_t hw_rev_show(struct device *device, |
|---|
| 2672 | + struct device_attribute *attr, char *buf) |
|---|
| 4105 | 2673 | { |
|---|
| 4106 | 2674 | struct mlx5_ib_dev *dev = |
|---|
| 4107 | | - container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
|---|
| 2675 | + rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
|---|
| 2676 | + |
|---|
| 4108 | 2677 | return sprintf(buf, "%x\n", dev->mdev->rev_id); |
|---|
| 4109 | 2678 | } |
|---|
| 2679 | +static DEVICE_ATTR_RO(hw_rev); |
|---|
| 4110 | 2680 | |
|---|
| 4111 | | -static ssize_t show_board(struct device *device, struct device_attribute *attr, |
|---|
| 4112 | | - char *buf) |
|---|
| 2681 | +static ssize_t board_id_show(struct device *device, |
|---|
| 2682 | + struct device_attribute *attr, char *buf) |
|---|
| 4113 | 2683 | { |
|---|
| 4114 | 2684 | struct mlx5_ib_dev *dev = |
|---|
| 4115 | | - container_of(device, struct mlx5_ib_dev, ib_dev.dev); |
|---|
| 2685 | + rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev); |
|---|
| 2686 | + |
|---|
| 4116 | 2687 | return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, |
|---|
| 4117 | 2688 | dev->mdev->board_id); |
|---|
| 4118 | 2689 | } |
|---|
| 2690 | +static DEVICE_ATTR_RO(board_id); |
|---|
| 4119 | 2691 | |
|---|
| 4120 | | -static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
|---|
| 4121 | | -static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
|---|
| 4122 | | -static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
|---|
| 4123 | | -static DEVICE_ATTR(fw_pages, S_IRUGO, show_fw_pages, NULL); |
|---|
| 4124 | | -static DEVICE_ATTR(reg_pages, S_IRUGO, show_reg_pages, NULL); |
|---|
| 2692 | +static struct attribute *mlx5_class_attributes[] = { |
|---|
| 2693 | + &dev_attr_hw_rev.attr, |
|---|
| 2694 | + &dev_attr_hca_type.attr, |
|---|
| 2695 | + &dev_attr_board_id.attr, |
|---|
| 2696 | + &dev_attr_fw_pages.attr, |
|---|
| 2697 | + &dev_attr_reg_pages.attr, |
|---|
| 2698 | + NULL, |
|---|
| 2699 | +}; |
|---|
| 4125 | 2700 | |
|---|
| 4126 | | -static struct device_attribute *mlx5_class_attributes[] = { |
|---|
| 4127 | | - &dev_attr_hw_rev, |
|---|
| 4128 | | - &dev_attr_hca_type, |
|---|
| 4129 | | - &dev_attr_board_id, |
|---|
| 4130 | | - &dev_attr_fw_pages, |
|---|
| 4131 | | - &dev_attr_reg_pages, |
|---|
| 2701 | +static const struct attribute_group mlx5_attr_group = { |
|---|
| 2702 | + .attrs = mlx5_class_attributes, |
|---|
| 4132 | 2703 | }; |
|---|
| 4133 | 2704 | |
|---|
| 4134 | 2705 | static void pkey_change_handler(struct work_struct *work) |
|---|
| .. | .. |
|---|
| 4137 | 2708 | container_of(work, struct mlx5_ib_port_resources, |
|---|
| 4138 | 2709 | pkey_change_work); |
|---|
| 4139 | 2710 | |
|---|
| 4140 | | - mutex_lock(&ports->devr->mutex); |
|---|
| 4141 | 2711 | mlx5_ib_gsi_pkey_change(ports->gsi); |
|---|
| 4142 | | - mutex_unlock(&ports->devr->mutex); |
|---|
| 4143 | 2712 | } |
|---|
| 4144 | 2713 | |
|---|
| 4145 | 2714 | static void mlx5_ib_handle_internal_error(struct mlx5_ib_dev *ibdev) |
|---|
| .. | .. |
|---|
| 4196 | 2765 | * lock/unlock above locks Now need to arm all involved CQs. |
|---|
| 4197 | 2766 | */ |
|---|
| 4198 | 2767 | list_for_each_entry(mcq, &cq_armed_list, reset_notify) { |
|---|
| 4199 | | - mcq->comp(mcq); |
|---|
| 2768 | + mcq->comp(mcq, NULL); |
|---|
| 4200 | 2769 | } |
|---|
| 4201 | 2770 | spin_unlock_irqrestore(&ibdev->reset_flow_resource_lock, flags); |
|---|
| 4202 | 2771 | } |
|---|
| .. | .. |
|---|
| 4211 | 2780 | atomic_inc(&delay_drop->events_cnt); |
|---|
| 4212 | 2781 | |
|---|
| 4213 | 2782 | mutex_lock(&delay_drop->lock); |
|---|
| 4214 | | - err = mlx5_core_set_delay_drop(delay_drop->dev->mdev, |
|---|
| 4215 | | - delay_drop->timeout); |
|---|
| 2783 | + err = mlx5_core_set_delay_drop(delay_drop->dev, delay_drop->timeout); |
|---|
| 4216 | 2784 | if (err) { |
|---|
| 4217 | 2785 | mlx5_ib_warn(delay_drop->dev, "Failed to set delay drop, timeout=%u\n", |
|---|
| 4218 | 2786 | delay_drop->timeout); |
|---|
| 4219 | 2787 | delay_drop->activate = false; |
|---|
| 4220 | 2788 | } |
|---|
| 4221 | 2789 | mutex_unlock(&delay_drop->lock); |
|---|
| 2790 | +} |
|---|
| 2791 | + |
|---|
| 2792 | +static void handle_general_event(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, |
|---|
| 2793 | + struct ib_event *ibev) |
|---|
| 2794 | +{ |
|---|
| 2795 | + u8 port = (eqe->data.port.port >> 4) & 0xf; |
|---|
| 2796 | + |
|---|
| 2797 | + switch (eqe->sub_type) { |
|---|
| 2798 | + case MLX5_GENERAL_SUBTYPE_DELAY_DROP_TIMEOUT: |
|---|
| 2799 | + if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
|---|
| 2800 | + IB_LINK_LAYER_ETHERNET) |
|---|
| 2801 | + schedule_work(&ibdev->delay_drop.delay_drop_work); |
|---|
| 2802 | + break; |
|---|
| 2803 | + default: /* do nothing */ |
|---|
| 2804 | + return; |
|---|
| 2805 | + } |
|---|
| 2806 | +} |
|---|
| 2807 | + |
|---|
| 2808 | +static int handle_port_change(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, |
|---|
| 2809 | + struct ib_event *ibev) |
|---|
| 2810 | +{ |
|---|
| 2811 | + u8 port = (eqe->data.port.port >> 4) & 0xf; |
|---|
| 2812 | + |
|---|
| 2813 | + ibev->element.port_num = port; |
|---|
| 2814 | + |
|---|
| 2815 | + switch (eqe->sub_type) { |
|---|
| 2816 | + case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE: |
|---|
| 2817 | + case MLX5_PORT_CHANGE_SUBTYPE_DOWN: |
|---|
| 2818 | + case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED: |
|---|
| 2819 | + /* In RoCE, port up/down events are handled in |
|---|
| 2820 | + * mlx5_netdev_event(). |
|---|
| 2821 | + */ |
|---|
| 2822 | + if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
|---|
| 2823 | + IB_LINK_LAYER_ETHERNET) |
|---|
| 2824 | + return -EINVAL; |
|---|
| 2825 | + |
|---|
| 2826 | + ibev->event = (eqe->sub_type == MLX5_PORT_CHANGE_SUBTYPE_ACTIVE) ? |
|---|
| 2827 | + IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
|---|
| 2828 | + break; |
|---|
| 2829 | + |
|---|
| 2830 | + case MLX5_PORT_CHANGE_SUBTYPE_LID: |
|---|
| 2831 | + ibev->event = IB_EVENT_LID_CHANGE; |
|---|
| 2832 | + break; |
|---|
| 2833 | + |
|---|
| 2834 | + case MLX5_PORT_CHANGE_SUBTYPE_PKEY: |
|---|
| 2835 | + ibev->event = IB_EVENT_PKEY_CHANGE; |
|---|
| 2836 | + schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work); |
|---|
| 2837 | + break; |
|---|
| 2838 | + |
|---|
| 2839 | + case MLX5_PORT_CHANGE_SUBTYPE_GUID: |
|---|
| 2840 | + ibev->event = IB_EVENT_GID_CHANGE; |
|---|
| 2841 | + break; |
|---|
| 2842 | + |
|---|
| 2843 | + case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG: |
|---|
| 2844 | + ibev->event = IB_EVENT_CLIENT_REREGISTER; |
|---|
| 2845 | + break; |
|---|
| 2846 | + default: |
|---|
| 2847 | + return -EINVAL; |
|---|
| 2848 | + } |
|---|
| 2849 | + |
|---|
| 2850 | + return 0; |
|---|
| 4222 | 2851 | } |
|---|
| 4223 | 2852 | |
|---|
| 4224 | 2853 | static void mlx5_ib_handle_event(struct work_struct *_work) |
|---|
| .. | .. |
|---|
| 4228 | 2857 | struct mlx5_ib_dev *ibdev; |
|---|
| 4229 | 2858 | struct ib_event ibev; |
|---|
| 4230 | 2859 | bool fatal = false; |
|---|
| 4231 | | - u8 port = (u8)work->param; |
|---|
| 4232 | 2860 | |
|---|
| 4233 | | - if (mlx5_core_is_mp_slave(work->dev)) { |
|---|
| 4234 | | - ibdev = mlx5_ib_get_ibdev_from_mpi(work->context); |
|---|
| 2861 | + if (work->is_slave) { |
|---|
| 2862 | + ibdev = mlx5_ib_get_ibdev_from_mpi(work->mpi); |
|---|
| 4235 | 2863 | if (!ibdev) |
|---|
| 4236 | 2864 | goto out; |
|---|
| 4237 | 2865 | } else { |
|---|
| 4238 | | - ibdev = work->context; |
|---|
| 2866 | + ibdev = work->dev; |
|---|
| 4239 | 2867 | } |
|---|
| 4240 | 2868 | |
|---|
| 4241 | 2869 | switch (work->event) { |
|---|
| 4242 | 2870 | case MLX5_DEV_EVENT_SYS_ERROR: |
|---|
| 4243 | 2871 | ibev.event = IB_EVENT_DEVICE_FATAL; |
|---|
| 4244 | 2872 | mlx5_ib_handle_internal_error(ibdev); |
|---|
| 2873 | + ibev.element.port_num = (u8)(unsigned long)work->param; |
|---|
| 4245 | 2874 | fatal = true; |
|---|
| 4246 | 2875 | break; |
|---|
| 4247 | | - |
|---|
| 4248 | | - case MLX5_DEV_EVENT_PORT_UP: |
|---|
| 4249 | | - case MLX5_DEV_EVENT_PORT_DOWN: |
|---|
| 4250 | | - case MLX5_DEV_EVENT_PORT_INITIALIZED: |
|---|
| 4251 | | - /* In RoCE, port up/down events are handled in |
|---|
| 4252 | | - * mlx5_netdev_event(). |
|---|
| 4253 | | - */ |
|---|
| 4254 | | - if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) == |
|---|
| 4255 | | - IB_LINK_LAYER_ETHERNET) |
|---|
| 2876 | + case MLX5_EVENT_TYPE_PORT_CHANGE: |
|---|
| 2877 | + if (handle_port_change(ibdev, work->param, &ibev)) |
|---|
| 4256 | 2878 | goto out; |
|---|
| 4257 | | - |
|---|
| 4258 | | - ibev.event = (work->event == MLX5_DEV_EVENT_PORT_UP) ? |
|---|
| 4259 | | - IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; |
|---|
| 4260 | 2879 | break; |
|---|
| 4261 | | - |
|---|
| 4262 | | - case MLX5_DEV_EVENT_LID_CHANGE: |
|---|
| 4263 | | - ibev.event = IB_EVENT_LID_CHANGE; |
|---|
| 4264 | | - break; |
|---|
| 4265 | | - |
|---|
| 4266 | | - case MLX5_DEV_EVENT_PKEY_CHANGE: |
|---|
| 4267 | | - ibev.event = IB_EVENT_PKEY_CHANGE; |
|---|
| 4268 | | - schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work); |
|---|
| 4269 | | - break; |
|---|
| 4270 | | - |
|---|
| 4271 | | - case MLX5_DEV_EVENT_GUID_CHANGE: |
|---|
| 4272 | | - ibev.event = IB_EVENT_GID_CHANGE; |
|---|
| 4273 | | - break; |
|---|
| 4274 | | - |
|---|
| 4275 | | - case MLX5_DEV_EVENT_CLIENT_REREG: |
|---|
| 4276 | | - ibev.event = IB_EVENT_CLIENT_REREGISTER; |
|---|
| 4277 | | - break; |
|---|
| 4278 | | - case MLX5_DEV_EVENT_DELAY_DROP_TIMEOUT: |
|---|
| 4279 | | - schedule_work(&ibdev->delay_drop.delay_drop_work); |
|---|
| 4280 | | - goto out; |
|---|
| 2880 | + case MLX5_EVENT_TYPE_GENERAL_EVENT: |
|---|
| 2881 | + handle_general_event(ibdev, work->param, &ibev); |
|---|
| 2882 | + fallthrough; |
|---|
| 4281 | 2883 | default: |
|---|
| 4282 | 2884 | goto out; |
|---|
| 4283 | 2885 | } |
|---|
| 4284 | 2886 | |
|---|
| 4285 | | - ibev.device = &ibdev->ib_dev; |
|---|
| 4286 | | - ibev.element.port_num = port; |
|---|
| 2887 | + ibev.device = &ibdev->ib_dev; |
|---|
| 4287 | 2888 | |
|---|
| 4288 | | - if (!rdma_is_port_valid(&ibdev->ib_dev, port)) { |
|---|
| 4289 | | - mlx5_ib_warn(ibdev, "warning: event on port %d\n", port); |
|---|
| 2889 | + if (!rdma_is_port_valid(&ibdev->ib_dev, ibev.element.port_num)) { |
|---|
| 2890 | + mlx5_ib_warn(ibdev, "warning: event on port %d\n", ibev.element.port_num); |
|---|
| 4290 | 2891 | goto out; |
|---|
| 4291 | 2892 | } |
|---|
| 4292 | 2893 | |
|---|
| .. | .. |
|---|
| 4299 | 2900 | kfree(work); |
|---|
| 4300 | 2901 | } |
|---|
| 4301 | 2902 | |
|---|
| 4302 | | -static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context, |
|---|
| 4303 | | - enum mlx5_dev_event event, unsigned long param) |
|---|
| 2903 | +static int mlx5_ib_event(struct notifier_block *nb, |
|---|
| 2904 | + unsigned long event, void *param) |
|---|
| 4304 | 2905 | { |
|---|
| 4305 | 2906 | struct mlx5_ib_event_work *work; |
|---|
| 4306 | 2907 | |
|---|
| 4307 | 2908 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
|---|
| 4308 | 2909 | if (!work) |
|---|
| 4309 | | - return; |
|---|
| 2910 | + return NOTIFY_DONE; |
|---|
| 4310 | 2911 | |
|---|
| 4311 | 2912 | INIT_WORK(&work->work, mlx5_ib_handle_event); |
|---|
| 4312 | | - work->dev = dev; |
|---|
| 2913 | + work->dev = container_of(nb, struct mlx5_ib_dev, mdev_events); |
|---|
| 2914 | + work->is_slave = false; |
|---|
| 4313 | 2915 | work->param = param; |
|---|
| 4314 | | - work->context = context; |
|---|
| 4315 | 2916 | work->event = event; |
|---|
| 4316 | 2917 | |
|---|
| 4317 | 2918 | queue_work(mlx5_ib_event_wq, &work->work); |
|---|
| 2919 | + |
|---|
| 2920 | + return NOTIFY_OK; |
|---|
| 2921 | +} |
|---|
| 2922 | + |
|---|
| 2923 | +static int mlx5_ib_event_slave_port(struct notifier_block *nb, |
|---|
| 2924 | + unsigned long event, void *param) |
|---|
| 2925 | +{ |
|---|
| 2926 | + struct mlx5_ib_event_work *work; |
|---|
| 2927 | + |
|---|
| 2928 | + work = kmalloc(sizeof(*work), GFP_ATOMIC); |
|---|
| 2929 | + if (!work) |
|---|
| 2930 | + return NOTIFY_DONE; |
|---|
| 2931 | + |
|---|
| 2932 | + INIT_WORK(&work->work, mlx5_ib_handle_event); |
|---|
| 2933 | + work->mpi = container_of(nb, struct mlx5_ib_multiport_info, mdev_events); |
|---|
| 2934 | + work->is_slave = true; |
|---|
| 2935 | + work->param = param; |
|---|
| 2936 | + work->event = event; |
|---|
| 2937 | + queue_work(mlx5_ib_event_wq, &work->work); |
|---|
| 2938 | + |
|---|
| 2939 | + return NOTIFY_OK; |
|---|
| 4318 | 2940 | } |
|---|
| 4319 | 2941 | |
|---|
| 4320 | 2942 | static int set_has_smi_cap(struct mlx5_ib_dev *dev) |
|---|
| .. | .. |
|---|
| 4323 | 2945 | int err; |
|---|
| 4324 | 2946 | int port; |
|---|
| 4325 | 2947 | |
|---|
| 4326 | | - for (port = 1; port <= dev->num_ports; port++) { |
|---|
| 2948 | + for (port = 1; port <= ARRAY_SIZE(dev->mdev->port_caps); port++) { |
|---|
| 4327 | 2949 | dev->mdev->port_caps[port - 1].has_smi = false; |
|---|
| 4328 | 2950 | if (MLX5_CAP_GEN(dev->mdev, port_type) == |
|---|
| 4329 | 2951 | MLX5_CAP_PORT_TYPE_IB) { |
|---|
| .. | .. |
|---|
| 4354 | 2976 | mlx5_query_ext_port_caps(dev, port); |
|---|
| 4355 | 2977 | } |
|---|
| 4356 | 2978 | |
|---|
| 4357 | | -static int get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
|---|
| 2979 | +static int __get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
|---|
| 4358 | 2980 | { |
|---|
| 4359 | 2981 | struct ib_device_attr *dprops = NULL; |
|---|
| 4360 | 2982 | struct ib_port_attr *pprops = NULL; |
|---|
| 4361 | 2983 | int err = -ENOMEM; |
|---|
| 4362 | | - struct ib_udata uhw = {.inlen = 0, .outlen = 0}; |
|---|
| 4363 | 2984 | |
|---|
| 4364 | | - pprops = kmalloc(sizeof(*pprops), GFP_KERNEL); |
|---|
| 2985 | + pprops = kzalloc(sizeof(*pprops), GFP_KERNEL); |
|---|
| 4365 | 2986 | if (!pprops) |
|---|
| 4366 | 2987 | goto out; |
|---|
| 4367 | 2988 | |
|---|
| .. | .. |
|---|
| 4369 | 2990 | if (!dprops) |
|---|
| 4370 | 2991 | goto out; |
|---|
| 4371 | 2992 | |
|---|
| 4372 | | - err = set_has_smi_cap(dev); |
|---|
| 4373 | | - if (err) |
|---|
| 4374 | | - goto out; |
|---|
| 4375 | | - |
|---|
| 4376 | | - err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw); |
|---|
| 2993 | + err = mlx5_ib_query_device(&dev->ib_dev, dprops, NULL); |
|---|
| 4377 | 2994 | if (err) { |
|---|
| 4378 | 2995 | mlx5_ib_warn(dev, "query_device failed %d\n", err); |
|---|
| 4379 | 2996 | goto out; |
|---|
| 4380 | 2997 | } |
|---|
| 4381 | 2998 | |
|---|
| 4382 | | - memset(pprops, 0, sizeof(*pprops)); |
|---|
| 4383 | 2999 | err = mlx5_ib_query_port(&dev->ib_dev, port, pprops); |
|---|
| 4384 | 3000 | if (err) { |
|---|
| 4385 | 3001 | mlx5_ib_warn(dev, "query_port %d failed %d\n", |
|---|
| .. | .. |
|---|
| 4401 | 3017 | return err; |
|---|
| 4402 | 3018 | } |
|---|
| 4403 | 3019 | |
|---|
| 4404 | | -static void destroy_umrc_res(struct mlx5_ib_dev *dev) |
|---|
| 3020 | +static int get_port_caps(struct mlx5_ib_dev *dev, u8 port) |
|---|
| 3021 | +{ |
|---|
| 3022 | + /* For representors use port 1, is this is the only native |
|---|
| 3023 | + * port |
|---|
| 3024 | + */ |
|---|
| 3025 | + if (dev->is_rep) |
|---|
| 3026 | + return __get_port_caps(dev, 1); |
|---|
| 3027 | + return __get_port_caps(dev, port); |
|---|
| 3028 | +} |
|---|
| 3029 | + |
|---|
| 3030 | +static u8 mlx5_get_umr_fence(u8 umr_fence_cap) |
|---|
| 3031 | +{ |
|---|
| 3032 | + switch (umr_fence_cap) { |
|---|
| 3033 | + case MLX5_CAP_UMR_FENCE_NONE: |
|---|
| 3034 | + return MLX5_FENCE_MODE_NONE; |
|---|
| 3035 | + case MLX5_CAP_UMR_FENCE_SMALL: |
|---|
| 3036 | + return MLX5_FENCE_MODE_INITIATOR_SMALL; |
|---|
| 3037 | + default: |
|---|
| 3038 | + return MLX5_FENCE_MODE_STRONG_ORDERING; |
|---|
| 3039 | + } |
|---|
| 3040 | +} |
|---|
| 3041 | + |
|---|
| 3042 | +static int mlx5_ib_dev_res_init(struct mlx5_ib_dev *dev) |
|---|
| 3043 | +{ |
|---|
| 3044 | + struct mlx5_ib_resources *devr = &dev->devr; |
|---|
| 3045 | + struct ib_srq_init_attr attr; |
|---|
| 3046 | + struct ib_device *ibdev; |
|---|
| 3047 | + struct ib_cq_init_attr cq_attr = {.cqe = 1}; |
|---|
| 3048 | + int port; |
|---|
| 3049 | + int ret = 0; |
|---|
| 3050 | + |
|---|
| 3051 | + ibdev = &dev->ib_dev; |
|---|
| 3052 | + |
|---|
| 3053 | + if (!MLX5_CAP_GEN(dev->mdev, xrc)) |
|---|
| 3054 | + return -EOPNOTSUPP; |
|---|
| 3055 | + |
|---|
| 3056 | + mutex_init(&devr->mutex); |
|---|
| 3057 | + |
|---|
| 3058 | + devr->p0 = rdma_zalloc_drv_obj(ibdev, ib_pd); |
|---|
| 3059 | + if (!devr->p0) |
|---|
| 3060 | + return -ENOMEM; |
|---|
| 3061 | + |
|---|
| 3062 | + devr->p0->device = ibdev; |
|---|
| 3063 | + devr->p0->uobject = NULL; |
|---|
| 3064 | + atomic_set(&devr->p0->usecnt, 0); |
|---|
| 3065 | + |
|---|
| 3066 | + ret = mlx5_ib_alloc_pd(devr->p0, NULL); |
|---|
| 3067 | + if (ret) |
|---|
| 3068 | + goto error0; |
|---|
| 3069 | + |
|---|
| 3070 | + devr->c0 = rdma_zalloc_drv_obj(ibdev, ib_cq); |
|---|
| 3071 | + if (!devr->c0) { |
|---|
| 3072 | + ret = -ENOMEM; |
|---|
| 3073 | + goto error1; |
|---|
| 3074 | + } |
|---|
| 3075 | + |
|---|
| 3076 | + devr->c0->device = &dev->ib_dev; |
|---|
| 3077 | + atomic_set(&devr->c0->usecnt, 0); |
|---|
| 3078 | + |
|---|
| 3079 | + ret = mlx5_ib_create_cq(devr->c0, &cq_attr, NULL); |
|---|
| 3080 | + if (ret) |
|---|
| 3081 | + goto err_create_cq; |
|---|
| 3082 | + |
|---|
| 3083 | + ret = mlx5_cmd_xrcd_alloc(dev->mdev, &devr->xrcdn0, 0); |
|---|
| 3084 | + if (ret) |
|---|
| 3085 | + goto error2; |
|---|
| 3086 | + |
|---|
| 3087 | + ret = mlx5_cmd_xrcd_alloc(dev->mdev, &devr->xrcdn1, 0); |
|---|
| 3088 | + if (ret) |
|---|
| 3089 | + goto error3; |
|---|
| 3090 | + |
|---|
| 3091 | + memset(&attr, 0, sizeof(attr)); |
|---|
| 3092 | + attr.attr.max_sge = 1; |
|---|
| 3093 | + attr.attr.max_wr = 1; |
|---|
| 3094 | + attr.srq_type = IB_SRQT_XRC; |
|---|
| 3095 | + attr.ext.cq = devr->c0; |
|---|
| 3096 | + |
|---|
| 3097 | + devr->s0 = rdma_zalloc_drv_obj(ibdev, ib_srq); |
|---|
| 3098 | + if (!devr->s0) { |
|---|
| 3099 | + ret = -ENOMEM; |
|---|
| 3100 | + goto error4; |
|---|
| 3101 | + } |
|---|
| 3102 | + |
|---|
| 3103 | + devr->s0->device = &dev->ib_dev; |
|---|
| 3104 | + devr->s0->pd = devr->p0; |
|---|
| 3105 | + devr->s0->srq_type = IB_SRQT_XRC; |
|---|
| 3106 | + devr->s0->ext.cq = devr->c0; |
|---|
| 3107 | + ret = mlx5_ib_create_srq(devr->s0, &attr, NULL); |
|---|
| 3108 | + if (ret) |
|---|
| 3109 | + goto err_create; |
|---|
| 3110 | + |
|---|
| 3111 | + atomic_inc(&devr->s0->ext.cq->usecnt); |
|---|
| 3112 | + atomic_inc(&devr->p0->usecnt); |
|---|
| 3113 | + atomic_set(&devr->s0->usecnt, 0); |
|---|
| 3114 | + |
|---|
| 3115 | + memset(&attr, 0, sizeof(attr)); |
|---|
| 3116 | + attr.attr.max_sge = 1; |
|---|
| 3117 | + attr.attr.max_wr = 1; |
|---|
| 3118 | + attr.srq_type = IB_SRQT_BASIC; |
|---|
| 3119 | + devr->s1 = rdma_zalloc_drv_obj(ibdev, ib_srq); |
|---|
| 3120 | + if (!devr->s1) { |
|---|
| 3121 | + ret = -ENOMEM; |
|---|
| 3122 | + goto error5; |
|---|
| 3123 | + } |
|---|
| 3124 | + |
|---|
| 3125 | + devr->s1->device = &dev->ib_dev; |
|---|
| 3126 | + devr->s1->pd = devr->p0; |
|---|
| 3127 | + devr->s1->srq_type = IB_SRQT_BASIC; |
|---|
| 3128 | + devr->s1->ext.cq = devr->c0; |
|---|
| 3129 | + |
|---|
| 3130 | + ret = mlx5_ib_create_srq(devr->s1, &attr, NULL); |
|---|
| 3131 | + if (ret) |
|---|
| 3132 | + goto error6; |
|---|
| 3133 | + |
|---|
| 3134 | + atomic_inc(&devr->p0->usecnt); |
|---|
| 3135 | + atomic_set(&devr->s1->usecnt, 0); |
|---|
| 3136 | + |
|---|
| 3137 | + for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) |
|---|
| 3138 | + INIT_WORK(&devr->ports[port].pkey_change_work, |
|---|
| 3139 | + pkey_change_handler); |
|---|
| 3140 | + |
|---|
| 3141 | + return 0; |
|---|
| 3142 | + |
|---|
| 3143 | +error6: |
|---|
| 3144 | + kfree(devr->s1); |
|---|
| 3145 | +error5: |
|---|
| 3146 | + mlx5_ib_destroy_srq(devr->s0, NULL); |
|---|
| 3147 | +err_create: |
|---|
| 3148 | + kfree(devr->s0); |
|---|
| 3149 | +error4: |
|---|
| 3150 | + mlx5_cmd_xrcd_dealloc(dev->mdev, devr->xrcdn1, 0); |
|---|
| 3151 | +error3: |
|---|
| 3152 | + mlx5_cmd_xrcd_dealloc(dev->mdev, devr->xrcdn0, 0); |
|---|
| 3153 | +error2: |
|---|
| 3154 | + mlx5_ib_destroy_cq(devr->c0, NULL); |
|---|
| 3155 | +err_create_cq: |
|---|
| 3156 | + kfree(devr->c0); |
|---|
| 3157 | +error1: |
|---|
| 3158 | + mlx5_ib_dealloc_pd(devr->p0, NULL); |
|---|
| 3159 | +error0: |
|---|
| 3160 | + kfree(devr->p0); |
|---|
| 3161 | + return ret; |
|---|
| 3162 | +} |
|---|
| 3163 | + |
|---|
| 3164 | +static void mlx5_ib_dev_res_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 3165 | +{ |
|---|
| 3166 | + struct mlx5_ib_resources *devr = &dev->devr; |
|---|
| 3167 | + int port; |
|---|
| 3168 | + |
|---|
| 3169 | + mlx5_ib_destroy_srq(devr->s1, NULL); |
|---|
| 3170 | + kfree(devr->s1); |
|---|
| 3171 | + mlx5_ib_destroy_srq(devr->s0, NULL); |
|---|
| 3172 | + kfree(devr->s0); |
|---|
| 3173 | + mlx5_cmd_xrcd_dealloc(dev->mdev, devr->xrcdn1, 0); |
|---|
| 3174 | + mlx5_cmd_xrcd_dealloc(dev->mdev, devr->xrcdn0, 0); |
|---|
| 3175 | + mlx5_ib_destroy_cq(devr->c0, NULL); |
|---|
| 3176 | + kfree(devr->c0); |
|---|
| 3177 | + mlx5_ib_dealloc_pd(devr->p0, NULL); |
|---|
| 3178 | + kfree(devr->p0); |
|---|
| 3179 | + |
|---|
| 3180 | + /* Make sure no change P_Key work items are still executing */ |
|---|
| 3181 | + for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) |
|---|
| 3182 | + cancel_work_sync(&devr->ports[port].pkey_change_work); |
|---|
| 3183 | +} |
|---|
| 3184 | + |
|---|
| 3185 | +static u32 get_core_cap_flags(struct ib_device *ibdev, |
|---|
| 3186 | + struct mlx5_hca_vport_context *rep) |
|---|
| 3187 | +{ |
|---|
| 3188 | + struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 3189 | + enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, 1); |
|---|
| 3190 | + u8 l3_type_cap = MLX5_CAP_ROCE(dev->mdev, l3_type); |
|---|
| 3191 | + u8 roce_version_cap = MLX5_CAP_ROCE(dev->mdev, roce_version); |
|---|
| 3192 | + bool raw_support = !mlx5_core_mp_enabled(dev->mdev); |
|---|
| 3193 | + u32 ret = 0; |
|---|
| 3194 | + |
|---|
| 3195 | + if (rep->grh_required) |
|---|
| 3196 | + ret |= RDMA_CORE_CAP_IB_GRH_REQUIRED; |
|---|
| 3197 | + |
|---|
| 3198 | + if (ll == IB_LINK_LAYER_INFINIBAND) |
|---|
| 3199 | + return ret | RDMA_CORE_PORT_IBA_IB; |
|---|
| 3200 | + |
|---|
| 3201 | + if (raw_support) |
|---|
| 3202 | + ret |= RDMA_CORE_PORT_RAW_PACKET; |
|---|
| 3203 | + |
|---|
| 3204 | + if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV4_CAP)) |
|---|
| 3205 | + return ret; |
|---|
| 3206 | + |
|---|
| 3207 | + if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV6_CAP)) |
|---|
| 3208 | + return ret; |
|---|
| 3209 | + |
|---|
| 3210 | + if (roce_version_cap & MLX5_ROCE_VERSION_1_CAP) |
|---|
| 3211 | + ret |= RDMA_CORE_PORT_IBA_ROCE; |
|---|
| 3212 | + |
|---|
| 3213 | + if (roce_version_cap & MLX5_ROCE_VERSION_2_CAP) |
|---|
| 3214 | + ret |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; |
|---|
| 3215 | + |
|---|
| 3216 | + return ret; |
|---|
| 3217 | +} |
|---|
| 3218 | + |
|---|
| 3219 | +static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
|---|
| 3220 | + struct ib_port_immutable *immutable) |
|---|
| 3221 | +{ |
|---|
| 3222 | + struct ib_port_attr attr; |
|---|
| 3223 | + struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 3224 | + enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, port_num); |
|---|
| 3225 | + struct mlx5_hca_vport_context rep = {0}; |
|---|
| 3226 | + int err; |
|---|
| 3227 | + |
|---|
| 3228 | + err = ib_query_port(ibdev, port_num, &attr); |
|---|
| 3229 | + if (err) |
|---|
| 3230 | + return err; |
|---|
| 3231 | + |
|---|
| 3232 | + if (ll == IB_LINK_LAYER_INFINIBAND) { |
|---|
| 3233 | + err = mlx5_query_hca_vport_context(dev->mdev, 0, port_num, 0, |
|---|
| 3234 | + &rep); |
|---|
| 3235 | + if (err) |
|---|
| 3236 | + return err; |
|---|
| 3237 | + } |
|---|
| 3238 | + |
|---|
| 3239 | + immutable->pkey_tbl_len = attr.pkey_tbl_len; |
|---|
| 3240 | + immutable->gid_tbl_len = attr.gid_tbl_len; |
|---|
| 3241 | + immutable->core_cap_flags = get_core_cap_flags(ibdev, &rep); |
|---|
| 3242 | + immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
|---|
| 3243 | + |
|---|
| 3244 | + return 0; |
|---|
| 3245 | +} |
|---|
| 3246 | + |
|---|
| 3247 | +static int mlx5_port_rep_immutable(struct ib_device *ibdev, u8 port_num, |
|---|
| 3248 | + struct ib_port_immutable *immutable) |
|---|
| 3249 | +{ |
|---|
| 3250 | + struct ib_port_attr attr; |
|---|
| 3251 | + int err; |
|---|
| 3252 | + |
|---|
| 3253 | + immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
|---|
| 3254 | + |
|---|
| 3255 | + err = ib_query_port(ibdev, port_num, &attr); |
|---|
| 3256 | + if (err) |
|---|
| 3257 | + return err; |
|---|
| 3258 | + |
|---|
| 3259 | + immutable->pkey_tbl_len = attr.pkey_tbl_len; |
|---|
| 3260 | + immutable->gid_tbl_len = attr.gid_tbl_len; |
|---|
| 3261 | + immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
|---|
| 3262 | + |
|---|
| 3263 | + return 0; |
|---|
| 3264 | +} |
|---|
| 3265 | + |
|---|
| 3266 | +static void get_dev_fw_str(struct ib_device *ibdev, char *str) |
|---|
| 3267 | +{ |
|---|
| 3268 | + struct mlx5_ib_dev *dev = |
|---|
| 3269 | + container_of(ibdev, struct mlx5_ib_dev, ib_dev); |
|---|
| 3270 | + snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%04d", |
|---|
| 3271 | + fw_rev_maj(dev->mdev), fw_rev_min(dev->mdev), |
|---|
| 3272 | + fw_rev_sub(dev->mdev)); |
|---|
| 3273 | +} |
|---|
| 3274 | + |
|---|
| 3275 | +static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev) |
|---|
| 3276 | +{ |
|---|
| 3277 | + struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 3278 | + struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(mdev, |
|---|
| 3279 | + MLX5_FLOW_NAMESPACE_LAG); |
|---|
| 3280 | + struct mlx5_flow_table *ft; |
|---|
| 3281 | + int err; |
|---|
| 3282 | + |
|---|
| 3283 | + if (!ns || !mlx5_lag_is_roce(mdev)) |
|---|
| 3284 | + return 0; |
|---|
| 3285 | + |
|---|
| 3286 | + err = mlx5_cmd_create_vport_lag(mdev); |
|---|
| 3287 | + if (err) |
|---|
| 3288 | + return err; |
|---|
| 3289 | + |
|---|
| 3290 | + ft = mlx5_create_lag_demux_flow_table(ns, 0, 0); |
|---|
| 3291 | + if (IS_ERR(ft)) { |
|---|
| 3292 | + err = PTR_ERR(ft); |
|---|
| 3293 | + goto err_destroy_vport_lag; |
|---|
| 3294 | + } |
|---|
| 3295 | + |
|---|
| 3296 | + dev->flow_db->lag_demux_ft = ft; |
|---|
| 3297 | + dev->lag_active = true; |
|---|
| 3298 | + return 0; |
|---|
| 3299 | + |
|---|
| 3300 | +err_destroy_vport_lag: |
|---|
| 3301 | + mlx5_cmd_destroy_vport_lag(mdev); |
|---|
| 3302 | + return err; |
|---|
| 3303 | +} |
|---|
| 3304 | + |
|---|
| 3305 | +static void mlx5_eth_lag_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 3306 | +{ |
|---|
| 3307 | + struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 3308 | + |
|---|
| 3309 | + if (dev->lag_active) { |
|---|
| 3310 | + dev->lag_active = false; |
|---|
| 3311 | + |
|---|
| 3312 | + mlx5_destroy_flow_table(dev->flow_db->lag_demux_ft); |
|---|
| 3313 | + dev->flow_db->lag_demux_ft = NULL; |
|---|
| 3314 | + |
|---|
| 3315 | + mlx5_cmd_destroy_vport_lag(mdev); |
|---|
| 3316 | + } |
|---|
| 3317 | +} |
|---|
| 3318 | + |
|---|
| 3319 | +static int mlx5_add_netdev_notifier(struct mlx5_ib_dev *dev, u8 port_num) |
|---|
| 3320 | +{ |
|---|
| 3321 | + int err; |
|---|
| 3322 | + |
|---|
| 3323 | + dev->port[port_num].roce.nb.notifier_call = mlx5_netdev_event; |
|---|
| 3324 | + err = register_netdevice_notifier(&dev->port[port_num].roce.nb); |
|---|
| 3325 | + if (err) { |
|---|
| 3326 | + dev->port[port_num].roce.nb.notifier_call = NULL; |
|---|
| 3327 | + return err; |
|---|
| 3328 | + } |
|---|
| 3329 | + |
|---|
| 3330 | + return 0; |
|---|
| 3331 | +} |
|---|
| 3332 | + |
|---|
| 3333 | +static void mlx5_remove_netdev_notifier(struct mlx5_ib_dev *dev, u8 port_num) |
|---|
| 3334 | +{ |
|---|
| 3335 | + if (dev->port[port_num].roce.nb.notifier_call) { |
|---|
| 3336 | + unregister_netdevice_notifier(&dev->port[port_num].roce.nb); |
|---|
| 3337 | + dev->port[port_num].roce.nb.notifier_call = NULL; |
|---|
| 3338 | + } |
|---|
| 3339 | +} |
|---|
| 3340 | + |
|---|
| 3341 | +static int mlx5_enable_eth(struct mlx5_ib_dev *dev) |
|---|
| 3342 | +{ |
|---|
| 3343 | + int err; |
|---|
| 3344 | + |
|---|
| 3345 | + err = mlx5_nic_vport_enable_roce(dev->mdev); |
|---|
| 3346 | + if (err) |
|---|
| 3347 | + return err; |
|---|
| 3348 | + |
|---|
| 3349 | + err = mlx5_eth_lag_init(dev); |
|---|
| 3350 | + if (err) |
|---|
| 3351 | + goto err_disable_roce; |
|---|
| 3352 | + |
|---|
| 3353 | + return 0; |
|---|
| 3354 | + |
|---|
| 3355 | +err_disable_roce: |
|---|
| 3356 | + mlx5_nic_vport_disable_roce(dev->mdev); |
|---|
| 3357 | + |
|---|
| 3358 | + return err; |
|---|
| 3359 | +} |
|---|
| 3360 | + |
|---|
| 3361 | +static void mlx5_disable_eth(struct mlx5_ib_dev *dev) |
|---|
| 3362 | +{ |
|---|
| 3363 | + mlx5_eth_lag_cleanup(dev); |
|---|
| 3364 | + mlx5_nic_vport_disable_roce(dev->mdev); |
|---|
| 3365 | +} |
|---|
| 3366 | + |
|---|
| 3367 | +static int mlx5_ib_rn_get_params(struct ib_device *device, u8 port_num, |
|---|
| 3368 | + enum rdma_netdev_t type, |
|---|
| 3369 | + struct rdma_netdev_alloc_params *params) |
|---|
| 3370 | +{ |
|---|
| 3371 | + if (type != RDMA_NETDEV_IPOIB) |
|---|
| 3372 | + return -EOPNOTSUPP; |
|---|
| 3373 | + |
|---|
| 3374 | + return mlx5_rdma_rn_get_params(to_mdev(device)->mdev, device, params); |
|---|
| 3375 | +} |
|---|
| 3376 | + |
|---|
| 3377 | +static ssize_t delay_drop_timeout_read(struct file *filp, char __user *buf, |
|---|
| 3378 | + size_t count, loff_t *pos) |
|---|
| 3379 | +{ |
|---|
| 3380 | + struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
|---|
| 3381 | + char lbuf[20]; |
|---|
| 3382 | + int len; |
|---|
| 3383 | + |
|---|
| 3384 | + len = snprintf(lbuf, sizeof(lbuf), "%u\n", delay_drop->timeout); |
|---|
| 3385 | + return simple_read_from_buffer(buf, count, pos, lbuf, len); |
|---|
| 3386 | +} |
|---|
| 3387 | + |
|---|
| 3388 | +static ssize_t delay_drop_timeout_write(struct file *filp, const char __user *buf, |
|---|
| 3389 | + size_t count, loff_t *pos) |
|---|
| 3390 | +{ |
|---|
| 3391 | + struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
|---|
| 3392 | + u32 timeout; |
|---|
| 3393 | + u32 var; |
|---|
| 3394 | + |
|---|
| 3395 | + if (kstrtouint_from_user(buf, count, 0, &var)) |
|---|
| 3396 | + return -EFAULT; |
|---|
| 3397 | + |
|---|
| 3398 | + timeout = min_t(u32, roundup(var, 100), MLX5_MAX_DELAY_DROP_TIMEOUT_MS * |
|---|
| 3399 | + 1000); |
|---|
| 3400 | + if (timeout != var) |
|---|
| 3401 | + mlx5_ib_dbg(delay_drop->dev, "Round delay drop timeout to %u usec\n", |
|---|
| 3402 | + timeout); |
|---|
| 3403 | + |
|---|
| 3404 | + delay_drop->timeout = timeout; |
|---|
| 3405 | + |
|---|
| 3406 | + return count; |
|---|
| 3407 | +} |
|---|
| 3408 | + |
|---|
| 3409 | +static const struct file_operations fops_delay_drop_timeout = { |
|---|
| 3410 | + .owner = THIS_MODULE, |
|---|
| 3411 | + .open = simple_open, |
|---|
| 3412 | + .write = delay_drop_timeout_write, |
|---|
| 3413 | + .read = delay_drop_timeout_read, |
|---|
| 3414 | +}; |
|---|
| 3415 | + |
|---|
| 3416 | +static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev, |
|---|
| 3417 | + struct mlx5_ib_multiport_info *mpi) |
|---|
| 3418 | +{ |
|---|
| 3419 | + u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
|---|
| 3420 | + struct mlx5_ib_port *port = &ibdev->port[port_num]; |
|---|
| 3421 | + int comps; |
|---|
| 3422 | + int err; |
|---|
| 3423 | + int i; |
|---|
| 3424 | + |
|---|
| 3425 | + lockdep_assert_held(&mlx5_ib_multiport_mutex); |
|---|
| 3426 | + |
|---|
| 3427 | + mlx5_ib_cleanup_cong_debugfs(ibdev, port_num); |
|---|
| 3428 | + |
|---|
| 3429 | + spin_lock(&port->mp.mpi_lock); |
|---|
| 3430 | + if (!mpi->ibdev) { |
|---|
| 3431 | + spin_unlock(&port->mp.mpi_lock); |
|---|
| 3432 | + return; |
|---|
| 3433 | + } |
|---|
| 3434 | + |
|---|
| 3435 | + mpi->ibdev = NULL; |
|---|
| 3436 | + |
|---|
| 3437 | + spin_unlock(&port->mp.mpi_lock); |
|---|
| 3438 | + if (mpi->mdev_events.notifier_call) |
|---|
| 3439 | + mlx5_notifier_unregister(mpi->mdev, &mpi->mdev_events); |
|---|
| 3440 | + mpi->mdev_events.notifier_call = NULL; |
|---|
| 3441 | + mlx5_remove_netdev_notifier(ibdev, port_num); |
|---|
| 3442 | + spin_lock(&port->mp.mpi_lock); |
|---|
| 3443 | + |
|---|
| 3444 | + comps = mpi->mdev_refcnt; |
|---|
| 3445 | + if (comps) { |
|---|
| 3446 | + mpi->unaffiliate = true; |
|---|
| 3447 | + init_completion(&mpi->unref_comp); |
|---|
| 3448 | + spin_unlock(&port->mp.mpi_lock); |
|---|
| 3449 | + |
|---|
| 3450 | + for (i = 0; i < comps; i++) |
|---|
| 3451 | + wait_for_completion(&mpi->unref_comp); |
|---|
| 3452 | + |
|---|
| 3453 | + spin_lock(&port->mp.mpi_lock); |
|---|
| 3454 | + mpi->unaffiliate = false; |
|---|
| 3455 | + } |
|---|
| 3456 | + |
|---|
| 3457 | + port->mp.mpi = NULL; |
|---|
| 3458 | + |
|---|
| 3459 | + spin_unlock(&port->mp.mpi_lock); |
|---|
| 3460 | + |
|---|
| 3461 | + err = mlx5_nic_vport_unaffiliate_multiport(mpi->mdev); |
|---|
| 3462 | + |
|---|
| 3463 | + mlx5_ib_dbg(ibdev, "unaffiliated port %d\n", port_num + 1); |
|---|
| 3464 | + /* Log an error, still needed to cleanup the pointers and add |
|---|
| 3465 | + * it back to the list. |
|---|
| 3466 | + */ |
|---|
| 3467 | + if (err) |
|---|
| 3468 | + mlx5_ib_err(ibdev, "Failed to unaffiliate port %u\n", |
|---|
| 3469 | + port_num + 1); |
|---|
| 3470 | + |
|---|
| 3471 | + ibdev->port[port_num].roce.last_port_state = IB_PORT_DOWN; |
|---|
| 3472 | +} |
|---|
| 3473 | + |
|---|
| 3474 | +static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev, |
|---|
| 3475 | + struct mlx5_ib_multiport_info *mpi) |
|---|
| 3476 | +{ |
|---|
| 3477 | + u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
|---|
| 3478 | + int err; |
|---|
| 3479 | + |
|---|
| 3480 | + lockdep_assert_held(&mlx5_ib_multiport_mutex); |
|---|
| 3481 | + |
|---|
| 3482 | + spin_lock(&ibdev->port[port_num].mp.mpi_lock); |
|---|
| 3483 | + if (ibdev->port[port_num].mp.mpi) { |
|---|
| 3484 | + mlx5_ib_dbg(ibdev, "port %d already affiliated.\n", |
|---|
| 3485 | + port_num + 1); |
|---|
| 3486 | + spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
|---|
| 3487 | + return false; |
|---|
| 3488 | + } |
|---|
| 3489 | + |
|---|
| 3490 | + ibdev->port[port_num].mp.mpi = mpi; |
|---|
| 3491 | + mpi->ibdev = ibdev; |
|---|
| 3492 | + mpi->mdev_events.notifier_call = NULL; |
|---|
| 3493 | + spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
|---|
| 3494 | + |
|---|
| 3495 | + err = mlx5_nic_vport_affiliate_multiport(ibdev->mdev, mpi->mdev); |
|---|
| 3496 | + if (err) |
|---|
| 3497 | + goto unbind; |
|---|
| 3498 | + |
|---|
| 3499 | + err = get_port_caps(ibdev, mlx5_core_native_port_num(mpi->mdev)); |
|---|
| 3500 | + if (err) |
|---|
| 3501 | + goto unbind; |
|---|
| 3502 | + |
|---|
| 3503 | + err = mlx5_add_netdev_notifier(ibdev, port_num); |
|---|
| 3504 | + if (err) { |
|---|
| 3505 | + mlx5_ib_err(ibdev, "failed adding netdev notifier for port %u\n", |
|---|
| 3506 | + port_num + 1); |
|---|
| 3507 | + goto unbind; |
|---|
| 3508 | + } |
|---|
| 3509 | + |
|---|
| 3510 | + mpi->mdev_events.notifier_call = mlx5_ib_event_slave_port; |
|---|
| 3511 | + mlx5_notifier_register(mpi->mdev, &mpi->mdev_events); |
|---|
| 3512 | + |
|---|
| 3513 | + mlx5_ib_init_cong_debugfs(ibdev, port_num); |
|---|
| 3514 | + |
|---|
| 3515 | + return true; |
|---|
| 3516 | + |
|---|
| 3517 | +unbind: |
|---|
| 3518 | + mlx5_ib_unbind_slave_port(ibdev, mpi); |
|---|
| 3519 | + return false; |
|---|
| 3520 | +} |
|---|
| 3521 | + |
|---|
| 3522 | +static int mlx5_ib_init_multiport_master(struct mlx5_ib_dev *dev) |
|---|
| 3523 | +{ |
|---|
| 3524 | + int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
|---|
| 3525 | + enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
|---|
| 3526 | + port_num + 1); |
|---|
| 3527 | + struct mlx5_ib_multiport_info *mpi; |
|---|
| 3528 | + int err; |
|---|
| 3529 | + int i; |
|---|
| 3530 | + |
|---|
| 3531 | + if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
|---|
| 3532 | + return 0; |
|---|
| 3533 | + |
|---|
| 3534 | + err = mlx5_query_nic_vport_system_image_guid(dev->mdev, |
|---|
| 3535 | + &dev->sys_image_guid); |
|---|
| 3536 | + if (err) |
|---|
| 3537 | + return err; |
|---|
| 3538 | + |
|---|
| 3539 | + err = mlx5_nic_vport_enable_roce(dev->mdev); |
|---|
| 3540 | + if (err) |
|---|
| 3541 | + return err; |
|---|
| 3542 | + |
|---|
| 3543 | + mutex_lock(&mlx5_ib_multiport_mutex); |
|---|
| 3544 | + for (i = 0; i < dev->num_ports; i++) { |
|---|
| 3545 | + bool bound = false; |
|---|
| 3546 | + |
|---|
| 3547 | + /* build a stub multiport info struct for the native port. */ |
|---|
| 3548 | + if (i == port_num) { |
|---|
| 3549 | + mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
|---|
| 3550 | + if (!mpi) { |
|---|
| 3551 | + mutex_unlock(&mlx5_ib_multiport_mutex); |
|---|
| 3552 | + mlx5_nic_vport_disable_roce(dev->mdev); |
|---|
| 3553 | + return -ENOMEM; |
|---|
| 3554 | + } |
|---|
| 3555 | + |
|---|
| 3556 | + mpi->is_master = true; |
|---|
| 3557 | + mpi->mdev = dev->mdev; |
|---|
| 3558 | + mpi->sys_image_guid = dev->sys_image_guid; |
|---|
| 3559 | + dev->port[i].mp.mpi = mpi; |
|---|
| 3560 | + mpi->ibdev = dev; |
|---|
| 3561 | + mpi = NULL; |
|---|
| 3562 | + continue; |
|---|
| 3563 | + } |
|---|
| 3564 | + |
|---|
| 3565 | + list_for_each_entry(mpi, &mlx5_ib_unaffiliated_port_list, |
|---|
| 3566 | + list) { |
|---|
| 3567 | + if (dev->sys_image_guid == mpi->sys_image_guid && |
|---|
| 3568 | + (mlx5_core_native_port_num(mpi->mdev) - 1) == i) { |
|---|
| 3569 | + bound = mlx5_ib_bind_slave_port(dev, mpi); |
|---|
| 3570 | + } |
|---|
| 3571 | + |
|---|
| 3572 | + if (bound) { |
|---|
| 3573 | + dev_dbg(mpi->mdev->device, |
|---|
| 3574 | + "removing port from unaffiliated list.\n"); |
|---|
| 3575 | + mlx5_ib_dbg(dev, "port %d bound\n", i + 1); |
|---|
| 3576 | + list_del(&mpi->list); |
|---|
| 3577 | + break; |
|---|
| 3578 | + } |
|---|
| 3579 | + } |
|---|
| 3580 | + if (!bound) { |
|---|
| 3581 | + get_port_caps(dev, i + 1); |
|---|
| 3582 | + mlx5_ib_dbg(dev, "no free port found for port %d\n", |
|---|
| 3583 | + i + 1); |
|---|
| 3584 | + } |
|---|
| 3585 | + } |
|---|
| 3586 | + |
|---|
| 3587 | + list_add_tail(&dev->ib_dev_list, &mlx5_ib_dev_list); |
|---|
| 3588 | + mutex_unlock(&mlx5_ib_multiport_mutex); |
|---|
| 3589 | + return err; |
|---|
| 3590 | +} |
|---|
| 3591 | + |
|---|
| 3592 | +static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev) |
|---|
| 3593 | +{ |
|---|
| 3594 | + int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
|---|
| 3595 | + enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
|---|
| 3596 | + port_num + 1); |
|---|
| 3597 | + int i; |
|---|
| 3598 | + |
|---|
| 3599 | + if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
|---|
| 3600 | + return; |
|---|
| 3601 | + |
|---|
| 3602 | + mutex_lock(&mlx5_ib_multiport_mutex); |
|---|
| 3603 | + for (i = 0; i < dev->num_ports; i++) { |
|---|
| 3604 | + if (dev->port[i].mp.mpi) { |
|---|
| 3605 | + /* Destroy the native port stub */ |
|---|
| 3606 | + if (i == port_num) { |
|---|
| 3607 | + kfree(dev->port[i].mp.mpi); |
|---|
| 3608 | + dev->port[i].mp.mpi = NULL; |
|---|
| 3609 | + } else { |
|---|
| 3610 | + mlx5_ib_dbg(dev, "unbinding port_num: %d\n", i + 1); |
|---|
| 3611 | + list_add_tail(&dev->port[i].mp.mpi->list, |
|---|
| 3612 | + &mlx5_ib_unaffiliated_port_list); |
|---|
| 3613 | + mlx5_ib_unbind_slave_port(dev, dev->port[i].mp.mpi); |
|---|
| 3614 | + } |
|---|
| 3615 | + } |
|---|
| 3616 | + } |
|---|
| 3617 | + |
|---|
| 3618 | + mlx5_ib_dbg(dev, "removing from devlist\n"); |
|---|
| 3619 | + list_del(&dev->ib_dev_list); |
|---|
| 3620 | + mutex_unlock(&mlx5_ib_multiport_mutex); |
|---|
| 3621 | + |
|---|
| 3622 | + mlx5_nic_vport_disable_roce(dev->mdev); |
|---|
| 3623 | +} |
|---|
| 3624 | + |
|---|
| 3625 | +static int mmap_obj_cleanup(struct ib_uobject *uobject, |
|---|
| 3626 | + enum rdma_remove_reason why, |
|---|
| 3627 | + struct uverbs_attr_bundle *attrs) |
|---|
| 3628 | +{ |
|---|
| 3629 | + struct mlx5_user_mmap_entry *obj = uobject->object; |
|---|
| 3630 | + |
|---|
| 3631 | + rdma_user_mmap_entry_remove(&obj->rdma_entry); |
|---|
| 3632 | + return 0; |
|---|
| 3633 | +} |
|---|
| 3634 | + |
|---|
| 3635 | +static int mlx5_rdma_user_mmap_entry_insert(struct mlx5_ib_ucontext *c, |
|---|
| 3636 | + struct mlx5_user_mmap_entry *entry, |
|---|
| 3637 | + size_t length) |
|---|
| 3638 | +{ |
|---|
| 3639 | + return rdma_user_mmap_entry_insert_range( |
|---|
| 3640 | + &c->ibucontext, &entry->rdma_entry, length, |
|---|
| 3641 | + (MLX5_IB_MMAP_OFFSET_START << 16), |
|---|
| 3642 | + ((MLX5_IB_MMAP_OFFSET_END << 16) + (1UL << 16) - 1)); |
|---|
| 3643 | +} |
|---|
| 3644 | + |
|---|
| 3645 | +static struct mlx5_user_mmap_entry * |
|---|
| 3646 | +alloc_var_entry(struct mlx5_ib_ucontext *c) |
|---|
| 3647 | +{ |
|---|
| 3648 | + struct mlx5_user_mmap_entry *entry; |
|---|
| 3649 | + struct mlx5_var_table *var_table; |
|---|
| 3650 | + u32 page_idx; |
|---|
| 3651 | + int err; |
|---|
| 3652 | + |
|---|
| 3653 | + var_table = &to_mdev(c->ibucontext.device)->var_table; |
|---|
| 3654 | + entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
|---|
| 3655 | + if (!entry) |
|---|
| 3656 | + return ERR_PTR(-ENOMEM); |
|---|
| 3657 | + |
|---|
| 3658 | + mutex_lock(&var_table->bitmap_lock); |
|---|
| 3659 | + page_idx = find_first_zero_bit(var_table->bitmap, |
|---|
| 3660 | + var_table->num_var_hw_entries); |
|---|
| 3661 | + if (page_idx >= var_table->num_var_hw_entries) { |
|---|
| 3662 | + err = -ENOSPC; |
|---|
| 3663 | + mutex_unlock(&var_table->bitmap_lock); |
|---|
| 3664 | + goto end; |
|---|
| 3665 | + } |
|---|
| 3666 | + |
|---|
| 3667 | + set_bit(page_idx, var_table->bitmap); |
|---|
| 3668 | + mutex_unlock(&var_table->bitmap_lock); |
|---|
| 3669 | + |
|---|
| 3670 | + entry->address = var_table->hw_start_addr + |
|---|
| 3671 | + (page_idx * var_table->stride_size); |
|---|
| 3672 | + entry->page_idx = page_idx; |
|---|
| 3673 | + entry->mmap_flag = MLX5_IB_MMAP_TYPE_VAR; |
|---|
| 3674 | + |
|---|
| 3675 | + err = mlx5_rdma_user_mmap_entry_insert(c, entry, |
|---|
| 3676 | + var_table->stride_size); |
|---|
| 3677 | + if (err) |
|---|
| 3678 | + goto err_insert; |
|---|
| 3679 | + |
|---|
| 3680 | + return entry; |
|---|
| 3681 | + |
|---|
| 3682 | +err_insert: |
|---|
| 3683 | + mutex_lock(&var_table->bitmap_lock); |
|---|
| 3684 | + clear_bit(page_idx, var_table->bitmap); |
|---|
| 3685 | + mutex_unlock(&var_table->bitmap_lock); |
|---|
| 3686 | +end: |
|---|
| 3687 | + kfree(entry); |
|---|
| 3688 | + return ERR_PTR(err); |
|---|
| 3689 | +} |
|---|
| 3690 | + |
|---|
| 3691 | +static int UVERBS_HANDLER(MLX5_IB_METHOD_VAR_OBJ_ALLOC)( |
|---|
| 3692 | + struct uverbs_attr_bundle *attrs) |
|---|
| 3693 | +{ |
|---|
| 3694 | + struct ib_uobject *uobj = uverbs_attr_get_uobject( |
|---|
| 3695 | + attrs, MLX5_IB_ATTR_VAR_OBJ_ALLOC_HANDLE); |
|---|
| 3696 | + struct mlx5_ib_ucontext *c; |
|---|
| 3697 | + struct mlx5_user_mmap_entry *entry; |
|---|
| 3698 | + u64 mmap_offset; |
|---|
| 3699 | + u32 length; |
|---|
| 3700 | + int err; |
|---|
| 3701 | + |
|---|
| 3702 | + c = to_mucontext(ib_uverbs_get_ucontext(attrs)); |
|---|
| 3703 | + if (IS_ERR(c)) |
|---|
| 3704 | + return PTR_ERR(c); |
|---|
| 3705 | + |
|---|
| 3706 | + entry = alloc_var_entry(c); |
|---|
| 3707 | + if (IS_ERR(entry)) |
|---|
| 3708 | + return PTR_ERR(entry); |
|---|
| 3709 | + |
|---|
| 3710 | + mmap_offset = mlx5_entry_to_mmap_offset(entry); |
|---|
| 3711 | + length = entry->rdma_entry.npages * PAGE_SIZE; |
|---|
| 3712 | + uobj->object = entry; |
|---|
| 3713 | + uverbs_finalize_uobj_create(attrs, MLX5_IB_ATTR_VAR_OBJ_ALLOC_HANDLE); |
|---|
| 3714 | + |
|---|
| 3715 | + err = uverbs_copy_to(attrs, MLX5_IB_ATTR_VAR_OBJ_ALLOC_MMAP_OFFSET, |
|---|
| 3716 | + &mmap_offset, sizeof(mmap_offset)); |
|---|
| 3717 | + if (err) |
|---|
| 3718 | + return err; |
|---|
| 3719 | + |
|---|
| 3720 | + err = uverbs_copy_to(attrs, MLX5_IB_ATTR_VAR_OBJ_ALLOC_PAGE_ID, |
|---|
| 3721 | + &entry->page_idx, sizeof(entry->page_idx)); |
|---|
| 3722 | + if (err) |
|---|
| 3723 | + return err; |
|---|
| 3724 | + |
|---|
| 3725 | + err = uverbs_copy_to(attrs, MLX5_IB_ATTR_VAR_OBJ_ALLOC_MMAP_LENGTH, |
|---|
| 3726 | + &length, sizeof(length)); |
|---|
| 3727 | + return err; |
|---|
| 3728 | +} |
|---|
| 3729 | + |
|---|
| 3730 | +DECLARE_UVERBS_NAMED_METHOD( |
|---|
| 3731 | + MLX5_IB_METHOD_VAR_OBJ_ALLOC, |
|---|
| 3732 | + UVERBS_ATTR_IDR(MLX5_IB_ATTR_VAR_OBJ_ALLOC_HANDLE, |
|---|
| 3733 | + MLX5_IB_OBJECT_VAR, |
|---|
| 3734 | + UVERBS_ACCESS_NEW, |
|---|
| 3735 | + UA_MANDATORY), |
|---|
| 3736 | + UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_VAR_OBJ_ALLOC_PAGE_ID, |
|---|
| 3737 | + UVERBS_ATTR_TYPE(u32), |
|---|
| 3738 | + UA_MANDATORY), |
|---|
| 3739 | + UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_VAR_OBJ_ALLOC_MMAP_LENGTH, |
|---|
| 3740 | + UVERBS_ATTR_TYPE(u32), |
|---|
| 3741 | + UA_MANDATORY), |
|---|
| 3742 | + UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_VAR_OBJ_ALLOC_MMAP_OFFSET, |
|---|
| 3743 | + UVERBS_ATTR_TYPE(u64), |
|---|
| 3744 | + UA_MANDATORY)); |
|---|
| 3745 | + |
|---|
| 3746 | +DECLARE_UVERBS_NAMED_METHOD_DESTROY( |
|---|
| 3747 | + MLX5_IB_METHOD_VAR_OBJ_DESTROY, |
|---|
| 3748 | + UVERBS_ATTR_IDR(MLX5_IB_ATTR_VAR_OBJ_DESTROY_HANDLE, |
|---|
| 3749 | + MLX5_IB_OBJECT_VAR, |
|---|
| 3750 | + UVERBS_ACCESS_DESTROY, |
|---|
| 3751 | + UA_MANDATORY)); |
|---|
| 3752 | + |
|---|
| 3753 | +DECLARE_UVERBS_NAMED_OBJECT(MLX5_IB_OBJECT_VAR, |
|---|
| 3754 | + UVERBS_TYPE_ALLOC_IDR(mmap_obj_cleanup), |
|---|
| 3755 | + &UVERBS_METHOD(MLX5_IB_METHOD_VAR_OBJ_ALLOC), |
|---|
| 3756 | + &UVERBS_METHOD(MLX5_IB_METHOD_VAR_OBJ_DESTROY)); |
|---|
| 3757 | + |
|---|
| 3758 | +static bool var_is_supported(struct ib_device *device) |
|---|
| 3759 | +{ |
|---|
| 3760 | + struct mlx5_ib_dev *dev = to_mdev(device); |
|---|
| 3761 | + |
|---|
| 3762 | + return (MLX5_CAP_GEN_64(dev->mdev, general_obj_types) & |
|---|
| 3763 | + MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_NET_Q); |
|---|
| 3764 | +} |
|---|
| 3765 | + |
|---|
| 3766 | +static struct mlx5_user_mmap_entry * |
|---|
| 3767 | +alloc_uar_entry(struct mlx5_ib_ucontext *c, |
|---|
| 3768 | + enum mlx5_ib_uapi_uar_alloc_type alloc_type) |
|---|
| 3769 | +{ |
|---|
| 3770 | + struct mlx5_user_mmap_entry *entry; |
|---|
| 3771 | + struct mlx5_ib_dev *dev; |
|---|
| 3772 | + u32 uar_index; |
|---|
| 3773 | + int err; |
|---|
| 3774 | + |
|---|
| 3775 | + entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
|---|
| 3776 | + if (!entry) |
|---|
| 3777 | + return ERR_PTR(-ENOMEM); |
|---|
| 3778 | + |
|---|
| 3779 | + dev = to_mdev(c->ibucontext.device); |
|---|
| 3780 | + err = mlx5_cmd_alloc_uar(dev->mdev, &uar_index); |
|---|
| 3781 | + if (err) |
|---|
| 3782 | + goto end; |
|---|
| 3783 | + |
|---|
| 3784 | + entry->page_idx = uar_index; |
|---|
| 3785 | + entry->address = uar_index2paddress(dev, uar_index); |
|---|
| 3786 | + if (alloc_type == MLX5_IB_UAPI_UAR_ALLOC_TYPE_BF) |
|---|
| 3787 | + entry->mmap_flag = MLX5_IB_MMAP_TYPE_UAR_WC; |
|---|
| 3788 | + else |
|---|
| 3789 | + entry->mmap_flag = MLX5_IB_MMAP_TYPE_UAR_NC; |
|---|
| 3790 | + |
|---|
| 3791 | + err = mlx5_rdma_user_mmap_entry_insert(c, entry, PAGE_SIZE); |
|---|
| 3792 | + if (err) |
|---|
| 3793 | + goto err_insert; |
|---|
| 3794 | + |
|---|
| 3795 | + return entry; |
|---|
| 3796 | + |
|---|
| 3797 | +err_insert: |
|---|
| 3798 | + mlx5_cmd_free_uar(dev->mdev, uar_index); |
|---|
| 3799 | +end: |
|---|
| 3800 | + kfree(entry); |
|---|
| 3801 | + return ERR_PTR(err); |
|---|
| 3802 | +} |
|---|
| 3803 | + |
|---|
| 3804 | +static int UVERBS_HANDLER(MLX5_IB_METHOD_UAR_OBJ_ALLOC)( |
|---|
| 3805 | + struct uverbs_attr_bundle *attrs) |
|---|
| 3806 | +{ |
|---|
| 3807 | + struct ib_uobject *uobj = uverbs_attr_get_uobject( |
|---|
| 3808 | + attrs, MLX5_IB_ATTR_UAR_OBJ_ALLOC_HANDLE); |
|---|
| 3809 | + enum mlx5_ib_uapi_uar_alloc_type alloc_type; |
|---|
| 3810 | + struct mlx5_ib_ucontext *c; |
|---|
| 3811 | + struct mlx5_user_mmap_entry *entry; |
|---|
| 3812 | + u64 mmap_offset; |
|---|
| 3813 | + u32 length; |
|---|
| 3814 | + int err; |
|---|
| 3815 | + |
|---|
| 3816 | + c = to_mucontext(ib_uverbs_get_ucontext(attrs)); |
|---|
| 3817 | + if (IS_ERR(c)) |
|---|
| 3818 | + return PTR_ERR(c); |
|---|
| 3819 | + |
|---|
| 3820 | + err = uverbs_get_const(&alloc_type, attrs, |
|---|
| 3821 | + MLX5_IB_ATTR_UAR_OBJ_ALLOC_TYPE); |
|---|
| 3822 | + if (err) |
|---|
| 3823 | + return err; |
|---|
| 3824 | + |
|---|
| 3825 | + if (alloc_type != MLX5_IB_UAPI_UAR_ALLOC_TYPE_BF && |
|---|
| 3826 | + alloc_type != MLX5_IB_UAPI_UAR_ALLOC_TYPE_NC) |
|---|
| 3827 | + return -EOPNOTSUPP; |
|---|
| 3828 | + |
|---|
| 3829 | + if (!to_mdev(c->ibucontext.device)->wc_support && |
|---|
| 3830 | + alloc_type == MLX5_IB_UAPI_UAR_ALLOC_TYPE_BF) |
|---|
| 3831 | + return -EOPNOTSUPP; |
|---|
| 3832 | + |
|---|
| 3833 | + entry = alloc_uar_entry(c, alloc_type); |
|---|
| 3834 | + if (IS_ERR(entry)) |
|---|
| 3835 | + return PTR_ERR(entry); |
|---|
| 3836 | + |
|---|
| 3837 | + mmap_offset = mlx5_entry_to_mmap_offset(entry); |
|---|
| 3838 | + length = entry->rdma_entry.npages * PAGE_SIZE; |
|---|
| 3839 | + uobj->object = entry; |
|---|
| 3840 | + uverbs_finalize_uobj_create(attrs, MLX5_IB_ATTR_UAR_OBJ_ALLOC_HANDLE); |
|---|
| 3841 | + |
|---|
| 3842 | + err = uverbs_copy_to(attrs, MLX5_IB_ATTR_UAR_OBJ_ALLOC_MMAP_OFFSET, |
|---|
| 3843 | + &mmap_offset, sizeof(mmap_offset)); |
|---|
| 3844 | + if (err) |
|---|
| 3845 | + return err; |
|---|
| 3846 | + |
|---|
| 3847 | + err = uverbs_copy_to(attrs, MLX5_IB_ATTR_UAR_OBJ_ALLOC_PAGE_ID, |
|---|
| 3848 | + &entry->page_idx, sizeof(entry->page_idx)); |
|---|
| 3849 | + if (err) |
|---|
| 3850 | + return err; |
|---|
| 3851 | + |
|---|
| 3852 | + err = uverbs_copy_to(attrs, MLX5_IB_ATTR_UAR_OBJ_ALLOC_MMAP_LENGTH, |
|---|
| 3853 | + &length, sizeof(length)); |
|---|
| 3854 | + return err; |
|---|
| 3855 | +} |
|---|
| 3856 | + |
|---|
| 3857 | +DECLARE_UVERBS_NAMED_METHOD( |
|---|
| 3858 | + MLX5_IB_METHOD_UAR_OBJ_ALLOC, |
|---|
| 3859 | + UVERBS_ATTR_IDR(MLX5_IB_ATTR_UAR_OBJ_ALLOC_HANDLE, |
|---|
| 3860 | + MLX5_IB_OBJECT_UAR, |
|---|
| 3861 | + UVERBS_ACCESS_NEW, |
|---|
| 3862 | + UA_MANDATORY), |
|---|
| 3863 | + UVERBS_ATTR_CONST_IN(MLX5_IB_ATTR_UAR_OBJ_ALLOC_TYPE, |
|---|
| 3864 | + enum mlx5_ib_uapi_uar_alloc_type, |
|---|
| 3865 | + UA_MANDATORY), |
|---|
| 3866 | + UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_UAR_OBJ_ALLOC_PAGE_ID, |
|---|
| 3867 | + UVERBS_ATTR_TYPE(u32), |
|---|
| 3868 | + UA_MANDATORY), |
|---|
| 3869 | + UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_UAR_OBJ_ALLOC_MMAP_LENGTH, |
|---|
| 3870 | + UVERBS_ATTR_TYPE(u32), |
|---|
| 3871 | + UA_MANDATORY), |
|---|
| 3872 | + UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_UAR_OBJ_ALLOC_MMAP_OFFSET, |
|---|
| 3873 | + UVERBS_ATTR_TYPE(u64), |
|---|
| 3874 | + UA_MANDATORY)); |
|---|
| 3875 | + |
|---|
| 3876 | +DECLARE_UVERBS_NAMED_METHOD_DESTROY( |
|---|
| 3877 | + MLX5_IB_METHOD_UAR_OBJ_DESTROY, |
|---|
| 3878 | + UVERBS_ATTR_IDR(MLX5_IB_ATTR_UAR_OBJ_DESTROY_HANDLE, |
|---|
| 3879 | + MLX5_IB_OBJECT_UAR, |
|---|
| 3880 | + UVERBS_ACCESS_DESTROY, |
|---|
| 3881 | + UA_MANDATORY)); |
|---|
| 3882 | + |
|---|
| 3883 | +DECLARE_UVERBS_NAMED_OBJECT(MLX5_IB_OBJECT_UAR, |
|---|
| 3884 | + UVERBS_TYPE_ALLOC_IDR(mmap_obj_cleanup), |
|---|
| 3885 | + &UVERBS_METHOD(MLX5_IB_METHOD_UAR_OBJ_ALLOC), |
|---|
| 3886 | + &UVERBS_METHOD(MLX5_IB_METHOD_UAR_OBJ_DESTROY)); |
|---|
| 3887 | + |
|---|
| 3888 | +ADD_UVERBS_ATTRIBUTES_SIMPLE( |
|---|
| 3889 | + mlx5_ib_dm, |
|---|
| 3890 | + UVERBS_OBJECT_DM, |
|---|
| 3891 | + UVERBS_METHOD_DM_ALLOC, |
|---|
| 3892 | + UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
|---|
| 3893 | + UVERBS_ATTR_TYPE(u64), |
|---|
| 3894 | + UA_MANDATORY), |
|---|
| 3895 | + UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
|---|
| 3896 | + UVERBS_ATTR_TYPE(u16), |
|---|
| 3897 | + UA_OPTIONAL), |
|---|
| 3898 | + UVERBS_ATTR_CONST_IN(MLX5_IB_ATTR_ALLOC_DM_REQ_TYPE, |
|---|
| 3899 | + enum mlx5_ib_uapi_dm_type, |
|---|
| 3900 | + UA_OPTIONAL)); |
|---|
| 3901 | + |
|---|
| 3902 | +ADD_UVERBS_ATTRIBUTES_SIMPLE( |
|---|
| 3903 | + mlx5_ib_flow_action, |
|---|
| 3904 | + UVERBS_OBJECT_FLOW_ACTION, |
|---|
| 3905 | + UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, |
|---|
| 3906 | + UVERBS_ATTR_FLAGS_IN(MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
|---|
| 3907 | + enum mlx5_ib_uapi_flow_action_flags)); |
|---|
| 3908 | + |
|---|
| 3909 | +ADD_UVERBS_ATTRIBUTES_SIMPLE( |
|---|
| 3910 | + mlx5_ib_query_context, |
|---|
| 3911 | + UVERBS_OBJECT_DEVICE, |
|---|
| 3912 | + UVERBS_METHOD_QUERY_CONTEXT, |
|---|
| 3913 | + UVERBS_ATTR_PTR_OUT( |
|---|
| 3914 | + MLX5_IB_ATTR_QUERY_CONTEXT_RESP_UCTX, |
|---|
| 3915 | + UVERBS_ATTR_STRUCT(struct mlx5_ib_alloc_ucontext_resp, |
|---|
| 3916 | + dump_fill_mkey), |
|---|
| 3917 | + UA_MANDATORY)); |
|---|
| 3918 | + |
|---|
| 3919 | +static const struct uapi_definition mlx5_ib_defs[] = { |
|---|
| 3920 | + UAPI_DEF_CHAIN(mlx5_ib_devx_defs), |
|---|
| 3921 | + UAPI_DEF_CHAIN(mlx5_ib_flow_defs), |
|---|
| 3922 | + UAPI_DEF_CHAIN(mlx5_ib_qos_defs), |
|---|
| 3923 | + UAPI_DEF_CHAIN(mlx5_ib_std_types_defs), |
|---|
| 3924 | + |
|---|
| 3925 | + UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_FLOW_ACTION, |
|---|
| 3926 | + &mlx5_ib_flow_action), |
|---|
| 3927 | + UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_DM, &mlx5_ib_dm), |
|---|
| 3928 | + UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_DEVICE, &mlx5_ib_query_context), |
|---|
| 3929 | + UAPI_DEF_CHAIN_OBJ_TREE_NAMED(MLX5_IB_OBJECT_VAR, |
|---|
| 3930 | + UAPI_DEF_IS_OBJ_SUPPORTED(var_is_supported)), |
|---|
| 3931 | + UAPI_DEF_CHAIN_OBJ_TREE_NAMED(MLX5_IB_OBJECT_UAR), |
|---|
| 3932 | + {} |
|---|
| 3933 | +}; |
|---|
| 3934 | + |
|---|
| 3935 | +static void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 3936 | +{ |
|---|
| 3937 | + mlx5_ib_cleanup_multiport_master(dev); |
|---|
| 3938 | + WARN_ON(!xa_empty(&dev->odp_mkeys)); |
|---|
| 3939 | + cleanup_srcu_struct(&dev->odp_srcu); |
|---|
| 3940 | + mutex_destroy(&dev->cap_mask_mutex); |
|---|
| 3941 | + WARN_ON(!xa_empty(&dev->sig_mrs)); |
|---|
| 3942 | + WARN_ON(!bitmap_empty(dev->dm.memic_alloc_pages, MLX5_MAX_MEMIC_PAGES)); |
|---|
| 3943 | +} |
|---|
| 3944 | + |
|---|
| 3945 | +static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev) |
|---|
| 3946 | +{ |
|---|
| 3947 | + struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 3948 | + int err; |
|---|
| 3949 | + int i; |
|---|
| 3950 | + |
|---|
| 3951 | + for (i = 0; i < dev->num_ports; i++) { |
|---|
| 3952 | + spin_lock_init(&dev->port[i].mp.mpi_lock); |
|---|
| 3953 | + rwlock_init(&dev->port[i].roce.netdev_lock); |
|---|
| 3954 | + dev->port[i].roce.dev = dev; |
|---|
| 3955 | + dev->port[i].roce.native_port_num = i + 1; |
|---|
| 3956 | + dev->port[i].roce.last_port_state = IB_PORT_DOWN; |
|---|
| 3957 | + } |
|---|
| 3958 | + |
|---|
| 3959 | + mlx5_ib_internal_fill_odp_caps(dev); |
|---|
| 3960 | + |
|---|
| 3961 | + err = mlx5_ib_init_multiport_master(dev); |
|---|
| 3962 | + if (err) |
|---|
| 3963 | + return err; |
|---|
| 3964 | + |
|---|
| 3965 | + err = set_has_smi_cap(dev); |
|---|
| 3966 | + if (err) |
|---|
| 3967 | + goto err_mp; |
|---|
| 3968 | + |
|---|
| 3969 | + if (!mlx5_core_mp_enabled(mdev)) { |
|---|
| 3970 | + for (i = 1; i <= dev->num_ports; i++) { |
|---|
| 3971 | + err = get_port_caps(dev, i); |
|---|
| 3972 | + if (err) |
|---|
| 3973 | + break; |
|---|
| 3974 | + } |
|---|
| 3975 | + } else { |
|---|
| 3976 | + err = get_port_caps(dev, mlx5_core_native_port_num(mdev)); |
|---|
| 3977 | + } |
|---|
| 3978 | + if (err) |
|---|
| 3979 | + goto err_mp; |
|---|
| 3980 | + |
|---|
| 3981 | + if (mlx5_use_mad_ifc(dev)) |
|---|
| 3982 | + get_ext_port_caps(dev); |
|---|
| 3983 | + |
|---|
| 3984 | + dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
|---|
| 3985 | + dev->ib_dev.local_dma_lkey = 0 /* not supported for now */; |
|---|
| 3986 | + dev->ib_dev.phys_port_cnt = dev->num_ports; |
|---|
| 3987 | + dev->ib_dev.num_comp_vectors = mlx5_comp_vectors_count(mdev); |
|---|
| 3988 | + dev->ib_dev.dev.parent = mdev->device; |
|---|
| 3989 | + dev->ib_dev.lag_flags = RDMA_LAG_FLAGS_HASH_ALL_SLAVES; |
|---|
| 3990 | + |
|---|
| 3991 | + err = init_srcu_struct(&dev->odp_srcu); |
|---|
| 3992 | + if (err) |
|---|
| 3993 | + goto err_mp; |
|---|
| 3994 | + |
|---|
| 3995 | + mutex_init(&dev->cap_mask_mutex); |
|---|
| 3996 | + INIT_LIST_HEAD(&dev->qp_list); |
|---|
| 3997 | + spin_lock_init(&dev->reset_flow_resource_lock); |
|---|
| 3998 | + xa_init(&dev->odp_mkeys); |
|---|
| 3999 | + xa_init(&dev->sig_mrs); |
|---|
| 4000 | + atomic_set(&dev->mkey_var, 0); |
|---|
| 4001 | + |
|---|
| 4002 | + spin_lock_init(&dev->dm.lock); |
|---|
| 4003 | + dev->dm.dev = mdev; |
|---|
| 4004 | + return 0; |
|---|
| 4005 | + |
|---|
| 4006 | +err_mp: |
|---|
| 4007 | + mlx5_ib_cleanup_multiport_master(dev); |
|---|
| 4008 | + return err; |
|---|
| 4009 | +} |
|---|
| 4010 | + |
|---|
| 4011 | +static int mlx5_ib_enable_driver(struct ib_device *dev) |
|---|
| 4012 | +{ |
|---|
| 4013 | + struct mlx5_ib_dev *mdev = to_mdev(dev); |
|---|
| 4014 | + int ret; |
|---|
| 4015 | + |
|---|
| 4016 | + ret = mlx5_ib_test_wc(mdev); |
|---|
| 4017 | + mlx5_ib_dbg(mdev, "Write-Combining %s", |
|---|
| 4018 | + mdev->wc_support ? "supported" : "not supported"); |
|---|
| 4019 | + |
|---|
| 4020 | + return ret; |
|---|
| 4021 | +} |
|---|
| 4022 | + |
|---|
| 4023 | +static const struct ib_device_ops mlx5_ib_dev_ops = { |
|---|
| 4024 | + .owner = THIS_MODULE, |
|---|
| 4025 | + .driver_id = RDMA_DRIVER_MLX5, |
|---|
| 4026 | + .uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION, |
|---|
| 4027 | + |
|---|
| 4028 | + .add_gid = mlx5_ib_add_gid, |
|---|
| 4029 | + .alloc_mr = mlx5_ib_alloc_mr, |
|---|
| 4030 | + .alloc_mr_integrity = mlx5_ib_alloc_mr_integrity, |
|---|
| 4031 | + .alloc_pd = mlx5_ib_alloc_pd, |
|---|
| 4032 | + .alloc_ucontext = mlx5_ib_alloc_ucontext, |
|---|
| 4033 | + .attach_mcast = mlx5_ib_mcg_attach, |
|---|
| 4034 | + .check_mr_status = mlx5_ib_check_mr_status, |
|---|
| 4035 | + .create_ah = mlx5_ib_create_ah, |
|---|
| 4036 | + .create_cq = mlx5_ib_create_cq, |
|---|
| 4037 | + .create_qp = mlx5_ib_create_qp, |
|---|
| 4038 | + .create_srq = mlx5_ib_create_srq, |
|---|
| 4039 | + .dealloc_pd = mlx5_ib_dealloc_pd, |
|---|
| 4040 | + .dealloc_ucontext = mlx5_ib_dealloc_ucontext, |
|---|
| 4041 | + .del_gid = mlx5_ib_del_gid, |
|---|
| 4042 | + .dereg_mr = mlx5_ib_dereg_mr, |
|---|
| 4043 | + .destroy_ah = mlx5_ib_destroy_ah, |
|---|
| 4044 | + .destroy_cq = mlx5_ib_destroy_cq, |
|---|
| 4045 | + .destroy_qp = mlx5_ib_destroy_qp, |
|---|
| 4046 | + .destroy_srq = mlx5_ib_destroy_srq, |
|---|
| 4047 | + .detach_mcast = mlx5_ib_mcg_detach, |
|---|
| 4048 | + .disassociate_ucontext = mlx5_ib_disassociate_ucontext, |
|---|
| 4049 | + .drain_rq = mlx5_ib_drain_rq, |
|---|
| 4050 | + .drain_sq = mlx5_ib_drain_sq, |
|---|
| 4051 | + .enable_driver = mlx5_ib_enable_driver, |
|---|
| 4052 | + .get_dev_fw_str = get_dev_fw_str, |
|---|
| 4053 | + .get_dma_mr = mlx5_ib_get_dma_mr, |
|---|
| 4054 | + .get_link_layer = mlx5_ib_port_link_layer, |
|---|
| 4055 | + .map_mr_sg = mlx5_ib_map_mr_sg, |
|---|
| 4056 | + .map_mr_sg_pi = mlx5_ib_map_mr_sg_pi, |
|---|
| 4057 | + .mmap = mlx5_ib_mmap, |
|---|
| 4058 | + .mmap_free = mlx5_ib_mmap_free, |
|---|
| 4059 | + .modify_cq = mlx5_ib_modify_cq, |
|---|
| 4060 | + .modify_device = mlx5_ib_modify_device, |
|---|
| 4061 | + .modify_port = mlx5_ib_modify_port, |
|---|
| 4062 | + .modify_qp = mlx5_ib_modify_qp, |
|---|
| 4063 | + .modify_srq = mlx5_ib_modify_srq, |
|---|
| 4064 | + .poll_cq = mlx5_ib_poll_cq, |
|---|
| 4065 | + .post_recv = mlx5_ib_post_recv_nodrain, |
|---|
| 4066 | + .post_send = mlx5_ib_post_send_nodrain, |
|---|
| 4067 | + .post_srq_recv = mlx5_ib_post_srq_recv, |
|---|
| 4068 | + .process_mad = mlx5_ib_process_mad, |
|---|
| 4069 | + .query_ah = mlx5_ib_query_ah, |
|---|
| 4070 | + .query_device = mlx5_ib_query_device, |
|---|
| 4071 | + .query_gid = mlx5_ib_query_gid, |
|---|
| 4072 | + .query_pkey = mlx5_ib_query_pkey, |
|---|
| 4073 | + .query_qp = mlx5_ib_query_qp, |
|---|
| 4074 | + .query_srq = mlx5_ib_query_srq, |
|---|
| 4075 | + .query_ucontext = mlx5_ib_query_ucontext, |
|---|
| 4076 | + .reg_user_mr = mlx5_ib_reg_user_mr, |
|---|
| 4077 | + .req_notify_cq = mlx5_ib_arm_cq, |
|---|
| 4078 | + .rereg_user_mr = mlx5_ib_rereg_user_mr, |
|---|
| 4079 | + .resize_cq = mlx5_ib_resize_cq, |
|---|
| 4080 | + |
|---|
| 4081 | + INIT_RDMA_OBJ_SIZE(ib_ah, mlx5_ib_ah, ibah), |
|---|
| 4082 | + INIT_RDMA_OBJ_SIZE(ib_counters, mlx5_ib_mcounters, ibcntrs), |
|---|
| 4083 | + INIT_RDMA_OBJ_SIZE(ib_cq, mlx5_ib_cq, ibcq), |
|---|
| 4084 | + INIT_RDMA_OBJ_SIZE(ib_pd, mlx5_ib_pd, ibpd), |
|---|
| 4085 | + INIT_RDMA_OBJ_SIZE(ib_srq, mlx5_ib_srq, ibsrq), |
|---|
| 4086 | + INIT_RDMA_OBJ_SIZE(ib_ucontext, mlx5_ib_ucontext, ibucontext), |
|---|
| 4087 | +}; |
|---|
| 4088 | + |
|---|
| 4089 | +static const struct ib_device_ops mlx5_ib_dev_ipoib_enhanced_ops = { |
|---|
| 4090 | + .rdma_netdev_get_params = mlx5_ib_rn_get_params, |
|---|
| 4091 | +}; |
|---|
| 4092 | + |
|---|
| 4093 | +static const struct ib_device_ops mlx5_ib_dev_sriov_ops = { |
|---|
| 4094 | + .get_vf_config = mlx5_ib_get_vf_config, |
|---|
| 4095 | + .get_vf_guid = mlx5_ib_get_vf_guid, |
|---|
| 4096 | + .get_vf_stats = mlx5_ib_get_vf_stats, |
|---|
| 4097 | + .set_vf_guid = mlx5_ib_set_vf_guid, |
|---|
| 4098 | + .set_vf_link_state = mlx5_ib_set_vf_link_state, |
|---|
| 4099 | +}; |
|---|
| 4100 | + |
|---|
| 4101 | +static const struct ib_device_ops mlx5_ib_dev_mw_ops = { |
|---|
| 4102 | + .alloc_mw = mlx5_ib_alloc_mw, |
|---|
| 4103 | + .dealloc_mw = mlx5_ib_dealloc_mw, |
|---|
| 4104 | + |
|---|
| 4105 | + INIT_RDMA_OBJ_SIZE(ib_mw, mlx5_ib_mw, ibmw), |
|---|
| 4106 | +}; |
|---|
| 4107 | + |
|---|
| 4108 | +static const struct ib_device_ops mlx5_ib_dev_xrc_ops = { |
|---|
| 4109 | + .alloc_xrcd = mlx5_ib_alloc_xrcd, |
|---|
| 4110 | + .dealloc_xrcd = mlx5_ib_dealloc_xrcd, |
|---|
| 4111 | + |
|---|
| 4112 | + INIT_RDMA_OBJ_SIZE(ib_xrcd, mlx5_ib_xrcd, ibxrcd), |
|---|
| 4113 | +}; |
|---|
| 4114 | + |
|---|
| 4115 | +static const struct ib_device_ops mlx5_ib_dev_dm_ops = { |
|---|
| 4116 | + .alloc_dm = mlx5_ib_alloc_dm, |
|---|
| 4117 | + .dealloc_dm = mlx5_ib_dealloc_dm, |
|---|
| 4118 | + .reg_dm_mr = mlx5_ib_reg_dm_mr, |
|---|
| 4119 | +}; |
|---|
| 4120 | + |
|---|
| 4121 | +static int mlx5_ib_init_var_table(struct mlx5_ib_dev *dev) |
|---|
| 4122 | +{ |
|---|
| 4123 | + struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 4124 | + struct mlx5_var_table *var_table = &dev->var_table; |
|---|
| 4125 | + u8 log_doorbell_bar_size; |
|---|
| 4126 | + u8 log_doorbell_stride; |
|---|
| 4127 | + u64 bar_size; |
|---|
| 4128 | + |
|---|
| 4129 | + log_doorbell_bar_size = MLX5_CAP_DEV_VDPA_EMULATION(mdev, |
|---|
| 4130 | + log_doorbell_bar_size); |
|---|
| 4131 | + log_doorbell_stride = MLX5_CAP_DEV_VDPA_EMULATION(mdev, |
|---|
| 4132 | + log_doorbell_stride); |
|---|
| 4133 | + var_table->hw_start_addr = dev->mdev->bar_addr + |
|---|
| 4134 | + MLX5_CAP64_DEV_VDPA_EMULATION(mdev, |
|---|
| 4135 | + doorbell_bar_offset); |
|---|
| 4136 | + bar_size = (1ULL << log_doorbell_bar_size) * 4096; |
|---|
| 4137 | + var_table->stride_size = 1ULL << log_doorbell_stride; |
|---|
| 4138 | + var_table->num_var_hw_entries = div_u64(bar_size, |
|---|
| 4139 | + var_table->stride_size); |
|---|
| 4140 | + mutex_init(&var_table->bitmap_lock); |
|---|
| 4141 | + var_table->bitmap = bitmap_zalloc(var_table->num_var_hw_entries, |
|---|
| 4142 | + GFP_KERNEL); |
|---|
| 4143 | + return (var_table->bitmap) ? 0 : -ENOMEM; |
|---|
| 4144 | +} |
|---|
| 4145 | + |
|---|
| 4146 | +static void mlx5_ib_stage_caps_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 4147 | +{ |
|---|
| 4148 | + bitmap_free(dev->var_table.bitmap); |
|---|
| 4149 | +} |
|---|
| 4150 | + |
|---|
| 4151 | +static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) |
|---|
| 4152 | +{ |
|---|
| 4153 | + struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 4154 | + int err; |
|---|
| 4155 | + |
|---|
| 4156 | + dev->ib_dev.uverbs_cmd_mask = |
|---|
| 4157 | + (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
|---|
| 4158 | + (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
|---|
| 4159 | + (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
|---|
| 4160 | + (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
|---|
| 4161 | + (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
|---|
| 4162 | + (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
|---|
| 4163 | + (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
|---|
| 4164 | + (1ull << IB_USER_VERBS_CMD_REG_MR) | |
|---|
| 4165 | + (1ull << IB_USER_VERBS_CMD_REREG_MR) | |
|---|
| 4166 | + (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
|---|
| 4167 | + (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
|---|
| 4168 | + (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
|---|
| 4169 | + (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
|---|
| 4170 | + (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
|---|
| 4171 | + (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
|---|
| 4172 | + (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
|---|
| 4173 | + (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
|---|
| 4174 | + (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
|---|
| 4175 | + (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
|---|
| 4176 | + (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
|---|
| 4177 | + (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
|---|
| 4178 | + (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
|---|
| 4179 | + (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
|---|
| 4180 | + (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
|---|
| 4181 | + (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
|---|
| 4182 | + (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
|---|
| 4183 | + dev->ib_dev.uverbs_ex_cmd_mask |= |
|---|
| 4184 | + (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | |
|---|
| 4185 | + (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) | |
|---|
| 4186 | + (1ull << IB_USER_VERBS_EX_CMD_MODIFY_QP); |
|---|
| 4187 | + |
|---|
| 4188 | + if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && |
|---|
| 4189 | + IS_ENABLED(CONFIG_MLX5_CORE_IPOIB)) |
|---|
| 4190 | + ib_set_device_ops(&dev->ib_dev, |
|---|
| 4191 | + &mlx5_ib_dev_ipoib_enhanced_ops); |
|---|
| 4192 | + |
|---|
| 4193 | + if (mlx5_core_is_pf(mdev)) |
|---|
| 4194 | + ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_sriov_ops); |
|---|
| 4195 | + |
|---|
| 4196 | + dev->umr_fence = mlx5_get_umr_fence(MLX5_CAP_GEN(mdev, umr_fence)); |
|---|
| 4197 | + |
|---|
| 4198 | + if (MLX5_CAP_GEN(mdev, imaicl)) { |
|---|
| 4199 | + dev->ib_dev.uverbs_cmd_mask |= |
|---|
| 4200 | + (1ull << IB_USER_VERBS_CMD_ALLOC_MW) | |
|---|
| 4201 | + (1ull << IB_USER_VERBS_CMD_DEALLOC_MW); |
|---|
| 4202 | + ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_mw_ops); |
|---|
| 4203 | + } |
|---|
| 4204 | + |
|---|
| 4205 | + if (MLX5_CAP_GEN(mdev, xrc)) { |
|---|
| 4206 | + dev->ib_dev.uverbs_cmd_mask |= |
|---|
| 4207 | + (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
|---|
| 4208 | + (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
|---|
| 4209 | + ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_xrc_ops); |
|---|
| 4210 | + } |
|---|
| 4211 | + |
|---|
| 4212 | + if (MLX5_CAP_DEV_MEM(mdev, memic) || |
|---|
| 4213 | + MLX5_CAP_GEN_64(dev->mdev, general_obj_types) & |
|---|
| 4214 | + MLX5_GENERAL_OBJ_TYPES_CAP_SW_ICM) |
|---|
| 4215 | + ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_dm_ops); |
|---|
| 4216 | + |
|---|
| 4217 | + ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_ops); |
|---|
| 4218 | + |
|---|
| 4219 | + if (IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)) |
|---|
| 4220 | + dev->ib_dev.driver_def = mlx5_ib_defs; |
|---|
| 4221 | + |
|---|
| 4222 | + err = init_node_data(dev); |
|---|
| 4223 | + if (err) |
|---|
| 4224 | + return err; |
|---|
| 4225 | + |
|---|
| 4226 | + if ((MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) && |
|---|
| 4227 | + (MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) || |
|---|
| 4228 | + MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
|---|
| 4229 | + mutex_init(&dev->lb.mutex); |
|---|
| 4230 | + |
|---|
| 4231 | + if (MLX5_CAP_GEN_64(dev->mdev, general_obj_types) & |
|---|
| 4232 | + MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_NET_Q) { |
|---|
| 4233 | + err = mlx5_ib_init_var_table(dev); |
|---|
| 4234 | + if (err) |
|---|
| 4235 | + return err; |
|---|
| 4236 | + } |
|---|
| 4237 | + |
|---|
| 4238 | + dev->ib_dev.use_cq_dim = true; |
|---|
| 4239 | + |
|---|
| 4240 | + return 0; |
|---|
| 4241 | +} |
|---|
| 4242 | + |
|---|
| 4243 | +static const struct ib_device_ops mlx5_ib_dev_port_ops = { |
|---|
| 4244 | + .get_port_immutable = mlx5_port_immutable, |
|---|
| 4245 | + .query_port = mlx5_ib_query_port, |
|---|
| 4246 | +}; |
|---|
| 4247 | + |
|---|
| 4248 | +static int mlx5_ib_stage_non_default_cb(struct mlx5_ib_dev *dev) |
|---|
| 4249 | +{ |
|---|
| 4250 | + ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_port_ops); |
|---|
| 4251 | + return 0; |
|---|
| 4252 | +} |
|---|
| 4253 | + |
|---|
| 4254 | +static const struct ib_device_ops mlx5_ib_dev_port_rep_ops = { |
|---|
| 4255 | + .get_port_immutable = mlx5_port_rep_immutable, |
|---|
| 4256 | + .query_port = mlx5_ib_rep_query_port, |
|---|
| 4257 | +}; |
|---|
| 4258 | + |
|---|
| 4259 | +static int mlx5_ib_stage_raw_eth_non_default_cb(struct mlx5_ib_dev *dev) |
|---|
| 4260 | +{ |
|---|
| 4261 | + ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_port_rep_ops); |
|---|
| 4262 | + return 0; |
|---|
| 4263 | +} |
|---|
| 4264 | + |
|---|
| 4265 | +static const struct ib_device_ops mlx5_ib_dev_common_roce_ops = { |
|---|
| 4266 | + .create_rwq_ind_table = mlx5_ib_create_rwq_ind_table, |
|---|
| 4267 | + .create_wq = mlx5_ib_create_wq, |
|---|
| 4268 | + .destroy_rwq_ind_table = mlx5_ib_destroy_rwq_ind_table, |
|---|
| 4269 | + .destroy_wq = mlx5_ib_destroy_wq, |
|---|
| 4270 | + .get_netdev = mlx5_ib_get_netdev, |
|---|
| 4271 | + .modify_wq = mlx5_ib_modify_wq, |
|---|
| 4272 | + |
|---|
| 4273 | + INIT_RDMA_OBJ_SIZE(ib_rwq_ind_table, mlx5_ib_rwq_ind_table, |
|---|
| 4274 | + ib_rwq_ind_tbl), |
|---|
| 4275 | +}; |
|---|
| 4276 | + |
|---|
| 4277 | +static int mlx5_ib_roce_init(struct mlx5_ib_dev *dev) |
|---|
| 4278 | +{ |
|---|
| 4279 | + struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 4280 | + enum rdma_link_layer ll; |
|---|
| 4281 | + int port_type_cap; |
|---|
| 4282 | + u8 port_num = 0; |
|---|
| 4283 | + int err; |
|---|
| 4284 | + |
|---|
| 4285 | + port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
|---|
| 4286 | + ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
|---|
| 4287 | + |
|---|
| 4288 | + if (ll == IB_LINK_LAYER_ETHERNET) { |
|---|
| 4289 | + ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_common_roce_ops); |
|---|
| 4290 | + |
|---|
| 4291 | + port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
|---|
| 4292 | + |
|---|
| 4293 | + /* Register only for native ports */ |
|---|
| 4294 | + err = mlx5_add_netdev_notifier(dev, port_num); |
|---|
| 4295 | + if (err || dev->is_rep || !mlx5_is_roce_enabled(mdev)) |
|---|
| 4296 | + /* |
|---|
| 4297 | + * We don't enable ETH interface for |
|---|
| 4298 | + * 1. IB representors |
|---|
| 4299 | + * 2. User disabled ROCE through devlink interface |
|---|
| 4300 | + */ |
|---|
| 4301 | + return err; |
|---|
| 4302 | + |
|---|
| 4303 | + err = mlx5_enable_eth(dev); |
|---|
| 4304 | + if (err) |
|---|
| 4305 | + goto cleanup; |
|---|
| 4306 | + } |
|---|
| 4307 | + |
|---|
| 4308 | + return 0; |
|---|
| 4309 | +cleanup: |
|---|
| 4310 | + mlx5_remove_netdev_notifier(dev, port_num); |
|---|
| 4311 | + return err; |
|---|
| 4312 | +} |
|---|
| 4313 | + |
|---|
| 4314 | +static void mlx5_ib_roce_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 4315 | +{ |
|---|
| 4316 | + struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 4317 | + enum rdma_link_layer ll; |
|---|
| 4318 | + int port_type_cap; |
|---|
| 4319 | + u8 port_num; |
|---|
| 4320 | + |
|---|
| 4321 | + port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
|---|
| 4322 | + ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
|---|
| 4323 | + |
|---|
| 4324 | + if (ll == IB_LINK_LAYER_ETHERNET) { |
|---|
| 4325 | + if (!dev->is_rep) |
|---|
| 4326 | + mlx5_disable_eth(dev); |
|---|
| 4327 | + |
|---|
| 4328 | + port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
|---|
| 4329 | + mlx5_remove_netdev_notifier(dev, port_num); |
|---|
| 4330 | + } |
|---|
| 4331 | +} |
|---|
| 4332 | + |
|---|
| 4333 | +static int mlx5_ib_stage_cong_debugfs_init(struct mlx5_ib_dev *dev) |
|---|
| 4334 | +{ |
|---|
| 4335 | + mlx5_ib_init_cong_debugfs(dev, |
|---|
| 4336 | + mlx5_core_native_port_num(dev->mdev) - 1); |
|---|
| 4337 | + return 0; |
|---|
| 4338 | +} |
|---|
| 4339 | + |
|---|
| 4340 | +static void mlx5_ib_stage_cong_debugfs_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 4341 | +{ |
|---|
| 4342 | + mlx5_ib_cleanup_cong_debugfs(dev, |
|---|
| 4343 | + mlx5_core_native_port_num(dev->mdev) - 1); |
|---|
| 4344 | +} |
|---|
| 4345 | + |
|---|
| 4346 | +static int mlx5_ib_stage_uar_init(struct mlx5_ib_dev *dev) |
|---|
| 4347 | +{ |
|---|
| 4348 | + dev->mdev->priv.uar = mlx5_get_uars_page(dev->mdev); |
|---|
| 4349 | + return PTR_ERR_OR_ZERO(dev->mdev->priv.uar); |
|---|
| 4350 | +} |
|---|
| 4351 | + |
|---|
| 4352 | +static void mlx5_ib_stage_uar_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 4353 | +{ |
|---|
| 4354 | + mlx5_put_uars_page(dev->mdev, dev->mdev->priv.uar); |
|---|
| 4355 | +} |
|---|
| 4356 | + |
|---|
| 4357 | +static int mlx5_ib_stage_bfrag_init(struct mlx5_ib_dev *dev) |
|---|
| 4358 | +{ |
|---|
| 4359 | + int err; |
|---|
| 4360 | + |
|---|
| 4361 | + err = mlx5_alloc_bfreg(dev->mdev, &dev->bfreg, false, false); |
|---|
| 4362 | + if (err) |
|---|
| 4363 | + return err; |
|---|
| 4364 | + |
|---|
| 4365 | + err = mlx5_alloc_bfreg(dev->mdev, &dev->fp_bfreg, false, true); |
|---|
| 4366 | + if (err) |
|---|
| 4367 | + mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
|---|
| 4368 | + |
|---|
| 4369 | + return err; |
|---|
| 4370 | +} |
|---|
| 4371 | + |
|---|
| 4372 | +static void mlx5_ib_stage_bfrag_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 4373 | +{ |
|---|
| 4374 | + mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
|---|
| 4375 | + mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
|---|
| 4376 | +} |
|---|
| 4377 | + |
|---|
| 4378 | +static int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev) |
|---|
| 4379 | +{ |
|---|
| 4380 | + const char *name; |
|---|
| 4381 | + |
|---|
| 4382 | + rdma_set_device_sysfs_group(&dev->ib_dev, &mlx5_attr_group); |
|---|
| 4383 | + if (!mlx5_lag_is_roce(dev->mdev)) |
|---|
| 4384 | + name = "mlx5_%d"; |
|---|
| 4385 | + else |
|---|
| 4386 | + name = "mlx5_bond_%d"; |
|---|
| 4387 | + return ib_register_device(&dev->ib_dev, name, &dev->mdev->pdev->dev); |
|---|
| 4388 | +} |
|---|
| 4389 | + |
|---|
| 4390 | +static void mlx5_ib_stage_pre_ib_reg_umr_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 4405 | 4391 | { |
|---|
| 4406 | 4392 | int err; |
|---|
| 4407 | 4393 | |
|---|
| .. | .. |
|---|
| 4410 | 4396 | mlx5_ib_warn(dev, "mr cache cleanup failed\n"); |
|---|
| 4411 | 4397 | |
|---|
| 4412 | 4398 | if (dev->umrc.qp) |
|---|
| 4413 | | - mlx5_ib_destroy_qp(dev->umrc.qp); |
|---|
| 4399 | + mlx5_ib_destroy_qp(dev->umrc.qp, NULL); |
|---|
| 4414 | 4400 | if (dev->umrc.cq) |
|---|
| 4415 | 4401 | ib_free_cq(dev->umrc.cq); |
|---|
| 4416 | 4402 | if (dev->umrc.pd) |
|---|
| 4417 | 4403 | ib_dealloc_pd(dev->umrc.pd); |
|---|
| 4418 | 4404 | } |
|---|
| 4419 | 4405 | |
|---|
| 4406 | +static void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 4407 | +{ |
|---|
| 4408 | + ib_unregister_device(&dev->ib_dev); |
|---|
| 4409 | +} |
|---|
| 4410 | + |
|---|
| 4420 | 4411 | enum { |
|---|
| 4421 | 4412 | MAX_UMR_WR = 128, |
|---|
| 4422 | 4413 | }; |
|---|
| 4423 | 4414 | |
|---|
| 4424 | | -static int create_umr_res(struct mlx5_ib_dev *dev) |
|---|
| 4415 | +static int mlx5_ib_stage_post_ib_reg_umr_init(struct mlx5_ib_dev *dev) |
|---|
| 4425 | 4416 | { |
|---|
| 4426 | 4417 | struct ib_qp_init_attr *init_attr = NULL; |
|---|
| 4427 | 4418 | struct ib_qp_attr *attr = NULL; |
|---|
| .. | .. |
|---|
| 4515 | 4506 | return 0; |
|---|
| 4516 | 4507 | |
|---|
| 4517 | 4508 | error_4: |
|---|
| 4518 | | - mlx5_ib_destroy_qp(qp); |
|---|
| 4509 | + mlx5_ib_destroy_qp(qp, NULL); |
|---|
| 4519 | 4510 | dev->umrc.qp = NULL; |
|---|
| 4520 | 4511 | |
|---|
| 4521 | 4512 | error_3: |
|---|
| .. | .. |
|---|
| 4532 | 4523 | return ret; |
|---|
| 4533 | 4524 | } |
|---|
| 4534 | 4525 | |
|---|
| 4535 | | -static u8 mlx5_get_umr_fence(u8 umr_fence_cap) |
|---|
| 4526 | +static int mlx5_ib_stage_delay_drop_init(struct mlx5_ib_dev *dev) |
|---|
| 4536 | 4527 | { |
|---|
| 4537 | | - switch (umr_fence_cap) { |
|---|
| 4538 | | - case MLX5_CAP_UMR_FENCE_NONE: |
|---|
| 4539 | | - return MLX5_FENCE_MODE_NONE; |
|---|
| 4540 | | - case MLX5_CAP_UMR_FENCE_SMALL: |
|---|
| 4541 | | - return MLX5_FENCE_MODE_INITIATOR_SMALL; |
|---|
| 4542 | | - default: |
|---|
| 4543 | | - return MLX5_FENCE_MODE_STRONG_ORDERING; |
|---|
| 4544 | | - } |
|---|
| 4545 | | -} |
|---|
| 4546 | | - |
|---|
| 4547 | | -static int create_dev_resources(struct mlx5_ib_resources *devr) |
|---|
| 4548 | | -{ |
|---|
| 4549 | | - struct ib_srq_init_attr attr; |
|---|
| 4550 | | - struct mlx5_ib_dev *dev; |
|---|
| 4551 | | - struct ib_cq_init_attr cq_attr = {.cqe = 1}; |
|---|
| 4552 | | - int port; |
|---|
| 4553 | | - int ret = 0; |
|---|
| 4554 | | - |
|---|
| 4555 | | - dev = container_of(devr, struct mlx5_ib_dev, devr); |
|---|
| 4556 | | - |
|---|
| 4557 | | - mutex_init(&devr->mutex); |
|---|
| 4558 | | - |
|---|
| 4559 | | - devr->p0 = mlx5_ib_alloc_pd(&dev->ib_dev, NULL, NULL); |
|---|
| 4560 | | - if (IS_ERR(devr->p0)) { |
|---|
| 4561 | | - ret = PTR_ERR(devr->p0); |
|---|
| 4562 | | - goto error0; |
|---|
| 4563 | | - } |
|---|
| 4564 | | - devr->p0->device = &dev->ib_dev; |
|---|
| 4565 | | - devr->p0->uobject = NULL; |
|---|
| 4566 | | - atomic_set(&devr->p0->usecnt, 0); |
|---|
| 4567 | | - |
|---|
| 4568 | | - devr->c0 = mlx5_ib_create_cq(&dev->ib_dev, &cq_attr, NULL, NULL); |
|---|
| 4569 | | - if (IS_ERR(devr->c0)) { |
|---|
| 4570 | | - ret = PTR_ERR(devr->c0); |
|---|
| 4571 | | - goto error1; |
|---|
| 4572 | | - } |
|---|
| 4573 | | - devr->c0->device = &dev->ib_dev; |
|---|
| 4574 | | - devr->c0->uobject = NULL; |
|---|
| 4575 | | - devr->c0->comp_handler = NULL; |
|---|
| 4576 | | - devr->c0->event_handler = NULL; |
|---|
| 4577 | | - devr->c0->cq_context = NULL; |
|---|
| 4578 | | - atomic_set(&devr->c0->usecnt, 0); |
|---|
| 4579 | | - |
|---|
| 4580 | | - devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
|---|
| 4581 | | - if (IS_ERR(devr->x0)) { |
|---|
| 4582 | | - ret = PTR_ERR(devr->x0); |
|---|
| 4583 | | - goto error2; |
|---|
| 4584 | | - } |
|---|
| 4585 | | - devr->x0->device = &dev->ib_dev; |
|---|
| 4586 | | - devr->x0->inode = NULL; |
|---|
| 4587 | | - atomic_set(&devr->x0->usecnt, 0); |
|---|
| 4588 | | - mutex_init(&devr->x0->tgt_qp_mutex); |
|---|
| 4589 | | - INIT_LIST_HEAD(&devr->x0->tgt_qp_list); |
|---|
| 4590 | | - |
|---|
| 4591 | | - devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL); |
|---|
| 4592 | | - if (IS_ERR(devr->x1)) { |
|---|
| 4593 | | - ret = PTR_ERR(devr->x1); |
|---|
| 4594 | | - goto error3; |
|---|
| 4595 | | - } |
|---|
| 4596 | | - devr->x1->device = &dev->ib_dev; |
|---|
| 4597 | | - devr->x1->inode = NULL; |
|---|
| 4598 | | - atomic_set(&devr->x1->usecnt, 0); |
|---|
| 4599 | | - mutex_init(&devr->x1->tgt_qp_mutex); |
|---|
| 4600 | | - INIT_LIST_HEAD(&devr->x1->tgt_qp_list); |
|---|
| 4601 | | - |
|---|
| 4602 | | - memset(&attr, 0, sizeof(attr)); |
|---|
| 4603 | | - attr.attr.max_sge = 1; |
|---|
| 4604 | | - attr.attr.max_wr = 1; |
|---|
| 4605 | | - attr.srq_type = IB_SRQT_XRC; |
|---|
| 4606 | | - attr.ext.cq = devr->c0; |
|---|
| 4607 | | - attr.ext.xrc.xrcd = devr->x0; |
|---|
| 4608 | | - |
|---|
| 4609 | | - devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
|---|
| 4610 | | - if (IS_ERR(devr->s0)) { |
|---|
| 4611 | | - ret = PTR_ERR(devr->s0); |
|---|
| 4612 | | - goto error4; |
|---|
| 4613 | | - } |
|---|
| 4614 | | - devr->s0->device = &dev->ib_dev; |
|---|
| 4615 | | - devr->s0->pd = devr->p0; |
|---|
| 4616 | | - devr->s0->uobject = NULL; |
|---|
| 4617 | | - devr->s0->event_handler = NULL; |
|---|
| 4618 | | - devr->s0->srq_context = NULL; |
|---|
| 4619 | | - devr->s0->srq_type = IB_SRQT_XRC; |
|---|
| 4620 | | - devr->s0->ext.xrc.xrcd = devr->x0; |
|---|
| 4621 | | - devr->s0->ext.cq = devr->c0; |
|---|
| 4622 | | - atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); |
|---|
| 4623 | | - atomic_inc(&devr->s0->ext.cq->usecnt); |
|---|
| 4624 | | - atomic_inc(&devr->p0->usecnt); |
|---|
| 4625 | | - atomic_set(&devr->s0->usecnt, 0); |
|---|
| 4626 | | - |
|---|
| 4627 | | - memset(&attr, 0, sizeof(attr)); |
|---|
| 4628 | | - attr.attr.max_sge = 1; |
|---|
| 4629 | | - attr.attr.max_wr = 1; |
|---|
| 4630 | | - attr.srq_type = IB_SRQT_BASIC; |
|---|
| 4631 | | - devr->s1 = mlx5_ib_create_srq(devr->p0, &attr, NULL); |
|---|
| 4632 | | - if (IS_ERR(devr->s1)) { |
|---|
| 4633 | | - ret = PTR_ERR(devr->s1); |
|---|
| 4634 | | - goto error5; |
|---|
| 4635 | | - } |
|---|
| 4636 | | - devr->s1->device = &dev->ib_dev; |
|---|
| 4637 | | - devr->s1->pd = devr->p0; |
|---|
| 4638 | | - devr->s1->uobject = NULL; |
|---|
| 4639 | | - devr->s1->event_handler = NULL; |
|---|
| 4640 | | - devr->s1->srq_context = NULL; |
|---|
| 4641 | | - devr->s1->srq_type = IB_SRQT_BASIC; |
|---|
| 4642 | | - devr->s1->ext.cq = devr->c0; |
|---|
| 4643 | | - atomic_inc(&devr->p0->usecnt); |
|---|
| 4644 | | - atomic_set(&devr->s1->usecnt, 0); |
|---|
| 4645 | | - |
|---|
| 4646 | | - for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) { |
|---|
| 4647 | | - INIT_WORK(&devr->ports[port].pkey_change_work, |
|---|
| 4648 | | - pkey_change_handler); |
|---|
| 4649 | | - devr->ports[port].devr = devr; |
|---|
| 4650 | | - } |
|---|
| 4651 | | - |
|---|
| 4652 | | - return 0; |
|---|
| 4653 | | - |
|---|
| 4654 | | -error5: |
|---|
| 4655 | | - mlx5_ib_destroy_srq(devr->s0); |
|---|
| 4656 | | -error4: |
|---|
| 4657 | | - mlx5_ib_dealloc_xrcd(devr->x1); |
|---|
| 4658 | | -error3: |
|---|
| 4659 | | - mlx5_ib_dealloc_xrcd(devr->x0); |
|---|
| 4660 | | -error2: |
|---|
| 4661 | | - mlx5_ib_destroy_cq(devr->c0); |
|---|
| 4662 | | -error1: |
|---|
| 4663 | | - mlx5_ib_dealloc_pd(devr->p0); |
|---|
| 4664 | | -error0: |
|---|
| 4665 | | - return ret; |
|---|
| 4666 | | -} |
|---|
| 4667 | | - |
|---|
| 4668 | | -static void destroy_dev_resources(struct mlx5_ib_resources *devr) |
|---|
| 4669 | | -{ |
|---|
| 4670 | | - struct mlx5_ib_dev *dev = |
|---|
| 4671 | | - container_of(devr, struct mlx5_ib_dev, devr); |
|---|
| 4672 | | - int port; |
|---|
| 4673 | | - |
|---|
| 4674 | | - mlx5_ib_destroy_srq(devr->s1); |
|---|
| 4675 | | - mlx5_ib_destroy_srq(devr->s0); |
|---|
| 4676 | | - mlx5_ib_dealloc_xrcd(devr->x0); |
|---|
| 4677 | | - mlx5_ib_dealloc_xrcd(devr->x1); |
|---|
| 4678 | | - mlx5_ib_destroy_cq(devr->c0); |
|---|
| 4679 | | - mlx5_ib_dealloc_pd(devr->p0); |
|---|
| 4680 | | - |
|---|
| 4681 | | - /* Make sure no change P_Key work items are still executing */ |
|---|
| 4682 | | - for (port = 0; port < dev->num_ports; ++port) |
|---|
| 4683 | | - cancel_work_sync(&devr->ports[port].pkey_change_work); |
|---|
| 4684 | | -} |
|---|
| 4685 | | - |
|---|
| 4686 | | -static u32 get_core_cap_flags(struct ib_device *ibdev, |
|---|
| 4687 | | - struct mlx5_hca_vport_context *rep) |
|---|
| 4688 | | -{ |
|---|
| 4689 | | - struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 4690 | | - enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, 1); |
|---|
| 4691 | | - u8 l3_type_cap = MLX5_CAP_ROCE(dev->mdev, l3_type); |
|---|
| 4692 | | - u8 roce_version_cap = MLX5_CAP_ROCE(dev->mdev, roce_version); |
|---|
| 4693 | | - bool raw_support = !mlx5_core_mp_enabled(dev->mdev); |
|---|
| 4694 | | - u32 ret = 0; |
|---|
| 4695 | | - |
|---|
| 4696 | | - if (rep->grh_required) |
|---|
| 4697 | | - ret |= RDMA_CORE_CAP_IB_GRH_REQUIRED; |
|---|
| 4698 | | - |
|---|
| 4699 | | - if (ll == IB_LINK_LAYER_INFINIBAND) |
|---|
| 4700 | | - return ret | RDMA_CORE_PORT_IBA_IB; |
|---|
| 4701 | | - |
|---|
| 4702 | | - if (raw_support) |
|---|
| 4703 | | - ret |= RDMA_CORE_PORT_RAW_PACKET; |
|---|
| 4704 | | - |
|---|
| 4705 | | - if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV4_CAP)) |
|---|
| 4706 | | - return ret; |
|---|
| 4707 | | - |
|---|
| 4708 | | - if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV6_CAP)) |
|---|
| 4709 | | - return ret; |
|---|
| 4710 | | - |
|---|
| 4711 | | - if (roce_version_cap & MLX5_ROCE_VERSION_1_CAP) |
|---|
| 4712 | | - ret |= RDMA_CORE_PORT_IBA_ROCE; |
|---|
| 4713 | | - |
|---|
| 4714 | | - if (roce_version_cap & MLX5_ROCE_VERSION_2_CAP) |
|---|
| 4715 | | - ret |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; |
|---|
| 4716 | | - |
|---|
| 4717 | | - return ret; |
|---|
| 4718 | | -} |
|---|
| 4719 | | - |
|---|
| 4720 | | -static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num, |
|---|
| 4721 | | - struct ib_port_immutable *immutable) |
|---|
| 4722 | | -{ |
|---|
| 4723 | | - struct ib_port_attr attr; |
|---|
| 4724 | | - struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 4725 | | - enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, port_num); |
|---|
| 4726 | | - struct mlx5_hca_vport_context rep = {0}; |
|---|
| 4727 | | - int err; |
|---|
| 4728 | | - |
|---|
| 4729 | | - err = ib_query_port(ibdev, port_num, &attr); |
|---|
| 4730 | | - if (err) |
|---|
| 4731 | | - return err; |
|---|
| 4732 | | - |
|---|
| 4733 | | - if (ll == IB_LINK_LAYER_INFINIBAND) { |
|---|
| 4734 | | - err = mlx5_query_hca_vport_context(dev->mdev, 0, port_num, 0, |
|---|
| 4735 | | - &rep); |
|---|
| 4736 | | - if (err) |
|---|
| 4737 | | - return err; |
|---|
| 4738 | | - } |
|---|
| 4739 | | - |
|---|
| 4740 | | - immutable->pkey_tbl_len = attr.pkey_tbl_len; |
|---|
| 4741 | | - immutable->gid_tbl_len = attr.gid_tbl_len; |
|---|
| 4742 | | - immutable->core_cap_flags = get_core_cap_flags(ibdev, &rep); |
|---|
| 4743 | | - if ((ll == IB_LINK_LAYER_INFINIBAND) || MLX5_CAP_GEN(dev->mdev, roce)) |
|---|
| 4744 | | - immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
|---|
| 4745 | | - |
|---|
| 4746 | | - return 0; |
|---|
| 4747 | | -} |
|---|
| 4748 | | - |
|---|
| 4749 | | -static int mlx5_port_rep_immutable(struct ib_device *ibdev, u8 port_num, |
|---|
| 4750 | | - struct ib_port_immutable *immutable) |
|---|
| 4751 | | -{ |
|---|
| 4752 | | - struct ib_port_attr attr; |
|---|
| 4753 | | - int err; |
|---|
| 4754 | | - |
|---|
| 4755 | | - immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
|---|
| 4756 | | - |
|---|
| 4757 | | - err = ib_query_port(ibdev, port_num, &attr); |
|---|
| 4758 | | - if (err) |
|---|
| 4759 | | - return err; |
|---|
| 4760 | | - |
|---|
| 4761 | | - immutable->pkey_tbl_len = attr.pkey_tbl_len; |
|---|
| 4762 | | - immutable->gid_tbl_len = attr.gid_tbl_len; |
|---|
| 4763 | | - immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET; |
|---|
| 4764 | | - |
|---|
| 4765 | | - return 0; |
|---|
| 4766 | | -} |
|---|
| 4767 | | - |
|---|
| 4768 | | -static void get_dev_fw_str(struct ib_device *ibdev, char *str) |
|---|
| 4769 | | -{ |
|---|
| 4770 | | - struct mlx5_ib_dev *dev = |
|---|
| 4771 | | - container_of(ibdev, struct mlx5_ib_dev, ib_dev); |
|---|
| 4772 | | - snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%04d", |
|---|
| 4773 | | - fw_rev_maj(dev->mdev), fw_rev_min(dev->mdev), |
|---|
| 4774 | | - fw_rev_sub(dev->mdev)); |
|---|
| 4775 | | -} |
|---|
| 4776 | | - |
|---|
| 4777 | | -static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev) |
|---|
| 4778 | | -{ |
|---|
| 4779 | | - struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 4780 | | - struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(mdev, |
|---|
| 4781 | | - MLX5_FLOW_NAMESPACE_LAG); |
|---|
| 4782 | | - struct mlx5_flow_table *ft; |
|---|
| 4783 | | - int err; |
|---|
| 4784 | | - |
|---|
| 4785 | | - if (!ns || !mlx5_lag_is_active(mdev)) |
|---|
| 4786 | | - return 0; |
|---|
| 4787 | | - |
|---|
| 4788 | | - err = mlx5_cmd_create_vport_lag(mdev); |
|---|
| 4789 | | - if (err) |
|---|
| 4790 | | - return err; |
|---|
| 4791 | | - |
|---|
| 4792 | | - ft = mlx5_create_lag_demux_flow_table(ns, 0, 0); |
|---|
| 4793 | | - if (IS_ERR(ft)) { |
|---|
| 4794 | | - err = PTR_ERR(ft); |
|---|
| 4795 | | - goto err_destroy_vport_lag; |
|---|
| 4796 | | - } |
|---|
| 4797 | | - |
|---|
| 4798 | | - dev->flow_db->lag_demux_ft = ft; |
|---|
| 4799 | | - return 0; |
|---|
| 4800 | | - |
|---|
| 4801 | | -err_destroy_vport_lag: |
|---|
| 4802 | | - mlx5_cmd_destroy_vport_lag(mdev); |
|---|
| 4803 | | - return err; |
|---|
| 4804 | | -} |
|---|
| 4805 | | - |
|---|
| 4806 | | -static void mlx5_eth_lag_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 4807 | | -{ |
|---|
| 4808 | | - struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 4809 | | - |
|---|
| 4810 | | - if (dev->flow_db->lag_demux_ft) { |
|---|
| 4811 | | - mlx5_destroy_flow_table(dev->flow_db->lag_demux_ft); |
|---|
| 4812 | | - dev->flow_db->lag_demux_ft = NULL; |
|---|
| 4813 | | - |
|---|
| 4814 | | - mlx5_cmd_destroy_vport_lag(mdev); |
|---|
| 4815 | | - } |
|---|
| 4816 | | -} |
|---|
| 4817 | | - |
|---|
| 4818 | | -static int mlx5_add_netdev_notifier(struct mlx5_ib_dev *dev, u8 port_num) |
|---|
| 4819 | | -{ |
|---|
| 4820 | | - int err; |
|---|
| 4821 | | - |
|---|
| 4822 | | - dev->roce[port_num].nb.notifier_call = mlx5_netdev_event; |
|---|
| 4823 | | - err = register_netdevice_notifier(&dev->roce[port_num].nb); |
|---|
| 4824 | | - if (err) { |
|---|
| 4825 | | - dev->roce[port_num].nb.notifier_call = NULL; |
|---|
| 4826 | | - return err; |
|---|
| 4827 | | - } |
|---|
| 4828 | | - |
|---|
| 4829 | | - return 0; |
|---|
| 4830 | | -} |
|---|
| 4831 | | - |
|---|
| 4832 | | -static void mlx5_remove_netdev_notifier(struct mlx5_ib_dev *dev, u8 port_num) |
|---|
| 4833 | | -{ |
|---|
| 4834 | | - if (dev->roce[port_num].nb.notifier_call) { |
|---|
| 4835 | | - unregister_netdevice_notifier(&dev->roce[port_num].nb); |
|---|
| 4836 | | - dev->roce[port_num].nb.notifier_call = NULL; |
|---|
| 4837 | | - } |
|---|
| 4838 | | -} |
|---|
| 4839 | | - |
|---|
| 4840 | | -static int mlx5_enable_eth(struct mlx5_ib_dev *dev) |
|---|
| 4841 | | -{ |
|---|
| 4842 | | - int err; |
|---|
| 4843 | | - |
|---|
| 4844 | | - if (MLX5_CAP_GEN(dev->mdev, roce)) { |
|---|
| 4845 | | - err = mlx5_nic_vport_enable_roce(dev->mdev); |
|---|
| 4846 | | - if (err) |
|---|
| 4847 | | - return err; |
|---|
| 4848 | | - } |
|---|
| 4849 | | - |
|---|
| 4850 | | - err = mlx5_eth_lag_init(dev); |
|---|
| 4851 | | - if (err) |
|---|
| 4852 | | - goto err_disable_roce; |
|---|
| 4853 | | - |
|---|
| 4854 | | - return 0; |
|---|
| 4855 | | - |
|---|
| 4856 | | -err_disable_roce: |
|---|
| 4857 | | - if (MLX5_CAP_GEN(dev->mdev, roce)) |
|---|
| 4858 | | - mlx5_nic_vport_disable_roce(dev->mdev); |
|---|
| 4859 | | - |
|---|
| 4860 | | - return err; |
|---|
| 4861 | | -} |
|---|
| 4862 | | - |
|---|
| 4863 | | -static void mlx5_disable_eth(struct mlx5_ib_dev *dev) |
|---|
| 4864 | | -{ |
|---|
| 4865 | | - mlx5_eth_lag_cleanup(dev); |
|---|
| 4866 | | - if (MLX5_CAP_GEN(dev->mdev, roce)) |
|---|
| 4867 | | - mlx5_nic_vport_disable_roce(dev->mdev); |
|---|
| 4868 | | -} |
|---|
| 4869 | | - |
|---|
| 4870 | | -struct mlx5_ib_counter { |
|---|
| 4871 | | - const char *name; |
|---|
| 4872 | | - size_t offset; |
|---|
| 4873 | | -}; |
|---|
| 4874 | | - |
|---|
| 4875 | | -#define INIT_Q_COUNTER(_name) \ |
|---|
| 4876 | | - { .name = #_name, .offset = MLX5_BYTE_OFF(query_q_counter_out, _name)} |
|---|
| 4877 | | - |
|---|
| 4878 | | -static const struct mlx5_ib_counter basic_q_cnts[] = { |
|---|
| 4879 | | - INIT_Q_COUNTER(rx_write_requests), |
|---|
| 4880 | | - INIT_Q_COUNTER(rx_read_requests), |
|---|
| 4881 | | - INIT_Q_COUNTER(rx_atomic_requests), |
|---|
| 4882 | | - INIT_Q_COUNTER(out_of_buffer), |
|---|
| 4883 | | -}; |
|---|
| 4884 | | - |
|---|
| 4885 | | -static const struct mlx5_ib_counter out_of_seq_q_cnts[] = { |
|---|
| 4886 | | - INIT_Q_COUNTER(out_of_sequence), |
|---|
| 4887 | | -}; |
|---|
| 4888 | | - |
|---|
| 4889 | | -static const struct mlx5_ib_counter retrans_q_cnts[] = { |
|---|
| 4890 | | - INIT_Q_COUNTER(duplicate_request), |
|---|
| 4891 | | - INIT_Q_COUNTER(rnr_nak_retry_err), |
|---|
| 4892 | | - INIT_Q_COUNTER(packet_seq_err), |
|---|
| 4893 | | - INIT_Q_COUNTER(implied_nak_seq_err), |
|---|
| 4894 | | - INIT_Q_COUNTER(local_ack_timeout_err), |
|---|
| 4895 | | -}; |
|---|
| 4896 | | - |
|---|
| 4897 | | -#define INIT_CONG_COUNTER(_name) \ |
|---|
| 4898 | | - { .name = #_name, .offset = \ |
|---|
| 4899 | | - MLX5_BYTE_OFF(query_cong_statistics_out, _name ## _high)} |
|---|
| 4900 | | - |
|---|
| 4901 | | -static const struct mlx5_ib_counter cong_cnts[] = { |
|---|
| 4902 | | - INIT_CONG_COUNTER(rp_cnp_ignored), |
|---|
| 4903 | | - INIT_CONG_COUNTER(rp_cnp_handled), |
|---|
| 4904 | | - INIT_CONG_COUNTER(np_ecn_marked_roce_packets), |
|---|
| 4905 | | - INIT_CONG_COUNTER(np_cnp_sent), |
|---|
| 4906 | | -}; |
|---|
| 4907 | | - |
|---|
| 4908 | | -static const struct mlx5_ib_counter extended_err_cnts[] = { |
|---|
| 4909 | | - INIT_Q_COUNTER(resp_local_length_error), |
|---|
| 4910 | | - INIT_Q_COUNTER(resp_cqe_error), |
|---|
| 4911 | | - INIT_Q_COUNTER(req_cqe_error), |
|---|
| 4912 | | - INIT_Q_COUNTER(req_remote_invalid_request), |
|---|
| 4913 | | - INIT_Q_COUNTER(req_remote_access_errors), |
|---|
| 4914 | | - INIT_Q_COUNTER(resp_remote_access_errors), |
|---|
| 4915 | | - INIT_Q_COUNTER(resp_cqe_flush_error), |
|---|
| 4916 | | - INIT_Q_COUNTER(req_cqe_flush_error), |
|---|
| 4917 | | -}; |
|---|
| 4918 | | - |
|---|
| 4919 | | -#define INIT_EXT_PPCNT_COUNTER(_name) \ |
|---|
| 4920 | | - { .name = #_name, .offset = \ |
|---|
| 4921 | | - MLX5_BYTE_OFF(ppcnt_reg, \ |
|---|
| 4922 | | - counter_set.eth_extended_cntrs_grp_data_layout._name##_high)} |
|---|
| 4923 | | - |
|---|
| 4924 | | -static const struct mlx5_ib_counter ext_ppcnt_cnts[] = { |
|---|
| 4925 | | - INIT_EXT_PPCNT_COUNTER(rx_icrc_encapsulated), |
|---|
| 4926 | | -}; |
|---|
| 4927 | | - |
|---|
| 4928 | | -static void mlx5_ib_dealloc_counters(struct mlx5_ib_dev *dev) |
|---|
| 4929 | | -{ |
|---|
| 4930 | | - int i; |
|---|
| 4931 | | - |
|---|
| 4932 | | - for (i = 0; i < dev->num_ports; i++) { |
|---|
| 4933 | | - if (dev->port[i].cnts.set_id_valid) |
|---|
| 4934 | | - mlx5_core_dealloc_q_counter(dev->mdev, |
|---|
| 4935 | | - dev->port[i].cnts.set_id); |
|---|
| 4936 | | - kfree(dev->port[i].cnts.names); |
|---|
| 4937 | | - kfree(dev->port[i].cnts.offsets); |
|---|
| 4938 | | - } |
|---|
| 4939 | | -} |
|---|
| 4940 | | - |
|---|
| 4941 | | -static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev, |
|---|
| 4942 | | - struct mlx5_ib_counters *cnts) |
|---|
| 4943 | | -{ |
|---|
| 4944 | | - u32 num_counters; |
|---|
| 4945 | | - |
|---|
| 4946 | | - num_counters = ARRAY_SIZE(basic_q_cnts); |
|---|
| 4947 | | - |
|---|
| 4948 | | - if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) |
|---|
| 4949 | | - num_counters += ARRAY_SIZE(out_of_seq_q_cnts); |
|---|
| 4950 | | - |
|---|
| 4951 | | - if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) |
|---|
| 4952 | | - num_counters += ARRAY_SIZE(retrans_q_cnts); |
|---|
| 4953 | | - |
|---|
| 4954 | | - if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) |
|---|
| 4955 | | - num_counters += ARRAY_SIZE(extended_err_cnts); |
|---|
| 4956 | | - |
|---|
| 4957 | | - cnts->num_q_counters = num_counters; |
|---|
| 4958 | | - |
|---|
| 4959 | | - if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
|---|
| 4960 | | - cnts->num_cong_counters = ARRAY_SIZE(cong_cnts); |
|---|
| 4961 | | - num_counters += ARRAY_SIZE(cong_cnts); |
|---|
| 4962 | | - } |
|---|
| 4963 | | - if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
|---|
| 4964 | | - cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts); |
|---|
| 4965 | | - num_counters += ARRAY_SIZE(ext_ppcnt_cnts); |
|---|
| 4966 | | - } |
|---|
| 4967 | | - cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL); |
|---|
| 4968 | | - if (!cnts->names) |
|---|
| 4969 | | - return -ENOMEM; |
|---|
| 4970 | | - |
|---|
| 4971 | | - cnts->offsets = kcalloc(num_counters, |
|---|
| 4972 | | - sizeof(cnts->offsets), GFP_KERNEL); |
|---|
| 4973 | | - if (!cnts->offsets) |
|---|
| 4974 | | - goto err_names; |
|---|
| 4975 | | - |
|---|
| 4976 | | - return 0; |
|---|
| 4977 | | - |
|---|
| 4978 | | -err_names: |
|---|
| 4979 | | - kfree(cnts->names); |
|---|
| 4980 | | - cnts->names = NULL; |
|---|
| 4981 | | - return -ENOMEM; |
|---|
| 4982 | | -} |
|---|
| 4983 | | - |
|---|
| 4984 | | -static void mlx5_ib_fill_counters(struct mlx5_ib_dev *dev, |
|---|
| 4985 | | - const char **names, |
|---|
| 4986 | | - size_t *offsets) |
|---|
| 4987 | | -{ |
|---|
| 4988 | | - int i; |
|---|
| 4989 | | - int j = 0; |
|---|
| 4990 | | - |
|---|
| 4991 | | - for (i = 0; i < ARRAY_SIZE(basic_q_cnts); i++, j++) { |
|---|
| 4992 | | - names[j] = basic_q_cnts[i].name; |
|---|
| 4993 | | - offsets[j] = basic_q_cnts[i].offset; |
|---|
| 4994 | | - } |
|---|
| 4995 | | - |
|---|
| 4996 | | - if (MLX5_CAP_GEN(dev->mdev, out_of_seq_cnt)) { |
|---|
| 4997 | | - for (i = 0; i < ARRAY_SIZE(out_of_seq_q_cnts); i++, j++) { |
|---|
| 4998 | | - names[j] = out_of_seq_q_cnts[i].name; |
|---|
| 4999 | | - offsets[j] = out_of_seq_q_cnts[i].offset; |
|---|
| 5000 | | - } |
|---|
| 5001 | | - } |
|---|
| 5002 | | - |
|---|
| 5003 | | - if (MLX5_CAP_GEN(dev->mdev, retransmission_q_counters)) { |
|---|
| 5004 | | - for (i = 0; i < ARRAY_SIZE(retrans_q_cnts); i++, j++) { |
|---|
| 5005 | | - names[j] = retrans_q_cnts[i].name; |
|---|
| 5006 | | - offsets[j] = retrans_q_cnts[i].offset; |
|---|
| 5007 | | - } |
|---|
| 5008 | | - } |
|---|
| 5009 | | - |
|---|
| 5010 | | - if (MLX5_CAP_GEN(dev->mdev, enhanced_error_q_counters)) { |
|---|
| 5011 | | - for (i = 0; i < ARRAY_SIZE(extended_err_cnts); i++, j++) { |
|---|
| 5012 | | - names[j] = extended_err_cnts[i].name; |
|---|
| 5013 | | - offsets[j] = extended_err_cnts[i].offset; |
|---|
| 5014 | | - } |
|---|
| 5015 | | - } |
|---|
| 5016 | | - |
|---|
| 5017 | | - if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
|---|
| 5018 | | - for (i = 0; i < ARRAY_SIZE(cong_cnts); i++, j++) { |
|---|
| 5019 | | - names[j] = cong_cnts[i].name; |
|---|
| 5020 | | - offsets[j] = cong_cnts[i].offset; |
|---|
| 5021 | | - } |
|---|
| 5022 | | - } |
|---|
| 5023 | | - |
|---|
| 5024 | | - if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
|---|
| 5025 | | - for (i = 0; i < ARRAY_SIZE(ext_ppcnt_cnts); i++, j++) { |
|---|
| 5026 | | - names[j] = ext_ppcnt_cnts[i].name; |
|---|
| 5027 | | - offsets[j] = ext_ppcnt_cnts[i].offset; |
|---|
| 5028 | | - } |
|---|
| 5029 | | - } |
|---|
| 5030 | | -} |
|---|
| 5031 | | - |
|---|
| 5032 | | -static int mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev) |
|---|
| 5033 | | -{ |
|---|
| 5034 | | - int err = 0; |
|---|
| 5035 | | - int i; |
|---|
| 5036 | | - |
|---|
| 5037 | | - for (i = 0; i < dev->num_ports; i++) { |
|---|
| 5038 | | - err = __mlx5_ib_alloc_counters(dev, &dev->port[i].cnts); |
|---|
| 5039 | | - if (err) |
|---|
| 5040 | | - goto err_alloc; |
|---|
| 5041 | | - |
|---|
| 5042 | | - mlx5_ib_fill_counters(dev, dev->port[i].cnts.names, |
|---|
| 5043 | | - dev->port[i].cnts.offsets); |
|---|
| 5044 | | - |
|---|
| 5045 | | - err = mlx5_core_alloc_q_counter(dev->mdev, |
|---|
| 5046 | | - &dev->port[i].cnts.set_id); |
|---|
| 5047 | | - if (err) { |
|---|
| 5048 | | - mlx5_ib_warn(dev, |
|---|
| 5049 | | - "couldn't allocate queue counter for port %d, err %d\n", |
|---|
| 5050 | | - i + 1, err); |
|---|
| 5051 | | - goto err_alloc; |
|---|
| 5052 | | - } |
|---|
| 5053 | | - dev->port[i].cnts.set_id_valid = true; |
|---|
| 5054 | | - } |
|---|
| 5055 | | - |
|---|
| 5056 | | - return 0; |
|---|
| 5057 | | - |
|---|
| 5058 | | -err_alloc: |
|---|
| 5059 | | - mlx5_ib_dealloc_counters(dev); |
|---|
| 5060 | | - return err; |
|---|
| 5061 | | -} |
|---|
| 5062 | | - |
|---|
| 5063 | | -static struct rdma_hw_stats *mlx5_ib_alloc_hw_stats(struct ib_device *ibdev, |
|---|
| 5064 | | - u8 port_num) |
|---|
| 5065 | | -{ |
|---|
| 5066 | | - struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 5067 | | - struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
|---|
| 5068 | | - |
|---|
| 5069 | | - /* We support only per port stats */ |
|---|
| 5070 | | - if (port_num == 0) |
|---|
| 5071 | | - return NULL; |
|---|
| 5072 | | - |
|---|
| 5073 | | - return rdma_alloc_hw_stats_struct(port->cnts.names, |
|---|
| 5074 | | - port->cnts.num_q_counters + |
|---|
| 5075 | | - port->cnts.num_cong_counters + |
|---|
| 5076 | | - port->cnts.num_ext_ppcnt_counters, |
|---|
| 5077 | | - RDMA_HW_STATS_DEFAULT_LIFESPAN); |
|---|
| 5078 | | -} |
|---|
| 5079 | | - |
|---|
| 5080 | | -static int mlx5_ib_query_q_counters(struct mlx5_core_dev *mdev, |
|---|
| 5081 | | - struct mlx5_ib_port *port, |
|---|
| 5082 | | - struct rdma_hw_stats *stats) |
|---|
| 5083 | | -{ |
|---|
| 5084 | | - int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); |
|---|
| 5085 | | - void *out; |
|---|
| 5086 | | - __be32 val; |
|---|
| 5087 | | - int ret, i; |
|---|
| 5088 | | - |
|---|
| 5089 | | - out = kvzalloc(outlen, GFP_KERNEL); |
|---|
| 5090 | | - if (!out) |
|---|
| 5091 | | - return -ENOMEM; |
|---|
| 5092 | | - |
|---|
| 5093 | | - ret = mlx5_core_query_q_counter(mdev, |
|---|
| 5094 | | - port->cnts.set_id, 0, |
|---|
| 5095 | | - out, outlen); |
|---|
| 5096 | | - if (ret) |
|---|
| 5097 | | - goto free; |
|---|
| 5098 | | - |
|---|
| 5099 | | - for (i = 0; i < port->cnts.num_q_counters; i++) { |
|---|
| 5100 | | - val = *(__be32 *)(out + port->cnts.offsets[i]); |
|---|
| 5101 | | - stats->value[i] = (u64)be32_to_cpu(val); |
|---|
| 5102 | | - } |
|---|
| 5103 | | - |
|---|
| 5104 | | -free: |
|---|
| 5105 | | - kvfree(out); |
|---|
| 5106 | | - return ret; |
|---|
| 5107 | | -} |
|---|
| 5108 | | - |
|---|
| 5109 | | -static int mlx5_ib_query_ext_ppcnt_counters(struct mlx5_ib_dev *dev, |
|---|
| 5110 | | - struct mlx5_ib_port *port, |
|---|
| 5111 | | - struct rdma_hw_stats *stats) |
|---|
| 5112 | | -{ |
|---|
| 5113 | | - int offset = port->cnts.num_q_counters + port->cnts.num_cong_counters; |
|---|
| 5114 | | - int sz = MLX5_ST_SZ_BYTES(ppcnt_reg); |
|---|
| 5115 | | - int ret, i; |
|---|
| 5116 | | - void *out; |
|---|
| 5117 | | - |
|---|
| 5118 | | - out = kvzalloc(sz, GFP_KERNEL); |
|---|
| 5119 | | - if (!out) |
|---|
| 5120 | | - return -ENOMEM; |
|---|
| 5121 | | - |
|---|
| 5122 | | - ret = mlx5_cmd_query_ext_ppcnt_counters(dev->mdev, out); |
|---|
| 5123 | | - if (ret) |
|---|
| 5124 | | - goto free; |
|---|
| 5125 | | - |
|---|
| 5126 | | - for (i = 0; i < port->cnts.num_ext_ppcnt_counters; i++) { |
|---|
| 5127 | | - stats->value[i + offset] = |
|---|
| 5128 | | - be64_to_cpup((__be64 *)(out + |
|---|
| 5129 | | - port->cnts.offsets[i + offset])); |
|---|
| 5130 | | - } |
|---|
| 5131 | | - |
|---|
| 5132 | | -free: |
|---|
| 5133 | | - kvfree(out); |
|---|
| 5134 | | - return ret; |
|---|
| 5135 | | -} |
|---|
| 5136 | | - |
|---|
| 5137 | | -static int mlx5_ib_get_hw_stats(struct ib_device *ibdev, |
|---|
| 5138 | | - struct rdma_hw_stats *stats, |
|---|
| 5139 | | - u8 port_num, int index) |
|---|
| 5140 | | -{ |
|---|
| 5141 | | - struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 5142 | | - struct mlx5_ib_port *port = &dev->port[port_num - 1]; |
|---|
| 5143 | | - struct mlx5_core_dev *mdev; |
|---|
| 5144 | | - int ret, num_counters; |
|---|
| 5145 | | - u8 mdev_port_num; |
|---|
| 5146 | | - |
|---|
| 5147 | | - if (!stats) |
|---|
| 5148 | | - return -EINVAL; |
|---|
| 5149 | | - |
|---|
| 5150 | | - num_counters = port->cnts.num_q_counters + |
|---|
| 5151 | | - port->cnts.num_cong_counters + |
|---|
| 5152 | | - port->cnts.num_ext_ppcnt_counters; |
|---|
| 5153 | | - |
|---|
| 5154 | | - /* q_counters are per IB device, query the master mdev */ |
|---|
| 5155 | | - ret = mlx5_ib_query_q_counters(dev->mdev, port, stats); |
|---|
| 5156 | | - if (ret) |
|---|
| 5157 | | - return ret; |
|---|
| 5158 | | - |
|---|
| 5159 | | - if (MLX5_CAP_PCAM_FEATURE(dev->mdev, rx_icrc_encapsulated_counter)) { |
|---|
| 5160 | | - ret = mlx5_ib_query_ext_ppcnt_counters(dev, port, stats); |
|---|
| 5161 | | - if (ret) |
|---|
| 5162 | | - return ret; |
|---|
| 5163 | | - } |
|---|
| 5164 | | - |
|---|
| 5165 | | - if (MLX5_CAP_GEN(dev->mdev, cc_query_allowed)) { |
|---|
| 5166 | | - mdev = mlx5_ib_get_native_port_mdev(dev, port_num, |
|---|
| 5167 | | - &mdev_port_num); |
|---|
| 5168 | | - if (!mdev) { |
|---|
| 5169 | | - /* If port is not affiliated yet, its in down state |
|---|
| 5170 | | - * which doesn't have any counters yet, so it would be |
|---|
| 5171 | | - * zero. So no need to read from the HCA. |
|---|
| 5172 | | - */ |
|---|
| 5173 | | - goto done; |
|---|
| 5174 | | - } |
|---|
| 5175 | | - ret = mlx5_lag_query_cong_counters(dev->mdev, |
|---|
| 5176 | | - stats->value + |
|---|
| 5177 | | - port->cnts.num_q_counters, |
|---|
| 5178 | | - port->cnts.num_cong_counters, |
|---|
| 5179 | | - port->cnts.offsets + |
|---|
| 5180 | | - port->cnts.num_q_counters); |
|---|
| 5181 | | - |
|---|
| 5182 | | - mlx5_ib_put_native_port_mdev(dev, port_num); |
|---|
| 5183 | | - if (ret) |
|---|
| 5184 | | - return ret; |
|---|
| 5185 | | - } |
|---|
| 5186 | | - |
|---|
| 5187 | | -done: |
|---|
| 5188 | | - return num_counters; |
|---|
| 5189 | | -} |
|---|
| 5190 | | - |
|---|
| 5191 | | -static struct net_device* |
|---|
| 5192 | | -mlx5_ib_alloc_rdma_netdev(struct ib_device *hca, |
|---|
| 5193 | | - u8 port_num, |
|---|
| 5194 | | - enum rdma_netdev_t type, |
|---|
| 5195 | | - const char *name, |
|---|
| 5196 | | - unsigned char name_assign_type, |
|---|
| 5197 | | - void (*setup)(struct net_device *)) |
|---|
| 5198 | | -{ |
|---|
| 5199 | | - struct net_device *netdev; |
|---|
| 5200 | | - |
|---|
| 5201 | | - if (type != RDMA_NETDEV_IPOIB) |
|---|
| 5202 | | - return ERR_PTR(-EOPNOTSUPP); |
|---|
| 5203 | | - |
|---|
| 5204 | | - netdev = mlx5_rdma_netdev_alloc(to_mdev(hca)->mdev, hca, |
|---|
| 5205 | | - name, setup); |
|---|
| 5206 | | - return netdev; |
|---|
| 5207 | | -} |
|---|
| 5208 | | - |
|---|
| 5209 | | -static void delay_drop_debugfs_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 5210 | | -{ |
|---|
| 5211 | | - if (!dev->delay_drop.dbg) |
|---|
| 5212 | | - return; |
|---|
| 5213 | | - debugfs_remove_recursive(dev->delay_drop.dbg->dir_debugfs); |
|---|
| 5214 | | - kfree(dev->delay_drop.dbg); |
|---|
| 5215 | | - dev->delay_drop.dbg = NULL; |
|---|
| 5216 | | -} |
|---|
| 4528 | + struct dentry *root; |
|---|
| 5217 | 4529 | |
|---|
| 5218 | | -static void cancel_delay_drop(struct mlx5_ib_dev *dev) |
|---|
| 5219 | | -{ |
|---|
| 5220 | 4530 | if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
|---|
| 5221 | | - return; |
|---|
| 5222 | | - |
|---|
| 5223 | | - cancel_work_sync(&dev->delay_drop.delay_drop_work); |
|---|
| 5224 | | - delay_drop_debugfs_cleanup(dev); |
|---|
| 5225 | | -} |
|---|
| 5226 | | - |
|---|
| 5227 | | -static ssize_t delay_drop_timeout_read(struct file *filp, char __user *buf, |
|---|
| 5228 | | - size_t count, loff_t *pos) |
|---|
| 5229 | | -{ |
|---|
| 5230 | | - struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
|---|
| 5231 | | - char lbuf[20]; |
|---|
| 5232 | | - int len; |
|---|
| 5233 | | - |
|---|
| 5234 | | - len = snprintf(lbuf, sizeof(lbuf), "%u\n", delay_drop->timeout); |
|---|
| 5235 | | - return simple_read_from_buffer(buf, count, pos, lbuf, len); |
|---|
| 5236 | | -} |
|---|
| 5237 | | - |
|---|
| 5238 | | -static ssize_t delay_drop_timeout_write(struct file *filp, const char __user *buf, |
|---|
| 5239 | | - size_t count, loff_t *pos) |
|---|
| 5240 | | -{ |
|---|
| 5241 | | - struct mlx5_ib_delay_drop *delay_drop = filp->private_data; |
|---|
| 5242 | | - u32 timeout; |
|---|
| 5243 | | - u32 var; |
|---|
| 5244 | | - |
|---|
| 5245 | | - if (kstrtouint_from_user(buf, count, 0, &var)) |
|---|
| 5246 | | - return -EFAULT; |
|---|
| 5247 | | - |
|---|
| 5248 | | - timeout = min_t(u32, roundup(var, 100), MLX5_MAX_DELAY_DROP_TIMEOUT_MS * |
|---|
| 5249 | | - 1000); |
|---|
| 5250 | | - if (timeout != var) |
|---|
| 5251 | | - mlx5_ib_dbg(delay_drop->dev, "Round delay drop timeout to %u usec\n", |
|---|
| 5252 | | - timeout); |
|---|
| 5253 | | - |
|---|
| 5254 | | - delay_drop->timeout = timeout; |
|---|
| 5255 | | - |
|---|
| 5256 | | - return count; |
|---|
| 5257 | | -} |
|---|
| 5258 | | - |
|---|
| 5259 | | -static const struct file_operations fops_delay_drop_timeout = { |
|---|
| 5260 | | - .owner = THIS_MODULE, |
|---|
| 5261 | | - .open = simple_open, |
|---|
| 5262 | | - .write = delay_drop_timeout_write, |
|---|
| 5263 | | - .read = delay_drop_timeout_read, |
|---|
| 5264 | | -}; |
|---|
| 5265 | | - |
|---|
| 5266 | | -static int delay_drop_debugfs_init(struct mlx5_ib_dev *dev) |
|---|
| 5267 | | -{ |
|---|
| 5268 | | - struct mlx5_ib_dbg_delay_drop *dbg; |
|---|
| 5269 | | - |
|---|
| 5270 | | - if (!mlx5_debugfs_root) |
|---|
| 5271 | 4531 | return 0; |
|---|
| 5272 | | - |
|---|
| 5273 | | - dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); |
|---|
| 5274 | | - if (!dbg) |
|---|
| 5275 | | - return -ENOMEM; |
|---|
| 5276 | | - |
|---|
| 5277 | | - dev->delay_drop.dbg = dbg; |
|---|
| 5278 | | - |
|---|
| 5279 | | - dbg->dir_debugfs = |
|---|
| 5280 | | - debugfs_create_dir("delay_drop", |
|---|
| 5281 | | - dev->mdev->priv.dbg_root); |
|---|
| 5282 | | - if (!dbg->dir_debugfs) |
|---|
| 5283 | | - goto out_debugfs; |
|---|
| 5284 | | - |
|---|
| 5285 | | - dbg->events_cnt_debugfs = |
|---|
| 5286 | | - debugfs_create_atomic_t("num_timeout_events", 0400, |
|---|
| 5287 | | - dbg->dir_debugfs, |
|---|
| 5288 | | - &dev->delay_drop.events_cnt); |
|---|
| 5289 | | - if (!dbg->events_cnt_debugfs) |
|---|
| 5290 | | - goto out_debugfs; |
|---|
| 5291 | | - |
|---|
| 5292 | | - dbg->rqs_cnt_debugfs = |
|---|
| 5293 | | - debugfs_create_atomic_t("num_rqs", 0400, |
|---|
| 5294 | | - dbg->dir_debugfs, |
|---|
| 5295 | | - &dev->delay_drop.rqs_cnt); |
|---|
| 5296 | | - if (!dbg->rqs_cnt_debugfs) |
|---|
| 5297 | | - goto out_debugfs; |
|---|
| 5298 | | - |
|---|
| 5299 | | - dbg->timeout_debugfs = |
|---|
| 5300 | | - debugfs_create_file("timeout", 0600, |
|---|
| 5301 | | - dbg->dir_debugfs, |
|---|
| 5302 | | - &dev->delay_drop, |
|---|
| 5303 | | - &fops_delay_drop_timeout); |
|---|
| 5304 | | - if (!dbg->timeout_debugfs) |
|---|
| 5305 | | - goto out_debugfs; |
|---|
| 5306 | | - |
|---|
| 5307 | | - return 0; |
|---|
| 5308 | | - |
|---|
| 5309 | | -out_debugfs: |
|---|
| 5310 | | - delay_drop_debugfs_cleanup(dev); |
|---|
| 5311 | | - return -ENOMEM; |
|---|
| 5312 | | -} |
|---|
| 5313 | | - |
|---|
| 5314 | | -static void init_delay_drop(struct mlx5_ib_dev *dev) |
|---|
| 5315 | | -{ |
|---|
| 5316 | | - if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
|---|
| 5317 | | - return; |
|---|
| 5318 | 4532 | |
|---|
| 5319 | 4533 | mutex_init(&dev->delay_drop.lock); |
|---|
| 5320 | 4534 | dev->delay_drop.dev = dev; |
|---|
| .. | .. |
|---|
| 5324 | 4538 | atomic_set(&dev->delay_drop.rqs_cnt, 0); |
|---|
| 5325 | 4539 | atomic_set(&dev->delay_drop.events_cnt, 0); |
|---|
| 5326 | 4540 | |
|---|
| 5327 | | - if (delay_drop_debugfs_init(dev)) |
|---|
| 5328 | | - mlx5_ib_warn(dev, "Failed to init delay drop debugfs\n"); |
|---|
| 5329 | | -} |
|---|
| 5330 | | - |
|---|
| 5331 | | -static const struct cpumask * |
|---|
| 5332 | | -mlx5_ib_get_vector_affinity(struct ib_device *ibdev, int comp_vector) |
|---|
| 5333 | | -{ |
|---|
| 5334 | | - struct mlx5_ib_dev *dev = to_mdev(ibdev); |
|---|
| 5335 | | - |
|---|
| 5336 | | - return mlx5_get_vector_affinity_hint(dev->mdev, comp_vector); |
|---|
| 5337 | | -} |
|---|
| 5338 | | - |
|---|
| 5339 | | -/* The mlx5_ib_multiport_mutex should be held when calling this function */ |
|---|
| 5340 | | -static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev, |
|---|
| 5341 | | - struct mlx5_ib_multiport_info *mpi) |
|---|
| 5342 | | -{ |
|---|
| 5343 | | - u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
|---|
| 5344 | | - struct mlx5_ib_port *port = &ibdev->port[port_num]; |
|---|
| 5345 | | - int comps; |
|---|
| 5346 | | - int err; |
|---|
| 5347 | | - int i; |
|---|
| 5348 | | - |
|---|
| 5349 | | - mlx5_ib_cleanup_cong_debugfs(ibdev, port_num); |
|---|
| 5350 | | - |
|---|
| 5351 | | - spin_lock(&port->mp.mpi_lock); |
|---|
| 5352 | | - if (!mpi->ibdev) { |
|---|
| 5353 | | - spin_unlock(&port->mp.mpi_lock); |
|---|
| 5354 | | - return; |
|---|
| 5355 | | - } |
|---|
| 5356 | | - mpi->ibdev = NULL; |
|---|
| 5357 | | - |
|---|
| 5358 | | - spin_unlock(&port->mp.mpi_lock); |
|---|
| 5359 | | - mlx5_remove_netdev_notifier(ibdev, port_num); |
|---|
| 5360 | | - spin_lock(&port->mp.mpi_lock); |
|---|
| 5361 | | - |
|---|
| 5362 | | - comps = mpi->mdev_refcnt; |
|---|
| 5363 | | - if (comps) { |
|---|
| 5364 | | - mpi->unaffiliate = true; |
|---|
| 5365 | | - init_completion(&mpi->unref_comp); |
|---|
| 5366 | | - spin_unlock(&port->mp.mpi_lock); |
|---|
| 5367 | | - |
|---|
| 5368 | | - for (i = 0; i < comps; i++) |
|---|
| 5369 | | - wait_for_completion(&mpi->unref_comp); |
|---|
| 5370 | | - |
|---|
| 5371 | | - spin_lock(&port->mp.mpi_lock); |
|---|
| 5372 | | - mpi->unaffiliate = false; |
|---|
| 5373 | | - } |
|---|
| 5374 | | - |
|---|
| 5375 | | - port->mp.mpi = NULL; |
|---|
| 5376 | | - |
|---|
| 5377 | | - spin_unlock(&port->mp.mpi_lock); |
|---|
| 5378 | | - |
|---|
| 5379 | | - err = mlx5_nic_vport_unaffiliate_multiport(mpi->mdev); |
|---|
| 5380 | | - |
|---|
| 5381 | | - mlx5_ib_dbg(ibdev, "unaffiliated port %d\n", port_num + 1); |
|---|
| 5382 | | - /* Log an error, still needed to cleanup the pointers and add |
|---|
| 5383 | | - * it back to the list. |
|---|
| 5384 | | - */ |
|---|
| 5385 | | - if (err) |
|---|
| 5386 | | - mlx5_ib_err(ibdev, "Failed to unaffiliate port %u\n", |
|---|
| 5387 | | - port_num + 1); |
|---|
| 5388 | | - |
|---|
| 5389 | | - ibdev->roce[port_num].last_port_state = IB_PORT_DOWN; |
|---|
| 5390 | | -} |
|---|
| 5391 | | - |
|---|
| 5392 | | -/* The mlx5_ib_multiport_mutex should be held when calling this function */ |
|---|
| 5393 | | -static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev, |
|---|
| 5394 | | - struct mlx5_ib_multiport_info *mpi) |
|---|
| 5395 | | -{ |
|---|
| 5396 | | - u8 port_num = mlx5_core_native_port_num(mpi->mdev) - 1; |
|---|
| 5397 | | - int err; |
|---|
| 5398 | | - |
|---|
| 5399 | | - spin_lock(&ibdev->port[port_num].mp.mpi_lock); |
|---|
| 5400 | | - if (ibdev->port[port_num].mp.mpi) { |
|---|
| 5401 | | - mlx5_ib_dbg(ibdev, "port %d already affiliated.\n", |
|---|
| 5402 | | - port_num + 1); |
|---|
| 5403 | | - spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
|---|
| 5404 | | - return false; |
|---|
| 5405 | | - } |
|---|
| 5406 | | - |
|---|
| 5407 | | - ibdev->port[port_num].mp.mpi = mpi; |
|---|
| 5408 | | - mpi->ibdev = ibdev; |
|---|
| 5409 | | - spin_unlock(&ibdev->port[port_num].mp.mpi_lock); |
|---|
| 5410 | | - |
|---|
| 5411 | | - err = mlx5_nic_vport_affiliate_multiport(ibdev->mdev, mpi->mdev); |
|---|
| 5412 | | - if (err) |
|---|
| 5413 | | - goto unbind; |
|---|
| 5414 | | - |
|---|
| 5415 | | - err = get_port_caps(ibdev, mlx5_core_native_port_num(mpi->mdev)); |
|---|
| 5416 | | - if (err) |
|---|
| 5417 | | - goto unbind; |
|---|
| 5418 | | - |
|---|
| 5419 | | - err = mlx5_add_netdev_notifier(ibdev, port_num); |
|---|
| 5420 | | - if (err) { |
|---|
| 5421 | | - mlx5_ib_err(ibdev, "failed adding netdev notifier for port %u\n", |
|---|
| 5422 | | - port_num + 1); |
|---|
| 5423 | | - goto unbind; |
|---|
| 5424 | | - } |
|---|
| 5425 | | - |
|---|
| 5426 | | - err = mlx5_ib_init_cong_debugfs(ibdev, port_num); |
|---|
| 5427 | | - if (err) |
|---|
| 5428 | | - goto unbind; |
|---|
| 5429 | | - |
|---|
| 5430 | | - return true; |
|---|
| 5431 | | - |
|---|
| 5432 | | -unbind: |
|---|
| 5433 | | - mlx5_ib_unbind_slave_port(ibdev, mpi); |
|---|
| 5434 | | - return false; |
|---|
| 5435 | | -} |
|---|
| 5436 | | - |
|---|
| 5437 | | -static int mlx5_ib_init_multiport_master(struct mlx5_ib_dev *dev) |
|---|
| 5438 | | -{ |
|---|
| 5439 | | - int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
|---|
| 5440 | | - enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
|---|
| 5441 | | - port_num + 1); |
|---|
| 5442 | | - struct mlx5_ib_multiport_info *mpi; |
|---|
| 5443 | | - int err; |
|---|
| 5444 | | - int i; |
|---|
| 5445 | | - |
|---|
| 5446 | | - if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
|---|
| 4541 | + if (!mlx5_debugfs_root) |
|---|
| 5447 | 4542 | return 0; |
|---|
| 5448 | 4543 | |
|---|
| 5449 | | - err = mlx5_query_nic_vport_system_image_guid(dev->mdev, |
|---|
| 5450 | | - &dev->sys_image_guid); |
|---|
| 5451 | | - if (err) |
|---|
| 5452 | | - return err; |
|---|
| 4544 | + root = debugfs_create_dir("delay_drop", dev->mdev->priv.dbg_root); |
|---|
| 4545 | + dev->delay_drop.dir_debugfs = root; |
|---|
| 5453 | 4546 | |
|---|
| 5454 | | - err = mlx5_nic_vport_enable_roce(dev->mdev); |
|---|
| 5455 | | - if (err) |
|---|
| 5456 | | - return err; |
|---|
| 5457 | | - |
|---|
| 5458 | | - mutex_lock(&mlx5_ib_multiport_mutex); |
|---|
| 5459 | | - for (i = 0; i < dev->num_ports; i++) { |
|---|
| 5460 | | - bool bound = false; |
|---|
| 5461 | | - |
|---|
| 5462 | | - /* build a stub multiport info struct for the native port. */ |
|---|
| 5463 | | - if (i == port_num) { |
|---|
| 5464 | | - mpi = kzalloc(sizeof(*mpi), GFP_KERNEL); |
|---|
| 5465 | | - if (!mpi) { |
|---|
| 5466 | | - mutex_unlock(&mlx5_ib_multiport_mutex); |
|---|
| 5467 | | - mlx5_nic_vport_disable_roce(dev->mdev); |
|---|
| 5468 | | - return -ENOMEM; |
|---|
| 5469 | | - } |
|---|
| 5470 | | - |
|---|
| 5471 | | - mpi->is_master = true; |
|---|
| 5472 | | - mpi->mdev = dev->mdev; |
|---|
| 5473 | | - mpi->sys_image_guid = dev->sys_image_guid; |
|---|
| 5474 | | - dev->port[i].mp.mpi = mpi; |
|---|
| 5475 | | - mpi->ibdev = dev; |
|---|
| 5476 | | - mpi = NULL; |
|---|
| 5477 | | - continue; |
|---|
| 5478 | | - } |
|---|
| 5479 | | - |
|---|
| 5480 | | - list_for_each_entry(mpi, &mlx5_ib_unaffiliated_port_list, |
|---|
| 5481 | | - list) { |
|---|
| 5482 | | - if (dev->sys_image_guid == mpi->sys_image_guid && |
|---|
| 5483 | | - (mlx5_core_native_port_num(mpi->mdev) - 1) == i) { |
|---|
| 5484 | | - bound = mlx5_ib_bind_slave_port(dev, mpi); |
|---|
| 5485 | | - } |
|---|
| 5486 | | - |
|---|
| 5487 | | - if (bound) { |
|---|
| 5488 | | - dev_dbg(&mpi->mdev->pdev->dev, "removing port from unaffiliated list.\n"); |
|---|
| 5489 | | - mlx5_ib_dbg(dev, "port %d bound\n", i + 1); |
|---|
| 5490 | | - list_del(&mpi->list); |
|---|
| 5491 | | - break; |
|---|
| 5492 | | - } |
|---|
| 5493 | | - } |
|---|
| 5494 | | - if (!bound) { |
|---|
| 5495 | | - get_port_caps(dev, i + 1); |
|---|
| 5496 | | - mlx5_ib_dbg(dev, "no free port found for port %d\n", |
|---|
| 5497 | | - i + 1); |
|---|
| 5498 | | - } |
|---|
| 5499 | | - } |
|---|
| 5500 | | - |
|---|
| 5501 | | - list_add_tail(&dev->ib_dev_list, &mlx5_ib_dev_list); |
|---|
| 5502 | | - mutex_unlock(&mlx5_ib_multiport_mutex); |
|---|
| 5503 | | - return err; |
|---|
| 5504 | | -} |
|---|
| 5505 | | - |
|---|
| 5506 | | -static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev) |
|---|
| 5507 | | -{ |
|---|
| 5508 | | - int port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
|---|
| 5509 | | - enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, |
|---|
| 5510 | | - port_num + 1); |
|---|
| 5511 | | - int i; |
|---|
| 5512 | | - |
|---|
| 5513 | | - if (!mlx5_core_is_mp_master(dev->mdev) || ll != IB_LINK_LAYER_ETHERNET) |
|---|
| 5514 | | - return; |
|---|
| 5515 | | - |
|---|
| 5516 | | - mutex_lock(&mlx5_ib_multiport_mutex); |
|---|
| 5517 | | - for (i = 0; i < dev->num_ports; i++) { |
|---|
| 5518 | | - if (dev->port[i].mp.mpi) { |
|---|
| 5519 | | - /* Destroy the native port stub */ |
|---|
| 5520 | | - if (i == port_num) { |
|---|
| 5521 | | - kfree(dev->port[i].mp.mpi); |
|---|
| 5522 | | - dev->port[i].mp.mpi = NULL; |
|---|
| 5523 | | - } else { |
|---|
| 5524 | | - mlx5_ib_dbg(dev, "unbinding port_num: %d\n", i + 1); |
|---|
| 5525 | | - list_add_tail(&dev->port[i].mp.mpi->list, |
|---|
| 5526 | | - &mlx5_ib_unaffiliated_port_list); |
|---|
| 5527 | | - mlx5_ib_unbind_slave_port(dev, dev->port[i].mp.mpi); |
|---|
| 5528 | | - } |
|---|
| 5529 | | - } |
|---|
| 5530 | | - } |
|---|
| 5531 | | - |
|---|
| 5532 | | - mlx5_ib_dbg(dev, "removing from devlist\n"); |
|---|
| 5533 | | - list_del(&dev->ib_dev_list); |
|---|
| 5534 | | - mutex_unlock(&mlx5_ib_multiport_mutex); |
|---|
| 5535 | | - |
|---|
| 5536 | | - mlx5_nic_vport_disable_roce(dev->mdev); |
|---|
| 5537 | | -} |
|---|
| 5538 | | - |
|---|
| 5539 | | -ADD_UVERBS_ATTRIBUTES_SIMPLE( |
|---|
| 5540 | | - mlx5_ib_dm, |
|---|
| 5541 | | - UVERBS_OBJECT_DM, |
|---|
| 5542 | | - UVERBS_METHOD_DM_ALLOC, |
|---|
| 5543 | | - UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET, |
|---|
| 5544 | | - UVERBS_ATTR_TYPE(u64), |
|---|
| 5545 | | - UA_MANDATORY), |
|---|
| 5546 | | - UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX, |
|---|
| 5547 | | - UVERBS_ATTR_TYPE(u16), |
|---|
| 5548 | | - UA_MANDATORY)); |
|---|
| 5549 | | - |
|---|
| 5550 | | -ADD_UVERBS_ATTRIBUTES_SIMPLE( |
|---|
| 5551 | | - mlx5_ib_flow_action, |
|---|
| 5552 | | - UVERBS_OBJECT_FLOW_ACTION, |
|---|
| 5553 | | - UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, |
|---|
| 5554 | | - UVERBS_ATTR_FLAGS_IN(MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
|---|
| 5555 | | - enum mlx5_ib_uapi_flow_action_flags)); |
|---|
| 5556 | | - |
|---|
| 5557 | | -static int populate_specs_root(struct mlx5_ib_dev *dev) |
|---|
| 5558 | | -{ |
|---|
| 5559 | | - const struct uverbs_object_tree_def **trees = dev->driver_trees; |
|---|
| 5560 | | - size_t num_trees = 0; |
|---|
| 5561 | | - |
|---|
| 5562 | | - if (mlx5_accel_ipsec_device_caps(dev->mdev) & |
|---|
| 5563 | | - MLX5_ACCEL_IPSEC_CAP_DEVICE) |
|---|
| 5564 | | - trees[num_trees++] = &mlx5_ib_flow_action; |
|---|
| 5565 | | - |
|---|
| 5566 | | - if (MLX5_CAP_DEV_MEM(dev->mdev, memic)) |
|---|
| 5567 | | - trees[num_trees++] = &mlx5_ib_dm; |
|---|
| 5568 | | - |
|---|
| 5569 | | - if (MLX5_CAP_GEN_64(dev->mdev, general_obj_types) & |
|---|
| 5570 | | - MLX5_GENERAL_OBJ_TYPES_CAP_UCTX) |
|---|
| 5571 | | - trees[num_trees++] = mlx5_ib_get_devx_tree(); |
|---|
| 5572 | | - |
|---|
| 5573 | | - num_trees += mlx5_ib_get_flow_trees(trees + num_trees); |
|---|
| 5574 | | - |
|---|
| 5575 | | - WARN_ON(num_trees >= ARRAY_SIZE(dev->driver_trees)); |
|---|
| 5576 | | - trees[num_trees] = NULL; |
|---|
| 5577 | | - dev->ib_dev.driver_specs = trees; |
|---|
| 5578 | | - |
|---|
| 5579 | | - return 0; |
|---|
| 5580 | | -} |
|---|
| 5581 | | - |
|---|
| 5582 | | -static int mlx5_ib_read_counters(struct ib_counters *counters, |
|---|
| 5583 | | - struct ib_counters_read_attr *read_attr, |
|---|
| 5584 | | - struct uverbs_attr_bundle *attrs) |
|---|
| 5585 | | -{ |
|---|
| 5586 | | - struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
|---|
| 5587 | | - struct mlx5_read_counters_attr mread_attr = {}; |
|---|
| 5588 | | - struct mlx5_ib_flow_counters_desc *desc; |
|---|
| 5589 | | - int ret, i; |
|---|
| 5590 | | - |
|---|
| 5591 | | - mutex_lock(&mcounters->mcntrs_mutex); |
|---|
| 5592 | | - if (mcounters->cntrs_max_index > read_attr->ncounters) { |
|---|
| 5593 | | - ret = -EINVAL; |
|---|
| 5594 | | - goto err_bound; |
|---|
| 5595 | | - } |
|---|
| 5596 | | - |
|---|
| 5597 | | - mread_attr.out = kcalloc(mcounters->counters_num, sizeof(u64), |
|---|
| 5598 | | - GFP_KERNEL); |
|---|
| 5599 | | - if (!mread_attr.out) { |
|---|
| 5600 | | - ret = -ENOMEM; |
|---|
| 5601 | | - goto err_bound; |
|---|
| 5602 | | - } |
|---|
| 5603 | | - |
|---|
| 5604 | | - mread_attr.hw_cntrs_hndl = mcounters->hw_cntrs_hndl; |
|---|
| 5605 | | - mread_attr.flags = read_attr->flags; |
|---|
| 5606 | | - ret = mcounters->read_counters(counters->device, &mread_attr); |
|---|
| 5607 | | - if (ret) |
|---|
| 5608 | | - goto err_read; |
|---|
| 5609 | | - |
|---|
| 5610 | | - /* do the pass over the counters data array to assign according to the |
|---|
| 5611 | | - * descriptions and indexing pairs |
|---|
| 5612 | | - */ |
|---|
| 5613 | | - desc = mcounters->counters_data; |
|---|
| 5614 | | - for (i = 0; i < mcounters->ncounters; i++) |
|---|
| 5615 | | - read_attr->counters_buff[desc[i].index] += mread_attr.out[desc[i].description]; |
|---|
| 5616 | | - |
|---|
| 5617 | | -err_read: |
|---|
| 5618 | | - kfree(mread_attr.out); |
|---|
| 5619 | | -err_bound: |
|---|
| 5620 | | - mutex_unlock(&mcounters->mcntrs_mutex); |
|---|
| 5621 | | - return ret; |
|---|
| 5622 | | -} |
|---|
| 5623 | | - |
|---|
| 5624 | | -static int mlx5_ib_destroy_counters(struct ib_counters *counters) |
|---|
| 5625 | | -{ |
|---|
| 5626 | | - struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); |
|---|
| 5627 | | - |
|---|
| 5628 | | - counters_clear_description(counters); |
|---|
| 5629 | | - if (mcounters->hw_cntrs_hndl) |
|---|
| 5630 | | - mlx5_fc_destroy(to_mdev(counters->device)->mdev, |
|---|
| 5631 | | - mcounters->hw_cntrs_hndl); |
|---|
| 5632 | | - |
|---|
| 5633 | | - kfree(mcounters); |
|---|
| 5634 | | - |
|---|
| 5635 | | - return 0; |
|---|
| 5636 | | -} |
|---|
| 5637 | | - |
|---|
| 5638 | | -static struct ib_counters *mlx5_ib_create_counters(struct ib_device *device, |
|---|
| 5639 | | - struct uverbs_attr_bundle *attrs) |
|---|
| 5640 | | -{ |
|---|
| 5641 | | - struct mlx5_ib_mcounters *mcounters; |
|---|
| 5642 | | - |
|---|
| 5643 | | - mcounters = kzalloc(sizeof(*mcounters), GFP_KERNEL); |
|---|
| 5644 | | - if (!mcounters) |
|---|
| 5645 | | - return ERR_PTR(-ENOMEM); |
|---|
| 5646 | | - |
|---|
| 5647 | | - mutex_init(&mcounters->mcntrs_mutex); |
|---|
| 5648 | | - |
|---|
| 5649 | | - return &mcounters->ibcntrs; |
|---|
| 5650 | | -} |
|---|
| 5651 | | - |
|---|
| 5652 | | -void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 5653 | | -{ |
|---|
| 5654 | | - mlx5_ib_cleanup_multiport_master(dev); |
|---|
| 5655 | | -#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
|---|
| 5656 | | - cleanup_srcu_struct(&dev->mr_srcu); |
|---|
| 5657 | | -#endif |
|---|
| 5658 | | - kfree(dev->port); |
|---|
| 5659 | | -} |
|---|
| 5660 | | - |
|---|
| 5661 | | -int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev) |
|---|
| 5662 | | -{ |
|---|
| 5663 | | - struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 5664 | | - const char *name; |
|---|
| 5665 | | - int err; |
|---|
| 5666 | | - int i; |
|---|
| 5667 | | - |
|---|
| 5668 | | - dev->port = kcalloc(dev->num_ports, sizeof(*dev->port), |
|---|
| 5669 | | - GFP_KERNEL); |
|---|
| 5670 | | - if (!dev->port) |
|---|
| 5671 | | - return -ENOMEM; |
|---|
| 5672 | | - |
|---|
| 5673 | | - for (i = 0; i < dev->num_ports; i++) { |
|---|
| 5674 | | - spin_lock_init(&dev->port[i].mp.mpi_lock); |
|---|
| 5675 | | - rwlock_init(&dev->roce[i].netdev_lock); |
|---|
| 5676 | | - } |
|---|
| 5677 | | - |
|---|
| 5678 | | - err = mlx5_ib_init_multiport_master(dev); |
|---|
| 5679 | | - if (err) |
|---|
| 5680 | | - goto err_free_port; |
|---|
| 5681 | | - |
|---|
| 5682 | | - if (!mlx5_core_mp_enabled(mdev)) { |
|---|
| 5683 | | - for (i = 1; i <= dev->num_ports; i++) { |
|---|
| 5684 | | - err = get_port_caps(dev, i); |
|---|
| 5685 | | - if (err) |
|---|
| 5686 | | - break; |
|---|
| 5687 | | - } |
|---|
| 5688 | | - } else { |
|---|
| 5689 | | - err = get_port_caps(dev, mlx5_core_native_port_num(mdev)); |
|---|
| 5690 | | - } |
|---|
| 5691 | | - if (err) |
|---|
| 5692 | | - goto err_mp; |
|---|
| 5693 | | - |
|---|
| 5694 | | - if (mlx5_use_mad_ifc(dev)) |
|---|
| 5695 | | - get_ext_port_caps(dev); |
|---|
| 5696 | | - |
|---|
| 5697 | | - if (!mlx5_lag_is_active(mdev)) |
|---|
| 5698 | | - name = "mlx5_%d"; |
|---|
| 5699 | | - else |
|---|
| 5700 | | - name = "mlx5_bond_%d"; |
|---|
| 5701 | | - |
|---|
| 5702 | | - strlcpy(dev->ib_dev.name, name, IB_DEVICE_NAME_MAX); |
|---|
| 5703 | | - dev->ib_dev.owner = THIS_MODULE; |
|---|
| 5704 | | - dev->ib_dev.node_type = RDMA_NODE_IB_CA; |
|---|
| 5705 | | - dev->ib_dev.local_dma_lkey = 0 /* not supported for now */; |
|---|
| 5706 | | - dev->ib_dev.phys_port_cnt = dev->num_ports; |
|---|
| 5707 | | - dev->ib_dev.num_comp_vectors = |
|---|
| 5708 | | - dev->mdev->priv.eq_table.num_comp_vectors; |
|---|
| 5709 | | - dev->ib_dev.dev.parent = &mdev->pdev->dev; |
|---|
| 5710 | | - |
|---|
| 5711 | | - mutex_init(&dev->cap_mask_mutex); |
|---|
| 5712 | | - INIT_LIST_HEAD(&dev->qp_list); |
|---|
| 5713 | | - spin_lock_init(&dev->reset_flow_resource_lock); |
|---|
| 5714 | | - |
|---|
| 5715 | | - spin_lock_init(&dev->memic.memic_lock); |
|---|
| 5716 | | - dev->memic.dev = mdev; |
|---|
| 5717 | | - |
|---|
| 5718 | | -#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
|---|
| 5719 | | - err = init_srcu_struct(&dev->mr_srcu); |
|---|
| 5720 | | - if (err) |
|---|
| 5721 | | - goto err_free_port; |
|---|
| 5722 | | -#endif |
|---|
| 5723 | | - |
|---|
| 5724 | | - return 0; |
|---|
| 5725 | | -err_mp: |
|---|
| 5726 | | - mlx5_ib_cleanup_multiport_master(dev); |
|---|
| 5727 | | - |
|---|
| 5728 | | -err_free_port: |
|---|
| 5729 | | - kfree(dev->port); |
|---|
| 5730 | | - |
|---|
| 5731 | | - return -ENOMEM; |
|---|
| 5732 | | -} |
|---|
| 5733 | | - |
|---|
| 5734 | | -static int mlx5_ib_stage_flow_db_init(struct mlx5_ib_dev *dev) |
|---|
| 5735 | | -{ |
|---|
| 5736 | | - dev->flow_db = kzalloc(sizeof(*dev->flow_db), GFP_KERNEL); |
|---|
| 5737 | | - |
|---|
| 5738 | | - if (!dev->flow_db) |
|---|
| 5739 | | - return -ENOMEM; |
|---|
| 5740 | | - |
|---|
| 5741 | | - mutex_init(&dev->flow_db->lock); |
|---|
| 5742 | | - |
|---|
| 5743 | | - return 0; |
|---|
| 5744 | | -} |
|---|
| 5745 | | - |
|---|
| 5746 | | -int mlx5_ib_stage_rep_flow_db_init(struct mlx5_ib_dev *dev) |
|---|
| 5747 | | -{ |
|---|
| 5748 | | - struct mlx5_ib_dev *nic_dev; |
|---|
| 5749 | | - |
|---|
| 5750 | | - nic_dev = mlx5_ib_get_uplink_ibdev(dev->mdev->priv.eswitch); |
|---|
| 5751 | | - |
|---|
| 5752 | | - if (!nic_dev) |
|---|
| 5753 | | - return -EINVAL; |
|---|
| 5754 | | - |
|---|
| 5755 | | - dev->flow_db = nic_dev->flow_db; |
|---|
| 5756 | | - |
|---|
| 5757 | | - return 0; |
|---|
| 5758 | | -} |
|---|
| 5759 | | - |
|---|
| 5760 | | -static void mlx5_ib_stage_flow_db_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 5761 | | -{ |
|---|
| 5762 | | - kfree(dev->flow_db); |
|---|
| 5763 | | -} |
|---|
| 5764 | | - |
|---|
| 5765 | | -int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) |
|---|
| 5766 | | -{ |
|---|
| 5767 | | - struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 5768 | | - int err; |
|---|
| 5769 | | - |
|---|
| 5770 | | - dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION; |
|---|
| 5771 | | - dev->ib_dev.uverbs_cmd_mask = |
|---|
| 5772 | | - (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
|---|
| 5773 | | - (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
|---|
| 5774 | | - (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
|---|
| 5775 | | - (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
|---|
| 5776 | | - (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
|---|
| 5777 | | - (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
|---|
| 5778 | | - (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
|---|
| 5779 | | - (1ull << IB_USER_VERBS_CMD_REG_MR) | |
|---|
| 5780 | | - (1ull << IB_USER_VERBS_CMD_REREG_MR) | |
|---|
| 5781 | | - (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
|---|
| 5782 | | - (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
|---|
| 5783 | | - (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
|---|
| 5784 | | - (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
|---|
| 5785 | | - (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
|---|
| 5786 | | - (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
|---|
| 5787 | | - (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
|---|
| 5788 | | - (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
|---|
| 5789 | | - (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
|---|
| 5790 | | - (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
|---|
| 5791 | | - (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
|---|
| 5792 | | - (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
|---|
| 5793 | | - (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
|---|
| 5794 | | - (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
|---|
| 5795 | | - (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
|---|
| 5796 | | - (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) | |
|---|
| 5797 | | - (1ull << IB_USER_VERBS_CMD_OPEN_QP); |
|---|
| 5798 | | - dev->ib_dev.uverbs_ex_cmd_mask = |
|---|
| 5799 | | - (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE) | |
|---|
| 5800 | | - (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | |
|---|
| 5801 | | - (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) | |
|---|
| 5802 | | - (1ull << IB_USER_VERBS_EX_CMD_MODIFY_QP) | |
|---|
| 5803 | | - (1ull << IB_USER_VERBS_EX_CMD_MODIFY_CQ); |
|---|
| 5804 | | - |
|---|
| 5805 | | - dev->ib_dev.query_device = mlx5_ib_query_device; |
|---|
| 5806 | | - dev->ib_dev.get_link_layer = mlx5_ib_port_link_layer; |
|---|
| 5807 | | - dev->ib_dev.query_gid = mlx5_ib_query_gid; |
|---|
| 5808 | | - dev->ib_dev.add_gid = mlx5_ib_add_gid; |
|---|
| 5809 | | - dev->ib_dev.del_gid = mlx5_ib_del_gid; |
|---|
| 5810 | | - dev->ib_dev.query_pkey = mlx5_ib_query_pkey; |
|---|
| 5811 | | - dev->ib_dev.modify_device = mlx5_ib_modify_device; |
|---|
| 5812 | | - dev->ib_dev.modify_port = mlx5_ib_modify_port; |
|---|
| 5813 | | - dev->ib_dev.alloc_ucontext = mlx5_ib_alloc_ucontext; |
|---|
| 5814 | | - dev->ib_dev.dealloc_ucontext = mlx5_ib_dealloc_ucontext; |
|---|
| 5815 | | - dev->ib_dev.mmap = mlx5_ib_mmap; |
|---|
| 5816 | | - dev->ib_dev.alloc_pd = mlx5_ib_alloc_pd; |
|---|
| 5817 | | - dev->ib_dev.dealloc_pd = mlx5_ib_dealloc_pd; |
|---|
| 5818 | | - dev->ib_dev.create_ah = mlx5_ib_create_ah; |
|---|
| 5819 | | - dev->ib_dev.query_ah = mlx5_ib_query_ah; |
|---|
| 5820 | | - dev->ib_dev.destroy_ah = mlx5_ib_destroy_ah; |
|---|
| 5821 | | - dev->ib_dev.create_srq = mlx5_ib_create_srq; |
|---|
| 5822 | | - dev->ib_dev.modify_srq = mlx5_ib_modify_srq; |
|---|
| 5823 | | - dev->ib_dev.query_srq = mlx5_ib_query_srq; |
|---|
| 5824 | | - dev->ib_dev.destroy_srq = mlx5_ib_destroy_srq; |
|---|
| 5825 | | - dev->ib_dev.post_srq_recv = mlx5_ib_post_srq_recv; |
|---|
| 5826 | | - dev->ib_dev.create_qp = mlx5_ib_create_qp; |
|---|
| 5827 | | - dev->ib_dev.modify_qp = mlx5_ib_modify_qp; |
|---|
| 5828 | | - dev->ib_dev.query_qp = mlx5_ib_query_qp; |
|---|
| 5829 | | - dev->ib_dev.destroy_qp = mlx5_ib_destroy_qp; |
|---|
| 5830 | | - dev->ib_dev.drain_sq = mlx5_ib_drain_sq; |
|---|
| 5831 | | - dev->ib_dev.drain_rq = mlx5_ib_drain_rq; |
|---|
| 5832 | | - dev->ib_dev.post_send = mlx5_ib_post_send; |
|---|
| 5833 | | - dev->ib_dev.post_recv = mlx5_ib_post_recv; |
|---|
| 5834 | | - dev->ib_dev.create_cq = mlx5_ib_create_cq; |
|---|
| 5835 | | - dev->ib_dev.modify_cq = mlx5_ib_modify_cq; |
|---|
| 5836 | | - dev->ib_dev.resize_cq = mlx5_ib_resize_cq; |
|---|
| 5837 | | - dev->ib_dev.destroy_cq = mlx5_ib_destroy_cq; |
|---|
| 5838 | | - dev->ib_dev.poll_cq = mlx5_ib_poll_cq; |
|---|
| 5839 | | - dev->ib_dev.req_notify_cq = mlx5_ib_arm_cq; |
|---|
| 5840 | | - dev->ib_dev.get_dma_mr = mlx5_ib_get_dma_mr; |
|---|
| 5841 | | - dev->ib_dev.reg_user_mr = mlx5_ib_reg_user_mr; |
|---|
| 5842 | | - dev->ib_dev.rereg_user_mr = mlx5_ib_rereg_user_mr; |
|---|
| 5843 | | - dev->ib_dev.dereg_mr = mlx5_ib_dereg_mr; |
|---|
| 5844 | | - dev->ib_dev.attach_mcast = mlx5_ib_mcg_attach; |
|---|
| 5845 | | - dev->ib_dev.detach_mcast = mlx5_ib_mcg_detach; |
|---|
| 5846 | | - dev->ib_dev.process_mad = mlx5_ib_process_mad; |
|---|
| 5847 | | - dev->ib_dev.alloc_mr = mlx5_ib_alloc_mr; |
|---|
| 5848 | | - dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg; |
|---|
| 5849 | | - dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status; |
|---|
| 5850 | | - dev->ib_dev.get_dev_fw_str = get_dev_fw_str; |
|---|
| 5851 | | - dev->ib_dev.get_vector_affinity = mlx5_ib_get_vector_affinity; |
|---|
| 5852 | | - if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads)) |
|---|
| 5853 | | - dev->ib_dev.alloc_rdma_netdev = mlx5_ib_alloc_rdma_netdev; |
|---|
| 5854 | | - |
|---|
| 5855 | | - if (mlx5_core_is_pf(mdev)) { |
|---|
| 5856 | | - dev->ib_dev.get_vf_config = mlx5_ib_get_vf_config; |
|---|
| 5857 | | - dev->ib_dev.set_vf_link_state = mlx5_ib_set_vf_link_state; |
|---|
| 5858 | | - dev->ib_dev.get_vf_stats = mlx5_ib_get_vf_stats; |
|---|
| 5859 | | - dev->ib_dev.set_vf_guid = mlx5_ib_set_vf_guid; |
|---|
| 5860 | | - } |
|---|
| 5861 | | - |
|---|
| 5862 | | - dev->ib_dev.disassociate_ucontext = mlx5_ib_disassociate_ucontext; |
|---|
| 5863 | | - |
|---|
| 5864 | | - dev->umr_fence = mlx5_get_umr_fence(MLX5_CAP_GEN(mdev, umr_fence)); |
|---|
| 5865 | | - |
|---|
| 5866 | | - if (MLX5_CAP_GEN(mdev, imaicl)) { |
|---|
| 5867 | | - dev->ib_dev.alloc_mw = mlx5_ib_alloc_mw; |
|---|
| 5868 | | - dev->ib_dev.dealloc_mw = mlx5_ib_dealloc_mw; |
|---|
| 5869 | | - dev->ib_dev.uverbs_cmd_mask |= |
|---|
| 5870 | | - (1ull << IB_USER_VERBS_CMD_ALLOC_MW) | |
|---|
| 5871 | | - (1ull << IB_USER_VERBS_CMD_DEALLOC_MW); |
|---|
| 5872 | | - } |
|---|
| 5873 | | - |
|---|
| 5874 | | - if (MLX5_CAP_GEN(mdev, xrc)) { |
|---|
| 5875 | | - dev->ib_dev.alloc_xrcd = mlx5_ib_alloc_xrcd; |
|---|
| 5876 | | - dev->ib_dev.dealloc_xrcd = mlx5_ib_dealloc_xrcd; |
|---|
| 5877 | | - dev->ib_dev.uverbs_cmd_mask |= |
|---|
| 5878 | | - (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) | |
|---|
| 5879 | | - (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD); |
|---|
| 5880 | | - } |
|---|
| 5881 | | - |
|---|
| 5882 | | - if (MLX5_CAP_DEV_MEM(mdev, memic)) { |
|---|
| 5883 | | - dev->ib_dev.alloc_dm = mlx5_ib_alloc_dm; |
|---|
| 5884 | | - dev->ib_dev.dealloc_dm = mlx5_ib_dealloc_dm; |
|---|
| 5885 | | - dev->ib_dev.reg_dm_mr = mlx5_ib_reg_dm_mr; |
|---|
| 5886 | | - } |
|---|
| 5887 | | - |
|---|
| 5888 | | - dev->ib_dev.create_flow = mlx5_ib_create_flow; |
|---|
| 5889 | | - dev->ib_dev.destroy_flow = mlx5_ib_destroy_flow; |
|---|
| 5890 | | - dev->ib_dev.uverbs_ex_cmd_mask |= |
|---|
| 5891 | | - (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) | |
|---|
| 5892 | | - (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW); |
|---|
| 5893 | | - dev->ib_dev.create_flow_action_esp = mlx5_ib_create_flow_action_esp; |
|---|
| 5894 | | - dev->ib_dev.destroy_flow_action = mlx5_ib_destroy_flow_action; |
|---|
| 5895 | | - dev->ib_dev.modify_flow_action_esp = mlx5_ib_modify_flow_action_esp; |
|---|
| 5896 | | - dev->ib_dev.driver_id = RDMA_DRIVER_MLX5; |
|---|
| 5897 | | - dev->ib_dev.create_counters = mlx5_ib_create_counters; |
|---|
| 5898 | | - dev->ib_dev.destroy_counters = mlx5_ib_destroy_counters; |
|---|
| 5899 | | - dev->ib_dev.read_counters = mlx5_ib_read_counters; |
|---|
| 5900 | | - |
|---|
| 5901 | | - err = init_node_data(dev); |
|---|
| 5902 | | - if (err) |
|---|
| 5903 | | - return err; |
|---|
| 5904 | | - |
|---|
| 5905 | | - if ((MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) && |
|---|
| 5906 | | - (MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) || |
|---|
| 5907 | | - MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc))) |
|---|
| 5908 | | - mutex_init(&dev->lb_mutex); |
|---|
| 5909 | | - |
|---|
| 5910 | | - return 0; |
|---|
| 5911 | | -} |
|---|
| 5912 | | - |
|---|
| 5913 | | -static int mlx5_ib_stage_non_default_cb(struct mlx5_ib_dev *dev) |
|---|
| 5914 | | -{ |
|---|
| 5915 | | - dev->ib_dev.get_port_immutable = mlx5_port_immutable; |
|---|
| 5916 | | - dev->ib_dev.query_port = mlx5_ib_query_port; |
|---|
| 5917 | | - |
|---|
| 5918 | | - return 0; |
|---|
| 5919 | | -} |
|---|
| 5920 | | - |
|---|
| 5921 | | -int mlx5_ib_stage_rep_non_default_cb(struct mlx5_ib_dev *dev) |
|---|
| 5922 | | -{ |
|---|
| 5923 | | - dev->ib_dev.get_port_immutable = mlx5_port_rep_immutable; |
|---|
| 5924 | | - dev->ib_dev.query_port = mlx5_ib_rep_query_port; |
|---|
| 5925 | | - |
|---|
| 5926 | | - return 0; |
|---|
| 5927 | | -} |
|---|
| 5928 | | - |
|---|
| 5929 | | -static int mlx5_ib_stage_common_roce_init(struct mlx5_ib_dev *dev) |
|---|
| 5930 | | -{ |
|---|
| 5931 | | - u8 port_num; |
|---|
| 5932 | | - int i; |
|---|
| 5933 | | - |
|---|
| 5934 | | - for (i = 0; i < dev->num_ports; i++) { |
|---|
| 5935 | | - dev->roce[i].dev = dev; |
|---|
| 5936 | | - dev->roce[i].native_port_num = i + 1; |
|---|
| 5937 | | - dev->roce[i].last_port_state = IB_PORT_DOWN; |
|---|
| 5938 | | - } |
|---|
| 5939 | | - |
|---|
| 5940 | | - dev->ib_dev.get_netdev = mlx5_ib_get_netdev; |
|---|
| 5941 | | - dev->ib_dev.create_wq = mlx5_ib_create_wq; |
|---|
| 5942 | | - dev->ib_dev.modify_wq = mlx5_ib_modify_wq; |
|---|
| 5943 | | - dev->ib_dev.destroy_wq = mlx5_ib_destroy_wq; |
|---|
| 5944 | | - dev->ib_dev.create_rwq_ind_table = mlx5_ib_create_rwq_ind_table; |
|---|
| 5945 | | - dev->ib_dev.destroy_rwq_ind_table = mlx5_ib_destroy_rwq_ind_table; |
|---|
| 5946 | | - |
|---|
| 5947 | | - dev->ib_dev.uverbs_ex_cmd_mask |= |
|---|
| 5948 | | - (1ull << IB_USER_VERBS_EX_CMD_CREATE_WQ) | |
|---|
| 5949 | | - (1ull << IB_USER_VERBS_EX_CMD_MODIFY_WQ) | |
|---|
| 5950 | | - (1ull << IB_USER_VERBS_EX_CMD_DESTROY_WQ) | |
|---|
| 5951 | | - (1ull << IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) | |
|---|
| 5952 | | - (1ull << IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL); |
|---|
| 5953 | | - |
|---|
| 5954 | | - port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
|---|
| 5955 | | - |
|---|
| 5956 | | - return mlx5_add_netdev_notifier(dev, port_num); |
|---|
| 5957 | | -} |
|---|
| 5958 | | - |
|---|
| 5959 | | -static void mlx5_ib_stage_common_roce_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 5960 | | -{ |
|---|
| 5961 | | - u8 port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
|---|
| 5962 | | - |
|---|
| 5963 | | - mlx5_remove_netdev_notifier(dev, port_num); |
|---|
| 5964 | | -} |
|---|
| 5965 | | - |
|---|
| 5966 | | -int mlx5_ib_stage_rep_roce_init(struct mlx5_ib_dev *dev) |
|---|
| 5967 | | -{ |
|---|
| 5968 | | - struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 5969 | | - enum rdma_link_layer ll; |
|---|
| 5970 | | - int port_type_cap; |
|---|
| 5971 | | - int err = 0; |
|---|
| 5972 | | - |
|---|
| 5973 | | - port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
|---|
| 5974 | | - ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
|---|
| 5975 | | - |
|---|
| 5976 | | - if (ll == IB_LINK_LAYER_ETHERNET) |
|---|
| 5977 | | - err = mlx5_ib_stage_common_roce_init(dev); |
|---|
| 5978 | | - |
|---|
| 5979 | | - return err; |
|---|
| 5980 | | -} |
|---|
| 5981 | | - |
|---|
| 5982 | | -void mlx5_ib_stage_rep_roce_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 5983 | | -{ |
|---|
| 5984 | | - mlx5_ib_stage_common_roce_cleanup(dev); |
|---|
| 5985 | | -} |
|---|
| 5986 | | - |
|---|
| 5987 | | -static int mlx5_ib_stage_roce_init(struct mlx5_ib_dev *dev) |
|---|
| 5988 | | -{ |
|---|
| 5989 | | - struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 5990 | | - enum rdma_link_layer ll; |
|---|
| 5991 | | - int port_type_cap; |
|---|
| 5992 | | - int err; |
|---|
| 5993 | | - |
|---|
| 5994 | | - port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
|---|
| 5995 | | - ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
|---|
| 5996 | | - |
|---|
| 5997 | | - if (ll == IB_LINK_LAYER_ETHERNET) { |
|---|
| 5998 | | - err = mlx5_ib_stage_common_roce_init(dev); |
|---|
| 5999 | | - if (err) |
|---|
| 6000 | | - return err; |
|---|
| 6001 | | - |
|---|
| 6002 | | - err = mlx5_enable_eth(dev); |
|---|
| 6003 | | - if (err) |
|---|
| 6004 | | - goto cleanup; |
|---|
| 6005 | | - } |
|---|
| 6006 | | - |
|---|
| 6007 | | - return 0; |
|---|
| 6008 | | -cleanup: |
|---|
| 6009 | | - mlx5_ib_stage_common_roce_cleanup(dev); |
|---|
| 6010 | | - |
|---|
| 6011 | | - return err; |
|---|
| 6012 | | -} |
|---|
| 6013 | | - |
|---|
| 6014 | | -static void mlx5_ib_stage_roce_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6015 | | -{ |
|---|
| 6016 | | - struct mlx5_core_dev *mdev = dev->mdev; |
|---|
| 6017 | | - enum rdma_link_layer ll; |
|---|
| 6018 | | - int port_type_cap; |
|---|
| 6019 | | - |
|---|
| 6020 | | - port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
|---|
| 6021 | | - ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
|---|
| 6022 | | - |
|---|
| 6023 | | - if (ll == IB_LINK_LAYER_ETHERNET) { |
|---|
| 6024 | | - mlx5_disable_eth(dev); |
|---|
| 6025 | | - mlx5_ib_stage_common_roce_cleanup(dev); |
|---|
| 6026 | | - } |
|---|
| 6027 | | -} |
|---|
| 6028 | | - |
|---|
| 6029 | | -int mlx5_ib_stage_dev_res_init(struct mlx5_ib_dev *dev) |
|---|
| 6030 | | -{ |
|---|
| 6031 | | - return create_dev_resources(&dev->devr); |
|---|
| 6032 | | -} |
|---|
| 6033 | | - |
|---|
| 6034 | | -void mlx5_ib_stage_dev_res_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6035 | | -{ |
|---|
| 6036 | | - destroy_dev_resources(&dev->devr); |
|---|
| 6037 | | -} |
|---|
| 6038 | | - |
|---|
| 6039 | | -static int mlx5_ib_stage_odp_init(struct mlx5_ib_dev *dev) |
|---|
| 6040 | | -{ |
|---|
| 6041 | | - mlx5_ib_internal_fill_odp_caps(dev); |
|---|
| 6042 | | - |
|---|
| 6043 | | - return mlx5_ib_odp_init_one(dev); |
|---|
| 6044 | | -} |
|---|
| 6045 | | - |
|---|
| 6046 | | -int mlx5_ib_stage_counters_init(struct mlx5_ib_dev *dev) |
|---|
| 6047 | | -{ |
|---|
| 6048 | | - if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) { |
|---|
| 6049 | | - dev->ib_dev.get_hw_stats = mlx5_ib_get_hw_stats; |
|---|
| 6050 | | - dev->ib_dev.alloc_hw_stats = mlx5_ib_alloc_hw_stats; |
|---|
| 6051 | | - |
|---|
| 6052 | | - return mlx5_ib_alloc_counters(dev); |
|---|
| 6053 | | - } |
|---|
| 6054 | | - |
|---|
| 6055 | | - return 0; |
|---|
| 6056 | | -} |
|---|
| 6057 | | - |
|---|
| 6058 | | -void mlx5_ib_stage_counters_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6059 | | -{ |
|---|
| 6060 | | - if (MLX5_CAP_GEN(dev->mdev, max_qp_cnt)) |
|---|
| 6061 | | - mlx5_ib_dealloc_counters(dev); |
|---|
| 6062 | | -} |
|---|
| 6063 | | - |
|---|
| 6064 | | -static int mlx5_ib_stage_cong_debugfs_init(struct mlx5_ib_dev *dev) |
|---|
| 6065 | | -{ |
|---|
| 6066 | | - return mlx5_ib_init_cong_debugfs(dev, |
|---|
| 6067 | | - mlx5_core_native_port_num(dev->mdev) - 1); |
|---|
| 6068 | | -} |
|---|
| 6069 | | - |
|---|
| 6070 | | -static void mlx5_ib_stage_cong_debugfs_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6071 | | -{ |
|---|
| 6072 | | - mlx5_ib_cleanup_cong_debugfs(dev, |
|---|
| 6073 | | - mlx5_core_native_port_num(dev->mdev) - 1); |
|---|
| 6074 | | -} |
|---|
| 6075 | | - |
|---|
| 6076 | | -static int mlx5_ib_stage_uar_init(struct mlx5_ib_dev *dev) |
|---|
| 6077 | | -{ |
|---|
| 6078 | | - dev->mdev->priv.uar = mlx5_get_uars_page(dev->mdev); |
|---|
| 6079 | | - return PTR_ERR_OR_ZERO(dev->mdev->priv.uar); |
|---|
| 6080 | | -} |
|---|
| 6081 | | - |
|---|
| 6082 | | -static void mlx5_ib_stage_uar_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6083 | | -{ |
|---|
| 6084 | | - mlx5_put_uars_page(dev->mdev, dev->mdev->priv.uar); |
|---|
| 6085 | | -} |
|---|
| 6086 | | - |
|---|
| 6087 | | -int mlx5_ib_stage_bfrag_init(struct mlx5_ib_dev *dev) |
|---|
| 6088 | | -{ |
|---|
| 6089 | | - int err; |
|---|
| 6090 | | - |
|---|
| 6091 | | - err = mlx5_alloc_bfreg(dev->mdev, &dev->bfreg, false, false); |
|---|
| 6092 | | - if (err) |
|---|
| 6093 | | - return err; |
|---|
| 6094 | | - |
|---|
| 6095 | | - err = mlx5_alloc_bfreg(dev->mdev, &dev->fp_bfreg, false, true); |
|---|
| 6096 | | - if (err) |
|---|
| 6097 | | - mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
|---|
| 6098 | | - |
|---|
| 6099 | | - return err; |
|---|
| 6100 | | -} |
|---|
| 6101 | | - |
|---|
| 6102 | | -void mlx5_ib_stage_bfrag_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6103 | | -{ |
|---|
| 6104 | | - mlx5_free_bfreg(dev->mdev, &dev->fp_bfreg); |
|---|
| 6105 | | - mlx5_free_bfreg(dev->mdev, &dev->bfreg); |
|---|
| 6106 | | -} |
|---|
| 6107 | | - |
|---|
| 6108 | | -static int mlx5_ib_stage_populate_specs(struct mlx5_ib_dev *dev) |
|---|
| 6109 | | -{ |
|---|
| 6110 | | - return populate_specs_root(dev); |
|---|
| 6111 | | -} |
|---|
| 6112 | | - |
|---|
| 6113 | | -int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev) |
|---|
| 6114 | | -{ |
|---|
| 6115 | | - return ib_register_device(&dev->ib_dev, NULL); |
|---|
| 6116 | | -} |
|---|
| 6117 | | - |
|---|
| 6118 | | -void mlx5_ib_stage_pre_ib_reg_umr_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6119 | | -{ |
|---|
| 6120 | | - destroy_umrc_res(dev); |
|---|
| 6121 | | -} |
|---|
| 6122 | | - |
|---|
| 6123 | | -void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6124 | | -{ |
|---|
| 6125 | | - ib_unregister_device(&dev->ib_dev); |
|---|
| 6126 | | -} |
|---|
| 6127 | | - |
|---|
| 6128 | | -int mlx5_ib_stage_post_ib_reg_umr_init(struct mlx5_ib_dev *dev) |
|---|
| 6129 | | -{ |
|---|
| 6130 | | - return create_umr_res(dev); |
|---|
| 6131 | | -} |
|---|
| 6132 | | - |
|---|
| 6133 | | -static int mlx5_ib_stage_delay_drop_init(struct mlx5_ib_dev *dev) |
|---|
| 6134 | | -{ |
|---|
| 6135 | | - init_delay_drop(dev); |
|---|
| 6136 | | - |
|---|
| 4547 | + debugfs_create_atomic_t("num_timeout_events", 0400, root, |
|---|
| 4548 | + &dev->delay_drop.events_cnt); |
|---|
| 4549 | + debugfs_create_atomic_t("num_rqs", 0400, root, |
|---|
| 4550 | + &dev->delay_drop.rqs_cnt); |
|---|
| 4551 | + debugfs_create_file("timeout", 0600, root, &dev->delay_drop, |
|---|
| 4552 | + &fops_delay_drop_timeout); |
|---|
| 6137 | 4553 | return 0; |
|---|
| 6138 | 4554 | } |
|---|
| 6139 | 4555 | |
|---|
| 6140 | 4556 | static void mlx5_ib_stage_delay_drop_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6141 | 4557 | { |
|---|
| 6142 | | - cancel_delay_drop(dev); |
|---|
| 4558 | + if (!(dev->ib_dev.attrs.raw_packet_caps & IB_RAW_PACKET_CAP_DELAY_DROP)) |
|---|
| 4559 | + return; |
|---|
| 4560 | + |
|---|
| 4561 | + cancel_work_sync(&dev->delay_drop.delay_drop_work); |
|---|
| 4562 | + if (!dev->delay_drop.dir_debugfs) |
|---|
| 4563 | + return; |
|---|
| 4564 | + |
|---|
| 4565 | + debugfs_remove_recursive(dev->delay_drop.dir_debugfs); |
|---|
| 4566 | + dev->delay_drop.dir_debugfs = NULL; |
|---|
| 6143 | 4567 | } |
|---|
| 6144 | 4568 | |
|---|
| 6145 | | -int mlx5_ib_stage_class_attr_init(struct mlx5_ib_dev *dev) |
|---|
| 4569 | +static int mlx5_ib_stage_dev_notifier_init(struct mlx5_ib_dev *dev) |
|---|
| 6146 | 4570 | { |
|---|
| 6147 | | - int err; |
|---|
| 6148 | | - int i; |
|---|
| 6149 | | - |
|---|
| 6150 | | - for (i = 0; i < ARRAY_SIZE(mlx5_class_attributes); i++) { |
|---|
| 6151 | | - err = device_create_file(&dev->ib_dev.dev, |
|---|
| 6152 | | - mlx5_class_attributes[i]); |
|---|
| 6153 | | - if (err) |
|---|
| 6154 | | - return err; |
|---|
| 6155 | | - } |
|---|
| 6156 | | - |
|---|
| 4571 | + dev->mdev_events.notifier_call = mlx5_ib_event; |
|---|
| 4572 | + mlx5_notifier_register(dev->mdev, &dev->mdev_events); |
|---|
| 6157 | 4573 | return 0; |
|---|
| 6158 | 4574 | } |
|---|
| 6159 | 4575 | |
|---|
| 6160 | | -static int mlx5_ib_stage_rep_reg_init(struct mlx5_ib_dev *dev) |
|---|
| 4576 | +static void mlx5_ib_stage_dev_notifier_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6161 | 4577 | { |
|---|
| 6162 | | - mlx5_ib_register_vport_reps(dev); |
|---|
| 6163 | | - |
|---|
| 6164 | | - return 0; |
|---|
| 6165 | | -} |
|---|
| 6166 | | - |
|---|
| 6167 | | -static void mlx5_ib_stage_rep_reg_cleanup(struct mlx5_ib_dev *dev) |
|---|
| 6168 | | -{ |
|---|
| 6169 | | - mlx5_ib_unregister_vport_reps(dev); |
|---|
| 4578 | + mlx5_notifier_unregister(dev->mdev, &dev->mdev_events); |
|---|
| 6170 | 4579 | } |
|---|
| 6171 | 4580 | |
|---|
| 6172 | 4581 | void __mlx5_ib_remove(struct mlx5_ib_dev *dev, |
|---|
| 6173 | 4582 | const struct mlx5_ib_profile *profile, |
|---|
| 6174 | 4583 | int stage) |
|---|
| 6175 | 4584 | { |
|---|
| 4585 | + dev->ib_active = false; |
|---|
| 4586 | + |
|---|
| 6176 | 4587 | /* Number of stages to cleanup */ |
|---|
| 6177 | 4588 | while (stage) { |
|---|
| 6178 | 4589 | stage--; |
|---|
| .. | .. |
|---|
| 6180 | 4591 | profile->stage[stage].cleanup(dev); |
|---|
| 6181 | 4592 | } |
|---|
| 6182 | 4593 | |
|---|
| 6183 | | - ib_dealloc_device((struct ib_device *)dev); |
|---|
| 4594 | + kfree(dev->port); |
|---|
| 4595 | + ib_dealloc_device(&dev->ib_dev); |
|---|
| 6184 | 4596 | } |
|---|
| 6185 | 4597 | |
|---|
| 6186 | 4598 | void *__mlx5_ib_add(struct mlx5_ib_dev *dev, |
|---|
| .. | .. |
|---|
| 6189 | 4601 | int err; |
|---|
| 6190 | 4602 | int i; |
|---|
| 6191 | 4603 | |
|---|
| 6192 | | - printk_once(KERN_INFO "%s", mlx5_version); |
|---|
| 4604 | + dev->profile = profile; |
|---|
| 6193 | 4605 | |
|---|
| 6194 | 4606 | for (i = 0; i < MLX5_IB_STAGE_MAX; i++) { |
|---|
| 6195 | 4607 | if (profile->stage[i].init) { |
|---|
| .. | .. |
|---|
| 6199 | 4611 | } |
|---|
| 6200 | 4612 | } |
|---|
| 6201 | 4613 | |
|---|
| 6202 | | - dev->profile = profile; |
|---|
| 6203 | 4614 | dev->ib_active = true; |
|---|
| 6204 | 4615 | |
|---|
| 6205 | 4616 | return dev; |
|---|
| .. | .. |
|---|
| 6214 | 4625 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
|---|
| 6215 | 4626 | mlx5_ib_stage_init_init, |
|---|
| 6216 | 4627 | mlx5_ib_stage_init_cleanup), |
|---|
| 6217 | | - STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
|---|
| 6218 | | - mlx5_ib_stage_flow_db_init, |
|---|
| 6219 | | - mlx5_ib_stage_flow_db_cleanup), |
|---|
| 4628 | + STAGE_CREATE(MLX5_IB_STAGE_FS, |
|---|
| 4629 | + mlx5_ib_fs_init, |
|---|
| 4630 | + mlx5_ib_fs_cleanup), |
|---|
| 6220 | 4631 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
|---|
| 6221 | 4632 | mlx5_ib_stage_caps_init, |
|---|
| 6222 | | - NULL), |
|---|
| 4633 | + mlx5_ib_stage_caps_cleanup), |
|---|
| 6223 | 4634 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
|---|
| 6224 | 4635 | mlx5_ib_stage_non_default_cb, |
|---|
| 6225 | 4636 | NULL), |
|---|
| 6226 | 4637 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
|---|
| 6227 | | - mlx5_ib_stage_roce_init, |
|---|
| 6228 | | - mlx5_ib_stage_roce_cleanup), |
|---|
| 4638 | + mlx5_ib_roce_init, |
|---|
| 4639 | + mlx5_ib_roce_cleanup), |
|---|
| 4640 | + STAGE_CREATE(MLX5_IB_STAGE_QP, |
|---|
| 4641 | + mlx5_init_qp_table, |
|---|
| 4642 | + mlx5_cleanup_qp_table), |
|---|
| 4643 | + STAGE_CREATE(MLX5_IB_STAGE_SRQ, |
|---|
| 4644 | + mlx5_init_srq_table, |
|---|
| 4645 | + mlx5_cleanup_srq_table), |
|---|
| 6229 | 4646 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
|---|
| 6230 | | - mlx5_ib_stage_dev_res_init, |
|---|
| 6231 | | - mlx5_ib_stage_dev_res_cleanup), |
|---|
| 4647 | + mlx5_ib_dev_res_init, |
|---|
| 4648 | + mlx5_ib_dev_res_cleanup), |
|---|
| 4649 | + STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER, |
|---|
| 4650 | + mlx5_ib_stage_dev_notifier_init, |
|---|
| 4651 | + mlx5_ib_stage_dev_notifier_cleanup), |
|---|
| 6232 | 4652 | STAGE_CREATE(MLX5_IB_STAGE_ODP, |
|---|
| 6233 | | - mlx5_ib_stage_odp_init, |
|---|
| 6234 | | - NULL), |
|---|
| 4653 | + mlx5_ib_odp_init_one, |
|---|
| 4654 | + mlx5_ib_odp_cleanup_one), |
|---|
| 6235 | 4655 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
|---|
| 6236 | | - mlx5_ib_stage_counters_init, |
|---|
| 6237 | | - mlx5_ib_stage_counters_cleanup), |
|---|
| 4656 | + mlx5_ib_counters_init, |
|---|
| 4657 | + mlx5_ib_counters_cleanup), |
|---|
| 6238 | 4658 | STAGE_CREATE(MLX5_IB_STAGE_CONG_DEBUGFS, |
|---|
| 6239 | 4659 | mlx5_ib_stage_cong_debugfs_init, |
|---|
| 6240 | 4660 | mlx5_ib_stage_cong_debugfs_cleanup), |
|---|
| .. | .. |
|---|
| 6247 | 4667 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
|---|
| 6248 | 4668 | NULL, |
|---|
| 6249 | 4669 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
|---|
| 6250 | | - STAGE_CREATE(MLX5_IB_STAGE_SPECS, |
|---|
| 6251 | | - mlx5_ib_stage_populate_specs, |
|---|
| 6252 | | - NULL), |
|---|
| 4670 | + STAGE_CREATE(MLX5_IB_STAGE_WHITELIST_UID, |
|---|
| 4671 | + mlx5_ib_devx_init, |
|---|
| 4672 | + mlx5_ib_devx_cleanup), |
|---|
| 6253 | 4673 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
|---|
| 6254 | 4674 | mlx5_ib_stage_ib_reg_init, |
|---|
| 6255 | 4675 | mlx5_ib_stage_ib_reg_cleanup), |
|---|
| .. | .. |
|---|
| 6259 | 4679 | STAGE_CREATE(MLX5_IB_STAGE_DELAY_DROP, |
|---|
| 6260 | 4680 | mlx5_ib_stage_delay_drop_init, |
|---|
| 6261 | 4681 | mlx5_ib_stage_delay_drop_cleanup), |
|---|
| 6262 | | - STAGE_CREATE(MLX5_IB_STAGE_CLASS_ATTR, |
|---|
| 6263 | | - mlx5_ib_stage_class_attr_init, |
|---|
| 4682 | + STAGE_CREATE(MLX5_IB_STAGE_RESTRACK, |
|---|
| 4683 | + mlx5_ib_restrack_init, |
|---|
| 6264 | 4684 | NULL), |
|---|
| 6265 | 4685 | }; |
|---|
| 6266 | 4686 | |
|---|
| 6267 | | -static const struct mlx5_ib_profile nic_rep_profile = { |
|---|
| 4687 | +const struct mlx5_ib_profile raw_eth_profile = { |
|---|
| 6268 | 4688 | STAGE_CREATE(MLX5_IB_STAGE_INIT, |
|---|
| 6269 | 4689 | mlx5_ib_stage_init_init, |
|---|
| 6270 | 4690 | mlx5_ib_stage_init_cleanup), |
|---|
| 6271 | | - STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB, |
|---|
| 6272 | | - mlx5_ib_stage_flow_db_init, |
|---|
| 6273 | | - mlx5_ib_stage_flow_db_cleanup), |
|---|
| 4691 | + STAGE_CREATE(MLX5_IB_STAGE_FS, |
|---|
| 4692 | + mlx5_ib_fs_init, |
|---|
| 4693 | + mlx5_ib_fs_cleanup), |
|---|
| 6274 | 4694 | STAGE_CREATE(MLX5_IB_STAGE_CAPS, |
|---|
| 6275 | 4695 | mlx5_ib_stage_caps_init, |
|---|
| 6276 | | - NULL), |
|---|
| 4696 | + mlx5_ib_stage_caps_cleanup), |
|---|
| 6277 | 4697 | STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB, |
|---|
| 6278 | | - mlx5_ib_stage_rep_non_default_cb, |
|---|
| 4698 | + mlx5_ib_stage_raw_eth_non_default_cb, |
|---|
| 6279 | 4699 | NULL), |
|---|
| 6280 | 4700 | STAGE_CREATE(MLX5_IB_STAGE_ROCE, |
|---|
| 6281 | | - mlx5_ib_stage_rep_roce_init, |
|---|
| 6282 | | - mlx5_ib_stage_rep_roce_cleanup), |
|---|
| 4701 | + mlx5_ib_roce_init, |
|---|
| 4702 | + mlx5_ib_roce_cleanup), |
|---|
| 4703 | + STAGE_CREATE(MLX5_IB_STAGE_QP, |
|---|
| 4704 | + mlx5_init_qp_table, |
|---|
| 4705 | + mlx5_cleanup_qp_table), |
|---|
| 4706 | + STAGE_CREATE(MLX5_IB_STAGE_SRQ, |
|---|
| 4707 | + mlx5_init_srq_table, |
|---|
| 4708 | + mlx5_cleanup_srq_table), |
|---|
| 6283 | 4709 | STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES, |
|---|
| 6284 | | - mlx5_ib_stage_dev_res_init, |
|---|
| 6285 | | - mlx5_ib_stage_dev_res_cleanup), |
|---|
| 4710 | + mlx5_ib_dev_res_init, |
|---|
| 4711 | + mlx5_ib_dev_res_cleanup), |
|---|
| 4712 | + STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER, |
|---|
| 4713 | + mlx5_ib_stage_dev_notifier_init, |
|---|
| 4714 | + mlx5_ib_stage_dev_notifier_cleanup), |
|---|
| 6286 | 4715 | STAGE_CREATE(MLX5_IB_STAGE_COUNTERS, |
|---|
| 6287 | | - mlx5_ib_stage_counters_init, |
|---|
| 6288 | | - mlx5_ib_stage_counters_cleanup), |
|---|
| 4716 | + mlx5_ib_counters_init, |
|---|
| 4717 | + mlx5_ib_counters_cleanup), |
|---|
| 4718 | + STAGE_CREATE(MLX5_IB_STAGE_CONG_DEBUGFS, |
|---|
| 4719 | + mlx5_ib_stage_cong_debugfs_init, |
|---|
| 4720 | + mlx5_ib_stage_cong_debugfs_cleanup), |
|---|
| 6289 | 4721 | STAGE_CREATE(MLX5_IB_STAGE_UAR, |
|---|
| 6290 | 4722 | mlx5_ib_stage_uar_init, |
|---|
| 6291 | 4723 | mlx5_ib_stage_uar_cleanup), |
|---|
| .. | .. |
|---|
| 6295 | 4727 | STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR, |
|---|
| 6296 | 4728 | NULL, |
|---|
| 6297 | 4729 | mlx5_ib_stage_pre_ib_reg_umr_cleanup), |
|---|
| 6298 | | - STAGE_CREATE(MLX5_IB_STAGE_SPECS, |
|---|
| 6299 | | - mlx5_ib_stage_populate_specs, |
|---|
| 6300 | | - NULL), |
|---|
| 4730 | + STAGE_CREATE(MLX5_IB_STAGE_WHITELIST_UID, |
|---|
| 4731 | + mlx5_ib_devx_init, |
|---|
| 4732 | + mlx5_ib_devx_cleanup), |
|---|
| 6301 | 4733 | STAGE_CREATE(MLX5_IB_STAGE_IB_REG, |
|---|
| 6302 | 4734 | mlx5_ib_stage_ib_reg_init, |
|---|
| 6303 | 4735 | mlx5_ib_stage_ib_reg_cleanup), |
|---|
| 6304 | 4736 | STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR, |
|---|
| 6305 | 4737 | mlx5_ib_stage_post_ib_reg_umr_init, |
|---|
| 6306 | 4738 | NULL), |
|---|
| 6307 | | - STAGE_CREATE(MLX5_IB_STAGE_CLASS_ATTR, |
|---|
| 6308 | | - mlx5_ib_stage_class_attr_init, |
|---|
| 4739 | + STAGE_CREATE(MLX5_IB_STAGE_DELAY_DROP, |
|---|
| 4740 | + mlx5_ib_stage_delay_drop_init, |
|---|
| 4741 | + mlx5_ib_stage_delay_drop_cleanup), |
|---|
| 4742 | + STAGE_CREATE(MLX5_IB_STAGE_RESTRACK, |
|---|
| 4743 | + mlx5_ib_restrack_init, |
|---|
| 6309 | 4744 | NULL), |
|---|
| 6310 | | - STAGE_CREATE(MLX5_IB_STAGE_REP_REG, |
|---|
| 6311 | | - mlx5_ib_stage_rep_reg_init, |
|---|
| 6312 | | - mlx5_ib_stage_rep_reg_cleanup), |
|---|
| 6313 | 4745 | }; |
|---|
| 6314 | 4746 | |
|---|
| 6315 | 4747 | static void *mlx5_ib_add_slave_port(struct mlx5_core_dev *mdev) |
|---|
| .. | .. |
|---|
| 6346 | 4778 | |
|---|
| 6347 | 4779 | if (!bound) { |
|---|
| 6348 | 4780 | list_add_tail(&mpi->list, &mlx5_ib_unaffiliated_port_list); |
|---|
| 6349 | | - dev_dbg(&mdev->pdev->dev, "no suitable IB device found to bind to, added to unaffiliated list.\n"); |
|---|
| 4781 | + dev_dbg(mdev->device, |
|---|
| 4782 | + "no suitable IB device found to bind to, added to unaffiliated list.\n"); |
|---|
| 6350 | 4783 | } |
|---|
| 6351 | 4784 | mutex_unlock(&mlx5_ib_multiport_mutex); |
|---|
| 6352 | 4785 | |
|---|
| .. | .. |
|---|
| 6355 | 4788 | |
|---|
| 6356 | 4789 | static void *mlx5_ib_add(struct mlx5_core_dev *mdev) |
|---|
| 6357 | 4790 | { |
|---|
| 4791 | + const struct mlx5_ib_profile *profile; |
|---|
| 6358 | 4792 | enum rdma_link_layer ll; |
|---|
| 6359 | 4793 | struct mlx5_ib_dev *dev; |
|---|
| 6360 | 4794 | int port_type_cap; |
|---|
| 4795 | + int num_ports; |
|---|
| 6361 | 4796 | |
|---|
| 6362 | | - printk_once(KERN_INFO "%s", mlx5_version); |
|---|
| 4797 | + if (MLX5_ESWITCH_MANAGER(mdev) && |
|---|
| 4798 | + mlx5_ib_eswitch_mode(mdev->priv.eswitch) == MLX5_ESWITCH_OFFLOADS) { |
|---|
| 4799 | + if (!mlx5_core_mp_enabled(mdev)) |
|---|
| 4800 | + mlx5_ib_register_vport_reps(mdev); |
|---|
| 4801 | + return mdev; |
|---|
| 4802 | + } |
|---|
| 6363 | 4803 | |
|---|
| 6364 | 4804 | port_type_cap = MLX5_CAP_GEN(mdev, port_type); |
|---|
| 6365 | 4805 | ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap); |
|---|
| .. | .. |
|---|
| 6367 | 4807 | if (mlx5_core_is_mp_slave(mdev) && ll == IB_LINK_LAYER_ETHERNET) |
|---|
| 6368 | 4808 | return mlx5_ib_add_slave_port(mdev); |
|---|
| 6369 | 4809 | |
|---|
| 6370 | | - dev = (struct mlx5_ib_dev *)ib_alloc_device(sizeof(*dev)); |
|---|
| 4810 | + num_ports = max(MLX5_CAP_GEN(mdev, num_ports), |
|---|
| 4811 | + MLX5_CAP_GEN(mdev, num_vhca_ports)); |
|---|
| 4812 | + dev = ib_alloc_device(mlx5_ib_dev, ib_dev); |
|---|
| 6371 | 4813 | if (!dev) |
|---|
| 6372 | 4814 | return NULL; |
|---|
| 6373 | | - |
|---|
| 6374 | | - dev->mdev = mdev; |
|---|
| 6375 | | - dev->num_ports = max(MLX5_CAP_GEN(mdev, num_ports), |
|---|
| 6376 | | - MLX5_CAP_GEN(mdev, num_vhca_ports)); |
|---|
| 6377 | | - |
|---|
| 6378 | | - if (MLX5_ESWITCH_MANAGER(mdev) && |
|---|
| 6379 | | - mlx5_ib_eswitch_mode(mdev->priv.eswitch) == SRIOV_OFFLOADS) { |
|---|
| 6380 | | - dev->rep = mlx5_ib_vport_rep(mdev->priv.eswitch, 0); |
|---|
| 6381 | | - |
|---|
| 6382 | | - return __mlx5_ib_add(dev, &nic_rep_profile); |
|---|
| 4815 | + dev->port = kcalloc(num_ports, sizeof(*dev->port), |
|---|
| 4816 | + GFP_KERNEL); |
|---|
| 4817 | + if (!dev->port) { |
|---|
| 4818 | + ib_dealloc_device(&dev->ib_dev); |
|---|
| 4819 | + return NULL; |
|---|
| 6383 | 4820 | } |
|---|
| 6384 | 4821 | |
|---|
| 6385 | | - return __mlx5_ib_add(dev, &pf_profile); |
|---|
| 4822 | + dev->mdev = mdev; |
|---|
| 4823 | + dev->num_ports = num_ports; |
|---|
| 4824 | + |
|---|
| 4825 | + if (ll == IB_LINK_LAYER_ETHERNET && !mlx5_is_roce_enabled(mdev)) |
|---|
| 4826 | + profile = &raw_eth_profile; |
|---|
| 4827 | + else |
|---|
| 4828 | + profile = &pf_profile; |
|---|
| 4829 | + |
|---|
| 4830 | + return __mlx5_ib_add(dev, profile); |
|---|
| 6386 | 4831 | } |
|---|
| 6387 | 4832 | |
|---|
| 6388 | 4833 | static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context) |
|---|
| 6389 | 4834 | { |
|---|
| 6390 | 4835 | struct mlx5_ib_multiport_info *mpi; |
|---|
| 6391 | 4836 | struct mlx5_ib_dev *dev; |
|---|
| 4837 | + |
|---|
| 4838 | + if (MLX5_ESWITCH_MANAGER(mdev) && context == mdev) { |
|---|
| 4839 | + mlx5_ib_unregister_vport_reps(mdev); |
|---|
| 4840 | + return; |
|---|
| 4841 | + } |
|---|
| 6392 | 4842 | |
|---|
| 6393 | 4843 | if (mlx5_core_is_mp_slave(mdev)) { |
|---|
| 6394 | 4844 | mpi = context; |
|---|
| .. | .. |
|---|
| 6408 | 4858 | static struct mlx5_interface mlx5_ib_interface = { |
|---|
| 6409 | 4859 | .add = mlx5_ib_add, |
|---|
| 6410 | 4860 | .remove = mlx5_ib_remove, |
|---|
| 6411 | | - .event = mlx5_ib_event, |
|---|
| 6412 | | -#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
|---|
| 6413 | | - .pfault = mlx5_ib_pfault, |
|---|
| 6414 | | -#endif |
|---|
| 6415 | 4861 | .protocol = MLX5_INTERFACE_PROTOCOL_IB, |
|---|
| 6416 | 4862 | }; |
|---|
| 6417 | 4863 | |
|---|