Module Name: src Committed By: jmcneill Date: Sun Feb 16 11:15:18 UTC 2025
Modified Files: src/sys/dev/sdmmc: sdhc.c Log Message: sdhc: Remove delay in sdhc_wait_state Replace the 10us delay loop in sdhc_wait_state with a microuptime based timeout test. To generate a diff of this commit: cvs rdiff -u -r1.120 -r1.121 src/sys/dev/sdmmc/sdhc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/sdmmc/sdhc.c diff -u src/sys/dev/sdmmc/sdhc.c:1.120 src/sys/dev/sdmmc/sdhc.c:1.121 --- src/sys/dev/sdmmc/sdhc.c:1.120 Sun Feb 16 11:03:30 2025 +++ src/sys/dev/sdmmc/sdhc.c Sun Feb 16 11:15:18 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: sdhc.c,v 1.120 2025/02/16 11:03:30 jmcneill Exp $ */ +/* $NetBSD: sdhc.c,v 1.121 2025/02/16 11:15:18 jmcneill Exp $ */ /* $OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $ */ /* @@ -23,7 +23,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.120 2025/02/16 11:03:30 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.121 2025/02/16 11:15:18 jmcneill Exp $"); #ifdef _KERNEL_OPT #include "opt_sdmmc.h" @@ -1563,17 +1563,25 @@ sdhc_hw_reset(sdmmc_chipset_handle_t sch static int sdhc_wait_state(struct sdhc_host *hp, uint32_t mask, uint32_t value) { + struct timeval start, diff; uint32_t state; - int timeout; - for (timeout = 100000; timeout > 0; timeout--) { - if (((state = HREAD4(hp, SDHC_PRESENT_STATE)) & mask) == value) + microuptime(&start); + for (;;) { + state = HREAD4(hp, SDHC_PRESENT_STATE); + if ((state & mask) == value) { return 0; - sdmmc_delay(10); + } + microuptime(&diff); + timersub(&diff, &start, &diff); + if (diff.tv_sec != 0) { + aprint_error_dev(hp->sc->sc_dev, + "timeout waiting for mask %#x value %#x " + "(state=%#x)\n", + mask, value, state); + return ETIMEDOUT; + } } - aprint_error_dev(hp->sc->sc_dev, "timeout waiting for mask %#x value %#x (state=%#x)\n", - mask, value, state); - return ETIMEDOUT; } static void