Page MenuHomeFreeBSD

D55541.id172889.diff
No OneTemporary

D55541.id172889.diff

diff --git a/sys/dev/nvme/nvme_pci.c b/sys/dev/nvme/nvme_pci.c
--- a/sys/dev/nvme/nvme_pci.c
+++ b/sys/dev/nvme/nvme_pci.c
@@ -31,6 +31,7 @@
#include <sys/conf.h>
#include <sys/proc.h>
#include <sys/smp.h>
+#include <sys/types.h>
#include <vm/vm.h>
#include <dev/pci/pcireg.h>
@@ -151,14 +152,23 @@
static int
nvme_ctrlr_allocate_bar(struct nvme_controller *ctrlr)
{
+ bool activate_msi_bar = false;
+ bool activate_pba_bar = false;
+
ctrlr->resource_id = PCIR_BAR(0);
ctrlr->msix_table_resource_id = -1;
ctrlr->msix_table_resource = NULL;
ctrlr->msix_pba_resource_id = -1;
ctrlr->msix_pba_resource = NULL;
+ /*
+ * Using RF_ACTIVE will set the Memory Space bit in the PCI command register.
+ * The remaining BARs will get mapped in before they've been programmed with
+ * an address. To avoid this we'll not set this flag and instead call
+ * bus_activate_resource() after all the BARs have been programmed.
+ */
ctrlr->resource = bus_alloc_resource_any(ctrlr->dev, SYS_RES_MEMORY,
- &ctrlr->resource_id, RF_ACTIVE);
+ &ctrlr->resource_id, 0);
if (ctrlr->resource == NULL) {
nvme_printf(ctrlr, "unable to allocate pci resource\n");
@@ -180,21 +190,38 @@
if (ctrlr->msix_table_resource_id >= 0 &&
ctrlr->msix_table_resource_id != ctrlr->resource_id) {
ctrlr->msix_table_resource = bus_alloc_resource_any(ctrlr->dev,
- SYS_RES_MEMORY, &ctrlr->msix_table_resource_id, RF_ACTIVE);
+ SYS_RES_MEMORY, &ctrlr->msix_table_resource_id, 0);
if (ctrlr->msix_table_resource == NULL) {
nvme_printf(ctrlr, "unable to allocate msi-x table resource\n");
return (ENOMEM);
}
+ activate_msi_bar = true;
}
if (ctrlr->msix_pba_resource_id >= 0 &&
ctrlr->msix_pba_resource_id != ctrlr->resource_id &&
ctrlr->msix_pba_resource_id != ctrlr->msix_table_resource_id) {
ctrlr->msix_pba_resource = bus_alloc_resource_any(ctrlr->dev,
- SYS_RES_MEMORY, &ctrlr->msix_pba_resource_id, RF_ACTIVE);
+ SYS_RES_MEMORY, &ctrlr->msix_pba_resource_id, 0);
if (ctrlr->msix_pba_resource == NULL) {
nvme_printf(ctrlr, "unable to allocate msi-x pba resource\n");
return (ENOMEM);
}
+ activate_pba_bar = true;
+ }
+
+ if (bus_activate_resource(ctrlr->dev, ctrlr->resource)) {
+ nvme_printf(ctrlr, "unable to activate pci resource\n");
+ return (ENOMEM);
+ }
+ if (activate_msi_bar &&
+ bus_activate_resource(ctrlr->dev, ctrlr->msix_table_resource)) {
+ nvme_printf(ctrlr, "unable to activate msi-x table resource\n");
+ return (ENOMEM);
+ }
+ if (activate_pba_bar &&
+ bus_activate_resource(ctrlr->dev, ctrlr->msix_pba_resource)) {
+ nvme_printf(ctrlr, "unable to activate msi-x pba resource\n");
+ return (ENOMEM);
}
return (0);

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 8, 4:04 AM (14 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29080848
Default Alt Text
D55541.id172889.diff (2 KB)

Event Timeline