[dpdk-dev,v6,5/6] bus: add helper to find a bus from a device name
Checks
Commit Message
Find which bus should be able to parse this device name into an internal
device representation.
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
lib/librte_eal/common/eal_common_bus.c | 15 +++++++++++++++
lib/librte_eal/common/eal_private.h | 12 ++++++++++++
2 files changed, 27 insertions(+)
Comments
I made this API private, however we can see the bonding PMD could use
this kind of facility:
http://dpdk.org/ml/archives/dev/2017-July/070087.html
I know the failsafe could leverage this, as well as another bus idea I
threw together a few weeks ago[1].
So maybe I should make it public? This can always be fixed
past-integration though, and I'd prefer being able to go forward on the
PCI move.
[1]: http://dpdk.org/ml/archives/dev/2017-June/067546.html
On Tue, Jul 04, 2017 at 02:58:32AM +0200, Gaetan Rivet wrote:
> Find which bus should be able to parse this device name into an internal
> device representation.
>
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
> lib/librte_eal/common/eal_common_bus.c | 15 +++++++++++++++
> lib/librte_eal/common/eal_private.h | 12 ++++++++++++
> 2 files changed, 27 insertions(+)
>
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> index 87b0c6e..b143f21 100644
> --- a/lib/librte_eal/common/eal_common_bus.c
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -204,3 +204,18 @@ rte_bus_find_by_name(const char *busname)
> {
> return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
> }
> +
> +static int
> +bus_can_parse(const struct rte_bus *bus, const void *_name)
> +{
> + const char *name = _name;
> +
> + return !(bus->parse && bus->parse(name, NULL) == 0);
> +}
> +
> +/* find a bus capable of parsing a device description */
> +struct rte_bus *
> +rte_bus_find_by_device_name(const char *str)
> +{
> + return rte_bus_find(NULL, bus_can_parse, str);
> +}
> diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
> index 6cacce0..0836339 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void);
> */
> bool rte_eal_using_phys_addrs(void);
>
> +/**
> + * Find a bus capable of identifying a device.
> + *
> + * @param str
> + * A device identifier (PCI address, virtual PMD name, ...).
> + *
> + * @return
> + * A valid bus handle if found.
> + * NULL if no bus is able to parse this device.
> + */
> +struct rte_bus *rte_bus_find_by_device_name(const char *str);
> +
> #endif /* _EAL_PRIVATE_H_ */
> --
> 2.1.4
>
@@ -204,3 +204,18 @@ rte_bus_find_by_name(const char *busname)
{
return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
}
+
+static int
+bus_can_parse(const struct rte_bus *bus, const void *_name)
+{
+ const char *name = _name;
+
+ return !(bus->parse && bus->parse(name, NULL) == 0);
+}
+
+/* find a bus capable of parsing a device description */
+struct rte_bus *
+rte_bus_find_by_device_name(const char *str)
+{
+ return rte_bus_find(NULL, bus_can_parse, str);
+}
@@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void);
*/
bool rte_eal_using_phys_addrs(void);
+/**
+ * Find a bus capable of identifying a device.
+ *
+ * @param str
+ * A device identifier (PCI address, virtual PMD name, ...).
+ *
+ * @return
+ * A valid bus handle if found.
+ * NULL if no bus is able to parse this device.
+ */
+struct rte_bus *rte_bus_find_by_device_name(const char *str);
+
#endif /* _EAL_PRIVATE_H_ */