OSDN Git Service

tools/power/x86/intel-speed-select: Add retries for mail box commands
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Wed, 1 Jul 2020 21:37:48 +0000 (14:37 -0700)
committerSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Thu, 16 Jul 2020 17:17:55 +0000 (10:17 -0700)
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>
tools/power/x86/intel-speed-select/isst-config.c

index c7b2e6a..0e94aa7 100644 (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,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;