From patchwork Fri Apr 27 11:47:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kishon Vijay Abraham I X-Patchwork-Id: 134596 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp619446lji; Fri, 27 Apr 2018 04:50:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoKsvet0c/d86/q66fEihX+VWDwklCIE38WjdQ3KUTCbz7jKolyN20GmehgFvFsshaBw5u7 X-Received: by 10.98.160.68 with SMTP id r65mr1899860pfe.235.1524829799919; Fri, 27 Apr 2018 04:49:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524829799; cv=none; d=google.com; s=arc-20160816; b=pOR67r+FblwTWpeVD8hD80Lmpw8sr1WPNdMrzuTxnC3zOYkqTw44MN9WdWAGRUMW03 G1X4yyJb8+pyk4zBd1ghnQsQByyOqHCIkPrjVcfqQzDgVt32szA1jZe2tvFKsHz22nc3 B7fgdIW6tpwgCI+jhzYRI2OUnj3QXPs58nTvAxbXtZCSQBGG58c7afjCk2sDGqz6/WPP Tzfhn0Bdon/4NOzt92tnnydlVBtZIEL3wMnFZXT8WvmFmgHv4WSFxzwclO1KF1hkC6tR 6crSbii/btYoLxZoSy2+QI8wAZGtXQuvsOVRNngva8lmumwU8xHlsHmSzThP65++E3xq vODw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=p//n/ddXPkFaoyHirpANVfmY+n+t3oNPyOWIRUroRfc=; b=FH9R59kIT9sj1xCQNcVYAfdzqhfqfa7V5XeRF9ZEsCT/qmRlI52SHRwKfYlcyYHLNy JtEDAtoxoEtO9SmJedEUSNxqnGUXyeu26Tm4eFvYnYDVfhACbe1k6cBu8p35IhP68anl QMzEayWqCD0A1jQtf57yh/VnezdsTKzNXLfnFBpku0dPBP+eRS0fydOgrTclwuFvbokp froRI2gRXm7WE+URSnLKWH1LqwXw2Hn+Yw9zxouYEoGKPr2AmlVQlVGDtkLvxQywbOdp LuUF2vCo3kQKxaefTrJPC+jx24bA7rjCuJdIw43MA6/UAEkczPdCVVlQCui6GyrUyHnL jaJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=QYc0Oc2M; 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 b6si1135466pfe.265.2018.04.27.04.49.59; Fri, 27 Apr 2018 04:49:59 -0700 (PDT) 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=QYc0Oc2M; 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 S1758173AbeD0Lt5 (ORCPT + 29 others); Fri, 27 Apr 2018 07:49:57 -0400 Received: from lelnx194.ext.ti.com ([198.47.27.80]:14972 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757680AbeD0LsB (ORCPT ); Fri, 27 Apr 2018 07:48:01 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w3RBltRN010406; Fri, 27 Apr 2018 06:47:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1524829675; bh=bomq/Dk1ln70ssxPmYIaylTBbXxZ+4AAq1ndP7We0hU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=QYc0Oc2MXzrJlcejH9EznUf6z2Hmsbwj6Yjf7Y9KRHMB8oYb+QkNLOymkB+BkU+1d hIT1ipHd23l1FDClcrQgKrFb+ylXiepRYsG9MRm/SWl2VtX0KCYAfdK64Ky7Odehie thNkwvWI/EGCfaf3OFPcp/GgvTizey+yicoNv7ig= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3RBlt3b020976; Fri, 27 Apr 2018 06:47:55 -0500 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 27 Apr 2018 06:47:55 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 27 Apr 2018 06:47:54 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3RBlRSM014207; Fri, 27 Apr 2018 06:47:52 -0500 From: Kishon Vijay Abraham I To: Ulf Hansson , Adrian Hunter CC: Rob Herring , Mark Rutland , , , , , Subject: [PATCH v5 08/14] mmc: sdhci: Program a relatively accurate SW timeout value Date: Fri, 27 Apr 2018 17:17:17 +0530 Message-ID: <20180427114723.2687-9-kishon@ti.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427114723.2687-1-kishon@ti.com> References: <20180427114723.2687-1-kishon@ti.com> MIME-Version: 1.0 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 sdhci has a 10 second timeout to catch devices that stop responding. In the case of quirk SDHCI_QUIRK2_DISABLE_HW_TIMEOUT, instead of programming 10 second arbitrary value, calculate the total time it would take for the entire transfer to happen and program the timeout value accordingly. Signed-off-by: Kishon Vijay Abraham I Signed-off-by: Adrian Hunter --- drivers/mmc/host/sdhci.c | 52 ++++++++++++++++++++++++++++++++++------ drivers/mmc/host/sdhci.h | 10 ++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) -- 2.17.0 diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index b229354e5b88..1c828e0e9905 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -738,6 +738,39 @@ static unsigned int sdhci_target_timeout(struct sdhci_host *host, return target_timeout; } +static void sdhci_calc_sw_timeout(struct sdhci_host *host, + struct mmc_command *cmd) +{ + struct mmc_data *data = cmd->data; + struct mmc_host *mmc = host->mmc; + struct mmc_ios *ios = &mmc->ios; + unsigned char bus_width = 1 << ios->bus_width; + unsigned int blksz; + unsigned int freq; + u64 target_timeout; + u64 transfer_time; + + target_timeout = sdhci_target_timeout(host, cmd, data); + target_timeout *= NSEC_PER_USEC; + + if (data) { + blksz = data->blksz; + freq = host->mmc->actual_clock ? : host->clock; + transfer_time = (u64)blksz * NSEC_PER_SEC * (8 / bus_width); + do_div(transfer_time, freq); + /* multiply by '2' to account for any unknowns */ + transfer_time = transfer_time * 2; + /* calculate timeout for the entire data */ + host->data_timeout = data->blocks * target_timeout + + transfer_time; + } else { + host->data_timeout = target_timeout; + } + + if (host->data_timeout) + host->data_timeout += MMC_CMD_TRANSFER_TIME; +} + static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd, bool *too_big) { @@ -831,6 +864,7 @@ static void sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) if (too_big && host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT) { + sdhci_calc_sw_timeout(host, cmd); sdhci_set_data_timeout_irq(host, false); } else if (!(host->ier & SDHCI_INT_DATA_TIMEOUT)) { sdhci_set_data_timeout_irq(host, true); @@ -845,6 +879,8 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd) u8 ctrl; struct mmc_data *data = cmd->data; + host->data_timeout = 0; + if (sdhci_data_line_cmd(cmd)) sdhci_set_timeout(host, cmd); @@ -1198,13 +1234,6 @@ void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) mdelay(1); } - timeout = jiffies; - if (!cmd->data && cmd->busy_timeout > 9000) - timeout += DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ; - else - timeout += 10 * HZ; - sdhci_mod_timer(host, cmd->mrq, timeout); - host->cmd = cmd; if (sdhci_data_line_cmd(cmd)) { WARN_ON(host->data_cmd); @@ -1244,6 +1273,15 @@ void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) cmd->opcode == MMC_SEND_TUNING_BLOCK_HS200) flags |= SDHCI_CMD_DATA; + timeout = jiffies; + if (host->data_timeout) + timeout += nsecs_to_jiffies(host->data_timeout); + else if (!cmd->data && cmd->busy_timeout > 9000) + timeout += DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ; + else + timeout += 10 * HZ; + sdhci_mod_timer(host, cmd->mrq, timeout); + sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND); } EXPORT_SYMBOL_GPL(sdhci_send_command); diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index f6555c0f4ad3..23966f887da6 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -332,6 +332,14 @@ struct sdhci_adma2_64_desc { /* Allow for a a command request and a data request at the same time */ #define SDHCI_MAX_MRQS 2 +/* + * 48bit command and 136 bit response in 100KHz clock could take upto 2.48ms. + * However since the start time of the command, the time between + * command and response, and the time between response and start of data is + * not known, set the command transfer time to 10ms. + */ +#define MMC_CMD_TRANSFER_TIME (10 * NSEC_PER_MSEC) /* max 10 ms */ + enum sdhci_cookie { COOKIE_UNMAPPED, COOKIE_PRE_MAPPED, /* mapped by sdhci_pre_req() */ @@ -555,6 +563,8 @@ struct sdhci_host { /* Host SDMA buffer boundary. */ u32 sdma_boundary; + u64 data_timeout; + unsigned long private[0] ____cacheline_aligned; };