Received: by 10.223.176.5 with SMTP id f5csp741192wra; Fri, 2 Feb 2018 05:27:00 -0800 (PST) X-Google-Smtp-Source: AH8x225w9yE1z8cbJuiPdmQck9BqHCQrlCjFav0GLxIfE4oy29xIbJbLOV7pm0Z+LLW5nECquKUf X-Received: by 10.99.114.24 with SMTP id n24mr4824785pgc.376.1517578020411; Fri, 02 Feb 2018 05:27:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517578020; cv=none; d=google.com; s=arc-20160816; b=zEcwII9tIFf2g6ZK2lkjcFhqzBqfeYNJRG0gLHw1WonaWP5LmcVSLAP86hYdsyjwZq ItkpHTUxOJpKVz1HdAqdQ5xqs8tXy7ITBOSXOCIwQ1VM1uWl7XtG+QASImAaHMguXOSM UFf0+F6g1Sv2AGGY9EKBxKO6CZRy0F/tW56GQrtSo8JX026HkkYK86yIlTtu1Svuk/cN BkuIT6lGi9LJc8+5okNm9L7ZsUSmnd6EfCUS5xsNN6ArbRCza48EVilJcMO2LegZa3mM gXvXIXgAwASJiLpYLemW5gYU+zcZ/aGz7XLlP5KTU0ZaOTG3bHzSs05sp7WKdAJQqz0G cy4Q== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:dkim-signature:arc-authentication-results; bh=9gbJOMrEfFkRkKm7fgBBs27hjTH69L39mHVUo3WrOkU=; b=OtCKgOoI/sPOgI8vOXfXSe9tjozVF03DR67R0LdOA/KF8JGn2lWq9dhXeI7jsoLyNp RIDIpaCw10527krXO8SaFb9KET5bA3y4ehv9D8hDx7no8hzpIbeCUusfk1OzcfqQnbg0 gu/3HMTzAroVUPbog1iQ/SmZXGZPLeY6gqx5GH7ETcASnbHrYZM1N7UYlx5IEen2AsBS dqwczN5t3AXRDsBngmw5ntFPjiSNBKqu1rP01WWp/TwWPN7SWRqbAqIzAbZEW+r5heBH H3kbXq169EEGsQQzMOXz7mxgfD3HGklA+b17zrWijJfeMpixg/dJ6Rs1GiIGdP9XOKC+ BDBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=vIVOD6ES; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r13si1392577pgf.626.2018.02.02.05.26.44; Fri, 02 Feb 2018 05:27:00 -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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=vIVOD6ES; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751697AbeBBN0V (ORCPT + 99 others); Fri, 2 Feb 2018 08:26:21 -0500 Received: from lelnx194.ext.ti.com ([198.47.27.80]:36274 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751416AbeBBN0P (ORCPT ); Fri, 2 Feb 2018 08:26:15 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w12DPdF9021186; Fri, 2 Feb 2018 07:25:39 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1517577939; bh=UePk+2xyxgFWoMSiL9h289wCfvb6Au4afFQFhuoEHM4=; h=Subject:To:References:CC:From:Date:In-Reply-To; b=vIVOD6ESL9Qm/mFXgDfQY/7nzuAM7aiUuJTDCiTXXvIEK6q4AcajK/ErZvArjCMi1 zUFXMnDwLXkXc9+wBJjMoP8x46ot7d7MBht8TpKt8L+DXXQSNxQUp6LOTkz8LH4oWq TywhZHJIgu3rK95T03kwhV/c5Af21W2Ouf7tuxEU= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w12DPdvM010336; Fri, 2 Feb 2018 07:25:39 -0600 Received: from DLEE105.ent.ti.com (157.170.170.35) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Fri, 2 Feb 2018 07:25:39 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Fri, 2 Feb 2018 07:25:39 -0600 Received: from [172.24.190.233] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w12DPZD7003753; Fri, 2 Feb 2018 07:25:35 -0600 Subject: Re: [RFC PATCH 09/12] mmc: sdhci: Use software timer when timeout greater than hardware capablility To: Adrian Hunter , Ulf Hansson , Rob Herring , Tony Lindgren References: <20171214130941.26666-1-kishon@ti.com> <20171214130941.26666-10-kishon@ti.com> <74170f0a-329a-2c66-7ad4-a1fedb9747df@intel.com> <2da01441-84d0-0d96-610d-2f9a3055ccc7@ti.com> <2a41ba31-07e5-027a-de30-495f69d71a88@intel.com> CC: Mark Rutland , Russell King , , , , , , From: Kishon Vijay Abraham I Message-ID: <04efc506-b6dd-3950-336d-a4d92787d35d@ti.com> Date: Fri, 2 Feb 2018 18:55:34 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <2a41ba31-07e5-027a-de30-495f69d71a88@intel.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Adrian, On Thursday 11 January 2018 02:16 PM, Adrian Hunter wrote: > On 04/01/18 14:59, Kishon Vijay Abraham I wrote: >> Hi Adrian, >> >> On Wednesday 20 December 2017 07:41 PM, Adrian Hunter wrote: >>> On 14/12/17 15:09, Kishon Vijay Abraham I wrote: >>>> Errata i834 in AM572x Sitara Processors Silicon Revision 2.0, 1.1 >>>> (SPRZ429K July 2014–Revised March 2017 [1]) mentions >>>> Under high speed HS200 and SDR104 modes, the functional clock for MMC >>>> modules will reach up to 192 MHz. At this frequency, the maximum obtainable >>>> timeout (DTO = 0xE) through MMC host controller is (1/192MHz)*2^27 = 700ms. >>>> Commands taking longer than 700ms may be affected by this small window >>>> frame. Workaround for this errata is use a software timer instead of >>>> hardware timer to provide the delay requested by the upper layer. >>>> >>>> While this errata is specific to AM572x, it is applicable to all sdhci >>>> based controllers when a particular request require timeout greater >>>> than hardware capability. >>> >>> It doesn't work for our controllers. Even if the data timeout interrupt is >>> disabled, it seems like the timeout still "happens" in some fashion - after >>> which the host controller starts misbehaving. >> >> even if the data timeout doesn't get disabled, count = 0xE is still present. So >> ideally this shouldn't break any existing platforms no? > > I don't want to hide this kind of variation in the hardware behaviour. > >>> >>> So you will need to add a quirk. >>> >>>> >>>> Re-use the software timer already implemented in sdhci to program the >>>> correct timeout value and also disable the hardware timeout when >>>> the required timeout is greater than hardware capabiltiy in order to >>>> avoid spurious timeout interrupts. >>>> >>>> This patch is based on the earlier patch implemented for omap_hsmmc [2] >>>> >>>> [1] -> http://www.ti.com/lit/er/sprz429k/sprz429k.pdf >>>> [2] -> https://patchwork.kernel.org/patch/9791449/ >>>> >>>> Signed-off-by: Kishon Vijay Abraham I >>>> --- >>>> drivers/mmc/host/sdhci.c | 41 +++++++++++++++++++++++++++++++++++++++-- >>>> drivers/mmc/host/sdhci.h | 11 +++++++++++ >>>> 2 files changed, 50 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c >>>> index e9290a3439d5..d0655e1d2cc7 100644 >>>> --- a/drivers/mmc/host/sdhci.c >>>> +++ b/drivers/mmc/host/sdhci.c >>>> @@ -673,6 +673,27 @@ static void sdhci_adma_table_post(struct sdhci_host *host, >>>> } >>>> } >>>> >>>> +static void sdhci_calc_sw_timeout(struct sdhci_host *host, >>>> + struct mmc_command *cmd, >>>> + unsigned int target_timeout) >>>> +{ >>>> + struct mmc_host *mmc = host->mmc; >>>> + struct mmc_ios *ios = &mmc->ios; >>>> + struct mmc_data *data = cmd->data; >>>> + unsigned long long transfer_time; >>>> + >>>> + if (data) { >>>> + transfer_time = MMC_BLOCK_TRANSFER_TIME_MS(data->blksz, >>>> + ios->bus_width, >>>> + ios->clock); >>> >>> If it has a value, actual_clock is better than ios->clock. >> >> okay. >>> >>>> + /* calculate timeout for the entire data */ >>>> + host->data_timeout = (data->blocks * (target_timeout + >>>> + transfer_time)); >>>> + } else if (cmd->flags & MMC_RSP_BUSY) { >>>> + host->data_timeout = cmd->busy_timeout * MSEC_PER_SEC; >>> >>> Doesn't need MSEC_PER_SEC multiplier. >> >> right. >>> >>>> + } >>>> +} >>>> + >>>> static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd) >>>> { >>>> u8 count; >>>> @@ -732,8 +753,12 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd) >>>> } >>>> >>>> if (count >= 0xF) { >>>> - DBG("Too large timeout 0x%x requested for CMD%d!\n", >>>> - count, cmd->opcode); >>>> + DBG("Too large timeout.. using SW timeout for CMD%d!\n", >>>> + cmd->opcode); >>>> + sdhci_calc_sw_timeout(host, cmd, target_timeout); >>>> + host->ier &= ~SDHCI_INT_DATA_TIMEOUT; >>>> + sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); >>>> + sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); >>>> count = 0xE; >>>> } >>>> >>>> @@ -1198,6 +1223,14 @@ static void sdhci_finish_command(struct sdhci_host *host) >>>> { >>>> struct mmc_command *cmd = host->cmd; >>>> >>>> + if (host->data_timeout) { >>>> + unsigned long timeout; >>>> + >>>> + timeout = jiffies + >>>> + msecs_to_jiffies(host->data_timeout); >>>> + sdhci_mod_timer(host, host->cmd->mrq, timeout); >>> >>> cmd could be the sbc or a stop cmd or a command during transfer, so this >>> needs more logic. >> >> host->data_timeout gets set only for data commands or commands with busy >> timeout. But I guess for commands during data transfer, host->data_timeout >> might still be set? >> >> Checking sdhci_data_line_cmd(mrq->cmd) in addition to host->data_timeout should >> take care of all cases right? > > I suggest you make the timeout calculation allow for the commands as well > and then reorder sdhci_mod_timer() to be called after sdhci_prepare_data() > and make sdhci_mod_timer() do the right thing. Since we don't know when exactly the command will be sent, the timeout calculation might not be very accurate. Programming the timer in command complete will be bit more accurate IMO. What do you think? Thanks Kishon