Skip to content

Commit

Permalink
vdpa/mlx5: Add shared memory registration code
Browse files Browse the repository at this point in the history
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 <parav@mellanox.com>
Signed-off-by: Eli Cohen <eli@mellanox.com>
Link: https://lore.kernel.org/r/20200804162048.22587-12-eli@mellanox.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Eli Cohen authored and mstsirkin committed Aug 5, 2020
1 parent 29064bf commit 94abbcc
Show file tree
Hide file tree
Showing 5 changed files with 522 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/vdpa/mlx5/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
obj-$(CONFIG_MLX5_VDPA) += core/resources.o
obj-$(CONFIG_MLX5_VDPA) += core/resources.o core/mr.o
1 change: 0 additions & 1 deletion drivers/vdpa/mlx5/core/Makefile

This file was deleted.

34 changes: 34 additions & 0 deletions drivers/vdpa/mlx5/core/mlx5_vdpa.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@
#include <linux/vdpa.h>
#include <linux/mlx5/driver.h>

struct mlx5_vdpa_direct_mr {
u64 start;
u64 end;
u32 perm;
struct mlx5_core_mkey mr;
struct sg_table sg_head;
int log_size;
int nsg;
struct list_head list;
u64 offset;
};

struct mlx5_vdpa_mr {
struct mlx5_core_mkey mkey;

/* list of direct MRs descendants of this indirect mr */
struct list_head head;
unsigned long num_directs;
unsigned long num_klms;
bool initialized;

/* serialize mkey creation and destruction */
struct mutex mkey_mtx;
};

struct mlx5_vdpa_resources {
u32 pdn;
struct mlx5_uars_page *uar;
Expand All @@ -26,6 +51,8 @@ struct mlx5_vdpa_dev {
u8 status;
u32 max_vqs;
u32 generation;

struct mlx5_vdpa_mr mr;
};

int mlx5_vdpa_alloc_pd(struct mlx5_vdpa_dev *dev, u32 *pdn, u16 uid);
Expand All @@ -41,6 +68,13 @@ int mlx5_vdpa_alloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 *tdn);
void mlx5_vdpa_dealloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 tdn);
int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev);
void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev);
int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, struct mlx5_core_mkey *mkey, u32 *in,
int inlen);
int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, struct mlx5_core_mkey *mkey);
int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
bool *change_map);
int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb);
void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev);

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

0 comments on commit 94abbcc

Please sign in to comment.