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
;
35 struct vhost_iotlb
*iotlb
;
40 struct list_head mr_list
;
43 struct mlx5_vdpa_resources
{
45 struct mlx5_uars_page
*uar
;
46 void __iomem
*kick_addr
;
53 struct mlx5_control_vq
{
54 struct vhost_iotlb
*iotlb
;
55 /* spinlock to synchronize iommu table */
56 spinlock_t iommu_lock
;
62 struct vdpa_callback event_cb
;
63 struct vringh_kiov riov
;
64 struct vringh_kiov wiov
;
66 unsigned int received_desc
;
67 unsigned int completed_desc
;
70 struct mlx5_vdpa_wq_ent
{
71 struct work_struct work
;
72 struct mlx5_vdpa_dev
*mvdev
;
76 MLX5_VDPA_DATAVQ_GROUP
,
78 MLX5_VDPA_DATAVQ_DESC_GROUP
,
79 MLX5_VDPA_NUMVQ_GROUPS
86 struct mlx5_vdpa_mr_resources
{
87 struct mlx5_vdpa_mr
*mr
[MLX5_VDPA_NUM_AS
];
88 unsigned int group2asid
[MLX5_VDPA_NUMVQ_GROUPS
];
90 /* Pre-deletion mr list */
91 struct list_head mr_list_head
;
93 /* Deferred mr list */
94 struct list_head mr_gc_list_head
;
95 struct workqueue_struct
*wq_gc
;
96 struct delayed_work gc_dwork_ent
;
103 struct mlx5_vdpa_dev
{
104 struct vdpa_device vdev
;
105 struct mlx5_core_dev
*mdev
;
106 struct mlx5_vdpa_resources res
;
107 struct mlx5_vdpa_mr_resources mres
;
116 struct mlx5_control_vq cvq
;
117 struct workqueue_struct
*wq
;
120 struct mlx5_async_ctx async_ctx
;
123 struct mlx5_vdpa_async_cmd
{
125 struct mlx5_async_work cb_work
;
126 struct completion cmd_done
;
135 int mlx5_vdpa_create_tis(struct mlx5_vdpa_dev
*mvdev
, void *in
, u32
*tisn
);
136 void mlx5_vdpa_destroy_tis(struct mlx5_vdpa_dev
*mvdev
, u32 tisn
);
137 int mlx5_vdpa_create_rqt(struct mlx5_vdpa_dev
*mvdev
, void *in
, int inlen
, u32
*rqtn
);
138 int mlx5_vdpa_modify_rqt(struct mlx5_vdpa_dev
*mvdev
, void *in
, int inlen
, u32 rqtn
);
139 void mlx5_vdpa_destroy_rqt(struct mlx5_vdpa_dev
*mvdev
, u32 rqtn
);
140 int mlx5_vdpa_create_tir(struct mlx5_vdpa_dev
*mvdev
, void *in
, u32
*tirn
);
141 void mlx5_vdpa_destroy_tir(struct mlx5_vdpa_dev
*mvdev
, u32 tirn
);
142 int mlx5_vdpa_alloc_transport_domain(struct mlx5_vdpa_dev
*mvdev
, u32
*tdn
);
143 void mlx5_vdpa_dealloc_transport_domain(struct mlx5_vdpa_dev
*mvdev
, u32 tdn
);
144 int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev
*mvdev
);
145 void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev
*mvdev
);
146 int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev
*mvdev
, u32
*mkey
, u32
*in
,
148 int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev
*mvdev
, u32 mkey
);
149 struct mlx5_vdpa_mr
*mlx5_vdpa_create_mr(struct mlx5_vdpa_dev
*mvdev
,
150 struct vhost_iotlb
*iotlb
);
151 int mlx5_vdpa_init_mr_resources(struct mlx5_vdpa_dev
*mvdev
);
152 void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev
*mvdev
);
153 void mlx5_vdpa_clean_mrs(struct mlx5_vdpa_dev
*mvdev
);
154 void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev
*mvdev
,
155 struct mlx5_vdpa_mr
*mr
);
156 void mlx5_vdpa_put_mr(struct mlx5_vdpa_dev
*mvdev
,
157 struct mlx5_vdpa_mr
*mr
);
158 void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev
*mvdev
,
159 struct mlx5_vdpa_mr
*mr
,
161 int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev
*mvdev
,
162 struct vhost_iotlb
*iotlb
,
164 int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev
*mvdev
);
165 int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev
*mvdev
, unsigned int asid
);
166 int mlx5_vdpa_exec_async_cmds(struct mlx5_vdpa_dev
*mvdev
,
167 struct mlx5_vdpa_async_cmd
*cmds
,
170 #define mlx5_vdpa_err(__dev, format, ...) \
171 dev_err((__dev)->mdev->device, "%s:%d:(pid %d) error: " format, __func__, __LINE__, \
172 current->pid, ##__VA_ARGS__)
175 #define mlx5_vdpa_warn(__dev, format, ...) \
176 dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__, \
177 current->pid, ##__VA_ARGS__)
179 #define mlx5_vdpa_info(__dev, format, ...) \
180 dev_info((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__, \
181 current->pid, ##__VA_ARGS__)
183 #define mlx5_vdpa_dbg(__dev, format, ...) \
184 dev_debug((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__, \
185 current->pid, ##__VA_ARGS__)
187 #endif /* __MLX5_VDPA_H__ */