Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Feb 2021 20:31:51 GMT
From:      Marcin Wojtas <mw@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: bc1df392499d - stable/12 - MFC 1c808fcd859f: Allocate BAR for ENA MSIx vector table
Message-ID:  <202102222031.11MKVpiK044164@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by mw:

URL: https://cgit.FreeBSD.org/src/commit/?id=bc1df392499ddf3ca5f089b850b898078267bd40

commit bc1df392499ddf3ca5f089b850b898078267bd40
Author:     Michal Krawczyk <mk@semihalf.com>
AuthorDate: 2021-02-18 09:00:58 +0000
Commit:     Marcin Wojtas <mw@FreeBSD.org>
CommitDate: 2021-02-22 20:31:16 +0000

    MFC 1c808fcd859f: Allocate BAR for ENA MSIx vector table
    
    In the new ENA-based instances like c6gn, the vector table moved to a
    new PCIe bar - BAR1. Previously it was always located on the BAR0, so
    the resources were already allocated together with the registers.
    
    As the FreeBSD isn't doing any resource allocation behind the scenes,
    the driver is responsible to allocate them explicitly, before other
    parts of the OS (like the PCI code allocating MSIx) will be able to
    access them.
    
    To determine dynamically BAR on which the MSIx vector table is present
    the pci_msix_table_bar() is being used and the new BAR is allocated if
    needed.
    
    Submitted by: Michal Krawczyk <mk@semihalf.com>
    Obtained from: Semihalf
    Sponsored by: Amazon, Inc
    
    (cherry picked from commit 1c808fcd859f5ce24132a903a4c7c9996e0513b1)
---
 sys/dev/ena/ena.c | 21 +++++++++++++++++++++
 sys/dev/ena/ena.h |  4 +++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/sys/dev/ena/ena.c b/sys/dev/ena/ena.c
index 306d5dc1fd1c..0079f5354c33 100644
--- a/sys/dev/ena/ena.c
+++ b/sys/dev/ena/ena.c
@@ -299,6 +299,11 @@ ena_free_pci_resources(struct ena_adapter *adapter)
 		bus_release_resource(pdev, SYS_RES_MEMORY,
 		    PCIR_BAR(ENA_REG_BAR), adapter->registers);
 	}
+
+	if (adapter->msix != NULL) {
+		bus_release_resource(pdev, SYS_RES_MEMORY,
+		    adapter->msix_rid, adapter->msix);
+	}
 }
 
 static int
@@ -3536,6 +3541,7 @@ ena_attach(device_t pdev)
 	struct ena_adapter *adapter;
 	struct ena_com_dev *ena_dev = NULL;
 	uint32_t max_num_io_queues;
+	int msix_rid;
 	int rid, rc;
 
 	adapter = device_get_softc(pdev);
@@ -3574,6 +3580,20 @@ ena_attach(device_t pdev)
 		goto err_dev_free;
 	}
 
+	/* MSIx vector table may reside on BAR0 with registers or on BAR1. */
+	msix_rid = pci_msix_table_bar(pdev);
+	if (msix_rid != rid) {
+		adapter->msix = bus_alloc_resource_any(pdev, SYS_RES_MEMORY,
+		    &msix_rid, RF_ACTIVE);
+		if (unlikely(adapter->msix == NULL)) {
+			device_printf(pdev,
+			    "unable to allocate bus resource: msix!\n");
+			rc = ENOMEM;
+			goto err_pci_free;
+		}
+		adapter->msix_rid = msix_rid;
+	}
+
 	ena_dev->bus = malloc(sizeof(struct ena_bus), M_DEVBUF,
 	    M_WAITOK | M_ZERO);
 
@@ -3739,6 +3759,7 @@ err_com_free:
 	ena_com_mmio_reg_read_request_destroy(ena_dev);
 err_bus_free:
 	free(ena_dev->bus, M_DEVBUF);
+err_pci_free:
 	ena_free_pci_resources(adapter);
 err_dev_free:
 	free(ena_dev, M_DEVBUF);
diff --git a/sys/dev/ena/ena.h b/sys/dev/ena/ena.h
index b3036eb16b2e..c8607a6d558d 100644
--- a/sys/dev/ena/ena.h
+++ b/sys/dev/ena/ena.h
@@ -41,7 +41,7 @@
 
 #define DRV_MODULE_VER_MAJOR	2
 #define DRV_MODULE_VER_MINOR	3
-#define DRV_MODULE_VER_SUBMINOR 0
+#define DRV_MODULE_VER_SUBMINOR 1
 
 #define DRV_MODULE_NAME		"ena"
 
@@ -397,6 +397,8 @@ struct ena_adapter {
 	/* OS resources */
 	struct resource *memory;
 	struct resource *registers;
+	struct resource *msix;
+	int msix_rid;
 
 	struct sx global_lock;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202102222031.11MKVpiK044164>