Skip to contentSkip to conversation

bus/cdx: provide driver flag for optional resource mapping

PATCH Superseded Abhijit Gangurde 4 participants 13 messages Jun 26, 2023 – Oct 16, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus/cdx: provide driver flag for optional resource mapping

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.

---
 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
drivers/bus/cdx/bus_cdx_driver.h +3 -23
index fcacdb5896..1571131417 100644
@@ -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.
  *
drivers/bus/cdx/cdx.c +7 -4
index 28bbf92ed5..47dc4eabe7 100644
@@ -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 */
drivers/bus/cdx/rte_bus_cdx.h new file +50 -0

50 lines not on this page · raw message

drivers/bus/cdx/version.map +9 -2
index 0a15d39ae8..cc7b1f821b 100644
@@ -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;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 93 lines · Abhijit Gangurde

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.

---
  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

drivers/bus/cdx/bus_cdx_driver.h +3 -23
index fcacdb5896..1571131417 100644
@@ -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.
   *
drivers/bus/cdx/cdx.c +7 -4
index 28bbf92ed5..47dc4eabe7 100644
@@ -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 */
drivers/bus/cdx/rte_bus_cdx.h new file +0 -0
new file mode 100644
index 0000000000..b9280b5f7f

drivers/bus/cdx/rte_bus_cdx.h line 6

Quoted 6 lines
drivers/bus/cdx/rte_bus_cdx.h new file +6 -0
@@ -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_

nit: there are no underscores before or after in other cdx header files. please change to RTE_BUS_CDX_H

Quoted 5 lines
drivers/bus/cdx/rte_bus_cdx.h new file +5 -0
+
+/**
+ * @file
+ * CDX device & driver interface
+ */

drivers/bus/cdx/rte_bus_cdx.h line 21

Quoted 10 lines
drivers/bus/cdx/rte_bus_cdx.h new file +10 -0
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Forward declarations */
+struct rte_cdx_device;
+
+/**
+ * Map the CDX device resources in user space virtual memory address

nit: all doxygen comments should end with a dot.

Quoted 52 lines
drivers/bus/cdx/rte_bus_cdx.h new file +29 -0
+ *
+ * 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_ */
drivers/bus/cdx/version.map +9 -2
index 0a15d39ae8..cc7b1f821b 100644
@@ -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 lore raw

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

In reply to Abhijit Gangurde

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.

---
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
drivers/bus/cdx/bus_cdx_driver.h +3 -23
index fcacdb5896..1571131417 100644
@@ -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.
  *
drivers/bus/cdx/cdx.c +7 -4
index 28bbf92ed5..47dc4eabe7 100644
@@ -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 */
drivers/bus/cdx/rte_bus_cdx.h new file +50 -0

50 lines not on this page · raw message

drivers/bus/cdx/version.map +9 -2
index 0a15d39ae8..cc7b1f821b 100644
@@ -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;
Signature · 1 line
2.25.1
#3 lore raw

PATCH v3 1/1 bus/cdx: provide driver flag for optional resource mapping

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.

---
v3:
- Changed APIs to __rte_experimental.

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    | 52 ++++++++++++++++++++++++++++++++
 drivers/bus/cdx/version.map      | 11 +++++--
 4 files changed, 71 insertions(+), 29 deletions(-)
 create mode 100644 drivers/bus/cdx/rte_bus_cdx.h
drivers/bus/cdx/bus_cdx_driver.h +3 -23
index fcacdb5896..1571131417 100644
@@ -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.
  *
drivers/bus/cdx/cdx.c +7 -4
index f9526e08cc..fc8d3b668b 100644
@@ -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>
 
@@ -383,10 +384,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 */
drivers/bus/cdx/rte_bus_cdx.h new file +52 -0

52 lines not on this page · raw message

