Don't unnecessarily unstall devices.

Some SD card readers are slow to unstall. We try to unstall them
in a loop if there's no SD card in there, but they're not stalled.
They're happily reporting that there's no SD card in them by giving
back the appropriate error code.

Skipping the unstall speeds up the retry loop, cutting the time spent
attaching the USB device at boot from multiple minutes to nearly instant.
This commit is contained in:
Ori Bernstein 2018-12-23 19:44:58 -08:00
parent ec1c1b9b52
commit bb151fa789

View file

@ -361,6 +361,15 @@ umsinit(void)
return 0;
}
static int
needunstall(void)
{
char buf[ERRMAX];
rerrstr(buf, sizeof(buf));
return strstr(buf, "medium not present") == nil;
}
/*
* called by SR*() commands provided by scuzz's scsireq
@ -412,15 +421,14 @@ umsrequest(Umsc *umsc, ScsiPtr *cmd, ScsiPtr *data, int *status)
if (n >= 0 && n < nio) /* didn't fill data->p? */
memset(data->p + n, 0, nio - n);
}
nio = n;
if(diskdebug)
if(n < 0)
fprint(2, "disk: data: %r\n");
else
fprint(2, "disk: data: %d bytes\n", n);
if(n <= 0)
if(data->write == 0)
unstall(dev, ums->epin, Ein);
fprint(2, "disk: data: %d bytes (nio: %d)\n", n, nio);
nio = n;
if((n < 0 && needunstall() || (n <= 9 || data->write == 0))
unstall(dev, ums->epin, Ein);
}
/* read the transfer's status */