net/i40e: move RSS to flow API
[dpdk.git] / drivers / net / sfc / sfc_kvargs.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2016-2018 Solarflare Communications Inc.
4  * All rights reserved.
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 sfc_kvargs_parse(struct sfc_adapter *sa)
21 {
22         struct rte_eth_dev *eth_dev = (sa)->eth_dev;
23         struct rte_devargs *devargs = eth_dev->device->devargs;
24         const char **params = (const char *[]){
25                 SFC_KVARG_STATS_UPDATE_PERIOD_MS,
26                 SFC_KVARG_DEBUG_INIT,
27                 SFC_KVARG_MCDI_LOGGING,
28                 SFC_KVARG_PERF_PROFILE,
29                 SFC_KVARG_RX_DATAPATH,
30                 SFC_KVARG_TX_DATAPATH,
31                 NULL,
32         };
33
34         if (devargs == NULL)
35                 return 0;
36
37         sa->kvargs = rte_kvargs_parse(devargs->args, params);
38         if (sa->kvargs == NULL)
39                 return EINVAL;
40
41         return 0;
42 }
43
44 void
45 sfc_kvargs_cleanup(struct sfc_adapter *sa)
46 {
47         rte_kvargs_free(sa->kvargs);
48 }
49
50 static int
51 sfc_kvarg_match_value(const char *value, const char * const *values,
52                       unsigned int n_values)
53 {
54         unsigned int i;
55
56         for (i = 0; i < n_values; ++i)
57                 if (strcasecmp(value, values[i]) == 0)
58                         return 1;
59
60         return 0;
61 }
62
63 int
64 sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,
65                    arg_handler_t handler, void *opaque_arg)
66 {
67         if (sa->kvargs == NULL)
68                 return 0;
69
70         return -rte_kvargs_process(sa->kvargs, key_match, handler, opaque_arg);
71 }
72
73 int
74 sfc_kvarg_bool_handler(__rte_unused const char *key,
75                        const char *value_str, void *opaque)
76 {
77         const char * const true_strs[] = {
78                 "1", "y", "yes", "on", "true"
79         };
80         const char * const false_strs[] = {
81                 "0", "n", "no", "off", "false"
82         };
83         bool *value = opaque;
84
85         if (sfc_kvarg_match_value(value_str, true_strs,
86                                   RTE_DIM(true_strs)))
87                 *value = true;
88         else if (sfc_kvarg_match_value(value_str, false_strs,
89                                        RTE_DIM(false_strs)))
90                 *value = false;
91         else
92                 return -EINVAL;
93
94         return 0;
95 }
96
97 int
98 sfc_kvarg_long_handler(__rte_unused const char *key,
99                        const char *value_str, void *opaque)
100 {
101         long value;
102         char *endptr;
103
104         if (!value_str || !opaque)
105                 return -EINVAL;
106
107         value = strtol(value_str, &endptr, 0);
108         if (endptr == value_str)
109                 return -EINVAL;
110
111         *(long *)opaque = value;
112
113         return 0;
114 }
115
116 int
117 sfc_kvarg_string_handler(__rte_unused const char *key,
118                          const char *value_str, void *opaque)
119 {
120         *(const char **)opaque = value_str;
121
122         return 0;
123 }