Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff54900c authored by Ram Prakash Gupta's avatar Ram Prakash Gupta Committed by Gerrit - the friendly Code Review server
Browse files

mmc: sdhci: Fix the timeout check window for clock and reset



We observed some premature timeouts on a virtualization platform,
the log is like this:

case 1:
[159525.255629] mmc1: Internal clock never stabilised.
[159525.255818] mmc1: sdhci: ============ SDHCI REGISTER DUMP ===========
[159525.256049] mmc1: sdhci: Sys addr:  0x00000000 | Version:  0x00001002
...
[159525.257205] mmc1: sdhci: Wake-up:   0x00000000 | Clock:    0x0000fa03
From the clock control register dump, we are pretty sure the clock was
stablized.

case 2:
[  914.550127] mmc1: Reset 0x2 never completed.
[  914.550321] mmc1: sdhci: ============ SDHCI REGISTER DUMP ===========
[  914.550608] mmc1: sdhci: Sys addr:  0x00000010 | Version:  0x00001002

After checking the sdhci code, we found the timeout check actually
has a little window that the CPU can be scheduled out and when it
comes back, the original time set or check is not valid.

Change-Id: I291379e640d2896cfdebbe73133329a64c57d8c7
Fixes: 5a436cc0 ("mmc: sdhci: Optimize delay loops")
Cc: stable@vger.kernel.org      # v4.12+
Signed-off-by: default avatarAlek Du <alek.du@intel.com>
Acked-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Git-commit: b704441e38f645dcfba1348ca3cc1ba43d1a9f31
Git-repo: https://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git


Signed-off-by: default avatarRam Prakash Gupta <rampraka@codeaurora.org>
parent b5131de4
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -248,8 +248,12 @@ void sdhci_reset(struct sdhci_host *host, u8 mask)
			SDHCI_INT_STATUS);

	/* hw clears the bit when it's done */
	while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) {
		if (ktime_after(ktime_get(), timeout)) {
	while (1) {
		bool timedout = ktime_after(ktime_get(), timeout);

		if (!(sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask))
			break;
		if (timedout) {
			pr_err("%s: Reset 0x%x never completed.\n",
				mmc_hostname(host->mmc), (int)mask);
			MMC_TRACE(host->mmc, "%s: Reset 0x%x never completed\n",
@@ -1576,9 +1580,13 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk)

	/* Wait max 20 ms */
	timeout = ktime_add_ms(ktime_get(), 20);
	while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
		& SDHCI_CLOCK_INT_STABLE)) {
		if (ktime_after(ktime_get(), timeout)) {
	while (1) {
		bool timedout = ktime_after(ktime_get(), timeout);

		clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
		if (clk & SDHCI_CLOCK_INT_STABLE)
			break;
		if (timedout) {
			pr_err("%s: Internal clock never stabilised.\n",
			       mmc_hostname(host->mmc));
			MMC_TRACE(host->mmc,