ref: bb151fa7899b279acb241458e3c00af08548d1a6
parent: ec1c1b9b52632a5af59f37c1330573b78775cce1
author: Ori Bernstein <[email protected]>
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 */