Merge tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu into staging
pci: fixes pcie_sriov: fix for user-creation of VFs replaced by v2 pcie sriov: a couple more robustness improvements pci: id docs clarified pci: a bunch of test fixes, robustness Signed-off-by: Michael S. Tsirkin <mst@redhat.com> # -----BEGIN PGP SIGNATURE----- # # iQFDBAABCgAtFiEEXQn9CHHI+FuUyooNKB8NuNKNVGkFAmrpylYPHG1zdEByZWRo # YXQuY29tAAoJECgfDbjSjVRpHV0H/3vwNiHqWPRuDymo+TCK+gysIk1rewMM0a+g # /fQ3L8iDBW+aofKJk6vwDuw03t/CJCUn/HupfESLpEhFM/wRkTCUyWwdfwfSDmO3 # O9kU0fA+JK+P/APDAasPBu+T0iNgHAx4oaLGCwe254zHyDpcYG3ef6+v4tEssXHR # J4HWXS2Oo/gngYtM6FnaqDy73e1G6O7dVlsCvX7z7XCaci0/2aB0Wtf9ttgswVxz # +MntmMccCDCJ9ybBvGgOBbPz/lZHGCoe2a171imo0PHOgV9r5gey0Ma71zz66G4F # Ba/Z046Oq/G5su7D4XIkr6qys6YhEpQhYDKyEnmdFXcHGb6Rvv0= # =MBg5 # -----END PGP SIGNATURE----- # gpg: Signature made Tue 03 Nov 2026 03:49:42 AM PST # gpg: using RSA key 5D09FD0871C8F85B94CA8A0D281F0DB8D28D5469 # gpg: issuer "mst@redhat.com" # gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" [unknown] # gpg: aka "Michael S. Tsirkin <mst@redhat.com>" [unknown] # gpg: WARNING: The key's User ID is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67 # Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469 * tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu: qtest/libqos/pci: Factor msix entry helpers into pci common code qtest/libqos/pci: Fix qpci_msix_enable sharing bar0 qtest/libqos/pci: Enforce balanced iomap/unmap tests/qtest/libquos/pci: Add migration fixup helper for pci devices tests/qtest/ahci: unmap pci bar before reusing device tests/qtest: Enable spapr dma with linear iommu tests/qtest/nvme-test: fix NVMe struct field endianness tests/qtest: Add libqos function for testing MSI-X interrupt status tests/qtest: Fix virtio msix message endianness tests/qtest: Enforce zero for the "un-fired" msix message value pcie_sriov: fix null pointer dereference when initializing PFs in a system with user and device created VFs pcie_sriov: perform additional checks after pci device realization pci: fix null pointer dereference on pci device registration failure pci id: assign pci subsystem id for osmates pci id: clarify pci subsystem id usage pcie_sriov: Adapt bar type array size to the number of regions pcie_sriov: Rework the assert statements checking region numbers Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
05f8e4662a
20 files changed
+319
-224
No files matched your search
@@ -46,8 +46,13 @@ maintained as part of the virtio specification.
|
||||
upstream merge or shipping a distro/product) to avoid conflicts.
|
||||
|
||||
1af4:1100
|
||||
Used as PCI Subsystem ID for existing hardware devices emulated
|
||||
by QEMU.
|
||||
Used as PCI Subsystem ID for existing hardware devices emulated by
|
||||
QEMU, such as the intel chipset devices. Also used for virtio
|
||||
devices and generic pci class devices (1b36:00xx, see below).
|
||||
|
||||
1af4:1101
|
||||
PCI Subsystem ID for OSMates (github.com/osmates), will be used
|
||||
for virtio devices and pci class devices (xhci, nvme).
|
||||
|
||||
1af4:1110
|
||||
ivshmem device (:doc:`ivshmem-spec`)
|
||||
|
||||
+7
-4
@@ -2329,10 +2329,8 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)
|
||||
pci_dev->cap_present |= QEMU_PCIE_CAP_CXL;
|
||||
}
|
||||
|
||||
pci_dev = do_pci_register_device(pci_dev,
|
||||
object_get_typename(OBJECT(qdev)),
|
||||
pci_dev->devfn, errp);
|
||||
if (pci_dev == NULL) {
|
||||
if (!do_pci_register_device(pci_dev, object_get_typename(OBJECT(qdev)),
|
||||
pci_dev->devfn, errp)) {
|
||||
pci_unregister_acpi_index(pci_dev);
|
||||
return;
|
||||
}
|
||||
@@ -2351,6 +2349,11 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)
|
||||
}
|
||||
}
|
||||
|
||||
if (!pcie_sriov_check_after_realize(pci_dev, errp)) {
|
||||
pci_qdev_unrealize(DEVICE(pci_dev));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* A PCIe Downstream Port that do not have ARI Forwarding enabled must
|
||||
* associate only Device 0 with the device attached to the bus
|
||||
|
||||
+22
-2
@@ -158,7 +158,7 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset,
|
||||
BusState *bus = qdev_get_parent_bus(&dev->qdev);
|
||||
int32_t devfn = dev->devfn + vf_offset;
|
||||
|
||||
if (pfs && g_hash_table_contains(pfs, dev->qdev.id)) {
|
||||
if (pfs && dev->qdev.id && g_hash_table_contains(pfs, dev->qdev.id)) {
|
||||
error_setg(errp, "attaching user-created SR-IOV VF unsupported");
|
||||
return false;
|
||||
}
|
||||
@@ -230,7 +230,6 @@ void pcie_sriov_pf_init_vf_bar(PCIDevice *dev, int region_num,
|
||||
assert(sriov_cap > 0);
|
||||
assert(region_num >= 0);
|
||||
assert(region_num < PCI_SRIOV_NUM_BARS);
|
||||
assert(region_num != PCI_ROM_SLOT);
|
||||
|
||||
wmask = ~(size - 1);
|
||||
addr = sriov_cap + PCI_SRIOV_BAR + region_num * 4;
|
||||
@@ -344,6 +343,8 @@ int16_t pcie_sriov_pf_init_from_user_created_vfs(PCIDevice *dev,
|
||||
dev->exp.sriov_pf.vf = vfs;
|
||||
dev->exp.sriov_pf.vf_user_created = true;
|
||||
|
||||
assert(vfs[0]->io_regions[PCI_ROM_SLOT].size == 0);
|
||||
|
||||
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
|
||||
PCIIORegion *region = &vfs[0]->io_regions[i];
|
||||
|
||||
@@ -392,6 +393,25 @@ bool pcie_sriov_register_device(PCIDevice *dev, Error **errp)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pcie_sriov_check_after_realize(PCIDevice *dev, Error **errp)
|
||||
{
|
||||
if (!dev->exp.sriov_pf.vf && dev->qdev.id &&
|
||||
pfs && g_hash_table_contains(pfs, dev->qdev.id)) {
|
||||
error_setg(errp, "attaching user-created SR-IOV VF unsupported");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dev->sriov_pf) {
|
||||
/* some devices might clear their PCIe capability during realization */
|
||||
if (!pci_is_express(dev)) {
|
||||
error_setg(errp, "PCI Express is required for SR-IOV VF");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void pcie_sriov_unregister_device(PCIDevice *dev)
|
||||
{
|
||||
if (dev->sriov_pf && pfs) {
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "qemu/log.h"
|
||||
#include "qemu/module.h"
|
||||
#include "system/kvm.h"
|
||||
#include "system/qtest.h"
|
||||
#include "exec/target_page.h"
|
||||
#include "kvm_ppc.h"
|
||||
#include "migration/vmstate.h"
|
||||
#include "system/dma.h"
|
||||
@@ -125,7 +127,13 @@ static IOMMUTLBEntry spapr_tce_translate_iommu(IOMMUMemoryRegion *iommu,
|
||||
.perm = IOMMU_NONE,
|
||||
};
|
||||
|
||||
if ((addr >> tcet->page_shift) < tcet->nb_table) {
|
||||
if (qtest_enabled()) {
|
||||
/* spapr qtests does not set up the IOMMU, shortcut a linear map */
|
||||
ret.iova = addr & TARGET_PAGE_MASK;
|
||||
ret.translated_addr = addr & TARGET_PAGE_MASK;
|
||||
ret.addr_mask = ~TARGET_PAGE_MASK;
|
||||
ret.perm = IOMMU_RW;
|
||||
} else if ((addr >> tcet->page_shift) < tcet->nb_table) {
|
||||
/* Check if we are in bound */
|
||||
hwaddr page_mask = IOMMU_PAGE_MASK(tcet->page_shift);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "hw/pci/pci.h"
|
||||
|
||||
typedef struct PCIESriovPF {
|
||||
uint8_t vf_bar_type[PCI_NUM_REGIONS]; /* Store type for each VF bar */
|
||||
uint8_t vf_bar_type[PCI_SRIOV_NUM_BARS]; /* Store type for each VF bar */
|
||||
PCIDevice **vf; /* Pointer to an array of num_vfs VF devices */
|
||||
bool vf_user_created; /* If VFs are created by user */
|
||||
} PCIESriovPF;
|
||||
@@ -57,6 +57,8 @@ int16_t pcie_sriov_pf_init_from_user_created_vfs(PCIDevice *dev,
|
||||
bool pcie_sriov_register_device(PCIDevice *dev, Error **errp);
|
||||
void pcie_sriov_unregister_device(PCIDevice *dev);
|
||||
|
||||
bool pcie_sriov_check_after_realize(PCIDevice *dev, Error **errp);
|
||||
|
||||
/*
|
||||
* Default (minimal) page size support values
|
||||
* as required by the SR/IOV standard:
|
||||
|
||||
@@ -85,6 +85,8 @@ static void verify_state(AHCIQState *ahci, uint64_t hba_old)
|
||||
uint64_t hba_base;
|
||||
AHCICommandHeader cmd;
|
||||
|
||||
g_assert_cmphex(ahci->hba_bar.addr, ==, hba_old);
|
||||
|
||||
ahci_fingerprint = qpci_config_readl(ahci->dev, PCI_VENDOR_ID);
|
||||
g_assert_cmphex(ahci_fingerprint, ==, ahci->fingerprint);
|
||||
|
||||
@@ -135,6 +137,7 @@ static void ahci_migrate(AHCIQState *from, AHCIQState *to, const char *uri)
|
||||
memcpy(to, from, sizeof(AHCIQState));
|
||||
to->parent = tmp;
|
||||
to->dev = dev;
|
||||
qpci_migrate_fixup(to->dev, from->dev);
|
||||
|
||||
tmp = from->parent;
|
||||
dev = from->dev;
|
||||
@@ -198,6 +201,7 @@ static void ahci_shutdown(AHCIQState *ahci)
|
||||
{
|
||||
QOSState *qs = ahci->parent;
|
||||
|
||||
ahci_pci_disable(ahci);
|
||||
ahci_clean_mem(ahci);
|
||||
free_ahci_device(ahci->dev);
|
||||
g_free(ahci);
|
||||
@@ -1457,7 +1461,9 @@ static void test_reset(void)
|
||||
CMD_READ_DMA_EXT,
|
||||
CMD_WRITE_DMA_EXT);
|
||||
ahci_set(ahci, AHCI_GHC, AHCI_GHC_HR);
|
||||
stop_ahci_device(ahci);
|
||||
ahci_clean_mem(ahci);
|
||||
start_ahci_device(ahci);
|
||||
}
|
||||
|
||||
ahci_shutdown(ahci);
|
||||
@@ -1523,6 +1529,7 @@ static void test_reset_pending_callback(void)
|
||||
sleep(1);
|
||||
|
||||
/* Start again. */
|
||||
stop_ahci_device(ahci);
|
||||
ahci_clean_mem(ahci);
|
||||
ahci_pci_enable(ahci);
|
||||
ahci_hba_enable(ahci);
|
||||
|
||||
@@ -139,13 +139,6 @@ static void test_e1000e_tx(void *obj, void *data, QGuestAllocator * alloc)
|
||||
{
|
||||
QE1000E_PCI *e1000e = obj;
|
||||
QE1000E *d = &e1000e->e1000e;
|
||||
QOSGraphObject *e_object = obj;
|
||||
QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
|
||||
|
||||
/* FIXME: add spapr support */
|
||||
if (qpci_check_buggy_msi(dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
e1000e_send_verify(d, data, alloc);
|
||||
}
|
||||
@@ -154,13 +147,6 @@ static void test_e1000e_rx(void *obj, void *data, QGuestAllocator * alloc)
|
||||
{
|
||||
QE1000E_PCI *e1000e = obj;
|
||||
QE1000E *d = &e1000e->e1000e;
|
||||
QOSGraphObject *e_object = obj;
|
||||
QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
|
||||
|
||||
/* FIXME: add spapr support */
|
||||
if (qpci_check_buggy_msi(dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
e1000e_receive_verify(d, data, alloc);
|
||||
}
|
||||
@@ -173,13 +159,6 @@ static void test_e1000e_multiple_transfers(void *obj, void *data,
|
||||
|
||||
QE1000E_PCI *e1000e = obj;
|
||||
QE1000E *d = &e1000e->e1000e;
|
||||
QOSGraphObject *e_object = obj;
|
||||
QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
|
||||
|
||||
/* FIXME: add spapr support */
|
||||
if (qpci_check_buggy_msi(dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < iterations; i++) {
|
||||
e1000e_send_verify(d, data, alloc);
|
||||
|
||||
@@ -142,13 +142,6 @@ static void test_igb_tx(void *obj, void *data, QGuestAllocator * alloc)
|
||||
{
|
||||
QE1000E_PCI *e1000e = obj;
|
||||
QE1000E *d = &e1000e->e1000e;
|
||||
QOSGraphObject *e_object = obj;
|
||||
QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
|
||||
|
||||
/* FIXME: add spapr support */
|
||||
if (qpci_check_buggy_msi(dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
igb_send_verify(d, data, alloc);
|
||||
}
|
||||
@@ -157,13 +150,6 @@ static void test_igb_rx(void *obj, void *data, QGuestAllocator * alloc)
|
||||
{
|
||||
QE1000E_PCI *e1000e = obj;
|
||||
QE1000E *d = &e1000e->e1000e;
|
||||
QOSGraphObject *e_object = obj;
|
||||
QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
|
||||
|
||||
/* FIXME: add spapr support */
|
||||
if (qpci_check_buggy_msi(dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
igb_receive_verify(d, data, alloc);
|
||||
}
|
||||
@@ -176,13 +162,6 @@ static void test_igb_multiple_transfers(void *obj, void *data,
|
||||
|
||||
QE1000E_PCI *e1000e = obj;
|
||||
QE1000E *d = &e1000e->e1000e;
|
||||
QOSGraphObject *e_object = obj;
|
||||
QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
|
||||
|
||||
/* FIXME: add spapr support */
|
||||
if (qpci_check_buggy_msi(dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < iterations; i++) {
|
||||
igb_send_verify(d, data, alloc);
|
||||
|
||||
@@ -206,6 +206,11 @@ void ahci_pci_enable(AHCIQState *ahci)
|
||||
|
||||
}
|
||||
|
||||
void ahci_pci_disable(AHCIQState *ahci)
|
||||
{
|
||||
stop_ahci_device(ahci);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map BAR5/ABAR, and engage the PCI device.
|
||||
*/
|
||||
@@ -218,6 +223,12 @@ void start_ahci_device(AHCIQState *ahci)
|
||||
qpci_device_enable(ahci->dev);
|
||||
}
|
||||
|
||||
void stop_ahci_device(AHCIQState *ahci)
|
||||
{
|
||||
/* Unmap AHCI's ABAR (no-op if not mapped) */
|
||||
qpci_iounmap(ahci->dev, ahci->hba_bar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test and initialize the AHCI's HBA memory areas.
|
||||
* Initialize and start any ports with devices attached.
|
||||
@@ -239,6 +250,7 @@ void ahci_hba_enable(AHCIQState *ahci)
|
||||
uint8_t num_cmd_slots;
|
||||
|
||||
g_assert(ahci != NULL);
|
||||
g_assert(ahci->hba_bar.mapped);
|
||||
|
||||
/* Set GHC.AE to 1 */
|
||||
ahci_set(ahci, AHCI_GHC, AHCI_GHC_AE);
|
||||
|
||||
@@ -580,7 +580,9 @@ void ahci_clean_mem(AHCIQState *ahci);
|
||||
QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint);
|
||||
void free_ahci_device(QPCIDevice *dev);
|
||||
void ahci_pci_enable(AHCIQState *ahci);
|
||||
void ahci_pci_disable(AHCIQState *ahci);
|
||||
void start_ahci_device(AHCIQState *ahci);
|
||||
void stop_ahci_device(AHCIQState *ahci);
|
||||
void ahci_hba_enable(AHCIQState *ahci);
|
||||
|
||||
/* Port Management */
|
||||
|
||||
@@ -182,7 +182,6 @@ void qpci_init_generic(QGenericPCIBus *qpci, QTestState *qts,
|
||||
|
||||
qpci->gpex_pio_base = 0x3eff0000;
|
||||
qpci->bus.not_hotpluggable = !hotpluggable;
|
||||
qpci->bus.has_buggy_msi = false;
|
||||
|
||||
qpci->bus.pio_readb = qpci_generic_pio_readb;
|
||||
qpci->bus.pio_readw = qpci_generic_pio_readw;
|
||||
|
||||
@@ -124,9 +124,6 @@ void qpci_init_pc(QPCIBusPC *qpci, QTestState *qts, QGuestAllocator *alloc)
|
||||
{
|
||||
assert(qts);
|
||||
|
||||
/* tests can use pci-bus */
|
||||
qpci->bus.has_buggy_msi = false;
|
||||
|
||||
qpci->bus.pio_readb = qpci_pc_pio_readb;
|
||||
qpci->bus.pio_readw = qpci_pc_pio_readw;
|
||||
qpci->bus.pio_readl = qpci_pc_pio_readl;
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
* PCI devices are always little-endian
|
||||
* SPAPR by default is big-endian
|
||||
* so PCI accessors need to swap data endianness
|
||||
*
|
||||
* The spapr iommu model has a qtest_enabled() check that short-cuts
|
||||
* the TCE table and provides a linear map for DMA, since qtests does
|
||||
* not have a way to make hcalls to set up the TCE table.
|
||||
*/
|
||||
|
||||
static uint8_t qpci_spapr_pio_readb(QPCIBus *bus, uint32_t addr)
|
||||
@@ -155,9 +159,6 @@ void qpci_init_spapr(QPCIBusSPAPR *qpci, QTestState *qts,
|
||||
{
|
||||
assert(qts);
|
||||
|
||||
/* tests cannot use spapr, needs to be fixed first */
|
||||
qpci->bus.has_buggy_msi = true;
|
||||
|
||||
qpci->alloc = alloc;
|
||||
|
||||
qpci->bus.pio_readb = qpci_spapr_pio_readb;
|
||||
|
||||
+192
-25
@@ -53,20 +53,6 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
|
||||
}
|
||||
}
|
||||
|
||||
bool qpci_has_buggy_msi(QPCIDevice *dev)
|
||||
{
|
||||
return dev->bus->has_buggy_msi;
|
||||
}
|
||||
|
||||
bool qpci_check_buggy_msi(QPCIDevice *dev)
|
||||
{
|
||||
if (qpci_has_buggy_msi(dev)) {
|
||||
g_test_skip("Skipping due to incomplete support for MSI");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void qpci_device_set(QPCIDevice *dev, QPCIBus *bus, int devfn)
|
||||
{
|
||||
g_assert(dev);
|
||||
@@ -93,12 +79,17 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
|
||||
void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr)
|
||||
{
|
||||
uint16_t vendor_id, device_id;
|
||||
int i;
|
||||
|
||||
qpci_device_set(dev, bus, addr->devfn);
|
||||
vendor_id = qpci_config_readw(dev, PCI_VENDOR_ID);
|
||||
device_id = qpci_config_readw(dev, PCI_DEVICE_ID);
|
||||
g_assert(!addr->vendor_id || vendor_id == addr->vendor_id);
|
||||
g_assert(!addr->device_id || device_id == addr->device_id);
|
||||
|
||||
for (i = 0; i < QPCI_NUM_REGIONS; i++) {
|
||||
g_assert(!dev->bars_mapped[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t qpci_find_resource_reserve_capability(QPCIDevice *dev)
|
||||
@@ -283,15 +274,21 @@ void qpci_msix_enable(QPCIDevice *dev)
|
||||
|
||||
table = qpci_config_readl(dev, addr + PCI_MSIX_TABLE);
|
||||
bir_table = table & PCI_MSIX_FLAGS_BIRMASK;
|
||||
dev->msix_table_bar = qpci_iomap(dev, bir_table, NULL);
|
||||
if (dev->bars_mapped[bir_table]) {
|
||||
dev->msix_table_bar = dev->bars[bir_table];
|
||||
} else {
|
||||
dev->msix_table_bar_iomap = true;
|
||||
dev->msix_table_bar = qpci_iomap(dev, bir_table, NULL);
|
||||
}
|
||||
dev->msix_table_off = table & ~PCI_MSIX_FLAGS_BIRMASK;
|
||||
|
||||
table = qpci_config_readl(dev, addr + PCI_MSIX_PBA);
|
||||
bir_pba = table & PCI_MSIX_FLAGS_BIRMASK;
|
||||
if (bir_pba != bir_table) {
|
||||
dev->msix_pba_bar = qpci_iomap(dev, bir_pba, NULL);
|
||||
if (dev->bars_mapped[bir_pba]) {
|
||||
dev->msix_pba_bar = dev->bars[bir_pba];
|
||||
} else {
|
||||
dev->msix_pba_bar = dev->msix_table_bar;
|
||||
dev->msix_pba_bar_iomap = true;
|
||||
dev->msix_pba_bar = qpci_iomap(dev, bir_pba, NULL);
|
||||
}
|
||||
dev->msix_pba_off = table & ~PCI_MSIX_FLAGS_BIRMASK;
|
||||
|
||||
@@ -302,6 +299,7 @@ void qpci_msix_disable(QPCIDevice *dev)
|
||||
{
|
||||
uint8_t addr;
|
||||
uint16_t val;
|
||||
uint32_t table;
|
||||
|
||||
g_assert(dev->msix_enabled);
|
||||
addr = qpci_find_capability(dev, PCI_CAP_ID_MSIX, 0);
|
||||
@@ -310,16 +308,55 @@ void qpci_msix_disable(QPCIDevice *dev)
|
||||
qpci_config_writew(dev, addr + PCI_MSIX_FLAGS,
|
||||
val & ~PCI_MSIX_FLAGS_ENABLE);
|
||||
|
||||
if (dev->msix_pba_bar.addr != dev->msix_table_bar.addr) {
|
||||
if (dev->msix_pba_bar_iomap) {
|
||||
dev->msix_pba_bar_iomap = false;
|
||||
qpci_iounmap(dev, dev->msix_pba_bar);
|
||||
} else {
|
||||
/*
|
||||
* If we had reused an existing iomap, ensure it is still mapped
|
||||
* otherwise it would be a bug if it were unmapped before msix is
|
||||
* disabled. A refcounting iomap implementation could avoid this
|
||||
* issue entirely, but let's wait until that's needed.
|
||||
*/
|
||||
uint8_t bir_pba;
|
||||
table = qpci_config_readl(dev, addr + PCI_MSIX_PBA);
|
||||
bir_pba = table & PCI_MSIX_FLAGS_BIRMASK;
|
||||
g_assert(dev->bars_mapped[bir_pba]);
|
||||
}
|
||||
|
||||
if (dev->msix_table_bar_iomap) {
|
||||
dev->msix_table_bar_iomap = false;
|
||||
qpci_iounmap(dev, dev->msix_table_bar);
|
||||
} else {
|
||||
uint8_t bir_table;
|
||||
table = qpci_config_readl(dev, addr + PCI_MSIX_TABLE);
|
||||
bir_table = table & PCI_MSIX_FLAGS_BIRMASK;
|
||||
g_assert(dev->bars_mapped[bir_table]);
|
||||
}
|
||||
qpci_iounmap(dev, dev->msix_table_bar);
|
||||
|
||||
dev->msix_enabled = 0;
|
||||
dev->msix_table_off = 0;
|
||||
dev->msix_pba_off = 0;
|
||||
}
|
||||
|
||||
void qpci_msix_set_entry(QPCIDevice *dev, uint16_t entry,
|
||||
uint64_t guest_addr, uint32_t data)
|
||||
{
|
||||
uint64_t vector_off = dev->msix_table_off + entry * PCI_MSIX_ENTRY_SIZE;
|
||||
|
||||
g_assert(dev->msix_enabled);
|
||||
g_assert_cmpint(entry, <, qpci_msix_table_size(dev));
|
||||
|
||||
qpci_io_writel(dev, dev->msix_table_bar,
|
||||
vector_off + PCI_MSIX_ENTRY_LOWER_ADDR, guest_addr & ~0UL);
|
||||
qpci_io_writel(dev, dev->msix_table_bar,
|
||||
vector_off + PCI_MSIX_ENTRY_UPPER_ADDR,
|
||||
(guest_addr >> 32) & ~0UL);
|
||||
|
||||
qpci_io_writel(dev, dev->msix_table_bar,
|
||||
vector_off + PCI_MSIX_ENTRY_DATA, data);
|
||||
}
|
||||
|
||||
bool qpci_msix_pending(QPCIDevice *dev, uint16_t entry)
|
||||
{
|
||||
uint32_t pba_entry;
|
||||
@@ -327,6 +364,8 @@ bool qpci_msix_pending(QPCIDevice *dev, uint16_t entry)
|
||||
uint64_t off = (entry / 32) * PCI_MSIX_ENTRY_SIZE / 4;
|
||||
|
||||
g_assert(dev->msix_enabled);
|
||||
g_assert_cmpint(entry, <, qpci_msix_table_size(dev));
|
||||
|
||||
pba_entry = qpci_io_readl(dev, dev->msix_pba_bar, dev->msix_pba_off + off);
|
||||
return (pba_entry & (1 << bit_n)) != 0;
|
||||
}
|
||||
@@ -338,6 +377,8 @@ bool qpci_msix_masked(QPCIDevice *dev, uint16_t entry)
|
||||
uint64_t vector_off = dev->msix_table_off + entry * PCI_MSIX_ENTRY_SIZE;
|
||||
|
||||
g_assert(dev->msix_enabled);
|
||||
g_assert_cmpint(entry, <, qpci_msix_table_size(dev));
|
||||
|
||||
addr = qpci_find_capability(dev, PCI_CAP_ID_MSIX, 0);
|
||||
g_assert_cmphex(addr, !=, 0);
|
||||
val = qpci_config_readw(dev, addr + PCI_MSIX_FLAGS);
|
||||
@@ -351,6 +392,86 @@ bool qpci_msix_masked(QPCIDevice *dev, uint16_t entry)
|
||||
}
|
||||
}
|
||||
|
||||
void qpci_msix_set_masked(QPCIDevice *dev, uint16_t entry, bool masked)
|
||||
{
|
||||
uint8_t addr;
|
||||
uint16_t val;
|
||||
uint64_t vector_off = dev->msix_table_off + entry * PCI_MSIX_ENTRY_SIZE;
|
||||
|
||||
g_assert(dev->msix_enabled);
|
||||
g_assert_cmpint(entry, <, qpci_msix_table_size(dev));
|
||||
|
||||
addr = qpci_find_capability(dev, PCI_CAP_ID_MSIX, 0);
|
||||
g_assert_cmphex(addr, !=, 0);
|
||||
val = qpci_config_readw(dev, addr + PCI_MSIX_FLAGS);
|
||||
g_assert(!(val & PCI_MSIX_FLAGS_MASKALL));
|
||||
|
||||
val = qpci_io_readl(dev, dev->msix_table_bar,
|
||||
vector_off + PCI_MSIX_ENTRY_VECTOR_CTRL);
|
||||
if (masked && !(val & PCI_MSIX_ENTRY_CTRL_MASKBIT)) {
|
||||
qpci_io_writel(dev, dev->msix_table_bar,
|
||||
vector_off + PCI_MSIX_ENTRY_VECTOR_CTRL,
|
||||
val | PCI_MSIX_ENTRY_CTRL_MASKBIT);
|
||||
} else if (!masked && (val & PCI_MSIX_ENTRY_CTRL_MASKBIT)) {
|
||||
qpci_io_writel(dev, dev->msix_table_bar,
|
||||
vector_off + PCI_MSIX_ENTRY_VECTOR_CTRL,
|
||||
val & ~PCI_MSIX_ENTRY_CTRL_MASKBIT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* qpci_msix_test_interrupt - test whether MSI-X interrupt has been raised
|
||||
* @dev: PCI device
|
||||
* @msix_entry: MSI-X entry to test
|
||||
* @msix_addr: address of MSI-X message
|
||||
* @msix_data: expected MSI-X message payload
|
||||
*
|
||||
* This tests whether the device has raised an MSI-X interrupt. If the MSI-X
|
||||
* entry is masked, it tests the pending bit array for a pending message
|
||||
* and @msix_addr and @msix_data need not be supplied. If the entry is not
|
||||
* masked, it tests the address for corresponding data to see if the interrupt
|
||||
* fired.
|
||||
*
|
||||
* Note that this does not lower the interrupt, however it does clear the
|
||||
* MSI-X message address to 0 if it is found set. This must be called with
|
||||
* the MSI-X address memory containing either 0 or the value of data, otherwise
|
||||
* it will assert on incorrect message.
|
||||
*/
|
||||
bool qpci_msix_test_interrupt(QPCIDevice *dev, uint16_t msix_entry,
|
||||
uint64_t msix_addr, uint32_t msix_data)
|
||||
{
|
||||
uint32_t data;
|
||||
|
||||
g_assert(dev->msix_enabled);
|
||||
g_assert_cmpint(msix_entry, <, qpci_msix_table_size(dev));
|
||||
|
||||
if (qpci_msix_masked(dev, msix_entry)) {
|
||||
/* No ISR checking should be done if masked, but read anyway */
|
||||
return qpci_msix_pending(dev, msix_entry);
|
||||
}
|
||||
|
||||
/*
|
||||
* 0 is used as the "not fired" sentinel — callers must program a
|
||||
* non-zero MSI-X data value so the pre-zeroed target memory can be
|
||||
* polled reliably.
|
||||
*/
|
||||
g_assert_cmpint(msix_addr, !=, 0);
|
||||
g_assert_cmpint(msix_data, !=, 0);
|
||||
|
||||
/* MSI-X payload is written in little-endian format */
|
||||
qtest_memread(dev->bus->qts, msix_addr, &data, sizeof(data));
|
||||
data = le32_to_cpu(data);
|
||||
if (data == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* got a message, ensure it matches expected value then clear it. */
|
||||
g_assert_cmphex(data, ==, msix_data);
|
||||
qtest_memset(dev->bus->qts, msix_addr, 0, sizeof(data));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t qpci_msix_table_size(QPCIDevice *dev)
|
||||
{
|
||||
uint8_t addr;
|
||||
@@ -515,21 +636,31 @@ void qpci_memwrite(QPCIDevice *dev, QPCIBar token, uint64_t off,
|
||||
dev->bus->memwrite(dev->bus, token.addr + off, buf, len);
|
||||
}
|
||||
|
||||
QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr)
|
||||
static uint8_t qpci_bar_reg(int barno)
|
||||
{
|
||||
QPCIBus *bus = dev->bus;
|
||||
static const int bar_reg_map[] = {
|
||||
PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
|
||||
PCI_BASE_ADDRESS_3, PCI_BASE_ADDRESS_4, PCI_BASE_ADDRESS_5,
|
||||
};
|
||||
|
||||
g_assert(barno >= 0 && barno < QPCI_NUM_REGIONS);
|
||||
|
||||
return bar_reg_map[barno];
|
||||
}
|
||||
|
||||
QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr)
|
||||
{
|
||||
QPCIBus *bus = dev->bus;
|
||||
QPCIBar bar;
|
||||
int bar_reg;
|
||||
uint32_t addr, size;
|
||||
uint32_t io_type;
|
||||
uint64_t loc;
|
||||
|
||||
g_assert(barno >= 0 && barno <= 5);
|
||||
bar_reg = bar_reg_map[barno];
|
||||
g_assert(barno >= 0 && barno < QPCI_NUM_REGIONS);
|
||||
g_assert(!dev->bars_mapped[barno]);
|
||||
|
||||
bar_reg = qpci_bar_reg(barno);
|
||||
|
||||
qpci_config_writel(dev, bar_reg, 0xFFFFFFFF);
|
||||
addr = qpci_config_readl(dev, bar_reg);
|
||||
@@ -572,12 +703,40 @@ QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr)
|
||||
}
|
||||
|
||||
bar.addr = loc;
|
||||
bar.mapped = true;
|
||||
|
||||
dev->bars_mapped[barno] = true;
|
||||
dev->bars[barno] = bar;
|
||||
|
||||
return bar;
|
||||
}
|
||||
|
||||
void qpci_iounmap(QPCIDevice *dev, QPCIBar bar)
|
||||
{
|
||||
/* FIXME */
|
||||
int bar_reg;
|
||||
int i;
|
||||
|
||||
if (!bar.mapped) {
|
||||
return; /* bar was never mapped; no-op */
|
||||
}
|
||||
|
||||
for (i = 0; i < QPCI_NUM_REGIONS; i++) {
|
||||
if (!dev->bars_mapped[i]) {
|
||||
continue;
|
||||
}
|
||||
if (dev->bars[i].addr == bar.addr) {
|
||||
dev->bars_mapped[i] = false;
|
||||
dev->bars[i].mapped = false;
|
||||
bar_reg = qpci_bar_reg(i);
|
||||
qpci_config_writel(dev, bar_reg, 0xFFFFFFFF);
|
||||
/* FIXME: the address space is leaked */
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* bar was not iomap()ed; treat as no-op for callers that may
|
||||
* call iounmap unconditionally during cleanup paths.
|
||||
*/
|
||||
}
|
||||
|
||||
QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr)
|
||||
@@ -586,6 +745,14 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr)
|
||||
return bar;
|
||||
}
|
||||
|
||||
void qpci_migrate_fixup(QPCIDevice *to, QPCIDevice *from)
|
||||
{
|
||||
memcpy(to->bars_mapped, from->bars_mapped, sizeof(from->bars_mapped));
|
||||
memset(from->bars_mapped, 0, sizeof(from->bars_mapped));
|
||||
memcpy(to->bars, from->bars, sizeof(from->bars));
|
||||
memset(from->bars, 0, sizeof(from->bars));
|
||||
}
|
||||
|
||||
void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr)
|
||||
{
|
||||
g_assert(addr);
|
||||
|
||||
@@ -51,7 +51,6 @@ struct QPCIBus {
|
||||
QTestState *qts;
|
||||
uint64_t pio_alloc_ptr, pio_limit;
|
||||
uint64_t mmio_alloc_ptr, mmio_limit;
|
||||
bool has_buggy_msi; /* TRUE for spapr, FALSE for pci */
|
||||
bool not_hotpluggable; /* TRUE if devices cannot be hotplugged */
|
||||
|
||||
};
|
||||
@@ -59,13 +58,24 @@ struct QPCIBus {
|
||||
struct QPCIBar {
|
||||
uint64_t addr;
|
||||
bool is_io;
|
||||
bool mapped;
|
||||
};
|
||||
|
||||
/*
|
||||
* hw/pci permits 7 (PCI_NUM_REGIONS) regions, the last for PCI_ROM_SLOT.
|
||||
* libqos does not implement PCI_ROM_SLOT at the moment, and as such it
|
||||
* permits 6.
|
||||
*/
|
||||
#define QPCI_NUM_REGIONS 6
|
||||
|
||||
struct QPCIDevice
|
||||
{
|
||||
QPCIBus *bus;
|
||||
int devfn;
|
||||
bool bars_mapped[QPCI_NUM_REGIONS];
|
||||
QPCIBar bars[QPCI_NUM_REGIONS];
|
||||
bool msix_enabled;
|
||||
bool msix_table_bar_iomap, msix_pba_bar_iomap;
|
||||
QPCIBar msix_table_bar, msix_pba_bar;
|
||||
uint64_t msix_table_off, msix_pba_off;
|
||||
};
|
||||
@@ -83,15 +93,17 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn);
|
||||
void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr);
|
||||
int qpci_secondary_buses_init(QPCIBus *bus);
|
||||
|
||||
bool qpci_has_buggy_msi(QPCIDevice *dev);
|
||||
bool qpci_check_buggy_msi(QPCIDevice *dev);
|
||||
|
||||
void qpci_device_enable(QPCIDevice *dev);
|
||||
uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id, uint8_t start_addr);
|
||||
void qpci_msix_enable(QPCIDevice *dev);
|
||||
void qpci_msix_disable(QPCIDevice *dev);
|
||||
void qpci_msix_set_entry(QPCIDevice *dev, uint16_t entry,
|
||||
uint64_t guest_addr, uint32_t data);
|
||||
bool qpci_msix_pending(QPCIDevice *dev, uint16_t entry);
|
||||
bool qpci_msix_masked(QPCIDevice *dev, uint16_t entry);
|
||||
void qpci_msix_set_masked(QPCIDevice *dev, uint16_t entry, bool masked);
|
||||
bool qpci_msix_test_interrupt(QPCIDevice *dev, uint16_t msix_entry,
|
||||
uint64_t msix_addr, uint32_t msix_data);
|
||||
uint16_t qpci_msix_table_size(QPCIDevice *dev);
|
||||
|
||||
uint8_t qpci_config_readb(QPCIDevice *dev, uint8_t offset);
|
||||
@@ -122,6 +134,7 @@ void qpci_memwrite(QPCIDevice *bus, QPCIBar token, uint64_t off,
|
||||
const void *buf, size_t len);
|
||||
QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr);
|
||||
void qpci_iounmap(QPCIDevice *dev, QPCIBar addr);
|
||||
void qpci_migrate_fixup(QPCIDevice *to, QPCIDevice *from);
|
||||
QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);
|
||||
|
||||
void qpci_unplug_acpi_device_test(QTestState *qs, const char *id, uint8_t slot);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "standard-headers/linux/pci_regs.h"
|
||||
#include "standard-headers/linux/virtio_pci.h"
|
||||
#include "standard-headers/linux/virtio_config.h"
|
||||
@@ -125,26 +126,6 @@ static void set_status(QVirtioDevice *d, uint8_t status)
|
||||
status);
|
||||
}
|
||||
|
||||
static bool get_msix_status(QVirtioPCIDevice *dev, uint32_t msix_entry,
|
||||
uint32_t msix_addr, uint32_t msix_data)
|
||||
{
|
||||
uint32_t data;
|
||||
|
||||
g_assert_cmpint(msix_entry, !=, -1);
|
||||
if (qpci_msix_masked(dev->pdev, msix_entry)) {
|
||||
/* No ISR checking should be done if masked, but read anyway */
|
||||
return qpci_msix_pending(dev->pdev, msix_entry);
|
||||
}
|
||||
|
||||
data = qtest_readl(dev->pdev->bus->qts, msix_addr);
|
||||
if (data == msix_data) {
|
||||
qtest_writel(dev->pdev->bus->qts, msix_addr, 0);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
|
||||
{
|
||||
QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
|
||||
@@ -152,8 +133,8 @@ static bool get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
|
||||
if (dev->pdev->msix_enabled) {
|
||||
QVirtQueuePCI *vqpci = container_of(vq, QVirtQueuePCI, vq);
|
||||
|
||||
return get_msix_status(dev, vqpci->msix_entry, vqpci->msix_addr,
|
||||
vqpci->msix_data);
|
||||
return qpci_msix_test_interrupt(dev->pdev, vqpci->msix_entry,
|
||||
vqpci->msix_addr, vqpci->msix_data);
|
||||
}
|
||||
|
||||
return qpci_io_readb(dev->pdev, dev->bar, dev->isr_cfg_offset) & 1;
|
||||
@@ -164,8 +145,9 @@ static bool get_config_isr_status(QVirtioDevice *d)
|
||||
QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
|
||||
|
||||
if (dev->pdev->msix_enabled) {
|
||||
return get_msix_status(dev, dev->config_msix_entry,
|
||||
dev->config_msix_addr, dev->config_msix_data);
|
||||
return qpci_msix_test_interrupt(dev->pdev, dev->config_msix_entry,
|
||||
dev->config_msix_addr,
|
||||
dev->config_msix_data);
|
||||
}
|
||||
|
||||
return qpci_io_readb(dev->pdev, dev->bar, dev->isr_cfg_offset) & 2;
|
||||
|
||||
@@ -122,23 +122,12 @@ static void qvirtio_pci_set_status(QVirtioDevice *d, uint8_t status)
|
||||
static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
|
||||
{
|
||||
QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
|
||||
QVirtQueuePCI *vqpci = (QVirtQueuePCI *)vq;
|
||||
uint32_t data;
|
||||
|
||||
if (dev->pdev->msix_enabled) {
|
||||
g_assert_cmpint(vqpci->msix_entry, !=, -1);
|
||||
if (qpci_msix_masked(dev->pdev, vqpci->msix_entry)) {
|
||||
/* No ISR checking should be done if masked, but read anyway */
|
||||
return qpci_msix_pending(dev->pdev, vqpci->msix_entry);
|
||||
} else {
|
||||
data = qtest_readl(dev->pdev->bus->qts, vqpci->msix_addr);
|
||||
if (data == vqpci->msix_data) {
|
||||
qtest_writel(dev->pdev->bus->qts, vqpci->msix_addr, 0);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
QVirtQueuePCI *vqpci = (QVirtQueuePCI *)vq;
|
||||
|
||||
return qpci_msix_test_interrupt(dev->pdev, vqpci->msix_entry,
|
||||
vqpci->msix_addr, vqpci->msix_data);
|
||||
} else {
|
||||
return qpci_io_readb(dev->pdev, dev->bar, VIRTIO_PCI_ISR) & 1;
|
||||
}
|
||||
@@ -147,22 +136,11 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
|
||||
static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d)
|
||||
{
|
||||
QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
|
||||
uint32_t data;
|
||||
|
||||
if (dev->pdev->msix_enabled) {
|
||||
g_assert_cmpint(dev->config_msix_entry, !=, -1);
|
||||
if (qpci_msix_masked(dev->pdev, dev->config_msix_entry)) {
|
||||
/* No ISR checking should be done if masked, but read anyway */
|
||||
return qpci_msix_pending(dev->pdev, dev->config_msix_entry);
|
||||
} else {
|
||||
data = qtest_readl(dev->pdev->bus->qts, dev->config_msix_addr);
|
||||
if (data == dev->config_msix_data) {
|
||||
qtest_writel(dev->pdev->bus->qts, dev->config_msix_addr, 0);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return qpci_msix_test_interrupt(dev->pdev, dev->config_msix_entry,
|
||||
dev->config_msix_addr,
|
||||
dev->config_msix_data);
|
||||
} else {
|
||||
return qpci_io_readb(dev->pdev, dev->bar, VIRTIO_PCI_ISR) & 2;
|
||||
}
|
||||
@@ -312,64 +290,28 @@ void qvirtio_pci_device_disable(QVirtioPCIDevice *d)
|
||||
void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci,
|
||||
QGuestAllocator *alloc, uint16_t entry)
|
||||
{
|
||||
uint32_t control;
|
||||
uint64_t off;
|
||||
|
||||
g_assert(d->pdev->msix_enabled);
|
||||
off = d->pdev->msix_table_off + (entry * 16);
|
||||
|
||||
g_assert_cmpint(entry, >=, 0);
|
||||
g_assert_cmpint(entry, <, qpci_msix_table_size(d->pdev));
|
||||
vqpci->msix_entry = entry;
|
||||
|
||||
vqpci->msix_addr = guest_alloc(alloc, 4);
|
||||
qpci_io_writel(d->pdev, d->pdev->msix_table_bar,
|
||||
off + PCI_MSIX_ENTRY_LOWER_ADDR, vqpci->msix_addr & ~0UL);
|
||||
qpci_io_writel(d->pdev, d->pdev->msix_table_bar,
|
||||
off + PCI_MSIX_ENTRY_UPPER_ADDR,
|
||||
(vqpci->msix_addr >> 32) & ~0UL);
|
||||
qpci_io_writel(d->pdev, d->pdev->msix_table_bar,
|
||||
off + PCI_MSIX_ENTRY_DATA, vqpci->msix_data);
|
||||
|
||||
control = qpci_io_readl(d->pdev, d->pdev->msix_table_bar,
|
||||
off + PCI_MSIX_ENTRY_VECTOR_CTRL);
|
||||
qpci_io_writel(d->pdev, d->pdev->msix_table_bar,
|
||||
off + PCI_MSIX_ENTRY_VECTOR_CTRL,
|
||||
control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT);
|
||||
qtest_memset(d->pdev->bus->qts, vqpci->msix_addr, 0, 4);
|
||||
|
||||
qpci_msix_set_entry(d->pdev, entry, vqpci->msix_addr, vqpci->msix_data);
|
||||
qpci_msix_set_masked(d->pdev, entry, false);
|
||||
d->msix_ops->set_queue_vector(d, vqpci->vq.index, entry);
|
||||
}
|
||||
|
||||
void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d,
|
||||
QGuestAllocator *alloc, uint16_t entry)
|
||||
{
|
||||
uint32_t control;
|
||||
uint64_t off;
|
||||
|
||||
g_assert(d->pdev->msix_enabled);
|
||||
off = d->pdev->msix_table_off + (entry * 16);
|
||||
|
||||
g_assert_cmpint(entry, >=, 0);
|
||||
g_assert_cmpint(entry, <, qpci_msix_table_size(d->pdev));
|
||||
d->config_msix_entry = entry;
|
||||
|
||||
d->config_msix_data = 0x12345678;
|
||||
d->config_msix_addr = guest_alloc(alloc, 4);
|
||||
qtest_memset(d->pdev->bus->qts, d->config_msix_addr, 0, 4);
|
||||
|
||||
qpci_io_writel(d->pdev, d->pdev->msix_table_bar,
|
||||
off + PCI_MSIX_ENTRY_LOWER_ADDR, d->config_msix_addr & ~0UL);
|
||||
qpci_io_writel(d->pdev, d->pdev->msix_table_bar,
|
||||
off + PCI_MSIX_ENTRY_UPPER_ADDR,
|
||||
(d->config_msix_addr >> 32) & ~0UL);
|
||||
qpci_io_writel(d->pdev, d->pdev->msix_table_bar,
|
||||
off + PCI_MSIX_ENTRY_DATA, d->config_msix_data);
|
||||
|
||||
control = qpci_io_readl(d->pdev, d->pdev->msix_table_bar,
|
||||
off + PCI_MSIX_ENTRY_VECTOR_CTRL);
|
||||
qpci_io_writel(d->pdev, d->pdev->msix_table_bar,
|
||||
off + PCI_MSIX_ENTRY_VECTOR_CTRL,
|
||||
control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT);
|
||||
|
||||
qpci_msix_set_entry(d->pdev, entry, d->config_msix_addr,
|
||||
d->config_msix_data);
|
||||
qpci_msix_set_masked(d->pdev, entry, false);
|
||||
d->msix_ops->set_config_vector(d, entry);
|
||||
}
|
||||
|
||||
|
||||
+17
-22
@@ -223,10 +223,12 @@ static void nvme_init_cq(nvme_ctrl *ctrl, nvme_cq *cq, uint16_t db_idx,
|
||||
|
||||
static int nvme_cqe_pending(nvme_cq *cq)
|
||||
{
|
||||
uint16_t status = qtest_readw(
|
||||
cq->common.ctrl->pdev->bus->qts,
|
||||
PHYS_ADDR_OF(NvmeCqe, cq->phys_cqe, [cq->head].status));
|
||||
return (status & 1) == cq->phase;
|
||||
uint16_t status;
|
||||
|
||||
qtest_memread(cq->common.ctrl->pdev->bus->qts,
|
||||
PHYS_ADDR_OF(NvmeCqe, cq->phys_cqe, [cq->head].status),
|
||||
&status, sizeof(status));
|
||||
return (le16_to_cpu(status) & 1) == cq->phase;
|
||||
}
|
||||
|
||||
static int nvme_is_cqe_success(NvmeCqe *cqe)
|
||||
@@ -253,8 +255,8 @@ static NvmeCqe nvme_handle_cqe(nvme_sq *sq)
|
||||
}
|
||||
cq->head = cq_next_head;
|
||||
|
||||
if (cqe.sq_head != sq->head) {
|
||||
sq->head = cqe.sq_head;
|
||||
if (le16_to_cpu(cqe.sq_head) != sq->head) {
|
||||
sq->head = le16_to_cpu(cqe.sq_head);
|
||||
g_test_message("sq %p head = %u", sq, sq->head);
|
||||
}
|
||||
|
||||
@@ -298,15 +300,14 @@ static uint64_t nvme_get_next_sqe(nvme_sq *sq, uint8_t opcode,
|
||||
qtest_memset(sq->common.ctrl->pdev->bus->qts,
|
||||
phys_sqe, 0, sizeof(NvmeCmd));
|
||||
|
||||
#define GUEST_MEM_WRITE(fn, phys_addr, val) \
|
||||
fn(sq->common.ctrl->pdev->bus->qts, phys_addr, (val))
|
||||
#define GUEST_MEM_WRITE(phys_addr, val) \
|
||||
qtest_memwrite(sq->common.ctrl->pdev->bus->qts, phys_addr, &val, sizeof(val))
|
||||
|
||||
GUEST_MEM_WRITE(qtest_writeb,
|
||||
PHYS_ADDR_OF_FIELD(NvmeCmd, phys_sqe, opcode), opcode);
|
||||
GUEST_MEM_WRITE(qtest_writew,
|
||||
PHYS_ADDR_OF_FIELD(NvmeCmd, phys_sqe, cid), cid);
|
||||
GUEST_MEM_WRITE(qtest_writeq,
|
||||
PHYS_ADDR_OF_FIELD(NvmeCmd, phys_sqe, dptr.prp1), prp1);
|
||||
GUEST_MEM_WRITE(PHYS_ADDR_OF_FIELD(NvmeCmd, phys_sqe, opcode), opcode);
|
||||
cid = cpu_to_le16(cid);
|
||||
GUEST_MEM_WRITE(PHYS_ADDR_OF_FIELD(NvmeCmd, phys_sqe, cid), cid);
|
||||
prp1 = cpu_to_le64(prp1);
|
||||
GUEST_MEM_WRITE(PHYS_ADDR_OF_FIELD(NvmeCmd, phys_sqe, dptr.prp1), prp1);
|
||||
|
||||
#undef GUEST_MEM_WRITE
|
||||
|
||||
@@ -344,7 +345,7 @@ static uint64_t nvme_admin_identify_ctrl(nvme_ctrl *ctrl,
|
||||
|
||||
GUEST_MEM_WRITE(qtest_writel,
|
||||
PHYS_ADDR_OF_FIELD(NvmeCmd, phys_cmd_identify, nsid), 0);
|
||||
GUEST_MEM_WRITE(qtest_writel,
|
||||
GUEST_MEM_WRITE(qtest_writeb,
|
||||
PHYS_ADDR_OF_FIELD(NvmeIdentify, phys_cmd_identify, cns),
|
||||
NVME_ID_CNS_CTRL);
|
||||
|
||||
@@ -492,10 +493,6 @@ static void test_migrate(void *obj, void *data, QGuestAllocator *alloc)
|
||||
{ 333, false }
|
||||
};
|
||||
|
||||
if (qpci_check_buggy_msi(pdev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* create temporary dir and prepare unix socket path for migration */
|
||||
tmpfs = g_dir_make_tmp("nvme-test-XXXXXX", &err);
|
||||
if (!tmpfs) {
|
||||
@@ -520,8 +517,6 @@ static void test_migrate(void *obj, void *data, QGuestAllocator *alloc)
|
||||
test_migrate_setup_nvme_ctrl(ctrl);
|
||||
test_migrate_send_nvme_reqs(ctrl, test_reqs, ARRAY_SIZE(test_reqs));
|
||||
|
||||
qpci_iounmap(ctrl->pdev, ctrl->bar);
|
||||
|
||||
dest_cmdline = g_string_new(qos_get_current_command_line());
|
||||
g_string_append_printf(dest_cmdline, " -incoming %s", uri);
|
||||
|
||||
@@ -531,8 +526,8 @@ static void test_migrate(void *obj, void *data, QGuestAllocator *alloc)
|
||||
/* Get access to PCI device from destination VM */
|
||||
nvme = qos_allocate_objects(to, &ctrl->alloc);
|
||||
pdev = &nvme->dev;
|
||||
qpci_migrate_fixup(pdev, ctrl->pdev);
|
||||
ctrl->pdev = pdev;
|
||||
ctrl->bar = qpci_iomap(ctrl->pdev, 0, NULL);
|
||||
g_assert(pdev->bus->qts == to);
|
||||
|
||||
/* Migrate VM */
|
||||
|
||||
@@ -554,14 +554,8 @@ static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc)
|
||||
uint32_t desc_idx;
|
||||
uint8_t status;
|
||||
char *data;
|
||||
QOSGraphObject *blk_object = obj;
|
||||
QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device");
|
||||
QTestState *qts = global_qtest;
|
||||
|
||||
if (qpci_check_buggy_msi(pci_dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
qpci_msix_enable(pdev->pdev);
|
||||
qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0);
|
||||
|
||||
|
||||
@@ -476,14 +476,8 @@ static void msix(void *obj, void *u_data, QGuestAllocator *t_alloc)
|
||||
uint32_t free_head;
|
||||
uint8_t status;
|
||||
char *data;
|
||||
QOSGraphObject *blk_object = obj;
|
||||
QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device");
|
||||
QTestState *qts = global_qtest;
|
||||
|
||||
if (qpci_check_buggy_msi(pci_dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
qpci_msix_enable(pdev->pdev);
|
||||
qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0);
|
||||
|
||||
@@ -586,14 +580,8 @@ static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc)
|
||||
uint32_t desc_idx;
|
||||
uint8_t status;
|
||||
char *data;
|
||||
QOSGraphObject *blk_object = obj;
|
||||
QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device");
|
||||
QTestState *qts = global_qtest;
|
||||
|
||||
if (qpci_check_buggy_msi(pci_dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
qpci_msix_enable(pdev->pdev);
|
||||
qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0);
|
||||
|
||||
|
||||
Reference in new issue
Block a user