Commit 6c6e28fe authored by Stefano Garzarella's avatar Stefano Garzarella Committed by Michael S. Tsirkin

vdpa_sim: add struct vdpasim_dev_attr for device attributes

vdpasim_dev_attr will contain device specific attributes. We starting
moving the number of virtqueues (i.e. nvqs) to vdpasim_dev_attr.

vdpasim_create() creates a new vDPA simulator following the device
attributes defined in the vdpasim_dev_attr parameter.
Co-developed-by: default avatarMax Gurtovoy <mgurtovoy@nvidia.com>
Signed-off-by: default avatarMax Gurtovoy <mgurtovoy@nvidia.com>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarStefano Garzarella <sgarzare@redhat.com>
Link: https://lore.kernel.org/r/20201215144256.155342-7-sgarzare@redhat.comSigned-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 36a9c306
...@@ -65,11 +65,16 @@ static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) | ...@@ -65,11 +65,16 @@ static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) |
(1ULL << VIRTIO_F_ACCESS_PLATFORM) | (1ULL << VIRTIO_F_ACCESS_PLATFORM) |
(1ULL << VIRTIO_NET_F_MAC); (1ULL << VIRTIO_NET_F_MAC);
struct vdpasim_dev_attr {
int nvqs;
};
/* State of each vdpasim device */ /* State of each vdpasim device */
struct vdpasim { struct vdpasim {
struct vdpa_device vdpa; struct vdpa_device vdpa;
struct vdpasim_virtqueue *vqs; struct vdpasim_virtqueue *vqs;
struct work_struct work; struct work_struct work;
struct vdpasim_dev_attr dev_attr;
/* spinlock to synchronize virtqueue state */ /* spinlock to synchronize virtqueue state */
spinlock_t lock; spinlock_t lock;
struct virtio_net_config config; struct virtio_net_config config;
...@@ -78,7 +83,6 @@ struct vdpasim { ...@@ -78,7 +83,6 @@ struct vdpasim {
u32 status; u32 status;
u32 generation; u32 generation;
u64 features; u64 features;
int nvqs;
/* spinlock to synchronize iommu table */ /* spinlock to synchronize iommu table */
spinlock_t iommu_lock; spinlock_t iommu_lock;
}; };
...@@ -143,7 +147,7 @@ static void vdpasim_reset(struct vdpasim *vdpasim) ...@@ -143,7 +147,7 @@ static void vdpasim_reset(struct vdpasim *vdpasim)
{ {
int i; int i;
for (i = 0; i < vdpasim->nvqs; i++) for (i = 0; i < vdpasim->dev_attr.nvqs; i++)
vdpasim_vq_reset(&vdpasim->vqs[i]); vdpasim_vq_reset(&vdpasim->vqs[i]);
spin_lock(&vdpasim->iommu_lock); spin_lock(&vdpasim->iommu_lock);
...@@ -344,7 +348,7 @@ static const struct dma_map_ops vdpasim_dma_ops = { ...@@ -344,7 +348,7 @@ static const struct dma_map_ops vdpasim_dma_ops = {
static const struct vdpa_config_ops vdpasim_config_ops; static const struct vdpa_config_ops vdpasim_config_ops;
static const struct vdpa_config_ops vdpasim_batch_config_ops; static const struct vdpa_config_ops vdpasim_batch_config_ops;
static struct vdpasim *vdpasim_create(void) static struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr)
{ {
const struct vdpa_config_ops *ops; const struct vdpa_config_ops *ops;
struct vdpasim *vdpasim; struct vdpasim *vdpasim;
...@@ -356,11 +360,12 @@ static struct vdpasim *vdpasim_create(void) ...@@ -356,11 +360,12 @@ static struct vdpasim *vdpasim_create(void)
else else
ops = &vdpasim_config_ops; ops = &vdpasim_config_ops;
vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, VDPASIM_VQ_NUM); vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops,
dev_attr->nvqs);
if (!vdpasim) if (!vdpasim)
goto err_alloc; goto err_alloc;
vdpasim->nvqs = VDPASIM_VQ_NUM; vdpasim->dev_attr = *dev_attr;
INIT_WORK(&vdpasim->work, vdpasim_work); INIT_WORK(&vdpasim->work, vdpasim_work);
spin_lock_init(&vdpasim->lock); spin_lock_init(&vdpasim->lock);
spin_lock_init(&vdpasim->iommu_lock); spin_lock_init(&vdpasim->iommu_lock);
...@@ -371,7 +376,7 @@ static struct vdpasim *vdpasim_create(void) ...@@ -371,7 +376,7 @@ static struct vdpasim *vdpasim_create(void)
goto err_iommu; goto err_iommu;
set_dma_ops(dev, &vdpasim_dma_ops); set_dma_ops(dev, &vdpasim_dma_ops);
vdpasim->vqs = kcalloc(vdpasim->nvqs, sizeof(struct vdpasim_virtqueue), vdpasim->vqs = kcalloc(dev_attr->nvqs, sizeof(struct vdpasim_virtqueue),
GFP_KERNEL); GFP_KERNEL);
if (!vdpasim->vqs) if (!vdpasim->vqs)
goto err_iommu; goto err_iommu;
...@@ -394,7 +399,7 @@ static struct vdpasim *vdpasim_create(void) ...@@ -394,7 +399,7 @@ static struct vdpasim *vdpasim_create(void)
eth_random_addr(vdpasim->config.mac); eth_random_addr(vdpasim->config.mac);
} }
for (i = 0; i < vdpasim->nvqs; i++) for (i = 0; i < dev_attr->nvqs; i++)
vringh_set_iotlb(&vdpasim->vqs[i].vring, vdpasim->iommu); vringh_set_iotlb(&vdpasim->vqs[i].vring, vdpasim->iommu);
vdpasim->vdpa.dma_dev = dev; vdpasim->vdpa.dma_dev = dev;
...@@ -722,7 +727,11 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { ...@@ -722,7 +727,11 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = {
static int __init vdpasim_dev_init(void) static int __init vdpasim_dev_init(void)
{ {
vdpasim_dev = vdpasim_create(); struct vdpasim_dev_attr dev_attr = {};
dev_attr.nvqs = VDPASIM_VQ_NUM;
vdpasim_dev = vdpasim_create(&dev_attr);
if (!IS_ERR(vdpasim_dev)) if (!IS_ERR(vdpasim_dev))
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment