Yishai Hadas | a8b92ca | 2018-06-17 12:59:57 +0300 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
| 2 | /* |
| 3 | * Copyright (c) 2018, Mellanox Technologies inc. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #include <rdma/ib_user_verbs.h> |
| 7 | #include <rdma/ib_verbs.h> |
| 8 | #include <rdma/uverbs_types.h> |
| 9 | #include <rdma/uverbs_ioctl.h> |
| 10 | #include <rdma/mlx5_user_ioctl_cmds.h> |
| 11 | #include <rdma/ib_umem.h> |
| 12 | #include <linux/mlx5/driver.h> |
| 13 | #include <linux/mlx5/fs.h> |
| 14 | #include "mlx5_ib.h" |
| 15 | |
| 16 | int mlx5_ib_devx_create(struct mlx5_ib_dev *dev, struct mlx5_ib_ucontext *context) |
| 17 | { |
| 18 | u32 in[MLX5_ST_SZ_DW(create_uctx_in)] = {0}; |
| 19 | u32 out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0}; |
| 20 | u64 general_obj_types; |
| 21 | void *uctx; |
| 22 | void *hdr; |
| 23 | int err; |
| 24 | |
| 25 | uctx = MLX5_ADDR_OF(create_uctx_in, in, uctx); |
| 26 | hdr = MLX5_ADDR_OF(create_uctx_in, in, hdr); |
| 27 | |
| 28 | general_obj_types = MLX5_CAP_GEN_64(dev->mdev, general_obj_types); |
| 29 | if (!(general_obj_types & MLX5_GENERAL_OBJ_TYPES_CAP_UCTX) || |
| 30 | !(general_obj_types & MLX5_GENERAL_OBJ_TYPES_CAP_UMEM)) |
| 31 | return -EINVAL; |
| 32 | |
| 33 | if (!capable(CAP_NET_RAW)) |
| 34 | return -EPERM; |
| 35 | |
| 36 | MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode, MLX5_CMD_OP_CREATE_GENERAL_OBJECT); |
| 37 | MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type, MLX5_OBJ_TYPE_UCTX); |
| 38 | |
| 39 | err = mlx5_cmd_exec(dev->mdev, in, sizeof(in), out, sizeof(out)); |
| 40 | if (err) |
| 41 | return err; |
| 42 | |
| 43 | context->devx_uid = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id); |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | void mlx5_ib_devx_destroy(struct mlx5_ib_dev *dev, |
| 48 | struct mlx5_ib_ucontext *context) |
| 49 | { |
| 50 | u32 in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {0}; |
| 51 | u32 out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0}; |
| 52 | |
| 53 | MLX5_SET(general_obj_in_cmd_hdr, in, opcode, MLX5_CMD_OP_DESTROY_GENERAL_OBJECT); |
| 54 | MLX5_SET(general_obj_in_cmd_hdr, in, obj_type, MLX5_OBJ_TYPE_UCTX); |
| 55 | MLX5_SET(general_obj_in_cmd_hdr, in, obj_id, context->devx_uid); |
| 56 | |
| 57 | mlx5_cmd_exec(dev->mdev, in, sizeof(in), out, sizeof(out)); |
| 58 | } |