Introducing EAL Bus-Device-Driver Model
v6 cover Introducing EAL Bus-Device-Driver Model
Link to v5: [15]
:: Introduction ::
DPDK has been inherently a PCI inclined framework. Because of this, the design of device tree (or list) within DPDK is also PCI inclined. A non-PCI device doesn't have a way of being expressed without using hooks started from EAL to PMD.
(Check 'Version Changes' section for changes)
:: Overview of the Proposed Changes ::
Assuming the below graph for a computing node:
device A1
|
+==.===='==============.============+ Bus A.
| `--> driver A11 \
device A2 `-> driver A12 \______
|CPU |
/`````
device B1 /
| /
+==.===='==============.============+ Bus B`
| `--> driver B11
device B2 `-> driver B12 - 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
In [15], model assumes that rte_bus would be the base class using which all the bus implementations would instantiate the objects. This patches takes a much more basic approach, on the same lines of rte_device/ rte_driver and rte_pci_device/rte_pci_driver.
This is based on various review comments as well as offline (IRC) discussions.
- rte_bus is an abstract class which includes basic methods supported by all buses.
- specific implementation, for example for PCI rte_pci_bus, would extend this class to form their own buses, with their own bus specific device and driver list.
-
+-----------------+ |rte_pci_bus | |+---------------+| ||rte_bus || |+---------------+| +-----------------+
And example implementation would look like:
.--------------->+-------------------+
| |rte_pci_bus |
| | +----------------+|
| | |rte_bus <------.
| | | name || |
| | | scan || |
| | | probe || |
| | | attach || |
| | | detach || |
| | +----------------+| |
| | pci_driver_list | |
| .-------------->pci_device_list | |
| | | ... | |
| | +-------------------+ |
| | |
| +-------------------+ |
| |rte_pci_device | |
'----bus | |
| +----------------+| |
| |rte_device || |
| | bus --------------------------------'
| | ... ||
| +----------------+|
| ... |
+-------------------+:: Brief about Patch Layout ::
0001~0002: Introducing the basic Bus model and associated test case
0003 : Split the PCI match into a separate function
0004~0005: Introduce bus->scan APIs and integrate with EAL
0006 : Update the Bus and PCI test cases for scanning/probing
0007 : Enable PCI bus and remove code for direct PCI scan/probe from
EAL
0008 : Add device hotplugging over the bus and introduce PCI helpers
:: Pending Changes/Caveats ::
1. This patchset only moves the PCI into a bus. And, that movement is also currently part of the EAL (lib/librte_eal/linux)
Eventual aim is the PCI bus reside in driver/bus/pci
2. Though the implementation for bus is common for Linux and BSD, the PCI bus implementation has been done/tested only for Linux.
3. RTE_REGISTER_BUS has been declared with contructor priority of 101 It is important that Bus is registered *before* drivers are registered. Only way I could find to assure that was via __attribute(contructor(priority)) of GCC. I am not sure how it would behave on other compilers. Any suggestions?
- One suggestion from David Marchand was to use global bus object handles, which I have not implemented for now. If that is common choice, I will change in v3.
:: ToDo list ::
- Bump to librte_eal version
- Documentation continues to have references to some _old_ PCI symbols
:: References ::
[1] http://dpdk.org/ml/archives/dev/2016-November/050186.html
[2] http://dpdk.org/ml/archives/dev/2016-November/050622.html
[3] http://dpdk.org/ml/archives/dev/2016-November/050416.html
[4] http://dpdk.org/ml/archives/dev/2016-November/050567.html
[5] http://dpdk.org/ml/archives/dev/2016-November/050628.html
[6] http://dpdk.org/ml/archives/dev/2016-November/050415.html
[7] http://dpdk.org/ml/archives/dev/2016-November/050443.html
[8] http://dpdk.org/ml/archives/dev/2016-November/050624.html
[9] http://dpdk.org/ml/archives/dev/2016-November/050296.html
[10] http://dpdk.org/ml/archives/dev/2016-December/051349.html
[12] http://dpdk.org/ml/archives/dev/2016-December/052092.html
[13] http://dpdk.org/ml/archives/dev/2016-December/052381.html
[14] http://dpdk.org/ml/archives/dev/2016-December/053302.html
[15] http://dpdk.org/ml/archives/dev/2016-December/053315.html
:: Version Changes ::
v6:
- Rearchitecture to bring bus object parallel to rte_device/driver This majorly includes:
-- rte_pci_bus class and pci_bus as its object for PCI -- bus->attach/detach (hotplugging)
-- removing bus->match as that is local to an implementation
- rename symbols rte_eal_bus_* to rte_bus_*
- restructuring patches (order) for simplicity
- update to test_pci
v5:
- Fix checkpatch error in Patch 0003
v4:
- rebase over master (eac901ce)
- Fix a bug in test_bus while setup and cleanup
- rename rte_eal_get_bus to rte_eal_bus_get
- Add helper (iterator) macros for easy bus,device,driver traversal
- removed 0001 patch as it is already merged in master
- fix missing rte_eal_bus_insert_device symbol in map file
v3:
- rebase over master (c431384c8f)
- revert patch 0001 changes for checkpatch (container_of macro)
- qat/rte_qat_cryptodev update for rte_driver->probe
- test_pci update for using a test_pci_bus for verification
- some bug fixes based on internal testing.
-- rte_eal_dev_attach not handling devargs
-- blacklisting not working
v2:
- No more bus->probe()
Now, rte_eal_bus_probe() calls rte_driver->probe based on match output
- new functions, rte_eal_pci_probe and rte_eal_pci_remove have been added as glue code between PCI PMDs and PCI Bus
`-> PMDs are updated to use these new functions as callbacks for
rte_driver
- 'default' keyword has been removed from match and scan
- Fix for incorrect changes in mlx* and nicvf*
- Checkpatch fixes
- Some variable checks have been removed from internal functions; functions which are externally visible continue to have such checks
- Some rearrangement of patches:
-- changes to drivers have been separated from EAL changes (but this
does make PCI PMDs non-working for a particular patch)
Shreyansh Jain (8):
eal/bus: introduce bus abstraction
test: add basic bus infrastructure tests
pci: split match and probe function
eal/bus: support for scanning of bus
eal: introduce bus scan and probe in EAL
test: update bus and pci unit test cases
eal: enable PCI bus
eal: enable hotplugging of devices on bus
app/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 686 ++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++-- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 13 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 13 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 15 +- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 140 +++++ lib/librte_eal/common/eal_common_dev.c | 56 +- lib/librte_eal/common/eal_common_pci.c | 330 ++++++++---- lib/librte_eal/common/eal_private.h | 10 - lib/librte_eal/common/include/rte_bus.h | 206 +++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/common/include/rte_pci.h | 161 +++++- lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal.c | 13 +- lib/librte_eal/linuxapp/eal/eal_pci.c | 53 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 15 +- 20 files changed, 1646 insertions(+), 238 deletions(-) create mode 100644 app/test/test_bus.c create mode 100644 lib/librte_eal/common/eal_common_bus.c create mode 100644 lib/librte_eal/common/include/rte_bus.h
Signature · 1 line
2.7.4
PATCH v6 1/8 eal/bus: introduce bus abstraction
This patch introduces the rte_bus abstraction for EAL.
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' base class which would be extended for specific implementations. It also introduces Bus registration and deregistration functions.
An example implementation would be like:
.--------------->+-------------------+
| |rte_pci_bus |
| | +----------------+|
| | |rte_bus <------.
| | | name || |
| | | scan || |
| | | match || |
| | | probe || |
| | | remove || |
| | | ... || |
| | +----------------+| |
| | pci_driver_list | |
| .-------------->pci_device_list | |
| | | ... | |
| | +-------------------+ |
| | |
| +-------------------+ |
| |rte_pci_device | |
'----bus | |
| +----------------+| |
| |rte_device || |
| | bus --------------------------------'
| | ... ||
| +----------------+|
| ... |
+-------------------+--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 10 +++ lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 97 +++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 111 ++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/rte_eal_version.map | 10 +++ 8 files changed, 232 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
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -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
lib/librte_eal/bsdapp/eal/rte_eal_version.map +10 -0
@@ -174,3 +174,13 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_list; + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
lib/librte_eal/common/Makefile +1 -1
@@ -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
lib/librte_eal/common/eal_common_bus.c new file +97 -0
97 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h new file +111 -0
111 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +1 -0
@@ -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 */ const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -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
lib/librte_eal/linuxapp/eal/rte_eal_version.map +10 -0
@@ -178,3 +178,13 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_list; + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
Signature · 1 line
2.7.4
PATCH v6 2/8 test: add basic bus infrastructure tests
In reply to Shreyansh JainVerification of bus registration, deregistration methods.
--- app/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 359 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 3 + 4 files changed, 365 insertions(+), 1 deletion(-) create mode 100644 app/test/test_bus.c
app/test/Makefile +1 -1
@@ -94,7 +94,7 @@ SRCS-y += test_cycles.c SRCS-y += test_spinlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c - +SRCS-y += test_bus.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c SRCS-y += test_pmd_perf.c
app/test/test.h +2 -0
@@ -236,6 +236,8 @@ int commands_init(void);int test_pci (void );int test_pci_run; +int test_bus (void ); +int test_mp_secondary (void );int test_set_rxtx_conf (cmdline_fixed_string_t mode);
app/test/test_bus.c new file +359 -0
359 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +3 -0
@@ -56,6 +56,9 @@ extern "C" {/** Double linked list of buses */ TAILQ_HEAD (rte_bus_list, rte_bus); +/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list; +/** * A structure describing a generic bus. */
Signature · 1 line
2.7.4
PATCH v6 3/8 pci: split match and probe function
In reply to Shreyansh JainMatching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev).
Splitting the matching function into a public fn rte_pci_match.
--- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_pci.c | 189 +++++++++++++----------- lib/librte_eal/common/include/rte_pci.h | 15 ++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 121 insertions(+), 85 deletions(-)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
@@ -182,5 +182,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match; } DPDK_16.11;
lib/librte_eal/common/eal_common_pci.c +104 -85
233 lines not on this page · raw message
lib/librte_eal/common/include/rte_pci.h +15 -0
@@ -371,6 +371,21 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,int rte_eal_pci_scan (void );/** +* Match the PCI Driver and Device using the ID Table +* +* @param pci_drv +* PCI driver from which ID table would be extracted +* @param pci_dev +* PCI device to match against the driver +* @return +* 0 for successful match +* !0 for unsuccessful match +*/ +int +rte_pci_match (struct rte_pci_driver *pci_drv, +struct rte_pci_device *pci_dev); + +/** * Probe the PCI bus for registered drivers. * * Scan the content of the PCI bus, and call the probe() function for
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -0
@@ -186,5 +186,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match; } DPDK_16.11;
Signature · 1 line
2.7.4
Re: [PATCH v6 3/8] pci: split match and probe function
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 157
Quoted 4 lines · On Mon, 16 Jan 2017 21:08:22 +0530 Shreyansh Jain <[email protected]>…
lib/librte_eal/common/eal_common_pci.c +3
-1-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) +int +rte_pci_match (struct rte_pci_driver *pci_drv, +struct rte_pci_device *pci_dev)
Use const?
Re: [PATCH v6 3/8] pci: split match and probe function
Quoted 10 lines · Stephen Hemminger
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 157
Quoted 4 lines · On Mon, 16 Jan 2017 21:08:22 +0530 Shreyansh Jain <[email protected]>…
lib/librte_eal/common/eal_common_pci.c +3
-1-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) +int +rte_pci_match (struct rte_pci_driver *pci_drv, +struct rte_pci_device *pci_dev)Use const?
Done in v7. Thanks
Re: [PATCH v6 3/8] pci: split match and probe function
In reply to Shreyansh JainQuoted 7 lines · Shreyansh Jain
Matching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (
rte_eal_pci_probe_one_driverandrte_eal_pci_detach_dev).Splitting the matching function into a public fn
rte_pci_match.Signed-off-by Shreyansh Jain <[email protected]>
<...>
Quoted 27 lines
/*
- * If vendor/device ID match, call theremove()function of the
+ * If vendor/device ID match, call theprobe()function of the
* driver.
*/
static intlib/librte_eal/common/eal_common_pci.c +5
-10-rte_eal_pci_detach_dev(struct rte_pci_driver *dr, - struct rte_pci_device *dev) +rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, + struct rte_pci_device *dev) { - const struct rte_pci_id *id_table; + int ret; +struct rte_pci_addr *loc;if ((dr ==NULL ) || (dev ==NULL ))return -EINVAL ; -for (id_table = dr->id_table; id_table->vendor_id !=0 ; id_table++) { + loc = &dev->addr; -/* check if device's identifiers match the driver's ones */ -if (id_table->vendor_id != dev->id.vendor_id && - id_table->vendor_id !=PCI_ANY_ID ) -continue ; -if (id_table->device_id != dev->id.device_id && - id_table->device_id !=PCI_ANY_ID )
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 213
Quoted 10 lines
lib/librte_eal/common/eal_common_pci.c +3
-7-continue ; -if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id && - id_table->subsystem_vendor_id !=PCI_ANY_ID ) -continue ; -if (id_table->subsystem_device_id != dev->id.subsystem_device_id && - id_table->subsystem_device_id !=PCI_ANY_ID ) -continue ; +RTE_LOG (INFO ,EAL ,"PCI device " PCI_PRI_FMT " on NUMA socket %i\n" , + loc->domain, loc->bus, loc->devid, loc->function, + dev->device.numa_node);
This cause bunch of log printed during app startup, what about printing this log when probed device found?
Quoted 15 lines
lib/librte_eal/common/eal_common_pci.c +13
-1-struct rte_pci_addr *loc = &dev->addr; +/* The device is not blacklisted; Check if driver supports it */ + ret =rte_pci_match (dr, dev); +if (ret) { +/* Match of device and driver failed */ +RTE_LOG (DEBUG ,EAL ,"Driver (%s) doesn't match the device\n" , + dr->driver.name); +return 1 ; + } + +/* no initialization when blacklisted, return without error */ +if (dev->device.devargs !=NULL && + dev->device.devargs->type == +RTE_DEVTYPE_BLACKLISTED_PCI ) {
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 234
Quoted 10 lines
lib/librte_eal/common/eal_common_pci.c +6
-3+RTE_LOG (INFO ,EAL ," Device is blacklisted, not" +" initializing\n" ); +return 1 ; + } -RTE_LOG (DEBUG ,EAL ,"PCI device " PCI_PRI_FMT " on NUMA socket %i\n" , - loc->domain, loc->bus, loc->devid, - loc->function, dev->device.numa_node); +RTE_LOG (INFO ,EAL ," probe driver: %x:%x %s\n" , dev->id.vendor_id, + dev->id.device_id, dr->driver.name);
Same for this one, this line cause printing all registered drivers for each device during app initialization, only matched one can be logged.
Quoted 29 lines
lib/librte_eal/common/eal_common_pci.c +14
-8-RTE_LOG (DEBUG ,EAL ," remove driver: %x:%x %s\n" , dev->id.vendor_id, - dev->id.device_id, dr->driver.name); +if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING ) { +/* map resources for devices that use igb_uio */ + ret =rte_eal_pci_map_device (dev); +if (ret !=0 ) +return ret; + } -if (dr->remove && (dr->remove (dev) <0 )) -return -1 ;/* negative value is an error */ +/* reference driver structure */ + dev->driver = dr; -/* clear driver structure */ +/* call the driver probe() function */ + ret = dr->probe (dr, dev); +if (ret) { dev->driver =NULL ; -if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING ) -/* unmap resources for devices that use igb_uio */ rte_eal_pci_unmap_device (dev); + } -return 0 ; +return ret; +}
<...>
lib/librte_eal/linuxapp/eal/rte_eal_version.map DPDK_17.02 { · line 189
Quoted 9 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1
-0@@ -186,5 +186,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match;
I think this is internal API, should library expose this API?
Quoted 3 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0
-0} DPDK_16.11;
Re: [PATCH v6 3/8] pci: split match and probe function
Hello Ferruh,
Quoted 43 lines · Ferruh Yigit
Quoted 7 lines · Shreyansh Jain
Matching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (
rte_eal_pci_probe_one_driverandrte_eal_pci_detach_dev).Splitting the matching function into a public fn
rte_pci_match.Signed-off-by Shreyansh Jain <[email protected]><...>
Quoted 32 lines
/*
- * If vendor/device ID match, call theremove()function of the
+ * If vendor/device ID match, call theprobe()function of the
* driver.
*/
static intlib/librte_eal/common/eal_common_pci.c +5
-15-rte_eal_pci_detach_dev(struct rte_pci_driver *dr, - struct rte_pci_device *dev) +rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, + struct rte_pci_device *dev) { - const struct rte_pci_id *id_table; + int ret; +struct rte_pci_addr *loc;if ((dr ==NULL ) || (dev ==NULL ))return -EINVAL ; -for (id_table = dr->id_table; id_table->vendor_id !=0 ; id_table++) { + loc = &dev->addr; -/* check if device's identifiers match the driver's ones */ -if (id_table->vendor_id != dev->id.vendor_id && - id_table->vendor_id !=PCI_ANY_ID ) -continue ; -if (id_table->device_id != dev->id.device_id && - id_table->device_id !=PCI_ANY_ID ) -continue ; -if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id && - id_table->subsystem_vendor_id !=PCI_ANY_ID ) -continue ; - if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
Quoted 8 lines
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 213
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +3
-2- id_table->subsystem_device_id != PCI_ANY_ID) -continue ; +RTE_LOG (INFO ,EAL ,"PCI device " PCI_PRI_FMT " on NUMA socket %i\n" , + loc->domain, loc->bus, loc->devid, loc->function, + dev->device.numa_node);This cause bunch of log printed during app startup, what about printing this log when probed device found?
Only thing I did was move around this log message without adding anything new. Maybe earlier it was in some conditional (match) and now it isn't. I will check again and move to match-only case.
Quoted 21 lines
Quoted 21 lines
lib/librte_eal/common/eal_common_pci.c +17
-1-struct rte_pci_addr *loc = &dev->addr; +/* The device is not blacklisted; Check if driver supports it */ + ret =rte_pci_match (dr, dev); +if (ret) { +/* Match of device and driver failed */ +RTE_LOG (DEBUG ,EAL ,"Driver (%s) doesn't match the device\n" , + dr->driver.name); +return 1 ; + } + +/* no initialization when blacklisted, return without error */ +if (dev->device.devargs !=NULL && + dev->device.devargs->type == +RTE_DEVTYPE_BLACKLISTED_PCI ) { +RTE_LOG (INFO ,EAL ," Device is blacklisted, not" +" initializing\n" ); +return 1 ; + }
Quoted 8 lines
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 234
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +2
-3-RTE_LOG (DEBUG ,EAL ,"PCI device " PCI_PRI_FMT " on NUMA socket %i\n" , - loc->domain, loc->bus, loc->devid, - loc->function, dev->device.numa_node); +RTE_LOG (INFO ,EAL ," probe driver: %x:%x %s\n" , dev->id.vendor_id, + dev->id.device_id, dr->driver.name);Same for this one, this line cause printing all registered drivers for each device during app initialization, only matched one can be logged.
Same. Will post v7 shortly with only match case printing. What about DEBUG for all cases?
Quoted 33 lines
Quoted 30 lines
lib/librte_eal/common/eal_common_pci.c +14
-8-RTE_LOG (DEBUG ,EAL ," remove driver: %x:%x %s\n" , dev->id.vendor_id, - dev->id.device_id, dr->driver.name); +if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING ) { +/* map resources for devices that use igb_uio */ + ret =rte_eal_pci_map_device (dev); +if (ret !=0 ) +return ret; + } -if (dr->remove && (dr->remove (dev) <0 )) -return -1 ;/* negative value is an error */ +/* reference driver structure */ + dev->driver = dr; -/* clear driver structure */ +/* call the driver probe() function */ + ret = dr->probe (dr, dev); +if (ret) { dev->driver =NULL ; -if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING ) -/* unmap resources for devices that use igb_uio */ rte_eal_pci_unmap_device (dev); + } -return 0 ; +return ret; +}<...>
Quoted 11 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map DPDK_17.02 { · line 189
Quoted 9 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1
-0@@ -186,5 +186,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match;I think this is internal API, should library expose this API?
Idea is that pci_match be useable outside of PCI for any other PCI-like bus (BDF compliant). For example, one of NXP's devices are very close to PCI (but not exactly PCI) and they too rely on BDF for addressing/naming.
Quoted 6 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map DPDK_17.02 { · line 191
Quoted 4 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0
-0} DPDK_16.11;
-
Shreyansh
Re: [PATCH v6 3/8] pci: split match and probe function
Quoted 89 lines · Shreyansh Jain
Hello Ferruh,
Quoted 43 lines · Ferruh Yigit
Quoted 7 lines · Shreyansh Jain
Matching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (
rte_eal_pci_probe_one_driverandrte_eal_pci_detach_dev).Splitting the matching function into a public fn
rte_pci_match.Signed-off-by Shreyansh Jain <[email protected]><...>
Quoted 32 lines
/*
- * If vendor/device ID match, call theremove()function of the
+ * If vendor/device ID match, call theprobe()function of the
* driver.
*/
static intlib/librte_eal/common/eal_common_pci.c +5
-15-rte_eal_pci_detach_dev(struct rte_pci_driver *dr, - struct rte_pci_device *dev) +rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, + struct rte_pci_device *dev) { - const struct rte_pci_id *id_table; + int ret; +struct rte_pci_addr *loc;if ((dr ==NULL ) || (dev ==NULL ))return -EINVAL ; -for (id_table = dr->id_table; id_table->vendor_id !=0 ; id_table++) { + loc = &dev->addr; -/* check if device's identifiers match the driver's ones */ -if (id_table->vendor_id != dev->id.vendor_id && - id_table->vendor_id !=PCI_ANY_ID ) -continue ; -if (id_table->device_id != dev->id.device_id && - id_table->device_id !=PCI_ANY_ID ) -continue ; -if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id && - id_table->subsystem_vendor_id !=PCI_ANY_ID ) -continue ; - if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&Quoted 8 lines
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 213
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +3
-2- id_table->subsystem_device_id != PCI_ANY_ID) -continue ; +RTE_LOG (INFO ,EAL ,"PCI device " PCI_PRI_FMT " on NUMA socket %i\n" , + loc->domain, loc->bus, loc->devid, loc->function, + dev->device.numa_node);This cause bunch of log printed during app startup, what about printing this log when probed device found?
Only thing I did was move around this log message without adding anything new. Maybe earlier it was in some conditional (match) and now it isn't. I will check again and move to match-only case.
Quoted 21 lines
Quoted 21 lines
lib/librte_eal/common/eal_common_pci.c +17
-1-struct rte_pci_addr *loc = &dev->addr; +/* The device is not blacklisted; Check if driver supports it */ + ret =rte_pci_match (dr, dev); +if (ret) { +/* Match of device and driver failed */ +RTE_LOG (DEBUG ,EAL ,"Driver (%s) doesn't match the device\n" , + dr->driver.name); +return 1 ; + } + +/* no initialization when blacklisted, return without error */ +if (dev->device.devargs !=NULL && + dev->device.devargs->type == +RTE_DEVTYPE_BLACKLISTED_PCI ) { +RTE_LOG (INFO ,EAL ," Device is blacklisted, not" +" initializing\n" ); +return 1 ; + }Quoted 8 lines
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 234
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +2
-3-RTE_LOG (DEBUG ,EAL ,"PCI device " PCI_PRI_FMT " on NUMA socket %i\n" , - loc->domain, loc->bus, loc->devid, - loc->function, dev->device.numa_node); +RTE_LOG (INFO ,EAL ," probe driver: %x:%x %s\n" , dev->id.vendor_id, + dev->id.device_id, dr->driver.name);Same for this one, this line cause printing all registered drivers for each device during app initialization, only matched one can be logged.
Quoted 2 lines
Same. Will post v7 shortly with only match case printing. What about DEBUG for all cases?
I would prefer existing behavior, INFO level for successfully probed device and driver, but no strong opinion.
Quoted 46 lines
Quoted 34 lines
Quoted 31 lines
lib/librte_eal/common/eal_common_pci.c +14
-8-RTE_LOG (DEBUG ,EAL ," remove driver: %x:%x %s\n" , dev->id.vendor_id, - dev->id.device_id, dr->driver.name); +if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING ) { +/* map resources for devices that use igb_uio */ + ret =rte_eal_pci_map_device (dev); +if (ret !=0 ) +return ret; + } -if (dr->remove && (dr->remove (dev) <0 )) -return -1 ;/* negative value is an error */ +/* reference driver structure */ + dev->driver = dr; -/* clear driver structure */ +/* call the driver probe() function */ + ret = dr->probe (dr, dev); +if (ret) { dev->driver =NULL ; -if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING ) -/* unmap resources for devices that use igb_uio */ rte_eal_pci_unmap_device (dev); + } -return 0 ; +return ret; +}<...>
Quoted 11 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map DPDK_17.02 { · line 189
Quoted 9 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1
-0@@ -186,5 +186,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match;I think this is internal API, should library expose this API?
Quoted 3 lines
Idea is that
pci_matchbe useable outside of PCI for any other PCI-like bus (BDF compliant). For example, one of NXP's devices are very close to PCI (but not exactly PCI) and they too rely on BDF for addressing/naming.
OK.
Quoted 11 lines
Quoted 7 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map DPDK_17.02 { · line 191
Quoted 5 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0
-0} DPDK_16.11;-
Shreyansh
Re: [PATCH v6 3/8] pci: split match and probe function
Quoted 90 lines · Ferruh Yigit
Quoted 89 lines · Shreyansh Jain
Hello Ferruh,
Quoted 43 lines · Ferruh Yigit
Quoted 7 lines · Shreyansh Jain
Matching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (
rte_eal_pci_probe_one_driverandrte_eal_pci_detach_dev).Splitting the matching function into a public fn
rte_pci_match.Signed-off-by Shreyansh Jain <[email protected]><...>
Quoted 32 lines
/*
- * If vendor/device ID match, call theremove()function of the
+ * If vendor/device ID match, call theprobe()function of the
* driver.
*/
static intlib/librte_eal/common/eal_common_pci.c +5
-15-rte_eal_pci_detach_dev(struct rte_pci_driver *dr, - struct rte_pci_device *dev) +rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, + struct rte_pci_device *dev) { - const struct rte_pci_id *id_table; + int ret; +struct rte_pci_addr *loc;if ((dr ==NULL ) || (dev ==NULL ))return -EINVAL ; -for (id_table = dr->id_table; id_table->vendor_id !=0 ; id_table++) { + loc = &dev->addr; -/* check if device's identifiers match the driver's ones */ -if (id_table->vendor_id != dev->id.vendor_id && - id_table->vendor_id !=PCI_ANY_ID ) -continue ; -if (id_table->device_id != dev->id.device_id && - id_table->device_id !=PCI_ANY_ID ) -continue ; -if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id && - id_table->subsystem_vendor_id !=PCI_ANY_ID ) -continue ; - if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&Quoted 8 lines
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 213
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +3
-2- id_table->subsystem_device_id != PCI_ANY_ID) -continue ; +RTE_LOG (INFO ,EAL ,"PCI device " PCI_PRI_FMT " on NUMA socket %i\n" , + loc->domain, loc->bus, loc->devid, loc->function, + dev->device.numa_node);This cause bunch of log printed during app startup, what about printing this log when probed device found?
Only thing I did was move around this log message without adding anything new. Maybe earlier it was in some conditional (match) and now it isn't. I will check again and move to match-only case.
Quoted 29 lines
Quoted 16 lines
lib/librte_eal/common/eal_common_pci.c +13
-1-struct rte_pci_addr *loc = &dev->addr; +/* The device is not blacklisted; Check if driver supports it */ + ret =rte_pci_match (dr, dev); +if (ret) { +/* Match of device and driver failed */ +RTE_LOG (DEBUG ,EAL ,"Driver (%s) doesn't match the device\n" , + dr->driver.name); +return 1 ; + } + +/* no initialization when blacklisted, return without error */ +if (dev->device.devargs !=NULL && + dev->device.devargs->type == +RTE_DEVTYPE_BLACKLISTED_PCI ) {lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 234
Quoted 10 lines
lib/librte_eal/common/eal_common_pci.c +6
-3+RTE_LOG (INFO ,EAL ," Device is blacklisted, not" +" initializing\n" ); +return 1 ; + } -RTE_LOG (DEBUG ,EAL ,"PCI device " PCI_PRI_FMT " on NUMA socket %i\n" , - loc->domain, loc->bus, loc->devid, - loc->function, dev->device.numa_node); +RTE_LOG (INFO ,EAL ," probe driver: %x:%x %s\n" , dev->id.vendor_id, + dev->id.device_id, dr->driver.name);Same for this one, this line cause printing all registered drivers for each device during app initialization, only matched one can be logged.
Quoted 5 lines
Quoted 2 lines
Same. Will post v7 shortly with only match case printing. What about DEBUG for all cases?
I would prefer existing behavior, INFO level for successfully probed device and driver, but no strong opinion.
Reverted to existing behavior. It was a miss from my side. I had moved this log message _before_ matching unlike the original code. Pushed v7 to ML.
Quoted 66 lines
Quoted 47 lines
Quoted 35 lines
Quoted 32 lines
lib/librte_eal/common/eal_common_pci.c +14
-8-RTE_LOG (DEBUG ,EAL ," remove driver: %x:%x %s\n" , dev->id.vendor_id, - dev->id.device_id, dr->driver.name); +if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING ) { +/* map resources for devices that use igb_uio */ + ret =rte_eal_pci_map_device (dev); +if (ret !=0 ) +return ret; + } -if (dr->remove && (dr->remove (dev) <0 )) -return -1 ;/* negative value is an error */ +/* reference driver structure */ + dev->driver = dr; -/* clear driver structure */ +/* call the driver probe() function */ + ret = dr->probe (dr, dev); +if (ret) { dev->driver =NULL ; -if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING ) -/* unmap resources for devices that use igb_uio */ rte_eal_pci_unmap_device (dev); + } -return 0 ; +return ret; +}<...>
Quoted 11 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map DPDK_17.02 { · line 189
Quoted 9 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1
-0@@ -186,5 +186,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match;I think this is internal API, should library expose this API?
Quoted 3 lines
Idea is that
pci_matchbe useable outside of PCI for any other PCI-like bus (BDF compliant). For example, one of NXP's devices are very close to PCI (but not exactly PCI) and they too rely on BDF for addressing/naming.OK.
Quoted 11 lines
Quoted 7 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map DPDK_17.02 { · line 191
Quoted 5 lines
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0
-0} DPDK_16.11;-
Shreyansh
PATCH v6 4/8 eal/bus: support for scanning of bus
In reply to Shreyansh JainScan for bus discovers the devices available on the bus and adds them to a bus specific device list. Each bus mandatorily implements this method.
Test cases for Bus are also updated by this patch.
--- app/test/test_bus.c | 175 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_common_bus.c | 2 + lib/librte_eal/common/include/rte_bus.h | 18 ++++ 3 files changed, 195 insertions(+)
app/test/test_bus.c +175 -0
@@ -106,10 +106,26 @@ struct dummy_bus_map {struct rte_bus_list orig_bus_list =TAILQ_HEAD_INITIALIZER (orig_bus_list); +/* Forward declarations for callbacks from bus */ + +/* Bus A +* Scan would register devA1 and devA2 to bus +*/ +static int scan_fn_for_busA (void ); + +/* Bus B +* Scan would register devB1 and devB2 to bus +*/ +static int scan_fn_for_busB (void ); + +/* generic implementations wrapped around by above declarations */ +static int generic_scan_fn (struct rte_bus *bus); +struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , + .scan = scan_fn_for_busA, }, };
@@ -117,6 +133,7 @@ struct dummy_bus busB = { .name = "busB_impl", /* busB */ .bus = { .name = "busB", + .scan = scan_fn_for_busB, }, };
@@ -226,9 +243,81 @@ dump_device_tree(void)printf ("------>8-------\n" ); } +/* @internal +* Move over the bus_map and find the entry matching the bus object +* passed as argument. +* For each device in that bus_map list, register. +* +* @param bus +* bus to scan againt test entry +* @return +* 0 for successful scan, even if no devices are found +* !0 for any error in scanning (like, invalid bus) +*/ +static int +generic_scan_fn (struct rte_bus *bus) +{ +int i =0 ; +struct dummy_device *ddev =NULL ; +struct dummy_bus_map *dbmap =NULL ; +struct dummy_bus *db =NULL ; + +if (!bus) +return -1 ; + +/* Extract the device tree node using the bus passed */ +for (i =0 ; bus_map[i].name; i++) { +if (!strcmp (bus_map[i].name, bus->name)) { + dbmap = &bus_map[i]; +break ; + } + } + +if (!dbmap) +return -1 ; + + db = dbmap->dbus; + +/* For all the devices in the device tree (bus_map), add device */ +for (i =0 ; dbmap->ddevices[i]; i++) { + ddev = dbmap->ddevices[i]; +TAILQ_INSERT_TAIL (&db->device_list, ddev, next); + ddev->dev.bus = bus; + } + +return 0 ; +} + +int +scan_fn_for_busA (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busA" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} + +int +scan_fn_for_busB (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busB" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} +static int test_bus_setup (void ) { +int i =0 ;struct rte_bus *bus_p =NULL ;/* Preserve the original bus list before executing test */
@@ -238,6 +327,13 @@ test_bus_setup(void)TAILQ_INSERT_TAIL (&orig_bus_list, bus_p, next); } +/* Initialize the bus lists */ +for (i =0 ; bus_map[i].name; i++) { +TAILQ_INIT (&bus_map[i].dbus->device_list); +TAILQ_INIT (&bus_map[i].dbus->driver_list); + } + +dump_device_tree ();return 0 ; }
@@ -336,6 +432,79 @@ test_bus_unregistration(void)return 0 ; } +static int +test_device_unregistration_on_bus (void ) +{ +int i; +struct rte_bus *bus =NULL ; +struct dummy_device *ddev; +struct dummy_bus *dbus; + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); +if (!bus) { +printf ("Unable to find bus (%s)\n" , + bus_map[i].name); +return -1 ; + } + + dbus = container_of(bus, struct dummy_bus, bus); +/* For bus 'bus', unregister all devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +TAILQ_REMOVE (&dbus->device_list, ddev, next); + } + } + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); + dbus = container_of(bus, struct dummy_bus, bus); + +if (!TAILQ_EMPTY (&dbus->device_list)) { +printf ("Unable to remove all devices on bus (%s)\n" , + bus->name); +return -1 ; + } + } + +/* All devices from all buses have been removed */ +printf ("All devices on all buses unregistered.\n" ); +dump_device_tree (); + +return 0 ; +} + +/* @internal +* For each bus registered, call the scan function to identify devices +* on the bus. +* +* @param void +* @return +* 0 for successful scan +* !0 for unsuccessful scan +* +*/ +static int +test_bus_scan (void ) +{ +int ret; +struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { +/* Call the scan function for each bus */ + ret = bus->scan (); +if (ret) { +printf ("Scan of buses failed.\n" ); +return -1 ; + } + } + +printf ("Scan of all buses completed.\n" ); +dump_device_tree (); + +return 0 ; +} + +int test_bus (void ) {
@@ -346,6 +515,12 @@ test_bus(void)if (test_bus_registration ())return -1 ; +if (test_bus_scan ()) +return -1 ; + +if (test_device_unregistration_on_bus ()) +return -1 ; +if (test_bus_unregistration ())return -1 ;
lib/librte_eal/common/eal_common_bus.c +2 -0
@@ -51,6 +51,8 @@ rte_bus_register(struct rte_bus *bus) {RTE_VERIFY (bus);RTE_VERIFY (bus->name &&strlen (bus->name)); +/* A bus should mandatorily have the scan implemented */ +RTE_VERIFY (bus->scan);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (INFO ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +18 -0
@@ -60,11 +60,29 @@ TAILQ_HEAD(rte_bus_list, rte_bus);extern struct rte_bus_list rte_bus_list;/** +* Bus specific scan for devices attached on the bus. +* For each bus object, the scan would be reponsible for finding devices and +* adding them to its private device list. +* +* A bus should mandatorily implement this method. +* +* Generic bus object passed only as a helper for implementation to find +* their respective registered bus object. Implementations can choose not +* to use this variable. +* +* @return +* 0 for successful scan +* !0 (<0) for unsuccessful scan with error value +*/ +typedef int (*rte_bus_scan_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ +rte_bus_scan_t scan;/**< Scan for devices attached to bus */ };/**
Signature · 1 line
2.7.4
PATCH v6 5/8 eal: introduce bus scan and probe in EAL
In reply to Shreyansh JainEach bus implementation defines their own callbacks for scanning bus and probing devices available on the bus. Enable EAL to call bus specific scan and probe functions during DPDK initialization.
Existing PCI scan/probe continues to exist. It will removed in subsequent patches.
--- lib/librte_eal/bsdapp/eal/eal.c | 8 +++ lib/librte_eal/bsdapp/eal/eal_pci.c | 11 ++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 + lib/librte_eal/common/eal_common_bus.c | 41 +++++++++++++++ lib/librte_eal/common/eal_common_pci.c | 33 ++++++++++++ lib/librte_eal/common/include/rte_bus.h | 39 ++++++++++++++ lib/librte_eal/common/include/rte_pci.h | 68 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 8 +++ lib/librte_eal/linuxapp/eal/eal_pci.c | 15 ++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 + 10 files changed, 227 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +8 -0
@@ -64,6 +64,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
@@ -577,6 +578,9 @@ rte_eal_init(int argc, char **argv) rte_config.master_lcore, thread_id, cpuset, ret == 0 ? "" : "..."); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
@@ -613,6 +617,10 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" ); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/bsdapp/eal/eal_pci.c +11 -0
@@ -673,3 +673,14 @@ rte_eal_pci_init(void) }return 0 ; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), + .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS (PCI_BUS_NAME , rte_pci_bus.bus);
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -0
@@ -182,6 +182,8 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_bus_probe; + rte_bus_scan; rte_pci_match; } DPDK_16.11;
lib/librte_eal/common/eal_common_bus.c +41 -0
53 lines not on this page · raw message
lib/librte_eal/common/eal_common_pci.c +33 -0
@@ -71,6 +71,7 @@#include <rte_interrupts.h> #include <rte_log.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_per_lcore.h> #include <rte_memory.h>
@@ -508,3 +509,35 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver)rte_eal_driver_unregister (&driver->driver);TAILQ_REMOVE (&pci_driver_list, driver, next); } + +/* Add a PCI device to PCI Bus */ +void +rte_eal_pci_add_device (struct rte_pci_bus *pci_bus, +struct rte_pci_device *pci_dev) +{ +TAILQ_INSERT_TAIL (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus = &pci_bus->bus; +} + +/* Insert a PCI device into a predefined position in PCI bus */ +void +rte_eal_pci_insert_device (struct rte_pci_device *exist_pci_dev, +struct rte_pci_device *new_pci_dev) +{ +TAILQ_INSERT_BEFORE (exist_pci_dev, new_pci_dev, next); +/* Update Bus references */ + new_pci_dev->device.bus = exist_pci_dev->device.bus; +} + +/* Remove a PCI device from PCI bus */ +void +rte_eal_pci_remove_device (struct rte_pci_device *pci_dev) +{ +struct rte_pci_bus *pci_bus; + + pci_bus = container_of(pci_dev->device.bus, struct rte_pci_bus, bus); +TAILQ_REMOVE (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus =NULL ; +}
lib/librte_eal/common/include/rte_bus.h +39 -0
@@ -77,12 +77,30 @@ extern struct rte_bus_list rte_bus_list;typedef int (*rte_bus_scan_t )(void );/** +* Implementation specific probe function which is responsible for linking +* devices on that bus with applicable drivers. +* +* This is called while iterating over each registered bus. Bus object is +* passed along assuming this is wrapped around (embedded) by Implementation +* specific bus object. +* +* @param bus +* Generic bus object which was registered with EAL +* +* @return +* 0 for successful probe +* !0 for any error while probing +*/ +typedef int (*rte_bus_probe_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ +rte_bus_probe_t probe;/**< Probe devices on bus */ };/**
@@ -104,6 +122,27 @@ void rte_bus_register(struct rte_bus *bus);void rte_bus_unregister (struct rte_bus *bus);/** +* Scan all the buses attached to the framework. +* +* @param void +* @return +* 0 in case of success in scanning all buses +* !0 in case of failure to scan +*/ +int rte_bus_scan (void ); + +/** +* For each device on the bus, perform a driver 'match' and call the +* bus's probe for device initialization. +* +* @param void +* @return +* 0 for successful match/probe +* !0 otherwise +*/ +int rte_bus_probe (void ); + +/** * Dump information of all the buses registered with EAL. * * @param f
lib/librte_eal/common/include/rte_pci.h +68 -0
98 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal.c +8 -0
@@ -69,6 +69,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
@@ -844,6 +845,9 @@ rte_eal_init(int argc, char **argv)if (rte_eal_intr_init () <0 )rte_panic ("Cannot init interrupt-handling thread\n" ); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
@@ -884,6 +888,10 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" ); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/linuxapp/eal/eal_pci.c +15 -0
@@ -35,6 +35,7 @@#include <dirent.h> #include <rte_log.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_eal_memconfig.h> #include <rte_malloc.h>
@@ -54,6 +55,9 @@* IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it). */ +/* Forward declaration of PCI bus */ +struct rte_pci_bus rte_pci_bus; +static int pci_get_kernel_driver_by_path (const char *filename,char *dri_name) {
@@ -723,3 +727,14 @@ rte_eal_pci_init(void)return 0 ; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), + .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS (PCI_BUS_NAME , rte_pci_bus.bus);
lib/librte_eal/linuxapp/eal/rte_eal_version.map +2 -0
@@ -186,6 +186,8 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_bus_probe; + rte_bus_scan; rte_pci_match; } DPDK_16.11;
Signature · 1 line
2.7.4
Re: [PATCH v6 5/8] eal: introduce bus scan and probe in EAL
Quoted 8 lines · Shreyansh Jain
Each bus implementation defines their own callbacks for scanning bus and probing devices available on the bus. Enable EAL to call bus specific scan and probe functions during DPDK initialization.
Existing PCI scan/probe continues to exist. It will removed in subsequent patches.
Signed-off-by Shreyansh Jain <[email protected]>
<...>
lib/librte_eal/common/eal_common_bus.c rte_bus_unregister(struct rte_bus *bus) · line 72
Quoted 3 lines
lib/librte_eal/common/eal_common_bus.c +3
-0+/* Scan all the buses for registering devices */ +int +rte_bus_scan (void )
I hesitate to make this kind of (not really functional) comments in this stage of the release, but please feel free to ignore them as your wish.
Previous patch is (4/8) for adding bus scan support, so why not this function (also .map and .h file part of it) added in prev patch?
And if there is a specific patch for scan, probe can be another one?
Quoted 16 lines
lib/librte_eal/common/eal_common_bus.c +16
-0+{ +int ret; +struct rte_bus *bus =NULL ; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->scan (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Scan for (%s) bus failed.\n" , + bus->name); +/* Error in scanning any bus stops the EAL init. */ +return ret; + } + } + +return 0 ; +}
<...>
Quoted 2 lines
lib/librte_eal/common/eal_common_pci.c +0
-0
<...>
lib/librte_eal/common/eal_common_pci.c rte_eal_pci_unregister(struct rte_pci_driver *driver) · line 516
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +5
-0+ +/* Add a PCI device to PCI Bus */ +void +rte_eal_pci_add_device (struct rte_pci_bus *pci_bus, +struct rte_pci_device *pci_dev)
I think more generic approach from previous version was better (rte_eal_bus_add_device()), but I guess they sacrificed for less modification.
Quoted 6 lines
lib/librte_eal/common/eal_common_pci.c +6
-0+{ +TAILQ_INSERT_TAIL (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus = &pci_bus->bus; +} +
<...>
lib/librte_eal/common/eal_common_pci.c
Quoted 8 lines
lib/librte_eal/common/eal_common_pci.c +7
-0+/** +* Structure describing the PCI bus +*/ +struct rte_pci_bus { +struct rte_bus bus;/**< Inherit the generic class */ +struct rte_pci_device_list device_list;/**< List of PCI devices */ +struct rte_pci_driver_list driver_list;/**< List of PCI drivers */
Why bus device/driver lists moved from rte_bus? Each bus will need this? Is it to change as less code as possible?
<...>
lib/librte_eal/common/eal_common_pci.c
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +5
-0+ +/** +* Insert a PCI device in the PCI Bus at a particular location in the device +* list. It also updates the PCI Bus reference of the new devices to be +* inserted.
Minor issue in document compilation:
- warning: argument 'pci_dev' of command @param is not found
- parameter 'new_pci_dev' not documented
Similar warnings exists for rte_eal_pci_remove_device() too.
Also following in rte_bus_scan(void) and rte_bus_probe(void)
- warning: argument 'void' of command @param is not found
Quoted 10 lines
+ *
+ * @paramexist_pci_dev
+ * Existing PCI device in PCI Bus
+ * @parampci_dev
+ * PCI device to be added beforeexist_pci_dev
+ * @return void
+ */lib/librte_eal/common/eal_common_pci.c +3
-0+void rte_eal_pci_insert_device (struct rte_pci_device *exist_pci_dev, +struct rte_pci_device *new_pci_dev); +
<...>
Re: [PATCH v6 5/8] eal: introduce bus scan and probe in EAL
Quoted 10 lines · Ferruh Yigit
Quoted 8 lines · Shreyansh Jain
Each bus implementation defines their own callbacks for scanning bus and probing devices available on the bus. Enable EAL to call bus specific scan and probe functions during DPDK initialization.
Existing PCI scan/probe continues to exist. It will removed in subsequent patches.
Signed-off-by Shreyansh Jain <[email protected]>
Quoted 8 lines
<...>
lib/librte_eal/common/eal_common_bus.c rte_bus_unregister(struct rte_bus *bus) · line 72
Quoted 3 lines
lib/librte_eal/common/eal_common_bus.c +3
-0+/* Scan all the buses for registering devices */ +int +rte_bus_scan (void )I hesitate to make this kind of (not really functional) comments in this stage of the release, but please feel free to ignore them as your wish.
No issues - any review comment is welcome.
Quoted 3 lines
Previous patch is (4/8) for adding bus scan support, so why not this function (also .map and .h file part of it) added in prev patch?
Maybe I didn't get your point well, but this is my take:
4/8 is for introducing the scan callbacks into the Bus layer. There is no work done for EAL yet in 4/8.
This patch, 5/8, adds functions (not callbacks) and modifications to EAL for plugging the bus (with its scan/probe) into EAL.
Quoted 2 lines
And if there is a specific patch for scan, probe can be another one?
I agree with this.
Quoted 23 lines
Quoted 17 lines
lib/librte_eal/common/eal_common_bus.c +16
-0+{ +int ret; +struct rte_bus *bus =NULL ; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->scan (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Scan for (%s) bus failed.\n" , + bus->name); +/* Error in scanning any bus stops the EAL init. */ +return ret; + } + } + +return 0 ; +}<...>
Quoted 2 lines
lib/librte_eal/common/eal_common_pci.c +0
-0<...>
Quoted 9 lines
lib/librte_eal/common/eal_common_pci.c rte_eal_pci_unregister(struct rte_pci_driver *driver) · line 516
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +5
-0+ +/* Add a PCI device to PCI Bus */ +void +rte_eal_pci_add_device (struct rte_pci_bus *pci_bus, +struct rte_pci_device *pci_dev)I think more generic approach from previous version was better (
rte_eal_bus_add_device()), but I guess they sacrificed for less modification.
There was a lot of offline discussions after the reviews were posted until v5. From the gist of it, I gathered that smaller 'specific' changes are preferred as compared to complete generic approach without an upfront usecase.
Also, this change became irrelevant once I moved out the device/driver lists from rte_bus to rte_xxx_bus. This is inline with existing model of (rte_pci_device->rte_device, rte_pci_driver->rte_driver, rte_pci_bus->rte_bus) and having pci_device_list/pci_driver_list private to PCI itself.
I guess what is going to happen is that in near future when buses start moving to drivers/bus/*, this kind of generic layer would come in.
Quoted 11 lines
Quoted 7 lines
lib/librte_eal/common/eal_common_pci.c +6
-0+{ +TAILQ_INSERT_TAIL (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus = &pci_bus->bus; +} +<...>
Quoted 1 line
Quoted 10 lines
lib/librte_eal/common/eal_common_pci.c
Quoted 7 lines
lib/librte_eal/common/eal_common_pci.c +7
-0+/** +* Structure describing the PCI bus +*/ +struct rte_pci_bus { +struct rte_bus bus;/**< Inherit the generic class */ +struct rte_pci_device_list device_list;/**< List of PCI devices */ +struct rte_pci_driver_list driver_list;/**< List of PCI drivers */ Why bus device/driver lists moved from
rte_bus? Each bus will need this? Is it to change as less code as possible?
Yes, to move towards a minimal change.
Also, in sync with existing 'pci_device_list/pci_driver_list'.
Quoted 11 lines
<...>
lib/librte_eal/common/eal_common_pci.c
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +5
-0+ +/** +* Insert a PCI device in the PCI Bus at a particular location in the device +* list. It also updates the PCI Bus reference of the new devices to be +* inserted. Minor issue in document compilation:
Quoted 8 lines
- warning: argument '
pci_dev' of command @param is not found- parameter '
new_pci_dev' not documentedSimilar warnings exists for
rte_eal_pci_remove_device()too.Also following in
rte_bus_scan(void)andrte_bus_probe(void)
- warning: argument 'void' of command @param is not found
I will fix and post v7 very shortly.
Quoted 15 lines
Quoted 11 lines
+ *
+ * @paramexist_pci_dev
+ * Existing PCI device in PCI Bus
+ * @parampci_dev
+ * PCI device to be added beforeexist_pci_dev
+ * @return void
+ */lib/librte_eal/common/eal_common_pci.c +3
-0+void rte_eal_pci_insert_device (struct rte_pci_device *exist_pci_dev, +struct rte_pci_device *new_pci_dev); +<...>
Re: [PATCH v6 5/8] eal: introduce bus scan and probe in EAL
2017-01-17 10:33, Shreyansh Jain:
Quoted 11 lines · Ferruh Yigit
Quoted 9 lines · Shreyansh Jain
lib/librte_eal/common/eal_common_pci.c rte_eal_pci_unregister(struct rte_pci_driver *driver) · line 516
Quoted 4 lines
lib/librte_eal/common/eal_common_pci.c +4
-0+/* Add a PCI device to PCI Bus */ +void +rte_eal_pci_add_device (struct rte_pci_bus *pci_bus, +struct rte_pci_device *pci_dev)I think more generic approach from previous version was better (
rte_eal_bus_add_device()), but I guess they sacrificed for less modification.
Quoted 4 lines
There was a lot of offline discussions after the reviews were posted until v5. From the gist of it, I gathered that smaller 'specific' changes are preferred as compared to complete generic approach without an upfront usecase.
Yes I discussed (a lot) this approach with Shreyansh.
Quoted 8 lines
Also, this change became irrelevant once I moved out the device/driver lists from
rte_bustorte_xxx_bus. This is inline with existing model of (rte_pci_device->rte_device,rte_pci_driver->rte_driver,rte_pci_bus->rte_bus) and having pci_device_list/pci_driver_list private to PCI itself.I guess what is going to happen is that in near future when buses start moving to
drivers/bus/*, this kind of generic layer would come in.
I think there will be no use case requiring a unique list of all rte_device(s). Being generic and wrapping stuff with abstract classes is not always a benefit. That's why, this version is more focused on specialized objects.
Experience with this layering will tell us wether it is a good design or not.
Re: [PATCH v6 5/8] eal: introduce bus scan and probe in EAL
In reply to Ferruh YigitJust an update on things fixed/updated in v7 against these comments:
Quoted 19 lines · Ferruh Yigit
Quoted 8 lines · Shreyansh Jain
Each bus implementation defines their own callbacks for scanning bus and probing devices available on the bus. Enable EAL to call bus specific scan and probe functions during DPDK initialization.
Existing PCI scan/probe continues to exist. It will removed in subsequent patches.
Signed-off-by Shreyansh Jain <[email protected]><...>
lib/librte_eal/common/eal_common_bus.c rte_bus_unregister(struct rte_bus *bus) · line 72
Quoted 3 lines
lib/librte_eal/common/eal_common_bus.c +3
-0+/* Scan all the buses for registering devices */ +int +rte_bus_scan (void )I hesitate to make this kind of (not really functional) comments in this stage of the release, but please feel free to ignore them as your wish.
Quoted 4 lines
Previous patch is (4/8) for adding bus scan support, so why not this function (also .map and .h file part of it) added in prev patch?
And if there is a specific patch for scan, probe can be another one?
v7 Contains a split patch for introducing probe handler and introducing scan and probe in EAL.
Quoted 64 lines
Quoted 17 lines
lib/librte_eal/common/eal_common_bus.c +16
-0+{ +int ret; +struct rte_bus *bus =NULL ; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->scan (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Scan for (%s) bus failed.\n" , + bus->name); +/* Error in scanning any bus stops the EAL init. */ +return ret; + } + } + +return 0 ; +}<...>
Quoted 2 lines
lib/librte_eal/common/eal_common_pci.c +0
-0<...>
lib/librte_eal/common/eal_common_pci.c rte_eal_pci_unregister(struct rte_pci_driver *driver) · line 516
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +5
-0+ +/* Add a PCI device to PCI Bus */ +void +rte_eal_pci_add_device (struct rte_pci_bus *pci_bus, +struct rte_pci_device *pci_dev)I think more generic approach from previous version was better (
rte_eal_bus_add_device()), but I guess they sacrificed for less modification.Quoted 6 lines
lib/librte_eal/common/eal_common_pci.c +6
-0+{ +TAILQ_INSERT_TAIL (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus = &pci_bus->bus; +} +<...>
lib/librte_eal/common/eal_common_pci.c
Quoted 8 lines
lib/librte_eal/common/eal_common_pci.c +7
-0+/** +* Structure describing the PCI bus +*/ +struct rte_pci_bus { +struct rte_bus bus;/**< Inherit the generic class */ +struct rte_pci_device_list device_list;/**< List of PCI devices */ +struct rte_pci_driver_list driver_list;/**< List of PCI drivers */ Why bus device/driver lists moved from
rte_bus? Each bus will need this? Is it to change as less code as possible?<...>
lib/librte_eal/common/eal_common_pci.c
Quoted 5 lines
lib/librte_eal/common/eal_common_pci.c +5
-0+ +/** +* Insert a PCI device in the PCI Bus at a particular location in the device +* list. It also updates the PCI Bus reference of the new devices to be +* inserted. Minor issue in document compilation:
Quoted 8 lines
- warning: argument '
pci_dev' of command @param is not found- parameter '
new_pci_dev' not documentedSimilar warnings exists for
rte_eal_pci_remove_device()too.Also following in
rte_bus_scan(void)andrte_bus_probe(void)
- warning: argument 'void' of command @param is not found
Pushed v7 to ML. 'make doc' is not reporting any warn/error now. Thanks for pointing it out.
Quoted 15 lines
Quoted 11 lines
+ *
+ * @paramexist_pci_dev
+ * Existing PCI device in PCI Bus
+ * @parampci_dev
+ * PCI device to be added beforeexist_pci_dev
+ * @return void
+ */lib/librte_eal/common/eal_common_pci.c +3
-0+void rte_eal_pci_insert_device (struct rte_pci_device *exist_pci_dev, +struct rte_pci_device *new_pci_dev); +<...>
PATCH v6 6/8 test: update bus and pci unit test cases
In reply to Shreyansh Jain--- app/test/test_bus.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 266 insertions(+), 50 deletions(-)
app/test/test_bus.c +152 -0
@@ -120,12 +120,15 @@ static int scan_fn_for_busB(void);/* generic implementations wrapped around by above declarations */ static int generic_scan_fn (struct rte_bus *bus); +static int generic_probe_fn (void ); +static int dummy_match_fn (struct rte_driver *drv,struct rte_device *dev);struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , .scan = scan_fn_for_busA, + .probe = generic_probe_fn, }, };
@@ -134,6 +137,7 @@ struct dummy_bus busB = { .bus = { .name = "busB", .scan = scan_fn_for_busB, + .probe = generic_probe_fn, }, };
@@ -288,6 +292,46 @@ generic_scan_fn(struct rte_bus *bus)return 0 ; } +/* @internal +* Obtain bus from driver object. Match the address of rte_device object +* with all the devices associated with that bus. +* +* Being a test function, all this does is validate that device object +* provided is available on the same bus to which driver is registered. +* +* @param drv +* driver to match with +* @param dev +* device object +* @return +* 0 for successful match +* !0 for failed match +*/ +static int +dummy_match_fn(struct rte_driver *drv __rte_unused, struct rte_device *dev) +{ +struct rte_bus *bus; +struct dummy_device *ddev =NULL ; +struct dummy_device *ddev_as_arg; +struct dummy_bus *dbus =NULL ; + +/* Match is based entirely on address of 'dev' and 'dev_p' extracted +* from bus->device_list. +*/ + +/* a driver is registered with the bus *before* the scan. */ + bus = dev->bus; + dbus = container_of(bus, struct dummy_bus, bus); + ddev_as_arg = container_of(dev, struct dummy_device, dev); + + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +if (ddev == ddev_as_arg) +return 0 ; + } + +return 1 ; +} +int scan_fn_for_busA (void ) {struct dummy_bus_map *dbm;
@@ -504,6 +548,110 @@ test_bus_scan(void)return 0 ; } +/* +* +*/ +static int +generic_probe_fn (void ) +{ +int ret =0 ; +int i, j; +struct rte_driver *drv; +struct rte_device *dev; +struct dummy_bus *dbus =NULL ; +struct dummy_device *ddev =NULL ; +struct dummy_driver *ddrv =NULL ; + +/* In case of this test: +* 1. for each bus in rte_bus_list +* 2. for each device on that bus (bus specific->device_list) +* 3. for each driver on that bus (bus specific->driver_list) +* 4. call match +* 5. link driver and device +* 6. Verify the linkage. +*/ +for (i =0 ; bus_map[i].name; i++) { +/* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + +/* Looping over all scanned devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +/* There is a list of drivers within dummy_bus_map. +* In case of PMDs, this would be driver registration +* APIs/list +*/ +for (j =0 ; bus_map[i].ddrivers[j]; j++) { + ddrv = bus_map[i].ddrivers[j]; + + drv = &ddrv->drv; + dev = &ddev->dev; + ret =dummy_match_fn (drv, dev); +if (!ret) { +/* As match is generic, it always +* results in dev->drv pointing to +* first driver entry in bus_map[i] +*/ + dev->driver = drv; + dev->bus = &dbus->bus; + } +/* Else, continue */ + } + } + } + +/* Verify the linkage. All devices belonging to a bus_map[i] +* should have same driver (first driver entry of bus_map[i]) +*/ +for (i =0 ; bus_map[i].name; i++) { + ddrv = bus_map[i].ddrivers[0 ]; + drv = &ddrv->drv; + +for (j =0 ; bus_map[i].ddevices[j]; j++) { + ddev = bus_map[i].ddevices[j]; + dev = &ddev->dev; +if (dev->driver != drv) { +printf ("Incorrect driver<->device linkage.\n" ); +return -1 ; + } + } + } + +return 0 ; +} + +/* @internal +* Function to perform 'probe' and link devices and drivers on a bus. +* This would work over all the buses registered, and all devices and drivers +* registered with it - call match on each pair. +* +* @param void +* @return +* 0 for successful probe +* !0 for failure in probe +* +*/ +static int +test_probe_on_bus (void ) +{ +int ret =0 ; +int i; +struct dummy_bus *dbus; +struct rte_bus *bus; + +for (i =0 ; bus_map[i].name; i++) { +/* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + bus = &dbus->bus; + ret = bus->probe (); +if (ret) +printf ("Probe for %s failed.\n" , bus_map[i].name); + } + +printf ("Probe on all buses successful.\n" ); +dump_device_tree (); + +return 0 ; +}int test_bus (void )
@@ -518,6 +666,10 @@ test_bus(void)if (test_bus_scan ())return -1 ; +/* Now that the devices and drivers are registered, perform probe */ +if (test_probe_on_bus ()) +return -1 ; +if (test_device_unregistration_on_bus ())return -1 ;
app/test/test_pci.c +114 -50
271 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 7/8 eal: enable PCI bus
In reply to Shreyansh JainRemove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.
--- lib/librte_eal/bsdapp/eal/eal.c | 7 ----- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 -- lib/librte_eal/common/eal_common_pci.c | 36 ++++++++++++----------- lib/librte_eal/common/eal_private.h | 10 ------- lib/librte_eal/common/include/rte_pci.h | 22 +++++--------- lib/librte_eal/linuxapp/eal/eal.c | 7 ----- lib/librte_eal/linuxapp/eal/eal_pci.c | 38 +++++++------------------ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 -- 8 files changed, 37 insertions(+), 87 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +0 -7
@@ -562,9 +562,6 @@ rte_eal_init(int argc, char **argv)if (rte_eal_timer_init () <0 )rte_panic ("Cannot init HPET or TSC timers\n" ); -if (rte_eal_pci_init () <0 ) -rte_panic ("Cannot init PCI\n" ); -eal_check_mem_on_local_socket ();if (eal_plugins_init () <0 )
@@ -613,10 +610,6 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); -/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
lib/librte_eal/bsdapp/eal/rte_eal_version.map +0 -2
@@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc;
lib/librte_eal/common/eal_common_pci.c +19 -17
@@ -83,11 +83,6 @@#include "eal_private.h" -struct pci_driver_list pci_driver_list = -TAILQ_HEAD_INITIALIZER (pci_driver_list); -struct pci_device_list pci_device_list = -TAILQ_HEAD_INITIALIZER (pci_device_list); -#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"const char *pci_get_sysfs_path (void )
@@ -315,7 +310,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)if (dev->driver !=NULL )return 0 ; - TAILQ_FOREACH(dr, &pci_driver_list, next) { +FOREACH_DRIVER_ON_PCIBUS (dr) { rc =rte_eal_pci_probe_one_driver (dr, dev);if (rc <0 )/* negative value is an error */
@@ -342,7 +337,7 @@ pci_detach_all_drivers(struct rte_pci_device *dev)if (dev ==NULL )return -1 ; - TAILQ_FOREACH(dr, &pci_driver_list, next) { +FOREACH_DRIVER_ON_PCIBUS (dr) { rc =rte_eal_pci_detach_dev (dr, dev);if (rc <0 )/* negative value is an error */
@@ -363,6 +358,7 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr) {struct rte_pci_device *dev =NULL ; +int ret =0 ;if (addr ==NULL )
@@ -374,7 +370,7 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)if (pci_update_device (addr) <0 ) goto err_return; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ;
@@ -404,7 +400,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)if (addr ==NULL )return -1 ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ;
@@ -412,7 +408,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)if (ret <0 ) goto err_return; -TAILQ_REMOVE (&pci_device_list, dev, next); +rte_eal_pci_remove_device (dev);free (dev);return 0 ; }
@@ -441,7 +437,7 @@ rte_eal_pci_probe(void)if (rte_eal_devargs_type_count (RTE_DEVTYPE_WHITELISTED_PCI ) ==0 ) probe_all =1 ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {/* set devargs in PCI structure */ devargs =pci_devargs_lookup (dev);
@@ -489,7 +485,7 @@ rte_eal_pci_dump(FILE *f) {struct rte_pci_device *dev =NULL ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {pci_dump_one_device (f, dev); } }
@@ -498,16 +494,22 @@ rte_eal_pci_dump(FILE *f)void rte_eal_pci_register (struct rte_pci_driver *driver) { -TAILQ_INSERT_TAIL (&pci_driver_list, driver, next); -rte_eal_driver_register (&driver->driver); +TAILQ_INSERT_TAIL (&rte_pci_bus.driver_list, driver, next); +/* Update Bus references */ + driver->pci_bus = &rte_pci_bus; } -/* unregister a driver */ +/* Unregister a driver */ void rte_eal_pci_unregister (struct rte_pci_driver *driver) { -rte_eal_driver_unregister (&driver->driver); -TAILQ_REMOVE (&pci_driver_list, driver, next); +struct rte_pci_bus *pci_bus; + + pci_bus = driver->pci_bus; + +TAILQ_REMOVE (&pci_bus->driver_list, driver, next); +/* Update Bus references */ + driver->pci_bus =NULL ; }/* Add a PCI device to PCI Bus */
lib/librte_eal/common/eal_private.h +0 -10
@@ -108,16 +108,6 @@ int rte_eal_timer_init(void);*/ int rte_eal_log_init (const char *id,int facility); -/** -* Init the PCI infrastructure -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error -*/ -int rte_eal_pci_init (void ); -struct rte_pci_driver ;struct rte_pci_device ;
lib/librte_eal/common/include/rte_pci.h +7 -15
@@ -87,12 +87,6 @@ extern "C" {#include <rte_dev.h> #include <rte_bus.h> -TAILQ_HEAD (pci_device_list, rte_pci_device);/**< PCI devices in D-linked Q. */ -TAILQ_HEAD (pci_driver_list, rte_pci_driver);/**< PCI drivers in D-linked Q. */ - -extern struct pci_driver_list pci_driver_list;/**< Global list of PCI drivers. */ -extern struct pci_device_list pci_device_list;/**< Global list of PCI devices. */ -/** Pathname of PCI devices directory. */ const char *pci_get_sysfs_path (void );
@@ -124,6 +118,9 @@ TAILQ_HEAD(rte_pci_device_list, rte_pci_device);/** List of PCI drivers */ TAILQ_HEAD (rte_pci_driver_list, rte_pci_driver); +/* Extend PCI bus definition to users */ +extern struct rte_pci_bus rte_pci_bus; +/* PCI Bus iterators */ #define FOREACH_DEVICE_ON_PCIBUS (p) \ TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next)
@@ -208,8 +205,6 @@ struct rte_pci_device { .subsystem_device_id = PCI_ANY_ID#endif -struct rte_pci_driver ; -/** * Initialisation function for the driver called during PCI probing. */
@@ -416,17 +411,14 @@ rte_pci_match(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev);/** -* Probe the PCI bus for registered drivers. -* -* Scan the content of the PCI bus, and call the probe() function for -* all registered drivers that have a matching entry in its id_table -* for discovered devices. +* Probe the PCI bus * * @return * - 0 on success. -* - Negative on error. +* - !0 on error. */ -int rte_eal_pci_probe (void ); +int +rte_eal_pci_probe (void );/** * Map the PCI device resources in user space virtual memory address
lib/librte_eal/linuxapp/eal/eal.c +0 -7
@@ -803,9 +803,6 @@ rte_eal_init(int argc, char **argv)if (rte_eal_log_init (logid, internal_config.syslog_facility) <0 )rte_panic ("Cannot init logs\n" ); -if (rte_eal_pci_init () <0 ) -rte_panic ("Cannot init PCI\n" ); -#ifdef VFIO_PRESENT if (rte_eal_vfio_setup () <0 )rte_panic ("Cannot init VFIO\n" );
@@ -884,10 +881,6 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); -/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
lib/librte_eal/linuxapp/eal/eal_pci.c +11 -27
@@ -232,7 +232,8 @@ pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)/* Scan one pci sysfs entry, and fill the devices list from it. */ static int -pci_scan_one (const char *dirname,const struct rte_pci_addr *addr) +pci_scan_one (struct rte_pci_bus *pci_bus,const char *dirname, +const struct rte_pci_addr *addr) {char filename[PATH_MAX ];unsigned long tmp;
@@ -350,21 +351,19 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) dev->kdrv =RTE_KDRV_NONE ;/* device is valid, add in list (sorted) */ -if (TAILQ_EMPTY (&pci_device_list)) { -rte_eal_device_insert (&dev->device); -TAILQ_INSERT_TAIL (&pci_device_list, dev, next); +if (TAILQ_EMPTY (&pci_bus->device_list)) { +rte_eal_pci_add_device (pci_bus, dev); }else {struct rte_pci_device *dev2;int ret; - TAILQ_FOREACH(dev2, &pci_device_list, next) { + TAILQ_FOREACH(dev2, &pci_bus->device_list, next) { ret =rte_eal_compare_pci_addr (&dev->addr, &dev2->addr);if (ret >0 )continue ;if (ret <0 ) { -TAILQ_INSERT_BEFORE (dev2, dev, next); -rte_eal_device_insert (&dev->device); +rte_eal_pci_insert_device (dev2, dev); }else {/* already registered */ dev2->kdrv = dev->kdrv; dev2->max_vfs = dev->max_vfs;
@@ -374,8 +373,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) }return 0 ; } -rte_eal_device_insert (&dev->device); -TAILQ_INSERT_TAIL (&pci_device_list, dev, next); + +rte_eal_pci_add_device (pci_bus, dev); }return 0 ;
@@ -390,7 +389,7 @@ pci_update_device(const struct rte_pci_addr *addr)pci_get_sysfs_path (), addr->domain, addr->bus, addr->devid, addr->function); -return pci_scan_one (filename, addr); +return pci_scan_one (&rte_pci_bus, filename, addr); }/*
@@ -467,7 +466,8 @@ rte_eal_pci_scan(void)snprintf (dirname,sizeof (dirname),"%s/%s" ,pci_get_sysfs_path (), e->d_name); -if (pci_scan_one (dirname, &addr) <0 ) + +if (pci_scan_one (&rte_pci_bus, dirname, &addr) <0 ) goto error; }closedir (dir);
@@ -712,22 +712,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)return ret; } -/* Init the PCI EAL subsystem */ -int -rte_eal_pci_init (void ) -{ -/* for debug purposes, PCI can be disabled */ -if (internal_config.no_pci) -return 0 ; - -if (rte_eal_pci_scan () <0 ) { -RTE_LOG (ERR ,EAL ,"%s(): Cannot scan PCI bus\n" , __func__); -return -1 ; - } - -return 0 ; -} -struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan,
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0 -2
@@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc;
Signature · 1 line
2.7.4
Re: [PATCH v6 7/8] eal: enable PCI bus
Quoted 4 lines · Shreyansh Jain
Remove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.
Signed-off-by Shreyansh Jain <[email protected]>---
<...>
lib/librte_eal/linuxapp/eal/eal_pci.c rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p) · line 721
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_pci.c +0
-7-/* Init the PCI EAL subsystem */ -int -rte_eal_pci_init (void ) -{ -/* for debug purposes, PCI can be disabled */ -if (internal_config.no_pci) -return 0 ;
Are we losing this feature? Should this check moved to rte_eal_pci_scan() ?
<...>
Re: [PATCH v6 7/8] eal: enable PCI bus
Quoted 8 lines · Ferruh Yigit
Quoted 4 lines · Shreyansh Jain
Remove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.
Signed-off-by Shreyansh Jain <[email protected]>---
<...>
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_pci.c rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p) · line 721
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_pci.c +0
-7-/* Init the PCI EAL subsystem */ -int -rte_eal_pci_init (void ) -{ -/* for debug purposes, PCI can be disabled */ -if (internal_config.no_pci) -return 0 ;Are we losing this feature? Should this check moved to
rte_eal_pci_scan()?
Yes, that is miss from my side. v5 had this, but I missed in v6 in all that code movement. I will add that to rte_eal_pci_scan. Thanks for highlighting.
Quoted 4 lines
<...>
Re: [PATCH v6 7/8] eal: enable PCI bus
In reply to Ferruh YigitQuoted 18 lines · Ferruh Yigit
Quoted 4 lines · Shreyansh Jain
Remove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.
Signed-off-by Shreyansh Jain <[email protected]>---
<...>
lib/librte_eal/linuxapp/eal/eal_pci.c rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p) · line 721
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_pci.c +0
-7-/* Init the PCI EAL subsystem */ -int -rte_eal_pci_init (void ) -{ -/* for debug purposes, PCI can be disabled */ -if (internal_config.no_pci) -return 0 ;Are we losing this feature? Should this check moved to
rte_eal_pci_scan()?
Quoted 3 lines
<...>
Fixed in v7. Thanks for comments.
PATCH v6 8/8 eal: enable hotplugging of devices on bus
In reply to Shreyansh JainGiven a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 + lib/librte_eal/common/eal_common_dev.c | 56 +++++++++++++++++----- lib/librte_eal/common/eal_common_pci.c | 82 +++++++++++++++++++++++++++++++-- lib/librte_eal/common/include/rte_bus.h | 35 ++++++++++++++ lib/librte_eal/common/include/rte_pci.h | 58 +++++++++++++++++++---- lib/librte_eal/linuxapp/eal/eal_pci.c | 2 + 6 files changed, 212 insertions(+), 23 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
@@ -678,6 +678,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
lib/librte_eal/common/eal_common_dev.c +44 -12
94 lines not on this page · raw message
lib/librte_eal/common/eal_common_pci.c +79 -3
98 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +35 -0
@@ -59,6 +59,8 @@ TAILQ_HEAD(rte_bus_list, rte_bus);/* Bus list exposed */ extern struct rte_bus_list rte_bus_list; +#define FOREACH_BUS (bus_p) TAILQ_FOREACH(bus_p, &rte_bus_list, next) +/** * Bus specific scan for devices attached on the bus. * For each bus object, the scan would be reponsible for finding devices and
@@ -94,6 +96,37 @@ typedef int (*rte_bus_scan_t)(void);typedef int (*rte_bus_probe_t )(void );/** +* Attach a device to a bus, assuming it is 'connected' to the bus. +* A bus is responsible for scanning for devices. Attaching a new device is +* for reenabling the device after being detached/removed. +* +* @param bus +* Generic bus object which was registered with EAL +* @param device_name +* Name of the device to attach. +* +* @return +* 0 for successful attach +* !0 for unsuccessful attach (or incorrect device name) +*/ +typedef int (*rte_bus_attach_t )(struct rte_bus *bus,const char *device_name); + +/** +* Detach a named device from a bus. Implementation would check the existence +* of device on the bus and detach it. +* +* @param bus +* Generic bus object which was registered with EAL +* @param device_name +* Name of the device to detach +* +* @return +* 0 for successful detaching +* !0 if device not found or can't detach +*/ +typedef int (*rte_bus_detach_t )(struct rte_bus *bus,const char *device_name); + +/** * A structure describing a generic bus. */ struct rte_bus {
@@ -101,6 +134,8 @@ struct rte_bus {const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ +rte_bus_attach_t attach;/**< Attach a named device */ +rte_bus_detach_t detach;/**< Detach a named device */ };/**
lib/librte_eal/common/include/rte_pci.h +50 -8
75 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -0
@@ -716,6 +716,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
Signature · 1 line
2.7.4
Re: [PATCH v6 8/8] eal: enable hotplugging of devices on bus
Quoted 303 lines · Shreyansh Jain
Given a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.
Signed-off-by Shreyansh Jain <[email protected]>--- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 + lib/librte_eal/common/eal_common_dev.c | 56 +++++++++++++++++----- lib/librte_eal/common/eal_common_pci.c | 82 +++++++++++++++++++++++++++++++-- lib/librte_eal/common/include/rte_bus.h | 35 ++++++++++++++ lib/librte_eal/common/include/rte_pci.h | 58 +++++++++++++++++++---- lib/librte_eal/linuxapp/eal/eal_pci.c | 2 + 6 files changed, 212 insertions(+), 23 deletions(-)lib/librte_eal/bsdapp/eal/eal_pci.c +2
-0@@ -678,6 +678,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),lib/librte_eal/common/eal_common_dev.c +44
-12@@ -38,6 +38,7 @@#include <sys/queue.h> #include <rte_dev.h> +#include <rte_bus.h> #include <rte_devargs.h> #include <rte_debug.h> #include <rte_devargs.h> @@ -106,23 +107,37 @@ rte_eal_dev_init(void)int rte_eal_dev_attach (const char *name,const char *devargs) { -struct rte_pci_addr addr; +int ret =1 ; +struct rte_bus *bus;if (name ==NULL || devargs ==NULL ) {RTE_LOG (ERR ,EAL ,"Invalid device or arguments provided\n" );return -EINVAL ; } -if (eal_parse_pci_DomBDF (name, &addr) ==0 ) { -if (rte_eal_pci_probe_one (&addr) <0 ) +FOREACH_BUS (bus) { +if (!bus->attach) { +RTE_LOG (DEBUG ,EAL ,"Bus (%s) doesn't implement" +" attach.\n" , bus->name); +continue ; + } + ret = bus->attach (bus, name); +if (!ret)/* device successfully attached */ +return ret; +if (ret >0 )/* device not found on bus */ +continue ; +else goto err; + } - }else { -if (rte_eal_vdev_init (name, devargs)) +if (ret >0 ) { +/* In case the device was not found on any bus, search VDEV */ + ret =rte_eal_vdev_init (name, devargs); +if (ret) goto err; } -return 0 ; +return ret; err:RTE_LOG (ERR ,EAL ,"Driver cannot attach the device (%s)\n" , name);@@ -131,21 +146,38 @@ int rte_eal_dev_attach(const char *name, const char *devargs)int rte_eal_dev_detach (const char *name) { -struct rte_pci_addr addr; +int ret =1 ; +struct rte_bus *bus;if (name ==NULL ) {RTE_LOG (ERR ,EAL ,"Invalid device provided.\n" );return -EINVAL ; } -if (eal_parse_pci_DomBDF (name, &addr) ==0 ) { -if (rte_eal_pci_detach (&addr) <0 ) +FOREACH_BUS (bus) { +if (!bus->detach) { +RTE_LOG (DEBUG ,EAL ,"Bus (%s) doesn't implement" +" detach.\n" , bus->name); +continue ; + } + + ret = bus->detach (bus, name); +if (!ret)/* device successfully detached */ +return ret; +if (ret >0 )/* device not found on the bus */ +continue ; +else goto err; - }else { -if (rte_eal_vdev_uninit (name)) + } + +if (ret >0 ) { +/* In case the device was not found on any bus, search VDEV */ + ret =rte_eal_vdev_uninit (name); +if (ret) goto err; } -return 0 ; + +return ret; err:RTE_LOG (ERR ,EAL ,"Driver cannot detach the device (%s)\n" , name);lib/librte_eal/common/eal_common_pci.c +79
-3@@ -389,19 +389,95 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr) }/* +* Attach device specific by its name +*/ +int +rte_eal_pci_attach(struct rte_bus *bus __rte_unused, const char *device_name) +{ +struct rte_pci_device *dev =NULL ; +struct rte_pci_driver *drv =NULL ; +struct rte_pci_addr addr; +int ret =-1 ; + +if (!device_name) +return -1 ; + +memset (&addr,0 ,sizeof (addr)); +if (eal_parse_pci_DomBDF (device_name, &addr) ==0 ) { +/* Device doesn't match PCI BDF naming format */ +return -1 ; + } + +FOREACH_DEVICE_ON_PCIBUS (dev) { +if (rte_eal_compare_pci_addr (&dev->addr, &addr)) +continue ; + +FOREACH_DRIVER_ON_PCIBUS (drv) { + ret =rte_pci_match (drv, dev); +if (ret) { +/* Match of device and driver failed */ +RTE_LOG (DEBUG ,EAL ,"Driver (%s) doesn't match" +" the device (%s)\n" , drv->driver.name, + device_name); +continue ; + } + +RTE_LOG (INFO ,EAL ," probe driver: %x:%x %s\n" , + dev->id.vendor_id, dev->id.device_id, + drv->driver.name); + +if (drv->drv_flags &RTE_PCI_DRV_NEED_MAPPING ) { +/* map resources for devices that use +* igb_uio +*/ + ret =rte_eal_pci_map_device (dev); +if (ret !=0 ) + goto err_return; + } + +/* reference driver structure */ + dev->driver = drv; + +/* call the driver probe() function */ + ret = drv->probe (drv, dev); +if (ret) { + dev->driver =NULL ; +if (drv->drv_flags &RTE_PCI_DRV_NEED_MAPPING ) +rte_eal_pci_unmap_device (dev); + } + } + } + +return ret; + +err_return: +RTE_LOG (WARNING ,EAL ,"Requested device " PCI_PRI_FMT +" cannot be used\n" , dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); +return -1 ; +} + +/* * Detach device specified by its pci address. */ int -rte_eal_pci_detach (const struct rte_pci_addr *addr) +rte_eal_pci_detach(struct rte_bus *bus __rte_unused, const char *device_name) {struct rte_pci_device *dev =NULL ; +struct rte_pci_addr addr;int ret =0 ; -if (addr ==NULL ) +if (!device_name)return -1 ; +memset (&addr,0 ,sizeof (addr)); +if (eal_parse_pci_DomBDF (device_name, &addr) ==0 ) { +/* Device doesn't match PCI BDF naming format */ +return -1 ; + } +FOREACH_DEVICE_ON_PCIBUS (dev) { -if (rte_eal_compare_pci_addr (&dev->addr, addr)) +if (rte_eal_compare_pci_addr (&dev->addr, &addr))continue ; ret =pci_detach_all_drivers (dev);lib/librte_eal/common/include/rte_bus.h +35
-0@@ -59,6 +59,8 @@ TAILQ_HEAD(rte_bus_list, rte_bus);/* Bus list exposed */ extern struct rte_bus_list rte_bus_list; +#define FOREACH_BUS (bus_p) TAILQ_FOREACH(bus_p, &rte_bus_list, next) +/** * Bus specific scan for devices attached on the bus. * For each bus object, the scan would be reponsible for finding devices and @@ -94,6 +96,37 @@ typedef int (*rte_bus_scan_t)(void);typedef int (*rte_bus_probe_t )(void );/** +* Attach a device to a bus, assuming it is 'connected' to the bus. +* A bus is responsible for scanning for devices. Attaching a new device is +* for reenabling the device after being detached/removed. +* +* @param bus +* Generic bus object which was registered with EAL +* @param device_name +* Name of the device to attach. +* +* @return +* 0 for successful attach +* !0 for unsuccessful attach (or incorrect device name) +*/ +typedef int (*rte_bus_attach_t )(struct rte_bus *bus,const char *device_name); + +/** +* Detach a named device from a bus. Implementation would check the existence +* of device on the bus and detach it. +* +* @param bus +* Generic bus object which was registered with EAL +* @param device_name +* Name of the device to detach +* +* @return +* 0 for successful detaching +* !0 if device not found or can't detach +*/ +typedef int (*rte_bus_detach_t )(struct rte_bus *bus,const char *device_name); + +/** * A structure describing a generic bus. */ struct rte_bus {@@ -101,6 +134,8 @@ struct rte_bus {const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ +rte_bus_attach_t attach;/**< Attach a named device */ +rte_bus_detach_t detach;/**< Detach a named device */ };/** lib/librte_eal/common/include/rte_pci.h +5
-0@@ -421,6 +421,40 @@ intrte_eal_pci_probe (void);/** +* Search and attach a PCI device to PCI Bus +* Implements rte_bus->attach +* +* @param bus +* Generic bus object representing PCI bus
lib/librte_eal/common/include/rte_pci.h int · line 438
Quoted 10 lines
lib/librte_eal/common/include/rte_pci.h +10
-0+* @param device_name +* Name of the device to search and attach +* +* @return +* 0 for successful removal of device +* >0 if device not found on bus +* <0 in case of error in removal. +*/ +int +rte_eal_pci_attach (struct rte_bus *bus,const char *device_name);
The first argument, rte_bus, is not required. I will remove this in v7.
Quoted 7 lines
lib/librte_eal/common/include/rte_pci.h +7
-0+ +/** +* Search and detach a PCI device from PCI Bus +* Implements rte_bus->detach +* +* @param bus +* Generic bus object representing PCI bus
lib/librte_eal/common/include/rte_pci.h int · line 455
Quoted 10 lines
lib/librte_eal/common/include/rte_pci.h +10
-0+* @param device_name +* Name of the device to search and detach +* +* @return +* 0 for successful detaching of device +* >0 if device not found on bus +* <0 in case of error in removal. +*/ +int +rte_eal_pci_detach (struct rte_bus *bus,const char *device_name);
Same as above, rte_bus argument is not required and will be removed in v7.
Quoted 55 lines
lib/librte_eal/common/include/rte_pci.h +18
-8+ +/** * Map the PCI device resources in user space virtual memory address * * Note that driver should not call this function when flag @@ -494,19 +528,27 @@ void pci_unmap_resource(void *requested_addr, size_t size);int rte_eal_pci_probe_one (const struct rte_pci_addr *addr);/** -* Close the single PCI device. -* -* Scan the content of the PCI bus, and find the pci device specified by pci -* address, then call the remove() function for registered driver that has a -* matching entry in its id_table for discovered device. +* Attach a PCI device on PCI Bus +* @param bus +* Generic Bus object for PCI Bus. If passed NULL, PCI bus is extracted +* using Bus APIs. +* @param device_name +* Device Name, which would be converted into BDF. +*/ +int rte_eal_pci_attach (struct rte_bus *bus,const char *device_name); + +/** +* Detach a single PCI device. * -* @param addr -* The PCI Bus-Device-Function address to close. +* @param bus +* Generic bus object for PCI bus. +* @param device_name +* Device Name, which would be converted into BDF. * @return * - 0 on success. * - Negative on error. */ -int rte_eal_pci_detach (const struct rte_pci_addr *addr); +int rte_eal_pci_detach (struct rte_bus *bus,const char *device_name);/** * Dump the content of the PCI bus. lib/librte_eal/linuxapp/eal/eal_pci.c +2
-0@@ -716,6 +716,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
Quoted 209 lines · On Mon, 16 Jan 2017 21:08:19 +0530 Shreyansh Jain <[email protected]>…
Link to v5: [15]
:: Introduction ::
DPDK has been inherently a PCI inclined framework. Because of this, the design of device tree (or list) within DPDK is also PCI inclined. A non-PCI device doesn't have a way of being expressed without using hooks started from EAL to PMD.
(Check 'Version Changes' section for changes)
:: Overview of the Proposed Changes ::
Assuming the below graph for a computing node:
device A1 | +==.===='==============.============+ Bus A. | `--> driver A11 \ device A2 `-> driver A12 \______ |CPU | /````` device B1 / | / +==.===='==============.============+ Bus B` | `--> driver B11 device B2 `-> driver B12- 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 deviceIn [15], model assumes that
rte_buswould be the base class using which all the bus implementations would instantiate the objects. This patches takes a much more basic approach, on the same lines of rte_device/rte_driverand rte_pci_device/rte_pci_driver.
This is based on various review comments as well as offline (IRC) discussions.-
rte_busis an abstract class which includes basic methods supported by all buses.
- specific implementation, for example for PCIrte_pci_bus, would extend this class to form their own buses, with their own bus specific device and driver list.
-+-----------------+ |rte_pci_bus | |+---------------+| ||rte_bus || |+---------------+| +-----------------+And example implementation would look like:
.--------------->+-------------------+ | |rte_pci_bus | | | +----------------+| | | |rte_bus <------. | | | name || | | | | scan || | | | | probe || | | | | attach || | | | | detach || | | | +----------------+| | | | pci_driver_list | | | .-------------->pci_device_list | | | | | ... | | | | +-------------------+ | | | | | +-------------------+ | | |rte_pci_device | | '----bus | | | +----------------+| | | |rte_device || | | | bus --------------------------------' | | ... || | +----------------+| | ... | +-------------------+:: Brief about Patch Layout ::
0001~0002: Introducing the basic Bus model and associated test case
0003 : Split the PCI match into a separate function
0004~0005: Introducebus->scanAPIs and integrate with EAL
0006 : Update the Bus and PCI test cases for scanning/probing
0007 : Enable PCI bus and remove code for direct PCI scan/probe from
EAL
0008 : Add device hotplugging over the bus and introduce PCI helpers:: Pending Changes/Caveats ::
1. This patchset only moves the PCI into a bus. And, that movement is also currently part of the EAL (
lib/librte_eal/linux)
Eventual aim is the PCI bus reside in driver/bus/pci2. Though the implementation for bus is common for Linux and BSD, the PCI bus implementation has been done/tested only for Linux.
3.
RTE_REGISTER_BUShas been declared with contructor priority of 101 It is important that Bus is registered *before* drivers are registered. Only way I could find to assure that was via __attribute(contructor(priority)) of GCC. I am not sure how it would behave on other compilers. Any suggestions?
- One suggestion from David Marchand was to use global bus object handles, which I have not implemented for now. If that is common choice, I will change in v3.:: ToDo list ::
- Bump to
librte_ealversion
- Documentation continues to have references to some _old_ PCI symbols:: References ::
[1] http://dpdk.org/ml/archives/dev/2016-November/050186.html
[2] http://dpdk.org/ml/archives/dev/2016-November/050622.html
[3] http://dpdk.org/ml/archives/dev/2016-November/050416.html
[4] http://dpdk.org/ml/archives/dev/2016-November/050567.html
[5] http://dpdk.org/ml/archives/dev/2016-November/050628.html
[6] http://dpdk.org/ml/archives/dev/2016-November/050415.html
[7] http://dpdk.org/ml/archives/dev/2016-November/050443.html
[8] http://dpdk.org/ml/archives/dev/2016-November/050624.html
[9] http://dpdk.org/ml/archives/dev/2016-November/050296.html
[10] http://dpdk.org/ml/archives/dev/2016-December/051349.html
[12] http://dpdk.org/ml/archives/dev/2016-December/052092.html
[13] http://dpdk.org/ml/archives/dev/2016-December/052381.html
[14] http://dpdk.org/ml/archives/dev/2016-December/053302.html
[15] http://dpdk.org/ml/archives/dev/2016-December/053315.html:: Version Changes ::
v6:
- Rearchitecture to bring bus object parallel to rte_device/driver This majorly includes:
--rte_pci_busclass andpci_busas its object for PCI -- bus->attach/detach (hotplugging)
-- removingbus->matchas that is local to an implementation
- rename symbols rte_eal_bus_* to rte_bus_*
- restructuring patches (order) for simplicity
- update totest_pciv5:
- Fix checkpatch error in Patch 0003v4:
- rebase over master (eac901ce)
- Fix a bug intest_buswhile setup and cleanup
- renamerte_eal_get_bustorte_eal_bus_get
- Add helper (iterator) macros for easy bus,device,driver traversal
- removed 0001 patch as it is already merged in master
- fix missingrte_eal_bus_insert_devicesymbol in map filev3:
- rebase over master (c431384c8f)
- revert patch 0001 changes for checkpatch (container_ofmacro)
- qat/rte_qat_cryptodev update forrte_driver->probe
-test_pciupdate for using atest_pci_busfor verification
- some bug fixes based on internal testing.
--rte_eal_dev_attachnot handling devargs
-- blacklisting not workingv2:
- No morebus->probe()
Now,rte_eal_bus_probe()callsrte_driver->probebased on match output
- new functions,rte_eal_pci_probeandrte_eal_pci_removehave been added as glue code between PCI PMDs and PCI Bus
`-> PMDs are updated to use these new functions as callbacks for
rte_driver
- 'default' keyword has been removed from match and scan
- Fix for incorrect changes in mlx* and nicvf*
- Checkpatch fixes
- Some variable checks have been removed from internal functions; functions which are externally visible continue to have such checks
- Some rearrangement of patches:
-- changes to drivers have been separated from EAL changes (but this
does make PCI PMDs non-working for a particular patch)Shreyansh Jain (8):
eal/bus: introduce bus abstraction
test: add basic bus infrastructure tests
pci: split match and probe function
eal/bus: support for scanning of bus
eal: introduce bus scan and probe in EAL
test: update bus and pci unit test cases
eal: enable PCI bus
eal: enable hotplugging of devices on busapp/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 686 ++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++-- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 13 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 13 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 15 +- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 140 +++++ lib/librte_eal/common/eal_common_dev.c | 56 +- lib/librte_eal/common/eal_common_pci.c | 330 ++++++++---- lib/librte_eal/common/eal_private.h | 10 - lib/librte_eal/common/include/rte_bus.h | 206 +++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/common/include/rte_pci.h | 161 +++++-
Quoted 9 lines
lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal.c | 13 +- lib/librte_eal/linuxapp/eal/eal_pci.c | 53 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 15 +- 20 files changed, 1646 insertions(+), 238 deletions(-) create mode 100644 app/test/test_bus.c create mode 100644 lib/librte_eal/common/eal_common_bus.c create mode 100644 lib/librte_eal/common/include/rte_bus.h
All this is excellent, but doesn't go far enough to break the assumptions of 'struct eth_driver'
Quoted 223 lines · Stephen Hemminger
Quoted 209 lines · On Mon, 16 Jan 2017 21:08:19 +0530 Shreyansh Jain <[email protected]>…
Link to v5: [15]
:: Introduction ::
DPDK has been inherently a PCI inclined framework. Because of this, the design of device tree (or list) within DPDK is also PCI inclined. A non-PCI device doesn't have a way of being expressed without using hooks started from EAL to PMD.
(Check 'Version Changes' section for changes)
:: Overview of the Proposed Changes ::
Assuming the below graph for a computing node:
device A1 | +==.===='==============.============+ Bus A. | `--> driver A11 \ device A2 `-> driver A12 \______ |CPU | /````` device B1 / | / +==.===='==============.============+ Bus B` | `--> driver B11 device B2 `-> driver B12- 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 deviceIn [15], model assumes that
rte_buswould be the base class using which all the bus implementations would instantiate the objects. This patches takes a much more basic approach, on the same lines of rte_device/rte_driverand rte_pci_device/rte_pci_driver.
This is based on various review comments as well as offline (IRC) discussions.-
rte_busis an abstract class which includes basic methods supported by all buses.
- specific implementation, for example for PCIrte_pci_bus, would extend this class to form their own buses, with their own bus specific device and driver list.
-+-----------------+ |rte_pci_bus | |+---------------+| ||rte_bus || |+---------------+| +-----------------+And example implementation would look like:
.--------------->+-------------------+ | |rte_pci_bus | | | +----------------+| | | |rte_bus <------. | | | name || | | | | scan || | | | | probe || | | | | attach || | | | | detach || | | | +----------------+| | | | pci_driver_list | | | .-------------->pci_device_list | | | | | ... | | | | +-------------------+ | | | | | +-------------------+ | | |rte_pci_device | | '----bus | | | +----------------+| | | |rte_device || | | | bus --------------------------------' | | ... || | +----------------+| | ... | +-------------------+:: Brief about Patch Layout ::
0001~0002: Introducing the basic Bus model and associated test case
0003 : Split the PCI match into a separate function
0004~0005: Introducebus->scanAPIs and integrate with EAL
0006 : Update the Bus and PCI test cases for scanning/probing
0007 : Enable PCI bus and remove code for direct PCI scan/probe from
EAL
0008 : Add device hotplugging over the bus and introduce PCI helpers:: Pending Changes/Caveats ::
1. This patchset only moves the PCI into a bus. And, that movement is also currently part of the EAL (
lib/librte_eal/linux)
Eventual aim is the PCI bus reside in driver/bus/pci2. Though the implementation for bus is common for Linux and BSD, the PCI bus implementation has been done/tested only for Linux.
3.
RTE_REGISTER_BUShas been declared with contructor priority of 101 It is important that Bus is registered *before* drivers are registered. Only way I could find to assure that was via __attribute(contructor(priority)) of GCC. I am not sure how it would behave on other compilers. Any suggestions?
- One suggestion from David Marchand was to use global bus object handles, which I have not implemented for now. If that is common choice, I will change in v3.:: ToDo list ::
- Bump to
librte_ealversion
- Documentation continues to have references to some _old_ PCI symbols:: References ::
[1] http://dpdk.org/ml/archives/dev/2016-November/050186.html
[2] http://dpdk.org/ml/archives/dev/2016-November/050622.html
[3] http://dpdk.org/ml/archives/dev/2016-November/050416.html
[4] http://dpdk.org/ml/archives/dev/2016-November/050567.html
[5] http://dpdk.org/ml/archives/dev/2016-November/050628.html
[6] http://dpdk.org/ml/archives/dev/2016-November/050415.html
[7] http://dpdk.org/ml/archives/dev/2016-November/050443.html
[8] http://dpdk.org/ml/archives/dev/2016-November/050624.html
[9] http://dpdk.org/ml/archives/dev/2016-November/050296.html
[10] http://dpdk.org/ml/archives/dev/2016-December/051349.html
[12] http://dpdk.org/ml/archives/dev/2016-December/052092.html
[13] http://dpdk.org/ml/archives/dev/2016-December/052381.html
[14] http://dpdk.org/ml/archives/dev/2016-December/053302.html
[15] http://dpdk.org/ml/archives/dev/2016-December/053315.html:: Version Changes ::
v6:
- Rearchitecture to bring bus object parallel to rte_device/driver This majorly includes:
--rte_pci_busclass andpci_busas its object for PCI -- bus->attach/detach (hotplugging)
-- removingbus->matchas that is local to an implementation
- rename symbols rte_eal_bus_* to rte_bus_*
- restructuring patches (order) for simplicity
- update totest_pciv5:
- Fix checkpatch error in Patch 0003v4:
- rebase over master (eac901ce)
- Fix a bug intest_buswhile setup and cleanup
- renamerte_eal_get_bustorte_eal_bus_get
- Add helper (iterator) macros for easy bus,device,driver traversal
- removed 0001 patch as it is already merged in master
- fix missingrte_eal_bus_insert_devicesymbol in map filev3:
- rebase over master (c431384c8f)
- revert patch 0001 changes for checkpatch (container_ofmacro)
- qat/rte_qat_cryptodev update forrte_driver->probe
-test_pciupdate for using atest_pci_busfor verification
- some bug fixes based on internal testing.
--rte_eal_dev_attachnot handling devargs
-- blacklisting not workingv2:
- No morebus->probe()
Now,rte_eal_bus_probe()callsrte_driver->probebased on match output
- new functions,rte_eal_pci_probeandrte_eal_pci_removehave been added as glue code between PCI PMDs and PCI Bus
`-> PMDs are updated to use these new functions as callbacks for
rte_driver
- 'default' keyword has been removed from match and scan
- Fix for incorrect changes in mlx* and nicvf*
- Checkpatch fixes
- Some variable checks have been removed from internal functions; functions which are externally visible continue to have such checks
- Some rearrangement of patches:
-- changes to drivers have been separated from EAL changes (but this
does make PCI PMDs non-working for a particular patch)Shreyansh Jain (8):
eal/bus: introduce bus abstraction
test: add basic bus infrastructure tests
pci: split match and probe function
eal/bus: support for scanning of bus
eal: introduce bus scan and probe in EAL
test: update bus and pci unit test cases
eal: enable PCI bus
eal: enable hotplugging of devices on busapp/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 686 ++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++-- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 13 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 13 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 15 +- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 140 +++++ lib/librte_eal/common/eal_common_dev.c | 56 +- lib/librte_eal/common/eal_common_pci.c | 330 ++++++++---- lib/librte_eal/common/eal_private.h | 10 - lib/librte_eal/common/include/rte_bus.h | 206 +++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/common/include/rte_pci.h | 161 +++++-Quoted 9 lines
lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal.c | 13 +- lib/librte_eal/linuxapp/eal/eal_pci.c | 53 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 15 +- 20 files changed, 1646 insertions(+), 238 deletions(-) create mode 100644 app/test/test_bus.c create mode 100644 lib/librte_eal/common/eal_common_bus.c create mode 100644 lib/librte_eal/common/include/rte_bus.h
Quoted 3 lines
All this is excellent, but doesn't go far enough to break the assumptions of 'struct
eth_driver'
That true. But, this is the first step. Next would be:
- unlinking eth_device from pci_device (already upstream by Jan)
- unlinking eth_driver from pci_driver dependency
- Same steps for cryptodev (I will pick this next)
- moving buses to drivers/bus
And some more minor changes making PCI just one bus exposing services; eth_device/eth_driver being just a type of device provided by DPDK without any linkage to bus actual device belongs to.
Quoted 223 lines · Stephen Hemminger
Quoted 209 lines · On Mon, 16 Jan 2017 21:08:19 +0530 Shreyansh Jain <[email protected]>…
Link to v5: [15]
:: Introduction ::
DPDK has been inherently a PCI inclined framework. Because of this, the design of device tree (or list) within DPDK is also PCI inclined. A non-PCI device doesn't have a way of being expressed without using hooks started from EAL to PMD.
(Check 'Version Changes' section for changes)
:: Overview of the Proposed Changes ::
Assuming the below graph for a computing node:
device A1 | +==.===='==============.============+ Bus A. | `--> driver A11 \ device A2 `-> driver A12 \______ |CPU | /````` device B1 / | / +==.===='==============.============+ Bus B` | `--> driver B11 device B2 `-> driver B12- 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 deviceIn [15], model assumes that
rte_buswould be the base class using which all the bus implementations would instantiate the objects. This patches takes a much more basic approach, on the same lines of rte_device/rte_driverand rte_pci_device/rte_pci_driver.
This is based on various review comments as well as offline (IRC) discussions.-
rte_busis an abstract class which includes basic methods supported by all buses.
- specific implementation, for example for PCIrte_pci_bus, would extend this class to form their own buses, with their own bus specific device and driver list.
-+-----------------+ |rte_pci_bus | |+---------------+| ||rte_bus || |+---------------+| +-----------------+And example implementation would look like:
.--------------->+-------------------+ | |rte_pci_bus | | | +----------------+| | | |rte_bus <------. | | | name || | | | | scan || | | | | probe || | | | | attach || | | | | detach || | | | +----------------+| | | | pci_driver_list | | | .-------------->pci_device_list | | | | | ... | | | | +-------------------+ | | | | | +-------------------+ | | |rte_pci_device | | '----bus | | | +----------------+| | | |rte_device || | | | bus --------------------------------' | | ... || | +----------------+| | ... | +-------------------+:: Brief about Patch Layout ::
0001~0002: Introducing the basic Bus model and associated test case
0003 : Split the PCI match into a separate function
0004~0005: Introducebus->scanAPIs and integrate with EAL
0006 : Update the Bus and PCI test cases for scanning/probing
0007 : Enable PCI bus and remove code for direct PCI scan/probe from
EAL
0008 : Add device hotplugging over the bus and introduce PCI helpers:: Pending Changes/Caveats ::
1. This patchset only moves the PCI into a bus. And, that movement is also currently part of the EAL (
lib/librte_eal/linux)
Eventual aim is the PCI bus reside in driver/bus/pci2. Though the implementation for bus is common for Linux and BSD, the PCI bus implementation has been done/tested only for Linux.
3.
RTE_REGISTER_BUShas been declared with contructor priority of 101 It is important that Bus is registered *before* drivers are registered. Only way I could find to assure that was via __attribute(contructor(priority)) of GCC. I am not sure how it would behave on other compilers. Any suggestions?
- One suggestion from David Marchand was to use global bus object handles, which I have not implemented for now. If that is common choice, I will change in v3.:: ToDo list ::
- Bump to
librte_ealversion
- Documentation continues to have references to some _old_ PCI symbols:: References ::
[1] http://dpdk.org/ml/archives/dev/2016-November/050186.html
[2] http://dpdk.org/ml/archives/dev/2016-November/050622.html
[3] http://dpdk.org/ml/archives/dev/2016-November/050416.html
[4] http://dpdk.org/ml/archives/dev/2016-November/050567.html
[5] http://dpdk.org/ml/archives/dev/2016-November/050628.html
[6] http://dpdk.org/ml/archives/dev/2016-November/050415.html
[7] http://dpdk.org/ml/archives/dev/2016-November/050443.html
[8] http://dpdk.org/ml/archives/dev/2016-November/050624.html
[9] http://dpdk.org/ml/archives/dev/2016-November/050296.html
[10] http://dpdk.org/ml/archives/dev/2016-December/051349.html
[12] http://dpdk.org/ml/archives/dev/2016-December/052092.html
[13] http://dpdk.org/ml/archives/dev/2016-December/052381.html
[14] http://dpdk.org/ml/archives/dev/2016-December/053302.html
[15] http://dpdk.org/ml/archives/dev/2016-December/053315.html:: Version Changes ::
v6:
- Rearchitecture to bring bus object parallel to rte_device/driver This majorly includes:
--rte_pci_busclass andpci_busas its object for PCI -- bus->attach/detach (hotplugging)
-- removingbus->matchas that is local to an implementation
- rename symbols rte_eal_bus_* to rte_bus_*
- restructuring patches (order) for simplicity
- update totest_pciv5:
- Fix checkpatch error in Patch 0003v4:
- rebase over master (eac901ce)
- Fix a bug intest_buswhile setup and cleanup
- renamerte_eal_get_bustorte_eal_bus_get
- Add helper (iterator) macros for easy bus,device,driver traversal
- removed 0001 patch as it is already merged in master
- fix missingrte_eal_bus_insert_devicesymbol in map filev3:
- rebase over master (c431384c8f)
- revert patch 0001 changes for checkpatch (container_ofmacro)
- qat/rte_qat_cryptodev update forrte_driver->probe
-test_pciupdate for using atest_pci_busfor verification
- some bug fixes based on internal testing.
--rte_eal_dev_attachnot handling devargs
-- blacklisting not workingv2:
- No morebus->probe()
Now,rte_eal_bus_probe()callsrte_driver->probebased on match output
- new functions,rte_eal_pci_probeandrte_eal_pci_removehave been added as glue code between PCI PMDs and PCI Bus
`-> PMDs are updated to use these new functions as callbacks for
rte_driver
- 'default' keyword has been removed from match and scan
- Fix for incorrect changes in mlx* and nicvf*
- Checkpatch fixes
- Some variable checks have been removed from internal functions; functions which are externally visible continue to have such checks
- Some rearrangement of patches:
-- changes to drivers have been separated from EAL changes (but this
does make PCI PMDs non-working for a particular patch)Shreyansh Jain (8):
eal/bus: introduce bus abstraction
test: add basic bus infrastructure tests
pci: split match and probe function
eal/bus: support for scanning of bus
eal: introduce bus scan and probe in EAL
test: update bus and pci unit test cases
eal: enable PCI bus
eal: enable hotplugging of devices on busapp/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 686 ++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++-- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 13 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 13 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 15 +- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 140 +++++ lib/librte_eal/common/eal_common_dev.c | 56 +- lib/librte_eal/common/eal_common_pci.c | 330 ++++++++---- lib/librte_eal/common/eal_private.h | 10 - lib/librte_eal/common/include/rte_bus.h | 206 +++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/common/include/rte_pci.h | 161 +++++-Quoted 9 lines
lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal.c | 13 +- lib/librte_eal/linuxapp/eal/eal_pci.c | 53 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 15 +- 20 files changed, 1646 insertions(+), 238 deletions(-) create mode 100644 app/test/test_bus.c create mode 100644 lib/librte_eal/common/eal_common_bus.c create mode 100644 lib/librte_eal/common/include/rte_bus.h
Quoted 3 lines
All this is excellent, but doesn't go far enough to break the assumptions of 'struct
eth_driver'
That is true. But, this is the first step of many steps. Next would be:
- unlinking eth_device from pci_device (already upstream by Jan)
- unlinking eth_driver from pci_driver dependency
- Same steps for cryptodev (I will pick this next)
- moving buses to drivers/bus
And some more minor changes making PCI just one bus exposing services; eth_device/eth_driver being just a type of device provided by DPDK without any linkage to bus actual device belongs to.
v7 cover Introducing EAL Bus-Device-Driver Model
In reply to Shreyansh JainLink to v6: [16]
:: Introduction ::
DPDK has been inherently a PCI inclined framework. Because of this, the design of device tree (or list) within DPDK is also PCI inclined. A non-PCI device doesn't have a way of being expressed without using hooks started from EAL to PMD.
(Check 'Version Changes' section for changes)
:: Overview of the Proposed Changes ::
Assuming the below graph for a computing node:
device A1
|
+==.===='==============.============+ Bus A.
| `--> driver A11 \
device A2 `-> driver A12 \______
|CPU |
/`````
device B1 /
| /
+==.===='==============.============+ Bus B`
| `--> driver B11
device B2 `-> driver B12 - 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
In [15], model assumes that rte_bus would be the base class using which all the bus implementations would instantiate the objects. This patches takes a much more basic approach, on the same lines of rte_device/ rte_driver and rte_pci_device/rte_pci_driver.
This is based on various review comments as well as offline (IRC) discussions.
- rte_bus is an abstract class which includes basic methods supported by all buses.
- specific implementation, for example for PCI rte_pci_bus, would extend this class to form their own buses, with their own bus specific device and driver list.
-
+-----------------+ |rte_pci_bus | |+---------------+| ||rte_bus || |+---------------+| +-----------------+
And example implementation would look like:
.--------------->+-------------------+
| |rte_pci_bus |
| | +----------------+|
| | |rte_bus <------.
| | | name || |
| | | scan || |
| | | probe || |
| | | attach || |
| | | detach || |
| | +----------------+| |
| | pci_driver_list | |
| .-------------->pci_device_list | |
| | | ... | |
| | +-------------------+ |
| | |
| +-------------------+ |
| |rte_pci_device | |
'----bus | |
| +----------------+| |
| |rte_device || |
| | bus --------------------------------'
| | ... ||
| +----------------+|
| ... |
+-------------------+:: Brief about Patch Layout ::
0001~0002: Introducing the basic Bus model and associated test case
0003 : Split the PCI match into a separate function
0004~0005: Introduce bus->scan/probe callbacks
0006 : Integrate bus with EAL, without removing existing PCI probe/
scan from EAL
0007 : Update the Bus and PCI test cases for scanning/probing
0008 : Enable PCI bus and remove code for direct PCI scan/probe from
EAL
0009 : Add device hotplugging over the bus and introduce PCI helpers
:: Pending Changes/Caveats ::
1. This patchset only moves the PCI into a bus. And, that movement is also currently part of the EAL (lib/librte_eal/linux)
Eventual aim is the PCI bus reside in driver/bus/pci
2. Though the implementation for bus is common for Linux and BSD, the PCI bus implementation has been done/tested only for Linux.
3. RTE_REGISTER_BUS has been declared with contructor priority of 101 It is important that Bus is registered *before* drivers are registered. Only way I could find to assure that was via __attribute(contructor(priority)) of GCC. I am not sure how it would behave on other compilers. Any suggestions?
- One suggestion from David Marchand was to use global bus object handles, which I have not implemented for now. If that is common choice, I will change in v3.
4. Hotplugging has been introduced over Bus with a caveat - it would only work for ports/NICs already scanned and available in the bus list.
:: ToDo list ::
- Bump to librte_eal version
- Documentation continues to have references to some _old_ PCI symbols
:: References ::
[1] http://dpdk.org/ml/archives/dev/2016-November/050186.html
[2] http://dpdk.org/ml/archives/dev/2016-November/050622.html
[3] http://dpdk.org/ml/archives/dev/2016-November/050416.html
[4] http://dpdk.org/ml/archives/dev/2016-November/050567.html
[5] http://dpdk.org/ml/archives/dev/2016-November/050628.html
[6] http://dpdk.org/ml/archives/dev/2016-November/050415.html
[7] http://dpdk.org/ml/archives/dev/2016-November/050443.html
[8] http://dpdk.org/ml/archives/dev/2016-November/050624.html
[9] http://dpdk.org/ml/archives/dev/2016-November/050296.html
[10] http://dpdk.org/ml/archives/dev/2016-December/051349.html - v1
[12] http://dpdk.org/ml/archives/dev/2016-December/052092.html - v2
[13] http://dpdk.org/ml/archives/dev/2016-December/052381.html - v3
[14] http://dpdk.org/ml/archives/dev/2016-December/053302.html - v4
[15] http://dpdk.org/ml/archives/dev/2016-December/053315.html - v5
[16] http://dpdk.org/ml/archives/dev/2017-January/055120.html - v6
:: Version Changes ::
v7:
- update to rte_pci_match for const parameters
- remove unnecessary log messages in probe; moved _after_ matching of device and driver
- bug fixes in attach/detach methods
- PCI disable for debugging was missed (from rte_eal_pci_init) in v6
- Split patch 5 into two: one for scan handler, another for integration with EAL
v6:
- Rearchitecture to bring bus object parallel to rte_device/driver This majorly includes:
-- rte_pci_bus class and pci_bus as its object for PCI -- bus->attach/detach (hotplugging)
-- removing bus->match as that is local to an implementation
- rename symbols rte_eal_bus_* to rte_bus_*
- restructuring patches (order) for simplicity
- update to test_pci
v5:
- Fix checkpatch error in Patch 0003
v4:
- rebase over master (eac901ce)
- Fix a bug in test_bus while setup and cleanup
- rename rte_eal_get_bus to rte_eal_bus_get
- Add helper (iterator) macros for easy bus,device,driver traversal
- removed 0001 patch as it is already merged in master
- fix missing rte_eal_bus_insert_device symbol in map file
v3:
- rebase over master (c431384c8f)
- revert patch 0001 changes for checkpatch (container_of macro)
- qat/rte_qat_cryptodev update for rte_driver->probe
- test_pci update for using a test_pci_bus for verification
- some bug fixes based on internal testing.
-- rte_eal_dev_attach not handling devargs
-- blacklisting not working
v2:
- No more bus->probe()
Now, rte_eal_bus_probe() calls rte_driver->probe based on match output
- new functions, rte_eal_pci_probe and rte_eal_pci_remove have been added as glue code between PCI PMDs and PCI Bus
`-> PMDs are updated to use these new functions as callbacks for
rte_driver
- 'default' keyword has been removed from match and scan
- Fix for incorrect changes in mlx* and nicvf*
- Checkpatch fixes
- Some variable checks have been removed from internal functions; functions which are externally visible continue to have such checks
- Some rearrangement of patches:
-- changes to drivers have been separated from EAL changes (but this
does make PCI PMDs non-working for a particular patch)
Shreyansh Jain (9):
eal/bus: introduce bus abstraction
test: add basic bus infrastructure tests
pci: split match and probe function
eal/bus: support for scanning of bus
eal/bus: introduce support for bus probing
eal: integrate bus scan and probe with EAL
test: update bus and pci unit test cases
eal: enable PCI bus
eal: enable hotplugging of devices on bus
app/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 686 ++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++-- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 13 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 17 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 15 +- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 140 +++++ lib/librte_eal/common/eal_common_dev.c | 56 +- lib/librte_eal/common/eal_common_pci.c | 334 ++++++++---- lib/librte_eal/common/eal_private.h | 10 - lib/librte_eal/common/include/rte_bus.h | 200 +++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/common/include/rte_pci.h | 148 ++++- lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal.c | 13 +- lib/librte_eal/linuxapp/eal/eal_pci.c | 57 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 15 +- 20 files changed, 1632 insertions(+), 245 deletions(-) create mode 100644 app/test/test_bus.c create mode 100644 lib/librte_eal/common/eal_common_bus.c create mode 100644 lib/librte_eal/common/include/rte_bus.h
Signature · 1 line
2.7.4
PATCH v7 1/9 eal/bus: introduce bus abstraction
This patch introduces the rte_bus abstraction for EAL.
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' base class which would be extended for specific implementations. It also introduces Bus registration and deregistration functions.
An example implementation would be like:
.--------------->+-------------------+
| |rte_pci_bus |
| | +----------------+|
| | |rte_bus <------.
| | | name || |
| | | scan || |
| | | match || |
| | | probe || |
| | | remove || |
| | | ... || |
| | +----------------+| |
| | pci_driver_list | |
| .-------------->pci_device_list | |
| | | ... | |
| | +-------------------+ |
| | |
| +-------------------+ |
| |rte_pci_device | |
'----bus | |
| +----------------+| |
| |rte_device || |
| | bus --------------------------------'
| | ... ||
| +----------------+|
| ... |
+-------------------+--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 10 +++ lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 97 +++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 111 ++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/rte_eal_version.map | 10 +++ 8 files changed, 232 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
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -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
lib/librte_eal/bsdapp/eal/rte_eal_version.map +10 -0
@@ -174,3 +174,13 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_list; + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
lib/librte_eal/common/Makefile +1 -1
@@ -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
lib/librte_eal/common/eal_common_bus.c new file +97 -0
97 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h new file +111 -0
111 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +1 -0
@@ -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 */ const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -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
lib/librte_eal/linuxapp/eal/rte_eal_version.map +10 -0
@@ -178,3 +178,13 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_list; + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
Signature · 1 line
2.7.4
PATCH v7 2/9 test: add basic bus infrastructure tests
In reply to Shreyansh JainVerification of bus registration, deregistration methods.
--- app/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 359 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 3 + 4 files changed, 365 insertions(+), 1 deletion(-) create mode 100644 app/test/test_bus.c
app/test/Makefile +1 -1
@@ -94,7 +94,7 @@ SRCS-y += test_cycles.c SRCS-y += test_spinlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c - +SRCS-y += test_bus.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c SRCS-y += test_pmd_perf.c
app/test/test.h +2 -0
@@ -236,6 +236,8 @@ int commands_init(void);int test_pci (void );int test_pci_run; +int test_bus (void ); +int test_mp_secondary (void );int test_set_rxtx_conf (cmdline_fixed_string_t mode);
app/test/test_bus.c new file +359 -0
359 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +3 -0
@@ -56,6 +56,9 @@ extern "C" {/** Double linked list of buses */ TAILQ_HEAD (rte_bus_list, rte_bus); +/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list; +/** * A structure describing a generic bus. */
Signature · 1 line
2.7.4
PATCH v7 3/9 pci: split match and probe function
In reply to Shreyansh JainMatching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev).
Splitting the matching function into a public fn rte_pci_match.
--- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_pci.c | 189 +++++++++++++----------- lib/librte_eal/common/include/rte_pci.h | 15 ++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 121 insertions(+), 85 deletions(-)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
@@ -182,5 +182,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match; } DPDK_16.11;
lib/librte_eal/common/eal_common_pci.c +104 -85
233 lines not on this page · raw message
lib/librte_eal/common/include/rte_pci.h +15 -0
@@ -371,6 +371,21 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,int rte_eal_pci_scan (void );/** +* Match the PCI Driver and Device using the ID Table +* +* @param pci_drv +* PCI driver from which ID table would be extracted +* @param pci_dev +* PCI device to match against the driver +* @return +* 0 for successful match +* !0 for unsuccessful match +*/ +int +rte_pci_match (const struct rte_pci_driver *pci_drv, +const struct rte_pci_device *pci_dev); + +/** * Probe the PCI bus for registered drivers. * * Scan the content of the PCI bus, and call the probe() function for
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -0
@@ -186,5 +186,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match; } DPDK_16.11;
Signature · 1 line
2.7.4
PATCH v7 4/9 eal/bus: support for scanning of bus
In reply to Shreyansh JainScan for bus discovers the devices available on the bus and adds them to a bus specific device list. Each bus mandatorily implements this method.
Test cases for Bus are also updated by this patch.
--- app/test/test_bus.c | 175 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_common_bus.c | 2 + lib/librte_eal/common/include/rte_bus.h | 18 ++++ 3 files changed, 195 insertions(+)
app/test/test_bus.c +175 -0
@@ -106,10 +106,26 @@ struct dummy_bus_map {struct rte_bus_list orig_bus_list =TAILQ_HEAD_INITIALIZER (orig_bus_list); +/* Forward declarations for callbacks from bus */ + +/* Bus A +* Scan would register devA1 and devA2 to bus +*/ +static int scan_fn_for_busA (void ); + +/* Bus B +* Scan would register devB1 and devB2 to bus +*/ +static int scan_fn_for_busB (void ); + +/* generic implementations wrapped around by above declarations */ +static int generic_scan_fn (struct rte_bus *bus); +struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , + .scan = scan_fn_for_busA, }, };
@@ -117,6 +133,7 @@ struct dummy_bus busB = { .name = "busB_impl", /* busB */ .bus = { .name = "busB", + .scan = scan_fn_for_busB, }, };
@@ -226,9 +243,81 @@ dump_device_tree(void)printf ("------>8-------\n" ); } +/* @internal +* Move over the bus_map and find the entry matching the bus object +* passed as argument. +* For each device in that bus_map list, register. +* +* @param bus +* bus to scan againt test entry +* @return +* 0 for successful scan, even if no devices are found +* !0 for any error in scanning (like, invalid bus) +*/ +static int +generic_scan_fn (struct rte_bus *bus) +{ +int i =0 ; +struct dummy_device *ddev =NULL ; +struct dummy_bus_map *dbmap =NULL ; +struct dummy_bus *db =NULL ; + +if (!bus) +return -1 ; + +/* Extract the device tree node using the bus passed */ +for (i =0 ; bus_map[i].name; i++) { +if (!strcmp (bus_map[i].name, bus->name)) { + dbmap = &bus_map[i]; +break ; + } + } + +if (!dbmap) +return -1 ; + + db = dbmap->dbus; + +/* For all the devices in the device tree (bus_map), add device */ +for (i =0 ; dbmap->ddevices[i]; i++) { + ddev = dbmap->ddevices[i]; +TAILQ_INSERT_TAIL (&db->device_list, ddev, next); + ddev->dev.bus = bus; + } + +return 0 ; +} + +int +scan_fn_for_busA (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busA" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} + +int +scan_fn_for_busB (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busB" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} +static int test_bus_setup (void ) { +int i =0 ;struct rte_bus *bus_p =NULL ;/* Preserve the original bus list before executing test */
@@ -238,6 +327,13 @@ test_bus_setup(void)TAILQ_INSERT_TAIL (&orig_bus_list, bus_p, next); } +/* Initialize the bus lists */ +for (i =0 ; bus_map[i].name; i++) { +TAILQ_INIT (&bus_map[i].dbus->device_list); +TAILQ_INIT (&bus_map[i].dbus->driver_list); + } + +dump_device_tree ();return 0 ; }
@@ -336,6 +432,79 @@ test_bus_unregistration(void)return 0 ; } +static int +test_device_unregistration_on_bus (void ) +{ +int i; +struct rte_bus *bus =NULL ; +struct dummy_device *ddev; +struct dummy_bus *dbus; + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); +if (!bus) { +printf ("Unable to find bus (%s)\n" , + bus_map[i].name); +return -1 ; + } + + dbus = container_of(bus, struct dummy_bus, bus); +/* For bus 'bus', unregister all devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +TAILQ_REMOVE (&dbus->device_list, ddev, next); + } + } + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); + dbus = container_of(bus, struct dummy_bus, bus); + +if (!TAILQ_EMPTY (&dbus->device_list)) { +printf ("Unable to remove all devices on bus (%s)\n" , + bus->name); +return -1 ; + } + } + +/* All devices from all buses have been removed */ +printf ("All devices on all buses unregistered.\n" ); +dump_device_tree (); + +return 0 ; +} + +/* @internal +* For each bus registered, call the scan function to identify devices +* on the bus. +* +* @param void +* @return +* 0 for successful scan +* !0 for unsuccessful scan +* +*/ +static int +test_bus_scan (void ) +{ +int ret; +struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { +/* Call the scan function for each bus */ + ret = bus->scan (); +if (ret) { +printf ("Scan of buses failed.\n" ); +return -1 ; + } + } + +printf ("Scan of all buses completed.\n" ); +dump_device_tree (); + +return 0 ; +} + +int test_bus (void ) {
@@ -346,6 +515,12 @@ test_bus(void)if (test_bus_registration ())return -1 ; +if (test_bus_scan ()) +return -1 ; + +if (test_device_unregistration_on_bus ()) +return -1 ; +if (test_bus_unregistration ())return -1 ;
lib/librte_eal/common/eal_common_bus.c +2 -0
@@ -51,6 +51,8 @@ rte_bus_register(struct rte_bus *bus) {RTE_VERIFY (bus);RTE_VERIFY (bus->name &&strlen (bus->name)); +/* A bus should mandatorily have the scan implemented */ +RTE_VERIFY (bus->scan);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (INFO ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +18 -0
@@ -60,11 +60,29 @@ TAILQ_HEAD(rte_bus_list, rte_bus);extern struct rte_bus_list rte_bus_list;/** +* Bus specific scan for devices attached on the bus. +* For each bus object, the scan would be reponsible for finding devices and +* adding them to its private device list. +* +* A bus should mandatorily implement this method. +* +* Generic bus object passed only as a helper for implementation to find +* their respective registered bus object. Implementations can choose not +* to use this variable. +* +* @return +* 0 for successful scan +* !0 (<0) for unsuccessful scan with error value +*/ +typedef int (*rte_bus_scan_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ +rte_bus_scan_t scan;/**< Scan for devices attached to bus */ };/**
Signature · 1 line
2.7.4
PATCH v7 5/9 eal/bus: introduce support for bus probing
In reply to Shreyansh JainBus implementations can implement a probe handler to match the devices scanned against the drivers registered.
This patch introduces the callback which would be implemented for PCI in subsequent patch.
--- lib/librte_eal/common/eal_common_bus.c | 1 + lib/librte_eal/common/include/rte_bus.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+)
lib/librte_eal/common/eal_common_bus.c +1 -0
@@ -53,6 +53,7 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->name &&strlen (bus->name));/* A bus should mandatorily have the scan implemented */ RTE_VERIFY (bus->scan); +RTE_VERIFY (bus->probe);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (INFO ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +18 -0
@@ -77,12 +77,30 @@ extern struct rte_bus_list rte_bus_list;typedef int (*rte_bus_scan_t )(void );/** +* Implementation specific probe function which is responsible for linking +* devices on that bus with applicable drivers. +* +* This is called while iterating over each registered bus. Bus object is +* passed along assuming this is wrapped around (embedded) by Implementation +* specific bus object. +* +* @param bus +* Generic bus object which was registered with EAL +* +* @return +* 0 for successful probe +* !0 for any error while probing +*/ +typedef int (*rte_bus_probe_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ +rte_bus_probe_t probe;/**< Probe devices on bus */ };/**
Signature · 1 line
2.7.4
PATCH v7 6/9 eal: integrate bus scan and probe with EAL
In reply to Shreyansh JainEach bus implementation defines their own callbacks for scanning its bus and probing devices available on the bus. Enable EAL to call bus specific scan and probe functions during DPDK initialization.
Existing PCI scan/probe continues to exist. It will removed in subsequent patches.
--- lib/librte_eal/bsdapp/eal/eal.c | 8 +++ lib/librte_eal/bsdapp/eal/eal_pci.c | 11 ++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 + lib/librte_eal/common/eal_common_bus.c | 40 +++++++++++++++ lib/librte_eal/common/eal_common_pci.c | 33 ++++++++++++ lib/librte_eal/common/include/rte_bus.h | 19 +++++++ lib/librte_eal/common/include/rte_pci.h | 68 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 8 +++ lib/librte_eal/linuxapp/eal/eal_pci.c | 15 ++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 + 10 files changed, 206 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +8 -0
@@ -64,6 +64,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
@@ -577,6 +578,9 @@ rte_eal_init(int argc, char **argv) rte_config.master_lcore, thread_id, cpuset, ret == 0 ? "" : "..."); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
@@ -613,6 +617,10 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" ); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/bsdapp/eal/eal_pci.c +11 -0
@@ -673,3 +673,14 @@ rte_eal_pci_init(void) }return 0 ; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), + .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS (PCI_BUS_NAME , rte_pci_bus.bus);
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -0
@@ -182,6 +182,8 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_bus_probe; + rte_bus_scan; rte_pci_match; } DPDK_16.11;
lib/librte_eal/common/eal_common_bus.c +40 -0
@@ -67,6 +67,46 @@ rte_bus_unregister(struct rte_bus *bus)RTE_LOG (INFO ,EAL ,"Unregistered [%s] bus.\n" , bus->name); } +/* Scan all the buses for registering devices */ +int +rte_bus_scan (void ) +{ +int ret; +struct rte_bus *bus =NULL ; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->scan (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Scan for (%s) bus failed.\n" , + bus->name); +/* Error in scanning any bus stops the EAL init. */ +return ret; + } + } + +return 0 ; +} + +/* Call bus specific probe */ +int +rte_bus_probe (void ) +{ +int ret; +struct rte_bus *bus; + +/* For each bus registered with EAL */ + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->probe (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Bus (%s) probe failed.\n" , + bus->name); +return ret; + } + } + +return 0 ; +} +/* dump one bus info */ static int bus_dump_one (FILE *f,struct rte_bus *bus)
lib/librte_eal/common/eal_common_pci.c +33 -0
@@ -71,6 +71,7 @@#include <rte_interrupts.h> #include <rte_log.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_per_lcore.h> #include <rte_memory.h>
@@ -508,3 +509,35 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver)rte_eal_driver_unregister (&driver->driver);TAILQ_REMOVE (&pci_driver_list, driver, next); } + +/* Add a PCI device to PCI Bus */ +void +rte_eal_pci_add_device (struct rte_pci_bus *pci_bus, +struct rte_pci_device *pci_dev) +{ +TAILQ_INSERT_TAIL (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus = &pci_bus->bus; +} + +/* Insert a PCI device into a predefined position in PCI bus */ +void +rte_eal_pci_insert_device (struct rte_pci_device *exist_pci_dev, +struct rte_pci_device *new_pci_dev) +{ +TAILQ_INSERT_BEFORE (exist_pci_dev, new_pci_dev, next); +/* Update Bus references */ + new_pci_dev->device.bus = exist_pci_dev->device.bus; +} + +/* Remove a PCI device from PCI bus */ +void +rte_eal_pci_remove_device (struct rte_pci_device *pci_dev) +{ +struct rte_pci_bus *pci_bus; + + pci_bus = container_of(pci_dev->device.bus, struct rte_pci_bus, bus); +TAILQ_REMOVE (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus =NULL ; +}
lib/librte_eal/common/include/rte_bus.h +19 -0
@@ -122,6 +122,25 @@ void rte_bus_register(struct rte_bus *bus);void rte_bus_unregister (struct rte_bus *bus);/** +* Scan all the buses attached to the framework. +* +* @return +* 0 in case of success in scanning all buses +* !0 in case of failure to scan +*/ +int rte_bus_scan (void ); + +/** +* For each device on the bus, perform a driver 'match' and call the +* bus's probe for device initialization. +* +* @return +* 0 for successful match/probe +* !0 otherwise +*/ +int rte_bus_probe (void ); + +/** * Dump information of all the buses registered with EAL. * * @param f
lib/librte_eal/common/include/rte_pci.h +68 -0
98 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal.c +8 -0
@@ -69,6 +69,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
@@ -844,6 +845,9 @@ rte_eal_init(int argc, char **argv)if (rte_eal_intr_init () <0 )rte_panic ("Cannot init interrupt-handling thread\n" ); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
@@ -884,6 +888,10 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" ); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/linuxapp/eal/eal_pci.c +15 -0
@@ -35,6 +35,7 @@#include <dirent.h> #include <rte_log.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_eal_memconfig.h> #include <rte_malloc.h>
@@ -54,6 +55,9 @@* IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it). */ +/* Forward declaration of PCI bus */ +struct rte_pci_bus rte_pci_bus; +static int pci_get_kernel_driver_by_path (const char *filename,char *dri_name) {
@@ -723,3 +727,14 @@ rte_eal_pci_init(void)return 0 ; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), + .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS (PCI_BUS_NAME , rte_pci_bus.bus);
lib/librte_eal/linuxapp/eal/rte_eal_version.map +2 -0
@@ -186,6 +186,8 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_bus_probe; + rte_bus_scan; rte_pci_match; } DPDK_16.11;
Signature · 1 line
2.7.4
PATCH v7 7/9 test: update bus and pci unit test cases
In reply to Shreyansh Jain--- app/test/test_bus.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 266 insertions(+), 50 deletions(-)
app/test/test_bus.c +152 -0
@@ -120,12 +120,15 @@ static int scan_fn_for_busB(void);/* generic implementations wrapped around by above declarations */ static int generic_scan_fn (struct rte_bus *bus); +static int generic_probe_fn (void ); +static int dummy_match_fn (struct rte_driver *drv,struct rte_device *dev);struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , .scan = scan_fn_for_busA, + .probe = generic_probe_fn, }, };
@@ -134,6 +137,7 @@ struct dummy_bus busB = { .bus = { .name = "busB", .scan = scan_fn_for_busB, + .probe = generic_probe_fn, }, };
@@ -288,6 +292,46 @@ generic_scan_fn(struct rte_bus *bus)return 0 ; } +/* @internal +* Obtain bus from driver object. Match the address of rte_device object +* with all the devices associated with that bus. +* +* Being a test function, all this does is validate that device object +* provided is available on the same bus to which driver is registered. +* +* @param drv +* driver to match with +* @param dev +* device object +* @return +* 0 for successful match +* !0 for failed match +*/ +static int +dummy_match_fn(struct rte_driver *drv __rte_unused, struct rte_device *dev) +{ +struct rte_bus *bus; +struct dummy_device *ddev =NULL ; +struct dummy_device *ddev_as_arg; +struct dummy_bus *dbus =NULL ; + +/* Match is based entirely on address of 'dev' and 'dev_p' extracted +* from bus->device_list. +*/ + +/* a driver is registered with the bus *before* the scan. */ + bus = dev->bus; + dbus = container_of(bus, struct dummy_bus, bus); + ddev_as_arg = container_of(dev, struct dummy_device, dev); + + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +if (ddev == ddev_as_arg) +return 0 ; + } + +return 1 ; +} +int scan_fn_for_busA (void ) {struct dummy_bus_map *dbm;
@@ -504,6 +548,110 @@ test_bus_scan(void)return 0 ; } +/* +* +*/ +static int +generic_probe_fn (void ) +{ +int ret =0 ; +int i, j; +struct rte_driver *drv; +struct rte_device *dev; +struct dummy_bus *dbus =NULL ; +struct dummy_device *ddev =NULL ; +struct dummy_driver *ddrv =NULL ; + +/* In case of this test: +* 1. for each bus in rte_bus_list +* 2. for each device on that bus (bus specific->device_list) +* 3. for each driver on that bus (bus specific->driver_list) +* 4. call match +* 5. link driver and device +* 6. Verify the linkage. +*/ +for (i =0 ; bus_map[i].name; i++) { +/* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + +/* Looping over all scanned devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +/* There is a list of drivers within dummy_bus_map. +* In case of PMDs, this would be driver registration +* APIs/list +*/ +for (j =0 ; bus_map[i].ddrivers[j]; j++) { + ddrv = bus_map[i].ddrivers[j]; + + drv = &ddrv->drv; + dev = &ddev->dev; + ret =dummy_match_fn (drv, dev); +if (!ret) { +/* As match is generic, it always +* results in dev->drv pointing to +* first driver entry in bus_map[i] +*/ + dev->driver = drv; + dev->bus = &dbus->bus; + } +/* Else, continue */ + } + } + } + +/* Verify the linkage. All devices belonging to a bus_map[i] +* should have same driver (first driver entry of bus_map[i]) +*/ +for (i =0 ; bus_map[i].name; i++) { + ddrv = bus_map[i].ddrivers[0 ]; + drv = &ddrv->drv; + +for (j =0 ; bus_map[i].ddevices[j]; j++) { + ddev = bus_map[i].ddevices[j]; + dev = &ddev->dev; +if (dev->driver != drv) { +printf ("Incorrect driver<->device linkage.\n" ); +return -1 ; + } + } + } + +return 0 ; +} + +/* @internal +* Function to perform 'probe' and link devices and drivers on a bus. +* This would work over all the buses registered, and all devices and drivers +* registered with it - call match on each pair. +* +* @param void +* @return +* 0 for successful probe +* !0 for failure in probe +* +*/ +static int +test_probe_on_bus (void ) +{ +int ret =0 ; +int i; +struct dummy_bus *dbus; +struct rte_bus *bus; + +for (i =0 ; bus_map[i].name; i++) { +/* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + bus = &dbus->bus; + ret = bus->probe (); +if (ret) +printf ("Probe for %s failed.\n" , bus_map[i].name); + } + +printf ("Probe on all buses successful.\n" ); +dump_device_tree (); + +return 0 ; +}int test_bus (void )
@@ -518,6 +666,10 @@ test_bus(void)if (test_bus_scan ())return -1 ; +/* Now that the devices and drivers are registered, perform probe */ +if (test_probe_on_bus ()) +return -1 ; +if (test_device_unregistration_on_bus ())return -1 ;
app/test/test_pci.c +114 -50
271 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v7 8/9 eal: enable PCI bus
In reply to Shreyansh JainRemove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.
--- lib/librte_eal/bsdapp/eal/eal.c | 7 ----- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 -- lib/librte_eal/common/eal_common_pci.c | 36 +++++++++++---------- lib/librte_eal/common/eal_private.h | 10 ------ lib/librte_eal/common/include/rte_pci.h | 22 +++++-------- lib/librte_eal/linuxapp/eal/eal.c | 7 ----- lib/librte_eal/linuxapp/eal/eal_pci.c | 42 +++++++++---------------- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 -- 9 files changed, 45 insertions(+), 87 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +0 -7
@@ -562,9 +562,6 @@ rte_eal_init(int argc, char **argv)if (rte_eal_timer_init () <0 )rte_panic ("Cannot init HPET or TSC timers\n" ); -if (rte_eal_pci_init () <0 ) -rte_panic ("Cannot init PCI\n" ); -eal_check_mem_on_local_socket ();if (eal_plugins_init () <0 )
@@ -613,10 +610,6 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); -/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
lib/librte_eal/bsdapp/eal/eal_pci.c +4 -0
@@ -365,6 +365,10 @@ rte_eal_pci_scan(void) .matches = &matches[0], }; +/* for debug purposes, PCI can be disabled */ +if (internal_config.no_pci) +return 0 ; + fd =open ("/dev/pci" ,O_RDONLY );if (fd <0 ) {RTE_LOG (ERR ,EAL ,"%s(): error opening /dev/pci\n" , __func__);
lib/librte_eal/bsdapp/eal/rte_eal_version.map +0 -2
@@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc;
lib/librte_eal/common/eal_common_pci.c +19 -17
@@ -83,11 +83,6 @@#include "eal_private.h" -struct pci_driver_list pci_driver_list = -TAILQ_HEAD_INITIALIZER (pci_driver_list); -struct pci_device_list pci_device_list = -TAILQ_HEAD_INITIALIZER (pci_device_list); -#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"const char *pci_get_sysfs_path (void )
@@ -315,7 +310,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)if (dev->driver !=NULL )return 0 ; - TAILQ_FOREACH(dr, &pci_driver_list, next) { +FOREACH_DRIVER_ON_PCIBUS (dr) { rc =rte_eal_pci_probe_one_driver (dr, dev);if (rc <0 )/* negative value is an error */
@@ -342,7 +337,7 @@ pci_detach_all_drivers(struct rte_pci_device *dev)if (dev ==NULL )return -1 ; - TAILQ_FOREACH(dr, &pci_driver_list, next) { +FOREACH_DRIVER_ON_PCIBUS (dr) { rc =rte_eal_pci_detach_dev (dr, dev);if (rc <0 )/* negative value is an error */
@@ -363,6 +358,7 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr) {struct rte_pci_device *dev =NULL ; +int ret =0 ;if (addr ==NULL )
@@ -374,7 +370,7 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)if (pci_update_device (addr) <0 ) goto err_return; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ;
@@ -404,7 +400,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)if (addr ==NULL )return -1 ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ;
@@ -412,7 +408,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)if (ret <0 ) goto err_return; -TAILQ_REMOVE (&pci_device_list, dev, next); +rte_eal_pci_remove_device (dev);free (dev);return 0 ; }
@@ -441,7 +437,7 @@ rte_eal_pci_probe(void)if (rte_eal_devargs_type_count (RTE_DEVTYPE_WHITELISTED_PCI ) ==0 ) probe_all =1 ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {/* set devargs in PCI structure */ devargs =pci_devargs_lookup (dev);
@@ -489,7 +485,7 @@ rte_eal_pci_dump(FILE *f) {struct rte_pci_device *dev =NULL ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {pci_dump_one_device (f, dev); } }
@@ -498,16 +494,22 @@ rte_eal_pci_dump(FILE *f)void rte_eal_pci_register (struct rte_pci_driver *driver) { -TAILQ_INSERT_TAIL (&pci_driver_list, driver, next); -rte_eal_driver_register (&driver->driver); +TAILQ_INSERT_TAIL (&rte_pci_bus.driver_list, driver, next); +/* Update Bus references */ + driver->pci_bus = &rte_pci_bus; } -/* unregister a driver */ +/* Unregister a driver */ void rte_eal_pci_unregister (struct rte_pci_driver *driver) { -rte_eal_driver_unregister (&driver->driver); -TAILQ_REMOVE (&pci_driver_list, driver, next); +struct rte_pci_bus *pci_bus; + + pci_bus = driver->pci_bus; + +TAILQ_REMOVE (&pci_bus->driver_list, driver, next); +/* Update Bus references */ + driver->pci_bus =NULL ; }/* Add a PCI device to PCI Bus */
lib/librte_eal/common/eal_private.h +0 -10
@@ -108,16 +108,6 @@ int rte_eal_timer_init(void);*/ int rte_eal_log_init (const char *id,int facility); -/** -* Init the PCI infrastructure -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error -*/ -int rte_eal_pci_init (void ); -struct rte_pci_driver ;struct rte_pci_device ;
lib/librte_eal/common/include/rte_pci.h +7 -15
@@ -87,12 +87,6 @@ extern "C" {#include <rte_dev.h> #include <rte_bus.h> -TAILQ_HEAD (pci_device_list, rte_pci_device);/**< PCI devices in D-linked Q. */ -TAILQ_HEAD (pci_driver_list, rte_pci_driver);/**< PCI drivers in D-linked Q. */ - -extern struct pci_driver_list pci_driver_list;/**< Global list of PCI drivers. */ -extern struct pci_device_list pci_device_list;/**< Global list of PCI devices. */ -/** Pathname of PCI devices directory. */ const char *pci_get_sysfs_path (void );
@@ -124,6 +118,9 @@ TAILQ_HEAD(rte_pci_device_list, rte_pci_device);/** List of PCI drivers */ TAILQ_HEAD (rte_pci_driver_list, rte_pci_driver); +/* Extend PCI bus definition to users */ +extern struct rte_pci_bus rte_pci_bus; +/* PCI Bus iterators */ #define FOREACH_DEVICE_ON_PCIBUS (p) \ TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next)
@@ -208,8 +205,6 @@ struct rte_pci_device { .subsystem_device_id = PCI_ANY_ID#endif -struct rte_pci_driver ; -/** * Initialisation function for the driver called during PCI probing. */
@@ -416,17 +411,14 @@ rte_pci_match(const struct rte_pci_driver *pci_drv, const struct rte_pci_device *pci_dev);/** -* Probe the PCI bus for registered drivers. -* -* Scan the content of the PCI bus, and call the probe() function for -* all registered drivers that have a matching entry in its id_table -* for discovered devices. +* Probe the PCI bus * * @return * - 0 on success. -* - Negative on error. +* - !0 on error. */ -int rte_eal_pci_probe (void ); +int +rte_eal_pci_probe (void );/** * Map the PCI device resources in user space virtual memory address
lib/librte_eal/linuxapp/eal/eal.c +0 -7
@@ -803,9 +803,6 @@ rte_eal_init(int argc, char **argv)if (rte_eal_log_init (logid, internal_config.syslog_facility) <0 )rte_panic ("Cannot init logs\n" ); -if (rte_eal_pci_init () <0 ) -rte_panic ("Cannot init PCI\n" ); -#ifdef VFIO_PRESENT if (rte_eal_vfio_setup () <0 )rte_panic ("Cannot init VFIO\n" );
@@ -884,10 +881,6 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); -/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
lib/librte_eal/linuxapp/eal/eal_pci.c +15 -27
93 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0 -2
@@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc;
Signature · 1 line
2.7.4
PATCH v7 9/9 eal: enable hotplugging of devices on bus
In reply to Shreyansh JainGiven a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 + lib/librte_eal/common/eal_common_dev.c | 56 ++++++++++++++++----- lib/librte_eal/common/eal_common_pci.c | 86 +++++++++++++++++++++++++++++++-- lib/librte_eal/common/include/rte_bus.h | 31 ++++++++++++ lib/librte_eal/common/include/rte_pci.h | 45 +++++++++++------ lib/librte_eal/linuxapp/eal/eal_pci.c | 2 + 6 files changed, 192 insertions(+), 30 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
@@ -682,6 +682,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
lib/librte_eal/common/eal_common_dev.c +44 -12
94 lines not on this page · raw message
lib/librte_eal/common/eal_common_pci.c +83 -3
102 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +31 -0
@@ -59,6 +59,8 @@ TAILQ_HEAD(rte_bus_list, rte_bus);/* Bus list exposed */ extern struct rte_bus_list rte_bus_list; +#define FOREACH_BUS (bus_p) TAILQ_FOREACH(bus_p, &rte_bus_list, next) +/** * Bus specific scan for devices attached on the bus. * For each bus object, the scan would be reponsible for finding devices and
@@ -94,6 +96,33 @@ typedef int (*rte_bus_scan_t)(void);typedef int (*rte_bus_probe_t )(void );/** +* Attach a device to a bus, assuming it is 'connected' to the bus. +* A bus is responsible for scanning for devices. Attaching a new device is +* for reenabling the device after being detached/removed. +* +* @param device_name +* Name of the device to attach. +* +* @return +* 0 for successful attach +* !0 for unsuccessful attach (or incorrect device name) +*/ +typedef int (*rte_bus_attach_t )(const char *device_name); + +/** +* Detach a named device from a bus. Implementation would check the existence +* of device on the bus and detach it. +* +* @param device_name +* Name of the device to detach +* +* @return +* 0 for successful detaching +* !0 if device not found or can't detach +*/ +typedef int (*rte_bus_detach_t )(const char *device_name); + +/** * A structure describing a generic bus. */ struct rte_bus {
@@ -101,6 +130,8 @@ struct rte_bus {const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ +rte_bus_attach_t attach;/**< Attach a named device */ +rte_bus_detach_t detach;/**< Detach a named device */ };/**
lib/librte_eal/common/include/rte_pci.h +30 -15
57 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -0
@@ -720,6 +720,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
Signature · 1 line
2.7.4
Re: [PATCH v7 9/9] eal: enable hotplugging of devices on bus
Quoted 4 lines · Shreyansh Jain
Given a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.
Signed-off-by Shreyansh Jain <[email protected]>
<...>
Quoted 11 lines
+/**
+ * Search and detach a PCI device from PCI Bus
+ * Implementsrte_bus->detach
+ *
+ * @paramdevice_name
+ * Name of the device to search and detach
+ *
+ * @return
+ * 0 for successful detaching of device
+ * >0 if device not found on bus
+ * <0 in case of error in removal.
These are the return values expected by rte_eal_dev_detach(), but rte_eal_pci_detach() is not following these right now, which is causing failure on detaching virtual devices.
Fix is not complex, it may be an option to fix this as a separate patch after this patchset applied.
Quoted 5 lines
+ */
lib/librte_eal/common/include/rte_pci.h +4
-0+int +rte_eal_pci_detach (const char *device_name); + +/**
<...>
Re: [PATCH v7 9/9] eal: enable hotplugging of devices on bus
Hi Ferruh,
Quoted 28 lines
-----Original Message-----
From: Ferruh Yigit [mailto:[email protected]]
Sent: Tuesday, January 17, 2017 4:18 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v7 9/9] eal: enable hotplugging of devices on busQuoted 4 lines · Shreyansh Jain
Given a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.
Signed-off-by Shreyansh Jain <[email protected]><...>
Quoted 11 lines
+/**
+ * Search and detach a PCI device from PCI Bus
+ * Implementsrte_bus->detach
+ *
+ * @paramdevice_name
+ * Name of the device to search and detach
+ *
+ * @return
+ * 0 for successful detaching of device
+ * >0 if device not found on bus
+ * <0 in case of error in removal.
Quoted 6 lines
These are the return values expected by
rte_eal_dev_detach(), butrte_eal_pci_detach()is not following these right now, which is causing failure on detaching virtual devices.Fix is not complex, it may be an option to fix this as a separate patch after this patchset applied.
Ok. I will have a look and fix it.
If possible I will push v8; keeping it pending is lower preference for me.
Quoted 8 lines
Quoted 6 lines
+ */
lib/librte_eal/common/include/rte_pci.h +4
-0+int +rte_eal_pci_detach (const char *device_name); + +/** <...>
Re: [PATCH v7 9/9] eal: enable hotplugging of devices on bus
Hello Ferruh,
Quoted 34 lines · Shreyansh Jain
Hi Ferruh,
Quoted 32 lines
-----Original Message-----
From: Ferruh Yigit [mailto:[email protected]]
Sent: Tuesday, January 17, 2017 4:18 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v7 9/9] eal: enable hotplugging of devices on busQuoted 4 lines · Shreyansh Jain
Given a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.
Signed-off-by Shreyansh Jain <[email protected]><...>
Quoted 11 lines
+/**
+ * Search and detach a PCI device from PCI Bus
+ * Implementsrte_bus->detach
+ *
+ * @paramdevice_name
+ * Name of the device to search and detach
+ *
+ * @return
+ * 0 for successful detaching of device
+ * >0 if device not found on bus
+ * <0 in case of error in removal.These are the return values expected by
rte_eal_dev_detach(), butrte_eal_pci_detach()is not following these right now, which is causing failure on detaching virtual devices.
Quoted 5 lines
Quoted 2 lines
Fix is not complex, it may be an option to fix this as a separate patch after this patchset applied.
Ok. I will have a look and fix it.
If possible I will push v8; keeping it pending is lower preference for me.
I have sent a v8 to fix this (issue was indeed there). I have not used reviewed-by from you on v8 9/9.
Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
+ */
lib/librte_eal/common/include/rte_pci.h +4
-0+int +rte_eal_pci_detach (const char *device_name); + +/** <...>
On 1/17/2017 10:09 AM, Shreyansh Jain wrote:
<...>
Quoted 11 lines
Shreyansh Jain (9):
eal/bus: introduce bus abstraction
test: add basic bus infrastructure tests
pci: split match and probe function
eal/bus: support for scanning of bus
eal/bus: introduce support for bus probing
eal: integrate bus scan and probe with EAL
test: update bus and pci unit test cases
eal: enable PCI bus
eal: enable hotplugging of devices on bus
Apart from issue mentioned in patch v7 9/9,
v8 cover Introducing EAL Bus-Device-Driver Model
In reply to Shreyansh JainLink to v7: [17]
:: Introduction ::
DPDK has been inherently a PCI inclined framework. Because of this, the design of device tree (or list) within DPDK is also PCI inclined. A non-PCI device doesn't have a way of being expressed without using hooks started from EAL to PMD.
(Check 'Version Changes' section for changes)
:: Overview of the Proposed Changes ::
Assuming the below graph for a computing node:
device A1
|
+==.===='==============.============+ Bus A.
| `--> driver A11 \
device A2 `-> driver A12 \______
|CPU |
/`````
device B1 /
| /
+==.===='==============.============+ Bus B`
| `--> driver B11
device B2 `-> driver B12 - 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
In [15], model assumes that rte_bus would be the base class using which all the bus implementations would instantiate the objects. This patches takes a much more basic approach, on the same lines of rte_device/ rte_driver and rte_pci_device/rte_pci_driver.
This is based on various review comments as well as offline (IRC) discussions.
- rte_bus is an abstract class which includes basic methods supported by all buses.
- specific implementation, for example for PCI rte_pci_bus, would extend this class to form their own buses, with their own bus specific device and driver list.
-
+-----------------+ |rte_pci_bus | |+---------------+| ||rte_bus || |+---------------+| +-----------------+
And example implementation would look like:
.--------------->+-------------------+
| |rte_pci_bus |
| | +----------------+|
| | |rte_bus <------.
| | | name || |
| | | scan || |
| | | probe || |
| | | attach || |
| | | detach || |
| | +----------------+| |
| | pci_driver_list | |
| .-------------->pci_device_list | |
| | | ... | |
| | +-------------------+ |
| | |
| +-------------------+ |
| |rte_pci_device | |
'----bus | |
| +----------------+| |
| |rte_device || |
| | bus --------------------------------'
| | ... ||
| +----------------+|
| ... |
+-------------------+:: Brief about Patch Layout ::
0001~0002: Introducing the basic Bus model and associated test case
0003 : Split the PCI match into a separate function
0004~0005: Introduce bus->scan APIs and integrate with EAL
0006 : Update the Bus and PCI test cases for scanning/probing
0007 : Enable PCI bus and remove code for direct PCI scan/probe from
EAL
0008 : Add device hotplugging over the bus and introduce PCI helpers
:: Pending Changes/Caveats ::
1. This patchset only moves the PCI into a bus. And, that movement is also currently part of the EAL (lib/librte_eal/linux)
Eventual aim is the PCI bus reside in driver/bus/pci
2. Though the implementation for bus is common for Linux and BSD, the PCI bus implementation has been done/tested only for Linux.
3. RTE_REGISTER_BUS has been declared with contructor priority of 101 It is important that Bus is registered *before* drivers are registered. Only way I could find to assure that was via __attribute(contructor(priority)) of GCC. I am not sure how it would behave on other compilers. Any suggestions?
- One suggestion from David Marchand was to use global bus object handles, which I have not implemented for now. If that is common choice, I will change in v3.
4. Hotplugging has been introduced over Bus with a caveat - it would only work for ports/NICs already scanned and available in the bus list.
:: ToDo list ::
- Bump to librte_eal version
- Documentation continues to have references to some _old_ PCI symbols
:: References ::
[1] http://dpdk.org/ml/archives/dev/2016-November/050186.html
[2] http://dpdk.org/ml/archives/dev/2016-November/050622.html
[3] http://dpdk.org/ml/archives/dev/2016-November/050416.html
[4] http://dpdk.org/ml/archives/dev/2016-November/050567.html
[5] http://dpdk.org/ml/archives/dev/2016-November/050628.html
[6] http://dpdk.org/ml/archives/dev/2016-November/050415.html
[7] http://dpdk.org/ml/archives/dev/2016-November/050443.html
[8] http://dpdk.org/ml/archives/dev/2016-November/050624.html
[9] http://dpdk.org/ml/archives/dev/2016-November/050296.html
[10] http://dpdk.org/ml/archives/dev/2016-December/051349.html - v1
[12] http://dpdk.org/ml/archives/dev/2016-December/052092.html - v2
[13] http://dpdk.org/ml/archives/dev/2016-December/052381.html - v3
[14] http://dpdk.org/ml/archives/dev/2016-December/053302.html - v4
[15] http://dpdk.org/ml/archives/dev/2016-December/053315.html - v5
[16] http://dpdk.org/ml/archives/dev/2017-January/055120.html - v6
[17] http://dpdk.org/ml/archives/dev/2017-January/055320.html - v7
:: Version Changes ::
v8:
- fix return value bug in rte_eal_pci_attach and rte_eal_pci_detach
v7:
- update to rte_pci_match for const parameters
- remove unnecessary log messages in probe; moved _after_ matching of device and driver
- bug fixes in attach/detach methods
- PCI disable for debugging was missed (from rte_eal_pci_init) in v6
v6:
- Rearchitecture to bring bus object parallel to rte_device/driver This majorly includes:
-- rte_pci_bus class and pci_bus as its object for PCI -- bus->attach/detach (hotplugging)
-- removing bus->match as that is local to an implementation
- rename symbols rte_eal_bus_* to rte_bus_*
- restructuring patches (order) for simplicity
- update to test_pci
v5:
- Fix checkpatch error in Patch 0003
v4:
- rebase over master (eac901ce)
- Fix a bug in test_bus while setup and cleanup
- rename rte_eal_get_bus to rte_eal_bus_get
- Add helper (iterator) macros for easy bus,device,driver traversal
- removed 0001 patch as it is already merged in master
- fix missing rte_eal_bus_insert_device symbol in map file
v3:
- rebase over master (c431384c8f)
- revert patch 0001 changes for checkpatch (container_of macro)
- qat/rte_qat_cryptodev update for rte_driver->probe
- test_pci update for using a test_pci_bus for verification
- some bug fixes based on internal testing.
-- rte_eal_dev_attach not handling devargs
-- blacklisting not working
v2:
- No more bus->probe()
Now, rte_eal_bus_probe() calls rte_driver->probe based on match output
- new functions, rte_eal_pci_probe and rte_eal_pci_remove have been added as glue code between PCI PMDs and PCI Bus
`-> PMDs are updated to use these new functions as callbacks for
rte_driver
- 'default' keyword has been removed from match and scan
- Fix for incorrect changes in mlx* and nicvf*
- Checkpatch fixes
- Some variable checks have been removed from internal functions; functions which are externally visible continue to have such checks
- Some rearrangement of patches:
-- changes to drivers have been separated from EAL changes (but this
does make PCI PMDs non-working for a particular patch)
Shreyansh Jain (9):
eal/bus: introduce bus abstraction
test: add basic bus infrastructure tests
pci: split match and probe function
eal/bus: support for scanning of bus
eal/bus: introduce support for bus probing
eal: integrate bus scan and probe with EAL
test: update bus and pci unit test cases
eal: enable PCI bus
eal: enable hotplugging of devices on bus
app/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 686 ++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++-- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 13 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 17 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 15 +- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 140 +++++ lib/librte_eal/common/eal_common_dev.c | 56 +- lib/librte_eal/common/eal_common_pci.c | 337 ++++++++---- lib/librte_eal/common/eal_private.h | 10 - lib/librte_eal/common/include/rte_bus.h | 200 +++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/common/include/rte_pci.h | 148 ++++- lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal.c | 13 +- lib/librte_eal/linuxapp/eal/eal_pci.c | 57 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 15 +- 20 files changed, 1633 insertions(+), 247 deletions(-) create mode 100644 app/test/test_bus.c create mode 100644 lib/librte_eal/common/eal_common_bus.c create mode 100644 lib/librte_eal/common/include/rte_bus.h
Signature · 1 line
2.7.4
PATCH v8 1/9 eal/bus: introduce bus abstraction
This patch introduces the rte_bus abstraction for EAL.
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' base class which would be extended for specific implementations. It also introduces Bus registration and deregistration functions.
An example implementation would be like:
.--------------->+-------------------+
| |rte_pci_bus |
| | +----------------+|
| | |rte_bus <------.
| | | name || |
| | | scan || |
| | | match || |
| | | probe || |
| | | remove || |
| | | ... || |
| | +----------------+| |
| | pci_driver_list | |
| .-------------->pci_device_list | |
| | | ... | |
| | +-------------------+ |
| | |
| +-------------------+ |
| |rte_pci_device | |
'----bus | |
| +----------------+| |
| |rte_device || |
| | bus --------------------------------'
| | ... ||
| +----------------+|
| ... |
+-------------------+--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 10 +++ lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 97 +++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 111 ++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/rte_eal_version.map | 10 +++ 8 files changed, 232 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
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -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
lib/librte_eal/bsdapp/eal/rte_eal_version.map +10 -0
@@ -174,3 +174,13 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_list; + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
lib/librte_eal/common/Makefile +1 -1
@@ -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
lib/librte_eal/common/eal_common_bus.c new file +97 -0
97 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h new file +111 -0
111 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +1 -0
@@ -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 */ const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -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
lib/librte_eal/linuxapp/eal/rte_eal_version.map +10 -0
@@ -178,3 +178,13 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_list; + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
Signature · 1 line
2.7.4
Re: [PATCH v8 1/9] eal/bus: introduce bus abstraction
2017-01-17 19:07, Shreyansh Jain:
lib/librte_eal/common/eal_common_bus.c line 56
Quoted 8 lines
lib/librte_eal/common/eal_common_bus.c new file +8
-0+void +rte_bus_register (struct rte_bus *bus) +{ +RTE_VERIFY (bus); +RTE_VERIFY (bus->name &&strlen (bus->name)); + +TAILQ_INSERT_TAIL (&rte_bus_list, bus, next); +RTE_LOG (INFO ,EAL ,"Registered [%s] bus.\n" , bus->name);
I think it should be a debug log.
lib/librte_eal/common/eal_common_bus.c line 61
Quoted 3 lines
lib/librte_eal/common/eal_common_bus.c new file +3
-0+/* unregister a bus */ +void +rte_bus_unregister (struct rte_bus *bus)
I appreciate the effort for commenting, but I think the function name is self describing.
Quoted 4 lines
+/**
+ * @file
+ *
+ * RTE PMD Bus Abstraction interfaces
RTE PMD?
I would say "DPDK device bus interface"
lib/librte_eal/bsdapp/eal/rte_eal_version.map DPDK_16.11 { · line 181
Quoted 4 lines
lib/librte_eal/bsdapp/eal/rte_eal_version.map +4
-0+DPDK_17.02 { + global: + + rte_bus_list;
Why the bus list is exported?
If it is for testing purpose, I wonder wether it is worth to do it.
Re: [PATCH v8 1/9] eal/bus: introduce bus abstraction
Quoted 8 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, January 18, 2017 4:50 AM
To: Shreyansh Jain <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v8 1/9] eal/bus: introduce bus abstraction2017-01-17 19:07, Shreyansh Jain:
Quoted 10 lines
lib/librte_eal/common/eal_common_bus.c line 56
Quoted 8 lines
lib/librte_eal/common/eal_common_bus.c new file +8
-0+void +rte_bus_register (struct rte_bus *bus) +{ +RTE_VERIFY (bus); +RTE_VERIFY (bus->name &&strlen (bus->name)); + +TAILQ_INSERT_TAIL (&rte_bus_list, bus, next); +RTE_LOG (INFO ,EAL ,"Registered [%s] bus.\n" , bus->name);I think it should be a debug log.
I thought it should be visible to user/app which buses exists parallel to the information about the detected devices.
But, no strong opinion on this - I will change in v9.
Quoted 7 lines
lib/librte_eal/common/eal_common_bus.c line 61
Quoted 4 lines
lib/librte_eal/common/eal_common_bus.c new file +3
-0+/* unregister a bus */ +void +rte_bus_unregister (struct rte_bus *bus)I appreciate the effort for commenting, but I think the function name is self describing.
Ok. I will remove the comment. (as well as similar occurences.
Quoted 8 lines
Quoted 5 lines
+/**
+ * @file
+ *
+ * RTE PMD Bus Abstraction interfacesRTE PMD?
I would say "DPDK device bus interface"
Yes, that is an oversight. PMD is irrelevant here.
Quoted 8 lines
lib/librte_eal/bsdapp/eal/rte_eal_version.map DPDK_16.11 { · line 181
Quoted 5 lines
lib/librte_eal/bsdapp/eal/rte_eal_version.map +4
-0+DPDK_17.02 { + global: + + rte_bus_list;Why the bus list is exported?
If it is for testing purpose, I wonder wether it is worth to do it.
I have modeled the test cases on the lines of test_pci and it worked on actual pci device lists. Though, it is very much possible to not even touch the actual lists (in either, bus or pci test cases).
I can easily remove the usage of actual list in test_bus.
PATCH v8 2/9 test: add basic bus infrastructure tests
In reply to Shreyansh JainVerification of bus registration, deregistration methods.
--- app/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 359 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 3 + 4 files changed, 365 insertions(+), 1 deletion(-) create mode 100644 app/test/test_bus.c
app/test/Makefile +1 -1
@@ -94,7 +94,7 @@ SRCS-y += test_cycles.c SRCS-y += test_spinlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c - +SRCS-y += test_bus.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c SRCS-y += test_pmd_perf.c
app/test/test.h +2 -0
@@ -236,6 +236,8 @@ int commands_init(void);int test_pci (void );int test_pci_run; +int test_bus (void ); +int test_mp_secondary (void );int test_set_rxtx_conf (cmdline_fixed_string_t mode);
app/test/test_bus.c new file +359 -0
359 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +3 -0
@@ -56,6 +56,9 @@ extern "C" {/** Double linked list of buses */ TAILQ_HEAD (rte_bus_list, rte_bus); +/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list; +/** * A structure describing a generic bus. */
Signature · 1 line
2.7.4
Re: [PATCH v8 2/9] test: add basic bus infrastructure tests
2017-01-17 19:07, Shreyansh Jain:
Quoted 1 line
+REGISTER_TEST_COMMAND(bus_autotest,
test_bus);
You should add it to app/test/autotest_data.py
lib/librte_eal/common/include/rte_bus.h extern "C" { · line 60
Quoted 2 lines
lib/librte_eal/common/include/rte_bus.h +2
-0+/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list;
I think it should be possible to write a test without the real list of registered bus.
Re: [PATCH v8 2/9] test: add basic bus infrastructure tests
Quoted 11 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, January 18, 2017 4:54 AM
To: Shreyansh Jain <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v8 2/9] test: add basic bus infrastructure tests2017-01-17 19:07, Shreyansh Jain:
Quoted 1 line
+REGISTER_TEST_COMMAND(bus_autotest,
test_bus);You should add it to
app/test/autotest_data.py
Ok. I will do that.
Quoted 6 lines
lib/librte_eal/common/include/rte_bus.h extern "C" { · line 60
Quoted 3 lines
lib/librte_eal/common/include/rte_bus.h +2
-0+/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list;I think it should be possible to write a test without the real list of registered bus.
Yes, it is possible. I just modeled it on test_pci assuming that is a kind of expected/standard. But, it seems probably it is not. I will change the tests.
Re: [PATCH v8 2/9] test: add basic bus infrastructure tests
Quoted 22 lines
-----Original Message-----
From: Shreyansh Jain
Sent: Wednesday, January 18, 2017 10:42 AM
To: 'Thomas Monjalon' <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v8 2/9] test: add basic bus infrastructure testsQuoted 11 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, January 18, 2017 4:54 AM
To: Shreyansh Jain <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v8 2/9] test: add basic bus infrastructure tests2017-01-17 19:07, Shreyansh Jain:
Quoted 1 line
+REGISTER_TEST_COMMAND(bus_autotest,
test_bus);You should add it to
app/test/autotest_data.pyOk. I will do that.
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
lib/librte_eal/common/include/rte_bus.h extern "C" { · line 60
Quoted 2 lines
lib/librte_eal/common/include/rte_bus.h +2
-0+/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list;I think it should be possible to write a test without the real list of registered bus.
Yes, it is possible. I just modeled it on
test_pciassuming that is a kind of expected/standard. But, it seems probably it is not. I will change the tests.
After sending out this mail I realized the real reason for using the actual lists. Functions like rte_eal_pci_register (for PCI) or rte_bus_register (for Bus), use global lists for registration. Test cases calls these functions for registering dummy device/bus.
One way is to not worry about adding these test/dummy devices/buses to original list as they would be unregistered anyway. But, risk is of impacting running list assuming multiple cases need to be run from same application/binary context.
Another way is to rewrite these functions locally in test case, but that also means not testing these global registration/de-registration functions.
Former method would continue to have symbols exported. Later is not testing some entry/exit functions of a sub-system.
You still interested in this change?
Re: [PATCH v8 2/9] test: add basic bus infrastructure tests
2017-01-18 06:56, Shreyansh Jain:
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
lib/librte_eal/common/include/rte_bus.h extern "C" { · line 60
Quoted 2 lines
lib/librte_eal/common/include/rte_bus.h +2
-0+/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list;I think it should be possible to write a test without the real list of registered bus.
Yes, it is possible. I just modeled it on
test_pciassuming that is a kind of expected/standard. But, it seems probably it is not. I will change the tests.After sending out this mail I realized the real reason for using the actual lists. Functions like
rte_eal_pci_register(for PCI) orrte_bus_register(for Bus), use global lists for registration. Test cases calls these functions for registering dummy device/bus.
Why access to the bus list is externally required?
I feel there is something wrong here. It should be private in PCI.
Quoted 7 lines
One way is to not worry about adding these test/dummy devices/buses to original list as they would be unregistered anyway. But, risk is of impacting running list assuming multiple cases need to be run from same application/binary context.
Another way is to rewrite these functions locally in test case, but that also means not testing these global registration/de-registration functions.
Former method would continue to have symbols exported. Later is not testing some entry/exit functions of a sub-system.
You still interested in this change?
I would prefer you do not lose time with testing at this stage.
Re: [PATCH v8 2/9] test: add basic bus infrastructure tests
Quoted 7 lines · Thomas Monjalon
2017-01-18 06:56, Shreyansh Jain:
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
lib/librte_eal/common/include/rte_bus.h extern "C" { · line 60
Quoted 2 lines
lib/librte_eal/common/include/rte_bus.h +2
-0+/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list;I think it should be possible to write a test without the real list of registered bus.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Yes, it is possible. I just modeled it on
test_pciassuming that is a kind of expected/standard. But, it seems probably it is not. I will change the tests.After sending out this mail I realized the real reason for using the actual lists. Functions like
rte_eal_pci_register(for PCI) orrte_bus_register(for Bus), use global lists for registration. Test cases calls these functions for registering dummy device/bus.Why access to the bus list is externally required?
I feel there is something wrong here. It should be private in PCI.
When I stated rte_eal_pci_register required global lists, I meant in previous code base (pre bus), the pci_device_list and pci_driver_list were public because registration function used them and test cases used
the registration function.
Quoted 11 lines
Quoted 8 lines
One way is to not worry about adding these test/dummy devices/buses to original list as they would be unregistered anyway. But, risk is of impacting running list assuming multiple cases need to be run from same application/binary context.
Another way is to rewrite these functions locally in test case, but that also means not testing these global registration/de-registration functions.
Former method would continue to have symbols exported. Later is not testing some entry/exit functions of a sub-system.
You still interested in this change?
I would prefer you do not lose time with testing at this stage.
Ok. I will leave it as it is for now.
PATCH v8 3/9 pci: split match and probe function
In reply to Shreyansh JainMatching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev).
Splitting the matching function into a public fn rte_pci_match.
--- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_pci.c | 189 +++++++++++++----------- lib/librte_eal/common/include/rte_pci.h | 15 ++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 121 insertions(+), 85 deletions(-)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
@@ -182,5 +182,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match; } DPDK_16.11;
lib/librte_eal/common/eal_common_pci.c +104 -85
233 lines not on this page · raw message
lib/librte_eal/common/include/rte_pci.h +15 -0
@@ -371,6 +371,21 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,int rte_eal_pci_scan (void );/** +* Match the PCI Driver and Device using the ID Table +* +* @param pci_drv +* PCI driver from which ID table would be extracted +* @param pci_dev +* PCI device to match against the driver +* @return +* 0 for successful match +* !0 for unsuccessful match +*/ +int +rte_pci_match (const struct rte_pci_driver *pci_drv, +const struct rte_pci_device *pci_dev); + +/** * Probe the PCI bus for registered drivers. * * Scan the content of the PCI bus, and call the probe() function for
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -0
@@ -186,5 +186,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match; } DPDK_16.11;
Signature · 1 line
2.7.4
Re: [PATCH v8 3/9] pci: split match and probe function
2017-01-17 19:07, Shreyansh Jain:
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 271
Quoted 11 lines
lib/librte_eal/common/eal_common_pci.c +11
-0+static int +rte_eal_pci_detach_dev (struct rte_pci_driver *dr, +struct rte_pci_device *dev) +{ +int ret; +struct rte_pci_addr *loc; + +if ((dr ==NULL ) || (dev ==NULL )) +return -EINVAL ; + + ret =rte_pci_match (dr, dev);
I do not understand this function.
The driver should be known by the device at this stage. Why specifying a driver as parameter?
I know it is not new in this series, but pci_detach_all_drivers(struct rte_pci_device *dev) makes no sense to me.
Re: [PATCH v8 3/9] pci: split match and probe function
Quoted 24 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, January 18, 2017 5:02 AM
To: Shreyansh Jain <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v8 3/9] pci: split match and probe function2017-01-17 19:07, Shreyansh Jain:
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 271
Quoted 11 lines
lib/librte_eal/common/eal_common_pci.c +11
-0+static int +rte_eal_pci_detach_dev (struct rte_pci_driver *dr, +struct rte_pci_device *dev) +{ +int ret; +struct rte_pci_addr *loc; + +if ((dr ==NULL ) || (dev ==NULL )) +return -EINVAL ; + + ret =rte_pci_match (dr, dev);I do not understand this function.
The driver should be known by the device at this stage. Why specifying a driver as parameter?
Quoted 4 lines
I know it is not new in this series, but
pci_detach_all_drivers(struct rte_pci_device *dev)makes no sense to me.From what I understand,
pci_detach_all_driversis simply a wrapper over the PCI driver list, callingrte_eal_pci_detach_devfor each driver. Considering that all it does is iterate, it is not functionally required.
But, let me clarify one more thing: There is a possibility that rte_pci_device->pci_driver be directly used in case of detach rather than searching for a driver. This is assuming that before 'detach', a pci_device would link to a valid pci_driver. Is there some caveat in this assumption?
Re: [PATCH v8 3/9] pci: split match and probe function
2017-01-18 06:17, Shreyansh Jain:
Quoted 18 lines
From: Thomas Monjalon [mailto:[email protected]]
Quoted 17 lines
2017-01-17 19:07, Shreyansh Jain:
lib/librte_eal/common/eal_common_pci.c pci_unmap_resource(void *requested_addr, size_t size) · line 271
Quoted 11 lines
lib/librte_eal/common/eal_common_pci.c +11
-0+static int +rte_eal_pci_detach_dev (struct rte_pci_driver *dr, +struct rte_pci_device *dev) +{ +int ret; +struct rte_pci_addr *loc; + +if ((dr ==NULL ) || (dev ==NULL )) +return -EINVAL ; + + ret =rte_pci_match (dr, dev);I do not understand this function.
The driver should be known by the device at this stage. Why specifying a driver as parameter?
Quoted 6 lines
Quoted 2 lines
I know it is not new in this series, but
pci_detach_all_drivers(struct rte_pci_device *dev)makes no sense to me.From what I understand,
pci_detach_all_driversis simply a wrapper over the PCI driver list, callingrte_eal_pci_detach_devfor each driver. Considering that all it does is iterate, it is not functionally required.But, let me clarify one more thing: There is a possibility that
rte_pci_device->pci_driverbe directly used in case of detach rather than searching for a driver. This is assuming that before 'detach', apci_devicewould link to a validpci_driver. Is there some caveat in this assumption?
I would say it it always true.
But seeing this code existing makes me hesitates.
I suggest to go with this assumption for RC1 and remove this loop.
PATCH v8 4/9 eal/bus: support for scanning of bus
In reply to Shreyansh JainScan for bus discovers the devices available on the bus and adds them to a bus specific device list. Each bus mandatorily implements this method.
Test cases for Bus are also updated by this patch.
--- app/test/test_bus.c | 175 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_common_bus.c | 2 + lib/librte_eal/common/include/rte_bus.h | 18 ++++ 3 files changed, 195 insertions(+)
app/test/test_bus.c +175 -0
@@ -106,10 +106,26 @@ struct dummy_bus_map {struct rte_bus_list orig_bus_list =TAILQ_HEAD_INITIALIZER (orig_bus_list); +/* Forward declarations for callbacks from bus */ + +/* Bus A +* Scan would register devA1 and devA2 to bus +*/ +static int scan_fn_for_busA (void ); + +/* Bus B +* Scan would register devB1 and devB2 to bus +*/ +static int scan_fn_for_busB (void ); + +/* generic implementations wrapped around by above declarations */ +static int generic_scan_fn (struct rte_bus *bus); +struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , + .scan = scan_fn_for_busA, }, };
@@ -117,6 +133,7 @@ struct dummy_bus busB = { .name = "busB_impl", /* busB */ .bus = { .name = "busB", + .scan = scan_fn_for_busB, }, };
@@ -226,9 +243,81 @@ dump_device_tree(void)printf ("------>8-------\n" ); } +/* @internal +* Move over the bus_map and find the entry matching the bus object +* passed as argument. +* For each device in that bus_map list, register. +* +* @param bus +* bus to scan againt test entry +* @return +* 0 for successful scan, even if no devices are found +* !0 for any error in scanning (like, invalid bus) +*/ +static int +generic_scan_fn (struct rte_bus *bus) +{ +int i =0 ; +struct dummy_device *ddev =NULL ; +struct dummy_bus_map *dbmap =NULL ; +struct dummy_bus *db =NULL ; + +if (!bus) +return -1 ; + +/* Extract the device tree node using the bus passed */ +for (i =0 ; bus_map[i].name; i++) { +if (!strcmp (bus_map[i].name, bus->name)) { + dbmap = &bus_map[i]; +break ; + } + } + +if (!dbmap) +return -1 ; + + db = dbmap->dbus; + +/* For all the devices in the device tree (bus_map), add device */ +for (i =0 ; dbmap->ddevices[i]; i++) { + ddev = dbmap->ddevices[i]; +TAILQ_INSERT_TAIL (&db->device_list, ddev, next); + ddev->dev.bus = bus; + } + +return 0 ; +} + +int +scan_fn_for_busA (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busA" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} + +int +scan_fn_for_busB (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busB" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} +static int test_bus_setup (void ) { +int i =0 ;struct rte_bus *bus_p =NULL ;/* Preserve the original bus list before executing test */
@@ -238,6 +327,13 @@ test_bus_setup(void)TAILQ_INSERT_TAIL (&orig_bus_list, bus_p, next); } +/* Initialize the bus lists */ +for (i =0 ; bus_map[i].name; i++) { +TAILQ_INIT (&bus_map[i].dbus->device_list); +TAILQ_INIT (&bus_map[i].dbus->driver_list); + } + +dump_device_tree ();return 0 ; }
@@ -336,6 +432,79 @@ test_bus_unregistration(void)return 0 ; } +static int +test_device_unregistration_on_bus (void ) +{ +int i; +struct rte_bus *bus =NULL ; +struct dummy_device *ddev; +struct dummy_bus *dbus; + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); +if (!bus) { +printf ("Unable to find bus (%s)\n" , + bus_map[i].name); +return -1 ; + } + + dbus = container_of(bus, struct dummy_bus, bus); +/* For bus 'bus', unregister all devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +TAILQ_REMOVE (&dbus->device_list, ddev, next); + } + } + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); + dbus = container_of(bus, struct dummy_bus, bus); + +if (!TAILQ_EMPTY (&dbus->device_list)) { +printf ("Unable to remove all devices on bus (%s)\n" , + bus->name); +return -1 ; + } + } + +/* All devices from all buses have been removed */ +printf ("All devices on all buses unregistered.\n" ); +dump_device_tree (); + +return 0 ; +} + +/* @internal +* For each bus registered, call the scan function to identify devices +* on the bus. +* +* @param void +* @return +* 0 for successful scan +* !0 for unsuccessful scan +* +*/ +static int +test_bus_scan (void ) +{ +int ret; +struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { +/* Call the scan function for each bus */ + ret = bus->scan (); +if (ret) { +printf ("Scan of buses failed.\n" ); +return -1 ; + } + } + +printf ("Scan of all buses completed.\n" ); +dump_device_tree (); + +return 0 ; +} + +int test_bus (void ) {
@@ -346,6 +515,12 @@ test_bus(void)if (test_bus_registration ())return -1 ; +if (test_bus_scan ()) +return -1 ; + +if (test_device_unregistration_on_bus ()) +return -1 ; +if (test_bus_unregistration ())return -1 ;
lib/librte_eal/common/eal_common_bus.c +2 -0
@@ -51,6 +51,8 @@ rte_bus_register(struct rte_bus *bus) {RTE_VERIFY (bus);RTE_VERIFY (bus->name &&strlen (bus->name)); +/* A bus should mandatorily have the scan implemented */ +RTE_VERIFY (bus->scan);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (INFO ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +18 -0
@@ -60,11 +60,29 @@ TAILQ_HEAD(rte_bus_list, rte_bus);extern struct rte_bus_list rte_bus_list;/** +* Bus specific scan for devices attached on the bus. +* For each bus object, the scan would be reponsible for finding devices and +* adding them to its private device list. +* +* A bus should mandatorily implement this method. +* +* Generic bus object passed only as a helper for implementation to find +* their respective registered bus object. Implementations can choose not +* to use this variable. +* +* @return +* 0 for successful scan +* !0 (<0) for unsuccessful scan with error value +*/ +typedef int (*rte_bus_scan_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ +rte_bus_scan_t scan;/**< Scan for devices attached to bus */ };/**
Signature · 1 line
2.7.4
Re: [PATCH v8 4/9] eal/bus: support for scanning of bus
2017-01-17 19:07, Shreyansh Jain:
Quoted 3 lines
+ * Generic bus object passed only as a helper for implementation to find
+ * their respective registered bus object. Implementations can choose not
+ * to use this variable.
I think this comment is obsolete.
Quoted 4 lines
+ *
+ * @return
+ * 0 for successful scan
+ * !0 (<0) for unsuccessful scan with error value
What do you mean with !0 (<0) ?
I guess <0 is enough.
Quoted 3 lines
+ */
+typedef int (*rte_bus_scan_t)(void);
Re: [PATCH v8 4/9] eal/bus: support for scanning of bus
Quoted 7 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, January 18, 2017 5:07 AM
To: Shreyansh Jain <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v8 4/9] eal/bus: support for scanning of bus
Quoted 6 lines
2017-01-17 19:07, Shreyansh Jain:
Quoted 3 lines
+ * Generic bus object passed only as a helper for implementation to find
+ * their respective registered bus object. Implementations can choose not
+ * to use this variable.I think this comment is obsolete.
I will remove it.
Quoted 9 lines
Quoted 5 lines
+ *
+ * @return
+ * 0 for successful scan
+ * !0 (<0) for unsuccessful scan with error valueWhat do you mean with !0 (<0) ?
I guess <0 is enough.
Only to highlight that only '-ve' values would be returned. I will change it to !0 only.
Quoted 4 lines
Quoted 3 lines
+ */
+typedef int (*rte_bus_scan_t)(void);
Re: [PATCH v8 4/9] eal/bus: support for scanning of bus
2017-01-18 05:15, Shreyansh Jain:
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
+ *
+ * @return
+ * 0 for successful scan
+ * !0 (<0) for unsuccessful scan with error valueWhat do you mean with !0 (<0) ?
I guess <0 is enough.Only to highlight that only '-ve' values would be returned. I will change it to !0 only.
What is -ve?
Why not specifying <0 if errors are always negative?
PATCH v8 5/9 eal/bus: introduce support for bus probing
In reply to Shreyansh JainBus implementations can implement a probe handler to match the devices scanned against the drivers registered.
This patch introduces the callback which would be implemented for PCI in subsequent patch.
--- lib/librte_eal/common/eal_common_bus.c | 1 + lib/librte_eal/common/include/rte_bus.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+)
lib/librte_eal/common/eal_common_bus.c +1 -0
@@ -53,6 +53,7 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->name &&strlen (bus->name));/* A bus should mandatorily have the scan implemented */ RTE_VERIFY (bus->scan); +RTE_VERIFY (bus->probe);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (INFO ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +18 -0
@@ -77,12 +77,30 @@ extern struct rte_bus_list rte_bus_list;typedef int (*rte_bus_scan_t )(void );/** +* Implementation specific probe function which is responsible for linking +* devices on that bus with applicable drivers. +* +* This is called while iterating over each registered bus. Bus object is +* passed along assuming this is wrapped around (embedded) by Implementation +* specific bus object. +* +* @param bus +* Generic bus object which was registered with EAL +* +* @return +* 0 for successful probe +* !0 for any error while probing +*/ +typedef int (*rte_bus_probe_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ +rte_bus_probe_t probe;/**< Probe devices on bus */ };/**
Signature · 1 line
2.7.4
Re: [PATCH v8 5/9] eal/bus: introduce support for bus probing
2017-01-17 19:07, Shreyansh Jain:
Quoted 6 lines
+ * This is called while iterating over each registered bus. Bus object is
+ * passed along assuming this is wrapped around (embedded) by Implementation
+ * specific bus object.
+ *
+ * @param bus
+ * Generic bus object which was registered with EAL
No param bus here.
Quoted 7 lines
+ *
+ * @return
+ * 0 for successful probe
+ * !0 for any error while probing
+ */
+typedef int (*rte_bus_probe_t)(void);
PATCH v8 6/9 eal: integrate bus scan and probe with EAL
In reply to Shreyansh JainEach bus implementation defines their own callbacks for scanning its bus and probing devices available on the bus. Enable EAL to call bus specific scan and probe functions during DPDK initialization.
Existing PCI scan/probe continues to exist. It will removed in subsequent patches.
--- lib/librte_eal/bsdapp/eal/eal.c | 8 +++ lib/librte_eal/bsdapp/eal/eal_pci.c | 11 ++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 + lib/librte_eal/common/eal_common_bus.c | 40 +++++++++++++++ lib/librte_eal/common/eal_common_pci.c | 33 ++++++++++++ lib/librte_eal/common/include/rte_bus.h | 19 +++++++ lib/librte_eal/common/include/rte_pci.h | 68 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 8 +++ lib/librte_eal/linuxapp/eal/eal_pci.c | 15 ++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 + 10 files changed, 206 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +8 -0
@@ -64,6 +64,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
@@ -577,6 +578,9 @@ rte_eal_init(int argc, char **argv) rte_config.master_lcore, thread_id, cpuset, ret == 0 ? "" : "..."); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
@@ -613,6 +617,10 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" ); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/bsdapp/eal/eal_pci.c +11 -0
@@ -673,3 +673,14 @@ rte_eal_pci_init(void) }return 0 ; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), + .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS (PCI_BUS_NAME , rte_pci_bus.bus);
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -0
@@ -182,6 +182,8 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_bus_probe; + rte_bus_scan; rte_pci_match; } DPDK_16.11;
lib/librte_eal/common/eal_common_bus.c +40 -0
@@ -67,6 +67,46 @@ rte_bus_unregister(struct rte_bus *bus)RTE_LOG (INFO ,EAL ,"Unregistered [%s] bus.\n" , bus->name); } +/* Scan all the buses for registering devices */ +int +rte_bus_scan (void ) +{ +int ret; +struct rte_bus *bus =NULL ; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->scan (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Scan for (%s) bus failed.\n" , + bus->name); +/* Error in scanning any bus stops the EAL init. */ +return ret; + } + } + +return 0 ; +} + +/* Call bus specific probe */ +int +rte_bus_probe (void ) +{ +int ret; +struct rte_bus *bus; + +/* For each bus registered with EAL */ + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->probe (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Bus (%s) probe failed.\n" , + bus->name); +return ret; + } + } + +return 0 ; +} +/* dump one bus info */ static int bus_dump_one (FILE *f,struct rte_bus *bus)
lib/librte_eal/common/eal_common_pci.c +33 -0
@@ -71,6 +71,7 @@#include <rte_interrupts.h> #include <rte_log.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_per_lcore.h> #include <rte_memory.h>
@@ -508,3 +509,35 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver)rte_eal_driver_unregister (&driver->driver);TAILQ_REMOVE (&pci_driver_list, driver, next); } + +/* Add a PCI device to PCI Bus */ +void +rte_eal_pci_add_device (struct rte_pci_bus *pci_bus, +struct rte_pci_device *pci_dev) +{ +TAILQ_INSERT_TAIL (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus = &pci_bus->bus; +} + +/* Insert a PCI device into a predefined position in PCI bus */ +void +rte_eal_pci_insert_device (struct rte_pci_device *exist_pci_dev, +struct rte_pci_device *new_pci_dev) +{ +TAILQ_INSERT_BEFORE (exist_pci_dev, new_pci_dev, next); +/* Update Bus references */ + new_pci_dev->device.bus = exist_pci_dev->device.bus; +} + +/* Remove a PCI device from PCI bus */ +void +rte_eal_pci_remove_device (struct rte_pci_device *pci_dev) +{ +struct rte_pci_bus *pci_bus; + + pci_bus = container_of(pci_dev->device.bus, struct rte_pci_bus, bus); +TAILQ_REMOVE (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus =NULL ; +}
lib/librte_eal/common/include/rte_bus.h +19 -0
@@ -122,6 +122,25 @@ void rte_bus_register(struct rte_bus *bus);void rte_bus_unregister (struct rte_bus *bus);/** +* Scan all the buses attached to the framework. +* +* @return +* 0 in case of success in scanning all buses +* !0 in case of failure to scan +*/ +int rte_bus_scan (void ); + +/** +* For each device on the bus, perform a driver 'match' and call the +* bus's probe for device initialization. +* +* @return +* 0 for successful match/probe +* !0 otherwise +*/ +int rte_bus_probe (void ); + +/** * Dump information of all the buses registered with EAL. * * @param f
lib/librte_eal/common/include/rte_pci.h +68 -0
98 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal.c +8 -0
@@ -69,6 +69,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
@@ -844,6 +845,9 @@ rte_eal_init(int argc, char **argv)if (rte_eal_intr_init () <0 )rte_panic ("Cannot init interrupt-handling thread\n" ); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
@@ -884,6 +888,10 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" ); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/linuxapp/eal/eal_pci.c +15 -0
@@ -35,6 +35,7 @@#include <dirent.h> #include <rte_log.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_eal_memconfig.h> #include <rte_malloc.h>
@@ -54,6 +55,9 @@* IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it). */ +/* Forward declaration of PCI bus */ +struct rte_pci_bus rte_pci_bus; +static int pci_get_kernel_driver_by_path (const char *filename,char *dri_name) {
@@ -723,3 +727,14 @@ rte_eal_pci_init(void)return 0 ; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), + .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS (PCI_BUS_NAME , rte_pci_bus.bus);
lib/librte_eal/linuxapp/eal/rte_eal_version.map +2 -0
@@ -186,6 +186,8 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_bus_probe; + rte_bus_scan; rte_pci_match; } DPDK_16.11;
Signature · 1 line
2.7.4
Re: [PATCH v8 6/9] eal: integrate bus scan and probe with EAL
2017-01-17 19:07, Shreyansh Jain:
Quoted 9 lines
Each bus implementation defines their own callbacks for scanning its bus and probing devices available on the bus. Enable EAL to call bus specific scan and probe functions during DPDK initialization.
Existing PCI scan/probe continues to exist. It will removed in subsequent patches.
Signed-off-by Shreyansh Jain <[email protected]>Reviewed-by Ferruh Yigit <[email protected]>
Quoted 12 lines
--- lib/librte_eal/bsdapp/eal/eal.c | 8 +++ lib/librte_eal/bsdapp/eal/eal_pci.c | 11 ++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 + lib/librte_eal/common/eal_common_bus.c | 40 +++++++++++++++ lib/librte_eal/common/eal_common_pci.c | 33 ++++++++++++ lib/librte_eal/common/include/rte_bus.h | 19 +++++++ lib/librte_eal/common/include/rte_pci.h | 68 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 8 +++ lib/librte_eal/linuxapp/eal/eal_pci.c | 15 ++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 + 10 files changed, 206 insertions(+)
You can make 2 patches here:
- 1 patch for generic functions
- 1 patch for PCI implementation
PATCH v8 7/9 test: update bus and pci unit test cases
In reply to Shreyansh Jain--- app/test/test_bus.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 266 insertions(+), 50 deletions(-)
app/test/test_bus.c +152 -0
@@ -120,12 +120,15 @@ static int scan_fn_for_busB(void);/* generic implementations wrapped around by above declarations */ static int generic_scan_fn (struct rte_bus *bus); +static int generic_probe_fn (void ); +static int dummy_match_fn (struct rte_driver *drv,struct rte_device *dev);struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , .scan = scan_fn_for_busA, + .probe = generic_probe_fn, }, };
@@ -134,6 +137,7 @@ struct dummy_bus busB = { .bus = { .name = "busB", .scan = scan_fn_for_busB, + .probe = generic_probe_fn, }, };
@@ -288,6 +292,46 @@ generic_scan_fn(struct rte_bus *bus)return 0 ; } +/* @internal +* Obtain bus from driver object. Match the address of rte_device object +* with all the devices associated with that bus. +* +* Being a test function, all this does is validate that device object +* provided is available on the same bus to which driver is registered. +* +* @param drv +* driver to match with +* @param dev +* device object +* @return +* 0 for successful match +* !0 for failed match +*/ +static int +dummy_match_fn(struct rte_driver *drv __rte_unused, struct rte_device *dev) +{ +struct rte_bus *bus; +struct dummy_device *ddev =NULL ; +struct dummy_device *ddev_as_arg; +struct dummy_bus *dbus =NULL ; + +/* Match is based entirely on address of 'dev' and 'dev_p' extracted +* from bus->device_list. +*/ + +/* a driver is registered with the bus *before* the scan. */ + bus = dev->bus; + dbus = container_of(bus, struct dummy_bus, bus); + ddev_as_arg = container_of(dev, struct dummy_device, dev); + + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +if (ddev == ddev_as_arg) +return 0 ; + } + +return 1 ; +} +int scan_fn_for_busA (void ) {struct dummy_bus_map *dbm;
@@ -504,6 +548,110 @@ test_bus_scan(void)return 0 ; } +/* +* +*/ +static int +generic_probe_fn (void ) +{ +int ret =0 ; +int i, j; +struct rte_driver *drv; +struct rte_device *dev; +struct dummy_bus *dbus =NULL ; +struct dummy_device *ddev =NULL ; +struct dummy_driver *ddrv =NULL ; + +/* In case of this test: +* 1. for each bus in rte_bus_list +* 2. for each device on that bus (bus specific->device_list) +* 3. for each driver on that bus (bus specific->driver_list) +* 4. call match +* 5. link driver and device +* 6. Verify the linkage. +*/ +for (i =0 ; bus_map[i].name; i++) { +/* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + +/* Looping over all scanned devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +/* There is a list of drivers within dummy_bus_map. +* In case of PMDs, this would be driver registration +* APIs/list +*/ +for (j =0 ; bus_map[i].ddrivers[j]; j++) { + ddrv = bus_map[i].ddrivers[j]; + + drv = &ddrv->drv; + dev = &ddev->dev; + ret =dummy_match_fn (drv, dev); +if (!ret) { +/* As match is generic, it always +* results in dev->drv pointing to +* first driver entry in bus_map[i] +*/ + dev->driver = drv; + dev->bus = &dbus->bus; + } +/* Else, continue */ + } + } + } + +/* Verify the linkage. All devices belonging to a bus_map[i] +* should have same driver (first driver entry of bus_map[i]) +*/ +for (i =0 ; bus_map[i].name; i++) { + ddrv = bus_map[i].ddrivers[0 ]; + drv = &ddrv->drv; + +for (j =0 ; bus_map[i].ddevices[j]; j++) { + ddev = bus_map[i].ddevices[j]; + dev = &ddev->dev; +if (dev->driver != drv) { +printf ("Incorrect driver<->device linkage.\n" ); +return -1 ; + } + } + } + +return 0 ; +} + +/* @internal +* Function to perform 'probe' and link devices and drivers on a bus. +* This would work over all the buses registered, and all devices and drivers +* registered with it - call match on each pair. +* +* @param void +* @return +* 0 for successful probe +* !0 for failure in probe +* +*/ +static int +test_probe_on_bus (void ) +{ +int ret =0 ; +int i; +struct dummy_bus *dbus; +struct rte_bus *bus; + +for (i =0 ; bus_map[i].name; i++) { +/* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + bus = &dbus->bus; + ret = bus->probe (); +if (ret) +printf ("Probe for %s failed.\n" , bus_map[i].name); + } + +printf ("Probe on all buses successful.\n" ); +dump_device_tree (); + +return 0 ; +}int test_bus (void )
@@ -518,6 +666,10 @@ test_bus(void)if (test_bus_scan ())return -1 ; +/* Now that the devices and drivers are registered, perform probe */ +if (test_probe_on_bus ()) +return -1 ; +if (test_device_unregistration_on_bus ())return -1 ;
app/test/test_pci.c +114 -50
271 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v8 7/9] test: update bus and pci unit test cases
2017-01-17 19:07, Shreyansh Jain:
Quoted 6 lines
Signed-off-by Shreyansh Jain <[email protected]>Reviewed-by Ferruh Yigit <[email protected]>--- app/test/test_bus.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 266 insertions(+), 50 deletions(-)
You can split in 2 patches (generic and PCI)
and squash them with their respective implementation in EAL.
PATCH v8 8/9 eal: enable PCI bus
In reply to Shreyansh JainRemove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.
--- lib/librte_eal/bsdapp/eal/eal.c | 7 ----- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 -- lib/librte_eal/common/eal_common_pci.c | 36 +++++++++++---------- lib/librte_eal/common/eal_private.h | 10 ------ lib/librte_eal/common/include/rte_pci.h | 22 +++++-------- lib/librte_eal/linuxapp/eal/eal.c | 7 ----- lib/librte_eal/linuxapp/eal/eal_pci.c | 42 +++++++++---------------- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 -- 9 files changed, 45 insertions(+), 87 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +0 -7
@@ -562,9 +562,6 @@ rte_eal_init(int argc, char **argv)if (rte_eal_timer_init () <0 )rte_panic ("Cannot init HPET or TSC timers\n" ); -if (rte_eal_pci_init () <0 ) -rte_panic ("Cannot init PCI\n" ); -eal_check_mem_on_local_socket ();if (eal_plugins_init () <0 )
@@ -613,10 +610,6 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); -/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
lib/librte_eal/bsdapp/eal/eal_pci.c +4 -0
@@ -365,6 +365,10 @@ rte_eal_pci_scan(void) .matches = &matches[0], }; +/* for debug purposes, PCI can be disabled */ +if (internal_config.no_pci) +return 0 ; + fd =open ("/dev/pci" ,O_RDONLY );if (fd <0 ) {RTE_LOG (ERR ,EAL ,"%s(): error opening /dev/pci\n" , __func__);
lib/librte_eal/bsdapp/eal/rte_eal_version.map +0 -2
@@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc;
lib/librte_eal/common/eal_common_pci.c +19 -17
@@ -83,11 +83,6 @@#include "eal_private.h" -struct pci_driver_list pci_driver_list = -TAILQ_HEAD_INITIALIZER (pci_driver_list); -struct pci_device_list pci_device_list = -TAILQ_HEAD_INITIALIZER (pci_device_list); -#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"const char *pci_get_sysfs_path (void )
@@ -315,7 +310,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)if (dev->driver !=NULL )return 0 ; - TAILQ_FOREACH(dr, &pci_driver_list, next) { +FOREACH_DRIVER_ON_PCIBUS (dr) { rc =rte_eal_pci_probe_one_driver (dr, dev);if (rc <0 )/* negative value is an error */
@@ -342,7 +337,7 @@ pci_detach_all_drivers(struct rte_pci_device *dev)if (dev ==NULL )return -1 ; - TAILQ_FOREACH(dr, &pci_driver_list, next) { +FOREACH_DRIVER_ON_PCIBUS (dr) { rc =rte_eal_pci_detach_dev (dr, dev);if (rc <0 )/* negative value is an error */
@@ -363,6 +358,7 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr) {struct rte_pci_device *dev =NULL ; +int ret =0 ;if (addr ==NULL )
@@ -374,7 +370,7 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)if (pci_update_device (addr) <0 ) goto err_return; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ;
@@ -404,7 +400,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)if (addr ==NULL )return -1 ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ;
@@ -412,7 +408,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)if (ret <0 ) goto err_return; -TAILQ_REMOVE (&pci_device_list, dev, next); +rte_eal_pci_remove_device (dev);free (dev);return 0 ; }
@@ -441,7 +437,7 @@ rte_eal_pci_probe(void)if (rte_eal_devargs_type_count (RTE_DEVTYPE_WHITELISTED_PCI ) ==0 ) probe_all =1 ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {/* set devargs in PCI structure */ devargs =pci_devargs_lookup (dev);
@@ -489,7 +485,7 @@ rte_eal_pci_dump(FILE *f) {struct rte_pci_device *dev =NULL ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {pci_dump_one_device (f, dev); } }
@@ -498,16 +494,22 @@ rte_eal_pci_dump(FILE *f)void rte_eal_pci_register (struct rte_pci_driver *driver) { -TAILQ_INSERT_TAIL (&pci_driver_list, driver, next); -rte_eal_driver_register (&driver->driver); +TAILQ_INSERT_TAIL (&rte_pci_bus.driver_list, driver, next); +/* Update Bus references */ + driver->pci_bus = &rte_pci_bus; } -/* unregister a driver */ +/* Unregister a driver */ void rte_eal_pci_unregister (struct rte_pci_driver *driver) { -rte_eal_driver_unregister (&driver->driver); -TAILQ_REMOVE (&pci_driver_list, driver, next); +struct rte_pci_bus *pci_bus; + + pci_bus = driver->pci_bus; + +TAILQ_REMOVE (&pci_bus->driver_list, driver, next); +/* Update Bus references */ + driver->pci_bus =NULL ; }/* Add a PCI device to PCI Bus */
lib/librte_eal/common/eal_private.h +0 -10
@@ -108,16 +108,6 @@ int rte_eal_timer_init(void);*/ int rte_eal_log_init (const char *id,int facility); -/** -* Init the PCI infrastructure -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error -*/ -int rte_eal_pci_init (void ); -struct rte_pci_driver ;struct rte_pci_device ;
lib/librte_eal/common/include/rte_pci.h +7 -15
@@ -87,12 +87,6 @@ extern "C" {#include <rte_dev.h> #include <rte_bus.h> -TAILQ_HEAD (pci_device_list, rte_pci_device);/**< PCI devices in D-linked Q. */ -TAILQ_HEAD (pci_driver_list, rte_pci_driver);/**< PCI drivers in D-linked Q. */ - -extern struct pci_driver_list pci_driver_list;/**< Global list of PCI drivers. */ -extern struct pci_device_list pci_device_list;/**< Global list of PCI devices. */ -/** Pathname of PCI devices directory. */ const char *pci_get_sysfs_path (void );
@@ -124,6 +118,9 @@ TAILQ_HEAD(rte_pci_device_list, rte_pci_device);/** List of PCI drivers */ TAILQ_HEAD (rte_pci_driver_list, rte_pci_driver); +/* Extend PCI bus definition to users */ +extern struct rte_pci_bus rte_pci_bus; +/* PCI Bus iterators */ #define FOREACH_DEVICE_ON_PCIBUS (p) \ TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next)
@@ -208,8 +205,6 @@ struct rte_pci_device { .subsystem_device_id = PCI_ANY_ID#endif -struct rte_pci_driver ; -/** * Initialisation function for the driver called during PCI probing. */
@@ -416,17 +411,14 @@ rte_pci_match(const struct rte_pci_driver *pci_drv, const struct rte_pci_device *pci_dev);/** -* Probe the PCI bus for registered drivers. -* -* Scan the content of the PCI bus, and call the probe() function for -* all registered drivers that have a matching entry in its id_table -* for discovered devices. +* Probe the PCI bus * * @return * - 0 on success. -* - Negative on error. +* - !0 on error. */ -int rte_eal_pci_probe (void ); +int +rte_eal_pci_probe (void );/** * Map the PCI device resources in user space virtual memory address
lib/librte_eal/linuxapp/eal/eal.c +0 -7
@@ -803,9 +803,6 @@ rte_eal_init(int argc, char **argv)if (rte_eal_log_init (logid, internal_config.syslog_facility) <0 )rte_panic ("Cannot init logs\n" ); -if (rte_eal_pci_init () <0 ) -rte_panic ("Cannot init PCI\n" ); -#ifdef VFIO_PRESENT if (rte_eal_vfio_setup () <0 )rte_panic ("Cannot init VFIO\n" );
@@ -884,10 +881,6 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); -/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
lib/librte_eal/linuxapp/eal/eal_pci.c +15 -27
93 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0 -2
@@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc;
Signature · 1 line
2.7.4
Re: [PATCH v8 8/9] eal: enable PCI bus
2017-01-17 19:07, Shreyansh Jain:
lib/librte_eal/bsdapp/eal/eal.c rte_eal_init(int argc, char **argv) · line 615
Quoted 8 lines
lib/librte_eal/bsdapp/eal/eal.c +0
-4-/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
I like reading this :)
It is a good step.
A next step could be removing rte_bus_probe() and do it from the scan functions, after letting the application manage the blacklist via a callback.
PATCH v8 9/9 eal: enable hotplugging of devices on bus
In reply to Shreyansh JainGiven a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 + lib/librte_eal/common/eal_common_dev.c | 56 ++++++++++++++++----- lib/librte_eal/common/eal_common_pci.c | 89 +++++++++++++++++++++++++++++++-- lib/librte_eal/common/include/rte_bus.h | 31 ++++++++++++ lib/librte_eal/common/include/rte_pci.h | 45 +++++++++++------ lib/librte_eal/linuxapp/eal/eal_pci.c | 2 + 6 files changed, 193 insertions(+), 32 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
@@ -682,6 +682,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
lib/librte_eal/common/eal_common_dev.c +44 -12
94 lines not on this page · raw message
lib/librte_eal/common/eal_common_pci.c +84 -5
111 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +31 -0
@@ -59,6 +59,8 @@ TAILQ_HEAD(rte_bus_list, rte_bus);/* Bus list exposed */ extern struct rte_bus_list rte_bus_list; +#define FOREACH_BUS (bus_p) TAILQ_FOREACH(bus_p, &rte_bus_list, next) +/** * Bus specific scan for devices attached on the bus. * For each bus object, the scan would be reponsible for finding devices and
@@ -94,6 +96,33 @@ typedef int (*rte_bus_scan_t)(void);typedef int (*rte_bus_probe_t )(void );/** +* Attach a device to a bus, assuming it is 'connected' to the bus. +* A bus is responsible for scanning for devices. Attaching a new device is +* for reenabling the device after being detached/removed. +* +* @param device_name +* Name of the device to attach. +* +* @return +* 0 for successful attach +* !0 for unsuccessful attach (or incorrect device name) +*/ +typedef int (*rte_bus_attach_t )(const char *device_name); + +/** +* Detach a named device from a bus. Implementation would check the existence +* of device on the bus and detach it. +* +* @param device_name +* Name of the device to detach +* +* @return +* 0 for successful detaching +* !0 if device not found or can't detach +*/ +typedef int (*rte_bus_detach_t )(const char *device_name); + +/** * A structure describing a generic bus. */ struct rte_bus {
@@ -101,6 +130,8 @@ struct rte_bus {const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ +rte_bus_attach_t attach;/**< Attach a named device */ +rte_bus_detach_t detach;/**< Detach a named device */ };/**
lib/librte_eal/common/include/rte_pci.h +30 -15
57 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -0
@@ -720,6 +720,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
Signature · 1 line
2.7.4
Re: [PATCH v8 9/9] eal: enable hotplugging of devices on bus
Quoted 4 lines · Shreyansh Jain
Given a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.
Signed-off-by Shreyansh Jain <[email protected]>
v9 cover Introducing EAL Bus-Device-Driver Model
In reply to Shreyansh JainLink to v8: [18]
:: Introduction ::
DPDK has been inherently a PCI inclined framework. Because of this, the design of device tree (or list) within DPDK is also PCI inclined. A non-PCI device doesn't have a way of being expressed without using hooks started from EAL to PMD.
(Check 'Version Changes' section for changes)
:: Overview of the Proposed Changes ::
Assuming the below graph for a computing node:
device A1
|
+==.===='==============.============+ Bus A.
| `--> driver A11 \
device A2 `-> driver A12 \______
|CPU |
/`````
device B1 /
| /
+==.===='==============.============+ Bus B`
| `--> driver B11
device B2 `-> driver B12 - 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
In [15], model assumes that rte_bus would be the base class using which all the bus implementations would instantiate the objects. This patches takes a much more basic approach, on the same lines of rte_device/ rte_driver and rte_pci_device/rte_pci_driver.
This is based on various review comments as well as offline (IRC) discussions.
- rte_bus is an abstract class which includes basic methods supported by all buses.
- specific implementation, for example for PCI rte_pci_bus, would extend this class to form their own buses, with their own bus specific device and driver list.
-
+-----------------+ |rte_pci_bus | |+---------------+| ||rte_bus || |+---------------+| +-----------------+
And example implementation would look like:
.--------------->+-------------------+
| |rte_pci_bus |
| | +----------------+|
| | |rte_bus <------.
| | | name || |
| | | scan || |
| | | probe || |
| | | attach || |
| | | detach || |
| | +----------------+| |
| | pci_driver_list | |
| .-------------->pci_device_list | |
| | | ... | |
| | +-------------------+ |
| | |
| +-------------------+ |
| |rte_pci_device | |
'----bus | |
| +----------------+| |
| |rte_device || |
| | bus --------------------------------'
| | ... ||
| +----------------+|
| ... |
+-------------------+:: Brief about Patch Layout ::
0001~0002: Introducing the basic Bus model and associated test case
0003 : Split the PCI match into a separate function
0004 : Remove an unnecessary loop over drivers in device detach
0005~0006: Introduce bus->scan and bus->probe APIs
0007 : Integrate the bus with EAL, without removing existing device
driver init/scan model.
0008 : Add PCI Bus over Bus patches introduced earlier
0009~0010: Update the Bus and PCI test cases for scanning/probing
0011 : Enable PCI bus and remove code for direct PCI scan/probe from
EAL
0012 : Add device hotplugging over the bus and introduce PCI helpers
:: Pending Changes/Caveats ::
1. This patchset only moves the PCI into a bus. And, that movement is also currently part of the EAL (lib/librte_eal/linux)
Eventual aim is the PCI bus reside in driver/bus/pci
2. Though the implementation for bus is common for Linux and BSD, the PCI bus implementation has been done/tested only for Linux.
3. RTE_REGISTER_BUS has been declared with contructor priority of 101 It is important that Bus is registered *before* drivers are registered. Only way I could find to assure that was via __attribute(contructor(priority)) of GCC. I am not sure how it would behave on other compilers. Any suggestions?
- One suggestion from David Marchand was to use global bus object handles, which I have not implemented for now. If that is common choice, I will change in v3.
4. Hotplugging has been introduced over Bus with a caveat - it would only work for ports/NICs already scanned and available in the bus list.
:: ToDo list ::
- Bump to librte_eal version
- Documentation continues to have references to some _old_ PCI symbols
:: References ::
[1] http://dpdk.org/ml/archives/dev/2016-November/050186.html
[2] http://dpdk.org/ml/archives/dev/2016-November/050622.html
[3] http://dpdk.org/ml/archives/dev/2016-November/050416.html
[4] http://dpdk.org/ml/archives/dev/2016-November/050567.html
[5] http://dpdk.org/ml/archives/dev/2016-November/050628.html
[6] http://dpdk.org/ml/archives/dev/2016-November/050415.html
[7] http://dpdk.org/ml/archives/dev/2016-November/050443.html
[8] http://dpdk.org/ml/archives/dev/2016-November/050624.html
[9] http://dpdk.org/ml/archives/dev/2016-November/050296.html
[10] http://dpdk.org/ml/archives/dev/2016-December/051349.html - v1
[12] http://dpdk.org/ml/archives/dev/2016-December/052092.html - v2
[13] http://dpdk.org/ml/archives/dev/2016-December/052381.html - v3
[14] http://dpdk.org/ml/archives/dev/2016-December/053302.html - v4
[15] http://dpdk.org/ml/archives/dev/2016-December/053315.html - v5
[16] http://dpdk.org/ml/archives/dev/2017-January/055120.html - v6 [17] http://dpdk.org/ml/archives/dev/2017-January/055320.html - v7 [18] http://dpdk.org/ml/archives/dev/2017-January/055398.html - v8
:: Version Changes ::
v9:
- Removed comments over function definitions
- Documentation fixes as per review comments
- Split the test_pci and test_bus patches
- Split the patches for generic bus changes and PCI level bus changes
- Add bus_autotest as entry into autotest_data.py
v8:
- fix return value bug in rte_eal_pci_attach and rte_eal_pci_detach
v7:
- update to rte_pci_match for const parameters
- remove unnecessary log messages in probe; moved _after_ matching of device and driver
- bug fixes in attach/detach methods
- PCI disable for debugging was missed (from rte_eal_pci_init) in v6
v6:
- Rearchitecture to bring bus object parallel to rte_device/driver This majorly includes:
-- rte_pci_bus class and pci_bus as its object for PCI -- bus->attach/detach (hotplugging)
-- removing bus->match as that is local to an implementation
- rename symbols rte_eal_bus_* to rte_bus_*
- restructuring patches (order) for simplicity
- update to test_pci
v5:
- Fix checkpatch error in Patch 0003
v4:
- rebase over master (eac901ce)
- Fix a bug in test_bus while setup and cleanup
- rename rte_eal_get_bus to rte_eal_bus_get
- Add helper (iterator) macros for easy bus,device,driver traversal
- removed 0001 patch as it is already merged in master
- fix missing rte_eal_bus_insert_device symbol in map file
v3:
- rebase over master (c431384c8f)
- revert patch 0001 changes for checkpatch (container_of macro)
- qat/rte_qat_cryptodev update for rte_driver->probe
- test_pci update for using a test_pci_bus for verification
- some bug fixes based on internal testing.
-- rte_eal_dev_attach not handling devargs
-- blacklisting not working
v2:
- No more bus->probe()
Now, rte_eal_bus_probe() calls rte_driver->probe based on match output
- new functions, rte_eal_pci_probe and rte_eal_pci_remove have been added as glue code between PCI PMDs and PCI Bus
`-> PMDs are updated to use these new functions as callbacks for
rte_driver
- 'default' keyword has been removed from match and scan
- Fix for incorrect changes in mlx* and nicvf*
- Checkpatch fixes
- Some variable checks have been removed from internal functions; functions which are externally visible continue to have such checks
- Some rearrangement of patches:
-- changes to drivers have been separated from EAL changes (but this
does make PCI PMDs non-working for a particular patch)
Shreyansh Jain (12):
eal/bus: introduce bus abstraction
test: add basic bus infrastructure tests
pci: split match and probe function
eal: remove loop over drivers in device detach eal/bus: support for scanning of bus eal/bus: introduce support for bus probing
eal: integrate bus scan and probe with EAL eal/pci: add support for PCI bus
test: add test cases for scan and probe on BUS
test: add Bus based scan and probe test cases for PCI
eal: enable PCI bus
eal: enable hotplugging of devices on bus
app/test/Makefile | 2 +- app/test/autotest_data.py | 6 + app/test/test.h | 2 + app/test/test_bus.c | 686 ++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++-- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 13 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 17 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 15 +- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 138 +++++ lib/librte_eal/common/eal_common_dev.c | 56 +- lib/librte_eal/common/eal_common_pci.c | 374 ++++++++----- lib/librte_eal/common/eal_private.h | 10 - lib/librte_eal/common/include/rte_bus.h | 191 +++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/common/include/rte_pci.h | 148 ++++- lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal.c | 13 +- lib/librte_eal/linuxapp/eal/eal_pci.c | 57 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 15 +- 21 files changed, 1636 insertions(+), 276 deletions(-) create mode 100644 app/test/test_bus.c create mode 100644 lib/librte_eal/common/eal_common_bus.c create mode 100644 lib/librte_eal/common/include/rte_bus.h
Signature · 1 line
2.7.4
PATCH v9 1/12 eal/bus: introduce bus abstraction
This patch introduces the rte_bus abstraction for EAL.
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' base class which would be extended for specific implementations. It also introduces Bus registration and deregistration functions.
An example implementation would be like:
.--------------->+-------------------+
| |rte_pci_bus |
| | +----------------+|
| | |rte_bus <------.
| | | name || |
| | | scan || |
| | | match || |
| | | probe || |
| | | remove || |
| | | ... || |
| | +----------------+| |
| | pci_driver_list | |
| .-------------->pci_device_list | |
| | | ... | |
| | +-------------------+ |
| | |
| +-------------------+ |
| |rte_pci_device | |
'----bus | |
| +----------------+| |
| |rte_device || |
| | bus --------------------------------'
| | ... ||
| +----------------+|
| ... |
+-------------------+--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 10 +++ lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 95 ++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 111 ++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/rte_eal_version.map | 10 +++ 8 files changed, 230 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
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -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
lib/librte_eal/bsdapp/eal/rte_eal_version.map +10 -0
@@ -174,3 +174,13 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_list; + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
lib/librte_eal/common/Makefile +1 -1
@@ -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
lib/librte_eal/common/eal_common_bus.c new file +95 -0
95 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h new file +111 -0
111 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +1 -0
@@ -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 */ const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -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
lib/librte_eal/linuxapp/eal/rte_eal_version.map +10 -0
@@ -178,3 +178,13 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_list; + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
Signature · 1 line
2.7.4
Re: [PATCH v9 01/12] eal/bus: introduce bus abstraction
2017-01-18 16:07, Shreyansh Jain:
Quoted 6 lines
lib/librte_eal/common/eal_common_bus.c new file +6
-0+void +rte_bus_register (struct rte_bus *bus) +{ +RTE_VERIFY (bus); +RTE_VERIFY (bus->name &&strlen (bus->name)); +
lib/librte_eal/common/eal_common_bus.c line 63
Quoted 10 lines
lib/librte_eal/common/eal_common_bus.c new file +10
-0+TAILQ_INSERT_TAIL (&rte_bus_list, bus, next); +RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name); +} + +void +rte_bus_unregister (struct rte_bus *bus) +{ +TAILQ_REMOVE (&rte_bus_list, bus, next); +RTE_LOG (INFO ,EAL ,"Unregistered [%s] bus.\n" , bus->name); +}
This log should be DEBUG, consistently with "register" one.
lib/librte_eal/bsdapp/eal/rte_eal_version.map DPDK_16.11 { · line 181
Quoted 4 lines
lib/librte_eal/bsdapp/eal/rte_eal_version.map +4
-0+DPDK_17.02 { + global: + + rte_bus_list;
So finally, is it an useful symbol?
Could it be removed from this patch?
Re: [PATCH v9 01/12] eal/bus: introduce bus abstraction
Quoted 18 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, January 18, 2017 4:16 PM
To: Shreyansh Jain <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v9 01/12] eal/bus: introduce bus abstraction2017-01-18 16:07, Shreyansh Jain:
Quoted 10 lines
lib/librte_eal/common/eal_common_bus.c new file +10
-0+void +rte_bus_register (struct rte_bus *bus) +{ +RTE_VERIFY (bus); +RTE_VERIFY (bus->name &&strlen (bus->name)); + +TAILQ_INSERT_TAIL (&rte_bus_list, bus, next); +RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name); +} +
Quoted 8 lines
lib/librte_eal/common/eal_common_bus.c line 63
Quoted 6 lines
lib/librte_eal/common/eal_common_bus.c new file +6
-0+void +rte_bus_unregister (struct rte_bus *bus) +{ +TAILQ_REMOVE (&rte_bus_list, bus, next); +RTE_LOG (INFO ,EAL ,"Unregistered [%s] bus.\n" , bus->name); +}This log should be DEBUG, consistently with "register" one.
:(
Obvious miss.
I will change it.
Quoted 8 lines
lib/librte_eal/bsdapp/eal/rte_eal_version.map DPDK_16.11 { · line 181
Quoted 5 lines
lib/librte_eal/bsdapp/eal/rte_eal_version.map +4
-0+DPDK_17.02 { + global: + + rte_bus_list;So finally, is it an useful symbol?
Could it be removed from this patch?
It is required until test_bus is re-written.
I can move this to next patch (which introduces test_bus).
PATCH v9 2/12 test: add basic bus infrastructure tests
In reply to Shreyansh JainVerification of bus registration, deregistration methods.
--- app/test/Makefile | 2 +- app/test/autotest_data.py | 6 + app/test/test.h | 2 + app/test/test_bus.c | 359 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 3 + 5 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 app/test/test_bus.c
app/test/Makefile +1 -1
@@ -94,7 +94,7 @@ SRCS-y += test_cycles.c SRCS-y += test_spinlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c - +SRCS-y += test_bus.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c SRCS-y += test_pmd_perf.c
app/test/autotest_data.py +6 -0
@@ -239,6 +239,12 @@ def per_sockets(num): "Func": default_autotest, "Report": None, }, + { + "Name": "Bus autotest", + "Command": "bus_autotest", + "Func": default_autotest, + "Report": None, + }, ] }, {
app/test/test.h +2 -0
@@ -236,6 +236,8 @@ int commands_init(void);int test_pci (void );int test_pci_run; +int test_bus (void ); +int test_mp_secondary (void );int test_set_rxtx_conf (cmdline_fixed_string_t mode);
app/test/test_bus.c new file +359 -0
359 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +3 -0
@@ -56,6 +56,9 @@ extern "C" {/** Double linked list of buses */ TAILQ_HEAD (rte_bus_list, rte_bus); +/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list; +/** * A structure describing a generic bus. */
Signature · 1 line
2.7.4
PATCH v9 3/12 pci: split match and probe function
In reply to Shreyansh JainMatching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev).
Splitting the matching function into a public fn rte_pci_match.
--- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_pci.c | 189 +++++++++++++----------- lib/librte_eal/common/include/rte_pci.h | 15 ++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 121 insertions(+), 85 deletions(-)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
@@ -182,5 +182,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match; } DPDK_16.11;
lib/librte_eal/common/eal_common_pci.c +104 -85
233 lines not on this page · raw message
lib/librte_eal/common/include/rte_pci.h +15 -0
@@ -371,6 +371,21 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,int rte_eal_pci_scan (void );/** +* Match the PCI Driver and Device using the ID Table +* +* @param pci_drv +* PCI driver from which ID table would be extracted +* @param pci_dev +* PCI device to match against the driver +* @return +* 0 for successful match +* !0 for unsuccessful match +*/ +int +rte_pci_match (const struct rte_pci_driver *pci_drv, +const struct rte_pci_device *pci_dev); + +/** * Probe the PCI bus for registered drivers. * * Scan the content of the PCI bus, and call the probe() function for
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -0
@@ -186,5 +186,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match; } DPDK_16.11;
Signature · 1 line
2.7.4
PATCH v9 4/12 eal: remove loop over drivers in device detach
In reply to Shreyansh Jainrte_eal_pci_detach calls pci_detach_all_drivers which loops over all PCI drivers for detaching the device. This is unnecessary as the device already has the PCI driver reference which can be used directly.
Removing pci_detach_all_drivers and restructuring rte_eal_pci_detach and rte_eal_pci_detach_dev to work without looping over driver list.
--- lib/librte_eal/common/eal_common_pci.c | 41 +++++++++------------------------- 1 file changed, 10 insertions(+), 31 deletions(-)
lib/librte_eal/common/eal_common_pci.c +10 -31
@@ -259,15 +259,17 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,* driver. */ static int -rte_eal_pci_detach_dev (struct rte_pci_driver *dr, -struct rte_pci_device *dev) +rte_eal_pci_detach_dev (struct rte_pci_device *dev) {int ret;struct rte_pci_addr *loc; +struct rte_pci_driver *dr; -if ((dr ==NULL ) || (dev ==NULL )) +if ((dev ==NULL ))return -EINVAL ; + dr = dev->driver; + ret =rte_pci_match (dr, dev);if (ret) {/* Device and driver don't match */
@@ -328,33 +330,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev) }/* -* If vendor/device ID match, call the remove() function of all -* registered driver for the given device. Return -1 if initialization -* failed, return 1 if no driver is found for this device. -*/ -static int -pci_detach_all_drivers (struct rte_pci_device *dev) -{ -struct rte_pci_driver *dr =NULL ; -int rc =0 ; - -if (dev ==NULL ) -return -1 ; - - TAILQ_FOREACH(dr, &pci_driver_list, next) { - rc =rte_eal_pci_detach_dev (dr, dev); -if (rc <0 ) -/* negative value is an error */ -return -1 ; -if (rc >0 ) -/* positive value means driver doesn't support it */ -continue ; -return 0 ; - } -return 1 ; -} - -/* * Find the pci device specified by pci address, then invoke probe function of * the driver of the devive. */
@@ -407,9 +382,13 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ; - ret =pci_detach_all_drivers (dev); + ret =rte_eal_pci_detach_dev (dev);if (ret <0 ) +/* negative value is an error */ goto err_return; +if (ret >0 ) +/* positive value means driver doesn't support it */ +continue ;TAILQ_REMOVE (&pci_device_list, dev, next);free (dev);
Signature · 1 line
2.7.4
Re: [PATCH v9 04/12] eal: remove loop over drivers in device detach
Thomas,
Quoted 8 lines · Shreyansh Jain
lib/librte_eal/common/eal_common_pci.c +0
-0@@ -259,15 +259,17 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,* driver. */ static int
lib/librte_eal/common/eal_common_pci.c rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, · line 268
Quoted 10 lines
lib/librte_eal/common/eal_common_pci.c +3
-3-rte_eal_pci_detach_dev(struct rte_pci_driver *dr, - struct rte_pci_device *dev) +rte_eal_pci_detach_dev(struct rte_pci_device *dev) {int ret;struct rte_pci_addr *loc; +struct rte_pci_driver *dr; -if ((dr ==NULL ) || (dev ==NULL )) +if ((dev ==NULL ))
There is a checkpatch warning here which missed my check (double paranthesis). Let me know if you want me to send v10 for this. Or, if there is anything major, I will send it along with that.
lib/librte_eal/common/eal_common_pci.c rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, · line 274
Quoted 6 lines
lib/librte_eal/common/eal_common_pci.c +2
-0return -EINVAL ; + dr = dev->driver; + ret =rte_pci_match (dr, dev);if (ret) {
-
Shreyansh
Re: [PATCH v9 04/12] eal: remove loop over drivers in device detach
In reply to Shreyansh Jain2017-01-18 16:07, Shreyansh Jain:
lib/librte_eal/common/eal_common_pci.c rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, · line 273
Quoted 4 lines
lib/librte_eal/common/eal_common_pci.c +2
-0+ dr = dev->driver; + ret =rte_pci_match (dr, dev);
I think you don't need to match driver anymore.
Re: [PATCH v9 04/12] eal: remove loop over drivers in device detach
Quoted 7 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, January 18, 2017 4:43 PM
To: Shreyansh Jain <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v9 04/12] eal: remove loop over drivers in device detach
Quoted 7 lines
2017-01-18 16:07, Shreyansh Jain:
lib/librte_eal/common/eal_common_pci.c rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, · line 273
Quoted 4 lines
lib/librte_eal/common/eal_common_pci.c +2
-0+ dr = dev->driver; + ret =rte_pci_match (dr, dev);I think you don't need to match driver anymore.
:(
I really need to have a strong shot of caffeine.
Will send out in v10.
PATCH v9 5/12 eal/bus: support for scanning of bus
In reply to Shreyansh JainScan for bus discovers the devices available on the bus and adds them to a bus specific device list. Each bus mandatorily implements this method.
Test cases for Bus are also updated by this patch.
--- app/test/test_bus.c | 175 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_common_bus.c | 2 + lib/librte_eal/common/include/rte_bus.h | 14 +++ 3 files changed, 191 insertions(+)
app/test/test_bus.c +175 -0
@@ -106,10 +106,26 @@ struct dummy_bus_map {struct rte_bus_list orig_bus_list =TAILQ_HEAD_INITIALIZER (orig_bus_list); +/* Forward declarations for callbacks from bus */ + +/* Bus A +* Scan would register devA1 and devA2 to bus +*/ +static int scan_fn_for_busA (void ); + +/* Bus B +* Scan would register devB1 and devB2 to bus +*/ +static int scan_fn_for_busB (void ); + +/* generic implementations wrapped around by above declarations */ +static int generic_scan_fn (struct rte_bus *bus); +struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , + .scan = scan_fn_for_busA, }, };
@@ -117,6 +133,7 @@ struct dummy_bus busB = { .name = "busB_impl", /* busB */ .bus = { .name = "busB", + .scan = scan_fn_for_busB, }, };
@@ -226,9 +243,81 @@ dump_device_tree(void)printf ("------>8-------\n" ); } +/* @internal +* Move over the bus_map and find the entry matching the bus object +* passed as argument. +* For each device in that bus_map list, register. +* +* @param bus +* bus to scan againt test entry +* @return +* 0 for successful scan, even if no devices are found +* !0 for any error in scanning (like, invalid bus) +*/ +static int +generic_scan_fn (struct rte_bus *bus) +{ +int i =0 ; +struct dummy_device *ddev =NULL ; +struct dummy_bus_map *dbmap =NULL ; +struct dummy_bus *db =NULL ; + +if (!bus) +return -1 ; + +/* Extract the device tree node using the bus passed */ +for (i =0 ; bus_map[i].name; i++) { +if (!strcmp (bus_map[i].name, bus->name)) { + dbmap = &bus_map[i]; +break ; + } + } + +if (!dbmap) +return -1 ; + + db = dbmap->dbus; + +/* For all the devices in the device tree (bus_map), add device */ +for (i =0 ; dbmap->ddevices[i]; i++) { + ddev = dbmap->ddevices[i]; +TAILQ_INSERT_TAIL (&db->device_list, ddev, next); + ddev->dev.bus = bus; + } + +return 0 ; +} + +int +scan_fn_for_busA (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busA" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} + +int +scan_fn_for_busB (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busB" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} +static int test_bus_setup (void ) { +int i =0 ;struct rte_bus *bus_p =NULL ;/* Preserve the original bus list before executing test */
@@ -238,6 +327,13 @@ test_bus_setup(void)TAILQ_INSERT_TAIL (&orig_bus_list, bus_p, next); } +/* Initialize the bus lists */ +for (i =0 ; bus_map[i].name; i++) { +TAILQ_INIT (&bus_map[i].dbus->device_list); +TAILQ_INIT (&bus_map[i].dbus->driver_list); + } + +dump_device_tree ();return 0 ; }
@@ -336,6 +432,79 @@ test_bus_unregistration(void)return 0 ; } +static int +test_device_unregistration_on_bus (void ) +{ +int i; +struct rte_bus *bus =NULL ; +struct dummy_device *ddev; +struct dummy_bus *dbus; + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); +if (!bus) { +printf ("Unable to find bus (%s)\n" , + bus_map[i].name); +return -1 ; + } + + dbus = container_of(bus, struct dummy_bus, bus); +/* For bus 'bus', unregister all devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +TAILQ_REMOVE (&dbus->device_list, ddev, next); + } + } + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); + dbus = container_of(bus, struct dummy_bus, bus); + +if (!TAILQ_EMPTY (&dbus->device_list)) { +printf ("Unable to remove all devices on bus (%s)\n" , + bus->name); +return -1 ; + } + } + +/* All devices from all buses have been removed */ +printf ("All devices on all buses unregistered.\n" ); +dump_device_tree (); + +return 0 ; +} + +/* @internal +* For each bus registered, call the scan function to identify devices +* on the bus. +* +* @param void +* @return +* 0 for successful scan +* !0 for unsuccessful scan +* +*/ +static int +test_bus_scan (void ) +{ +int ret; +struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { +/* Call the scan function for each bus */ + ret = bus->scan (); +if (ret) { +printf ("Scan of buses failed.\n" ); +return -1 ; + } + } + +printf ("Scan of all buses completed.\n" ); +dump_device_tree (); + +return 0 ; +} + +int test_bus (void ) {
@@ -346,6 +515,12 @@ test_bus(void)if (test_bus_registration ())return -1 ; +if (test_bus_scan ()) +return -1 ; + +if (test_device_unregistration_on_bus ()) +return -1 ; +if (test_bus_unregistration ())return -1 ;
lib/librte_eal/common/eal_common_bus.c +2 -0
@@ -50,6 +50,8 @@ rte_bus_register(struct rte_bus *bus) {RTE_VERIFY (bus);RTE_VERIFY (bus->name &&strlen (bus->name)); +/* A bus should mandatorily have the scan implemented */ +RTE_VERIFY (bus->scan);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +14 -0
@@ -60,11 +60,25 @@ TAILQ_HEAD(rte_bus_list, rte_bus);extern struct rte_bus_list rte_bus_list;/** +* Bus specific scan for devices attached on the bus. +* For each bus object, the scan would be reponsible for finding devices and +* adding them to its private device list. +* +* A bus should mandatorily implement this method. +* +* @return +* 0 for successful scan +* <0 for unsuccessful scan with error value +*/ +typedef int (*rte_bus_scan_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ +rte_bus_scan_t scan;/**< Scan for devices attached to bus */ };/**
Signature · 1 line
2.7.4
PATCH v9 6/12 eal/bus: introduce support for bus probing
In reply to Shreyansh JainBus implementations can implement a probe handler to match the devices scanned against the drivers registered.
This patch introduces the callback which would be implemented for PCI in subsequent patch.
--- lib/librte_eal/common/eal_common_bus.c | 1 + lib/librte_eal/common/include/rte_bus.h | 13 +++++++++++++ 2 files changed, 14 insertions(+)
lib/librte_eal/common/eal_common_bus.c +1 -0
@@ -52,6 +52,7 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->name &&strlen (bus->name));/* A bus should mandatorily have the scan implemented */ RTE_VERIFY (bus->scan); +RTE_VERIFY (bus->probe);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +13 -0
@@ -73,12 +73,25 @@ extern struct rte_bus_list rte_bus_list;typedef int (*rte_bus_scan_t )(void );/** +* Implementation specific probe function which is responsible for linking +* devices on that bus with applicable drivers. +* +* This is called while iterating over each registered bus. +* +* @return +* 0 for successful probe +* !0 for any error while probing +*/ +typedef int (*rte_bus_probe_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ +rte_bus_probe_t probe;/**< Probe devices on bus */ };/**
Signature · 1 line
2.7.4
PATCH v9 7/12 eal: integrate bus scan and probe with EAL
In reply to Shreyansh JainAdd functions for scanning all the buses and performing probe on all the buses on EAL initialization.
Presently, no bus exists - in subseqent patches, PCI bus would be introduced.
--- lib/librte_eal/bsdapp/eal/eal.c | 7 +++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 ++ lib/librte_eal/common/eal_common_bus.c | 40 +++++++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 19 ++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 8 +++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 ++ 6 files changed, 78 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +7 -0
@@ -577,6 +577,9 @@ rte_eal_init(int argc, char **argv) rte_config.master_lcore, thread_id, cpuset, ret == 0 ? "" : "..."); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
@@ -613,6 +616,10 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" ); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -0
@@ -182,6 +182,8 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_bus_probe; + rte_bus_scan; rte_pci_match; } DPDK_16.11;
lib/librte_eal/common/eal_common_bus.c +40 -0
@@ -65,6 +65,46 @@ rte_bus_unregister(struct rte_bus *bus)RTE_LOG (INFO ,EAL ,"Unregistered [%s] bus.\n" , bus->name); } +/* Scan all the buses for registering devices */ +int +rte_bus_scan (void ) +{ +int ret; +struct rte_bus *bus =NULL ; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->scan (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Scan for (%s) bus failed.\n" , + bus->name); +/* Error in scanning any bus stops the EAL init. */ +return ret; + } + } + +return 0 ; +} + +/* Call bus specific probe */ +int +rte_bus_probe (void ) +{ +int ret; +struct rte_bus *bus; + +/* For each bus registered with EAL */ + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->probe (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Bus (%s) probe failed.\n" , + bus->name); +return ret; + } + } + +return 0 ; +} +/* Dump information of a single bus */ static int bus_dump_one (FILE *f,struct rte_bus *bus)
lib/librte_eal/common/include/rte_bus.h +19 -0
@@ -113,6 +113,25 @@ void rte_bus_register(struct rte_bus *bus);void rte_bus_unregister (struct rte_bus *bus);/** +* Scan all the buses attached to the framework. +* +* @return +* 0 in case of success in scanning all buses +* !0 in case of failure to scan +*/ +int rte_bus_scan (void ); + +/** +* For each device on the bus, perform a driver 'match' and call the +* bus's probe for device initialization. +* +* @return +* 0 for successful match/probe +* !0 otherwise +*/ +int rte_bus_probe (void ); + +/** * Dump information of all the buses registered with EAL. * * @param f
lib/librte_eal/linuxapp/eal/eal.c +8 -0
@@ -69,6 +69,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
@@ -844,6 +845,9 @@ rte_eal_init(int argc, char **argv)if (rte_eal_intr_init () <0 )rte_panic ("Cannot init interrupt-handling thread\n" ); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
@@ -884,6 +888,10 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" ); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/linuxapp/eal/rte_eal_version.map +2 -0
@@ -186,6 +186,8 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_bus_probe; + rte_bus_scan; rte_pci_match; } DPDK_16.11;
Signature · 1 line
2.7.4
PATCH v9 8/12 eal/pci: add support for PCI bus
In reply to Shreyansh JainBased on EAL Bus APIs, PCI bus callbacks and support functions are introduced in this patch.
EAL continues to have direct PCI init/scan calls as well. These would be removed in subsequent patches to enable bus only PCI devices.
--- lib/librte_eal/bsdapp/eal/eal.c | 1 + lib/librte_eal/bsdapp/eal/eal_pci.c | 11 ++++++ lib/librte_eal/common/eal_common_pci.c | 33 ++++++++++++++++ lib/librte_eal/common/include/rte_pci.h | 68 +++++++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 15 ++++++++ 5 files changed, 128 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +1 -0
@@ -64,6 +64,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
lib/librte_eal/bsdapp/eal/eal_pci.c +11 -0
@@ -673,3 +673,14 @@ rte_eal_pci_init(void) }return 0 ; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), + .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS (PCI_BUS_NAME , rte_pci_bus.bus);
lib/librte_eal/common/eal_common_pci.c +33 -0
@@ -71,6 +71,7 @@#include <rte_interrupts.h> #include <rte_log.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_per_lcore.h> #include <rte_memory.h>
@@ -487,3 +488,35 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver)rte_eal_driver_unregister (&driver->driver);TAILQ_REMOVE (&pci_driver_list, driver, next); } + +/* Add a PCI device to PCI Bus */ +void +rte_eal_pci_add_device (struct rte_pci_bus *pci_bus, +struct rte_pci_device *pci_dev) +{ +TAILQ_INSERT_TAIL (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus = &pci_bus->bus; +} + +/* Insert a PCI device into a predefined position in PCI bus */ +void +rte_eal_pci_insert_device (struct rte_pci_device *exist_pci_dev, +struct rte_pci_device *new_pci_dev) +{ +TAILQ_INSERT_BEFORE (exist_pci_dev, new_pci_dev, next); +/* Update Bus references */ + new_pci_dev->device.bus = exist_pci_dev->device.bus; +} + +/* Remove a PCI device from PCI bus */ +void +rte_eal_pci_remove_device (struct rte_pci_device *pci_dev) +{ +struct rte_pci_bus *pci_bus; + + pci_bus = container_of(pci_dev->device.bus, struct rte_pci_bus, bus); +TAILQ_REMOVE (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus =NULL ; +}
lib/librte_eal/common/include/rte_pci.h +68 -0
98 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci.c +15 -0
@@ -35,6 +35,7 @@#include <dirent.h> #include <rte_log.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_eal_memconfig.h> #include <rte_malloc.h>
@@ -54,6 +55,9 @@* IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it). */ +/* Forward declaration of PCI bus */ +struct rte_pci_bus rte_pci_bus; +static int pci_get_kernel_driver_by_path (const char *filename,char *dri_name) {
@@ -723,3 +727,14 @@ rte_eal_pci_init(void)return 0 ; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), + .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS (PCI_BUS_NAME , rte_pci_bus.bus);
Signature · 1 line
2.7.4
PATCH v9 9/12 test: add test cases for scan and probe on BUS
In reply to Shreyansh Jain--- app/test/test_bus.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+)
app/test/test_bus.c +152 -0
@@ -120,12 +120,15 @@ static int scan_fn_for_busB(void);/* generic implementations wrapped around by above declarations */ static int generic_scan_fn (struct rte_bus *bus); +static int generic_probe_fn (void ); +static int dummy_match_fn (struct rte_driver *drv,struct rte_device *dev);struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , .scan = scan_fn_for_busA, + .probe = generic_probe_fn, }, };
@@ -134,6 +137,7 @@ struct dummy_bus busB = { .bus = { .name = "busB", .scan = scan_fn_for_busB, + .probe = generic_probe_fn, }, };
@@ -288,6 +292,46 @@ generic_scan_fn(struct rte_bus *bus)return 0 ; } +/* @internal +* Obtain bus from driver object. Match the address of rte_device object +* with all the devices associated with that bus. +* +* Being a test function, all this does is validate that device object +* provided is available on the same bus to which driver is registered. +* +* @param drv +* driver to match with +* @param dev +* device object +* @return +* 0 for successful match +* !0 for failed match +*/ +static int +dummy_match_fn(struct rte_driver *drv __rte_unused, struct rte_device *dev) +{ +struct rte_bus *bus; +struct dummy_device *ddev =NULL ; +struct dummy_device *ddev_as_arg; +struct dummy_bus *dbus =NULL ; + +/* Match is based entirely on address of 'dev' and 'dev_p' extracted +* from bus->device_list. +*/ + +/* a driver is registered with the bus *before* the scan. */ + bus = dev->bus; + dbus = container_of(bus, struct dummy_bus, bus); + ddev_as_arg = container_of(dev, struct dummy_device, dev); + + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +if (ddev == ddev_as_arg) +return 0 ; + } + +return 1 ; +} +int scan_fn_for_busA (void ) {struct dummy_bus_map *dbm;
@@ -504,6 +548,110 @@ test_bus_scan(void)return 0 ; } +/* +* +*/ +static int +generic_probe_fn (void ) +{ +int ret =0 ; +int i, j; +struct rte_driver *drv; +struct rte_device *dev; +struct dummy_bus *dbus =NULL ; +struct dummy_device *ddev =NULL ; +struct dummy_driver *ddrv =NULL ; + +/* In case of this test: +* 1. for each bus in rte_bus_list +* 2. for each device on that bus (bus specific->device_list) +* 3. for each driver on that bus (bus specific->driver_list) +* 4. call match +* 5. link driver and device +* 6. Verify the linkage. +*/ +for (i =0 ; bus_map[i].name; i++) { +/* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + +/* Looping over all scanned devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +/* There is a list of drivers within dummy_bus_map. +* In case of PMDs, this would be driver registration +* APIs/list +*/ +for (j =0 ; bus_map[i].ddrivers[j]; j++) { + ddrv = bus_map[i].ddrivers[j]; + + drv = &ddrv->drv; + dev = &ddev->dev; + ret =dummy_match_fn (drv, dev); +if (!ret) { +/* As match is generic, it always +* results in dev->drv pointing to +* first driver entry in bus_map[i] +*/ + dev->driver = drv; + dev->bus = &dbus->bus; + } +/* Else, continue */ + } + } + } + +/* Verify the linkage. All devices belonging to a bus_map[i] +* should have same driver (first driver entry of bus_map[i]) +*/ +for (i =0 ; bus_map[i].name; i++) { + ddrv = bus_map[i].ddrivers[0 ]; + drv = &ddrv->drv; + +for (j =0 ; bus_map[i].ddevices[j]; j++) { + ddev = bus_map[i].ddevices[j]; + dev = &ddev->dev; +if (dev->driver != drv) { +printf ("Incorrect driver<->device linkage.\n" ); +return -1 ; + } + } + } + +return 0 ; +} + +/* @internal +* Function to perform 'probe' and link devices and drivers on a bus. +* This would work over all the buses registered, and all devices and drivers +* registered with it - call match on each pair. +* +* @param void +* @return +* 0 for successful probe +* !0 for failure in probe +* +*/ +static int +test_probe_on_bus (void ) +{ +int ret =0 ; +int i; +struct dummy_bus *dbus; +struct rte_bus *bus; + +for (i =0 ; bus_map[i].name; i++) { +/* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + bus = &dbus->bus; + ret = bus->probe (); +if (ret) +printf ("Probe for %s failed.\n" , bus_map[i].name); + } + +printf ("Probe on all buses successful.\n" ); +dump_device_tree (); + +return 0 ; +}int test_bus (void )
@@ -518,6 +666,10 @@ test_bus(void)if (test_bus_scan ())return -1 ; +/* Now that the devices and drivers are registered, perform probe */ +if (test_probe_on_bus ()) +return -1 ; +if (test_device_unregistration_on_bus ())return -1 ;
Signature · 1 line
2.7.4
PATCH v9 10/12 test: add Bus based scan and probe test cases for PCI
In reply to Shreyansh Jain--- app/test/test_pci.c | 164 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 114 insertions(+), 50 deletions(-)
app/test/test_pci.c +114 -50
@@ -38,9 +38,11 @@#include <sys/queue.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_ethdev.h> #include <rte_devargs.h> +#include <rte_tailq.h> #include "test.h" #include "resource.h"
@@ -61,10 +63,31 @@int test_pci_run =0 ;/* value checked by the multiprocess test */ static unsigned pci_dev_count; +struct test_pci_bus ; +static struct test_pci_bus *pci_bus;/* global reference to a Test PCI bus */ + +/** List of PCI devices */ +TAILQ_HEAD (test_pci_device_list, rte_pci_device); +/** List of PCI drivers */ +TAILQ_HEAD (test_pci_driver_list, rte_pci_driver);static int my_driver_init (struct rte_pci_driver *dr,struct rte_pci_device *dev); +struct test_pci_bus { +struct rte_bus bus; +struct test_pci_device_list test_device_list; +struct test_pci_driver_list test_driver_list; +}; + +struct test_pci_bus test_pci_bus = { + .bus = { + .name ="test_pci_bus" , + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, +}; +/* IXGBE NICS */ struct rte_pci_id my_driver_id[] = { {RTE_PCI_DEVICE (0x0001 ,0x1234 )},
@@ -79,7 +102,7 @@ struct rte_pci_id my_driver_id2[] = {struct rte_pci_driver my_driver = { .driver = { - .name ="test_driver" + .name ="test_driver" , }, .probe = my_driver_init, .id_table = my_driver_id,
@@ -88,7 +111,7 @@ struct rte_pci_driver my_driver = {struct rte_pci_driver my_driver2 = { .driver = { - .name ="test_driver2" + .name ="test_driver2" , }, .probe = my_driver_init, .id_table = my_driver_id2,
@@ -108,6 +131,55 @@ my_driver_init(__attribute__((unused)) struct rte_pci_driver *dr,return 0 ; } +/* dump devices on the bus */ +static void +do_pci_device_dump (FILE *f) +{ +int i; +struct rte_pci_device *dev =NULL ; + + TAILQ_FOREACH(dev, &test_pci_bus.test_device_list, next) { + +fprintf (f,PCI_PRI_FMT , dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); +fprintf (f," - vendor:%x device:%x\n" , dev->id.vendor_id, + dev->id.device_id); + +for (i =0 ; i !=sizeof (dev->mem_resource) / +sizeof (dev->mem_resource[0 ]); i++) { +fprintf (f," %16.16" PRIx64" %16.16" PRIx64"\n" , + dev->mem_resource[i].phys_addr, + dev->mem_resource[i].len); + } + } +} + +/* Dummy implementation for rte_eal_pci_probe() over test_pci_bus */ +static int +do_pci_bus_probe (void ) +{ +int ret; +struct rte_pci_device *device; +struct rte_pci_driver *driver; + + TAILQ_FOREACH(device, &test_pci_bus.test_device_list, next) { + TAILQ_FOREACH(driver, &test_pci_bus.test_driver_list, next) { + ret =rte_pci_match (driver, device); +if (!ret) { +if (!driver->probe) +continue ; + + device->driver = driver; + ret = driver->probe (driver, device); +if (ret !=0 ) +return ret; + } + } + } + +return 0 ; +} +static void blacklist_all_devices (void ) {
@@ -115,7 +187,7 @@ blacklist_all_devices(void)unsigned i =0 ;char pci_addr_str[16 ]; - TAILQ_FOREACH(dev, &pci_device_list, next) { + TAILQ_FOREACH(dev, &(test_pci_bus.test_device_list), next) {snprintf (pci_addr_str,sizeof (pci_addr_str),PCI_PRI_FMT , dev->addr.domain, dev->addr.bus, dev->addr.devid, dev->addr.function);
@@ -142,19 +214,11 @@ static void free_devargs_list(void) } } -/* backup real devices & drivers (not used for testing) */ -struct pci_driver_list real_pci_driver_list = -TAILQ_HEAD_INITIALIZER (real_pci_driver_list); -struct pci_device_list real_pci_device_list = -TAILQ_HEAD_INITIALIZER (real_pci_device_list); -REGISTER_LINKED_RESOURCE (test_pci_sysfs);static int test_pci_setup (void ) { -struct rte_pci_device *dev; -struct rte_pci_driver *dr;const struct resource *r;int ret;
@@ -167,22 +231,22 @@ test_pci_setup(void) ret =setenv ("SYSFS_PCI_DEVICES" ,"test_pci_sysfs/bus/pci/devices" ,1 );TEST_ASSERT_SUCCESS (ret,"failed to setenv" ); -/* Unregister original devices & drivers lists */ -while (!TAILQ_EMPTY (&pci_driver_list)) { - dr =TAILQ_FIRST (&pci_driver_list); -rte_eal_pci_unregister (dr); -TAILQ_INSERT_TAIL (&real_pci_driver_list, dr, next); - } +TAILQ_INIT (&test_pci_bus.test_device_list); +TAILQ_INIT (&test_pci_bus.test_driver_list); -while (!TAILQ_EMPTY (&pci_device_list)) { - dev =TAILQ_FIRST (&pci_device_list); -TAILQ_REMOVE (&pci_device_list, dev, next); -TAILQ_INSERT_TAIL (&real_pci_device_list, dev, next); - } +/* Create a new Bus called 'test_pci_bus' */ +/* Bus doesn't exist; Create the test bus */ +printf ("Creating a Test PCI bus\n" ); +rte_bus_register (&test_pci_bus.bus); + pci_bus = &test_pci_bus; + +printf ("Scan for Test devices and add to bus\n" ); + ret = pci_bus->bus.scan (); - ret =rte_eal_pci_scan ();TEST_ASSERT_SUCCESS (ret,"failed to scan PCI bus" ); -rte_eal_pci_dump (stdout); + +printf ("Dump of all devices scanned:\n" ); +do_pci_device_dump (stdout);return 0 ; }
@@ -190,10 +254,11 @@ test_pci_setup(void)static int test_pci_cleanup (void ) { -struct rte_pci_device *dev; -struct rte_pci_driver *dr; +struct rte_pci_device *dev =NULL ; +struct rte_pci_driver *dr =NULL ;const struct resource *r;int ret; +void *temp;unsetenv ("SYSFS_PCI_DEVICES" );
@@ -203,28 +268,23 @@ test_pci_cleanup(void) ret =resource_rm_by_tar (r);TEST_ASSERT_SUCCESS (ret,"Failed to delete resource %s" , r->name); +TEST_ASSERT_NOT_NULL (pci_bus,"Invalid bus specified" ); +/* * FIXME: there is no API in DPDK to free a rte_pci_device so we * cannot free the devices in the right way. Let's assume that we * don't care for tests. */ -while (!TAILQ_EMPTY (&pci_device_list)) { - dev =TAILQ_FIRST (&pci_device_list); -TAILQ_REMOVE (&pci_device_list, dev, next); + TAILQ_FOREACH_SAFE(dev, &(test_pci_bus.test_device_list), next, temp) { +TAILQ_REMOVE (&(test_pci_bus.test_device_list), dev, next); + dev->driver =NULL ; } -/* Restore original devices & drivers lists */ -while (!TAILQ_EMPTY (&real_pci_driver_list)) { - dr =TAILQ_FIRST (&real_pci_driver_list); -TAILQ_REMOVE (&real_pci_driver_list, dr, next); -rte_eal_pci_register (dr); + TAILQ_FOREACH_SAFE(dr, &(test_pci_bus.test_driver_list), next, temp) { +TAILQ_REMOVE (&(test_pci_bus.test_driver_list), dr, next); } -while (!TAILQ_EMPTY (&real_pci_device_list)) { - dev =TAILQ_FIRST (&real_pci_device_list); -TAILQ_REMOVE (&real_pci_device_list, dev, next); -TAILQ_INSERT_TAIL (&pci_device_list, dev, next); - } +rte_bus_unregister (&pci_bus->bus);return 0 ; }
@@ -234,16 +294,19 @@ test_pci_blacklist(void) {struct rte_devargs_list save_devargs_list; -printf ("Dump all devices\n" ); -TEST_ASSERT (TAILQ_EMPTY (&pci_driver_list), -"pci_driver_list not empty" ); +TEST_ASSERT_NOT_NULL (pci_bus,"Invalid bus specified" ); -rte_eal_pci_register (&my_driver); -rte_eal_pci_register (&my_driver2); +TEST_ASSERT (TAILQ_EMPTY (&test_pci_bus.test_driver_list), +"PCI Driver list not empty" ); + +/* Add test drivers to Bus */ +TAILQ_INSERT_TAIL (&test_pci_bus.test_driver_list, &my_driver, next); +TAILQ_INSERT_TAIL (&test_pci_bus.test_driver_list, &my_driver2, next); pci_dev_count =0 ; -printf ("Scan bus\n" ); -rte_eal_pci_probe (); + +printf ("Probe the Test Bus\n" ); +do_pci_bus_probe ();if (pci_dev_count ==0 ) {printf ("no device detected\n" );
@@ -257,8 +320,8 @@ test_pci_blacklist(void)blacklist_all_devices (); pci_dev_count =0 ; -printf ("Scan bus with all devices blacklisted\n" ); -rte_eal_pci_probe (); +printf ("Probe bus with all devices blacklisted\n" ); +do_pci_bus_probe ();free_devargs_list (); devargs_list = save_devargs_list;
@@ -270,8 +333,9 @@ test_pci_blacklist(void) test_pci_run =1 ; -rte_eal_pci_unregister (&my_driver); -rte_eal_pci_unregister (&my_driver2); +/* Clear the test drivers added to Test Bus */ +TAILQ_REMOVE (&(test_pci_bus.test_driver_list), &my_driver, next); +TAILQ_REMOVE (&(test_pci_bus.test_driver_list), &my_driver2, next);return 0 ; }
Signature · 1 line
2.7.4
PATCH v9 11/12 eal: enable PCI bus
In reply to Shreyansh JainRemove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.
--- lib/librte_eal/bsdapp/eal/eal.c | 7 ----- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 -- lib/librte_eal/common/eal_common_pci.c | 34 ++++++++++---------- lib/librte_eal/common/eal_private.h | 10 ------ lib/librte_eal/common/include/rte_pci.h | 22 +++++-------- lib/librte_eal/linuxapp/eal/eal.c | 7 ----- lib/librte_eal/linuxapp/eal/eal_pci.c | 42 +++++++++---------------- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 -- 9 files changed, 44 insertions(+), 86 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +0 -7
@@ -562,9 +562,6 @@ rte_eal_init(int argc, char **argv)if (rte_eal_timer_init () <0 )rte_panic ("Cannot init HPET or TSC timers\n" ); -if (rte_eal_pci_init () <0 ) -rte_panic ("Cannot init PCI\n" ); -eal_check_mem_on_local_socket ();if (eal_plugins_init () <0 )
@@ -613,10 +610,6 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); -/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
lib/librte_eal/bsdapp/eal/eal_pci.c +4 -0
@@ -365,6 +365,10 @@ rte_eal_pci_scan(void) .matches = &matches[0], }; +/* for debug purposes, PCI can be disabled */ +if (internal_config.no_pci) +return 0 ; + fd =open ("/dev/pci" ,O_RDONLY );if (fd <0 ) {RTE_LOG (ERR ,EAL ,"%s(): error opening /dev/pci\n" , __func__);
lib/librte_eal/bsdapp/eal/rte_eal_version.map +0 -2
@@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc;
lib/librte_eal/common/eal_common_pci.c +18 -16
@@ -83,11 +83,6 @@#include "eal_private.h" -struct pci_driver_list pci_driver_list = -TAILQ_HEAD_INITIALIZER (pci_driver_list); -struct pci_device_list pci_device_list = -TAILQ_HEAD_INITIALIZER (pci_device_list); -#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"const char *pci_get_sysfs_path (void )
@@ -317,7 +312,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)if (dev->driver !=NULL )return 0 ; - TAILQ_FOREACH(dr, &pci_driver_list, next) { +FOREACH_DRIVER_ON_PCIBUS (dr) { rc =rte_eal_pci_probe_one_driver (dr, dev);if (rc <0 )/* negative value is an error */
@@ -338,6 +333,7 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr) {struct rte_pci_device *dev =NULL ; +int ret =0 ;if (addr ==NULL )
@@ -349,7 +345,7 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)if (pci_update_device (addr) <0 ) goto err_return; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ;
@@ -379,7 +375,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)if (addr ==NULL )return -1 ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ;
@@ -391,7 +387,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)/* positive value means driver doesn't support it */ continue ; -TAILQ_REMOVE (&pci_device_list, dev, next); +rte_eal_pci_remove_device (dev);free (dev);return 0 ; }
@@ -420,7 +416,7 @@ rte_eal_pci_probe(void)if (rte_eal_devargs_type_count (RTE_DEVTYPE_WHITELISTED_PCI ) ==0 ) probe_all =1 ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {/* set devargs in PCI structure */ devargs =pci_devargs_lookup (dev);
@@ -468,7 +464,7 @@ rte_eal_pci_dump(FILE *f) {struct rte_pci_device *dev =NULL ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {pci_dump_one_device (f, dev); } }
@@ -477,16 +473,22 @@ rte_eal_pci_dump(FILE *f)void rte_eal_pci_register (struct rte_pci_driver *driver) { -TAILQ_INSERT_TAIL (&pci_driver_list, driver, next); -rte_eal_driver_register (&driver->driver); +TAILQ_INSERT_TAIL (&rte_pci_bus.driver_list, driver, next); +/* Update Bus references */ + driver->pci_bus = &rte_pci_bus; } -/* unregister a driver */ +/* Unregister a driver */ void rte_eal_pci_unregister (struct rte_pci_driver *driver) { -rte_eal_driver_unregister (&driver->driver); -TAILQ_REMOVE (&pci_driver_list, driver, next); +struct rte_pci_bus *pci_bus; + + pci_bus = driver->pci_bus; + +TAILQ_REMOVE (&pci_bus->driver_list, driver, next); +/* Update Bus references */ + driver->pci_bus =NULL ; }/* Add a PCI device to PCI Bus */
lib/librte_eal/common/eal_private.h +0 -10
@@ -108,16 +108,6 @@ int rte_eal_timer_init(void);*/ int rte_eal_log_init (const char *id,int facility); -/** -* Init the PCI infrastructure -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error -*/ -int rte_eal_pci_init (void ); -struct rte_pci_driver ;struct rte_pci_device ;
lib/librte_eal/common/include/rte_pci.h +7 -15
@@ -87,12 +87,6 @@ extern "C" {#include <rte_dev.h> #include <rte_bus.h> -TAILQ_HEAD (pci_device_list, rte_pci_device);/**< PCI devices in D-linked Q. */ -TAILQ_HEAD (pci_driver_list, rte_pci_driver);/**< PCI drivers in D-linked Q. */ - -extern struct pci_driver_list pci_driver_list;/**< Global list of PCI drivers. */ -extern struct pci_device_list pci_device_list;/**< Global list of PCI devices. */ -/** Pathname of PCI devices directory. */ const char *pci_get_sysfs_path (void );
@@ -124,6 +118,9 @@ TAILQ_HEAD(rte_pci_device_list, rte_pci_device);/** List of PCI drivers */ TAILQ_HEAD (rte_pci_driver_list, rte_pci_driver); +/* Extend PCI bus definition to users */ +extern struct rte_pci_bus rte_pci_bus; +/* PCI Bus iterators */ #define FOREACH_DEVICE_ON_PCIBUS (p) \ TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next)
@@ -208,8 +205,6 @@ struct rte_pci_device { .subsystem_device_id = PCI_ANY_ID#endif -struct rte_pci_driver ; -/** * Initialisation function for the driver called during PCI probing. */
@@ -416,17 +411,14 @@ rte_pci_match(const struct rte_pci_driver *pci_drv, const struct rte_pci_device *pci_dev);/** -* Probe the PCI bus for registered drivers. -* -* Scan the content of the PCI bus, and call the probe() function for -* all registered drivers that have a matching entry in its id_table -* for discovered devices. +* Probe the PCI bus * * @return * - 0 on success. -* - Negative on error. +* - !0 on error. */ -int rte_eal_pci_probe (void ); +int +rte_eal_pci_probe (void );/** * Map the PCI device resources in user space virtual memory address
lib/librte_eal/linuxapp/eal/eal.c +0 -7
@@ -803,9 +803,6 @@ rte_eal_init(int argc, char **argv)if (rte_eal_log_init (logid, internal_config.syslog_facility) <0 )rte_panic ("Cannot init logs\n" ); -if (rte_eal_pci_init () <0 ) -rte_panic ("Cannot init PCI\n" ); -#ifdef VFIO_PRESENT if (rte_eal_vfio_setup () <0 )rte_panic ("Cannot init VFIO\n" );
@@ -884,10 +881,6 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); -/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
lib/librte_eal/linuxapp/eal/eal_pci.c +15 -27
93 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0 -2
@@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc;
Signature · 1 line
2.7.4
PATCH v9 12/12 eal: enable hotplugging of devices on bus
In reply to Shreyansh JainGiven a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 + lib/librte_eal/common/eal_common_dev.c | 56 ++++++++++++++++----- lib/librte_eal/common/eal_common_pci.c | 89 +++++++++++++++++++++++++++++++-- lib/librte_eal/common/include/rte_bus.h | 31 ++++++++++++ lib/librte_eal/common/include/rte_pci.h | 45 +++++++++++------ lib/librte_eal/linuxapp/eal/eal_pci.c | 2 + 6 files changed, 193 insertions(+), 32 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
@@ -682,6 +682,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
lib/librte_eal/common/eal_common_dev.c +44 -12
94 lines not on this page · raw message
lib/librte_eal/common/eal_common_pci.c +84 -5
111 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +31 -0
@@ -59,6 +59,8 @@ TAILQ_HEAD(rte_bus_list, rte_bus);/* Bus list exposed */ extern struct rte_bus_list rte_bus_list; +#define FOREACH_BUS (bus_p) TAILQ_FOREACH(bus_p, &rte_bus_list, next) +/** * Bus specific scan for devices attached on the bus. * For each bus object, the scan would be reponsible for finding devices and
@@ -85,6 +87,33 @@ typedef int (*rte_bus_scan_t)(void);typedef int (*rte_bus_probe_t )(void );/** +* Attach a device to a bus, assuming it is 'connected' to the bus. +* A bus is responsible for scanning for devices. Attaching a new device is +* for reenabling the device after being detached/removed. +* +* @param device_name +* Name of the device to attach. +* +* @return +* 0 for successful attach +* !0 for unsuccessful attach (or incorrect device name) +*/ +typedef int (*rte_bus_attach_t )(const char *device_name); + +/** +* Detach a named device from a bus. Implementation would check the existence +* of device on the bus and detach it. +* +* @param device_name +* Name of the device to detach +* +* @return +* 0 for successful detaching +* !0 if device not found or can't detach +*/ +typedef int (*rte_bus_detach_t )(const char *device_name); + +/** * A structure describing a generic bus. */ struct rte_bus {
@@ -92,6 +121,8 @@ struct rte_bus {const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ +rte_bus_attach_t attach;/**< Attach a named device */ +rte_bus_detach_t detach;/**< Detach a named device */ };/**
lib/librte_eal/common/include/rte_pci.h +30 -15
57 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -0
@@ -720,6 +720,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
Signature · 1 line
2.7.4
2017-01-18 16:07, Shreyansh Jain:
Quoted 3 lines
:: ToDo list ::
- Bump to
librte_ealversion
Please, could you update doc/guides/rel_notes/deprecation.rst in v10? It is also the opportunity to update the EAL abiver.
v10 cover Introducing EAL Bus-Device-Driver Model
In reply to Shreyansh JainLink to v9: [19]
:: Introduction ::
DPDK has been inherently a PCI inclined framework. Because of this, the design of device tree (or list) within DPDK is also PCI inclined. A non-PCI device doesn't have a way of being expressed without using hooks started from EAL to PMD.
(Check 'Version Changes' section for changes)
:: Overview of the Proposed Changes ::
Assuming the below graph for a computing node:
device A1
|
+==.===='==============.============+ Bus A.
| `--> driver A11 \
device A2 `-> driver A12 \______
|CPU |
/`````
device B1 /
| /
+==.===='==============.============+ Bus B`
| `--> driver B11
device B2 `-> driver B12 - 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
In [15], model assumes that rte_bus would be the base class using which all the bus implementations would instantiate the objects. This patches takes a much more basic approach, on the same lines of rte_device/ rte_driver and rte_pci_device/rte_pci_driver.
This is based on various review comments as well as offline (IRC) discussions.
- rte_bus is an abstract class which includes basic methods supported by all buses.
- specific implementation, for example for PCI rte_pci_bus, would extend this class to form their own buses, with their own bus specific device and driver list.
-
+-----------------+ |rte_pci_bus | |+---------------+| ||rte_bus || |+---------------+| +-----------------+
And example implementation would look like:
.--------------->+-------------------+
| |rte_pci_bus |
| | +----------------+|
| | |rte_bus <------.
| | | name || |
| | | scan || |
| | | probe || |
| | | attach || |
| | | detach || |
| | +----------------+| |
| | pci_driver_list | |
| .-------------->pci_device_list | |
| | | ... | |
| | +-------------------+ |
| | |
| +-------------------+ |
| |rte_pci_device | |
'----bus | |
| +----------------+| |
| |rte_device || |
| | bus --------------------------------'
| | ... ||
| +----------------+|
| ... |
+-------------------+:: Brief about Patch Layout ::
0001~0002: Introducing the basic Bus model and associated test case
0003 : Split the PCI match into a separate function
0004 : Remove an unnecessary loop over drivers in device detach
0005~0006: Introduce bus->scan and bus->probe APIs
0007 : Integrate the bus with EAL, without removing existing device
driver init/scan model.
0008 : Add PCI Bus over Bus patches introduced earlier
0009~0010: Update the Bus and PCI test cases for scanning/probing
0011 : Enable PCI bus and remove code for direct PCI scan/probe from
EAL
0012 : Add device hotplugging over the bus and introduce PCI helpers
0013 : Remove the deprecation notice for rte_bus
:: Pending Changes/Caveats ::
1. This patchset only moves the PCI into a bus. And, that movement is also currently part of the EAL (lib/librte_eal/linux)
Eventual aim is the PCI bus reside in driver/bus/pci
2. Though the implementation for bus is common for Linux and BSD, the PCI bus implementation has been done/tested only for Linux.
3. RTE_REGISTER_BUS has been declared with contructor priority of 101 It is important that Bus is registered *before* drivers are registered. Only way I could find to assure that was via __attribute(contructor(priority)) of GCC. I am not sure how it would behave on other compilers. Any suggestions?
- One suggestion from David Marchand was to use global bus object handles, which I have not implemented for now. If that is common choice, I will change in v3.
4. Hotplugging has been introduced over Bus with a caveat - it would only work for ports/NICs already scanned and available in the bus list.
:: ToDo list ::
- Bump to librte_eal version
- Documentation continues to have references to some _old_ PCI symbols
:: References ::
[1] http://dpdk.org/ml/archives/dev/2016-November/050186.html
[2] http://dpdk.org/ml/archives/dev/2016-November/050622.html
[3] http://dpdk.org/ml/archives/dev/2016-November/050416.html
[4] http://dpdk.org/ml/archives/dev/2016-November/050567.html
[5] http://dpdk.org/ml/archives/dev/2016-November/050628.html
[6] http://dpdk.org/ml/archives/dev/2016-November/050415.html
[7] http://dpdk.org/ml/archives/dev/2016-November/050443.html
[8] http://dpdk.org/ml/archives/dev/2016-November/050624.html
[9] http://dpdk.org/ml/archives/dev/2016-November/050296.html
[10] http://dpdk.org/ml/archives/dev/2016-December/051349.html - v1
[12] http://dpdk.org/ml/archives/dev/2016-December/052092.html - v2
[13] http://dpdk.org/ml/archives/dev/2016-December/052381.html - v3
[14] http://dpdk.org/ml/archives/dev/2016-December/053302.html - v4
[15] http://dpdk.org/ml/archives/dev/2016-December/053315.html - v5
[16] http://dpdk.org/ml/archives/dev/2017-January/055120.html - v6 [17] http://dpdk.org/ml/archives/dev/2017-January/055320.html - v7 [18] http://dpdk.org/ml/archives/dev/2017-January/055398.html - v8 [19] http://dpdk.org/ml/archives/dev/2017-January/055621.html - v9
:: Version Changes ::
v10:
- bump to librte_eal LIBABIVER
- remove an unnecessary call to rte_pci_match
- INFO->DEBUG movement of a log message
- Checkpatch issue fix
- deprecation notice removal for rte_bus
v9:
- Removed comments over function definitions
- Documentation fixes as per review comments
- Split the test_pci and test_bus patches
- Split the patches for generic bus changes and PCI level bus changes
- Add bus_autotest as entry into autotest_data.py
v8:
- fix return value bug in rte_eal_pci_attach and rte_eal_pci_detach
v7:
- update to rte_pci_match for const parameters
- remove unnecessary log messages in probe; moved _after_ matching of device and driver
- bug fixes in attach/detach methods
- PCI disable for debugging was missed (from rte_eal_pci_init) in v6
v6:
- Rearchitecture to bring bus object parallel to rte_device/driver This majorly includes:
-- rte_pci_bus class and pci_bus as its object for PCI -- bus->attach/detach (hotplugging)
-- removing bus->match as that is local to an implementation
- rename symbols rte_eal_bus_* to rte_bus_*
- restructuring patches (order) for simplicity
- update to test_pci
v5:
- Fix checkpatch error in Patch 0003
v4:
- rebase over master (eac901ce)
- Fix a bug in test_bus while setup and cleanup
- rename rte_eal_get_bus to rte_eal_bus_get
- Add helper (iterator) macros for easy bus,device,driver traversal
- removed 0001 patch as it is already merged in master
- fix missing rte_eal_bus_insert_device symbol in map file
v3:
- rebase over master (c431384c8f)
- revert patch 0001 changes for checkpatch (container_of macro)
- qat/rte_qat_cryptodev update for rte_driver->probe
- test_pci update for using a test_pci_bus for verification
- some bug fixes based on internal testing.
-- rte_eal_dev_attach not handling devargs
-- blacklisting not working
v2:
- No more bus->probe()
Now, rte_eal_bus_probe() calls rte_driver->probe based on match output
- new functions, rte_eal_pci_probe and rte_eal_pci_remove have been added as glue code between PCI PMDs and PCI Bus
`-> PMDs are updated to use these new functions as callbacks for
rte_driver
- 'default' keyword has been removed from match and scan
- Fix for incorrect changes in mlx* and nicvf*
- Checkpatch fixes
- Some variable checks have been removed from internal functions; functions which are externally visible continue to have such checks
- Some rearrangement of patches:
-- changes to drivers have been separated from EAL changes (but this
does make PCI PMDs non-working for a particular patch)
Shreyansh Jain (13):
eal/bus: introduce bus abstraction
test: add basic bus infrastructure tests
pci: split match and probe function
eal: remove loop over drivers in device detach eal/bus: support for scanning of bus eal/bus: introduce support for bus probing
eal: integrate bus scan and probe with EAL eal/pci: add support for PCI bus
test: add test cases for scan and probe on BUS
test: add Bus based scan and probe test cases for PCI
eal: enable PCI bus
eal: enable hotplugging of devices on bus
doc: remove deprecation notice for rte_bus
app/test/Makefile | 2 +- app/test/autotest_data.py | 6 + app/test/test.h | 2 + app/test/test_bus.c | 686 ++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++-- doc/guides/rel_notes/deprecation.rst | 5 - lib/librte_eal/bsdapp/eal/Makefile | 3 +- lib/librte_eal/bsdapp/eal/eal.c | 13 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 17 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 15 +- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 138 +++++ lib/librte_eal/common/eal_common_dev.c | 56 +- lib/librte_eal/common/eal_common_pci.c | 368 ++++++++----- lib/librte_eal/common/eal_private.h | 10 - lib/librte_eal/common/include/rte_bus.h | 191 +++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/common/include/rte_pci.h | 148 ++++- lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal.c | 13 +- lib/librte_eal/linuxapp/eal/eal_pci.c | 57 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 15 +- 22 files changed, 1631 insertions(+), 284 deletions(-) create mode 100644 app/test/test_bus.c create mode 100644 lib/librte_eal/common/eal_common_bus.c create mode 100644 lib/librte_eal/common/include/rte_bus.h
Signature · 1 line
2.7.4
PATCH v10 1/13 eal/bus: introduce bus abstraction
This patch introduces the rte_bus abstraction for EAL.
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' base class which would be extended for specific implementations. It also introduces Bus registration and deregistration functions.
An example implementation would be like:
.--------------->+-------------------+
| |rte_pci_bus |
| | +----------------+|
| | |rte_bus <------.
| | | name || |
| | | scan || |
| | | match || |
| | | probe || |
| | | remove || |
| | | ... || |
| | +----------------+| |
| | pci_driver_list | |
| .-------------->pci_device_list | |
| | | ... | |
| | +-------------------+ |
| | |
| +-------------------+ |
| |rte_pci_device | |
'----bus | |
| +----------------+| |
| |rte_device || |
| | bus --------------------------------'
| | ... ||
| +----------------+|
| ... |
+-------------------+--- lib/librte_eal/bsdapp/eal/Makefile | 3 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 9 ++ lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 95 ++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 111 ++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 9 ++ 8 files changed, 230 insertions(+), 3 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_bus.c create mode 100644 lib/librte_eal/common/include/rte_bus.h
lib/librte_eal/bsdapp/eal/Makefile +2 -1
@@ -48,7 +48,7 @@ LDLIBS += -lgcc_s EXPORT_MAP := rte_eal_version.map -LIBABIVER := 3 +LIBABIVER := 4 # specific to bsdapp exec-env SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) := eal.c
@@ -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
lib/librte_eal/bsdapp/eal/rte_eal_version.map +9 -0
@@ -174,3 +174,12 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
lib/librte_eal/common/Makefile +1 -1
@@ -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
lib/librte_eal/common/eal_common_bus.c new file +95 -0
95 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h new file +111 -0
111 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +1 -0
@@ -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 */ const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */
lib/librte_eal/linuxapp/eal/Makefile +2 -1
@@ -37,7 +37,7 @@ ARCH_DIR ?= $(RTE_ARCH) EXPORT_MAP := rte_eal_version.map VPATH += $(RTE_SDK)/lib/librte_eal/common/arch/$(ARCH_DIR) -LIBABIVER := 3 +LIBABIVER := 4 VPATH += $(RTE_SDK)/lib/librte_eal/common
@@ -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
lib/librte_eal/linuxapp/eal/rte_eal_version.map +9 -0
@@ -178,3 +178,12 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
Signature · 1 line
2.7.4
PATCH v10 2/13 test: add basic bus infrastructure tests
In reply to Shreyansh JainVerification of bus registration, deregistration methods.
--- app/test/Makefile | 2 +- app/test/autotest_data.py | 6 + app/test/test.h | 2 + app/test/test_bus.c | 359 ++++++++++++++++++++++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/include/rte_bus.h | 3 + lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 7 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 app/test/test_bus.c
app/test/Makefile +1 -1
@@ -94,7 +94,7 @@ SRCS-y += test_cycles.c SRCS-y += test_spinlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c - +SRCS-y += test_bus.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c SRCS-y += test_pmd_perf.c
app/test/autotest_data.py +6 -0
@@ -239,6 +239,12 @@ def per_sockets(num): "Func": default_autotest, "Report": None, }, + { + "Name": "Bus autotest", + "Command": "bus_autotest", + "Func": default_autotest, + "Report": None, + }, ] }, {
app/test/test.h +2 -0
@@ -236,6 +236,8 @@ int commands_init(void);int test_pci (void );int test_pci_run; +int test_bus (void ); +int test_mp_secondary (void );int test_set_rxtx_conf (cmdline_fixed_string_t mode);
app/test/test_bus.c new file +359 -0
359 lines not on this page · raw message
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
@@ -178,6 +178,7 @@ DPDK_16.11 { DPDK_17.02 { global: + rte_bus_list; rte_bus_dump; rte_bus_register; rte_bus_unregister;
lib/librte_eal/common/include/rte_bus.h +3 -0
@@ -56,6 +56,9 @@ extern "C" {/** Double linked list of buses */ TAILQ_HEAD (rte_bus_list, rte_bus); +/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list; +/** * A structure describing a generic bus. */
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -0
@@ -182,6 +182,7 @@ DPDK_16.11 { DPDK_17.02 { global: + rte_bus_list; rte_bus_dump; rte_bus_register; rte_bus_unregister;
Signature · 1 line
2.7.4
PATCH v10 3/13 pci: split match and probe function
In reply to Shreyansh JainMatching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev).
Splitting the matching function into a public fn rte_pci_match.
--- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_pci.c | 189 +++++++++++++----------- lib/librte_eal/common/include/rte_pci.h | 15 ++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 121 insertions(+), 85 deletions(-)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
@@ -182,5 +182,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match; } DPDK_16.11;
lib/librte_eal/common/eal_common_pci.c +104 -85
233 lines not on this page · raw message
lib/librte_eal/common/include/rte_pci.h +15 -0
@@ -371,6 +371,21 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,int rte_eal_pci_scan (void );/** +* Match the PCI Driver and Device using the ID Table +* +* @param pci_drv +* PCI driver from which ID table would be extracted +* @param pci_dev +* PCI device to match against the driver +* @return +* 0 for successful match +* !0 for unsuccessful match +*/ +int +rte_pci_match (const struct rte_pci_driver *pci_drv, +const struct rte_pci_device *pci_dev); + +/** * Probe the PCI bus for registered drivers. * * Scan the content of the PCI bus, and call the probe() function for
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -0
@@ -186,5 +186,6 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_pci_match; } DPDK_16.11;
Signature · 1 line
2.7.4
PATCH v10 4/13 eal: remove loop over drivers in device detach
In reply to Shreyansh Jainrte_eal_pci_detach calls pci_detach_all_drivers which loops over all PCI drivers for detaching the device. This is unnecessary as the device already has the PCI driver reference which can be used directly.
Removing pci_detach_all_drivers and restructuring rte_eal_pci_detach and rte_eal_pci_detach_dev to work without looping over driver list.
--- lib/librte_eal/common/eal_common_pci.c | 47 +++++++--------------------------- 1 file changed, 9 insertions(+), 38 deletions(-)
lib/librte_eal/common/eal_common_pci.c +9 -38
@@ -259,21 +259,15 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,* driver. */ static int -rte_eal_pci_detach_dev (struct rte_pci_driver *dr, -struct rte_pci_device *dev) +rte_eal_pci_detach_dev (struct rte_pci_device *dev) { -int ret;struct rte_pci_addr *loc; +struct rte_pci_driver *dr; -if ((dr ==NULL ) || (dev ==NULL )) +if (dev ==NULL )return -EINVAL ; - ret =rte_pci_match (dr, dev); -if (ret) { -/* Device and driver don't match */ -return 1 ; - } - + dr = dev->driver; loc = &dev->addr; RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
@@ -328,33 +322,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev) }/* -* If vendor/device ID match, call the remove() function of all -* registered driver for the given device. Return -1 if initialization -* failed, return 1 if no driver is found for this device. -*/ -static int -pci_detach_all_drivers (struct rte_pci_device *dev) -{ -struct rte_pci_driver *dr =NULL ; -int rc =0 ; - -if (dev ==NULL ) -return -1 ; - - TAILQ_FOREACH(dr, &pci_driver_list, next) { - rc =rte_eal_pci_detach_dev (dr, dev); -if (rc <0 ) -/* negative value is an error */ -return -1 ; -if (rc >0 ) -/* positive value means driver doesn't support it */ -continue ; -return 0 ; - } -return 1 ; -} - -/* * Find the pci device specified by pci address, then invoke probe function of * the driver of the devive. */
@@ -407,9 +374,13 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ; - ret =pci_detach_all_drivers (dev); + ret =rte_eal_pci_detach_dev (dev);if (ret <0 ) +/* negative value is an error */ goto err_return; +if (ret >0 ) +/* positive value means driver doesn't support it */ +continue ;TAILQ_REMOVE (&pci_device_list, dev, next);free (dev);
Signature · 1 line
2.7.4
PATCH v10 5/13 eal/bus: support for scanning of bus
In reply to Shreyansh JainScan for bus discovers the devices available on the bus and adds them to a bus specific device list. Each bus mandatorily implements this method.
Test cases for Bus are also updated by this patch.
--- app/test/test_bus.c | 175 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_common_bus.c | 2 + lib/librte_eal/common/include/rte_bus.h | 14 +++ 3 files changed, 191 insertions(+)
app/test/test_bus.c +175 -0
@@ -106,10 +106,26 @@ struct dummy_bus_map {struct rte_bus_list orig_bus_list =TAILQ_HEAD_INITIALIZER (orig_bus_list); +/* Forward declarations for callbacks from bus */ + +/* Bus A +* Scan would register devA1 and devA2 to bus +*/ +static int scan_fn_for_busA (void ); + +/* Bus B +* Scan would register devB1 and devB2 to bus +*/ +static int scan_fn_for_busB (void ); + +/* generic implementations wrapped around by above declarations */ +static int generic_scan_fn (struct rte_bus *bus); +struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , + .scan = scan_fn_for_busA, }, };
@@ -117,6 +133,7 @@ struct dummy_bus busB = { .name = "busB_impl", /* busB */ .bus = { .name = "busB", + .scan = scan_fn_for_busB, }, };
@@ -226,9 +243,81 @@ dump_device_tree(void)printf ("------>8-------\n" ); } +/* @internal +* Move over the bus_map and find the entry matching the bus object +* passed as argument. +* For each device in that bus_map list, register. +* +* @param bus +* bus to scan againt test entry +* @return +* 0 for successful scan, even if no devices are found +* !0 for any error in scanning (like, invalid bus) +*/ +static int +generic_scan_fn (struct rte_bus *bus) +{ +int i =0 ; +struct dummy_device *ddev =NULL ; +struct dummy_bus_map *dbmap =NULL ; +struct dummy_bus *db =NULL ; + +if (!bus) +return -1 ; + +/* Extract the device tree node using the bus passed */ +for (i =0 ; bus_map[i].name; i++) { +if (!strcmp (bus_map[i].name, bus->name)) { + dbmap = &bus_map[i]; +break ; + } + } + +if (!dbmap) +return -1 ; + + db = dbmap->dbus; + +/* For all the devices in the device tree (bus_map), add device */ +for (i =0 ; dbmap->ddevices[i]; i++) { + ddev = dbmap->ddevices[i]; +TAILQ_INSERT_TAIL (&db->device_list, ddev, next); + ddev->dev.bus = bus; + } + +return 0 ; +} + +int +scan_fn_for_busA (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busA" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} + +int +scan_fn_for_busB (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busB" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} +static int test_bus_setup (void ) { +int i =0 ;struct rte_bus *bus_p =NULL ;/* Preserve the original bus list before executing test */
@@ -238,6 +327,13 @@ test_bus_setup(void)TAILQ_INSERT_TAIL (&orig_bus_list, bus_p, next); } +/* Initialize the bus lists */ +for (i =0 ; bus_map[i].name; i++) { +TAILQ_INIT (&bus_map[i].dbus->device_list); +TAILQ_INIT (&bus_map[i].dbus->driver_list); + } + +dump_device_tree ();return 0 ; }
@@ -336,6 +432,79 @@ test_bus_unregistration(void)return 0 ; } +static int +test_device_unregistration_on_bus (void ) +{ +int i; +struct rte_bus *bus =NULL ; +struct dummy_device *ddev; +struct dummy_bus *dbus; + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); +if (!bus) { +printf ("Unable to find bus (%s)\n" , + bus_map[i].name); +return -1 ; + } + + dbus = container_of(bus, struct dummy_bus, bus); +/* For bus 'bus', unregister all devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +TAILQ_REMOVE (&dbus->device_list, ddev, next); + } + } + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); + dbus = container_of(bus, struct dummy_bus, bus); + +if (!TAILQ_EMPTY (&dbus->device_list)) { +printf ("Unable to remove all devices on bus (%s)\n" , + bus->name); +return -1 ; + } + } + +/* All devices from all buses have been removed */ +printf ("All devices on all buses unregistered.\n" ); +dump_device_tree (); + +return 0 ; +} + +/* @internal +* For each bus registered, call the scan function to identify devices +* on the bus. +* +* @param void +* @return +* 0 for successful scan +* !0 for unsuccessful scan +* +*/ +static int +test_bus_scan (void ) +{ +int ret; +struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { +/* Call the scan function for each bus */ + ret = bus->scan (); +if (ret) { +printf ("Scan of buses failed.\n" ); +return -1 ; + } + } + +printf ("Scan of all buses completed.\n" ); +dump_device_tree (); + +return 0 ; +} + +int test_bus (void ) {
@@ -346,6 +515,12 @@ test_bus(void)if (test_bus_registration ())return -1 ; +if (test_bus_scan ()) +return -1 ; + +if (test_device_unregistration_on_bus ()) +return -1 ; +if (test_bus_unregistration ())return -1 ;
lib/librte_eal/common/eal_common_bus.c +2 -0
@@ -50,6 +50,8 @@ rte_bus_register(struct rte_bus *bus) {RTE_VERIFY (bus);RTE_VERIFY (bus->name &&strlen (bus->name)); +/* A bus should mandatorily have the scan implemented */ +RTE_VERIFY (bus->scan);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +14 -0
@@ -60,11 +60,25 @@ TAILQ_HEAD(rte_bus_list, rte_bus);extern struct rte_bus_list rte_bus_list;/** +* Bus specific scan for devices attached on the bus. +* For each bus object, the scan would be reponsible for finding devices and +* adding them to its private device list. +* +* A bus should mandatorily implement this method. +* +* @return +* 0 for successful scan +* <0 for unsuccessful scan with error value +*/ +typedef int (*rte_bus_scan_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ +rte_bus_scan_t scan;/**< Scan for devices attached to bus */ };/**
Signature · 1 line
2.7.4
PATCH v10 6/13 eal/bus: introduce support for bus probing
In reply to Shreyansh JainBus implementations can implement a probe handler to match the devices scanned against the drivers registered.
This patch introduces the callback which would be implemented for PCI in subsequent patch.
--- lib/librte_eal/common/eal_common_bus.c | 1 + lib/librte_eal/common/include/rte_bus.h | 13 +++++++++++++ 2 files changed, 14 insertions(+)
lib/librte_eal/common/eal_common_bus.c +1 -0
@@ -52,6 +52,7 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->name &&strlen (bus->name));/* A bus should mandatorily have the scan implemented */ RTE_VERIFY (bus->scan); +RTE_VERIFY (bus->probe);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +13 -0
@@ -73,12 +73,25 @@ extern struct rte_bus_list rte_bus_list;typedef int (*rte_bus_scan_t )(void );/** +* Implementation specific probe function which is responsible for linking +* devices on that bus with applicable drivers. +* +* This is called while iterating over each registered bus. +* +* @return +* 0 for successful probe +* !0 for any error while probing +*/ +typedef int (*rte_bus_probe_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ +rte_bus_probe_t probe;/**< Probe devices on bus */ };/**
Signature · 1 line
2.7.4
PATCH v10 7/13 eal: integrate bus scan and probe with EAL
In reply to Shreyansh JainAdd functions for scanning all the buses and performing probe on all the buses on EAL initialization.
Presently, no bus exists - in subseqent patches, PCI bus would be introduced.
--- lib/librte_eal/bsdapp/eal/eal.c | 7 +++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 ++ lib/librte_eal/common/eal_common_bus.c | 40 +++++++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 19 ++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 8 +++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 ++ 6 files changed, 78 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +7 -0
@@ -577,6 +577,9 @@ rte_eal_init(int argc, char **argv) rte_config.master_lcore, thread_id, cpuset, ret == 0 ? "" : "..."); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
@@ -613,6 +616,10 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" ); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -0
@@ -182,6 +182,8 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_bus_probe; + rte_bus_scan; rte_pci_match; } DPDK_16.11;
lib/librte_eal/common/eal_common_bus.c +40 -0
@@ -65,6 +65,46 @@ rte_bus_unregister(struct rte_bus *bus)RTE_LOG (DEBUG ,EAL ,"Unregistered [%s] bus.\n" , bus->name); } +/* Scan all the buses for registering devices */ +int +rte_bus_scan (void ) +{ +int ret; +struct rte_bus *bus =NULL ; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->scan (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Scan for (%s) bus failed.\n" , + bus->name); +/* Error in scanning any bus stops the EAL init. */ +return ret; + } + } + +return 0 ; +} + +/* Call bus specific probe */ +int +rte_bus_probe (void ) +{ +int ret; +struct rte_bus *bus; + +/* For each bus registered with EAL */ + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->probe (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Bus (%s) probe failed.\n" , + bus->name); +return ret; + } + } + +return 0 ; +} +/* Dump information of a single bus */ static int bus_dump_one (FILE *f,struct rte_bus *bus)
lib/librte_eal/common/include/rte_bus.h +19 -0
@@ -113,6 +113,25 @@ void rte_bus_register(struct rte_bus *bus);void rte_bus_unregister (struct rte_bus *bus);/** +* Scan all the buses attached to the framework. +* +* @return +* 0 in case of success in scanning all buses +* !0 in case of failure to scan +*/ +int rte_bus_scan (void ); + +/** +* For each device on the bus, perform a driver 'match' and call the +* bus's probe for device initialization. +* +* @return +* 0 for successful match/probe +* !0 otherwise +*/ +int rte_bus_probe (void ); + +/** * Dump information of all the buses registered with EAL. * * @param f
lib/librte_eal/linuxapp/eal/eal.c +8 -0
@@ -69,6 +69,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
@@ -844,6 +845,9 @@ rte_eal_init(int argc, char **argv)if (rte_eal_intr_init () <0 )rte_panic ("Cannot init interrupt-handling thread\n" ); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
@@ -884,6 +888,10 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" ); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/linuxapp/eal/rte_eal_version.map +2 -0
@@ -186,6 +186,8 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; rte_bus_unregister; + rte_bus_probe; + rte_bus_scan; rte_pci_match; } DPDK_16.11;
Signature · 1 line
2.7.4
PATCH v10 8/13 eal/pci: add support for PCI bus
In reply to Shreyansh JainBased on EAL Bus APIs, PCI bus callbacks and support functions are introduced in this patch.
EAL continues to have direct PCI init/scan calls as well. These would be removed in subsequent patches to enable bus only PCI devices.
--- lib/librte_eal/bsdapp/eal/eal.c | 1 + lib/librte_eal/bsdapp/eal/eal_pci.c | 11 ++++++ lib/librte_eal/common/eal_common_pci.c | 33 ++++++++++++++++ lib/librte_eal/common/include/rte_pci.h | 68 +++++++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 15 ++++++++ 5 files changed, 128 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +1 -0
@@ -64,6 +64,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
lib/librte_eal/bsdapp/eal/eal_pci.c +11 -0
@@ -673,3 +673,14 @@ rte_eal_pci_init(void) }return 0 ; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), + .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS (PCI_BUS_NAME , rte_pci_bus.bus);
lib/librte_eal/common/eal_common_pci.c +33 -0
@@ -71,6 +71,7 @@#include <rte_interrupts.h> #include <rte_log.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_per_lcore.h> #include <rte_memory.h>
@@ -479,3 +480,35 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver)rte_eal_driver_unregister (&driver->driver);TAILQ_REMOVE (&pci_driver_list, driver, next); } + +/* Add a PCI device to PCI Bus */ +void +rte_eal_pci_add_device (struct rte_pci_bus *pci_bus, +struct rte_pci_device *pci_dev) +{ +TAILQ_INSERT_TAIL (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus = &pci_bus->bus; +} + +/* Insert a PCI device into a predefined position in PCI bus */ +void +rte_eal_pci_insert_device (struct rte_pci_device *exist_pci_dev, +struct rte_pci_device *new_pci_dev) +{ +TAILQ_INSERT_BEFORE (exist_pci_dev, new_pci_dev, next); +/* Update Bus references */ + new_pci_dev->device.bus = exist_pci_dev->device.bus; +} + +/* Remove a PCI device from PCI bus */ +void +rte_eal_pci_remove_device (struct rte_pci_device *pci_dev) +{ +struct rte_pci_bus *pci_bus; + + pci_bus = container_of(pci_dev->device.bus, struct rte_pci_bus, bus); +TAILQ_REMOVE (&pci_bus->device_list, pci_dev, next); +/* Update Bus references */ + pci_dev->device.bus =NULL ; +}
lib/librte_eal/common/include/rte_pci.h +68 -0
98 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci.c +15 -0
@@ -35,6 +35,7 @@#include <dirent.h> #include <rte_log.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_eal_memconfig.h> #include <rte_malloc.h>
@@ -54,6 +55,9 @@* IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it). */ +/* Forward declaration of PCI bus */ +struct rte_pci_bus rte_pci_bus; +static int pci_get_kernel_driver_by_path (const char *filename,char *dri_name) {
@@ -723,3 +727,14 @@ rte_eal_pci_init(void)return 0 ; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), + .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS (PCI_BUS_NAME , rte_pci_bus.bus);
Signature · 1 line
2.7.4
PATCH v10 9/13 test: add test cases for scan and probe on BUS
In reply to Shreyansh Jain--- app/test/test_bus.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+)
app/test/test_bus.c +152 -0
@@ -120,12 +120,15 @@ static int scan_fn_for_busB(void);/* generic implementations wrapped around by above declarations */ static int generic_scan_fn (struct rte_bus *bus); +static int generic_probe_fn (void ); +static int dummy_match_fn (struct rte_driver *drv,struct rte_device *dev);struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , .scan = scan_fn_for_busA, + .probe = generic_probe_fn, }, };
@@ -134,6 +137,7 @@ struct dummy_bus busB = { .bus = { .name = "busB", .scan = scan_fn_for_busB, + .probe = generic_probe_fn, }, };
@@ -288,6 +292,46 @@ generic_scan_fn(struct rte_bus *bus)return 0 ; } +/* @internal +* Obtain bus from driver object. Match the address of rte_device object +* with all the devices associated with that bus. +* +* Being a test function, all this does is validate that device object +* provided is available on the same bus to which driver is registered. +* +* @param drv +* driver to match with +* @param dev +* device object +* @return +* 0 for successful match +* !0 for failed match +*/ +static int +dummy_match_fn(struct rte_driver *drv __rte_unused, struct rte_device *dev) +{ +struct rte_bus *bus; +struct dummy_device *ddev =NULL ; +struct dummy_device *ddev_as_arg; +struct dummy_bus *dbus =NULL ; + +/* Match is based entirely on address of 'dev' and 'dev_p' extracted +* from bus->device_list. +*/ + +/* a driver is registered with the bus *before* the scan. */ + bus = dev->bus; + dbus = container_of(bus, struct dummy_bus, bus); + ddev_as_arg = container_of(dev, struct dummy_device, dev); + + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +if (ddev == ddev_as_arg) +return 0 ; + } + +return 1 ; +} +int scan_fn_for_busA (void ) {struct dummy_bus_map *dbm;
@@ -504,6 +548,110 @@ test_bus_scan(void)return 0 ; } +/* +* +*/ +static int +generic_probe_fn (void ) +{ +int ret =0 ; +int i, j; +struct rte_driver *drv; +struct rte_device *dev; +struct dummy_bus *dbus =NULL ; +struct dummy_device *ddev =NULL ; +struct dummy_driver *ddrv =NULL ; + +/* In case of this test: +* 1. for each bus in rte_bus_list +* 2. for each device on that bus (bus specific->device_list) +* 3. for each driver on that bus (bus specific->driver_list) +* 4. call match +* 5. link driver and device +* 6. Verify the linkage. +*/ +for (i =0 ; bus_map[i].name; i++) { +/* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + +/* Looping over all scanned devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +/* There is a list of drivers within dummy_bus_map. +* In case of PMDs, this would be driver registration +* APIs/list +*/ +for (j =0 ; bus_map[i].ddrivers[j]; j++) { + ddrv = bus_map[i].ddrivers[j]; + + drv = &ddrv->drv; + dev = &ddev->dev; + ret =dummy_match_fn (drv, dev); +if (!ret) { +/* As match is generic, it always +* results in dev->drv pointing to +* first driver entry in bus_map[i] +*/ + dev->driver = drv; + dev->bus = &dbus->bus; + } +/* Else, continue */ + } + } + } + +/* Verify the linkage. All devices belonging to a bus_map[i] +* should have same driver (first driver entry of bus_map[i]) +*/ +for (i =0 ; bus_map[i].name; i++) { + ddrv = bus_map[i].ddrivers[0 ]; + drv = &ddrv->drv; + +for (j =0 ; bus_map[i].ddevices[j]; j++) { + ddev = bus_map[i].ddevices[j]; + dev = &ddev->dev; +if (dev->driver != drv) { +printf ("Incorrect driver<->device linkage.\n" ); +return -1 ; + } + } + } + +return 0 ; +} + +/* @internal +* Function to perform 'probe' and link devices and drivers on a bus. +* This would work over all the buses registered, and all devices and drivers +* registered with it - call match on each pair. +* +* @param void +* @return +* 0 for successful probe +* !0 for failure in probe +* +*/ +static int +test_probe_on_bus (void ) +{ +int ret =0 ; +int i; +struct dummy_bus *dbus; +struct rte_bus *bus; + +for (i =0 ; bus_map[i].name; i++) { +/* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + bus = &dbus->bus; + ret = bus->probe (); +if (ret) +printf ("Probe for %s failed.\n" , bus_map[i].name); + } + +printf ("Probe on all buses successful.\n" ); +dump_device_tree (); + +return 0 ; +}int test_bus (void )
@@ -518,6 +666,10 @@ test_bus(void)if (test_bus_scan ())return -1 ; +/* Now that the devices and drivers are registered, perform probe */ +if (test_probe_on_bus ()) +return -1 ; +if (test_device_unregistration_on_bus ())return -1 ;
Signature · 1 line
2.7.4
PATCH v10 10/13 test: add Bus based scan and probe test cases for PCI
In reply to Shreyansh Jain--- app/test/test_pci.c | 164 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 114 insertions(+), 50 deletions(-)
app/test/test_pci.c +114 -50
@@ -38,9 +38,11 @@#include <sys/queue.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_ethdev.h> #include <rte_devargs.h> +#include <rte_tailq.h> #include "test.h" #include "resource.h"
@@ -61,10 +63,31 @@int test_pci_run =0 ;/* value checked by the multiprocess test */ static unsigned pci_dev_count; +struct test_pci_bus ; +static struct test_pci_bus *pci_bus;/* global reference to a Test PCI bus */ + +/** List of PCI devices */ +TAILQ_HEAD (test_pci_device_list, rte_pci_device); +/** List of PCI drivers */ +TAILQ_HEAD (test_pci_driver_list, rte_pci_driver);static int my_driver_init (struct rte_pci_driver *dr,struct rte_pci_device *dev); +struct test_pci_bus { +struct rte_bus bus; +struct test_pci_device_list test_device_list; +struct test_pci_driver_list test_driver_list; +}; + +struct test_pci_bus test_pci_bus = { + .bus = { + .name ="test_pci_bus" , + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, +}; +/* IXGBE NICS */ struct rte_pci_id my_driver_id[] = { {RTE_PCI_DEVICE (0x0001 ,0x1234 )},
@@ -79,7 +102,7 @@ struct rte_pci_id my_driver_id2[] = {struct rte_pci_driver my_driver = { .driver = { - .name ="test_driver" + .name ="test_driver" , }, .probe = my_driver_init, .id_table = my_driver_id,
@@ -88,7 +111,7 @@ struct rte_pci_driver my_driver = {struct rte_pci_driver my_driver2 = { .driver = { - .name ="test_driver2" + .name ="test_driver2" , }, .probe = my_driver_init, .id_table = my_driver_id2,
@@ -108,6 +131,55 @@ my_driver_init(__attribute__((unused)) struct rte_pci_driver *dr,return 0 ; } +/* dump devices on the bus */ +static void +do_pci_device_dump (FILE *f) +{ +int i; +struct rte_pci_device *dev =NULL ; + + TAILQ_FOREACH(dev, &test_pci_bus.test_device_list, next) { + +fprintf (f,PCI_PRI_FMT , dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); +fprintf (f," - vendor:%x device:%x\n" , dev->id.vendor_id, + dev->id.device_id); + +for (i =0 ; i !=sizeof (dev->mem_resource) / +sizeof (dev->mem_resource[0 ]); i++) { +fprintf (f," %16.16" PRIx64" %16.16" PRIx64"\n" , + dev->mem_resource[i].phys_addr, + dev->mem_resource[i].len); + } + } +} + +/* Dummy implementation for rte_eal_pci_probe() over test_pci_bus */ +static int +do_pci_bus_probe (void ) +{ +int ret; +struct rte_pci_device *device; +struct rte_pci_driver *driver; + + TAILQ_FOREACH(device, &test_pci_bus.test_device_list, next) { + TAILQ_FOREACH(driver, &test_pci_bus.test_driver_list, next) { + ret =rte_pci_match (driver, device); +if (!ret) { +if (!driver->probe) +continue ; + + device->driver = driver; + ret = driver->probe (driver, device); +if (ret !=0 ) +return ret; + } + } + } + +return 0 ; +} +static void blacklist_all_devices (void ) {
@@ -115,7 +187,7 @@ blacklist_all_devices(void)unsigned i =0 ;char pci_addr_str[16 ]; - TAILQ_FOREACH(dev, &pci_device_list, next) { + TAILQ_FOREACH(dev, &(test_pci_bus.test_device_list), next) {snprintf (pci_addr_str,sizeof (pci_addr_str),PCI_PRI_FMT , dev->addr.domain, dev->addr.bus, dev->addr.devid, dev->addr.function);
@@ -142,19 +214,11 @@ static void free_devargs_list(void) } } -/* backup real devices & drivers (not used for testing) */ -struct pci_driver_list real_pci_driver_list = -TAILQ_HEAD_INITIALIZER (real_pci_driver_list); -struct pci_device_list real_pci_device_list = -TAILQ_HEAD_INITIALIZER (real_pci_device_list); -REGISTER_LINKED_RESOURCE (test_pci_sysfs);static int test_pci_setup (void ) { -struct rte_pci_device *dev; -struct rte_pci_driver *dr;const struct resource *r;int ret;
@@ -167,22 +231,22 @@ test_pci_setup(void) ret =setenv ("SYSFS_PCI_DEVICES" ,"test_pci_sysfs/bus/pci/devices" ,1 );TEST_ASSERT_SUCCESS (ret,"failed to setenv" ); -/* Unregister original devices & drivers lists */ -while (!TAILQ_EMPTY (&pci_driver_list)) { - dr =TAILQ_FIRST (&pci_driver_list); -rte_eal_pci_unregister (dr); -TAILQ_INSERT_TAIL (&real_pci_driver_list, dr, next); - } +TAILQ_INIT (&test_pci_bus.test_device_list); +TAILQ_INIT (&test_pci_bus.test_driver_list); -while (!TAILQ_EMPTY (&pci_device_list)) { - dev =TAILQ_FIRST (&pci_device_list); -TAILQ_REMOVE (&pci_device_list, dev, next); -TAILQ_INSERT_TAIL (&real_pci_device_list, dev, next); - } +/* Create a new Bus called 'test_pci_bus' */ +/* Bus doesn't exist; Create the test bus */ +printf ("Creating a Test PCI bus\n" ); +rte_bus_register (&test_pci_bus.bus); + pci_bus = &test_pci_bus; + +printf ("Scan for Test devices and add to bus\n" ); + ret = pci_bus->bus.scan (); - ret =rte_eal_pci_scan ();TEST_ASSERT_SUCCESS (ret,"failed to scan PCI bus" ); -rte_eal_pci_dump (stdout); + +printf ("Dump of all devices scanned:\n" ); +do_pci_device_dump (stdout);return 0 ; }
@@ -190,10 +254,11 @@ test_pci_setup(void)static int test_pci_cleanup (void ) { -struct rte_pci_device *dev; -struct rte_pci_driver *dr; +struct rte_pci_device *dev =NULL ; +struct rte_pci_driver *dr =NULL ;const struct resource *r;int ret; +void *temp;unsetenv ("SYSFS_PCI_DEVICES" );
@@ -203,28 +268,23 @@ test_pci_cleanup(void) ret =resource_rm_by_tar (r);TEST_ASSERT_SUCCESS (ret,"Failed to delete resource %s" , r->name); +TEST_ASSERT_NOT_NULL (pci_bus,"Invalid bus specified" ); +/* * FIXME: there is no API in DPDK to free a rte_pci_device so we * cannot free the devices in the right way. Let's assume that we * don't care for tests. */ -while (!TAILQ_EMPTY (&pci_device_list)) { - dev =TAILQ_FIRST (&pci_device_list); -TAILQ_REMOVE (&pci_device_list, dev, next); + TAILQ_FOREACH_SAFE(dev, &(test_pci_bus.test_device_list), next, temp) { +TAILQ_REMOVE (&(test_pci_bus.test_device_list), dev, next); + dev->driver =NULL ; } -/* Restore original devices & drivers lists */ -while (!TAILQ_EMPTY (&real_pci_driver_list)) { - dr =TAILQ_FIRST (&real_pci_driver_list); -TAILQ_REMOVE (&real_pci_driver_list, dr, next); -rte_eal_pci_register (dr); + TAILQ_FOREACH_SAFE(dr, &(test_pci_bus.test_driver_list), next, temp) { +TAILQ_REMOVE (&(test_pci_bus.test_driver_list), dr, next); } -while (!TAILQ_EMPTY (&real_pci_device_list)) { - dev =TAILQ_FIRST (&real_pci_device_list); -TAILQ_REMOVE (&real_pci_device_list, dev, next); -TAILQ_INSERT_TAIL (&pci_device_list, dev, next); - } +rte_bus_unregister (&pci_bus->bus);return 0 ; }
@@ -234,16 +294,19 @@ test_pci_blacklist(void) {struct rte_devargs_list save_devargs_list; -printf ("Dump all devices\n" ); -TEST_ASSERT (TAILQ_EMPTY (&pci_driver_list), -"pci_driver_list not empty" ); +TEST_ASSERT_NOT_NULL (pci_bus,"Invalid bus specified" ); -rte_eal_pci_register (&my_driver); -rte_eal_pci_register (&my_driver2); +TEST_ASSERT (TAILQ_EMPTY (&test_pci_bus.test_driver_list), +"PCI Driver list not empty" ); + +/* Add test drivers to Bus */ +TAILQ_INSERT_TAIL (&test_pci_bus.test_driver_list, &my_driver, next); +TAILQ_INSERT_TAIL (&test_pci_bus.test_driver_list, &my_driver2, next); pci_dev_count =0 ; -printf ("Scan bus\n" ); -rte_eal_pci_probe (); + +printf ("Probe the Test Bus\n" ); +do_pci_bus_probe ();if (pci_dev_count ==0 ) {printf ("no device detected\n" );
@@ -257,8 +320,8 @@ test_pci_blacklist(void)blacklist_all_devices (); pci_dev_count =0 ; -printf ("Scan bus with all devices blacklisted\n" ); -rte_eal_pci_probe (); +printf ("Probe bus with all devices blacklisted\n" ); +do_pci_bus_probe ();free_devargs_list (); devargs_list = save_devargs_list;
@@ -270,8 +333,9 @@ test_pci_blacklist(void) test_pci_run =1 ; -rte_eal_pci_unregister (&my_driver); -rte_eal_pci_unregister (&my_driver2); +/* Clear the test drivers added to Test Bus */ +TAILQ_REMOVE (&(test_pci_bus.test_driver_list), &my_driver, next); +TAILQ_REMOVE (&(test_pci_bus.test_driver_list), &my_driver2, next);return 0 ; }
Signature · 1 line
2.7.4
PATCH v10 11/13 eal: enable PCI bus
In reply to Shreyansh JainRemove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.
--- lib/librte_eal/bsdapp/eal/eal.c | 7 ----- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 -- lib/librte_eal/common/eal_common_pci.c | 34 ++++++++++---------- lib/librte_eal/common/eal_private.h | 10 ------ lib/librte_eal/common/include/rte_pci.h | 22 +++++-------- lib/librte_eal/linuxapp/eal/eal.c | 7 ----- lib/librte_eal/linuxapp/eal/eal_pci.c | 42 +++++++++---------------- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 -- 9 files changed, 44 insertions(+), 86 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +0 -7
@@ -562,9 +562,6 @@ rte_eal_init(int argc, char **argv)if (rte_eal_timer_init () <0 )rte_panic ("Cannot init HPET or TSC timers\n" ); -if (rte_eal_pci_init () <0 ) -rte_panic ("Cannot init PCI\n" ); -eal_check_mem_on_local_socket ();if (eal_plugins_init () <0 )
@@ -613,10 +610,6 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); -/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
lib/librte_eal/bsdapp/eal/eal_pci.c +4 -0
@@ -365,6 +365,10 @@ rte_eal_pci_scan(void) .matches = &matches[0], }; +/* for debug purposes, PCI can be disabled */ +if (internal_config.no_pci) +return 0 ; + fd =open ("/dev/pci" ,O_RDONLY );if (fd <0 ) {RTE_LOG (ERR ,EAL ,"%s(): error opening /dev/pci\n" , __func__);
lib/librte_eal/bsdapp/eal/rte_eal_version.map +0 -2
@@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc;
lib/librte_eal/common/eal_common_pci.c +18 -16
@@ -83,11 +83,6 @@#include "eal_private.h" -struct pci_driver_list pci_driver_list = -TAILQ_HEAD_INITIALIZER (pci_driver_list); -struct pci_device_list pci_device_list = -TAILQ_HEAD_INITIALIZER (pci_device_list); -#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"const char *pci_get_sysfs_path (void )
@@ -309,7 +304,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)if (dev->driver !=NULL )return 0 ; - TAILQ_FOREACH(dr, &pci_driver_list, next) { +FOREACH_DRIVER_ON_PCIBUS (dr) { rc =rte_eal_pci_probe_one_driver (dr, dev);if (rc <0 )/* negative value is an error */
@@ -330,6 +325,7 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr) {struct rte_pci_device *dev =NULL ; +int ret =0 ;if (addr ==NULL )
@@ -341,7 +337,7 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)if (pci_update_device (addr) <0 ) goto err_return; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ;
@@ -371,7 +367,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)if (addr ==NULL )return -1 ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {if (rte_eal_compare_pci_addr (&dev->addr, addr))continue ;
@@ -383,7 +379,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)/* positive value means driver doesn't support it */ continue ; -TAILQ_REMOVE (&pci_device_list, dev, next); +rte_eal_pci_remove_device (dev);free (dev);return 0 ; }
@@ -412,7 +408,7 @@ rte_eal_pci_probe(void)if (rte_eal_devargs_type_count (RTE_DEVTYPE_WHITELISTED_PCI ) ==0 ) probe_all =1 ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {/* set devargs in PCI structure */ devargs =pci_devargs_lookup (dev);
@@ -460,7 +456,7 @@ rte_eal_pci_dump(FILE *f) {struct rte_pci_device *dev =NULL ; - TAILQ_FOREACH(dev, &pci_device_list, next) { +FOREACH_DEVICE_ON_PCIBUS (dev) {pci_dump_one_device (f, dev); } }
@@ -469,16 +465,22 @@ rte_eal_pci_dump(FILE *f)void rte_eal_pci_register (struct rte_pci_driver *driver) { -TAILQ_INSERT_TAIL (&pci_driver_list, driver, next); -rte_eal_driver_register (&driver->driver); +TAILQ_INSERT_TAIL (&rte_pci_bus.driver_list, driver, next); +/* Update Bus references */ + driver->pci_bus = &rte_pci_bus; } -/* unregister a driver */ +/* Unregister a driver */ void rte_eal_pci_unregister (struct rte_pci_driver *driver) { -rte_eal_driver_unregister (&driver->driver); -TAILQ_REMOVE (&pci_driver_list, driver, next); +struct rte_pci_bus *pci_bus; + + pci_bus = driver->pci_bus; + +TAILQ_REMOVE (&pci_bus->driver_list, driver, next); +/* Update Bus references */ + driver->pci_bus =NULL ; }/* Add a PCI device to PCI Bus */
lib/librte_eal/common/eal_private.h +0 -10
@@ -108,16 +108,6 @@ int rte_eal_timer_init(void);*/ int rte_eal_log_init (const char *id,int facility); -/** -* Init the PCI infrastructure -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error -*/ -int rte_eal_pci_init (void ); -struct rte_pci_driver ;struct rte_pci_device ;
lib/librte_eal/common/include/rte_pci.h +7 -15
@@ -87,12 +87,6 @@ extern "C" {#include <rte_dev.h> #include <rte_bus.h> -TAILQ_HEAD (pci_device_list, rte_pci_device);/**< PCI devices in D-linked Q. */ -TAILQ_HEAD (pci_driver_list, rte_pci_driver);/**< PCI drivers in D-linked Q. */ - -extern struct pci_driver_list pci_driver_list;/**< Global list of PCI drivers. */ -extern struct pci_device_list pci_device_list;/**< Global list of PCI devices. */ -/** Pathname of PCI devices directory. */ const char *pci_get_sysfs_path (void );
@@ -124,6 +118,9 @@ TAILQ_HEAD(rte_pci_device_list, rte_pci_device);/** List of PCI drivers */ TAILQ_HEAD (rte_pci_driver_list, rte_pci_driver); +/* Extend PCI bus definition to users */ +extern struct rte_pci_bus rte_pci_bus; +/* PCI Bus iterators */ #define FOREACH_DEVICE_ON_PCIBUS (p) \ TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next)
@@ -208,8 +205,6 @@ struct rte_pci_device { .subsystem_device_id = PCI_ANY_ID#endif -struct rte_pci_driver ; -/** * Initialisation function for the driver called during PCI probing. */
@@ -416,17 +411,14 @@ rte_pci_match(const struct rte_pci_driver *pci_drv, const struct rte_pci_device *pci_dev);/** -* Probe the PCI bus for registered drivers. -* -* Scan the content of the PCI bus, and call the probe() function for -* all registered drivers that have a matching entry in its id_table -* for discovered devices. +* Probe the PCI bus * * @return * - 0 on success. -* - Negative on error. +* - !0 on error. */ -int rte_eal_pci_probe (void ); +int +rte_eal_pci_probe (void );/** * Map the PCI device resources in user space virtual memory address
lib/librte_eal/linuxapp/eal/eal.c +0 -7
@@ -803,9 +803,6 @@ rte_eal_init(int argc, char **argv)if (rte_eal_log_init (logid, internal_config.syslog_facility) <0 )rte_panic ("Cannot init logs\n" ); -if (rte_eal_pci_init () <0 ) -rte_panic ("Cannot init PCI\n" ); -#ifdef VFIO_PRESENT if (rte_eal_vfio_setup () <0 )rte_panic ("Cannot init VFIO\n" );
@@ -884,10 +881,6 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); -/* Probe & Initialize PCI devices */ -if (rte_eal_pci_probe ()) -rte_panic ("Cannot probe PCI\n" ); -/* Probe all the buses and devices/drivers on them */ if (rte_bus_probe ())rte_panic ("Cannot probe devices\n" );
lib/librte_eal/linuxapp/eal/eal_pci.c +15 -27
93 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0 -2
@@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc;
Signature · 1 line
2.7.4
PATCH v10 12/13 eal: enable hotplugging of devices on bus
In reply to Shreyansh JainGiven a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 + lib/librte_eal/common/eal_common_dev.c | 56 ++++++++++++++++----- lib/librte_eal/common/eal_common_pci.c | 89 +++++++++++++++++++++++++++++++-- lib/librte_eal/common/include/rte_bus.h | 31 ++++++++++++ lib/librte_eal/common/include/rte_pci.h | 45 +++++++++++------ lib/librte_eal/linuxapp/eal/eal_pci.c | 2 + 6 files changed, 193 insertions(+), 32 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
@@ -682,6 +682,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
lib/librte_eal/common/eal_common_dev.c +44 -12
94 lines not on this page · raw message
lib/librte_eal/common/eal_common_pci.c +84 -5
111 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +31 -0
@@ -59,6 +59,8 @@ TAILQ_HEAD(rte_bus_list, rte_bus);/* Bus list exposed */ extern struct rte_bus_list rte_bus_list; +#define FOREACH_BUS (bus_p) TAILQ_FOREACH(bus_p, &rte_bus_list, next) +/** * Bus specific scan for devices attached on the bus. * For each bus object, the scan would be reponsible for finding devices and
@@ -85,6 +87,33 @@ typedef int (*rte_bus_scan_t)(void);typedef int (*rte_bus_probe_t )(void );/** +* Attach a device to a bus, assuming it is 'connected' to the bus. +* A bus is responsible for scanning for devices. Attaching a new device is +* for reenabling the device after being detached/removed. +* +* @param device_name +* Name of the device to attach. +* +* @return +* 0 for successful attach +* !0 for unsuccessful attach (or incorrect device name) +*/ +typedef int (*rte_bus_attach_t )(const char *device_name); + +/** +* Detach a named device from a bus. Implementation would check the existence +* of device on the bus and detach it. +* +* @param device_name +* Name of the device to detach +* +* @return +* 0 for successful detaching +* !0 if device not found or can't detach +*/ +typedef int (*rte_bus_detach_t )(const char *device_name); + +/** * A structure describing a generic bus. */ struct rte_bus {
@@ -92,6 +121,8 @@ struct rte_bus {const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ +rte_bus_attach_t attach;/**< Attach a named device */ +rte_bus_detach_t detach;/**< Detach a named device */ };/**
lib/librte_eal/common/include/rte_pci.h +30 -15
57 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -0
@@ -720,6 +720,8 @@ struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_eal_pci_scan, .probe = rte_eal_pci_probe, + .attach = rte_eal_pci_attach, + .detach = rte_eal_pci_detach, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
Signature · 1 line
2.7.4
PATCH v10 13/13 doc: remove deprecation notice for rte_bus
In reply to Shreyansh Jain--- doc/guides/rel_notes/deprecation.rst | 5 ----- 1 file changed, 5 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -5
@@ -13,11 +13,6 @@ Deprecation Notices has exposed, like the way we have done with uio-pci-generic. This change targets release 17.02. -* ABI/API changes are planned for 17.02: ``rte_device``, ``rte_driver`` will be - impacted because of introduction of a new ``rte_bus`` hierarchy. This would - also impact the way devices are identified by EAL. A bus-device-driver model - will be introduced providing a hierarchical view of devices. - * ``eth_driver`` is planned to be removed in 17.02. This currently serves as a placeholder for PMDs to register themselves. Changes for ``rte_bus`` will provide a way to handle device initialization currently being done in
Signature · 1 line
2.7.4
v11 cover rte_bus + rte_pci_bus
In reply to Shreyansh JainI've continued the work done by Shreyansh for bus abstraction and PCI implementation.
This change has two benefits:
- ease future introduction of new bus
- clean existing buses (only PCI here)
The same kind of work must be done on VDEV in order to move these implementations as bus drivers.
changes in v11:
- fixes for BSD
- remove useless bus object retrieving
- remove useless bus reference in rte_device
- some rewording and patch reordering
Unfortunately, it is not ready to be integrated in 17.02. More specifically:
- the tests need some review/rework
- the PCI implementation requires more work
- the documentation must be updated
However there are some new buses waiting for the bus abstraction, which is simple and good enough.
That's why I have isolated the generic bus model in first patches and will apply them in 17.02-rc1. It will allow to base new buses on top of rte_bus.
Shreyansh Jain (13):
bus: introduce bus abstraction
bus: add scanning
bus: add probing
app/test: check bus registration
app/test: check bus scan
app/test: check bus probe
pci: split match and probe
pci: remove loop over drivers in device detach
pci: add bus driver
app/test: add PCI bus driver
pci: use bus driver for scan/probe
pci: use bus driver for attach/detach
doc: remove deprecation notice for rte_bus
MAINTAINERS | 1 + app/test/Makefile | 2 +- app/test/autotest_data.py | 6 + app/test/test.h | 1 + app/test/test_bus.c | 678 ++++++++++++++++++++++++ app/test/test_pci.c | 164 ++++-- doc/guides/rel_notes/deprecation.rst | 5 - doc/guides/rel_notes/release_17_02.rst | 2 +- lib/librte_eal/bsdapp/eal/Makefile | 3 +- lib/librte_eal/bsdapp/eal/eal.c | 13 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 43 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 15 +- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 133 +++++ lib/librte_eal/common/eal_common_dev.c | 56 +- lib/librte_eal/common/eal_common_pci.c | 350 +++++++----- lib/librte_eal/common/eal_private.h | 10 - lib/librte_eal/common/include/rte_bus.h | 192 +++++++ lib/librte_eal/common/include/rte_pci.h | 142 ++++- lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal.c | 13 +- lib/librte_eal/linuxapp/eal/eal_pci.c | 50 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 15 +- 23 files changed, 1600 insertions(+), 299 deletions(-) create mode 100644 app/test/test_bus.c create mode 100644 lib/librte_eal/common/eal_common_bus.c create mode 100644 lib/librte_eal/common/include/rte_bus.h
Signature · 1 line
2.7.0
PATCH v11 1/13 bus: introduce bus abstraction
From: Shreyansh Jain <[email protected]>
This patch introduces the rte_bus abstraction for EAL.
The model is:
- One or more devices are connected 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' base class which would be extended for specific implementations. It also introduces Bus registration and deregistration functions.
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 9 ++ lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_bus.c | 92 +++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 112 ++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/rte_eal_version.map | 9 ++ 7 files changed, 225 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
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -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
lib/librte_eal/bsdapp/eal/rte_eal_version.map +9 -0
@@ -174,3 +174,12 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
lib/librte_eal/common/Makefile +1 -1
@@ -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
lib/librte_eal/common/eal_common_bus.c new file +92 -0
92 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h new file +112 -0
112 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -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
lib/librte_eal/linuxapp/eal/rte_eal_version.map +9 -0
@@ -178,3 +178,12 @@ DPDK_16.11 { rte_eal_vdrv_unregister; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_bus_dump; + rte_bus_register; + rte_bus_unregister; + +} DPDK_16.11;
Signature · 1 line
2.7.0
PATCH v11 2/13 bus: add scanning
In reply to Thomas MonjalonFrom: Shreyansh Jain <[email protected]>
Scan for bus discovers the devices available on the bus and adds them to a bus specific device list. Each bus mandatorily implements this method.
--- lib/librte_eal/bsdapp/eal/eal.c | 3 +++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_bus.c | 21 +++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 23 +++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 4 ++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 6 files changed, 53 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +3 -0
@@ -577,6 +577,9 @@ rte_eal_init(int argc, char **argv) rte_config.master_lcore, thread_id, cpuset, ret == 0 ? "" : "..."); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
@@ -180,6 +180,7 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; + rte_bus_scan; rte_bus_unregister; } DPDK_16.11;
lib/librte_eal/common/eal_common_bus.c +21 -0
@@ -47,6 +47,8 @@ rte_bus_register(struct rte_bus *bus) {RTE_VERIFY (bus);RTE_VERIFY (bus->name &&strlen (bus->name)); +/* A bus should mandatorily have the scan implemented */ +RTE_VERIFY (bus->scan);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);
@@ -59,6 +61,25 @@ rte_bus_unregister(struct rte_bus *bus)RTE_LOG (DEBUG ,EAL ,"Unregistered [%s] bus.\n" , bus->name); } +/* Scan all the buses for registered devices */ +int +rte_bus_scan (void ) +{ +int ret; +struct rte_bus *bus =NULL ; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->scan (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Scan for (%s) bus failed.\n" , + bus->name); +return ret; + } + } + +return 0 ; +} +/* Dump information of a single bus */ static int bus_dump_one (FILE *f,struct rte_bus *bus)
lib/librte_eal/common/include/rte_bus.h +23 -0
@@ -57,11 +57,25 @@ extern "C" {TAILQ_HEAD (rte_bus_list, rte_bus);/** +* Bus specific scan for devices attached on the bus. +* For each bus object, the scan would be reponsible for finding devices and +* adding them to its private device list. +* +* A bus should mandatorily implement this method. +* +* @return +* 0 for successful scan +* <0 for unsuccessful scan with error value +*/ +typedef int (*rte_bus_scan_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ +rte_bus_scan_t scan;/**< Scan for devices attached to bus */ };/**
@@ -83,6 +97,15 @@ void rte_bus_register(struct rte_bus *bus);void rte_bus_unregister (struct rte_bus *bus);/** +* Scan all the buses. +* +* @return +* 0 in case of success in scanning all buses +* !0 in case of failure to scan +*/ +int rte_bus_scan (void ); + +/** * Dump information of all the buses registered with EAL. * * @param f
lib/librte_eal/linuxapp/eal/eal.c +4 -0
@@ -69,6 +69,7 @@#include <rte_string_fns.h> #include <rte_cpuflags.h> #include <rte_interrupts.h> +#include <rte_bus.h> #include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h>
@@ -844,6 +845,9 @@ rte_eal_init(int argc, char **argv)if (rte_eal_intr_init () <0 )rte_panic ("Cannot init interrupt-handling thread\n" ); +if (rte_bus_scan ()) +rte_panic ("Cannot scan the buses for devices\n" ); +RTE_LCORE_FOREACH_SLAVE (i) {/*
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -0
@@ -184,6 +184,7 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; + rte_bus_scan; rte_bus_unregister; } DPDK_16.11;
Signature · 1 line
2.7.0
PATCH v11 3/13 bus: add probing
In reply to Thomas MonjalonFrom: Shreyansh Jain <[email protected]>
Bus implementations can implement a probe handler to match the devices scanned against the drivers registered.
--- lib/librte_eal/bsdapp/eal/eal.c | 4 ++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_bus.c | 20 ++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 23 +++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 4 ++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 6 files changed, 53 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +4 -0
@@ -612,6 +612,10 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +/* Probe & Initialize PCI devices */ if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" );
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
@@ -179,6 +179,7 @@ DPDK_17.02 { global: rte_bus_dump; + rte_bus_probe; rte_bus_register; rte_bus_scan; rte_bus_unregister;
lib/librte_eal/common/eal_common_bus.c +20 -0
@@ -49,6 +49,7 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->name &&strlen (bus->name));/* A bus should mandatorily have the scan implemented */ RTE_VERIFY (bus->scan); +RTE_VERIFY (bus->probe);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);
@@ -80,6 +81,25 @@ rte_bus_scan(void)return 0 ; } +/* Probe all devices of all buses */ +int +rte_bus_probe (void ) +{ +int ret; +struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->probe (); +if (ret) { +RTE_LOG (ERR ,EAL ,"Bus (%s) probe failed.\n" , + bus->name); +return ret; + } + } + +return 0 ; +} +/* Dump information of a single bus */ static int bus_dump_one (FILE *f,struct rte_bus *bus)
lib/librte_eal/common/include/rte_bus.h +23 -0
@@ -70,12 +70,25 @@ TAILQ_HEAD(rte_bus_list, rte_bus);typedef int (*rte_bus_scan_t )(void );/** +* Implementation specific probe function which is responsible for linking +* devices on that bus with applicable drivers. +* +* This is called while iterating over each registered bus. +* +* @return +* 0 for successful probe +* !0 for any error while probing +*/ +typedef int (*rte_bus_probe_t )(void ); + +/** * A structure describing a generic bus. */ struct rte_bus {TAILQ_ENTRY (rte_bus) next;/**< Next bus object in linked list */ const char *name;/**< Name of the bus */ rte_bus_scan_t scan;/**< Scan for devices attached to bus */ +rte_bus_probe_t probe;/**< Probe devices on bus */ };/**
@@ -106,6 +119,16 @@ void rte_bus_unregister(struct rte_bus *bus);int rte_bus_scan (void );/** +* For each device on the buses, perform a driver 'match' and call the +* driver-specific probe for device initialization. +* +* @return +* 0 for successful match/probe +* !0 otherwise +*/ +int rte_bus_probe (void ); + +/** * Dump information of all the buses registered with EAL. * * @param f
lib/librte_eal/linuxapp/eal/eal.c +4 -0
@@ -884,6 +884,10 @@ rte_eal_init(int argc, char **argv)rte_eal_mp_remote_launch (sync_func,NULL ,SKIP_MASTER );rte_eal_mp_wait_lcore (); +/* Probe all the buses and devices/drivers on them */ +if (rte_bus_probe ()) +rte_panic ("Cannot probe devices\n" ); +/* Probe & Initialize PCI devices */ if (rte_eal_pci_probe ())rte_panic ("Cannot probe PCI\n" );
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -0
@@ -183,6 +183,7 @@ DPDK_17.02 { global: rte_bus_dump; + rte_bus_probe; rte_bus_register; rte_bus_scan; rte_bus_unregister;
Signature · 1 line
2.7.0
PATCH v11 4/13 app/test: check bus registration
In reply to Thomas MonjalonFrom: Shreyansh Jain <[email protected]>
Verification of bus registration, deregistration methods.
--- MAINTAINERS | 1 + app/test/Makefile | 2 +- app/test/autotest_data.py | 6 + app/test/test.h | 1 + app/test/test_bus.c | 355 ++++++++++++++++++++++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/include/rte_bus.h | 3 + lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 8 files changed, 369 insertions(+), 1 deletion(-) create mode 100644 app/test/test_bus.c
MAINTAINERS +1 -0
@@ -89,6 +89,7 @@ F: lib/librte_eal/common/include/generic/ F: doc/guides/prog_guide/env_abstraction_layer.rst F: app/test/test_alarm.c F: app/test/test_atomic.c +F: app/test/test_bus.c F: app/test/test_byteorder.c F: app/test/test_common.c F: app/test/test_cpuflags.c
app/test/Makefile +1 -1
@@ -94,7 +94,7 @@ SRCS-y += test_cycles.c SRCS-y += test_spinlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c - +SRCS-y += test_bus.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c SRCS-y += test_pmd_perf.c
app/test/autotest_data.py +6 -0
@@ -204,6 +204,12 @@ def per_sockets(num): "Tests": [ { + "Name": "Bus autotest", + "Command": "bus_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "PCI autotest", "Command": "pci_autotest", "Func": default_autotest,
app/test/test.h +1 -0
@@ -233,6 +233,7 @@ extern const char *prgname;int commands_init (void ); +int test_bus (void );int test_pci (void );int test_pci_run;
app/test/test_bus.c new file +355 -0
355 lines not on this page · raw message
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
@@ -178,6 +178,7 @@ DPDK_16.11 { DPDK_17.02 { global: + rte_bus_list; rte_bus_dump; rte_bus_probe; rte_bus_register;
lib/librte_eal/common/include/rte_bus.h +3 -0
@@ -56,6 +56,9 @@ extern "C" {/** Double linked list of buses */ TAILQ_HEAD (rte_bus_list, rte_bus); +/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list; +/** * Bus specific scan for devices attached on the bus. * For each bus object, the scan would be reponsible for finding devices and
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -0
@@ -182,6 +182,7 @@ DPDK_16.11 { DPDK_17.02 { global: + rte_bus_list; rte_bus_dump; rte_bus_probe; rte_bus_register;
Signature · 1 line
2.7.0
PATCH v11 5/13 app/test: check bus scan
In reply to Thomas MonjalonFrom: Shreyansh Jain <[email protected]>
--- app/test/test_bus.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+)
app/test/test_bus.c +174 -0
@@ -106,10 +106,26 @@ struct dummy_bus_map {struct rte_bus_list orig_bus_list =TAILQ_HEAD_INITIALIZER (orig_bus_list); +/* Forward declarations for callbacks from bus */ + +/* Bus A +* Scan would register devA1 and devA2 to bus +*/ +static int scan_fn_for_busA (void ); + +/* Bus B +* Scan would register devB1 and devB2 to bus +*/ +static int scan_fn_for_busB (void ); + +/* generic implementations wrapped around by above declarations */ +static int generic_scan_fn (struct rte_bus *bus); +struct dummy_bus busA = { .name ="busA_impl" ,/* busA */ .bus = { .name ="busA" , + .scan = scan_fn_for_busA, }, };
@@ -117,6 +133,7 @@ struct dummy_bus busB = { .name = "busB_impl", /* busB */ .bus = { .name = "busB", + .scan = scan_fn_for_busB, }, };
@@ -222,9 +239,80 @@ dump_device_tree(void)printf ("------>8-------\n" ); } +/* @internal +* Move over the bus_map and find the entry matching the bus object +* passed as argument. +* For each device in that bus_map list, register. +* +* @param bus +* bus to scan againt test entry +* @return +* 0 for successful scan, even if no devices are found +* !0 for any error in scanning (like, invalid bus) +*/ +static int +generic_scan_fn (struct rte_bus *bus) +{ +int i =0 ; +struct dummy_device *ddev =NULL ; +struct dummy_bus_map *dbmap =NULL ; +struct dummy_bus *db =NULL ; + +if (!bus) +return -1 ; + +/* Extract the device tree node using the bus passed */ +for (i =0 ; bus_map[i].name; i++) { +if (!strcmp (bus_map[i].name, bus->name)) { + dbmap = &bus_map[i]; +break ; + } + } + +if (!dbmap) +return -1 ; + + db = dbmap->dbus; + +/* For all the devices in the device tree (bus_map), add device */ +for (i =0 ; dbmap->ddevices[i]; i++) { + ddev = dbmap->ddevices[i]; +TAILQ_INSERT_TAIL (&db->device_list, ddev, next); + } + +return 0 ; +} + +int +scan_fn_for_busA (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busA" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} + +int +scan_fn_for_busB (void ) { +struct dummy_bus_map *dbm; + + dbm = &bus_map[0 ]; +while (dbm) { +if (strcmp (dbm->name,"busB" ) ==0 ) +return generic_scan_fn (&dbm->dbus->bus); + dbm++; + } +return 1 ; +} +static int test_bus_setup (void ) { +int i =0 ;struct rte_bus *bus_p =NULL ;/* Preserve the original bus list before executing test */
@@ -234,6 +322,13 @@ test_bus_setup(void)TAILQ_INSERT_TAIL (&orig_bus_list, bus_p, next); } +/* Initialize the bus lists */ +for (i =0 ; bus_map[i].name; i++) { +TAILQ_INIT (&bus_map[i].dbus->device_list); +TAILQ_INIT (&bus_map[i].dbus->driver_list); + } + +dump_device_tree ();return 0 ; }
@@ -332,6 +427,79 @@ test_bus_unregistration(void)return 0 ; } +static int +test_device_unregistration_on_bus (void ) +{ +int i; +struct rte_bus *bus =NULL ; +struct dummy_device *ddev; +struct dummy_bus *dbus; + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); +if (!bus) { +printf ("Unable to find bus (%s)\n" , + bus_map[i].name); +return -1 ; + } + + dbus = container_of(bus, struct dummy_bus, bus); +/* For bus 'bus', unregister all devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { +TAILQ_REMOVE (&dbus->device_list, ddev, next); + } + } + +for (i =0 ; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); + dbus = container_of(bus, struct dummy_bus, bus); + +if (!TAILQ_EMPTY (&dbus->device_list)) { +printf ("Unable to remove all devices on bus (%s)\n" , + bus->name); +return -1 ; + } + } + +/* All devices from all buses have been removed */ +printf ("All devices on all buses unregistered.\n" ); +dump_device_tree (); + +return 0 ; +} + +/* @internal +* For each bus registered, call the scan function to identify devices +* on the bus. +* +* @param void +* @return +* 0 for successful scan +* !0 for unsuccessful scan +* +*/ +static int +test_bus_scan (void ) +{ +int ret; +struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { +/* Call the scan function for each bus */ + ret = bus->scan (); +if (ret) { +printf ("Scan of buses failed.\n" ); +return -1 ; + } + } + +printf ("Scan of all buses completed.\n" ); +dump_device_tree (); + +return 0 ; +} + +int test_bus (void ) {
@@ -342,6 +510,12 @@ test_bus(void)if (test_bus_registration ())return -1 ; +if (test_bus_scan ()) +return -1 ; + +if (test_device_unregistration_on_bus ()) +return -1 ; +if (test_bus_unregistration ())return -1 ;
Signature · 1 line
2.7.0