4 * Copyright (c) 2016-2017 Solarflare Communications Inc.
7 * This software was jointly developed between OKTET Labs (under contract
8 * for Solarflare) and Solarflare Communications, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <rte_devargs.h>
36 #include <rte_kvargs.h>
39 #include "sfc_kvargs.h"
42 sfc_kvargs_parse(struct sfc_adapter *sa)
44 struct rte_eth_dev *eth_dev = (sa)->eth_dev;
45 struct rte_devargs *devargs = eth_dev->device->devargs;
46 const char **params = (const char *[]){
47 SFC_KVARG_STATS_UPDATE_PERIOD_MS,
49 SFC_KVARG_MCDI_LOGGING,
50 SFC_KVARG_PERF_PROFILE,
57 sa->kvargs = rte_kvargs_parse(devargs->args, params);
58 if (sa->kvargs == NULL)
65 sfc_kvargs_cleanup(struct sfc_adapter *sa)
67 rte_kvargs_free(sa->kvargs);
71 sfc_kvarg_match_value(const char *value, const char * const *values,
72 unsigned int n_values)
76 for (i = 0; i < n_values; ++i)
77 if (strcasecmp(value, values[i]) == 0)
84 sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,
85 arg_handler_t handler, void *opaque_arg)
87 if (sa->kvargs == NULL)
90 return -rte_kvargs_process(sa->kvargs, key_match, handler, opaque_arg);
94 sfc_kvarg_bool_handler(__rte_unused const char *key,
95 const char *value_str, void *opaque)
97 const char * const true_strs[] = {
98 "1", "y", "yes", "on", "true"
100 const char * const false_strs[] = {
101 "0", "n", "no", "off", "false"
103 bool *value = opaque;
105 if (sfc_kvarg_match_value(value_str, true_strs,
108 else if (sfc_kvarg_match_value(value_str, false_strs,
109 RTE_DIM(false_strs)))
118 sfc_kvarg_long_handler(__rte_unused const char *key,
119 const char *value_str, void *opaque)
124 if (!value_str || !opaque)
127 value = strtol(value_str, &endptr, 0);
128 if (endptr == value_str)
131 *(long *)opaque = value;