[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 11/15] hw/nvme: Calculate BAR attributes in a function
From: |
Lukasz Maniak |
Subject: |
[PATCH v3 11/15] hw/nvme: Calculate BAR attributes in a function |
Date: |
Tue, 21 Dec 2021 15:32:42 +0100 |
From: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
An NVMe device with SR-IOV capability calculates the BAR size
differently for PF and VF, so it makes sense to extract the common code
to a separate function.
Signed-off-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
---
hw/nvme/ctrl.c | 45 +++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index a4b11b201a..a26abaea36 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6429,6 +6429,34 @@ static void nvme_init_pmr(NvmeCtrl *n, PCIDevice
*pci_dev)
memory_region_set_enabled(&n->pmr.dev->mr, false);
}
+static uint64_t nvme_bar_size(unsigned total_queues, unsigned total_irqs,
+ unsigned *msix_table_offset,
+ unsigned *msix_pba_offset)
+{
+ uint64_t bar_size, msix_table_size, msix_pba_size;
+
+ bar_size = sizeof(NvmeBar) + 2 * total_queues * NVME_DB_SIZE;
+ bar_size = QEMU_ALIGN_UP(bar_size, 4 * KiB);
+
+ if (msix_table_offset) {
+ *msix_table_offset = bar_size;
+ }
+
+ msix_table_size = PCI_MSIX_ENTRY_SIZE * total_irqs;
+ bar_size += msix_table_size;
+ bar_size = QEMU_ALIGN_UP(bar_size, 4 * KiB);
+
+ if (msix_pba_offset) {
+ *msix_pba_offset = bar_size;
+ }
+
+ msix_pba_size = QEMU_ALIGN_UP(total_irqs, 64) / 8;
+ bar_size += msix_pba_size;
+
+ bar_size = pow2ceil(bar_size);
+ return bar_size;
+}
+
static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset,
uint64_t bar_size)
{
@@ -6468,7 +6496,7 @@ static int nvme_add_pm_capability(PCIDevice *pci_dev,
uint8_t offset)
static int nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp)
{
uint8_t *pci_conf = pci_dev->config;
- uint64_t bar_size, msix_table_size, msix_pba_size;
+ uint64_t bar_size;
unsigned msix_table_offset, msix_pba_offset;
int ret;
@@ -6494,19 +6522,8 @@ static int nvme_init_pci(NvmeCtrl *n, PCIDevice
*pci_dev, Error **errp)
}
/* add one to max_ioqpairs to account for the admin queue pair */
- bar_size = sizeof(NvmeBar) +
- 2 * (n->params.max_ioqpairs + 1) * NVME_DB_SIZE;
- bar_size = QEMU_ALIGN_UP(bar_size, 4 * KiB);
- msix_table_offset = bar_size;
- msix_table_size = PCI_MSIX_ENTRY_SIZE * n->params.msix_qsize;
-
- bar_size += msix_table_size;
- bar_size = QEMU_ALIGN_UP(bar_size, 4 * KiB);
- msix_pba_offset = bar_size;
- msix_pba_size = QEMU_ALIGN_UP(n->params.msix_qsize, 64) / 8;
-
- bar_size += msix_pba_size;
- bar_size = pow2ceil(bar_size);
+ bar_size = nvme_bar_size(n->params.max_ioqpairs + 1, n->params.msix_qsize,
+ &msix_table_offset, &msix_pba_offset);
memory_region_init(&n->bar0, OBJECT(n), "nvme-bar0", bar_size);
memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme",
--
2.25.1
- [PATCH v3 00/15] hw/nvme: SR-IOV with Virtualization Enhancements, Lukasz Maniak, 2021/12/21
- [PATCH v3 01/15] pcie: Add support for Single Root I/O Virtualization (SR/IOV), Lukasz Maniak, 2021/12/21
- [PATCH v3 02/15] pcie: Add some SR/IOV API documentation in docs/pcie_sriov.txt, Lukasz Maniak, 2021/12/21
- [PATCH v3 03/15] pcie: Add a helper to the SR/IOV API, Lukasz Maniak, 2021/12/21
- [PATCH v3 04/15] pcie: Add 1.2 version token for the Power Management Capability, Lukasz Maniak, 2021/12/21
- [PATCH v3 05/15] hw/nvme: Add support for SR-IOV, Lukasz Maniak, 2021/12/21
- [PATCH v3 06/15] hw/nvme: Add support for Primary Controller Capabilities, Lukasz Maniak, 2021/12/21
- [PATCH v3 07/15] hw/nvme: Add support for Secondary Controller List, Lukasz Maniak, 2021/12/21
- [PATCH v3 08/15] hw/nvme: Implement the Function Level Reset, Lukasz Maniak, 2021/12/21
- [PATCH v3 09/15] hw/nvme: Make max_ioqpairs and msix_qsize configurable in runtime, Lukasz Maniak, 2021/12/21
- [PATCH v3 11/15] hw/nvme: Calculate BAR attributes in a function,
Lukasz Maniak <=
- [PATCH v3 12/15] hw/nvme: Initialize capability structures for primary/secondary controllers, Lukasz Maniak, 2021/12/21
- [PATCH v3 13/15] hw/nvme: Add support for the Virtualization Management command, Lukasz Maniak, 2021/12/21
- [PATCH v3 10/15] hw/nvme: Remove reg_size variable and update BAR0 size calculation, Lukasz Maniak, 2021/12/21
- [PATCH v3 14/15] docs: Add documentation for SR-IOV and Virtualization Enhancements, Lukasz Maniak, 2021/12/21
- [PATCH v3 15/15] hw/nvme: Update the initalization place for the AER queue, Lukasz Maniak, 2021/12/21