1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2016-2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
13 #include <rte_devargs.h>
14 #include <rte_kvargs.h>
17 #include "sfc_kvargs.h"
20 sfc_kvargs_parse(struct sfc_adapter *sa)
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_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,
32 SFC_KVARG_RXD_WAIT_TIMEOUT_NS,
33 RTE_DEVARGS_KEY_CLASS,
40 sa->kvargs = rte_kvargs_parse(devargs->args, params);
41 if (sa->kvargs == NULL)
48 sfc_kvargs_cleanup(struct sfc_adapter *sa)
50 rte_kvargs_free(sa->kvargs);
54 sfc_kvarg_match_value(const char *value, const char * const *values,
55 unsigned int n_values)
59 for (i = 0; i < n_values; ++i)
60 if (strcasecmp(value, values[i]) == 0)
67 sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,
68 arg_handler_t handler, void *opaque_arg)
70 if (sa->kvargs == NULL)
73 return -rte_kvargs_process(sa->kvargs, key_match, handler, opaque_arg);
77 sfc_kvarg_bool_handler(__rte_unused const char *key,
78 const char *value_str, void *opaque)
80 const char * const true_strs[] = {
81 "1", "y", "yes", "on", "true"
83 const char * const false_strs[] = {
84 "0", "n", "no", "off", "false"
88 if (sfc_kvarg_match_value(value_str, true_strs,
91 else if (sfc_kvarg_match_value(value_str, false_strs,
101 sfc_kvarg_long_handler(__rte_unused const char *key,
102 const char *value_str, void *opaque)
107 if (!value_str || !opaque)
110 value = strtol(value_str, &endptr, 0);
111 if (endptr == value_str)
114 *(long *)opaque = value;
120 sfc_kvarg_string_handler(__rte_unused const char *key,
121 const char *value_str, void *opaque)
123 *(const char **)opaque = value_str;