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?

Index: sdmmc/sdhc.c
===================================================================
RCS file: /cvs/src/sys/dev/sdmmc/sdhc.c,v
retrieving revision 1.62
diff -u -p -r1.62 sdhc.c
--- sdmmc/sdhc.c        2 Apr 2019 07:08:40 -0000       1.62
+++ sdmmc/sdhc.c        10 Jan 2020 23:49:07 -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;

Reply via email to