eal: complete attach / detach support
cover eal: complete attach / detach support
Implements attach / detach for the PCI bus, and a streamlined attach for the virtual bus.
This is necessary to remove the final dependencies of the EAL on the virtual and PCI buses, due to the rte_eal_dev_attach and rte_eal_dev_detach functions.
This patchset depends on:
pci: implement find_device bus operation
http://dpdk.org/ml/archives/dev/2017-May/066340.html
http://dpdk.org/dev/patchwork/patch/24498/
[PATCH 00/14] Generic devargs parsing
http://dpdk.org/ml/archives/dev/2017-May/066351.html
http://dpdk.org/dev/patchwork/patch/24508/
Gaetan Rivet (3):
pci: implement attach/detach bus operation
vdev: implement attach bus operation
vdev: use standard bus registration function
lib/librte_eal/common/eal_common_dev.c | 53 +++++++++++++++++++-------------- lib/librte_eal/common/eal_common_pci.c | 50 +++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_common_vdev.c | 26 +++++----------- 3 files changed, 88 insertions(+), 41 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/3 pci: implement attach/detach bus operation
--- lib/librte_eal/common/eal_common_pci.c | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
lib/librte_eal/common/eal_common_pci.c +50 -0
@@ -76,6 +76,7 @@#include <rte_pci.h> #include <rte_per_lcore.h> #include <rte_memory.h> +#include <rte_memcpy.h> #include <rte_memzone.h> #include <rte_eal.h> #include <rte_string_fns.h>
@@ -546,12 +547,61 @@ pci_find_device(int (*match)(const struct rte_device *dev, const void *data),return NULL ; } +static int +pci_attach (struct rte_device *dev) +{ +struct rte_pci_device *pdev; +struct rte_pci_addr addr; + +if (dev ==NULL ) +return -EINVAL ; +if (pci_parse (dev->name, &addr)) +return -EFAULT ; +/* +* Update eventual pci device in global list. +* Insert it if none was found. +*/ +if (pci_update_device (&addr) <0 ) +return -EIO ; +/* Find the current device holding this address in the bus. */ +FOREACH_DEVICE_ON_PCIBUS (pdev) { +if (rte_eal_compare_pci_addr (&pdev->addr, &addr)) +continue ; +/* Update eventual devargs, others device infos. */ +if (dev != &pdev->device) +rte_memcpy (&pdev->device, dev,sizeof (*dev)); +break ; + } +if (rte_pci_probe_one (&addr)) +return -ENODEV ; +/* Get back new device info. */ +if (dev != &pdev->device) +rte_memcpy (dev, &pdev->device,sizeof (*dev)); +return 0 ; +} + +static int +pci_detach (struct rte_device *dev) +{ +struct rte_pci_addr addr; + +if (dev ==NULL ) +return -EINVAL ; +if (pci_parse (dev->name, &addr)) +return -EFAULT ; +if (rte_pci_detach (&addr)) +return -ENODEV ; +return 0 ; +} +struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_pci_scan, .probe = rte_pci_probe, .find_device = pci_find_device, .parse = pci_parse, + .attach = pci_attach, + .detach = 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.1.4
PATCH 2/3 vdev: implement attach bus operation
In reply to Gaetan Rivet--- lib/librte_eal/common/eal_common_dev.c | 53 +++++++++++++++++++-------------- lib/librte_eal/common/eal_common_vdev.c | 8 ++++- 2 files changed, 37 insertions(+), 24 deletions(-)
lib/librte_eal/common/eal_common_dev.c +30 -23
@@ -61,6 +61,9 @@ static int cmp_detached_dev_name(const struct rte_device *dev,int rte_eal_dev_attach (const char *name,const char *devargs) {struct rte_device *dev; +struct rte_device device; +struct rte_devargs da; +struct rte_bus *bus;int ret;if (name ==NULL || devargs ==NULL ) {
@@ -69,31 +72,35 @@ int rte_eal_dev_attach(const char *name, const char *devargs) } dev =rte_bus_find_device (NULL , cmp_detached_dev_name, name); -if (dev) { -struct rte_bus *bus; - +if (dev) bus =rte_bus_find_by_device (dev); -if (!bus) { -RTE_LOG (ERR ,EAL ,"Cannot find bus for device (%s)\n" , - name); -return -EINVAL ; - } - -if (!bus->attach) { -RTE_LOG (ERR ,EAL ,"Bus function not supported\n" ); -return -ENOTSUP ; - } - - ret = bus->attach (dev); - goto out; +else + bus =rte_bus_from_dev (name); +if (!bus) { +RTE_LOG (ERR ,EAL ,"Cannot find bus for device (%s)\n" , + name); +return -EINVAL ; } - -/* -* If we haven't found a bus device the user meant to "hotplug" a -* virtual device instead. -*/ - ret =rte_vdev_init (name, devargs); -out: +if (!bus->attach) { +RTE_LOG (ERR ,EAL ,"Bus function not supported\n" ); +return -ENOTSUP ; + } +if (!dev) { +char da_str[snprintf (NULL ,0 ,"%s,%s" , name, devargs) +1 ]; + +/* +* If we haven't found a bus device the user meant to "hotplug" +* a device instead. +*/ + dev = &device; +snprintf (da_str,sizeof (da_str),"%s,%s" , name, devargs); + ret =rte_eal_devargs_parse (da_str, &da); +if (ret) +return ret; + dev->name = da.name; + dev->devargs = &da; + } + ret = bus->attach (dev);if (ret)RTE_LOG (ERR ,EAL ,"Driver cannot attach the device (%s)\n" , name);
lib/librte_eal/common/eal_common_vdev.c +7 -1
@@ -356,6 +356,12 @@ vdev_find_device(int (*match)(const struct rte_device *dev, const void *data), }static int +vdev_attach (struct rte_device *dev) +{ +return rte_vdev_init (dev->devargs->name, dev->devargs->args); +} + +static int vdev_detach (struct rte_device *dev) {/*
@@ -369,7 +375,7 @@ static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, .find_device = vdev_find_device, - /* .attach = NULL, see comment on vdev_detach */ + .attach = vdev_attach, .detach = vdev_detach, .parse = vdev_parse, };
Signature · 1 line
2.1.4
PATCH 3/3 vdev: use standard bus registration function
In reply to Gaetan Rivet--- lib/librte_eal/common/eal_common_vdev.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-)
lib/librte_eal/common/eal_common_vdev.c +1 -17
@@ -52,14 +52,10 @@ static struct vdev_device_list vdev_device_list =struct vdev_driver_list vdev_driver_list =TAILQ_HEAD_INITIALIZER (vdev_driver_list); -static void rte_vdev_bus_register (void ); -/* register a driver */ void rte_vdev_register (struct rte_vdev_driver *driver) { -rte_vdev_bus_register (); -TAILQ_INSERT_TAIL (&vdev_driver_list, driver, next); }
@@ -380,16 +376,4 @@ static struct rte_bus rte_vdev_bus = { .parse = vdev_parse, }; -RTE_INIT (rte_vdev_bus_register); - -static void rte_vdev_bus_register (void ) -{ -static int registered; - -if (registered) -return ; - - registered =1 ; - rte_vdev_bus.name =VIRTUAL_BUS_NAME ; -rte_bus_register (&rte_vdev_bus); -} +RTE_REGISTER_BUS (VIRTUAL_BUS_NAME , rte_vdev_bus);
Signature · 1 line
2.1.4
v2 cover eal: complete attach / detach support
In reply to Gaetan RivetImplements attach / detach for the PCI bus, and a streamlined attach for the virtual bus.
This is necessary to remove the final dependencies of the EAL on the virtual and PCI buses, due to the rte_eal_dev_attach and rte_eal_dev_detach functions.
This patchset depends on:
pci: implement find_device bus operation
http://dpdk.org/ml/archives/dev/2017-May/066340.html
http://dpdk.org/dev/patchwork/patch/24498/
[PATCH 00/14] Generic devargs parsing
http://dpdk.org/ml/archives/dev/2017-May/066351.html
http://dpdk.org/dev/patchwork/patch/24508/
v1 -> v2:
* Rebase the series on the plug / unplug API.
* removed the vdev_plug implementation as it is now done in the plug/unplug introduction.
Gaetan Rivet (3):
pci: implement plug/unplug bus operation
dev: remove vdev function dependency
vdev: use standard bus registration function
lib/librte_eal/common/eal_common_dev.c | 49 ++++++++++++++++------------- lib/librte_eal/common/eal_common_pci.c | 56 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_common_vdev.c | 18 +---------- 3 files changed, 84 insertions(+), 39 deletions(-)
Signature · 1 line
2.1.4
PATCH v2 1/3 pci: implement plug/unplug bus operation
--- lib/librte_eal/common/eal_common_pci.c | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
lib/librte_eal/common/eal_common_pci.c +56 -0
@@ -76,6 +76,7 @@#include <rte_pci.h> #include <rte_per_lcore.h> #include <rte_memory.h> +#include <rte_memcpy.h> #include <rte_memzone.h> #include <rte_eal.h> #include <rte_string_fns.h>
@@ -545,12 +546,67 @@ pci_find_device(rte_dev_match_t match, const void *data)return NULL ; } +static int +pci_plug (struct rte_devargs *da) +{ +struct rte_pci_device *pdev; +struct rte_pci_addr addr; + +if (da ==NULL ) +return -EINVAL ; +if (pci_parse (da->name, &addr)) +return -EFAULT ; +/* +* Update eventual pci device in global list. +* Insert it if none was found. +*/ +if (pci_update_device (&addr) <0 ) +return -EIO ; +/* Find the current device holding this address in the bus. */ +FOREACH_DEVICE_ON_PCIBUS (pdev) { +if (rte_eal_compare_pci_addr (&pdev->addr, &addr)) +continue ; +/* Update eventual devargs. */ +if (pdev->device.devargs && + da != pdev->device.devargs) { +/* TODO: cleanup free */ +free (pdev->device.devargs->args); +rte_memcpy (pdev->device.devargs, da,sizeof (*da)); + } +break ; + } +if (rte_pci_probe_one (&addr)) +return -ENODEV ; +/* Get back new device name. */ +if (pdev->device.devargs && + da != pdev->device.devargs) +snprintf (da->name,sizeof (da->name),"%s" , + pdev->device.devargs->name); +return 0 ; +} + +static int +pci_unplug (struct rte_devargs *da) +{ +struct rte_pci_addr addr; + +if (da ==NULL ) +return -EINVAL ; +if (pci_parse (da->name, &addr)) +return -EFAULT ; +if (rte_pci_detach (&addr)) +return -ENODEV ; +return 0 ; +} +struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_pci_scan, .probe = rte_pci_probe, .find_device = pci_find_device, .parse = pci_parse, + .plug = pci_plug, + .unplug = pci_unplug, }, .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list),
Signature · 1 line
2.1.4
PATCH v2 2/3 dev: remove vdev function dependency
In reply to Gaetan Rivet--- lib/librte_eal/common/eal_common_dev.c | 49 +++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 22 deletions(-)
lib/librte_eal/common/eal_common_dev.c +27 -22
@@ -61,6 +61,7 @@ static int cmp_detached_dev_name(const struct rte_device *dev,int rte_eal_dev_attach (const char *name,const char *devargs) {struct rte_device *dev; +struct rte_bus *bus;int ret;if (name ==NULL || devargs ==NULL ) {
@@ -69,31 +70,35 @@ int rte_eal_dev_attach(const char *name, const char *devargs) } dev =rte_bus_find_device (NULL , cmp_detached_dev_name, name); -if (dev) { -struct rte_bus *bus; - +if (dev) bus =rte_bus_find_by_device (dev); -if (!bus) { -RTE_LOG (ERR ,EAL ,"Cannot find bus for device (%s)\n" , - name); -return -EINVAL ; - } - -if (!bus->plug) { -RTE_LOG (ERR ,EAL ,"Bus function not supported\n" ); -return -ENOTSUP ; - } - +else + bus =rte_bus_from_dev (name); +if (!bus) { +RTE_LOG (ERR ,EAL ,"Cannot find bus for device (%s)\n" , + name); +return -EINVAL ; + } +if (!bus->plug) { +RTE_LOG (ERR ,EAL ,"Device hotplug not supported on this bus\n" ); +return -ENOTSUP ; + } +if (!dev) { +struct rte_devargs da; +char da_str[snprintf (NULL ,0 ,"%s,%s" , name, devargs) +1 ]; + +/* +* If we haven't found a bus device the user meant to hotplug +* a device instead. +*/ +snprintf (da_str,sizeof (da_str),"%s,%s" , name, devargs); + ret =rte_eal_devargs_parse (da_str, &da); +if (ret) +return ret; + ret = bus->plug (&da); + }else { ret = bus->plug (dev->devargs); - goto out; } - -/* -* If we haven't found a bus device the user meant to "hotplug" a -* virtual device instead. -*/ - ret =rte_vdev_init (name, devargs); -out:if (ret)RTE_LOG (ERR ,EAL ,"Driver cannot attach the device (%s)\n" , name);
Signature · 1 line
2.1.4
PATCH v2 3/3 vdev: use standard bus registration function
In reply to Gaetan Rivet--- lib/librte_eal/common/eal_common_vdev.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-)
lib/librte_eal/common/eal_common_vdev.c +1 -17
@@ -52,14 +52,10 @@ static struct vdev_device_list vdev_device_list =struct vdev_driver_list vdev_driver_list =TAILQ_HEAD_INITIALIZER (vdev_driver_list); -static void rte_vdev_bus_register (void ); -/* register a driver */ void rte_vdev_register (struct rte_vdev_driver *driver) { -rte_vdev_bus_register (); -TAILQ_INSERT_TAIL (&vdev_driver_list, driver, next); }
@@ -374,16 +370,4 @@ static struct rte_bus rte_vdev_bus = { .parse = vdev_parse, }; -RTE_INIT (rte_vdev_bus_register); - -static void rte_vdev_bus_register (void ) -{ -static int registered; - -if (registered) -return ; - - registered =1 ; - rte_vdev_bus.name =VIRTUAL_BUS_NAME ; -rte_bus_register (&rte_vdev_bus); -} +RTE_REGISTER_BUS (VIRTUAL_BUS_NAME , rte_vdev_bus);
Signature · 1 line
2.1.4
v3 cover eal: complete attach / detach support
In reply to Gaetan RivetImplements attach / detach for the PCI bus, and a streamlined attach for the virtual bus.
This is necessary to remove the final dependencies of the EAL on the virtual and PCI buses, due to the rte_eal_dev_attach and rte_eal_dev_detach functions.
This patchset depends on:
pci: implement find_device bus operation
http://dpdk.org/ml/archives/dev/2017-May/066340.html
http://dpdk.org/dev/patchwork/patch/24498/
[PATCH 00/14] Generic devargs parsing
http://dpdk.org/ml/archives/dev/2017-May/066351.html
http://dpdk.org/dev/patchwork/patch/24508/
v1 -> v2:
* Rebase the series on the plug / unplug API.
* removed the vdev_plug implementation as it is now done in the plug/unplug introduction.
v2 -> v3:
* Fix a few bugs in rte_dev_attach / detach.
* Follow new plug / unplug API.
Gaetan Rivet (3):
pci: implement hotplug bus operation
dev: remove vdev function dependency
vdev: use standard bus registration function
lib/librte_eal/common/eal_common_dev.c | 50 ++++++++++++++---------- lib/librte_eal/common/eal_common_pci.c | 67 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_common_vdev.c | 18 +-------- 3 files changed, 98 insertions(+), 37 deletions(-)
Signature · 1 line
2.1.4
PATCH v3 1/3 pci: implement hotplug bus operation
--- lib/librte_eal/common/eal_common_pci.c | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
lib/librte_eal/common/eal_common_pci.c +67 -0
@@ -47,6 +47,7 @@#include <rte_pci.h> #include <rte_per_lcore.h> #include <rte_memory.h> +#include <rte_memcpy.h> #include <rte_memzone.h> #include <rte_eal.h> #include <rte_string_fns.h>
@@ -517,12 +518,78 @@ pci_find_device(rte_dev_cmp_t cmp, const void *data)return NULL ; } +static struct rte_device * +pci_plug (struct rte_devargs *da) +{ +struct rte_pci_device *pdev; +struct rte_pci_addr addr; + +if (pci_parse (da->name, &addr)) { + rte_errno =EFAULT ; +return NULL ; + } +/* +* Update eventual pci device in global list. +* Insert it if none was found. +*/ +if (pci_update_device (&addr) <0 ) { + rte_errno =EIO ; +return NULL ; + } +/* Find the current device holding this address in the bus. */ +FOREACH_DEVICE_ON_PCIBUS (pdev) { +if (rte_eal_compare_pci_addr (&pdev->addr, &addr)) +continue ; +/* Update eventual devargs. */ + pdev->device.devargs =rte_eal_devargs_clone (da); +if (pdev->device.devargs ==NULL ) { + rte_errno =ENOMEM ; +return NULL ; + } +break ; + } +if (rte_pci_probe_one (&addr)) { + rte_errno =ENODEV ; +return NULL ; + } +/* Get back new device name. */ +if (pdev->device.devargs && + da != pdev->device.devargs) +snprintf (da->name,sizeof (da->name),"%s" , + pdev->device.devargs->name); +return &pdev->device; +} + +static int +pci_unplug (struct rte_device *dev) +{ +struct rte_pci_addr addr; + +if (dev ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } +if (pci_parse (dev->name, &addr)) { + rte_errno =EFAULT ; +return -1 ; + } +if (rte_pci_detach (&addr)) { + rte_errno =ENODEV ; +return -1 ; + } +if (dev->devargs) +rte_eal_devargs_rmv (dev->devargs); +return 0 ; +} +struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_pci_scan, .probe = rte_pci_probe, .find_device = pci_find_device, .parse = pci_parse, + .plug = pci_plug, + .unplug = pci_unplug, }, .device_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.device_list), .driver_list =TAILQ_HEAD_INITIALIZER (rte_pci_bus.driver_list),
Signature · 1 line
2.1.4
PATCH v3 2/3 dev: remove vdev function dependency
In reply to Gaetan Rivet--- lib/librte_eal/common/eal_common_dev.c | 50 ++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 20 deletions(-)
lib/librte_eal/common/eal_common_dev.c +30 -20
@@ -43,6 +43,7 @@#include <rte_debug.h> #include <rte_devargs.h> #include <rte_log.h> +#include <rte_errno.h> #include "eal_private.h"
@@ -61,6 +62,8 @@ static int cmp_detached_dev_name(const struct rte_device *dev,int rte_eal_dev_attach (const char *name,const char *devargs) {struct rte_device *dev; +struct rte_bus *bus; +struct rte_devargs da;int ret;if (name ==NULL || devargs ==NULL ) {
@@ -70,30 +73,37 @@ int rte_eal_dev_attach(const char *name, const char *devargs) dev =rte_bus_find_device (NULL , cmp_detached_dev_name, name);if (dev) { -struct rte_bus *bus; - bus =rte_bus_find_by_device (dev); -if (!bus) { -RTE_LOG (ERR ,EAL ,"Cannot find bus for device (%s)\n" , + }else { +char da_str[snprintf (NULL ,0 ,"%s,%s" , name, devargs) +1 ]; + +/* +* If we haven't found a bus device the user meant to hotplug +* a device instead. +*/ +snprintf (da_str,sizeof (da_str),"%s,%s" , name, devargs); + ret =rte_eal_devargs_parse (da_str, &da); +if (ret) { +RTE_LOG (ERR ,EAL ,"Could not parse device (%s)\n" , name); -return -EINVAL ; - } - -if (!bus->plug) { -RTE_LOG (ERR ,EAL ,"Bus function not supported\n" ); -return -ENOTSUP ; +return ret; } - - ret = (bus->plug (dev->devargs) ==NULL ); - goto out; + bus = da.bus; } - -/* -* If we haven't found a bus device the user meant to "hotplug" a -* virtual device instead. -*/ - ret =rte_vdev_init (name, devargs); -out: +if (bus ==NULL ) { +RTE_LOG (ERR ,EAL ,"Cannot find bus for device (%s)\n" , + name); +return -EINVAL ; + } +if (bus->plug ==NULL ) { +RTE_LOG (ERR ,EAL ,"Device hotplug not supported on this bus\n" ); +return -ENOTSUP ; + } +if (dev ==NULL ) + dev = bus->plug (&da); +else + dev = bus->plug (dev->devargs); + ret = dev ?0 : -rte_errno;if (ret)RTE_LOG (ERR ,EAL ,"Driver cannot attach the device (%s)\n" , name);
Signature · 1 line
2.1.4
Re: [PATCH v3 2/3] dev: remove vdev function dependency
08/06/2017 01:58, Gaetan Rivet:
Quoted 4 lines
Signed-off-by Gaetan Rivet <[email protected]>--- lib/librte_eal/common/eal_common_dev.c | 50 ++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 20 deletions(-)
It's difficult to understand this patch. Please add some explanations.
And it may be better to insert or merge it in the first attach/detach series.
PATCH v3 3/3 vdev: use standard bus registration function
In reply to Gaetan Rivet--- lib/librte_eal/common/eal_common_vdev.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-)
lib/librte_eal/common/eal_common_vdev.c +1 -17
@@ -54,14 +54,10 @@ static struct vdev_device_list vdev_device_list =struct vdev_driver_list vdev_driver_list =TAILQ_HEAD_INITIALIZER (vdev_driver_list); -static void rte_vdev_bus_register (void ); -/* register a driver */ void rte_vdev_register (struct rte_vdev_driver *driver) { -rte_vdev_bus_register (); -TAILQ_INSERT_TAIL (&vdev_driver_list, driver, next); }
@@ -394,16 +390,4 @@ static struct rte_bus rte_vdev_bus = { .parse = vdev_parse, }; -RTE_INIT (rte_vdev_bus_register); - -static void rte_vdev_bus_register (void ) -{ -static int registered; - -if (registered) -return ; - - registered =1 ; - rte_vdev_bus.name =VIRTUAL_BUS_NAME ; -rte_bus_register (&rte_vdev_bus); -} +RTE_REGISTER_BUS (VIRTUAL_BUS_NAME , rte_vdev_bus);
Signature · 1 line
2.1.4
Re: [PATCH v3 3/3] vdev: use standard bus registration function
08/06/2017 01:58, Gaetan Rivet:
Quoted 1 line
+RTE_REGISTER_BUS(VIRTUAL_BUS_NAME,
rte_vdev_bus);
nice :)