Skip to content

Commit 94abbcc

Browse files
Eli Cohenmstsirkin
authored andcommitted
vdpa/mlx5: Add shared memory registration code
Add code to support registering address space region for the device. The virtio driver can run as either: 1. Guest virtio driver 2. Userspace virtio driver on the host 3. Kernel virtio driver on the host In any case a memory key object is required to provide access to memory for the device. This code will be shared by network or block driver implementations. Reviewed-by: Parav Pandit <[email protected]> Signed-off-by: Eli Cohen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 29064bf commit 94abbcc

File tree

5 files changed

+522
-2
lines changed

5 files changed

+522
-2
lines changed

drivers/vdpa/mlx5/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
obj-$(CONFIG_MLX5_VDPA) += core/resources.o
1+
obj-$(CONFIG_MLX5_VDPA) += core/resources.o core/mr.o

drivers/vdpa/mlx5/core/Makefile

Lines changed: 0 additions & 1 deletion
This file was deleted.

drivers/vdpa/mlx5/core/mlx5_vdpa.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@
77
#include <linux/vdpa.h>
88
#include <linux/mlx5/driver.h>
99

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+
1035
struct mlx5_vdpa_resources {
1136
u32 pdn;
1237
struct mlx5_uars_page *uar;
@@ -26,6 +51,8 @@ struct mlx5_vdpa_dev {
2651
u8 status;
2752
u32 max_vqs;
2853
u32 generation;
54+
55+
struct mlx5_vdpa_mr mr;
2956
};
3057

3158
int mlx5_vdpa_alloc_pd(struct mlx5_vdpa_dev *dev, u32 *pdn, u16 uid);
@@ -41,6 +68,13 @@ int mlx5_vdpa_alloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 *tdn);
4168
void mlx5_vdpa_dealloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 tdn);
4269
int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev);
4370
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);
4478

4579
#define mlx5_vdpa_warn(__dev, format, ...) \
4680
dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__, \

0 commit comments

Comments
 (0)