[dpdk-dev,v3,02/12] eal/bus: introduce bus abstraction

Message ID 1481893853-31790-3-git-send-email-shreyansh.jain@nxp.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation success Compilation OK

Commit Message

Shreyansh Jain Dec. 16, 2016, 1:10 p.m. UTC
  This patch introduces the rte_bus abstraction for devices and drivers in
EAL framework. The model is:
 - One or more buses are connected to a CPU (or core)
 - One or more devices are conneted to a Bus
 - Drivers are running instances which manage one or more devices
 - Bus is responsible for identifying devices (and interrupt propogation)
 - Driver is responsible for initializing the device

This patch adds a 'rte_bus' class which rte_driver and rte_device refer.
This way, each device (rte_xxx_device) would have reference to the bus
it is based on. As well as, each driver (rte_xxx_driver) would have link
to the bus and devices on it for servicing.

                                  __ rte_bus_list
                                 /
                     +----------'---+
                     |rte_bus       |
                     | driver_list------> List of rte_bus specific
                     | device_list----    devices
                     |              | `-> List of rte_bus associated
                     |              |     drivers
                     +--|------|----+
              _________/        \_________
    +--------/----+                     +-\---------------+
    |rte_device   |                     |rte_driver       |
    | rte_bus     |                     | rte_bus         |
    | rte_driver  |                     | ...             |
    | ...         |                     +---------...-----+
    |             |                               |||
    +---||--------+                               |||
        ||                                        |||
        | \                                        \\\
        |  \_____________                           \\\
        |                \                          |||
 +------|---------+ +----|----------+               |||
 |rte_pci_device  | |rte_xxx_device |               |||
 | ....           | | ....          |               |||
 +----------------+ +---------------+              / | \
                                                  /  |  \
                            _____________________/  /    \
                           /                    ___/      \
            +-------------'--+    +------------'---+    +--'------------+
            |rte_pci_driver  |    |rte_vdev_driver |    |rte_xxx_driver |
            | ....           |    | ....           |    | ....          |
            +----------------+    +----------------+    +---------------+

This patch only enables the bus references on rte_driver and rte_driver.
EAL wide global device and driver list continue to exist until an instance
of bus is added in subsequent patches.

This patch also introduces RTE_REGISTER_BUS macro on the lines of
RTE_PMD_REGISTER_XXX. Key difference is that the constructor priority has
been explicitly set to 101 so as to execute bus registration before PMD.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>

--
v2:
 - fix bsdapp compilation issue because of missing export symbols in map
   file
---
 lib/librte_eal/bsdapp/eal/Makefile              |   1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  15 ++
 lib/librte_eal/common/Makefile                  |   2 +-
 lib/librte_eal/common/eal_common_bus.c          | 192 ++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 174 +++++++++++++++++++++
 lib/librte_eal/common/include/rte_dev.h         |   2 +
 lib/librte_eal/linuxapp/eal/Makefile            |   1 +
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  15 ++
 8 files changed, 401 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_eal/common/eal_common_bus.c
 create mode 100644 lib/librte_eal/common/include/rte_bus.h
  

Comments

Hemant Agrawal Dec. 20, 2016, 12:37 p.m. UTC | #1
On 12/16/2016 6:40 PM, Shreyansh Jain wrote:
> This patch introduces the rte_bus abstraction for devices and drivers in
> EAL framework. The model is:
>  - One or more buses are connected to a CPU (or core)
>  - One or more devices are conneted to a Bus
>  - Drivers are running instances which manage one or more devices
>  - Bus is responsible for identifying devices (and interrupt propogation)
>  - Driver is responsible for initializing the device
>
> This patch adds a 'rte_bus' class which rte_driver and rte_device refer.
> This way, each device (rte_xxx_device) would have reference to the bus
> it is based on. As well as, each driver (rte_xxx_driver) would have link
> to the bus and devices on it for servicing.
>
>                                   __ rte_bus_list
>                                  /
>                      +----------'---+
>                      |rte_bus       |
>                      | driver_list------> List of rte_bus specific
>                      | device_list----    devices
>                      |              | `-> List of rte_bus associated
>                      |              |     drivers
>                      +--|------|----+
>               _________/        \_________
>     +--------/----+                     +-\---------------+
>     |rte_device   |                     |rte_driver       |
>     | rte_bus     |                     | rte_bus         |
>     | rte_driver  |                     | ...             |
>     | ...         |                     +---------...-----+
>     |             |                               |||
>     +---||--------+                               |||
>         ||                                        |||
>         | \                                        \\\
>         |  \_____________                           \\\
>         |                \                          |||
>  +------|---------+ +----|----------+               |||
>  |rte_pci_device  | |rte_xxx_device |               |||
>  | ....           | | ....          |               |||
>  +----------------+ +---------------+              / | \
>                                                   /  |  \
>                             _____________________/  /    \
>                            /                    ___/      \
>             +-------------'--+    +------------'---+    +--'------------+
>             |rte_pci_driver  |    |rte_vdev_driver |    |rte_xxx_driver |
>             | ....           |    | ....           |    | ....          |
>             +----------------+    +----------------+    +---------------+
>
> This patch only enables the bus references on rte_driver and rte_driver.
> EAL wide global device and driver list continue to exist until an instance
> of bus is added in subsequent patches.
>
> This patch also introduces RTE_REGISTER_BUS macro on the lines of
> RTE_PMD_REGISTER_XXX. Key difference is that the constructor priority has
> been explicitly set to 101 so as to execute bus registration before PMD.
>
> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>
> --
> v2:
>  - fix bsdapp compilation issue because of missing export symbols in map
>    file
> ---
>  lib/librte_eal/bsdapp/eal/Makefile              |   1 +
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  15 ++
>  lib/librte_eal/common/Makefile                  |   2 +-
>  lib/librte_eal/common/eal_common_bus.c          | 192 ++++++++++++++++++++++++
>  lib/librte_eal/common/include/rte_bus.h         | 174 +++++++++++++++++++++
>  lib/librte_eal/common/include/rte_dev.h         |   2 +
>  lib/librte_eal/linuxapp/eal/Makefile            |   1 +
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  15 ++
>  8 files changed, 401 insertions(+), 1 deletion(-)
>  create mode 100644 lib/librte_eal/common/eal_common_bus.c
>  create mode 100644 lib/librte_eal/common/include/rte_bus.h
>
> diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
> index a15b762..cce99f7 100644
> --- a/lib/librte_eal/bsdapp/eal/Makefile
> +++ b/lib/librte_eal/bsdapp/eal/Makefile
> @@ -78,6 +78,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_cpuflags.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_string_fns.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_hexdump.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_devargs.c
> +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_bus.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c
> diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> index 2f81f7c..23fc1c1 100644
> --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> @@ -174,3 +174,18 @@ DPDK_16.11 {
>  	rte_eal_vdrv_unregister;
>
>  } DPDK_16.07;
> +
> +DPDK_17.02 {
> +	global:
> +
> +	rte_bus_list;
> +	rte_eal_bus_add_device;
> +	rte_eal_bus_add_driver;
> +	rte_eal_get_bus;
> +	rte_eal_bus_dump;
> +	rte_eal_bus_register;
> +	rte_eal_bus_remove_device;
> +	rte_eal_bus_remove_driver;
> +	rte_eal_bus_unregister;
> +
> +} DPDK_16.11;
> diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
> index a92c984..0c39414 100644
> --- a/lib/librte_eal/common/Makefile
> +++ b/lib/librte_eal/common/Makefile
> @@ -38,7 +38,7 @@ INC += rte_per_lcore.h rte_random.h
>  INC += rte_tailq.h rte_interrupts.h rte_alarm.h
>  INC += rte_string_fns.h rte_version.h
>  INC += rte_eal_memconfig.h rte_malloc_heap.h
> -INC += rte_hexdump.h rte_devargs.h rte_dev.h rte_vdev.h
> +INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_vdev.h
>  INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
>  INC += rte_malloc.h rte_keepalive.h rte_time.h
>
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> new file mode 100644
> index 0000000..612f64e
> --- /dev/null
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -0,0 +1,192 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2016 NXP
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of NXP nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include <stdio.h>
> +#include <string.h>
> +#include <inttypes.h>
> +#include <sys/queue.h>
> +
> +#include <rte_bus.h>
> +#include <rte_devargs.h>
> +#include <rte_debug.h>
> +
> +#include "eal_private.h"
> +
> +struct rte_bus_list rte_bus_list =
> +	TAILQ_HEAD_INITIALIZER(rte_bus_list);
> +
> +/** @internal
> + * Add a device to a bus.
> + */
> +void
> +rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev)
> +{
> +	RTE_VERIFY(bus);
> +	RTE_VERIFY(dev);
> +
> +	TAILQ_INSERT_TAIL(&bus->device_list, dev, next);
> +	dev->bus = bus;
> +}
> +
> +/** @internal
> + * Remove a device from its bus.
> + */
> +void
> +rte_eal_bus_remove_device(struct rte_device *dev)
> +{
> +	struct rte_bus *bus;
> +
> +	RTE_VERIFY(dev);
> +	RTE_VERIFY(dev->bus);
> +
> +	bus = dev->bus;
> +	TAILQ_REMOVE(&bus->device_list, dev, next);
> +	dev->bus = NULL;
> +}
> +
> +/** @internal
> + * Associate a driver with a bus.
> + */
> +void
> +rte_eal_bus_add_driver(struct rte_bus *bus, struct rte_driver *drv)
> +{
> +	RTE_VERIFY(bus);
> +	RTE_VERIFY(drv);
> +
> +	TAILQ_INSERT_TAIL(&bus->driver_list, drv, next);
> +	drv->bus = bus;
> +}
> +
> +/** @internal
> + * Disassociate a driver from bus.
> + */
> +void
> +rte_eal_bus_remove_driver(struct rte_driver *drv)
> +{
> +	struct rte_bus *bus;
> +
> +	RTE_VERIFY(drv);
> +	RTE_VERIFY(drv->bus);
> +
> +	bus = drv->bus;
> +	TAILQ_REMOVE(&bus->driver_list, drv, next);
> +	drv->bus = NULL;
> +}
> +
> +/**
> + * Get the bus handle using its name
> + */
> +struct rte_bus *
> +rte_eal_get_bus(const char *bus_name)
> +{
> +	struct rte_bus *bus;
> +
> +	RTE_VERIFY(bus_name);
> +
> +	TAILQ_FOREACH(bus, &rte_bus_list, next) {
> +		RTE_VERIFY(bus->name);
> +
> +		if (!strcmp(bus_name, bus->name)) {
> +			RTE_LOG(DEBUG, EAL, "Returning Bus object %p\n", bus);
> +			return bus;
> +		}
> +	}
> +
> +	/* Unable to find bus requested */
> +	return NULL;
> +}
> +
> +/* register a bus */
> +void
> +rte_eal_bus_register(struct rte_bus *bus)
> +{
> +	RTE_VERIFY(bus);
> +	RTE_VERIFY(bus->name && strlen(bus->name));
> +
> +	/* Initialize the driver and device list associated with the bus */
> +	TAILQ_INIT(&(bus->driver_list));
> +	TAILQ_INIT(&(bus->device_list));
> +
> +	TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
> +	RTE_LOG(INFO, EAL, "Registered [%s] bus.\n", bus->name);
> +}
> +
> +/* unregister a bus */
> +void
> +rte_eal_bus_unregister(struct rte_bus *bus)
> +{
> +	/* All devices and drivers associated with the bus should have been
> +	 * 'device->uninit' and 'driver->remove()' already.
> +	 */
> +	RTE_VERIFY(TAILQ_EMPTY(&(bus->driver_list)));
> +	RTE_VERIFY(TAILQ_EMPTY(&(bus->device_list)));
> +
> +	/* TODO: For each device, call its rte_device->driver->remove()
> +	 * and rte_eal_bus_remove_driver()
> +	 */
> +
> +	TAILQ_REMOVE(&rte_bus_list, bus, next);
> +	RTE_LOG(INFO, EAL, "Unregistered [%s] bus.\n", bus->name);
> +}
> +
> +/* dump one bus info */
> +static int
> +bus_dump_one(FILE *f, struct rte_bus *bus)
> +{
> +	int ret;
> +
> +	/* For now, dump only the bus name */
> +	ret = fprintf(f, " %s\n", bus->name);
> +
> +	/* Error in case of inability in writing to stream */
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +void
> +rte_eal_bus_dump(FILE *f)
> +{
> +	int ret;
> +	struct rte_bus *bus;
> +
> +	TAILQ_FOREACH(bus, &rte_bus_list, next) {
> +		ret = bus_dump_one(f, bus);
> +		if (ret) {
> +			RTE_LOG(ERR, EAL, "Unable to write to stream (%d)\n",
> +				ret);
> +			break;
> +		}
> +	}
> +}
> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> new file mode 100644
> index 0000000..f0297a9
> --- /dev/null
> +++ b/lib/librte_eal/common/include/rte_bus.h
> @@ -0,0 +1,174 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2016 NXP
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of NXP nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef _RTE_BUS_H_
> +#define _RTE_BUS_H_
> +
> +/**
> + * @file
> + *
> + * RTE PMD Bus Abstraction interfaces
> + *
> + * This file exposes APIs and Interfaces for Bus Abstraction over the devices
> + * drivers in EAL.
> + */
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +#include <stdio.h>
> +#include <sys/queue.h>
> +
> +#include <rte_log.h>
> +#include <rte_dev.h>
> +
> +/** Double linked list of buses */
> +TAILQ_HEAD(rte_bus_list, rte_bus);
> +
> +/* Global Bus list */
> +extern struct rte_bus_list rte_bus_list;
> +
> +struct rte_bus {
> +	TAILQ_ENTRY(rte_bus) next;   /**< Next bus object in linked list */
> +	struct rte_driver_list driver_list;
> +				     /**< List of all drivers on bus */
> +	struct rte_device_list device_list;
> +				     /**< List of all devices on bus */
> +	const char *name;            /**< Name of the bus */
> +};
> +
> +/** @internal
> + * Add a device to a bus.
> + *
> + * @param bus
> + *	Bus on which device is to be added
> + * @param dev
> + *	Device handle
> + * @return
> + *	None
> + */
> +void
> +rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev);
> +
> +/** @internal
> + * Remove a device from its bus.
> + *
> + * @param dev
> + *	Device handle to remove
> + * @return
> + *	None
> + */
> +void
> +rte_eal_bus_remove_device(struct rte_device *dev);
> +
> +/** @internal
> + * Associate a driver with a bus.
> + *
> + * @param bus
> + *	Bus on which driver is to be added
> + * @param dev
> + *	Driver handle
> + * @return
> + *	None
> + */
> +void
> +rte_eal_bus_add_driver(struct rte_bus *bus, struct rte_driver *drv);
> +
> +/** @internal
> + * Disassociate a driver from its bus.
> + *
> + * @param dev
> + *	Driver handle to remove
> + * @return
> + *	None
> + */
> +void
> +rte_eal_bus_remove_driver(struct rte_driver *drv);
> +
> +/**
> + * Register a Bus handler.
> + *
> + * @param driver
> + *   A pointer to a rte_bus structure describing the bus
> + *   to be registered.
> + */
> +void rte_eal_bus_register(struct rte_bus *bus);
> +
> +/**
> + * Unregister a Bus handler.
> + *
> + * @param driver
> + *   A pointer to a rte_bus structure describing the bus
> + *   to be unregistered.
> + */
> +void rte_eal_bus_unregister(struct rte_bus *bus);
> +
> +/**
> + * Obtain handle for bus given its name.
> + *
> + * @param bus_name
> + *	Name of the bus handle to search
> + * @return
> + *	Pointer to Bus object if name matches any registered bus object
> + *	NULL, if no matching bus found
> + */
> +struct rte_bus *rte_eal_get_bus(const char *bus_name);
> +
> +/**
> + * Dump information of all the buses registered with EAL.
> + *
> + * @param f
> + *	A valid and open output stream handle
> + *
> + * @return
> + *	 0 in case of success
> + *	!0 in case there is error in opening the output stream
> + */
> +void rte_eal_bus_dump(FILE *f);
> +
> +/** Helper for Bus registration. The constructor has higher priority than
> + * PMD constructors
> + */
> +#define RTE_REGISTER_BUS(nm, bus) \
> +static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
> +{\
> +	(bus).name = RTE_STR(nm);\
> +	rte_eal_bus_register(&bus); \
> +}
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* _RTE_BUS_H */
> diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
> index 8840380..4004f9a 100644
> --- a/lib/librte_eal/common/include/rte_dev.h
> +++ b/lib/librte_eal/common/include/rte_dev.h
> @@ -122,6 +122,7 @@ struct rte_driver;
>   */
>  struct rte_device {
>  	TAILQ_ENTRY(rte_device) next; /**< Next device */
> +	struct rte_bus *bus;          /**< Device connected to this bus */
>  	struct rte_driver *driver;    /**< Associated driver */
>  	int numa_node;                /**< NUMA node connection */
>  	struct rte_devargs *devargs;  /**< Device user arguments */
> @@ -148,6 +149,7 @@ void rte_eal_device_remove(struct rte_device *dev);
>   */
>  struct rte_driver {
>  	TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */
> +	struct rte_bus *bus;           /**< Bus serviced by this driver */
>  	const char *name;                   /**< Driver name. */
>  	const char *alias;              /**< Driver alias. */
>  };
> diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
> index 4e206f0..aa874a5 100644
> --- a/lib/librte_eal/linuxapp/eal/Makefile
> +++ b/lib/librte_eal/linuxapp/eal/Makefile
> @@ -87,6 +87,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_cpuflags.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_string_fns.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_hexdump.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c
> +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_bus.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c
> diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> index 83721ba..c873a7f 100644
> --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> @@ -178,3 +178,18 @@ DPDK_16.11 {
>  	rte_eal_vdrv_unregister;
>
>  } DPDK_16.07;
> +
> +DPDK_17.02 {
> +	global:
> +
> +	rte_bus_list;
> +	rte_eal_bus_add_device;
> +	rte_eal_bus_add_driver;
> +	rte_eal_get_bus;

This should be rte_eal_bus_get

Also you are missing rte_eal_bus_insert_device

> +	rte_eal_bus_dump;
> +	rte_eal_bus_register;
> +	rte_eal_bus_remove_device;
> +	rte_eal_bus_remove_driver;
> +	rte_eal_bus_unregister;
> +
> +} DPDK_16.11;
>
  
Jan Blunck Dec. 20, 2016, 1:17 p.m. UTC | #2
On Fri, Dec 16, 2016 at 2:10 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> This patch introduces the rte_bus abstraction for devices and drivers in
> EAL framework. The model is:
>  - One or more buses are connected to a CPU (or core)
>  - One or more devices are conneted to a Bus
>  - Drivers are running instances which manage one or more devices
>  - Bus is responsible for identifying devices (and interrupt propogation)
>  - Driver is responsible for initializing the device
>
> This patch adds a 'rte_bus' class which rte_driver and rte_device refer.
> This way, each device (rte_xxx_device) would have reference to the bus
> it is based on. As well as, each driver (rte_xxx_driver) would have link
> to the bus and devices on it for servicing.
>
>                                   __ rte_bus_list
>                                  /
>                      +----------'---+
>                      |rte_bus       |
>                      | driver_list------> List of rte_bus specific
>                      | device_list----    devices
>                      |              | `-> List of rte_bus associated
>                      |              |     drivers
>                      +--|------|----+
>               _________/        \_________
>     +--------/----+                     +-\---------------+
>     |rte_device   |                     |rte_driver       |
>     | rte_bus     |                     | rte_bus         |
>     | rte_driver  |                     | ...             |
>     | ...         |                     +---------...-----+
>     |             |                               |||
>     +---||--------+                               |||
>         ||                                        |||
>         | \                                        \\\
>         |  \_____________                           \\\
>         |                \                          |||
>  +------|---------+ +----|----------+               |||
>  |rte_pci_device  | |rte_xxx_device |               |||
>  | ....           | | ....          |               |||
>  +----------------+ +---------------+              / | \
>                                                   /  |  \
>                             _____________________/  /    \
>                            /                    ___/      \
>             +-------------'--+    +------------'---+    +--'------------+
>             |rte_pci_driver  |    |rte_vdev_driver |    |rte_xxx_driver |
>             | ....           |    | ....           |    | ....          |
>             +----------------+    +----------------+    +---------------+
>
> This patch only enables the bus references on rte_driver and rte_driver.
> EAL wide global device and driver list continue to exist until an instance
> of bus is added in subsequent patches.
>
> This patch also introduces RTE_REGISTER_BUS macro on the lines of
> RTE_PMD_REGISTER_XXX. Key difference is that the constructor priority has
> been explicitly set to 101 so as to execute bus registration before PMD.
>
> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>
> --
> v2:
>  - fix bsdapp compilation issue because of missing export symbols in map
>    file
> ---
>  lib/librte_eal/bsdapp/eal/Makefile              |   1 +
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  15 ++
>  lib/librte_eal/common/Makefile                  |   2 +-
>  lib/librte_eal/common/eal_common_bus.c          | 192 ++++++++++++++++++++++++
>  lib/librte_eal/common/include/rte_bus.h         | 174 +++++++++++++++++++++
>  lib/librte_eal/common/include/rte_dev.h         |   2 +
>  lib/librte_eal/linuxapp/eal/Makefile            |   1 +
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  15 ++
>  8 files changed, 401 insertions(+), 1 deletion(-)
>  create mode 100644 lib/librte_eal/common/eal_common_bus.c
>  create mode 100644 lib/librte_eal/common/include/rte_bus.h
>
> diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
> index a15b762..cce99f7 100644
> --- a/lib/librte_eal/bsdapp/eal/Makefile
> +++ b/lib/librte_eal/bsdapp/eal/Makefile
> @@ -78,6 +78,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_cpuflags.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_string_fns.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_hexdump.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_devargs.c
> +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_bus.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c
> diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> index 2f81f7c..23fc1c1 100644
> --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> @@ -174,3 +174,18 @@ DPDK_16.11 {
>         rte_eal_vdrv_unregister;
>
>  } DPDK_16.07;
> +
> +DPDK_17.02 {
> +       global:
> +
> +       rte_bus_list;
> +       rte_eal_bus_add_device;
> +       rte_eal_bus_add_driver;
> +       rte_eal_get_bus;
> +       rte_eal_bus_dump;
> +       rte_eal_bus_register;
> +       rte_eal_bus_remove_device;
> +       rte_eal_bus_remove_driver;
> +       rte_eal_bus_unregister;
> +
> +} DPDK_16.11;
> diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
> index a92c984..0c39414 100644
> --- a/lib/librte_eal/common/Makefile
> +++ b/lib/librte_eal/common/Makefile
> @@ -38,7 +38,7 @@ INC += rte_per_lcore.h rte_random.h
>  INC += rte_tailq.h rte_interrupts.h rte_alarm.h
>  INC += rte_string_fns.h rte_version.h
>  INC += rte_eal_memconfig.h rte_malloc_heap.h
> -INC += rte_hexdump.h rte_devargs.h rte_dev.h rte_vdev.h
> +INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_vdev.h
>  INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
>  INC += rte_malloc.h rte_keepalive.h rte_time.h
>
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> new file mode 100644
> index 0000000..612f64e
> --- /dev/null
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -0,0 +1,192 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2016 NXP
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of NXP nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include <stdio.h>
> +#include <string.h>
> +#include <inttypes.h>
> +#include <sys/queue.h>
> +
> +#include <rte_bus.h>
> +#include <rte_devargs.h>
> +#include <rte_debug.h>
> +
> +#include "eal_private.h"
> +
> +struct rte_bus_list rte_bus_list =
> +       TAILQ_HEAD_INITIALIZER(rte_bus_list);
> +
> +/** @internal
> + * Add a device to a bus.
> + */
> +void
> +rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev)
> +{
> +       RTE_VERIFY(bus);
> +       RTE_VERIFY(dev);
> +
> +       TAILQ_INSERT_TAIL(&bus->device_list, dev, next);
> +       dev->bus = bus;
> +}
> +
> +/** @internal
> + * Remove a device from its bus.
> + */
> +void
> +rte_eal_bus_remove_device(struct rte_device *dev)
> +{
> +       struct rte_bus *bus;
> +
> +       RTE_VERIFY(dev);
> +       RTE_VERIFY(dev->bus);
> +
> +       bus = dev->bus;
> +       TAILQ_REMOVE(&bus->device_list, dev, next);
> +       dev->bus = NULL;
> +}
> +
> +/** @internal
> + * Associate a driver with a bus.
> + */
> +void
> +rte_eal_bus_add_driver(struct rte_bus *bus, struct rte_driver *drv)
> +{
> +       RTE_VERIFY(bus);
> +       RTE_VERIFY(drv);
> +
> +       TAILQ_INSERT_TAIL(&bus->driver_list, drv, next);
> +       drv->bus = bus;
> +}
> +
> +/** @internal
> + * Disassociate a driver from bus.
> + */
> +void
> +rte_eal_bus_remove_driver(struct rte_driver *drv)
> +{
> +       struct rte_bus *bus;
> +
> +       RTE_VERIFY(drv);
> +       RTE_VERIFY(drv->bus);
> +
> +       bus = drv->bus;
> +       TAILQ_REMOVE(&bus->driver_list, drv, next);
> +       drv->bus = NULL;
> +}
> +
> +/**
> + * Get the bus handle using its name
> + */
> +struct rte_bus *
> +rte_eal_get_bus(const char *bus_name)
> +{
> +       struct rte_bus *bus;
> +
> +       RTE_VERIFY(bus_name);
> +
> +       TAILQ_FOREACH(bus, &rte_bus_list, next) {
> +               RTE_VERIFY(bus->name);
> +
> +               if (!strcmp(bus_name, bus->name)) {
> +                       RTE_LOG(DEBUG, EAL, "Returning Bus object %p\n", bus);
> +                       return bus;
> +               }
> +       }
> +
> +       /* Unable to find bus requested */
> +       return NULL;
> +}
> +
> +/* register a bus */
> +void
> +rte_eal_bus_register(struct rte_bus *bus)
> +{
> +       RTE_VERIFY(bus);
> +       RTE_VERIFY(bus->name && strlen(bus->name));
> +
> +       /* Initialize the driver and device list associated with the bus */
> +       TAILQ_INIT(&(bus->driver_list));
> +       TAILQ_INIT(&(bus->device_list));
> +
> +       TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
> +       RTE_LOG(INFO, EAL, "Registered [%s] bus.\n", bus->name);
> +}
> +
> +/* unregister a bus */
> +void
> +rte_eal_bus_unregister(struct rte_bus *bus)
> +{
> +       /* All devices and drivers associated with the bus should have been
> +        * 'device->uninit' and 'driver->remove()' already.
> +        */
> +       RTE_VERIFY(TAILQ_EMPTY(&(bus->driver_list)));
> +       RTE_VERIFY(TAILQ_EMPTY(&(bus->device_list)));
> +
> +       /* TODO: For each device, call its rte_device->driver->remove()
> +        * and rte_eal_bus_remove_driver()
> +        */
> +
> +       TAILQ_REMOVE(&rte_bus_list, bus, next);
> +       RTE_LOG(INFO, EAL, "Unregistered [%s] bus.\n", bus->name);
> +}
> +
> +/* dump one bus info */
> +static int
> +bus_dump_one(FILE *f, struct rte_bus *bus)
> +{
> +       int ret;
> +
> +       /* For now, dump only the bus name */
> +       ret = fprintf(f, " %s\n", bus->name);
> +
> +       /* Error in case of inability in writing to stream */
> +       if (ret < 0)
> +               return ret;
> +
> +       return 0;
> +}
> +
> +void
> +rte_eal_bus_dump(FILE *f)
> +{
> +       int ret;
> +       struct rte_bus *bus;
> +
> +       TAILQ_FOREACH(bus, &rte_bus_list, next) {
> +               ret = bus_dump_one(f, bus);
> +               if (ret) {
> +                       RTE_LOG(ERR, EAL, "Unable to write to stream (%d)\n",
> +                               ret);
> +                       break;
> +               }
> +       }
> +}
> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> new file mode 100644
> index 0000000..f0297a9
> --- /dev/null
> +++ b/lib/librte_eal/common/include/rte_bus.h
> @@ -0,0 +1,174 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2016 NXP
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of NXP nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef _RTE_BUS_H_
> +#define _RTE_BUS_H_
> +
> +/**
> + * @file
> + *
> + * RTE PMD Bus Abstraction interfaces
> + *
> + * This file exposes APIs and Interfaces for Bus Abstraction over the devices
> + * drivers in EAL.
> + */
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +#include <stdio.h>
> +#include <sys/queue.h>
> +
> +#include <rte_log.h>
> +#include <rte_dev.h>
> +
> +/** Double linked list of buses */
> +TAILQ_HEAD(rte_bus_list, rte_bus);
> +
> +/* Global Bus list */
> +extern struct rte_bus_list rte_bus_list;
> +
> +struct rte_bus {
> +       TAILQ_ENTRY(rte_bus) next;   /**< Next bus object in linked list */
> +       struct rte_driver_list driver_list;
> +                                    /**< List of all drivers on bus */
> +       struct rte_device_list device_list;
> +                                    /**< List of all devices on bus */
> +       const char *name;            /**< Name of the bus */
> +};
> +
> +/** @internal
> + * Add a device to a bus.
> + *
> + * @param bus
> + *     Bus on which device is to be added
> + * @param dev
> + *     Device handle
> + * @return
> + *     None
> + */
> +void
> +rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev);
> +
> +/** @internal
> + * Remove a device from its bus.
> + *
> + * @param dev
> + *     Device handle to remove
> + * @return
> + *     None
> + */
> +void
> +rte_eal_bus_remove_device(struct rte_device *dev);
> +
> +/** @internal
> + * Associate a driver with a bus.
> + *
> + * @param bus
> + *     Bus on which driver is to be added
> + * @param dev
> + *     Driver handle
> + * @return
> + *     None
> + */
> +void
> +rte_eal_bus_add_driver(struct rte_bus *bus, struct rte_driver *drv);
> +
> +/** @internal
> + * Disassociate a driver from its bus.
> + *
> + * @param dev
> + *     Driver handle to remove
> + * @return
> + *     None
> + */
> +void
> +rte_eal_bus_remove_driver(struct rte_driver *drv);
> +
> +/**
> + * Register a Bus handler.
> + *
> + * @param driver
> + *   A pointer to a rte_bus structure describing the bus
> + *   to be registered.
> + */
> +void rte_eal_bus_register(struct rte_bus *bus);
> +
> +/**
> + * Unregister a Bus handler.
> + *
> + * @param driver
> + *   A pointer to a rte_bus structure describing the bus
> + *   to be unregistered.
> + */
> +void rte_eal_bus_unregister(struct rte_bus *bus);
> +
> +/**
> + * Obtain handle for bus given its name.
> + *
> + * @param bus_name
> + *     Name of the bus handle to search
> + * @return
> + *     Pointer to Bus object if name matches any registered bus object
> + *     NULL, if no matching bus found
> + */
> +struct rte_bus *rte_eal_get_bus(const char *bus_name);
> +
> +/**
> + * Dump information of all the buses registered with EAL.
> + *
> + * @param f
> + *     A valid and open output stream handle
> + *
> + * @return
> + *      0 in case of success
> + *     !0 in case there is error in opening the output stream
> + */
> +void rte_eal_bus_dump(FILE *f);
> +
> +/** Helper for Bus registration. The constructor has higher priority than
> + * PMD constructors
> + */
> +#define RTE_REGISTER_BUS(nm, bus) \
> +static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
> +{\
> +       (bus).name = RTE_STR(nm);\
> +       rte_eal_bus_register(&bus); \
> +}
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* _RTE_BUS_H */
> diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
> index 8840380..4004f9a 100644
> --- a/lib/librte_eal/common/include/rte_dev.h
> +++ b/lib/librte_eal/common/include/rte_dev.h
> @@ -122,6 +122,7 @@ struct rte_driver;
>   */
>  struct rte_device {
>         TAILQ_ENTRY(rte_device) next; /**< Next device */
> +       struct rte_bus *bus;          /**< Device connected to this bus */

Is there a reason why this isn't const?


>         struct rte_driver *driver;    /**< Associated driver */
>         int numa_node;                /**< NUMA node connection */
>         struct rte_devargs *devargs;  /**< Device user arguments */
> @@ -148,6 +149,7 @@ void rte_eal_device_remove(struct rte_device *dev);
>   */
>  struct rte_driver {
>         TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */
> +       struct rte_bus *bus;           /**< Bus serviced by this driver */

Same thing here.

>         const char *name;                   /**< Driver name. */
>         const char *alias;              /**< Driver alias. */
>  };
> diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
> index 4e206f0..aa874a5 100644
> --- a/lib/librte_eal/linuxapp/eal/Makefile
> +++ b/lib/librte_eal/linuxapp/eal/Makefile
> @@ -87,6 +87,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_cpuflags.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_string_fns.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_hexdump.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c
> +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_bus.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c
> diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> index 83721ba..c873a7f 100644
> --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> @@ -178,3 +178,18 @@ DPDK_16.11 {
>         rte_eal_vdrv_unregister;
>
>  } DPDK_16.07;
> +
> +DPDK_17.02 {
> +       global:
> +
> +       rte_bus_list;
> +       rte_eal_bus_add_device;
> +       rte_eal_bus_add_driver;
> +       rte_eal_get_bus;
> +       rte_eal_bus_dump;
> +       rte_eal_bus_register;
> +       rte_eal_bus_remove_device;
> +       rte_eal_bus_remove_driver;
> +       rte_eal_bus_unregister;
> +
> +} DPDK_16.11;
> --
> 2.7.4
>
  
Shreyansh Jain Dec. 20, 2016, 1:51 p.m. UTC | #3
> -----Original Message-----

> From: jblunck@gmail.com [mailto:jblunck@gmail.com] On Behalf Of Jan Blunck

> Sent: Tuesday, December 20, 2016 6:47 PM

> To: Shreyansh Jain <shreyansh.jain@nxp.com>

> Cc: dev@dpdk.org; David Marchand <david.marchand@6wind.com>; Thomas Monjalon

> <thomas.monjalon@6wind.com>; Ferruh Yigit <ferruh.yigit@intel.com>;

> jianbo.liu@linaro.org

> Subject: Re: [dpdk-dev] [PATCH v3 02/12] eal/bus: introduce bus abstraction

> 

> On Fri, Dec 16, 2016 at 2:10 PM, Shreyansh Jain <shreyansh.jain@nxp.com>

> wrote:

> > This patch introduces the rte_bus abstraction for devices and drivers in

> > EAL framework. The model is:

> >  - One or more buses are connected to a CPU (or core)

> >  - One or more devices are conneted to a Bus

> >  - Drivers are running instances which manage one or more devices

> >  - Bus is responsible for identifying devices (and interrupt propogation)

> >  - Driver is responsible for initializing the device

> >

> > This patch adds a 'rte_bus' class which rte_driver and rte_device refer.

> > This way, each device (rte_xxx_device) would have reference to the bus

> > it is based on. As well as, each driver (rte_xxx_driver) would have link

> > to the bus and devices on it for servicing.

> >

> >                                   __ rte_bus_list

> >                                  /

> >                      +----------'---+

> >                      |rte_bus       |

> >                      | driver_list------> List of rte_bus specific

> >                      | device_list----    devices

> >                      |              | `-> List of rte_bus associated

> >                      |              |     drivers

> >                      +--|------|----+

> >               _________/        \_________

> >     +--------/----+                     +-\---------------+

> >     |rte_device   |                     |rte_driver       |

> >     | rte_bus     |                     | rte_bus         |

> >     | rte_driver  |                     | ...             |

> >     | ...         |                     +---------...-----+

> >     |             |                               |||

> >     +---||--------+                               |||

> >         ||                                        |||

> >         | \                                        \\\

> >         |  \_____________                           \\\

> >         |                \                          |||

> >  +------|---------+ +----|----------+               |||

> >  |rte_pci_device  | |rte_xxx_device |               |||

> >  | ....           | | ....          |               |||

> >  +----------------+ +---------------+              / | \

> >                                                   /  |  \

> >                             _____________________/  /    \

> >                            /                    ___/      \

> >             +-------------'--+    +------------'---+    +--'------------+

> >             |rte_pci_driver  |    |rte_vdev_driver |    |rte_xxx_driver |

> >             | ....           |    | ....           |    | ....          |

> >             +----------------+    +----------------+    +---------------+

> >

> > This patch only enables the bus references on rte_driver and rte_driver.

> > EAL wide global device and driver list continue to exist until an instance

> > of bus is added in subsequent patches.

> >

> > This patch also introduces RTE_REGISTER_BUS macro on the lines of

> > RTE_PMD_REGISTER_XXX. Key difference is that the constructor priority has

> > been explicitly set to 101 so as to execute bus registration before PMD.

> >

> > Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>

> >

> > --

> > v2:

> >  - fix bsdapp compilation issue because of missing export symbols in map

> >    file

> > ---

> >  lib/librte_eal/bsdapp/eal/Makefile              |   1 +

> >  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  15 ++

> >  lib/librte_eal/common/Makefile                  |   2 +-

> >  lib/librte_eal/common/eal_common_bus.c          | 192

> ++++++++++++++++++++++++

> >  lib/librte_eal/common/include/rte_bus.h         | 174

> +++++++++++++++++++++

> >  lib/librte_eal/common/include/rte_dev.h         |   2 +

> >  lib/librte_eal/linuxapp/eal/Makefile            |   1 +

> >  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  15 ++

> >  8 files changed, 401 insertions(+), 1 deletion(-)

> >  create mode 100644 lib/librte_eal/common/eal_common_bus.c

> >  create mode 100644 lib/librte_eal/common/include/rte_bus.h

> >

> > diff --git a/lib/librte_eal/bsdapp/eal/Makefile

> b/lib/librte_eal/bsdapp/eal/Makefile

> > index a15b762..cce99f7 100644

> > --- a/lib/librte_eal/bsdapp/eal/Makefile

> > +++ b/lib/librte_eal/bsdapp/eal/Makefile

> > @@ -78,6 +78,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=

> eal_common_cpuflags.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_string_fns.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_hexdump.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_devargs.c

> > +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_bus.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c

> > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map

> b/lib/librte_eal/bsdapp/eal/rte_eal_version.map

> > index 2f81f7c..23fc1c1 100644

> > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map

> > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map

> > @@ -174,3 +174,18 @@ DPDK_16.11 {

> >         rte_eal_vdrv_unregister;

> >

> >  } DPDK_16.07;

> > +

> > +DPDK_17.02 {

> > +       global:

> > +

> > +       rte_bus_list;

> > +       rte_eal_bus_add_device;

> > +       rte_eal_bus_add_driver;

> > +       rte_eal_get_bus;

> > +       rte_eal_bus_dump;

> > +       rte_eal_bus_register;

> > +       rte_eal_bus_remove_device;

> > +       rte_eal_bus_remove_driver;

> > +       rte_eal_bus_unregister;

> > +

> > +} DPDK_16.11;

> > diff --git a/lib/librte_eal/common/Makefile

> b/lib/librte_eal/common/Makefile

> > index a92c984..0c39414 100644

> > --- a/lib/librte_eal/common/Makefile

> > +++ b/lib/librte_eal/common/Makefile

> > @@ -38,7 +38,7 @@ INC += rte_per_lcore.h rte_random.h

> >  INC += rte_tailq.h rte_interrupts.h rte_alarm.h

> >  INC += rte_string_fns.h rte_version.h

> >  INC += rte_eal_memconfig.h rte_malloc_heap.h

> > -INC += rte_hexdump.h rte_devargs.h rte_dev.h rte_vdev.h

> > +INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_vdev.h

> >  INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h

> >  INC += rte_malloc.h rte_keepalive.h rte_time.h

> >

> > diff --git a/lib/librte_eal/common/eal_common_bus.c

> b/lib/librte_eal/common/eal_common_bus.c

> > new file mode 100644

> > index 0000000..612f64e

> > --- /dev/null

> > +++ b/lib/librte_eal/common/eal_common_bus.c

> > @@ -0,0 +1,192 @@

> > +/*-

> > + *   BSD LICENSE

> > + *

> > + *   Copyright(c) 2016 NXP

> > + *   All rights reserved.

> > + *

> > + *   Redistribution and use in source and binary forms, with or without

> > + *   modification, are permitted provided that the following conditions

> > + *   are met:

> > + *

> > + *     * Redistributions of source code must retain the above copyright

> > + *       notice, this list of conditions and the following disclaimer.

> > + *     * Redistributions in binary form must reproduce the above copyright

> > + *       notice, this list of conditions and the following disclaimer in

> > + *       the documentation and/or other materials provided with the

> > + *       distribution.

> > + *     * Neither the name of NXP nor the names of its

> > + *       contributors may be used to endorse or promote products derived

> > + *       from this software without specific prior written permission.

> > + *

> > + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

> > + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

> > + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

> > + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

> > + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

> > + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

> > + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

> > + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

> > + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

> > + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

> > + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

> > + */

> > +

> > +#include <stdio.h>

> > +#include <string.h>

> > +#include <inttypes.h>

> > +#include <sys/queue.h>

> > +

> > +#include <rte_bus.h>

> > +#include <rte_devargs.h>

> > +#include <rte_debug.h>

> > +

> > +#include "eal_private.h"

> > +

> > +struct rte_bus_list rte_bus_list =

> > +       TAILQ_HEAD_INITIALIZER(rte_bus_list);

> > +

> > +/** @internal

> > + * Add a device to a bus.

> > + */

> > +void

> > +rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev)

