xref: /openbmc/linux/drivers/vdpa/mlx5/core/mlx5_vdpa.h (revision aa74c44b)
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/etherdevice.h>
8 #include <linux/vringh.h>
9 #include <linux/vdpa.h>
10 #include <linux/mlx5/driver.h>
11 
12 #define MLX5V_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
13 
14 struct mlx5_vdpa_direct_mr {
15 	u64 start;
16 	u64 end;
17 	u32 perm;
18 	u32 mr;
19 	struct sg_table sg_head;
20 	int log_size;
21 	int nsg;
22 	int nent;
23 	struct list_head list;
24 	u64 offset;
25 };
26 
27 struct mlx5_vdpa_mr {
28 	u32 mkey;
29 
30 	/* list of direct MRs descendants of this indirect mr */
31 	struct list_head head;
32 	unsigned long num_directs;
33 	unsigned long num_klms;
34 	bool initialized;
35 
36 	/* serialize mkey creation and destruction */
37 	struct mutex mkey_mtx;
38 	bool user_mr;
39 };
40 
41 struct mlx5_vdpa_resources {
42 	u32 pdn;
43 	struct mlx5_uars_page *uar;
44 	void __iomem *kick_addr;
45 	u64 phys_kick_addr;
46 	u16 uid;
47 	u32 null_mkey;
48 	bool valid;
49 };
50 
51 struct mlx5_control_vq {
52 	struct vhost_iotlb *iotlb;
53 	/* spinlock to synchronize iommu table */
54 	spinlock_t iommu_lock;
55 	struct vringh vring;
56 	bool ready;
57 	u64 desc_addr;
58 	u64 device_addr;
59 	u64 driver_addr;
60 	struct vdpa_callback event_cb;
61 	struct vringh_kiov riov;
62 	struct vringh_kiov wiov;
63 	unsigned short head;
64 };
65 
66 struct mlx5_vdpa_wq_ent {
67 	struct work_struct work;
68 	struct mlx5_vdpa_dev *mvdev;
69 };
70 
71 struct mlx5_vdpa_dev {
72 	struct vdpa_device vdev;
73 	struct mlx5_core_dev *mdev;
74 	struct mlx5_vdpa_resources res;
75 
76 	u64 mlx_features;
77 	u64 actual_features;
78 	u8 status;
79 	u32 max_vqs;
80 	u16 max_idx;
81 	u32 generation;
82 
83 	struct mlx5_vdpa_mr mr;
84 	struct mlx5_control_vq cvq;
85 	struct workqueue_struct *wq;
86 };
87 
88 int mlx5_vdpa_alloc_pd(struct mlx5_vdpa_dev *dev, u32 *pdn, u16 uid);
89 int mlx5_vdpa_dealloc_pd(struct mlx5_vdpa_dev *dev, u32 pdn, u16 uid);
90 int mlx5_vdpa_get_null_mkey(struct mlx5_vdpa_dev *dev, u32 *null_mkey);
91 int mlx5_vdpa_create_tis(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tisn);
92 void mlx5_vdpa_destroy_tis(struct mlx5_vdpa_dev *mvdev, u32 tisn);
93 int mlx5_vdpa_create_rqt(struct mlx5_vdpa_dev *mvdev, void *in, int inlen, u32 *rqtn);
94 int mlx5_vdpa_modify_rqt(struct mlx5_vdpa_dev *mvdev, void *in, int inlen, u32 rqtn);
95 void mlx5_vdpa_destroy_rqt(struct mlx5_vdpa_dev *mvdev, u32 rqtn);
96 int mlx5_vdpa_create_tir(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tirn);
97 void mlx5_vdpa_destroy_tir(struct mlx5_vdpa_dev *mvdev, u32 tirn);
98 int mlx5_vdpa_alloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 *tdn);
99 void mlx5_vdpa_dealloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 tdn);
100 int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev);
101 void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev);
102 int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, u32 *mkey, u32 *in,
103 			  int inlen);
104 int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey);
105 int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
106 			     bool *change_map);
107 int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb);
108 void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev);
109 
110 #define mlx5_vdpa_warn(__dev, format, ...)                                                         \
111 	dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__,     \
112 		 current->pid, ##__VA_ARGS__)
113 
114 #define mlx5_vdpa_info(__dev, format, ...)                                                         \
115 	dev_info((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__,             \
116 		 current->pid, ##__VA_ARGS__)
117 
118 #define mlx5_vdpa_dbg(__dev, format, ...)                                                          \
119 	dev_debug((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__,            \
120 		  current->pid, ##__VA_ARGS__)
121 
122 #endif /* __MLX5_VDPA_H__ */
123