From bb151fa7899b279acb241458e3c00af08548d1a6 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Sun, 23 Dec 2018 19:44:58 -0800 Subject: 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. --- sys/src/cmd/nusb/disk/disk.c | 18 +++++++++++++----- 1 file 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 */ -- cgit v1.2.3