> > +{

> > +       RTE_VERIFY(bus);

> > +       RTE_VERIFY(dev);

> > +

> > +       TAILQ_INSERT_TAIL(&bus->device_list, dev, next);

> > +       dev->bus = bus;

> > +}

> > +

> > +/** @internal

> > + * Remove a device from its bus.

> > + */

> > +void

> > +rte_eal_bus_remove_device(struct rte_device *dev)

> > +{

> > +       struct rte_bus *bus;

> > +

> > +       RTE_VERIFY(dev);

> > +       RTE_VERIFY(dev->bus);

> > +

> > +       bus = dev->bus;

> > +       TAILQ_REMOVE(&bus->device_list, dev, next);

> > +       dev->bus = NULL;

> > +}

> > +

> > +/** @internal

> > + * Associate a driver with a bus.

> > + */

> > +void

> > +rte_eal_bus_add_driver(struct rte_bus *bus, struct rte_driver *drv)

> > +{

> > +       RTE_VERIFY(bus);

> > +       RTE_VERIFY(drv);

> > +

> > +       TAILQ_INSERT_TAIL(&bus->driver_list, drv, next);

> > +       drv->bus = bus;

> > +}

> > +

> > +/** @internal

> > + * Disassociate a driver from bus.

> > + */

> > +void

