xref: /openbmc/linux/drivers/vdpa/mlx5/core/mlx5_vdpa.h (revision e0d07278)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2020 Mellanox Technologies Ltd. */
3 
4 #ifndef __MLX5_VDPA_H__
5 #define __MLX5_VDPA_H__
6 
7 #include <linux/vdpa.h>
8 #include <linux/mlx5/driver.h>
9 
10 struct mlx5_vdpa_direct_mr {
11 	u64 start;
12 	u64 end;
13 	u32 perm;
14 	struct mlx5_core_mkey mr;
15 	struct sg_table sg_head;
16 	int log_size;
17 	int nsg;
18 	struct list_head list;
19 	u64 offset;
20 };
21 
22 struct mlx5_vdpa_mr {
23 	struct mlx5_core_mkey mkey;
24 
25 	/* list of direct MRs descendants of this indirect mr */
26 	struct list_head head;
27 	unsigned long num_directs;
28 	unsigned long num_klms;
29 	bool initialized;
30 
31 	/* serialize mkey creation and destruction */
32 	struct mutex mkey_mtx;
33 };
34 
35 struct mlx5_vdpa_resources {
36 	u32 pdn;
37 	struct mlx5_uars_page *uar;
38 	void __iomem *kick_addr;
39 	u16 uid;
40 	u32 null_mkey;
41 	bool valid;
42 };
43 
44 struct mlx5_vdpa_dev {
45 	struct vdpa_device vdev;
46 	struct mlx5_core_dev *mdev;
47 	struct mlx5_vdpa_resources res;
48 
49 	u64 mlx_features;
50 	u64 actual_features;
51 	u8 status;
52 	u32 max_vqs;
53 	u32 generation;
54 
55 	struct mlx5_vdpa_mr mr;
56 };
57 
58 int mlx5_vdpa_alloc_pd(struct mlx5_vdpa_dev *dev, u32 *pdn, u16 uid);
59 int mlx5_vdpa_dealloc_pd(struct mlx5_vdpa_dev *dev, u32 pdn, u16 uid);
60 int mlx5_vdpa_get_null_mkey(struct mlx5_vdpa_dev *dev, u32 *null_mkey);
61 int mlx5_vdpa_create_tis(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tisn);
62 void mlx5_vdpa_destroy_tis(struct mlx5_vdpa_dev *mvdev, u32 tisn);
63 int mlx5_vdpa_create_rqt(struct mlx5_vdpa_dev *mvdev, void *in, int inlen, u32 *rqtn);
64 void mlx5_vdpa_destroy_rqt(struct mlx5_vdpa_dev *mvdev, u32 rqtn);
65 int mlx5_vdpa_create_tir(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tirn);
66 void mlx5_vdpa_destroy_tir(struct mlx5_vdpa_dev *mvdev, u32 tirn);
67 int mlx5_vdpa_alloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 *tdn);
68 void mlx5_vdpa_dealloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 tdn);
69 int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev);
70 void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev);
71 int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, struct mlx5_core_mkey *mkey, u32 *in,
72 			  int inlen);
73 int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, struct mlx5_core_mkey *mkey);
74 int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
75 			     bool *change_map);
76 int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb);
77 void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev);
78 
79 #define mlx5_vdpa_warn(__dev, format, ...)                                                         \
80 	dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__,     \
81 		 current->pid, ##__VA_ARGS__)
82 
83 #define mlx5_vdpa_info(__dev, format, ...)                                                         \
84 	dev_info((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__,             \
85 		 current->pid, ##__VA_ARGS__)
86 
87 #define mlx5_vdpa_dbg(__dev, format, ...)                                                          \
88 	dev_debug((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__,            \
89 		  current->pid, ##__VA_ARGS__)
90 
91 #endif /* __MLX5_VDPA_H__ */
92