[dpdk-dev,v3,11/25] mlx5: add support for configuration through kvargs
Commit Message
The intent is to replace the remaining compile-time options and environment
variables with a common mean of runtime configuration. This commit only
adds the kvargs handling code, subsequent commits will update the rest.
Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
drivers/net/mlx5/mlx5.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
Comments
On 6/21/2016 8:23 AM, Nelio Laranjeiro wrote:
> The intent is to replace the remaining compile-time options and environment
> variables with a common mean of runtime configuration. This commit only
> adds the kvargs handling code, subsequent commits will update the rest.
>
> Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
> Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> ---
...
> +static int
> +mlx5_args_check(const char *key, const char *val, void *opaque)
> +{
> + struct priv *priv = opaque;
> +
> + /* No parameters are expected at the moment. */
> + (void)priv;
> + (void)val;
> + WARN("%s: unknown parameter", key);
> + return EINVAL;
Returning positive value here will prevent rte_kvargs_process() to fail,
I guess that is the intention but returning EINVAL is misleading.
Also generating the checkpatch warning:
WARNING:USE_NEGATIVE_ERRNO: return of an errno should typically be
negative (ie: return -EINVAL)
#71: FILE: drivers/net/mlx5/mlx5.c:264:
+ return EINVAL;
On Tue, Jun 21, 2016 at 05:42:42PM +0100, Ferruh Yigit wrote:
> On 6/21/2016 8:23 AM, Nelio Laranjeiro wrote:
> > The intent is to replace the remaining compile-time options and environment
> > variables with a common mean of runtime configuration. This commit only
> > adds the kvargs handling code, subsequent commits will update the rest.
> >
> > Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
> > Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> > ---
>
> ...
>
> > +static int
> > +mlx5_args_check(const char *key, const char *val, void *opaque)
> > +{
> > + struct priv *priv = opaque;
> > +
> > + /* No parameters are expected at the moment. */
> > + (void)priv;
> > + (void)val;
> > + WARN("%s: unknown parameter", key);
> > + return EINVAL;
> Returning positive value here will prevent rte_kvargs_process() to fail,
> I guess that is the intention but returning EINVAL is misleading.
>
> Also generating the checkpatch warning:
> WARNING:USE_NEGATIVE_ERRNO: return of an errno should typically be
> negative (ie: return -EINVAL)
> #71: FILE: drivers/net/mlx5/mlx5.c:264:
> + return EINVAL;
>
Good catch, in fact as it is not processed by the PMD itself, it must be
compliant with the rte_kvargs_process().
I will fix in in the v4.
@@ -37,6 +37,7 @@
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
+#include <errno.h>
#include <net/if.h>
/* Verbs header. */
@@ -57,6 +58,7 @@
#include <rte_ethdev.h>
#include <rte_pci.h>
#include <rte_common.h>
+#include <rte_kvargs.h>
#ifdef PEDANTIC
#pragma GCC diagnostic error "-pedantic"
#endif
@@ -237,6 +239,70 @@ mlx5_dev_idx(struct rte_pci_addr *pci_addr)
return ret;
}
+/**
+ * Verify and store value for device argument.
+ *
+ * @param[in] key
+ * Key argument to verify.
+ * @param[in] val
+ * Value associated with key.
+ * @param opaque
+ * User data.
+ *
+ * @return
+ * 0 on success, errno value on failure.
+ */
+static int
+mlx5_args_check(const char *key, const char *val, void *opaque)
+{
+ struct priv *priv = opaque;
+
+ /* No parameters are expected at the moment. */
+ (void)priv;
+ (void)val;
+ WARN("%s: unknown parameter", key);
+ return EINVAL;
+}
+
+/**
+ * Parse device parameters.
+ *
+ * @param priv
+ * Pointer to private structure.
+ * @param devargs
+ * Device arguments structure.
+ *
+ * @return
+ * 0 on success, errno value on failure.
+ */
+static int
+mlx5_args(struct priv *priv, struct rte_devargs *devargs)
+{
+ static const char *params[] = {
+ NULL,
+ };
+ struct rte_kvargs *kvlist;
+ int ret = 0;
+ int i;
+
+ if (devargs == NULL)
+ return 0;
+ kvlist = rte_kvargs_parse(devargs->args, params);
+ if (kvlist == NULL)
+ return 0;
+ /* Process parameters. */
+ for (i = 0; (i != RTE_DIM(params)); ++i) {
+ if (rte_kvargs_count(kvlist, params[i])) {
+ ret = rte_kvargs_process(kvlist, params[i],
+ mlx5_args_check, priv);
+ if (ret != 0)
+ return ret;
+ }
+ }
+ rte_kvargs_free(kvlist);
+ return 0;
+}
+
static struct eth_driver mlx5_driver;
/**
@@ -408,6 +474,12 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
priv->port = port;
priv->pd = pd;
priv->mtu = ETHER_MTU;
+ err = mlx5_args(priv, pci_dev->devargs);
+ if (err) {
+ ERROR("failed to process device arguments: %s",
+ strerror(err));
+ goto port_error;
+ }
if (ibv_exp_query_device(ctx, &exp_device_attr)) {
ERROR("ibv_exp_query_device() failed");
goto port_error;