[v6,22/27] dev: introduce driver accessors

Message ID 20220914075841.51555-23-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series Bus and device cleanup for 22.11 |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

David Marchand Sept. 14, 2022, 7:58 a.m. UTC
  Prepare for making the driver object opaque by adding accessors.
Update existing "external" users.
Internal users may still dereference a rte_driver object.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/test-pmd/config.c           |  2 +-
 lib/eal/common/eal_common_dev.c |  6 ++++++
 lib/eal/include/rte_dev.h       | 15 +++++++++++++++
 lib/eal/version.map             |  3 +++
 lib/ethdev/rte_ethdev.h         |  2 +-
 5 files changed, 26 insertions(+), 2 deletions(-)
  

Patch

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 7bd28ee3e8..6510f29c76 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -654,7 +654,7 @@  device_infos_display(const char *identifier)
 			printf("\n%s Infos for device %s %s\n",
 			       info_border, dev->name, info_border);
 			printf("Bus name: %s", rte_bus_name(dev->bus));
-			printf("\nDriver name: %s", dev->driver->name);
+			printf("\nDriver name: %s", rte_driver_name(dev->driver));
 			printf("\nDevargs: %s",
 			       dev->devargs ? dev->devargs->args : "");
 			printf("\nConnect to socket: %d", dev->numa_node);
diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c
index 62a598957c..16c5aef1d8 100644
--- a/lib/eal/common/eal_common_dev.c
+++ b/lib/eal/common/eal_common_dev.c
@@ -19,6 +19,12 @@ 
 #include "eal_private.h"
 #include "hotplug_mp.h"
 
+const char *
+rte_driver_name(const struct rte_driver *driver)
+{
+	return driver->name;
+}
+
 /**
  * The device event callback description.
  *
diff --git a/lib/eal/include/rte_dev.h b/lib/eal/include/rte_dev.h
index 2743c09320..ddea163cca 100644
--- a/lib/eal/include/rte_dev.h
+++ b/lib/eal/include/rte_dev.h
@@ -76,6 +76,21 @@  struct rte_driver {
 	const char *alias;              /**< Driver alias. */
 };
 
+/**
+ * Retrieve a driver name.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @param driver
+ *   A pointer to a driver structure.
+ * @return
+ *   A pointer to the driver name string.
+ */
+__rte_experimental
+const char *
+rte_driver_name(const struct rte_driver *driver);
+
 /*
  * Internal identifier length
  * Sufficiently large to allow for UUID or PCI address
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 6ec15f1147..d10fd89458 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -423,6 +423,9 @@  EXPERIMENTAL {
 	rte_thread_self;
 	rte_thread_set_affinity_by_id;
 	rte_thread_set_priority;
+
+	# added in 22.11
+	rte_driver_name;
 };
 
 INTERNAL {
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index 41d37e41b5..7556b94602 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -3380,7 +3380,7 @@  int rte_eth_macaddrs_get(uint16_t port_id, struct rte_ether_addr *ma,
  * exists for the device and the rte_eth_dev 'dev' has been populated
  * successfully with a call to it:
  *
- * driver_name = dev->device->driver->name
+ * driver_name = rte_driver_name(dev->device->driver)
  * nb_rx_queues = dev->data->nb_rx_queues
  * nb_tx_queues = dev->data->nb_tx_queues
  * dev_flags = &dev->data->dev_flags