1515#define VFIO_SPAPR_TCE_v2_IOMMU 7
1616#define VFIO_NOIOMMU_IOMMU 8
1717
18+ #define EEH_STATE_MIN_WAIT_TIME (1000*1000)
19+ #define EEH_STATE_MAX_WAIT_TIME (300*1000*1000)
20+
21+ #define MIN (X , Y ) (((X) < (Y)) ? (X) : (Y))
1822
1923#include <errno.h>
2024#include <libgen.h>
3741#include <asm/eeh.h>
3842
3943
44+
4045void usage (char * name )
4146{
4247 printf ("usage: %s <iommu group id> <ssss:bb:dd.f>\n" , name );
@@ -71,6 +76,9 @@ int main(int argc, char **argv)
7176 ssize_t pret ;
7277 uint32_t mask = 0b0100 ;
7378 unsigned int buf [512 ];
79+ int max_wait = EEH_STATE_MAX_WAIT_TIME ;
80+ int mwait = EEH_STATE_MIN_WAIT_TIME ;
81+
7482
7583 struct vfio_group_status group_status = {
7684 .argsz = sizeof (group_status )
@@ -291,12 +299,14 @@ int main(int argc, char **argv)
291299 pe_op .err .addr = 0ul ;
292300 pe_op .err .mask = 0ul ;
293301
302+ /*
294303 pret = ioctl(container, VFIO_EEH_PE_OP, &pe_op);
295304 if(pret < 0) {
296305 perror("");
297306 printf("VFIO_EEH_PE_INJECT_ERR failed , buf out : %s \n", path);
298307 return pret;
299308 }
309+ */
300310
301311 printf ("inject error \n" );
302312 fgetc (stdin );
@@ -357,17 +367,25 @@ int main(int argc, char **argv)
357367 ioctl (container , VFIO_EEH_PE_OP , & pe_op );
358368 printf ("slot VFIO_EEH_PE_RESET_HOT initiated\n" );
359369 pe_op .op = VFIO_EEH_PE_GET_STATE ;
360- i = 5 ;
361- while (i -- )
370+
371+
372+ while (1 )
362373 {
363374 ret = ioctl (container , VFIO_EEH_PE_OP , & pe_op );
364- if ( ret < 0 ) {
365- perror ("" );
366- }
367- printf ("\t." );
368- sleep (5 );
375+ if (ret != EEH_PE_STATE_UNAVAIL )
376+ {
377+ if (ret == EEH_PE_STATE_RESET )
378+ {
379+ /* if the slot in reset active state wait for minimum delay */
380+ usleep (mwait );
381+ }
382+ break ;
383+ }
384+ if (max_wait < 0 )
385+ break ;
386+ usleep (MIN (mwait , max_wait ));
387+ max_wait -= mwait ;
369388 }
370-
371389 printf ("\nVFIO_EEH_PE_GET_STATE %d\n" ,ret );
372390
373391 pe_op .op = VFIO_EEH_PE_RESET_DEACTIVATE ;
@@ -377,7 +395,7 @@ int main(int argc, char **argv)
377395 pe_op .op = VFIO_EEH_PE_CONFIGURE ;
378396 ret = ioctl (container , VFIO_EEH_PE_OP , & pe_op );
379397 if (!ret ) {
380- printf ("Success\n" );
398+ printf ("PE configure Success\n" );
381399 } else {
382400 printf ("VFIO_EEH_PE_CONFIGURE failed \n" );
383401 }
@@ -410,6 +428,6 @@ int main(int argc, char **argv)
410428 printf ("Press any key to exit\n" );
411429 fgetc (stdin );
412430
413- ioctl (device , VFIO_DEVICE_RESET );
431+ // ioctl(device, VFIO_DEVICE_RESET);
414432 return 0 ;
415433}
0 commit comments