Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : *
3 : : * Copyright(c) 2019-2021 Xilinx, Inc.
4 : : * Copyright(c) 2016-2019 Solarflare Communications Inc.
5 : : *
6 : : * This software was jointly developed between OKTET Labs (under contract
7 : : * for Solarflare) and Solarflare Communications, Inc.
8 : : */
9 : :
10 : : #include <stdbool.h>
11 : : #include <strings.h>
12 : :
13 : : #include <rte_devargs.h>
14 : : #include <rte_kvargs.h>
15 : :
16 : : #include "sfc.h"
17 : : #include "sfc_kvargs.h"
18 : :
19 : : int
20 : 0 : sfc_kvargs_parse(struct sfc_adapter *sa)
21 : : {
22 : 0 : struct rte_eth_dev *eth_dev = (sa)->eth_dev;
23 : 0 : struct rte_devargs *devargs = eth_dev->device->devargs;
24 : 0 : const char **params = (const char *[]){
25 : : SFC_KVARG_SWITCH_MODE,
26 : : SFC_KVARG_REPRESENTOR,
27 : : SFC_KVARG_STATS_UPDATE_PERIOD_MS,
28 : : SFC_KVARG_PERF_PROFILE,
29 : : SFC_KVARG_RX_DATAPATH,
30 : : SFC_KVARG_TX_DATAPATH,
31 : : SFC_KVARG_FW_VARIANT,
32 : : SFC_KVARG_RXD_WAIT_TIMEOUT_NS,
33 : : RTE_DEVARGS_KEY_CLASS,
34 : : NULL,
35 : : };
36 : :
37 [ # # ]: 0 : if (devargs == NULL)
38 : : return 0;
39 : :
40 : 0 : sa->kvargs = rte_kvargs_parse(devargs->args, params);
41 [ # # ]: 0 : if (sa->kvargs == NULL)
42 : 0 : return EINVAL;
43 : :
44 : : return 0;
45 : : }
46 : :
47 : : void
48 : 0 : sfc_kvargs_cleanup(struct sfc_adapter *sa)
49 : : {
50 : 0 : rte_kvargs_free(sa->kvargs);
51 : 0 : }
52 : :
53 : : static int
54 : : sfc_kvarg_match_value(const char *value, const char * const *values,
55 : : unsigned int n_values)
56 : : {
57 : : unsigned int i;
58 : :
59 [ # # # # ]: 0 : for (i = 0; i < n_values; ++i)
60 [ # # # # ]: 0 : if (strcasecmp(value, values[i]) == 0)
61 : : return 1;
62 : :
63 : : return 0;
64 : : }
65 : :
66 : : int
67 : 0 : sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,
68 : : arg_handler_t handler, void *opaque_arg)
69 : : {
70 [ # # ]: 0 : if (sa->kvargs == NULL)
71 : : return 0;
72 : :
73 : 0 : return -rte_kvargs_process(sa->kvargs, key_match, handler, opaque_arg);
74 : : }
75 : :
76 : : int
77 : 0 : sfc_kvarg_bool_handler(__rte_unused const char *key,
78 : : const char *value_str, void *opaque)
79 : : {
80 : 0 : const char * const true_strs[] = {
81 : : "1", "y", "yes", "on", "true"
82 : : };
83 : 0 : const char * const false_strs[] = {
84 : : "0", "n", "no", "off", "false"
85 : : };
86 : : bool *value = opaque;
87 : :
88 [ # # ]: 0 : if (sfc_kvarg_match_value(value_str, true_strs,
89 : : RTE_DIM(true_strs)))
90 : 0 : *value = true;
91 [ # # ]: 0 : else if (sfc_kvarg_match_value(value_str, false_strs,
92 : : RTE_DIM(false_strs)))
93 : 0 : *value = false;
94 : : else
95 : : return -EINVAL;
96 : :
97 : : return 0;
98 : : }
99 : :
100 : : int
101 : 0 : sfc_kvarg_long_handler(__rte_unused const char *key,
102 : : const char *value_str, void *opaque)
103 : : {
104 : : long value;
105 : : char *endptr;
106 : :
107 [ # # ]: 0 : if (!value_str || !opaque)
108 : : return -EINVAL;
109 : :
110 : 0 : value = strtol(value_str, &endptr, 0);
111 [ # # ]: 0 : if (endptr == value_str)
112 : : return -EINVAL;
113 : :
114 : 0 : *(long *)opaque = value;
115 : :
116 : 0 : return 0;
117 : : }
118 : :
119 : : int
120 : 0 : sfc_kvarg_string_handler(__rte_unused const char *key,
121 : : const char *value_str, void *opaque)
122 : : {
123 : 0 : *(const char **)opaque = value_str;
124 : :
125 : 0 : return 0;
126 : : }
|