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>
This commit is contained in:
Srinivas Pandruvada 2020-07-01 14:37:48 -07:00
parent a85a35fc1d
commit 32279be7e1

View File

@ -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,6 +798,9 @@ int isst_send_mbox_command(unsigned int cpu, unsigned char command,
if (fd < 0)
err(-1, "%s open failed", pathname);
retry = mbox_retries;
do {
if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) {
if (errno == ENOTTY) {
perror("ISST_IF_MBOX_COMMAND\n");
@ -806,16 +810,23 @@ int isst_send_mbox_command(unsigned int cpu, unsigned char command,
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;
--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;
}
} 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;