Skip to content

Commit 32279be

Browse files
committed
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 <[email protected]>
1 parent a85a35f commit 32279be

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

tools/power/x86/intel-speed-select/isst-config.c

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static int auto_mode;
4545
static int fact_enable_fail;
4646

4747
static int mbox_delay;
48+
static int mbox_retries = 3;
4849

4950
/* clos related */
5051
static int current_clos = -1;
@@ -738,7 +739,7 @@ int isst_send_mbox_command(unsigned int cpu, unsigned char command,
738739
unsigned int req_data, unsigned int *resp)
739740
{
740741
const char *pathname = "/dev/isst_interface";
741-
int fd;
742+
int fd, retry;
742743
struct isst_if_mbox_cmds mbox_cmds = { 0 };
743744

744745
debug_printf(
@@ -797,25 +798,35 @@ int isst_send_mbox_command(unsigned int cpu, unsigned char command,
797798
if (fd < 0)
798799
err(-1, "%s open failed", pathname);
799800

800-
if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) {
801-
if (errno == ENOTTY) {
802-
perror("ISST_IF_MBOX_COMMAND\n");
803-
fprintf(stderr, "Check presence of kernel modules: isst_if_mbox_pci or isst_if_mbox_msr\n");
804-
exit(0);
801+
retry = mbox_retries;
802+
803+
do {
804+
if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) {
805+
if (errno == ENOTTY) {
806+
perror("ISST_IF_MBOX_COMMAND\n");
807+
fprintf(stderr, "Check presence of kernel modules: isst_if_mbox_pci or isst_if_mbox_msr\n");
808+
exit(0);
809+
}
810+
debug_printf(
811+
"Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x errorno:%d\n",
812+
cpu, command, sub_command, parameter, req_data, errno);
813+
--retry;
814+
} else {
815+
*resp = mbox_cmds.mbox_cmd[0].resp_data;
816+
debug_printf(
817+
"mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n",
818+
cpu, command, sub_command, parameter, req_data, *resp);
819+
break;
805820
}
806-
debug_printf(
807-
"Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x errorno:%d\n",
808-
cpu, command, sub_command, parameter, req_data, errno);
809-
return -1;
810-
} else {
811-
*resp = mbox_cmds.mbox_cmd[0].resp_data;
812-
debug_printf(
813-
"mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n",
814-
cpu, command, sub_command, parameter, req_data, *resp);
815-
}
821+
} while (retry);
816822

817823
close(fd);
818824

825+
if (!retry) {
826+
debug_printf("Failed mbox command even after retries\n");
827+
return -1;
828+
829+
}
819830
return 0;
820831
}
821832

@@ -2605,6 +2616,7 @@ static void usage(void)
26052616
printf("\t[-o|--out] : Output file\n");
26062617
printf("\t\t\tDefault : stderr\n");
26072618
printf("\t[-p|--pause] : Delay between two mail box commands in milliseconds\n");
2619+
printf("\t[-r|--retry] : Retry count for mail box commands on failure, default 3\n");
26082620
printf("\t[-v|--version] : Print version\n");
26092621

26102622
printf("\nResult format\n");
@@ -2650,6 +2662,7 @@ static void cmdline(int argc, char **argv)
26502662
{ "info", no_argument, 0, 'i' },
26512663
{ "pause", required_argument, 0, 'p' },
26522664
{ "out", required_argument, 0, 'o' },
2665+
{ "retry", required_argument, 0, 'r' },
26532666
{ "version", no_argument, 0, 'v' },
26542667
{ 0, 0, 0, 0 }
26552668
};
@@ -2709,6 +2722,13 @@ static void cmdline(int argc, char **argv)
27092722
else
27102723
mbox_delay = ret;
27112724
break;
2725+
case 'r':
2726+
ret = strtol(optarg, &ptr, 10);
2727+
if (!ret)
2728+
fprintf(stderr, "Invalid retry count, ignore\n");
2729+
else
2730+
mbox_retries = ret;
2731+
break;
27122732
case 'v':
27132733
print_version();
27142734
break;

0 commit comments

Comments
 (0)