Skip to contentSkip to conversation

virtio-pci: Add Function Level Reset support

PATCH Superseded Julia Suvorova 2 participants 3 messages Aug 7, 2019 – Aug 14, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-pci: Add Function Level Reset support

Using FLR becomes convenient in cases where resetting the bus is impractical, for example, when debugging the behavior of individual functions.

---
 hw/virtio/virtio-pci.c | 10 ++++++++++
 hw/virtio/virtio-pci.h |  1 +
 2 files changed, 11 insertions(+)
hw/virtio/virtio-pci.c +10 -0
index f6d2223e78..37c5d6efbc 100644
@@ -599,6 +599,10 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
 
     pci_default_write_config(pci_dev, address, val, len);
 
+    if (proxy->has_flr) {
+        pcie_cap_flr_write_config(pci_dev, address, val, len);
+    }
+
     if (range_covers_byte(address, len, PCI_COMMAND) &&
         !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
         virtio_pci_stop_ioeventfd(proxy);
@@ -1718,6 +1722,8 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
     proxy->notify_pio.size = 0x4;
     proxy->notify_pio.type = VIRTIO_PCI_CAP_NOTIFY_CFG;
 
+    proxy->has_flr = false;
+
     /* subclasses can enforce modern, so do this unconditionally */
     memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci",
                        /* PCI BAR regions must be powers of 2 */
@@ -1749,6 +1755,10 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
 
         pci_dev->exp.pm_cap = pos;
 
+        /* Set Function Level Reset capability bit */
+        pcie_cap_flr_init(pci_dev);
+        proxy->has_flr = true;
+
         /*
          * Indicates that this function complies with revision 1.2 of the
          * PCI Power Management Interface Specification.
hw/virtio/virtio-pci.h +1 -0
index 292275acb1..16d293a6bf 100644
@@ -152,6 +152,7 @@ struct VirtIOPCIProxy {
     VirtIOIRQFD *vector_irqfd;
     int nvqs_with_notifiers;
     VirtioBusState bus;
+    bool has_flr;
 };
 
 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
Signature · 1 line
2.21.0
#1 lore raw
Quoted 35 lines · Julia Suvorova

Using FLR becomes convenient in cases where resetting the bus is impractical, for example, when debugging the behavior of individual functions.

---
 hw/virtio/virtio-pci.c | 10 ++++++++++
 hw/virtio/virtio-pci.h |  1 +
 2 files changed, 11 insertions(+)
hw/virtio/virtio-pci.c +6 -0
index f6d2223e78..37c5d6efbc 100644
@@ -599,6 +599,10 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
 
     pci_default_write_config(pci_dev, address, val, len);
 
+    if (proxy->has_flr) {
+        pcie_cap_flr_write_config(pci_dev, address, val, len);
+    }
+
     if (range_covers_byte(address, len, PCI_COMMAND) &&
         !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
         virtio_pci_stop_ioeventfd(proxy);
@@ -1718,6 +1722,8 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
     proxy->notify_pio.size = 0x4;
     proxy->notify_pio.type = VIRTIO_PCI_CAP_NOTIFY_CFG;
 
+    proxy->has_flr = false;
+
     /* subclasses can enforce modern, so do this unconditionally */
     memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci",
                        /* PCI BAR regions must be powers of 2 */

hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) · line 1764

Quoted 10 lines
hw/virtio/virtio-pci.c +4 -0
@@ -1749,6 +1755,10 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
 
         pci_dev->exp.pm_cap = pos;
 
+        /* Set Function Level Reset capability bit */
+        pcie_cap_flr_init(pci_dev);
+        proxy->has_flr = true;
+
         /*
          * Indicates that this function complies with revision 1.2 of the
          * PCI Power Management Interface Specification.

I don't think we can set this for everyone: this will break things like cross version migration.

Quoted 17 lines
hw/virtio/virtio-pci.h +1 -0
index 292275acb1..16d293a6bf 100644
@@ -152,6 +152,7 @@ struct VirtIOPCIProxy {
     VirtIOIRQFD *vector_irqfd;
     int nvqs_with_notifiers;
     VirtioBusState bus;
+    bool has_flr;
 };
 
 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
Signature · 2 lines
-- 
2.21.0
#2 lore raw
Quoted 40 lines · Michael S. Tsirkin
Quoted 38 lines · Julia Suvorova

Using FLR becomes convenient in cases where resetting the bus is impractical, for example, when debugging the behavior of individual functions.

---
 hw/virtio/virtio-pci.c | 10 ++++++++++
 hw/virtio/virtio-pci.h |  1 +
 2 files changed, 11 insertions(+)
hw/virtio/virtio-pci.c +6 -0
index f6d2223e78..37c5d6efbc 100644
@@ -599,6 +599,10 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
 
     pci_default_write_config(pci_dev, address, val, len);
 
+    if (proxy->has_flr) {
+        pcie_cap_flr_write_config(pci_dev, address, val, len);
+    }
+
     if (range_covers_byte(address, len, PCI_COMMAND) &&
         !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
         virtio_pci_stop_ioeventfd(proxy);
@@ -1718,6 +1722,8 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
     proxy->notify_pio.size = 0x4;
     proxy->notify_pio.type = VIRTIO_PCI_CAP_NOTIFY_CFG;
 
+    proxy->has_flr = false;
+
     /* subclasses can enforce modern, so do this unconditionally */
     memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci",
                        /* PCI BAR regions must be powers of 2 */
@@ -1749,6 +1755,10 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
 
         pci_dev->exp.pm_cap = pos;
 
Quoted 11 lines

hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) · line 1764

Quoted 7 lines
hw/virtio/virtio-pci.c +4 -0
+        /* Set Function Level Reset capability bit */
+        pcie_cap_flr_init(pci_dev);
+        proxy->has_flr = true;
+
         /*
          * Indicates that this function complies with revision 1.2 of the
          * PCI Power Management Interface Specification.

I don't think we can set this for everyone: this will break things like cross version migration.

I see. If I add a flag and a property, which version of hw_compat should I use?

Best regards, Julia Suvorova.