[PATCH 2/4] hw/nvme: Fix ARI next function numbers

Akihiko Odaki posted 4 patches 2 years, 5 months ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Akihiko Odaki <akihiko.odaki@daynix.com>, Sriram Yagnaraman <sriram.yagnaraman@est.tech>, Jason Wang <jasowang@redhat.com>, Keith Busch <kbusch@kernel.org>, Klaus Jensen <its@irrelevant.dk>
There is a newer version of this series
[PATCH 2/4] hw/nvme: Fix ARI next function numbers
Posted by Akihiko Odaki 2 years, 5 months ago
The next function numbers are expected to form a linked list ending with
0.

Fixes: 44c2c09488 ("hw/nvme: Add support for SR-IOV")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 hw/nvme/ctrl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index fd917fcda1..12500dc80b 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -8088,7 +8088,12 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp)
     pcie_endpoint_cap_init(pci_dev, 0x80);
     pcie_cap_flr_init(pci_dev);
     if (n->params.sriov_max_vfs) {
-        pcie_ari_init(pci_dev, 0x100, 1);
+        uint16_t nextvfn = pci_is_vf(pci_dev) ?
+                           pcie_sriov_vf_number(pci_dev) + 1 : 0;
+        uint16_t nextfn = nextvfn < n->params.sriov_max_vfs ?
+                          NVME_VF_OFFSET + nextvfn * NVME_VF_STRIDE : 0;
+
+        pcie_ari_init(pci_dev, 0x100, nextfn);
     }
 
     /* add one to max_ioqpairs to account for the admin queue pair */
-- 
2.41.0