Skip to content

Commit

Permalink
condinitional delay after VFIO_EEH_PE_RESET_HOT
Browse files Browse the repository at this point in the history
  • Loading branch information
NarayanamurtyN committed Nov 25, 2024
1 parent 724eb0f commit e56a90f
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions vfio-spapr-eeh-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#define VFIO_SPAPR_TCE_v2_IOMMU 7
#define VFIO_NOIOMMU_IOMMU 8

#define EEH_STATE_MIN_WAIT_TIME (1000*1000)
#define EEH_STATE_MAX_WAIT_TIME (300*1000*1000)

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))

#include <errno.h>
#include <libgen.h>
Expand All @@ -37,6 +41,7 @@
#include <asm/eeh.h>



void usage(char *name)
{
printf("usage: %s <iommu group id> <ssss:bb:dd.f>\n", name);
Expand Down Expand Up @@ -71,6 +76,9 @@ int main(int argc, char **argv)
ssize_t pret;
uint32_t mask= 0b0100;
unsigned int buf[512];
int max_wait = EEH_STATE_MAX_WAIT_TIME;
int mwait = EEH_STATE_MIN_WAIT_TIME;


struct vfio_group_status group_status = {
.argsz = sizeof(group_status)
Expand Down Expand Up @@ -291,15 +299,15 @@ int main(int argc, char **argv)
pe_op.err.addr = 0ul;
pe_op.err.mask = 0ul;


pret = ioctl(container, VFIO_EEH_PE_OP, &pe_op);
if(pret < 0) {
perror("");
printf("VFIO_EEH_PE_INJECT_ERR failed , buf out : %s \n", path);
return pret;
}

printf("inject error \n");
fgetc(stdin);


pe_op.op = VFIO_EEH_PE_GET_STATE;
ret = ioctl(container, VFIO_EEH_PE_OP, &pe_op);
Expand Down Expand Up @@ -357,17 +365,25 @@ int main(int argc, char **argv)
ioctl(container, VFIO_EEH_PE_OP, &pe_op);
printf("slot VFIO_EEH_PE_RESET_HOT initiated\n");
pe_op.op = VFIO_EEH_PE_GET_STATE;
i = 5 ;
while (i--)


while (1)
{
ret = ioctl(container, VFIO_EEH_PE_OP, &pe_op);
if( ret < 0) {
perror("");
}
printf("\t.");
sleep(5);
if (ret != EEH_PE_STATE_UNAVAIL)
{
if(ret == EEH_PE_STATE_RESET)
{
/* if the slot in reset active state wait for minimum delay */
usleep(mwait);
}
break;
}
if(max_wait < 0)
break;
usleep(MIN(mwait, max_wait));
max_wait -= mwait;
}

printf("\nVFIO_EEH_PE_GET_STATE %d\n",ret);

pe_op.op = VFIO_EEH_PE_RESET_DEACTIVATE;
Expand All @@ -377,7 +393,7 @@ int main(int argc, char **argv)
pe_op.op = VFIO_EEH_PE_CONFIGURE;
ret = ioctl(container, VFIO_EEH_PE_OP, &pe_op);
if(!ret) {
printf("Success\n");
printf("PE configure Success\n");
} else {
printf("VFIO_EEH_PE_CONFIGURE failed \n");
}
Expand Down Expand Up @@ -410,6 +426,6 @@ int main(int argc, char **argv)
printf("Press any key to exit\n");
fgetc(stdin);

ioctl(device, VFIO_DEVICE_RESET);
// ioctl(device, VFIO_DEVICE_RESET);
return 0;
}

0 comments on commit e56a90f

Please sign in to comment.