1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2021 NVIDIA Corporation & Affiliates
3  */
4 
5 #include <string.h>
6 
7 #include <rte_bus.h>
8 #include <rte_dev.h>
9 #include <rte_errno.h>
10 #include <rte_kvargs.h>
11 
12 #include "private.h"
13 #include "rte_bus_auxiliary.h"
14 
15 enum auxiliary_params {
16 	RTE_AUXILIARY_PARAM_NAME,
17 };
18 
19 static const char * const auxiliary_params_keys[] = {
20 	[RTE_AUXILIARY_PARAM_NAME] = "name",
21 };
22 
23 static int
24 auxiliary_dev_match(const struct rte_device *dev,
25 	      const void *_kvlist)
26 {
27 	const struct rte_kvargs *kvlist = _kvlist;
28 	int ret;
29 
30 	ret = rte_kvargs_process(kvlist,
31 			auxiliary_params_keys[RTE_AUXILIARY_PARAM_NAME],
32 			rte_kvargs_strcmp, (void *)(uintptr_t)dev->name);
33 
34 	return ret != 0 ? -1 : 0;
35 }
36 
37 void *
38 auxiliary_dev_iterate(const void *start,
39 		    const char *str,
40 		    const struct rte_dev_iterator *it __rte_unused)
41 {
42 	rte_bus_find_device_t find_device;
43 	struct rte_kvargs *kvargs = NULL;
44 	struct rte_device *dev;
45 
46 	if (str != NULL) {
47 		kvargs = rte_kvargs_parse(str, auxiliary_params_keys);
48 		if (kvargs == NULL) {
49 			AUXILIARY_LOG(ERR, "cannot parse argument list %s",
50 				      str);
51 			rte_errno = EINVAL;
52 			return NULL;
53 		}
54 	}
55 	find_device = auxiliary_bus.bus.find_device;
56 	dev = find_device(start, auxiliary_dev_match, kvargs);
57 	rte_kvargs_free(kvargs);
58 	return dev;
59 }
60