Skip to contentSkip to conversation

q35: Minor fixes/enhancements to improve usability of root ports

PATCH Applied Knut Omang 3 participants 12 messages Aug 24, 2014 – Aug 25, 2014

lore
Share & tools
lore

Knut Omang

author
#0 lore raw

v2 cover q35: Minor fixes/enhancements to improve usability of root ports

These are some minor fixes necessary to be able to operate ARI capable devices in PCIe root ports on a q35 machine, using command line options like this:

-device ioh3420,slot=0,id=pcie_port.0
-device ioh3420,slot=1,id=pcie_port.1
-device <ari_capable_device1>,bus=pcie_port.0
-device <ari_capable_device2>,bus=pcie_port.1

Changes since v1:
Removed "ioh3420: Provide a unique bus name and an interrupt mapping function"
as it is no longer necessary.
Added rename of ari -> arifwd for clarity and removal of obsolete init function (separate patches)
Use the renamed functions in ioh3420.

Knut Omang (4):
pcie: Fix incorrect write to the ari capability next function field
pcie: Rename the pcie_cap_ari_* functions to pcie_cap_arifwd_*
ioh3420: Remove obsoleted, unused ioh3420_init function
ioh3420: Enable ARI forwarding

 hw/pci-bridge/ioh3420.c            | 27 +++------------------------
 hw/pci-bridge/xio3130_downstream.c |  4 ++--
 hw/pci/pcie.c                      | 13 +++++++------
 include/hw/pci/pcie.h              |  7 ++++---
 4 files changed, 16 insertions(+), 35 deletions(-)
Signature · 1 line
1.9.0
author
#1 lore raw

PATCH v2 1/4 pcie: Fix incorrect write to the ari capability next function field

PCI_ARI_CAP_NFN, a macro for reading next function was used instead of the intended write.

---
 hw/pci/pcie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pcie.c +1 -1
index a123c01..de0e967 100644
@@ -630,5 +630,5 @@ void pcie_ari_init(PCIDevice *dev, uint16_t offset, uint16_t nextfn)
 {
     pcie_add_capability(dev, PCI_EXT_CAP_ID_ARI, PCI_ARI_VER,
                         offset, PCI_ARI_SIZEOF);
-    pci_set_long(dev->config + offset + PCI_ARI_CAP, PCI_ARI_CAP_NFN(nextfn));
+    pci_set_long(dev->config + offset + PCI_ARI_CAP, (nextfn & 0xff) << 8);
 }
Signature · 1 line
1.9.0
author
#2 lore raw

PATCH v2 2/4 pcie: Rename the pcie_cap_ari_* functions to pcie_cap_arifwd_*

In reply to Knut Omang

Rename helper functions to make a clearer distinction between the PCIe capability/control register feature ARI forwarding and a device that supports the ARI feature via an ARI extended PCIe capability.

---
 hw/pci-bridge/ioh3420.c            |  1 +
 hw/pci-bridge/xio3130_downstream.c |  4 ++--
 hw/pci/pcie.c                      | 11 ++++++-----
 include/hw/pci/pcie.h              |  7 ++++---
 4 files changed, 13 insertions(+), 10 deletions(-)
hw/pci-bridge/ioh3420.c +1 -0
index 7cd87fc..aed2bf1 100644
@@ -118,6 +118,7 @@ static int ioh3420_initfn(PCIDevice *d)
     if (rc < 0) {
         goto err_msi;
     }
+
     pcie_cap_deverr_init(d);
     pcie_cap_slot_init(d, s->slot);
     pcie_chassis_create(s->chassis);
hw/pci-bridge/xio3130_downstream.c +2 -2
index 51f20d7..b3a6479 100644
@@ -50,7 +50,7 @@ static void xio3130_downstream_reset(DeviceState *qdev)
 
     pcie_cap_deverr_reset(d);
     pcie_cap_slot_reset(d);
-    pcie_cap_ari_reset(d);
+    pcie_cap_arifwd_reset(d);
     pci_bridge_reset(qdev);
 }
 
