From patchwork Wed Apr 25 12:09:33 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: 134260 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp781284lji; Wed, 25 Apr 2018 05:12:19 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Y4lWisFRgcTf5ofJrFexvgAZz4KGJHztT/EVO2lvBBQZysy4rThJwnosXQgv7lIncMalC X-Received: by 10.99.109.65 with SMTP id i62mr23438013pgc.233.1524658338979; Wed, 25 Apr 2018 05:12:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524658338; cv=none; d=google.com; s=arc-20160816; b=gvus3NhyDhzckkqKjbyHNhbjzKj/bu9DDHfHxENShBzq8AyeS6lcLHCernwdcIN8er TDW5jVX01mxQtWcbIX25/0LNYs3pTrSwITSz/GDzmH/ovIUZLS0Vb2TARJyD1XbLsSRU x8sccDJaXMf/1aYSN3SM7RStX2HnTjYdn9HRrf9yDauqTZuIvYVXAFbq67FzgOXqxaor 9Zvjisr41naqkoUcwOfGd8ygdPeVXemeLmeKIyFMWOa8bmqFNMSP9HtxI0YfTKS89VnS HeOBaptErn+VWrmdpp0zUGI9aOn4PV321/XaLOI1Mrxr6WpeC7EWcDFxKGblPIOADavU CnuA== 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=GasaNds9/wahdWZcivR46c/YzSzKn4QYAMssCYpwBf0=; b=rboa4wYVmQ09nEqqbHROWfDGFjmSOKhvlkxRnbjUOf2ltSrrpe1IIMaOEOI/I5InNU j+4Lohj/TOCQfrm2ov+UClvyddJP07QKOVMWh5hvp4++oepU/UBPrLmCIOhz6X5wxaA9 5juHa7oroX2BUiZtHZcFOamT1pofLbIdbnr7+EmZD4QI7F8KBqDtWMNhaYi9qggfWaMq +DEUH0dh0t3aA/RofDpRrdb3nb46rokho8ExRPl0unbSOzASZl7PH9unV8HRJ2ubpjyV e8TH5AuIz+EcC9dUc8BGhqf4aPoynX6QGqLK7VBAKtuh/r5G/KI19qdUjBdqL9oBmbUk bWQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=tBj02moI; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) 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 e71si9844927pfj.250.2018.04.25.05.12.18; Wed, 25 Apr 2018 05:12:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=tBj02moI; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752902AbeDYMMR (ORCPT + 5 others); Wed, 25 Apr 2018 08:12:17 -0400 Received: from fllnx210.ext.ti.com ([198.47.19.17]:60392 "EHLO fllnx210.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753131AbeDYMKS (ORCPT ); Wed, 25 Apr 2018 08:10:18 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id w3PCACli012312; Wed, 25 Apr 2018 07:10:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1524658212; bh=R8gDQyHVt8TydKfvjijpaXCPXplMcWEvrQ2ZYNEzAcY=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=tBj02moI2ilQ9auWqrDtxThRg2pcjVxVkpqXhZ0+0i38cyHbUdSPY5bgjF/v7huVN LgD9H8+yQqsZDzDH+9ntx2PkTNQcpJ2EUuJnClPrtMAAG/tamEbx4mnO7qtExe6LdF uR7WtgX2xaQGe6CDP9yDWAk80d2ttayYMDIsMLnY= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3PCACRG017419; Wed, 25 Apr 2018 07:10:12 -0500 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Wed, 25 Apr 2018 07:10:12 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Wed, 25 Apr 2018 07:10:12 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3PC9hhV009970; Wed, 25 Apr 2018 07:10:09 -0500 From: Kishon Vijay Abraham I To: Ulf Hansson , Adrian Hunter CC: , Rob Herring , Mark Rutland , , , , , Tony Lindgren Subject: [PATCH v4 08/12] mmc: sdhci: Program a relatively accurate SW timeout value Date: Wed, 25 Apr 2018 17:39:33 +0530 Message-ID: <20180425120937.29867-9-kishon@ti.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425120937.29867-1-kishon@ti.com> References: <20180425120937.29867-1-kishon@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@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 | 36 ++++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci.h | 10 ++++++++++ 2 files changed, 46 insertions(+) -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index c432ec3644aa..1ed0b8b6570a 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); 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; };