> > +rte_eal_bus_remove_driver(struct rte_driver *drv)

> > +{

> > +       struct rte_bus *bus;

> > +

> > +       RTE_VERIFY(drv);

> > +       RTE_VERIFY(drv->bus);

> > +

> > +       bus = drv->bus;

> > +       TAILQ_REMOVE(&bus->driver_list, drv, next);

> > +       drv->bus = NULL;

> > +}

> > +

> > +/**

> > + * Get the bus handle using its name

> > + */

> > +struct rte_bus *

> > +rte_eal_get_bus(const char *bus_name)

> > +{

> > +       struct rte_bus *bus;

> > +

> > +       RTE_VERIFY(bus_name);

> > +

> > +       TAILQ_FOREACH(bus, &rte_bus_list, next) {

> > +               RTE_VERIFY(bus->name);

> > +

> > +               if (!strcmp(bus_name, bus->name)) {

> > +                       RTE_LOG(DEBUG, EAL, "Returning Bus object %p\n",

> bus);

> > +                       return bus;

> > +               }

> > +       }

> > +

> > +       /* Unable to find bus requested */

> > +       return NULL;

> > +}

> > +

> > +/* register a bus */

> > +void

> > +rte_eal_bus_register(struct rte_bus *bus)

> > +{

> > +       RTE_VERIFY(bus);

> > +       RTE_VERIFY(bus->name && strlen(bus->name));

> > +

> > +       /* Initialize the driver and device list associated with the bus */

> > +       TAILQ_INIT(&(bus->driver_list));

> > +       TAILQ_INIT(&(bus->device_list));

> > +

> > +       TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);