@@ -91,7 +91,7 @@ static int xio3130_downstream_initfn(PCIDevice *d)
     if (rc < 0) {
         goto err_pcie_cap;
     }
-    pcie_cap_ari_init(d);
+    pcie_cap_arifwd_init(d);
     rc = pcie_aer_init(d, XIO3130_AER_OFFSET);
     if (rc < 0) {
         goto err;
hw/pci/pcie.c +6 -5
index de0e967..6cb6e0c 100644
@@ -497,9 +497,10 @@ void pcie_cap_flr_write_config(PCIDevice *dev,
     }
 }
 
-/* Alternative Routing-ID Interpretation (ARI) */
-/* ari forwarding support for down stream port */
-void pcie_cap_ari_init(PCIDevice *dev)
+/* Alternative Routing-ID Interpretation (ARI)
+ * forwarding support for root and downstream ports 
+ */
+void pcie_cap_arifwd_init(PCIDevice *dev)
 {
     uint32_t pos = dev->exp.exp_cap;
     pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_DEVCAP2,
@@ -508,13 +509,13 @@ void pcie_cap_ari_init(PCIDevice *dev)
                                PCI_EXP_DEVCTL2_ARI);
 }
 
-void pcie_cap_ari_reset(PCIDevice *dev)
+void pcie_cap_arifwd_reset(PCIDevice *dev)
 {
     uint8_t *devctl2 = dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL2;
     pci_long_test_and_clear_mask(devctl2, PCI_EXP_DEVCTL2_ARI);
 }
 
-bool pcie_cap_is_ari_enabled(const PCIDevice *dev)
+bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev)
 {
     if (!pci_is_express(dev)) {
         return false;
include/hw/pci/pcie.h +4 -3
index 7fe81f3..d139d58 100644
@@ -103,9 +103,10 @@ void pcie_cap_flr_init(PCIDevice *dev);
 void pcie_cap_flr_write_config(PCIDevice *dev,
                            uint32_t addr, uint32_t val, int len);
 
-void pcie_cap_ari_init(PCIDevice *dev);
-void pcie_cap_ari_reset(PCIDevice *dev);
-bool pcie_cap_is_ari_enabled(const PCIDevice *dev);
+/* ARI forwarding capability and control */
+void pcie_cap_arifwd_init(PCIDevice *dev);
+void pcie_cap_arifwd_reset(PCIDevice *dev);
+bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev);
 
 /* PCI express extended capability helper functions */
 uint16_t pcie_find_capability(PCIDevice *dev, uint16_t cap_id);
Signature · 1 line
1.9.0
author
#3 lore raw

PATCH v2 3/4 ioh3420: Remove obsoleted, unused ioh3420_init function

In reply to Knut Omang
---
 hw/pci-bridge/ioh3420.c | 24 ------------------------
 1 file changed, 24 deletions(-)
hw/pci-bridge/ioh3420.c +0 -24
index aed2bf1..e6674a1 100644
@@ -157,30 +157,6 @@ static void ioh3420_exitfn(PCIDevice *d)
     pci_bridge_exitfn(d);
 }
 
-PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool multifunction,
-                         const char *bus_name, pci_map_irq_fn map_irq,
-                         uint8_t port, uint8_t chassis, uint16_t slot)
-{
-    PCIDevice *d;
-    PCIBridge *br;
-    DeviceState *qdev;
-
-    d = pci_create_multifunction(bus, devfn, multifunction, "ioh3420");
-    if (!d) {
-        return NULL;
-    }
-    br = PCI_BRIDGE(d);
-
-    qdev = DEVICE(d);
-    pci_bridge_map_irq(br, bus_name, map_irq);
-    qdev_prop_set_uint8(qdev, "port", port);
-    qdev_prop_set_uint8(qdev, "chassis", chassis);
-    qdev_prop_set_uint16(qdev, "slot", slot);
-    qdev_init_nofail(qdev);
-
-    return PCIE_SLOT(d);
-}
-
 static Property ioh3420_props[] = {
     DEFINE_PROP_BIT(COMPAT_PROP_PCP, PCIDevice, cap_present,
                     QEMU_PCIE_SLTCAP_PCP_BITNR, true),
Signature · 1 line
1.9.0
author
#6 lore raw

PATCH v2 4/4 ioh3420: Enable ARI forwarding

In reply to Knut Omang
---
 hw/pci-bridge/ioh3420.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-bridge/ioh3420.c +2 -0
index e6674a1..cce2fdd 100644
@@ -85,6 +85,7 @@ static void ioh3420_reset(DeviceState *qdev)
     pcie_cap_root_reset(d);
     pcie_cap_deverr_reset(d);
     pcie_cap_slot_reset(d);
+    pcie_cap_arifwd_reset(d);
     pcie_aer_root_reset(d);
     pci_bridge_reset(qdev);
     pci_bridge_disable_base_limit(d);
@@ -119,6 +120,7 @@ static int ioh3420_initfn(PCIDevice *d)
         goto err_msi;
     }
 
