On Fri, Jan 10, 2020 at 05:55:14PM -0600, Scott Cheloha wrote:
> Here the timeout constants are all in terms of seconds. We can change
> the input unit of the wait functions from hz to seconds and then
> convert as needed.
>
> sdhc_wait_intr_cold() uses delay(9), so convert to microseconds.
>
> sdhc_wait_intr() (now) uses tsleep_nsec(9), so convert to nanoseconds.
>
> I've sprinkled in some name changes and intermediate variables to make
> the units in use more obvious.
>
> ok?
Bump.
Index: sdmmc/sdhc.c
===================================================================
RCS file: /cvs/src/sys/dev/sdmmc/sdhc.c,v
retrieving revision 1.63
diff -u -p -r1.63 sdhc.c
--- sdmmc/sdhc.c 22 Jan 2020 07:52:37 -0000 1.63
+++ sdmmc/sdhc.c 7 Feb 2020 14:00:23 -0000
@@ -35,10 +35,11 @@
#include <dev/sdmmc/sdmmcvar.h>
#include <dev/sdmmc/sdmmc_ioreg.h>
-#define SDHC_COMMAND_TIMEOUT hz
-#define SDHC_BUFFER_TIMEOUT hz
-#define SDHC_TRANSFER_TIMEOUT hz
-#define SDHC_DMA_TIMEOUT (hz*3)
+/* Timeouts in seconds */
+#define SDHC_COMMAND_TIMEOUT 1
+#define SDHC_BUFFER_TIMEOUT 1
+#define SDHC_TRANSFER_TIMEOUT 1
+#define SDHC_DMA_TIMEOUT 3
struct sdhc_host {
struct sdhc_softc *sc; /* host controller device */
@@ -1103,12 +1104,12 @@ sdhc_soft_reset(struct sdhc_host *hp, in
}
int
-sdhc_wait_intr_cold(struct sdhc_host *hp, int mask, int timo)
+sdhc_wait_intr_cold(struct sdhc_host *hp, int mask, int secs)
{
- int status;
+ int status, usecs;
mask |= SDHC_ERROR_INTERRUPT;
- timo = timo * tick;
+ usecs = secs * 1000000;
status = hp->intr_status;
while ((status & mask) == 0) {
@@ -1142,7 +1143,7 @@ sdhc_wait_intr_cold(struct sdhc_host *hp
}
delay(1);
- if (timo-- == 0) {
+ if (usecs-- == 0) {
status |= SDHC_ERROR_INTERRUPT;
break;
}
@@ -1153,20 +1154,22 @@ sdhc_wait_intr_cold(struct sdhc_host *hp
}
int
-sdhc_wait_intr(struct sdhc_host *hp, int mask, int timo)
+sdhc_wait_intr(struct sdhc_host *hp, int mask, int secs)
{
+ uint64_t nsecs;
int status;
int s;
if (cold)
- return (sdhc_wait_intr_cold(hp, mask, timo));
+ return (sdhc_wait_intr_cold(hp, mask, secs));
mask |= SDHC_ERROR_INTERRUPT;
+ nsecs = SEC_TO_NSEC(secs);
s = splsdmmc();
status = hp->intr_status & mask;
while (status == 0) {
- if (tsleep(&hp->intr_status, PWAIT, "hcintr", timo)
+ if (tsleep_nsec(&hp->intr_status, PWAIT, "hcintr", nsecs)
== EWOULDBLOCK) {
status |= SDHC_ERROR_INTERRUPT;
break;