> > +       RTE_LOG(INFO, EAL, "Registered [%s] bus.\n", bus->name);

> > +}

> > +

> > +/* unregister a bus */

> > +void

> > +rte_eal_bus_unregister(struct rte_bus *bus)

> > +{

> > +       /* All devices and drivers associated with the bus should have been

> > +        * 'device->uninit' and 'driver->remove()' already.

> > +        */

> > +       RTE_VERIFY(TAILQ_EMPTY(&(bus->driver_list)));

> > +       RTE_VERIFY(TAILQ_EMPTY(&(bus->device_list)));

> > +

> > +       /* TODO: For each device, call its rte_device->driver->remove()

> > +        * and rte_eal_bus_remove_driver()

> > +        */

> > +

> > +       TAILQ_REMOVE(&rte_bus_list, bus, next);

> > +       RTE_LOG(INFO, EAL, "Unregistered [%s] bus.\n", bus->name);

> > +}

> > +

> > +/* dump one bus info */

> > +static int

> > +bus_dump_one(FILE *f, struct rte_bus *bus)

> > +{

> > +       int ret;

> > +

> > +       /* For now, dump only the bus name */

> > +       ret = fprintf(f, " %s\n", bus->name);

> > +

> > +       /* Error in case of inability in writing to stream */

> > +       if (ret < 0)

> > +               return ret;

> > +

> > +       return 0;

> > +}