+    pcie_cap_arifwd_init(d);
     pcie_cap_deverr_init(d);
     pcie_cap_slot_init(d, s->slot);
     pcie_chassis_create(s->chassis);
Signature · 1 line
1.9.0
#11 lore raw
In reply to Knut Omang
Quoted 8 lines · Knut Omang

These are some minor fixes necessary to be able to operate ARI capable devices in PCIe root ports on a q35 machine, using command line options like this:

-device ioh3420,slot=0,id=pcie_port.0
-device ioh3420,slot=1,id=pcie_port.1
-device <ari_capable_device1>,bus=pcie_port.0
-device <ari_capable_device2>,bus=pcie_port.1

Quoted 6 lines

Changes since v1:
Removed "ioh3420: Provide a unique bus name and an interrupt mapping function"
as it is no longer necessary.
Added rename of ari -> arifwd for clarity and removal of obsolete init function (separate patches)
Use the renamed functions in ioh3420.

Applied, thanks!

Quoted 14 lines

Knut Omang (4):
pcie: Fix incorrect write to the ari capability next function field
pcie: Rename the pcie_cap_ari_* functions to pcie_cap_arifwd_*
ioh3420: Remove obsoleted, unused ioh3420_init function
ioh3420: Enable ARI forwarding

 hw/pci-bridge/ioh3420.c            | 27 +++------------------------
 hw/pci-bridge/xio3130_downstream.c |  4 ++--
 hw/pci/pcie.c                      | 13 +++++++------
 include/hw/pci/pcie.h              |  7 ++++---
 4 files changed, 16 insertions(+), 35 deletions(-)
Signature · 1 line
1.9.0
#7 lore raw

Re: [Qemu-devel] [PATCH v2 4/4] ioh3420: Enable ARI forwarding

In reply to Knut Omang
Quoted 1 line · Knut Omang

BTW pcie_cap_is_arifwd_enabled is still unused. We really should use it to make ARI work properly, right?

Quoted 26 lines
---
 hw/pci-bridge/ioh3420.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-bridge/ioh3420.c +2 -0
index e6674a1..cce2fdd 100644
@@ -85,6 +85,7 @@ static void ioh3420_reset(DeviceState *qdev)
     pcie_cap_root_reset(d);
     pcie_cap_deverr_reset(d);
     pcie_cap_slot_reset(d);
+    pcie_cap_arifwd_reset(d);
     pcie_aer_root_reset(d);
     pci_bridge_reset(qdev);
     pci_bridge_disable_base_limit(d);
@@ -119,6 +120,7 @@ static int ioh3420_initfn(PCIDevice *d)
         goto err_msi;
     }
 
+    pcie_cap_arifwd_init(d);
     pcie_cap_deverr_init(d);
     pcie_cap_slot_init(d, s->slot);
     pcie_chassis_create(s->chassis);
Signature · 1 line
1.9.0
#8 lore raw

Re: [Qemu-devel] [PATCH v2 4/4] ioh3420: Enable ARI forwarding

Quoted 7 lines

From: Michael S. Tsirkin [mailto:[email protected]]
Subject: Re: [PATCH v2 4/4] ioh3420: Enable ARI forwarding

