virtio: move queue allocation to backend code
Right now both virtio-pci and virtio-user allocate the queue via spdk_dma_malloc, but that's about to change soon. Change-Id: I3acdad45cd9a0639f9070bc448fdf8f9d2c706c0 Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/417000 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
e724452ec0
commit
3a15b49b05
@ -116,11 +116,8 @@ virtio_init_vring(struct virtqueue *vq)
|
|||||||
static int
|
static int
|
||||||
virtio_init_queue(struct virtio_dev *dev, uint16_t vtpci_queue_idx)
|
virtio_init_queue(struct virtio_dev *dev, uint16_t vtpci_queue_idx)
|
||||||
{
|
{
|
||||||
void *queue_mem;
|
|
||||||
unsigned int vq_size, size;
|
unsigned int vq_size, size;
|
||||||
uint64_t queue_mem_phys_addr;
|
|
||||||
struct virtqueue *vq;
|
struct virtqueue *vq;
|
||||||
int ret;
|
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "setting up queue: %"PRIu16"\n", vtpci_queue_idx);
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "setting up queue: %"PRIu16"\n", vtpci_queue_idx);
|
||||||
|
|
||||||
@ -164,21 +161,6 @@ virtio_init_queue(struct virtio_dev *dev, uint16_t vtpci_queue_idx)
|
|||||||
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "vring_size: %u, rounded_vring_size: %u\n",
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "vring_size: %u, rounded_vring_size: %u\n",
|
||||||
size, vq->vq_ring_size);
|
size, vq->vq_ring_size);
|
||||||
|
|
||||||
queue_mem = spdk_dma_zmalloc(vq->vq_ring_size, VIRTIO_PCI_VRING_ALIGN, &queue_mem_phys_addr);
|
|
||||||
if (queue_mem == NULL) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto fail_q_alloc;
|
|
||||||
}
|
|
||||||
|
|
||||||
vq->vq_ring_mem = queue_mem_phys_addr;
|
|
||||||
vq->vq_ring_virt_mem = queue_mem;
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "vq->vq_ring_mem: 0x%" PRIx64 "\n",
|
|
||||||
vq->vq_ring_mem);
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "vq->vq_ring_virt_mem: 0x%" PRIx64 "\n",
|
|
||||||
(uint64_t)(uintptr_t)vq->vq_ring_virt_mem);
|
|
||||||
|
|
||||||
virtio_init_vring(vq);
|
|
||||||
|
|
||||||
vq->owner_thread = NULL;
|
vq->owner_thread = NULL;
|
||||||
|
|
||||||
if (virtio_dev_backend_ops(dev)->setup_queue(dev, vq) < 0) {
|
if (virtio_dev_backend_ops(dev)->setup_queue(dev, vq) < 0) {
|
||||||
@ -186,12 +168,13 @@ virtio_init_queue(struct virtio_dev *dev, uint16_t vtpci_queue_idx)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "vq->vq_ring_mem: 0x%" PRIx64 "\n",
|
||||||
|
vq->vq_ring_mem);
|
||||||
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "vq->vq_ring_virt_mem: 0x%" PRIx64 "\n",
|
||||||
|
(uint64_t)(uintptr_t)vq->vq_ring_virt_mem);
|
||||||
|
|
||||||
|
virtio_init_vring(vq);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail_q_alloc:
|
|
||||||
rte_free(vq);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -212,7 +195,6 @@ virtio_free_queues(struct virtio_dev *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtio_dev_backend_ops(dev)->del_queue(dev, vq);
|
virtio_dev_backend_ops(dev)->del_queue(dev, vq);
|
||||||
spdk_dma_free(vq->vq_ring_virt_mem);
|
|
||||||
|
|
||||||
rte_free(vq);
|
rte_free(vq);
|
||||||
dev->vqs[i] = NULL;
|
dev->vqs[i] = NULL;
|
||||||
|
@ -261,6 +261,16 @@ modern_setup_queue(struct virtio_dev *dev, struct virtqueue *vq)
|
|||||||
struct virtio_hw *hw = dev->ctx;
|
struct virtio_hw *hw = dev->ctx;
|
||||||
uint64_t desc_addr, avail_addr, used_addr;
|
uint64_t desc_addr, avail_addr, used_addr;
|
||||||
uint16_t notify_off;
|
uint16_t notify_off;
|
||||||
|
void *queue_mem;
|
||||||
|
uint64_t queue_mem_phys_addr;
|
||||||
|
|
||||||
|
queue_mem = spdk_dma_zmalloc(vq->vq_ring_size, VIRTIO_PCI_VRING_ALIGN, &queue_mem_phys_addr);
|
||||||
|
if (queue_mem == NULL) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
vq->vq_ring_mem = queue_mem_phys_addr;
|
||||||
|
vq->vq_ring_virt_mem = queue_mem;
|
||||||
|
|
||||||
if (!check_vq_phys_addr_ok(vq)) {
|
if (!check_vq_phys_addr_ok(vq)) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -311,6 +321,8 @@ modern_del_queue(struct virtio_dev *dev, struct virtqueue *vq)
|
|||||||
&hw->common_cfg->queue_used_hi);
|
&hw->common_cfg->queue_used_hi);
|
||||||
|
|
||||||
spdk_mmio_write_2(&hw->common_cfg->queue_enable, 0);
|
spdk_mmio_write_2(&hw->common_cfg->queue_enable, 0);
|
||||||
|
|
||||||
|
spdk_dma_free(vq->vq_ring_virt_mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -356,6 +356,8 @@ virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq)
|
|||||||
struct virtio_user_dev *dev = vdev->ctx;
|
struct virtio_user_dev *dev = vdev->ctx;
|
||||||
struct vhost_vring_state state;
|
struct vhost_vring_state state;
|
||||||
uint16_t queue_idx = vq->vq_queue_index;
|
uint16_t queue_idx = vq->vq_queue_index;
|
||||||
|
void *queue_mem;
|
||||||
|
uint64_t queue_mem_phys_addr;
|
||||||
uint64_t desc_addr, avail_addr, used_addr;
|
uint64_t desc_addr, avail_addr, used_addr;
|
||||||
int callfd;
|
int callfd;
|
||||||
int kickfd;
|
int kickfd;
|
||||||
@ -365,6 +367,14 @@ virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queue_mem = spdk_dma_zmalloc(vq->vq_ring_size, VIRTIO_PCI_VRING_ALIGN, &queue_mem_phys_addr);
|
||||||
|
if (queue_mem == NULL) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
vq->vq_ring_mem = queue_mem_phys_addr;
|
||||||
|
vq->vq_ring_virt_mem = queue_mem;
|
||||||
|
|
||||||
/* May use invalid flag, but some backend uses kickfd and
|
/* May use invalid flag, but some backend uses kickfd and
|
||||||
* callfd as criteria to judge if dev is alive. so finally we
|
* callfd as criteria to judge if dev is alive. so finally we
|
||||||
* use real event_fd.
|
* use real event_fd.
|
||||||
@ -427,6 +437,8 @@ virtio_user_del_queue(struct virtio_dev *vdev, struct virtqueue *vq)
|
|||||||
close(dev->kickfds[vq->vq_queue_index]);
|
close(dev->kickfds[vq->vq_queue_index]);
|
||||||
dev->callfds[vq->vq_queue_index] = -1;
|
dev->callfds[vq->vq_queue_index] = -1;
|
||||||
dev->kickfds[vq->vq_queue_index] = -1;
|
dev->kickfds[vq->vq_queue_index] = -1;
|
||||||
|
|
||||||
|
spdk_dma_free(vq->vq_ring_virt_mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user