2014-02-09 07:32:55 +04:00
|
|
|
/*
|
|
|
|
* QTest testcase for VirtIO Block Device
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 SUSE LINUX Products GmbH
|
2014-09-01 14:07:54 +04:00
|
|
|
* Copyright (c) 2014 Marc Marí
|
2014-02-09 07:32:55 +04:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-02-08 21:08:51 +03:00
|
|
|
#include "qemu/osdep.h"
|
2014-02-09 07:32:55 +04:00
|
|
|
#include "libqtest.h"
|
2016-10-17 13:30:23 +03:00
|
|
|
#include "libqos/libqos-pc.h"
|
2016-10-17 13:30:24 +03:00
|
|
|
#include "libqos/libqos-spapr.h"
|
2014-09-01 14:07:54 +04:00
|
|
|
#include "libqos/virtio.h"
|
|
|
|
#include "libqos/virtio-pci.h"
|
2015-02-25 00:21:55 +03:00
|
|
|
#include "libqos/virtio-mmio.h"
|
|
|
|
#include "libqos/malloc-generic.h"
|
2014-09-01 14:07:56 +04:00
|
|
|
#include "qemu/bswap.h"
|
2016-05-09 15:47:34 +03:00
|
|
|
#include "standard-headers/linux/virtio_ids.h"
|
2016-05-09 15:47:36 +03:00
|
|
|
#include "standard-headers/linux/virtio_config.h"
|
2016-05-09 15:47:37 +03:00
|
|
|
#include "standard-headers/linux/virtio_ring.h"
|
2016-05-09 15:47:39 +03:00
|
|
|
#include "standard-headers/linux/virtio_blk.h"
|
2016-05-09 15:47:41 +03:00
|
|
|
#include "standard-headers/linux/virtio_pci.h"
|
2014-09-01 14:07:56 +04:00
|
|
|
|
|
|
|
#define TEST_IMAGE_SIZE (64 * 1024 * 1024)
|
2014-09-29 19:40:11 +04:00
|
|
|
#define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000)
|
2015-02-25 00:21:55 +03:00
|
|
|
#define PCI_SLOT_HP 0x06
|
2014-09-01 14:07:56 +04:00
|
|
|
#define PCI_SLOT 0x04
|
|
|
|
#define PCI_FN 0x00
|
|
|
|
|
2015-02-25 00:21:55 +03:00
|
|
|
#define MMIO_PAGE_SIZE 4096
|
|
|
|
#define MMIO_DEV_BASE_ADDR 0x0A003E00
|
|
|
|
#define MMIO_RAM_ADDR 0x40000000
|
|
|
|
#define MMIO_RAM_SIZE 0x20000000
|
2014-09-26 13:28:11 +04:00
|
|
|
|
2014-09-01 14:07:56 +04:00
|
|
|
typedef struct QVirtioBlkReq {
|
|
|
|
uint32_t type;
|
|
|
|
uint32_t ioprio;
|
|
|
|
uint64_t sector;
|
|
|
|
char *data;
|
|
|
|
uint8_t status;
|
|
|
|
} QVirtioBlkReq;
|
2014-09-01 14:07:54 +04:00
|
|
|
|
2015-02-25 00:21:52 +03:00
|
|
|
static char *drive_create(void)
|
2014-02-09 07:32:55 +04:00
|
|
|
{
|
2014-09-01 14:07:54 +04:00
|
|
|
int fd, ret;
|
2015-02-25 00:21:52 +03:00
|
|
|
char *tmp_path = g_strdup("/tmp/qtest.XXXXXX");
|
2014-09-01 14:07:54 +04:00
|
|
|
|
|
|
|
/* Create a temporary raw image */
|
|
|
|
fd = mkstemp(tmp_path);
|
|
|
|
g_assert_cmpint(fd, >=, 0);
|
|
|
|
ret = ftruncate(fd, TEST_IMAGE_SIZE);
|
|
|
|
g_assert_cmpint(ret, ==, 0);
|
|
|
|
close(fd);
|
|
|
|
|
2015-02-25 00:21:52 +03:00
|
|
|
return tmp_path;
|
|
|
|
}
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
static QOSState *pci_test_start(void)
|
2015-02-25 00:21:52 +03:00
|
|
|
{
|
2016-10-17 13:30:23 +03:00
|
|
|
QOSState *qs;
|
2016-10-17 13:30:24 +03:00
|
|
|
const char *arch = qtest_get_arch();
|
2015-02-25 00:21:52 +03:00
|
|
|
char *tmp_path;
|
2016-10-17 13:30:23 +03:00
|
|
|
const char *cmd = "-drive if=none,id=drive0,file=%s,format=raw "
|
2017-05-02 19:35:49 +03:00
|
|
|
"-drive if=none,id=drive1,file=null-co://,format=raw "
|
2016-10-17 13:30:23 +03:00
|
|
|
"-device virtio-blk-pci,id=drv0,drive=drive0,"
|
|
|
|
"addr=%x.%x";
|
2015-02-25 00:21:52 +03:00
|
|
|
|
|
|
|
tmp_path = drive_create();
|
|
|
|
|
2016-10-17 13:30:24 +03:00
|
|
|
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
|
|
|
qs = qtest_pc_boot(cmd, tmp_path, PCI_SLOT, PCI_FN);
|
|
|
|
} else if (strcmp(arch, "ppc64") == 0) {
|
|
|
|
qs = qtest_spapr_boot(cmd, tmp_path, PCI_SLOT, PCI_FN);
|
|
|
|
} else {
|
|
|
|
g_printerr("virtio-blk tests are only available on x86 or ppc64\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2014-09-01 14:07:54 +04:00
|
|
|
unlink(tmp_path);
|
2015-02-25 00:21:52 +03:00
|
|
|
g_free(tmp_path);
|
2016-10-17 13:30:23 +03:00
|
|
|
return qs;
|
2014-09-01 14:07:54 +04:00
|
|
|
}
|
|
|
|
|
2015-02-25 00:21:55 +03:00
|
|
|
static void arm_test_start(void)
|
|
|
|
{
|
|
|
|
char *cmdline;
|
|
|
|
char *tmp_path;
|
|
|
|
|
|
|
|
tmp_path = drive_create();
|
|
|
|
|
|
|
|
cmdline = g_strdup_printf("-machine virt "
|
|
|
|
"-drive if=none,id=drive0,file=%s,format=raw "
|
|
|
|
"-device virtio-blk-device,drive=drive0",
|
|
|
|
tmp_path);
|
|
|
|
qtest_start(cmdline);
|
|
|
|
unlink(tmp_path);
|
|
|
|
g_free(tmp_path);
|
|
|
|
g_free(cmdline);
|
|
|
|
}
|
|
|
|
|
2014-09-01 14:07:54 +04:00
|
|
|
static void test_end(void)
|
|
|
|
{
|
|
|
|
qtest_end();
|
|
|
|
}
|
|
|
|
|
2015-02-25 00:21:52 +03:00
|
|
|
static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, int slot)
|
2014-09-01 14:07:54 +04:00
|
|
|
{
|
|
|
|
QVirtioPCIDevice *dev;
|
|
|
|
|
2017-02-07 15:55:14 +03:00
|
|
|
dev = qvirtio_pci_device_find_slot(bus, VIRTIO_ID_BLOCK, slot);
|
2014-09-01 14:07:54 +04:00
|
|
|
g_assert(dev != NULL);
|
2016-05-09 15:47:34 +03:00
|
|
|
g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK);
|
2014-09-26 13:28:11 +04:00
|
|
|
g_assert_cmphex(dev->pdev->devfn, ==, ((slot << 3) | PCI_FN));
|
2014-09-01 14:07:54 +04:00
|
|
|
|
2014-09-01 14:07:55 +04:00
|
|
|
qvirtio_pci_device_enable(dev);
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_reset(&dev->vdev);
|
|
|
|
qvirtio_set_acknowledge(&dev->vdev);
|
|
|
|
qvirtio_set_driver(&dev->vdev);
|
2014-09-01 14:07:55 +04:00
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2016-10-17 13:30:22 +03:00
|
|
|
static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkReq *req)
|
2014-09-01 14:07:56 +04:00
|
|
|
{
|
|
|
|
#ifdef HOST_WORDS_BIGENDIAN
|
2016-10-17 13:30:22 +03:00
|
|
|
const bool host_is_big_endian = true;
|
2014-09-01 14:07:56 +04:00
|
|
|
#else
|
2016-10-17 13:30:22 +03:00
|
|
|
const bool host_is_big_endian = false;
|
2014-09-01 14:07:56 +04:00
|
|
|
#endif
|
|
|
|
|
2016-10-17 13:30:22 +03:00
|
|
|
if (qvirtio_is_big_endian(d) != host_is_big_endian) {
|
2014-09-01 14:07:56 +04:00
|
|
|
req->type = bswap32(req->type);
|
|
|
|
req->ioprio = bswap32(req->ioprio);
|
|
|
|
req->sector = bswap64(req->sector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-17 13:30:22 +03:00
|
|
|
static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d,
|
|
|
|
QVirtioBlkReq *req, uint64_t data_size)
|
2014-09-01 14:07:56 +04:00
|
|
|
{
|
|
|
|
uint64_t addr;
|
|
|
|
uint8_t status = 0xFF;
|
|
|
|
|
|
|
|
g_assert_cmpuint(data_size % 512, ==, 0);
|
|
|
|
addr = guest_alloc(alloc, sizeof(*req) + data_size);
|
|
|
|
|
2016-10-17 13:30:22 +03:00
|
|
|
virtio_blk_fix_request(d, req);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
|
|
|
memwrite(addr, req, 16);
|
|
|
|
memwrite(addr + 16, req->data, data_size);
|
|
|
|
memwrite(addr + 16 + data_size, &status, sizeof(status));
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
|
2016-10-20 06:08:07 +03:00
|
|
|
QVirtQueue *vq)
|
2014-09-01 14:07:55 +04:00
|
|
|
{
|
2014-09-01 14:07:56 +04:00
|
|
|
QVirtioBlkReq req;
|
|
|
|
uint64_t req_addr;
|
2014-09-01 14:07:55 +04:00
|
|
|
uint64_t capacity;
|
2014-09-01 14:07:56 +04:00
|
|
|
uint32_t features;
|
|
|
|
uint32_t free_head;
|
|
|
|
uint8_t status;
|
|
|
|
char *data;
|
2014-09-01 14:07:55 +04:00
|
|
|
|
2016-10-20 06:08:07 +03:00
|
|
|
capacity = qvirtio_config_readq(dev, 0);
|
2015-02-25 00:21:53 +03:00
|
|
|
|
2014-09-01 14:07:55 +04:00
|
|
|
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
|
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
features = qvirtio_get_features(dev);
|
2014-09-01 14:07:56 +04:00
|
|
|
features = features & ~(QVIRTIO_F_BAD_FEATURE |
|
2016-05-09 15:47:37 +03:00
|
|
|
(1u << VIRTIO_RING_F_INDIRECT_DESC) |
|
|
|
|
(1u << VIRTIO_RING_F_EVENT_IDX) |
|
2016-05-09 15:47:39 +03:00
|
|
|
(1u << VIRTIO_BLK_F_SCSI));
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_set_features(dev, features);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_set_driver_ok(dev);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
/* Write and read with 3 descriptor layout */
|
2014-09-01 14:07:56 +04:00
|
|
|
/* Write request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_OUT;
|
2014-09-01 14:07:56 +04:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 0;
|
|
|
|
req.data = g_malloc0(512);
|
|
|
|
strcpy(req.data, "TEST");
|
|
|
|
|
2016-10-17 13:30:22 +03:00
|
|
|
req_addr = virtio_blk_request(alloc, dev, &req, 512);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
|
|
|
g_free(req.data);
|
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
|
|
|
|
qvirtqueue_add(vq, req_addr + 16, 512, false, true);
|
2015-02-25 00:21:52 +03:00
|
|
|
qvirtqueue_add(vq, req_addr + 528, 1, true, false);
|
2015-02-25 00:59:14 +03:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(dev, vq, free_head);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(dev, vq, QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:07:56 +04:00
|
|
|
status = readb(req_addr + 528);
|
|
|
|
g_assert_cmpint(status, ==, 0);
|
|
|
|
|
|
|
|
guest_free(alloc, req_addr);
|
|
|
|
|
|
|
|
/* Read request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_IN;
|
2014-09-01 14:07:56 +04:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 0;
|
|
|
|
req.data = g_malloc0(512);
|
|
|
|
|
2016-10-17 13:30:22 +03:00
|
|
|
req_addr = virtio_blk_request(alloc, dev, &req, 512);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
|
|
|
g_free(req.data);
|
|
|
|
|
2015-02-25 00:21:52 +03:00
|
|
|
free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
|
2015-02-25 00:59:14 +03:00
|
|
|
qvirtqueue_add(vq, req_addr + 16, 512, true, true);
|
|
|
|
qvirtqueue_add(vq, req_addr + 528, 1, true, false);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(dev, vq, free_head);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(dev, vq, QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:07:56 +04:00
|
|
|
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);
|
|
|
|
|
2016-05-09 15:47:36 +03:00
|
|
|
if (features & (1u << VIRTIO_F_ANY_LAYOUT)) {
|
2015-02-25 00:59:14 +03:00
|
|
|
/* Write and read with 2 descriptor layout */
|
|
|
|
/* Write request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_OUT;
|
2015-02-25 00:59:14 +03:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 1;
|
|
|
|
req.data = g_malloc0(512);
|
|
|
|
strcpy(req.data, "TEST");
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2016-10-17 13:30:22 +03:00
|
|
|
req_addr = virtio_blk_request(alloc, dev, &req, 512);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
g_free(req.data);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
free_head = qvirtqueue_add(vq, req_addr, 528, false, true);
|
|
|
|
qvirtqueue_add(vq, req_addr + 528, 1, true, false);
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(dev, vq, free_head);
|
2015-02-25 00:21:52 +03:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(dev, vq, QVIRTIO_BLK_TIMEOUT_US);
|
2015-02-25 00:59:14 +03:00
|
|
|
status = readb(req_addr + 528);
|
|
|
|
g_assert_cmpint(status, ==, 0);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
guest_free(alloc, req_addr);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
/* Read request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_IN;
|
2015-02-25 00:59:14 +03:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 1;
|
|
|
|
req.data = g_malloc0(512);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2016-10-17 13:30:22 +03:00
|
|
|
req_addr = virtio_blk_request(alloc, dev, &req, 512);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
g_free(req.data);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
|
|
|
|
qvirtqueue_add(vq, req_addr + 16, 513, true, false);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(dev, vq, free_head);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(dev, vq, QVIRTIO_BLK_TIMEOUT_US);
|
2015-02-25 00:59:14 +03:00
|
|
|
status = readb(req_addr + 528);
|
|
|
|
g_assert_cmpint(status, ==, 0);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
data = g_malloc0(512);
|
|
|
|
memread(req_addr + 16, data, 512);
|
|
|
|
g_assert_cmpstr(data, ==, "TEST");
|
|
|
|
g_free(data);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
guest_free(alloc, req_addr);
|
|
|
|
}
|
2015-02-25 00:21:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pci_basic(void)
|
|
|
|
{
|
|
|
|
QVirtioPCIDevice *dev;
|
2016-10-17 13:30:23 +03:00
|
|
|
QOSState *qs;
|
2015-02-25 00:21:52 +03:00
|
|
|
QVirtQueuePCI *vqpci;
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
qs = pci_test_start();
|
|
|
|
dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT);
|
2015-02-25 00:21:52 +03:00
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
|
2015-02-25 00:21:52 +03:00
|
|
|
|
2016-10-20 06:08:07 +03:00
|
|
|
test_basic(&dev->vdev, qs->alloc, &vqpci->vq);
|
2014-09-01 14:07:56 +04:00
|
|
|
|
|
|
|
/* End test */
|
2016-10-17 13:30:23 +03:00
|
|
|
qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc);
|
2014-09-01 14:07:55 +04:00
|
|
|
qvirtio_pci_device_disable(dev);
|
2017-02-07 15:55:14 +03:00
|
|
|
qvirtio_pci_device_free(dev);
|
2016-10-17 13:30:23 +03:00
|
|
|
qtest_shutdown(qs);
|
2014-02-09 07:32:55 +04:00
|
|
|
}
|
|
|
|
|
2014-09-01 14:07:57 +04:00
|
|
|
static void pci_indirect(void)
|
|
|
|
{
|
|
|
|
QVirtioPCIDevice *dev;
|
2014-09-01 14:07:59 +04:00
|
|
|
QVirtQueuePCI *vqpci;
|
2016-10-17 13:30:23 +03:00
|
|
|
QOSState *qs;
|
2014-09-01 14:07:57 +04:00
|
|
|
QVirtioBlkReq req;
|
|
|
|
QVRingIndirectDesc *indirect;
|
|
|
|
uint64_t req_addr;
|
|
|
|
uint64_t capacity;
|
|
|
|
uint32_t features;
|
|
|
|
uint32_t free_head;
|
|
|
|
uint8_t status;
|
|
|
|
char *data;
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
qs = pci_test_start();
|
2014-09-01 14:07:57 +04:00
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT);
|
2014-09-01 14:07:57 +04:00
|
|
|
|
2016-10-20 06:08:07 +03:00
|
|
|
capacity = qvirtio_config_readq(&dev->vdev, 0);
|
2014-09-01 14:07:57 +04:00
|
|
|
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
|
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
features = qvirtio_get_features(&dev->vdev);
|
2016-05-09 15:47:37 +03:00
|
|
|
g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=, 0);
|
|
|
|
features = features & ~(QVIRTIO_F_BAD_FEATURE |
|
|
|
|
(1u << VIRTIO_RING_F_EVENT_IDX) |
|
2016-05-09 15:47:39 +03:00
|
|
|
(1u << VIRTIO_BLK_F_SCSI));
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_set_features(&dev->vdev, features);
|
2014-09-01 14:07:57 +04:00
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_set_driver_ok(&dev->vdev);
|
2014-09-01 14:07:57 +04:00
|
|
|
|
|
|
|
/* Write request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_OUT;
|
2014-09-01 14:07:57 +04:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 0;
|
|
|
|
req.data = g_malloc0(512);
|
|
|
|
strcpy(req.data, "TEST");
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512);
|
2014-09-01 14:07:57 +04:00
|
|
|
|
|
|
|
g_free(req.data);
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
indirect = qvring_indirect_desc_setup(&dev->vdev, qs->alloc, 2);
|
2014-09-01 14:07:57 +04:00
|
|
|
qvring_indirect_desc_add(indirect, req_addr, 528, false);
|
|
|
|
qvring_indirect_desc_add(indirect, req_addr + 528, 1, true);
|
2014-09-01 14:07:59 +04:00
|
|
|
free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect);
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
|
2014-09-01 14:07:57 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq,
|
2014-09-29 19:40:12 +04:00
|
|
|
QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:07:57 +04:00
|
|
|
status = readb(req_addr + 528);
|
|
|
|
g_assert_cmpint(status, ==, 0);
|
|
|
|
|
|
|
|
g_free(indirect);
|
2016-10-17 13:30:23 +03:00
|
|
|
guest_free(qs->alloc, req_addr);
|
2014-09-01 14:07:57 +04:00
|
|
|
|
|
|
|
/* Read request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_IN;
|
2014-09-01 14:07:57 +04:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 0;
|
|
|
|
req.data = g_malloc0(512);
|
|
|
|
strcpy(req.data, "TEST");
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512);
|
2014-09-01 14:07:57 +04:00
|
|
|
|
|
|
|
g_free(req.data);
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
indirect = qvring_indirect_desc_setup(&dev->vdev, qs->alloc, 2);
|
2014-09-01 14:07:57 +04:00
|
|
|
qvring_indirect_desc_add(indirect, req_addr, 16, false);
|
|
|
|
qvring_indirect_desc_add(indirect, req_addr + 16, 513, true);
|
2014-09-01 14:07:59 +04:00
|
|
|
free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect);
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
|
2014-09-01 14:07:57 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq,
|
2014-09-29 19:40:12 +04:00
|
|
|
QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:07:57 +04:00
|
|
|
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);
|
|
|
|
|
|
|
|
g_free(indirect);
|
2016-10-17 13:30:23 +03:00
|
|
|
guest_free(qs->alloc, req_addr);
|
2014-09-01 14:07:57 +04:00
|
|
|
|
|
|
|
/* End test */
|
2016-10-17 13:30:23 +03:00
|
|
|
qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc);
|
2014-09-01 14:07:57 +04:00
|
|
|
qvirtio_pci_device_disable(dev);
|
2017-02-07 15:55:14 +03:00
|
|
|
qvirtio_pci_device_free(dev);
|
2016-10-17 13:30:23 +03:00
|
|
|
qtest_shutdown(qs);
|
2014-09-01 14:07:57 +04:00
|
|
|
}
|
|
|
|
|
2014-09-01 14:07:58 +04:00
|
|
|
static void pci_config(void)
|
|
|
|
{
|
|
|
|
QVirtioPCIDevice *dev;
|
2016-10-17 13:30:23 +03:00
|
|
|
QOSState *qs;
|
2014-09-01 14:07:58 +04:00
|
|
|
int n_size = TEST_IMAGE_SIZE / 2;
|
|
|
|
uint64_t capacity;
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
qs = pci_test_start();
|
2014-09-01 14:07:58 +04:00
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT);
|
2014-09-01 14:07:58 +04:00
|
|
|
|
2016-10-20 06:08:07 +03:00
|
|
|
capacity = qvirtio_config_readq(&dev->vdev, 0);
|
2014-09-01 14:07:58 +04:00
|
|
|
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
|
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_set_driver_ok(&dev->vdev);
|
2014-09-01 14:07:58 +04:00
|
|
|
|
2016-11-10 11:27:11 +03:00
|
|
|
qmp_discard_response("{ 'execute': 'block_resize', "
|
|
|
|
" 'arguments': { 'device': 'drive0', "
|
|
|
|
" 'size': %d } }", n_size);
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_config_isr(&dev->vdev, QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:07:58 +04:00
|
|
|
|
2016-10-20 06:08:07 +03:00
|
|
|
capacity = qvirtio_config_readq(&dev->vdev, 0);
|
2014-09-01 14:07:58 +04:00
|
|
|
g_assert_cmpint(capacity, ==, n_size / 512);
|
|
|
|
|
|
|
|
qvirtio_pci_device_disable(dev);
|
2017-02-07 15:55:14 +03:00
|
|
|
qvirtio_pci_device_free(dev);
|
2016-10-17 13:30:23 +03:00
|
|
|
|
|
|
|
qtest_shutdown(qs);
|
2014-09-01 14:07:58 +04:00
|
|
|
}
|
|
|
|
|
2014-09-01 14:07:59 +04:00
|
|
|
static void pci_msix(void)
|
|
|
|
{
|
|
|
|
QVirtioPCIDevice *dev;
|
2016-10-17 13:30:23 +03:00
|
|
|
QOSState *qs;
|
2014-09-01 14:07:59 +04:00
|
|
|
QVirtQueuePCI *vqpci;
|
|
|
|
QVirtioBlkReq req;
|
|
|
|
int n_size = TEST_IMAGE_SIZE / 2;
|
|
|
|
uint64_t req_addr;
|
|
|
|
uint64_t capacity;
|
|
|
|
uint32_t features;
|
|
|
|
uint32_t free_head;
|
|
|
|
uint8_t status;
|
|
|
|
char *data;
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
qs = pci_test_start();
|
2014-09-01 14:07:59 +04:00
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT);
|
2014-09-01 14:07:59 +04:00
|
|
|
qpci_msix_enable(dev->pdev);
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
qvirtio_pci_set_msix_configuration_vector(dev, qs->alloc, 0);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
2016-10-20 06:08:07 +03:00
|
|
|
capacity = qvirtio_config_readq(&dev->vdev, 0);
|
2014-09-01 14:07:59 +04:00
|
|
|
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
|
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
features = qvirtio_get_features(&dev->vdev);
|
2014-09-01 14:07:59 +04:00
|
|
|
features = features & ~(QVIRTIO_F_BAD_FEATURE |
|
2016-05-09 15:47:37 +03:00
|
|
|
(1u << VIRTIO_RING_F_INDIRECT_DESC) |
|
|
|
|
(1u << VIRTIO_RING_F_EVENT_IDX) |
|
2016-05-09 15:47:39 +03:00
|
|
|
(1u << VIRTIO_BLK_F_SCSI));
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_set_features(&dev->vdev, features);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
|
|
|
|
qvirtqueue_pci_msix_setup(dev, vqpci, qs->alloc, 1);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_set_driver_ok(&dev->vdev);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
2016-11-10 11:27:11 +03:00
|
|
|
qmp_discard_response("{ 'execute': 'block_resize', "
|
|
|
|
" 'arguments': { 'device': 'drive0', "
|
|
|
|
" 'size': %d } }", n_size);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_config_isr(&dev->vdev, QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
2016-10-20 06:08:07 +03:00
|
|
|
capacity = qvirtio_config_readq(&dev->vdev, 0);
|
2014-09-01 14:07:59 +04:00
|
|
|
g_assert_cmpint(capacity, ==, n_size / 512);
|
|
|
|
|
|
|
|
/* Write request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_OUT;
|
2014-09-01 14:07:59 +04:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 0;
|
|
|
|
req.data = g_malloc0(512);
|
|
|
|
strcpy(req.data, "TEST");
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
|
|
|
g_free(req.data);
|
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true);
|
|
|
|
qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true);
|
2014-09-01 14:07:59 +04:00
|
|
|
qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false);
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq,
|
2014-09-29 19:40:12 +04:00
|
|
|
QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
|
|
|
status = readb(req_addr + 528);
|
|
|
|
g_assert_cmpint(status, ==, 0);
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
guest_free(qs->alloc, req_addr);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
|
|
|
/* Read request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_IN;
|
2014-09-01 14:07:59 +04:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 0;
|
|
|
|
req.data = g_malloc0(512);
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
|
|
|
g_free(req.data);
|
|
|
|
|
|
|
|
free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true);
|
2015-02-25 00:59:14 +03:00
|
|
|
qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, true, true);
|
|
|
|
qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
2014-09-01 14:08:00 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq,
|
2014-09-29 19:40:12 +04:00
|
|
|
QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
guest_free(qs->alloc, req_addr);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
|
|
|
/* End test */
|
2016-10-17 13:30:23 +03:00
|
|
|
qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc);
|
2014-09-01 14:08:00 +04:00
|
|
|
qpci_msix_disable(dev->pdev);
|
|
|
|
qvirtio_pci_device_disable(dev);
|
2017-02-07 15:55:14 +03:00
|
|
|
qvirtio_pci_device_free(dev);
|
2016-10-17 13:30:23 +03:00
|
|
|
qtest_shutdown(qs);
|
2014-09-01 14:08:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pci_idx(void)
|
|
|
|
{
|
|
|
|
QVirtioPCIDevice *dev;
|
2016-10-17 13:30:23 +03:00
|
|
|
QOSState *qs;
|
2014-09-01 14:08:00 +04:00
|
|
|
QVirtQueuePCI *vqpci;
|
|
|
|
QVirtioBlkReq req;
|
|
|
|
uint64_t req_addr;
|
|
|
|
uint64_t capacity;
|
|
|
|
uint32_t features;
|
|
|
|
uint32_t free_head;
|
|
|
|
uint8_t status;
|
|
|
|
char *data;
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
qs = pci_test_start();
|
2014-09-01 14:08:00 +04:00
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT);
|
2014-09-01 14:08:00 +04:00
|
|
|
qpci_msix_enable(dev->pdev);
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
qvirtio_pci_set_msix_configuration_vector(dev, qs->alloc, 0);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
2016-10-20 06:08:07 +03:00
|
|
|
capacity = qvirtio_config_readq(&dev->vdev, 0);
|
2014-09-01 14:08:00 +04:00
|
|
|
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
|
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
features = qvirtio_get_features(&dev->vdev);
|
2014-09-01 14:08:00 +04:00
|
|
|
features = features & ~(QVIRTIO_F_BAD_FEATURE |
|
2016-05-09 15:47:37 +03:00
|
|
|
(1u << VIRTIO_RING_F_INDIRECT_DESC) |
|
2016-05-09 15:47:36 +03:00
|
|
|
(1u << VIRTIO_F_NOTIFY_ON_EMPTY) |
|
2016-05-09 15:47:39 +03:00
|
|
|
(1u << VIRTIO_BLK_F_SCSI));
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_set_features(&dev->vdev, features);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
|
|
|
|
qvirtqueue_pci_msix_setup(dev, vqpci, qs->alloc, 1);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_set_driver_ok(&dev->vdev);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
|
|
|
/* Write request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_OUT;
|
2014-09-01 14:08:00 +04:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 0;
|
|
|
|
req.data = g_malloc0(512);
|
|
|
|
strcpy(req.data, "TEST");
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
|
|
|
g_free(req.data);
|
|
|
|
|
2015-02-25 00:59:14 +03:00
|
|
|
free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true);
|
|
|
|
qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true);
|
2014-09-01 14:08:00 +04:00
|
|
|
qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false);
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq, QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
|
|
|
/* Write request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_OUT;
|
2014-09-01 14:08:00 +04:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 1;
|
|
|
|
req.data = g_malloc0(512);
|
|
|
|
strcpy(req.data, "TEST");
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
|
|
|
g_free(req.data);
|
|
|
|
|
|
|
|
/* Notify after processing the third request */
|
|
|
|
qvirtqueue_set_used_event(&vqpci->vq, 2);
|
2015-02-25 00:59:14 +03:00
|
|
|
free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true);
|
|
|
|
qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true);
|
2014-09-01 14:08:00 +04:00
|
|
|
qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false);
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
|
|
|
/* No notification expected */
|
2016-10-17 13:30:21 +03:00
|
|
|
status = qvirtio_wait_status_byte_no_isr(&dev->vdev,
|
2014-09-29 19:40:11 +04:00
|
|
|
&vqpci->vq, req_addr + 528,
|
|
|
|
QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:08:00 +04:00
|
|
|
g_assert_cmpint(status, ==, 0);
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
guest_free(qs->alloc, req_addr);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
|
|
|
/* Read request */
|
2016-05-09 15:47:39 +03:00
|
|
|
req.type = VIRTIO_BLK_T_IN;
|
2014-09-01 14:08:00 +04:00
|
|
|
req.ioprio = 1;
|
|
|
|
req.sector = 1;
|
|
|
|
req.data = g_malloc0(512);
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
|
|
|
g_free(req.data);
|
|
|
|
|
|
|
|
free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true);
|
2015-02-25 00:59:14 +03:00
|
|
|
qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, true, true);
|
|
|
|
qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
|
2014-09-01 14:08:00 +04:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq,
|
2014-09-29 19:40:12 +04:00
|
|
|
QVIRTIO_BLK_TIMEOUT_US);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
guest_free(qs->alloc, req_addr);
|
2014-09-01 14:07:59 +04:00
|
|
|
|
|
|
|
/* End test */
|
2016-10-17 13:30:23 +03:00
|
|
|
qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc);
|
2014-09-01 14:07:59 +04:00
|
|
|
qpci_msix_disable(dev->pdev);
|
|
|
|
qvirtio_pci_device_disable(dev);
|
2017-02-07 15:55:14 +03:00
|
|
|
qvirtio_pci_device_free(dev);
|
2016-10-17 13:30:23 +03:00
|
|
|
qtest_shutdown(qs);
|
2014-09-01 14:07:59 +04:00
|
|
|
}
|
|
|
|
|
2015-02-25 00:21:52 +03:00
|
|
|
static void pci_hotplug(void)
|
2014-09-26 13:28:11 +04:00
|
|
|
{
|
|
|
|
QVirtioPCIDevice *dev;
|
2016-10-17 13:30:23 +03:00
|
|
|
QOSState *qs;
|
2016-10-17 13:30:24 +03:00
|
|
|
const char *arch = qtest_get_arch();
|
2014-09-26 13:28:11 +04:00
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
qs = pci_test_start();
|
2014-09-26 13:28:11 +04:00
|
|
|
|
|
|
|
/* plug secondary disk */
|
|
|
|
qpci_plug_device_test("virtio-blk-pci", "drv1", PCI_SLOT_HP,
|
|
|
|
"'drive': 'drive1'");
|
|
|
|
|
2016-10-17 13:30:23 +03:00
|
|
|
dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT_HP);
|
2014-09-26 13:28:11 +04:00
|
|
|
g_assert(dev);
|
|
|
|
qvirtio_pci_device_disable(dev);
|
2017-02-07 15:55:14 +03:00
|
|
|
qvirtio_pci_device_free(dev);
|
2014-09-26 13:28:11 +04:00
|
|
|
|
|
|
|
/* unplug secondary disk */
|
2016-10-17 13:30:24 +03:00
|
|
|
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
|
|
|
qpci_unplug_acpi_device_test("drv1", PCI_SLOT_HP);
|
|
|
|
}
|
2016-10-17 13:30:23 +03:00
|
|
|
qtest_shutdown(qs);
|
2014-09-26 13:28:11 +04:00
|
|
|
}
|
|
|
|
|
2015-02-25 00:21:55 +03:00
|
|
|
static void mmio_basic(void)
|
|
|
|
{
|
|
|
|
QVirtioMMIODevice *dev;
|
|
|
|
QVirtQueue *vq;
|
|
|
|
QGuestAllocator *alloc;
|
|
|
|
int n_size = TEST_IMAGE_SIZE / 2;
|
|
|
|
uint64_t capacity;
|
|
|
|
|
|
|
|
arm_test_start();
|
|
|
|
|
|
|
|
dev = qvirtio_mmio_init_device(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE);
|
|
|
|
g_assert(dev != NULL);
|
2016-05-09 15:47:34 +03:00
|
|
|
g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK);
|
2015-02-25 00:21:55 +03:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_reset(&dev->vdev);
|
|
|
|
qvirtio_set_acknowledge(&dev->vdev);
|
|
|
|
qvirtio_set_driver(&dev->vdev);
|
2015-02-25 00:21:55 +03:00
|
|
|
|
|
|
|
alloc = generic_alloc_init(MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE_SIZE);
|
2016-10-17 13:30:21 +03:00
|
|
|
vq = qvirtqueue_setup(&dev->vdev, alloc, 0);
|
2015-02-25 00:21:55 +03:00
|
|
|
|
2016-10-20 06:08:07 +03:00
|
|
|
test_basic(&dev->vdev, alloc, vq);
|
2015-02-25 00:21:55 +03:00
|
|
|
|
2016-11-10 11:27:11 +03:00
|
|
|
qmp_discard_response("{ 'execute': 'block_resize', "
|
|
|
|
" 'arguments': { 'device': 'drive0', "
|
|
|
|
" 'size': %d } }", n_size);
|
2015-02-25 00:21:55 +03:00
|
|
|
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtio_wait_queue_isr(&dev->vdev, vq, QVIRTIO_BLK_TIMEOUT_US);
|
2015-02-25 00:21:55 +03:00
|
|
|
|
2016-10-20 06:08:07 +03:00
|
|
|
capacity = qvirtio_config_readq(&dev->vdev, 0);
|
2015-02-25 00:21:55 +03:00
|
|
|
g_assert_cmpint(capacity, ==, n_size / 512);
|
|
|
|
|
|
|
|
/* End test */
|
2016-10-17 13:30:21 +03:00
|
|
|
qvirtqueue_cleanup(dev->vdev.bus, vq, alloc);
|
2015-02-25 00:21:55 +03:00
|
|
|
g_free(dev);
|
2016-10-17 13:30:23 +03:00
|
|
|
generic_alloc_uninit(alloc);
|
2015-02-25 00:21:55 +03:00
|
|
|
test_end();
|
|
|
|
}
|
|
|
|
|
2014-02-09 07:32:55 +04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2015-02-25 00:21:55 +03:00
|
|
|
const char *arch = qtest_get_arch();
|
2014-02-09 07:32:55 +04:00
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
|
2016-10-17 13:30:24 +03:00
|
|
|
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0 ||
|
|
|
|
strcmp(arch, "ppc64") == 0) {
|
2015-02-25 00:21:55 +03:00
|
|
|
qtest_add_func("/virtio/blk/pci/basic", pci_basic);
|
|
|
|
qtest_add_func("/virtio/blk/pci/indirect", pci_indirect);
|
|
|
|
qtest_add_func("/virtio/blk/pci/config", pci_config);
|
2016-10-17 13:30:24 +03:00
|
|
|
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
|
|
|
qtest_add_func("/virtio/blk/pci/msix", pci_msix);
|
|
|
|
qtest_add_func("/virtio/blk/pci/idx", pci_idx);
|
|
|
|
}
|
2015-02-25 00:21:55 +03:00
|
|
|
qtest_add_func("/virtio/blk/pci/hotplug", pci_hotplug);
|
|
|
|
} else if (strcmp(arch, "arm") == 0) {
|
|
|
|
qtest_add_func("/virtio/blk/mmio/basic", mmio_basic);
|
|
|
|
}
|
2014-02-09 07:32:55 +04:00
|
|
|
|
2016-06-14 00:57:58 +03:00
|
|
|
return g_test_run();
|
2014-02-09 07:32:55 +04:00
|
|
|
}
|