diff options
author | Ori Bernstein <ori@eigenstate.org> | 2018-12-23 19:44:58 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2018-12-23 19:44:58 -0800 |
commit | bb151fa7899b279acb241458e3c00af08548d1a6 (patch) | |
tree | 083603f2035538fad33db98c73144875b0cb8023 /sys/src/cmd/nusb | |
parent | ec1c1b9b52632a5af59f37c1330573b78775cce1 (diff) |
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.
Diffstat (limited to 'sys/src/cmd/nusb')
-rw-r--r-- | sys/src/cmd/nusb/disk/disk.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/sys/src/cmd/nusb/disk/disk.c b/sys/src/cmd/nusb/disk/disk.c index fd6c9dc2e..f1756ce66 100644 --- a/sys/src/cmd/nusb/disk/disk.c +++ b/sys/src/cmd/nusb/disk/disk.c @@ -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 */ |