#include <rte_kvargs.h>
#include <rte_log.h>
#include <rte_tailq.h>
+#include <rte_string_fns.h>
#include "eal_private.h"
/** user device double-linked queue type definition */
return i;
}
+/* Resolve devargs name from bus arguments. */
+static int
+devargs_bus_parse_default(struct rte_devargs *devargs,
+ struct rte_kvargs *bus_args)
+{
+ const char *name;
+
+ /* Parse devargs name from bus key-value list. */
+ name = rte_kvargs_get(bus_args, "name");
+ if (name == NULL) {
+ RTE_LOG(INFO, EAL, "devargs name not found: %s\n",
+ devargs->data);
+ return 0;
+ }
+ if (rte_strscpy(devargs->name, name, sizeof(devargs->name)) < 0) {
+ RTE_LOG(ERR, EAL, "devargs name too long: %s\n",
+ devargs->data);
+ return -E2BIG;
+ }
+ return 0;
+}
+
int
rte_devargs_layers_parse(struct rte_devargs *devargs,
const char *devstr)
const char *str;
struct rte_kvargs *kvlist;
} layers[] = {
- { "bus=", NULL, NULL, },
- { "class=", NULL, NULL, },
- { "driver=", NULL, NULL, },
+ { RTE_DEVARGS_KEY_BUS "=", NULL, NULL, },
+ { RTE_DEVARGS_KEY_CLASS "=", NULL, NULL, },
+ { RTE_DEVARGS_KEY_DRIVER "=", NULL, NULL, },
};
struct rte_kvargs_pair *kv = NULL;
struct rte_class *cls = NULL;
layers[i].str = s;
layers[i].kvlist = rte_kvargs_parse_delim(s, NULL, "/");
if (layers[i].kvlist == NULL) {
- RTE_LOG(ERR, EAL, "Could not parse %s\n", s);
ret = -EINVAL;
goto get_out;
}
if (layers[i].kvlist == NULL)
continue;
kv = &layers[i].kvlist->pairs[0];
- if (strcmp(kv->key, "bus") == 0) {
+ if (kv->key == NULL)
+ continue;
+ if (strcmp(kv->key, RTE_DEVARGS_KEY_BUS) == 0) {
bus = rte_bus_find_by_name(kv->value);
if (bus == NULL) {
RTE_LOG(ERR, EAL, "Could not find bus \"%s\"\n",
ret = -EFAULT;
goto get_out;
}
- } else if (strcmp(kv->key, "class") == 0) {
+ } else if (strcmp(kv->key, RTE_DEVARGS_KEY_CLASS) == 0) {
cls = rte_class_find_by_name(kv->value);
if (cls == NULL) {
RTE_LOG(ERR, EAL, "Could not find class \"%s\"\n",
ret = -EFAULT;
goto get_out;
}
- } else if (strcmp(kv->key, "driver") == 0) {
+ } else if (strcmp(kv->key, RTE_DEVARGS_KEY_DRIVER) == 0) {
/* Ignore */
continue;
}
}
}
+ /* Resolve devargs name. */
+ if (bus != NULL && bus->devargs_parse != NULL)
+ ret = bus->devargs_parse(devargs);
+ else if (layers[0].kvlist != NULL)
+ ret = devargs_bus_parse_default(devargs, layers[0].kvlist);
+
get_out:
for (i = 0; i < RTE_DIM(layers); i++) {
if (layers[i].kvlist)
if (da == NULL)
return -EINVAL;
+ /* First parse according global device syntax. */
+ if (rte_devargs_layers_parse(da, dev) == 0) {
+ if (da->bus != NULL || da->cls != NULL)
+ return 0;
+ rte_devargs_reset(da);
+ }
+
+ /* Otherwise fallback to legacy syntax: */
+
/* Retrieve eventual bus info */
do {
devname = dev;