diff options
author | Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> | 2020-07-01 14:37:48 -0700 |
---|---|---|
committer | Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> | 2020-07-16 10:17:55 -0700 |
commit | 32279be7e159df5de68f2c37e4ca96e7e4358c4d (patch) | |
tree | 950059c7aff265e716a205fa608a8d21998b8588 /tools/power | |
parent | a85a35fc1d9be7984f052926e42291219ee5ef85 (diff) |
tools/power/x86/intel-speed-select: Add retries for mail box commands
Retry mail box command on failure. The default retry count is 3. This can
be changed by "-r|--retry" options. This helps during early bring up of
platforms.
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r-- | tools/power/x86/intel-speed-select/isst-config.c | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/tools/power/x86/intel-speed-select/isst-config.c b/tools/power/x86/intel-speed-select/isst-config.c index c7b2e6afc7e8..0e94aa787c59 100644 --- a/tools/power/x86/intel-speed-select/isst-config.c +++ b/tools/power/x86/intel-speed-select/isst-config.c @@ -45,6 +45,7 @@ static int auto_mode; static int fact_enable_fail; static int mbox_delay; +static int mbox_retries = 3; /* clos related */ static int current_clos = -1; @@ -738,7 +739,7 @@ int isst_send_mbox_command(unsigned int cpu, unsigned char command, unsigned int req_data, unsigned int *resp) { const char *pathname = "/dev/isst_interface"; - int fd; + int fd, retry; struct isst_if_mbox_cmds mbox_cmds = { 0 }; debug_printf( @@ -797,25 +798,35 @@ int isst_send_mbox_command(unsigned int cpu, unsigned char command, if (fd < 0) err(-1, "%s open failed", pathname); - if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) { - if (errno == ENOTTY) { - perror("ISST_IF_MBOX_COMMAND\n"); - fprintf(stderr, "Check presence of kernel modules: isst_if_mbox_pci or isst_if_mbox_msr\n"); - exit(0); + retry = mbox_retries; + + do { + if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) { + if (errno == ENOTTY) { + perror("ISST_IF_MBOX_COMMAND\n"); + fprintf(stderr, "Check presence of kernel modules: isst_if_mbox_pci or isst_if_mbox_msr\n"); + exit(0); + } + debug_printf( + "Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x errorno:%d\n", + cpu, command, sub_command, parameter, req_data, errno); + --retry; + } else { + *resp = mbox_cmds.mbox_cmd[0].resp_data; + debug_printf( + "mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n", + cpu, command, sub_command, parameter, req_data, *resp); + break; } - debug_printf( - "Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x errorno:%d\n", - cpu, command, sub_command, parameter, req_data, errno); - return -1; - } else { - *resp = mbox_cmds.mbox_cmd[0].resp_data; - debug_printf( - "mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n", - cpu, command, sub_command, parameter, req_data, *resp); - } + } while (retry); close(fd); + if (!retry) { + debug_printf("Failed mbox command even after retries\n"); + return -1; + + } return 0; } @@ -2605,6 +2616,7 @@ static void usage(void) printf("\t[-o|--out] : Output file\n"); printf("\t\t\tDefault : stderr\n"); printf("\t[-p|--pause] : Delay between two mail box commands in milliseconds\n"); + printf("\t[-r|--retry] : Retry count for mail box commands on failure, default 3\n"); printf("\t[-v|--version] : Print version\n"); printf("\nResult format\n"); @@ -2650,6 +2662,7 @@ static void cmdline(int argc, char **argv) { "info", no_argument, 0, 'i' }, { "pause", required_argument, 0, 'p' }, { "out", required_argument, 0, 'o' }, + { "retry", required_argument, 0, 'r' }, { "version", no_argument, 0, 'v' }, { 0, 0, 0, 0 } }; @@ -2709,6 +2722,13 @@ static void cmdline(int argc, char **argv) else mbox_delay = ret; break; + case 'r': + ret = strtol(optarg, &ptr, 10); + if (!ret) + fprintf(stderr, "Invalid retry count, ignore\n"); + else + mbox_retries = ret; + break; case 'v': print_version(); break; |