1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2020 Mellanox Technologies Ltd. */
4 #ifndef __MLX5_VDPA_H__
5 #define __MLX5_VDPA_H__
7 #include <linux/etherdevice.h>
8 #include <linux/vringh.h>
9 #include <linux/vdpa.h>
10 #include <linux/mlx5/driver.h>
12 #define MLX5V_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
14 struct mlx5_vdpa_direct_mr {
19 struct sg_table sg_head;
23 struct list_head list;
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;
36 /* serialize mkey creation and destruction */
37 struct mutex mkey_mtx;
41 struct mlx5_vdpa_resources {
43 struct mlx5_uars_page *uar;
44 void __iomem *kick_addr;
51 struct mlx5_control_vq {
52 struct vhost_iotlb *iotlb;
53 /* spinlock to synchronize iommu table */
54 spinlock_t iommu_lock;
60 struct vdpa_callback event_cb;
61 struct vringh_kiov riov;
62 struct vringh_kiov wiov;
64 unsigned int received_desc;
65 unsigned int completed_desc;
68 struct mlx5_vdpa_wq_ent {
69 struct work_struct work;
70 struct mlx5_vdpa_dev *mvdev;
74 MLX5_VDPA_DATAVQ_GROUP,
76 MLX5_VDPA_NUMVQ_GROUPS
80 MLX5_VDPA_NUM_AS = MLX5_VDPA_NUMVQ_GROUPS
83 struct mlx5_vdpa_dev {
84 struct vdpa_device vdev;
85 struct mlx5_core_dev *mdev;
86 struct mlx5_vdpa_resources res;
95 struct mlx5_vdpa_mr mr;
96 struct mlx5_control_vq cvq;
97 struct workqueue_struct *wq;
98 unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS];
101 int mlx5_vdpa_alloc_pd(struct mlx5_vdpa_dev *dev, u32 *pdn, u16 uid);
102 int mlx5_vdpa_dealloc_pd(struct mlx5_vdpa_dev *dev, u32 pdn, u16 uid);
103 int mlx5_vdpa_get_null_mkey(struct mlx5_vdpa_dev *dev, u32 *null_mkey);
104 int mlx5_vdpa_create_tis(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tisn);
105 void mlx5_vdpa_destroy_tis(struct mlx5_vdpa_dev *mvdev, u32 tisn);
106 int mlx5_vdpa_create_rqt(struct mlx5_vdpa_dev *mvdev, void *in, int inlen, u32 *rqtn);
107 int mlx5_vdpa_modify_rqt(struct mlx5_vdpa_dev *mvdev, void *in, int inlen, u32 rqtn);
108 void mlx5_vdpa_destroy_rqt(struct mlx5_vdpa_dev *mvdev, u32 rqtn);
109 int mlx5_vdpa_create_tir(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tirn);
110 void mlx5_vdpa_destroy_tir(struct mlx5_vdpa_dev *mvdev, u32 tirn);
111 int mlx5_vdpa_alloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 *tdn);
112 void mlx5_vdpa_dealloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 tdn);
113 int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev);
114 void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev);
115 int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, u32 *mkey, u32 *in,
117 int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey);
118 int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
120 int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb);
121 void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev);
123 #define mlx5_vdpa_warn(__dev, format, ...) \
124 dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__, \
125 current->pid, ##__VA_ARGS__)
127 #define mlx5_vdpa_info(__dev, format, ...) \
128 dev_info((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__, \
129 current->pid, ##__VA_ARGS__)
131 #define mlx5_vdpa_dbg(__dev, format, ...) \
132 dev_debug((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__, \
133 current->pid, ##__VA_ARGS__)
135 #endif /* __MLX5_VDPA_H__ */