Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Max Gurtovoy <mgurtovoy@nvidia.com>
Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lore.kernel.org/r/20201215144256.155342-7-sgarzare@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Stefano Garzarella and committed by
Michael S. Tsirkin
6c6e28fe 36a9c306

+17 -8
+17 -8
drivers/vdpa/vdpa_sim/vdpa_sim.c
··· 65 65 (1ULL << VIRTIO_F_ACCESS_PLATFORM) | 66 66 (1ULL << VIRTIO_NET_F_MAC); 67 67 68 + struct vdpasim_dev_attr { 69 + int nvqs; 70 + }; 71 + 68 72 /* State of each vdpasim device */ 69 73 struct vdpasim { 70 74 struct vdpa_device vdpa; 71 75 struct vdpasim_virtqueue *vqs; 72 76 struct work_struct work; 77 + struct vdpasim_dev_attr dev_attr; 73 78 /* spinlock to synchronize virtqueue state */ 74 79 spinlock_t lock; 75 80 struct virtio_net_config config; ··· 83 78 u32 status; 84 79 u32 generation; 85 80 u64 features; 86 - int nvqs; 87 81 /* spinlock to synchronize iommu table */ 88 82 spinlock_t iommu_lock; 89 83 }; ··· 147 143 { 148 144 int i; 149 145 150 - for (i = 0; i < vdpasim->nvqs; i++) 146 + for (i = 0; i < vdpasim->dev_attr.nvqs; i++) 151 147 vdpasim_vq_reset(&vdpasim->vqs[i]); 152 148 153 149 spin_lock(&vdpasim->iommu_lock); ··· 348 344 static const struct vdpa_config_ops vdpasim_config_ops; 349 345 static const struct vdpa_config_ops vdpasim_batch_config_ops; 350 346 351 - static struct vdpasim *vdpasim_create(void) 347 + static struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) 352 348 { 353 349 const struct vdpa_config_ops *ops; 354 350 struct vdpasim *vdpasim; ··· 360 356 else 361 357 ops = &vdpasim_config_ops; 362 358 363 - vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, VDPASIM_VQ_NUM); 359 + vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, 360 + dev_attr->nvqs); 364 361 if (!vdpasim) 365 362 goto err_alloc; 366 363 367 - vdpasim->nvqs = VDPASIM_VQ_NUM; 364 + vdpasim->dev_attr = *dev_attr; 368 365 INIT_WORK(&vdpasim->work, vdpasim_work); 369 366 spin_lock_init(&vdpasim->lock); 370 367 spin_lock_init(&vdpasim->iommu_lock); ··· 376 371 goto err_iommu; 377 372 set_dma_ops(dev, &vdpasim_dma_ops); 378 373 379 - vdpasim->vqs = kcalloc(vdpasim->nvqs, sizeof(struct vdpasim_virtqueue), 374 + vdpasim->vqs = kcalloc(dev_attr->nvqs, sizeof(struct vdpasim_virtqueue), 380 375 GFP_KERNEL); 381 376 if (!vdpasim->vqs) 382 377 goto err_iommu; ··· 399 394 eth_random_addr(vdpasim->config.mac); 400 395 } 401 396 402 - for (i = 0; i < vdpasim->nvqs; i++) 397 + for (i = 0; i < dev_attr->nvqs; i++) 403 398 vringh_set_iotlb(&vdpasim->vqs[i].vring, vdpasim->iommu); 404 399 405 400 vdpasim->vdpa.dma_dev = dev; ··· 727 722 728 723 static int __init vdpasim_dev_init(void) 729 724 { 730 - vdpasim_dev = vdpasim_create(); 725 + struct vdpasim_dev_attr dev_attr = {}; 726 + 727 + dev_attr.nvqs = VDPASIM_VQ_NUM; 728 + 729 + vdpasim_dev = vdpasim_create(&dev_attr); 731 730 732 731 if (!IS_ERR(vdpasim_dev)) 733 732 return 0;