> > +

> > +void

> > +rte_eal_bus_dump(FILE *f)

> > +{

> > +       int ret;

> > +       struct rte_bus *bus;

> > +

> > +       TAILQ_FOREACH(bus, &rte_bus_list, next) {

> > +               ret = bus_dump_one(f, bus);

> > +               if (ret) {

> > +                       RTE_LOG(ERR, EAL, "Unable to write to stream

> (%d)\n",

> > +                               ret);

> > +                       break;

> > +               }

> > +       }

> > +}

> > diff --git a/lib/librte_eal/common/include/rte_bus.h

> b/lib/librte_eal/common/include/rte_bus.h

> > new file mode 100644

> > index 0000000..f0297a9

> > --- /dev/null

> > +++ b/lib/librte_eal/common/include/rte_bus.h

> > @@ -0,0 +1,174 @@

> > +/*-

> > + *   BSD LICENSE

> > + *

> > + *   Copyright(c) 2016 NXP

> > + *   All rights reserved.

> > + *

> > + *   Redistribution and use in source and binary forms, with or without

> > + *   modification, are permitted provided that the following conditions

> > + *   are met:

> > + *

> > + *     * Redistributions of source code must retain the above copyright

> > + *       notice, this list of conditions and the following disclaimer.

> > + *     * Redistributions in binary form must reproduce the above copyright

> > + *       notice, this list of conditions and the following disclaimer in

> > + *       the documentation and/or other materials provided with the

> > + *       distribution.

> > + *     * Neither the name of NXP nor the names of its

> > + *       contributors may be used to endorse or promote products derived

> > + *       from this software without specific prior written permission.

> > + *

> > + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

> > + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

> > + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

> > + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

> > + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

> > + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

> > + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

> > + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

> > + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

> > + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

> > + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

> > + */

> > +

> > +#ifndef _RTE_BUS_H_

> > +#define _RTE_BUS_H_

> > +

> > +/**

> > + * @file

> > + *

> > + * RTE PMD Bus Abstraction interfaces

> > + *

> > + * This file exposes APIs and Interfaces for Bus Abstraction over the

> devices

> > + * drivers in EAL.

> > + */

> > +

> > +#ifdef __cplusplus

> > +extern "C" {

> > +#endif

> > +

> > +#include <stdio.h>

> > +#include <sys/queue.h>

> > +

> > +#include <rte_log.h>

> > +#include <rte_dev.h>

> > +

> > +/** Double linked list of buses */

> > +TAILQ_HEAD(rte_bus_list, rte_bus);

> > +

> > +/* Global Bus list */

> > +extern struct rte_bus_list rte_bus_list;

> > +

> > +struct rte_bus {

> > +       TAILQ_ENTRY(rte_bus) next;   /**< Next bus object in linked list */

> > +       struct rte_driver_list driver_list;

> > +                                    /**< List of all drivers on bus */

> > +       struct rte_device_list device_list;

> > +                                    /**< List of all devices on bus */

> > +       const char *name;            /**< Name of the bus */

> > +};

> > +

> > +/** @internal

> > + * Add a device to a bus.

> > + *

> > + * @param bus

> > + *     Bus on which device is to be added

> > + * @param dev

> > + *     Device handle

> > + * @return

> > + *     None

> > + */

> > +void

> > +rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev);

> > +

> > +/** @internal

> > + * Remove a device from its bus.

> > + *

> > + * @param dev

> > + *     Device handle to remove

> > + * @return

> > + *     None

> > + */

> > +void

> > +rte_eal_bus_remove_device(struct rte_device *dev);

> > +

> > +/** @internal

> > + * Associate a driver with a bus.

> > + *

> > + * @param bus

> > + *     Bus on which driver is to be added

> > + * @param dev

> > + *     Driver handle

> > + * @return

> > + *     None

> > + */

> > +void

> > +rte_eal_bus_add_driver(struct rte_bus *bus, struct rte_driver *drv);

> > +

> > +/** @internal

> > + * Disassociate a driver from its bus.

> > + *

> > + * @param dev

> > + *     Driver handle to remove

> > + * @return

> > + *     None

> > + */

> > +void

> > +rte_eal_bus_remove_driver(struct rte_driver *drv);

> > +

> > +/**

> > + * Register a Bus handler.

> > + *

> > + * @param driver

> > + *   A pointer to a rte_bus structure describing the bus

> > + *   to be registered.

> > + */

> > +void rte_eal_bus_register(struct rte_bus *bus);

> > +

> > +/**

> > + * Unregister a Bus handler.

> > + *

> > + * @param driver

> > + *   A pointer to a rte_bus structure describing the bus

> > + *   to be unregistered.

> > + */

> > +void rte_eal_bus_unregister(struct rte_bus *bus);

> > +

> > +/**

> > + * Obtain handle for bus given its name.

> > + *

> > + * @param bus_name

> > + *     Name of the bus handle to search

> > + * @return

> > + *     Pointer to Bus object if name matches any registered bus object

> > + *     NULL, if no matching bus found

> > + */

> > +struct rte_bus *rte_eal_get_bus(const char *bus_name);

> > +

> > +/**

> > + * Dump information of all the buses registered with EAL.

> > + *

> > + * @param f

> > + *     A valid and open output stream handle

> > + *

> > + * @return

> > + *      0 in case of success

> > + *     !0 in case there is error in opening the output stream

> > + */

> > +void rte_eal_bus_dump(FILE *f);

> > +

> > +/** Helper for Bus registration. The constructor has higher priority than

> > + * PMD constructors

> > + */

> > +#define RTE_REGISTER_BUS(nm, bus) \

> > +static void __attribute__((constructor(101), used)) businitfn_ ##nm(void)

> \

> > +{\

> > +       (bus).name = RTE_STR(nm);\

> > +       rte_eal_bus_register(&bus); \

> > +}

> > +

> > +#ifdef __cplusplus

> > +}

> > +#endif

> > +

> > +#endif /* _RTE_BUS_H */

> > diff --git a/lib/librte_eal/common/include/rte_dev.h

> b/lib/librte_eal/common/include/rte_dev.h

> > index 8840380..4004f9a 100644

> > --- a/lib/librte_eal/common/include/rte_dev.h

> > +++ b/lib/librte_eal/common/include/rte_dev.h

> > @@ -122,6 +122,7 @@ struct rte_driver;

> >   */

