[PATCH v2] bus/cdx: provide driver flag for optional resource mapping

Abhijit Gangurde abhijit.gangurde at amd.com
Wed Jul 5 08:52:35 CEST 2023


Provide driver flag which gives an option to map the cdx
device resource before probing the device driver.
Also, make rte_cdx_map_device() API as public to map
device resource separately.

Signed-off-by: Abhijit Gangurde <abhijit.gangurde at amd.com>
---
 v2:
 - Corrected _RTE_BUS_CDX_H_ to RTE_BUS_CDX_H
 - Improved code comments.
 
 drivers/bus/cdx/bus_cdx_driver.h | 26 ++---------------
 drivers/bus/cdx/cdx.c            | 11 ++++---
 drivers/bus/cdx/rte_bus_cdx.h    | 50 ++++++++++++++++++++++++++++++++
 drivers/bus/cdx/version.map      | 11 +++++--
 4 files changed, 69 insertions(+), 29 deletions(-)
 create mode 100644 drivers/bus/cdx/rte_bus_cdx.h

diff --git a/drivers/bus/cdx/bus_cdx_driver.h b/drivers/bus/cdx/bus_cdx_driver.h
index fcacdb5896..1571131417 100644
--- a/drivers/bus/cdx/bus_cdx_driver.h
+++ b/drivers/bus/cdx/bus_cdx_driver.h
@@ -37,6 +37,9 @@ struct rte_cdx_bus;
 static const char DRV_EXP_TAG(name, cdx_tbl_export)[] __rte_used = \
 RTE_STR(table)
 
+/** Device needs resource mapping */
+#define RTE_CDX_DRV_NEED_MAPPING 0x0001
+
 /**
  * A structure describing an ID for a CDX driver. Each driver provides a
  * table of these IDs for each device that it supports.
@@ -107,29 +110,6 @@ struct rte_cdx_driver {
 	uint32_t drv_flags;			/**< Flags RTE_CDX_DRV_*. */
 };
 
-/**
- * Map the CDX device resources in user space virtual memory address.
- *
- * @param dev
- *   A pointer to a rte_cdx_device structure describing the device
- *   to use.
- *
- * @return
- *   0 on success, <0 on error.
- */
-__rte_internal
-int rte_cdx_map_device(struct rte_cdx_device *dev);
-
-/**
- * Unmap this device.
- *
- * @param dev
- *   A pointer to a rte_cdx_device structure describing the device
- *   to use.
- */
-__rte_internal
-void rte_cdx_unmap_device(struct rte_cdx_device *dev);
-
 /**
  * Register a CDX driver.
  *
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 28bbf92ed5..47dc4eabe7 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -74,6 +74,7 @@
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
 #include <rte_vfio.h>
+#include <rte_bus_cdx.h>
 
 #include <eal_filesystem.h>
 
@@ -380,10 +381,12 @@ cdx_probe_one_driver(struct rte_cdx_driver *dr,
 	CDX_BUS_DEBUG("  probe device %s using driver: %s", dev_name,
 		dr->driver.name);
 
-	ret = cdx_vfio_map_resource(dev);
-	if (ret != 0) {
-		CDX_BUS_ERR("CDX map device failed: %d", ret);
-		goto error_map_device;
+	if (dr->drv_flags & RTE_CDX_DRV_NEED_MAPPING) {
+		ret = cdx_vfio_map_resource(dev);
+		if (ret != 0) {
+			CDX_BUS_ERR("CDX map device failed: %d", ret);
+			goto error_map_device;
+		}
 	}
 
 	/* call the driver probe() function */
diff --git a/drivers/bus/cdx/rte_bus_cdx.h b/drivers/bus/cdx/rte_bus_cdx.h
new file mode 100644
index 0000000000..80acd668c0
--- /dev/null
+++ b/drivers/bus/cdx/rte_bus_cdx.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2023, Advanced Micro Devices, Inc.
+ */
+
+#ifndef RTE_BUS_CDX_H
+#define RTE_BUS_CDX_H
+
+/**
+ * @file
+ * CDX device & driver interface
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Forward declarations */
+struct rte_cdx_device;
+
+/**
+ * Map the CDX device resources in user space virtual memory address.
+ *
+ * Note that driver should not call this function when flag
+ * RTE_CDX_DRV_NEED_MAPPING is set, as EAL will do that for
+ * you when it's on.
+ *
+ * @param dev
+ *   A pointer to a rte_cdx_device structure describing the device
+ *   to use.
+ *
+ * @return
+ *   0 on success, negative on error and positive if no driver
+ *   is found for the device.
+ */
+int rte_cdx_map_device(struct rte_cdx_device *dev);
+
+/**
+ * Unmap this device.
+ *
+ * @param dev
+ *   A pointer to a rte_cdx_device structure describing the device
+ *   to use.
+ */
+void rte_cdx_unmap_device(struct rte_cdx_device *dev);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RTE_BUS_CDX_H */
diff --git a/drivers/bus/cdx/version.map b/drivers/bus/cdx/version.map
index 0a15d39ae8..cc7b1f821b 100644
--- a/drivers/bus/cdx/version.map
+++ b/drivers/bus/cdx/version.map
@@ -1,9 +1,16 @@
-INTERNAL {
+DPDK_23 {
 	global:
 
 	rte_cdx_map_device;
-	rte_cdx_register;
 	rte_cdx_unmap_device;
+
+	local: *;
+};
+
+INTERNAL {
+	global:
+
+	rte_cdx_register;
 	rte_cdx_unregister;
 	rte_cdx_vfio_intr_disable;
 	rte_cdx_vfio_intr_enable;
-- 
2.25.1



More information about the dev mailing list