Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7654614imu; Mon, 3 Dec 2018 17:02:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/VLNu5knTKgE3KP41qmEOxeUjEDcPRle8OqWo0usbk/b142icWMTpdz5KhDItUXKU9TxOFR X-Received: by 2002:a62:5b83:: with SMTP id p125mr9850580pfb.116.1543885343756; Mon, 03 Dec 2018 17:02:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543885343; cv=none; d=google.com; s=arc-20160816; b=uxKakuGXPpgFZb7Ev5fnToc3xKA4CP2AQ2Tbe9K+kUKpP9Cc47h3M/livIaZ2UIAxM qjimkJr/t9d+a6qdoK+6t7N2NicHJ5ZLc5JepOs5CcTq0X9kpHLN8zLs9zvHSL3r89Lz Te208HAt50nsBQe85ra/CHMKTJ2hUC+4qg06I6u2F+blcynSH8LFDv1DmlB56yYbLgxn veYHyAqKeFjOfLBw7wzaYRcI37NeBGIATm0TaQeOk7nQYXus6JGBJ3W0EGbI53dkkQgn DPW+eQ+5x1DYQ61EA/0DOpdO5GpoNy0+zzr00NJfjM1W5yIICzgtDu28uXjmYlpmV/Da Iq2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=Hi8j6YzrYJoN1pwP/7XHs8t2Cji/wnKmFlHcVfnLdkg=; b=lyr1LsF7ZF2tyw8cbmuIT6D+m99THn48NBeD4n1rAuqGzGfqpjdLq3V6fju3W1dJV3 xAAhCy6rM79rchyY3JbNoYEyBUicvtxfNa24pavKJPxq2mrjzAIbpca0ec9HNEb2seNQ MhxhpSP9GyWNr4j4oyCzAo5BB25K0teqUIv4s1AOrj2bdJHyPnS85AJrN0ka+guWg9uY uxf+Hu6b6yS3b38ScAi3xP3XnvSgEEgAooGommFUcdmuGqLJ4Sg787s97grH8oWNh3T/ h/zb6MH6Z1A6/jPy3uYtMiJrXDcZERNSd9jmLMLEZAGwNHq7ZnPLlYQvHlKwYf1kNDxM +H0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5si15683703pfb.188.2018.12.03.17.02.05; Mon, 03 Dec 2018 17:02:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726018AbeLDBB1 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 3 Dec 2018 20:01:27 -0500 Received: from mga12.intel.com ([192.55.52.136]:51647 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725971AbeLDBB1 (ORCPT ); Mon, 3 Dec 2018 20:01:27 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Dec 2018 17:01:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,312,1539673200"; d="scan'208,223";a="299028526" Received: from xdu1-mobl.sh.intel.com (HELO xdu1-mobl) ([10.239.204.5]) by fmsmga006.fm.intel.com with ESMTP; 03 Dec 2018 17:01:24 -0800 Date: Tue, 4 Dec 2018 09:01:20 +0800 From: "Du, Alek" To: Adrian Hunter Cc: , , Subject: [PATCH V2] sdhci: fix the timeout check window for clock and reset Message-ID: <20181204090120.63b5f0a4@xdu1-mobl> In-Reply-To: <20181201134251.26573207@xdu1-mobl> References: <20181130150028.732896d8@xdu1-mobl> <81ba3745-8277-d16e-3aad-48324f51dc8a@intel.com> <20181130221300.4ef2956c@xdu1-mobl> <20181201134251.26573207@xdu1-mobl> Organization: Intel APAC R&D X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From 87692fc090978bde8fe872f02d0023a57af6b492 Mon Sep 17 00:00:00 2001 From: Alek Du Date: Fri, 30 Nov 2018 14:02:28 +0800 Subject: [PATCH] sdhci: fix the timeout check window for clock and reset We observed some fake timeouts on some devices, 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.256277] mmc1: sdhci: Blk size: 0x00000000 | Blk cnt: 0x00000000 [159525.256523] mmc1: sdhci: Argument: 0x00000000 | Trn mode: 0x00000000 [159525.256752] mmc1: sdhci: Present: 0x1fff0000 | Host ctl: 0x00000000 [159525.256979] mmc1: sdhci: Power: 0x0000000b | Blk gap: 0x00000080 [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. Signed-off-by: Alek Du --- drivers/mmc/host/sdhci.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 99bdae53fa2e..af01f7d16eae 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -218,12 +218,17 @@ void sdhci_reset(struct sdhci_host *host, u8 mask) /* hw clears the bit when it's done */ while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) { if (ktime_after(ktime_get(), timeout)) { + /* check it again, since there is a window between + bit check and time check */ + if (!(sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask)) + break; pr_err("%s: Reset 0x%x never completed.\n", mmc_hostname(host->mmc), (int)mask); sdhci_dumpregs(host); return; + } else { + udelay(10); } - udelay(10); } } EXPORT_SYMBOL_GPL(sdhci_reset); @@ -1611,12 +1616,19 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk) while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL)) & SDHCI_CLOCK_INT_STABLE)) { if (ktime_after(ktime_get(), timeout)) { + /* check it again since there is a window between + status check and time check */ + if ((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL)) + & SDHCI_CLOCK_INT_STABLE) + break; pr_err("%s: Internal clock never stabilised.\n", mmc_hostname(host->mmc)); sdhci_dumpregs(host); return; } - udelay(10); + else { + udelay(10); + } } clk |= SDHCI_CLOCK_CARD_EN; -- 2.17.1