[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 34/63] virtio-pci: Implement SR-IOV PF
From: |
Michael S. Tsirkin |
Subject: |
[PULL 34/63] virtio-pci: Implement SR-IOV PF |
Date: |
Sun, 21 Jul 2024 20:18:00 -0400 |
From: Akihiko Odaki <akihiko.odaki@daynix.com>
Allow user to attach SR-IOV VF to a virtio-pci PF.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-Id: <20240715-sriov-v5-6-3f5539093ffc@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-pci.h | 1 +
hw/virtio/virtio-pci.c | 20 +++++++++++++++-----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h
index 9e67ba38c7..34539f2f67 100644
--- a/include/hw/virtio/virtio-pci.h
+++ b/include/hw/virtio/virtio-pci.h
@@ -152,6 +152,7 @@ struct VirtIOPCIProxy {
uint32_t modern_io_bar_idx;
uint32_t modern_mem_bar_idx;
int config_cap;
+ uint16_t last_pcie_cap_offset;
uint32_t flags;
bool disable_modern;
bool ignore_backend_features;
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 9534730bba..0c8fcc5627 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1955,6 +1955,7 @@ static void virtio_pci_device_plugged(DeviceState *d,
Error **errp)
uint8_t *config;
uint32_t size;
VirtIODevice *vdev = virtio_bus_get_device(bus);
+ int16_t res;
/*
* Virtio capabilities present without
@@ -2100,6 +2101,14 @@ static void virtio_pci_device_plugged(DeviceState *d,
Error **errp)
pci_register_bar(&proxy->pci_dev, proxy->legacy_io_bar_idx,
PCI_BASE_ADDRESS_SPACE_IO, &proxy->bar);
}
+
+ res = pcie_sriov_pf_init_from_user_created_vfs(&proxy->pci_dev,
+ proxy->last_pcie_cap_offset,
+ errp);
+ if (res > 0) {
+ proxy->last_pcie_cap_offset += res;
+ virtio_add_feature(&vdev->host_features, VIRTIO_F_SR_IOV);
+ }
}
static void virtio_pci_device_unplugged(DeviceState *d)
@@ -2187,7 +2196,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error
**errp)
if (pcie_port && pci_is_express(pci_dev)) {
int pos;
- uint16_t last_pcie_cap_offset = PCI_CONFIG_SPACE_SIZE;
+ proxy->last_pcie_cap_offset = PCI_CONFIG_SPACE_SIZE;
pos = pcie_endpoint_cap_init(pci_dev, 0);
assert(pos > 0);
@@ -2207,9 +2216,9 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error
**errp)
pci_set_word(pci_dev->config + pos + PCI_PM_PMC, 0x3);
if (proxy->flags & VIRTIO_PCI_FLAG_AER) {
- pcie_aer_init(pci_dev, PCI_ERR_VER, last_pcie_cap_offset,
+ pcie_aer_init(pci_dev, PCI_ERR_VER, proxy->last_pcie_cap_offset,
PCI_ERR_SIZEOF, NULL);
- last_pcie_cap_offset += PCI_ERR_SIZEOF;
+ proxy->last_pcie_cap_offset += PCI_ERR_SIZEOF;
}
if (proxy->flags & VIRTIO_PCI_FLAG_INIT_DEVERR) {
@@ -2234,9 +2243,9 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error
**errp)
}
if (proxy->flags & VIRTIO_PCI_FLAG_ATS) {
- pcie_ats_init(pci_dev, last_pcie_cap_offset,
+ pcie_ats_init(pci_dev, proxy->last_pcie_cap_offset,
proxy->flags & VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED);
- last_pcie_cap_offset += PCI_EXT_CAP_ATS_SIZEOF;
+ proxy->last_pcie_cap_offset += PCI_EXT_CAP_ATS_SIZEOF;
}
if (proxy->flags & VIRTIO_PCI_FLAG_INIT_FLR) {
@@ -2263,6 +2272,7 @@ static void virtio_pci_exit(PCIDevice *pci_dev)
bool pcie_port = pci_bus_is_express(pci_get_bus(pci_dev)) &&
!pci_bus_is_root(pci_get_bus(pci_dev));
+ pcie_sriov_pf_exit(&proxy->pci_dev);
msix_uninit_exclusive_bar(pci_dev);
if (proxy->flags & VIRTIO_PCI_FLAG_AER && pcie_port &&
pci_is_express(pci_dev)) {
--
MST
- [PULL 25/63] virtio: virtqueue_ordered_flush - VIRTIO_F_IN_ORDER support, (continued)
- [PULL 25/63] virtio: virtqueue_ordered_flush - VIRTIO_F_IN_ORDER support, Michael S. Tsirkin, 2024/07/21
- [PULL 24/63] virtio: virtqueue_ordered_fill - VIRTIO_F_IN_ORDER support, Michael S. Tsirkin, 2024/07/21
- [PULL 23/63] virtio: virtqueue_pop - VIRTIO_F_IN_ORDER support, Michael S. Tsirkin, 2024/07/21
- [PULL 27/63] virtio: Add VIRTIO_F_IN_ORDER property definition, Michael S. Tsirkin, 2024/07/21
- [PULL 29/63] hw/pci: Do not add ROM BAR for SR-IOV VF, Michael S. Tsirkin, 2024/07/21
- [PULL 28/63] contrib/vhost-user-blk: fix overflowing expression, Michael S. Tsirkin, 2024/07/21
- [PULL 26/63] vhost,vhost-user: Add VIRTIO_F_IN_ORDER to vhost feature bits, Michael S. Tsirkin, 2024/07/21
- [PULL 31/63] pcie_sriov: Ensure PF and VF are mutually exclusive, Michael S. Tsirkin, 2024/07/21
- [PULL 30/63] hw/pci: Fix SR-IOV VF number calculation, Michael S. Tsirkin, 2024/07/21
- [PULL 32/63] pcie_sriov: Check PCI Express for SR-IOV PF, Michael S. Tsirkin, 2024/07/21
- [PULL 34/63] virtio-pci: Implement SR-IOV PF,
Michael S. Tsirkin <=
- [PULL 33/63] pcie_sriov: Allow user to create SR-IOV device, Michael S. Tsirkin, 2024/07/21
- [PULL 35/63] virtio-net: Implement SR-IOV VF, Michael S. Tsirkin, 2024/07/21
- [PULL 36/63] docs: Document composable SR-IOV device, Michael S. Tsirkin, 2024/07/21
- [PULL 37/63] smbios: make memory device size configurable per Machine, Michael S. Tsirkin, 2024/07/21
- [PULL 38/63] accel/kvm: Extract common KVM vCPU {creation,parking} code, Michael S. Tsirkin, 2024/07/21
- [PULL 39/63] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file, Michael S. Tsirkin, 2024/07/21
- [PULL 40/63] hw/acpi: Update ACPI GED framework to support vCPU Hotplug, Michael S. Tsirkin, 2024/07/21
- [PULL 50/63] virtio-iommu: Add trace point on virtio_iommu_detach_endpoint_from_domain, Michael S. Tsirkin, 2024/07/21
- [PULL 41/63] hw/acpi: Update GED _EVT method AML with CPU scan, Michael S. Tsirkin, 2024/07/21
- [PULL 47/63] virtio-iommu: Free [host_]resv_ranges on unset_iommu_devices, Michael S. Tsirkin, 2024/07/21