xref: /openbmc/linux/drivers/infiniband/hw/mlx5/dm.h (revision 2cf1c348)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /*
3  * Copyright (c) 2021, Mellanox Technologies inc. All rights reserved.
4  */
5 
6 #ifndef _MLX5_IB_DM_H
7 #define _MLX5_IB_DM_H
8 
9 #include "mlx5_ib.h"
10 
11 extern const struct ib_device_ops mlx5_ib_dev_dm_ops;
12 extern const struct uapi_definition mlx5_ib_dm_defs[];
13 
14 struct mlx5_ib_dm {
15 	struct ib_dm		ibdm;
16 	u32			type;
17 	phys_addr_t		dev_addr;
18 	size_t			size;
19 };
20 
21 struct mlx5_ib_dm_op_entry {
22 	struct mlx5_user_mmap_entry	mentry;
23 	phys_addr_t			op_addr;
24 	struct mlx5_ib_dm_memic		*dm;
25 	u8				op;
26 };
27 
28 struct mlx5_ib_dm_memic {
29 	struct mlx5_ib_dm           base;
30 	struct mlx5_user_mmap_entry mentry;
31 	struct xarray               ops;
32 	struct mutex                ops_xa_lock;
33 	struct kref                 ref;
34 	size_t                      req_length;
35 };
36 
37 struct mlx5_ib_dm_icm {
38 	struct mlx5_ib_dm      base;
39 	u32                    obj_id;
40 };
41 
42 static inline struct mlx5_ib_dm *to_mdm(struct ib_dm *ibdm)
43 {
44 	return container_of(ibdm, struct mlx5_ib_dm, ibdm);
45 }
46 
47 static inline struct mlx5_ib_dm_memic *to_memic(struct ib_dm *ibdm)
48 {
49 	return container_of(ibdm, struct mlx5_ib_dm_memic, base.ibdm);
50 }
51 
52 static inline struct mlx5_ib_dm_icm *to_icm(struct ib_dm *ibdm)
53 {
54 	return container_of(ibdm, struct mlx5_ib_dm_icm, base.ibdm);
55 }
56 
57 struct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev,
58 			       struct ib_ucontext *context,
59 			       struct ib_dm_alloc_attr *attr,
60 			       struct uverbs_attr_bundle *attrs);
61 void mlx5_ib_dm_mmap_free(struct mlx5_ib_dev *dev,
62 			  struct mlx5_user_mmap_entry *mentry);
63 void mlx5_cmd_dealloc_memic(struct mlx5_dm *dm, phys_addr_t addr,
64 			    u64 length);
65 void mlx5_cmd_dealloc_memic_op(struct mlx5_dm *dm, phys_addr_t addr,
66 			       u8 operation);
67 
68 #endif /* _MLX5_IB_DM_H */
69