[dpdk-dev] [PATCH v2 1/2] eal/pci: introduce a PCI driver flag

Jerin Jacob jerin.jacob at caviumnetworks.com
Thu Jun 8 13:44:13 CEST 2017


Some ethdev devices like nicvf thunderx PMD need special treatment for
Secondary queue set(SQS) PCIe VF devices, where, it expects to not unmap
or free the memory without registering the ethdev subsystem.

Introducing a new RTE_PCI_DRV_KEEP_MAPPED_RES
PCI driver flag to request PCI subsystem to not unmap the mapped PCI
resources(PCI BAR address) if unsupported device detected.

Signed-off-by: Jerin Jacob <jerin.jacob at caviumnetworks.com>
---
v2:
Introduced RTE_PCI_DRV_KEEP_MAPPED_RES flag scheme(Ferruh),
Based on the discussion in the following thread.
http://dpdk.org/ml/archives/dev/2017-June/067091.htmlRTE_PCI_DRV_KEEP_MAPPED_RES
---
 lib/librte_eal/common/eal_common_pci.c  | 19 +++++++++++++++----
 lib/librte_eal/common/include/rte_pci.h |  2 ++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 5ae520186..0d4e4a9f1 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -221,7 +221,12 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr,
 	ret = dr->probe(dr, dev);
 	if (ret) {
 		dev->driver = NULL;
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+		if ((dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) &&
+			/* Don't unmap if device is unsupported and
+			 * driver needs mapped resources.
+			 */
+			!(ret > 0 &&
+				(dr->drv_flags & RTE_PCI_DRV_KEEP_MAPPED_RES)))
 			rte_pci_unmap_device(dev);
 	}
 
@@ -235,6 +240,7 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr,
 static int
 rte_pci_detach_dev(struct rte_pci_device *dev)
 {
+	int ret = 0;
 	struct rte_pci_addr *loc;
 	struct rte_pci_driver *dr;
 
@@ -251,13 +257,18 @@ rte_pci_detach_dev(struct rte_pci_device *dev)
 	RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
 			dev->id.device_id, dr->driver.name);
 
-	if (dr->remove && (dr->remove(dev) < 0))
-		return -1;	/* negative value is an error */
+	if (dr->remove) {
+		ret = dr->remove(dev);
+		if (ret < 0)
+			return -1; /* negative value is an error */
+	}
 
 	/* clear driver structure */
 	dev->driver = NULL;
 
-	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+	if ((dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) &&
+	/* Don't unmap if dev is unsupported and it needs mapped resources */
+		!(ret > 0 && (dr->drv_flags & RTE_PCI_DRV_KEEP_MAPPED_RES)))
 		/* unmap resources for devices that use igb_uio */
 		rte_pci_unmap_device(dev);
 
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index b82ab9e79..0284a6208 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -212,6 +212,8 @@ struct rte_pci_bus {
 #define RTE_PCI_DRV_INTR_LSC	0x0008
 /** Device driver supports device removal interrupt */
 #define RTE_PCI_DRV_INTR_RMV 0x0010
+/** Device driver needs to keep mapped resources if unsupported dev detected */
+#define RTE_PCI_DRV_KEEP_MAPPED_RES 0x0020
 
 /**
  * A structure describing a PCI mapping.
-- 
2.13.1



More information about the dev mailing list