net/ice/base: fix NVGRE switch rule programming
[dpdk.git] / drivers / bus / vdev / vdev_params.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018 GaĆ«tan Rivet
3  */
4
5 #include <string.h>
6
7 #include <rte_dev.h>
8 #include <rte_bus.h>
9 #include <rte_kvargs.h>
10 #include <rte_errno.h>
11
12 #include "vdev_logs.h"
13 #include "vdev_private.h"
14
15 enum vdev_params {
16         RTE_VDEV_PARAM_NAME,
17         RTE_VDEV_PARAM_MAX,
18 };
19
20 static const char * const vdev_params_keys[] = {
21         [RTE_VDEV_PARAM_NAME] = "name",
22         [RTE_VDEV_PARAM_MAX] = NULL,
23 };
24
25 static int
26 vdev_dev_match(const struct rte_device *dev,
27                const void *_kvlist)
28 {
29         int ret;
30         const struct rte_kvargs *kvlist = _kvlist;
31         char *name;
32
33         /* cannot pass const dev->name to rte_kvargs_process() */
34         name = strdup(dev->name);
35         if (name == NULL)
36                 return -1;
37         ret = rte_kvargs_process(kvlist,
38                 vdev_params_keys[RTE_VDEV_PARAM_NAME],
39                 rte_kvargs_strcmp, name);
40         free(name);
41         if (ret != 0)
42                 return -1;
43
44         return 0;
45 }
46
47 void *
48 rte_vdev_dev_iterate(const void *start,
49                      const char *str,
50                      const struct rte_dev_iterator *it __rte_unused)
51 {
52         struct rte_kvargs *kvargs = NULL;
53         struct rte_device *dev;
54
55         if (str != NULL) {
56                 kvargs = rte_kvargs_parse(str, vdev_params_keys);
57                 if (kvargs == NULL) {
58                         VDEV_LOG(ERR, "cannot parse argument list\n");
59                         rte_errno = EINVAL;
60                         return NULL;
61                 }
62         }
63         dev = rte_vdev_find_device(start, vdev_dev_match, kvargs);
64         rte_kvargs_free(kvargs);
65         return dev;
66 }