0001
0002
0003
0004 #ifndef __MLX5_VDPA_H__
0005 #define __MLX5_VDPA_H__
0006
0007 #include <linux/etherdevice.h>
0008 #include <linux/vringh.h>
0009 #include <linux/vdpa.h>
0010 #include <linux/mlx5/driver.h>
0011
0012 #define MLX5V_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
0013
0014 struct mlx5_vdpa_direct_mr {
0015 u64 start;
0016 u64 end;
0017 u32 perm;
0018 u32 mr;
0019 struct sg_table sg_head;
0020 int log_size;
0021 int nsg;
0022 int nent;
0023 struct list_head list;
0024 u64 offset;
0025 };
0026
0027 struct mlx5_vdpa_mr {
0028 u32 mkey;
0029
0030
0031 struct list_head head;
0032 unsigned long num_directs;
0033 unsigned long num_klms;
0034 bool initialized;
0035
0036
0037 struct mutex mkey_mtx;
0038 bool user_mr;
0039 };
0040
0041 struct mlx5_vdpa_resources {
0042 u32 pdn;
0043 struct mlx5_uars_page *uar;
0044 void __iomem *kick_addr;
0045 u64 phys_kick_addr;
0046 u16 uid;
0047 u32 null_mkey;
0048 bool valid;
0049 };
0050
0051 struct mlx5_control_vq {
0052 struct vhost_iotlb *iotlb;
0053
0054 spinlock_t iommu_lock;
0055 struct vringh vring;
0056 bool ready;
0057 u64 desc_addr;
0058 u64 device_addr;
0059 u64 driver_addr;
0060 struct vdpa_callback event_cb;
0061 struct vringh_kiov riov;
0062 struct vringh_kiov wiov;
0063 unsigned short head;
0064 unsigned int received_desc;
0065 unsigned int completed_desc;
0066 };
0067
0068 struct mlx5_vdpa_wq_ent {
0069 struct work_struct work;
0070 struct mlx5_vdpa_dev *mvdev;
0071 };
0072
0073 enum {
0074 MLX5_VDPA_DATAVQ_GROUP,
0075 MLX5_VDPA_CVQ_GROUP,
0076 MLX5_VDPA_NUMVQ_GROUPS
0077 };
0078
0079 enum {
0080 MLX5_VDPA_NUM_AS = MLX5_VDPA_NUMVQ_GROUPS
0081 };
0082
0083 struct mlx5_vdpa_dev {
0084 struct vdpa_device vdev;
0085 struct mlx5_core_dev *mdev;
0086 struct mlx5_vdpa_resources res;
0087
0088 u64 mlx_features;
0089 u64 actual_features;
0090 u8 status;
0091 u32 max_vqs;
0092 u16 max_idx;
0093 u32 generation;
0094
0095 struct mlx5_vdpa_mr mr;
0096 struct mlx5_control_vq cvq;
0097 struct workqueue_struct *wq;
0098 unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS];
0099 };
0100
0101 int mlx5_vdpa_alloc_pd(struct mlx5_vdpa_dev *dev, u32 *pdn, u16 uid);
0102 int mlx5_vdpa_dealloc_pd(struct mlx5_vdpa_dev *dev, u32 pdn, u16 uid);
0103 int mlx5_vdpa_get_null_mkey(struct mlx5_vdpa_dev *dev, u32 *null_mkey);
0104 int mlx5_vdpa_create_tis(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tisn);
0105 void mlx5_vdpa_destroy_tis(struct mlx5_vdpa_dev *mvdev, u32 tisn);
0106 int mlx5_vdpa_create_rqt(struct mlx5_vdpa_dev *mvdev, void *in, int inlen, u32 *rqtn);
0107 int mlx5_vdpa_modify_rqt(struct mlx5_vdpa_dev *mvdev, void *in, int inlen, u32 rqtn);
0108 void mlx5_vdpa_destroy_rqt(struct mlx5_vdpa_dev *mvdev, u32 rqtn);
0109 int mlx5_vdpa_create_tir(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tirn);
0110 void mlx5_vdpa_destroy_tir(struct mlx5_vdpa_dev *mvdev, u32 tirn);
0111 int mlx5_vdpa_alloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 *tdn);
0112 void mlx5_vdpa_dealloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 tdn);
0113 int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev);
0114 void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev);
0115 int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, u32 *mkey, u32 *in,
0116 int inlen);
0117 int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey);
0118 int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
0119 bool *change_map);
0120 int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb);
0121 void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev);
0122
0123 #define mlx5_vdpa_warn(__dev, format, ...) \
0124 dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__, \
0125 current->pid, ##__VA_ARGS__)
0126
0127 #define mlx5_vdpa_info(__dev, format, ...) \
0128 dev_info((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__, \
0129 current->pid, ##__VA_ARGS__)
0130
0131 #define mlx5_vdpa_dbg(__dev, format, ...) \
0132 dev_debug((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__, \
0133 current->pid, ##__VA_ARGS__)
0134
0135 #endif