[v1,12/13] ethdev: process declarative eth devargs
Checks
Commit Message
Process the class-specific arguments in a devargs.
This processing takes the form of setting the proper eth_dev fields when
relevant.
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
lib/librte_ethdev/eth_private.h | 5 +++
lib/librte_ethdev/rte_class_eth.c | 62 +++++++++++++++++++++++++++++++
lib/librte_ethdev/rte_ethdev.c | 7 ++++
3 files changed, 74 insertions(+)
Comments
On 08/30/2018 04:42 PM, Gaetan Rivet wrote:
> Process the class-specific arguments in a devargs.
> This processing takes the form of setting the proper eth_dev fields when
> relevant.
>
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
> lib/librte_ethdev/eth_private.h | 5 +++
> lib/librte_ethdev/rte_class_eth.c | 62 +++++++++++++++++++++++++++++++
> lib/librte_ethdev/rte_ethdev.c | 7 ++++
> 3 files changed, 74 insertions(+)
>
> diff --git a/lib/librte_ethdev/eth_private.h b/lib/librte_ethdev/eth_private.h
> index 0f5c6d5c4..c0c065165 100644
> --- a/lib/librte_ethdev/eth_private.h
> +++ b/lib/librte_ethdev/eth_private.h
> @@ -19,6 +19,11 @@ struct rte_eth_dev *
> eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
> const void *data);
>
> +/* Generic rte_eth_dev parameters processor. */
> +int
> +rte_eth_dev_args_parse(struct rte_eth_dev *eth_dev,
> + struct rte_devargs *da);
> +
> #ifdef __cplusplus
> }
> #endif
> diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c
> index d8d8e8845..18fdef605 100644
> --- a/lib/librte_ethdev/rte_class_eth.c
> +++ b/lib/librte_ethdev/rte_class_eth.c
<...>
> @@ -79,6 +93,54 @@ eth_dev_iterate(const void *start,
> return edev;
> }
>
> +static int
> +eth_dev_set_name(struct rte_eth_dev *edev,
> + const char *value)
> +{
> + snprintf(edev->data->name,
> + sizeof(edev->data->name),
> + "%s", value);
strlcpy()?
Shouldn't we return error if name does fit in name buffer?
> + return 0;
> +}
> +
> +static int
> +ethdev_args_process(const char *key,
> + const char *value,
> + void *_edev)
> +{
> + static eth_dev_set_t eth_dev_set[] = {
> + [RTE_ETH_PARAMS_NAME] = eth_dev_set_name,
> + [RTE_ETH_PARAMS_MAX] = NULL,
> + };
> + struct rte_eth_dev *edev = _edev;
> + int param;
> +
> + param = ethdev_param_id(key);
> + if (eth_dev_set[param])
> + return eth_dev_set[param](edev, value);
> + return 0;
> +}
> +
> +int
> +rte_eth_dev_args_parse(struct rte_eth_dev *edev,
> + struct rte_devargs *devargs)
> +{
> + struct rte_kvargs *kvargs = NULL;
> +
> + if (devargs == NULL || devargs->cls_str == NULL)
> + return 0;
> +
> + kvargs = rte_kvargs_parse_delim(devargs->cls_str, eth_params_keys, "/");
> + if (kvargs == NULL) {
> + RTE_LOG(ERR, EAL, "cannot parse argument list\n");
> + return -EINVAL;
> + }
> + if (rte_kvargs_process(kvargs, NULL, ethdev_args_process, edev))
Shouldn't we free kvargs here as well?
> + return -1;
> + rte_kvargs_free(kvargs);
> + return 0;
> +}
> +
> struct rte_class rte_class_eth = {
> .dev_iterate = eth_dev_iterate,
> };
<...>
On Fri, Aug 31, 2018 at 01:10:48PM +0300, Andrew Rybchenko wrote:
> On 08/30/2018 04:42 PM, Gaetan Rivet wrote:
> > Process the class-specific arguments in a devargs.
> > This processing takes the form of setting the proper eth_dev fields when
> > relevant.
> >
> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> > ---
> > lib/librte_ethdev/eth_private.h | 5 +++
> > lib/librte_ethdev/rte_class_eth.c | 62 +++++++++++++++++++++++++++++++
> > lib/librte_ethdev/rte_ethdev.c | 7 ++++
> > 3 files changed, 74 insertions(+)
> >
> > diff --git a/lib/librte_ethdev/eth_private.h b/lib/librte_ethdev/eth_private.h
> > index 0f5c6d5c4..c0c065165 100644
> > --- a/lib/librte_ethdev/eth_private.h
> > +++ b/lib/librte_ethdev/eth_private.h
> > @@ -19,6 +19,11 @@ struct rte_eth_dev *
> > eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
> > const void *data);
> > +/* Generic rte_eth_dev parameters processor. */
> > +int
> > +rte_eth_dev_args_parse(struct rte_eth_dev *eth_dev,
> > + struct rte_devargs *da);
> > +
> > #ifdef __cplusplus
> > }
> > #endif
> > diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c
> > index d8d8e8845..18fdef605 100644
> > --- a/lib/librte_ethdev/rte_class_eth.c
> > +++ b/lib/librte_ethdev/rte_class_eth.c
>
> <...>
>
> > @@ -79,6 +93,54 @@ eth_dev_iterate(const void *start,
> > return edev;
> > }
> > +static int
> > +eth_dev_set_name(struct rte_eth_dev *edev,
> > + const char *value)
> > +{
> > + snprintf(edev->data->name,
> > + sizeof(edev->data->name),
> > + "%s", value);
>
> strlcpy()?
Ok.
> Shouldn't we return error if name does fit in name buffer?
Good idea.
>
> > + return 0;
> > +}
> > +
> > +static int
> > +ethdev_args_process(const char *key,
> > + const char *value,
> > + void *_edev)
> > +{
> > + static eth_dev_set_t eth_dev_set[] = {
> > + [RTE_ETH_PARAMS_NAME] = eth_dev_set_name,
> > + [RTE_ETH_PARAMS_MAX] = NULL,
> > + };
> > + struct rte_eth_dev *edev = _edev;
> > + int param;
> > +
> > + param = ethdev_param_id(key);
> > + if (eth_dev_set[param])
> > + return eth_dev_set[param](edev, value);
> > + return 0;
> > +}
> > +
> > +int
> > +rte_eth_dev_args_parse(struct rte_eth_dev *edev,
> > + struct rte_devargs *devargs)
> > +{
> > + struct rte_kvargs *kvargs = NULL;
> > +
> > + if (devargs == NULL || devargs->cls_str == NULL)
> > + return 0;
> > +
> > + kvargs = rte_kvargs_parse_delim(devargs->cls_str, eth_params_keys, "/");
> > + if (kvargs == NULL) {
> > + RTE_LOG(ERR, EAL, "cannot parse argument list\n");
> > + return -EINVAL;
> > + }
> > + if (rte_kvargs_process(kvargs, NULL, ethdev_args_process, edev))
>
> Shouldn't we free kvargs here as well?
>
Indeed, silly mistake.
Thanks
> > + return -1;
> > + rte_kvargs_free(kvargs);
> > + return 0;
> > +}
> > +
> > struct rte_class rte_class_eth = {
> > .dev_iterate = eth_dev_iterate,
> > };
>
> <...>
@@ -19,6 +19,11 @@ struct rte_eth_dev *
eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
const void *data);
+/* Generic rte_eth_dev parameters processor. */
+int
+rte_eth_dev_args_parse(struct rte_eth_dev *eth_dev,
+ struct rte_devargs *da);
+
#ifdef __cplusplus
}
#endif
@@ -6,6 +6,7 @@
#include <rte_class.h>
#include <rte_compat.h>
+#include <rte_devargs.h>
#include <rte_errno.h>
#include <rte_kvargs.h>
#include <rte_log.h>
@@ -35,6 +36,19 @@ struct eth_dev_match_arg {
.kvlist = (k), \
})
+typedef int (*eth_dev_set_t)(struct rte_eth_dev *edev, const char *value);
+
+static enum eth_params
+ethdev_param_id(const char *key)
+{
+ int i;
+
+ for (i = 0; i < RTE_ETH_PARAMS_MAX; i++)
+ if (strcmp(key, eth_params_keys[i]) == 0)
+ return i;
+ return RTE_ETH_PARAMS_MAX;
+}
+
static int
eth_dev_match(const struct rte_eth_dev *edev,
const void *_arg)
@@ -79,6 +93,54 @@ eth_dev_iterate(const void *start,
return edev;
}
+static int
+eth_dev_set_name(struct rte_eth_dev *edev,
+ const char *value)
+{
+ snprintf(edev->data->name,
+ sizeof(edev->data->name),
+ "%s", value);
+ return 0;
+}
+
+static int
+ethdev_args_process(const char *key,
+ const char *value,
+ void *_edev)
+{
+ static eth_dev_set_t eth_dev_set[] = {
+ [RTE_ETH_PARAMS_NAME] = eth_dev_set_name,
+ [RTE_ETH_PARAMS_MAX] = NULL,
+ };
+ struct rte_eth_dev *edev = _edev;
+ int param;
+
+ param = ethdev_param_id(key);
+ if (eth_dev_set[param])
+ return eth_dev_set[param](edev, value);
+ return 0;
+}
+
+int
+rte_eth_dev_args_parse(struct rte_eth_dev *edev,
+ struct rte_devargs *devargs)
+{
+ struct rte_kvargs *kvargs = NULL;
+
+ if (devargs == NULL || devargs->cls_str == NULL)
+ return 0;
+
+ kvargs = rte_kvargs_parse_delim(devargs->cls_str, eth_params_keys, "/");
+ if (kvargs == NULL) {
+ RTE_LOG(ERR, EAL, "cannot parse argument list\n");
+ return -EINVAL;
+ }
+ if (rte_kvargs_process(kvargs, NULL, ethdev_args_process, edev))
+ return -1;
+ rte_kvargs_free(kvargs);
+ return 0;
+}
+
struct rte_class rte_class_eth = {
.dev_iterate = eth_dev_iterate,
};
@@ -41,6 +41,7 @@
#include "rte_ethdev.h"
#include "rte_ethdev_driver.h"
#include "ethdev_profile.h"
+#include "eth_private.h"
int rte_eth_dev_logtype;
@@ -3496,6 +3497,12 @@ rte_eth_dev_create(struct rte_device *device, const char *name,
}
}
+ retval = rte_eth_dev_args_parse(ethdev, device->devargs);
+ if (retval) {
+ RTE_LOG(ERR, EAL, "ethdev parsing failed");
+ goto probe_failed;
+ }
+
retval = ethdev_init(ethdev, init_params);
if (retval) {
RTE_LOG(ERR, EAL, "ethdev initialisation failed");