Skip to content

Commit 3ab8511

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 <limings@nvidia.com>
1 parent 727685b commit 3ab8511

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-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: 33 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,29 @@ 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+
}
378+
}
379+
355380
static void print_help(void)
356381
{
357382
printf("Usage: rshim [options]\n");
@@ -361,21 +386,23 @@ static void print_help(void)
361386
printf(" -g, --get-debug get debug code\n");
362387
printf(" -m, --bfdump debug dump\n");
363388
printf(" -r, --reg <addr.[32|64] [value]> read/write register\n");
389+
printf(" -p, --get-config <NAME | all> get config value\n");
364390
printf(" -s, --set-debug <0 | 1> set debug code\n");
365391
printf(" -h, --help show help info\n");
366392
printf(" -i, --index use device path /dev/rshim<i>/\n");
367393
}
368394

369395
int rshim_cmdmode_run(int argc, char *argv[])
370396
{
371-
static const char short_options[] = "cghimr:s:";
397+
static const char short_options[] = "cghimp:r:s:";
372398
static struct option long_options[] = {
373399
{ "get-debug", no_argument, NULL, 'g' },
374400
{ "help", no_argument, NULL, 'h' },
375401
{ "index", required_argument, NULL, 'i' },
376402
{ "bfdump", no_argument, NULL, 'm' },
377403
{ "reg", required_argument, NULL, 'r' },
378404
{ "set-debug", required_argument, NULL, 's' },
405+
{ "get-config", required_argument, NULL, 'p' },
379406
{ NULL, 0, NULL, 0 }
380407
};
381408
uint64_t addr = 0, value = 0;
@@ -416,6 +443,10 @@ int rshim_cmdmode_run(int argc, char *argv[])
416443
rc = bfdump();
417444
break;
418445

446+
case 'p':
447+
dump_config(optarg);
448+
break;
449+
419450
case 'r':
420451
/* Syntax: <addr.[32|64]> [value] */
421452
strncpy(tmp, (char *)optarg, sizeof(tmp) - 1);

0 commit comments

Comments
 (0)