mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 09:13:55 -06:00
virtio-pci: Implement SR-IOV PF
Allow user to attach SR-IOV VF to a virtio-pci PF. Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> Message-Id: <20250314-sriov-v9-6-57dae8ae3ab5@daynix.com> Tested-by: Yui Washizu <yui.washidu@gmail.com> Tested-by: Pasha Tatashin <pasha.tatashin@soleen.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
19e55471d4
commit
3f9cfaa92c
2 changed files with 16 additions and 5 deletions
|
@ -1962,6 +1962,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
|
||||||
uint8_t *config;
|
uint8_t *config;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
VirtIODevice *vdev = virtio_bus_get_device(bus);
|
VirtIODevice *vdev = virtio_bus_get_device(bus);
|
||||||
|
int16_t res;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Virtio capabilities present without
|
* Virtio capabilities present without
|
||||||
|
@ -2109,6 +2110,14 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
|
||||||
pci_register_bar(&proxy->pci_dev, proxy->legacy_io_bar_idx,
|
pci_register_bar(&proxy->pci_dev, proxy->legacy_io_bar_idx,
|
||||||
PCI_BASE_ADDRESS_SPACE_IO, &proxy->bar);
|
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)
|
static void virtio_pci_device_unplugged(DeviceState *d)
|
||||||
|
@ -2199,7 +2208,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
|
||||||
|
|
||||||
if (pcie_port && pci_is_express(pci_dev)) {
|
if (pcie_port && pci_is_express(pci_dev)) {
|
||||||
int pos;
|
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);
|
pos = pcie_endpoint_cap_init(pci_dev, 0);
|
||||||
assert(pos > 0);
|
assert(pos > 0);
|
||||||
|
@ -2216,9 +2225,9 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
|
||||||
pci_set_word(pci_dev->config + pos + PCI_PM_PMC, 0x3);
|
pci_set_word(pci_dev->config + pos + PCI_PM_PMC, 0x3);
|
||||||
|
|
||||||
if (proxy->flags & VIRTIO_PCI_FLAG_AER) {
|
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);
|
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) {
|
if (proxy->flags & VIRTIO_PCI_FLAG_INIT_DEVERR) {
|
||||||
|
@ -2243,9 +2252,9 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proxy->flags & VIRTIO_PCI_FLAG_ATS) {
|
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);
|
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) {
|
if (proxy->flags & VIRTIO_PCI_FLAG_INIT_FLR) {
|
||||||
|
@ -2273,6 +2282,7 @@ static void virtio_pci_exit(PCIDevice *pci_dev)
|
||||||
!pci_bus_is_root(pci_get_bus(pci_dev));
|
!pci_bus_is_root(pci_get_bus(pci_dev));
|
||||||
bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY;
|
bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY;
|
||||||
|
|
||||||
|
pcie_sriov_pf_exit(&proxy->pci_dev);
|
||||||
msix_uninit_exclusive_bar(pci_dev);
|
msix_uninit_exclusive_bar(pci_dev);
|
||||||
if (proxy->flags & VIRTIO_PCI_FLAG_AER && pcie_port &&
|
if (proxy->flags & VIRTIO_PCI_FLAG_AER && pcie_port &&
|
||||||
pci_is_express(pci_dev)) {
|
pci_is_express(pci_dev)) {
|
||||||
|
|
|
@ -155,6 +155,7 @@ struct VirtIOPCIProxy {
|
||||||
uint32_t modern_io_bar_idx;
|
uint32_t modern_io_bar_idx;
|
||||||
uint32_t modern_mem_bar_idx;
|
uint32_t modern_mem_bar_idx;
|
||||||
int config_cap;
|
int config_cap;
|
||||||
|
uint16_t last_pcie_cap_offset;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
bool disable_modern;
|
bool disable_modern;
|
||||||
bool ignore_backend_features;
|
bool ignore_backend_features;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue