Skip to content

Commit a819ada

Browse files
committed
Some enhancement for the command mode
This commit adds option to display configuration in command mode. Currently only some of the global configuration are added. Others could be added later when needed. This commit also has a change to incease bfdump timeout to 10s. RM #4669177 RM #4670238 Signed-off-by: Liming Sun <[email protected]>
1 parent 727685b commit a819ada

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

man/rshim.8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ OPTIONS:
106106
-m, --bfdump
107107
Start debug dump which is sent to the standard output.
108108

109+
-p, --get-config <NAME | all>
110+
Get configuration value by name or use 'all' to see the list.
111+
109112
-r, --reg <addr.[32|64] [value]>
110113
Read/write registers.
111114

src/rshim.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ char *rshim_static_dev_name;
224224
/* Default configuration file. */
225225
const char *rshim_cfg_file = DEFAULT_RSHIM_CONFIG_FILE;
226226
static int rshim_display_level;
227-
static int rshim_boot_timeout = 300;
227+
int rshim_boot_timeout = 300;
228228
int rshim_drop_mode = -1;
229229
int rshim_usb_reset_delay = 1;
230230
bool rshim_has_usb_reset_delay;
@@ -3446,6 +3446,9 @@ int main(int argc, char *argv[])
34463446
}
34473447
}
34483448

3449+
/* Load configuration. */
3450+
rshim_load_cfg();
3451+
34493452
/* Handle command mode separately. */
34503453
if (rshim_cmdmode) {
34513454
return rshim_cmdmode_run(argc, argv);
@@ -3491,8 +3494,6 @@ int main(int argc, char *argv[])
34913494
}
34923495
}
34933496

3494-
rshim_load_cfg();
3495-
34963497
/* In force mode, we will send a one-time ownership request command for each
34973498
* rshim backend if they are found to be detached (aka. in drop mode) */
34983499
if (rshim_force_mode) {

src/rshim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extern int rshim_log_level;
4242
extern bool rshim_daemon_mode;
4343
extern int rshim_drop_mode;
4444
extern bool rshim_force_mode;
45+
extern int rshim_boot_timeout;
4546
extern int rshim_usb_timeout;
4647
extern int rshim_usb_reset_delay;
4748
extern bool rshim_has_usb_reset_delay;

src/rshim_cmdmode.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include "rshim.h"
1414

15+
#define RSHIM_BFDUMP_TIMEOUT 10
16+
1517
int rshim_cmd_fd = -1;
1618
rshim_backend_t *rshim_cmd_bd = NULL;
1719

@@ -191,7 +193,7 @@ static int bfdump_poll(rsh_scratchpad3_t *sp)
191193
break;
192194

193195
time(&t1);
194-
if (difftime(t1, t0) > 2)
196+
if (difftime(t1, t0) > RSHIM_BFDUMP_TIMEOUT)
195197
return -ETIMEDOUT;
196198

197199
usleep(1000);
@@ -352,6 +354,31 @@ static void set_signals(void)
352354
sigaction(SIGPIPE, &sa, NULL);
353355
}
354356

357+
static void dump_config(char *name)
358+
{
359+
if (!name) {
360+
printf("Invalid command\n");
361+
return;
362+
}
363+
364+
if (!strcmp(name, "USB_TIMEOUT")) {
365+
printf("%d\n", rshim_usb_timeout);
366+
} else if (!strcmp(name, "BOOT_TIMEOUT")) {
367+
printf("%d\n", rshim_boot_timeout);
368+
} else if (!strcmp(name, "PCIE_RESET_DELAY")) {
369+
printf("%d\n", rshim_pcie_reset_delay);
370+
} else if (!strcmp(name, "USB_RESET_DELAY")) {
371+
printf("%d\n", rshim_usb_reset_delay);
372+
} else if (!strcmp(name, "all")) {
373+
printf("BOOT_TIMEOUT %d\n", rshim_boot_timeout);
374+
printf("PCIE_RESET_DELAY %d\n", rshim_pcie_reset_delay);
375+
printf("USB_RESET_DELAY %d\n", rshim_usb_reset_delay);
376+
printf("USB_TIMEOUT %d\n", rshim_usb_timeout);
377+
} else {
378+
printf("Invalid command\n");
379+
}
380+
}
381+
355382
static void print_help(void)
356383
{
357384
printf("Usage: rshim [options]\n");
@@ -361,21 +388,23 @@ static void print_help(void)
361388
printf(" -g, --get-debug get debug code\n");
362389
printf(" -m, --bfdump debug dump\n");
363390
printf(" -r, --reg <addr.[32|64] [value]> read/write register\n");
391+
printf(" -p, --get-config <NAME | all> get config value\n");
364392
printf(" -s, --set-debug <0 | 1> set debug code\n");
365393
printf(" -h, --help show help info\n");
366394
printf(" -i, --index use device path /dev/rshim<i>/\n");
367395
}
368396

369397
int rshim_cmdmode_run(int argc, char *argv[])
370398
{
371-
static const char short_options[] = "cghimr:s:";
399+
static const char short_options[] = "cghimp:r:s:";
372400
static struct option long_options[] = {
373401
{ "get-debug", no_argument, NULL, 'g' },
374402
{ "help", no_argument, NULL, 'h' },
375403
{ "index", required_argument, NULL, 'i' },
376404
{ "bfdump", no_argument, NULL, 'm' },
377405
{ "reg", required_argument, NULL, 'r' },
378406
{ "set-debug", required_argument, NULL, 's' },
407+
{ "get-config", required_argument, NULL, 'p' },
379408
{ NULL, 0, NULL, 0 }
380409
};
381410
uint64_t addr = 0, value = 0;
@@ -416,6 +445,10 @@ int rshim_cmdmode_run(int argc, char *argv[])
416445
rc = bfdump();
417446
break;
418447

448+
case 'p':
449+
dump_config(optarg);
450+
break;
451+
419452
case 'r':
420453
/* Syntax: <addr.[32|64]> [value] */
421454
strncpy(tmp, (char *)optarg, sizeof(tmp) - 1);

0 commit comments

Comments
 (0)