> >  struct rte_device {

> >         TAILQ_ENTRY(rte_device) next; /**< Next device */

> > +       struct rte_bus *bus;          /**< Device connected to this bus */

> 

> Is there a reason why this isn't const?


No reason. Miss from my end. I will fix this.
(I also took hint from Stephen's recent patches) 

> 

> 

> >         struct rte_driver *driver;    /**< Associated driver */

> >         int numa_node;                /**< NUMA node connection */

> >         struct rte_devargs *devargs;  /**< Device user arguments */

> > @@ -148,6 +149,7 @@ void rte_eal_device_remove(struct rte_device *dev);

> >   */

> >  struct rte_driver {

> >         TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */

> > +       struct rte_bus *bus;           /**< Bus serviced by this driver */

> 

> Same thing here.


I will send out v4 with this. Thanks for comments.

> 

> >         const char *name;                   /**< Driver name. */

> >         const char *alias;              /**< Driver alias. */

> >  };

> > diff --git a/lib/librte_eal/linuxapp/eal/Makefile

> b/lib/librte_eal/linuxapp/eal/Makefile

> > index 4e206f0..aa874a5 100644

> > --- a/lib/librte_eal/linuxapp/eal/Makefile

> > +++ b/lib/librte_eal/linuxapp/eal/Makefile

> > @@ -87,6 +87,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=

> eal_common_cpuflags.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_string_fns.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_hexdump.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c

> > +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_bus.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c

> > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map

> b/lib/librte_eal/linuxapp/eal/rte_eal_version.map

> > index 83721ba..c873a7f 100644

> > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map

> > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map

> > @@ -178,3 +178,18 @@ DPDK_16.11 {

> >         rte_eal_vdrv_unregister;

> >

> >  } DPDK_16.07;

> > +

> > +DPDK_17.02 {

> > +       global:

> > +

> > +       rte_bus_list;

> > +       rte_eal_bus_add_device;

> > +       rte_eal_bus_add_driver;

> > +       rte_eal_get_bus;

> > +       rte_eal_bus_dump;

> > +       rte_eal_bus_register;

> > +       rte_eal_bus_remove_device;

> > +       rte_eal_bus_remove_driver;

> > +       rte_eal_bus_unregister;

> > +

> > +} DPDK_16.11;

> > --

> > 2.7.4

> >
  
Stephen Hemminger Dec. 20, 2016, 5:11 p.m. UTC | #4
On Tue, 20 Dec 2016 14:17:14 +0100
Jan Blunck <jblunck@infradead.org> wrote:

> On Fri, Dec 16, 2016 at 2:10 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> > This patch introduces the rte_bus abstraction for devices and drivers in
> > EAL framework. The model is:
> >  - One or more buses are connected to a CPU (or core)
> >  - One or more devices are conneted to a Bus
> >  - Drivers are running instances which manage one or more devices
> >  - Bus is responsible for identifying devices (and interrupt propogation)
> >  - Driver is responsible for initializing the device
> >
> > This patch adds a 'rte_bus' class which rte_driver and rte_device refer.
> > This way, each device (rte_xxx_device) would have reference to the bus
> > it is based on. As well as, each driver (rte_xxx_driver) would have link
> > to the bus and devices on it for servicing.
> >
> >                                   __ rte_bus_list
> >                                  /
> >                      +----------'---+
> >                      |rte_bus       |
> >                      | driver_list------> List of rte_bus specific
> >                      | device_list----    devices
> >                      |              | `-> List of rte_bus associated
> >                      |              |     drivers
> >                      +--|------|----+
> >               _________/        \_________
> >     +--------/----+                     +-\---------------+
> >     |rte_device   |                     |rte_driver       |
> >     | rte_bus     |                     | rte_bus         |
> >     | rte_driver  |                     | ...             |
> >     | ...         |                     +---------...-----+
> >     |             |                               |||
> >     +---||--------+                               |||
> >         ||                                        |||
> >         | \                                        \\\
> >         |  \_____________                           \\\
> >         |                \                          |||
> >  +------|---------+ +----|----------+               |||
> >  |rte_pci_device  | |rte_xxx_device |               |||
> >  | ....           | | ....          |               |||
> >  +----------------+ +---------------+              / | \
> >                                                   /  |  \
> >                             _____________________/  /    \
> >                            /                    ___/      \
> >             +-------------'--+    +------------'---+    +--'------------+
> >             |rte_pci_driver  |    |rte_vdev_driver |    |rte_xxx_driver |
> >             | ....           |    | ....           |    | ....          |
> >             +----------------+    +----------------+    +---------------+
> >
> > This patch only enables the bus references on rte_driver and rte_driver.
> > EAL wide global device and driver list continue to exist until an instance
> > of bus is added in subsequent patches.
> >
> > This patch also introduces RTE_REGISTER_BUS macro on the lines of
> > RTE_PMD_REGISTER_XXX. Key difference is that the constructor priority has
> > been explicitly set to 101 so as to execute bus registration before PMD.
> >
> > Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> >

Ok, but let's keep this as bus type not bus. It gets really hard and complex
to enumerate all layers of PCI bus and bridges.
  
Shreyansh Jain Dec. 21, 2016, 7:11 a.m. UTC | #5
On Tuesday 20 December 2016 10:41 PM, Stephen Hemminger wrote:
> On Tue, 20 Dec 2016 14:17:14 +0100
> Jan Blunck <jblunck@infradead.org> wrote:
>
>> On Fri, Dec 16, 2016 at 2:10 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>>> This patch introduces the rte_bus abstraction for devices and drivers in
>>> EAL framework. The model is:
>>>  - One or more buses are connected to a CPU (or core)
>>>  - One or more devices are conneted to a Bus
>>>  - Drivers are running instances which manage one or more devices
>>>  - Bus is responsible for identifying devices (and interrupt propogation)
>>>  - Driver is responsible for initializing the device
>>>
>>> This patch adds a 'rte_bus' class which rte_driver and rte_device refer.
>>> This way, each device (rte_xxx_device) would have reference to the bus
>>> it is based on. As well as, each driver (rte_xxx_driver) would have link
>>> to the bus and devices on it for servicing.
>>>
>>>                                   __ rte_bus_list
>>>                                  /
>>>                      +----------'---+
>>>                      |rte_bus       |
>>>                      | driver_list------> List of rte_bus specific
>>>                      | device_list----    devices
>>>                      |              | `-> List of rte_bus associated
>>>                      |              |     drivers
>>>                      +--|------|----+
>>>               _________/        \_________
>>>     +--------/----+                     +-\---------------+
>>>     |rte_device   |                     |rte_driver       |
>>>     | rte_bus     |                     | rte_bus         |
>>>     | rte_driver  |                     | ...             |
>>>     | ...         |                     +---------...-----+
>>>     |             |                               |||
>>>     +---||--------+                               |||
>>>         ||                                        |||
>>>         | \                                        \\\
>>>         |  \_____________                           \\\
>>>         |                \                          |||
>>>  +------|---------+ +----|----------+               |||
>>>  |rte_pci_device  | |rte_xxx_device |               |||
>>>  | ....           | | ....          |               |||
>>>  +----------------+ +---------------+              / | \
>>>                                                   /  |  \
>>>                             _____________________/  /    \
>>>                            /                    ___/      \
>>>             +-------------'--+    +------------'---+    +--'------------+
>>>             |rte_pci_driver  |    |rte_vdev_driver |    |rte_xxx_driver |
>>>             | ....           |    | ....           |    | ....          |
>>>             +----------------+    +----------------+    +---------------+
>>>
>>> This patch only enables the bus references on rte_driver and rte_driver.
>>> EAL wide global device and driver list continue to exist until an instance
>>> of bus is added in subsequent patches.
>>>
>>> This patch also introduces RTE_REGISTER_BUS macro on the lines of
>>> RTE_PMD_REGISTER_XXX. Key difference is that the constructor priority has
>>> been explicitly set to 101 so as to execute bus registration before PMD.
>>>
>>> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>>>
>
> Ok, but let's keep this as bus type not bus. It gets really hard and complex
> to enumerate all layers of PCI bus and bridges.
>

Sorry, I couldn't understand your comment. You mean it should be 
rte_bus_type rather than rte_bus? Or, you mean rather than creating a 
rte_bus, we should rather have a type embedded in rte_device/driver?

(Though this is 'to' Jan, the context is hinting at my mail)
  
Jan Blunck Dec. 21, 2016, 3:38 p.m. UTC | #6
On Tue, Dec 20, 2016 at 6:11 PM, Stephen Hemminger
<stephen@networkplumber.org> wrote:
> On Tue, 20 Dec 2016 14:17:14 +0100
> Jan Blunck <jblunck@infradead.org> wrote:
>
>> On Fri, Dec 16, 2016 at 2:10 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>> > This patch introduces the rte_bus abstraction for devices and drivers in
>> > EAL framework. The model is:
>> >  - One or more buses are connected to a CPU (or core)
>> >  - One or more devices are conneted to a Bus
>> >  - Drivers are running instances which manage one or more devices
>> >  - Bus is responsible for identifying devices (and interrupt propogation)
>> >  - Driver is responsible for initializing the device
>> >
>> > This patch adds a 'rte_bus' class which rte_driver and rte_device refer.
>> > This way, each device (rte_xxx_device) would have reference to the bus
>> > it is based on. As well as, each driver (rte_xxx_driver) would have link
>> > to the bus and devices on it for servicing.
>> >
>> >                                   __ rte_bus_list
>> >                                  /
>> >                      +----------'---+
>> >                      |rte_bus       |
>> >                      | driver_list------> List of rte_bus specific
>> >                      | device_list----    devices
>> >                      |              | `-> List of rte_bus associated
>> >                      |              |     drivers
>> >                      +--|------|----+
>> >               _________/        \_________
>> >     +--------/----+                     +-\---------------+
>> >     |rte_device   |                     |rte_driver       |
>> >     | rte_bus     |                     | rte_bus         |
>> >     | rte_driver  |                     | ...             |
>> >     | ...         |                     +---------...-----+
>> >     |             |                               |||
>> >     +---||--------+                               |||
>> >         ||                                        |||
>> >         | \                                        \\\
>> >         |  \_____________                           \\\
>> >         |                \                          |||
>> >  +------|---------+ +----|----------+               |||
>> >  |rte_pci_device  | |rte_xxx_device |               |||
>> >  | ....           | | ....          |               |||
>> >  +----------------+ +---------------+              / | \
>> >                                                   /  |  \
>> >                             _____________________/  /    \
>> >                            /                    ___/      \
>> >             +-------------'--+    +------------'---+    +--'------------+
>> >             |rte_pci_driver  |    |rte_vdev_driver |    |rte_xxx_driver |
>> >             | ....           |    | ....           |    | ....          |
>> >             +----------------+    +----------------+    +---------------+
>> >
>> > This patch only enables the bus references on rte_driver and rte_driver.
>> > EAL wide global device and driver list continue to exist until an instance
>> > of bus is added in subsequent patches.
>> >
>> > This patch also introduces RTE_REGISTER_BUS macro on the lines of
>> > RTE_PMD_REGISTER_XXX. Key difference is that the constructor priority has
>> > been explicitly set to 101 so as to execute bus registration before PMD.
>> >
>> > Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>> >
>
> Ok, but let's keep this as bus type not bus. It gets really hard and complex
> to enumerate all layers of PCI bus and bridges.

As far as I understand it this isn't the intention to replicate the
hierarchy of buses we have in the kernel. The PCI bus in this case
becomes a list of PCI devices.
  
Stephen Hemminger Dec. 21, 2016, 11:33 p.m. UTC | #7
On Wed, 21 Dec 2016 16:38:42 +0100
Jan Blunck <jblunck@infradead.org> wrote:

> On Tue, Dec 20, 2016 at 6:11 PM, Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> > On Tue, 20 Dec 2016 14:17:14 +0100
> > Jan Blunck <jblunck@infradead.org> wrote:
> >  
> >> On Fri, Dec 16, 2016 at 2:10 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:  
> >> > This patch introduces the rte_bus abstraction for devices and drivers in
> >> > EAL framework. The model is:
> >> >  - One or more buses are connected to a CPU (or core)
> >> >  - One or more devices are conneted to a Bus
> >> >  - Drivers are running instances which manage one or more devices
> >> >  - Bus is responsible for identifying devices (and interrupt propogation)
> >> >  - Driver is responsible for initializing the device
> >> >
> >> > This patch adds a 'rte_bus' class which rte_driver and rte_device refer.
> >> > This way, each device (rte_xxx_device) would have reference to the bus
> >> > it is based on. As well as, each driver (rte_xxx_driver) would have link
> >> > to the bus and devices on it for servicing.
> >> >
> >> >                                   __ rte_bus_list
> >> >                                  /
> >> >                      +----------'---+
> >> >                      |rte_bus       |
> >> >                      | driver_list------> List of rte_bus specific
> >> >                      | device_list----    devices
> >> >                      |              | `-> List of rte_bus associated
> >> >                      |              |     drivers
> >> >                      +--|------|----+
> >> >               _________/        \_________
> >> >     +--------/----+                     +-\---------------+
> >> >     |rte_device   |                     |rte_driver       |
> >> >     | rte_bus     |                     | rte_bus         |
> >> >     | rte_driver  |                     | ...             |
> >> >     | ...         |                     +---------...-----+
> >> >     |             |                               |||
> >> >     +---||--------+                               |||
> >> >         ||                                        |||
> >> >         | \                                        \\\
> >> >         |  \_____________                           \\\
> >> >         |                \                          |||
> >> >  +------|---------+ +----|----------+               |||
> >> >  |rte_pci_device  | |rte_xxx_device |               |||
> >> >  | ....           | | ....          |               |||
> >> >  +----------------+ +---------------+              / | \
> >> >                                                   /  |  \
> >> >                             _____________________/  /    \
> >> >                            /                    ___/      \
> >> >             +-------------'--+    +------------'---+    +--'------------+
> >> >             |rte_pci_driver  |    |rte_vdev_driver |    |rte_xxx_driver |
> >> >             | ....           |    | ....           |    | ....          |
> >> >             +----------------+    +----------------+    +---------------+
> >> >
> >> > This patch only enables the bus references on rte_driver and rte_driver.
> >> > EAL wide global device and driver list continue to exist until an instance
> >> > of bus is added in subsequent patches.
> >> >
> >> > This patch also introduces RTE_REGISTER_BUS macro on the lines of
> >> > RTE_PMD_REGISTER_XXX. Key difference is that the constructor priority has
> >> > been explicitly set to 101 so as to execute bus registration before PMD.
> >> >
> >> > Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> >> >  
> >
> > Ok, but let's keep this as bus type not bus. It gets really hard and complex
> > to enumerate all layers of PCI bus and bridges.  
> 
> As far as I understand it this isn't the intention to replicate the
> hierarchy of buses we have in the kernel. The PCI bus in this case
> becomes a list of PCI devices.

One of the motivations seems to be "lets be able to handle lots of devices",
but the current model with an array of ports is not going to scale well for that.

It is time to make rte_eth_devices into rb-tree and get rid of MAX_PORTS config
option.
  
Shreyansh Jain Dec. 22, 2016, 5:12 a.m. UTC | #8
On Thursday 22 December 2016 05:03 AM, Stephen Hemminger wrote:
> On Wed, 21 Dec 2016 16:38:42 +0100
> Jan Blunck <jblunck@infradead.org> wrote:
>
>> On Tue, Dec 20, 2016 at 6:11 PM, Stephen Hemminger
>> <stephen@networkplumber.org> wrote:
>>> On Tue, 20 Dec 2016 14:17:14 +0100
>>> Jan Blunck <jblunck@infradead.org> wrote:
>>>
>>>> On Fri, Dec 16, 2016 at 2:10 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>>>>> This patch introduces the rte_bus abstraction for devices and drivers in
>>>>> EAL framework. The model is:
>>>>>  - One or more buses are connected to a CPU (or core)
>>>>>  - One or more devices are conneted to a Bus
>>>>>  - Drivers are running instances which manage one or more devices
>>>>>  - Bus is responsible for identifying devices (and interrupt propogation)
>>>>>  - Driver is responsible for initializing the device
>>>>>
>>>>> This patch adds a 'rte_bus' class which rte_driver and rte_device refer.
>>>>> This way, each device (rte_xxx_device) would have reference to the bus
>>>>> it is based on. As well as, each driver (rte_xxx_driver) would have link
>>>>> to the bus and devices on it for servicing.
>>>>>
>>>>>                                   __ rte_bus_list
>>>>>                                  /
>>>>>                      +----------'---+
>>>>>                      |rte_bus       |
>>>>>                      | driver_list------> List of rte_bus specific
>>>>>                      | device_list----    devices
>>>>>                      |              | `-> List of rte_bus associated
>>>>>                      |              |     drivers
>>>>>                      +--|------|----+
>>>>>               _________/        \_________
>>>>>     +--------/----+                     +-\---------------+
>>>>>     |rte_device   |                     |rte_driver       |
>>>>>     | rte_bus     |                     | rte_bus         |
>>>>>     | rte_driver  |                     | ...             |
>>>>>     | ...         |                     +---------...-----+
>>>>>     |             |                               |||
>>>>>     +---||--------+                               |||
>>>>>         ||                                        |||
>>>>>         | \                                        \\\
>>>>>         |  \_____________                           \\\
>>>>>         |                \                          |||
>>>>>  +------|---------+ +----|----------+               |||
>>>>>  |rte_pci_device  | |rte_xxx_device |               |||
>>>>>  | ....           | | ....          |               |||
>>>>>  +----------------+ +---------------+              / | \
>>>>>                                                   /  |  \
>>>>>                             _____________________/  /    \
>>>>>                            /                    ___/      \
>>>>>             +-------------'--+    +------------'---+    +--'------------+
>>>>>             |rte_pci_driver  |    |rte_vdev_driver |    |rte_xxx_driver |
>>>>>             | ....           |    | ....           |    | ....          |
>>>>>             +----------------+    +----------------+    +---------------+
>>>>>
>>>>> This patch only enables the bus references on rte_driver and rte_driver.
>>>>> EAL wide global device and driver list continue to exist until an instance
>>>>> of bus is added in subsequent patches.
>>>>>
>>>>> This patch also introduces RTE_REGISTER_BUS macro on the lines of
>>>>> RTE_PMD_REGISTER_XXX. Key difference is that the constructor priority has
>>>>> been explicitly set to 101 so as to execute bus registration before PMD.
>>>>>
>>>>> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>>>>>
>>>
>>> Ok, but let's keep this as bus type not bus. It gets really hard and complex
>>> to enumerate all layers of PCI bus and bridges.
>>
>> As far as I understand it this isn't the intention to replicate the
>> hierarchy of buses we have in the kernel. The PCI bus in this case
>> becomes a list of PCI devices.
>
> One of the motivations seems to be "lets be able to handle lots of devices",
> but the current model with an array of ports is not going to scale well for that.
>
> It is time to make rte_eth_devices into rb-tree and get rid of MAX_PORTS config
> option.
>

That is a nice idea. Probably once we get the EAL compatible for 'lots 
of devices', this would be next good change.

-
Shreyansh
  
Shreyansh Jain Dec. 22, 2016, 5:52 a.m. UTC | #9
On Thursday 22 December 2016 10:42 AM, Shreyansh Jain wrote:
> On Thursday 22 December 2016 05:03 AM, Stephen Hemminger wrote:
>> On Wed, 21 Dec 2016 16:38:42 +0100
>> Jan Blunck <jblunck@infradead.org> wrote:
>>
>>> On Tue, Dec 20, 2016 at 6:11 PM, Stephen Hemminger
>>> <stephen@networkplumber.org> wrote:
>>>> On Tue, 20 Dec 2016 14:17:14 +0100
>>>> Jan Blunck <jblunck@infradead.org> wrote:
>>>>
>>>>> On Fri, Dec 16, 2016 at 2:10 PM, Shreyansh Jain
>>>>> <shreyansh.jain@nxp.com> wrote:
>>>>>> This patch introduces the rte_bus abstraction for devices and
>>>>>> drivers in
>>>>>> EAL framework. The model is:
>>>>>>  - One or more buses are connected to a CPU (or core)
>>>>>>  - One or more devices are conneted to a Bus
>>>>>>  - Drivers are running instances which manage one or more devices
>>>>>>  - Bus is responsible for identifying devices (and interrupt
>>>>>> propogation)
>>>>>>  - Driver is responsible for initializing the device
>>>>>>
>>>>>> This patch adds a 'rte_bus' class which rte_driver and rte_device
>>>>>> refer.
>>>>>> This way, each device (rte_xxx_device) would have reference to the
>>>>>> bus
>>>>>> it is based on. As well as, each driver (rte_xxx_driver) would
>>>>>> have link
>>>>>> to the bus and devices on it for servicing.
>>>>>>
>>>>>>                                   __ rte_bus_list
>>>>>>                                  /
>>>>>>                      +----------'---+
>>>>>>                      |rte_bus       |
>>>>>>                      | driver_list------> List of rte_bus specific
>>>>>>                      | device_list----    devices
>>>>>>                      |              | `-> List of rte_bus associated
>>>>>>                      |              |     drivers
>>>>>>                      +--|------|----+
>>>>>>               _________/        \_________
>>>>>>     +--------/----+                     +-\---------------+
>>>>>>     |rte_device   |                     |rte_driver       |
>>>>>>     | rte_bus     |                     | rte_bus         |
>>>>>>     | rte_driver  |                     | ...             |
>>>>>>     | ...         |                     +---------...-----+
>>>>>>     |             |                               |||
>>>>>>     +---||--------+                               |||
>>>>>>         ||                                        |||
>>>>>>         | \                                        \\\
>>>>>>         |  \_____________                           \\\
>>>>>>         |                \                          |||
>>>>>>  +------|---------+ +----|----------+               |||
>>>>>>  |rte_pci_device  | |rte_xxx_device |               |||
>>>>>>  | ....           | | ....          |               |||
>>>>>>  +----------------+ +---------------+              / | \
>>>>>>                                                   /  |  \
>>>>>>                             _____________________/  /    \
>>>>>>                            /                    ___/      \
>>>>>>             +-------------'--+    +------------'---+
>>>>>> +--'------------+
>>>>>>             |rte_pci_driver  |    |rte_vdev_driver |
>>>>>> |rte_xxx_driver |
>>>>>>             | ....           |    | ....           |    |
>>>>>> ....          |
>>>>>>             +----------------+    +----------------+
>>>>>> +---------------+
>>>>>>
>>>>>> This patch only enables the bus references on rte_driver and
>>>>>> rte_driver.
>>>>>> EAL wide global device and driver list continue to exist until an
>>>>>> instance
>>>>>> of bus is added in subsequent patches.
>>>>>>
>>>>>> This patch also introduces RTE_REGISTER_BUS macro on the lines of
>>>>>> RTE_PMD_REGISTER_XXX. Key difference is that the constructor
>>>>>> priority has
>>>>>> been explicitly set to 101 so as to execute bus registration
>>>>>> before PMD.
>>>>>>
>>>>>> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>>>>>>
>>>>
>>>> Ok, but let's keep this as bus type not bus. It gets really hard and
>>>> complex
>>>> to enumerate all layers of PCI bus and bridges.
>>>
>>> As far as I understand it this isn't the intention to replicate the
>>> hierarchy of buses we have in the kernel. The PCI bus in this case
>>> becomes a list of PCI devices.
>>
>> One of the motivations seems to be "lets be able to handle lots of
>> devices",
>> but the current model with an array of ports is not going to scale
>> well for that.
>>
>> It is time to make rte_eth_devices into rb-tree and get rid of
>> MAX_PORTS config
>> option.
>>
>
> That is a nice idea. Probably once we get the EAL compatible for 'lots
> of devices', this would be next good change.

Just out of curiosity - I think only need here is to do away with 
'MAX_PORTS'. There is no need for a 'fast' lookup of ports as this part 
wouldn't be part of datapath. Am I wrong in assuming this?

>
> -
> Shreyansh
>
>
  
Shreyansh Jain Dec. 25, 2016, 5:39 p.m. UTC | #10
Hi Jan,

> -----Original Message-----

> From: jblunck@gmail.com [mailto:jblunck@gmail.com] On Behalf Of Jan Blunck

> Sent: Tuesday, December 20, 2016 6:47 PM

> To: Shreyansh Jain <shreyansh.jain@nxp.com>

> Cc: dev@dpdk.org; David Marchand <david.marchand@6wind.com>; Thomas Monjalon

> <thomas.monjalon@6wind.com>; Ferruh Yigit <ferruh.yigit@intel.com>;

> jianbo.liu@linaro.org

> Subject: Re: [dpdk-dev] [PATCH v3 02/12] eal/bus: introduce bus abstraction

> 


[...]

> > +#endif /* _RTE_BUS_H */

> > diff --git a/lib/librte_eal/common/include/rte_dev.h

> b/lib/librte_eal/common/include/rte_dev.h

> > index 8840380..4004f9a 100644

> > --- a/lib/librte_eal/common/include/rte_dev.h

> > +++ b/lib/librte_eal/common/include/rte_dev.h

> > @@ -122,6 +122,7 @@ struct rte_driver;

> >   */

> >  struct rte_device {

> >         TAILQ_ENTRY(rte_device) next; /**< Next device */

> > +       struct rte_bus *bus;          /**< Device connected to this bus */

> 

> Is there a reason why this isn't const?


Though initially I thought it should be fine, while creating v4 of Bus patches, I didn't change it.

There are cases where the rte_device is used to access the bus and modify the device list within (attaching/detaching the device). Same is the case for rte_driver. Making bus object read-only, prevents that change.

So, I will skip this in v4. If need be, I will revisit in v5 (if any).

> 

> 

> >         struct rte_driver *driver;    /**< Associated driver */

> >         int numa_node;                /**< NUMA node connection */

> >         struct rte_devargs *devargs;  /**< Device user arguments */

> > @@ -148,6 +149,7 @@ void rte_eal_device_remove(struct rte_device *dev);

> >   */

> >  struct rte_driver {

> >         TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */

> > +       struct rte_bus *bus;           /**< Bus serviced by this driver */

> 

> Same thing here.

> 

> >         const char *name;                   /**< Driver name. */

> >         const char *alias;              /**< Driver alias. */

> >  };

> > diff --git a/lib/librte_eal/linuxapp/eal/Makefile

> b/lib/librte_eal/linuxapp/eal/Makefile

> > index 4e206f0..aa874a5 100644

> > --- a/lib/librte_eal/linuxapp/eal/Makefile

> > +++ b/lib/librte_eal/linuxapp/eal/Makefile

> > @@ -87,6 +87,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=

> eal_common_cpuflags.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_string_fns.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_hexdump.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c

> > +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_bus.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c

> >  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c

> > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map

> b/lib/librte_eal/linuxapp/eal/rte_eal_version.map

> > index 83721ba..c873a7f 100644

> > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map

> > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map

> > @@ -178,3 +178,18 @@ DPDK_16.11 {

> >         rte_eal_vdrv_unregister;

> >

> >  } DPDK_16.07;

> > +

> > +DPDK_17.02 {

> > +       global:

> > +

> > +       rte_bus_list;

> > +       rte_eal_bus_add_device;

> > +       rte_eal_bus_add_driver;

> > +       rte_eal_get_bus;

> > +       rte_eal_bus_dump;

> > +       rte_eal_bus_register;

> > +       rte_eal_bus_remove_device;

> > +       rte_eal_bus_remove_driver;

> > +       rte_eal_bus_unregister;

> > +

> > +} DPDK_16.11;

> > --

> > 2.7.4

> >


-
Shreyansh
  

Patch

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index a15b762..cce99f7 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -78,6 +78,7 @@  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_cpuflags.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_string_fns.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_hexdump.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_devargs.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_bus.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 2f81f7c..23fc1c1 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -174,3 +174,18 @@  DPDK_16.11 {
 	rte_eal_vdrv_unregister;
 
 } DPDK_16.07;
+
+DPDK_17.02 {
+	global:
+
+	rte_bus_list;
+	rte_eal_bus_add_device;
+	rte_eal_bus_add_driver;
+	rte_eal_get_bus;
+	rte_eal_bus_dump;
+	rte_eal_bus_register;
+	rte_eal_bus_remove_device;
+	rte_eal_bus_remove_driver;
+	rte_eal_bus_unregister;
+
+} DPDK_16.11;
diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
index a92c984..0c39414 100644
--- a/lib/librte_eal/common/Makefile
+++ b/lib/librte_eal/common/Makefile
@@ -38,7 +38,7 @@  INC += rte_per_lcore.h rte_random.h
 INC += rte_tailq.h rte_interrupts.h rte_alarm.h
 INC += rte_string_fns.h rte_version.h
 INC += rte_eal_memconfig.h rte_malloc_heap.h
-INC += rte_hexdump.h rte_devargs.h rte_dev.h rte_vdev.h
+INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_vdev.h
 INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
 INC += rte_malloc.h rte_keepalive.h rte_time.h
 
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
new file mode 100644
index 0000000..612f64e
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -0,0 +1,192 @@ 
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 NXP
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of NXP nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+#include <sys/queue.h>
+
+#include <rte_bus.h>
+#include <rte_devargs.h>
+#include <rte_debug.h>
+
+#include "eal_private.h"
+
+struct rte_bus_list rte_bus_list =
+	TAILQ_HEAD_INITIALIZER(rte_bus_list);
+
+/** @internal
+ * Add a device to a bus.
+ */
+void
+rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev)
+{
+	RTE_VERIFY(bus);
+	RTE_VERIFY(dev);
+
+	TAILQ_INSERT_TAIL(&bus->device_list, dev, next);
+	dev->bus = bus;
+}
+
+/** @internal
+ * Remove a device from its bus.
+ */
+void
+rte_eal_bus_remove_device(struct rte_device *dev)
+{
+	struct rte_bus *bus;
+
+	RTE_VERIFY(dev);
+	RTE_VERIFY(dev->bus);
+
+	bus = dev->bus;
+	TAILQ_REMOVE(&bus->device_list, dev, next);
+	dev->bus = NULL;
+}
+
+/** @internal
+ * Associate a driver with a bus.
+ */
+void
+rte_eal_bus_add_driver(struct rte_bus *bus, struct rte_driver *drv)
+{
+	RTE_VERIFY(bus);
+	RTE_VERIFY(drv);
+
+	TAILQ_INSERT_TAIL(&bus->driver_list, drv, next);
+	drv->bus = bus;
+}
+
+/** @internal
+ * Disassociate a driver from bus.
+ */
+void
+rte_eal_bus_remove_driver(struct rte_driver *drv)
+{
+	struct rte_bus *bus;
+
+	RTE_VERIFY(drv);
+	RTE_VERIFY(drv->bus);
+
+	bus = drv->bus;
+	TAILQ_REMOVE(&bus->driver_list, drv, next);
+	drv->bus = NULL;
+}
+
+/**
+ * Get the bus handle using its name
+ */
+struct rte_bus *
+rte_eal_get_bus(const char *bus_name)
+{
+	struct rte_bus *bus;
+
+	RTE_VERIFY(bus_name);
+
+	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		RTE_VERIFY(bus->name);
+
+		if (!strcmp(bus_name, bus->name)) {
+			RTE_LOG(DEBUG, EAL, "Returning Bus object %p\n", bus);
+			return bus;
+		}
+	}
+
+	/* Unable to find bus requested */
+	return NULL;
+}
+
+/* register a bus */
+void
+rte_eal_bus_register(struct rte_bus *bus)
+{
+	RTE_VERIFY(bus);
+	RTE_VERIFY(bus->name && strlen(bus->name));
+
+	/* Initialize the driver and device list associated with the bus */
+	TAILQ_INIT(&(bus->driver_list));
+	TAILQ_INIT(&(bus->device_list));
+
+	TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
+	RTE_LOG(INFO, EAL, "Registered [%s] bus.\n", bus->name);
+}
+
+/* unregister a bus */
+void
+rte_eal_bus_unregister(struct rte_bus *bus)
+{
+	/* All devices and drivers associated with the bus should have been
+	 * 'device->uninit' and 'driver->remove()' already.
+	 */
+	RTE_VERIFY(TAILQ_EMPTY(&(bus->driver_list)));
+	RTE_VERIFY(TAILQ_EMPTY(&(bus->device_list)));
+
+	/* TODO: For each device, call its rte_device->driver->remove()
+	 * and rte_eal_bus_remove_driver()
+	 */
+
+	TAILQ_REMOVE(&rte_bus_list, bus, next);
+	RTE_LOG(INFO, EAL, "Unregistered [%s] bus.\n", bus->name);
+}
+
+/* dump one bus info */
+static int
+bus_dump_one(FILE *f, struct rte_bus *bus)
+{
+	int ret;
+
+	/* For now, dump only the bus name */
+	ret = fprintf(f, " %s\n", bus->name);
+
+	/* Error in case of inability in writing to stream */
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+void
+rte_eal_bus_dump(FILE *f)
+{
+	int ret;
+	struct rte_bus *bus;
+
+	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		ret = bus_dump_one(f, bus);
+		if (ret) {
+			RTE_LOG(ERR, EAL, "Unable to write to stream (%d)\n",
+				ret);
+			break;
+		}
+	}
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
new file mode 100644
index 0000000..f0297a9
--- /dev/null
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -0,0 +1,174 @@ 
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 NXP
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of NXP nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_BUS_H_
+#define _RTE_BUS_H_
+
+/**
+ * @file
+ *
+ * RTE PMD Bus Abstraction interfaces
+ *
+ * This file exposes APIs and Interfaces for Bus Abstraction over the devices
+ * drivers in EAL.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+#include <sys/queue.h>
+
+#include <rte_log.h>
+#include <rte_dev.h>
+
+/** Double linked list of buses */
+TAILQ_HEAD(rte_bus_list, rte_bus);
+
+/* Global Bus list */
+extern struct rte_bus_list rte_bus_list;
+
+struct rte_bus {
+	TAILQ_ENTRY(rte_bus) next;   /**< Next bus object in linked list */
+	struct rte_driver_list driver_list;
+				     /**< List of all drivers on bus */
+	struct rte_device_list device_list;
+				     /**< List of all devices on bus */
+	const char *name;            /**< Name of the bus */
+};
+
+/** @internal
+ * Add a device to a bus.
+ *
+ * @param bus
+ *	Bus on which device is to be added
+ * @param dev
+ *	Device handle
+ * @return
+ *	None
+ */
+void
+rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev);
+
+/** @internal
+ * Remove a device from its bus.
+ *
+ * @param dev
+ *	Device handle to remove
+ * @return
+ *	None
+ */
+void
+rte_eal_bus_remove_device(struct rte_device *dev);
+
+/** @internal
+ * Associate a driver with a bus.
+ *
+ * @param bus
+ *	Bus on which driver is to be added
+ * @param dev
+ *	Driver handle
+ * @return
+ *	None
+ */
+void
+rte_eal_bus_add_driver(struct rte_bus *bus, struct rte_driver *drv);
+
+/** @internal
+ * Disassociate a driver from its bus.
+ *
+ * @param dev
+ *	Driver handle to remove
+ * @return
+ *	None
+ */
+void
+rte_eal_bus_remove_driver(struct rte_driver *drv);
+
+/**
+ * Register a Bus handler.
+ *
+ * @param driver
+ *   A pointer to a rte_bus structure describing the bus
+ *   to be registered.
+ */
+void rte_eal_bus_register(struct rte_bus *bus);
+
+/**
+ * Unregister a Bus handler.
+ *
+ * @param driver
+ *   A pointer to a rte_bus structure describing the bus
+ *   to be unregistered.
+ */
+void rte_eal_bus_unregister(struct rte_bus *bus);
+
+/**
+ * Obtain handle for bus given its name.
+ *
+ * @param bus_name
+ *	Name of the bus handle to search
+ * @return
+ *	Pointer to Bus object if name matches any registered bus object
+ *	NULL, if no matching bus found
+ */
+struct rte_bus *rte_eal_get_bus(const char *bus_name);
+
+/**
+ * Dump information of all the buses registered with EAL.
+ *
+ * @param f
+ *	A valid and open output stream handle
+ *
+ * @return
+ *	 0 in case of success
+ *	!0 in case there is error in opening the output stream
+ */
+void rte_eal_bus_dump(FILE *f);
+
+/** Helper for Bus registration. The constructor has higher priority than
+ * PMD constructors
+ */
+#define RTE_REGISTER_BUS(nm, bus) \
+static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
+{\
+	(bus).name = RTE_STR(nm);\
+	rte_eal_bus_register(&bus); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_BUS_H */
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index 8840380..4004f9a 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -122,6 +122,7 @@  struct rte_driver;
  */
 struct rte_device {
 	TAILQ_ENTRY(rte_device) next; /**< Next device */
+	struct rte_bus *bus;          /**< Device connected to this bus */
 	struct rte_driver *driver;    /**< Associated driver */
 	int numa_node;                /**< NUMA node connection */
 	struct rte_devargs *devargs;  /**< Device user arguments */
@@ -148,6 +149,7 @@  void rte_eal_device_remove(struct rte_device *dev);
  */
 struct rte_driver {
 	TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */
+	struct rte_bus *bus;           /**< Bus serviced by this driver */
 	const char *name;                   /**< Driver name. */
 	const char *alias;              /**< Driver alias. */
 };
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 4e206f0..aa874a5 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -87,6 +87,7 @@  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_cpuflags.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_string_fns.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_hexdump.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_bus.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 83721ba..c873a7f 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -178,3 +178,18 @@  DPDK_16.11 {
 	rte_eal_vdrv_unregister;
 
 } DPDK_16.07;
+
+DPDK_17.02 {
+	global:
+
+	rte_bus_list;
+	rte_eal_bus_add_device;
+	rte_eal_bus_add_driver;
+	rte_eal_get_bus;
+	rte_eal_bus_dump;
+	rte_eal_bus_register;
+	rte_eal_bus_remove_device;
+	rte_eal_bus_remove_driver;
+	rte_eal_bus_unregister;
+
+} DPDK_16.11;