Quoted 1 line · Knut Omang

BTW pcie_cap_is_arifwd_enabled is still unused.

Not yet, but I have posted a patch series:

[PATCH v2 0/2] add check for PCIe root ports and downstream ports

Which we used this function to check ARI Forwarding is enabled or not. I hope you can help me review it, thanks a lot!

BTW, I will rebase my patches on Kunt's patch series. And will do some fixes about Hu Tao's and Marcel Apfelbaum's comments.

Quoted 2 lines

We really should use it to make ARI work properly, right?

Yes. I think we should.

Best regards,
-Gonglei

Quoted 26 lines
Quoted 26 lines
---
 hw/pci-bridge/ioh3420.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-bridge/ioh3420.c +2 -1
index e6674a1..cce2fdd 100644
@@ -85,6 +85,7 @@ static void ioh3420_reset(DeviceState *qdev)
     pcie_cap_root_reset(d);
     pcie_cap_deverr_reset(d);
     pcie_cap_slot_reset(d);
+    pcie_cap_arifwd_reset(d);
     pcie_aer_root_reset(d);
     pci_bridge_reset(qdev);
     pci_bridge_disable_base_limit(d);
@@ -119,6 +120,7 @@ static int ioh3420_initfn(PCIDevice *d)
         goto err_msi;
     }
 
+    pcie_cap_arifwd_init(d);
     pcie_cap_deverr_init(d);
     pcie_cap_slot_init(d, s->slot);
     pcie_chassis_create(s->chassis);
--

1.9.0

#4 lore raw

Re: [Qemu-devel] [PATCH v2 3/4] ioh3420: Remove obsoleted, unused ioh3420_init function

In reply to Knut Omang
Quoted 50 lines

-----Original Message-----
From: Knut Omang [mailto:[email protected]]
Sent: Sunday, August 24, 2014 9:32 PM
To: [email protected]
Cc: Michael S. Tsirkin; Alexey Kardashevskiy; Juan Quintela; Marcel Apfelbaum; Markus Armbruster; Paolo Bonzini; Gonglei (Arei); Igor Mammedov; Knut Omang
Subject: [PATCH v2 3/4] ioh3420: Remove obsoleted, unused ioh3420_init function

---
 hw/pci-bridge/ioh3420.c | 24 ------------------------
 1 file changed, 24 deletions(-)
hw/pci-bridge/ioh3420.c +0 -24
index aed2bf1..e6674a1 100644
@@ -157,30 +157,6 @@ static void ioh3420_exitfn(PCIDevice *d)
     pci_bridge_exitfn(d);
 }
 
-PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool multifunction,
-                         const char *bus_name, pci_map_irq_fn
 map_irq,
