libqos: Added EVENT_IDX support
Added avail_event and NO_NOTIFY check before notifying. Added used_event setting. Signed-off-by: Marc Marí <marc.mari.barcelo@gmail.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
5836811398
commit
1053587c3f
@ -203,6 +203,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
|
||||
vqpci->vq.num_free = vqpci->vq.size;
|
||||
vqpci->vq.align = QVIRTIO_PCI_ALIGN;
|
||||
vqpci->vq.indirect = (feat & QVIRTIO_F_RING_INDIRECT_DESC) != 0;
|
||||
vqpci->vq.event = (feat & QVIRTIO_F_RING_EVENT_IDX) != 0;
|
||||
|
||||
vqpci->msix_entry = -1;
|
||||
vqpci->msix_addr = 0;
|
||||
|
@ -124,9 +124,13 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr)
|
||||
writew(vq->avail, 0);
|
||||
/* vq->avail->idx */
|
||||
writew(vq->avail + 2, 0);
|
||||
/* vq->avail->used_event */
|
||||
writew(vq->avail + 4 + (2 * vq->size), 0);
|
||||
|
||||
/* vq->used->flags */
|
||||
writew(vq->used, 0);
|
||||
/* vq->used->avail_event */
|
||||
writew(vq->used+2+(sizeof(struct QVRingUsedElem)*vq->size), 0);
|
||||
}
|
||||
|
||||
QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
|
||||
@ -222,11 +226,32 @@ void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq,
|
||||
{
|
||||
/* vq->avail->idx */
|
||||
uint16_t idx = readl(vq->avail + 2);
|
||||
/* vq->used->flags */
|
||||
uint16_t flags;
|
||||
/* vq->used->avail_event */
|
||||
uint16_t avail_event;
|
||||
|
||||
/* vq->avail->ring[idx % vq->size] */
|
||||
writel(vq->avail + 4 + (2 * (idx % vq->size)), free_head);
|
||||
/* vq->avail->idx */
|
||||
writel(vq->avail + 2, idx + 1);
|
||||
|
||||
bus->virtqueue_kick(d, vq);
|
||||
/* Must read after idx is updated */
|
||||
flags = readw(vq->avail);
|
||||
avail_event = readw(vq->used + 4 +
|
||||
(sizeof(struct QVRingUsedElem) * vq->size));
|
||||
|
||||
/* < 1 because we add elements to avail queue one by one */
|
||||
if ((flags & QVRING_USED_F_NO_NOTIFY) == 0 &&
|
||||
(!vq->event || (uint16_t)(idx-avail_event) < 1)) {
|
||||
bus->virtqueue_kick(d, vq);
|
||||
}
|
||||
}
|
||||
|
||||
void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx)
|
||||
{
|
||||
g_assert(vq->event);
|
||||
|
||||
/* vq->avail->used_event */
|
||||
writew(vq->avail + 4 + (2 * vq->size), idx);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#define QVIRTIO_F_ANY_LAYOUT 0x08000000
|
||||
#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000
|
||||
#define QVIRTIO_F_RING_EVENT_IDX 0x20000000
|
||||
#define QVIRTIO_F_BAD_FEATURE 0x40000000
|
||||
|
||||
#define QVRING_DESC_F_NEXT 0x1
|
||||
#define QVRING_DESC_F_WRITE 0x2
|
||||
@ -57,6 +58,7 @@ typedef struct QVRingAvail {
|
||||
uint16_t flags;
|
||||
uint16_t idx;
|
||||
uint16_t ring[0]; /* This is an array of uint16_t */
|
||||
uint16_t used_event;
|
||||
} QVRingAvail;
|
||||
|
||||
typedef struct QVRingUsedElem {
|
||||
@ -68,6 +70,7 @@ typedef struct QVRingUsed {
|
||||
uint16_t flags;
|
||||
uint16_t idx;
|
||||
QVRingUsedElem ring[0]; /* This is an array of QVRingUsedElem structs */
|
||||
uint16_t avail_event;
|
||||
} QVRingUsed;
|
||||
|
||||
typedef struct QVirtQueue {
|
||||
@ -80,6 +83,7 @@ typedef struct QVirtQueue {
|
||||
uint32_t num_free;
|
||||
uint32_t align;
|
||||
bool indirect;
|
||||
bool event;
|
||||
} QVirtQueue;
|
||||
|
||||
typedef struct QVRingIndirectDesc {
|
||||
@ -174,4 +178,5 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect);
|
||||
void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq,
|
||||
uint32_t free_head);
|
||||
|
||||
void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx);
|
||||
#endif
|
||||
|
@ -496,6 +496,129 @@ static void pci_msix(void)
|
||||
|
||||
qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head);
|
||||
|
||||
|
||||
g_assert(qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq,
|
||||
QVIRTIO_BLK_TIMEOUT));
|
||||
|
||||
status = readb(req_addr + 528);
|
||||
g_assert_cmpint(status, ==, 0);
|
||||
|
||||
data = g_malloc0(512);
|
||||
memread(req_addr + 16, data, 512);
|
||||
g_assert_cmpstr(data, ==, "TEST");
|
||||
g_free(data);
|
||||
|
||||
guest_free(alloc, req_addr);
|
||||
|
||||
/* End test */
|
||||
guest_free(alloc, (uint64_t)vqpci->vq.desc);
|
||||
qpci_msix_disable(dev->pdev);
|
||||
qvirtio_pci_device_disable(dev);
|
||||
g_free(dev);
|
||||
test_end();
|
||||
}
|
||||
|
||||
static void pci_idx(void)
|
||||
{
|
||||
QVirtioPCIDevice *dev;
|
||||
QPCIBus *bus;
|
||||
QVirtQueuePCI *vqpci;
|
||||
QGuestAllocator *alloc;
|
||||
QVirtioBlkReq req;
|
||||
void *addr;
|
||||
uint64_t req_addr;
|
||||
uint64_t capacity;
|
||||
uint32_t features;
|
||||
uint32_t free_head;
|
||||
uint8_t status;
|
||||
char *data;
|
||||
|
||||
bus = test_start();
|
||||
alloc = pc_alloc_init();
|
||||
|
||||
dev = virtio_blk_init(bus);
|
||||
qpci_msix_enable(dev->pdev);
|
||||
|
||||
qvirtio_pci_set_msix_configuration_vector(dev, alloc, 0);
|
||||
|
||||
/* MSI-X is enabled */
|
||||
addr = dev->addr + QVIRTIO_DEVICE_SPECIFIC_MSIX;
|
||||
|
||||
capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, addr);
|
||||
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
|
||||
|
||||
features = qvirtio_get_features(&qvirtio_pci, &dev->vdev);
|
||||
features = features & ~(QVIRTIO_F_BAD_FEATURE |
|
||||
QVIRTIO_F_RING_INDIRECT_DESC |
|
||||
QVIRTIO_F_NOTIFY_ON_EMPTY | QVIRTIO_BLK_F_SCSI);
|
||||
qvirtio_set_features(&qvirtio_pci, &dev->vdev, features);
|
||||
|
||||
vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
|
||||
alloc, 0);
|
||||
qvirtqueue_pci_msix_setup(dev, vqpci, alloc, 1);
|
||||
|
||||
qvirtio_set_driver_ok(&qvirtio_pci, &dev->vdev);
|
||||
|
||||
/* Write request */
|
||||
req.type = QVIRTIO_BLK_T_OUT;
|
||||
req.ioprio = 1;
|
||||
req.sector = 0;
|
||||
req.data = g_malloc0(512);
|
||||
strcpy(req.data, "TEST");
|
||||
|
||||
req_addr = virtio_blk_request(alloc, &req, 512);
|
||||
|
||||
g_free(req.data);
|
||||
|
||||
free_head = qvirtqueue_add(&vqpci->vq, req_addr, 528, false, true);
|
||||
qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false);
|
||||
qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head);
|
||||
|
||||
g_assert(qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq,
|
||||
QVIRTIO_BLK_TIMEOUT));
|
||||
|
||||
/* Write request */
|
||||
req.type = QVIRTIO_BLK_T_OUT;
|
||||
req.ioprio = 1;
|
||||
req.sector = 1;
|
||||
req.data = g_malloc0(512);
|
||||
strcpy(req.data, "TEST");
|
||||
|
||||
req_addr = virtio_blk_request(alloc, &req, 512);
|
||||
|
||||
g_free(req.data);
|
||||
|
||||
/* Notify after processing the third request */
|
||||
qvirtqueue_set_used_event(&vqpci->vq, 2);
|
||||
free_head = qvirtqueue_add(&vqpci->vq, req_addr, 528, false, true);
|
||||
qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false);
|
||||
qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head);
|
||||
|
||||
/* No notification expected */
|
||||
g_assert(!qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq,
|
||||
QVIRTIO_BLK_TIMEOUT));
|
||||
|
||||
status = readb(req_addr + 528);
|
||||
g_assert_cmpint(status, ==, 0);
|
||||
|
||||
guest_free(alloc, req_addr);
|
||||
|
||||
/* Read request */
|
||||
req.type = QVIRTIO_BLK_T_IN;
|
||||
req.ioprio = 1;
|
||||
req.sector = 1;
|
||||
req.data = g_malloc0(512);
|
||||
|
||||
req_addr = virtio_blk_request(alloc, &req, 512);
|
||||
|
||||
g_free(req.data);
|
||||
|
||||
free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true);
|
||||
qvirtqueue_add(&vqpci->vq, req_addr + 16, 513, true, false);
|
||||
|
||||
qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head);
|
||||
|
||||
|
||||
g_assert(qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq,
|
||||
QVIRTIO_BLK_TIMEOUT));
|
||||
|
||||
@ -527,6 +650,7 @@ int main(int argc, char **argv)
|
||||
g_test_add_func("/virtio/blk/pci/indirect", pci_indirect);
|
||||
g_test_add_func("/virtio/blk/pci/config", pci_config);
|
||||
g_test_add_func("/virtio/blk/pci/msix", pci_msix);
|
||||
g_test_add_func("/virtio/blk/pci/idx", pci_idx);
|
||||
|
||||
ret = g_test_run();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user