[dpdk-dev,RFC] eal: use busname and devargs to attach devices
Checks
Commit Message
Using just the device name to attach a device on the EAL level is not enough
for a unique identification of the bus it should get attached to. Therefore
lets change rte_eal_dev_attach() introduced in 16.11 to take the busname and
the raw devargs string.
Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
lib/librte_eal/common/eal_common_dev.c | 61 ++++++++++++++++++++++++++--------
lib/librte_ether/rte_ethdev.c | 17 +---------
2 files changed, 49 insertions(+), 29 deletions(-)
@@ -37,6 +37,7 @@
#include <inttypes.h>
#include <sys/queue.h>
+#include <rte_bus.h>
#include <rte_dev.h>
#include <rte_devargs.h>
#include <rte_debug.h>
@@ -76,29 +77,63 @@ void rte_eal_device_remove(struct rte_device *dev)
TAILQ_REMOVE(&dev_device_list, dev, next);
}
-int rte_eal_dev_attach(const char *name, const char *devargs)
+int rte_eal_dev_attach(const char *busname, const char *devargs)
{
- struct rte_pci_addr addr;
+ struct rte_bus *bus;
+ rte_bus_attach_t attach;
+ int ret;
- if (name == NULL || devargs == NULL) {
+ if (busname == 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)
- goto err;
+ if (!busname) {
+ char *name, *args;
+ struct rte_pci_addr addr;
- } else {
- if (rte_eal_vdev_init(name, devargs))
- goto err;
+ /*
+ * We default to virtual device but lets check for PCI device format for
+ * backwards compatibility reasons.
+ */
+ busname = "virtual";
+
+ if (rte_eal_parse_devargs_str(devargs, &name, &args))
+ return -EINVAL;
+
+ if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+ RTE_LOG(ERR, EAL, "Deprectated\n");
+ busname = "pci";
+ }
+
+ free(name);
+ free(args);
}
- return 0;
+ bus = rte_bus_find_by_name(busname);
+ if (!bus) {
+ RTE_LOG(ERR, EAL, "Can't find bus (%s)\n", busname);
+ return -EINVAL;
+ }
-err:
- RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", name);
- return -EINVAL;
+ attach = bus->attach;
+ if (!attach) {
+ RTE_LOG(ERR, EAL, "Function not supported\n");
+ return -ENOTSUP;
+ }
+
+ ret = attach(devargs);
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Attaching device to bus failed \n");
+ return ret;
+ }
+
+ /*
+ * Probing might fail because some devices are not claimed by any driver
+ * but we don't care: the device is properly attached at this point.
+ */
+ (void)bus->probe();
+ return 0;
}
int rte_eal_dev_detach(const char *name)
@@ -474,29 +474,16 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
{
int ret = -1;
int current = rte_eth_dev_count();
- char *name = NULL;
- char *args = NULL;
if ((devargs == NULL) || (port_id == NULL)) {
ret = -EINVAL;
goto err;
}
- /* parse devargs, then retrieve device name and args */
- if (rte_eal_parse_devargs_str(devargs, &name, &args))
- goto err;
-
- ret = rte_eal_dev_attach(name, args);
+ ret = rte_eal_dev_attach(NULL, devargs);
if (ret < 0)
goto err;
- /* no point looking at the port count if no port exists */
- if (!rte_eth_dev_count()) {
- RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
- ret = -1;
- goto err;
- }
-
/* if nothing happened, there is a bug here, since some driver told us
* it did attach a device, but did not create a port.
*/
@@ -509,8 +496,6 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
ret = 0;
err:
- free(name);
- free(args);
return ret;
}