-                         uint8_t port, uint8_t chassis, uint16_t slot)
-{
-    PCIDevice *d;
-    PCIBridge *br;
-    DeviceState *qdev;
-
-    d = pci_create_multifunction(bus, devfn, multifunction, "ioh3420");
-    if (!d) {
-        return NULL;
-    }
-    br = PCI_BRIDGE(d);
-
-    qdev = DEVICE(d);
-    pci_bridge_map_irq(br, bus_name, map_irq);
-    qdev_prop_set_uint8(qdev, "port", port);
-    qdev_prop_set_uint8(qdev, "chassis", chassis);
-    qdev_prop_set_uint16(qdev, "slot", slot);
-    qdev_init_nofail(qdev);
-
-    return PCIE_SLOT(d);
-}
-
 static Property ioh3420_props[] = {
     DEFINE_PROP_BIT(COMPAT_PROP_PCP, PCIDevice, cap_present,
Quoted 3 lines

QEMU_PCIE_SLTCAP_PCP_BITNR, true),
--
1.9.0

That's OK. But the declaration of header file should also be removed. I noticed MST have pulled into master tree. So, maybe I can post another patch to fix this trivial problem.

Best regards,
-Gonglei

author
#9 lore raw

Re: [Qemu-devel] [PATCH v2 4/4] ioh3420: Enable ARI forwarding

In reply to Gonglei (Arei)
Quoted 15 lines · Gonglei (Arei)
Quoted 7 lines

From: Michael S. Tsirkin [mailto:[email protected]]
Subject: Re: [PATCH v2 4/4] ioh3420: Enable ARI forwarding

Quoted 1 line · Knut Omang

BTW pcie_cap_is_arifwd_enabled is still unused.

Not yet, but I have posted a patch series:

[PATCH v2 0/2] add check for PCIe root ports and downstream ports

Which we used this function to check ARI Forwarding is enabled or not. I hope you can help me review it, thanks a lot!

Quoted 6 lines

BTW, I will rebase my patches on Kunt's patch series. And will do some fixes about Hu Tao's and Marcel Apfelbaum's comments.

Quoted 2 lines

We really should use it to make ARI work properly, right?

Yes. I think we should.

Modelling the real world, one way to go with multifunction devices would be to introduce a separate concept of a "PCIFunction" object in the current Qemu model, and let each device have 1 or more such function objects associated with them.

The simpler way to implement a true multifunction device would just be to add one PCIDevice object at the right bus, devfn for each additional function that are associated with the master device.

I have implemented the latter approach in a simple SR/IOV emulation implementation - will post a patch for that shortly, as it seems to be relevant for this discussion.

With that approach (which came out pleasantly simple wrt changes in the code) the role of the ARI forwarding bit would be to do nothing when enabled, as ARI forwarding works with no changes, but make ARI forwarding, when disabled or not available, makes the additional functions beyond #8 not addressable from the outside (which in my view is what a modified version of Gonglei's patch should do)

Knut

Quoted 30 lines

Best regards,
-Gonglei

Quoted 26 lines
Quoted 26 lines
---
 hw/pci-bridge/ioh3420.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-bridge/ioh3420.c +2 -1
index e6674a1..cce2fdd 100644
@@ -85,6 +85,7 @@ static void ioh3420_reset(DeviceState *qdev)
     pcie_cap_root_reset(d);
     pcie_cap_deverr_reset(d);
     pcie_cap_slot_reset(d);
+    pcie_cap_arifwd_reset(d);
     pcie_aer_root_reset(d);
     pci_bridge_reset(qdev);
     pci_bridge_disable_base_limit(d);
@@ -119,6 +120,7 @@ static int ioh3420_initfn(PCIDevice *d)
         goto err_msi;
     }
 
+    pcie_cap_arifwd_init(d);
     pcie_cap_deverr_init(d);
     pcie_cap_slot_init(d, s->slot);
     pcie_chassis_create(s->chassis);
--

1.9.0

author
#5 lore raw

Re: [Qemu-devel] [PATCH v2 3/4] ioh3420: Remove obsoleted, unused ioh3420_init function

In reply to Gonglei (Arei)
Quoted 49 lines · Gonglei (Arei)
Quoted 49 lines

-----Original Message-----
From: Knut Omang [mailto:[email protected]]
Sent: Sunday, August 24, 2014 9:32 PM
To: [email protected]
Cc: Michael S. Tsirkin; Alexey Kardashevskiy; Juan Quintela; Marcel Apfelbaum; Markus Armbruster; Paolo Bonzini; Gonglei (Arei); Igor Mammedov; Knut Omang
Subject: [PATCH v2 3/4] ioh3420: Remove obsoleted, unused ioh3420_init function

---
 hw/pci-bridge/ioh3420.c | 24 ------------------------
 1 file changed, 24 deletions(-)
hw/pci-bridge/ioh3420.c +0 -24
index aed2bf1..e6674a1 100644
@@ -157,30 +157,6 @@ static void ioh3420_exitfn(PCIDevice *d)
     pci_bridge_exitfn(d);
 }
 
-PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool multifunction,
-                         const char *bus_name, pci_map_irq_fn
 map_irq,