drivers/bus/cdx/version.map +9 -2
index 0a15d39ae8..4ce444572b 100644
@@ -1,9 +1,16 @@
-INTERNAL {
+EXPERIMENTAL {
 	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;
Signature · 1 line
2.25.1
Acked-by on v3 1/1
#4 lore raw

Please use 'in-reply-to' of the first submission when sending any subsequent patches.

Quoted 6 lines · Abhijit Gangurde

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.

#5 lore raw
In reply to Abhijit Gangurde
Quoted 38 lines · Abhijit Gangurde
drivers/bus/cdx/cdx.c +6 -4
@@ -383,10 +384,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 */
drivers/bus/cdx/rte_bus_cdx.h new file +15 -0
new file mode 100644
index 0000000000..4ca12f90c4
@@ -0,0 +1,52 @@
+/* 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

drivers/bus/cdx/rte_bus_cdx.h line 25

Quoted 10 lines
drivers/bus/cdx/rte_bus_cdx.h new file +10 -0
+
+/* 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.

Why should we export this function in the application ABI, if it is only used by drivers?

Quoted 12 lines
drivers/bus/cdx/rte_bus_cdx.h new file +11 -0
+ *
+ * @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.
+ */
+__rte_experimental
+int rte_cdx_map_device(struct rte_cdx_device *dev);
Signature · 1 line
David Marchand
#6 lore raw

[AMD Official Use Only - General]

Quoted 44 lines
Quoted 43 lines · <[email protected]> wrote:
drivers/bus/cdx/cdx.c +6 -4
@@ -383,10 +384,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 */
drivers/bus/cdx/rte_bus_cdx.h new file +20 -0
new file mode 100644
index 0000000000..4ca12f90c4
@@ -0,0 +1,52 @@
+/* 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;
+
+/**
Quoted 8 lines

drivers/bus/cdx/rte_bus_cdx.h line 25

Quoted 5 lines
drivers/bus/cdx/rte_bus_cdx.h new file +5 -0
+ * 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.

Why should we export this function in the application ABI, if it is only used by drivers?

This can be called from an application as well if this flag is not set hence, we need to export this function. If needed, I can update the description of the API.

Thanks,
Abhijit

#7 lore raw
Quoted 11 lines · Abhijit
Quoted 9 lines
Quoted 6 lines

+/**
+ * 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.

Why should we export this function in the application ABI, if it is only used by drivers?

This can be called from an application as well if this flag is not set hence, we need to export this function.

What kind of applications / in which usecase, one would need to map the device resources?
Except a driver?

Signature · 1 line
David Marchand
#8 lore raw
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines

+/**
+ * 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.

Why should we export this function in the application ABI, if it is only used by drivers?

Quoted 6 lines
Quoted 1 line

This can be called from an application as well if this flag is not set hence, we

need to export this function.

What kind of applications / in which usecase, one would need to map the device resources?
Except a driver?

I understand that it is probably not the ideal use case, but some of the customers are using a single application which also registers itself as driver. Probably such applications need to use internal APIs instead of making these APIs external. Will analyze it further and send another rev of this patch.

Thanks,
Abhijit

#9 lore raw
Quoted 14 lines · Abhijit
Quoted 14 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

+/**
+ * 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.

Quoted 4 lines
Quoted 2 lines

Why should we export this function in the application ABI, if it is only used by drivers?

This can be called from an application as well if this flag is not set hence, we

need to export this function.

Quoted 8 lines
Quoted 3 lines

What kind of applications / in which usecase, one would need to map the device resources?
Except a driver?

I understand that it is probably not the ideal use case, but some of the customers are using a single application which also registers itself as driver. Probably such applications need to use internal APIs instead of making these APIs external. Will analyze it further and send another rev of this patch.

External drivers should be supported with current code.
DPDK must be built with enable_driver_sdk option, and the external driver code can include bus_cdx_driver.h.
Possibly compiling this code with -DENABLE_INTERNAL_API cflag will be necessary.

Signature · 1 line
David Marchand
#10 lore raw
In reply to Abhijit Gangurde
Quoted 25 lines

-----Original Message-----
From: Abhijit Gangurde <[email protected]>
Sent: Monday, June 26, 2023 4:10 PM
To: Gupta, Nipun <[email protected]>; Agarwal, Nikhil <[email protected]>
Cc: [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; Gangurde, Abhijit <[email protected]>
Subject: [PATCH] bus/cdx: provide driver flag for optional resource mapping

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.

---
 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

<snip>

Quoted 9 lines
drivers/bus/cdx/rte_bus_cdx.h new file +9 -0
+/* 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.

drivers/bus/cdx/rte_bus_cdx.h line 35

Quoted 10 lines
drivers/bus/cdx/rte_bus_cdx.h new file +10 -0
+ *
+ * @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);

rte_experimental?

#11 lore raw

PATCH v4 1/1 bus/cdx: provide driver flag for optional resource mapping

In reply to Abhijit Gangurde

Provide driver flag which gives an option to map the cdx device resource before probing the device driver. External driver can use rte_cdx_map_device() and rte_cdx_unmap_device() APIs to map/ unmap device resource separately.

---
v4:
- rte_cdx_map_device() and rte_cdx_unmap_device() APIs are kept as internal APIs.

v3:
- Changed APIs to __rte_experimental.

v2:
- Corrected _RTE_BUS_CDX_H_ to RTE_BUS_CDX_H
- Improved code comments.

 drivers/bus/cdx/bus_cdx_driver.h |  3 +++
 drivers/bus/cdx/cdx.c            | 10 ++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)
drivers/bus/cdx/bus_cdx_driver.h +3 -0
index fcacdb5896..1c9a64c87a 100644
@@ -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.
drivers/bus/cdx/cdx.c +6 -4
index f9526e08cc..541aae76c3 100644
@@ -383,10 +383,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 */
Signature · 1 line
2.34.1
#12 lore raw

16/10/2023 11:16, Abhijit Gangurde:

Quoted 6 lines

Provide driver flag which gives an option to map the cdx device resource before probing the device driver. External driver can use rte_cdx_map_device() and rte_cdx_unmap_device() APIs to map/ unmap device resource separately.

Applied, thanks.