From patchwork Wed Apr 25 12:09:31 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: 134254 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp779024lji; Wed, 25 Apr 2018 05:10:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+cXh97B1/YQ0l0RXlTHji7P0okcTr7r3IdggMbEewgPfqEI6DjdOKsqhXVIUFSSabBkuTB X-Received: by 2002:a17:902:a603:: with SMTP id u3-v6mr29222495plq.214.1524658220464; Wed, 25 Apr 2018 05:10:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524658220; cv=none; d=google.com; s=arc-20160816; b=sQ50H3Ot/inFh/hbpb6PsGDPVfQOt4jVnoHvIkNDwGB74pUhzmIzN1YWtmii27gfA9 8pF/X5JwfjlZ5uFEGDmeBA75hdMng5wHCq7dc1zbCzKFhM3cc+FHA3mouF77RmUuu3ln uVCzOfHqss06uVe+Y/KyGvG+lEULPVZlSU3huU9pb09wEgaTiMivLz2/kaR5lnBY7n22 PW16KxZM+6PnpwWYpAYMNOxS7eFaKT5lCS55e4vt4lmXZSyCIws4hPpbF7h1sUM8NcxR +quh1Ni5+0dwuf+JrcUvPnPBChbkOOw94oho0ZB2O8tCVwCezBu/AlUwut7ru0XPRL8k oSfw== 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=6OvxDYSr0FraS4HLEoiFtRxfScJF3TDfg3XmbA8nLGQ=; b=orBBuUGnocZry4DujvQ9z/Z6n4KjeRxXmYUffQmUCIXIfd8UQRhndBDuVCwLvpyX61 VFn3MfKhfNuYn5J0zAr+9ObtNaybwXF4h/1bGlX74vBpjqb3kOuXN5KYvNWnsoCN2zA7 l9jF4yuzSVYfNESFQN8uAfFtmCbMMWdX7q8L/Rn0SVWFVt9aPFk93roRoKZfhckLBOcu XGAyVm/7QoZsGHAa6++V1fGASEUSX2L5o26DRJm9u4JsV21oEWHzbXAbnLkVRdDx+noy 2r3qVfa6PK4gKt7t+hVrBu5PeLST+ANHmq7L2FCch1KnP0MZ+gSpWZDo+DJg6psX0sSr JM9A== 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=DoK4fncv; 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 a123si13650325pgc.43.2018.04.25.05.10.20; Wed, 25 Apr 2018 05:10:20 -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=DoK4fncv; 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 S1753157AbeDYMKS (ORCPT + 5 others); Wed, 25 Apr 2018 08:10:18 -0400 Received: from lelnx194.ext.ti.com ([198.47.27.80]:63442 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752785AbeDYMKM (ORCPT ); Wed, 25 Apr 2018 08:10:12 -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 w3PCA6Rn018891; Wed, 25 Apr 2018 07:10:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1524658206; bh=niQzSScxUplumje1ksG05RgPXuCxbuOYOyYTH6hi0hk=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=DoK4fncv92NS3jkLy2EnWXZLZkDDLxBLxIKI5p1rRzthRKLG7GucbNjJQiRwH9rFW znaipX4arMEfcHYz3j84SdL1MAarodip4d2YvAbK+itpbhtLuW5Jf+idOMNcKD+GBm fDSpnByLP/Qp0Uy5RcShmTy1XDYAYFtzvdqCngpQ= Received: from DFLE102.ent.ti.com (dfle102.ent.ti.com [10.64.6.23]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3PCA6qv017232; Wed, 25 Apr 2018 07:10:06 -0500 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE102.ent.ti.com (10.64.6.23) 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:06 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) 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; Wed, 25 Apr 2018 07:10:06 -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 w3PC9hhT009970; Wed, 25 Apr 2018 07:10:03 -0500 From: Kishon Vijay Abraham I To: Ulf Hansson , Adrian Hunter CC: , Rob Herring , Mark Rutland , , , , , Tony Lindgren Subject: [PATCH v4 06/12] mmc: sdhci: Add quirk to disable HW timeout Date: Wed, 25 Apr 2018 17:39:31 +0530 Message-ID: <20180425120937.29867-7-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 From: Adrian Hunter Add quirk to disable HW timeout if the requested timeout is more than the maximum obtainable timeout. Also, if the quirk is set and ->get_max_timeout_count() is not implemented, max_busy_timeout is set to zero. Based-on-patch-by: Kishon Vijay Abraham I Signed-off-by: Adrian Hunter Signed-off-by: Kishon Vijay Abraham I --- drivers/mmc/host/sdhci.c | 38 ++++++++++++++++++++++++++++++++++---- drivers/mmc/host/sdhci.h | 5 +++++ 2 files changed, 39 insertions(+), 4 deletions(-) -- 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 b5f047b5f3ae..b91163de4da4 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -709,12 +709,15 @@ static u32 sdhci_sdma_address(struct sdhci_host *host) return sg_dma_address(host->data->sg); } -static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd) +static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd, + bool *too_big) { u8 count; struct mmc_data *data = cmd->data; unsigned target_timeout, current_timeout; + *too_big = true; + /* * If the host controller provides us with an incorrect timeout * value, just skip the check and use 0xE. The hardware may take @@ -768,9 +771,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); + if (!(host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT)) + DBG("Too large timeout 0x%x requested for CMD%d!\n", + count, cmd->opcode); count = 0xE; + } else { + *too_big = false; } return count; @@ -790,6 +796,16 @@ static void sdhci_set_transfer_irqs(struct sdhci_host *host) sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); } +static void sdhci_set_data_timeout_irq(struct sdhci_host *host, bool enable) +{ + if (enable) + host->ier |= SDHCI_INT_DATA_TIMEOUT; + else + host->ier &= ~SDHCI_INT_DATA_TIMEOUT; + sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); + sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); +} + static void sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) { u8 count; @@ -797,7 +813,17 @@ static void sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) if (host->ops->set_timeout) { host->ops->set_timeout(host, cmd); } else { - count = sdhci_calc_timeout(host, cmd); + bool too_big = false; + + count = sdhci_calc_timeout(host, cmd, &too_big); + + if (too_big && + host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT) { + sdhci_set_data_timeout_irq(host, false); + } else if (!(host->ier & SDHCI_INT_DATA_TIMEOUT)) { + sdhci_set_data_timeout_irq(host, true); + } + sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL); } } @@ -3616,6 +3642,10 @@ int sdhci_setup_host(struct sdhci_host *host) mmc->max_busy_timeout /= host->timeout_clk; } + if (host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT && + !host->ops->get_max_timeout_count) + mmc->max_busy_timeout = 0; + mmc->caps |= MMC_CAP_SDIO_IRQ | MMC_CAP_ERASE | MMC_CAP_CMD23; mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD; diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index c95b0a4a7594..f6555c0f4ad3 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -437,6 +437,11 @@ struct sdhci_host { #define SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN (1<<15) /* Controller has CRC in 136 bit Command Response */ #define SDHCI_QUIRK2_RSP_136_HAS_CRC (1<<16) +/* + * Disable HW timeout if the requested timeout is more than the maximum + * obtainable timeout. + */ +#define SDHCI_QUIRK2_DISABLE_HW_TIMEOUT (1<<17) int irq; /* Device IRQ */ void __iomem *ioaddr; /* Mapped address */ 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; };