@@ -45,6 +45,7 @@ static int auto_mode;
45
45
static int fact_enable_fail ;
46
46
47
47
static int mbox_delay ;
48
+ static int mbox_retries = 3 ;
48
49
49
50
/* clos related */
50
51
static int current_clos = -1 ;
@@ -738,7 +739,7 @@ int isst_send_mbox_command(unsigned int cpu, unsigned char command,
738
739
unsigned int req_data , unsigned int * resp )
739
740
{
740
741
const char * pathname = "/dev/isst_interface" ;
741
- int fd ;
742
+ int fd , retry ;
742
743
struct isst_if_mbox_cmds mbox_cmds = { 0 };
743
744
744
745
debug_printf (
@@ -797,25 +798,35 @@ int isst_send_mbox_command(unsigned int cpu, unsigned char command,
797
798
if (fd < 0 )
798
799
err (-1 , "%s open failed" , pathname );
799
800
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 ;
805
820
}
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 );
816
822
817
823
close (fd );
818
824
825
+ if (!retry ) {
826
+ debug_printf ("Failed mbox command even after retries\n" );
827
+ return -1 ;
828
+
829
+ }
819
830
return 0 ;
820
831
}
821
832
@@ -2605,6 +2616,7 @@ static void usage(void)
2605
2616
printf ("\t[-o|--out] : Output file\n" );
2606
2617
printf ("\t\t\tDefault : stderr\n" );
2607
2618
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" );
2608
2620
printf ("\t[-v|--version] : Print version\n" );
2609
2621
2610
2622
printf ("\nResult format\n" );
@@ -2650,6 +2662,7 @@ static void cmdline(int argc, char **argv)
2650
2662
{ "info" , no_argument , 0 , 'i' },
2651
2663
{ "pause" , required_argument , 0 , 'p' },
2652
2664
{ "out" , required_argument , 0 , 'o' },
2665
+ { "retry" , required_argument , 0 , 'r' },
2653
2666
{ "version" , no_argument , 0 , 'v' },
2654
2667
{ 0 , 0 , 0 , 0 }
2655
2668
};
@@ -2709,6 +2722,13 @@ static void cmdline(int argc, char **argv)
2709
2722
else
2710
2723
mbox_delay = ret ;
2711
2724
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 ;
2712
2732
case 'v' :
2713
2733
print_version ();
2714
2734
break ;
0 commit comments