ref: aa067dc83aad8a1adf02ddc1cdff831bafb9ca67
parent: 71d20e3bd1824004c443543f7e9794cf72b2ac3a
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Dec 23 14:44:58 EST 2018
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.
--- a/sys/src/cmd/nusb/disk/disk.c
+++ b/sys/src/cmd/nusb/disk/disk.c
@@ -361,7 +361,16 @@
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 @@
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 */
--
⑨