1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 #include <cmdline_rdline.h>
11 #include <cmdline_parse.h>
12 #include <cmdline_parse_num.h>
13 #include <cmdline_parse_string.h>
19 #include "../include/conf.h"
26 struct cmd_help_tokens
{
27 cmdline_fixed_string_t verb
;
30 cmdline_parse_token_string_t cmd_help_verb
=
31 TOKEN_STRING_INITIALIZER(struct cmd_help_tokens
, verb
, "help");
34 cmd_help_handler(__attribute__((unused
)) void *parsed_result
,
36 __attribute__((unused
)) void *data
)
38 cmdline_printf(cl
, "Available commands:\n"
40 "- set [ring_name|variable] <value>\n"
41 "- show [ring_name|variable]\n"
43 "Available variables:\n"
46 "- ring names follow the core%%u_port%%u format\n");
49 cmdline_parse_inst_t cmd_help
= {
50 .f
= cmd_help_handler
,
52 .help_str
= "show help",
54 (void *) &cmd_help_verb
,
64 struct cmd_set_tokens
{
65 cmdline_fixed_string_t verb
;
66 cmdline_fixed_string_t variable
;
70 cmdline_parse_token_string_t cmd_set_verb
=
71 TOKEN_STRING_INITIALIZER(struct cmd_set_tokens
, verb
, "set");
73 cmdline_parse_token_string_t cmd_set_variable
=
74 TOKEN_STRING_INITIALIZER(struct cmd_set_tokens
, variable
, NULL
);
76 cmdline_parse_token_num_t cmd_set_value
=
77 TOKEN_NUM_INITIALIZER(struct cmd_set_tokens
, value
, UINT32
);
80 cmd_set_handler(__attribute__((unused
)) void *parsed_result
,
82 __attribute__((unused
)) void *data
)
84 struct cmd_set_tokens
*tokens
= parsed_result
;
85 struct rte_ring
*ring
;
87 if (!strcmp(tokens
->variable
, "quota")) {
89 if (tokens
->value
> 0 && tokens
->value
<= MAX_PKT_QUOTA
)
90 *quota
= tokens
->value
;
92 cmdline_printf(cl
, "quota must be between 1 and %u\n",
96 else if (!strcmp(tokens
->variable
, "low_watermark")) {
98 if (tokens
->value
<= 100)
99 *low_watermark
= tokens
->value
* RING_SIZE
/ 100;
102 "low_watermark must be between 0%% and 100%%\n");
107 ring
= rte_ring_lookup(tokens
->variable
);
109 cmdline_printf(cl
, "Cannot find ring \"%s\"\n",
112 if (tokens
->value
>= *low_watermark
* 100 / RING_SIZE
113 && tokens
->value
<= 100)
114 *high_watermark
= tokens
->value
*
118 "ring high watermark must be between %u%% and 100%%\n",
119 *low_watermark
* 100 / RING_SIZE
);
123 cmdline_parse_inst_t cmd_set
= {
124 .f
= cmd_set_handler
,
126 .help_str
= "Set a variable value",
128 (void *) &cmd_set_verb
,
129 (void *) &cmd_set_variable
,
130 (void *) &cmd_set_value
,
140 struct cmd_show_tokens
{
141 cmdline_fixed_string_t verb
;
142 cmdline_fixed_string_t variable
;
145 cmdline_parse_token_string_t cmd_show_verb
=
146 TOKEN_STRING_INITIALIZER(struct cmd_show_tokens
, verb
, "show");
148 cmdline_parse_token_string_t cmd_show_variable
=
149 TOKEN_STRING_INITIALIZER(struct cmd_show_tokens
,
154 cmd_show_handler(__attribute__((unused
)) void *parsed_result
,
156 __attribute__((unused
)) void *data
)
158 struct cmd_show_tokens
*tokens
= parsed_result
;
159 struct rte_ring
*ring
;
161 if (!strcmp(tokens
->variable
, "quota"))
162 cmdline_printf(cl
, "Global quota: %d\n", *quota
);
164 else if (!strcmp(tokens
->variable
, "low_watermark"))
165 cmdline_printf(cl
, "Global low_watermark: %u\n",
170 ring
= rte_ring_lookup(tokens
->variable
);
172 cmdline_printf(cl
, "Cannot find ring \"%s\"\n",
175 rte_ring_dump(stdout
, ring
);
179 cmdline_parse_inst_t cmd_show
= {
180 .f
= cmd_show_handler
,
182 .help_str
= "Show a variable value",
184 (void *) &cmd_show_verb
,
185 (void *) &cmd_show_variable
,
191 cmdline_parse_ctx_t qwctl_ctx
[] = {
192 (cmdline_parse_inst_t
*)&cmd_help
,
193 (cmdline_parse_inst_t
*)&cmd_set
,
194 (cmdline_parse_inst_t
*)&cmd_show
,