-                         uint8_t port, uint8_t chassis, uint16_t slot)
-{
-    PCIDevice *d;
-    PCIBridge *br;
-    DeviceState *qdev;
-
-    d = pci_create_multifunction(bus, devfn, multifunction, "ioh3420");
-    if (!d) {
-        return NULL;
-    }
-    br = PCI_BRIDGE(d);
-
-    qdev = DEVICE(d);
-    pci_bridge_map_irq(br, bus_name, map_irq);
-    qdev_prop_set_uint8(qdev, "port", port);
-    qdev_prop_set_uint8(qdev, "chassis", chassis);
-    qdev_prop_set_uint16(qdev, "slot", slot);
-    qdev_init_nofail(qdev);
-
-    return PCIE_SLOT(d);
-}
-
 static Property ioh3420_props[] = {
Quoted 8 lines
Quoted 4 lines
hw/pci-bridge/ioh3420.c +0 -0
     DEFINE_PROP_BIT(COMPAT_PROP_PCP, PCIDevice, cap_present,

QEMU_PCIE_SLTCAP_PCP_BITNR, true),
--
1.9.0

That's OK. But the declaration of header file should also be removed. I noticed MST have pulled into master tree. So, maybe I can post another patch to fix this trivial problem.

Yes, definitely, an obvious mistake from me, sorry. Don't understand how I could have overlooked that..

Knut

Quoted 2 lines

Best regards,
-Gonglei

#10 lore raw

Re: [Qemu-devel] [PATCH v2 4/4] ioh3420: Enable ARI forwarding

In reply to Knut Omang
Quoted 36 lines · Knut Omang
Quoted 15 lines · Gonglei (Arei)
Quoted 7 lines

From: Michael S. Tsirkin [mailto:[email protected]]
Subject: Re: [PATCH v2 4/4] ioh3420: Enable ARI forwarding

Quoted 1 line · Knut Omang

BTW pcie_cap_is_arifwd_enabled is still unused.

Not yet, but I have posted a patch series:

[PATCH v2 0/2] add check for PCIe root ports and downstream ports

Which we used this function to check ARI Forwarding is enabled or not. I hope you can help me review it, thanks a lot!

Quoted 6 lines

BTW, I will rebase my patches on Kunt's patch series. And will do some fixes about Hu Tao's and Marcel Apfelbaum's comments.

Quoted 2 lines

We really should use it to make ARI work properly, right?

Yes. I think we should.

Modelling the real world, one way to go with multifunction devices would be to introduce a separate concept of a "PCIFunction" object in the current Qemu model, and let each device have 1 or more such function objects associated with them.

The simpler way to implement a true multifunction device would just be to add one PCIDevice object at the right bus, devfn for each additional function that are associated with the master device.

I have implemented the latter approach in a simple SR/IOV emulation implementation - will post a patch for that shortly, as it seems to be relevant for this discussion.

Quoted 8 lines

With that approach (which came out pleasantly simple wrt changes in the code) the role of the ARI forwarding bit would be to do nothing when enabled, as ARI forwarding works with no changes, but make ARI forwarding, when disabled or not available, makes the additional functions beyond #8 not addressable from the outside (which in my view is what a modified version of Gonglei's patch should do)

Knut

Makes sense to me.

Quoted 31 lines
Quoted 30 lines

Best regards,
-Gonglei

Quoted 26 lines
Quoted 26 lines
---
 hw/pci-bridge/ioh3420.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-bridge/ioh3420.c +2 -1
index e6674a1..cce2fdd 100644
@@ -85,6 +85,7 @@ static void ioh3420_reset(DeviceState *qdev)
     pcie_cap_root_reset(d);
     pcie_cap_deverr_reset(d);
     pcie_cap_slot_reset(d);
+    pcie_cap_arifwd_reset(d);
     pcie_aer_root_reset(d);
     pci_bridge_reset(qdev);
     pci_bridge_disable_base_limit(d);
@@ -119,6 +120,7 @@ static int ioh3420_initfn(PCIDevice *d)
         goto err_msi;
     }
 
+    pcie_cap_arifwd_init(d);
     pcie_cap_deverr_init(d);
     pcie_cap_slot_init(d, s->slot);
     pcie_chassis_create(s->chassis);
--

1.9.0